From 0ec78f1daac2d7fa1415f4deff0d129252c1c9de Mon Sep 17 00:00:00 2001 From: raramakr <91213141+raramakr@users.noreply.github.com> Date: Mon, 8 Jan 2024 11:20:41 -0800 Subject: [PATCH] SWDEV-428379 - Set LD_LIBRARY_PATH for executing the binaries from build directory (#449) * SWDEV-428379 - Set LD_LIBRARY_PATH for executing the binaries from build directory The binaries rocfft_aot_helper and stockham_aot are getting executed from build directory during build time. The hardcoded RUNPATH in this binaries are helping to find the required libraries. Hardcoded RUNPATH will be removed and will be having relative RUNPATH with respect to install directory. LD_LIBRARY_PATH need to set during build time for a successfull exectuion of the binaries * SWDEV-436762 - Honor the LD_LIBRARY_PATH set by build scripts In ASAN build, the environment variable LD_LIBRARY_PATH is used to set libclang_rt.asan.so library path. Use the LD_LIBRARY_PATH provided by build script * SWDEV-437149 - Add RPATH to the binary rocfft_rtc_helper Since the binary is installed in /opt/rocm-ver/lib/rocfft/version_string folder, it need relative RPATH $ORIGIN/../../../lib to find rocm libraries --- library/src/CMakeLists.txt | 11 +++++++++-- library/src/device/CMakeLists.txt | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/library/src/CMakeLists.txt b/library/src/CMakeLists.txt index 29d5555b..24c1058e 100644 --- a/library/src/CMakeLists.txt +++ b/library/src/CMakeLists.txt @@ -55,8 +55,13 @@ target_include_directories( rocfft_rtc_helper PRIVATE $ ) +# rocfft_rtc_helper will be installed in /opt/rocm-ver/lib/rocfft/VERSION_STRING +# To find rocm libraries need the relative RPATH +set(APPEND_ROCMLIB_RPATH "\$ORIGIN/../../../lib") target_link_libraries( rocfft_rtc_helper PRIVATE rocfft-rtc-compile ) -set_target_properties( rocfft_rtc_helper PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON ) +set_target_properties( rocfft_rtc_helper PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON + BUILD_WITH_INSTALL_RPATH TRUE + INSTALL_RPATH "${APPEND_ROCMLIB_RPATH}" ) # Package that helps me set visibility for function names exported # from shared library @@ -517,9 +522,11 @@ endif() set( AMDGPU_TARGETS_AOT ${AMDGPU_TARGETS} ) list( REMOVE_ITEM AMDGPU_TARGETS_AOT gfx803 ) list( REMOVE_ITEM AMDGPU_TARGETS_AOT gfx900 ) +# The binary will be having relative RUNPATH with respect to install directory +# Set LD_LIBRARY_PATH for executing the binary from build directory. add_custom_command( OUTPUT rocfft_kernel_cache.db - COMMAND rocfft_aot_helper \"${ROCFFT_BUILD_KERNEL_CACHE_PATH}\" ${ROCFFT_KERNEL_CACHE_PATH} $ ${AMDGPU_TARGETS_AOT} + COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${ROCM_PATH}/${CMAKE_INSTALL_LIBDIR}" ./rocfft_aot_helper \"${ROCFFT_BUILD_KERNEL_CACHE_PATH}\" ${ROCFFT_KERNEL_CACHE_PATH} $ ${AMDGPU_TARGETS_AOT} DEPENDS rocfft_aot_helper rocfft_rtc_helper COMMENT "Compile default kernels and solution-map kernels into shipped cache file" ) diff --git a/library/src/device/CMakeLists.txt b/library/src/device/CMakeLists.txt index ec02a654..5b6de5a9 100644 --- a/library/src/device/CMakeLists.txt +++ b/library/src/device/CMakeLists.txt @@ -112,8 +112,10 @@ if( STATUS AND NOT STATUS EQUAL 0 ) message( FATAL_ERROR "Kernel generator failed (list): ${STATUS}") endif() +# stockham_aot will be having relative RUNPATH with respect to package install directory +# Set LD_LIBRARY_PATH for running the executable from build directory add_custom_command(OUTPUT ${gen_headers} - COMMAND ${PYTHON3_EXE} ${kgen} + COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${ROCM_PATH}/${CMAKE_INSTALL_LIBDIR}" ${PYTHON3_EXE} ${kgen} --pattern=${GENERATOR_PATTERN} --precision=${GENERATOR_PRECISION} --manual-small=${GENERATOR_MANUAL_SMALL_SIZE}