Created
December 16, 2020 01:55
-
-
Save SteveBronder/f14df4b040b5d6d3e4afb03fecbf8888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef CALLBACK_TOSS_ME_HPP | |
#define CALLBACK_TOSS_ME_HPP | |
#include <benchmark/benchmark.h> | |
#include <stan/math.hpp> | |
#include <utility> | |
static bool needs_done = true; | |
// Just to fill up the stack allocator | |
template <int max_alloc> | |
static void toss_me(benchmark::State& state) { | |
using stan::math::var; | |
if (needs_done) { | |
needs_done = false; | |
using stan::math::var; | |
using stan::math::sum; | |
Eigen::Matrix<var, -1, -1> x(Eigen::MatrixXd::Random(max_alloc, max_alloc)); | |
Eigen::Matrix<var, -1, -1> y(Eigen::MatrixXd::Random(max_alloc, max_alloc)); | |
Eigen::Matrix<var, -1, -1> z = elt_multiply(x, y); | |
var lp = sum(z); | |
benchmark::DoNotOptimize(lp.vi_); | |
for (auto _ : state) { | |
lp.grad(); | |
stan::math::set_zero_all_adjoints(); | |
} | |
stan::math::recover_memory(); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment