Skip to content

Commit

Permalink
Add simple benchmark for vector forward mode
Browse files Browse the repository at this point in the history
  • Loading branch information
vaithak committed Aug 7, 2023
1 parent a07e47a commit 06b006c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions benchmark/Simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,38 @@ static void BM_ReverseModeSumExecute(benchmark::State &state) {
}
BENCHMARK(BM_ReverseModeSumExecute);

// Benchmark computing gradient using vector forward mode via
// CladFunction::execute.
static void BM_VectorForwardModeSumExecute(benchmark::State &state) {
auto vm_grad = clad::differentiate<clad::opts::vector_mode>(sum, "p");
double inputs[] = {1, 2, 3, 4, 5};
double result[3] = {};
clad::array_ref<double> result_ref(result, 3);
unsigned long long sum = 0;
for (auto _ : state) {
vm_grad.execute(inputs,/*dim*/ 3, result_ref);
benchmark::DoNotOptimize(sum += result[0] + result[1] + result[2]);
}
}
BENCHMARK(BM_VectorForwardModeSumExecute);

// Benchmark computing gradient using vector forward mode via
// a forward declaration.
inline void sum_dvec_0(double*, int, clad::array_ref<double>);
static void BM_VectorForwardModeSumFwdDecl(benchmark::State &state) {
auto vm_grad = clad::differentiate<clad::opts::vector_mode>(sum, "p");
(void) vm_grad;
double inputs[] = {1, 2, 3, 4, 5};
double result[3] = {};
clad::array_ref<double> result_ref(result, 3);
unsigned long long sum = 0;
for (auto _ : state) {
sum_dvec_0(inputs,/*dim*/ 3, result_ref);
benchmark::DoNotOptimize(sum += result[0] + result[1] + result[2]);
}
}
BENCHMARK(BM_VectorForwardModeSumFwdDecl);


// Define our main.
BENCHMARK_MAIN();

0 comments on commit 06b006c

Please sign in to comment.