Skip to content

Commit 6911f82

Browse files
committed
[libc] Fix invalid format specifier in benchmark
Summary: This value is a uint32_t but is printed as a uint64_t, leading to invalid offsets when done on AMDGPU due to its packed format extending past the buffer.
1 parent 2c92335 commit 6911f82

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

libc/benchmarks/gpu/LibcGpuBenchmark.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,10 @@ struct AtomicBenchmarkSums {
7474
};
7575

7676
AtomicBenchmarkSums all_results;
77-
const char *header_format_string =
78-
"Benchmark | Cycles | Min | Max | Iterations | "
79-
"Time | Stddev | Threads |\n";
80-
const char *output_format_string =
81-
"%-20s |%8ld |%8ld |%8ld |%11ld |%9ld %2s |%9ld |%9d |\n";
82-
8377
constexpr auto GREEN = "\033[32m";
8478
constexpr auto RESET = "\033[0m";
8579

8680
void print_results(Benchmark *b) {
87-
8881
BenchmarkResult result;
8982
cpp::atomic_thread_fence(cpp::MemoryOrder::RELEASE);
9083
int num_threads = all_results.active_threads.load(cpp::MemoryOrder::RELAXED);
@@ -104,35 +97,37 @@ void print_results(Benchmark *b) {
10497
const uint64_t duration_us = duration_ns / 1000;
10598
const uint64_t duration_ms = duration_ns / (1000 * 1000);
10699
uint64_t converted_duration = duration_ns;
107-
cpp::string time_unit;
100+
const char *time_unit;
108101
if (duration_ms != 0) {
109102
converted_duration = duration_ms;
110-
time_unit = cpp::string("ms");
103+
time_unit = "ms";
111104
} else if (duration_us != 0) {
112105
converted_duration = duration_us;
113-
time_unit = cpp::string("us");
106+
time_unit = "us";
114107
} else {
115108
converted_duration = duration_ns;
116-
time_unit = cpp::string("ns");
109+
time_unit = "ns";
117110
}
118111
result.total_time = converted_duration;
119112
// result.total_time =
120113
// all_results.time_sum.load(cpp::MemoryOrder::RELAXED) / num_threads;
121114
cpp::atomic_thread_fence(cpp::MemoryOrder::RELEASE);
122115

123116
LIBC_NAMESPACE::printf(
124-
output_format_string, b->get_test_name().data(), result.cycles,
125-
result.min, result.max, result.total_iterations, result.total_time,
126-
time_unit.data(), static_cast<uint64_t>(result.standard_deviation),
127-
num_threads);
117+
"%-20s |%8ld |%8ld |%8ld |%11d |%9ld %2s |%9ld |%9d |\n",
118+
b->get_test_name().data(), result.cycles, result.min, result.max,
119+
result.total_iterations, result.total_time, time_unit,
120+
static_cast<uint64_t>(result.standard_deviation), num_threads);
128121
}
129122

130123
void print_header() {
131124
LIBC_NAMESPACE::printf("%s", GREEN);
132125
LIBC_NAMESPACE::printf("Running Suite: %-10s\n",
133126
benchmarks[0]->get_suite_name().data());
134127
LIBC_NAMESPACE::printf("%s", RESET);
135-
LIBC_NAMESPACE::printf(header_format_string);
128+
LIBC_NAMESPACE::printf("Benchmark | Cycles | Min | Max | "
129+
"Iterations | "
130+
"Time | Stddev | Threads |\n");
136131
LIBC_NAMESPACE::printf(
137132
"---------------------------------------------------------------------"
138133
"--------------------------------\n");

0 commit comments

Comments
 (0)