Skip to content

Commit

Permalink
[libc] Only link in the appropriate architecture's device libs
Browse files Browse the repository at this point in the history
  • Loading branch information
jhuber6 committed Jul 30, 2024
1 parent 12189f8 commit ebdcb76
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions libc/benchmarks/gpu/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
add_custom_target(libc-gpu-math-benchmarks)

if(CUDAToolkit_FOUND)
set(libdevice_path ${CUDAToolkit_BIN_DIR}/../nvvm/libdevice/libdevice.10.bc)
if (EXISTS ${libdevice_path})
set(nvptx_bitcode_link_flags
set(math_benchmark_flags "")
if(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
if(CUDAToolkit_FOUND)
set(libdevice_path ${CUDAToolkit_BIN_DIR}/../nvvm/libdevice/libdevice.10.bc)
if (EXISTS ${libdevice_path})
list(APPEND math_benchmark_flags
"SHELL:-Xclang -mlink-builtin-bitcode -Xclang ${libdevice_path}")
# Compile definition needed so the benchmark knows to register
# NVPTX benchmarks.
set(nvptx_math_found "-DNVPTX_MATH_FOUND=1")
# Compile definition needed so the benchmark knows to register
# NVPTX benchmarks.
list(APPEND math_benchmark_flags "-DNVPTX_MATH_FOUND=1")
endif()
endif()
endif()

find_package(AMDDeviceLibs QUIET HINTS ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm)
if(AMDDeviceLibs_FOUND)
get_target_property(ocml_path ocml IMPORTED_LOCATION)
set(amdgpu_bitcode_link_flags
"SHELL:-Xclang -mlink-builtin-bitcode -Xclang ${ocml_path}")
set(amdgpu_math_found "-DAMDGPU_MATH_FOUND=1")
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
find_package(AMDDeviceLibs QUIET HINTS ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm)
if(AMDDeviceLibs_FOUND)
get_target_property(ocml_path ocml IMPORTED_LOCATION)
list(APPEND math_benchmark_flags
"SHELL:-Xclang -mlink-builtin-bitcode -Xclang ${ocml_path}")
list(APPEND math_benchmark_flags "-DAMDGPU_MATH_FOUND=1")
endif()
endif()

add_benchmark(
Expand All @@ -33,10 +38,7 @@ add_benchmark(
libc.src.__support.CPP.bit
libc.src.__support.CPP.array
COMPILE_OPTIONS
${nvptx_math_found}
${nvptx_bitcode_link_flags}
${amdgpu_math_found}
${amdgpu_bitcode_link_flags}
${math_benchmark_flags}
LOADER_ARGS
--threads 64
)

0 comments on commit ebdcb76

Please sign in to comment.