-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
79 lines (62 loc) · 2.93 KB
/
CMakeLists.txt
File metadata and controls
79 lines (62 loc) · 2.93 KB
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
cmake_minimum_required(VERSION 3.26)
project(mase-cuda VERSION 0.1 LANGUAGES CUDA CXX)
# print CUDA_ARCHITECTURES
message(STATUS "CUDA_ARCHITECTURES: ${CUDA_ARCHITECTURES}")
# add CUTLASS
set(CUTLASS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/submodules/cutlass" CACHE PATH "CUTLASS Repository Directory")
# cutlass/include
add_library(cutlass INTERFACE)
target_include_directories(cutlass INTERFACE "${CUTLASS_DIR}/include")
add_library(cutlass_util INTERFACE)
target_include_directories(cutlass_util INTERFACE "${CUTLASS_DIR}/tools/util/include")
add_library(cutlass_exp INTERFACE)
target_include_directories(cutlass_exp INTERFACE "${CUTLASS_DIR}/examples/common")
# python
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
include_directories("${Python3_INCLUDE_DIRS}")
# torch
# add libtorch by executing 'import torch; print(torch.utils.cmake_prefix_path)'
execute_process(
COMMAND python3 -c "import torch; print(torch.utils.cmake_prefix_path)"
OUTPUT_VARIABLE Torch_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
list(APPEND CMAKE_PREFIX_PATH "${Torch_DIR}")
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
# json
add_library(nlohmann_json INTERFACE)
target_include_directories(nlohmann_json INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/submodules/nlohmann_json/single_include")
# add mase_cuda
add_library(mase_cuda INTERFACE)
target_include_directories(mase_cuda INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src/csrc")
# a function to add a cuda test
function(add_executable_test name)
set(multiValueArgs SRC)
cmake_parse_arguments(PARSE_ARGV 1 arg "" "" ${multiValueArgs})
add_executable(${name} ${arg_SRC})
# add dependencies: cutlass, cutlass_util, cutlass_exp, python, libtorch, nlohmann_json, mase_cuda
target_link_libraries(${name} cutlass cutlass_util cutlass_exp ${Python3_LIBRARIES} ${TORCH_LIBRARIES} nlohmann_json mase_cuda)
set_property(TARGET ${name} PROPERTY CXX_STANDARD 17)
# if NVCCGDB is set, add -g -G flags
if(NVCCGDB)
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-g -G>)
endif()
endfunction()
# a function to add a cuda executable for nsight profiling
function(add_executable_nsight name)
set(multiValueArgs SRC)
cmake_parse_arguments(PARSE_ARGV 1 arg "" "" ${multiValueArgs})
add_executable(${name} ${arg_SRC})
# add dependencies: cutlass, cutlass_util, cutlass_exp, python, libtorch, nlohmann_json, mase_cuda
target_link_libraries(${name} cutlass cutlass_util cutlass_exp ${Python3_LIBRARIES} ${TORCH_LIBRARIES} nlohmann_json mase_cuda)
set_property(TARGET ${name} PROPERTY CXX_STANDARD 17)
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-lineinfo>)
endfunction()
# add tests
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/test/cu")
endif()
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_PROFILING)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/profile/cu")
endif()