Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit b858a08

Browse files
tapaswenipathakpramodk
authored andcommitted
Added instrumentor::phase struct API implementation (#168)
- This has implementation of instrumentor::phase struct and replaces use of existing implementation. - Clang-format source and suppress warning with clang for unused value
1 parent f776393 commit b858a08

File tree

6 files changed

+104
-62
lines changed

6 files changed

+104
-62
lines changed

coreneuron/nrniv/main1.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,10 @@ extern "C" int run_solve_core(int argc, char** argv) {
453453
}
454454

455455
// initializationa and loading functions moved to separate
456-
Instrumentor::phase_begin("load-model");
457-
nrn_init_and_load_data(argc, argv, !configs.empty());
458-
Instrumentor::phase_end("load-model");
456+
{
457+
Instrumentor::phase p("load-model");
458+
nrn_init_and_load_data(argc, argv, !configs.empty());
459+
}
459460

460461
std::string checkpoint_path = nrnopt_get_str("--checkpoint");
461462
if (strlen(checkpoint_path.c_str())) {
@@ -543,19 +544,20 @@ extern "C" int run_solve_core(int argc, char** argv) {
543544
// Report global cell statistics
544545
report_cell_stats();
545546

546-
547547
// prcellstate after end of solver
548548
call_prcellstate_for_prcellgid(nrnopt_get_int("--prcellgid"), compute_gpu, 0);
549549
}
550550

551551
// write spike information to outpath
552-
Instrumentor::phase_begin("output-spike");
553-
output_spikes(output_dir.c_str());
554-
Instrumentor::phase_end("output-spike");
552+
{
553+
Instrumentor::phase p("output-spike");
554+
output_spikes(output_dir.c_str());
555+
}
555556

556-
Instrumentor::phase_begin("checkpoint");
557-
write_checkpoint(nrn_threads, nrn_nthread, checkpoint_path.c_str(), nrn_need_byteswap);
558-
Instrumentor::phase_end("checkpoint");
557+
{
558+
Instrumentor::phase p("checkpoint");
559+
write_checkpoint(nrn_threads, nrn_nthread, checkpoint_path.c_str(), nrn_need_byteswap);
560+
}
559561

560562
// must be done after checkpoint (to avoid deleting events)
561563
if (reports_needs_finalize) {

coreneuron/nrniv/profiler_interface.h

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ namespace coreneuron {
2727

2828
namespace detail {
2929

30-
/*! \class Instrumentor
31-
* \brief Instrumentation infrastructure for benchmarking and profiling.
32-
*
33-
* The Instrumentor class exposes static methods that can be used to
34-
* toggle with fine-grained resolution the profiling of specific
35-
* areas within the code.
36-
*/
30+
/*! \class Instrumentor
31+
* \brief Instrumentation infrastructure for benchmarking and profiling.
32+
*
33+
* The Instrumentor class exposes static methods that can be used to
34+
* toggle with fine-grained resolution the profiling of specific
35+
* areas within the code.
36+
*/
3737
template <class... TProfilerImpl>
3838
struct Instrumentor {
39+
#pragma clang diagnostic push
40+
#pragma clang diagnostic ignored "-Wunused-value"
3941
/*! \fn phase_begin
4042
* \brief Activate the collection of profiling data within a code region.
4143
*
@@ -128,6 +130,7 @@ struct Instrumentor {
128130
inline static void finalize_profile() {
129131
std::initializer_list<int>{(TProfilerImpl::finalize_profile(), 0)...};
130132
}
133+
#pragma clang diagnostic pop
131134
};
132135

133136
#if defined(CORENEURON_CALIPER)
@@ -220,29 +223,26 @@ struct Tau {
220223
#if defined(LIKWID_PERFMON)
221224

222225
struct Likwid {
223-
inline static void phase_begin(const char* name){
226+
inline static void phase_begin(const char* name) {
224227
LIKWID_MARKER_START(name);
225228
};
226229

227-
inline static void phase_end(const char* name){
230+
inline static void phase_end(const char* name) {
228231
LIKWID_MARKER_STOP(name);
229232
};
230233

231-
inline static void start_profile() {};
234+
inline static void start_profile(){};
232235

233-
inline static void stop_profile() {};
236+
inline static void stop_profile(){};
234237

235-
inline static void init_profile(){
238+
inline static void init_profile() {
236239
LIKWID_MARKER_INIT;
237240

238241
#pragma omp parallel
239-
{
240-
LIKWID_MARKER_THREADINIT;
241-
}
242-
242+
{ LIKWID_MARKER_THREADINIT; }
243243
};
244244

245-
inline static void finalize_profile(){
245+
inline static void finalize_profile() {
246246
LIKWID_MARKER_CLOSE;
247247
};
248248
};
@@ -258,9 +258,7 @@ struct NullInstrumentor {
258258
inline static void finalize_profile(){};
259259
};
260260

261-
} // namespace detail
262-
263-
using Instrumentor = detail::Instrumentor<
261+
using InstrumentorImpl = detail::Instrumentor<
264262
#if defined CORENEURON_CALIPER
265263
detail::Caliper,
266264
#endif
@@ -277,5 +275,41 @@ using Instrumentor = detail::Instrumentor<
277275
detail::Likwid,
278276
#endif
279277
detail::NullInstrumentor>;
278+
} // namespace detail
279+
280+
namespace Instrumentor {
281+
struct phase {
282+
phase(const char* name) {
283+
detail::InstrumentorImpl::phase_begin(name);
284+
}
285+
~phase() {
286+
detail::InstrumentorImpl::phase_end("");
287+
}
288+
};
289+
290+
inline static void start_profile() {
291+
detail::InstrumentorImpl::start_profile();
292+
}
293+
294+
inline static void stop_profile() {
295+
detail::InstrumentorImpl::stop_profile();
296+
}
297+
298+
inline static void phase_begin(const char* name) {
299+
detail::InstrumentorImpl::phase_begin(name);
300+
}
301+
302+
inline static void phase_end(const char* name) {
303+
detail::InstrumentorImpl::phase_end(name);
304+
}
305+
306+
inline static void init_profile() {
307+
detail::InstrumentorImpl::init_profile();
308+
}
309+
310+
inline static void finalize_profile() {
311+
detail::InstrumentorImpl::finalize_profile();
312+
}
313+
}
280314

281315
} // namespace coreneuron

coreneuron/nrnmpi/mpispike.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@ void wait_before_spike_exchange() {
116116
int nrnmpi_spike_exchange() {
117117
int i, n;
118118
Instrumentor::phase_begin("spike-exchange");
119-
Instrumentor::phase_begin("imbalance");
120-
wait_before_spike_exchange();
121-
Instrumentor::phase_end("imbalance");
119+
120+
{
121+
Instrumentor::phase p("imbalance");
122+
wait_before_spike_exchange();
123+
}
122124

123125
Instrumentor::phase_begin("communication");
124126
#if nrn_spikebuf_size > 0

coreneuron/nrnoc/fadvance_core.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,11 @@ void update(NrnThread* _nt) {
192192
}
193193
}
194194

195-
196195
void nonvint(NrnThread* _nt) {
197196
NrnThreadMembList* tml;
198197
if (nrn_have_gaps) {
199-
Instrumentor::phase_begin("gap-v-transfer");
198+
Instrumentor::phase p("gap-v-transfer");
200199
nrnthread_v_transfer(_nt);
201-
Instrumentor::phase_end("gap-v-transfer");
202200
}
203201
errno = 0;
204202

@@ -208,9 +206,10 @@ void nonvint(NrnThread* _nt) {
208206
mod_f_t s = memb_func[tml->index].state;
209207
std::string ss("state-");
210208
ss += nrn_get_mechname(tml->index);
211-
Instrumentor::phase_begin(ss.c_str());
212-
(*s)(_nt, tml->ml, tml->index);
213-
Instrumentor::phase_end(ss.c_str());
209+
{
210+
Instrumentor::phase p(ss.c_str());
211+
(*s)(_nt, tml->ml, tml->index);
212+
}
214213
#ifdef DEBUG
215214
if (errno) {
216215
hoc_warning("errno set during calculation of states", (char*)0);
@@ -277,9 +276,10 @@ static void* nrn_fixed_step_thread(NrnThread* nth) {
277276
events up to t+dt/2 */
278277
Instrumentor::phase_begin("timestep");
279278

280-
Instrumentor::phase_begin("deliver_events");
281-
deliver_net_events(nth);
282-
Instrumentor::phase_end("deliver_events");
279+
{
280+
Instrumentor::phase p("deliver_events");
281+
deliver_net_events(nth);
282+
}
283283

284284
nth->_t += .5 * nth->_dt;
285285

@@ -294,21 +294,25 @@ static void* nrn_fixed_step_thread(NrnThread* nth) {
294294
#endif
295295
fixed_play_continuous(nth);
296296

297-
Instrumentor::phase_begin("setup_tree_matrix");
298-
setup_tree_matrix_minimal(nth);
299-
Instrumentor::phase_end("setup_tree_matrix");
297+
{
298+
Instrumentor::phase p("setup_tree_matrix");
299+
setup_tree_matrix_minimal(nth);
300+
}
300301

301-
Instrumentor::phase_begin("matrix-solver");
302-
nrn_solve_minimal(nth);
303-
Instrumentor::phase_end("matrix-solver");
302+
{
303+
Instrumentor::phase p("matrix-solver");
304+
nrn_solve_minimal(nth);
305+
}
304306

305-
Instrumentor::phase_begin("second_order_cur");
306-
second_order_cur(nth, secondorder);
307-
Instrumentor::phase_end("second_order_cur");
307+
{
308+
Instrumentor::phase p("second_order_cur");
309+
second_order_cur(nth, secondorder);
310+
}
308311

309-
Instrumentor::phase_begin("update");
310-
update(nth);
311-
Instrumentor::phase_end("update");
312+
{
313+
Instrumentor::phase p("update");
314+
update(nth);
315+
}
312316
}
313317
if (!nrn_have_gaps) {
314318
nrn_fixed_step_lastpart(nth);
@@ -339,9 +343,11 @@ void* nrn_fixed_step_lastpart(NrnThread* nth) {
339343
nrncore2nrn_send_values(nth);
340344
}
341345

342-
Instrumentor::phase_begin("deliver_events");
343-
nrn_deliver_events(nth); /* up to but not past texit */
344-
Instrumentor::phase_end("deliver_events");
346+
{
347+
Instrumentor::phase p("deliver_events");
348+
nrn_deliver_events(nth); /* up to but not past texit */
349+
}
350+
345351
return (void*)0;
346352
}
347353
} // namespace coreneuron

coreneuron/nrnoc/treeset_core.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ static void nrn_rhs(NrnThread* _nt) {
7474
mod_f_t s = memb_func[tml->index].current;
7575
std::string ss("cur-");
7676
ss += nrn_get_mechname(tml->index);
77-
Instrumentor::phase_begin(ss.c_str());
77+
Instrumentor::phase p(ss.c_str());
7878
(*s)(_nt, tml->ml, tml->index);
79-
Instrumentor::phase_end(ss.c_str());
8079
#ifdef DEBUG
8180
if (errno) {
8281
hoc_warning("errno set during calculation of currents", (char*)0);
@@ -130,9 +129,8 @@ static void nrn_lhs(NrnThread* _nt) {
130129
mod_f_t s = memb_func[tml->index].jacob;
131130
std::string ss("cur-");
132131
ss += nrn_get_mechname(tml->index);
133-
Instrumentor::phase_begin(ss.c_str());
132+
Instrumentor::phase p(ss.c_str());
134133
(*s)(_nt, tml->ml, tml->index);
135-
Instrumentor::phase_end(ss.c_str());
136134
#ifdef DEBUG
137135
if (errno) {
138136
hoc_warning("errno set during calculation of jacobian", (char*)0);

coreneuron/utils/ispc/globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
*/
77

88
extern "C" {
9-
double ispc_celsius;
9+
double ispc_celsius;
1010
}

0 commit comments

Comments
 (0)