[libc-commits] [libc] 8f7910a - [libc] Add AMDGPU Sin Benchmark (#101120)

via libc-commits libc-commits at lists.llvm.org
Tue Jul 30 08:19:51 PDT 2024


Author: jameshu15869
Date: 2024-07-30T10:19:48-05:00
New Revision: 8f7910a4fc08818462e0e836db74b20290cd36c7

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

LOG: [libc] Add AMDGPU Sin Benchmark (#101120)

This PR adds support for benchmarking `__ocml_sin_f64()` against
`sin()`. This PR is currently a draft because I do not have access to an
AMD GPU and was not able to test the PR, but the code compiled when I
ran `ninja gpu-benchmark` from `runtimes-amdgcn-amd-amdhsa-bins`

Co-authored-by: Joseph Huber <huberjn at outlook.com>

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/libc/benchmarks/gpu/src/math/CMakeLists.txt b/libc/benchmarks/gpu/src/math/CMakeLists.txt
index 116dfb580215a..539a57d9c1431 100644
--- a/libc/benchmarks/gpu/src/math/CMakeLists.txt
+++ b/libc/benchmarks/gpu/src/math/CMakeLists.txt
@@ -11,6 +11,14 @@ if(CUDAToolkit_FOUND)
   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")
+endif()
+
 add_benchmark(
   sin_benchmark
   SUITE
@@ -27,6 +35,8 @@ add_benchmark(
   COMPILE_OPTIONS
     ${nvptx_math_found}
     ${nvptx_bitcode_link_flags}
+    ${amdgpu_math_found}
+    ${amdgpu_bitcode_link_flags}
   LOADER_ARGS
     --threads 64
 )

diff  --git a/libc/benchmarks/gpu/src/math/sin_benchmark.cpp b/libc/benchmarks/gpu/src/math/sin_benchmark.cpp
index 39d730cb01a52..5849ea3e99bb0 100644
--- a/libc/benchmarks/gpu/src/math/sin_benchmark.cpp
+++ b/libc/benchmarks/gpu/src/math/sin_benchmark.cpp
@@ -6,12 +6,15 @@
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/math/sin.h"
 #include "src/stdlib/rand.h"
-#include "src/stdlib/srand.h"
 
 #ifdef NVPTX_MATH_FOUND
 #include "src/math/nvptx/declarations.h"
 #endif
 
+#ifdef AMDGPU_MATH_FOUND
+#include "src/math/amdgpu/declarations.h"
+#endif
+
 constexpr double M_PI = 3.14159265358979323846;
 uint64_t get_bits(double x) {
   return LIBC_NAMESPACE::cpp::bit_cast<uint64_t>(x);
@@ -51,3 +54,12 @@ BENCHMARK(LlvmLibcSinGpuBenchmark, NvSinTwoPi,
 BENCHMARK(LlvmLibcSinGpuBenchmark, NvSinLargeInt,
           BM_LARGE_INT(LIBC_NAMESPACE::__nv_sin));
 #endif
+
+#ifdef AMDGPU_MATH_FOUND
+BENCHMARK(LlvmLibcSinGpuBenchmark, AmdgpuSin,
+          BM_RANDOM_INPUT(LIBC_NAMESPACE::__ocml_sin_f64));
+BENCHMARK(LlvmLibcSinGpuBenchmark, AmdgpuSinTwoPi,
+          BM_TWO_PI(LIBC_NAMESPACE::__ocml_sin_f64));
+BENCHMARK(LlvmLibcSinGpuBenchmark, AmdgpuSinLargeInt,
+          BM_LARGE_INT(LIBC_NAMESPACE::__ocml_sin_f64));
+#endif


        


More information about the libc-commits mailing list