-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
291 lines (259 loc) · 14.9 KB
/
CMakeLists.txt
File metadata and controls
291 lines (259 loc) · 14.9 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
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
cmake_minimum_required(VERSION 3.10)
project(PyC C)
if(POLICY CMP0104)
cmake_policy(SET CMP0104 NEW)
endif()
option(PYC_BUILD_BENCHMARKS "Build benchmark targets" OFF)
option(PYC_BUILD_COMPILER_NEXT "Build next-generation compiler stack (experimental)" ON)
option(PYC_BUILD_COMPILER_NEXT_TESTS "Build next-generation compiler smoke tests" ON)
option(PYC_ENABLE_CUDA_RUNTIME "Enable CUDA runtime backend when CUDA toolkit is available" ON)
option(PYC_BUILD_EXPERIMENTAL "Compatibility no-op for legacy configure flows" OFF)
option(PYC_BUILD_DISTRIBUTED_SCAFFOLD "Build distributed communication scaffold (loader + stub backend)" OFF)
set(PYC_CUTLASS_PATH "" CACHE PATH "Path to CUTLASS headers root containing cutlass/cutlass.h")
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES OR CMAKE_CUDA_ARCHITECTURES STREQUAL "")
set(CMAKE_CUDA_ARCHITECTURES "80;86;89;90" CACHE STRING "CUDA architectures for PyC" FORCE)
endif()
set(SRC_DIR "${CMAKE_SOURCE_DIR}/src/core/C_Files")
set(HEADER_DIR "${CMAKE_SOURCE_DIR}/src/core/Header_Files")
set(PYC_CORE_SOURCES
"${SRC_DIR}/adapter.c"
"${SRC_DIR}/semantic.c"
"${SRC_DIR}/stack.c"
"${SRC_DIR}/symbol_table.c"
)
add_library(pyc_core_obj OBJECT ${PYC_CORE_SOURCES})
target_include_directories(pyc_core_obj PUBLIC "${HEADER_DIR}")
target_compile_features(pyc_core_obj PUBLIC c_std_11)
add_library(pyc_core STATIC $<TARGET_OBJECTS:pyc_core_obj>)
target_include_directories(pyc_core PUBLIC "${HEADER_DIR}")
target_compile_features(pyc_core PUBLIC c_std_11)
# Compatibility target kept for downstream consumers that still reference pyc_foundation.
add_library(pyc_foundation STATIC $<TARGET_OBJECTS:pyc_core_obj>)
target_include_directories(pyc_foundation PUBLIC "${HEADER_DIR}")
target_compile_features(pyc_foundation PUBLIC c_std_11)
add_executable(pyc "${SRC_DIR}/ci_main.c")
target_link_libraries(pyc PRIVATE pyc_core)
if(PYC_BUILD_BENCHMARKS)
add_executable(pyc_core_microbench
"${CMAKE_SOURCE_DIR}/benchmark/workloads/core_microbench.c"
)
target_include_directories(pyc_core_microbench PRIVATE "${HEADER_DIR}")
target_compile_features(pyc_core_microbench PRIVATE c_std_11)
target_link_libraries(pyc_core_microbench PRIVATE pyc_core)
endif()
if(PYC_BUILD_COMPILER_NEXT)
set(PYC_COMPILER_NEXT_SOURCES
"${CMAKE_SOURCE_DIR}/src/compiler/compiler_api.c"
"${CMAKE_SOURCE_DIR}/src/compiler/ir/ir.c"
"${CMAKE_SOURCE_DIR}/src/compiler/passes/pass_manager.c"
"${CMAKE_SOURCE_DIR}/src/compiler/runtime/runtime_allocator.c"
"${CMAKE_SOURCE_DIR}/src/compiler/runtime/kernel_registry.c"
"${CMAKE_SOURCE_DIR}/src/compiler/runtime/runtime_control.c"
"${CMAKE_SOURCE_DIR}/src/compiler/runtime/cuda_backend.c"
"${CMAKE_SOURCE_DIR}/src/compiler/runtime/comm_backend_loader.c"
"${CMAKE_SOURCE_DIR}/src/compiler/runtime/distributed_runtime.c"
)
add_library(pyc_compiler_next STATIC ${PYC_COMPILER_NEXT_SOURCES})
target_include_directories(pyc_compiler_next
PUBLIC
"${CMAKE_SOURCE_DIR}/include"
)
target_compile_features(pyc_compiler_next PUBLIC c_std_11)
if(MSVC)
target_compile_options(pyc_compiler_next PRIVATE /O2)
else()
target_compile_options(pyc_compiler_next PRIVATE -O3)
endif()
find_package(Threads)
if(Threads_FOUND)
target_link_libraries(pyc_compiler_next PUBLIC Threads::Threads)
endif()
find_package(OpenMP COMPONENTS C)
if(OpenMP_C_FOUND)
target_link_libraries(pyc_compiler_next PUBLIC OpenMP::OpenMP_C)
endif()
if(NOT WIN32)
target_link_libraries(pyc_compiler_next PRIVATE ${CMAKE_DL_LIBS})
endif()
if(PYC_ENABLE_CUDA_RUNTIME)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17")
find_package(CUDAToolkit QUIET)
if(CUDAToolkit_FOUND)
target_compile_definitions(pyc_compiler_next PUBLIC PYC_HAVE_CUDA_RUNTIME=1)
target_link_libraries(pyc_compiler_next PUBLIC CUDA::cudart CUDA::cublas)
if(TARGET CUDA::cublasLt)
target_link_libraries(pyc_compiler_next PUBLIC CUDA::cublasLt)
message(STATUS "PyC: CUDA runtime backend enabled (cudart + cublas + cublasLt)")
else()
message(STATUS "PyC: CUDA runtime backend enabled (cudart + cublas)")
endif()
set(PYC_CUTLASS_PATH_CANDIDATE "${PYC_CUTLASS_PATH}")
if(NOT PYC_CUTLASS_PATH_CANDIDATE AND DEFINED ENV{CUTLASS_PATH})
set(PYC_CUTLASS_PATH_CANDIDATE "$ENV{CUTLASS_PATH}")
endif()
include(CheckLanguage)
check_language(CXX)
check_language(CUDA)
if(CMAKE_CXX_COMPILER AND CMAKE_CUDA_COMPILER)
enable_language(CXX)
enable_language(CUDA)
if(PYC_CUTLASS_PATH_CANDIDATE AND EXISTS "${PYC_CUTLASS_PATH_CANDIDATE}/cutlass/cutlass.h")
set(PYC_CUTLASS_PATH "${PYC_CUTLASS_PATH_CANDIDATE}" CACHE PATH "Path to CUTLASS headers root containing cutlass/cutlass.h" FORCE)
set(PYC_CUTLASS_FULL_ENABLED ON)
message(STATUS "PyC: CUTLASS kernel library enabled from ${PYC_CUTLASS_PATH}")
else()
set(PYC_CUTLASS_FULL_ENABLED OFF)
message(STATUS "PyC: CUTLASS headers not configured; building minimal promoted CUDA kernel registry")
endif()
add_subdirectory("${CMAKE_SOURCE_DIR}/src/compiler/cutlass_kernels" "${CMAKE_BINARY_DIR}/src/compiler/cutlass_kernels")
target_compile_definitions(pyc_compiler_next PUBLIC PYC_HAVE_CUTLASS_KERNELS=1)
target_link_libraries(pyc_compiler_next PUBLIC pyc_cutlass_kernels)
else()
message(STATUS "PyC: CXX/CUDA language support unavailable; building without promoted CUDA kernels")
endif()
else()
message(STATUS "PyC: CUDA toolkit not found, building fallback-only CUDA dispatcher")
endif()
else()
message(STATUS "PyC: CMake < 3.17, skipping CUDA toolkit auto-detection")
endif()
endif()
if(PYC_BUILD_BENCHMARKS)
add_executable(pyc_compiler_next_bench
"${CMAKE_SOURCE_DIR}/benchmark/benchmarks/gpu/workloads/pyc_compiler_next_bench.c"
)
target_include_directories(pyc_compiler_next_bench PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_link_libraries(pyc_compiler_next_bench PRIVATE pyc_compiler_next)
target_compile_features(pyc_compiler_next_bench PRIVATE c_std_11)
if(MSVC)
target_compile_options(pyc_compiler_next_bench PRIVATE /O2)
else()
target_compile_options(pyc_compiler_next_bench PRIVATE -O3)
endif()
if(PYC_BUILD_DISTRIBUTED_SCAFFOLD)
add_executable(pyc_distributed_comm_bench
"${CMAKE_SOURCE_DIR}/benchmark/benchmarks/distributed/workloads/pyc_distributed_comm_bench.c"
)
target_include_directories(pyc_distributed_comm_bench PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_link_libraries(pyc_distributed_comm_bench PRIVATE pyc_compiler_next)
target_compile_features(pyc_distributed_comm_bench PRIVATE c_std_11)
if(MSVC)
target_compile_options(pyc_distributed_comm_bench PRIVATE /O2)
else()
target_compile_options(pyc_distributed_comm_bench PRIVATE -O3)
endif()
endif()
endif()
add_library(pyc_ai_bridge STATIC "${CMAKE_SOURCE_DIR}/src/compiler/ai/ai_bridge.c")
target_include_directories(pyc_ai_bridge PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_link_libraries(pyc_ai_bridge PUBLIC pyc_compiler_next)
target_compile_features(pyc_ai_bridge PUBLIC c_std_11)
if(PYC_BUILD_DISTRIBUTED_SCAFFOLD)
add_library(pyc_comm_backend_stub SHARED
"${CMAKE_SOURCE_DIR}/src/compiler/runtime/comm_backend_stub.c"
)
target_include_directories(pyc_comm_backend_stub PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_compile_features(pyc_comm_backend_stub PUBLIC c_std_11)
add_library(pyc_comm_backend_nccl SHARED
"${CMAKE_SOURCE_DIR}/src/compiler/runtime/comm_backend_nccl.c"
)
target_include_directories(pyc_comm_backend_nccl PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_compile_features(pyc_comm_backend_nccl PUBLIC c_std_11)
add_library(pyc_comm_backend_rccl SHARED
"${CMAKE_SOURCE_DIR}/src/compiler/runtime/comm_backend_rccl.c"
)
target_include_directories(pyc_comm_backend_rccl PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_compile_features(pyc_comm_backend_rccl PUBLIC c_std_11)
add_library(pyc_comm_backend_mpi SHARED
"${CMAKE_SOURCE_DIR}/src/compiler/runtime/comm_backend_mpi.c"
)
target_include_directories(pyc_comm_backend_mpi PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_compile_features(pyc_comm_backend_mpi PUBLIC c_std_11)
endif()
if(PYC_BUILD_COMPILER_NEXT_TESTS)
set(PYC_COMPILER_NEXT_TEST_TARGETS "")
macro(pyc_add_compiler_next_test test_name source_file)
add_executable(${test_name} "${source_file}")
target_include_directories(${test_name} PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_link_libraries(${test_name} PRIVATE pyc_compiler_next)
target_compile_features(${test_name} PRIVATE c_std_11)
file(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}" PYC_SOURCE_DIR_NORMALIZED)
target_compile_definitions(${test_name} PRIVATE PYC_SOURCE_DIR="${PYC_SOURCE_DIR_NORMALIZED}")
add_test(NAME ${test_name} COMMAND ${test_name})
list(APPEND PYC_COMPILER_NEXT_TEST_TARGETS ${test_name})
endmacro()
enable_testing()
add_executable(pyc_compiler_next_smoke
"${CMAKE_SOURCE_DIR}/tests/compiler_next/compiler_next_smoke.c"
)
target_include_directories(pyc_compiler_next_smoke PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_link_libraries(pyc_compiler_next_smoke PRIVATE pyc_compiler_next)
target_compile_features(pyc_compiler_next_smoke PRIVATE c_std_11)
add_test(NAME pyc_compiler_next_smoke_test COMMAND pyc_compiler_next_smoke)
list(APPEND PYC_COMPILER_NEXT_TEST_TARGETS pyc_compiler_next_smoke)
pyc_add_compiler_next_test(pyc_compiler_next_test_ir "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_ir.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_pass_manager "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_pass_manager.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_runtime_allocator "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_runtime_allocator.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_kernel_registry "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_kernel_registry.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_compiler_api "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_compiler_api.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_determinism "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_determinism.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_pass_golden "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_pass_golden.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_policy_modes "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_policy_modes.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_runtime_control "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_runtime_control.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_cpu_execution "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_cpu_execution.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_cuda_backend "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_cuda_backend.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_deterministic_contracts "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_deterministic_contracts.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_compile_cache "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_compile_cache.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_graph_break_reporting "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_graph_break_reporting.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_speculative_plans "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_speculative_plans.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_autotune_persistence "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_autotune_persistence.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_autotune_compaction "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_autotune_compaction.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_prod_status_errors "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_production_status_errors.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_prod_decision_log "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_production_decision_log.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_prod_cuda_contracts "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_production_cuda_contracts.c")
pyc_add_compiler_next_test(pyc_compiler_next_test_prod_runtime_rollback "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_production_runtime_rollback.c")
add_executable(pyc_compiler_next_test_ai_bridge "${CMAKE_SOURCE_DIR}/tests/compiler_next/test_ai_bridge.c")
target_include_directories(pyc_compiler_next_test_ai_bridge PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_link_libraries(pyc_compiler_next_test_ai_bridge PRIVATE pyc_ai_bridge)
target_compile_features(pyc_compiler_next_test_ai_bridge PRIVATE c_std_11)
add_test(NAME pyc_compiler_next_test_ai_bridge COMMAND pyc_compiler_next_test_ai_bridge)
list(APPEND PYC_COMPILER_NEXT_TEST_TARGETS pyc_compiler_next_test_ai_bridge)
if(PYC_BUILD_DISTRIBUTED_SCAFFOLD)
add_library(pyc_comm_backend_invalid SHARED
"${CMAKE_SOURCE_DIR}/src/compiler/runtime/comm_backend_invalid.c"
)
target_compile_features(pyc_comm_backend_invalid PUBLIC c_std_11)
add_executable(
pyc_compiler_next_test_collective_comm_loader
"${CMAKE_SOURCE_DIR}/tests/compiler_next/test_collective_comm_loader.c"
)
target_include_directories(pyc_compiler_next_test_collective_comm_loader PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_link_libraries(pyc_compiler_next_test_collective_comm_loader PRIVATE pyc_compiler_next)
target_compile_features(pyc_compiler_next_test_collective_comm_loader PRIVATE c_std_11)
target_compile_definitions(
pyc_compiler_next_test_collective_comm_loader
PRIVATE
PYC_TEST_STUB_BACKEND_PATH="$<TARGET_FILE:pyc_comm_backend_stub>"
PYC_TEST_NCCL_BACKEND_PATH="$<TARGET_FILE:pyc_comm_backend_nccl>"
PYC_TEST_RCCL_BACKEND_PATH="$<TARGET_FILE:pyc_comm_backend_rccl>"
PYC_TEST_MPI_BACKEND_PATH="$<TARGET_FILE:pyc_comm_backend_mpi>"
PYC_TEST_INVALID_BACKEND_PATH="$<TARGET_FILE:pyc_comm_backend_invalid>"
)
add_test(
NAME pyc_compiler_next_test_collective_comm_loader
COMMAND pyc_compiler_next_test_collective_comm_loader
)
list(APPEND PYC_COMPILER_NEXT_TEST_TARGETS pyc_compiler_next_test_collective_comm_loader)
endif()
if(PYC_COMPILER_NEXT_TEST_TARGETS)
add_custom_target(pyc_compiler_next_tests DEPENDS ${PYC_COMPILER_NEXT_TEST_TARGETS})
endif()
find_package(Python3 COMPONENTS Interpreter)
if(Python3_Interpreter_FOUND)
add_test(
NAME pyc_validate_cmake_source_coverage
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/tests/validate_cmake_sources.py" "${CMAKE_SOURCE_DIR}/CMakeLists.txt" "${CMAKE_SOURCE_DIR}"
)
endif()
endif()
endif()