Merge "SWDEV-291455 - File Reorganization with backward compatibility" into amd-staging

This commit is contained in:
Ranjith Ramakrishnan
2022-03-04 19:21:56 -05:00
committed by Gerrit Code Review
6 changed files with 145 additions and 27 deletions
+13 -2
View File
@@ -11,6 +11,7 @@ include(GNUInstallDirs)
option(BUILD_TESTS "Enable building OpenCL tests" OFF)
option(EMU_ENV "Enable building for emulation environment" OFF)
option(FILE_REORG_BACKWARD_COMPATIBILITY "Enable File Reorganization backward compatibility" ON)
set(OPENCL_ICD_LOADER_HEADERS_DIR "${CMAKE_CURRENT_LIST_DIR}/khronos/headers/opencl2.2" CACHE PATH "")
@@ -62,13 +63,18 @@ if(DEFINED ENV{ROCM_LIBPATCH_VERSION})
message("Using CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}")
endif()
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/rocm/opencl" CACHE PATH "Package Installation path for OpenCL")
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Package Installation path for OpenCL")
#ROCM_PATH is needed to create symlink of libraries
if(NOT DEFINED ROCM_PATH)
string(REPLACE "/opencl" "" ROCM_PATH ${CPACK_PACKAGING_INSTALL_PREFIX})
endif()
message (STATUS "ROCM Installation path(ROCM_PATH): ${ROCM_PATH}")
#TODO: Once build script changes are in , the string replace statement can be removed
if(FILE_REORG_BACKWARD_COMPATIBILITY)
if(CPACK_PACKAGING_INSTALL_PREFIX)
string(REPLACE "/opencl" "" CPACK_PACKAGING_INSTALL_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX})
endif()
endif()
#Package: rocm-opencl,rocm-opencl-dev/devel,rocm-ocl-icd
@@ -80,4 +86,9 @@ configure_file(packaging/rocm-ocl-icd.rpm_postun ${BUILD_DIR}/rpm_postun @ONLY)
add_subdirectory(packaging)
#File reorg Backward compatibility function
if(FILE_REORG_BACKWARD_COMPATIBILITY)
include(opencl-backward-compat.cmake)
endif()
endif()
+132
View File
@@ -0,0 +1,132 @@
# 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(OPENCL ${PROJECT_NAME})
set(OPENCL_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(OPENCL_WRAPPER_DIR ${OPENCL_BUILD_DIR}/wrapper_dir)
set(OPENCL_WRAPPER_INC_DIR ${OPENCL_WRAPPER_DIR}/include/CL)
set(OPENCL_WRAPPER_BIN_DIR ${OPENCL_WRAPPER_DIR}/bin)
set(OPENCL_WRAPPER_LIB_DIR ${OPENCL_WRAPPER_DIR}/lib)
#Function to generate header template file
function(create_header_template)
file(WRITE ${OPENCL_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 CL\")\n@include_statements@ \n\n#endif")
endfunction()
#use header template file and generate wrapper header files
function(generate_wrapper_header)
file(MAKE_DIRECTORY ${OPENCL_WRAPPER_INC_DIR})
set(HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/khronos/headers/opencl2.2/CL )
#find all header files from CL folder
file(GLOB include_files ${CMAKE_CURRENT_SOURCE_DIR}/khronos/headers/opencl2.2/CL/*)
#remove files that are not required in package
list(REMOVE_ITEM include_files ${HEADER_DIR}/cl_egl.h ${HEADER_DIR}/cl_dx9_media_sharing.h ${HEADER_DIR}/cl_d3d11.h ${HEADER_DIR}/cl_d3d10.h)
#Generate wrapper header files
foreach(header_file ${include_files})
# 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}OPENCL_WRAPPER_INCLUDE_${INC_GAURD_NAME}_H")
#set #include statement
get_filename_component(file_name ${header_file} NAME)
set(include_statements "${include_statements}#include \"../../../include/CL/${file_name}\"\n")
configure_file(${OPENCL_WRAPPER_DIR}/header.hpp.in ${OPENCL_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 ${OPENCL_WRAPPER_BIN_DIR})
set(file_name "clinfo")
add_custom_target(link_${file_name} ALL
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E create_symlink
../../bin/${file_name} ${OPENCL_WRAPPER_BIN_DIR}/${file_name})
endfunction()
#function to create symlink to libraries
function(create_library_symlink)
file(MAKE_DIRECTORY ${OPENCL_WRAPPER_LIB_DIR})
set(LIB_OPENCL "libOpenCL.so")
set(MAJ_VERSION "${OPENCL_LIB_VERSION_MAJOR}")
set(SO_VERSION "${OPENCL_LIB_VERSION_STRING}")
set(library_files "${LIB_OPENCL}" "${LIB_OPENCL}.${MAJ_VERSION}" "${LIB_OPENCL}.${SO_VERSION}")
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} ${OPENCL_WRAPPER_LIB_DIR}/${file_name})
endforeach()
if(BUILD_SHARED_LIBS)
set(LIB_AMDDOC "libamdocl64.so")
else()
set(LIB_AMDDOC "libamdocl64.a")
endif()
set(file_name "${LIB_AMDDOC}")
add_custom_target(link_${file_name} ALL
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E create_symlink
../../lib/${file_name} ${OPENCL_WRAPPER_DIR}/${file_name})
endfunction()
#Creater a template for header file
create_header_template()
#Use template header file and generater wrapper header files
generate_wrapper_header()
install(DIRECTORY ${OPENCL_WRAPPER_INC_DIR} DESTINATION ${OPENCL}/include COMPONENT dev)
# Create symlink to binaries
create_binary_symlink()
install(DIRECTORY ${OPENCL_WRAPPER_BIN_DIR} DESTINATION ${OPENCL} COMPONENT binary)
option(BUILD_SHARED_LIBS "Build the shared library" ON)
# Create symlink to libraries
create_library_symlink()
install(DIRECTORY ${OPENCL_WRAPPER_LIB_DIR} DESTINATION ${OPENCL} COMPONENT icd)
if(BUILD_SHARED_LIBS)
install(FILES ${OPENCL_WRAPPER_DIR}/libamdocl64.so DESTINATION ${OPENCL}/lib COMPONENT binary)
else()
install(FILES ${OPENCL_WRAPPER_DIR}/libamdocl64.a DESTINATION ${OPENCL}/lib COMPONENT binary)
endif()
-5
View File
@@ -3,7 +3,6 @@
set -e
INSTALL_PATH=@CPACK_PACKAGING_INSTALL_PREFIX@
ROCM_LIBPATH=@ROCM_PATH@/lib
do_ldconfig() {
echo ${INSTALL_PATH}/lib > /etc/ld.so.conf.d/10-rocm-opencl.conf && ldconfig
@@ -15,10 +14,6 @@ case "$1" in
echo "$1"
;;
configure)
mkdir -p ${ROCM_LIBPATH}
ln -s -f -r ${INSTALL_PATH}/lib/libOpenCL.so ${ROCM_LIBPATH}/libOpenCL.so
ln -s -f -r ${INSTALL_PATH}/lib/libOpenCL.so.@OPENCL_LIB_VERSION_MAJOR@ ${ROCM_LIBPATH}/libOpenCL.so.@OPENCL_LIB_VERSION_MAJOR@
ln -s -f -r ${INSTALL_PATH}/lib/libOpenCL.so.@OPENCL_LIB_VERSION_STRING@ ${ROCM_LIBPATH}/libOpenCL.so.@OPENCL_LIB_VERSION_STRING@
do_ldconfig
;;
*)
-9
View File
@@ -11,15 +11,6 @@ case "$1" in
purge)
;;
remove | upgrade )
rm -f @ROCM_PATH@/lib/libOpenCL.so
rm -f @ROCM_PATH@/lib/libOpenCL.so.@OPENCL_LIB_VERSION_MAJOR@
rm -f @ROCM_PATH@/lib/libOpenCL.so.@OPENCL_LIB_VERSION_STRING@
if [ -e "@ROCM_PATH@" ] ; then
if [ -e "@ROCM_PATH@/lib" ] ; then
rmdir --ignore-fail-on-non-empty @ROCM_PATH@/lib
fi
rmdir --ignore-fail-on-non-empty @ROCM_PATH@
fi
rm_ldconfig
;;
*)
-6
View File
@@ -1,10 +1,4 @@
INSTALL_PATH=@CPACK_PACKAGING_INSTALL_PREFIX@
ROCM_LIBPATH=@ROCM_PATH@/lib
echo ${INSTALL_PATH}/lib > /etc/ld.so.conf.d/10-rocm-opencl.conf && ldconfig
mkdir -p /etc/OpenCL/vendors && (echo libamdocl64.so > /etc/OpenCL/vendors/@OPENCL_AMD_ICD_FILE@)
mkdir -p ${ROCM_LIBPATH}
ln -s -f -r ${INSTALL_PATH}/lib/libOpenCL.so ${ROCM_LIBPATH}/libOpenCL.so
ln -s -f -r ${INSTALL_PATH}/lib/libOpenCL.so.@OPENCL_LIB_VERSION_MAJOR@ ${ROCM_LIBPATH}/libOpenCL.so.@OPENCL_LIB_VERSION_MAJOR@
ln -s -f -r ${INSTALL_PATH}/lib/libOpenCL.so.@OPENCL_LIB_VERSION_STRING@ ${ROCM_LIBPATH}/libOpenCL.so.@OPENCL_LIB_VERSION_STRING@
-5
View File
@@ -3,11 +3,6 @@ if [ $1 -le 1 ]; then
rm -f /etc/ld.so.conf.d/10-rocm-opencl.conf && ldconfig
rm -f /etc/OpenCL/vendors/@OPENCL_AMD_ICD_FILE@
rm -f @ROCM_PATH@/lib/libOpenCL.so
rm -f @ROCM_PATH@/lib/libOpenCL.so.@OPENCL_LIB_VERSION_MAJOR@
rm -f @ROCM_PATH@/lib/libOpenCL.so.@OPENCL_LIB_VERSION_STRING@
rmdir --ignore-fail-on-non-empty @ROCM_PATH@/lib
rmdir --ignore-fail-on-non-empty @ROCM_PATH@
fi