Skip to content

Commit 8f7910a

Browse files
[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 <[email protected]>
1 parent bf42a78 commit 8f7910a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ if(CUDAToolkit_FOUND)
1111
endif()
1212
endif()
1313

14+
find_package(AMDDeviceLibs QUIET HINTS ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm)
15+
if(AMDDeviceLibs_FOUND)
16+
get_target_property(ocml_path ocml IMPORTED_LOCATION)
17+
set(amdgpu_bitcode_link_flags
18+
"SHELL:-Xclang -mlink-builtin-bitcode -Xclang ${ocml_path}")
19+
set(amdgpu_math_found "-DAMDGPU_MATH_FOUND=1")
20+
endif()
21+
1422
add_benchmark(
1523
sin_benchmark
1624
SUITE
@@ -27,6 +35,8 @@ add_benchmark(
2735
COMPILE_OPTIONS
2836
${nvptx_math_found}
2937
${nvptx_bitcode_link_flags}
38+
${amdgpu_math_found}
39+
${amdgpu_bitcode_link_flags}
3040
LOADER_ARGS
3141
--threads 64
3242
)

libc/benchmarks/gpu/src/math/sin_benchmark.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
#include "src/__support/FPUtil/FPBits.h"
77
#include "src/math/sin.h"
88
#include "src/stdlib/rand.h"
9-
#include "src/stdlib/srand.h"
109

1110
#ifdef NVPTX_MATH_FOUND
1211
#include "src/math/nvptx/declarations.h"
1312
#endif
1413

14+
#ifdef AMDGPU_MATH_FOUND
15+
#include "src/math/amdgpu/declarations.h"
16+
#endif
17+
1518
constexpr double M_PI = 3.14159265358979323846;
1619
uint64_t get_bits(double x) {
1720
return LIBC_NAMESPACE::cpp::bit_cast<uint64_t>(x);
@@ -51,3 +54,12 @@ BENCHMARK(LlvmLibcSinGpuBenchmark, NvSinTwoPi,
5154
BENCHMARK(LlvmLibcSinGpuBenchmark, NvSinLargeInt,
5255
BM_LARGE_INT(LIBC_NAMESPACE::__nv_sin));
5356
#endif
57+
58+
#ifdef AMDGPU_MATH_FOUND
59+
BENCHMARK(LlvmLibcSinGpuBenchmark, AmdgpuSin,
60+
BM_RANDOM_INPUT(LIBC_NAMESPACE::__ocml_sin_f64));
61+
BENCHMARK(LlvmLibcSinGpuBenchmark, AmdgpuSinTwoPi,
62+
BM_TWO_PI(LIBC_NAMESPACE::__ocml_sin_f64));
63+
BENCHMARK(LlvmLibcSinGpuBenchmark, AmdgpuSinLargeInt,
64+
BM_LARGE_INT(LIBC_NAMESPACE::__ocml_sin_f64));
65+
#endif

0 commit comments

Comments
 (0)