Skip to content

Commit

Permalink
ROCm 3.0.0 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
skeelyamd committed Dec 18, 2019
1 parent 8546125 commit ae653de
Show file tree
Hide file tree
Showing 9 changed files with 427 additions and 155 deletions.
77 changes: 32 additions & 45 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down Expand Up @@ -85,41 +82,31 @@ 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} )
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" )
Expand All @@ -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 ----------------------------

Expand Down Expand Up @@ -177,47 +162,49 @@ 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
)

## Strip should be optional or not at all
if ( "${CMAKE_BUILD_TYPE}" STREQUAL Release )
# add_custom_command ( TARGET ${CORE_RUNTIME_TARGET} POST_BUILD COMMAND ${CMAKE_STRIP} *.so )
# add_custom_command ( TARGET ${CORE_RUNTIME_TARGET} POST_BUILD COMMAND ${CMAKE_STRIP} $<TARGET_FILE_NAME:${CORE_RUNTIME_TARGET}> )
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" )

Expand Down
153 changes: 122 additions & 31 deletions src/cmake_modules/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(<VAR> NAMES name1 [name2...] [HINTS path1 [path2 ... ENV var]] [RESULT <var>]
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(<VAR> NAMES name1 [name2...] [HINTS path1 [path2 ... ENV var]] [RESULT <var>]
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.
Expand All @@ -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
Expand All @@ -87,30 +131,77 @@ endfunction ()
## and a library version string.
function ( get_version DEFAULT_VERSION_STRING )

parse_version ( ${DEFAULT_VERSION_STRING} )

## 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 ()

set( VERSION_STRING "${VERSION_STRING}" PARENT_SCOPE )
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 )

# 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_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()
Loading

0 comments on commit ae653de

Please sign in to comment.