Skip to content

Commit 332b0b8

Browse files
authored
【New Feature: c++ pointwise dynamic】add pointwise_prepare_args.h and cmake (flagos-ai#1919)
* add pointwise_prepare_args.h and cmake * add pointwise_prepare_args.h and cmake
1 parent 1c81b2b commit 332b0b8

3 files changed

Lines changed: 713 additions & 1 deletion

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# ==============================================================================
2+
# CMakeLists.txt for pointwise_dynamic C++ implementation
3+
# ==============================================================================
4+
5+
set(POINTWISE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
6+
7+
# Operations to generate (full module paths)
8+
set(POINTWISE_OP_FILES "flag_gems.ops.add"
9+
CACHE STRING "Comma-separated list of op module paths")
10+
11+
# Maximum tensor rank
12+
set(POINTWISE_MAX_RANK 5 CACHE STRING "Maximum tensor rank")
13+
14+
# ==============================================================================
15+
# Generate kernels at BUILD TIME (not configure time)
16+
# ==============================================================================
17+
18+
file(MAKE_DIRECTORY ${POINTWISE_OUTPUT_DIR})
19+
20+
set(PREBUILD_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/prebuild_kernels.py)
21+
22+
set(POINTWISE_MANIFEST_H ${POINTWISE_OUTPUT_DIR}/pointwise_manifest.h)
23+
set(POINTWISE_RUNTIME_H ${POINTWISE_OUTPUT_DIR}/pointwise_runtime.h)
24+
set(POINTWISE_REPORT ${POINTWISE_OUTPUT_DIR}/kernel_report.txt)
25+
26+
# Always regenerate kernels at build time.
27+
# This ensures kernel .py cache files are recreated even if the
28+
# C++ headers already exist (e.g. after clearing the code cache).
29+
add_custom_target(pointwise_generate_kernels ALL
30+
COMMAND ${Python_EXECUTABLE}
31+
${PREBUILD_SCRIPT}
32+
--op-files ${POINTWISE_OP_FILES}
33+
--max-rank ${POINTWISE_MAX_RANK}
34+
--output-dir ${POINTWISE_OUTPUT_DIR}
35+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
36+
COMMENT "Generating pointwise kernels (build-time, shared codegen)..."
37+
BYPRODUCTS
38+
${POINTWISE_MANIFEST_H}
39+
${POINTWISE_RUNTIME_H}
40+
${POINTWISE_REPORT}
41+
)
42+
43+
# ==============================================================================
44+
# Create interface library
45+
# ==============================================================================
46+
add_library(pointwise_dynamic INTERFACE)
47+
48+
target_include_directories(pointwise_dynamic
49+
INTERFACE
50+
$<BUILD_INTERFACE:${POINTWISE_OUTPUT_DIR}>
51+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
52+
)
53+
54+
# Ensure headers are generated before anything uses this library
55+
add_dependencies(pointwise_dynamic pointwise_generate_kernels)
56+
57+
# ==============================================================================
58+
# Install
59+
# ==============================================================================
60+
if(FLAGGEMS_INSTALL)
61+
install(FILES
62+
${POINTWISE_MANIFEST_H}
63+
${POINTWISE_RUNTIME_H}
64+
DESTINATION include/flag_gems/pointwise_dynamic
65+
)
66+
endif()
67+
68+
# ==============================================================================
69+
# Status message (configure time)
70+
# ==============================================================================
71+
message(STATUS "Pointwise dynamic C++ support configured:")
72+
message(STATUS " Op files: ${POINTWISE_OP_FILES}")
73+
message(STATUS " Max rank: ${POINTWISE_MAX_RANK}")
74+
message(STATUS " Output dir: ${POINTWISE_OUTPUT_DIR}")
75+
message(STATUS " Kernels will be generated at BUILD time (not configure time)")

0 commit comments

Comments
 (0)