1 cmake_minimum_required(VERSION 3.22.1)
2 project(cuda_backend)
3
4 set(CMAKE_CXX_STANDARD 17)
5
6 find_package(CUDAToolkit)
7 if(CUDAToolkit_FOUND)
8 message("CUDA")
9 if ("${CUDA_BACKEND}EMPTY" STREQUAL "EMPTY")
10 set (CUDA_BACKEND "${CMAKE_SOURCE_DIR}")
11 message("CUDA_BACKEND=${CUDA_BACKEND}")
12 endif()
13
14 if ("${SHARED_BACKEND}EMPTY" STREQUAL "EMPTY")
15 set (SHARED_BACKEND "${CMAKE_SOURCE_DIR}/../shared")
16 message("SHARED_BACKEND=${SHARED_BACKEND}")
17 endif()
18
19 include_directories(
20 ${CUDAToolkit_INCLUDE_DIRS} # was ${CUDAToolkit_INCLUDE_DIR}
21 ${SHARED_BACKEND}/src/main/native/include
22 ${CUDA_BACKEND}/src/main/native/include
23 )
24
25 link_directories(
26 ${CMAKE_BINARY_DIR}
27 ../shared/target/build
28 ${CUDAToolkit_LIBRARY_DIR}
29 )
30
31 add_library(cuda_backend SHARED
32 ${CUDA_BACKEND}/src/main/native/include/cuda_backend.h
33 ${CUDA_BACKEND}/src/main/native/cpp/cuda_backend.cpp
34 ${CUDA_BACKEND}/src/main/native/cpp/cuda_backend_buffer.cpp
35 ${CUDA_BACKEND}/src/main/native/cpp/cuda_backend_kernel.cpp
36 ${CUDA_BACKEND}/src/main/native/cpp/cuda_backend_module.cpp
37 ${CUDA_BACKEND}/src/main/native/cpp/cuda_backend_queue.cpp
38 )
39
40 # Pass the full CUDA Toolkit include list to the NVRTC path. Newer CUDA
41 # Toolkit layouts may report multiple include roots, for example the main
42 # include directory plus CCCL headers, while older toolkits may only report
43 # one. Keep all entries to avoid baking CUDA-version-specific include logic
44 # into the native backend.
45 string(REPLACE ";" "|" HAT_CUDA_INCLUDE_DIRS "${CUDAToolkit_INCLUDE_DIRS}")
46 target_compile_definitions(cuda_backend
47 PRIVATE HAT_CUDA_INCLUDE_DIRS="${HAT_CUDA_INCLUDE_DIRS}"
48 HAT_CUDA_LIBRARY_DIR="${CUDAToolkit_LIBRARY_DIR}"
49 )
50
51 target_link_libraries(cuda_backend
52 shared_backend
53 -lcuda
54 ${CMAKE_DL_LIBS}
55 )
56
57 add_executable(cuda_info
58 ${CUDA_BACKEND}/src/main/native/cpp/info.cpp
59 )
60
61 add_executable(cuda_squares
62 ${CUDA_BACKEND}/src/main/native/cpp/squares.cpp
63 )
64
65 target_link_libraries(cuda_squares
66 cuda_backend
67
68 )
69
70 target_link_libraries(cuda_info
71 cuda_backend
72
73 )
74 endif()