1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "tutorial.h"
#include "statistics.h"
#include "benchmark.h"
#ifdef USE_GOOGLE_BENCHMARK
#include <benchmark/benchmark.h>
#endif
/* ray statistics */
#if !defined(TASKING_PPL) // not supported with PPL because threadIndex is not unique and atomics are too expensive
#define RAY_STATS
#endif
namespace embree
{
template<class Tutorial>
static void renderBenchmarkLegacy(BenchState& state, BenchParams& params ,int argc, char** argv);
template<class Tutorial>
static void renderBenchFunc(BenchState& state, BenchParams& params ,int argc, char** argv)
{
#ifdef USE_GOOGLE_BENCHMARK
if (params.legacy) {
renderBenchmarkLegacy<Tutorial>(state, params, argc, argv);
return;
}
Tutorial tutorial;
tutorial.interactive = false;
tutorial.main(argc,argv);
tutorial.resize(tutorial.width, tutorial.height);
ISPCCamera ispccamera = tutorial.camera.getISPCCamera(tutorial.width, tutorial.height);
for (size_t i = 0; i < params.skipIterations; i++)
{
tutorial.initRayStats();
tutorial.render(tutorial.pixels,tutorial.width,tutorial.height,0.0f,ispccamera);
}
size_t numRays = 0;
for (auto _ : *state.state)
{
tutorial.initRayStats();
tutorial.render(tutorial.pixels,tutorial.width,tutorial.height,0.0f,ispccamera);
numRays += tutorial.getNumRays();
}
state.state->SetItemsProcessed(state.state->iterations());
state.state->counters["Rays/s"] = benchmark::Counter(numRays, benchmark::Counter::kIsRate);
#else
renderBenchmarkLegacy<Tutorial>(state, params, argc, argv);
#endif
}
template<class Tutorial>
static void renderBenchmarkLegacy(BenchState& state, BenchParams& params ,int argc, char** argv)
{
Tutorial tutorial;
tutorial.interactive = false;
tutorial.main(argc,argv);
tutorial.resize(tutorial.width, tutorial.height);
ISPCCamera ispccamera = tutorial.camera.getISPCCamera(tutorial.width, tutorial.height);
IOStreamStateRestorer cout_state(std::cout);
std::cout.setf(std::ios::fixed, std::ios::floatfield);
std::cout.precision(4);
//Statistics stat;
FilteredStatistics fpsStat(0.5f,0.0f);
FilteredStatistics mraypsStat(0.5f,0.0f);
{
size_t numTotalFrames = params.skipIterations + params.minTimeOrIterations;
for (size_t i=0; i<params.skipIterations; i++)
{
tutorial.initRayStats();
double t0 = getSeconds();
tutorial.render(tutorial.pixels,tutorial.width,tutorial.height,0.0f,ispccamera);
double t1 = getSeconds();
std::cout << "frame [" << std::setw(3) << i << " / " << std::setw(3) << numTotalFrames << "]: " << std::setw(8) << 1.0/(t1-t0) << " fps (skipped)" << std::endl << std::flush;
}
for (size_t i=params.skipIterations; i<numTotalFrames; i++)
{
tutorial.initRayStats();
double t0 = getSeconds();
tutorial.render(tutorial.pixels,tutorial.width,tutorial.height,0.0f,ispccamera);
double t1 = getSeconds();
float fps = float(1.0/(t1-t0));
fpsStat.add(fps);
float mrayps = float(double(tutorial.getNumRays())/(1000000.0*(t1-t0)));
mraypsStat.add(mrayps);
if (numTotalFrames >= 1024 && (i % 64 == 0))
{
double rate = 0;
if (fpsStat.getAvg()) rate = 100.0f*fpsStat.getSigma()/fpsStat.getAvg();
std::cout << "frame [" << std::setw(3) << i << " / " << std::setw(3) << numTotalFrames << "]: "
<< std::setw(8) << fps << " fps, "
<< "min = " << std::setw(8) << fpsStat.getMin() << " fps, "
<< "avg = " << std::setw(8) << fpsStat.getAvg() << " fps, "
<< "max = " << std::setw(8) << fpsStat.getMax() << " fps, "
<< "sigma = " << std::setw(6) << fpsStat.getSigma() << " (" << rate << "%)" << std::endl << std::flush;
}
}
double rate = 0;
if (fpsStat.getAvg()) rate = 100.0f*fpsStat.getAvgSigma()/fpsStat.getAvg();
std::cout << "frame [" << std::setw(3) << params.skipIterations << " - " << std::setw(3) << numTotalFrames << "]: "
<< " "
<< "min = " << std::setw(8) << fpsStat.getMin() << " fps, "
<< "avg = " << std::setw(8) << fpsStat.getAvg() << " fps, "
<< "max = " << std::setw(8) << fpsStat.getMax() << " fps, "
<< "sigma = " << std::setw(6) << fpsStat.getAvgSigma() << " (" << rate << "%)" << std::endl;
}
std::cout << "BENCHMARK_RENDER_MIN " << fpsStat.getMin() << std::endl;
std::cout << "BENCHMARK_RENDER_AVG " << fpsStat.getAvg() << std::endl;
std::cout << "BENCHMARK_RENDER_MAX " << fpsStat.getMax() << std::endl;
std::cout << "BENCHMARK_RENDER_SIGMA " << fpsStat.getSigma() << std::endl;
std::cout << "BENCHMARK_RENDER_AVG_SIGMA " << fpsStat.getAvgSigma() << std::endl;
#if defined(RAY_STATS)
std::cout << "BENCHMARK_RENDER_MRAYPS_MIN " << mraypsStat.getMin() << std::endl;
std::cout << "BENCHMARK_RENDER_MRAYPS_AVG " << mraypsStat.getAvg() << std::endl;
std::cout << "BENCHMARK_RENDER_MRAYPS_MAX " << mraypsStat.getMax() << std::endl;
std::cout << "BENCHMARK_RENDER_MRAYPS_SIGMA " << mraypsStat.getSigma() << std::endl;
std::cout << "BENCHMARK_RENDER_MRAYPS_AVG_SIGMA " << mraypsStat.getAvgSigma() << std::endl;
#endif
std::cout << std::flush;
}
}
|