Skip to content

Commit 2f699f4

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

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

External/HIP/CMakeLists.txt

+63
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,48 @@ 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_PERL_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+
add_dependencies(${_executable} ${_hipify_target})
44+
if(VariantLibs)
45+
target_link_libraries(${_executable} ${VariantLibs})
46+
endif()
47+
48+
add_dependencies(hip-tests-simple-${VariantSuffix} ${_executable})
49+
list(APPEND VARIANT_SIMPLE_TEST_TARGETS ${_executable}.test)
50+
endmacro()
51+
1052
# Create targets for HIP tests that are part of the test suite.
1153
macro(create_local_hip_tests VariantSuffix)
1254
set(VariantOffload "hip")
@@ -48,6 +90,27 @@ macro(create_local_hip_tests VariantSuffix)
4890
"${VariantCPPFLAGS}" "${VariantLibs}")
4991
endforeach()
5092

93+
list(APPEND CUDA_LOCAL_TESTS algorithm)
94+
list(APPEND CUDA_LOCAL_TESTS cmath)
95+
list(APPEND CUDA_LOCAL_TESTS complex)
96+
list(APPEND CUDA_LOCAL_TESTS math_h)
97+
list(APPEND CUDA_LOCAL_TESTS new)
98+
99+
find_program(HIPIFY_PERL_EXE
100+
NAME hipify-perl
101+
PATHS ${_RocmPath}/bin)
102+
103+
if(HIPIFY_PERL_EXE)
104+
foreach(_cuda_test IN LISTS CUDA_LOCAL_TESTS)
105+
set(_cuda_src "${CMAKE_CURRENT_SOURCE_DIR}/../CUDA/${_cuda_test}.cu")
106+
create_one_hipify_cuda_test(${_cuda_test} ${_cuda_src}
107+
${VariantOffload} ${VariantSuffix}
108+
"${VariantCPPFLAGS}" "${VariantLibs}")
109+
endforeach()
110+
else()
111+
message(WARNING "hipify-perl not found for ROCm installation in ${_RocmPath}.")
112+
endif()
113+
51114
# Add test for Blender.
52115
configure_file(workload/blender/test_blender.sh.in ${CMAKE_CURRENT_BINARY_DIR}/test_blender.sh @ONLY)
53116
configure_file(workload/blender/verify_blender.sh.in ${CMAKE_CURRENT_BINARY_DIR}/verify_blender.sh @ONLY)

0 commit comments

Comments
 (0)