Skip to content

Commit 57ae476

Browse files
committed
[HIP] Add cuda_wrapper tests from Externals/CUDA using hipify-perl
1 parent a45d162 commit 57ae476

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

External/HIP/CMakeLists.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,54 @@ message(STATUS "TEST_SUITE_HIP_ROOT: ${TEST_SUITE_HIP_ROOT}")
77
get_filename_component(HIP_CLANG_PATH ${CMAKE_CXX_COMPILER} DIRECTORY)
88
message(STATUS "HIP_CLANG_PATH: ${HIP_CLANG_PATH}")
99

10+
# Inspired from create_one_local_test. Runs hipify on the TestSource and then compiles it.
11+
# Search for the reference files next to TestSource.
12+
macro(create_one_hipify_cuda_test TestName TestSource VairantOffload VariantSuffix VariantCPPFlags VariantLibs)
13+
set(_cuda_src "${TestSource}")
14+
set(_hip_src "${TestName}.hip")
15+
set(_hipify_target "${TestName}-hipify")
16+
17+
set_source_files_properties(${_hip_src} PROPERTIES LANGUAGE CXX)
18+
add_custom_command(OUTPUT ${_hip_src}
19+
COMMAND ${HIPIFY_EXE} "${_cuda_src}" -o "${_hip_src}"
20+
DEPENDS "${_cuda_src}")
21+
add_custom_target(${_hipify_target} DEPENDS ${_hip_src})
22+
23+
set(_executable ${TestName}-${VariantSuffix})
24+
set(_executable_path ${CMAKE_CURRENT_BINARY_DIR}/${_executable})
25+
llvm_test_run()
26+
27+
get_filename_component(_test_source_dir "${TestSource}" DIRECTORY)
28+
get_filename_component(_test_source_name "${TestSource}" NAME_WE)
29+
set(REFERENCE_OUTPUT "${_test_source_dir}/${test_source_name}.reference_output")
30+
if(EXISTS "${REFERENCE_OUTPUT}")
31+
llvm_test_verify(WORKDIR %S
32+
%b/${FPCMP} %o ${REFERENCE_OUTPUT}-${VariantSuffix}
33+
)
34+
llvm_test_executable(${_executable} ${_hip_src})
35+
llvm_test_data(${_executable}
36+
DEST_SUFFIX "-${VariantSuffix}"
37+
${REFERENCE_OUTPUT})
38+
else()
39+
llvm_test_executable(${_executable} ${_hip_src})
40+
endif()
41+
42+
target_compile_options(${_executable} PUBLIC ${VariantCPPFLAGS})
43+
44+
# In External/CUDA, tests define a STDLIB_VERSION that matches the C++
45+
# standard supported by the standard library.
46+
# For the HIP case, we set a huge number and assume that the latest C++
47+
# standard version is supported by the library.
48+
target_compile_definitions(${_executable} PRIVATE STDLIB_VERSION=9999)
49+
add_dependencies(${_executable} ${_hipify_target})
50+
if(VariantLibs)
51+
target_link_libraries(${_executable} ${VariantLibs})
52+
endif()
53+
54+
add_dependencies(hip-tests-simple-${VariantSuffix} ${_executable})
55+
list(APPEND VARIANT_SIMPLE_TEST_TARGETS ${_executable}.test)
56+
endmacro()
57+
1058
# Create targets for HIP tests that are part of the test suite.
1159
macro(create_local_hip_tests VariantSuffix)
1260
set(VariantOffload "hip")
@@ -48,6 +96,27 @@ macro(create_local_hip_tests VariantSuffix)
4896
"${VariantCPPFLAGS}" "${VariantLibs}")
4997
endforeach()
5098

99+
list(APPEND CUDA_LOCAL_TESTS algorithm)
100+
list(APPEND CUDA_LOCAL_TESTS cmath)
101+
list(APPEND CUDA_LOCAL_TESTS complex)
102+
list(APPEND CUDA_LOCAL_TESTS math_h)
103+
list(APPEND CUDA_LOCAL_TESTS new)
104+
105+
find_program(HIPIFY_EXE
106+
NAME hipify-perl
107+
PATHS ${_RocmPath}/bin)
108+
109+
if(HIPIFY_EXE)
110+
foreach(_cuda_test IN LISTS CUDA_LOCAL_TESTS)
111+
set(_cuda_src "${CMAKE_CURRENT_SOURCE_DIR}/../CUDA/${_cuda_test}.cu")
112+
create_one_hipify_cuda_test(${_cuda_test} ${_cuda_src}
113+
${VariantOffload} ${VariantSuffix}
114+
"${VariantCPPFLAGS}" "${VariantLibs}")
115+
endforeach()
116+
else()
117+
message(WARNING "hipify-perl not found for ROCm installation in ${_RocmPath}.")
118+
endif()
119+
51120
# Add test for Blender.
52121
configure_file(workload/blender/test_blender.sh.in ${CMAKE_CURRENT_BINARY_DIR}/test_blender.sh @ONLY)
53122
configure_file(workload/blender/verify_blender.sh.in ${CMAKE_CURRENT_BINARY_DIR}/verify_blender.sh @ONLY)

0 commit comments

Comments
 (0)