From afbd11eb66ddd1bdbb06e66eae27f6f8422a08e7 Mon Sep 17 00:00:00 2001 From: Tao Sang Date: Mon, 4 May 2020 18:06:34 -0400 Subject: [PATCH] Support performance tests Support performance tests while direct tests commands keep unchanged. To build performance tests, run "make build_perf". To run all performance testis, run "make perf". To run specific tests, for example, run /usr/bin/ctest -C performance -R performance_tests/perfDispatch --verbose To run individual test, for example, run performance_tests/memory/hipPerfMemMallocCpyFree Change-Id: I168c1b9ef1ec21b392d48648d0c71e8fbd37d57b [ROCm/hip commit: 6e972dd3bb94631541805b0795f286a9cf0c1339] --- projects/hip/CMakeLists.txt | 16 +++++++- projects/hip/tests/README.md | 22 +++++++++++ projects/hip/tests/hip_tests.txt | 2 +- projects/hip/tests/hit/HIT.cmake | 37 ++++++++++++------- .../memory/hipPerfMemMallocCpyFree.cpp | 2 +- .../hipPerfBufferCopyRectSpeed.cpp | 2 +- .../perfDispatch/hipPerfBufferCopySpeed.cpp | 2 +- .../perfDispatch/hipPerfDispatchSpeed.cpp | 2 +- .../perfDispatch/timer.cpp | 0 .../perfDispatch/timer.h | 0 10 files changed, 65 insertions(+), 20 deletions(-) rename projects/hip/tests/{src/Performance => performance}/memory/hipPerfMemMallocCpyFree.cpp (98%) rename projects/hip/tests/{src/Performance => performance}/perfDispatch/hipPerfBufferCopyRectSpeed.cpp (99%) rename projects/hip/tests/{src/Performance => performance}/perfDispatch/hipPerfBufferCopySpeed.cpp (99%) rename projects/hip/tests/{src/Performance => performance}/perfDispatch/hipPerfDispatchSpeed.cpp (98%) rename projects/hip/tests/{src/Performance => performance}/perfDispatch/timer.cpp (100%) rename projects/hip/tests/{src/Performance => performance}/perfDispatch/timer.h (100%) diff --git a/projects/hip/CMakeLists.txt b/projects/hip/CMakeLists.txt index 28f9daf015..db72c8dd75 100755 --- a/projects/hip/CMakeLists.txt +++ b/projects/hip/CMakeLists.txt @@ -648,15 +648,27 @@ if(${RUN_HIT} EQUAL 0) # Add tests include_directories(${HIP_SRC_PATH}/tests/src) - hit_add_directory_recursive(${HIP_SRC_PATH}/tests/src "directed_tests") + hit_add_directory_recursive(${HIP_CTEST_CONFIG_DEFAULT} ${HIP_SRC_PATH}/tests/src "directed_tests") # Add unit tests include_directories(${HIP_SRC_PATH}/tests/unit) - hit_add_directory_recursive(${HIP_SRC_PATH}/tests/unit "unit_tests") + hit_add_directory_recursive(${HIP_CTEST_CONFIG_DEFAULT} ${HIP_SRC_PATH}/tests/unit "unit_tests") + + # Add performance tests + include_directories(${HIP_SRC_PATH}/tests/performance) + hit_add_directory_recursive(${HIP_CTEST_CONFIG_PERFORMANCE} ${HIP_SRC_PATH}/tests/performance "performance_tests") # Add top-level tests to build_tests add_custom_target(build_tests DEPENDS directed_tests unit_tests) + # Add top-level tests to build performance_tests. + # To build performance tests, just run "make build_perf" + add_custom_target(build_perf DEPENDS performance_tests) + + # Add custom target: perf. + # To run performance tests, just run "make perf" + add_custom_target(perf COMMAND "${CMAKE_CTEST_COMMAND}" -C "${HIP_CTEST_CONFIG_PERFORMANCE}" -R "performance_tests/" --verbose) + # Add custom target: check add_custom_target(check COMMAND "${CMAKE_COMMAND}" --build . --target test DEPENDS build_tests) else() diff --git a/projects/hip/tests/README.md b/projects/hip/tests/README.md index 7e82f66cd6..275a25f9dd 100644 --- a/projects/hip/tests/README.md +++ b/projects/hip/tests/README.md @@ -121,6 +121,28 @@ ctest -R Memcpy ctest -R memory ``` +### Performance tests: +``` +Above tests are direct tests which are majorly used for function verification. +We also provide performance tests under tests/performance folder. + +# Build all performance tests after running "make install" under build folder: +make build_perf + +Then all performance test applications will be built into ./performance_tests folder. + +# Run all performance tests: +make perf + +# Run individual performance test: +For example, +performance_tests/memory/hipPerfMemMallocCpyFree + +# Run a specific test set: +For example, +/usr/bin/ctest -C performance -R performance_tests/perfDispatch --verbose +Here "-C performance" indicate the "performance" configuration of ctest. +``` ### If a test fails - how to debug a test diff --git a/projects/hip/tests/hip_tests.txt b/projects/hip/tests/hip_tests.txt index 67a4238520..fd08932557 100644 --- a/projects/hip/tests/hip_tests.txt +++ b/projects/hip/tests/hip_tests.txt @@ -10,4 +10,4 @@ include(${HIP_SRC_PATH}/tests/hit/HIT.cmake) # Add tests include_directories(${HIP_SRC_PATH}/tests/src) -hit_add_directory_recursive(${HIP_SRC_PATH}/tests/src "directed_tests") +hit_add_directory_recursive(${HIP_CTEST_CONFIG_DEFAULT} ${HIP_SRC_PATH}/tests/src "directed_tests") diff --git a/projects/hip/tests/hit/HIT.cmake b/projects/hip/tests/hit/HIT.cmake index be89721ce3..1677d93a20 100644 --- a/projects/hip/tests/hit/HIT.cmake +++ b/projects/hip/tests/hit/HIT.cmake @@ -1,6 +1,9 @@ include(CTest) find_package(HIP REQUIRED) +set(HIP_CTEST_CONFIG_DEFAULT "default") +set(HIP_CTEST_CONFIG_PERFORMANCE "performance") + #------------------------------------------------------------------------------- # Helper macro to parse BUILD instructions macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _clang_options _nvcc_options _link_options _exclude_platforms _exclude_runtime _exclude_compiler _depends _dir) @@ -291,22 +294,30 @@ macro(READ_FROM_MAP _map _key _value) endmacro() # Helper macro to create a test -macro(MAKE_TEST exe) +macro(MAKE_TEST _config exe) string(REPLACE " " "" smush_args ${ARGN}) set(testname ${exe}${smush_args}.tst) - add_test(NAME ${testname} COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN}) + if(${_config} STREQUAL ${HIP_CTEST_CONFIG_DEFAULT}) + add_test(NAME ${testname} COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN}) + else() + add_test(NAME ${testname} CONFIGURATIONS ${_config} COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN}) + endif() set_tests_properties(${testname} PROPERTIES PASS_REGULAR_EXPRESSION "PASSED" ENVIRONMENT HIP_PATH=${HIP_ROOT_DIR}) endmacro() -macro(MAKE_NAMED_TEST exe testname) - add_test(NAME ${testname} COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN}) +macro(MAKE_NAMED_TEST _config exe testname) + if(${_config} STREQUAL ${HIP_CTEST_CONFIG_DEFAULT}) + add_test(NAME ${testname} COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN}) + else() + add_test(NAME ${testname} CONFIGURATIONS ${_config} COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN}) + endif() set_tests_properties(${testname} PROPERTIES PASS_REGULAR_EXPRESSION "PASSED" ENVIRONMENT HIP_PATH=${HIP_ROOT_DIR}) endmacro() #------------------------------------------------------------------------------- # Macro: HIT_ADD_FILES used to scan+add multiple files for testing. file(GLOB HIP_LIB_FILES ${HIP_PATH}/lib/*) -macro(HIT_ADD_FILES _dir _label _parent) +macro(HIT_ADD_FILES _config _dir _label _parent) foreach (file ${ARGN}) # Build tests execute_process(COMMAND ${HIP_SRC_PATH}/tests/hit/parser --buildCMDs ${file} @@ -398,7 +409,7 @@ macro(HIT_ADD_FILES _dir _label _parent) elseif(${HIP_RUNTIME} IN_LIST _exclude_runtime AND ${HIP_COMPILER} IN_LIST _exclude_compiler) elseif(_exclude_test_from_build STREQUAL TRUE) else() - make_test(${_label}/${_target} ${_arguments}) + make_test(${_config} ${_label}/${_target} ${_arguments}) endif() endforeach() @@ -420,7 +431,7 @@ macro(HIT_ADD_FILES _dir _label _parent) elseif(${HIP_RUNTIME} IN_LIST _exclude_runtime AND ${HIP_COMPILER} IN_LIST _exclude_compiler) elseif(_exclude_test_from_build STREQUAL TRUE) else() - make_named_test(${_label}/${_target} ${_label}/${_testname}.tst ${_arguments}) + make_named_test(${_config} ${_label}/${_target} ${_label}/${_testname}.tst ${_arguments}) endif() endforeach() endforeach() @@ -432,16 +443,16 @@ macro(HIT_ADD_DIRECTORY _dir _label) string(REGEX REPLACE "/" "." _parent ${_label}) add_custom_target(${_parent}) file(GLOB files "${_dir}/*.c*") - hit_add_files(${_dir} ${_label} ${parent} ${files}) + hit_add_files(${HIP_CTEST_CONFIG_DEFAULT} ${_dir} ${_label} ${parent} ${files}) endmacro() # Macro: HIT_ADD_DIRECTORY_RECURSIVE to scan+add all files in a directory+subdirectories for testing -macro(HIT_ADD_DIRECTORY_RECURSIVE _dir _label) +macro(HIT_ADD_DIRECTORY_RECURSIVE _config _dir _label) execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${_label} WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) string(REGEX REPLACE "/" "." _parent ${_label}) add_custom_target(${_parent}) - if(${ARGC} EQUAL 3) - add_dependencies(${ARGV2} ${_parent}) + if(${ARGC} EQUAL 4) + add_dependencies(${ARGV3} ${_parent}) endif() file(GLOB children RELATIVE ${_dir} ${_dir}/*) set(dirlist "") @@ -449,12 +460,12 @@ macro(HIT_ADD_DIRECTORY_RECURSIVE _dir _label) if(IS_DIRECTORY ${_dir}/${child}) list(APPEND dirlist ${child}) else() - hit_add_files(${_dir} ${_label} ${_parent} ${child}) + hit_add_files(${_config} ${_dir} ${_label} ${_parent} ${child}) endif() endforeach() foreach(child ${dirlist}) string(REGEX REPLACE "/" "." _parent ${_label}) - hit_add_directory_recursive(${_dir}/${child} ${_label}/${child} ${_parent}) + hit_add_directory_recursive(${_config} ${_dir}/${child} ${_label}/${child} ${_parent}) endforeach() endmacro() diff --git a/projects/hip/tests/src/Performance/memory/hipPerfMemMallocCpyFree.cpp b/projects/hip/tests/performance/memory/hipPerfMemMallocCpyFree.cpp similarity index 98% rename from projects/hip/tests/src/Performance/memory/hipPerfMemMallocCpyFree.cpp rename to projects/hip/tests/performance/memory/hipPerfMemMallocCpyFree.cpp index f059a564a1..d58fdb381e 100644 --- a/projects/hip/tests/src/Performance/memory/hipPerfMemMallocCpyFree.cpp +++ b/projects/hip/tests/performance/memory/hipPerfMemMallocCpyFree.cpp @@ -22,7 +22,7 @@ THE SOFTWARE. #include /* HIT_START - * BUILD: %t %s ../../test_common.cpp EXCLUDE_HIP_PLATFORM nvcc + * BUILD: %t %s ../../src/test_common.cpp EXCLUDE_HIP_PLATFORM nvcc * TEST: %t * HIT_END */ diff --git a/projects/hip/tests/src/Performance/perfDispatch/hipPerfBufferCopyRectSpeed.cpp b/projects/hip/tests/performance/perfDispatch/hipPerfBufferCopyRectSpeed.cpp similarity index 99% rename from projects/hip/tests/src/Performance/perfDispatch/hipPerfBufferCopyRectSpeed.cpp rename to projects/hip/tests/performance/perfDispatch/hipPerfBufferCopyRectSpeed.cpp index 71d8ebbe0a..5000904af9 100644 --- a/projects/hip/tests/src/Performance/perfDispatch/hipPerfBufferCopyRectSpeed.cpp +++ b/projects/hip/tests/performance/perfDispatch/hipPerfBufferCopyRectSpeed.cpp @@ -7,7 +7,7 @@ #include "test_common.h" /* HIT_START - * BUILD: %t %s ../../test_common.cpp timer.cpp EXCLUDE_HIP_PLATFORM nvcc + * BUILD: %t %s ../../src/test_common.cpp timer.cpp EXCLUDE_HIP_PLATFORM nvcc * TEST: %t * HIT_END */ diff --git a/projects/hip/tests/src/Performance/perfDispatch/hipPerfBufferCopySpeed.cpp b/projects/hip/tests/performance/perfDispatch/hipPerfBufferCopySpeed.cpp similarity index 99% rename from projects/hip/tests/src/Performance/perfDispatch/hipPerfBufferCopySpeed.cpp rename to projects/hip/tests/performance/perfDispatch/hipPerfBufferCopySpeed.cpp index 239d47b347..6f284ae7fb 100644 --- a/projects/hip/tests/src/Performance/perfDispatch/hipPerfBufferCopySpeed.cpp +++ b/projects/hip/tests/performance/perfDispatch/hipPerfBufferCopySpeed.cpp @@ -7,7 +7,7 @@ #include "test_common.h" /* HIT_START - * BUILD: %t %s ../../test_common.cpp timer.cpp EXCLUDE_HIP_PLATFORM nvcc + * BUILD: %t %s ../../src/test_common.cpp timer.cpp EXCLUDE_HIP_PLATFORM nvcc * TEST: %t * HIT_END */ diff --git a/projects/hip/tests/src/Performance/perfDispatch/hipPerfDispatchSpeed.cpp b/projects/hip/tests/performance/perfDispatch/hipPerfDispatchSpeed.cpp similarity index 98% rename from projects/hip/tests/src/Performance/perfDispatch/hipPerfDispatchSpeed.cpp rename to projects/hip/tests/performance/perfDispatch/hipPerfDispatchSpeed.cpp index 3d14c7b95f..84ba73c3aa 100644 --- a/projects/hip/tests/src/Performance/perfDispatch/hipPerfDispatchSpeed.cpp +++ b/projects/hip/tests/performance/perfDispatch/hipPerfDispatchSpeed.cpp @@ -7,7 +7,7 @@ #include "test_common.h" /* HIT_START - * BUILD: %t %s ../../test_common.cpp timer.cpp EXCLUDE_HIP_PLATFORM nvcc + * BUILD: %t %s ../../src/test_common.cpp timer.cpp EXCLUDE_HIP_PLATFORM nvcc * TEST: %t * HIT_END */ diff --git a/projects/hip/tests/src/Performance/perfDispatch/timer.cpp b/projects/hip/tests/performance/perfDispatch/timer.cpp similarity index 100% rename from projects/hip/tests/src/Performance/perfDispatch/timer.cpp rename to projects/hip/tests/performance/perfDispatch/timer.cpp diff --git a/projects/hip/tests/src/Performance/perfDispatch/timer.h b/projects/hip/tests/performance/perfDispatch/timer.h similarity index 100% rename from projects/hip/tests/src/Performance/perfDispatch/timer.h rename to projects/hip/tests/performance/perfDispatch/timer.h