-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
233 lines (199 loc) · 6.79 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
# CUDA_ARCHITECTURES native is available in CMake since 3.24
set(PROJ_NAME "cuda-pt")
project(${PROJ_NAME} LANGUAGES CUDA CXX)
message(STATUS "Using SoA3 (struct of arrays) for GPU containers.")
set(CUDA_COMMON_FLAGS --expt-relaxed-constexpr)
find_package(Threads REQUIRED)
find_package(OpenMP REQUIRED)
IF("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}" STREQUAL "debug" OR "${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
set(CMAKE_BUILD_TYPE Debug)
if (MSVC)
message(STATUS "MSVC: Building project in DEBUG mode.")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -maxrregcount=40 -lineinfo -arch=native -g -G")
set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} -G -g -lineinfo")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /g /Od /Zi /MDd")
else()
message(STATUS "GCC & G++: Building project in DEBUG mode.")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wall -G -O0 -lineinfo -maxrregcount=40 -arch=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -O0")
endif ()
set(CUDA_CONFIG_FLAGS -G)
ELSE()
# to check register usage, please set "-Xptxas -v"
# to cap the register usage to boost occupancy, set ""
set(CMAKE_BUILD_TYPE Release)
if (MSVC)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /openmp")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
set (CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler /openmp")
else()
message(FATAL_ERROR "OpenMP can not be found but it is required by wavefront path tracer. Manual overriding is required to skip this exception.")
endif()
message(STATUS "MSVC: Building project in RELEASE mode.")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -maxrregcount=40 -lineinfo -arch=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2")
else()
message(STATUS "GCC & G++: Building project in RELEASE mode.")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -O3 --maxrregcount=40 -lineinfo -arch=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${OpenMP_CXX_FLAGS}")
else()
message(FATAL_ERROR "OpenMP can not be found but it is required by wavefront path tracer. Manual overriding is required to skip this exception.")
endif()
endif ()
set(CUDA_CONFIG_FLAGS --use_fast_math -Xptxas -O3)
ENDIF()
set(CUDA_FINAL_FLAGS ${CUDA_COMMON_FLAGS} ${CUDA_CONFIG_FLAGS})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_SEPARABLE_COMPILATION ON)
include_directories(
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/src/ext/glfw/include
${CMAKE_CURRENT_LIST_DIR}/src/ext/imgui
${CMAKE_CURRENT_LIST_DIR}/src/ext/tinyxml2
${CMAKE_CURRENT_LIST_DIR}/src/ext/tinyobjloader
${CMAKE_CURRENT_LIST_DIR}/src/ext/stb
)
add_subdirectory(src/ext/tinyxml2)
add_subdirectory(src/ext/tinyobjloader)
add_subdirectory(src/ext/imgui)
add_subdirectory(src/ext/glfw)
add_subdirectory(src/ext/nanobind)
find_package(OpenGL REQUIRED)
if (MSVC)
list(APPEND CMAKE_PREFIX_PATH "E:\\glew-2.2.0\\glew")
set(GLEW_USE_STATIC_LIBS false)
find_package(GLEW REQUIRED)
else()
find_package(GLEW REQUIRED)
endif()
include_directories(
${GLEW_INCLUDE_DIRS}
)
aux_source_directory(src/impl CPT_IMPL_SRC)
aux_source_directory(src/pt_impl CPT_PT_IMPL_SRC)
aux_source_directory(src/viewer_impl CPT_VIEWER_IMPL_SRC)
set(RENDER_CORE_SRC
${CPT_IMPL_SRC}
${CPT_PT_IMPL_SRC}
)
add_library(RenderCore STATIC
${RENDER_CORE_SRC}
)
set_target_properties(RenderCore PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_ARCHITECTURES native
)
target_compile_options(RenderCore PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>:${CUDA_FINAL_FLAGS}>
)
target_link_libraries(RenderCore PRIVATE
tinyxml2
tinyobjloader
GLEW::glew
glfw
imgui
${OPENGL_gl_LIBRARY}
)
set(EXEC1_NAME "pt")
add_executable(${EXEC1_NAME}
app/pt_renderer.cu
)
target_link_libraries(
${EXEC1_NAME} PRIVATE
RenderCore
)
set_target_properties(
${EXEC1_NAME} PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_ARCHITECTURES native
)
target_compile_options(
${EXEC1_NAME} PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>:${CUDA_FINAL_FLAGS}>
)
set(EXEC2_NAME "cpt")
add_executable(${EXEC2_NAME}
app/viewer.cu
${CPT_VIEWER_IMPL_SRC}
)
target_link_libraries(
${EXEC2_NAME} PRIVATE
RenderCore
${OPENGL_LIBRARIES}
)
set_target_properties(
${EXEC2_NAME} PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_ARCHITECTURES native
)
target_compile_options(
${EXEC2_NAME} PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>:${CUDA_FINAL_FLAGS}>
)
# ============================ Python Bindings ============================
find_package(Python REQUIRED COMPONENTS Development)
find_package(CUDAToolkit REQUIRED)
if (Python_FOUND AND CUDAToolkit_FOUND)
message(STATUS "Python found: Version: ${Python_VERSION}")
message(STATUS "CUDAToolkit found: Version: ${CUDAToolkit_VERSION}")
message(STATUS "Building remote distributed rendering code and nanobind python binds...")
enable_language(CUDA)
set(NANOBIND_NDARRAY_SRC_FILES
src/ext/nanobind/src/nb_func.cpp
src/ext/nanobind/src/common.cpp
src/ext/nanobind/src/error.cpp
src/ext/nanobind/src/nb_internals.cpp
src/ext/nanobind/src/nb_type.cpp
src/ext/nanobind/src/nb_static_property.cpp
src/ext/nanobind/src/implicit.cpp
src/ext/nanobind/src/nb_ndarray.cpp
)
add_library(pyrender MODULE
src/pyrender/python_render.cu
src/pyrender/python_bind.cu
${NANOBIND_NDARRAY_SRC_FILES}
)
target_include_directories(pyrender PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/src/ext/nanobind/include
${CMAKE_CURRENT_LIST_DIR}/src/ext/nanobind/ext/robin_map/include/
${Python_INCLUDE_DIRS}
)
target_link_libraries(pyrender PRIVATE
${Python_LIBRARIES}
RenderCore
)
if (MSVC)
set(MODULE_SUFFIX ".pyd")
else()
set(MODULE_SUFFIX ".so")
endif()
set_target_properties(pyrender PROPERTIES
PREFIX ""
SUFFIX ${MODULE_SUFFIX}
CUDA_SEPARABLE_COMPILATION ON
CUDA_ARCHITECTURES native
)
target_compile_options(pyrender PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>:${CUDA_FINAL_FLAGS}>
)
else()
if (Python_FOUND)
message(WARNING "Python Package not found. Without Python Package, remote distributed rendering can not be compiled.")
else()
message(WARNING "CUDAToolkit not found. Without CUDAToolkit, remote distributed rendering can not be compiled.")
endif()
endif()
# CUDA_SEPARABLE_COMPILATION ON: member function declaration and implementation can be separate
# https://developer.nvidia.com/blog/separate-compilation-linking-cuda-device-code/
# CUDA_ARCHITECTURES native: CUDA_ARCHITECTURES is detected automatically
# https://stackoverflow.com/questions/68223398/how-can-i-get-cmake-to-automatically-detect-the-value-for-cuda-architectures