diff --git a/projects/rocm-core/.azuredevops/rocm-ci.yml b/projects/rocm-core/.azuredevops/rocm-ci.yml new file mode 100644 index 0000000000..8d61d8f456 --- /dev/null +++ b/projects/rocm-core/.azuredevops/rocm-ci.yml @@ -0,0 +1,38 @@ +resources: + repositories: + - repository: pipelines_repo + type: github + endpoint: ROCm + name: ROCm/ROCm + +variables: +- group: common +- template: /.azuredevops/variables-global.yml@pipelines_repo + +trigger: + batch: true + branches: + include: + - master + paths: + exclude: + - 'CHANGELOG.md' + - 'CODEOWNERS' + - 'copyright' + - 'README.txt' + +pr: + autoCancel: true + branches: + include: + - master + paths: + exclude: + - 'CHANGELOG.md' + - 'CODEOWNERS' + - 'copyright' + - 'README.txt' + drafts: false + +jobs: + - template: ${{ variables.CI_COMPONENT_PATH }}/rocm-core.yml@pipelines_repo diff --git a/projects/rocm-core/.github/palamida.yml b/projects/rocm-core/.github/palamida.yml new file mode 100644 index 0000000000..2a54378973 --- /dev/null +++ b/projects/rocm-core/.github/palamida.yml @@ -0,0 +1,5 @@ +disabled: false +scmId: gh-emu-rocm +branchesToScan: + - amd-staging + - amd-mainline diff --git a/projects/rocm-core/.github/workflows/kws-caller.yml b/projects/rocm-core/.github/workflows/kws-caller.yml new file mode 100644 index 0000000000..c0f4f26807 --- /dev/null +++ b/projects/rocm-core/.github/workflows/kws-caller.yml @@ -0,0 +1,15 @@ +name: Rocm Validation Suite KWS +on: + push: + branches: [amd-staging, amd-mainline] + pull_request: + types: [opened, synchronize, reopened] + workflow_dispatch: +jobs: + kws: + if: ${{ github.event_name == 'pull_request' }} + uses: AMD-ROCm-Internal/rocm_ci_infra/.github/workflows/kws.yml@mainline + secrets: inherit + with: + pr_number: ${{github.event.pull_request.number}} + base_branch: ${{github.base_ref}} diff --git a/projects/rocm-core/.github/workflows/rocm_ci_caller.yml b/projects/rocm-core/.github/workflows/rocm_ci_caller.yml new file mode 100644 index 0000000000..15981c8b59 --- /dev/null +++ b/projects/rocm-core/.github/workflows/rocm_ci_caller.yml @@ -0,0 +1,26 @@ +name: ROCm CI Caller +on: + # Commenting below to avoid re-runs of amd smi for trivial rebases + pull_request: + branches: [release/rocm-rel-*, amd-mainline] + types: [opened, reopened, synchronize] + push: + branches: [amd-mainline] + workflow_dispatch: + issue_comment: + types: [created] + +jobs: + call-workflow: + if: github.event_name != 'issue_comment' ||(github.event_name == 'issue_comment' && github.event.issue.pull_request && (startsWith(github.event.comment.body, '!verify') || startsWith(github.event.comment.body, '!verify release') || startsWith(github.event.comment.body, '!verify retest'))) + uses: AMD-ROCm-Internal/rocm_ci_infra/.github/workflows/rocm_ci.yml@mainline + secrets: inherit + with: + input_sha: ${{github.event_name == 'pull_request' && github.event.pull_request.head.sha || (github.event_name == 'push' && github.sha) || (github.event_name == 'issue_comment' && github.event.issue.pull_request.head.sha) || github.sha}} + input_pr_num: ${{github.event_name == 'pull_request' && github.event.pull_request.number || (github.event_name == 'issue_comment' && github.event.issue.number) || 0}} + input_pr_url: ${{github.event_name == 'pull_request' && github.event.pull_request.html_url || (github.event_name == 'issue_comment' && github.event.issue.pull_request.html_url) || ''}} + input_pr_title: ${{github.event_name == 'pull_request' && github.event.pull_request.title || (github.event_name == 'issue_comment' && github.event.issue.pull_request.title) || ''}} + repository_name: ${{ github.repository }} + base_ref: ${{github.event_name == 'pull_request' && github.event.pull_request.base.ref || (github.event_name == 'issue_comment' && github.event.issue.pull_request.base.ref) || github.ref}} + trigger_event_type: ${{ github.event_name }} + comment_text: ${{ github.event_name == 'issue_comment' && github.event.comment.body || '' }} diff --git a/projects/rocm-core/CHANGELOG.md b/projects/rocm-core/CHANGELOG.md new file mode 100644 index 0000000000..2e86a42f2e --- /dev/null +++ b/projects/rocm-core/CHANGELOG.md @@ -0,0 +1,20 @@ +Change Logs for rocm-core + +ROCm6.4.1 release + - Added changelog.debian and copyright for debian packages. +ROCm6.3.0 release + - Enabled Support for CMAKE Module Config. +ROCm6.1.0 release + - Added new API to get ROCm install Path (getROCmInstallPath()) at runtime + using dlinfo of rocm-core Target Library. +ROCm6.0.0 release + - Added script to convert RUNPATH in libraries and binaries to RPATH. + - Disabled ROCm file reorg backward compatibility + +ROCm5.6.0 release + - Added initial support for Adress Sanitizer(ASAN) enabled builds. + - Full support of ASAN will be coming in later release + +ROCm5.5.0 release + - Added module file support for ROCm. + - From ROCm5.5.0 release ROCm module files can be loaded as rocm/5.5.0 diff --git a/projects/rocm-core/CMakeLists.txt b/projects/rocm-core/CMakeLists.txt new file mode 100644 index 0000000000..cc6a8f6839 --- /dev/null +++ b/projects/rocm-core/CMakeLists.txt @@ -0,0 +1,319 @@ +################################################################################ +## +## MIT License +## +## Copyright (c) 2017 - 2023 Advanced Micro Devices, Inc. All rights Reserved. +## +## Permission is hereby granted, free of charge, to any person obtaining a copy +## of this software and associated documentation files (the "Software"), to deal +## in 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: +## +## The above copyright notice and this permission notice shall be included in all +## copies or substantial portions of the Software. +## +## 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 +## AUTHORS 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 IN THE +## SOFTWARE. +## +################################################################################ + +cmake_minimum_required( VERSION 3.16 ) +set( CORE_TARGET "rocm-core" ) + +project( ${CORE_TARGET} CXX ) + +## Define Lib Target Name and Lib Target Install Dir to be available to c++ source +add_definitions( -DTARGET_LIBRARY_NAME=\"${CORE_TARGET}\" -DTARGET_LIBRARY_INSTALL_DIR=\"${CMAKE_INSTALL_LIBDIR}\" ) + +## Build Type Settings +set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." ) + +## Verbose output. +set( CMAKE_VERBOSE_MAKEFILE on ) +include( GNUInstallDirs ) + +if(ENABLE_ASAN_PACKAGING) + # Only libraries required for ASAN Package + set( CPACK_COMPONENTS_ALL CORE_ASAN ) + set( COMP_TYPE "CORE_ASAN" ) + set( PKG_DESCRIPTION "ROCm AddressSanitizer Instrumented Runtime software stack" ) + set( CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DOCDIR}-asan" ) +else() + if(BUILD_SHARED_LIBS) + set( CPACK_COMPONENTS_ALL CORE_RUNTIME ) + set( COMP_TYPE "CORE_RUNTIME" ) + set( PKG_DESCRIPTION "ROCm Runtime software stack" ) + else() + set( CPACK_COMPONENTS_ALL CORE_STATIC ) + set( STATIC_COMP_TYPE "CORE_STATIC" ) + set( PKG_DESCRIPTION "ROCm Static software stack" ) + endif() +endif() + +include( utils.cmake ) + +#Parse Version +message( STATUS "ROCM_VERSION = ${ROCM_VERSION}" ) +parse_rocm_version( ${ROCM_VERSION} ) + +set( CPACK_PACKAGING_INSTALL_PREFIX "/opt/rocm" CACHE PATH "default cpack directory" ) +set( BUILD_SHARED_LIBS ON CACHE BOOL "Build shared library (.so) or not." ) +set( CPACK_GENERATOR "TGZ;DEB;RPM" CACHE STRING "package types to be produced " ) +set( LICENSE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/copyright" CACHE PATH "Path to License File in source dir" ) +set( BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR} ) +set( EXTENDED_PACKAGE_DESCRIPTION + "ROCM-CORE package helps to get ROCm release version,get install path. + It is also important to note that ROCM-CORE takes the role as a base + component on which all of ROCm can depend, to make it easy to remove + all of ROCm with a package manager." ) + +set( BUILD_ENABLE_LINTIAN_OVERRIDES OFF CACHE BOOL "Enable/Disable Lintian Overrides" ) +set( BUILD_DEBIAN_PKGING_FLAG OFF CACHE BOOL "Internal Status Flag to indicate Debian Packaging Build" ) + +## Set variables +set_variables() + +set( SO_MAJOR "1") +set( SO_MINOR "0" ) + +if( NOT DEFINED BUILD_ID ) + set( BUILD_ID "9999") +endif() + +#Add the libpatch version if available +if( DEFINED VERSION_POINT ) + set( PACKAGE_BUILD_INFO "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_POINT}.${VERSION_COMMIT_COUNT}-${BUILD_ID}-${VERSION_HASH}" ) + message ( STATUS "PACKAGE_BUILD_INFO ${PACKAGE_BUILD_INFO}" ) +else () + set( PACKAGE_BUILD_INFO "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT_COUNT}-${BUILD_ID}-${VERSION_HASH}" ) +endif() + +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocmmod.in ${BUILD_DIR}/rocmmod @ONLY ) + +# Setting Permission 0755 for pre/post install scripts +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocm-core.postinst ${BUILD_DIR}/postinst + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE @ONLY ) +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocm-core.prerm ${BUILD_DIR}/prerm + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE @ONLY ) + +#Generate BUILD_INFO +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocm_version.h.in ${BUILD_DIR}/rocm_version.h @ONLY ) +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocm_getpath.h.in ${BUILD_DIR}/rocm_getpath.h @ONLY ) + +#Make the rocmlib +set( SRCS rocm_version.cpp rocm_getpath.cpp) +add_library( ${CORE_TARGET} ${SRCS} ) + +set( CXX_FLAGS ${CXX_FLAGS} -g -fPIC -fvisibility=hidden -W -Wall -Wextra -Wno-unused-parameter -Wformat-security -Wundef -Wshadow -Wpointer-arith -Wcast-qual -Wmissing-declarations -Wredundant-decls -Wunreachable-code -std=c++11 ) +set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,nodelete -Wl,-no-undefined" ) +target_include_directories( ${CORE_TARGET} PRIVATE ${BUILD_DIR} ) +if(BUILD_SHARED_LIBS) + target_link_libraries( ${CORE_TARGET} PRIVATE dl ) +endif() + +## Set the VERSION and SOVERSION values +set( SO_VERSION_STRING "${SO_MAJOR}.${SO_MINOR}.${ROCM_LIBPATCH_VERSION}" ) +set_property( TARGET ${CORE_TARGET} PROPERTY VERSION "${SO_VERSION_STRING}" ) +set_property( TARGET ${CORE_TARGET} PROPERTY SOVERSION "${SO_MAJOR}" ) + +#Add the libpatch version if available to the version file +if( DEFINED VERSION_POINT ) + file ( WRITE "${CMAKE_CURRENT_BINARY_DIR}/version" "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_POINT}\n" ) +else() + file ( WRITE "${CMAKE_CURRENT_BINARY_DIR}/version" "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}\n" ) +endif() + +## Support for Static and Shared Target Packaging +if(BUILD_SHARED_LIBS) + install ( FILES ${BUILD_DIR}/version DESTINATION .info COMPONENT CORE_RUNTIME ) + + # Target Library needs to installed/packaged to same destination + # in both ASAN and nonASAN Shared library builds + install ( TARGETS ${CORE_TARGET} EXPORT rocmCoreTargets DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT ${COMP_TYPE} ) + install ( FILES ${BUILD_DIR}/rocm_version.h ${BUILD_DIR}/rocm_getpath.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rocm-core + COMPONENT CORE_RUNTIME ) + + install ( PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/runpath_to_rpath.py + DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/rocm-core + COMPONENT CORE_RUNTIME ) + install ( FILES ${BUILD_DIR}/rocmmod + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT CORE_RUNTIME ) + +else() + install ( FILES ${BUILD_DIR}/version + DESTINATION .info + COMPONENT ${STATIC_COMP_TYPE} ) + install ( TARGETS ${CORE_TARGET} + EXPORT rocmCoreTargets + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT ${STATIC_COMP_TYPE} ) + + install ( FILES ${BUILD_DIR}/rocm_version.h ${BUILD_DIR}/rocm_getpath.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rocm-core + COMPONENT ${STATIC_COMP_TYPE} ) + + install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/runpath_to_rpath.py + DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/rocm-core + COMPONENT ${STATIC_COMP_TYPE} ) + install ( FILES ${BUILD_DIR}/rocmmod + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT ${STATIC_COMP_TYPE} ) +endif() + +## Cmake module config file configurations +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/" CACHE INTERNAL "Default module path.") + +## Export the package for use from the build-tree +## (this registers the build-tree with a global CMake-registry) +export(PACKAGE ${CORE_TARGET}) +set(CONF_LIB_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + +## Create the rocm-core-config.cmake and rocm-core-config-version files +include(CMakePackageConfigHelpers) +set(CONFIG_PACKAGE_INSTALL_DIR ${CONF_LIB_DIR}/cmake/${CORE_TARGET}) +set(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") +set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}") +set(BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}") +set(PKG_MAINTAINER_NM "ROCm Dev Support") +set(PKG_MAINTAINER_EMAIL "rocm-dev.support@amd.com") + +## Generate Config File for rocm-core +configure_package_config_file( + ${CMAKE_MODULE_PATH}/${CORE_TARGET}-config.cmake.in + ${BUILD_DIR}/${CORE_TARGET}-config.cmake + INSTALL_DESTINATION ${CONFIG_PACKAGE_INSTALL_DIR} + PATH_VARS LIB_INSTALL_DIR INCLUDE_INSTALL_DIR BIN_INSTALL_DIR +) + +## Generate config Version File for rocm-core +write_basic_package_version_file( + ${BUILD_DIR}/${CORE_TARGET}-config-version.cmake + VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" + COMPATIBILITY SameMajorVersion) + +## Install the rocm-core-config.cmake and rocm-core-config-version.cmake +install(FILES + "${PROJECT_BINARY_DIR}/${CORE_TARGET}-config.cmake" + "${PROJECT_BINARY_DIR}/${CORE_TARGET}-config-version.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${CORE_TARGET}" + COMPONENT ${COMP_TYPE}) + +## Install the export set for use with the install-tree +install(EXPORT rocmCoreTargets DESTINATION + "${CMAKE_INSTALL_LIBDIR}/cmake/${CORE_TARGET}" COMPONENT ${COMP_TYPE}) + +## Packaging directives +set ( CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc." ) +set ( CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR} ) +set ( CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR} ) +set ( CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH} ) +set ( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}" ) +set ( CPACK_PACKAGE_CONTACT "${PKG_MAINTAINER_NM} <${PKG_MAINTAINER_EMAIL}>" ) +set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PKG_DESCRIPTION}" ) +set ( CPACK_RESOURCE_FILE_LICENSE "${LICENSE_FILE}" ) +## packaging variables +if ( DEFINED ROCM_LIBPATCH_VERSION ) + set ( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}.${ROCM_LIBPATCH_VERSION}" ) + message ( STATUS "Using CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}" ) +endif() + +## Debian package specific variables +set ( CPACK_DEB_COMPONENT_INSTALL ON ) +set ( CPACK_DEBIAN_CORE_RUNTIME_PACKAGE_NAME "${CORE_TARGET}" ) +# ASAN package name +set ( CPACK_DEBIAN_CORE_ASAN_PACKAGE_NAME ${CORE_TARGET}-asan ) +# STATIC package name - For Now, No change for static package Name from default +set ( CPACK_DEBIAN_CORE_STATIC_PACKAGE_NAME ${CORE_TARGET} ) +message ( STATUS "Using CPACK_DEBIAN_PACKAGE_RELEASE ${CPACK_DEBIAN_PACKAGE_RELEASE}" ) +set ( CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT" ) + +# Debian specific packaging configuration +if(COMP_TYPE) + configure_debian_pkg( ${CORE_TARGET} ${COMP_TYPE} ${CPACK_PACKAGE_VERSION} ${PKG_MAINTAINER_NM} ${PKG_MAINTAINER_EMAIL} ) +elseif(STATIC_COMP_TYPE) + configure_debian_pkg( ${CORE_TARGET} ${STATIC_COMP_TYPE} ${CPACK_PACKAGE_VERSION} ${PKG_MAINTAINER_NM} ${PKG_MAINTAINER_EMAIL} ) +endif() + +## RPM package specific variables +set ( CPACK_RPM_COMPONENT_INSTALL ON ) +set ( CPACK_RPM_CORE_RUNTIME_PACKAGE_NAME "${CORE_TARGET}" ) +# ASAN package name +set ( CPACK_RPM_CORE_ASAN_PACKAGE_NAME ${CORE_TARGET}-asan ) +# STATIC package name - For Now, No change for static package Name from default +set ( CPACK_RPM_CORE_STATIC_PACKAGE_NAME ${CORE_TARGET} ) + +## 'dist' breaks manual builds on debian systems due to empty Provides +execute_process( COMMAND rpm --eval %{?dist} + RESULT_VARIABLE PROC_RESULT + OUTPUT_VARIABLE EVAL_RESULT + OUTPUT_STRIP_TRAILING_WHITESPACE ) + +if ( PROC_RESULT EQUAL "0" AND NOT EVAL_RESULT STREQUAL "" ) + string ( APPEND CPACK_RPM_PACKAGE_RELEASE "%{?dist}" ) +endif() +message(STATUS "Using CPACK_RPM_PACKAGE_RELEASE: ${CPACK_RPM_PACKAGE_RELEASE}") +set ( CPACK_RPM_FILE_NAME "RPM-DEFAULT" ) +# #!/usr/bin/env is converted to /usr/libexec/platform-python in some OS like RHEL +# Prevent the modification of python interpreter directives in runpath_to_rpath.py +set( CPACK_RPM_SPEC_MORE_DEFINE "\n%undefine __brp_mangle_shebangs") + +# Debian Lintian Fix - Add Dependency for Python Script delivered +set( DEB_DEPENDS_STRING "python3, libc6" ) + +# Debian package specific variables +set ( CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEPENDS_STRING} ) +set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/ROCm/rocm-core" ) +set ( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${BUILD_DIR}/postinst;${BUILD_DIR}/prerm" ) +set ( CPACK_DEBIAN_CORE_RUNTIME_PACKAGE_DEPENDS ${DEB_DEPENDS_STRING} ) +set ( CPACK_DEBIAN_CORE_ASAN_PACKAGE_DEPENDS ${CORE_TARGET} ) +set ( CPACK_DEBIAN_CORE_RUNTIME_PACKAGE_CONTROL_EXTRA "${CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA}" ) +set ( CPACK_DEBIAN_CORE_STATIC_PACKAGE_CONTROL_EXTRA "${CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA}" ) +set ( CPACK_DEBIAN_PACKAGE_DESCRIPTION "${EXTENDED_PACKAGE_DESCRIPTION}" ) + +## RPM package specific variables +set ( CPACK_RPM_PACKAGE_REQUIRES ${RPM_DEPENDS_STRING} ) +set ( CPACK_RPM_PACKAGE_LICENSE "MIT" ) +set ( CPACK_RPM_CORE_ASAN_PACKAGE_REQUIRES ${CORE_TARGET} ) +set ( CPACK_RPM_CORE_RUNTIME_POST_INSTALL_SCRIPT_FILE "${BUILD_DIR}/postinst" ) +set ( CPACK_RPM_CORE_RUNTIME_POST_UNINSTALL_SCRIPT_FILE "${BUILD_DIR}/prerm" ) +set ( CPACK_RPM_CORE_STATIC_POST_INSTALL_SCRIPT_FILE "${BUILD_DIR}/postinst" ) +set ( CPACK_RPM_CORE_STATIC_POST_UNINSTALL_SCRIPT_FILE "${BUILD_DIR}/prerm" ) +set ( CPACK_RPM_PACKAGE_DESCRIPTION "${EXTENDED_PACKAGE_DESCRIPTION}" ) + +if ( DEFINED CPACK_PACKAGING_INSTALL_PREFIX ) + set ( CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION + "${CPACK_PACKAGING_INSTALL_PREFIX} ${CPACK_PACKAGING_INSTALL_PREFIX}/.info" ) +endif() + +# Backward compatibility support for deprecated package rocm-clang-ocl +# TODO: To be removed after two releases +set(CPACK_DEBIAN_RUNTIME_PACKAGE_REPLACES "rocm-clang-ocl") +set(CPACK_DEBIAN_RUNTIME_PACKAGE_CONFLICTS "rocm-clang-ocl") +set(CPACK_RPM_RUNTIME_PACKAGE_OBSOLETES "rocm-clang-ocl") + +# Custom installation for Debian Lintian File +if( BUILD_ENABLE_LINTIAN_OVERRIDES STREQUAL "ON" AND BUILD_DEBIAN_PKGING_FLAG STREQUAL "ON") + set( OVERRIDE_FILE "${CMAKE_BINARY_DIR}/DEBIAN/${DEB_OVERRIDES_INSTALL_FILENM}" ) + if(COMP_TYPE) + set( OVERRIDE_TEMP_INSTALL_LOC "/_CPack_Packages/Linux/DEB/${CORE_TARGET}-${CPACK_PACKAGE_VERSION}-Linux/${COMP_TYPE}" ) + elseif(STATIC_COMP_TYPE) + set( OVERRIDE_TEMP_INSTALL_LOC "/_CPack_Packages/Linux/DEB/${CORE_TARGET}-${CPACK_PACKAGE_VERSION}-Linux/${STATIC_COMP_TYPE}" ) + endif() + set(CPACK_INSTALL_COMMANDS + "${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}${OVERRIDE_TEMP_INSTALL_LOC}${DEB_OVERRIDES_INSTALL_PATH}" + "${CMAKE_COMMAND} -E copy ${OVERRIDE_FILE} ${CMAKE_BINARY_DIR}${OVERRIDE_TEMP_INSTALL_LOC}${DEB_OVERRIDES_INSTALL_PATH}" + ) +endif() + +## Include packaging +include ( CPack ) diff --git a/projects/rocm-core/CODEOWNERS b/projects/rocm-core/CODEOWNERS new file mode 100644 index 0000000000..d239e886d7 --- /dev/null +++ b/projects/rocm-core/CODEOWNERS @@ -0,0 +1 @@ +* @nunnikri @frepaul @raramakr @ashutom @amd-isparry @arvindcheru diff --git a/projects/rocm-core/CONTRIBUTING.md b/projects/rocm-core/CONTRIBUTING.md new file mode 100644 index 0000000000..002210e947 --- /dev/null +++ b/projects/rocm-core/CONTRIBUTING.md @@ -0,0 +1,161 @@ +# ROCM-CORE Contributing Guide +To ensure the quality of the ROCM-CORE code base, the ROCM-CORE team has +established a code review process to inform developers of the steps +that are required to shepherd a change-set into the repository. + +#### Table Of Contents + +[How to get started](#How-to-get-started) + +[How do I contribute?](#how-do-i-contribute) + * [Reporting Issues](#reporting-issues) + * [Creating a Pull Request](#Creating-a-Pull-Request) + +[Responsibility of the Author](#Responsibility-of-the-Author) + +[Responsibility of the Reviewer](#Responsibility-of-the-Reviewer) + +[The Review](#the-review) + +[References](#References) +## How to get started +rocm-core is a utility which can be used to get ROCm release version. +It also provides the Lmod modules files for the ROCm release. +getROCmVersion function provides the ROCm version. + +## How do I contribute +### Deliverables +All contributions you make will be under the [MIT Software License](copyright). +For each new file in repository, +Please include the licensing header +``` +/******************************************************************************* + * + * MIT License + * + * Copyright (c) 20xx Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in 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: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * 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 + * AUTHORS 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 IN THE + * SOFTWARE. + * + *******************************************************************************/ +``` + +### Formatting the code + +All the code is formatted using `clang-format`. To format a file, use: + +```shell +clang-format-10 -style=file -i +``` + + +### Reporting Issues +We use [GitHub Issues](https://github.com/ROCm/rocm-core/issues) to track public **bugs** and **enhancement requests**. + +#### Bugs +Please follow the template below to report any bugs found in ROCM-CORE: + +1. Description: ***Please be clear and descriptive*** +2. How to Reproduce the issue: +* Hardware Information: +* Docker environment or Software Version: +* Expected behavior: +* Actual behavior: +3. Any additional information: + +#### Enhancement Requests +Please follow the template below to report any enhancement requests for ROCM-CORE: + +1. Description: ***Please be clear and descriptive*** +2. Value and Motivation: +* Feature and functionalities enabled: +* Any alternatives: +3. Any additional information: + +The author must set labels (and assigns a milestone) according to his/her own understanding. + +Other contributors can change these values if they disagree. That being said, +adding a small comment explaining the motivation is highly recommended. +In this way, we keep the process flexible while cultivating mutual understanding. + +[**Note**] Most likely, the labels like "bug", "feature" or "complexity*" +would not be changed. However, "value*" or "urgency*" might be from mutual +understanding. +### Creating a Pull Request + +No changes are allowed to be directly committed to the develop +branch of the ROCM-CORE repository. All authors are required to +develop their change sets on a separate branch and then create +a pull request (PR) to merge their changes into the develop branch. + +Once a PR has been created, a developer must choose two reviewers +to review the changes made. The first reviewer should be a +technical expert in the portion of the library that the changes +are being made in. You can find a list of these experts in +[CODEOWNERS](CODEOWNERS) list. +The second reviewer should be a peer reviewer. This reviewer +can be any other ROCM-CORE developer. + +## Responsibility of the Author +The author of a PR is responsible for: + * Writing clear, well documented code + * Meeting expectations of code quality + * Verifying that the changes do not break current functionality + * Writing tests to ensure code coverage + * Report on the impact to performance + +## Responsibility of the Reviewer +Each reviewer is responsible for verifying that the changes are +clearly written in keeping with the coding styles of the library, +are documented in a way that future developers will be able to +understand the intent of the added functionality, and will +maintain or improve the overall quality of the codebase. + +Reviewer's task checklist: +1. Has the PR passed? +2. Does the PR consist of a well-organized sequence of small commits, +each of which is designed to make one specific feature or fix ? +3. Does the PR only include a reviewable amount of changes? Or it is a +consolidation of already reviewed small batches? e.g. break it into smaller +testable and reviewable tasks instead of a huge chunk at once. +4. Does the PR have sufficient documentation and easy to read and understand, +feasible for test and future maintainence, related docs already in place? +if API or functionality has changed? +5. For bugfixes and new features, new regression test created? +6. Is every PR associated with a ticket or issue number for tracking purposes? + +## The Review +During the review, reviewers will look over the changes and make +suggestions or requests for changes. + +In order to assist the reviewer in prioritizing their efforts, +authors can take the following actions: + +* Set the urgency and value labels +* Set the milestone where the changes need to be delivered +* Describe the testing procedure and post the measured effect of + the change +* Remind reviewers via email if a PR needs attention +* If a PR needs to be reviewed as soon as possible, explain to + the reviewers why a review may need to take priority + +## References + +1. [ROCM-CORE Readme](README.md) + diff --git a/projects/rocm-core/DEBIAN/changelog.in b/projects/rocm-core/DEBIAN/changelog.in new file mode 100644 index 0000000000..95ba9572fb --- /dev/null +++ b/projects/rocm-core/DEBIAN/changelog.in @@ -0,0 +1,5 @@ +@DEB_PACKAGE_NAME@ (@DEB_PACKAGE_VERSION@) stable; urgency=low + + * ROCm Runtime software stack Base Package. + -- @DEB_MAINTAINER_NAME@ <@DEB_MAINTAINER_EMAIL@> @DEB_TIMESTAMP@ + diff --git a/projects/rocm-core/DEBIAN/copyright.in b/projects/rocm-core/DEBIAN/copyright.in new file mode 100644 index 0000000000..e90d34aa20 --- /dev/null +++ b/projects/rocm-core/DEBIAN/copyright.in @@ -0,0 +1,26 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: @DEB_PACKAGE_NAME@ +Upstream-Contact: @DEB_MAINTAINER_NAME@ <@DEB_MAINTAINER_EMAIL@> +Source: https://github.com/ROCm/@DEB_PACKAGE_NAME@ +Files: * +License: @DEB_LICENSE@ +Copyright: @DEB_COPYRIGHT_YEAR@ Advanced Micro Devices, Inc. All rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in 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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +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 +AUTHORS 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 IN THE +SOFTWARE. + diff --git a/projects/rocm-core/DEBIAN/overrides.in b/projects/rocm-core/DEBIAN/overrides.in new file mode 100644 index 0000000000..6bee886c10 --- /dev/null +++ b/projects/rocm-core/DEBIAN/overrides.in @@ -0,0 +1,3 @@ +@DEB_OVERRIDES_INSTALL_FILENM@: no-copyright-file +@DEB_OVERRIDES_INSTALL_FILENM@: debian-changelog-file-missing +@DEB_OVERRIDES_INSTALL_FILENM@: dir-or-file-in-opt diff --git a/projects/rocm-core/README.md b/projects/rocm-core/README.md new file mode 100644 index 0000000000..68868bbe3c --- /dev/null +++ b/projects/rocm-core/README.md @@ -0,0 +1,217 @@ +# ROCM-CORE Introduction + +ROCM-CORE is a package which can be used to get ROCm release version, get ROCm install path information etc. +It is also important to note that ROCM-CORE takes the role as a base component on which all of ROCm can depend, +to make it easy to remove all of ROCm with a package manager. + +getROCmVersion function provides the ROCm version. + +It also provides an example Lmod modules files for the ROCm release. + +Lmod module files can be loaded with the following commands. +``` shell +module load rocm/x.y or +module load rocm +``` + +You can find sources and binaries in our [GitHub repository](https://github.com/ROCm/rocm-core). + +> [!NOTE] +> As with all ROCm projects, the documentation is open source. For more information, see [Contribute to ROCm documentation](https://rocm.docs.amd.com/en/latest/contribute/contributing.html). + +## Installing ROCM-CORE + +Before we proceed with how to install, take a look on references given below to understand System requirements, ROCm Installation prerequisites, ROCm package repository set up etc. + +### Prerequisite References + +* Refer [System Requirements](https://rocm.docs.amd.com/projects/install-on-linux/en/docs-6.2.2/reference/system-requirements.html#supported-gpus) +* Refer [ROCm installation for Linux](https://rocm.docs.amd.com/projects/install-on-linux/en/docs-6.2.2/index.html) +* A [ROCm](https://rocm.docs.amd.com/)-enabled platform +* To be noted that ROCM-CORE library primarily depends on having the C library available for the respective platform. + +### Installing with pre-built packages + +You can install ROCM-CORE on Ubuntu using + +```shell +apt-get install rocm-core +``` + +## Building ROCM-CORE from source + +You can build ROCM-CORE form source + +First, get the sources from repository. + +```shell + git clone https://github.com/ROCm/rocm-core.git +``` + +Go to Root Directory, create a build directory: + +```shell + cd rocm-core; mkdir build; cd build +``` + +Next, configure CMake. Invoke cmake with the following variables define as deemed fit + +```shell +cmake -S $PWD/../ -B . \ + -DCMAKE_VERBOSE_MAKEFILE=1 \ + -DCMAKE_INSTALL_PREFIX=./ \ + -DROCM_VERSION="6.4.0" \ + .. +``` + +>[!NOTE] +>When specifying the path for the `CMAKE_PREFIX_PATH` variable, **do not** use the tilde (`~`) +>shorthand to represent the home directory. +### Setting up install locations +By default, the install location is set to `/opt/rocm`. You can change this using +`CMAKE_INSTALL_PREFIX`: +```shell +cmake -DCMAKE_INSTALL_PREFIX= .. +``` +where rocm-core-install-path is "./" in the cmake configure command shared above. + +### Install + +Once cmake configuration successfully completed, from the same build directory run build, install targets + +```shell +cmake --build . -- +cmake --build . -- install +``` + +### Package Generated + +Once cmake configuration and build successfully completed from the same build directory trigger package generation + +```shell +cmake --build . -- package +``` + +Once successfull execution of above command "rocm-core" RPM/DEBIAN packages will be generated (ex:rocm-core_6.4.0.60400-22.04_amd64.deb, rocm-core-6.4.0.60400-x86_64.rpm). The contents of the "rocm-core" package will include the following files: + +```shell +Debian Package Sample: +$ dpkg -I rocm-core_6.4.0.60400-crdnnh.15158~22.04_amd64.deb + new debian package, version 2.0. + size 13986 bytes: control archive=2083 bytes. + 305 bytes, 10 lines control + 917 bytes, 11 lines md5sums + 2871 bytes, 75 lines * postinst #!/bin/bash + 873 bytes, 32 lines * prerm #!/bin/bash + Architecture: amd64 + Description: ROCm Runtime software stack + Homepage: https://github.com/ROCm/rocm-core + Maintainer: ROCm Dev Support + Package: rocm-core + Priority: optional + Section: devel + Version: 6.4.0.60400-crdnnh.15158~22.04 + Installed-Size: 125 + +$ dpkg -c rocm-core_6.4.0.60400-crdnnh.15158~22.04_amd64.deb +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/ +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/ +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/.info/ +-rw-r--r-- root/root 12 2024-11-22 10:37 ./opt/rocm-6.4.0/.info/version +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/include/ +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/include/rocm-core/ +-rw-r--r-- root/root 2801 2024-11-22 10:37 ./opt/rocm-6.4.0/include/rocm-core/rocm_getpath.h +-rw-r--r-- root/root 2440 2024-11-22 10:37 ./opt/rocm-6.4.0/include/rocm-core/rocm_version.h +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/lib/ +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/lib/cmake/ +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/lib/cmake/rocm-core/ +-rw-r--r-- root/root 2878 2024-11-22 10:37 ./opt/rocm-6.4.0/lib/cmake/rocm-core/rocm-core-config-version.cmake +-rw-r--r-- root/root 1590 2024-11-22 10:37 ./opt/rocm-6.4.0/lib/cmake/rocm-core/rocm-core-config.cmake +-rw-r--r-- root/root 842 2024-11-22 10:37 ./opt/rocm-6.4.0/lib/cmake/rocm-core/rocmCoreTargets-release.cmake +-rw-r--r-- root/root 3774 2024-11-22 10:37 ./opt/rocm-6.4.0/lib/cmake/rocm-core/rocmCoreTargets.cmake +lrwxrwxrwx root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/lib/librocm-core.so -> librocm-core.so.1 +lrwxrwxrwx root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/lib/librocm-core.so.1 -> librocm-core.so.1.0.60400 +-rw-r--r-- root/root 16640 2024-11-22 10:37 ./opt/rocm-6.4.0/lib/librocm-core.so.1.0.60400 +-rw-r--r-- root/root 550 2024-11-22 10:37 ./opt/rocm-6.4.0/lib/rocmmod +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/libexec/ +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/libexec/rocm-core/ +-rw-r--r-- root/root 8208 2024-11-22 10:34 ./opt/rocm-6.4.0/libexec/rocm-core/runpath_to_rpath.py +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/share/ +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/share/doc/ +drwxr-xr-x root/root 0 2024-11-22 10:37 ./opt/rocm-6.4.0/share/doc/rocm-core/ +-rw-r--r-- root/root 1113 2024-11-22 10:34 ./opt/rocm-6.4.0/share/doc/rocm-core/LICENSE.txt + +RPM Package Sample: +$ rpm -qip rocm-core-6.4.0.60400-crdnnh.15158.el8.x86_64.rpm +Name : rocm-core +Version : 6.4.0.60400 +Release : crdnnh.15158.el8 +Architecture: x86_64 +Install Date: (not installed) +Group : unknown +Size : 37096 +License : MIT +Signature : (none) +Source RPM : rocm-core-6.4.0.60400-crdnnh.15158.el8.src.rpm +Build Date : Fri 22 Nov 2024 10:41:01 AM PST +Build Host : 514dbdf6c195 +Relocations : /opt/rocm-6.4.0 +Vendor : Advanced Micro Devices, Inc. +Summary : ROCm Runtime software stack +Description : +DESCRIPTION +=========== + +This is an installer created using CPack (https://cmake.org). No additional installation instructions provided. +$ rpm -qlp rocm-core-6.4.0.60400-crdnnh.15158.el8.x86_64.rpm +/opt/rocm-6.4.0 +/opt/rocm-6.4.0/.info +/opt/rocm-6.4.0/.info/version +/opt/rocm-6.4.0/include +/opt/rocm-6.4.0/include/rocm-core +/opt/rocm-6.4.0/include/rocm-core/rocm_getpath.h +/opt/rocm-6.4.0/include/rocm-core/rocm_version.h +/opt/rocm-6.4.0/lib +/opt/rocm-6.4.0/lib/cmake +/opt/rocm-6.4.0/lib/cmake/rocm-core +/opt/rocm-6.4.0/lib/cmake/rocm-core/rocm-core-config-version.cmake +/opt/rocm-6.4.0/lib/cmake/rocm-core/rocm-core-config.cmake +/opt/rocm-6.4.0/lib/cmake/rocm-core/rocmCoreTargets-release.cmake +/opt/rocm-6.4.0/lib/cmake/rocm-core/rocmCoreTargets.cmake +/opt/rocm-6.4.0/lib/librocm-core.so +/opt/rocm-6.4.0/lib/librocm-core.so.1 +/opt/rocm-6.4.0/lib/librocm-core.so.1.0.60400 +/opt/rocm-6.4.0/lib/rocmmod +/opt/rocm-6.4.0/libexec +/opt/rocm-6.4.0/libexec/rocm-core +/opt/rocm-6.4.0/libexec/rocm-core/runpath_to_rpath.py +/opt/rocm-6.4.0/share +/opt/rocm-6.4.0/share/doc +/opt/rocm-6.4.0/share/doc/rocm-core +/opt/rocm-6.4.0/share/doc/rocm-core/LICENSE.txt + + +``` + + +## ROCM-CORE Library + +ROCM-CORE Library generated will be found in lib directory of the rocm-core package generated. + +```shell +find . -name "librocm-core.so.*" +``` + +### Sample Usage of APIs provided by rocm-core Library +#### Get ROCm Version + +For getting ROCm Version make use of getROCMVersion() API. +Sample Usage Example as shown below. + +```C +// Usage : + int mj=0,mn=0,p=0,ret=0; + ret=getROCMVersion(&mj,&mn,&p); + if(ret !=VerSuccess ) // error occured +``` + diff --git a/projects/rocm-core/cmake_modules/rocm-core-config.cmake.in b/projects/rocm-core/cmake_modules/rocm-core-config.cmake.in new file mode 100644 index 0000000000..f5fe07c8bd --- /dev/null +++ b/projects/rocm-core/cmake_modules/rocm-core-config.cmake.in @@ -0,0 +1,18 @@ +# - Config file for the rocm-core package +# It defines the following variables +# ROCM_CORE_INCLUDE_DIR - include directories for rocm-core +# ROCM_CORE_LIB_DIR - libraries to link against +# ROCM_PATH - Install Base Location for ROCM. + +@PACKAGE_INIT@ + +# Compute paths +set_and_check(rocm_core_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(ROCM_CORE_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(rocm_core_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") +set_and_check(ROCM_CORE_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") +set_and_check(ROCM_PATH "${PACKAGE_PREFIX_DIR}") + +get_filename_component(ROCM_CORE_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +include("${ROCM_CORE_CMAKE_DIR}/rocmCoreTargets.cmake") + diff --git a/projects/rocm-core/copyright b/projects/rocm-core/copyright new file mode 100644 index 0000000000..8dc3cc8167 --- /dev/null +++ b/projects/rocm-core/copyright @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 - 2024 Advanced Micro Devices, Inc. All rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in 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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +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 +AUTHORS 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 IN THE +SOFTWARE. diff --git a/projects/rocm-core/rocm-core.postinst b/projects/rocm-core/rocm-core.postinst new file mode 100755 index 0000000000..846b391bb4 --- /dev/null +++ b/projects/rocm-core/rocm-core.postinst @@ -0,0 +1,76 @@ +#!/bin/bash +set -e + +do_update_alternatives(){ + # skip update if program doesn't exist + command -v update-alternatives >/dev/null || return 0 + local altscore now + now=$(date -u +%s) # Number of seconds since 1 Jan 1970 + + # The reason for this approach rather than using the build number + # is to allow for jobs from different builds. In one build job the + # job number might be at 1200, whilst in a release job the number + # may be only 1. This approach assums that if you install a build + # with a different semantic version then the highest is the + # desired one, but if you install two with the same semver then + # the newest is the desired version. + + # Build up a score. It needs to fit in 32 bits + altscore=$((@VERSION_MAJOR@ - 3)) + altscore=$((altscore * 14 + @VERSION_MINOR@)) # Allow up to 14 minor + altscore=$((altscore * 14 + @VERSION_PATCH@)) # Allow up to 14 patch + + # So far if the version is less than 9 we have a number (altscore) + # that is less than 1175. 2**31/1175 is about 1.8 million. So + # multiply altscore by 1,000,000 and add in a factor of how many + # minutes have passed from an arbitary point in time (1,600,000,000 + # seconds after 1 Jan 1970 or Sep 13 12:26:40 2020) on the + # basis that no one is going to be installing a new version more + # often than every minute. This does get things wrong if a million + # minutes pass and you are downgrading, but the chances of someone + # waiting almost 2 years between installing a version and the + # previous patch level is small. + + + altscore=$((altscore*1000000+(now-1600000000)/60)) + + # Update the /opt/rocm symlink + # For custom location installation of rpm package, /opt/rocm symlink is not required + # TBD: For custom location installation of deb package. + if [[ ${ID_LIKE:-$ID} == "debian" ]] || [[ "$RPM_INSTALL_PREFIX0" == "/opt/rocm-"* ]] ; then + update-alternatives --install "/opt/rocm" "rocm" "@CPACK_PACKAGING_INSTALL_PREFIX@" "$altscore" + fi + + for loc in "/usr/share/modules/modulefiles" "/usr/local/Modules/modulefiles" "/usr/share/Modules/modulefiles" "/usr/share/Modules/3.2.10/modulefiles" + do + if [ -d "$loc" ] + then + mkdir -p "$loc/rocm" + if [[ ${ID_LIKE:-$ID} == "debian" ]] ; then + update-alternatives --install "$loc/rocm/@ROCM_VERSION@" "rocmmod@ROCM_VERSION@" "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/rocmmod" "$altscore" + else + update-alternatives --install "$loc/rocm/@ROCM_VERSION@" "rocmmod@ROCM_VERSION@" "$RPM_INSTALL_PREFIX0/@CMAKE_INSTALL_LIBDIR@/rocmmod" "$altscore" + fi + break; + fi + done + true +} + +if [ -e /etc/os-release ] && source /etc/os-release && [[ ${ID_LIKE:-$ID} == "debian" ]] +then + case "$1" in + (configure) + do_update_alternatives + ;; + (abort-upgrade|abort-remove|abort-deconfigure) + echo "$1" + ;; + (*) + exit 0 + ;; + esac +else + do_update_alternatives +fi + diff --git a/projects/rocm-core/rocm-core.prerm b/projects/rocm-core/rocm-core.prerm new file mode 100755 index 0000000000..2cb55fe6b7 --- /dev/null +++ b/projects/rocm-core/rocm-core.prerm @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +do_update_alternatives(){ + # skip update if program doesn't exist + command -v update-alternatives >/dev/null || return 0 + # Update the /opt/rocm symlink + if [[ ${ID_LIKE:-$ID} == "debian" ]] || [[ "$RPM_INSTALL_PREFIX0" == "/opt/rocm-"* ]] ; then + update-alternatives --remove "rocm" "@CPACK_PACKAGING_INSTALL_PREFIX@" + fi + + if [[ ${ID_LIKE:-$ID} == "debian" ]] ; then + update-alternatives --remove "rocmmod@ROCM_VERSION@" "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/rocmmod"|| true + else + update-alternatives --remove "rocmmod@ROCM_VERSION@" "$RPM_INSTALL_PREFIX0/@CMAKE_INSTALL_LIBDIR@/rocmmod"|| true + fi +} + +if [ -e /etc/os-release ] && source /etc/os-release && [[ ${ID_LIKE:-$ID} == "debian" ]] +then + case "$1" in + (remove | upgrade) + do_update_alternatives + ;; + (purge) + ;; + (*) + exit 0 + ;; + esac +else + do_update_alternatives +fi diff --git a/projects/rocm-core/rocm_getpath.cpp b/projects/rocm-core/rocm_getpath.cpp new file mode 100644 index 0000000000..182b0babea --- /dev/null +++ b/projects/rocm-core/rocm_getpath.cpp @@ -0,0 +1,168 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// MIT License +// +// Copyright (c) 2017 - 2024 Advanced Micro Devices, Inc. All rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in 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: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// 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 +// AUTHORS 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 IN THE +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include /* PATH_MAX */ +#include +#include +#include +#include "rocm_getpath.h" + +/* Macro for NULL CHECK */ +#define NULL_CHECK(ptr) if(!ptr) return PathIncorrecPararmeters; + + +/* Target Library Install Dir */ +#define TARGET_LIB_INSTALL_DIR TARGET_LIBRARY_INSTALL_DIR + +/* Target Library Name Buf Size */ +#define LIBRARY_FILENAME_BUFSZ (PATH_MAX+1) + +/* Internal Function to get Base Path - Ref from Icarus Logic*/ +static int getROCmBase(char *buf); + +/* Public Function to get the ROCm Install Base Path +// Argument1 (out) : InstallPath (char** pointer which will return InstallPath found) +// Argument2 (out) : InstallPathLen (Pointer to integer (size of InstallPath) returned) +// Usage : +// char *installPath=NULL; +// int installPathLen = 0; +// installStatus = getROCmInstallPath( &installPath, &installPathLen ); +// if(installStatus !=PathSuccess ){ // error occured +// ... +// } +// free(installPath); //caller must free allocated memory after usage. +// ... + +*/ +PathErrors_t getROCmInstallPath( char** InstallPath, unsigned int *InstallPathLen ) { + + NULL_CHECK(InstallPath); + NULL_CHECK(InstallPathLen); + int ret = PathErrorMAX; + char *bufPtr = (char *)NULL; + unsigned int bufSz = 0; + + bufPtr = (char *)malloc( LIBRARY_FILENAME_BUFSZ * sizeof(char) ); + memset( bufPtr, 0, LIBRARY_FILENAME_BUFSZ ); + *InstallPathLen = 0; + *InstallPath = NULL; + + ret = getROCmBase(bufPtr); + if (0 > ret){ + free(bufPtr); + return (PathErrors_t)ret; + } + else if (0 == ret){ + free(bufPtr); + return PathFailedToGetBase; + } + else{ + bufSz = ret;//additional char for null termination + } + + *InstallPath = bufPtr; + *InstallPathLen = bufSz; + return PathSuccess; +} + +/* General purpose function that fills the directory to find rocm related stuff */ +/* returns the offset into the buffer for the terminating NUL or -1 for error */ +/* The buffer should be at least PATH_MAX */ +static int getROCmBase(char *buf) +{ + int len=0; + char *envStr=NULL; + char libFileName[LIBRARY_FILENAME_BUFSZ]; + char *end=NULL; + + // Check Environment Variable is set for ROCM + // install base path, then use it directly. + if ((envStr = getenv("ROCM_PATH"))) { + /* User space override, essentially just copied through as long as it is not too long */ + len = strlen(envStr); + if (len > 0) { + if (envStr[len] == '/') { + /* Already has at least one terminating */ + len--; + } + if (len > PATH_MAX-1 ) { + return PathValuesTooLong; + } + strncpy(buf, envStr, len); + buf[len]='/'; + buf[len+1]='\0'; + + /* Length of string including trailing '/' */ + return len+1; + } + } + + // If Environment Variable is not set + // use dl APIs to get target lib path + // and get rocm base install path using the lib Path. +#if BUILD_SHARED_LIBS + sprintf(libFileName, "lib%s.so", TARGET_LIBRARY_NAME); + void *handle=dlopen(libFileName,RTLD_NOW); + if (!handle){ + /* We can't find the library */ + return PathLinuxRuntimeErrors; + } + /* Variable to hold the return value from dlinfo */ + struct link_map *map = (struct link_map*)NULL; + /* Query the runtime linker */ + dlinfo(handle,RTLD_DI_LINKMAP,&map); + if (map ->l_name && realpath(map ->l_name,buf)) { + /* Get Library Directory Path */ + char *end = strrchr(buf, '/'); + if (end && end > buf) { + *end = '\0'; + } + } + else{ + /* If l_name is NULL or realpath() failed + * Close handle before return error */ + dlclose(handle); + return PathLinuxRuntimeErrors; + } + + dlclose(handle); + /* find the start of substring TARGET_LIB_INSTALL_DIR + * To strip down Path up to Parent Directory of TARGET_LIB_INSTALL_DIR. */ + end=strstr(buf, TARGET_LIB_INSTALL_DIR); + if( NULL == end ){ + /* We can't find the library install directory*/ + return PathLinuxRuntimeErrors; + } + *end = '\0'; +#endif + + /* Length of Path String up to Parent Directoy (ROCm Base Path) + * with trailing '/'.*/ + len = strlen(buf); + return len; +} + diff --git a/projects/rocm-core/rocm_getpath.h.in b/projects/rocm-core/rocm_getpath.h.in new file mode 100644 index 0000000000..c0eb448f52 --- /dev/null +++ b/projects/rocm-core/rocm_getpath.h.in @@ -0,0 +1,72 @@ +//////////////////////////////////////////////////////////////////////////////// +//// +//// MIT License +//// +//// Copyright (c) 2017 - 2024 Advanced Micro Devices, Inc. All rights Reserved. +//// +//// Permission is hereby granted, free of charge, to any person obtaining a copy +//// of this software and associated documentation files (the "Software"), to deal +//// in 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: +//// +//// The above copyright notice and this permission notice shall be included in all +//// copies or substantial portions of the Software. +//// +//// 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 +//// AUTHORS 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 IN THE +//// +////////////////////////////////////////////////////////////////////////////////// + + +#ifndef _ROCM_GETPATH_H_ +#define _ROCM_GETPATH_H_ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define LIB_API_PUBLIC __attribute__ ((visibility ("default"))) + +/* Get Library Target Build Type */ +#cmakedefine01 BUILD_SHARED_LIBS + +/* Return Status Flag Definitions*/ +typedef enum { + PathSuccess=0, + PathIncorrecPararmeters = -994, + PathValuesNotDefined = -995, + PathValuesTooLong = -996, + PathFailedToGetBase = -997, + PathLinuxRuntimeErrors = -998, + PathErrorMAX = -999 //This should always be last value in the enumerations +} PathErrors_t; + +// API for getting the ROCmInstallPath +// Return val : PathErrors_t (API execution status) +// Argument1 (out) : InstallPath (char** pointer which will return InstallPath found ) +// Argument2 (out) : InstallPathLen (Pointer to integer (size of InstallPath) returned) +// Usage : +// char *installPath=NULL; +// int installPathLen = 0; +// installStatus = getROCmInstallPath( &installPath, &installPathLen ); +// if(installStatus !=PathSuccess ){ // error occured +// ... +// } +// free(installPath); //caller must free allocated memory after usage. +// ... +// } +LIB_API_PUBLIC PathErrors_t getROCmInstallPath(char **InstallPath, unsigned int *InstallPathLen) __attribute__((nonnull)) ; + +#ifdef __cplusplus +} // end extern "C" block +#endif + +#endif //_ROCM_GETPATH_H_ header guard + diff --git a/projects/rocm-core/rocm_version.cpp b/projects/rocm-core/rocm_version.cpp new file mode 100644 index 0000000000..e8ac822258 --- /dev/null +++ b/projects/rocm-core/rocm_version.cpp @@ -0,0 +1,77 @@ +#include "rocm_version.h" +#include +#include +#include + + +#define NULL_CHECK(ptr) if(!ptr) return VerIncorrecPararmeters; + + +#define CHECK_AND_REPORT_API_RESULT(val) do { \ + if(VerSuccess != val) { \ + const char *ErrStrings[VerErrorMAX]= { "VerSuccess", "VerIncorrecPararmeters", "VerValuesNotDefined" }; \ + fprintf(stderr, " API returned : %s \n", ErrStrings[val]); \ + fflush(stderr); \ + return val; \ + } \ + }while(0); + + + +VerErrors getROCmVersion(unsigned int* Major, unsigned int* Minor, unsigned int* Patch) { + + NULL_CHECK(Major) + NULL_CHECK(Minor) + NULL_CHECK(Patch) + + *Major=ROCM_VERSION_MAJOR; + *Minor=ROCM_VERSION_MINOR; + *Patch=ROCM_VERSION_PATCH; + + return VerSuccess; +} + + + +static VerErrors getBuildInfoLen( int* InfoStrlen ) { + + NULL_CHECK(InfoStrlen); +#if defined(ROCM_BUILD_INFO) + *InfoStrlen = 1 + strlen(ROCM_BUILD_INFO);//additional char for null termination +#else + return VerValuesNotDefined; +#endif //end defination checker + return VerSuccess; +} + +static VerErrors getBuildInfo( char* InfoString, int len ) { + + NULL_CHECK(InfoString); +#if defined(ROCM_BUILD_INFO) + + strcpy(InfoString,ROCM_BUILD_INFO); + InfoString[len]='\0'; +#else + return VerValuesNotDefined; +#endif //end defination checker + return VerSuccess; +} + +VerErrors printBuildInfo() { + + int lenstr=0; + VerErrors apiret=VerSuccess; + + apiret=getBuildInfoLen(&lenstr); + CHECK_AND_REPORT_API_RESULT(apiret); + + char* cstr=(char*) malloc(lenstr*sizeof(char)); + apiret=getBuildInfo(cstr,lenstr); + CHECK_AND_REPORT_API_RESULT(apiret); + + printf("\n Build Info of lib = [%s] \n",cstr); + + free(cstr); + + return VerSuccess; +} diff --git a/projects/rocm-core/rocm_version.h.in b/projects/rocm-core/rocm_version.h.in new file mode 100644 index 0000000000..f9c11a9c6f --- /dev/null +++ b/projects/rocm-core/rocm_version.h.in @@ -0,0 +1,75 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// MIT License +// +// Copyright (c) 2017 - 2023 Advanced Micro Devices, Inc. All rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in 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: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// 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 +// AUTHORS 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 IN THE +// +//////////////////////////////////////////////////////////////////////////////// + + +#ifndef _ROCM_VERSION_H_ +#define _ROCM_VERSION_H_ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#define LIB_API_PUBLIC __attribute__ ((visibility ("default"))) + + +#define ROCM_VERSION_MAJOR @VERSION_MAJOR@ +#define ROCM_VERSION_MINOR @VERSION_MINOR@ +#define ROCM_VERSION_PATCH @VERSION_PATCH@ + +#define ROCM_BUILD_INFO "@PACKAGE_BUILD_INFO@" + +typedef enum { + VerSuccess=0, + VerIncorrecPararmeters, + VerValuesNotDefined, + VerErrorMAX //This should always be last value in the enumerations +} VerErrors; + + +// API for getting the verion +// Return val : VerErros : API execution status. The parameters are valid only when the exetution status is SUCCESS==0 +LIB_API_PUBLIC VerErrors getROCmVersion(unsigned int* Major, unsigned int* Minor, unsigned int* Patch) __attribute__((nonnull)) ; +// Usage : +// int mj=0,mn=0,p=0,ret=0; +// ret=getROCMVersion(&mj,&mn,&p); +// if(ret !=VerSuccess ) // error occured +// +// check for the values and +// + + + +//API for building build info on console +LIB_API_PUBLIC VerErrors printBuildInfo(); + + +#ifdef __cplusplus +} // end extern "C" block +#endif + +#endif //_ROCM_VERSION_H_ header guard + diff --git a/projects/rocm-core/rocmmod.in b/projects/rocm-core/rocmmod.in new file mode 100644 index 0000000000..3f0466d454 --- /dev/null +++ b/projects/rocm-core/rocmmod.in @@ -0,0 +1,18 @@ +#%Module1.0###################################################################### +## +## Rocm module +## + +module-whatis "Adds ROCm binary paths to your environment variable" + +proc ModulesHelp { } { + puts stderr "\tThe ROCM Module." +} + +set ROOT [file normalize [file dirname [file normalize ${ModulesCurrentModulefile}/__]]/../..] + +prepend-path PATH "${ROOT}/@CMAKE_INSTALL_BINDIR@:${ROOT}/lib/llvm/bin" +prepend-path MANPATH "${ROOT}/@CMAKE_INSTALL_MANDIR@:${ROOT}/lib/llvm/share/man1" +prepend-path CMAKE_PREFIX_PATH "${ROOT}" +setenv ROCM_PATH "${ROOT}" +setenv HIP_PATH "${ROOT}" diff --git a/projects/rocm-core/runpath_to_rpath.py b/projects/rocm-core/runpath_to_rpath.py new file mode 100644 index 0000000000..f6a9203402 --- /dev/null +++ b/projects/rocm-core/runpath_to_rpath.py @@ -0,0 +1,180 @@ +#!/usr/bin/env python3 +################################################################################ +## +## MIT License +## +## Copyright (c) 2017 - 2023 Advanced Micro Devices, Inc. All rights Reserved. +## +## Permission is hereby granted, free of charge, to any person obtaining a copy +## of this software and associated documentation files (the "Software"), to deal +## in 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: +## +## The above copyright notice and this permission notice shall be included in all +## copies or substantial portions of the Software. +## +## 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 +## AUTHORS 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 IN THE +## SOFTWARE. +## +################################################################################ + +import os +import sys +import subprocess +import argparse +import pathlib +import re + +try: + from elftools.elf.elffile import ELFFile + from elftools.elf.dynamic import DynamicSection + from elftools.common.exceptions import ELFError + from elftools.elf.dynamic import ENUM_D_TAG +except ImportError: + print("Error : pyelftools failed to import.\n" + "Run \'pip3 install pyelftools\' to install the prerequisite\n") + +def update_rpath(search_path, excludes) : + ''' Function helps to change DT_RUNPATH in libraries and binaries in search_path to DT_RPATH. + Its done with the following steps : + 1. Check all if the file is an ELF except in excludes folder + 2. Find the DT_RUNPATH tag and its offset from file. + 3. Toggle the DT_RUNPATH(0x1d) tag byte to DT_RPATH(0xf) and write back to file ''' + for path, dirs, files in os.walk(search_path, topdown=True, followlinks=True): + dirs[:] = [d for d in dirs if d not in excludes] + print( dirs ) + for filename in files: + filename = os.path.join(path, filename) + print("Opening file ", filename) + # Open the file and check if its ELF file + try : + with open(filename, 'rb+') as file: + elffile = ELFFile(file) + # Find the dynamic section and look for DT_RUNPATH tag + section = elffile.get_section_by_name('.dynamic') + if not section: break + n = 0 + for tag in section.iter_tags(): + # DT_RUNPATH tag found. Toggle the byte to DT_RPATH + if tag.entry.d_tag == 'DT_RUNPATH': + offset = section.header.sh_offset + n* section._tagsize + section.stream.seek(offset) + section.stream.write(bytes([ENUM_D_TAG['DT_RPATH']])) # DT_PATH + print("DT_RUNPATH changed to DT_RPATH ") + break + # DT_RUNPATH tag not found. Loop to the next tag + n = n + 1 + except ELFError: + print("Discarding file as its not an ELF file", filename) + continue + except FileNotFoundError: + print("Discarding file with bad links", filename) + continue + except OSError: + print("Discarding file with OS error", filename) + continue + except Exception as ex: + print("Discarding file ", filename, ex) + continue + +def update_config_file(cfg_path): + ''' Function helps to update rocm llvm config file to default to DT_RPATH. ''' + print("Updating cfg file in", cfg_path) + config_file_exist = os.path.exists(cfg_path) + if config_file_exist: + print("cfg file exist in path, going ahead with update ") + search_str = "enable-new-dtags" + replace_str = "disable-new-dtags" + try: + # Read contents from file as a single string + file_string = '' + with open(cfg_path, 'r') as f: + file_string = f.read() + + # Use RE package for string replacement + file_string = (re.sub(search_str, replace_str, file_string)) + + # Write contents back to file. Using mode 'w' truncates the file. + with open(cfg_path, 'w') as f: + f.write(file_string) + except Exception as ex: + print("Couldnt update rocm.cfg file. ", ex) + else: + print("Config path doesnt exist", cfg_path) + +def update_compiler_config(search_path): + ''' Function search for rocm llvm config(rocm.cfg) file in the search_path folder. + If the config file is not foung search in ROCM_PATH. Once the config file is found, + update llvm config to default to DT_RPATH ''' + cfg_file_name = "rocm.cfg" + found_cfg = False + print("Searching for ", cfg_file_name) + for path, dirs, files in os.walk(search_path): + # Search for rocm.cfg in the search path and default to DT_RPATH + if cfg_file_name in files: + cfg_path = os.path.join(path, cfg_file_name) + print(" Found cfg file cfg_path") + found_cfg = True + update_config_file(cfg_path) + # Continue with the search as there could be cfg files in llvm and llvm/alt + continue; + if found_cfg: + return + # rocm.cfg config file not found in search path. Search in the ROCM_PATH. + print(cfg_file_name, " not found in search_path. Trying to search in ROCM_PATH") + try : + rocm_path = os.environ["ROCM_PATH"] + print(" Found ROCM_PATH trying for rocm.cfg") + # There are multiple possible paths for cfg file. + # ROCM_PATH/llvm/bin and ROCM_PATH/lib/llvm/bin. Also alt location + update_config_file(rocm_path + "/llvm/bin/" + cfg_file_name) + update_config_file(rocm_path + "/llvm/alt/bin/" + cfg_file_name) + update_config_file(rocm_path + "/lib/llvm/bin/" + cfg_file_name) + update_config_file(rocm_path + "/lib/llvm/alt/bin/" + cfg_file_name) + # Found config file. Change default DT_RUNPATH setting to DT_RPATH + except Exception as ex: + print("ROCM_PATH not found ", ex) + +def main(): + # The script expect a search folder as parameter. It finds all ELF files and updates RPATH + argparser = argparse.ArgumentParser( + usage='usage: %(prog)s ', + description='Find the ELF files in the specified folder and convert the RUNPATH to RPATH. \n', + add_help=False, + prog='runpath_to_rpath.py') + + argparser.add_argument('searchdir', + nargs='?', type=pathlib.Path, default=None, + help='Folder to search for ELF file. \nPlease note: Any folder with name llvm in that path will be discarded') + argparser.add_argument('-h', '--help', + action='store_true', dest='help', + help='Display this information') + + args = argparser.parse_args() + if args.help or not args.searchdir: + argparser.print_help() + sys.exit(0) + + # pyelftools is a mandatory requirement for this script. Exit if requirement is not met + if 'ELFFile' not in globals(): + print('Please install pyelftools using \'pip3 install pyelftools\' ' + + 'before using the script : runpath_to_rpath.py') + sys.exit(0) + + # Find the elf files in the serach path and update DT_RUNPATH to DT_RPATH + # SWDEV-467155 : remove the exclusion of llvm folder + excludes = [] + update_rpath(args.searchdir, excludes) + # Update rocm clang configs to default to DT_RPATH + update_compiler_config(args.searchdir) + print("Done with rpath update") + +if __name__ == "__main__": + main() diff --git a/projects/rocm-core/utils.cmake b/projects/rocm-core/utils.cmake new file mode 100644 index 0000000000..1200fb0655 --- /dev/null +++ b/projects/rocm-core/utils.cmake @@ -0,0 +1,287 @@ +################################################################################ +## +## MIT License +## +## Copyright (c) 2017 - 2023 Advanced Micro Devices, Inc. All rights Reserved. +## +## Permission is hereby granted, free of charge, to any person obtaining a copy +## of this software and associated documentation files (the "Software"), to deal +## in 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: +## +## The above copyright notice and this permission notice shall be included in all +## copies or substantial portions of the Software. +## +## 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 +## AUTHORS 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 IN THE +## SOFTWARE. +## +################################################################################ + +## Parses the VERSION_STRING variable and places +## the first, second and third number values in +## the major, minor and patch variables. +function( parse_rocm_version VERSION_STRING ) + + string ( FIND ${VERSION_STRING} "-" STRING_INDEX ) + + if ( ${STRING_INDEX} GREATER -1 ) + math ( EXPR STRING_INDEX "${STRING_INDEX} + 1" ) + string ( SUBSTRING ${VERSION_STRING} ${STRING_INDEX} -1 VERSION_BUILD ) + endif () + + string ( REGEX MATCHALL "[0123456789]+" VERSIONS ${VERSION_STRING} ) + list ( LENGTH VERSIONS VERSION_COUNT ) + + 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_COUNT} GREATER 3 ) + list ( GET VERSIONS 3 POINT ) + set ( VERSION_POINT ${POINT} PARENT_SCOPE ) + set ( TEMP_VERSION_STRING "${TEMP_VERSION_STRING}.${POINT}" ) + endif () + + if ( DEFINED VERSION_BUILD ) + set ( VERSION_BUILD "${VERSION_BUILD}" PARENT_SCOPE ) + endif () + + set ( VERSION_STRING "${TEMP_VERSION_STRING}" PARENT_SCOPE ) + +endfunction () + + +## Sets cmake variables which can be derived from existing +function( set_variables ) + set( VERSION_COMMIT_COUNT 0 ) + set( VERSION_HASH "unknown" ) + + find_program( GIT NAMES git ) + + if( GIT ) + # 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() + + #set libpatch version + if(NOT DEFINED ENV{ROCM_LIBPATCH_VERSION}) + set(ROCM_LIBPATCH_VERSION "${VERSION_MAJOR}") + string(LENGTH ${VERSION_MINOR} LENSTR) + if(LENSTR EQUAL 1) # length of version cannot be zero hence it would be 1 or greater + set(ROCM_LIBPATCH_VERSION "${ROCM_LIBPATCH_VERSION}0${VERSION_MINOR}") + else() # length is greater than 1 + set(ROCM_LIBPATCH_VERSION "${ROCM_LIBPATCH_VERSION}${VERSION_MINOR}") + endif() + + string(LENGTH ${VERSION_PATCH} LENSTR) + if(LENSTR EQUAL 1) # length of version cannot be zero hence it would be 1 or greater + set(ROCM_LIBPATCH_VERSION "${ROCM_LIBPATCH_VERSION}0${VERSION_PATCH}") + else() # length is greater than 1 + set(ROCM_LIBPATCH_VERSION "${ROCM_LIBPATCH_VERSION}${VERSION_PATCH}") + endif() + + set(ROCM_LIBPATCH_VERSION "${ROCM_LIBPATCH_VERSION}" PARENT_SCOPE ) + else() + set (ROCM_LIBPATCH_VERSION $ENV{ROCM_LIBPATCH_VERSION} PARENT_SCOPE ) + endif() + + if ( DEFINED ENV{CPACK_RPM_PACKAGE_RELEASE} ) + set ( CPACK_RPM_PACKAGE_RELEASE ${CPACK_RPM_PACKAGE_RELEASE} PARENT_SCOPE ) + else() + set ( CPACK_RPM_PACKAGE_RELEASE "local" PARENT_SCOPE ) + endif() + + if ( DEFINED ENV{CPACK_DEBIAN_PACKAGE_RELEASE} ) + set ( CPACK_DEBIAN_PACKAGE_RELEASE ${CPACK_DEBIAN_PACKAGE_RELEASE} PARENT_SCOPE ) + else() + set ( CPACK_DEBIAN_PACKAGE_RELEASE "local" PARENT_SCOPE ) + endif() + + set( VERSION_COMMIT_COUNT "${VERSION_COMMIT_COUNT}" PARENT_SCOPE ) + set( VERSION_HASH "${VERSION_HASH}" PARENT_SCOPE ) + set( VERSION_BUILD "${VERSION_BUILD}" PARENT_SCOPE ) + + message(STATUS "VERSION_MAJOR : ${VERSION_MAJOR}" ) + message(STATUS "VERSION_MINOR : ${VERSION_MINOR}" ) + message(STATUS "VERSION_PATCH : ${VERSION_PATCH}" ) + message(STATUS "VERSION_POINT : ${VERSION_POINT}" ) + message(STATUS "ROCM_LIBPATCH_VERSION : ${ROCM_LIBPATCH_VERSION}" ) + message(STATUS "VERSION_COMMIT_COUNT : ${VERSION_COMMIT_COUNT}" ) + message(STATUS "VERSION_HASH : ${VERSION_HASH}" ) + message(STATUS "VERSION_BUILD : ${VERSION_BUILD}" ) + message(STATUS "CPACK_DEBIAN_PACKAGE_RELEASE : ${CPACK_DEBIAN_PACKAGE_RELEASE}" ) + message(STATUS "CPACK_RPM_PACKAGE_RELEASE : ${CPACK_RPM_PACKAGE_RELEASE}" ) + +endfunction() + +## Configure Copyright File for Debian Package +function( configure_debian_pkg PACKAGE_NAME_T COMPONENT_NAME_T PACKAGE_VERSION_T MAINTAINER_NM_T MAINTAINER_EMAIL_T) + # Check If Debian Platform + find_file (DEBIAN debian_version debconf.conf PATHS /etc) + if(DEBIAN) + set( BUILD_DEBIAN_PKGING_FLAG ON CACHE BOOL "Internal Status Flag to indicate Debian Packaging Build" FORCE ) + set_debian_pkg_cmake_flags( ${PACKAGE_NAME_T} ${PACKAGE_VERSION_T} + ${MAINTAINER_NM_T} ${MAINTAINER_EMAIL_T} ) + + # Create debian directory in build tree + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/DEBIAN") + + # Configure the copyright file + configure_file( + "${CMAKE_SOURCE_DIR}/DEBIAN/copyright.in" + "${CMAKE_BINARY_DIR}/DEBIAN/copyright" + @ONLY + ) + + # Install copyright file + install ( FILES "${CMAKE_BINARY_DIR}/DEBIAN/copyright" + DESTINATION "${CMAKE_INSTALL_DOCDIR}" + COMPONENT ${COMPONENT_NAME_T} ) + + # Configure the changelog file + configure_file( + "${CMAKE_SOURCE_DIR}/DEBIAN/changelog.in" + "${CMAKE_BINARY_DIR}/DEBIAN/changelog.Debian" + @ONLY + ) + + if( BUILD_ENABLE_LINTIAN_OVERRIDES ) + if(NOT BUILD_SHARED_LIBS) + string(FIND ${DEB_OVERRIDES_INSTALL_FILENM} "static" OUT_VAR1) + if(OUT_VAR1 EQUAL -1) + set( DEB_OVERRIDES_INSTALL_FILENM "${DEB_OVERRIDES_INSTALL_FILENM}-static" ) + endif() + else() + if(ENABLE_ASAN_PACKAGING) + string( FIND ${DEB_OVERRIDES_INSTALL_FILENM} "asan" OUT_VAR2) + if(OUT_VAR2 EQUAL -1) + set( DEB_OVERRIDES_INSTALL_FILENM "${DEB_OVERRIDES_INSTALL_FILENM}-asan" ) + endif() + endif() + endif() + set( DEB_OVERRIDES_INSTALL_FILENM + "${DEB_OVERRIDES_INSTALL_FILENM}" CACHE STRING "Debian Package Lintian Override File Name" FORCE) + # Configure the changelog file + configure_file( + "${CMAKE_SOURCE_DIR}/DEBIAN/overrides.in" + "${CMAKE_BINARY_DIR}/DEBIAN/${DEB_OVERRIDES_INSTALL_FILENM}" + FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + @ONLY + ) + endif() + + # Install Change Log + find_program ( DEB_GZIP_EXEC gzip ) + if(EXISTS "${CMAKE_BINARY_DIR}/DEBIAN/changelog.Debian" ) + execute_process( + COMMAND ${DEB_GZIP_EXEC} -n -9 "${CMAKE_BINARY_DIR}/DEBIAN/changelog.Debian" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/DEBIAN" + RESULT_VARIABLE result + OUTPUT_VARIABLE output + ERROR_VARIABLE error + ) + if(NOT ${result} EQUAL 0) + message(FATAL_ERROR "Failed to compress: ${error}") + endif() + install ( FILES "${CMAKE_BINARY_DIR}/DEBIAN/${DEB_CHANGELOG_INSTALL_FILENM}" + DESTINATION ${CMAKE_INSTALL_DOCDIR} + COMPONENT ${COMPONENT_NAME_T}) + endif() + else() + # License file + install ( FILES ${LICENSE_FILE} + DESTINATION ${CMAKE_INSTALL_DOCDIR} RENAME LICENSE.txt + COMPONENT ${COMPONENT_NAME_T}) + endif() +endfunction() + +# Set variables for changelog and copyright +# For Debian specific Packages +function( set_debian_pkg_cmake_flags DEB_PACKAGE_NAME_T DEB_PACKAGE_VERSION_T DEB_MAINTAINER_NM_T DEB_MAINTAINER_EMAIL_T ) + # Setting configure flags + set( DEB_PACKAGE_NAME "${DEB_PACKAGE_NAME_T}" CACHE STRING "Debian Package Name" ) + set( DEB_PACKAGE_VERSION "${DEB_PACKAGE_VERSION_T}" CACHE STRING "Debian Package Version String" ) + set( DEB_MAINTAINER_NAME "${DEB_MAINTAINER_NM_T}" CACHE STRING "Debian Package Maintainer Name" ) + set( DEB_MAINTAINER_EMAIL "${DEB_MAINTAINER_EMAIL_T}" CACHE STRING "Debian Package Maintainer Email" ) + set( DEB_COPYRIGHT_YEAR "2025" CACHE STRING "Debian Package Copyright Year" ) + set( DEB_LICENSE "MIT" CACHE STRING "Debian Package License Type" ) + set( DEB_CHANGELOG_INSTALL_FILENM "changelog.Debian.gz" CACHE STRING "Debian Package ChangeLog File Name" ) + + if( BUILD_ENABLE_LINTIAN_OVERRIDES ) + set( DEB_OVERRIDES_INSTALL_FILENM "${DEB_PACKAGE_NAME}" CACHE STRING "Debian Package Lintian Override File Name" ) + set( DEB_OVERRIDES_INSTALL_PATH "/usr/share/lintian/overrides/" CACHE STRING "Deb Pkg Lintian Override Install Loc" ) + endif() + + # Get TimeStamp + find_program( DEB_DATE_TIMESTAMP_EXEC date ) + set ( DEB_TIMESTAMP_FORMAT_OPTION "-R" ) + execute_process ( + COMMAND ${DEB_DATE_TIMESTAMP_EXEC} ${DEB_TIMESTAMP_FORMAT_OPTION} + OUTPUT_VARIABLE TIMESTAMP_T + ) + set( DEB_TIMESTAMP "${TIMESTAMP_T}" CACHE STRING "Current Time Stamp for Copyright/Changelog" ) + + message(STATUS "DEB_PACKAGE_NAME : ${DEB_PACKAGE_NAME}" ) + message(STATUS "DEB_PACKAGE_VERSION : ${DEB_PACKAGE_VERSION}" ) + message(STATUS "DEB_MAINTAINER_NAME : ${DEB_MAINTAINER_NAME}" ) + message(STATUS "DEB_MAINTAINER_EMAIL : ${DEB_MAINTAINER_EMAIL}" ) + message(STATUS "DEB_COPYRIGHT_YEAR : ${DEB_COPYRIGHT_YEAR}" ) + message(STATUS "DEB_LICENSE : ${DEB_LICENSE}" ) + message(STATUS "DEB_TIMESTAMP : ${DEB_TIMESTAMP}" ) + message(STATUS "DEB_CHANGELOG_INSTALL_FILENM : ${DEB_CHANGELOG_INSTALL_FILENM}" ) +endfunction()