-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
105 lines (88 loc) · 3.68 KB
/
CMakeLists.txt
File metadata and controls
105 lines (88 loc) · 3.68 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
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
option(USE_CUDA "Support NVIDIA CUDA" OFF)
option(BUILD_TEST "Build tests" OFF)
option(BUILD_TESTING "third party tests" OFF)
cmake_minimum_required(VERSION 3.28)
include(CMakeDependentOption)
cmake_dependent_option(BUILD_TEST_CORE "Build tests for core components" ON BUILD_TEST OFF)
project(infini_train VERSION 0.3.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Generate compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Add gflags
add_subdirectory(third_party/gflags)
include_directories(${gflags_SOURCE_DIR}/include)
set(WITH_GFLAGS OFF CACHE BOOL "Disable glog finding system gflags" FORCE)
set(WITH_GTEST OFF CACHE BOOL "Disable glog finding system gtest" FORCE)
# Add glog
add_subdirectory(third_party/glog)
include_directories(${glog_SOURCE_DIR}/src)
# Add eigen
find_package(OpenMP REQUIRED)
add_subdirectory(third_party/eigen)
include_directories(${PROJECT_SOURCE_DIR}/third_party/eigen)
include_directories(${PROJECT_SOURCE_DIR})
file(GLOB_RECURSE SRC ${PROJECT_SOURCE_DIR}/infini_train/src/*.cc)
list(FILTER SRC EXCLUDE REGEX ".*kernels/cpu/.*")
file (GLOB_RECURSE CPU_KERNELS ${PROJECT_SOURCE_DIR}/infini_train/src/kernels/cpu/*.cc)
add_library(infini_train_cpu_kernels STATIC ${CPU_KERNELS})
target_link_libraries(infini_train_cpu_kernels glog Eigen3::Eigen OpenMP::OpenMP_CXX)
if(USE_CUDA)
add_compile_definitions(USE_CUDA=1)
enable_language(CUDA)
include(FindCUDAToolkit)
# enable CUDA-related compilation options
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-extended-lambda --expt-relaxed-constexpr")
file(GLOB_RECURSE CUDA_KERNELS ${PROJECT_SOURCE_DIR}/infini_train/src/*.cu)
add_library(infini_train_cuda_kernels STATIC ${CUDA_KERNELS})
set_target_properties(infini_train_cuda_kernels PROPERTIES CUDA_ARCHITECTURES "75;80")
target_link_libraries(infini_train_cuda_kernels glog CUDA::cudart CUDA::cublas)
add_library(infini_train STATIC ${SRC})
target_link_libraries(infini_train glog gflags "-Wl,--whole-archive" infini_train_cpu_kernels infini_train_cuda_kernels "-Wl,--no-whole-archive")
else()
add_library(infini_train STATIC ${SRC})
target_link_libraries(infini_train glog gflags "-Wl,--whole-archive" infini_train_cpu_kernels "-Wl,--no-whole-archive")
endif()
if(BUILD_TEST)
set(BUILD_GMOCK
OFF
CACHE BOOL "Do not build gmock" FORCE)
set(INSTALL_GTEST
OFF
CACHE BOOL "Do not install gtest" FORCE)
add_subdirectory(third_party/googletest)
include_directories(third_party/googletest/googletest/include)
endif()
add_library(example_gpt2 STATIC
example/common/tiny_shakespeare_dataset.cc
example/common/tokenizer.cc
example/gpt2/net.cc
)
target_link_libraries(example_gpt2 infini_train)
function(build_test files)
# Non-recursive glob for skip failed tests
file(GLOB TEST_SOURCES ${files})
foreach(testsourcefile ${TEST_SOURCES})
get_filename_component(testname ${testsourcefile} NAME_WE)
add_executable(${testname} ${testsourcefile})
target_link_libraries(${testname} infini_train example_gpt2 GTest::gtest_main)
add_test(NAME ${testname} COMMAND ${testname})
endforeach(testsourcefile ${TEST_SOURCES})
endfunction()
if(BUILD_TEST)
add_compile_definitions(BUILD_TEST=1)
enable_testing()
if(BUILD_TEST_CORE)
build_test(test/autograd/test_elementwise.cc)
build_test(test/kernels/test_matmul.cc)
build_test(test/kernels/test_dispatcher.cc)
build_test(test/tensor/test_tensor.cc)
build_test(test/optimizer/test_adam.cc)
build_test(test/example/test_gpt2.cc)
if(USE_CUDA)
build_test(test/kernels/test_matmul_cuda.cc)
build_test(test/optimizer/test_adam_cuda.cc)
endif()
endif()
endif()