From d3e2bbc791aad079769944532be53ec905054411 Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Wed, 14 Aug 2019 11:30:42 +0000 Subject: [PATCH] [hit] Add support for specifying dependencies in HIT syntax (#1323) --- tests/README.md | 7 +++++-- tests/hit/HIT.cmake | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/tests/README.md b/tests/README.md index 0c2c645085..e8f8116049 100644 --- a/tests/README.md +++ b/tests/README.md @@ -47,7 +47,7 @@ In the above, BUILD commands provide instructions on how to build the test case The supported syntax for the BUILD command is: ``` -BUILD: %t %s HIPCC_OPTIONS HCC_OPTIONS NVCC_OPTIONS EXCLUDE_HIP_PLATFORM +BUILD: %t %s HIPCC_OPTIONS HCC_OPTIONS NVCC_OPTIONS EXCLUDE_HIP_PLATFORM DEPENDS ``` %s: refers to current source file name. Additional source files needed for the test can be specified by name (including relative path). %t: refers to target executable named derived by removing the extension from the current source file. Alternatively a target executable name can be specified. @@ -55,13 +55,14 @@ HIPCC_OPTIONS: All options specified after this delimiter are passed to hipcc on HCC_OPTIONS: All options specified after this delimiter are passed to hipcc on HCC platform only. NVCC_OPTIONS: All options specified after this delimiter are passed to hipcc on NVCC platform only. EXCLUDE_HIP_PLATFORM: This can be used to exclude a test case from HCC, NVCC or both platforms. +DEPENDS: This can be used to specify dependencies that need to be built before building the current target. #### BUILD_CMD command The supported syntax for the BUILD_CMD command is: ``` -BUILD_CMD: EXCLUDE_HIP_PLATFORM +BUILD_CMD: EXCLUDE_HIP_PLATFORM DEPENDS ``` %s: refers to current source file name. Additional source files needed for the test can be specified by name (including relative path). %t: refers to target executable named derived by removing the extension from the current source file. Alternatively a target executable name can be specified. @@ -71,6 +72,8 @@ BUILD_CMD: EXCLUDE_HIP_PLATFORM %cxx: refers to system c compiler pointed to by /usr/bin/c++. %S: refers to path to current source file. %T: refers to path to current build target. +EXCLUDE_HIP_PLATFORM: This can be used to exclude a test case from HCC, NVCC or both platforms. +DEPENDS: This can be used to specify dependencies that need to be built before building the current target. #### TEST command diff --git a/tests/hit/HIT.cmake b/tests/hit/HIT.cmake index d446742dd1..3d8607f0f5 100644 --- a/tests/hit/HIT.cmake +++ b/tests/hit/HIT.cmake @@ -3,7 +3,7 @@ find_package(HIP REQUIRED) #------------------------------------------------------------------------------- # Helper macro to parse BUILD instructions -macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_options _link_options _exclude_platforms _dir) +macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_options _link_options _exclude_platforms _depends _dir) set(${_target}) set(${_sources}) set(${_hipcc_options}) @@ -11,12 +11,14 @@ macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_opt set(${_nvcc_options}) set(${_link_options}) set(${_exclude_platforms}) + set(${_depends}) set(_target_found FALSE) set(_hipcc_options_found FALSE) set(_hcc_options_found FALSE) set(_nvcc_options_found FALSE) set(_link_options_found FALSE) set(_exclude_platforms_found FALSE) + set(_depends_found FALSE) foreach(arg ${ARGN}) if(NOT _target_found) set(_target_found TRUE) @@ -27,30 +29,42 @@ macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_opt set(_nvcc_options_found FALSE) set(_link_options_found FALSE) set(_exclude_platforms_found FALSE) + set(_depends_found FALSE) elseif("x${arg}" STREQUAL "xHCC_OPTIONS") set(_hipcc_options_found FALSE) set(_hcc_options_found TRUE) set(_nvcc_options_found FALSE) set(_link_options_found FALSE) set(_exclude_platforms_found FALSE) + set(_depends_found FALSE) elseif("x${arg}" STREQUAL "xNVCC_OPTIONS") set(_hipcc_options_found FALSE) set(_hcc_options_found FALSE) set(_nvcc_options_found TRUE) set(_link_options_found FALSE) set(_exclude_platforms_found FALSE) + set(_depends_found FALSE) elseif("x${arg}" STREQUAL "xLINK_OPTIONS") set(_hipcc_options_found FALSE) set(_hcc_options_found FALSE) set(_nvcc_options_found FALSE) set(_link_options_found TRUE) set(_exclude_platforms_found FALSE) + set(_depends_found FALSE) elseif("x${arg}" STREQUAL "xEXCLUDE_HIP_PLATFORM") set(_hipcc_options_found FALSE) set(_hcc_options_found FALSE) set(_nvcc_options_found FALSE) set(_link_options_found FALSE) set(_exclude_platforms_found TRUE) + set(_depends_found FALSE) + elseif("x${arg}" STREQUAL "xDEPENDS") + set(_hipcc_options_found FALSE) + set(_hcc_options_found FALSE) + set(_nvcc_options_found FALSE) + set(_link_options_found FALSE) + set(_exclude_platforms_found FALSE) + set(_depends_found TRUE) else() if(_hipcc_options_found) list(APPEND ${_hipcc_options} ${arg}) @@ -62,6 +76,8 @@ macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_opt list(APPEND ${_link_options} ${arg}) elseif(_exclude_platforms_found) set(${_exclude_platforms} ${arg}) + elseif(_depends_found) + list(APPEND ${_depends} ${arg}) else() list(APPEND ${_sources} "${_dir}/${arg}") endif() @@ -70,21 +86,29 @@ macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_opt endmacro() # Helper macro to parse CUSTOM BUILD instructions -macro(PARSE_CUSTOMBUILD_COMMAND _target _buildcmd _exclude_platforms) +macro(PARSE_CUSTOMBUILD_COMMAND _target _buildcmd _exclude_platforms _depends) set(${_target}) set(${_buildcmd} " ") set(${_exclude_platforms}) + set(${_depends}) set(_target_found FALSE) set(_exclude_platforms_found FALSE) + set(_depends_found FALSE) foreach(arg ${ARGN}) if(NOT _target_found) set(_target_found TRUE) set(${_target} ${arg}) elseif("x${arg}" STREQUAL "xEXCLUDE_HIP_PLATFORM") set(_exclude_platforms_found TRUE) + set(_depends_found FALSE) + elseif("x${arg}" STREQUAL "xDEPENDS") + set(_exclude_platforms_found FALSE) + set(_depends_found TRUE) else() if(_exclude_platforms_found) set(${_exclude_platforms} ${arg}) + elseif(_depends_found) + list(APPEND ${_depends} ${arg}) else() list(APPEND ${_buildcmd} ${arg}) endif() @@ -179,7 +203,7 @@ macro(HIT_ADD_FILES _dir _label _parent) string(REGEX REPLACE "\n" ";" _contents "${_contents}") foreach(_cmd ${_contents}) string(REGEX REPLACE " " ";" _cmd "${_cmd}") - parse_build_command(_target _sources _hipcc_options _hcc_options _nvcc_options _link_options _exclude_platforms ${_dir} ${_cmd}) + parse_build_command(_target _sources _hipcc_options _hcc_options _nvcc_options _link_options _exclude_platforms _depends ${_dir} ${_cmd}) string(REGEX REPLACE "/" "." target ${_label}/${_target}) insert_into_map("_exclude" "${target}" "${_exclude_platforms}") if(_exclude_platforms STREQUAL "all" OR _exclude_platforms STREQUAL ${HIP_PLATFORM}) @@ -190,6 +214,10 @@ macro(HIT_ADD_FILES _dir _label _parent) target_link_libraries(${target} PRIVATE ${_link_options}) set_target_properties(${target} PROPERTIES OUTPUT_NAME ${_target} RUNTIME_OUTPUT_DIRECTORY ${_label} LINK_DEPENDS "${HIP_LIB_FILES}") add_dependencies(${_parent} ${target}) + foreach(_dependency ${_depends}) + string(REGEX REPLACE "/" "." _dependency ${_label}/${_dependency}) + add_dependencies(${target} ${_dependency}) + endforeach() endif() endforeach() @@ -208,7 +236,7 @@ macro(HIT_ADD_FILES _dir _label _parent) string(REGEX REPLACE "%T" ${_label} _contents "${_contents}") foreach(_cmd ${_contents}) string(REGEX REPLACE " " ";" _cmd "${_cmd}") - parse_custombuild_command(_target _buildcmd _exclude_platforms ${_cmd}) + parse_custombuild_command(_target _buildcmd _exclude_platforms _depends ${_cmd}) string(REGEX REPLACE "/" "." target ${_label}/${_target}) insert_into_map("_exclude" "${target}" "${_exclude_platforms}") if(_exclude_platforms STREQUAL "all" OR _exclude_platforms STREQUAL ${HIP_PLATFORM}) @@ -219,6 +247,10 @@ macro(HIT_ADD_FILES _dir _label _parent) #add_custom_target(${target} COMMAND ${buildscript}) add_custom_target(${target} COMMAND sh -c "${_buildcmd}") add_dependencies(${_parent} ${target}) + foreach(_dependency ${_depends}) + string(REGEX REPLACE "/" "." _dependency ${_label}/${_dependency}) + add_dependencies(${target} ${_dependency}) + endforeach() endif() endforeach()