60 lines · cpp
1//===-- GPU benchmark for exp ---------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "benchmarks/gpu/LibcGpuBenchmark.h"10#include "benchmarks/gpu/Random.h"11 12#include "hdr/stdint_proxy.h"13#include "src/math/exp.h"14 15#if defined(NVPTX_MATH_FOUND) || defined(AMDGPU_MATH_FOUND)16#include "platform.h"17#endif18 19#define RANDOM_INPUT(T, Func, Dist, Min, Max, N) \20 [](uint32_t call_index) { \21 using namespace LIBC_NAMESPACE::benchmarks; \22 \23 const Dist<T> dist(Min, Max); \24 return MathPerf<T>::template run_throughput<N>(Func, dist, call_index); \25 }26 27#define BENCH(T, Name, Func, Dist, Min, Max) \28 SINGLE_WAVE_BENCHMARK(LlvmLibcExpGpuBenchmark, Name##_1, \29 RANDOM_INPUT(T, Func, Dist, Min, Max, 1)); \30 SINGLE_WAVE_BENCHMARK(LlvmLibcExpGpuBenchmark, Name##_128, \31 RANDOM_INPUT(T, Func, Dist, Min, Max, 128)); \32 SINGLE_WAVE_BENCHMARK(LlvmLibcExpGpuBenchmark, Name##_1024, \33 RANDOM_INPUT(T, Func, Dist, Min, Max, 1024)); \34 SINGLE_WAVE_BENCHMARK(LlvmLibcExpGpuBenchmark, Name##_4096, \35 RANDOM_INPUT(T, Func, Dist, Min, Max, 4096))36 37using LIBC_NAMESPACE::exp;38 39BENCH(double, ExpSubnormal, exp, UniformExponent, -1022, -1022);40BENCH(double, ExpCoreRange, exp, UniformLinear, -10.0, 10.0);41BENCH(double, ExpFinite, exp, UniformLinear, -745.0, 709.0);42BENCH(double, ExpUnderflow, exp, UniformLinear, -746.0, -745.0);43BENCH(double, ExpOverflow, exp, UniformLinear, 709.0, 710.0);44 45#ifdef NVPTX_MATH_FOUND46BENCH(double, NvExpSubnormal, __nv_exp, UniformExponent, -1022, -1022);47BENCH(double, NvExpCoreRange, __nv_exp, UniformLinear, -10.0, 10.0);48BENCH(double, NvExpFinite, __nv_exp, UniformLinear, -745.0, 709.0);49BENCH(double, NvExpUnderflow, __nv_exp, UniformLinear, -746.0, -745.0);50BENCH(double, NvExpOverflow, __nv_exp, UniformLinear, 709.0, 710.0);51#endif52 53#ifdef AMDGPU_MATH_FOUND54BENCH(double, AmdExpSubnormal, __ocml_exp_f64, UniformExponent, -1022, -1022);55BENCH(double, AmdExpCoreRange, __ocml_exp_f64, UniformLinear, -10.0, 10.0);56BENCH(double, AmdExpFinite, __ocml_exp_f64, UniformLinear, -745.0, 709.0);57BENCH(double, AmdExpUnderflow, __ocml_exp_f64, UniformLinear, -746.0, -745.0);58BENCH(double, AmdExpOverflow, __ocml_exp_f64, UniformLinear, 709.0, 710.0);59#endif60