-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
302 lines (259 loc) · 12.1 KB
/
CMakeLists.txt
File metadata and controls
302 lines (259 loc) · 12.1 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
292
293
294
295
296
297
298
299
300
301
302
include(ExternalProject)
include(External)
include(GPUTestVariant)
llvm_externals_find(TEST_SUITE_HIP_ROOT "hip" "HIP prerequisites")
message(STATUS "TEST_SUITE_HIP_ROOT: ${TEST_SUITE_HIP_ROOT}")
get_filename_component(HIP_CLANG_PATH ${CMAKE_CXX_COMPILER} DIRECTORY)
message(STATUS "HIP_CLANG_PATH: ${HIP_CLANG_PATH}")
# Include Catch tests integration module
include(${CMAKE_CURRENT_LIST_DIR}/HipCatchTests.cmake)
# Inspired from create_one_local_test. Runs hipify on the TestSource and then compiles it.
# Search for the reference files next to TestSource.
macro(create_one_hipify_cuda_test TestName TestSource VairantOffload VariantSuffix VariantCPPFlags VariantLibs)
set(_cuda_src "${TestSource}")
set(_hip_src "${TestName}.hip")
set(_hipify_target "${TestName}-hipify")
set_source_files_properties(${_hip_src} PROPERTIES LANGUAGE CXX)
add_custom_command(OUTPUT ${_hip_src}
COMMAND ${HIPIFY_EXE} "${_cuda_src}" -o "${_hip_src}"
DEPENDS "${_cuda_src}")
add_custom_target(${_hipify_target} DEPENDS ${_hip_src})
set(_executable ${TestName}-${VariantSuffix})
set(_executable_path ${CMAKE_CURRENT_BINARY_DIR}/${_executable})
llvm_test_run()
get_filename_component(_test_source_dir "${TestSource}" DIRECTORY)
get_filename_component(_test_source_name "${TestSource}" NAME_WE)
set(REFERENCE_OUTPUT "${_test_source_dir}/${test_source_name}.reference_output")
if(EXISTS "${REFERENCE_OUTPUT}")
llvm_test_verify(WORKDIR %S
%b/${FPCMP} %o ${REFERENCE_OUTPUT}-${VariantSuffix}
)
llvm_test_executable(${_executable} ${_hip_src})
llvm_test_data(${_executable}
DEST_SUFFIX "-${VariantSuffix}"
${REFERENCE_OUTPUT})
else()
llvm_test_executable(${_executable} ${_hip_src})
endif()
target_compile_options(${_executable} PUBLIC ${VariantCPPFLAGS})
# In External/CUDA, tests define a STDLIB_VERSION that matches the C++
# standard supported by the standard library.
# For the HIP case, we set a huge number and assume that the latest C++
# standard version is supported by the library.
target_compile_definitions(${_executable} PRIVATE STDLIB_VERSION=9999)
add_dependencies(${_executable} ${_hipify_target})
if(VariantLibs)
target_link_libraries(${_executable} ${VariantLibs})
endif()
add_dependencies(hip-tests-simple-${VariantSuffix} ${_executable})
list(APPEND VARIANT_SIMPLE_TEST_TARGETS ${_executable}.test)
endmacro()
# Create targets for HIP tests that are part of the test suite.
macro(create_local_hip_tests VariantSuffix)
set(VariantOffload "hip")
# Set per-source compilation/link options
set_source_files_properties(with-fopenmp.hip PROPERTIES
COMPILE_FLAGS -fopenmp)
# TODO: Add the flag after the kernel argument splitting pass is enabled.
#set_source_files_properties(split-kernel-args.hip PROPERTIES
# COMPILE_FLAGS "-mllvm -amdgpu-enable-split-kernel-args")
# Add HIP tests to be added to hip-tests-simple
list(APPEND HIP_LOCAL_TESTS array)
list(APPEND HIP_LOCAL_TESTS empty)
list(APPEND HIP_LOCAL_TESTS with-fopenmp)
list(APPEND HIP_LOCAL_TESTS saxpy)
list(APPEND HIP_LOCAL_TESTS memmove)
list(APPEND HIP_LOCAL_TESTS memset)
list(APPEND HIP_LOCAL_TESTS split-kernel-args)
list(APPEND HIP_LOCAL_TESTS builtin-logb-scalbn)
list(APPEND HIP_LOCAL_TESTS pgo-tiled-matmul)
list(APPEND HIP_LOCAL_TESTS InOneWeekend)
list(APPEND HIP_LOCAL_TESTS TheNextWeek)
# Copy files needed for ray-tracing tests.
file(GLOB IMAGE_FILES "workload/ray-tracing/images/*.jpg" "workload/ray-tracing/images/*.png")
file(COPY ${IMAGE_FILES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
foreach(_hip_test IN LISTS HIP_LOCAL_TESTS)
set(test_source "${_hip_test}.hip")
if(_hip_test STREQUAL "TheNextWeek" OR _hip_test STREQUAL "InOneWeekend")
file(GLOB REF_PPM_FILES "workload/ray-tracing/${_hip_test}/*.ppm")
file(COPY ${REF_PPM_FILES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
set(test_source "workload/ray-tracing/${_hip_test}/main.cc")
# need -mfma to enable FMA in host code
set_source_files_properties(${test_source} PROPERTIES
COMPILE_FLAGS "-xhip -mfma")
endif()
create_one_local_test(${_hip_test} ${test_source}
${VariantOffload} ${VariantSuffix}
"${VariantCPPFLAGS}" "${VariantLibs}")
endforeach()
list(APPEND CUDA_LOCAL_TESTS algorithm)
list(APPEND CUDA_LOCAL_TESTS cmath)
list(APPEND CUDA_LOCAL_TESTS complex)
list(APPEND CUDA_LOCAL_TESTS math_h)
list(APPEND CUDA_LOCAL_TESTS new)
find_program(HIPIFY_EXE
NAME hipify-perl
PATHS ${_RocmPath}/bin)
if(HIPIFY_EXE)
foreach(_cuda_test IN LISTS CUDA_LOCAL_TESTS)
set(_cuda_src "${CMAKE_CURRENT_SOURCE_DIR}/../CUDA/${_cuda_test}.cu")
create_one_hipify_cuda_test(${_cuda_test} ${_cuda_src}
${VariantOffload} ${VariantSuffix}
"${VariantCPPFLAGS}" "${VariantLibs}")
endforeach()
else()
message(WARNING "hipify-perl not found for ROCm installation in ${_RocmPath}.")
endif()
# Add test for PGO tiled matmul.
configure_file(workload/pgo/test_pgo_matmul.sh.in ${CMAKE_CURRENT_BINARY_DIR}/test_pgo_matmul.sh @ONLY)
configure_file(workload/pgo/verify_pgo_matmul.sh.in ${CMAKE_CURRENT_BINARY_DIR}/verify_pgo_matmul.sh @ONLY)
llvm_test_run(EXECUTABLE "/bin/bash" "test_pgo_matmul.sh")
llvm_test_verify(/bin/bash verify_pgo_matmul.sh %o)
llvm_add_test(pgo-tiled-matmul-pipeline.test test_pgo_matmul.sh)
list(APPEND VARIANT_SIMPLE_TEST_TARGETS pgo-tiled-matmul-pipeline.test)
# Add test for Blender.
configure_file(workload/blender/test_blender.sh.in ${CMAKE_CURRENT_BINARY_DIR}/test_blender.sh @ONLY)
configure_file(workload/blender/verify_blender.sh.in ${CMAKE_CURRENT_BINARY_DIR}/verify_blender.sh @ONLY)
file(COPY utils/log_data.py DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
file(COPY utils/compare_image.py DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
file(COPY utils/requirements.txt DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
llvm_test_run(EXECUTABLE "/bin/bash" "test_blender.sh")
llvm_test_verify(/bin/bash verify_blender.sh %o)
llvm_add_test(blender.test test_blender.sh)
list(APPEND VARIANT_SIMPLE_TEST_TARGETS blender.test)
endmacro()
function(create_hip_test VariantSuffix)
message(STATUS "Creating HIP test variant ${VariantSuffix}")
add_custom_target(hip-tests-simple-${VariantSuffix}
COMMENT "Build HIP test variant ${VariantSuffix}")
set(VariantCPPFLAGS ${_HIP_CPPFLAGS})
set(VariantLibs ${_HIP_Libs})
list(APPEND LDFLAGS ${_HIP_LDFLAGS})
create_local_hip_tests(${VariantSuffix})
add_dependencies(hip-tests-simple hip-tests-simple-${VariantSuffix})
# Enable verbose output for running HIP tests.
set(HIP_LIT_FLAGS "-v")
if (HIP_EXPORT_XUNIT_XML)
list(APPEND HIP_LIT_FLAGS --xunit-xml-output hip-results-${VariantSuffix}.xml)
endif()
add_custom_target(check-hip-simple-${VariantSuffix}
COMMAND ${TEST_SUITE_LIT} ${HIP_LIT_FLAGS}
${VARIANT_SIMPLE_TEST_TARGETS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS hip-tests-simple-${VariantSuffix}
USES_TERMINAL)
add_dependencies(check-hip-simple check-hip-simple-${VariantSuffix})
# Integrate Catch tests for this variant (if enabled)
if(ENABLE_HIP_CATCH_TESTS)
integrate_catch_tests(${VariantSuffix} ${_RocmPath})
endif()
endfunction(create_hip_test)
macro(create_hip_tests)
# Find all rocm installations at Externals/hip/ directory.
# For ROCm, the path looks like rocm-4.1.0
message(STATUS "Checking HIP prerequisites in ${TEST_SUITE_HIP_ROOT}")
file(GLOB RocmVersions ${TEST_SUITE_HIP_ROOT}/rocm-*)
list(SORT RocmVersions)
foreach(RocmDir IN LISTS RocmVersions)
get_version(RocmVersion ${RocmDir})
message(STATUS "Found ROCm ${RocmVersion}")
list(APPEND ROCM_PATHS ${RocmDir})
endforeach(RocmDir)
if(NOT ROCM_PATHS)
message(SEND_ERROR
"There are no ROCm installations in ${TEST_SUITE_HIP_ROOT}")
return()
endif()
add_custom_target(hip-tests-simple
COMMENT "Build all simple HIP tests")
add_custom_target(check-hip-simple
COMMENT "Run all simple HIP tests")
# Initialize Catch tests framework
initialize_catch_tests()
if(NOT AMDGPU_ARCHS)
list(APPEND AMDGPU_ARCHS "gfx906;gfx90a;gfx1030;gfx1100;gfx1201;gfx942;gfx950;native")
endif()
foreach(_RocmPath ${ROCM_PATHS})
get_version(_RocmVersion ${_RocmPath})
set(_HIP_Suffix "hip-${_RocmVersion}")
# Set up HIP test flags
set(_HIP_CPPFLAGS --rocm-path=${_RocmPath})
set(_HIP_LDFLAGS --rocm-path=${_RocmPath} --hip-link -rtlib=compiler-rt -unwindlib=libgcc -frtlib-add-rpath)
# Unset these for each iteration of rocm path.
set(_ArchFlags)
set(_ArchList)
foreach(_AMDGPUArch IN LISTS AMDGPU_ARCHS)
list(APPEND _ArchFlags --offload-arch=${_AMDGPUArch})
endforeach()
message(STATUS "Building ${_RocmPath} targets for ${AMDGPU_ARCHS}")
list(APPEND _HIP_CPPFLAGS ${_ArchFlags})
create_hip_test(${_HIP_Suffix})
endforeach()
if (EXTERNAL_HIP_TESTS_KOKKOS)
set(EXTERNAL_HIP_TESTS_KOKKOS_TAG "4.5.01" CACHE STRING "Kokkos tag to download and test")
ExternalProject_Add(TestKokkosHIP
GIT_REPOSITORY https://github.com/kokkos/kokkos.git
GIT_TAG ${EXTERNAL_HIP_TESTS_KOKKOS_TAG}
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_STANDARD=17
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DKokkos_ENABLE_HIP=ON
-DKokkos_ARCH_AMD_GFX90A=ON
-DCMAKE_PREFIX_PATH=/opt/rocm
-DKokkos_ENABLE_TESTS=ON
INSTALL_COMMAND ""
TEST_COMMAND ""
)
add_custom_target(build-kokkos DEPENDS TestKokkosHIP)
ExternalProject_Get_Property(TestKokkosHIP BINARY_DIR)
add_custom_target(test-kokkos ${CMAKE_COMMAND} -E env GTEST_FILTER=-hip.atomics:hip.bit_manip_bit_ceil "ctest" WORKING_DIRECTORY "${BINARY_DIR}" DEPENDS build-kokkos)
endif()
if (EXTERNAL_HIP_TESTS_GINKGO)
set(EXTERNAL_HIP_TESTS_GINKGO_TAG "v1.9.0" CACHE STRING "Ginkgo tag to download and test")
ExternalProject_Add(TestGinkgoHIP
GIT_REPOSITORY https://github.com/ginkgo-project/ginkgo.git
GIT_TAG ${EXTERNAL_HIP_TESTS_GINKGO_TAG}
CMAKE_ARGS -DGINKGO_BUILD_HIP=ON
-DCMAKE_PREFIX_PATH=/opt/rocm
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DGINKGO_BUILD_MPI=OFF
-DCMAKE_HIP_COMPILER=${CMAKE_CXX_COMPILER}
-DGINKGO_WITH_CCACHE=OFF
-DGINKGO_BUILD_EXAMPLES=OFF
INSTALL_COMMAND ""
TEST_COMMAND ""
)
add_custom_target(build-ginkgo DEPENDS TestGinkgoHIP)
ExternalProject_Get_Property(TestGinkgoHIP BINARY_DIR)
add_custom_target(test-ginkgo COMMAND "ctest" "-R hip" WORKING_DIRECTORY "${BINARY_DIR}" DEPENDS build-ginkgo)
endif()
if (EXTERNAL_HIP_TESTS_ROCPRIM)
ExternalProject_Add(BuildRocPrim
GIT_REPOSITORY https://github.com/ROCm/rocPRIM.git
GIT_TAG ae4d27e # Staging for ROCm 6.4
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_HIP_COMPILER=${CMAKE_CXX_COMPILER}
-DBUILD_TEST=ON
-DAMDGPU_TARGETS="${AMDGPU_ARCHS}"
-DCMAKE_BUILD_TYPE=Release
INSTALL_COMMAND ""
TEST_COMMAND ""
)
add_custom_target(build-rocprim DEPENDS BuildRocPrim)
endif()
# Build all HIP tests (simple + catch if enabled)
if(ENABLE_HIP_CATCH_TESTS)
add_custom_target(hip-tests-all DEPENDS hip-tests-simple hip-tests-catch
COMMENT "Build all HIP tests (simple + catch).")
else()
add_custom_target(hip-tests-all DEPENDS hip-tests-simple
COMMENT "Build all HIP tests (simple only, catch disabled).")
endif()
file(COPY lit.local.cfg DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
endmacro(create_hip_tests)
if(TEST_SUITE_HIP_ROOT)
create_hip_tests()
endif()