Skip to content

Commit

Permalink
use CMake builtin mechanisms for setting target CUDA architecture(s) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb authored Jul 19, 2024
1 parent e445fa1 commit 2f2a6ee
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ jobs:
run: |
mypy ./legateboost --config-file ./setup.cfg --exclude=legateboost/test --exclude=install_info
- name: Build legateboost
env:
CUDAARCHS: '70;80'
run: |
CUDA_ARCH=70\;80 ./build.sh
./build.sh
python -m build -n --wheel
- uses: actions/upload-artifact@v3
with:
Expand Down
9 changes: 7 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/usr/bin/env bash

set -e
set -e -u -o pipefail

# ensure 'native' is used if CUDAARCHS isn't set
# (instead of the CMake default which is a specific architecture)
# ref: https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_ARCHITECTURES.html
declare -r CMAKE_CUDA_ARCHITECTURES="${CUDAARCHS:-native}"

legate_root=`python -c 'import legate.install_info as i; from pathlib import Path; print(Path(i.libpath).parent.resolve())'`
echo "Using Legate at $legate_root"
cmake -S . -B build -D legate_core_ROOT=$legate_root -DCMAKE_BUILD_TYPE=Release -DCMAKE_CUDA_ARCHITECTURES=native
cmake -S . -B build -D legate_core_ROOT=$legate_root -DCMAKE_BUILD_TYPE=Release -DCMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES}
cmake --build build -j
python -m pip install -e .
16 changes: 15 additions & 1 deletion contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ legate --module pytest legateboost/test

## Change default CUDA architectures

Set the environment variable `CUDA_ARCH` according to cmake [CUDA_ARCHITECTURES](https://cmake.org/cmake/help/latest/prop_tgt/CUDA_ARCHITECTURES.html) if you are installing with pip. For running cmake directly, the argument `CMAKE_CUDA_ARCHITECTURES` works as well.
By default, builds here default to `CMAKE_CUDA_ARCHITECTURES=native` (whatever GPU exists on the system where the build is running).

If installing with `pip`, set the `CUDAARCHS` environment variable, as described in the CMake docs ([link](https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_ARCHITECTURES.html)).

```shell
CUDAARCHS="70;80" \
pip install .
```

For CMake-based builds, pass `CMAKE_CUDA_ARCHITECTURES`.

```shell
cmake -B build -S . -DCMAKE_CUDA_ARCHITECTURES="70;80"
cmake --build build -j
```

## Pre-commit hooks

Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@

legate_dir = Path(lg_install_info.libpath).parent.as_posix()

# ensure 'native' is used if CUDAARCHS isn't set
# (instead of the CMake default which is a specific architecture)
# ref: https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_ARCHITECTURES.html
cuda_arch = os.getenv("CUDAARCHS", "native")

cmake_flags = [
f"-Dlegate_core_ROOT:STRING={legate_dir}",
"-DCMAKE_CUDA_ARCHITECTURES=native",
f"-DCMAKE_CUDA_ARCHITECTURES={cuda_arch}",
]

env_cmake_args = os.environ.get("CMAKE_ARGS")
Expand Down
7 changes: 0 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,7 @@ target_compile_options(legateboost
"$<$<COMPILE_LANGUAGE:CUDA>:${LB_CUDA_FLAGS}>"
)



if (Legion_USE_CUDA)
# CUDA_ARCH environment variable can override the CMAKE_CUDA_ARCHITECTURES
if(DEFINED ENV{CUDA_ARCH})
message(STATUS "legateboost: CUDA_ARCH=$ENV{CUDA_ARCH}")
set_property(TARGET legateboost PROPERTY CUDA_ARCHITECTURES $ENV{CUDA_ARCH} )
endif()
target_compile_definitions(legateboost PRIVATE LEGATEBOOST_USE_CUDA)
endif()

Expand Down

0 comments on commit 2f2a6ee

Please sign in to comment.