From f1da5591b58e7c5f09ac3aa88aef85257b87478d Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Fri, 25 Feb 2022 00:41:34 -0800 Subject: [PATCH] File reorganization with backward compatibility Wrapper header files Soft link to libraries and binaries rocm_smi.py and rsmiBindings.py installed in libexec/rocm_smi Binaries, libraries and header files installed as per File Reorg folder structure Change-Id: I3166ab67f89c2ae4aafbc87bb00c9a5233221ade --- CMakeLists.txt | 6 +- DEBIAN/postinst.in | 2 +- RPM/post.in | 2 +- oam/CMakeLists.txt | 6 +- python_smi_tools/rsmiBindings.py | 4 +- rocm_smi-backward-compat.cmake | 190 +++++++++++++++++++++++++++++++ rocm_smi/CMakeLists.txt | 50 +++----- 7 files changed, 220 insertions(+), 40 deletions(-) create mode 100644 rocm_smi-backward-compat.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ffecf08b8f..561a035b35 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,10 @@ set(CMN_INC_LIST ${CMN_INC_LIST} "${SHR_MUTEX_DIR}/shared_mutex.h") add_subdirectory("rocm_smi") add_subdirectory("oam") +option(FILE_REORG_BACKWARD_COMPATIBILITY "Enable File Reorg with backward compatibility" ON) +if(FILE_REORG_BACKWARD_COMPATIBILITY) + include(rocm_smi-backward-compat.cmake) +endif() #TODO: Should use GNUInstallDirs to match distro standards #This need fix in subdirectory CMakefile as well #include(GNUInstallDirs) @@ -190,7 +194,7 @@ install(EXPORT rocm_smiTargets DESTINATION #License file set(CPACK_RPM_PACKAGE_LICENSE "NCSA") -install( FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION share/doc/smi-lib RENAME LICENSE.txt) +install( FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION share/doc/${ROCM_SMI} RENAME LICENSE.txt) ########################### # Packaging directives diff --git a/DEBIAN/postinst.in b/DEBIAN/postinst.in index 74ee2db0a7..5fda052286 100755 --- a/DEBIAN/postinst.in +++ b/DEBIAN/postinst.in @@ -5,7 +5,7 @@ set -e do_ldconfig() { # left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build if [ "@ENABLE_LDCONFIG@" == "ON" ]; then - echo @CPACK_PACKAGING_INSTALL_PREFIX@/rocm_smi/lib > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf + echo @CPACK_PACKAGING_INSTALL_PREFIX@/lib > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf ldconfig fi } diff --git a/RPM/post.in b/RPM/post.in index 52e78fce17..df1074537a 100755 --- a/RPM/post.in +++ b/RPM/post.in @@ -1,5 +1,5 @@ # left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build if [ "@ENABLE_LDCONFIG@" == "ON" ]; then - echo -e "@CPACK_PACKAGING_INSTALL_PREFIX@/rocm_smi/lib\n@CPACK_PACKAGING_INSTALL_PREFIX@/rocm_smi/lib64" > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf + echo -e "@CPACK_PACKAGING_INSTALL_PREFIX@/lib\n@CPACK_PACKAGING_INSTALL_PREFIX@/lib64" > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf ldconfig fi diff --git a/oam/CMakeLists.txt b/oam/CMakeLists.txt index 6373a84dda..8cbf9dd918 100644 --- a/oam/CMakeLists.txt +++ b/oam/CMakeLists.txt @@ -101,12 +101,12 @@ target_include_directories(${OAM_TARGET} ## Add the install directives for the runtime library. install(TARGETS ${OAM_TARGET} EXPORT rocm_smiTargets - LIBRARY DESTINATION ${OAM_NAME}/lib - ARCHIVE DESTINATION ${OAM_NAME}/lib + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib COMPONENT ${OAM_COMPONENT}) install(FILES ${COMMON_SRC_ROOT}/oam/include/oam/oam_mapi.h ${COMMON_SRC_ROOT}/oam/include/oam/amd_oam.h - DESTINATION oam/include/oam) + DESTINATION include/oam) # Generate Doxygen documentation if (DOXYGEN_FOUND) diff --git a/python_smi_tools/rsmiBindings.py b/python_smi_tools/rsmiBindings.py index d11ab62058..090b85c3d8 100644 --- a/python_smi_tools/rsmiBindings.py +++ b/python_smi_tools/rsmiBindings.py @@ -10,7 +10,9 @@ from enum import Enum import os # Use ROCm installation path if running from standard installation -path_librocm = os.path.dirname(os.path.realpath(__file__)) + '/../lib/librocm_smi64.so' +# With File Reorg rsmiBindings.py will be installed in /opt/rocm/libexec/rocm_smi. +# relative path changed accordingly +path_librocm = os.path.dirname(os.path.realpath(__file__)) + '/../../lib/librocm_smi64.so' if not os.path.isfile(path_librocm): print('Unable to find %s . Trying /opt/rocm*' % path_librocm) for root, dirs, files in os.walk('/opt', followlinks=True): diff --git a/rocm_smi-backward-compat.cmake b/rocm_smi-backward-compat.cmake new file mode 100644 index 0000000000..2dff82ad4a --- /dev/null +++ b/rocm_smi-backward-compat.cmake @@ -0,0 +1,190 @@ +# Copyright (c) 2022 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.8) + +set(RSMI_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(RSMI_WRAPPER_DIR ${RSMI_BUILD_DIR}/wrapper_dir) +set(RSMI_WRAPPER_INC_DIR ${RSMI_WRAPPER_DIR}/include/${ROCM_SMI}) +set(OAM_TARGET_NAME "oam") +set(OAM_WRAPPER_INC_DIR ${RSMI_WRAPPER_DIR}/include/${OAM_TARGET_NAME}) +set(RSMI_WRAPPER_LIB_DIR ${RSMI_WRAPPER_DIR}/${ROCM_SMI}/lib) +set(OAM_WRAPPER_LIB_DIR ${RSMI_WRAPPER_DIR}/${OAM_TARGET_NAME}/lib) +## package headers +set(PUBLIC_RSMI_HEADERS + rocm_smi.h + ${ROCM_SMI_TARGET}Config.h + kfd_ioctl.h) +set(OAM_HEADERS + oam_mapi.h + amd_oam.h) + +#Function to generate header template file +function(create_header_template) + file(WRITE ${RSMI_WRAPPER_DIR}/header.hpp.in "/* + Copyright (c) 2022 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. + */\n\n#ifndef @include_guard@\n#define @include_guard@ \n\n#pragma message(\"This file is deprecated. Use file from include path /opt/rocm-ver/include/ and prefix with ${ROCM_SMI}\")\n@include_statements@ \n\n#endif") +endfunction() + +#use header template file and generate wrapper header files +function(generate_wrapper_header) + file(MAKE_DIRECTORY ${RSMI_WRAPPER_INC_DIR}) + #Generate wrapper header files from the list + foreach(header_file ${PUBLIC_RSMI_HEADERS}) + # set include guard + get_filename_component(INC_GAURD_NAME ${header_file} NAME_WE) + string(TOUPPER ${INC_GAURD_NAME} INC_GAURD_NAME) + set(include_guard "${include_guard}COMGR_WRAPPER_INCLUDE_${INC_GAURD_NAME}_H") + #set #include statement + get_filename_component(file_name ${header_file} NAME) + set(include_statements "${include_statements}#include \"../../../include/${ROCM_SMI}/${file_name}\"\n") + configure_file(${RSMI_WRAPPER_DIR}/header.hpp.in ${RSMI_WRAPPER_INC_DIR}/${file_name}) + unset(include_guard) + unset(include_statements) + endforeach() + +#OAM Wrpper Header file generation + file(MAKE_DIRECTORY ${OAM_WRAPPER_INC_DIR}) + #Generate wrapper header files from the list + foreach(header_file ${OAM_HEADERS}) + # set include guard + get_filename_component(INC_GAURD_NAME ${header_file} NAME_WE) + string(TOUPPER ${INC_GAURD_NAME} INC_GAURD_NAME) + set(include_guard "${include_guard}COMGR_WRAPPER_INCLUDE_${INC_GAURD_NAME}_H") + #set #include statement + get_filename_component(file_name ${header_file} NAME) + set(include_statements "${include_statements}#include \"../../../include/${OAM_TARGET_NAME}/${file_name}\"\n") + configure_file(${RSMI_WRAPPER_DIR}/header.hpp.in ${OAM_WRAPPER_INC_DIR}/${file_name}) + unset(include_guard) + unset(include_statements) + endforeach() + +endfunction() + +#function to create symlink to binaries +function(create_binary_symlink) + file(MAKE_DIRECTORY ${RSMI_WRAPPER_DIR}/bin) + + file(GLOB binary_files ${COMMON_SRC_ROOT}/python_smi_tools/*.py ) + foreach(binary_file ${binary_files}) + get_filename_component(file_name ${binary_file} NAME) + add_custom_target(link_${file_name} ALL + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E create_symlink + ../../libexec/${ROCM_SMI}/${file_name} ${RSMI_WRAPPER_DIR}/bin/${file_name}) + endforeach() + #soft link rocm_smi binary + add_custom_target(link_${ROCM_SMI} ALL + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E create_symlink + ../../bin/${ROCM_SMI} ${RSMI_WRAPPER_DIR}/bin/${ROCM_SMI}) +endfunction() + +#function to create symlink to libraries +function(create_library_symlink) + + file(MAKE_DIRECTORY ${RSMI_WRAPPER_LIB_DIR}) + if(BUILD_SHARED_LIBS) + + #get rsmi lib versions + set(SO_VERSION_GIT_TAG_PREFIX "rsmi_so_ver") + get_version_from_tag("1.0.0.0" ${SO_VERSION_GIT_TAG_PREFIX} GIT) + if(${ROCM_PATCH_VERSION}) + set(VERSION_PATCH ${ROCM_PATCH_VERSION}) + set(SO_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") + else() + set(SO_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}") + endif() + + #link RSMI library files + set(LIB_RSMI "${ROCM_SMI_LIB_NAME}.so") + set(library_files "${LIB_RSMI}" "${LIB_RSMI}.${VERSION_MAJOR}" "${LIB_RSMI}.${SO_VERSION_STRING}") + else() + set(LIB_RSMI "${ROCM_SMI_LIB_NAME}.a") + set(library_files "${LIB_RSMI}") + endif() + + foreach(file_name ${library_files}) + add_custom_target(link_${file_name} ALL + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E create_symlink + ../../lib/${file_name} ${RSMI_WRAPPER_LIB_DIR}/${file_name}) + endforeach() + + file(MAKE_DIRECTORY ${OAM_WRAPPER_LIB_DIR}) + if(BUILD_SHARED_LIBS) + + #get OAM lib versions + set(SO_VERSION_GIT_TAG_PREFIX "oam_so_ver") + get_version_from_tag("1.0.0.0" ${SO_VERSION_GIT_TAG_PREFIX} GIT) + if(${ROCM_PATCH_VERSION}) + set(VERSION_PATCH ${ROCM_PATCH_VERSION}) + set(SO_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") + else() + set(SO_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}") + endif() + + #link OAM library files + set(LIB_OAM "lib${OAM_TARGET_NAME}.so") + set(library_files "${LIB_OAM}" "${LIB_OAM}.${VERSION_MAJOR}" "${LIB_OAM}.${SO_VERSION_STRING}") + else() + set(LIB_OAM "lib${OAM_TARGET_NAME}.a") + set(library_files "${LIB_OAM}") + endif() + + foreach(file_name ${library_files}) + add_custom_target(link_${file_name} ALL + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E create_symlink + ../../lib/${file_name} ${OAM_WRAPPER_LIB_DIR}/${file_name}) + endforeach() + +endfunction() + +#Creater a template for header file +create_header_template() +#Use template header file and generater wrapper header files +generate_wrapper_header() +install(DIRECTORY ${RSMI_WRAPPER_INC_DIR} DESTINATION ${ROCM_SMI}/include) +install(DIRECTORY ${OAM_WRAPPER_INC_DIR} DESTINATION ${OAM_TARGET_NAME}/include) +# Create symlink to binaries +create_binary_symlink() +install(DIRECTORY ${RSMI_WRAPPER_DIR}/bin DESTINATION ${ROCM_SMI}) +# Create symlink to library files +create_library_symlink() +install(DIRECTORY ${RSMI_WRAPPER_LIB_DIR} DESTINATION ${ROCM_SMI} COMPONENT lib${ROCM_SMI}) +install(DIRECTORY ${OAM_WRAPPER_LIB_DIR} DESTINATION ${OAM_TARGET_NAME} COMPONENT lib${OAM_TARGET_NAME} ) diff --git a/rocm_smi/CMakeLists.txt b/rocm_smi/CMakeLists.txt index e6c49b87e9..862199d3e3 100755 --- a/rocm_smi/CMakeLists.txt +++ b/rocm_smi/CMakeLists.txt @@ -102,51 +102,35 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL Release) POST_BUILD COMMAND ${CMAKE_STRIP} lib${ROCM_SMI_TARGET}.so.${SO_VERSION_STRING}) endif() endif () +#file reorganization changes +#rocm_smi.py moved to libexec/rocm_smi. so creating rocm-smi symlink +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) +add_custom_target(link-rocm-smi ALL + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E create_symlink + ../libexec/${ROCM_SMI}/rocm_smi.py ${CMAKE_CURRENT_BINARY_DIR}/bin/rocm-smi) -## Add symlinks from top level ROCm lib dir to rocm-smi lib so files -if(${BUILD_SHARED_LIBS}) - add_custom_target ( so-link ALL WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E create_symlink - ../${ROCM_SMI}/lib/${ROCM_SMI_LIB_NAME}.so so-link ) - add_custom_target ( so-major-link ALL WORKING_DIRECTORY - ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} - -E create_symlink - ../${ROCM_SMI}/lib/${ROCM_SMI_LIB_NAME}.so.${VERSION_MAJOR} - so-major-link ) - - install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/so-link DESTINATION lib RENAME - ${ROCM_SMI_LIB_NAME}.so ) - install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/so-major-link DESTINATION lib - RENAME ${ROCM_SMI_LIB_NAME}.so.${VERSION_MAJOR} ) -endif() ## Add the install directives for the runtime library. install(TARGETS ${ROCM_SMI_TARGET} EXPORT rocm_smiTargets - LIBRARY DESTINATION ${ROCM_SMI}/lib - ARCHIVE DESTINATION ${ROCM_SMI}/lib + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib COMPONENT ${ROCM_SMI_COMPONENT}) install(FILES ${COMMON_SRC_ROOT}/include/rocm_smi/rocm_smi.h - DESTINATION rocm_smi/include/rocm_smi) + DESTINATION include/rocm_smi) install(FILES ${COMMON_SRC_ROOT}/include/rocm_smi/${ROCM_SMI_TARGET}Config.h - DESTINATION rocm_smi/include/rocm_smi) + DESTINATION include/rocm_smi) install(FILES ${COMMON_SRC_ROOT}/include/rocm_smi/kfd_ioctl.h - DESTINATION rocm_smi/include/rocm_smi) + DESTINATION include/rocm_smi) install(FILES ${COMMON_SRC_ROOT}/python_smi_tools/rsmiBindings.py - DESTINATION rocm_smi/bindings) + DESTINATION libexec/${ROCM_SMI}) install(FILES ${COMMON_SRC_ROOT}/python_smi_tools/rocm_smi.py PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + DESTINATION libexec/${ROCM_SMI}) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bin/rocm-smi DESTINATION bin) -install(FILES ${COMMON_SRC_ROOT}/python_smi_tools/rocm-smi - DESTINATION bin) -add_custom_target(bindings_link ALL - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E create_symlink - ../rocm_smi/bindings/rsmiBindings.py bindings_link) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bindings_link - DESTINATION bin RENAME rsmiBindings.py) - # Generate Doxygen documentation find_package(Doxygen) @@ -173,9 +157,9 @@ if (DOXYGEN_FOUND AND LATEX_FOUND) add_dependencies(${ROCM_SMI_TARGET} docs) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/latex/refman.pdf - DESTINATION ${ROCM_SMI}/docs/${RSMI_MANUAL_NAME}.pdf) + DESTINATION share/doc/${ROCM_SMI} RENAME ${RSMI_MANUAL_NAME}.pdf) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../README.md - DESTINATION ${ROCM_SMI}/docs/) + DESTINATION share/doc/${ROCM_SMI}/) else() message("Doxygen or Latex is not found. Will not generate documents.") endif(DOXYGEN_FOUND AND LATEX_FOUND)