Skip to content

Commit e00962c

Browse files
committed
Added cmake file to build pytorch from source.
1 parent b6d3539 commit e00962c

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# generate a list of kernels, but not actually emit files at config stage
2+
execute_process(
3+
COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/../../../../../../../../third_party/composable_kernel/example/ck_tile/01_fmha/generate.py
4+
--api fwd --receipt 4 --list_blobs ${CMAKE_CURRENT_LIST_DIR}/fwd_blob_list.txt
5+
RESULT_VARIABLE ret
6+
)
7+
8+
if(ret AND NOT ret EQUAL 0)
9+
message( FATAL_ERROR "CK Tile FMHA FAILED to generate a list of FWD kernels via Python.")
10+
endif()
11+
12+
execute_process(
13+
COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/../../../../../../../../third_party/composable_kernel/example/ck_tile/01_fmha/generate.py
14+
--api bwd --receipt 4 --list_blobs ${CMAKE_CURRENT_LIST_DIR}/bwd_blob_list.txt
15+
RESULT_VARIABLE ret
16+
)
17+
18+
if(ret AND NOT ret EQUAL 0)
19+
message( FATAL_ERROR "CK Tile FMHA FAILED to generate a list of BWD kernels via Python.")
20+
endif()
21+
22+
# Generate the files for both fwd and bwd
23+
execute_process(COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/../../../../../../../../third_party/composable_kernel/example/ck_tile/01_fmha/generate.py --api fwd --receipt 4 --output_dir ${CMAKE_CURRENT_LIST_DIR}
24+
)
25+
26+
if(ret AND NOT ret EQUAL 0)
27+
message( FATAL_ERROR "CK Tile FMHA FAILED to generate FWD kernels.")
28+
endif()
29+
30+
execute_process(COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/../../../../../../../../third_party/composable_kernel/example/ck_tile/01_fmha/generate.py --api bwd --receipt 4 --output_dir ${CMAKE_CURRENT_LIST_DIR}
31+
RESULT_VARIABLE ret
32+
)
33+
34+
if(ret AND NOT ret EQUAL 0)
35+
message( FATAL_ERROR "CK Tile FMHA FAILED to generate BWD kernels.")
36+
endif()
37+
38+
# Change make_kernel to make_kernel_pt for fwd
39+
execute_process(
40+
COMMAND bash -c "${CMAKE_CURRENT_LIST_DIR}/add_make_kernel_pt.sh ${CMAKE_CURRENT_LIST_DIR}/fwd_blob_list.txt"
41+
RESULT_VARIABLE ret)
42+
43+
if(ret AND NOT ret EQUAL 0)
44+
message( FATAL_ERROR "CK Tile FMHA FAILED to change make_kernel to make_kernel_pt for the fwd pass")
45+
endif()
46+
47+
# Change make_kernel to make_kernel_pt for bwd
48+
execute_process(
49+
COMMAND bash -c "${CMAKE_CURRENT_LIST_DIR}/add_make_kernel_pt.sh ${CMAKE_CURRENT_LIST_DIR}/bwd_blob_list.txt"
50+
RESULT_VARIABLE ret)
51+
52+
if(ret AND NOT ret EQUAL 0)
53+
message( FATAL_ERROR "CK Tile FMHA FAILED to change make_kernel to make_kernel_pt for the bwd pass")
54+
endif()
55+
56+
# Change file extensions to .hip
57+
execute_process(COMMAND bash -c "for file in ${CMAKE_CURRENT_LIST_DIR}/*.cpp; do mv -- \"$file\" \"\${file%.cpp}.hip\"; done"
58+
RESULT_VARIABLE ret
59+
)
60+
61+
if(ret AND NOT ret EQUAL 0)
62+
message( FATAL_ERROR "CK Tile FMHA FAILED to change the generated instances extensions from .cpp to .hpp")
63+
endif()
64+

0 commit comments

Comments
 (0)