File tree Expand file tree Collapse file tree 4 files changed +30
-24
lines changed Expand file tree Collapse file tree 4 files changed +30
-24
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ function(add_benchmark benchmark_name)
22
22
${BENCHMARK_LINK_LIBRARIES}
23
23
DEPENDS
24
24
libc.src.stdio.printf
25
+ libc.src.stdlib.srand
26
+ libc.src.stdlib.rand
25
27
${BENCHMARK_DEPENDS}
26
28
${BENCHMARK_UNPARSED_ARGUMENTS}
27
29
COMPILE_OPTIONS
@@ -62,6 +64,7 @@ add_unittest_framework_library(
62
64
libc.src.__support.fixedvector
63
65
libc.src.time.clock
64
66
libc.src.stdlib.rand
67
+ libc.src.stdlib.srand
65
68
libc.benchmarks.gpu.timing.timing
66
69
libc.src.stdio.printf
67
70
)
Original file line number Diff line number Diff line change 8
8
#include " src/__support/fixedvector.h"
9
9
#include " src/__support/macros/config.h"
10
10
#include " src/stdio/printf.h"
11
+ #include " src/stdlib/srand.h"
11
12
#include " src/time/gpu/time_utils.h"
12
13
13
14
namespace LIBC_NAMESPACE_DECL {
@@ -133,6 +134,29 @@ void print_header() {
133
134
" --------------------------------\n " );
134
135
}
135
136
137
+ // We want our random values to be approximately
138
+ // |real value| <= 2^(max_exponent) * (1 + (random 52 bits) * 2^-52) <
139
+ // 2^(max_exponent + 1)
140
+ // The largest integer that can be stored in a double is 2^53
141
+ static constexpr int MAX_EXPONENT = 52 ;
142
+
143
+ static double get_rand () {
144
+ using FPBits = LIBC_NAMESPACE::fputil::FPBits<double >;
145
+ uint64_t bits = LIBC_NAMESPACE::rand ();
146
+ double scale = 0.5 + MAX_EXPONENT / 2048.0 ;
147
+ FPBits fp (bits);
148
+ fp.set_biased_exponent (
149
+ static_cast <uint32_t >(fp.get_biased_exponent () * scale));
150
+ return fp.get_val ();
151
+ }
152
+
153
+ static void init_random_input () {
154
+ LIBC_NAMESPACE::srand (LIBC_NAMESPACE::gpu::processor_clock ());
155
+ for (int i = 0 ; i < RANDOM_INPUT_SIZE; i++) {
156
+ random_input[i] = get_rand ();
157
+ }
158
+ }
159
+
136
160
void Benchmark::run_benchmarks () {
137
161
uint64_t id = gpu::get_thread_id ();
138
162
Original file line number Diff line number Diff line change @@ -109,30 +109,9 @@ class Benchmark {
109
109
}
110
110
};
111
111
112
- // We want our random values to be approximately
113
- // |real value| <= 2^(max_exponent) * (1 + (random 52 bits) * 2^-52) <
114
- // 2^(max_exponent + 1)
115
- // The largest integer that can be stored in a double is 2^53
116
- static constexpr int MAX_EXPONENT = 52 ;
117
112
static constexpr int RANDOM_INPUT_SIZE = 1024 ;
118
113
static cpp::array<double , RANDOM_INPUT_SIZE> random_input;
119
114
120
- static double get_rand () {
121
- using FPBits = LIBC_NAMESPACE::fputil::FPBits<double >;
122
- uint64_t bits = LIBC_NAMESPACE::rand ();
123
- double scale = 0.5 + MAX_EXPONENT / 2048.0 ;
124
- FPBits fp (bits);
125
- fp.set_biased_exponent (
126
- static_cast <uint32_t >(fp.get_biased_exponent () * scale));
127
- return fp.get_val ();
128
- }
129
-
130
- static void init_random_input () {
131
- for (int i = 0 ; i < RANDOM_INPUT_SIZE; i++) {
132
- random_input[i] = get_rand ();
133
- }
134
- }
135
-
136
115
template <typename T> class MathPerf {
137
116
using FPBits = fputil::FPBits<T>;
138
117
using StorageType = typename FPBits::StorageType;
Original file line number Diff line number Diff line change @@ -16,10 +16,10 @@ uint64_t get_bits(double x) {
16
16
return LIBC_NAMESPACE::cpp::bit_cast<uint64_t >(x);
17
17
}
18
18
19
- // BENCHMARK() expects a function that with no parameters that returns a
19
+ // BENCHMARK() expects a function with no parameters that returns a
20
20
// uint64_t representing the latency. Defining each benchmark using macro that
21
- // expands to a lambda to allow us to switch the implementation of `sin()` to
22
- // easily register NVPTX benchmarks.
21
+ // expands to a lambda to allow us to switch the implementation of `sin()` and
22
+ // easily register vendor-specific benchmarks.
23
23
#define BM_RANDOM_INPUT (Func ) \
24
24
[]() { \
25
25
uint64_t total_time = 0 ; \
You can’t perform that action at this time.
0 commit comments