-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathCMakeLists.txt
106 lines (81 loc) · 3.8 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
cmake_minimum_required(VERSION 3.18)
project(ScudaProject LANGUAGES CXX CUDA)
set(MIN_CUDA_VERSION 12.0)
set(MAX_CUDA_VERSION 12.7)
find_package(CUDAToolkit REQUIRED)
if (NOT CUDAToolkit_VERSION)
message(FATAL_ERROR "CUDA Toolkit is required but not found.")
endif()
if (CUDAToolkit_VERSION VERSION_LESS MIN_CUDA_VERSION OR CUDAToolkit_VERSION VERSION_GREATER MAX_CUDA_VERSION)
message(FATAL_ERROR "CUDA Toolkit version must be >= ${MIN_CUDA_VERSION} and <= ${MAX_CUDA_VERSION}. Found: ${CUDAToolkit_VERSION}")
endif()
message(STATUS "Found CUDA Toolkit version: ${CUDAToolkit_VERSION}")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_EXTENSIONS OFF)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/codegen
${CUDAToolkit_INCLUDE_DIRS}
)
set(CLIENT_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/client.cpp
${CMAKE_CURRENT_SOURCE_DIR}/codegen/gen_client.cpp
${CMAKE_CURRENT_SOURCE_DIR}/codegen/manual_client.cpp
)
set(SERVER_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/server.cu
${CMAKE_CURRENT_SOURCE_DIR}/codegen/gen_server.cpp
${CMAKE_CURRENT_SOURCE_DIR}/codegen/manual_server.cpp
)
set(CLIENT_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/codegen/gen_client.h
${CMAKE_CURRENT_SOURCE_DIR}/codegen/manual_client.h
)
set(SERVER_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/codegen/gen_server.h
${CMAKE_CURRENT_SOURCE_DIR}/codegen/manual_server.h
)
set(CLIENT_OUTPUT scuda_${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR})
set(SERVER_OUTPUT server_${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}.so)
find_library(CUBLAS_LIBRARY cublas HINTS ${CUDAToolkit_LIBRARY_DIR} PATHS /usr/local/cuda/lib64)
find_library(CUDNN_LIBRARY cudnn HINTS ${CUDAToolkit_LIBRARY_DIR} PATHS /usr/local/cuda/lib64)
find_library(CUDART_LIBRARY cudart HINTS ${CUDAToolkit_LIBRARY_DIR} PATHS /usr/local/cuda/lib64)
find_library(NVML_LIBRARY nvidia-ml HINTS ${CUDAToolkit_LIBRARY_DIR} PATHS /usr/local/cuda/lib64)
if (NOT CUBLAS_LIBRARY)
message(FATAL_ERROR "cuBLAS library not found. Ensure CUDA is installed and the library path is correct.")
endif()
if (NOT CUDNN_LIBRARY)
message(FATAL_ERROR "cuDNN library not found. Ensure CUDA is installed and the library path is correct.")
endif()
if (NOT CUDART_LIBRARY)
message(FATAL_ERROR "CUDA Runtime library (libcudart.so) not found. Ensure CUDA is installed and the library path is correct.")
endif()
if (NOT NVML_LIBRARY)
message(FATAL_ERROR "NVML library not found. Ensure CUDA is installed and the library path is correct.")
endif()
add_library(${CLIENT_OUTPUT} SHARED ${CLIENT_SOURCES} ${CLIENT_HEADERS})
target_include_directories(${CLIENT_OUTPUT} PRIVATE ${CUDAToolkit_INCLUDE_DIRS})
target_link_libraries(${CLIENT_OUTPUT} PRIVATE ${CUDART_LIBRARY} ${CUBLAS_LIBRARY} stdc++)
set_target_properties(${CLIENT_OUTPUT} PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_executable(${SERVER_OUTPUT} ${SERVER_SOURCES} ${SERVER_HEADERS})
target_include_directories(${SERVER_OUTPUT} PRIVATE ${CUDAToolkit_INCLUDE_DIRS})
target_link_libraries(${SERVER_OUTPUT} PRIVATE ${CUDAToolkit_LIBRARIES} cuda)
target_link_libraries(${SERVER_OUTPUT} PRIVATE ${CUDART_LIBRARY} ${CUBLAS_LIBRARY} ${CUDNN_LIBRARY} ${NVML_LIBRARY})
set_source_files_properties(
${SERVER_SOURCES}
PROPERTIES LANGUAGE CUDA
)
target_compile_options(${SERVER_OUTPUT} PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>: --compiler-options=-fPIC,-g,-Wno-deprecated-declarations>
)
target_compile_options(${CLIENT_OUTPUT} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>: -Wno-deprecated-declarations>
)
message(STATUS "Building client output: ${CLIENT_OUTPUT}")
message(STATUS "Building server output: ${SERVER_OUTPUT}")