Skip to content

Commit 8f05b9f

Browse files
Enable building of NVBench as part of buildign extension
1. Download and include CPM.cmake, version 0.42.0 2. Use CPM.make to get Pybind11 3. Update to use pybind11=3.0.0 4. Also use CPM to configure/build nvbench
1 parent 03b9c7f commit 8f05b9f

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

python/CMakeLists.txt

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
cmake_minimum_required(VERSION 3.30...4.0)
22

3-
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)
4-
5-
set(CMAKE_CXX_STANDARD 20)
6-
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
3+
# CUDA is transitive dependency of nvbench
4+
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX CUDA)
75

86
find_package(Python REQUIRED COMPONENTS Development.Module)
97
find_package(CUDAToolkit REQUIRED)
108

11-
include(FetchContent)
9+
# Get CMake package manager
10+
set(_cpm_download_location ${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
11+
file(
12+
DOWNLOAD
13+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.42.0/CPM.cmake
14+
${_cpm_download_location}
15+
EXPECTED_HASH SHA256=2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a
16+
)
17+
include(${_cpm_download_location})
1218

13-
FetchContent_Declare(
14-
pybind11
15-
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.13.6.tar.gz
16-
URL_HASH SHA256=e08cb87f4773da97fa7b5f035de8763abc656d87d5773e62f6da0587d1f0ec20
17-
FIND_PACKAGE_ARGS NAMES pybind11
19+
CPMAddPackage(
20+
NAME nvbench
21+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..
22+
OPTIONS "NVBench_INSTALL_RULES ON"
23+
FIND_PACKAGE_ARGS CONFIG REQUIRED
1824
)
19-
FetchContent_MakeAvailable(pybind11)
2025

21-
find_package(nvbench CONFIG REQUIRED)
26+
CPMAddPackage("gh:pybind/[email protected]")
2227

2328
pybind11_add_module(_nvbench MODULE src/py_nvbench.cpp)
2429
target_link_libraries(_nvbench PUBLIC nvbench::nvbench)
2530
target_link_libraries(_nvbench PRIVATE CUDA::cudart_static)
31+
2632
set_target_properties(_nvbench PROPERTIES INSTALL_RPATH "$ORIGIN")
33+
set_target_properties(_nvbench PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)
34+
set_target_properties(_nvbench PROPERTIES POSITION_INDEPENDENT_CODE ON)
35+
set_target_properties(_nvbench PROPERTIES CXX_STANDARD 20)
2736

2837
install(TARGETS _nvbench DESTINATION cuda/nvbench)
29-
install(IMPORTED_RUNTIME_ARTIFACTS nvbench::nvbench DESTINATION cuda/nvbench)
38+
39+
# Determine target that nvbench::nvbench is an alias of,
40+
# necessary because ALIAS targets cannot be installed
41+
get_target_property(_aliased_target_name nvbench::nvbench ALIASED_TARGET)
42+
install(IMPORTED_RUNTIME_ARTIFACTS ${_aliased_target_name} DESTINATION cuda/nvbench)

python/README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This package provides Python API to CUDA Kernel Benchmarking Library `NVBench`.
44

55
## Building
66

7-
### Build `NVBench` project
7+
### Ensure recent version of CMake
88

99
Since `nvbench` requires a rather new version of CMake (>=3.30.4), either build CMake from sources, or create a conda environment with a recent version of CMake, using
1010

@@ -13,48 +13,49 @@ conda create -n build_env --yes cmake ninja
1313
conda activate build_env
1414
```
1515

16-
Now switch to python folder, configure and install NVBench library, and install the package in editable mode:
16+
### Ensure CUDA compiler
1717

18-
```
19-
cd nvbench/python
20-
cmake -B nvbench_build --preset nvbench-ci -S $(pwd)/.. -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc -DNVBench_ENABLE_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=$(pwd)/nvbench_install
21-
cmake --build nvbench_build/ --config Release --target install
22-
```
18+
Since building `NVBench` library requires CUDA compiler, ensure that appropriate environment variables
19+
are set. For example, assuming CUDA toolkit is installedsystem-wide, and assuming Ampere GPU architecture:
2320

24-
### Build Python extension
21+
```bash
22+
export CUDACXX=/usr/local/cuda/bin/nvcc
23+
export CUDAARCHS=86
24+
``
2525

26-
Specify location local installation of `NVBench` library and perform editable `pip install`:
26+
### Build Python project
2727

28-
```
29-
nvbench_DIR=$(pwd)/nvbench_install/lib/cmake CUDACXX=/usr/local/cuda/bin/nvcc pip install -e .
30-
```
28+
Now switch to python folder, configure and install NVBench library, and install the package in editable mode:
3129

32-
Note that `CUDACXX` must be set for NVBench cmake script to work, but Python extension itself only uses host compiler.
30+
```bash
31+
cd nvbench/python
32+
pip install -e .
33+
```
3334

3435
### Verify that package works
3536

36-
```
37+
```bash
3738
python test/run_1.py
3839
```
3940

4041
### Run examples
4142

42-
```
43+
```bash
4344
# Example benchmarking numba.cuda kernel
4445
python examples/throughput.py
4546
```
4647

47-
```
48+
```bash
4849
# Example benchmarking kernels authored using cuda.core
4950
python examples/axes.py
5051
```
5152

52-
```
53+
```bash
5354
# Example benchmarking algorithms from cuda.cccl.parallel
5455
python examples/cccl_parallel_segmented_reduce.py
5556
```
5657

57-
```
58+
```bash
5859
# Example benchmarking CuPy function
5960
python examples/cupy_extract.py
6061
```

0 commit comments

Comments
 (0)