diff --git a/projects/rocr-runtime/runtime/cmake_modules/utils.cmake b/projects/rocr-runtime/runtime/cmake_modules/utils.cmake index 5b4e73ce23..77e4411312 100644 --- a/projects/rocr-runtime/runtime/cmake_modules/utils.cmake +++ b/projects/rocr-runtime/runtime/cmake_modules/utils.cmake @@ -40,6 +40,59 @@ ## ################################################################################ +function( get_path LIB CACHED_PATH HELP ) + + set( options "") + set( oneValueArgs RESULT ) + set( multiValueArgs HINTS NAMES ) + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + + # Search for canary file. + if( ${LIB} ) + find_library( FULLPATH NAMES ${ARGS_NAMES} HINTS ${${CACHED_PATH}} ${ARGS_HINTS} ) + else() + find_file( FULLPATH NAMES ${ARGS_NAMES} HINTS ${${CACHED_PATH}} ${ARGS_HINTS} ) + endif() + set( RESULT (NOT ${FULLPATH} MATCHES NOTFOUND) ) + + # Extract path + get_filename_component ( DIRPATH ${FULLPATH} DIRECTORY ) + + # Check path against cache + if( NOT "${${CACHED_PATH}}" STREQUAL "" ) + if ( NOT "${${CACHED_PATH}}" STREQUAL "${DIRPATH}" ) + message(WARNING "${CACHED_PATH} may be incorrect." ) + set( DIRPATH ${${CACHED_PATH}} ) + endif() + elseif(NOT ${RESULT}) + message(WARNING "${CACHED_PATH} not located during path search.") + endif() + + # Set cache variable and help text + set( ${CACHED_PATH} ${DIRPATH} CACHE PATH ${HELP} FORCE ) + unset( FULLPATH CACHE ) + + # Return success flag + if( NOT ${ARGS_RESULT} STREQUAL "" ) + set( ${ARGS_RESULT} ${RESULT} PARENT_SCOPE) + endif() + +endfunction() + +## Searches for a file using include paths and stores the path to that file in the cache +## using the cached value if set. Search paths are optional. Returns success in RESULT. +## get_include_path( NAMES name1 [name2...] [HINTS path1 [path2 ... ENV var]] [RESULT ] +macro( get_include_path CACHED_PATH HELP ) + get_path( 0 ${ARGV} ) +endmacro() + +## Searches for a file using library paths and stores the path to that file in the cache +## using the cached value if set. Search paths are optional. Returns success in RESULT. +## get_library_path( NAMES name1 [name2...] [HINTS path1 [path2 ... ENV var]] [RESULT ] +macro( get_library_path CACHED_PATH HELP ) + get_path( 1 ${ARGV} ) +endmacro() + ## Parses the VERSION_STRING variable and places ## the first, second and third number values in ## the major, minor and patch variables. @@ -58,27 +111,18 @@ function( parse_version VERSION_STRING ) if ( ${VERSION_COUNT} GREATER 0) list ( GET VERSIONS 0 MAJOR ) set ( VERSION_MAJOR ${MAJOR} PARENT_SCOPE ) - set ( TEMP_VERSION_STRING "${MAJOR}" ) endif () if ( ${VERSION_COUNT} GREATER 1 ) list ( GET VERSIONS 1 MINOR ) set ( VERSION_MINOR ${MINOR} PARENT_SCOPE ) - set ( TEMP_VERSION_STRING "${TEMP_VERSION_STRING}.${MINOR}" ) endif () if ( ${VERSION_COUNT} GREATER 2 ) list ( GET VERSIONS 2 PATCH ) set ( VERSION_PATCH ${PATCH} PARENT_SCOPE ) - set ( TEMP_VERSION_STRING "${TEMP_VERSION_STRING}.${PATCH}" ) endif () - if ( DEFINED VERSION_BUILD ) - set ( VERSION_BUILD "${VERSION_BUILD}" PARENT_SCOPE ) - endif () - - set ( VERSION_STRING "${TEMP_VERSION_STRING}" PARENT_SCOPE ) - endfunction () ## Gets the current version of the repository @@ -87,30 +131,77 @@ endfunction () ## and a library version string. function ( get_version DEFAULT_VERSION_STRING ) - parse_version ( ${DEFAULT_VERSION_STRING} ) + set( VERSION_JOB "local-build" ) + set( VERSION_COMMIT_COUNT 0 ) + set( VERSION_HASH "unknown" ) - find_program ( GIT NAMES git ) + find_program( GIT NAMES git ) - if ( GIT ) + if( GIT ) - execute_process ( COMMAND git describe --dirty --long --match [0-9]* - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_TAG_STRING - OUTPUT_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE RESULT ) + #execute_process ( COMMAND git describe --tags --dirty --long + # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + # OUTPUT_VARIABLE GIT_TAG_STRING + # OUTPUT_STRIP_TRAILING_WHITESPACE + # RESULT_VARIABLE RESULT ) - if ( ${RESULT} EQUAL 0 ) + # Get branch commit (common ancestor) of current branch and master branch. + execute_process(COMMAND git merge-base HEAD origin/HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_MERGE_BASE + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RESULT ) - parse_version ( ${GIT_TAG_STRING} ) + if( ${RESULT} EQUAL 0 ) + # Count commits from branch point. + execute_process(COMMAND git rev-list --count ${GIT_MERGE_BASE}..HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE VERSION_COMMIT_COUNT + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RESULT ) + if(NOT ${RESULT} EQUAL 0 ) + set( VERSION_COMMIT_COUNT 0 ) + endif() + endif() - endif () + # Get current short hash. + execute_process(COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE VERSION_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RESULT ) + if( ${RESULT} EQUAL 0 ) + # Check for dirty workspace. + execute_process(COMMAND git diff --quiet + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE RESULT ) + if(${RESULT} EQUAL 1) + set(VERSION_HASH "${VERSION_HASH}-dirty") + endif() + else() + set( VERSION_HASH "unknown" ) + endif() + endif() - endif () + # Build automation IDs + if(DEFINED ENV{ROCM_BUILD_ID}) + set( VERSION_JOB $ENV{ROCM_BUILD_ID} ) + endif() + + parse_version(${DEFAULT_VERSION_STRING}) - set( VERSION_STRING "${VERSION_STRING}" PARENT_SCOPE ) set( VERSION_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE ) set( VERSION_MINOR "${VERSION_MINOR}" PARENT_SCOPE ) set( VERSION_PATCH "${VERSION_PATCH}" PARENT_SCOPE ) - set( VERSION_BUILD "${VERSION_BUILD}" PARENT_SCOPE ) + set( VERSION_COMMIT_COUNT "${VERSION_COMMIT_COUNT}" PARENT_SCOPE ) + set( VERSION_HASH "${VERSION_HASH}" PARENT_SCOPE ) + set( VERSION_JOB "${VERSION_JOB}" PARENT_SCOPE ) + + #message("${VERSION_MAJOR}" ) + #message("${VERSION_MINOR}" ) + #message("${VERSION_PATCH}" ) + #message("${VERSION_COMMIT_COUNT}") + #message("${VERSION_HASH}") + #message("${VERSION_JOB}") endfunction() diff --git a/projects/rocr-runtime/runtime/hsa-ext-image/CMakeLists.txt b/projects/rocr-runtime/runtime/hsa-ext-image/CMakeLists.txt index ef87e16491..16b81e316c 100755 --- a/projects/rocr-runtime/runtime/hsa-ext-image/CMakeLists.txt +++ b/projects/rocr-runtime/runtime/hsa-ext-image/CMakeLists.txt @@ -1,20 +1,22 @@ cmake_minimum_required ( VERSION 3.5.0 ) -## Verbose output. -set ( CMAKE_VERBOSE_MAKEFILE on ) - -## Determine external build folder. -if( "${CMAKE_BUILD_TYPE}" STREQUAL Release ) - set( BUILD_FOLDER "lnx64a/B_rel" ) -else() - set( BUILD_FOLDER "lnx64a/B_dbg" ) -endif() - ## Set ext runtime module name and project name. set ( IMAGE_NAME "hsa-ext-image" ) set ( IMAGE_TARGET "${IMAGE_NAME}64" ) +set ( IMAGE_LIBRARY "lib${IMAGE_TARGET}" ) project ( ${IMAGE_TARGET} ) +# Optionally, build with ccache. +set(ROCM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build") +if (ROCM_CCACHE_BUILD) + find_program(CCACHE_PROGRAM ccache) + if (CCACHE_PROGRAM) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM}) + else() + message(WARNING "Unable to find ccache. Falling back to real compiler") + endif() # if (CCACHE_PROGRAM) +endif() # if (ROCM_CCACHE_BUILD) + ## Include the cmake_modules utils.cmake list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules" ) include ( utils ) @@ -30,52 +32,43 @@ add_definitions ( -DLITTLEENDIAN_CPU=1 ) add_definitions ( -D HSA_DEPRECATED= ) add_definitions ( -D BRAHMA_BUILD=1 ) -## Get the package version. The defaults to 1.0.0. -get_version ( "1.0.0" ) +## Get the package version. +get_version( "1.1.9") +set(SO_MAJOR 1) +set(SO_MINOR 1) +set(SO_PATCH 9) -set ( BUILD_VERSION_MAJOR ${VERSION_MAJOR} ) -set ( BUILD_VERSION_MINOR ${VERSION_MINOR} ) -set ( BUILD_VERSION_PATCH ${VERSION_PATCH} ) -set ( LIB_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" ) -if ( DEFINED VERSION_BUILD ) - set ( BUILD_VERSION_PATCH "${BUILD_VERSION_PATCH}-${VERSION_BUILD}" ) -endif () -set ( BUILD_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" ) +set( SO_VERSION_STRING "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}" ) +set( PACKAGE_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT_COUNT}-${VERSION_JOB}-${VERSION_HASH}" ) ## Find the hsakmt library and include files -find_file ( HSAKMT_INC NAMES "hsakmt.h" "libhsakmt/hsakmt.h" ) -find_library ( HSAKMT_LIB libhsakmt.so ) -get_filename_component ( HSAKMT_LIB_PATH ${HSAKMT_LIB} DIRECTORY ) -get_filename_component ( HSAKMT_INC_PATH ${HSAKMT_INC} DIRECTORY ) -include_directories ( ${HSAKMT_INC_PATH} ) -link_directories (${HSAKMT_LIB_PATH}) +get_include_path( HSAKMT_INC_PATH "libhsakmt include path" NAMES "hsakmt.h" "libhsakmt/hsakmt.h" HINTS "${CMAKE_BINARY_DIR}/../../include" "${CMAKE_CURRENT_SOURCE_DIR}/../../../../libhsakmt/include" PATHS "/opt/rocm/include") +get_library_path( HSAKMT_LIB_PATH "libhsakmt library path" NAMES "libhsakmt.so" HINTS "${CMAKE_BINARY_DIR}/../../lib" "${CMAKE_BINARY_DIR}/../roct" PATHS "/opt/rocm/lib") +include_directories( ${HSAKMT_INC_PATH} ) +link_directories( ${HSAKMT_LIB_PATH} ) ## Find the hsa-runtime and include files -find_file ( HSA_INC "hsa/hsa.h" ) -find_library ( HSA_LIB libhsa-runtime64.so ) -get_filename_component ( HSA_LIB_PATH ${HSA_LIB} DIRECTORY ) -get_filename_component ( HSA_INC_PATH ${HSA_INC} DIRECTORY ) -include_directories ( ${HSA_INC_PATH} ) -link_directories (${HSA_LIB_PATH}) +get_include_path( HSA_INC_PATH "ROCr include path" NAMES "hsa.h" "hsa/hsa.h" HINTS "${CMAKE_BINARY_DIR}/../../include" "${CMAKE_CURRENT_SOURCE_DIR}/../hsa-runtime/inc" PATHS "/opt/rocm/include") +get_library_path( HSA_LIB_PATH "ROCr library path" NAMES "libhsa-runtime64.so" HINTS "${CMAKE_BINARY_DIR}/../../lib" "${CMAKE_BINARY_DIR}/../hsa-core" "${CMAKE_CURRENT_SOURCE_DIR}/../hsa-runtime/build" PATHS "/opt/rocm/lib") +include_directories( ${HSA_INC_PATH} ) +link_directories( ${HSA_LIB_PATH} ) -## External dependencies and directories -if ( NOT DEFINED REG_INCLUDE ) - set(REG_INCLUDE ${HSA_CLOSED_SOURCE_DIR}/drivers/inc/asic_reg) +## External dependencies +get_include_path( REG_INCLUDE "ASIC register directory" NAMES "si_id.h" HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../p4/driver/drivers/inc/asic_reg" "${HSA_CLOSED_SOURCE_DIR}/drivers/inc/asic_reg" "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../drivers/inc/asic_reg" ) + +## Find self +if( "${EXT_SOURCE_DIR}" STREQUAL "" ) + get_include_path( EXT_SOURCE_FILE null NAMES "image/image_runtime.h" HINTS "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/../../ext/" ) + get_filename_component( EXT_SOURCE_DIR "${EXT_SOURCE_FILE}/.." ABSOLUTE ) + unset( EXT_SOURCE_FILE CACHE ) endif() +set( EXT_SOURCE_DIR ${EXT_SOURCE_DIR} CACHE PATH "Image lib source dir" FORCE ) -if ( NOT EXISTS ${REG_INCLUDE}/si_id.h ) - MESSAGE ( FATAL_ERROR "Environment variable REG_INCLUDE is not set appropriately. REG_INCLUDE=${REG_INCLUDE}" ) -else () - set ( REG_INCLUDE ${REG_INCLUDE} ) -endif () +get_filename_component( OPEN_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE CACHE ) +set( OPEN_SOURCE_DIR ${OPEN_SOURCE_DIR} CACHE PATH "Open source root dir" FORCE ) -if( NOT DEFINED EXT_SOURCE_DIR ) - set ( EXT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) -endif() - -if( NOT DEFINED OPEN_SOURCE_DIR ) - set ( OPEN_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." ) -endif() +## Set RUNPATH - ../../lib covers use of the legacy symlink in /hsa/lib/ +set(CMAKE_INSTALL_RPATH "$ORIGIN;$ORIGIN/../../lib") ## ------------------------- Linux Compiler and Linker options ------------------------- set ( CMAKE_CXX_FLAGS "-std=c++11 " ) @@ -94,9 +87,7 @@ endif () set ( DRVDEF "${EXT_SOURCE_DIR}/make/image.so.def" ) -set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bdynamic -Wl,-z,noexecstack -Wl,--version-script=${DRVDEF}" ) - -set ( CMAKE_SKIP_BUILD_RPATH TRUE ) +set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bdynamic -Wl,-z,noexecstack -Wl,--version-script=${DRVDEF} -Wl,--enable-new-dtags" ) ## Library path(s). include_directories ( ${REG_INCLUDE} ) @@ -154,7 +145,6 @@ set ( IMAGE_SRCS ${EXT_SOURCE_DIR}/image/addrlib/addrinterface.cpp ${OPEN_SOURCE_DIR}/hsa-runtime/core/common/hsa_table_interface.cpp ) - add_subdirectory(${EXT_SOURCE_DIR}/image/blit_src ${CMAKE_BINARY_DIR}/image_blit) set_source_files_properties(${EXT_SOURCE_DIR}/image/opencl_blit_objects.cpp PROPERTIES GENERATED 1) @@ -162,8 +152,8 @@ add_library ( ${IMAGE_TARGET} SHARED ${IMAGE_SRCS} ) add_dependencies( ${IMAGE_TARGET} opencl_blit_objects.cpp ) ## Set the VERSION and SOVERSION values -set_property ( TARGET ${IMAGE_TARGET} PROPERTY VERSION "${LIB_VERSION_STRING}" ) -set_property ( TARGET ${IMAGE_TARGET} PROPERTY SOVERSION "${BUILD_VERSION_MAJOR}" ) +set_property ( TARGET ${IMAGE_TARGET} PROPERTY VERSION "${SO_VERSION_STRING}" ) +set_property ( TARGET ${IMAGE_TARGET} PROPERTY SOVERSION "${SO_MAJOR}" ) ## Add the core runtime in the link target_link_libraries ( @@ -178,5 +168,9 @@ if ( "${CMAKE_BUILD_TYPE}" STREQUAL Release ) add_custom_command ( TARGET ${IMAGE_TARGET} POST_BUILD COMMAND ${CMAKE_STRIP} *.so ) endif () +## Create symlinks for legacy packaging and install +add_custom_target ( hsa_images_lib_link ALL WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E create_symlink ../hsa/lib/${IMAGE_LIBRARY}.so ${IMAGE_LIBRARY}-link.so ) + ## Set install information install ( TARGETS ${IMAGE_TARGET} LIBRARY DESTINATION hsa/lib ) +install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/${IMAGE_LIBRARY}-link.so DESTINATION lib PERMISSIONS OWNER_WRITE OWNER_READ RENAME ${IMAGE_LIBRARY}.so ) diff --git a/projects/rocr-runtime/runtime/hsa-runtime-tools/CMakeLists.txt b/projects/rocr-runtime/runtime/hsa-runtime-tools/CMakeLists.txt index 2860c18a3f..977ba117d8 100755 --- a/projects/rocr-runtime/runtime/hsa-runtime-tools/CMakeLists.txt +++ b/projects/rocr-runtime/runtime/hsa-runtime-tools/CMakeLists.txt @@ -1,13 +1,22 @@ cmake_minimum_required ( VERSION 3.5.0 ) -## Verbose output. -set ( CMAKE_VERBOSE_MAKEFILE on ) - -## Set ext runtime module name and project name. +# Set ext runtime module name and project name. set ( TOOLS_NAME "hsa-runtime-tools" ) set ( TOOLS_TARGET "${TOOLS_NAME}64" ) +set ( TOOLS_LIBRARY "lib${TOOLS_TARGET}" ) project ( ${TOOLS_TARGET} ) +# Optionally, build with ccache. +set(ROCM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build") +if (ROCM_CCACHE_BUILD) + find_program(CCACHE_PROGRAM ccache) + if (CCACHE_PROGRAM) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM}) + else() + message(WARNING "Unable to find ccache. Falling back to real compiler") + endif() # if (CCACHE_PROGRAM) +endif() # if (ROCM_CCACHE_BUILD) + ## Include the cmake_modules utils.cmake list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules" ) include ( utils ) @@ -23,57 +32,42 @@ add_definitions ( -DLITTLEENDIAN_CPU=1 ) add_definitions ( -D HSA_DEPRECATED= ) ## Get the package version. The defaults to 1.0.0. -get_version ( "1.0.0" ) +get_version( "1.1.9") +set(SO_MAJOR 1) +set(SO_MINOR 1) +set(SO_PATCH 9) -set ( BUILD_VERSION_MAJOR ${VERSION_MAJOR} ) -set ( BUILD_VERSION_MINOR ${VERSION_MINOR} ) -set ( BUILD_VERSION_PATCH ${VERSION_PATCH} ) -set ( LIB_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" ) -if ( DEFINED VERSION_BUILD ) - set ( BUILD_VERSION_PATCH "${BUILD_VERSION_PATCH}-${VERSION_BUILD}" ) -endif () -set ( BUILD_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" ) +set( SO_VERSION_STRING "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}" ) +set( PACKAGE_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT_COUNT}-${VERSION_JOB}-${VERSION_HASH}" ) ## Find the hsakmt library and include files -find_file ( HSAKMT_INC NAMES "hsakmt.h" "libhsakmt/hsakmt.h" ) -find_library ( HSAKMT_LIB libhsakmt.so ) -get_filename_component ( HSAKMT_LIB_PATH ${HSAKMT_LIB} DIRECTORY ) -get_filename_component ( HSAKMT_INC_PATH ${HSAKMT_INC} DIRECTORY ) -include_directories ( ${HSAKMT_INC_PATH} ) -link_directories (${HSAKMT_LIB_PATH}) +get_include_path( HSAKMT_INC_PATH "libhsakmt include path" NAMES "hsakmt.h" "libhsakmt/hsakmt.h" HINTS "${CMAKE_BINARY_DIR}/../../include" "${CMAKE_CURRENT_SOURCE_DIR}/../../../../libhsakmt/include" PATHS "/opt/rocm/include") +get_library_path( HSAKMT_LIB_PATH "libhsakmt library path" NAMES "libhsakmt.so" HINTS "${CMAKE_BINARY_DIR}/../../lib" "${CMAKE_BINARY_DIR}/../roct" PATHS "/opt/rocm/lib") +include_directories( ${HSAKMT_INC_PATH} ) +link_directories( ${HSAKMT_LIB_PATH} ) ## Find the hsa-runtime and include files -find_file ( HSA_INC "hsa/hsa.h" ) -find_library ( HSA_LIB libhsa-runtime64.so ) -get_filename_component ( HSA_LIB_PATH ${HSA_LIB} DIRECTORY ) -get_filename_component ( HSA_INC_PATH ${HSA_INC} DIRECTORY ) -include_directories ( ${HSA_INC_PATH} ) -link_directories (${HSA_LIB_PATH}) +get_include_path( HSA_INC_PATH "ROCr include path" NAMES "hsa.h" "hsa/hsa.h" HINTS "${CMAKE_BINARY_DIR}/../../include" "${CMAKE_CURRENT_SOURCE_DIR}/../hsa-runtime/inc" PATHS "/opt/rocm/include") +get_library_path( HSA_LIB_PATH "ROCr library path" NAMES "libhsa-runtime64.so" HINTS "${CMAKE_BINARY_DIR}/../../lib" "${CMAKE_BINARY_DIR}/../hsa-core" "${CMAKE_CURRENT_SOURCE_DIR}/../hsa-runtime/build" PATHS "/opt/rocm/lib") +include_directories( ${HSA_INC_PATH} ) +link_directories( ${HSA_LIB_PATH} ) ## External dependencies -if ( NOT DEFINED REG_INCLUDE ) - set(REG_INCLUDE ${HSA_CLOSED_SOURCE_DIR}/drivers/inc/asic_reg) +get_include_path( REG_INCLUDE "ASIC register directory" NAMES "si_id.h" HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../p4/driver/drivers/inc/asic_reg" "${HSA_CLOSED_SOURCE_DIR}/drivers/inc/asic_reg" "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../drivers/inc/asic_reg" ) + +## Find self +if( "${TOOLS_SOURCE_DIR}" STREQUAL "" ) + get_include_path( TOOLS_SOURCE_FILE null NAMES "inc/amd_hsa_tools_interfaces.h" HINTS "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/../../tools/" ) + get_filename_component( TOOLS_SOURCE_DIR "${TOOLS_SOURCE_FILE}/.." ABSOLUTE ) + unset( TOOLS_SOURCE_FILE CACHE ) endif() +set( TOOLS_SOURCE_DIR ${TOOLS_SOURCE_DIR} CACHE PATH "Tools lib source dir" FORCE ) -if ( NOT EXISTS ${REG_INCLUDE}/si_id.h ) - MESSAGE ( FATAL_ERROR "Environment variable REG_INCLUDE is not set appropriately." ) -endif () +get_filename_component( OPEN_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE CACHE ) +set( OPEN_SOURCE_DIR ${OPEN_SOURCE_DIR} CACHE PATH "Open source root dir" FORCE ) -if ( NOT DEFINED HSAKMT_INCLUDE ) - set(HSAKMT_INCLUDE ${HSA_CLOSED_SOURCE_DIR}/drivers/hsathk/include) -endif() - -if ( NOT EXISTS ${HSAKMT_INCLUDE}/hsakmt.h ) - MESSAGE ( FATAL_ERROR "Environment variable REG_INCLUDE is not set appropriately." ) -endif () - -if( NOT DEFINED TOOLS_SOURCE_DIR ) - set ( TOOLS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) -endif() - -if( NOT DEFINED OPEN_SOURCE_DIR ) - set ( OPEN_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." ) -endif() +## Set RUNPATH - ../../lib covers use of the legacy symlink in /hsa/lib/ +set(CMAKE_INSTALL_RPATH "$ORIGIN;$ORIGIN/../../lib") ## ------------------------- Linux Compiler and Linker options ------------------------- set ( CMAKE_CXX_FLAGS "-std=c++11 ") @@ -92,13 +86,10 @@ endif () set ( DRVDEF "${TOOLS_SOURCE_DIR}/make/hsatools.so.def" ) -set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bdynamic -Wl,-z,noexecstack -Wl,--version-script=${DRVDEF}" ) - -set ( CMAKE_SKIP_BUILD_RPATH TRUE ) +set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bdynamic -Wl,-z,noexecstack -Wl,--version-script=${DRVDEF} -Wl,--enable-new-dtags" ) ## Library path(s). include_directories ( ${REG_INCLUDE} ) -include_directories ( ${HSAKMT_INCLUDE} ) include_directories ( ${TOOLS_SOURCE_DIR} ) include_directories ( ${TOOLS_SOURCE_DIR}/.. ) include_directories ( ${OPEN_SOURCE_DIR}/hsa-runtime ) @@ -213,7 +204,7 @@ set ( SP3_R1000_SRC ${TOOLS_SOURCE_DIR}/sp3/Chip/R1000/sp3-asic.c set ( UTIL_SRC ${OPEN_SOURCE_DIR}/hsa-runtime/core/util/timer.cpp ${OPEN_SOURCE_DIR}/hsa-runtime/core/util/small_heap.cpp ${OPEN_SOURCE_DIR}/hsa-runtime/core/util/lnx/os_linux.cpp ) - + ## This is the main shared library. add_library ( ${TOOLS_TARGET} SHARED ${CORE_SRC} @@ -228,8 +219,8 @@ add_library ( ${TOOLS_TARGET} SHARED ${CORE_SRC} ${UTIL_SRC} ) ## Set the VERSION and SOVERSION values -set_property ( TARGET ${TOOLS_TARGET} PROPERTY VERSION "${LIB_VERSION_STRING}" ) -set_property ( TARGET ${TOOLS_TARGET} PROPERTY SOVERSION "${BUILD_VERSION_MAJOR}" ) +set_property ( TARGET ${TOOLS_TARGET} PROPERTY VERSION "${SO_VERSION_STRING}" ) +set_property ( TARGET ${TOOLS_TARGET} PROPERTY SOVERSION "${SO_MAJOR}" ) ## Add the required link libraries target_link_libraries ( @@ -244,6 +235,10 @@ if ( "${CMAKE_BUILD_TYPE}" STREQUAL Release ) add_custom_command ( TARGET ${TOOLS_TARGET} POST_BUILD COMMAND ${CMAKE_STRIP} *.so ) endif () +## Create symlinks for legacy packaging and install +add_custom_target ( hsa_tools_lib_link ALL WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E create_symlink ../hsa/lib/${TOOLS_LIBRARY}.so ${TOOLS_LIBRARY}-link.so ) + ## Set install information install ( TARGETS ${TOOLS_TARGET} LIBRARY DESTINATION hsa/lib ) install ( DIRECTORY ${TOOLS_SOURCE_DIR}/inc/ DESTINATION hsa/include/hsa FILES_MATCHING PATTERN "*.h" ) +install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/${TOOLS_LIBRARY}-link.so DESTINATION lib PERMISSIONS OWNER_WRITE OWNER_READ RENAME ${TOOLS_LIBRARY}.so ) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/CMakeLists.txt b/projects/rocr-runtime/runtime/hsa-runtime/CMakeLists.txt index 2c8eea7007..9eb7e32c5d 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/CMakeLists.txt +++ b/projects/rocr-runtime/runtime/hsa-runtime/CMakeLists.txt @@ -42,9 +42,6 @@ cmake_minimum_required ( VERSION 3.5.0 ) -## Verbose output. -set ( CMAKE_VERBOSE_MAKEFILE on ) - ## Set core runtime module name and project name. set ( CORE_RUNTIME_NAME "hsa-runtime" ) set ( CORE_RUNTIME_TARGET "${CORE_RUNTIME_NAME}64" ) @@ -85,24 +82,19 @@ endif() ## Get the package version. get_version ( "1.1.9" ) +set (SO_MAJOR 1) +set (SO_MINOR 1) +set (SO_PATCH 9) -set ( BUILD_VERSION_MAJOR ${VERSION_MAJOR} ) -set ( BUILD_VERSION_MINOR ${VERSION_MINOR} ) -set ( BUILD_VERSION_PATCH ${VERSION_PATCH} ) -set ( LIB_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" ) - -if ( VERSION_BUILD ) - set ( BUILD_VERSION_PATCH "${BUILD_VERSION_PATCH}-${VERSION_BUILD}" ) -endif () -set ( BUILD_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" ) +set ( SO_VERSION_STRING "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}" ) +set ( PACKAGE_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT_COUNT}-${VERSION_JOB}-${VERSION_HASH}" ) ## Find the hsakmt library and include files, use directory hint from cache -find_file ( HSAKMT_INC NAMES "hsakmt.h" "libhsakmt/hsakmt.h" PATHS ${HSAKMT_INC_PATH} ) -find_library ( HSAKMT_LIB "libhsakmt.so" ${HSAKMT_LIB_PATH} ) -get_filename_component ( HSAKMT_INC_PATH ${HSAKMT_INC} DIRECTORY CACHE ) -get_filename_component ( HSAKMT_LIB_PATH ${HSAKMT_LIB} DIRECTORY CACHE ) -unset( HSAKMT_INC CACHE ) -unset( HSAKMT_LIB CACHE ) +## Search relative to build directory, relative to source directory, and finally the rocm install default (/opt/rocm) +get_include_path( HSAKMT_INC_PATH "libhsakmt include path" NAMES "hsakmt.h" "libhsakmt/hsakmt.h" HINTS "${CMAKE_BINARY_DIR}/../../include" "${CMAKE_CURRENT_SOURCE_DIR}/../../../../libhsakmt/include" PATHS "/opt/rocm/include") +get_library_path( HSAKMT_LIB_PATH "libhsakmt library path" NAMES "libhsakmt.so" HINTS "${CMAKE_BINARY_DIR}/../../lib" "${CMAKE_BINARY_DIR}/../roct" PATHS "/opt/rocm/lib") +include_directories ( ${HSAKMT_INC_PATH} ) +link_directories ( ${HSAKMT_LIB_PATH} ) ## Set include directories for ROCr runtime include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -110,16 +102,11 @@ include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}/inc ) include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}/core/inc ) include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}/libamdhsacode ) -## Set include and link directories for libhsakmt -include_directories ( ${HSAKMT_INC_PATH} ) -link_directories ( ${HSAKMT_LIB_PATH} ) - ## ROCr build internal versioning -if ( VERSION_BUILD ) - add_definitions ( -DROCR_BUILD_ID=${BUILD_VERSION_STRING} ) -else () - add_definitions ( -DROCR_BUILD_ID="${BUILD_VERSION_STRING}-unknown" ) -endif () +add_definitions ( -DROCR_BUILD_ID=${PACKAGE_VERSION_STRING} ) + +## Set RUNPATH - ../../lib covers use of the legacy symlink in /hsa/lib/ +set(CMAKE_INSTALL_RPATH "$ORIGIN;$ORIGIN/../../lib") ## ------------------------- Linux Compiler and Linker options ------------------------- set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fexceptions -fno-rtti -fvisibility=hidden -Wno-error=sign-compare -Wno-sign-compare -Wno-write-strings -Wno-conversion-null -fno-math-errno -fno-threadsafe-statics -fmerge-all-constants -fms-extensions -Wno-error=comment -Wno-comment -Wno-error=pointer-arith -Wno-pointer-arith -Wno-error=unused-variable -Wno-error=unused-function" ) @@ -131,9 +118,7 @@ set ( DRVDEF "${CMAKE_CURRENT_SOURCE_DIR}/hsacore.so.def" ) set ( LNKSCR "${CMAKE_CURRENT_SOURCE_DIR}/hsacore.so.link" ) -set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bdynamic -Wl,-z,noexecstack -Wl,${LNKSCR} -Wl,--version-script=${DRVDEF}" ) - -set ( CMAKE_SKIP_BUILD_RPATH TRUE ) +set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bdynamic -Wl,-z,noexecstack -Wl,${LNKSCR} -Wl,--version-script=${DRVDEF} -Wl,--enable-new-dtags" ) ## ------------------------- End Compiler and Linker options ---------------------------- @@ -177,10 +162,6 @@ set ( SRCS "core/util/lnx/os_linux.cpp" add_library( ${CORE_RUNTIME_TARGET} SHARED ${SRCS} ) -## Set the VERSION and SOVERSION values -set_property ( TARGET ${CORE_RUNTIME_TARGET} PROPERTY VERSION "${LIB_VERSION_STRING}" ) -set_property ( TARGET ${CORE_RUNTIME_TARGET} PROPERTY SOVERSION "${BUILD_VERSION_MAJOR}" ) - target_link_libraries ( ${CORE_RUNTIME_TARGET} PRIVATE hsakmt elf dl pthread rt @@ -191,33 +172,39 @@ if ( "${CMAKE_BUILD_TYPE}" STREQUAL Release ) # add_custom_command ( TARGET ${CORE_RUNTIME_TARGET} POST_BUILD COMMAND ${CMAKE_STRIP} *.so ) endif () -## Create symlinks for packaging and install -add_custom_target ( hsa-link ALL WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E create_symlink ../hsa/include/hsa hsa-link ) -add_custom_target ( ${CORE_RUNTIME_TARGET}.so-link ALL WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E create_symlink ../hsa/lib/${CORE_RUNTIME_LIBRARY}.so ${CORE_RUNTIME_LIBRARY}.so-link ) +## Set the VERSION and SOVERSION values +set_property ( TARGET ${CORE_RUNTIME_TARGET} PROPERTY VERSION "${SO_VERSION_STRING}" ) +set_property ( TARGET ${CORE_RUNTIME_TARGET} PROPERTY SOVERSION "${SO_MAJOR}" ) + +## Create symlinks for legacy packaging and install +add_custom_target ( hsa_include_link ALL WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E create_symlink ../hsa/include/hsa hsa_include_link ) +add_custom_target ( hsa_lib_link ALL WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E create_symlink ../hsa/lib/${CORE_RUNTIME_LIBRARY}.so ${CORE_RUNTIME_LIBRARY}-link.so ) +add_custom_target ( hsa_lib_link2 ALL WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E create_symlink ../hsa/lib/${CORE_RUNTIME_LIBRARY}.so.${SO_MAJOR} ${CORE_RUNTIME_LIBRARY}-link.so.${SO_MAJOR} ) ## Set install information install ( TARGETS ${CORE_RUNTIME_TARGET} LIBRARY DESTINATION hsa/lib ) install ( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/inc/ DESTINATION hsa/include/hsa ) -install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/hsa-link DESTINATION include PERMISSIONS OWNER_WRITE OWNER_READ RENAME hsa ) -install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/${CORE_RUNTIME_LIBRARY}.so-link DESTINATION lib PERMISSIONS OWNER_WRITE OWNER_READ RENAME ${CORE_RUNTIME_LIBRARY}.so ) +install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/hsa_include_link DESTINATION include PERMISSIONS OWNER_WRITE OWNER_READ RENAME hsa ) +install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/${CORE_RUNTIME_LIBRARY}-link.so DESTINATION lib PERMISSIONS OWNER_WRITE OWNER_READ RENAME ${CORE_RUNTIME_LIBRARY}.so ) +install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/${CORE_RUNTIME_LIBRARY}-link.so.${SO_MAJOR} DESTINATION lib PERMISSIONS OWNER_WRITE OWNER_READ RENAME ${CORE_RUNTIME_LIBRARY}.so.${SO_MAJOR} ) ## Packaging directives +set ( CPACK_GENERATOR "DEB;RPM" CACHE STRING "Package types to build") + set ( CPACK_PACKAGE_NAME "hsa-rocr-dev" ) set ( CPACK_PACKAGE_VENDOR "AMD" ) -set ( CPACK_PACKAGE_VERSION_MAJOR ${BUILD_VERSION_MAJOR} ) -set ( CPACK_PACKAGE_VERSION_MINOR ${BUILD_VERSION_MINOR} ) -set ( CPACK_PACKAGE_VERSION_PATCH ${BUILD_VERSION_PATCH} ) +set ( CPACK_PACKAGE_VERSION ${PACKAGE_VERSION_STRING} ) set ( CPACK_PACKAGE_CONTACT "Advanced Micro Devices Inc." ) set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "AMD Heterogeneous System Architecture HSA - Linux HSA Runtime for Boltzmann (ROCm) platforms" ) set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md" ) # Debian package specific variables -set ( CPACK_DEBIAN_PACKAGE_DEPENDS "hsakmt-roct-dev" ) +set ( CPACK_DEBIAN_PACKAGE_DEPENDS "hsakmt-roct" ) set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCR-Runtime" ) set ( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/DEBIAN/postinst;${CMAKE_CURRENT_SOURCE_DIR}/DEBIAN/prerm" ) ## RPM package specific variables -set ( CPACK_RPM_PACKAGE_DEPENDS "hsakmt-roct-dev" ) +set ( CPACK_RPM_PACKAGE_DEPENDS "hsakmt-roct" ) set ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/RPM/rpm_post" ) set ( CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/RPM/rpm_postun" ) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/cmake_modules/utils.cmake b/projects/rocr-runtime/runtime/hsa-runtime/cmake_modules/utils.cmake index 0530c87f32..77e4411312 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/cmake_modules/utils.cmake +++ b/projects/rocr-runtime/runtime/hsa-runtime/cmake_modules/utils.cmake @@ -40,6 +40,59 @@ ## ################################################################################ +function( get_path LIB CACHED_PATH HELP ) + + set( options "") + set( oneValueArgs RESULT ) + set( multiValueArgs HINTS NAMES ) + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + + # Search for canary file. + if( ${LIB} ) + find_library( FULLPATH NAMES ${ARGS_NAMES} HINTS ${${CACHED_PATH}} ${ARGS_HINTS} ) + else() + find_file( FULLPATH NAMES ${ARGS_NAMES} HINTS ${${CACHED_PATH}} ${ARGS_HINTS} ) + endif() + set( RESULT (NOT ${FULLPATH} MATCHES NOTFOUND) ) + + # Extract path + get_filename_component ( DIRPATH ${FULLPATH} DIRECTORY ) + + # Check path against cache + if( NOT "${${CACHED_PATH}}" STREQUAL "" ) + if ( NOT "${${CACHED_PATH}}" STREQUAL "${DIRPATH}" ) + message(WARNING "${CACHED_PATH} may be incorrect." ) + set( DIRPATH ${${CACHED_PATH}} ) + endif() + elseif(NOT ${RESULT}) + message(WARNING "${CACHED_PATH} not located during path search.") + endif() + + # Set cache variable and help text + set( ${CACHED_PATH} ${DIRPATH} CACHE PATH ${HELP} FORCE ) + unset( FULLPATH CACHE ) + + # Return success flag + if( NOT ${ARGS_RESULT} STREQUAL "" ) + set( ${ARGS_RESULT} ${RESULT} PARENT_SCOPE) + endif() + +endfunction() + +## Searches for a file using include paths and stores the path to that file in the cache +## using the cached value if set. Search paths are optional. Returns success in RESULT. +## get_include_path( NAMES name1 [name2...] [HINTS path1 [path2 ... ENV var]] [RESULT ] +macro( get_include_path CACHED_PATH HELP ) + get_path( 0 ${ARGV} ) +endmacro() + +## Searches for a file using library paths and stores the path to that file in the cache +## using the cached value if set. Search paths are optional. Returns success in RESULT. +## get_library_path( NAMES name1 [name2...] [HINTS path1 [path2 ... ENV var]] [RESULT ] +macro( get_library_path CACHED_PATH HELP ) + get_path( 1 ${ARGV} ) +endmacro() + ## Parses the VERSION_STRING variable and places ## the first, second and third number values in ## the major, minor and patch variables. @@ -58,27 +111,18 @@ function( parse_version VERSION_STRING ) if ( ${VERSION_COUNT} GREATER 0) list ( GET VERSIONS 0 MAJOR ) set ( VERSION_MAJOR ${MAJOR} PARENT_SCOPE ) - set ( TEMP_VERSION_STRING "${MAJOR}" ) endif () if ( ${VERSION_COUNT} GREATER 1 ) list ( GET VERSIONS 1 MINOR ) set ( VERSION_MINOR ${MINOR} PARENT_SCOPE ) - set ( TEMP_VERSION_STRING "${TEMP_VERSION_STRING}.${MINOR}" ) endif () if ( ${VERSION_COUNT} GREATER 2 ) list ( GET VERSIONS 2 PATCH ) set ( VERSION_PATCH ${PATCH} PARENT_SCOPE ) - set ( TEMP_VERSION_STRING "${TEMP_VERSION_STRING}.${PATCH}" ) endif () - if ( VERSION_BUILD ) - set ( VERSION_BUILD "${VERSION_BUILD}" PARENT_SCOPE ) - endif () - - set ( VERSION_STRING "${TEMP_VERSION_STRING}" PARENT_SCOPE ) - endfunction () ## Gets the current version of the repository @@ -87,30 +131,77 @@ endfunction () ## and a library version string. function ( get_version DEFAULT_VERSION_STRING ) - parse_version ( ${DEFAULT_VERSION_STRING} ) + set( VERSION_JOB "local-build" ) + set( VERSION_COMMIT_COUNT 0 ) + set( VERSION_HASH "unknown" ) -## find_program ( GIT NAMES git ) -## -## if ( GIT ) -## -## execute_process ( COMMAND git describe --tags --dirty --long -## WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -## OUTPUT_VARIABLE GIT_TAG_STRING -## OUTPUT_STRIP_TRAILING_WHITESPACE -## RESULT_VARIABLE RESULT ) -## -## if ( ${RESULT} EQUAL 0 ) -## -## parse_version ( ${GIT_TAG_STRING} ) -## -## endif () -## -## endif () + find_program( GIT NAMES git ) + + if( GIT ) + + #execute_process ( COMMAND git describe --tags --dirty --long + # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + # OUTPUT_VARIABLE GIT_TAG_STRING + # OUTPUT_STRIP_TRAILING_WHITESPACE + # RESULT_VARIABLE RESULT ) + + # Get branch commit (common ancestor) of current branch and master branch. + execute_process(COMMAND git merge-base HEAD origin/HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_MERGE_BASE + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RESULT ) + + if( ${RESULT} EQUAL 0 ) + # Count commits from branch point. + execute_process(COMMAND git rev-list --count ${GIT_MERGE_BASE}..HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE VERSION_COMMIT_COUNT + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RESULT ) + if(NOT ${RESULT} EQUAL 0 ) + set( VERSION_COMMIT_COUNT 0 ) + endif() + endif() + + # Get current short hash. + execute_process(COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE VERSION_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RESULT ) + if( ${RESULT} EQUAL 0 ) + # Check for dirty workspace. + execute_process(COMMAND git diff --quiet + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE RESULT ) + if(${RESULT} EQUAL 1) + set(VERSION_HASH "${VERSION_HASH}-dirty") + endif() + else() + set( VERSION_HASH "unknown" ) + endif() + endif() + + # Build automation IDs + if(DEFINED ENV{ROCM_BUILD_ID}) + set( VERSION_JOB $ENV{ROCM_BUILD_ID} ) + endif() + + parse_version(${DEFAULT_VERSION_STRING}) - set( VERSION_STRING "${VERSION_STRING}" PARENT_SCOPE ) set( VERSION_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE ) set( VERSION_MINOR "${VERSION_MINOR}" PARENT_SCOPE ) set( VERSION_PATCH "${VERSION_PATCH}" PARENT_SCOPE ) - set( VERSION_BUILD "${VERSION_BUILD}" PARENT_SCOPE ) + set( VERSION_COMMIT_COUNT "${VERSION_COMMIT_COUNT}" PARENT_SCOPE ) + set( VERSION_HASH "${VERSION_HASH}" PARENT_SCOPE ) + set( VERSION_JOB "${VERSION_JOB}" PARENT_SCOPE ) + + #message("${VERSION_MAJOR}" ) + #message("${VERSION_MINOR}" ) + #message("${VERSION_PATCH}" ) + #message("${VERSION_COMMIT_COUNT}") + #message("${VERSION_HASH}") + #message("${VERSION_JOB}") endfunction() diff --git a/projects/rocr-runtime/runtime/packages/hsa-ext-rocr-dev/CMakeLists.txt b/projects/rocr-runtime/runtime/packages/hsa-ext-rocr-dev/CMakeLists.txt index 2edd2be274..7d75299e95 100644 --- a/projects/rocr-runtime/runtime/packages/hsa-ext-rocr-dev/CMakeLists.txt +++ b/projects/rocr-runtime/runtime/packages/hsa-ext-rocr-dev/CMakeLists.txt @@ -42,73 +42,29 @@ cmake_minimum_required ( VERSION 3.5.0 ) -## Verbose output. -set ( CMAKE_VERBOSE_MAKEFILE on ) - ## Set the name and project name. set ( PROJECT_STRING hsa-ext-rocr-dev ) project ( ${PROJECT_STRING} ) -list ( APPEND CMAKE_MODULE_PATH "${HSA_OPENSOURCE_ROOT}/cmake_modules" ) +add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../hsa-ext-image" "../hsa-ext-image") +add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../hsa-runtime-tools" "../hsa-tools") + +## Include the cmake_modules utils.cmake +list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_modules" ) include ( utils ) -## Get the package version. The defaults to 1.0.0. -get_version ( "1.0.0" ) +## Get the package version. +get_version ( "1.1.9" ) -set ( BUILD_VERSION_MAJOR ${VERSION_MAJOR} ) -set ( BUILD_VERSION_MINOR ${VERSION_MINOR} ) -set ( BUILD_VERSION_PATCH ${VERSION_PATCH} ) -set ( LIB_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" ) -if ( DEFINED VERSION_BUILD ) - set ( BUILD_VERSION_PATCH "${BUILD_VERSION_PATCH}-${VERSION_BUILD}" ) -endif () -set ( BUILD_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" ) +set( PACKAGE_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT_COUNT}-${VERSION_JOB}-${VERSION_HASH}" ) -set ( PACKAGE_DIRECTORIES "hsa/lib") - -add_custom_command ( OUTPUT ${PACKAGE_DIRECTORIES} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E make_directory "hsa/lib" ) - -add_custom_target (create_dirs DEPENDS ${PACKAGE_DIRECTORIES} ) - -set ( TOOLS_NAME "libhsa-runtime-tools64" ) -set ( IMAGE_NAME "libhsa-ext-image64" ) - -set ( TOOLS_LIBRARY_SOURCE "${OUT_DIR}/lib/${TOOLS_NAME}.so.${LIB_VERSION_STRING}" ) -set ( IMAGE_LIBRARY_SOURCE "${OUT_DIR}/lib/${IMAGE_NAME}.so.${LIB_VERSION_STRING}" ) - -set ( TOOLS_LIBRARY_TARGET "${CMAKE_CURRENT_BINARY_DIR}/hsa/lib/${TOOLS_NAME}.so.${LIB_VERSION_STRING}" ) -set ( IMAGE_LIBRARY_TARGET "${CMAKE_CURRENT_BINARY_DIR}/hsa/lib/${IMAGE_NAME}.so.${LIB_VERSION_STRING}" ) - -set ( TOOLS_LIBRARY_SONAME "${CMAKE_CURRENT_BINARY_DIR}/hsa/lib/${TOOLS_NAME}.so.${BUILD_VERSION_MAJOR}" ) -set ( IMAGE_LIBRARY_SONAME "${CMAKE_CURRENT_BINARY_DIR}/hsa/lib/${IMAGE_NAME}.so.${BUILD_VERSION_MAJOR}" ) - -add_custom_command ( OUTPUT ${TOOLS_LIBRARY_TARGET} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E copy ${TOOLS_LIBRARY_SOURCE} ${TOOLS_LIBRARY_TARGET} ) - -add_custom_command ( OUTPUT ${IMAGE_LIBRARY_TARGET} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E copy ${IMAGE_LIBRARY_SOURCE} ${IMAGE_LIBRARY_TARGET} ) - -add_custom_command ( OUTPUT ${TOOLS_LIBRARY_SONAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/hsa/lib - COMMAND ${CMAKE_COMMAND} -E create_symlink ${TOOLS_NAME}.so.${VERSION_STRING} ${TOOLS_NAME}.so.${BUILD_VERSION_MAJOR} ) - -add_custom_command ( OUTPUT ${IMAGE_LIBRARY_SONAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/hsa/lib - COMMAND ${CMAKE_COMMAND} -E create_symlink ${IMAGE_NAME}.so.${VERSION_STRING} ${IMAGE_NAME}.so.${BUILD_VERSION_MAJOR} ) - -add_custom_target ( copy_targets ALL DEPENDS create_dirs - ${TOOLS_LIBRARY_TARGET} - ${IMAGE_LIBRARY_TARGET} - ${TOOLS_LIBRARY_SONAME} - ${IMAGE_LIBRARY_SONAME} - ) - -install ( DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/hsa/ DESTINATION hsa USE_SOURCE_PERMISSIONS ) +## Packaging directives +set ( CPACK_GENERATOR "DEB;RPM" CACHE STRING "Package types to build") set ( CPACK_PACKAGE_NAME ${PROJECT_NAME} ) set ( CPACK_PACKAGE_VENDOR "AMD" ) -set ( CPACK_PACKAGE_VERSION_MAJOR ${BUILD_VERSION_MAJOR} ) -set ( CPACK_PACKAGE_VERSION_MINOR ${BUILD_VERSION_MINOR} ) -set ( CPACK_PACKAGE_VERSION_PATCH ${BUILD_VERSION_PATCH} ) -set ( CPACK_PACKAGE_CONTACT "James Edwards (JamesAdrian.Edwards@amd.com)" ) +set ( CPACK_PACKAGE_VERSION ${PACKAGE_VERSION_STRING} ) +set ( CPACK_PACKAGE_CONTACT "Advanced Micro Devices Inc." ) set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "AMD Heterogeneous System Architecture HSA - Linux HSA Runtime extensions for ROCm platforms" ) set ( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/description" ) set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/copyright" ) diff --git a/projects/rocr-runtime/runtime/packages/hsa-ext-rocr-dev/Old CMakeLists.txt b/projects/rocr-runtime/runtime/packages/hsa-ext-rocr-dev/Old CMakeLists.txt new file mode 100644 index 0000000000..9dad458693 --- /dev/null +++ b/projects/rocr-runtime/runtime/packages/hsa-ext-rocr-dev/Old CMakeLists.txt @@ -0,0 +1,103 @@ +################################################################################ +## +## The University of Illinois/NCSA +## Open Source License (NCSA) +## +## Copyright (c) 2014-2017, Advanced Micro Devices, Inc. All rights reserved. +## +## Developed by: +## +## AMD Research and AMD HSA Software Development +## +## Advanced Micro Devices, Inc. +## +## www.amd.com +## +## Permission is hereby granted, free of charge, to any person obtaining a copy +## of this software and associated documentation files (the "Software"), to +## deal with the Software without restriction, including without limitation +## the rights to use, copy, modify, merge, publish, distribute, sublicense, +## and#or sell copies of the Software, and to permit persons to whom the +## Software is furnished to do so, subject to the following conditions: +## +## - Redistributions of source code must retain the above copyright notice, +## this list of conditions and the following disclaimers. +## - Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimers in +## the documentation and#or other materials provided with the distribution. +## - Neither the names of Advanced Micro Devices, Inc, +## nor the names of its contributors may be used to endorse or promote +## products derived from this Software without specific prior written +## permission. +## +## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +## THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +## DEALINGS WITH THE SOFTWARE. +## +################################################################################ + +cmake_minimum_required ( VERSION 3.5.0 ) + +## Set the name and project name. +set ( PROJECT_STRING hsa-ext-rocr-dev ) +project ( ${PROJECT_STRING} ) + +## Include the cmake_modules utils.cmake +list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake_modules" ) +include ( utils ) + +## Get the package version. +get_version ( "1.2.0" ) + +set( PACKAGE_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT_COUNT}-${VERSION_JOB}-${VERSION_BUILD_ID}-${VERSION_HASH}" ) + +## Packaging directives +set ( CPACK_GENERATOR "DEB;RPM" CACHE STRING "Package types to build") + +set ( PACKAGE_DIRECTORIES "hsa/lib") +add_custom_command ( OUTPUT ${PACKAGE_DIRECTORIES} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E make_directory "hsa/lib" ) +add_custom_target (create_dirs DEPENDS ${PACKAGE_DIRECTORIES} ) + +set ( TOOLS_NAME "libhsa-runtime-tools64" ) +set ( IMAGE_NAME "libhsa-ext-image64" ) + +set ( TOOLS_LIBRARY_SOURCE "${OUT_DIR}/lib/${TOOLS_NAME}.so*" ) +set ( IMAGE_LIBRARY_SOURCE "${OUT_DIR}/lib/${IMAGE_NAME}.so*" ) + +set ( TOOLS_LIBRARY_TARGET "${CMAKE_CURRENT_BINARY_DIR}/hsa/lib/${TOOLS_NAME}.so" ) +set ( IMAGE_LIBRARY_TARGET "${CMAKE_CURRENT_BINARY_DIR}/hsa/lib/${IMAGE_NAME}.so" ) + +add_custom_command ( OUTPUT ${TOOLS_LIBRARY_TARGET} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${TOOLS_LIBRARY_SOURCE} "${CMAKE_CURRENT_BINARY_DIR}/hsa/lib/" ) + +add_custom_command ( OUTPUT ${IMAGE_LIBRARY_TARGET} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${IMAGE_LIBRARY_SOURCE} "${CMAKE_CURRENT_BINARY_DIR}/hsa/lib/" ) + +add_custom_target ( copy_targets ALL DEPENDS create_dirs + ${TOOLS_LIBRARY_TARGET} + ${IMAGE_LIBRARY_TARGET} + ) + +install ( DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/hsa/ DESTINATION hsa USE_SOURCE_PERMISSIONS ) + +set ( CPACK_PACKAGE_NAME ${PROJECT_NAME} ) +set ( CPACK_PACKAGE_VENDOR "AMD" ) +set ( CPACK_PACKAGE_VERSION ${PACKAGE_VERSION_STRING} ) +set ( CPACK_PACKAGE_CONTACT "Advanced Micro Devices Inc." ) +set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "AMD Heterogeneous System Architecture HSA - Linux HSA Runtime extensions for ROCm platforms" ) +set ( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/description" ) +set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/copyright" ) + +# Debian package specific variables +set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCR-Runtime" ) +set ( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/postinst;${CMAKE_CURRENT_SOURCE_DIR}/prerm" ) + +# RPM package specific variables +set ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/rpm_post" ) +set ( CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/rpm_postun" ) + +include ( CPack ) diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/CMakeLists.txt b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/CMakeLists.txt deleted file mode 100644 index df6971a297..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/CMakeLists.txt +++ /dev/null @@ -1,187 +0,0 @@ -################################################################################ -## -## The University of Illinois/NCSA -## Open Source License (NCSA) -## -## Copyright (c) 2014-2017, Advanced Micro Devices, Inc. All rights reserved. -## -## Developed by: -## -## AMD Research and AMD HSA Software Development -## -## Advanced Micro Devices, Inc. -## -## www.amd.com -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to -## deal with the Software without restriction, including without limitation -## the rights to use, copy, modify, merge, publish, distribute, sublicense, -## and#or sell copies of the Software, and to permit persons to whom the -## Software is furnished to do so, subject to the following conditions: -## -## - Redistributions of source code must retain the above copyright notice, -## this list of conditions and the following disclaimers. -## - Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimers in -## the documentation and#or other materials provided with the distribution. -## - Neither the names of Advanced Micro Devices, Inc, -## nor the names of its contributors may be used to endorse or promote -## products derived from this Software without specific prior written -## permission. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR -## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -## DEALINGS WITH THE SOFTWARE. -## -################################################################################ - -cmake_minimum_required ( VERSION 3.5.0 ) - -## Verbose output. -set ( CMAKE_VERBOSE_MAKEFILE on ) - -## Set the name and project name. -set ( PROJECT_STRING hsa-rocr-dev ) -project( ${PROJECT_STRING} ) - -list ( APPEND CMAKE_MODULE_PATH "${HSA_OPENSOURCE_ROOT}/cmake_modules" ) -include ( utils ) - -## Get the package version. The defaults to 1.0.0. -get_version ( "1.0.0" ) - -set ( BUILD_VERSION_MAJOR ${VERSION_MAJOR} ) -set ( BUILD_VERSION_MINOR ${VERSION_MINOR} ) -set ( BUILD_VERSION_PATCH ${VERSION_PATCH} ) -set ( LIB_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" ) -if ( DEFINED VERSION_BUILD ) - set ( BUILD_VERSION_PATCH "${BUILD_VERSION_PATCH}-${VERSION_BUILD}" ) -endif () -set ( BUILD_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" ) - -## Define the runtime components -set ( RUNTIME_NAME "libhsa-runtime64" ) -set ( RUNTIME_LIBRARY_SOURCE "${OUT_DIR}/lib/${RUNTIME_NAME}.so.${LIB_VERSION_STRING}" ) -set ( RUNTIME_LIBRARY_TARGET "${CMAKE_CURRENT_BINARY_DIR}/hsa/lib/${RUNTIME_NAME}.so.${LIB_VERSION_STRING}" ) -set ( RUNTIME_LIBRARY_SONAME "${CMAKE_CURRENT_BINARY_DIR}/hsa/lib/${RUNTIME_NAME}.so.${BUILD_VERSION_MAJOR}" ) -set ( RUNTIME_LIBRARY_LINKNAME "${CMAKE_CURRENT_BINARY_DIR}/lib/${RUNTIME_NAME}.so" ) - -set ( PACKAGE_DIRECTORIES - "include" - "hsa/include/hsa" - "hsa/lib") - -set ( RUNTIME_HEADER_NAMES - "hsa.h" - "amd_hsa_common.h" - "amd_hsa_elf.h" - "amd_hsa_kernel_code.h" - "amd_hsa_queue.h" - "amd_hsa_signal.h" - "Brig.h" - "hsa_api_trace.h" - "hsa_ext_amd.h" - "hsa_ext_finalize.h" - "hsa_ext_image.h" - "hsa_ven_amd_loader.h" - "hsa_ven_amd_aqlprofile.h" - ) - -set ( RUNTIME_TOOLS_HEADER_NAMES - "hsa_ext_profiler.h" - "hsa_ext_debugger.h" - "amd_hsa_tools_interfaces.h" - ) - -set ( RUNTIME_TOOLS_INCLUDE_DIR "${HSA_CLOSED_SOURCE_ROOT}/drivers/hsa/runtime/tools/inc" ) - -set ( TOPLEVEL_INCLUDE_LINK "${CMAKE_CURRENT_BINARY_DIR}/include/hsa" ) - -add_custom_command(OUTPUT ${PACKAGE_DIRECTORIES} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E make_directory "include" - COMMAND ${CMAKE_COMMAND} -E make_directory "lib" - COMMAND ${CMAKE_COMMAND} -E make_directory "hsa/lib" - COMMAND ${CMAKE_COMMAND} -E make_directory "hsa/include/hsa" ) - -add_custom_target (create_dirs DEPENDS ${PACKAGE_DIRECTORIES} ) - -add_custom_target (link_dirs DEPENDS create_dirs ${TOPLEVEL_INCLUDE_LINK} ) - -add_custom_command( OUTPUT ${RUNTIME_LIBRARY_TARGET} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E copy ${RUNTIME_LIBRARY_SOURCE} ${RUNTIME_LIBRARY_TARGET} ) - -add_custom_command( OUTPUT ${TOPLEVEL_INCLUDE_LINK} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include - COMMAND ${CMAKE_COMMAND} -E create_symlink ../hsa/include/hsa hsa ) - -add_custom_command( OUTPUT ${RUNTIME_LIBRARY_SONAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/hsa/lib - COMMAND ${CMAKE_COMMAND} -E create_symlink ${RUNTIME_NAME}.so.${LIB_VERSION_STRING} ${RUNTIME_NAME}.so.${BUILD_VERSION_MAJOR} ) - -add_custom_command( OUTPUT ${RUNTIME_LIBRARY_LINKNAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib - COMMAND ${CMAKE_COMMAND} -E create_symlink ../hsa/lib/${RUNTIME_NAME}.so.${BUILD_VERSION_MAJOR} ${RUNTIME_NAME}.so ) - -foreach ( HEADER_FILE ${RUNTIME_HEADER_NAMES} ) - - set ( HEADER_TARGET "${CMAKE_CURRENT_BINARY_DIR}/hsa/include/hsa/${HEADER_FILE}" ) - - add_custom_command( OUTPUT ${HEADER_TARGET} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E copy ${OUT_DIR}/include/hsa/${HEADER_FILE} ${HEADER_TARGET} ) - - list ( APPEND RUNTIME_HEADERS ${HEADER_TARGET} ) - -endforeach() - -foreach ( HEADER_FILE ${RUNTIME_TOOLS_HEADER_NAMES} ) - - set ( HEADER_TARGET "${CMAKE_CURRENT_BINARY_DIR}/hsa/include/hsa/${HEADER_FILE}" ) - - add_custom_command( OUTPUT ${HEADER_TARGET} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E copy ${RUNTIME_TOOLS_INCLUDE_DIR}/${HEADER_FILE} ${HEADER_TARGET} ) - - list ( APPEND RUNTIME_HEADERS ${HEADER_TARGET} ) - -endforeach() - -add_custom_target (copy_headers DEPENDS ${RUNTIME_HEADERS} create_dirs) - -add_custom_target (copy_targets ALL DEPENDS create_dirs - ${RUNTIME_LIBRARY_TARGET} - ${RUNTIME_LIBRARY_SONAME} - ${RUNTIME_LIBRARY_LINKNAME} - link_dirs - copy_headers - ) - -## Install directives -install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ DESTINATION include USE_SOURCE_PERMISSIONS ) -install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib/ DESTINATION lib USE_SOURCE_PERMISSIONS ) -install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/hsa/ DESTINATION hsa USE_SOURCE_PERMISSIONS ) -install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt DESTINATION hsa ) -install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.md DESTINATION hsa ) - -## Packaging directives -set ( CPACK_PACKAGE_NAME ${PROJECT_NAME} ) -set ( CPACK_PACKAGE_VENDOR "AMD" ) -set ( CPACK_PACKAGE_VERSION_MAJOR ${BUILD_VERSION_MAJOR} ) -set ( CPACK_PACKAGE_VERSION_MINOR ${BUILD_VERSION_MINOR} ) -set ( CPACK_PACKAGE_VERSION_PATCH ${BUILD_VERSION_PATCH} ) -set ( CPACK_PACKAGE_CONTACT "James Edwards (JamesAdrian.Edwards@amd.com)" ) -set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "AMD Heterogeneous System Architecture HSA - Linux HSA Runtime for ROCm platforms" ) -set ( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/description" ) -set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/copyright" ) - -# Debian package specific variables -set ( CPACK_DEBIAN_PACKAGE_DEPENDS "hsa-ext-rocr-dev (=${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}) , hsakmt-roct-dev" ) -set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCR-Runtime" ) -set ( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/postinst;${CMAKE_CURRENT_SOURCE_DIR}/prerm" ) - -# RPM package specific variables -set ( CPACK_RPM_PACKAGE_DEPENDS "hsa-ext-rocr-dev (=${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}), hsakmt-roct-dev" ) -set ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/rpm_post" ) -set ( CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/rpm_postun" ) - -include ( CPack ) diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/LICENSE.txt b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/LICENSE.txt deleted file mode 100644 index 4a8dd58823..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/LICENSE.txt +++ /dev/null @@ -1,37 +0,0 @@ -The University of Illinois/NCSA -Open Source License (NCSA) - -Copyright (c) 2014-2016, Advanced Micro Devices, Inc. All rights reserved. - -Developed by: - - AMD Research and AMD HSA Software Development - - Advanced Micro Devices, Inc. - - www.amd.com - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to -deal with the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimers in - the documentation and/or other materials provided with the distribution. - - Neither the names of Advanced Micro Devices, Inc, - nor the names of its contributors may be used to endorse or promote - products derived from this Software without specific prior written - permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS WITH THE SOFTWARE. diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/README.md b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/README.md deleted file mode 100644 index 6660f1f1fe..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/README.md +++ /dev/null @@ -1,78 +0,0 @@ -### HSA Runtime API and runtime for ROCm - -This repository includes the user-mode API interfaces and libraries necessary for host applications to launch compute kernels to available HSA ROCm kernel agents. Reference source code for the core runtime is also available. - -#### Initial Target Platform Requirements - -* CPU: Intel(c) Haswell or newer, Core i5, Core i7, Xeon E3 v4 & v5; Xeon E5 v3 -* GPU: Fiji(c) ASIC (AMD R9 Nano, R9 Fury and R9 Fury X) -* GPU: Polaris(c) ASIC (AMD RX480) - -#### Source code - -The HSA core runtime source code for the ROCR runtime is located in the src subdirectory. Please consult the associated README.md file for contents and build instructions. - -#### Binaries for Ubuntu & Fedora and Installation Instructions - -Pre-built binaries are available for installation from the ROCm package repository. For ROCR, they include: - -Core runtime package: - -* HSA include files to support application development on the HSA runtime for the ROCR runtime -* A 64-bit version of AMD's HSA core runtime for the ROCR runtime - -Runtime extension package: - -* A 64-bit version of AMD's finalizer extension for ROCR runtime -* A 64-bit version of AMD's runtime tools library -* A 64-bit version of AMD's runtime image library, which supports the HSAIL image implementation only. - -The contents of these packages are installed in /opt/rocm/hsa and /opt/rocm by default. -The core runtime package depends on the hsakmt-roct-dev package - -Installation instructions can be found in the ROCm manifest repository README.md: - -https://github.com/RadeonOpenCompute/ROCm - -#### Infrastructure - -The HSA runtime is a thin, user-mode API that exposes the necessary interfaces to access and interact with graphics hardware driven by the AMDGPU driver set and the ROCK kernel driver. Together they enable programmers to directly harness the power of AMD discrete graphics devices by allowing host applications to launch compute kernels directly to the graphics hardware. - -The capabilities expressed by the HSA Runtime API are: - -* Error handling -* Runtime initialization and shutdown -* System and agent information -* Signals and synchronization -* Architected dispatch -* Memory management -* HSA runtime fits into a typical software architecture stack. - -The HSA runtime provides direct access to the graphics hardware to give the programmer more control of the execution. An example of low level hardware access is the support of one or more user mode queues provides programmers with a low-latency kernel dispatch interface, allowing them to develop customized dispatch algorithms specific to their application. - -The HSA Architected Queuing Language is an open standard, defined by the HSA Foundation, specifying the packet syntax used to control supported AMD/ATI Radeon (c) graphics devices. The AQL language supports several packet types, including packets that can command the hardware to automatically resolve inter-packet dependencies (barrier AND & barrier OR packet), kernel dispatch packets and agent dispatch packets. - -In addition to user mode queues and AQL, the HSA runtime exposes various virtual address ranges that can be accessed by one or more of the system's graphics devices, and possibly the host. The exposed virtual address ranges either support a fine grained or a coarse grained access. Updates to memory in a fine grained region are immediately visible to all devices that can access it, but only one device can have access to a coarse grained allocation at a time. Ownership of a coarse grained region can be changed using the HSA runtime memory APIs, but this transfer of ownership must be explicitly done by the host application. - -Programmers should consult the HSA Runtime Programmer's Reference Manual for a full description of the HSA Runtime APIs, AQL and the HSA memory policy. - -#### Sample - -The simplest way to check if the kernel, runtime and base development environment are installed correctly is to run a simple sample. A modified version of the vector_copy sample was taken from the HSA-Runtime-AMD repository and added to the ROCR repository to facilitate this. Build the sample and run it, using this series of commands: - -cd ROCR-Runtime/sample && make && ./vector_copy - -If the sample runs without generating errors, the installation is complete. - -#### Known Issues - -* The image extension is currently not supported for discrete GPUs. An image extension library is not provided in the binary package. The standard hsa_ext_image.h extension include file is provided for reference. -* Each HSA process creates and internal DMA queue, but there is a system-wide limit of four DMA queues. The fifth simultaneous HSA process will fail hsa_init() with HSA_STATUS_ERROR_OUT_OF_RESOURCES. To run an unlimited number of simultaneous HSA processes, set the environment variable HSA_ENABLE_SDMA=0. - -#### Disclaimer - -The information contained herein is for informational purposes only, and is subject to change without notice. While every precaution has been taken in the preparation of this document, it may contain technical inaccuracies, omissions and typographical errors, and AMD is under no obligation to update or otherwise correct this information. Advanced Micro Devices, Inc. makes no representations or warranties with respect to the accuracy or completeness of the contents of this document, and assumes no liability of any kind, including the implied warranties of noninfringement, merchantability or fitness for particular purposes, with respect to the operation or use of AMD hardware, software or other products described herein. No license, including implied or arising by estoppel, to any intellectual property rights is granted by this document. Terms and limitations applicable to the purchase or use of AMD's products are as set forth in a signed agreement between the parties or in AMD's Standard Terms and Conditions of Sale. - -AMD, the AMD Arrow logo, and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies. - -Copyright (c) 2014-2016 Advanced Micro Devices, Inc. All rights reserved. diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/copyright b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/copyright deleted file mode 100644 index 1fc00dc10a..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/copyright +++ /dev/null @@ -1,38 +0,0 @@ -The University of Illinois/NCSA -Open Source License (NCSA) - -Copyright (c) 2014-2016, Advanced Micro Devices, Inc. All rights reserved. - -Developed by: - - AMD Research and AMD HSA Software Development - - Advanced Micro Devices, Inc. - - www.amd.com - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to -deal with the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimers. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimers in - the documentation and/or other materials provided with the distribution. - - Neither the names of Advanced Micro Devices, Inc, - nor the names of its contributors may be used to endorse or promote - products derived from this Software without specific prior written - permission. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS WITH THE SOFTWARE. - diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/description b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/description deleted file mode 100644 index f8bc053f0d..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/description +++ /dev/null @@ -1 +0,0 @@ -This package includes the user-mode runtime necessary for host applications to launch compute kernels to available HSA and ROCm components. This version is consistent with the 1.0 Final HSA Runtime Programmer's Reference Manual and targets AMD AMD Fiji ASICS on supported platforms. diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/postinst b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/postinst deleted file mode 100644 index 769a72e462..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/postinst +++ /dev/null @@ -1,19 +0,0 @@ -#/bin/bash - -set -e - -do_ldconfig() { - echo /opt/rocm/hsa/lib > /etc/ld.so.conf.d/hsa-rocr-dev.conf && ldconfig -} - -case "$1" in - configure) - do_ldconfig - ;; - abort-upgrade|abort-remove|abort-deconfigure) - echo "$1" - ;; - *) - exit 0 - ;; -esac diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/prerm b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/prerm deleted file mode 100644 index 2b7d50a825..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/prerm +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -set -e - -rm_ldconfig() { - rm -f /etc/ld.so.conf.d/hsa-rocr-dev.conf && ldconfig -} - -case "$1" in - remove) - rm_ldconfig - ;; - purge) - ;; - *) - exit 0 - ;; -esac - diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/rpm_post b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/rpm_post deleted file mode 100644 index 5a9aaac79f..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/rpm_post +++ /dev/null @@ -1 +0,0 @@ -echo /opt/rocm/hsa/lib > /etc/ld.so.conf.d/hsa-rocr-dev.conf && ldconfig diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/rpm_postun b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/rpm_postun deleted file mode 100644 index af28397d30..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/rpm_postun +++ /dev/null @@ -1,3 +0,0 @@ -if [ $1 -eq 0]; then - rm -f /etc/ld.so.conf.d/hsa-rocr-dev.conf && ldconfig -fi diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/Makefile b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/Makefile deleted file mode 100644 index 37de17a4a9..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/Makefile +++ /dev/null @@ -1,60 +0,0 @@ -################################################################################ -## -## The University of Illinois/NCSA -## Open Source License (NCSA) -## -## Copyright (c) 2014-2016, Advanced Micro Devices, Inc. All rights reserved. -## -## Developed by: -## -## AMD Research and AMD HSA Software Development -## -## Advanced Micro Devices, Inc. -## -## www.amd.com -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to -## deal with the Software without restriction, including without limitation -## the rights to use, copy, modify, merge, publish, distribute, sublicense, -## and#or sell copies of the Software, and to permit persons to whom the -## Software is furnished to do so, subject to the following conditions: -## -## - Redistributions of source code must retain the above copyright notice, -## this list of conditions and the following disclaimers. -## - Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimers in -## the documentation and#or other materials provided with the distribution. -## - Neither the names of Advanced Micro Devices, Inc, -## nor the names of its contributors may be used to endorse or promote -## products derived from this Software without specific prior written -## permission. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR -## OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -## ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -## DEALINGS WITH THE SOFTWARE. -## -################################################################################ - -LFLAGS= -Wl,--unresolved-symbols=ignore-in-shared-libs - -CC := gcc - -C_FILES := $(wildcard *.c) - -OBJ_FILES := $(notdir $(C_FILES:.c=.o)) - -all: vector_copy - -vector_copy: $(OBJ_FILES) - $(CC) $(LFLAGS) $(OBJ_FILES) -L/opt/rocm/lib -lhsa-runtime64 -o vector_copy - -%.o: %.c - $(CC) -c -I/opt/rocm/include -o $@ $< -std=c99 - -clean: - rm -rf *.o vector_copy diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy.c b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy.c deleted file mode 100644 index d1de531bbe..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy.c +++ /dev/null @@ -1,458 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// The University of Illinois/NCSA -// Open Source License (NCSA) -// -// Copyright (c) 2014-2016, Advanced Micro Devices, Inc. All rights reserved. -// -// Developed by: -// -// AMD Research and AMD HSA Software Development -// -// Advanced Micro Devices, Inc. -// -// www.amd.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal with the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimers. -// - Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimers in -// the documentation and/or other materials provided with the distribution. -// - Neither the names of Advanced Micro Devices, Inc, -// nor the names of its contributors may be used to endorse or promote -// products derived from this Software without specific prior written -// permission. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR -// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS WITH THE SOFTWARE. -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include "hsa/hsa.h" -#include "hsa/hsa_ext_finalize.h" - -#define check(msg, status) \ -if (status != HSA_STATUS_SUCCESS) { \ - printf("%s failed.\n", #msg); \ - exit(1); \ -} else { \ - printf("%s succeeded.\n", #msg); \ -} - -/* - * Loads a BRIG module from a specified file. This - * function does not validate the module. - */ -int load_module_from_file(const char* file_name, hsa_ext_module_t* module) { - int rc = -1; - - FILE *fp = fopen(file_name, "rb"); - - rc = fseek(fp, 0, SEEK_END); - - size_t file_size = (size_t) (ftell(fp) * sizeof(char)); - - rc = fseek(fp, 0, SEEK_SET); - - char* buf = (char*) malloc(file_size); - - memset(buf,0,file_size); - - size_t read_size = fread(buf,sizeof(char),file_size,fp); - - if(read_size != file_size) { - free(buf); - } else { - rc = 0; - *module = (hsa_ext_module_t) buf; - } - - fclose(fp); - - return rc; -} - -/* - * Determines if the given agent is of type HSA_DEVICE_TYPE_GPU - * and sets the value of data to the agent handle if it is. - */ -static hsa_status_t get_gpu_agent(hsa_agent_t agent, void *data) { - hsa_status_t status; - hsa_device_type_t device_type; - status = hsa_agent_get_info(agent, HSA_AGENT_INFO_DEVICE, &device_type); - if (HSA_STATUS_SUCCESS == status && HSA_DEVICE_TYPE_GPU == device_type) { - hsa_agent_t* ret = (hsa_agent_t*)data; - *ret = agent; - return HSA_STATUS_INFO_BREAK; - } - return HSA_STATUS_SUCCESS; -} - -/* - * Determines if a memory region can be used for kernarg - * allocations. - */ -static hsa_status_t get_kernarg_memory_region(hsa_region_t region, void* data) { - hsa_region_segment_t segment; - hsa_region_get_info(region, HSA_REGION_INFO_SEGMENT, &segment); - if (HSA_REGION_SEGMENT_GLOBAL != segment) { - return HSA_STATUS_SUCCESS; - } - - hsa_region_global_flag_t flags; - hsa_region_get_info(region, HSA_REGION_INFO_GLOBAL_FLAGS, &flags); - if (flags & HSA_REGION_GLOBAL_FLAG_KERNARG) { - hsa_region_t* ret = (hsa_region_t*) data; - *ret = region; - return HSA_STATUS_INFO_BREAK; - } - - return HSA_STATUS_SUCCESS; -} - -/* - * Determines if a memory region can be used for fine grained - * allocations. - */ -static hsa_status_t get_fine_grained_memory_region(hsa_region_t region, void* data) { - hsa_region_segment_t segment; - hsa_region_get_info(region, HSA_REGION_INFO_SEGMENT, &segment); - if (HSA_REGION_SEGMENT_GLOBAL != segment) { - return HSA_STATUS_SUCCESS; - } - - hsa_region_global_flag_t flags; - hsa_region_get_info(region, HSA_REGION_INFO_GLOBAL_FLAGS, &flags); - if (flags & HSA_REGION_GLOBAL_FLAG_FINE_GRAINED) { - hsa_region_t* ret = (hsa_region_t*) data; - *ret = region; - return HSA_STATUS_INFO_BREAK; - } - - return HSA_STATUS_SUCCESS; -} - -int main(int argc, char **argv) { - hsa_status_t err; - - err = hsa_init(); - check(Initializing the hsa runtime, err); - - /* - * Determine if the finalizer 1.0 extension is supported. - */ - bool support; - - err = hsa_system_extension_supported(HSA_EXTENSION_FINALIZER, 1, 0, &support); - - check(Checking finalizer 1.0 extension support, err); - - /* - * Generate the finalizer function table. - */ - hsa_ext_finalizer_1_00_pfn_t table_1_00; - - err = hsa_system_get_extension_table(HSA_EXTENSION_FINALIZER, 1, 0, &table_1_00); - - check(Generating function table for finalizer, err); - - /* - * Iterate over the agents and pick the gpu agent using - * the get_gpu_agent callback. - */ - hsa_agent_t agent; - err = hsa_iterate_agents(get_gpu_agent, &agent); - if(err == HSA_STATUS_INFO_BREAK) { - err = HSA_STATUS_SUCCESS; - } else { - /* - * No GPU agent was found. - */ - err = HSA_STATUS_ERROR; - } - check(Getting a gpu agent, err); - - /* - * Query the name of the agent. - */ - char name[64] = { 0 }; - err = hsa_agent_get_info(agent, HSA_AGENT_INFO_NAME, name); - check(Querying the agent name, err); - printf("The agent name is %s.\n", name); - - /* - * Query the maximum size of the queue. - */ - uint32_t queue_size = 0; - err = hsa_agent_get_info(agent, HSA_AGENT_INFO_QUEUE_MAX_SIZE, &queue_size); - check(Querying the agent maximum queue size, err); - printf("The maximum queue size is %u.\n", (unsigned int) queue_size); - - /* - * Create a queue using the maximum size. - */ - hsa_queue_t* queue; - err = hsa_queue_create(agent, queue_size, HSA_QUEUE_TYPE_SINGLE, NULL, NULL, UINT32_MAX, UINT32_MAX, &queue); - check(Creating the queue, err); - - /* - * Obtain the agent's machine model - */ - hsa_machine_model_t machine_model; - err = hsa_agent_get_info(agent, HSA_AGENT_INFO_MACHINE_MODEL, &machine_model); - check("Obtaining machine model",err); - - /* - * Obtain the agent's profile - */ - hsa_profile_t profile; - err = hsa_agent_get_info(agent, HSA_AGENT_INFO_PROFILE, &profile); - check("Getting agent profile",err); - - /* - * Load the BRIG binary. - */ - hsa_ext_module_t module; - if(HSA_PROFILE_FULL == profile) { - load_module_from_file("vector_copy_full.brig",&module); - } else { - load_module_from_file("vector_copy_base.brig",&module); - } - - /* - * Create hsa program. - */ - hsa_ext_program_t program; - memset(&program,0,sizeof(hsa_ext_program_t)); - err = table_1_00.hsa_ext_program_create(machine_model, profile, HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT, NULL, &program); - check(Create the program, err); - - /* - * Add the BRIG module to hsa program. - */ - err = table_1_00.hsa_ext_program_add_module(program, module); - check(Adding the brig module to the program, err); - - /* - * Determine the agents ISA. - */ - hsa_isa_t isa; - err = hsa_agent_get_info(agent, HSA_AGENT_INFO_ISA, &isa); - check(Query the agents isa, err); - - /* - * Finalize the program and extract the code object. - */ - hsa_ext_control_directives_t control_directives; - memset(&control_directives, 0, sizeof(hsa_ext_control_directives_t)); - hsa_code_object_t code_object; - err = table_1_00.hsa_ext_program_finalize(program, isa, 0, control_directives, "", HSA_CODE_OBJECT_TYPE_PROGRAM, &code_object); - check(Finalizing the program, err); - - /* - * Destroy the program, it is no longer needed. - */ - err=table_1_00.hsa_ext_program_destroy(program); - check(Destroying the program, err); - - /* - * Create the empty executable. - */ - hsa_executable_t executable; - err = hsa_executable_create(profile, HSA_EXECUTABLE_STATE_UNFROZEN, "", &executable); - check(Create the executable, err); - - /* - * Load the code object. - */ - err = hsa_executable_load_code_object(executable, agent, code_object, ""); - check(Loading the code object, err); - - /* - * Freeze the executable; it can now be queried for symbols. - */ - err = hsa_executable_freeze(executable, ""); - check(Freeze the executable, err); - - /* - * Extract the symbol from the executable. - */ - hsa_executable_symbol_t symbol; - err = hsa_executable_get_symbol(executable, NULL, "&__vector_copy_kernel", agent, 0, &symbol); - check(Extract the symbol from the executable, err); - - /* - * Extract dispatch information from the symbol - */ - uint64_t kernel_object; - uint32_t kernarg_segment_size; - uint32_t group_segment_size; - uint32_t private_segment_size; - err = hsa_executable_symbol_get_info(symbol, HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_OBJECT, &kernel_object); - check(Extracting the symbol from the executable, err); - err = hsa_executable_symbol_get_info(symbol, HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_KERNARG_SEGMENT_SIZE, &kernarg_segment_size); - check(Extracting the kernarg segment size from the executable, err); - err = hsa_executable_symbol_get_info(symbol, HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_GROUP_SEGMENT_SIZE, &group_segment_size); - check(Extracting the group segment size from the executable, err); - err = hsa_executable_symbol_get_info(symbol, HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_PRIVATE_SEGMENT_SIZE, &private_segment_size); - check(Extracting the private segment from the executable, err); - - /* - * Create a signal to wait for the dispatch to finish. - */ - hsa_signal_t signal; - err=hsa_signal_create(1, 0, NULL, &signal); - check(Creating a HSA signal, err); - - hsa_region_t finegrained_region; - finegrained_region.handle=(uint64_t)-1; - hsa_agent_iterate_regions(agent, get_fine_grained_memory_region, &finegrained_region); - err = (finegrained_region.handle == (uint64_t)-1) ? HSA_STATUS_ERROR : HSA_STATUS_SUCCESS; - check(Finding a fine grained memory region, err); - - /* - * Allocate and initialize the kernel arguments from the fine - * grained memory region. - */ - char* in; - err=hsa_memory_allocate(finegrained_region, 1024*1024*4, (void**) &in); - check(Allocating argument memory for input parameter, err); - memset(in, 1, 1024*1024*4); - - char* out; - err=hsa_memory_allocate(finegrained_region, 1024*1024*4, (void**) &out); - check(Allocating argument memory for output parameter, err); - memset(out, 0, 1024*1024*4); - - struct __attribute__ ((aligned(16))) args_t { - void* in; - void* out; - } args; - - args.in=in; - args.out=out; - - /* - * Find a memory region that supports kernel arguments. - */ - hsa_region_t kernarg_region; - kernarg_region.handle=(uint64_t)-1; - hsa_agent_iterate_regions(agent, get_kernarg_memory_region, &kernarg_region); - err = (kernarg_region.handle == (uint64_t)-1) ? HSA_STATUS_ERROR : HSA_STATUS_SUCCESS; - check(Finding a kernarg memory region, err); - void* kernarg_address = NULL; - - /* - * Allocate the kernel argument buffer from the correct region. - */ - err = hsa_memory_allocate(kernarg_region, kernarg_segment_size, &kernarg_address); - check(Allocating kernel argument memory buffer, err); - memcpy(kernarg_address, &args, sizeof(args)); - - /* - * Obtain the current queue write index. - */ - uint64_t index = hsa_queue_load_write_index_relaxed(queue); - - /* - * Write the aql packet at the calculated queue index address. - */ - const uint32_t queueMask = queue->size - 1; - hsa_kernel_dispatch_packet_t* dispatch_packet = &(((hsa_kernel_dispatch_packet_t*)(queue->base_address))[index&queueMask]); - - dispatch_packet->setup |= 1 << HSA_KERNEL_DISPATCH_PACKET_SETUP_DIMENSIONS; - dispatch_packet->workgroup_size_x = (uint16_t)256; - dispatch_packet->workgroup_size_y = (uint16_t)1; - dispatch_packet->workgroup_size_z = (uint16_t)1; - dispatch_packet->grid_size_x = (uint32_t) (1024*1024); - dispatch_packet->grid_size_y = 1; - dispatch_packet->grid_size_z = 1; - dispatch_packet->completion_signal = signal; - dispatch_packet->kernel_object = kernel_object; - dispatch_packet->kernarg_address = (void*) kernarg_address; - dispatch_packet->private_segment_size = private_segment_size; - dispatch_packet->group_segment_size = group_segment_size; - - uint16_t header = 0; - header |= HSA_FENCE_SCOPE_SYSTEM << HSA_PACKET_HEADER_ACQUIRE_FENCE_SCOPE; - header |= HSA_FENCE_SCOPE_SYSTEM << HSA_PACKET_HEADER_RELEASE_FENCE_SCOPE; - header |= HSA_PACKET_TYPE_KERNEL_DISPATCH << HSA_PACKET_HEADER_TYPE; - - __atomic_store_n((uint16_t*)(&dispatch_packet->header), header, __ATOMIC_RELEASE); - - /* - * Increment the write index and ring the doorbell to dispatch the kernel. - */ - hsa_queue_store_write_index_relaxed(queue, index+1); - hsa_signal_store_relaxed(queue->doorbell_signal, index); - check(Dispatching the kernel, err); - - /* - * Wait on the dispatch completion signal until the kernel is finished. - */ - hsa_signal_value_t value = hsa_signal_wait_acquire(signal, HSA_SIGNAL_CONDITION_LT, 1, UINT64_MAX, HSA_WAIT_STATE_BLOCKED); - - /* - * Validate the data in the output buffer. - */ - int valid=1; - int fail_index=0; - for(int i=0; i<1024*1024; i++) { - if(out[i]!=in[i]) { - fail_index=i; - valid=0; - break; - } - } - - if(valid) { - printf("Passed validation.\n"); - } else { - printf("VALIDATION FAILED!\nBad index: %d\n", fail_index); - } - - /* - * Cleanup all allocated resources. - */ - err = hsa_memory_free(kernarg_address); - check(Freeing kernel argument memory buffer, err); - - err=hsa_signal_destroy(signal); - check(Destroying the signal, err); - - err=hsa_executable_destroy(executable); - check(Destroying the executable, err); - - err=hsa_code_object_destroy(code_object); - check(Destroying the code object, err); - - err=hsa_queue_destroy(queue); - check(Destroying the queue, err); - - err = hsa_memory_free(in); - check(Freeing in argument memory buffer, err); - - err = hsa_memory_free(out); - check(Freeing out argument memory buffer, err); - - err=hsa_shut_down(); - check(Shutting down the runtime, err); - - return 0; -} diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_base.brig b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_base.brig deleted file mode 100644 index 563960cd63..0000000000 Binary files a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_base.brig and /dev/null differ diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_base.hsail b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_base.hsail deleted file mode 100644 index 7eeeb471db..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_base.hsail +++ /dev/null @@ -1,63 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// The University of Illinois/NCSA -// Open Source License (NCSA) -// -// Copyright (c) 2014-2015, Advanced Micro Devices, Inc. All rights reserved. -// -// Developed by: -// -// AMD Research and AMD HSA Software Development -// -// Advanced Micro Devices, Inc. -// -// www.amd.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal with the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimers. -// - Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimers in -// the documentation and/or other materials provided with the distribution. -// - Neither the names of Advanced Micro Devices, Inc, -// nor the names of its contributors may be used to endorse or promote -// products derived from this Software without specific prior written -// permission. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR -// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS WITH THE SOFTWARE. -// -//////////////////////////////////////////////////////////////////////////////// - -module &m:1:0:$base:$large:$default; - -decl prog function &abort()(); - -prog kernel &__vector_copy_kernel( - kernarg_u64 %in, - kernarg_u64 %out) -{ -@__vector_copy_kernel_entry: - // BB#0: // %entry - workitemabsid_u32 $s0, 0; - cvt_s64_s32 $d0, $s0; - shl_u64 $d0, $d0, 2; - ld_kernarg_align(8)_width(all)_u64 $d1, [%out]; - add_u64 $d1, $d1, $d0; - ld_kernarg_align(8)_width(all)_u64 $d2, [%in]; - add_u64 $d0, $d2, $d0; - ld_global_u32 $s0, [$d0]; - st_global_u32 $s0, [$d1]; - ret; -}; diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_full.brig b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_full.brig deleted file mode 100644 index bd042dbffe..0000000000 Binary files a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_full.brig and /dev/null differ diff --git a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_full.hsail b/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_full.hsail deleted file mode 100644 index 070ba28492..0000000000 --- a/projects/rocr-runtime/runtime/packages/hsa-rocr-dev/sample/vector_copy_full.hsail +++ /dev/null @@ -1,63 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// The University of Illinois/NCSA -// Open Source License (NCSA) -// -// Copyright (c) 2014-2015, Advanced Micro Devices, Inc. All rights reserved. -// -// Developed by: -// -// AMD Research and AMD HSA Software Development -// -// Advanced Micro Devices, Inc. -// -// www.amd.com -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal with the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimers. -// - Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimers in -// the documentation and/or other materials provided with the distribution. -// - Neither the names of Advanced Micro Devices, Inc, -// nor the names of its contributors may be used to endorse or promote -// products derived from this Software without specific prior written -// permission. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR -// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS WITH THE SOFTWARE. -// -//////////////////////////////////////////////////////////////////////////////// - -module &m:1:0:$full:$large:$default; - -decl prog function &abort()(); - -prog kernel &__vector_copy_kernel( - kernarg_u64 %in, - kernarg_u64 %out) -{ -@__vector_copy_kernel_entry: - // BB#0: // %entry - workitemabsid_u32 $s0, 0; - cvt_s64_s32 $d0, $s0; - shl_u64 $d0, $d0, 2; - ld_kernarg_align(8)_width(all)_u64 $d1, [%out]; - add_u64 $d1, $d1, $d0; - ld_kernarg_align(8)_width(all)_u64 $d2, [%in]; - add_u64 $d0, $d2, $d0; - ld_global_u32 $s0, [$d0]; - st_global_u32 $s0, [$d1]; - ret; -};