-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Add Generic and NVPTX Sin Benchmark #99795
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dbb4f54
implement generic sin benchmark and compare with nvsin
jameshu15869 788f615
basic generic and nvptx sin benchmark
jameshu15869 7d37fed
minor fixes
jameshu15869 3a39304
seed rand with processor clock
jameshu15869 c3e14be
move random array to per thread
jameshu15869 908bdef
use single variable instead of array
jameshu15869 2adc13d
allow AMDGPU to store doubles to register
jameshu15869 a0f1905
minor fixes
jameshu15869 84c2afb
address comments
jameshu15869 1729e13
Correctly generate 64 bit random values
jameshu15869 080f61f
Switch to only 1 thread calling srand() once
jameshu15869 ae902b0
Remove extra LIBC_NAMESPACE
jameshu15869 5fc1219
remove unnecessary colons
jameshu15869 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(ctype) | ||
add_subdirectory(math) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
add_custom_target(libc-gpu-math-benchmarks) | ||
|
||
if(CUDAToolkit_FOUND) | ||
set(libdevice_path ${CUDAToolkit_BIN_DIR}/../nvvm/libdevice/libdevice.10.bc) | ||
if (EXISTS ${libdevice_path}) | ||
set(nvptx_bitcode_link_flags | ||
"SHELL:-Xclang -mlink-builtin-bitcode -Xclang ${libdevice_path}") | ||
# Compile definition needed so the benchmark knows to register | ||
# NVPTX benchmarks. | ||
set(nvptx_math_found "-DNVPTX_MATH_FOUND=1") | ||
endif() | ||
endif() | ||
|
||
add_benchmark( | ||
sin_benchmark | ||
SUITE | ||
libc-gpu-math-benchmarks | ||
SRCS | ||
sin_benchmark.cpp | ||
DEPENDS | ||
libc.src.math.sin | ||
libc.src.stdlib.srand | ||
libc.src.stdlib.rand | ||
libc.src.__support.FPUtil.fp_bits | ||
libc.src.__support.CPP.bit | ||
libc.src.__support.CPP.array | ||
COMPILE_OPTIONS | ||
${nvptx_math_found} | ||
${nvptx_bitcode_link_flags} | ||
LOADER_ARGS | ||
--threads 64 | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "benchmarks/gpu/LibcGpuBenchmark.h" | ||
|
||
#include "src/__support/CPP/array.h" | ||
#include "src/__support/CPP/bit.h" | ||
#include "src/__support/CPP/functional.h" | ||
#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 | ||
|
||
constexpr double M_PI = 3.14159265358979323846; | ||
uint64_t get_bits(double x) { | ||
return LIBC_NAMESPACE::cpp::bit_cast<uint64_t>(x); | ||
} | ||
|
||
// BENCHMARK() expects a function that with no parameters that returns a | ||
// uint64_t representing the latency. Defining each benchmark using macro that | ||
// expands to a lambda to allow us to switch the implementation of `sin()` to | ||
// easily register NVPTX benchmarks. | ||
#define BM_RANDOM_INPUT(Func) \ | ||
[]() { \ | ||
double x = LIBC_NAMESPACE::benchmarks::get_rand_input<double>(); \ | ||
return LIBC_NAMESPACE::latency(Func, x); \ | ||
} | ||
BENCHMARK(LlvmLibcSinGpuBenchmark, Sin, BM_RANDOM_INPUT(LIBC_NAMESPACE::sin)); | ||
|
||
#define BM_TWO_PI(Func) \ | ||
[]() { \ | ||
return LIBC_NAMESPACE::benchmarks::MathPerf<double>::run_perf_in_range( \ | ||
Func, 0, get_bits(2 * M_PI), get_bits(M_PI / 64)); \ | ||
} | ||
BENCHMARK(LlvmLibcSinGpuBenchmark, SinTwoPi, BM_TWO_PI(LIBC_NAMESPACE::sin)); | ||
|
||
#define BM_LARGE_INT(Func) \ | ||
[]() { \ | ||
return LIBC_NAMESPACE::benchmarks::MathPerf<double>::run_perf_in_range( \ | ||
Func, 0, get_bits(1 << 30), get_bits(1 << 4)); \ | ||
} | ||
BENCHMARK(LlvmLibcSinGpuBenchmark, SinLargeInt, | ||
BM_LARGE_INT(LIBC_NAMESPACE::sin)); | ||
|
||
#ifdef NVPTX_MATH_FOUND | ||
BENCHMARK(LlvmLibcSinGpuBenchmark, NvSin, | ||
BM_RANDOM_INPUT(LIBC_NAMESPACE::__nv_sin)); | ||
BENCHMARK(LlvmLibcSinGpuBenchmark, NvSinTwoPi, | ||
BM_TWO_PI(LIBC_NAMESPACE::__nv_sin)); | ||
BENCHMARK(LlvmLibcSinGpuBenchmark, NvSinLargeInt, | ||
BM_LARGE_INT(LIBC_NAMESPACE::__nv_sin)); | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.