Skip to content

[BUILD] change cuda and hip to default off - #17996

Merged
maxbartel merged 17 commits into
iree-org:mainfrom
maxbartel:disable_cuda_hip_on_default_build
Sep 4, 2024
Merged

maxbartel merged 17 commits into
iree-org:mainfrom
maxbartel:disable_cuda_hip_on_default_build

Conversation

@maxbartel

Copy link
Copy Markdown
Contributor

As discussed in #17564 the default build should not include targets that require an SDK. This PR disables CUDA and ROCM by default.

@maxbartel maxbartel changed the title build: change cuda and hip to default off [BUILD] change cuda and hip to default off Jul 24, 2024
Comment thread build_tools/cmake/build_all.sh Resolved
Comment thread CMakeLists.txt Resolved
Comment thread CMakeLists.txt Resolved
@ScottTodd
ScottTodd self-requested a review July 26, 2024 15:30
@maxbartel
maxbartel marked this pull request as ready for review July 30, 2024 20:03
@maxbartel

Copy link
Copy Markdown
Contributor Author

@ScottTodd You are changing a lot of this scripts at the moment right? How much do you still have to change? Can you give me a hint what needs to be updated afterwards? I would like to get this in soonish, because the Aarch64 CUDA package is regarded as a follow-up and I want to unblock this path.

@ScottTodd

Copy link
Copy Markdown
Member

@ScottTodd You are changing a lot of this scripts at the moment right? How much do you still have to change? Can you give me a hint what needs to be updated afterwards? I would like to get this in soonish, because the Aarch64 CUDA package is regarded as a follow-up and I want to unblock this path.

Yep, sorry for not giving this much (visible) attention. It's still in my queue and top of mind.

I've been mainly organizing the CI and PkgCI workflows so we have fewer builds requiring large self-hosted runner VMs and we build release packages on host platforms then test packages across targets. This is adjacent to some of that and I expect it will be easier to manage once the dust settles a bit more (~ 1 week?). We could try to push through both at the same time, but I'd prefer to focus my attention and limit the surface area of builds to debug.

Here's how I think this can work out:

  1. I finish migrating jobs to pkgci
  2. I clean up old build scripts (CI workflows should either be explicit about what commands they are running or should use CMake presets - right now they go through these build_all.sh style scripts, which you're editing in this PR, that pass environment variables around)
  3. We flip the CMake defaults for more optional components to disabled, updating documentation, scripts, and workflows to enable the components that are needed

Steps 2-3 are still a bit unclear in my head right now... there are too many indirection layers to make those changes with confidence right now.

We also have some macOS py-runtime-pkg release builds failing since they are including Vulkan code and that somehow broke recently. In that case we can have Vulkan default to disabled and then decide explicitly if it should be enabled there, much like the decision you'd like to make to enable CUDA for arm jetson boards.

@maxbartel

Copy link
Copy Markdown
Contributor Author

Sound good. Let's get your changes in first. After editing them I am not a huge fand of the build_all.sh scripts... They are also shared between macos and linux, which makes this PR bigger than it needed to be.

ScottTodd added a commit that referenced this pull request Aug 8, 2024
I'm trying to reduce the number of scripts that we have in
[`build_tools/cmake/`](https://github.com/iree-org/iree/tree/main/build_tools/cmake),
so changes like #17996 will be
easier to make with confidence.

This makes the `build_test_runtime` CI job no longer depend on these
scripts:
*
[`build_tools/cmake/build_runtime.sh`](https://github.com/iree-org/iree/blob/main/build_tools/cmake/build_runtime.sh)
* After this, the last use will be deleted in
#18144
*
[`build_tools/cmake/setup_build.sh`](https://github.com/iree-org/iree/blob/main/build_tools/cmake/setup_build.sh)
*
[`build_tools/cmake/setup_ccache.sh`](https://github.com/iree-org/iree/blob/main/build_tools/cmake/setup_ccache.sh)

These layers of scripts made it somewhat easier to have CI workflows
just run scripts, but the scripts grew branches over time that obscured
what was actually running. In many cases the commands are quite simple
and can just be inlined.

Other ideas for simplification:
* Use https://github.com/marketplace/actions/get-cmake to install Ninja
across platforms (with caching)
* Use https://github.com/marketplace/actions/run-cmake together with
CMake presets ("configure"/"build"/"test", possibly also "workflow")
* Reduce reliance on
[`build_tools/cmake/ctest_all.sh`](https://github.com/iree-org/iree/blob/main/build_tools/cmake/ctest_all.sh)
- that excludes some tests based on platform (e.g. Windows) and adds
exclude labels for tests that need special hardware (e.g. GPUs), but
ideally `ctest` would work out of the box without such a script

ci-exactly: build_test_runtime
@ScottTodd

Copy link
Copy Markdown
Member

I've started deleting or limiting the use of the build_tools/cmake/build_*.sh scripts. One thing I'm not fully sure of in the context of this work is how we want to handle opting CI jobs in to build these components once they are made optional.

Consider the case of the 'runtime' job matrix:

runtime:
needs: setup
name: "runtime :: ${{ matrix.name }}"
if: contains(fromJson(needs.setup.outputs.enabled-jobs), 'runtime')
runs-on: ${{ matrix.runs-on }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include:
- name: ubuntu-20.04
runs-on: ubuntu-20.04
- name: windows-2022
runs-on: windows-2022
- name: macos-14
runs-on: macos-14
env:
BUILD_DIR: build-runtime
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: "3.11"
- name: (Linux) Install requirements
if: contains(matrix.name, 'ubuntu')
run: |
sudo apt update
sudo apt install -y ninja-build
echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
- name: (Windows) Configure MSVC
if: contains(matrix.name, 'windows')
uses: ilammy/[email protected]
- name: (macOS) Install requirements
if: contains(matrix.name, 'macos')
run: brew install ninja ccache coreutils bash
- name: Checkout runtime submodules
run: bash ./build_tools/scripts/git/update_runtime_submodules.sh
- name: Install Python requirements
run: pip install -r ./runtime/bindings/python/iree/runtime/build_requirements.txt
- name: ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ github.job }}-${{ matrix.name }}
save: ${{ needs.setup.outputs.write-caches == 1 }}
- name: CMake - configure
run: |
cmake \
-G Ninja \
-B ${BUILD_DIR} \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DIREE_BUILD_COMPILER=OFF \
-DIREE_BUILD_PYTHON_BINDINGS=ON \
-DIREE_BUILD_SAMPLES=ON \
-DIREE_ENABLE_LLD=ON \
-DIREE_ENABLE_ASSERTIONS=ON
- name: CMake - build
run: cmake --build ${BUILD_DIR} -- -k 0
- name: CTest
run: bash ./build_tools/cmake/ctest_all.sh "${BUILD_DIR}"

should the macos build there opt-in to -DIREE_HAL_DRIVER_METAL=ON? If so, should that job be split out from being a matrix, or should that setting somehow get passed through to only one platform? The script was the default place to put such logic (either via automatic detection or environment variable plumbing). A replacement could be a set of presets in https://github.com/iree-org/iree/tree/main/build_tools/cmake/presets. The matrix could choose a specific preset for each platform, and those preset would list the options they want to enable.

@ScottTodd

Copy link
Copy Markdown
Member

Sorry, refactoring the scripts and workflows is taking longer than originally anticipated (shocker 😅). We could try this again rebased on the latest scripts, but there will still be some plumbing through env vars and confusing indirection to watch out for.

We also have a few breaking changes in flight to batch together into a stable release. This sort of change could also be included in that batch.

@maxbartel

Copy link
Copy Markdown
Contributor Author

No worries! Disabling stuff in the default build does not change the release imo. However the AArch64 CUDA backend would. Maybe we can get that at least in? Would be separete from this.

I am going to take a look at cmake presets. Can you maybe explain what Because these can interact badly with tools from the README refers to?

@ScottTodd

Copy link
Copy Markdown
Member

No worries! Disabling stuff in the default build does not change the release imo. However the AArch64 CUDA backend would. Maybe we can get that at least in? Would be separete from this.

We should end up with the same set of available compiler target backends and runtime HAL drivers in the distributed release artifacts, yes. Any developers building from source will need to opt-in and enable the features that they want though, and that's what I'd like to batch with other breaking changes. Release notes (if we finally write them this time 😅) would then call that out as something developers updating would want to be aware of.

I am going to take a look at cmake presets. Can you maybe explain what Because these can interact badly with tools from the README refers to?

With VSCode in particular, see https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/cmake-presets.md#enable-cmakepresetsjson-in-the-cmake-tools-extension. The default behavior when a CMakePresets.json file exists is to use that preset file. Developers can opt-out and change the cmake.useCMakePresets setting from auto/always to never, but we want good default settings out of the box. It is tricky to define presets for this sort of project that are generally applicable to all developers, so we've been concerned that having them used by default would be confusing or artificially limiting. See also #5804 (comment)

@maxbartel

maxbartel commented Aug 20, 2024 •

Copy link
Copy Markdown
Contributor Author

Hmm yeah you have a point about the release notes. When is that release planned?

Regarding the presets, I think we converged to a minimal build without most backends, didn't we? They have things like conditionals in newer versions. I will try them out to see how that works and give feedback hopefully at the end of this week.

@ScottTodd

Copy link
Copy Markdown
Member

Hmm yeah you have a point about the release notes. When is that release planned?

We've been trying to promote a nightly release to stable around once a month, and the last release was ~1 month ago, so soon. I'm expecting that we'll try to formalize the process more over the coming weeks/months.

Regarding the presets, I think we converged to a minimal build without most backends, didn't we? They have things like conditionals in newer versions. I will try them out to see how that works and give feedback hopefully at the end of this week.

Yep. We have a few presets like this "minimal" one already:

"configurePresets": [
{
"name": "minimal",
"displayName": "Minimal config",
"description": "Project configured with minimal features enabled",

Any feedback or improvements on the setup there would be appreciated.

@maxbartel

Copy link
Copy Markdown
Contributor Author

@ScottTodd So I played around with presets a bit and I think the ergonomics from the command line are ok. However I feel like the behavior with the cmake extension is a bit weird. I am not using that extension for other reasons (no color output, automatic configuration, etc.), so I am probably the wrong person to ask here. Also the conditionals depend on env variables, which wouldn't be better than now...

It feels like we would end up with a python script to create user presets and I am not sure if that would be really better than just using something like python to begin with...

@maxbartel
maxbartel force-pushed the disable_cuda_hip_on_default_build branch from e92814d to 4258a85 Compare August 26, 2024 11:55
@maxbartel

Copy link
Copy Markdown
Contributor Author

@ScottTodd I am in the process of updating the PR. I just wanted to ping you because the CUDA tests for example are marked as passed even though they didn't run... Is there a way to mark them as required?

@ScottTodd

Copy link
Copy Markdown
Member

@ScottTodd I am in the process of updating the PR. I just wanted to ping you because the CUDA tests for example are marked as passed even though they didn't run... Is there a way to mark them as required?

Are you referring to these? https://github.com/iree-org/iree/actions/runs/10562806742/job/29262093188?pr=17996#step:11:75

        Start  133: iree/tests/e2e/linalg/check_winograd_vulkan-spirv_vulkan_conv2d.mlir
 21/403 Test  #133: iree/tests/e2e/linalg/check_winograd_vulkan-spirv_vulkan_conv2d.mli ............   Passed    0.58 sec
        Start  134: iree/tests/e2e/linalg/check_large_linalg_matmul_cuda_conv2d.mlir
 22/403 Test  #134: iree/tests/e2e/linalg/check_large_linalg_matmul_cuda_conv2d.mli ................***Not Run (Disabled)   0.00 sec
        Start  135: iree/tests/e2e/linalg/check_large_linalg_matmul_cuda_fp_to_subbyte.mlir
 23/403 Test  #135: iree/tests/e2e/linalg/check_large_linalg_matmul_cuda_fp_to_subbyte.mli .........***Not Run (Disabled)   0.00 sec

The logic for that is here:

# ---------------------------------------------------------------------------
# Tests are defined if _RULE_DRIVER is defined.
set(_TEST_DEFINED TRUE)
if(NOT DEFINED _RULE_DRIVER)
set(_TEST_DEFINED FALSE)
endif()
# Test execution requires
# 1. the bytecode module build to be enabled
# 2. _RULE_DRIVER is defined and runtime support is enabled
# 3. no other label exclusions (e.g. 'optonly' test with 'debug' config)
set(_TEST_DISABLED FALSE)
# 1. Check bytecode module build.
if(NOT _BYTECODE_MODULE_BUILD_ENABLED)
set(_TEST_DISABLED TRUE)
endif()
# 2. Check driver availability.
if(DEFINED _RULE_DRIVER)
string(TOUPPER ${_RULE_DRIVER} _UPPERCASE_DRIVER)
string(REPLACE "-" "_" _NORMALIZED_DRIVER ${_UPPERCASE_DRIVER})
if((NOT IREE_HAL_DRIVER_${_NORMALIZED_DRIVER}) AND
(NOT IREE_EXTERNAL_${_NORMALIZED_DRIVER}_HAL_DRIVER_FOUND))
set(_TEST_DISABLED TRUE)
endif()
endif()
# 3. Check label exclusions.
iree_is_bytecode_module_test_excluded_by_labels(_EXCLUDED_BY_LABELS "${_RULE_LABELS}")
if(_EXCLUDED_BY_LABELS)
set(_TEST_DISABLED TRUE)
endif()
if((_TEST_DISABLED OR NOT _TEST_DEFINED) AND NOT IREE_BUILD_ALL_CHECK_TEST_MODULES)
set(_BYTECODE_MODULE_BUILD_ENABLED FALSE)
endif()
# ---------------------------------------------------------------------------

I set it up that way to show which tests could run, if the backends were enabled. One of my goals for https://github.com/iree-org/iree-test-suites is to make the tests explicit and obvious. That's hard when the tests are so tightly linked with CMake build settings (including cross-compilation). In the separate repo we can define pytest labels/marks/filters and CMake options unique to the test suites.

Comment thread .github/workflows/ci.yml Resolved
Comment thread .github/workflows/ci.yml Resolved
Comment thread .github/workflows/ci.yml Resolved
Comment thread build_tools/cmake/build_all.sh Resolved
Comment thread build_tools/cmake/build_all.sh Resolved
Comment thread build_tools/cmake/build_all.sh Resolved
Comment thread build_tools/cmake/build_runtime.sh Resolved
@maxbartel
maxbartel requested a review from ScottTodd August 27, 2024 09:48
@maxbartel

Copy link
Copy Markdown
Contributor Author

@ScottTodd I think this PR is now ready. Enabling CUDA for Aarch64 is now also just a change in an if-statement.

@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.

Hopefully the last batch of comments from me. Looks good with a few small edits!

Comment thread .github/workflows/ci.yml Resolved
Comment thread .github/workflows/ci.yml Resolved
Comment thread CMakeLists.txt Resolved
@maxbartel

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I am OOO until Monday and cannot update until then. Just fyi because we also talked about the release this week.

@maxbartel
maxbartel requested a review from ScottTodd September 2, 2024 14:22

@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.

I think the iree/compiler/Codegen/LLVMCPU/test/select_aarch64_sme_lowering_strategy.mlir.test test failures (e.g. https://github.com/iree-org/iree/actions/runs/10668091799/job/29567045891?pr=17996#step:5:599) should be unrelated to these changes. Can you sync the branch used here? (Merge main into your branch, or rebase)

@maxbartel
maxbartel force-pushed the disable_cuda_hip_on_default_build branch from a588cf9 to deb31b5 Compare September 4, 2024 09:44
@ScottTodd ScottTodd added infrastructure Relating to build systems, CI, or testing hal/cuda Runtime CUDA HAL backend hal/hip Runtime HIP HAL backend labels Sep 4, 2024
@maxbartel

Copy link
Copy Markdown
Contributor Author

@ScottTodd I will merge now, but it is also end of day in Germany. Please revert if this breaks something.

@maxbartel
maxbartel merged commit f2bf602 into iree-org:main Sep 4, 2024
@maxbartel
maxbartel deleted the disable_cuda_hip_on_default_build branch September 4, 2024 15:53
IanWood1 pushed a commit to IanWood1/iree that referenced this pull request Sep 8, 2024
As discussed in iree-org#17564 the default
build should not include targets that require an SDK. This PR disables
CUDA and ROCM by default.
josemonsalve2 pushed a commit to josemonsalve2/iree that referenced this pull request Sep 14, 2024
As discussed in iree-org#17564 the default
build should not include targets that require an SDK. This PR disables
CUDA and ROCM by default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hal/cuda Runtime CUDA HAL backend hal/hip Runtime HIP HAL backend infrastructure Relating to build systems, CI, or testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants