[libc-commits] [libc] [libc] NVPTX Profiling Draft (PR #92009)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Wed May 22 13:14:29 PDT 2024
================
@@ -0,0 +1,92 @@
+#include "LibcGpuBenchmark.h"
+#include "src/__support/CPP/algorithm.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/time/gpu/time_utils.h"
+
+namespace LIBC_NAMESPACE {
+namespace libc_gpu_benchmarks {
+
+Benchmark *Benchmark::start = nullptr;
+Benchmark *Benchmark::end = nullptr;
+
+void Benchmark::add_benchmark(Benchmark *benchmark) {
+ if (end == nullptr) {
+ start = benchmark;
+ end = benchmark;
+ return;
+ }
+ end->next = benchmark;
+ end = benchmark;
+}
+
+int Benchmark::run_benchmarks() {
+ for (Benchmark *b = start; b != nullptr; b = b->next)
+ b->run();
+ return 0;
+}
+
+BenchmarkResult benchmark(const BenchmarkOptions &options,
+ cpp::function<uint64_t(void)> wrapper_func) {
+ BenchmarkResult result;
+ RuntimeEstimationProgression rep;
+ size_t total_iterations = 0;
+ size_t iterations = options.initial_iterations;
+ if (iterations < (uint32_t)1)
+ iterations = 1;
+
+ size_t samples = 0;
+ uint64_t total_time = 0;
+ uint64_t best_guess = 0;
+ uint64_t total_cycles = 0;
+ uint64_t cycles_2 = 0;
+ uint64_t min = UINT_MAX;
+ uint64_t max = 0;
+ for (;;) {
+ uint64_t sample_cycles = 0;
+ uint64_t overhead = LIBC_NAMESPACE::overhead();
----------------
jhuber6 wrote:
Just do this a few times and get the smallest. It's possible that the scheduler could make this take a really long time and then your results would be negative.
https://github.com/llvm/llvm-project/pull/92009
More information about the libc-commits
mailing list