Skip to content

Commit

Permalink
SWDEV-428379 - Set LD_LIBRARY_PATH for executing the binary mtx2csr.e…
Browse files Browse the repository at this point in the history
…xe from build directory. (#686) (#368)

The binary mtx2csr.exe is getting executed from build directory during build time. The hardcoded RUNPATH in this binary is 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

Co-authored-by: Mohammed Junaid <[email protected]>
  • Loading branch information
raramakr and jkottiku authored Jan 8, 2024
1 parent 7f62842 commit 1c5d839
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions cmake/ClientMatrices.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ get_filename_component(CMAKE_MATRICES_DIR "${CMAKE_MATRICES_DIR}"
ABSOLUTE BASE_DIR "${CMAKE_SOURCE_DIR}")

file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR})

# Set relative RUNPATH to the executable
if(BUILD_ADDRESS_SANITIZER)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CONVERT_SOURCE} -O3 -fsanitize=address -shared-libasan -o ${PROJECT_BINARY_DIR}/mtx2csr.exe
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CONVERT_SOURCE} -O3 -fsanitize=address -shared-libasan -L${ROCM_PATH}/${CMAKE_INSTALL_LIBDIR} -Wl,--enable-new-dtags,--build-id=sha1,--rpath,$ENV{ROCM_ASAN_EXE_RPATH} -o ${PROJECT_BINARY_DIR}/mtx2csr.exe
RESULT_VARIABLE STATUS)
else()
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CONVERT_SOURCE} -O3 -o ${PROJECT_BINARY_DIR}/mtx2csr.exe
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CONVERT_SOURCE} -O3 -L${ROCM_PATH}/${CMAKE_INSTALL_LIBDIR} -Wl,--enable-new-dtags,--build-id=sha1,--rpath,$ENV{ROCM_EXE_RPATH} -o ${PROJECT_BINARY_DIR}/mtx2csr.exe
RESULT_VARIABLE STATUS)
endif()

Expand Down Expand Up @@ -174,6 +174,9 @@ foreach(i RANGE 0 ${len1})
else()
file(RENAME ${ROCSPARSE_MTX_DIR}/${mat}/${mat}.mtx ${CMAKE_MATRICES_DIR}/${mat}.mtx)
endif()
# mtx2csr.exe is having relative RUNPATH with respect to package install directory
# Set LD_LIBRARY_PATH for running the executable from build directory
set(ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH}:${ROCM_PATH}/${CMAKE_INSTALL_LIBDIR}")
execute_process(COMMAND ${PROJECT_BINARY_DIR}/mtx2csr.exe ${mat}.mtx ${mat}.csr
RESULT_VARIABLE STATUS
WORKING_DIRECTORY ${CMAKE_MATRICES_DIR})
Expand Down
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ done
# If matrices_dir_install has been set up then install matrices dir and exit.
#
if ! [[ "${matrices_dir_install}" == "" ]];then
cmake -DCMAKE_CXX_COMPILER="${rocm_path}/bin/hipcc" -DCMAKE_C_COMPILER="${rocm_path}/bin/hipcc" -DPROJECT_BINARY_DIR=${matrices_dir_install} -DCMAKE_MATRICES_DIR=${matrices_dir_install} -P ./cmake/ClientMatrices.cmake
cmake -DCMAKE_CXX_COMPILER="${rocm_path}/bin/hipcc" -DCMAKE_C_COMPILER="${rocm_path}/bin/hipcc" -DPROJECT_BINARY_DIR=${matrices_dir_install} -DCMAKE_MATRICES_DIR=${matrices_dir_install} -DROCM_PATH=${rocm_path} -DCMAKE_INSTALL_LIBDIR=lib -P ./cmake/ClientMatrices.cmake
exit 0
fi

Expand All @@ -388,7 +388,7 @@ if ! [[ "${matrices_dir}" == "" ]];then
# Let's 'reinstall' to the specified location to check if all good
# Will be fast if everything already exists as expected.
# This is to prevent any empty directory.
cmake -DCMAKE_CXX_COMPILER="${rocm_path}/bin/hipcc" -DCMAKE_C_COMPILER="${rocm_path}/bin/hipcc" -DPROJECT_BINARY_DIR=${matrices_dir} -DCMAKE_MATRICES_DIR=${matrices_dir} -P ./cmake/ClientMatrices.cmake
cmake -DCMAKE_CXX_COMPILER="${rocm_path}/bin/hipcc" -DCMAKE_C_COMPILER="${rocm_path}/bin/hipcc" -DPROJECT_BINARY_DIR=${matrices_dir} -DCMAKE_MATRICES_DIR=${matrices_dir} -DROCM_PATH=${rocm_path} -DCMAKE_INSTALL_LIBDIR=lib -P ./cmake/ClientMatrices.cmake
fi

build_dir=./build
Expand Down

0 comments on commit 1c5d839

Please sign in to comment.