forked from pytorch/FBGEMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
304 lines (252 loc) · 10.4 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
cmake_minimum_required(VERSION 3.11.0 FATAL_ERROR)
option(FBGEMM_CPU_ONLY "Build fbgemm_gpu without GPU support" OFF)
set(message_line
"-------------------------------------------------------------")
message("${message_line}")
if(SKBUILD)
message("The project is built using scikit-build")
endif()
if(FBGEMM_CPU_ONLY)
message("Building for CPU-only")
endif()
message("${message_line}")
if(FBGEMM_CPU_ONLY)
project(
fbgemm_gpu
VERSION 0.0.1
LANGUAGES CXX C)
else()
project(
fbgemm_gpu
VERSION 0.0.1
LANGUAGES CXX C CUDA)
endif()
find_package(Torch REQUIRED)
find_package(PythonExtensions REQUIRED)
set(FBGEMM ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(THIRDPARTY ${FBGEMM}/third_party)
#
# Toch Cuda Extensions are normally compiled with the flags below. However we
# disabled -D__CUDA_NO_HALF_CONVERSIONS__ here as it caused "error: no suitable
# constructor exists to convert from "int" to "__half" errors in
# gen_embedding_forward_quantized_split_[un]weighted_codegen_cuda.cu
#
set(TORCH_CUDA_OPTIONS
--expt-relaxed-constexpr
-D__CUDA_NO_HALF_OPERATORS__
# -D__CUDA_NO_HALF_CONVERSIONS__
-D__CUDA_NO_BFLOAT16_CONVERSIONS__
-D__CUDA_NO_HALF2_OPERATORS__)
#
# GENERATED CUDA, CPP and Python code
#
set(OPTIMIZERS
adagrad
adam
approx_rowwise_adagrad
approx_sgd
lamb
lars_sgd
partial_rowwise_adam
partial_rowwise_lamb
rowwise_adagrad
rowwise_weighted_adagrad
sgd)
set(gen_gpu_source_files
"gen_embedding_forward_dense_weighted_codegen_cuda.cu"
"gen_embedding_forward_dense_unweighted_codegen_cuda.cu"
"gen_embedding_forward_quantized_split_unweighted_codegen_cuda.cu"
"gen_embedding_forward_quantized_split_weighted_codegen_cuda.cu"
"gen_embedding_forward_split_weighted_codegen_cuda.cu"
"gen_embedding_forward_split_unweighted_codegen_cuda.cu"
"gen_embedding_backward_split_indice_weights_codegen_cuda.cu"
"gen_embedding_backward_dense_indice_weights_codegen_cuda.cu"
"gen_embedding_backward_dense_split_unweighted_cuda.cu"
"gen_embedding_backward_dense_split_weighted_cuda.cu")
set(gen_cpu_source_files
"gen_embedding_forward_quantized_unweighted_codegen_cpu.cpp"
"gen_embedding_forward_quantized_weighted_codegen_cpu.cpp"
"gen_embedding_backward_dense_split_cpu.cpp")
set(gen_python_files ${CMAKE_BINARY_DIR}/__init__.py)
foreach(optimizer ${OPTIMIZERS})
list(APPEND gen_gpu_host_source_files
"gen_embedding_backward_split_${optimizer}.cpp")
list(APPEND gen_cpu_source_files
"gen_embedding_backward_split_${optimizer}_cpu.cpp")
list(APPEND gen_cpu_source_files
"gen_embedding_backward_${optimizer}_split_cpu.cpp")
list(APPEND gen_python_files "${CMAKE_BINARY_DIR}/lookup_${optimizer}.py")
foreach(weight weighted unweighted)
list(APPEND gen_gpu_source_files
"gen_embedding_backward_${optimizer}_split_${weight}_cuda.cu")
endforeach()
endforeach()
set(CMAKE_CODEGEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/codegen)
set(codegen_dependencies
${CMAKE_CODEGEN_DIR}/embedding_backward_code_generator.py
${CMAKE_CODEGEN_DIR}/embedding_backward_dense_host.cpp
${CMAKE_CODEGEN_DIR}/embedding_backward_dense_host_cpu.cpp
${CMAKE_CODEGEN_DIR}/embedding_backward_split_cpu_approx_template.cpp
${CMAKE_CODEGEN_DIR}/embedding_backward_split_cpu_template.cpp
${CMAKE_CODEGEN_DIR}/embedding_backward_split_host_cpu_template.cpp
${CMAKE_CODEGEN_DIR}/embedding_backward_split_host_template.cpp
${CMAKE_CODEGEN_DIR}/embedding_backward_split_indice_weights_template.cu
${CMAKE_CODEGEN_DIR}/embedding_backward_split_template.cu
${CMAKE_CODEGEN_DIR}/embedding_forward_quantized_cpu_template.cpp
${CMAKE_CODEGEN_DIR}/embedding_forward_quantized_host.cpp
${CMAKE_CODEGEN_DIR}/embedding_forward_quantized_host_cpu.cpp
${CMAKE_CODEGEN_DIR}/embedding_forward_quantized_split_template.cu
${CMAKE_CODEGEN_DIR}/embedding_forward_split_cpu.cpp
${CMAKE_CODEGEN_DIR}/embedding_forward_split_cpu.h
${CMAKE_CODEGEN_DIR}/embedding_forward_split_template.cu
${CMAKE_CODEGEN_DIR}/embedding_forward_template_helpers.cuh
${CMAKE_CODEGEN_DIR}/__init__.template
${CMAKE_CODEGEN_DIR}/lookup_args.py
${CMAKE_CODEGEN_DIR}/split_embedding_codegen_lookup_invoker.template
${CMAKE_CURRENT_SOURCE_DIR}/include/fbgemm_gpu/cpu_utils.h
${CMAKE_CURRENT_SOURCE_DIR}/include/fbgemm_gpu/cub_namespace_postfix.cuh
${CMAKE_CURRENT_SOURCE_DIR}/include/fbgemm_gpu/dispatch_macros.h
${CMAKE_CURRENT_SOURCE_DIR}/include/fbgemm_gpu/embedding_backward_template_helpers.cuh
${CMAKE_CURRENT_SOURCE_DIR}/include/fbgemm_gpu/embedding_common.h
${CMAKE_CURRENT_SOURCE_DIR}/include/fbgemm_gpu/fbgemm_cuda_utils.cuh
${CMAKE_CURRENT_SOURCE_DIR}/include/fbgemm_gpu/quantize_ops_gpu.h
${CMAKE_CURRENT_SOURCE_DIR}/include/fbgemm_gpu/quantize_ops_utils.h
${CMAKE_CURRENT_SOURCE_DIR}/include/fbgemm_gpu/split_embeddings_utils.cuh
${CMAKE_CURRENT_SOURCE_DIR}/include/fbgemm_gpu/sparse_ops_utils.h
)
add_custom_command(
OUTPUT ${gen_cpu_source_files} ${gen_gpu_source_files}
${gen_gpu_host_source_files} ${gen_python_files}
COMMAND
"${PYTHON_EXECUTABLE}"
"${CMAKE_CODEGEN_DIR}/embedding_backward_code_generator.py"
"--opensource"
DEPENDS "${codegen_dependencies}")
set_source_files_properties(
${gen_cpu_source_files} PROPERTIES COMPILE_OPTIONS
"-mavx2;-mf16c;-mfma;-fopenmp")
set_source_files_properties(
${gen_cpu_source_files}
PROPERTIES
INCLUDE_DIRECTORIES
"${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_SOURCE_DIR}/../include"
)
set_source_files_properties(
${gen_gpu_host_source_files}
PROPERTIES
INCLUDE_DIRECTORIES
"${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_SOURCE_DIR}/../include"
)
set_source_files_properties(
${gen_gpu_source_files}
PROPERTIES INCLUDE_DIRECTORIES
"${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/include")
set_source_files_properties(${gen_gpu_source_files}
PROPERTIES COMPILE_OPTIONS "${TORCH_CUDA_OPTIONS}")
if(NOT FBGEMM_CPU_ONLY)
set(gen_source_files ${gen_gpu_source_files}
${gen_gpu_host_source_files} ${gen_cpu_source_files})
else()
set(gen_source_files ${gen_cpu_source_files})
endif()
#
# CPP FBGEMM support
#
file(GLOB_RECURSE cpp_asmjit_files
"${CMAKE_CURRENT_SOURCE_DIR}/../third_party/asmjit/src/asmjit/*/*.cpp")
set(cpp_fbgemm_files_normal
"../src/EmbeddingSpMDM.cc"
"../src/EmbeddingSpMDMNBit.cc"
"../src/QuantUtils.cc"
"../src/RefImplementations.cc"
"../src/RowWiseSparseAdagradFused.cc"
"../src/SparseAdagrad.cc"
"../src/Utils.cc")
set(cpp_fbgemm_files_avx2 "../src/EmbeddingSpMDMAvx2.cc"
"../src/QuantUtilsAvx2.cc")
set_source_files_properties(${cpp_fbgemm_files_avx2}
PROPERTIES COMPILE_OPTIONS "-mavx2;-mf16c;-mfma")
set(cpp_fbgemm_files_avx512 "../src/EmbeddingSpMDMAvx512.cc")
set_source_files_properties(
${cpp_fbgemm_files_avx512}
PROPERTIES COMPILE_OPTIONS
"-mavx2;-mf16c;-mfma;-mavx512f;-mavx512bw;-mavx512dq;-mavx512vl")
set(cpp_fbgemm_files ${cpp_fbgemm_files_normal} ${cpp_fbgemm_files_avx2}
${cpp_fbgemm_files_avx512})
set(cpp_fbgemm_files_include_directories
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include
${FBGEMM}/include ${THIRDPARTY}/asmjit/src ${THIRDPARTY}/cpuinfo/include)
set_source_files_properties(
${cpp_fbgemm_files} PROPERTIES INCLUDE_DIRECTORIES
"${cpp_fbgemm_files_include_directories}")
#
# Actual static SOURCES
#
set(fbgemm_gpu_sources_cpu
codegen/embedding_forward_split_cpu.cpp
codegen/embedding_forward_quantized_host_cpu.cpp
codegen/embedding_backward_dense_host_cpu.cpp
codegen/embedding_bounds_check_host_cpu.cpp
src/cpu_utils.cpp
src/jagged_tensor_ops_cpu.cpp
src/input_combine_cpu.cpp
src/layout_transform_ops_cpu.cpp
src/permute_pooled_embedding_ops_cpu.cpp
src/quantize_ops_cpu.cpp
src/sparse_ops_cpu.cpp)
if(NOT FBGEMM_CPU_ONLY)
list(APPEND fbgemm_gpu_sources_cpu
codegen/embedding_forward_quantized_host.cpp
codegen/embedding_backward_dense_host.cpp
codegen/embedding_bounds_check_host.cpp
src/cumem_utils_host.cpp
src/layout_transform_ops_gpu.cpp
# src/merge_pooled_embeddings_cpu.cpp src/merge_pooled_embeddings_gpu.cpp
src/permute_pooled_embedding_ops_gpu.cpp
src/quantize_ops_gpu.cpp
src/sparse_ops_gpu.cpp
src/split_table_batched_embeddings.cpp)
endif()
set_source_files_properties(
${fbgemm_gpu_sources_cpu} PROPERTIES COMPILE_OPTIONS
"-mavx;-mf16c;-mfma;-mavx2;-fopenmp")
if(NOT FBGEMM_CPU_ONLY)
set(fbgemm_gpu_sources_gpu
codegen/embedding_bounds_check.cu src/cumem_utils.cu
src/histogram_binning_calibration_ops.cu src/jagged_tensor_ops.cu
src/layout_transform_ops.cu src/permute_pooled_embedding_ops.cu
src/quantize_ops.cu src/sparse_ops.cu src/split_embeddings_cache_cuda.cu
src/split_embeddings_utils.cu)
set_source_files_properties(${fbgemm_gpu_sources_gpu}
PROPERTIES COMPILE_OPTIONS "${TORCH_CUDA_OPTIONS}")
# XXXUPS!!! Replace with real
set_source_files_properties(
${fbgemm_gpu_sources_gpu}
PROPERTIES INCLUDE_DIRECTORIES "${cpp_fbgemm_files_include_directories}")
endif()
set_source_files_properties(
${fbgemm_gpu_sources_cpu}
PROPERTIES INCLUDE_DIRECTORIES "${cpp_fbgemm_files_include_directories}")
if(NOT FBGEMM_CPU_ONLY)
set(fbgemm_gpu_sources ${fbgemm_gpu_sources_gpu} ${fbgemm_gpu_sources_cpu})
else()
set(fbgemm_gpu_sources ${fbgemm_gpu_sources_cpu})
endif()
#
# MODULE
#
add_library(fbgemm_gpu_py MODULE ${fbgemm_gpu_sources} ${gen_source_files}
${cpp_asmjit_files} ${cpp_fbgemm_files})
if(NOT FBGEMM_CPU_ONLY)
target_compile_definitions(fbgemm_gpu_py PRIVATE FBGEMM_CUB_USE_NAMESPACE)
endif()
set_target_properties(fbgemm_gpu_py PROPERTIES PREFIX "")
target_link_libraries(fbgemm_gpu_py ${TORCH_LIBRARIES})
target_include_directories(fbgemm_gpu_py PRIVATE ${TORCH_INCLUDE_DIRS})
set_property(TARGET fbgemm_gpu_py PROPERTY CXX_STANDARD 17)
install(TARGETS fbgemm_gpu_py DESTINATION fbgemm_gpu)
# Python
install(FILES ${gen_python_files}
DESTINATION fbgemm_gpu/split_embedding_codegen_lookup_invokers)
install(FILES ${CMAKE_CODEGEN_DIR}/lookup_args.py
DESTINATION fbgemm_gpu/split_embedding_codegen_lookup_invokers)