Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
171 lines (146 loc) · 4.97 KB
/
Copy pathCMakeLists.txt
File metadata and controls
171 lines (146 loc) · 4.97 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
cmake_minimum_required(VERSION 3.16)
project(
tgn
VERSION 0.1.0
DESCRIPTION "C++ Port of Temporal Graph Networks for Deep Learning on Dynamic Graphs"
LANGUAGES CXX
)
option(TGN_BUILD_TESTS "Build test binaries" OFF)
option(TGN_BUILD_EXAMPLES "Build example binaries" OFF)
option(TGN_BUILD_PYTHON "Build Python Bindings" OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(
-Wall
-Wextra
-Wpedantic
-Wshadow # Catches local variables hiding class members
-Wnon-virtual-dtor # Ensures proper cleanup of polymorphic classes
-Wold-style-cast # Encourages static_cast over C-style casts
-Woverloaded-virtual # Warns if you accidentally hide virtual functions
-Wnull-dereference # Warns if a null dereference is detected
)
include(FetchContent)
set(CUDA_VERSION "cpu" CACHE STRING "CUDA version (cpu, 12.6, 12.8, 13.0)")
if(APPLE) # Target Apple Silicon (M1/M2/M3)
set(LIBTORCH_URL "https://download.pytorch.org/libtorch/cpu/libtorch-macos-arm64-2.10.0.zip")
message(STATUS "TGUF: Target System is APPLE (ARM64). Using CPU LibTorch.")
else() # Target Linux x86_64
if(CUDA_VERSION STREQUAL "cpu")
set(LIBTORCH_URL "https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-2.10.0%2Bcpu.zip")
message(STATUS "TGUF: Target System is LINUX (CPU).")
else()
# Clean "12.6" -> "126" for the URL mapping
string(REPLACE "." "" CUDA_TAG ${CUDA_VERSION})
set(LIBTORCH_URL "https://download.pytorch.org/libtorch/cu${CUDA_TAG}/libtorch-shared-with-deps-2.10.0%2Bcu${CUDA_TAG}.zip")
message(STATUS "TGUF: Target System is LINUX (CUDA ${CUDA_VERSION}).")
enable_language(CUDA)
add_compile_definitions(TGN_WITH_CUDA)
endif()
endif()
message(STATUS "Downloading Libtorch (${LIBTORCH_URL})")
FetchContent_Declare(
libtorch
URL ${LIBTORCH_URL}
DOWNLOAD_EXTRACT_TIMESTAMP ON
)
FetchContent_MakeAvailable(libtorch)
message(STATUS "Downloading Libtorch (${LIBTORCH_URL}) - done")
set(CMAKE_PREFIX_PATH ${libtorch_SOURCE_DIR})
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
if(APPLE)
set(OpenMP_ROOT "/opt/homebrew/opt/libomp")
endif()
find_package(OpenMP REQUIRED)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Debug build: Enabling Address and UndefinedBehavior Sanitizers")
add_compile_options(-fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer)
add_link_options(-fsanitize=address -fsanitize=undefined)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "Release build: Enabling some Compiler Optimizations")
add_compile_options(-O3 -march=native -ffast-math -pthread)
endif()
# TGUF Target
add_library(tguf
SHARED
src/tguf/store.cpp
src/tguf/tguf.cpp
)
target_link_libraries(tguf
PUBLIC
"${TORCH_LIBRARIES}"
OpenMP::OpenMP_CXX
)
target_include_directories(tguf
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
set_target_properties(tguf PROPERTIES COMPILE_FLAGS "${TORCH_CXX_FLAGS}")
# TGUF-Models Target
add_library(tguf_models
SHARED
src/tguf_models/common/sampler.cpp
src/tguf_models/common/scatter_ops.cpp
src/tguf_models/tgn.cpp
)
target_link_libraries(tguf_models
PUBLIC
tguf
)
target_include_directories(tguf_models
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
set_target_properties(tguf_models PROPERTIES COMPILE_FLAGS "${TORCH_CXX_FLAGS}")
if (TGN_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if (TGN_BUILD_PYTHON)
add_subdirectory(python)
endif()
if (TGN_BUILD_TESTS)
enable_testing()
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.17.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# TGUF unit tests
add_executable(test_tguf
test/unit/tguf/test_store.cpp
test/unit/tguf/test_tguf.cpp
)
target_link_libraries(test_tguf PRIVATE
tguf
"${TORCH_LIBRARIES}"
GTest::gtest_main
)
target_include_directories(test_tguf PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# TGUF-Model unit tests
add_executable(test_tguf_models
test/unit/tguf_models/test_recency_sampler.cpp
test/unit/tguf_models/test_scatter_ops.cpp
test/unit/tguf_models/test_tgn.cpp
)
target_link_libraries(test_tguf_models PRIVATE
tguf_models
"${TORCH_LIBRARIES}"
GTest::gtest_main
)
target_include_directories(test_tguf_models PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
include(GoogleTest)
gtest_discover_tests(test_tguf PROPERTIES LABELS "tguf")
gtest_discover_tests(test_tguf_models PROPERTIES LABELS "models")
endif()