Skip to content

Commit 7cc9bae

Browse files
[rocm-libraries] ROCm/rocm-libraries#5722 (commit 55febd2)
[CK Tile] Stream-K gtest Code Gen ## Motivation Stream-K was using the tile engine infrastructure for smoke tests. However, tile engine creates a different target per kernel instance, which has resulted in scalability issues when used in the context of unit tests. To avoid burdens on cmake configuration and build time, we have opted to remove our Stream-K tile engine tests. Instead, we use pure gtests with code gen to generate repetitive .cpp files. **Note: This appears to change a lot of files because many files are removed since they are now generated at build time.** ## Technical Details We originally used Tile Engine to facilitate code gen for unit tests since we found that pure gtests required the addition of many repetitive .cpp files of the following form: ```cpp #include "test_gemm_streamk_common_includes.hpp" template <typename Tuple> class TestCkTileStreamKBf8 : public TestCkTileStreamK<Tuple> { }; #define TEST_SUITE_NAME TestCkTileStreamKBf8 TYPED_TEST_SUITE(TestCkTileStreamKBf8, KernelTypesStreamKBf8); #include "test_gemm_streamk_atomic_cases.inc" #undef TEST_SUITE_NAME ``` Due to issues encountered with tile engine, we instead use pure gtests to generate the repetitive .cpp files. The code generator parses `KernelTypesStreamK*` type aliases from the types header using a two-phase approach: 1. At **configure time**, CMake runs the Python script with `--list_files` to extract the type alias names from the header (test_gemm_streamk_types.hpp) and compute the list of .cpp file paths that will be generated. This lets CMake know the exact set of source files for each target. 2. At **build time**, `add_custom_command` runs the script again with `--gen_files` to actually emit the .cpp files into the build directory, triggered only when the types header or generator script changes. With these changes, we've removed all Stream-K tile engine tests. There are now 5 targets for Stream-K GEMM tests: 1. test_ck_tile_streamk_atomic_smoke: smoke tests for Atomic reduction strategy (pipeline: compv3) 2. test_ck_tile_streamk_linear_smoke: smoke tests for Linear reduction strategy (pipeline: compv3) 3. test_ck_tile_streamk_tree_smoke: smoke tests for Tree reduction strategy (pipeline: compv3) 4. test_ck_tile_streamk_pipelines_smoke: smoke tests (smaller set) for pipelines other than compv3 - Since Stream-K can be thought of as a wrapper around universal GEMM, we don't need to extensively test each pipeline. So, we opt to run a few tests for different pipelines. Currently, this just consists of the mem pipeline, but compv4 is coming soon. 5. test_ck_tile_streamk_extended: extended tests ## Test Plan I have tests the gtests locally on gfx90a, gfx942, and gfx950. ## Test Result All local tests pass. ## Submission Checklist - [x] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
1 parent 6d77edc commit 7cc9bae

39 files changed

Lines changed: 741 additions & 1778 deletions

File tree

test/ck_tile/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,4 @@ add_subdirectory(fmha)
6969
add_subdirectory(gemm_tile_engine)
7070
add_subdirectory(pooling)
7171
add_subdirectory(grouped_conv)
72-
add_subdirectory(gemm_streamk_tile_engine)
7372
add_subdirectory(pooling_tile_engine)

test/ck_tile/gemm_streamk/CMakeLists.txt

Lines changed: 75 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,93 @@ set(EXAMPLE_GEMM_COMPILE_COMPUTE_ASYNC_OPTIONS ${EXAMPLE_GEMM_COMPILE_COMPUTE_V4
1919
if(GPU_TARGETS MATCHES "gfx90a|gfx942|gfx950")
2020

2121
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR})
22-
22+
2323
#TODO: support all arches
2424
#TODO: current c-shuffle only supports C layout as R
2525
add_gtest_executable(test_ck_tile_streamk_tile_partitioner test_streamk_tile_partitioner.cpp)
26-
set(STREAMK_EXTENDED_SOURCES
27-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp16_persistent_compv3.cpp
28-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp16_persistent_compv4.cpp
29-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp16_persistent_mem.cpp
30-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf16_persistent_compv3.cpp
31-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf16_persistent_compv4.cpp
32-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf16_persistent_mem.cpp
33-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp16_nonpersistent_compv3.cpp
34-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp16_nonpersistent_compv4.cpp
35-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp16_nonpersistent_mem.cpp
36-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf16_nonpersistent_compv3.cpp
37-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf16_nonpersistent_compv4.cpp
38-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf16_nonpersistent_mem.cpp
39-
test_gemm_streamk_util.cpp)
40-
41-
# We only test fp8 and bf8 on gfx942 and gfx950 since these types are not natively supported on gfx90a
42-
if(GPU_TARGETS MATCHES "gfx942|gfx950")
43-
list(APPEND STREAMK_EXTENDED_SOURCES
44-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp8_persistent_compv3.cpp
45-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp8_persistent_compv4.cpp
46-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp8_persistent_mem.cpp
47-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf8_persistent_compv3.cpp
48-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf8_persistent_compv4.cpp
49-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf8_persistent_mem.cpp
50-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp8_nonpersistent_compv3.cpp
51-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp8_nonpersistent_compv4.cpp
52-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_fp8_nonpersistent_mem.cpp
53-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf8_nonpersistent_compv3.cpp
54-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf8_nonpersistent_compv4.cpp
55-
${CMAKE_CURRENT_SOURCE_DIR}/extended_tests/test_gemm_streamk_bf8_nonpersistent_mem.cpp)
56-
endif()
57-
58-
add_gtest_executable(test_ck_tile_streamk_extended ${STREAMK_EXTENDED_SOURCES})
59-
target_compile_options(test_ck_tile_streamk_extended PRIVATE ${EXAMPLE_GEMM_COMPILE_OPTIONS})
26+
27+
# ---- Code-generate test .cpp files from types header ----
28+
set(STREAMK_TYPES_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/test_gemm_streamk_types.hpp)
29+
set(STREAMK_GEN_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/generate_test_files.py)
30+
31+
# Re-run configure automatically if the types header changes (e.g. types added/removed)
32+
# or if the generation script changes
33+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${STREAMK_TYPES_HEADER} ${STREAMK_GEN_SCRIPT})
34+
35+
# Define the targets and their corresponding executable names
36+
set(STREAMK_GEN_TARGETS extended atomic_smoke linear_smoke tree_smoke pipelines_smoke)
37+
set(STREAMK_GEN_EXEC_EXTENDED test_ck_tile_streamk_extended)
38+
set(STREAMK_GEN_EXEC_ATOMIC_SMOKE test_ck_tile_streamk_atomic_smoke)
39+
set(STREAMK_GEN_EXEC_LINEAR_SMOKE test_ck_tile_streamk_linear_smoke)
40+
set(STREAMK_GEN_EXEC_TREE_SMOKE test_ck_tile_streamk_tree_smoke)
41+
set(STREAMK_GEN_EXEC_PIPELINES_SMOKE test_ck_tile_streamk_pipelines_smoke)
6042

6143
# Collect all test targets for umbrella label
6244
set(CK_TILE_GEMM_STREAMK_TEST_TARGETS
63-
test_ck_tile_streamk_tile_partitioner
64-
test_ck_tile_streamk_extended
45+
test_ck_tile_streamk_tile_partitioner)
46+
47+
foreach(target IN LISTS STREAMK_GEN_TARGETS)
48+
string(TOUPPER ${target} TARGET_UPPER)
49+
set(GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/${target})
50+
set(EXEC_NAME ${STREAMK_GEN_EXEC_${TARGET_UPPER}})
51+
set(LIST_FILE ${CMAKE_CURRENT_BINARY_DIR}/${target}_files.txt)
52+
53+
# Phase 1 (configure time): discover the list of files that will be generated
54+
execute_process(
55+
COMMAND ${Python3_EXECUTABLE} ${STREAMK_GEN_SCRIPT}
56+
--types_header ${STREAMK_TYPES_HEADER}
57+
--output_dir ${GEN_DIR}
58+
--target ${target}
59+
--list_files ${LIST_FILE}
60+
RESULT_VARIABLE ret
61+
ERROR_VARIABLE list_files_stderr)
62+
if(ret AND NOT ret EQUAL 0)
63+
message(FATAL_ERROR
64+
"Failed to list ${target} test files via Python: ${ret}\n"
65+
"stderr: ${list_files_stderr}"
66+
)
67+
endif()
68+
file(STRINGS ${LIST_FILE} ALL_SOURCES_${target})
69+
70+
# Phase 2 (build time): generate the .cpp files when the types header changes
71+
add_custom_command(
72+
OUTPUT ${ALL_SOURCES_${target}}
73+
COMMAND ${Python3_EXECUTABLE} ${STREAMK_GEN_SCRIPT}
74+
--types_header ${STREAMK_TYPES_HEADER}
75+
--output_dir ${GEN_DIR}
76+
--target ${target}
77+
--gen_files
78+
DEPENDS ${STREAMK_TYPES_HEADER} ${STREAMK_GEN_SCRIPT}
79+
COMMENT "Generating StreamK ${target} test sources from types header")
80+
81+
# Filter out fp8/bf8 sources on gfx90a since those types are not natively supported
82+
set(FILTERED_SOURCES)
83+
foreach(src IN LISTS ALL_SOURCES_${target})
84+
if(NOT src MATCHES "_(fp8|bf8)_" OR GPU_TARGETS MATCHES "gfx942|gfx950")
85+
list(APPEND FILTERED_SOURCES ${src})
86+
endif()
87+
endforeach()
88+
list(APPEND FILTERED_SOURCES test_gemm_streamk_util.cpp)
89+
90+
add_gtest_executable(${EXEC_NAME} ${FILTERED_SOURCES})
91+
target_compile_options(${EXEC_NAME} PRIVATE ${EXAMPLE_GEMM_COMPILE_OPTIONS})
92+
93+
list(APPEND CK_TILE_GEMM_STREAMK_TEST_TARGETS ${EXEC_NAME})
94+
endforeach()
95+
96+
# Add python unit tests to validate the code gen logic in generate_test_files.py
97+
add_test(
98+
NAME test_ck_tile_streamk_generate_test_files
99+
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_generate_test_files.py -v
100+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..
65101
)
66102

67103
# Label all ck_tile gemm_streamk tests with CK_TILE_GEMM_STREAMK_TESTS for selective execution
68104
foreach(test_target ${CK_TILE_GEMM_STREAMK_TEST_TARGETS})
69105
set_tests_properties(${test_target} PROPERTIES LABELS "CK_TILE_GEMM_STREAMK_TESTS")
70106
endforeach()
107+
# Also label the Python test
108+
set_tests_properties(test_ck_tile_streamk_generate_test_files PROPERTIES LABELS "CK_TILE_GEMM_STREAMK_TESTS")
71109

72110
# Umbrella target to build and run all ck_tile gemm_streamk tests
73111
# Usage: ninja ck_tile_gemm_streamk_tests

test/ck_tile/gemm_streamk/extended_tests/test_gemm_streamk_bf16_nonpersistent_compv3.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/ck_tile/gemm_streamk/extended_tests/test_gemm_streamk_bf16_nonpersistent_compv4.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/ck_tile/gemm_streamk/extended_tests/test_gemm_streamk_bf16_nonpersistent_mem.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/ck_tile/gemm_streamk/extended_tests/test_gemm_streamk_bf16_persistent_compv3.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/ck_tile/gemm_streamk/extended_tests/test_gemm_streamk_bf16_persistent_compv4.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/ck_tile/gemm_streamk/extended_tests/test_gemm_streamk_bf16_persistent_mem.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/ck_tile/gemm_streamk/extended_tests/test_gemm_streamk_bf8_nonpersistent_compv3.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/ck_tile/gemm_streamk/extended_tests/test_gemm_streamk_bf8_nonpersistent_compv4.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)