[libc-commits] [libc] [libc] NVPTX Profiling Draft (PR #92009)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Tue May 14 08:58:58 PDT 2024
================
@@ -0,0 +1,122 @@
+#ifndef LLVM_LIBC_BENCHMARKS_LIBC_GPU_BENCHMARK_H
+#define LLVM_LIBC_BENCHMARKS_LIBC_GPU_BENCHMARK_H
+
+#include "benchmarks/gpu/timing/timing.h"
+
+#include "benchmarks/gpu/BenchmarkLogger.h"
+
+#include <stddef.h>
+#include <stdint.h>
+
+namespace LIBC_NAMESPACE {
+
+namespace libc_gpu_benchmarks {
+
+struct BenchmarkOptions {
+ uint32_t InitialIterations = 1;
+ uint32_t MaxIterations = 10000000;
+ uint32_t MinSamples = 4;
+ uint32_t MaxSamples = 1000;
+ double Epsilon = 0.01;
+ double ScalingFactor = 1.4;
+};
+
+struct Measurement {
+ size_t Iterations = 0;
+ uint64_t ElapsedCycles = 0;
+};
+
+class RefinableRuntimeEstimation {
+ uint64_t TotalCycles = 0;
+ size_t TotalIterations = 0;
+
+public:
+ uint64_t Update(const Measurement &M) {
+ TotalCycles += M.ElapsedCycles;
+ TotalIterations += M.Iterations;
+ return TotalCycles / TotalIterations;
+ }
+};
+
+// Tracks the progression of the runtime estimation
+class RuntimeEstimationProgression {
+ RefinableRuntimeEstimation RRE;
+
+public:
+ uint64_t CurrentEstimation = 0;
+
+ double ComputeImprovement(const Measurement &M) {
+ const uint64_t NewEstimation = RRE.Update(M);
+ double Ratio = ((double)CurrentEstimation / NewEstimation) - 1.0;
+
+ // Get absolute value
+ if (Ratio < 0) {
+ Ratio *= -1;
+ }
+
+ CurrentEstimation = NewEstimation;
+ return Ratio;
+ }
+};
+
+struct BenchmarkResult {
+ uint64_t Cycles = 0;
+ size_t Samples = 0;
+ size_t TotalIterations = 0;
+};
+
+BenchmarkResult benchmark(const BenchmarkOptions &Options,
+ uint64_t (*WrapperFunc)());
+
+class Benchmark {
+ Benchmark *Next = nullptr;
+
+public:
+ virtual ~Benchmark() {}
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+
+ static int runBenchmarks();
+
+protected:
+ static void addBenchmark(Benchmark *);
+
+private:
+ virtual void Run() = 0;
+ virtual const char *getName() const = 0;
+
+ static Benchmark *Start;
+ static Benchmark *End;
+};
+
+class WrapperBenchmark : public Benchmark {
+ using BenchmarkWrapperFunction = uint64_t (*)();
+ BenchmarkWrapperFunction Func;
+ const char *Name;
----------------
jhuber6 wrote:
```suggestion
cpp:string_view Name;
```
https://github.com/llvm/llvm-project/pull/92009
More information about the libc-commits
mailing list