-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
65 lines (51 loc) · 1.59 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
cmake_minimum_required(VERSION 3.20)
project(CUDANet
LANGUAGES CXX CUDA
)
find_package(CUDAToolkit QUIET)
# Set USE_CUDA option based on whether CUDA was found
if(CUDAToolkit_FOUND)
option(USE_CUDA "Use CUDA implementation" ON)
else()
option(USE_CUDA "Use CUDA implementation" OFF)
endif()
if(USE_CUDA)
enable_language(CUDA)
add_definitions(-DUSE_CUDA)
message(STATUS "Building library with CUDA support")
else()
message(STATUS "CUDA not found or disabled. Defaulting to CPU implementation.")
endif()
file(GLOB_RECURSE CPU_SOURCES
src/layers/*.cpp
src/model/*.cpp
)
set(LIBRARY_SOURCES ${CPU_SOURCES})
if(USE_CUDA)
file(GLOB_RECURSE CUDA_SOURCES
src/backends/cuda/*.cu
src/backends/cuda/utils/*.cu
src/backends/cuda/kernels/*.cu
src/backends/cuda/layers/*.cu
src/layers/*.cu # To be removed
)
set(LIBRARY_SOURCES ${LIBRARY_SOURCES} ${CUDA_SOURCES})
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Build static library
add_library(${PROJECT_NAME} STATIC ${LIBRARY_SOURCES})
if(USE_CUDA)
target_link_libraries(${PROJECT_NAME} CUDA::cudart)
endif()
# Set include directories for the library
target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/utils
${CMAKE_CURRENT_SOURCE_DIR}/include/kernels
${CMAKE_CURRENT_SOURCE_DIR}/include/layers
${CMAKE_CURRENT_SOURCE_DIR}/include/model
${CMAKE_CURRENT_SOURCE_DIR}/src
)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20)
# Add testing subdirectory
add_subdirectory(test)