Skip to content

[libc] Add AMDGPU Sin Benchmark #101120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2024
Merged

Conversation

jameshu15869
Copy link
Contributor

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

@jameshu15869 jameshu15869 marked this pull request as draft July 30, 2024 04:07
@llvmbot llvmbot added the libc label Jul 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 30, 2024

@llvm/pr-subscribers-libc

Author: None (jameshu15869)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/101120.diff

2 Files Affected:

  • (modified) libc/benchmarks/gpu/src/math/CMakeLists.txt (+10)
  • (modified) libc/benchmarks/gpu/src/math/sin_benchmark.cpp (+13-1)
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

@jhuber6 jhuber6 marked this pull request as ready for review July 30, 2024 11:43
@jhuber6 jhuber6 changed the title [libc] DRAFT: Add AMDGPU Sin Benchmark [libc] Add AMDGPU Sin Benchmark Jul 30, 2024
@jhuber6 jhuber6 merged commit 8f7910a into llvm:main Jul 30, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants