Skip to content

Commit f4e6ddb

Browse files
authored
[libc] Fix Cppcheck Issues (#96999)
This PR fixes linting issues discovered by `cppcheck`. Fixes: #96863
1 parent 02c7be5 commit f4e6ddb

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

libc/benchmarks/gpu/LibcGpuBenchmark.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ void Benchmark::add_benchmark(Benchmark *benchmark) {
1717
benchmarks.push_back(benchmark);
1818
}
1919

20-
BenchmarkResult reduce_results(cpp::array<BenchmarkResult, 1024> &results) {
20+
BenchmarkResult
21+
reduce_results(const cpp::array<BenchmarkResult, 1024> &results) {
2122
BenchmarkResult result;
2223
uint64_t cycles_sum = 0;
2324
double standard_deviation_sum = 0;
@@ -51,16 +52,16 @@ void Benchmark::run_benchmarks() {
5152
uint64_t id = gpu::get_thread_id();
5253
gpu::sync_threads();
5354

54-
for (Benchmark *benchmark : benchmarks)
55-
results[id] = benchmark->run();
55+
for (Benchmark *b : benchmarks)
56+
results[id] = b->run();
5657
gpu::sync_threads();
5758
if (id == 0) {
58-
for (Benchmark *benchmark : benchmarks) {
59+
for (Benchmark const *b : benchmarks) {
5960
BenchmarkResult all_results = reduce_results(results);
6061
constexpr auto GREEN = "\033[32m";
6162
constexpr auto RESET = "\033[0m";
62-
log << GREEN << "[ RUN ] " << RESET << benchmark->get_name() << '\n';
63-
log << GREEN << "[ OK ] " << RESET << benchmark->get_name() << ": "
63+
log << GREEN << "[ RUN ] " << RESET << b->get_name() << '\n';
64+
log << GREEN << "[ OK ] " << RESET << b->get_name() << ": "
6465
<< all_results.cycles << " cycles, " << all_results.min << " min, "
6566
<< all_results.max << " max, " << all_results.total_iterations
6667
<< " iterations, " << all_results.total_time << " ns, "
@@ -82,7 +83,6 @@ BenchmarkResult benchmark(const BenchmarkOptions &options,
8283
uint32_t samples = 0;
8384
uint64_t total_time = 0;
8485
uint64_t best_guess = 0;
85-
uint64_t total_cycles = 0;
8686
uint64_t cycles_squared = 0;
8787
uint64_t min = UINT64_MAX;
8888
uint64_t max = 0;
@@ -92,23 +92,22 @@ BenchmarkResult benchmark(const BenchmarkOptions &options,
9292
for (int i = 0; i < overhead_iterations; i++)
9393
overhead = cpp::min(overhead, LIBC_NAMESPACE::overhead());
9494

95-
for (uint64_t time_budget = options.max_duration; time_budget >= 0;) {
95+
for (int64_t time_budget = options.max_duration; time_budget >= 0;) {
9696
uint64_t sample_cycles = 0;
9797
const clock_t start = static_cast<double>(clock());
9898
for (uint32_t i = 0; i < iterations; i++) {
9999
auto wrapper_intermediate = wrapper_func();
100-
uint64_t result = wrapper_intermediate - overhead;
101-
max = cpp::max(max, result);
102-
min = cpp::min(min, result);
103-
sample_cycles += result;
100+
uint64_t current_result = wrapper_intermediate - overhead;
101+
max = cpp::max(max, current_result);
102+
min = cpp::min(min, current_result);
103+
sample_cycles += current_result;
104104
}
105105
const clock_t end = clock();
106106
const clock_t duration_ns =
107107
((end - start) * 1000 * 1000 * 1000) / CLOCKS_PER_SEC;
108108
total_time += duration_ns;
109109
time_budget -= duration_ns;
110110
samples++;
111-
total_cycles += sample_cycles;
112111
cycles_squared += sample_cycles * sample_cycles;
113112

114113
total_iterations += iterations;

libc/benchmarks/gpu/LibcGpuBenchmark.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ struct BenchmarkOptions {
1919
uint32_t max_iterations = 10000000;
2020
uint32_t min_samples = 4;
2121
uint32_t max_samples = 1000;
22-
uint64_t min_duration = 0; // in nanoseconds (ns)
23-
uint64_t max_duration = 1000 * 1000 * 1000; // 1e9 nanoseconds = 1 second
22+
int64_t min_duration = 0; // in nanoseconds (ns)
23+
int64_t max_duration = 1000 * 1000 * 1000; // 1e9 nanoseconds = 1 second
2424
double epsilon = 0.01;
2525
double scaling_factor = 1.4;
2626
};

0 commit comments

Comments
 (0)