From 9749a10abcd232d3fa7e05dcd42e2f82d1684862 Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Tue, 13 Sep 2016 14:03:07 +0530 Subject: [PATCH] Directed tests: Refactor phase 2 - Restore HIP_BUILD_LOCAL flag. Defaults to 1. - HIP_PATH is used only when HIP_BUILD_LOCAL is 0. - HIP_PLATFORM, HCC_HOME, HIP_LIB_TYPE are passed on to HIP build. - Specifying HCC_HOME automatically sets HIP_DEVELOPER=1 for HIP build. - Always show HIP configure step output. Output is colored magenta. - Fix code indentation. Change-Id: I74f2d9c1cb04bf865313b2db6b55fda567c8e071 --- tests/src/CMakeLists.txt | 301 ++++++++++++++++++++++----------------- 1 file changed, 171 insertions(+), 130 deletions(-) diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt index 43a74910b2..2563c31bab 100644 --- a/tests/src/CMakeLists.txt +++ b/tests/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 2.6) +cmake_minimum_required(VERSION 2.6) # remove CMAKE_CXX_COMPILER entry from cache since it will be pointing to hipcc unset(CMAKE_CXX_COMPILER CACHE) @@ -9,69 +9,109 @@ project(HIP_Unit_Tests) include(CTest) set(HIPTEST_SOURCE_DIR ${PROJECT_SOURCE_DIR}) +string(ASCII 27 Esc) +set(ColorReset "${Esc}[m") +set(Red "${Esc}[31m") +set(Magenta "${Esc}[35m") + # Enable multi-gpu tests if(NOT DEFINED HIP_MULTI_GPU) set(HIP_MULTI_GPU 0 CACHE BOOL "Run tests requiring more than one GPU") endif() -# Determine HIP_PATH -if(NOT DEFINED HIP_PATH) - if(NOT DEFINED ENV{HIP_PATH}) - # We are going to use HIP source... - get_filename_component(HIP_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../.. ABSOLUTE) - execute_process( - COMMAND "${CMAKE_COMMAND}" -E remove_directory hip - OUTPUT_QUIET - ERROR_QUIET - ) - execute_process( - COMMAND "${CMAKE_COMMAND}" -E make_directory hip - OUTPUT_QUIET - ERROR_QUIET - ) - message(STATUS "Configuring HIP") - # ...so need to build HIP locally. - execute_process( - COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/hip/localbuild ${HIP_SRC_PATH} - WORKING_DIRECTORY hip - RESULT_VARIABLE hip_build_result - OUTPUT_QUIET - ERROR_QUIET - ) - if(hip_build_result) - message(FATAL_ERROR "Error configuring HIP") - else() - message(STATUS "Configuring HIP - done") - message(STATUS "Building HIP") - endif() - execute_process( - COMMAND "${CMAKE_COMMAND}" --build . --target install - WORKING_DIRECTORY hip - RESULT_VARIABLE hip_build_result - OUTPUT_VARIABLE hip_build_log - ERROR_QUIET - ) - if(hip_build_result) - message(${hip_build_log}) - message(FATAL_ERROR "Error building HIP") - else() - # Building HIP is successful. Point HIP_PATH to this location. - message(STATUS "Building HIP - done") - get_filename_component(HIP_PATH ${CMAKE_CURRENT_BINARY_DIR}/hip/localbuild ABSOLUTE) - endif() - # Add a target to rebuild HIP if HIP source changes. - add_custom_target( - hip ALL - COMMAND "${CMAKE_COMMAND}" --build . --target install - WORKING_DIRECTORY hip - ) +# Determine HIP_BUILD_LOCAL +if(NOT DEFINED HIP_BUILD_LOCAL) + if(NOT DEFINED ENV{HIP_BUILD_LOCAL}) + set(HIP_BUILD_LOCAL 1 CACHE BOOL "Build HIP in local folder") else() - # We are using HIP_PATH from env. So just create a fake target. - set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to installed HIP") - add_custom_target(hip ALL) + set(HIP_BUILD_LOCAL $ENV{HIP_BUILD_LOCAL} CACHE BOOL "Build HIP in local folder") endif() +endif() + +# Determine HIP_PATH +if(HIP_BUILD_LOCAL) + # We are going to use HIP source... + get_filename_component(HIP_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../.. ABSOLUTE) + + # ...so we first need to determine the options to cascade to HIP build. + if(DEFINED HIP_PLATFORM) + set(ENV{HIP_PLATFORM} ${HIP_PLATFORM}) + endif() + if(DEFINED HCC_HOME) + get_filename_component(HCC_HOME ${HCC_HOME} ABSOLUTE) + set(ENV{HCC_HOME} ${HCC_HOME}) + set(ENV{HIP_DEVELOPER} 1) + endif() + if(DEFINED HIP_LIB_TYPE) + set(ENV{HIP_LIB_TYPE} ${HIP_LIB_TYPE}) + endif() + + # Purge previous HIP installation... + execute_process( + COMMAND "${CMAKE_COMMAND}" -E remove_directory hip + OUTPUT_QUIET + ERROR_QUIET + ) + execute_process( + COMMAND "${CMAKE_COMMAND}" -E make_directory hip + OUTPUT_QUIET + ERROR_QUIET + ) + message(STATUS "Configuring HIP") + + # ...and now build HIP locally. + execute_process( + COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/hip/localbuild ${HIP_SRC_PATH} + WORKING_DIRECTORY hip + RESULT_VARIABLE hip_build_result + OUTPUT_VARIABLE hip_build_log + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + message("${Magenta}${hip_build_log}${ColorReset}") + + if(hip_build_result) + message(FATAL_ERROR "Error configuring HIP") + else() + message(STATUS "Configuring HIP - done") + message(STATUS "Building HIP") + endif() + execute_process( + COMMAND "${CMAKE_COMMAND}" --build . --target install + WORKING_DIRECTORY hip + RESULT_VARIABLE hip_build_result + OUTPUT_VARIABLE hip_build_log + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + + # Show HIP build errors if any. + if(hip_build_result) + message("${Red}${hip_build_log}${ColorReset}") + message(FATAL_ERROR "Error building HIP") + else() + # Building HIP is successful. Point HIP_PATH to this location. + message(STATUS "Building HIP - done") + get_filename_component(HIP_PATH ${CMAKE_CURRENT_BINARY_DIR}/hip/localbuild ABSOLUTE) + endif() + + # Add a target to rebuild HIP if HIP source changes. + add_custom_target( + hip ALL + COMMAND "${CMAKE_COMMAND}" --build . --target install + WORKING_DIRECTORY hip + ) else() - # We are using HIP_PATH passed to cmake. So just create a fake target. + if(NOT DEFINED HIP_PATH) + if(NOT DEFINED ENV{HIP_PATH}) + # We set to to default HIP installation path. + set(HIP_PATH /opt/rocm/hip CACHE PATH "Path to installed HIP") + else() + # We are using HIP_PATH from env. + set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to installed HIP") + endif() + endif() + # Create a fake target since we are using an installed HIP. add_custom_target(hip ALL) endif() MESSAGE("HIP_PATH=" ${HIP_PATH}) @@ -80,123 +120,123 @@ MESSAGE("HIP_PATH=" ${HIP_PATH}) execute_process(COMMAND ${HIP_PATH}/bin/hipconfig --platform OUTPUT_VARIABLE HIP_PLATFORM) if(${HIP_PLATFORM} STREQUAL "hcc") - MESSAGE("HIP_PLATFORM=hcc") + MESSAGE("HIP_PLATFORM=hcc") elseif(${HIP_PLATFORM} STREQUAL "nvcc") - MESSAGE("HIP_PLATFORM=nvcc") + MESSAGE("HIP_PLATFORM=nvcc") - #Need C++11 for threads in some of the tests. - add_definitions(-std=c++11) + #Need C++11 for threads in some of the tests. + add_definitions(-std=c++11) - # NVCC does not not support -rdynamic option - set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS ) - set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS ) + # NVCC does not not support -rdynamic option + set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) + set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS) else() - MESSAGE(FATAL_ERROR "UNKNOWN HIP_PLATFORM=" ${HIP_PLATFORM}) + MESSAGE(FATAL_ERROR "UNKNOWN HIP_PLATFORM=" ${HIP_PLATFORM}) endif() set(HIPCC ${HIP_PATH}/bin/hipcc) set(CMAKE_CXX_COMPILER ${HIPCC} CACHE FILEPATH "CXX Compiler" FORCE) -add_library(test_common OBJECT test_common.cpp ) +add_library(test_common OBJECT test_common.cpp) -# usage : build_hip_executable (exe_name CPP_FILES) -macro (build_hip_executable exe cpp) - add_executable (${exe} ${cpp} ${ARGN} $ ) +# usage : build_hip_executable(exe_name CPP_FILES) +macro(build_hip_executable exe cpp) + add_executable(${exe} ${cpp} ${ARGN} $) add_dependencies(${exe} hip) endmacro() # Make a hip executable, using libc++ -macro (build_hip_executable_libcpp exe cpp) - build_hip_executable( ${exe} ${cpp} ${ARGN} ) - if (${HIP_PLATFORM} STREQUAL "hcc") - set_source_files_properties (${cpp} i${ARGN} PROPERTIES COMPILE_FLAGS --stdlib=libc++ ) +macro(build_hip_executable_libcpp exe cpp) + build_hip_executable( ${exe} ${cpp} ${ARGN}) + if(${HIP_PLATFORM} STREQUAL "hcc") + set_source_files_properties(${cpp} i${ARGN} PROPERTIES COMPILE_FLAGS --stdlib=libc++) endif() endmacro() -function (make_named_test exe testname ) - add_test (NAME ${testname} - COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN} - ) - set_tests_properties (${testname} - PROPERTIES PASS_REGULAR_EXPRESSION "PASSED" - ) +function(make_named_test exe testname) + add_test(NAME ${testname} + COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN} + ) + set_tests_properties(${testname} + PROPERTIES PASS_REGULAR_EXPRESSION "PASSED" + ) endfunction() -macro (make_test exe ) - string (REPLACE " " "" smush_args ${ARGN}) - set (testname ${PROJECT_NAME}/${exe}${smush_args}.tst) +macro(make_test exe) + string(REPLACE " " "" smush_args ${ARGN}) + set(testname ${PROJECT_NAME}/${exe}${smush_args}.tst) - make_named_test(${exe} ${testname} ${ARGN}) + make_named_test(${exe} ${testname} ${ARGN}) endmacro() -macro (make_hipify_test sourceFile ) - #string (REPLACE " " "" smush_args ${ARGN}) - set (testname ${sourceFile}${smush_args}.tst) +macro(make_hipify_test sourceFile) + #string(REPLACE " " "" smush_args ${ARGN}) + set(testname ${sourceFile}${smush_args}.tst) - add_test (NAME ${testname} - COMMAND ${HIP_PATH}/bin/hipify ${PROJECT_SOURCE_DIR}/${sourceFile} ${ARGN} - ) + add_test(NAME ${testname} + COMMAND ${HIP_PATH}/bin/hipify ${PROJECT_SOURCE_DIR}/${sourceFile} ${ARGN} + ) endmacro() -macro (make_test_matches exe match_string) - string (REPLACE " " "" smush_args ${ARGN}) - set (testname ${exe}${smush_args}.tst) - add_test (NAME ${testname} - COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN} - ) - set_tests_properties (${testname} - PROPERTIES PASS_REGULAR_EXPRESSION ${match_string} - ) +macro(make_test_matches exe match_string) + string(REPLACE " " "" smush_args ${ARGN}) + set(testname ${exe}${smush_args}.tst) + add_test(NAME ${testname} + COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN} + ) + set_tests_properties(${testname} + PROPERTIES PASS_REGULAR_EXPRESSION ${match_string} + ) endmacro() -macro (build_hip_executable_sm35 exe cpp) - build_hip_executable( ${exe} ${cpp} ${ARGN} ) - if (${HIP_PLATFORM} STREQUAL "nvcc") - set_source_files_properties (${cpp} i${ARGN} PROPERTIES COMPILE_FLAGS --gpu-architecture=sm_35 ) - endif() +macro(build_hip_executable_sm35 exe cpp) + build_hip_executable( ${exe} ${cpp} ${ARGN}) + if(${HIP_PLATFORM} STREQUAL "nvcc") + set_source_files_properties(${cpp} i${ARGN} PROPERTIES COMPILE_FLAGS --gpu-architecture=sm_35) + endif() endmacro() -build_hip_executable (hipGetDeviceAttribute hipGetDeviceAttribute.cpp) -build_hip_executable (hipEnvVar hipEnvVar.cpp) -build_hip_executable (hipEnvVarDriver hipEnvVarDriver.cpp) -build_hip_executable (hipEventRecord hipEventRecord.cpp) +build_hip_executable(hipGetDeviceAttribute hipGetDeviceAttribute.cpp) +build_hip_executable(hipEnvVar hipEnvVar.cpp) +build_hip_executable(hipEnvVarDriver hipEnvVarDriver.cpp) +build_hip_executable(hipEventRecord hipEventRecord.cpp) -build_hip_executable_libcpp (hipHcc hipHcc.cpp) -#set_source_files_properties (hipHcc.cpp PROPERTIES COMPILE_FLAGS --stdlib=libc++ ) +build_hip_executable_libcpp(hipHcc hipHcc.cpp) +#set_source_files_properties(hipHcc.cpp PROPERTIES COMPILE_FLAGS --stdlib=libc++) # __workweek fix. -#build_hip_executable_libcpp (hipPointerAttrib hipPointerAttrib.cpp) -build_hip_executable (hipHostAlloc hipHostAlloc.cpp) -build_hip_executable (hipHostGetFlags hipHostGetFlags.cpp) -build_hip_executable (hipHostRegister hipHostRegister.cpp) -build_hip_executable (hipRandomMemcpyAsync hipRandomMemcpyAsync.cpp) -build_hip_executable (hipFuncSetDeviceFlags hipFuncSetDeviceFlags.cpp) -build_hip_executable (hipFuncGetDevice hipFuncGetDevice.cpp) -build_hip_executable (hipFuncSetDevice hipFuncSetDevice.cpp) -build_hip_executable (hipFuncDeviceSynchronize hipFuncDeviceSynchronize.cpp) -build_hip_executable (hipPeerToPeer_simple hipPeerToPeer_simple.cpp) -build_hip_executable (hipTestMemcpyPin hipTestMemcpyPin.cpp) -build_hip_executable (hipDynamicShared hipDynamicShared.cpp) -build_hip_executable (hipLaunchParm hipLaunchParm.cpp) +#build_hip_executable_libcpp(hipPointerAttrib hipPointerAttrib.cpp) +build_hip_executable(hipHostAlloc hipHostAlloc.cpp) +build_hip_executable(hipHostGetFlags hipHostGetFlags.cpp) +build_hip_executable(hipHostRegister hipHostRegister.cpp) +build_hip_executable(hipRandomMemcpyAsync hipRandomMemcpyAsync.cpp) +build_hip_executable(hipFuncSetDeviceFlags hipFuncSetDeviceFlags.cpp) +build_hip_executable(hipFuncGetDevice hipFuncGetDevice.cpp) +build_hip_executable(hipFuncSetDevice hipFuncSetDevice.cpp) +build_hip_executable(hipFuncDeviceSynchronize hipFuncDeviceSynchronize.cpp) +build_hip_executable(hipPeerToPeer_simple hipPeerToPeer_simple.cpp) +build_hip_executable(hipTestMemcpyPin hipTestMemcpyPin.cpp) +build_hip_executable(hipDynamicShared hipDynamicShared.cpp) +build_hip_executable(hipLaunchParm hipLaunchParm.cpp) -if (${HIP_PLATFORM} STREQUAL "hcc") - build_hip_executable (hipArray hipArray.cpp) +if(${HIP_PLATFORM} STREQUAL "hcc") + build_hip_executable(hipArray hipArray.cpp) endif() make_test(hipEventRecord --iterations 10) -make_test(hipEnvVarDriver " " ) +make_test(hipEnvVarDriver " ") make_test(hipLaunchParm " ") #TODO -reenable -#make_test(hipPointerAttrib " " ) +#make_test(hipPointerAttrib " ") make_test(hipHostAlloc " ") # BS- comment out since test appears broken - asks for device pointer but pointer was never allocated. #make_test(hipHostGetFlags " ") -make_test(hipHcc " " ) +make_test(hipHcc " ") make_test(hipHostRegister " ") make_test(hipRandomMemcpyAsync " ") make_test(hipFuncSetDeviceFlags " ") @@ -204,20 +244,20 @@ make_test(hipFuncGetDevice " ") make_test(hipFuncDeviceSynchronize " ") make_test(hipTestMemcpyPin " ") -if (${HIP_MULTI_GPU}) +if(${HIP_MULTI_GPU}) make_test(hipPeerToPeer_simple " ") # use current device for copy, this fails. make_test(hipPeerToPeer_simple --memcpyWithPeer) make_test(hipPeerToPeer_simple --mirrorPeers) # mirror mapping: test to ensure mirror doesn't destroy orig mapping. endif() -if (${HIP_PLATFORM} STREQUAL "hcc") +if(${HIP_PLATFORM} STREQUAL "hcc") make_test(hipArray " ") make_test(hipFuncSetDevice " ") make_test(hipDynamicShared " ") endif() -make_hipify_test(specialFunc.cu ) +make_hipify_test(specialFunc.cu) # Add subdirs here: @@ -225,3 +265,4 @@ add_subdirectory(context) add_subdirectory(deviceLib) add_subdirectory(runtimeApi) add_subdirectory(kernel) +# vim: ts=4:sw=4:expandtab:smartindent