Fix the openmp-target ctest (#300)

- openmp-target: add runtime rpath for libomptarget and update tests
- Handle events not associated with a HIP Stream
  - Kernels from OpenMP target offload are not associated with a HIP stream. Fix handling with the callback record's stream_id is 0

---------

Co-authored-by: David Galiffi <David.Galiffi@amd.com>
This commit is contained in:
habajpai-amd
2025-07-31 20:11:27 +05:30
committed by GitHub
parent d1a2deba1f
commit c424dac261
3 changed files with 85 additions and 40 deletions
+49 -32
View File
@@ -50,49 +50,66 @@ set(GPU_TARGETS "${DEFAULT_GPU_TARGETS}" CACHE STRING "GPU targets to compile fo
find_package(Threads REQUIRED)
function(add_offload_flags tgt)
foreach(arch IN LISTS GPU_TARGETS)
target_compile_options(${tgt} PRIVATE --offload-arch=${arch})
target_link_options(${tgt} PUBLIC --offload-arch=${arch})
endforeach()
endfunction()
get_filename_component(OMP_TARGET_COMPILER_DIR ${OMP_TARGET_COMPILER} PATH)
get_filename_component(OMP_TARGET_COMPILER_DIR ${OMP_TARGET_COMPILER_DIR} PATH)
message(STATUS "Using OpenMP target compiler: ${OMP_TARGET_COMPILER}")
message(STATUS "Using OpenMP target compiler directory: ${OMP_TARGET_COMPILER_DIR}")
set(_rocm_llvm_lib "${OMP_TARGET_COMPILER_DIR}/llvm/lib")
set(_rocm_clang_lib "${OMP_TARGET_COMPILER_DIR}/lib")
set(_COMMON_RPATH "${_rocm_llvm_lib};${_rocm_clang_lib}")
if(NOT EXISTS "${_rocm_llvm_lib}/libomptarget.so")
message(FATAL_ERROR "Could not find libomptarget.so in ${_rocm_llvm_lib}")
endif()
# Shared library
add_library(openmp-target-lib SHARED)
target_sources(openmp-target-lib PRIVATE library.cpp)
target_link_libraries(openmp-target-lib PUBLIC Threads::Threads)
target_compile_options(openmp-target-lib PRIVATE -fopenmp -ggdb)
target_link_options(openmp-target-lib PUBLIC -fopenmp)
add_offload_flags(openmp-target-lib)
foreach(_TARGET ${GPU_TARGETS})
target_compile_options(openmp-target-lib PRIVATE --offload-arch=${_TARGET})
target_link_options(openmp-target-lib PUBLIC --offload-arch=${_TARGET})
endforeach()
message(STATUS "Using OpenMP target compiler: ${OMP_TARGET_COMPILER}")
get_filename_component(OMP_TARGET_COMPILER_DIR ${OMP_TARGET_COMPILER} PATH)
get_filename_component(OMP_TARGET_COMPILER_DIR ${OMP_TARGET_COMPILER_DIR} PATH)
message(STATUS "Using OpemMP target compiler directory: ${OMP_TARGET_COMPILER_DIR}")
if(NOT EXISTS ${OMP_TARGET_COMPILER_DIR}/llvm/lib)
message(FATAL_ERROR "${OMP_TARGET_COMPILER_DIR}/llvm/lib does not exist")
endif()
set_target_properties(
openmp-target-lib
PROPERTIES
BUILD_RPATH "${OMP_TARGET_COMPILER_DIR}/llvm/lib:${OMP_TARGET_COMPILER_DIR}/lib"
OUTPUT_NAME "openmp-target"
POSITION_INDEPENDENT_CODE ON
)
rocprofiler_systems_custom_compilation(TARGET openmp-target-lib
COMPILER ${OMP_TARGET_COMPILER}
)
# Executable
add_executable(openmp-target)
target_sources(openmp-target PRIVATE main.cpp)
target_link_libraries(openmp-target PRIVATE openmp-target-lib)
target_compile_options(openmp-target PRIVATE -ggdb)
target_compile_options(openmp-target PRIVATE -fopenmp -ggdb)
target_link_options(openmp-target PUBLIC -fopenmp)
add_offload_flags(openmp-target)
set_target_properties(
openmp-target
PROPERTIES
BUILD_RPATH "${OMP_TARGET_COMPILER_DIR}/llvm/lib:${OMP_TARGET_COMPILER_DIR}/lib"
POSITION_INDEPENDENT_CODE ON
foreach(tgt openmp-target-lib openmp-target)
set_target_properties(
${tgt}
PROPERTIES
BUILD_RPATH "${_COMMON_RPATH}"
INSTALL_RPATH "${_COMMON_RPATH}"
INSTALL_RPATH_USE_LINK_PATH TRUE
POSITION_INDEPENDENT_CODE ON
)
target_link_options(
${tgt}
PUBLIC
"-L${_rocm_llvm_lib}"
"-Wl,-rpath,${_rocm_llvm_lib}"
"-Wl,-rpath,${_rocm_clang_lib}"
)
endforeach()
rocprofiler_systems_custom_compilation(
TARGET openmp-target-lib
COMPILER ${OMP_TARGET_COMPILER}
)
rocprofiler_systems_custom_compilation(TARGET openmp-target