[libc-commits] [libc] ebdcb76 - [libc] Only link in the appropriate architecture's device libs

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Tue Jul 30 16:36:51 PDT 2024


Author: Joseph Huber
Date: 2024-07-30T18:36:41-05:00
New Revision: ebdcb76d1a3b6d8fed06c91c0a318f07f4bca628

URL: https://github.com/llvm/llvm-project/commit/ebdcb76d1a3b6d8fed06c91c0a318f07f4bca628
DIFF: https://github.com/llvm/llvm-project/commit/ebdcb76d1a3b6d8fed06c91c0a318f07f4bca628.diff

LOG: [libc] Only link in the appropriate architecture's device libs

Added: 
    

Modified: 
    libc/benchmarks/gpu/src/math/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/benchmarks/gpu/src/math/CMakeLists.txt b/libc/benchmarks/gpu/src/math/CMakeLists.txt
index 539a57d9c1431..77250edb6bb52 100644
--- a/libc/benchmarks/gpu/src/math/CMakeLists.txt
+++ b/libc/benchmarks/gpu/src/math/CMakeLists.txt
@@ -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(
@@ -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
 )


        


More information about the libc-commits mailing list