From 68c763f3d0a1f683ddffab784a8452ec75c35a7a Mon Sep 17 00:00:00 2001 From: Ashutosh Mishra Date: Tue, 18 Oct 2022 10:35:37 +0530 Subject: [PATCH] Inital commit of the new lib package Signed-off-by: Ashutosh Mishra Change-Id: I605c3fb56584806dc6b392230e64d304449819f6 --- CMakeLists.txt | 162 +++++++++++++++++++++++++++++++++++++++++++++ README.txt | 93 ++++++++++++++++++++++++++ copyright | 37 +++++++++++ rocm-core.postinst | 65 ++++++++++++++++++ rocm-core.prerm | 25 +++++++ rocm_version.cpp | 77 +++++++++++++++++++++ rocm_version.h.in | 92 +++++++++++++++++++++++++ rocmmod.in | 16 +++++ utils.cmake | 156 +++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 723 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 README.txt create mode 100644 copyright create mode 100755 rocm-core.postinst create mode 100755 rocm-core.prerm create mode 100644 rocm_version.cpp create mode 100644 rocm_version.h.in create mode 100644 rocmmod.in create mode 100644 utils.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..54910944f2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,162 @@ +################################################################################ +## +## The University of Illinois/NCSA +## Open Source License (NCSA) +## +## Copyright (c) 2014-2018, 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.16 ) +set( CORE_TARGET "rocm-core" ) + +project( ${CORE_TARGET} CXX ) + +## Verbose output. +set( CMAKE_VERBOSE_MAKEFILE on ) + +include( utils.cmake ) +include( GNUInstallDirs ) + +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( COPYRIGHT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/copyright" ) +set( BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR} ) + +if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/rocm_version.h.in ) + file( READ "${CMAKE_CURRENT_SOURCE_DIR}/rocm_version.h.in" VER ) + + string( REGEX MATCH "ROCM_VERSION_MAJOR ([0-9]*)" _ ${VER} ) + set( ROCM_VERSION ${CMAKE_MATCH_1} ) + string( REGEX MATCH "ROCM_VERSION_MINOR ([0-9]*)" _ ${VER} ) + set( ROCM_VERSION "${ROCM_VERSION}.${CMAKE_MATCH_1}" ) + string( REGEX MATCH "ROCM_VERSION_PATCH ([0-9]*)" _ ${VER} ) + set( ROCM_VERSION "${ROCM_VERSION}.${CMAKE_MATCH_1}" ) + message( STATUS "ROCM_VERSION = ${ROCM_VERSION}" ) +else() + message( FATAL_ERROR "${CMAKE_CURRENT_SOURCE_DIR}/rocm_version.h.in does not exists." ) +endif() + +## Set the version +parse_rocm_version( ${ROCM_VERSION} ) +set_variables() + +if( DEFINED BUILD_ID ) + set( PACKAGE_BUILD_INFO "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT_COUNT}-${BUILD_ID}-${VERSION_HASH}" ) +else() + set( PACKAGE_BUILD_INFO "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT_COUNT}-9999-${VERSION_HASH}" ) +endif() + +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocmmod.in ${BUILD_DIR}/rocmmod @ONLY ) +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocm-core.postinst ${BUILD_DIR}/postinst @ONLY ) +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocm-core.prerm ${BUILD_DIR}/prerm @ONLY ) + +#Generate BUILD_INFO +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocm_version.h.in ${BUILD_DIR}/rocm_version.h @ONLY ) + +#Make the rocmlib +set( SRCS rocm_version.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} ) + +## Set the VERSION and SOVERSION values +set( PATCH_STRING "${VERSION_PATCH}.${ROCM_LIBPATCH_VERSION}" ) +set( SO_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${PATCH_STRING}" ) +set_property( TARGET ${CORE_TARGET} PROPERTY VERSION "${SO_VERSION_STRING}" ) +set_property( TARGET ${CORE_TARGET} PROPERTY SOVERSION "${VERSION_MAJOR}" ) + + +#intallation directive +install ( TARGETS ${CORE_TARGET} DESTINATION ${CMAKE_INSTALL_LIBDIR} PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) +install ( FILES ${BUILD_DIR}/rocm_version.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) +install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/rocmmod DESTINATION ${CMAKE_INSTALL_LIBDIR} ) + + +## Packaging directives +set ( CPACK_PACKAGE_NAME ${CORE_TARGET} ) +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 "ROCm Dev Support " ) +set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "Radeon Open Compute (ROCm) Runtime software stack" ) +set ( CPACK_RESOURCE_FILE_LICENSE "${COPYRIGHT_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 +message ( STATUS "Using CPACK_DEBIAN_PACKAGE_RELEASE ${CPACK_DEBIAN_PACKAGE_RELEASE}" ) +set ( CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT" ) + +## RPM package specific variables + +## '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" ) + +# Debian package specific variables +set ( CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEPENDS_STRING} ) +set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCm" ) +set ( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${BUILD_DIR}/postinst;${BUILD_DIR}/prerm" ) + +## RPM package specific variables +set ( CPACK_RPM_PACKAGE_REQUIRES ${RPM_DEPENDS_STRING} ) +set ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/postinst" ) +set ( CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/prerm" ) + +if ( DEFINED CPACK_PACKAGING_INSTALL_PREFIX ) + set ( CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX} ${CPACK_PACKAGING_INSTALL_PREFIX}/.info" ) +endif ( ) + +## Include packaging +include ( CPack ) diff --git a/README.txt b/README.txt new file mode 100644 index 0000000000..e0e2a7e27d --- /dev/null +++ b/README.txt @@ -0,0 +1,93 @@ + +For building : + + git clone + + cd rocm-core; mkdir -p build ; cd build + + After this invoke cmake with the following variables define as deemed fit + + + cmake \ + -DCMAKE_CURRENT_BINARY_DIR=$PWD \ + -DCMAKE_CURRENT_SOURCE_DIR=$PWD/../ \ + -DCMAKE_VERBOSE_MAKEFILE=1 \ + -DCMAKE_INSTALL_PREFIX=./ \ + -DCPACK_GENERATOR=DEB \ + .. + + make + make install + make package + +After this the package "rocm-core_1.0.0-local_amd64.deb" will be generated accordingly + +The content of which will be the following : + +$dpkg -I rocm-core_1.0.0-local_amd64.deb + new Debian package, version 2.0. + size 6604 bytes: control archive=1608 bytes. + 285 bytes, 10 lines control + 191 bytes, 3 lines md5sums + 2360 bytes, 65 lines * postinst #!/bin/bash + 593 bytes, 25 lines * prerm #!/bin/bash + Architecture: amd64 + Description: Radeon Open Compute (ROCm) Runtime software stack + Homepage: https://github.com/RadeonOpenCompute/ROCm + Maintainer: ROCm Dev Support + Package: rocm-core + Priority: optional + Section: devel + Version: 1.0.0-local + Installed-Size: 70 + + +$dpkg -c rocm-core_1.0.0-local_amd64.deb +drwxrwxr-x root/root 0 2022-11-09 09:02 ./opt/ +drwxrwxr-x root/root 0 2022-11-09 09:02 ./opt/rocm/ +drwxrwxr-x root/root 0 2022-11-09 09:02 ./opt/rocm/include/ +-rw-r--r-- root/root 2970 2022-11-09 09:02 ./opt/rocm/include/rocm_version.h +drwxrwxr-x root/root 0 2022-11-09 09:02 ./opt/rocm/lib/ +lrwxrwxrwx root/root 0 2022-11-09 09:02 ./opt/rocm/lib/librocm-core.so -> librocm-core.so.1 +lrwxrwxrwx root/root 0 2022-11-09 09:02 ./opt/rocm/lib/librocm-core.so.1 -> librocm-core.so.1.0.0. +-rwxr-xr-x root/root 17096 2022-11-09 09:02 ./opt/rocm/lib/librocm-core.so.1.0.0. +-rw-r--r-- root/root 420 2022-11-09 09:02 ./opt/rocm/lib/rocmmod + + + +The flags for the lib would the following : + +$readelf -d ./opt/rocm/lib/librocm-core.so.1.0.0. + +Dynamic section at offset 0x2de0 contains 28 entries: + Tag Type Name/Value + 0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6] + 0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1] + 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] + 0x000000000000000e (SONAME) Library soname: [librocm-core.so.1] + 0x000000000000000c (INIT) 0x1000 + 0x000000000000000d (FINI) 0x12dc + 0x0000000000000019 (INIT_ARRAY) 0x3dd0 + 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) + 0x000000000000001a (FINI_ARRAY) 0x3dd8 + 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) + 0x000000006ffffef5 (GNU_HASH) 0x2f0 + 0x0000000000000005 (STRTAB) 0x480 + 0x0000000000000006 (SYMTAB) 0x318 + 0x000000000000000a (STRSZ) 558 (bytes) + 0x000000000000000b (SYMENT) 24 (bytes) + 0x0000000000000003 (PLTGOT) 0x4000 + 0x0000000000000002 (PLTRELSZ) 168 (bytes) + 0x0000000000000014 (PLTREL) RELA + 0x0000000000000017 (JMPREL) 0x820 + 0x0000000000000007 (RELA) 0x760 + 0x0000000000000008 (RELASZ) 192 (bytes) + 0x0000000000000009 (RELAENT) 24 (bytes) + 0x000000006ffffffb (FLAGS_1) Flags: NODELETE + 0x000000006ffffffe (VERNEED) 0x6d0 + 0x000000006fffffff (VERNEEDNUM) 3 + 0x000000006ffffff0 (VERSYM) 0x6ae + 0x000000006ffffff9 (RELACOUNT) 3 + 0x0000000000000000 (NULL) 0x0 + + diff --git a/copyright b/copyright new file mode 100644 index 0000000000..6a2ccdfb1b --- /dev/null +++ b/copyright @@ -0,0 +1,37 @@ +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. diff --git a/rocm-core.postinst b/rocm-core.postinst new file mode 100755 index 0000000000..728f6e6ff5 --- /dev/null +++ b/rocm-core.postinst @@ -0,0 +1,65 @@ +#!/bin/bash + +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 + update-alternatives --install "/opt/rocm" "rocm" "@CPACK_PACKAGING_INSTALL_PREFIX@" "$altscore" + for loc in "/usr/share/modules/modulefiles" "/usr/local/Modules/modulefiles" "/usr/share/Modules/modulefiles" + do + if [ -d "$loc" ] + then + update-alternatives --install "$loc/rocmmod@ROCM_VERSION@" "rocmod@ROCM_VERSION@" "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/rocmmod" "$altscore" + break; + fi + done + true +} + +if [ -e /etc/lsb-release ] && source /etc/lsb-release && [ "$DISTRIB_ID" = "Ubuntu" ] +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/rocm-core.prerm b/rocm-core.prerm new file mode 100755 index 0000000000..bb83e250bd --- /dev/null +++ b/rocm-core.prerm @@ -0,0 +1,25 @@ +#!/bin/bash + +do_update_alternatives(){ + # skip update if program doesn't exist + command -v update-alternatives >/dev/null || return 0 + # Update the /opt/rocm symlink + update-alternatives --remove "rocm" "@CPACK_PACKAGING_INSTALL_PREFIX@" + update-alternatives --remove "rocmod@ROCM_VERSION@" "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/rocmmod"|| true +} + +if [ -e /etc/lsb-release ] && source /etc/lsb-release && [ "$DISTRIB_ID" = "Ubuntu" ] +then + case "$1" in + (remove | upgrade) + do_update_alternatives + ;; + (purge) + ;; + (*) + exit 0 + ;; + esac +else + do_update_alternatives +fi diff --git a/rocm_version.cpp b/rocm_version.cpp new file mode 100644 index 0000000000..e8ac822258 --- /dev/null +++ b/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/rocm_version.h.in b/rocm_version.h.in new file mode 100644 index 0000000000..03539232be --- /dev/null +++ b/rocm_version.h.in @@ -0,0 +1,92 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// The University of Illinois/NCSA +// Open Source License (NCSA) +// +// Copyright (c) 2014-2021, 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. +// +//////////////////////////////////////////////////////////////////////////////// + + +#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 1 +#define ROCM_VERSION_MINOR 0 +#define ROCM_VERSION_PATCH 0 +#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/rocmmod.in b/rocmmod.in new file mode 100644 index 0000000000..584c00582f --- /dev/null +++ b/rocmmod.in @@ -0,0 +1,16 @@ +#%Module1.0###################################################################### +## +## Rocm module +## + +module-whatis "adds `@CPACK_PACKAGING_INSTALL_PREFIX@/bin' to your PATH environment variable" + +proc ModulesHelp { } { + puts stderr "\tThe ROCM Module." +} + + +prepend-path PATH "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@:@CPACK_PACKAGING_INSTALL_PREFIX@/llvm/bin:@CPACK_PACKAGING_INSTALL_PREFIX@/opencl/bin" +prepend-path CMAKE_PREFIX_PATH "@CPACK_PACKAGING_INSTALL_PREFIX@" +setenv ROCM_PATH "@CPACK_PACKAGING_INSTALL_PREFIX@" +setenv HIP_PATH "@CPACK_PACKAGING_INSTALL_PREFIX@/hip" diff --git a/utils.cmake b/utils.cmake new file mode 100644 index 0000000000..d3431590e7 --- /dev/null +++ b/utils.cmake @@ -0,0 +1,156 @@ +################################################################################ +## +## The University of Illinois/NCSA +## Open Source License (NCSA) +## +## Copyright (c) 2014-2018, 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. +## +################################################################################ + +## 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 ( 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() + + if ( DEFINED 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 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 ) + + message(STATUS "VERSION_MAJOR : ${VERSION_MAJOR}" ) + message(STATUS "VERSION_MINOR : ${VERSION_MINOR}" ) + message(STATUS "VERSION_PATCH : ${VERSION_PATCH}" ) + message(STATUS "VERSION_COMMIT_COUNT : ${VERSION_COMMIT_COUNT}" ) + message(STATUS "VERSION_HASH : ${VERSION_HASH}" ) + message(STATUS "CPACK_DEBIAN_PACKAGE_RELEASE : ${CPACK_DEBIAN_PACKAGE_RELEASE}" ) + message(STATUS "CPACK_RPM_PACKAGE_RELEASE : ${CPACK_RPM_PACKAGE_RELEASE}" ) + +endfunction() + +