@@ -156,7 +156,7 @@ ensure_finalization(bool _static_init = false)
156
156
config::set_signal_handler (&finalization_handler);
157
157
158
158
if (config::set_attach_signal_handler (nullptr ) == nullptr )
159
- config::set_signal_handler (&attach_detach_handler);
159
+ config::set_attach_signal_handler (&attach_detach_handler);
160
160
161
161
if (_static_init)
162
162
{
@@ -418,8 +418,16 @@ rocprofsys_init_library_hidden()
418
418
} };
419
419
420
420
ROCPROFSYS_CONDITIONAL_BASIC_PRINT_F (_debug_init, " \n " );
421
- }
422
421
422
+ if (tim::get_env (" ROCPROFSYS_ATTACH" , false ) &&
423
+ config::set_attach_signal_handler (nullptr ) == nullptr )
424
+ config::set_attach_signal_handler (&attach_detach_handler);
425
+ }
426
+ // Initialize RCCL if:
427
+ // - postinit=true - so the code doesn't hang at the initialization stage
428
+ // - get_state() >= State::Init - so the code doesn't throw an exception
429
+ // - rccl_initialized=false - so we don't try to initialize RCCL twice
430
+ // - get_use_rcclp()=true - only if the environment is configured to use RCCL
423
431
static void
424
432
rccl_setup (bool postinit)
425
433
{
@@ -467,14 +475,11 @@ rocprofsys_init_tooling_hidden(bool postinit)
467
475
468
476
ROCPROFSYS_CONDITIONAL_BASIC_PRINT_F (_debug_init, " State is %s...\n " ,
469
477
std::to_string (get_state ()).c_str ());
470
- if (_is_attach)
471
- if (get_state () != State::PreInit || get_state () == State::Init || _once)
472
- {
473
- rccl_setup (postinit);
474
- if (!tim::get_env (" ROCPROFSYS_ATTACH" , false ) ||
475
- get_state () >= State::Active || _once)
476
- return false ;
477
- }
478
+ if (get_state () != State::PreInit || get_state () == State::Init || _once)
479
+ {
480
+ rccl_setup (postinit);
481
+ if (!_is_attach || get_state () >= State::Active || _once) return false ;
482
+ }
478
483
_once = true ;
479
484
480
485
ROCPROFSYS_SCOPED_THREAD_STATE (ThreadState::Internal);
@@ -549,13 +554,10 @@ rocprofsys_init_tooling_hidden(bool postinit)
549
554
if (get_use_sampling ()) sampling::block_signals ();
550
555
551
556
// perfetto initialization
552
- // Tim: Perfetto should only need to be setup once.
553
- static bool _perfetto_once = false ;
554
- if (!_perfetto_once && get_use_perfetto ())
557
+ if (get_use_perfetto ())
555
558
{
556
559
ROCPROFSYS_VERBOSE_F (1 , " Setting up Perfetto...\n " );
557
560
rocprofsys::perfetto::setup ();
558
- _perfetto_once = true ;
559
561
}
560
562
561
563
tasking::setup ();
@@ -606,7 +608,7 @@ rocprofsys_init_tooling_hidden(bool postinit)
606
608
categories::setup ();
607
609
608
610
#if defined(ROCPROFSYS_USE_ROCM) && ROCPROFSYS_USE_ROCM > 0
609
- rocprofiler_sdk::start ();
611
+ if (_is_attach) rocprofiler_sdk::start ();
610
612
#endif
611
613
// if static objects are destroyed in the inverse order of when they are
612
614
// created this should ensure that finalization is called before perfetto
0 commit comments