82 void Print(
const std::string &label)
const
85 auto row = [&](
const char *name,
double t)
87 std::cout <<
" " << std::left << std::setw(24) << name
88 << std::right << std::setw(10) << std::fixed << std::setprecision(4) << t <<
" s"
89 << std::setw(8) << std::setprecision(1) << (phaseSum > 0 ? 100.0 * t / phaseSum : 0.0) <<
"%\n";
93 <<
" CalculateState calls, " <<
updateStateCalls <<
" UpdateState calls) ---\n";
94 std::cout <<
" CalculateState() [top-level: " << std::fixed << std::setprecision(4)
107 std::cout <<
" Other:\n";
110 std::cout <<
" Sub-phase sum: " << phaseSum <<
" s"
112 <<
" -- these should be CLOSE; large divergence means the sub-phase"
113 <<
" timers aren't capturing everything the function does)\n";
131 static std::vector<std::pair<const void *, ProfileEntry>> registry;
143 template <
typename LayerT>
147 for (
auto &entry : registry)
148 if (entry.first == layer)
149 return entry.second.acc;
152 entry.
label =
"layer(" + std::to_string(layer->GetInputSize()) +
"->"
153 + std::to_string(layer->GetOutputSize()) +
") @ " + std::to_string((
size_t)layer);
154 registry.emplace_back(layer, std::move(entry));
155 return registry.back().second.acc;
169 double grandTotal = 0.0;
172 entry.second.acc.Print(entry.second.label);
173 grandTotal += entry.second.acc.PhaseSum();
175 std::cout <<
"\n=== Reconciliation ===\n";
176 std::cout <<
" Wall-clock (measured around whole run): " << std::fixed << std::setprecision(4)
177 << wallClockSeconds <<
" s\n";
178 std::cout <<
" Sum of all layers' phase sums: " << grandTotal <<
" s\n";
179 std::cout <<
" Unaccounted-for time: " << (wallClockSeconds - grandTotal) <<
" s"
180 <<
" (" << (wallClockSeconds > 0 ? 100.0 * (wallClockSeconds - grandTotal) / wallClockSeconds : 0.0)
181 <<
"% -- data loading, Python/pybind overhead, timer overhead itself, etc.)\n";
195 : accumulator(accumulator), start(std::chrono::steady_clock::now()) {}
198 auto end = std::chrono::steady_clock::now();
199 accumulator += std::chrono::duration<double>(end - start).count();
205 std::chrono::steady_clock::time_point start;
209 #define PCN_TIME(accumulator) ::Deep::ScopedTimer _pcn_timer_##__LINE__(accumulator)
221 #define PCN_TIME(accumulator) do {} while (0)
ScopedTimer(double &) noexcept
No-op; the accumulator reference is discarded.
Definition Profile.h:217
This file exists to provide both Tensor.h and IComputeBackend.h with device types without introducing...
Definition Backend.cpp:10
void PrintAllProfiles(double wallClockSeconds)
Prints every registered layer's profile, then a grand-total reconciliation against an independently m...
Definition Profile.h:167
std::vector< std::pair< const void *, ProfileEntry > > & ProfileRegistry()
The process-wide table of every layer that's had LayerProfile() called on it at least once,...
Definition Profile.h:129
ProfileAccumulator & LayerProfile(LayerT *layer)
Looks up (or creates, on first call) layer's accumulator in the process-wide registry,...
Definition Profile.h:144
One layer's accumulated time-per-phase, in seconds – see the file-level note for the reconciliation i...
Definition Profile.h:35
double forwardGemm
CalculateState: the forward prediction GEMM.
Definition Profile.h:38
double bottomUpConstruction
UpdateState: assembling the bottom-up term.
Definition Profile.h:44
double energyCalculation
CalculateState: the energy reduction itself.
Definition Profile.h:37
void Print(const std::string &label) const
Prints this accumulator's per-phase breakdown (with percentages of PhaseSum()) plus the top-level/sub...
Definition Profile.h:82
double errorConstruction
CalculateState: building the error term.
Definition Profile.h:36
double activationForward
CalculateState: forward activation function.
Definition Profile.h:40
double biasAdd
CalculateState: bias-add after the forward GEMM.
Definition Profile.h:39
long long updateStateCalls
Number of UpdateState() calls recorded.
Definition Profile.h:58
double feedbackGemm
UpdateState: the feedback GEMM.
Definition Profile.h:45
double updatePrecisionTotal
UpdatePrecision(), whole-call total.
Definition Profile.h:49
double updateWeightsTotal
UpdateWeights(), whole-call total.
Definition Profile.h:48
double PhaseSum() const noexcept
Sum of every sub-phase timer (excludes the top-level calculateStateTotal/updateStateTotal,...
Definition Profile.h:63
double localErrorTerm
UpdateState: dz_dt = -p*e (was ownGradientTerm – not a backprop gradient).
Definition Profile.h:43
double updateStateTotal
UpdateState(), whole-call total.
Definition Profile.h:55
double saxpyUpdate
UpdateState: the final z += ir*dz SAXPY.
Definition Profile.h:46
double calculateStateTotal
CalculateState(), whole-call total.
Definition Profile.h:54
long long calculateStateCalls
Number of CalculateState() calls recorded.
Definition Profile.h:57
double activationDerivative
UpdateState: activation derivative.
Definition Profile.h:42
One registered layer's profiling data: its print label paired with its accumulator.
Definition Profile.h:120
std::string label
Printed heading, e.g. "layer(784->512) @ 0x...".
Definition Profile.h:121
ProfileAccumulator acc
That layer's accumulated phase timings.
Definition Profile.h:122