Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate chipstar #459

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion catch/ABM/AddKernels/add.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ template <typename T> __global__ void add(T* a, T* b, T* c, size_t size) {
}

TEMPLATE_TEST_CASE("ABM_AddKernel_MultiTypeMultiSize", "", int, long, float, long long, double) {
auto size = GENERATE(as<size_t>{}, 100, 500, 1000);
auto size = GENERATE(as<size_t>{}, 100, 500);
TestType *d_a, *d_b, *d_c;
auto res = hipMalloc(&d_a, sizeof(TestType) * size);
REQUIRE(res == hipSuccess);
Expand Down
26 changes: 21 additions & 5 deletions catch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ option(ENABLE_ADDRESS_SANITIZER "Option to enable ASAN build" OFF)
message(STATUS "STANDALONE_TESTS : ${STANDALONE_TESTS}")

# Check if platform is set
if(NOT HIP_PLATFORM STREQUAL "amd" AND NOT HIP_PLATFORM STREQUAL "nvidia")
if(NOT HIP_PLATFORM STREQUAL "amd" AND NOT HIP_PLATFORM STREQUAL "nvidia" AND NOT HIP_PLATFORM STREQUAL "spirv")
message(FATAL_ERROR "Unexpected HIP_PLATFORM: " ${HIP_PLATFORM})
endif()

Expand Down Expand Up @@ -60,9 +60,11 @@ message(STATUS "ROCM_PATH: ${ROCM_PATH}")
set(CMAKE_CXX_COMPILER "${HIP_PATH}/bin/hipcc${EXT}")
set(CMAKE_C_COMPILER "${HIP_PATH}/bin/hipcc${EXT}")
set(HIPCONFIG_EXECUTABLE "${HIP_PATH}/bin/hipconfig${EXT}")
execute_process(COMMAND ${HIPCONFIG_EXECUTABLE} --version
OUTPUT_VARIABLE HIP_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT DEFINED HIP_VERSION)
execute_process(COMMAND ${HIPCONFIG_EXECUTABLE} --version
OUTPUT_VARIABLE HIP_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()

# enforce c++17
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++17")
Expand Down Expand Up @@ -132,7 +134,21 @@ option(RTC_TESTING "Run tests using HIP RTC to compile the kernels" OFF)
if (RTC_TESTING)
add_definitions(-DRTC_TESTING=ON)
endif()
add_definitions(-DKERNELS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/kernels/")

# The following does not work
# add_definitions(-DKERNELS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/kernels/")
# In file included from /space/pvelesko/chipStar/hip-tests-update/hip-tests/catch/hipTestMain/main.cc:3:
# In file included from /space/pvelesko/chipStar/hip-tests-update/hip-tests/catch/./include/hip_test_common.hh:37:
# /space/pvelesko/chipStar/hip-tests-update/hip-tests/catch/./include/hip_test_rtc.hh:110:36: error: use of undeclared identifier 'tests'
# <command line>:1:68: note: expanded from macro 'KERNELS_PATH'
# 1 | #define KERNELS_PATH /space/pvelesko/chipStar/hip-tests-update/hip-tests/catch/kernels/
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/kernels_path.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/kernels_path.h"
)

# Include the generated header file directory
include_directories("${CMAKE_CURRENT_BINARY_DIR}")

set(CATCH_BUILD_DIR catch_tests)
execute_process(COMMAND ${CMAKE_COMMAND} -E
Expand Down
98 changes: 13 additions & 85 deletions catch/external/Catch2/cmake/Catch2/Catch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function(catch_discover_tests_compile_time_detection TARGET TEST_SET)

add_custom_command(
TARGET ${EXE_NAME} POST_BUILD
BYPRODUCTS "${ctest_tests_file}"
COMMAND "${CMAKE_COMMAND}"
-D "TEST_TARGET=${EXE_NAME}"
-D "TEST_EXECUTABLE=$<TARGET_FILE:${EXE_NAME}>"
Expand Down Expand Up @@ -252,88 +253,6 @@ set(_CATCH_DISCOVER_TESTS_SCRIPT
CACHE INTERNAL "Catch2 full path to CatchAddTests.cmake helper file"
)


###############################################################################
# function to be called by all tests
function(hip_add_exe_to_target_compile_time_detection)
set(options)
# NAME EventTest, TEST_SRC src, TEST_TARGET_NAME build_tests
set(args NAME TEST_TARGET_NAME PLATFORM COMPILE_OPTIONS)
set(list_args TEST_SRC LINKER_LIBS COMMON_SHARED_SRC PROPERTY)
cmake_parse_arguments(
PARSE_ARGV 0
"" # variable prefix
"${options}"
"${args}"
"${list_args}"
)

foreach(SRC_NAME ${TEST_SRC})
if(NOT STANDALONE_TESTS EQUAL "1")
set(_EXE_NAME ${_NAME})
# take the entire source set for building the executable
set(SRC_NAME ${TEST_SRC})
else()
# strip extension of src and use exe name as src name
get_filename_component(_EXE_NAME ${SRC_NAME} NAME_WLE)
endif()

if(NOT RTC_TESTING)
add_executable(${_EXE_NAME} EXCLUDE_FROM_ALL ${SRC_NAME} ${COMMON_SHARED_SRC} $<TARGET_OBJECTS:Main_Object> $<TARGET_OBJECTS:KERNELS>)
else ()
add_executable(${_EXE_NAME} EXCLUDE_FROM_ALL ${SRC_NAME} ${COMMON_SHARED_SRC} $<TARGET_OBJECTS:Main_Object>)
if(HIP_PLATFORM STREQUAL "amd")
target_link_libraries(${_EXE_NAME} hiprtc)
else()
target_link_libraries(${_EXE_NAME} nvrtc)
endif()
endif()



if(UNIX)
set(_LINKER_LIBS ${_LINKER_LIBS} stdc++fs)
set(_LINKER_LIBS ${_LINKER_LIBS} -ldl)
else()
# res files are built resource files using rc files.
# use llvm-rc exe to build the res files
# Thes are used to populate the properties of the built executables
if(EXISTS "${PROP_RC}/catchProp.res")
set(_LINKER_LIBS ${_LINKER_LIBS} "${PROP_RC}/catchProp.res")
endif()
#set(_LINKER_LIBS ${_LINKER_LIBS} -noAutoResponse)
endif()

if(DEFINED _LINKER_LIBS)
target_link_libraries(${_EXE_NAME} ${_LINKER_LIBS})
endif()

# Add dependency on build_tests to build it on this custom target
add_dependencies(${_TEST_TARGET_NAME} ${_EXE_NAME})
# add_dependencies(${_TEST_TARGET_NAME} ${_EXE_NAME})

if (DEFINED _PROPERTY)
set_property(TARGET ${_EXE_NAME} PROPERTY ${_PROPERTY})
endif()

if (DEFINED _COMPILE_OPTIONS)
target_compile_options(${_EXE_NAME} PUBLIC ${_COMPILE_OPTIONS})
endif()
foreach(arg IN LISTS _UNPARSED_ARGUMENTS)
message(WARNING "Unparsed arguments: ${arg}")
endforeach()
get_property(crosscompiling_emulator
TARGET ${_EXE_NAME}
PROPERTY CROSSCOMPILING_EMULATOR
)
set(_EXE_NAME_LIST ${_EXE_NAME_LIST} ${_EXE_NAME})
if(NOT STANDALONE_TESTS EQUAL "1")
break()
endif()
endforeach()
catch_discover_tests("${_EXE_NAME_LIST}" "${_NAME}" PROPERTIES SKIP_REGULAR_EXPRESSION "HIP_SKIP_THIS_TEST")
endfunction()

###############################################################################
# current staging
# function to be called by all tests
Expand Down Expand Up @@ -365,8 +284,12 @@ function(hip_add_exe_to_target)
add_executable(${_EXE_NAME} EXCLUDE_FROM_ALL ${SRC_NAME} ${COMMON_SHARED_SRC} $<TARGET_OBJECTS:Main_Object>)
if(HIP_PLATFORM STREQUAL "amd")
target_link_libraries(${_EXE_NAME} hiprtc)
else()
elseif(HIP_PLATFORM STREQUAL "nvidia")
target_link_libraries(${_EXE_NAME} nvrtc)
elseif(HIP_PLATFORM STREQUAL "spirv")
# nothing extra needed for chipStar
else()
message(FATAL_ERROR "Unsupported HIP_PLATFORM: ${HIP_PLATFORM}")
endif()
endif()
if (DEFINED _PROPERTY)
Expand Down Expand Up @@ -411,6 +334,11 @@ function(hip_add_exe_to_target)

endforeach()

catch_discover_tests("${_EXE_NAME_LIST}" "${_NAME}" PROPERTIES SKIP_REGULAR_EXPRESSION "HIP_SKIP_THIS_TEST")
endfunction()

if(DEFINED CATCH2_DISCOVER_TESTS_COMPILE_TIME AND CATCH2_DISCOVER_TESTS_COMPILE_TIME)
catch_discover_tests_compile_time_detection("${_EXE_NAME_LIST}" "${_NAME}" PROPERTIES SKIP_REGULAR_EXPRESSION "HIP_SKIP_THIS_TEST")
else()
catch_discover_tests("${_EXE_NAME_LIST}" "${_NAME}" PROPERTIES SKIP_REGULAR_EXPRESSION "HIP_SKIP_THIS_TEST")
endif()

endfunction()
192 changes: 93 additions & 99 deletions catch/external/Catch2/cmake/Catch2/CatchAddTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,116 +29,110 @@ function(add_command NAME)
set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE)
endfunction()

get_filename_component(TEST_EXECUTABLE ${TEST_EXECUTABLE} ABSOLUTE)

foreach(TEST_EXECUTABLE ${TEST_EXE_LIST})
if(WIN32)
set(TEST_EXECUTABLE ${TEST_EXECUTABLE}.exe)
endif()
get_filename_component(TEST_EXECUTABLE ${TEST_EXECUTABLE} ABSOLUTE)

# Run test executable to get list of available tests
if(NOT EXISTS "${TEST_EXECUTABLE}")
# exe does not exist moving to the next executable
continue()
endif()
execute_process(
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-names-only
OUTPUT_VARIABLE output
RESULT_VARIABLE result
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
# Run test executable to get list of available tests
if(NOT EXISTS "${TEST_EXECUTABLE}")
message(FATAL_ERROR
"Specified test executable '${TEST_EXECUTABLE}' does not exist"
)
# Catch --list-test-names-only reports the number of tests, so 0 is... surprising
if(${result} EQUAL 0)
message(WARNING
"Test executable '${TEST_EXECUTABLE}' contains no tests!\n"
)
elseif(${result} LESS 0)
message(FATAL_ERROR
"Error running test executable '${TEST_EXECUTABLE}':\n"
" Result: ${result}\n"
" Output: ${output}\n"
)
endif()
endif()
execute_process(
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-names-only
OUTPUT_VARIABLE output
RESULT_VARIABLE result
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
)
# Catch --list-test-names-only reports the number of tests, so 0 is... surprising
if(${result} EQUAL 0)
message(WARNING
"Test executable '${TEST_EXECUTABLE}' contains no tests!\n"
)
elseif(${result} LESS 0)
message(FATAL_ERROR
"Error running test executable '${TEST_EXECUTABLE}':\n"
" Result: ${result}\n"
" Output: ${output}\n"
)
endif()

string(REPLACE "\n" ";" output "${output}")
string(REPLACE "\n" ";" output "${output}")

# Run test executable to get list of available reporters
execute_process(
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-reporters
OUTPUT_VARIABLE reporters_output
RESULT_VARIABLE reporters_result
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
# Run test executable to get list of available reporters
execute_process(
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-reporters
OUTPUT_VARIABLE reporters_output
RESULT_VARIABLE reporters_result
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
)
if(${reporters_result} EQUAL 0)
message(WARNING
"Test executable '${TEST_EXECUTABLE}' contains no reporters!\n"
)
if(${reporters_result} EQUAL 0)
message(WARNING
"Test executable '${TEST_EXECUTABLE}' contains no reporters!\n"
)
elseif(${reporters_result} LESS 0)
message(FATAL_ERROR
"Error running test executable '${TEST_EXECUTABLE}':\n"
" Result: ${reporters_result}\n"
" Output: ${reporters_output}\n"
)
endif()
string(FIND "${reporters_output}" "${reporter}" reporter_is_valid)
if(reporter AND ${reporter_is_valid} EQUAL -1)
message(FATAL_ERROR
"\"${reporter}\" is not a valid reporter!\n"
)
endif()
elseif(${reporters_result} LESS 0)
message(FATAL_ERROR
"Error running test executable '${TEST_EXECUTABLE}':\n"
" Result: ${reporters_result}\n"
" Output: ${reporters_output}\n"
)
endif()
string(FIND "${reporters_output}" "${reporter}" reporter_is_valid)
if(reporter AND ${reporter_is_valid} EQUAL -1)
message(FATAL_ERROR
"\"${reporter}\" is not a valid reporter!\n"
)
endif()

# Prepare reporter
if(reporter)
set(reporter_arg "--reporter ${reporter}")
endif()
# Prepare reporter
if(reporter)
set(reporter_arg "--reporter ${reporter}")
endif()

# Prepare output dir
if(output_dir AND NOT IS_ABSOLUTE ${output_dir})
set(output_dir "${TEST_WORKING_DIR}/${output_dir}")
if(NOT EXISTS ${output_dir})
file(MAKE_DIRECTORY ${output_dir})
endif()
# Prepare output dir
if(output_dir AND NOT IS_ABSOLUTE ${output_dir})
set(output_dir "${TEST_WORKING_DIR}/${output_dir}")
if(NOT EXISTS ${output_dir})
file(MAKE_DIRECTORY ${output_dir})
endif()
endif()

# Parse output
foreach(line ${output})
set(test ${line})
# Escape characters in test case names that would be parsed by Catch2
set(test_name ${test})
foreach(char , [ ])
string(REPLACE ${char} "\\${char}" test_name ${test_name})
endforeach(char)
# ...add output dir
if(output_dir)
string(REGEX REPLACE "[^A-Za-z0-9_]" "_" test_name_clean ${test_name})
set(output_dir_arg "--out ${output_dir}/${output_prefix}${test_name_clean}${output_suffix}")
endif()

file(RELATIVE_PATH exe_path ${CMAKE_CURRENT_BINARY_DIR} ${TEST_EXECUTABLE})

# ...and add to script
add_command(add_test
"${prefix}${test}${suffix}"
${TEST_EXECUTOR}
"${exe_path}"
"${test_name}"
${extra_args}
"${reporter_arg}"
"${output_dir_arg}"
)
add_command(set_tests_properties
"${prefix}${test}${suffix}"
PROPERTIES
${properties}
)
list(APPEND tests "${prefix}${test}${suffix}")
endforeach()
# Parse output
foreach(line ${output})
set(test ${line})
# Escape characters in test case names that would be parsed by Catch2
set(test_name ${test})
foreach(char , [ ])
string(REPLACE ${char} "\\${char}" test_name ${test_name})
endforeach(char)
# ...add output dir
if(output_dir)
string(REGEX REPLACE "[^A-Za-z0-9_]" "_" test_name_clean ${test_name})
set(output_dir_arg "--out ${output_dir}/${output_prefix}${test_name_clean}${output_suffix}")
endif()

# Create a list of all discovered tests, which users may use to e.g. set
# properties on the tests
add_command(set ${TEST_LIST} ${tests})
file(RELATIVE_PATH exe_path ${CMAKE_CURRENT_BINARY_DIR} ${TEST_EXECUTABLE})

# ...and add to script
add_command(add_test
"${prefix}${test}${suffix}"
${TEST_EXECUTOR}
"${exe_path}"
"${test_name}"
${extra_args}
"${reporter_arg}"
"${output_dir_arg}"
)
add_command(set_tests_properties
"${prefix}${test}${suffix}"
PROPERTIES
${properties}
)
list(APPEND tests "${prefix}${test}${suffix}")
endforeach()

# Create a list of all discovered tests, which users may use to e.g. set
# properties on the tests
add_command(set ${TEST_LIST} ${tests})

# Write CTest script
file(WRITE "${CTEST_FILE}" "${script}")
file(APPEND "${CTEST_FILE}" "${script}")
Loading