diff options
Diffstat (limited to 'libc/benchmarks/gpu/src')
| -rw-r--r-- | libc/benchmarks/gpu/src/math/CMakeLists.txt | 147 | ||||
| -rw-r--r-- | libc/benchmarks/gpu/src/math/atan2_benchmark.cpp | 7 | ||||
| -rw-r--r-- | libc/benchmarks/gpu/src/math/exp_benchmark.cpp | 59 | ||||
| -rw-r--r-- | libc/benchmarks/gpu/src/math/expf16_benchmark.cpp | 56 | ||||
| -rw-r--r-- | libc/benchmarks/gpu/src/math/expf_benchmark.cpp | 59 | ||||
| -rw-r--r-- | libc/benchmarks/gpu/src/math/log_benchmark.cpp | 68 | ||||
| -rw-r--r-- | libc/benchmarks/gpu/src/math/logf16_benchmark.cpp | 62 | ||||
| -rw-r--r-- | libc/benchmarks/gpu/src/math/logf_benchmark.cpp | 68 | ||||
| -rw-r--r-- | libc/benchmarks/gpu/src/math/platform.h | 19 | ||||
| -rw-r--r-- | libc/benchmarks/gpu/src/math/sin_benchmark.cpp | 7 |
10 files changed, 537 insertions, 15 deletions
diff --git a/libc/benchmarks/gpu/src/math/CMakeLists.txt b/libc/benchmarks/gpu/src/math/CMakeLists.txt index 8417f23c124a..53da45d9eb2b 100644 --- a/libc/benchmarks/gpu/src/math/CMakeLists.txt +++ b/libc/benchmarks/gpu/src/math/CMakeLists.txt @@ -25,15 +25,19 @@ if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU) endif() add_benchmark( - sin_benchmark + atan2_benchmark SUITE libc-gpu-math-benchmarks SRCS - sin_benchmark.cpp + atan2_benchmark.cpp + HDRS + platform.h DEPENDS libc.hdr.stdint_proxy - libc.src.math.sin - libc.src.math.sinf + libc.src.__support.macros.attributes + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + libc.src.math.atan2 COMPILE_OPTIONS ${math_benchmark_flags} LOADER_ARGS @@ -41,14 +45,143 @@ add_benchmark( ) add_benchmark( - atan2_benchmark + exp_benchmark SUITE libc-gpu-math-benchmarks SRCS - atan2_benchmark.cpp + exp_benchmark.cpp + HDRS + platform.h DEPENDS libc.hdr.stdint_proxy - libc.src.math.atan2 + libc.src.__support.macros.attributes + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + libc.src.math.exp + COMPILE_OPTIONS + ${math_benchmark_flags} + LOADER_ARGS + --threads 64 +) + +add_benchmark( + expf_benchmark + SUITE + libc-gpu-math-benchmarks + SRCS + expf_benchmark.cpp + HDRS + platform.h + DEPENDS + libc.hdr.stdint_proxy + libc.src.__support.macros.attributes + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + libc.src.math.expf + COMPILE_OPTIONS + ${math_benchmark_flags} + LOADER_ARGS + --threads 64 +) + +add_benchmark( + expf16_benchmark + SUITE + libc-gpu-math-benchmarks + SRCS + expf16_benchmark.cpp + HDRS + platform.h + DEPENDS + libc.hdr.stdint_proxy + libc.src.__support.macros.attributes + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + libc.src.math.expf16 + COMPILE_OPTIONS + ${math_benchmark_flags} + LOADER_ARGS + --threads 64 +) + +add_benchmark( + log_benchmark + SUITE + libc-gpu-math-benchmarks + SRCS + log_benchmark.cpp + HDRS + platform.h + DEPENDS + libc.hdr.stdint_proxy + libc.src.__support.macros.attributes + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + libc.src.__support.sign + libc.src.math.log + COMPILE_OPTIONS + ${math_benchmark_flags} + LOADER_ARGS + --threads 64 +) + +add_benchmark( + logf_benchmark + SUITE + libc-gpu-math-benchmarks + SRCS + logf_benchmark.cpp + HDRS + platform.h + DEPENDS + libc.hdr.stdint_proxy + libc.src.__support.macros.attributes + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + libc.src.__support.sign + libc.src.math.logf + COMPILE_OPTIONS + ${math_benchmark_flags} + LOADER_ARGS + --threads 64 +) + +add_benchmark( + logf16_benchmark + SUITE + libc-gpu-math-benchmarks + SRCS + logf16_benchmark.cpp + HDRS + platform.h + DEPENDS + libc.hdr.stdint_proxy + libc.src.__support.macros.attributes + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + libc.src.__support.sign + libc.src.math.logf16 + COMPILE_OPTIONS + ${math_benchmark_flags} + LOADER_ARGS + --threads 64 +) + +add_benchmark( + sin_benchmark + SUITE + libc-gpu-math-benchmarks + SRCS + sin_benchmark.cpp + HDRS + platform.h + DEPENDS + libc.hdr.stdint_proxy + libc.src.__support.macros.attributes + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + libc.src.math.sin + libc.src.math.sinf COMPILE_OPTIONS ${math_benchmark_flags} LOADER_ARGS diff --git a/libc/benchmarks/gpu/src/math/atan2_benchmark.cpp b/libc/benchmarks/gpu/src/math/atan2_benchmark.cpp index 82bb0c5d7de4..6039f0c66b2a 100644 --- a/libc/benchmarks/gpu/src/math/atan2_benchmark.cpp +++ b/libc/benchmarks/gpu/src/math/atan2_benchmark.cpp @@ -9,8 +9,11 @@ #define BM_RANDOM_INPUTS(T, Func, MinExp, MaxExp, N) \ [](uint32_t call_index) { \ - return LIBC_NAMESPACE::benchmarks::MathPerf<T>::run_throughput_in_range< \ - N>(Func, MinExp, MaxExp, MinExp, MaxExp, call_index); \ + using namespace LIBC_NAMESPACE::benchmarks; \ + \ + const UniformExponent<T> dist(MinExp, MaxExp); \ + return MathPerf<T>::template run_throughput<N>(Func, dist, dist, \ + call_index); \ } #define BENCH(T, Name, Func, MinExp, MaxExp) \ diff --git a/libc/benchmarks/gpu/src/math/exp_benchmark.cpp b/libc/benchmarks/gpu/src/math/exp_benchmark.cpp new file mode 100644 index 000000000000..2398c4b9f17b --- /dev/null +++ b/libc/benchmarks/gpu/src/math/exp_benchmark.cpp @@ -0,0 +1,59 @@ +//===-- GPU benchmark for exp ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "benchmarks/gpu/LibcGpuBenchmark.h" +#include "benchmarks/gpu/Random.h" + +#include "hdr/stdint_proxy.h" +#include "src/math/exp.h" + +#if defined(NVPTX_MATH_FOUND) || defined(AMDGPU_MATH_FOUND) +#include "platform.h" +#endif + +#define RANDOM_INPUT(T, Func, Dist, Min, Max, N) \ + [](uint32_t call_index) { \ + using namespace LIBC_NAMESPACE::benchmarks; \ + \ + const Dist<T> dist(Min, Max); \ + return MathPerf<T>::template run_throughput<N>(Func, dist, call_index); \ + } + +#define BENCH(T, Name, Func, Dist, Min, Max) \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpGpuBenchmark, Name##_1, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 1)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpGpuBenchmark, Name##_128, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 128)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpGpuBenchmark, Name##_1024, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 1024)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpGpuBenchmark, Name##_4096, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 4096)) + +using LIBC_NAMESPACE::exp; + +BENCH(double, ExpSubnormal, exp, UniformExponent, -1022, -1022); +BENCH(double, ExpCoreRange, exp, UniformLinear, -10.0, 10.0); +BENCH(double, ExpFinite, exp, UniformLinear, -745.0, 709.0); +BENCH(double, ExpUnderflow, exp, UniformLinear, -746.0, -745.0); +BENCH(double, ExpOverflow, exp, UniformLinear, 709.0, 710.0); + +#ifdef NVPTX_MATH_FOUND +BENCH(double, NvExpSubnormal, __nv_exp, UniformExponent, -1022, -1022); +BENCH(double, NvExpCoreRange, __nv_exp, UniformLinear, -10.0, 10.0); +BENCH(double, NvExpFinite, __nv_exp, UniformLinear, -745.0, 709.0); +BENCH(double, NvExpUnderflow, __nv_exp, UniformLinear, -746.0, -745.0); +BENCH(double, NvExpOverflow, __nv_exp, UniformLinear, 709.0, 710.0); +#endif + +#ifdef AMDGPU_MATH_FOUND +BENCH(double, AmdExpSubnormal, __ocml_exp_f64, UniformExponent, -1022, -1022); +BENCH(double, AmdExpCoreRange, __ocml_exp_f64, UniformLinear, -10.0, 10.0); +BENCH(double, AmdExpFinite, __ocml_exp_f64, UniformLinear, -745.0, 709.0); +BENCH(double, AmdExpUnderflow, __ocml_exp_f64, UniformLinear, -746.0, -745.0); +BENCH(double, AmdExpOverflow, __ocml_exp_f64, UniformLinear, 709.0, 710.0); +#endif diff --git a/libc/benchmarks/gpu/src/math/expf16_benchmark.cpp b/libc/benchmarks/gpu/src/math/expf16_benchmark.cpp new file mode 100644 index 000000000000..20e045b893ec --- /dev/null +++ b/libc/benchmarks/gpu/src/math/expf16_benchmark.cpp @@ -0,0 +1,56 @@ +//===-- GPU benchmark for expf16 ------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "benchmarks/gpu/LibcGpuBenchmark.h" +#include "benchmarks/gpu/Random.h" + +#include "hdr/stdint_proxy.h" +#include "src/__support/macros/properties/types.h" +#include "src/math/expf16.h" + +#if defined(NVPTX_MATH_FOUND) || defined(AMDGPU_MATH_FOUND) +#include "platform.h" +#endif + +#define RANDOM_INPUT(T, Func, Dist, Min, Max, N) \ + [](uint32_t call_index) { \ + using namespace LIBC_NAMESPACE::benchmarks; \ + \ + const Dist<T> dist(Min, Max); \ + return MathPerf<T>::template run_throughput<N>(Func, dist, call_index); \ + } + +#define BENCH(T, Name, Func, Dist, Min, Max) \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpf16GpuBenchmark, Name##_1, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 1)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpf16GpuBenchmark, Name##_128, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 128)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpf16GpuBenchmark, Name##_1024, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 1024)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpf16GpuBenchmark, Name##_4096, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 4096)) + +using LIBC_NAMESPACE::expf16; + +BENCH(float16, Expf16Subnormal, expf16, UniformExponent, -14, -14); +BENCH(float16, Expf16CoreRange, expf16, UniformLinear, -10.0f16, 10.0f16); +BENCH(float16, Expf16Finite, expf16, UniformLinear, -16.0f16, 11.0f16); +BENCH(float16, Expf16Underflow, expf16, UniformLinear, -17.0f16, -16.0f16); +BENCH(float16, Expf16Overflow, expf16, UniformLinear, 11.0f16, 12.0f16); + +#ifdef AMDGPU_MATH_FOUND +BENCH(float16, AmdExpf16Subnormal, __ocml_exp_f16, UniformExponent, -14, -14); +BENCH(float16, AmdExpf16CoreRange, __ocml_exp_f16, UniformLinear, -10.0f16, + 10.0f16); +BENCH(float16, AmdExpf16Finite, __ocml_exp_f16, UniformLinear, -16.0f16, + 11.0f16); +BENCH(float16, AmdExpf16Underflow, __ocml_exp_f16, UniformLinear, -17.0f16, + -16.0f16); +BENCH(float16, AmdExpf16Overflow, __ocml_exp_f16, UniformLinear, 11.0f16, + 12.0f16); +#endif diff --git a/libc/benchmarks/gpu/src/math/expf_benchmark.cpp b/libc/benchmarks/gpu/src/math/expf_benchmark.cpp new file mode 100644 index 000000000000..4ef54c53baf4 --- /dev/null +++ b/libc/benchmarks/gpu/src/math/expf_benchmark.cpp @@ -0,0 +1,59 @@ +//===-- GPU benchmark for expf --------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "benchmarks/gpu/LibcGpuBenchmark.h" +#include "benchmarks/gpu/Random.h" + +#include "hdr/stdint_proxy.h" +#include "src/math/expf.h" + +#if defined(NVPTX_MATH_FOUND) || defined(AMDGPU_MATH_FOUND) +#include "platform.h" +#endif + +#define RANDOM_INPUT(T, Func, Dist, Min, Max, N) \ + [](uint32_t call_index) { \ + using namespace LIBC_NAMESPACE::benchmarks; \ + \ + const Dist<T> dist(Min, Max); \ + return MathPerf<T>::template run_throughput<N>(Func, dist, call_index); \ + } + +#define BENCH(T, Name, Func, Dist, Min, Max) \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpfGpuBenchmark, Name##_1, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 1)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpfGpuBenchmark, Name##_128, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 128)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpfGpuBenchmark, Name##_1024, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 1024)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcExpfGpuBenchmark, Name##_4096, \ + RANDOM_INPUT(T, Func, Dist, Min, Max, 4096)) + +using LIBC_NAMESPACE::expf; + +BENCH(float, ExpfSubnormal, expf, UniformExponent, -126, -126); +BENCH(float, ExpfCoreRange, expf, UniformLinear, -10.0f, 10.0f); +BENCH(float, ExpfFinite, expf, UniformLinear, -103.0f, 88.0f); +BENCH(float, ExpfUnderflow, expf, UniformLinear, -104.0f, -103.0f); +BENCH(float, ExpfOverflow, expf, UniformLinear, 88.0f, 89.0f); + +#ifdef NVPTX_MATH_FOUND +BENCH(float, NvExpfSubnormal, __nv_expf, UniformExponent, -126, -126); +BENCH(float, NvExpfCoreRange, __nv_expf, UniformLinear, -10.0f, 10.0f); +BENCH(float, NvExpfFinite, __nv_expf, UniformLinear, -103.0f, 88.0f); +BENCH(float, NvExpfUnderflow, __nv_expf, UniformLinear, -104.0f, -103.0f); +BENCH(float, NvExpfOverflow, __nv_expf, UniformLinear, 88.0f, 89.0f); +#endif + +#ifdef AMDGPU_MATH_FOUND +BENCH(float, AmdExpfSubnormal, __ocml_exp_f32, UniformExponent, -126, -126); +BENCH(float, AmdExpfCoreRange, __ocml_exp_f32, UniformLinear, -10.0f, 10.0f); +BENCH(float, AmdExpfFinite, __ocml_exp_f32, UniformLinear, -103.0f, 88.0f); +BENCH(float, AmdExpfUnderflow, __ocml_exp_f32, UniformLinear, -104.0f, -103.0f); +BENCH(float, AmdExpfOverflow, __ocml_exp_f32, UniformLinear, 88.0f, 89.0f); +#endif diff --git a/libc/benchmarks/gpu/src/math/log_benchmark.cpp b/libc/benchmarks/gpu/src/math/log_benchmark.cpp new file mode 100644 index 000000000000..0ea1906ff053 --- /dev/null +++ b/libc/benchmarks/gpu/src/math/log_benchmark.cpp @@ -0,0 +1,68 @@ +//===-- GPU benchmark for log ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "benchmarks/gpu/LibcGpuBenchmark.h" +#include "benchmarks/gpu/Random.h" + +#include "hdr/stdint_proxy.h" +#include "src/__support/sign.h" +#include "src/math/log.h" + +#if defined(NVPTX_MATH_FOUND) || defined(AMDGPU_MATH_FOUND) +#include "platform.h" +#endif + +#define RANDOM_INPUT_UniformExponent(T, Func, Min, Max, N) \ + [](uint32_t call_index) { \ + using namespace LIBC_NAMESPACE::benchmarks; \ + \ + const UniformExponent<T> dist(Min, Max, LIBC_NAMESPACE::Sign::POS); \ + return MathPerf<T>::template run_throughput<N>(Func, dist, call_index); \ + } + +#define RANDOM_INPUT_UniformLinear(T, Func, Min, Max, N) \ + [](uint32_t call_index) { \ + using namespace LIBC_NAMESPACE::benchmarks; \ + \ + const UniformLinear<T> dist(Min, Max); \ + return MathPerf<T>::template run_throughput<N>(Func, dist, call_index); \ + } + +#define BENCH(T, Name, Func, Dist, Min, Max) \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogGpuBenchmark, Name##_1, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 1)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogGpuBenchmark, Name##_128, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 128)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogGpuBenchmark, Name##_1024, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 1024)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogGpuBenchmark, Name##_4096, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 4096)) + +using LIBC_NAMESPACE::log; + +static constexpr double INV_E = 0x1.78b56362cef38p-2; // exp(-1.0) +static constexpr double E = 0x1.5bf0a8b145769p+1; // exp(+1.0) + +BENCH(double, LogSubnormal, log, UniformExponent, -1022, -1022); +BENCH(double, LogAroundOne, log, UniformLinear, INV_E, E); +BENCH(double, LogMedMag, log, UniformExponent, -10, 10); +BENCH(double, LogNormal, log, UniformExponent, -1021, 1023); + +#ifdef NVPTX_MATH_FOUND +BENCH(double, NvLogSubnormal, __nv_log, UniformExponent, -1022, -1022); +BENCH(double, NvLogAroundOne, __nv_log, UniformLinear, INV_E, E); +BENCH(double, NvLogMedMag, __nv_log, UniformExponent, -10, 10); +BENCH(double, NvLogNormal, __nv_log, UniformExponent, -1021, 1023); +#endif + +#ifdef AMDGPU_MATH_FOUND +BENCH(double, AmdLogSubnormal, __ocml_log_f64, UniformExponent, -1022, -1022); +BENCH(double, AmdLogAroundOne, __ocml_log_f64, UniformLinear, INV_E, E); +BENCH(double, AmdLogMedMag, __ocml_log_f64, UniformExponent, -10, 10); +BENCH(double, AmdLogNormal, __ocml_log_f64, UniformExponent, -1021, 1023); +#endif diff --git a/libc/benchmarks/gpu/src/math/logf16_benchmark.cpp b/libc/benchmarks/gpu/src/math/logf16_benchmark.cpp new file mode 100644 index 000000000000..9748e15c4640 --- /dev/null +++ b/libc/benchmarks/gpu/src/math/logf16_benchmark.cpp @@ -0,0 +1,62 @@ +//===-- GPU benchmark for logf16 ------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "benchmarks/gpu/LibcGpuBenchmark.h" +#include "benchmarks/gpu/Random.h" + +#include "hdr/stdint_proxy.h" +#include "src/__support/macros/properties/types.h" +#include "src/__support/sign.h" +#include "src/math/logf16.h" + +#if defined(NVPTX_MATH_FOUND) || defined(AMDGPU_MATH_FOUND) +#include "platform.h" +#endif + +#define RANDOM_INPUT_UniformExponent(T, Func, Min, Max, N) \ + [](uint32_t call_index) { \ + using namespace LIBC_NAMESPACE::benchmarks; \ + \ + const UniformExponent<T> dist(Min, Max, LIBC_NAMESPACE::Sign::POS); \ + return MathPerf<T>::template run_throughput<N>(Func, dist, call_index); \ + } + +#define RANDOM_INPUT_UniformLinear(T, Func, Min, Max, N) \ + [](uint32_t call_index) { \ + using namespace LIBC_NAMESPACE::benchmarks; \ + \ + const UniformLinear<T> dist(Min, Max); \ + return MathPerf<T>::template run_throughput<N>(Func, dist, call_index); \ + } + +#define BENCH(T, Name, Func, Dist, Min, Max) \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogf16GpuBenchmark, Name##_1, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 1)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogf16GpuBenchmark, Name##_128, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 128)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogf16GpuBenchmark, Name##_1024, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 1024)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogf16GpuBenchmark, Name##_4096, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 4096)) + +using LIBC_NAMESPACE::logf16; + +static constexpr float16 INV_E = 0x1.78b56362cef38p-2f16; // exp(-1.0) +static constexpr float16 E = 0x1.5bf0a8b145769p+1f16; // exp(+1.0) + +BENCH(float16, Logf16Subnormal, logf16, UniformExponent, -14, -14); +BENCH(float16, Logf16AroundOne, logf16, UniformLinear, INV_E, E); +BENCH(float16, Logf16MedMag, logf16, UniformExponent, -10, 10); +BENCH(float16, Logf16Normal, logf16, UniformExponent, -13, 15); + +#ifdef AMDGPU_MATH_FOUND +BENCH(float16, AmdLogf16Subnormal, __ocml_log_f16, UniformExponent, -14, -14); +BENCH(float16, AmdLogf16AroundOne, __ocml_log_f16, UniformLinear, INV_E, E); +BENCH(float16, AmdLogf16MedMag, __ocml_log_f16, UniformExponent, -10, 10); +BENCH(float16, AmdLogf16Normal, __ocml_log_f16, UniformExponent, -13, 15); +#endif diff --git a/libc/benchmarks/gpu/src/math/logf_benchmark.cpp b/libc/benchmarks/gpu/src/math/logf_benchmark.cpp new file mode 100644 index 000000000000..c4e5a226a18f --- /dev/null +++ b/libc/benchmarks/gpu/src/math/logf_benchmark.cpp @@ -0,0 +1,68 @@ +//===-- GPU benchmark for logf --------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "benchmarks/gpu/LibcGpuBenchmark.h" +#include "benchmarks/gpu/Random.h" + +#include "hdr/stdint_proxy.h" +#include "src/__support/sign.h" +#include "src/math/logf.h" + +#if defined(NVPTX_MATH_FOUND) || defined(AMDGPU_MATH_FOUND) +#include "platform.h" +#endif + +#define RANDOM_INPUT_UniformExponent(T, Func, Min, Max, N) \ + [](uint32_t call_index) { \ + using namespace LIBC_NAMESPACE::benchmarks; \ + \ + const UniformExponent<T> dist(Min, Max, LIBC_NAMESPACE::Sign::POS); \ + return MathPerf<T>::template run_throughput<N>(Func, dist, call_index); \ + } + +#define RANDOM_INPUT_UniformLinear(T, Func, Min, Max, N) \ + [](uint32_t call_index) { \ + using namespace LIBC_NAMESPACE::benchmarks; \ + \ + const UniformLinear<T> dist(Min, Max); \ + return MathPerf<T>::template run_throughput<N>(Func, dist, call_index); \ + } + +#define BENCH(T, Name, Func, Dist, Min, Max) \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogfGpuBenchmark, Name##_1, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 1)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogfGpuBenchmark, Name##_128, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 128)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogfGpuBenchmark, Name##_1024, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 1024)); \ + SINGLE_WAVE_BENCHMARK(LlvmLibcLogfGpuBenchmark, Name##_4096, \ + RANDOM_INPUT_##Dist(T, Func, Min, Max, 4096)) + +using LIBC_NAMESPACE::logf; + +static constexpr float INV_E = 0x1.78b56362cef38p-2f; // exp(-1.0) +static constexpr float E = 0x1.5bf0a8b145769p+1f; // exp(+1.0) + +BENCH(float, LogfSubnormal, logf, UniformExponent, -126, -126); +BENCH(float, LogfAroundOne, logf, UniformLinear, INV_E, E); +BENCH(float, LogfMedMag, logf, UniformExponent, -10, 10); +BENCH(float, LogfNormal, logf, UniformExponent, -125, 127); + +#ifdef NVPTX_MATH_FOUND +BENCH(float, NvLogfSubnormal, __nv_logf, UniformExponent, -126, -126); +BENCH(float, NvLogfAroundOne, __nv_logf, UniformLinear, INV_E, E); +BENCH(float, NvLogfMedMag, __nv_logf, UniformExponent, -10, 10); +BENCH(float, NvLogfNormal, __nv_logf, UniformExponent, -125, 127); +#endif + +#ifdef AMDGPU_MATH_FOUND +BENCH(float, AmdLogfSubnormal, __ocml_log_f32, UniformExponent, -126, -126); +BENCH(float, AmdLogfAroundOne, __ocml_log_f32, UniformLinear, INV_E, E); +BENCH(float, AmdLogfMedMag, __ocml_log_f32, UniformExponent, -10, 10); +BENCH(float, AmdLogfNormal, __ocml_log_f32, UniformExponent, -125, 127); +#endif diff --git a/libc/benchmarks/gpu/src/math/platform.h b/libc/benchmarks/gpu/src/math/platform.h index 2dfa9f2299d4..e675d1e7b0d1 100644 --- a/libc/benchmarks/gpu/src/math/platform.h +++ b/libc/benchmarks/gpu/src/math/platform.h @@ -11,6 +11,7 @@ #include "hdr/stdint_proxy.h" #include "src/__support/macros/attributes.h" #include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" namespace LIBC_NAMESPACE_DECL { @@ -41,17 +42,27 @@ extern const LIBC_INLINE_VAR uint32_t __oclc_ISA_version = 9000; // Forward declarations for the vendor math libraries. extern "C" { #ifdef AMDGPU_MATH_FOUND -double __ocml_sin_f64(double); -float __ocml_sin_f32(float); double __ocml_atan2_f64(double, double); float __ocml_atan2_f32(float, float); +double __ocml_exp_f64(double); +float __ocml_exp_f32(float); +float16 __ocml_exp_f16(float16); +double __ocml_log_f64(double); +float __ocml_log_f32(float); +float16 __ocml_log_f16(float16); +double __ocml_sin_f64(double); +float __ocml_sin_f32(float); #endif #ifdef NVPTX_MATH_FOUND -double __nv_sin(double); -float __nv_sinf(float); double __nv_atan2(double, double); float __nv_atan2f(float, float); +double __nv_exp(double); +float __nv_expf(float); +double __nv_log(double); +float __nv_logf(float); +double __nv_sin(double); +float __nv_sinf(float); #endif } diff --git a/libc/benchmarks/gpu/src/math/sin_benchmark.cpp b/libc/benchmarks/gpu/src/math/sin_benchmark.cpp index 5fe95c3f3b26..5ed82c845dec 100644 --- a/libc/benchmarks/gpu/src/math/sin_benchmark.cpp +++ b/libc/benchmarks/gpu/src/math/sin_benchmark.cpp @@ -1,4 +1,5 @@ #include "benchmarks/gpu/LibcGpuBenchmark.h" +#include "benchmarks/gpu/Random.h" #include "hdr/stdint_proxy.h" #include "src/math/sin.h" @@ -10,8 +11,10 @@ #define BM_RANDOM_INPUT(T, Func, MinExp, MaxExp, N) \ [](uint32_t call_index) { \ - return LIBC_NAMESPACE::benchmarks::MathPerf<T>::run_throughput_in_range< \ - N>(Func, MinExp, MaxExp, call_index); \ + using namespace LIBC_NAMESPACE::benchmarks; \ + \ + const UniformExponent<T> dist(MinExp, MaxExp); \ + return MathPerf<T>::template run_throughput<N>(Func, dist, call_index); \ } #define BENCH(T, Name, Func, MinExp, MaxExp) \ |
