Directed tests: Refactor phase 1 - build HIP the right way

Change-Id: I8fcd2bcb01b12878878f50777e2cf0095fae61a1
This commit is contained in:
Maneesh Gupta
2016-09-08 17:20:38 +05:30
والد 8022671a5e
کامیت f9c3e759e9
+72 -72
مشاهده پرونده
@@ -2,74 +2,86 @@ 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)
message (CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER} )
# remove HIP_PATH entry from cache since we might be running tests with a different configuration
unset(HIP_PATH CACHE)
project (HIP_Unit_Tests)
project(HIP_Unit_Tests)
include(CTest)
set(HIPTEST_SOURCE_DIR ${PROJECT_SOURCE_DIR})
#include_directories( ${PROJECT_SOURCE_DIR}/include )
set (HIPTEST_SOURCE_DIR ${PROJECT_SOURCE_DIR} )
# The version number.
set (HIP_Unit_Test_VERSION_MAJOR 1)
set (HIP_Unit_Test_VERSION_MINOR 0)
# 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()
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")
# 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_QUIET
ERROR_QUIET
)
if(hip_build_result)
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()
set(HIP_BUILD_LOCAL $ENV{HIP_BUILD_LOCAL} CACHE BOOL "Build HIP in local folder")
# 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)
endif()
else()
# We are using HIP_PATH passed to cmake. So just create a fake target.
add_custom_target(hip ALL)
endif()
MESSAGE("HIP_PATH=" ${HIP_PATH})
set(HIP_PATH $ENV{HIP_PATH})
if (NOT DEFINED HIP_PATH)
get_filename_component (HIP_PATH ../.. ABSOLUTE)
endif()
# Determine HIP_PLATFORM
execute_process(COMMAND ${HIP_PATH}/bin/hipconfig --platform OUTPUT_VARIABLE HIP_PLATFORM)
MESSAGE ("HIP_PATH=" ${HIP_PATH})
if (${HIP_PLATFORM} STREQUAL "hcc")
MESSAGE ("HIP_PLATFORM=hcc")
set (HSA_PATH $ENV{HSA_PATH})
if (NOT DEFINED HSA_PATH)
set (HSA_PATH /opt/rocm/hsa)
endif()
set (CODEXL_PATH $ENV{CODEXL_PATH})
if (NOT DEFINED CODEXL_PATH)
set (CODEXL_PATH /opt/AMD/CodeXL)
endif()
set (CODEXL_SDK_ATAL_PATH ${CODEXL_PATH}/SDK/AMDTActivityLogger)
#---
# Add HSA library:
add_library(hsa-runtime64 SHARED IMPORTED)
set_property(TARGET hsa-runtime64 PROPERTY IMPORTED_LOCATION "${HSA_PATH}/lib/libhsa-runtime64.so")
#These includes are used for all files.
#Include HIP and HC since the tests need both of these:
include_directories(${HIP_PATH}/include)
# This will create a subdir "hip_hcc" in the test build directory
# Any changes to hip_hcc source will be detected and force the library and then the tests to be rebuilt.
if (${HIP_BUILD_LOCAL})
add_subdirectory(${HIP_PATH} build.hip_hcc)
#link_directories(${CMAKE_CURRENT_BINARY_DIR}/build.hip_hcc) # search the local hip_hcc for libhip_hcc.a
set (CMAKE_CXX_FLAGS --hipcc_explicit_lib)
endif()
elseif (${HIP_PLATFORM} STREQUAL "nvcc")
MESSAGE ("HIP_PLATFORM=nvcc")
if(${HIP_PLATFORM} STREQUAL "hcc")
MESSAGE("HIP_PLATFORM=hcc")
elseif(${HIP_PLATFORM} STREQUAL "nvcc")
MESSAGE("HIP_PLATFORM=nvcc")
#Need C++11 for threads in some of the tests.
add_definitions(-std=c++11)
@@ -77,33 +89,21 @@ elseif (${HIP_PLATFORM} STREQUAL "nvcc")
# 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)
set(HIPCC ${HIP_PATH}/bin/hipcc)
set(CMAKE_CXX_COMPILER ${HIPCC} CACHE FILEPATH "CXX Compiler" FORCE)
add_library(test_common OBJECT test_common.cpp )
# usage : build_hip_executable (exe_name CPP_FILES)
macro (build_hip_executable exe cpp)
if (${HIP_PLATFORM} STREQUAL "hcc")
if (${HIP_BUILD_LOCAL})
#target_link_libraries(${exe} hip_hcc)
add_executable (${exe} ${cpp} ${ARGN} $<TARGET_OBJECTS:test_common> $<TARGET_OBJECTS:hip_hcc> )
else()
add_executable (${exe} ${cpp} ${ARGN} $<TARGET_OBJECTS:test_common> )
endif()
else()
add_executable (${exe} ${cpp} ${ARGN} $<TARGET_OBJECTS:test_common> )
endif()
add_executable (${exe} ${cpp} ${ARGN} $<TARGET_OBJECTS:test_common> )
add_dependencies(${exe} hip)
endmacro()
# Make a hip executable, using libc++
macro (build_hip_executable_libcpp exe cpp)
build_hip_executable( ${exe} ${cpp} ${ARGN} )