Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions projects/rocprofiler-systems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ endif()
include(GNUInstallDirs) # install directories
include(MacroUtilities) # various functions and macros

if(NOT DEFINED LLVM_HOST_TRIPLE)
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} --print-target-triple
OUTPUT_VARIABLE LLVM_HOST_TRIPLE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
Comment on lines +139 to +145
endif()

if(CI_BUILD)
rocprofiler_systems_add_option(ROCPROFSYS_BUILD_CI "Enable internal asserts, etc." ON
ADVANCED NO_FEATURE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,30 @@ get_filename_component(ROCM_ROOT_DIR "${_omp_bin_dir}" DIRECTORY)
message(STATUS "Using OpenMP target compiler: ${OMP_TARGET_COMPILER}")
message(STATUS "ROCm root inferred from compiler: ${ROCM_ROOT_DIR}")

if(NOT DEFINED LLVM_HOST_TRIPLE)
execute_process(
COMMAND ${OMP_TARGET_COMPILER} --print-target-triple
OUTPUT_VARIABLE LLVM_HOST_TRIPLE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()
Comment on lines +70 to +77

# Candidate lib directories for libomptarget across ROCm layouts
set(_LLVM_LIB_HINTS
"${ROCmVersion_DIR}/llvm/lib/${LLVM_HOST_TRIPLE}"
"${ROCmVersion_DIR}/llvm/lib"
"${ROCmVersion_DIR}/lib"
"${ROCM_ROOT_DIR}/lib"
"${ROCM_ROOT_DIR}/llvm/lib/${LLVM_HOST_TRIPLE}"
"${ROCM_ROOT_DIR}/llvm/lib"
"$ENV{ROCM_PATH}/llvm/lib/${LLVM_HOST_TRIPLE}"
"$ENV{ROCM_PATH}/llvm/lib"
"$ENV{ROCM_PATH}/lib/llvm/lib/${LLVM_HOST_TRIPLE}"
"$ENV{ROCM_PATH}/lib/llvm/lib"
"/opt/rocm/llvm/lib/${LLVM_HOST_TRIPLE}"
"/opt/rocm/llvm/lib"
"/opt/rocm/lib/llvm/lib/${LLVM_HOST_TRIPLE}"
"/opt/rocm/lib/llvm/lib"
)

Expand All @@ -91,7 +106,11 @@ get_filename_component(_rocm_llvm_lib "${LIBOMPTARGET_SO}" DIRECTORY)
set(_rocm_clang_lib "${ROCM_ROOT_DIR}/lib")
set(_COMMON_RPATH "${_rocm_llvm_lib};${_rocm_clang_lib};$ORIGIN;$ORIGIN/lib")
if(ROCmVersion_DIR)
list(APPEND _COMMON_RPATH "${ROCmVersion_DIR}/llvm/lib")
list(
APPEND _COMMON_RPATH
"${ROCmVersion_DIR}/llvm/lib"
"${ROCmVersion_DIR}/llvm/lib/${LLVM_HOST_TRIPLE}"
)
endif()
list(REMOVE_DUPLICATES _COMMON_RPATH)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ else
if [ -n "$(basename ${ROCPROFSYS_COMPILER} | egrep 'amdclang|amdllvm')" ]; then
# this ensures the libomptarget-amdgpu-gfx*.bc files are found
LLVM_LIB_DIR=$(cd $(dirname $(realpath ${ROCPROFSYS_COMPILER}))/../lib && pwd)
LLVM_HOST_TRIPLE=$(${ROCPROFSYS_COMPILER} --print-target-triple 2>/dev/null || true)
if [ -n "${LLVM_HOST_TRIPLE}" ] && [ -d "${LLVM_LIB_DIR}/${LLVM_HOST_TRIPLE}" ]; then
LLVM_LIB_DIR="${LLVM_LIB_DIR}/${LLVM_HOST_TRIPLE}:${LLVM_LIB_DIR}"
fi
debug-message export LIBRARY_PATH=${LLVM_LIB_DIR}:${LIBRARY_PATH}
export LIBRARY_PATH=${LLVM_LIB_DIR}:${LIBRARY_PATH}
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
// compiler information
#define ROCPROFSYS_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@"
#define ROCPROFSYS_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@"
#define ROCPROFSYS_LLVM_HOST_TRIPLE "@LLVM_HOST_TRIPLE@"
#define ROCPROFSYS_COMPILER_STRING ROCPROFSYS_COMPILER_ID " v" ROCPROFSYS_COMPILER_VERSION

#define ROCPROFSYS_DEFAULT_ROCM_PATH "@ROCmVersion_DIR@"
Expand Down
22 changes: 17 additions & 5 deletions projects/rocprofiler-systems/source/lib/common/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,27 @@ discover_llvm_libdir_for_ompt(bool verbose = false)
candidates.emplace_back(p);
};

auto host_triple = []() -> std::string {
if(auto* env = std::getenv("LLVM_HOST_TRIPLE"); env && *env) return env;
constexpr auto builtin = std::string_view{ ROCPROFSYS_LLVM_HOST_TRIPLE };
if(!builtin.empty()) return std::string{ builtin };
return {};
}();
Comment on lines +210 to +215

auto push_with_triple = [&](const std::string& base) {
push_unique(base);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it preferred to try the triple path first before the flat one?
I am not an expert about this but in the examples cmake we search the triple path first.

if(!host_triple.empty()) push_unique(base + "/" + host_triple);
};

if(!rocmv_dir.empty())
{
push_unique(rocmv_dir + "/llvm/lib");
push_with_triple(rocmv_dir + "/llvm/lib");
push_unique(rocmv_dir + "/lib");
}
push_unique(rocm_dir + "/llvm/lib");
push_unique(rocm_dir + "/lib/llvm/lib");
push_unique("/opt/rocm/llvm/lib");
push_unique("/opt/rocm/lib/llvm/lib");
push_with_triple(rocm_dir + "/llvm/lib");
push_with_triple(rocm_dir + "/lib/llvm/lib");
push_with_triple("/opt/rocm/llvm/lib");
push_with_triple("/opt/rocm/lib/llvm/lib");

auto has_libomptarget = [](const std::string& dir) {
const std::string so = dir + "/libomptarget.so";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,19 @@ def get_llvm_lib_paths(self) -> list[Path]:
Returns:
List of existing LLVM lib paths found, empty list if none found.
"""
import os
import platform

host_triple = os.environ.get(
"LLVM_HOST_TRIPLE", f"{platform.machine()}-unknown-linux-gnu"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a helper to calculate compiler --print-target-triple instead??

)
Comment on lines +85 to +90
found_paths = []
if self.rocm_path:
# Match discover_llvm_libdir_for_ompt() logic
candidates = [
self.rocm_path / "llvm" / "lib",
self.rocm_path / "llvm" / "lib" / host_triple,
self.rocm_path / "lib" / "llvm" / "lib",
self.rocm_path / "lib" / "llvm" / "lib" / host_triple,
]
for candidate in candidates:
if candidate.exists():
Expand Down
Loading