Skip to content

Commit a70b262

Browse files
committed
Fix build without CUDA NVCC
1 parent 92fe6a0 commit a70b262

File tree

2 files changed

+61
-43
lines changed

2 files changed

+61
-43
lines changed

CMakeLists.txt

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ set(CMAKE_CUDA_STANDARD 17)
99

1010
# Set default build type to Release
1111
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
12-
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
13-
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
12+
set(CMAKE_BUILD_TYPE
13+
Release
14+
CACHE STRING "Choose the type of build." FORCE)
15+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
16+
"MinSizeRel" "RelWithDebInfo")
1417
endif()
1518

1619
# Check for CUDA
@@ -23,43 +26,49 @@ if(CMAKE_CUDA_COMPILER)
2326
message(STATUS "CUDA compiler found: ${CMAKE_CUDA_COMPILER}")
2427

2528
if(NOT SKBUILD)
26-
message(FATAL_ERROR "Building standalone project directly without pip install is not supported"
27-
"Please use pip install to build the project")
29+
message(
30+
FATAL_ERROR
31+
"Building standalone project directly without pip install is not supported"
32+
"Please use pip install to build the project")
2833
else()
2934
find_package(CUDAToolkit REQUIRED)
3035

3136
# Add the executable
32-
find_package(Python 3.8
33-
REQUIRED COMPONENTS Interpreter Development.Module
34-
OPTIONAL_COMPONENTS Development.SABIModule)
37+
find_package(
38+
Python 3.8 REQUIRED
39+
COMPONENTS Interpreter Development.Module
40+
OPTIONAL_COMPONENTS Development.SABIModule)
3541
execute_process(
36-
COMMAND "${Python_EXECUTABLE}"
37-
"-c" "from jax.extend import ffi; print(ffi.include_dir())"
38-
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE XLA_DIR)
42+
COMMAND "${Python_EXECUTABLE}" "-c"
43+
"from jax.extend import ffi; print(ffi.include_dir())"
44+
OUTPUT_STRIP_TRAILING_WHITESPACE
45+
OUTPUT_VARIABLE XLA_DIR)
3946
message(STATUS "XLA include directory: ${XLA_DIR}")
4047

4148
# Detect the installed nanobind package and import it into CMake
4249
find_package(nanobind CONFIG REQUIRED)
4350

44-
nanobind_add_module(_s2fft STABLE_ABI
45-
${CMAKE_CURRENT_LIST_DIR}/lib/src/extensions.cc
46-
${CMAKE_CURRENT_LIST_DIR}/lib/src/s2fft.cu
47-
${CMAKE_CURRENT_LIST_DIR}/lib/src/s2fft_callbacks.cu
48-
${CMAKE_CURRENT_LIST_DIR}/lib/src/plan_cache.cc
49-
${CMAKE_CURRENT_LIST_DIR}/lib/src/s2fft_kernels.cu
50-
)
51-
52-
target_link_libraries(_s2fft PRIVATE CUDA::cudart_static CUDA::cufft_static CUDA::culibos)
53-
target_include_directories(_s2fft PUBLIC
54-
${CMAKE_CURRENT_LIST_DIR}/lib/include
55-
${XLA_DIR}
56-
)
57-
set_target_properties(_s2fft PROPERTIES
58-
LINKER_LANGUAGE CUDA
59-
CUDA_SEPARABLE_COMPILATION ON)
60-
set(CMAKE_CUDA_ARCHITECTURES "70;80;89" CACHE STRING "List of CUDA compute capabilities to build cuDecomp for.")
51+
nanobind_add_module(
52+
_s2fft
53+
STABLE_ABI
54+
${CMAKE_CURRENT_LIST_DIR}/lib/src/extensions.cc
55+
${CMAKE_CURRENT_LIST_DIR}/lib/src/s2fft.cu
56+
${CMAKE_CURRENT_LIST_DIR}/lib/src/s2fft_callbacks.cu
57+
${CMAKE_CURRENT_LIST_DIR}/lib/src/plan_cache.cc
58+
${CMAKE_CURRENT_LIST_DIR}/lib/src/s2fft_kernels.cu)
59+
60+
target_link_libraries(_s2fft PRIVATE CUDA::cudart_static CUDA::cufft_static
61+
CUDA::culibos)
62+
target_include_directories(
63+
_s2fft PUBLIC ${CMAKE_CURRENT_LIST_DIR}/lib/include ${XLA_DIR})
64+
set_target_properties(_s2fft PROPERTIES LINKER_LANGUAGE CUDA
65+
CUDA_SEPARABLE_COMPILATION ON)
66+
set(CMAKE_CUDA_ARCHITECTURES
67+
"70;80;89"
68+
CACHE STRING "List of CUDA compute capabilities to build cuDecomp for.")
6169
message(STATUS "CUDA_ARCHITECTURES: ${CMAKE_CUDA_ARCHITECTURES}")
62-
set_target_properties(_s2fft PROPERTIES CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}")
70+
set_target_properties(_s2fft PROPERTIES CUDA_ARCHITECTURES
71+
"${CMAKE_CUDA_ARCHITECTURES}")
6372

6473
install(TARGETS _s2fft LIBRARY DESTINATION s2fft_lib)
6574
endif()
@@ -68,26 +77,35 @@ else()
6877
if(SKBUILD)
6978
message(WARNING "CUDA compiler not found, building without CUDA support")
7079

71-
find_package(Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED)
80+
find_package(
81+
Python 3.8
82+
COMPONENTS Interpreter Development.Module
83+
REQUIRED)
7284

85+
# Add the executable
7386
execute_process(
74-
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
75-
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT)
76-
find_package(nanobind CONFIG REQUIRED)
87+
COMMAND "${Python_EXECUTABLE}" "-c"
88+
"from jax.extend import ffi; print(ffi.include_dir())"
89+
OUTPUT_STRIP_TRAILING_WHITESPACE
90+
OUTPUT_VARIABLE XLA_DIR)
91+
message(STATUS "XLA include directory: ${XLA_DIR}")
7792

78-
nanobind_add_module(_s2fft STABLE_ABI
79-
${CMAKE_CURRENT_LIST_DIR}/lib/src/extensions.cc
80-
)
93+
# Detect the installed nanobind package and import it into CMake
94+
find_package(nanobind CONFIG REQUIRED)
95+
96+
nanobind_add_module(_s2fft STABLE_ABI
97+
${CMAKE_CURRENT_LIST_DIR}/lib/src/extensions.cc)
8198

8299
target_compile_definitions(_s2fft PRIVATE NO_CUDA_COMPILER)
83-
target_include_directories(_s2fft PUBLIC ${CMAKE_CURRENT_LIST_DIR}/lib/include)
100+
target_include_directories(
101+
_s2fft PUBLIC ${CMAKE_CURRENT_LIST_DIR}/lib/include ${XLA_DIR})
84102

85103
install(TARGETS _s2fft LIBRARY DESTINATION s2fft_lib)
86104

87105
else()
88-
message(FATAL_ERROR "Building standalone project directly without pip install is not supported"
89-
"Please use pip install to build the project")
106+
message(
107+
FATAL_ERROR
108+
"Building standalone project directly without pip install is not supported"
109+
"Please use pip install to build the project")
90110
endif()
91111
endif()
92-
93-

lib/src/extensions.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
#include <complex>
77
#include <type_traits>
88

9+
namespace ffi = xla::ffi;
10+
namespace nb = nanobind;
11+
912
#ifndef NO_CUDA_COMPILER
1013
#include "cuda_runtime.h"
1114
#include "plan_cache.h"
1215
#include "s2fft_kernels.h"
1316
#include "s2fft.h"
1417
#include "cudastreamhandler.hpp" // For forking and joining CUDA streams
1518

16-
namespace ffi = xla::ffi;
17-
namespace nb = nanobind;
18-
1919
namespace s2fft {
2020

2121
/**

0 commit comments

Comments
 (0)