Skip to content

Rework cmake test deps, target selection and presets. - #8423

Merged
stellaraccident merged 12 commits into
iree-org:mainfrom
stellaraccident:cmakepreset
Mar 2, 2022
Merged

stellaraccident merged 12 commits into
iree-org:mainfrom
stellaraccident:cmakepreset

Conversation

@stellaraccident

@stellaraccident stellaraccident commented Mar 1, 2022 •

Copy link
Copy Markdown
Collaborator

This patch does a few things:

  • Marks all targets under iree/test/ as EXCLUDE_FROM_ALL.

  • Configures check-tests to add a dependency to the global iree-test-deps target.

    • Added a seperate build step for CIs to build iree-test-deps.
  • Reworks compiler target selection to distinguish between "default" targets and those not built by default.

    • Fine-grained LLVM_TARGETS_TO_BUILD are added based on the IREE targets.
    • lld is built if CPU targets are enabled.
    • CPU targets are expanded from a new IREE_DEFAULT_CPU_LLVM_TARGETSoption (defaults to what we had previously hard-coded).
  • Layered CMake options for LLVM so that they are forward and backwards compatible with CMP0126 and work for nested inclusion from another project.

  • Fixed up some old stuff in iree-compiler-api and brought it up to spec for the above changed.

In several places, we had hard-coded assumptions about the above. Fixes include:

  • Conditional inclusion of lld related things when lld is actually build (gated on an IREE_LLD_TARGET variable).
  • C++ code to initialize LLVM code generation was not generic based on targets actually available. Now it is.
  • Added bazel-to-cmake diversions for codegen targets that are hard-coded in Bazel to an IREELLVMCPUTargetDeps, which is manually populated with what is actually built (note that the LLVM build system has a more declarative way to do this but it is incompatible with ours).

This patch does a few things:

* Marks all targets under iree/test/ as EXCLUDE_FROM_ALL.
* Configures check-tests to add a dependency to the global iree-test-deps target.
  * Added a seperate build step for CIs to build iree-test-deps.
* Reworks compiler target selection to distinguish between "default" targets and those not built by default.
  * Fine-grained LLVM_TARGETS_TO_BUILD are added based on the IREE targets.
  * lld is built if CPU targets are enabled.
  * CPU targets are expanded from a new IREE_CPU_LLVM_TARGETS option (defaults to what we had previously hard-coded).

In several places, we had hard-coded assumptions about the above. Fixes include:
  * Conditional inclusion of lld related things when lld is actually build (gated on an IREE_LLD_TARGET variable).
  * C++ code to initialize LLVM code generation was not generic based on targets actually available. Now it is.
  * Added bazel-to-cmake diversions for codegen targets that are hard-coded in Bazel to an IREELLVMCPUTargetDeps, which is manually populated with what is actually built (note that the LLVM build system has a more declarative way to do this but it is incompatible with ours).
  * Gate populating any CPU LLVM backends on IREE_CPU_LLVM_TARGETS_DEFAULTS as it layers better with the wonky CMake preset system.

Adds CMakePresets.json. This is experimental but encoded some of our getting started configurations:
  * minimal: Disables all optional compiler features and samples.
  * clang-dev: Recommended clang dev settings (enables ninja/clang/lld/ccache and defaults to RelWithDebInfo and assertions).
  * minimal-clang-dev: Combination of the first two.
  * x86-clang-dev: The first two plus options to enable CPU compilation on x86.

Presets can be set with something like (requires CMake 3.21+):
  ```
  cmake -B../iree-build --preset x86-clang-dev
  ```

The setup is a bit wonky, but we can add more for common cases, and it is just starting points. Users can flip options from there.

With all of the above, the build is down to ~3200 files for `minimal-clang-dev` (only vmvx compilation is enabled) and ~3800 for `x86-clang-dev` (only vmvx and cpu/x86 enabled). Will probably take some more fiddling to find good defaults.

@ScottTodd ScottTodd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for narrowing the LLVM target deps.

Comment thread CMakePresets.json Resolved
Comment thread CMakeLists.txt Resolved
@ScottTodd ScottTodd added cleanup 🧹 codegen/llvm LLVM code generation compiler backend infrastructure/cmake labels Mar 1, 2022
Comment thread CMakePresets.json Resolved
@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

This is awesome. Really looking forward to not have to build all backends, but just the CPU backends for my in-progress big change to backends. Having to get all tests to build before I can even run the tests is really getting in the way for me!

@benvanik

benvanik commented Mar 1, 2022

Copy link
Copy Markdown
Collaborator

going to give this a try first
will have some feedback on the presets (I've gone down that rabbit hole before)

@benvanik benvanik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's hold off on the cmake presets file - unless there's a pressing need I'd say what's in there today should just be in your local CMakeUserPresets.json if you want to use presets. Adding a global presets file fundamentally changes CLion/vscode/etc behavior and is pretty disruptive so it should be added with care (this file being present in the repo makes it so I can't build anything on Windows, for example, without going and forcing presets to be disabled in my vscode settings) - it's a lot less like a bazelrc than one coming from bazel may first think :) If you think it's really useful as-is then you'll need to rename it to CMakePresets.json.example or something so it doesn't break others by default.

I've got a sketch from awhile back that I'd like to revive that decomposes things to make more sense in IDEs w/ cross-compilation and be usable from CMakeUserPresets.json (which can inherit the base CMakePresets.json to allow for local configuration). I'll fiddle with that a bit more.

Comment thread CMakeLists.txt Resolved
Comment thread CMakeLists.txt Resolved
@stellaraccident

Copy link
Copy Markdown
Collaborator Author

Let's hold off on the cmake presets file - unless there's a pressing need I'd say what's in there today should just be in your local CMakeUserPresets.json if you want to use presets. Adding a global presets file fundamentally changes CLion/vscode/etc behavior and is pretty disruptive so it should be added with care (this file being present in the repo makes it so I can't build anything on Windows, for example, without going and forcing presets to be disabled in my vscode settings) - it's a lot less like a bazelrc than one coming from bazel may first think :) If you think it's really useful as-is then you'll need to rename it to CMakePresets.json.example or something so it doesn't break others by default.

I've got a sketch from awhile back that I'd like to revive that decomposes things to make more sense in IDEs w/ cross-compilation and be usable from CMakeUserPresets.json (which can inherit the base CMakePresets.json to allow for local configuration). I'll fiddle with that a bit more.

Ugh, no good deed. But thanks for checking. I'll pop this out of the patch then in some fashion. Some of the stuff in here is insanely useful and hard to get otherwise (i.e. to the tune of halving ~build/link overheads on Linux), but we can figure out how to walk it forward. I guess I'll need to try the IDE/GUI way to really understand how this is so messed up... it is pretty straight-forward from the CLI.

@benvanik

benvanik commented Mar 1, 2022

Copy link
Copy Markdown
Collaborator

Yeah, sorry - it's traditional cmake: close enough to make you think it's good but then flawed enough to make you realize nothing will ever be good :P

There's some new support I just noticed while fiddling for conditional enablement of configs/builds - that should make it easier to not present msvc on mac and gcc on windows etc and get us a reasonable set of things. Will share some stuff ... after perf... this is too enticing....

@stellaraccident

Copy link
Copy Markdown
Collaborator Author

Yeah, sorry - it's traditional cmake: close enough to make you think it's good but then flawed enough to make you realize nothing will ever be good :P

There's some new support I just noticed while fiddling for conditional enablement of configs/builds - that should make it easier to not present msvc on mac and gcc on windows etc and get us a reasonable set of things. Will share some stuff ... after perf... this is too enticing....

Yeah, i just thought I already stumbled through the sharp parts. I failed to factor in that it is all sharp parts.

Comment thread CMakeLists.txt Resolved
@stellaraccident

Copy link
Copy Markdown
Collaborator Author

PTAL

Comment on lines +48 to +50
echo "Building test deps"
echo "------------------"
"${CMAKE_BIN?}" --build "${CMAKE_BUILD_DIR?}" --target iree-test-deps -- -k 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling that a few other scripts should also build this new iree-test-deps target.

@GMNGeoffrey can you review that part of this also?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they aren't in the CI, we'll just have to be on a voyage of self discovery on that. CTest does show a useful error on these situations (it says that a test input is not available and marks the test as "not run" and counts those as failures).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stellaraccident
stellaraccident merged commit 74b04b7 into iree-org:main Mar 2, 2022
@stellaraccident
stellaraccident deleted the cmakepreset branch March 2, 2022 18:21
KoolJBlack added a commit that referenced this pull request Mar 3, 2022
Should fix `iree/gcp_ubuntu/cmake/linux/x86-turing/main[default]` and `iree/iree-android-arm64-v8a` by adding `"$CMAKE_BIN" --build . --target iree-test-deps -- -k 0` steps to each.
ScottTodd added a commit that referenced this pull request Jun 6, 2022
This list of CMake options was moved into their own file in #8423, for inclusion in `llvm-external-projects/iree-compiler-api/CMakeLists.txt`, which used an "out of tree" build setup. The `llvm-external-projects/iree-compiler-api/` directory was then moved back "in tree" to `iree/compiler/API` in #8911. We can now move the options back into the root file, where they will be easier to read alongside other high level project options.
@GMNGeoffrey GMNGeoffrey added the infrastructure Relating to build systems, CI, or testing label Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup 🧹 codegen/llvm LLVM code generation compiler backend infrastructure Relating to build systems, CI, or testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants