@@ -409,23 +409,25 @@ pi_uint64 _pi_event::get_queued_time() const {
409
409
assert (is_started ());
410
410
411
411
PI_CHECK_ERROR (
412
- cuEventElapsedTime (&miliSeconds, context_-> evBase_ , evQueued_));
412
+ cuEventElapsedTime (&miliSeconds, _pi_platform:: evBase_, evQueued_));
413
413
return static_cast <pi_uint64>(miliSeconds * 1.0e6 );
414
414
}
415
415
416
416
pi_uint64 _pi_event::get_start_time () const {
417
417
float miliSeconds = 0 .0f ;
418
418
assert (is_started ());
419
419
420
- PI_CHECK_ERROR (cuEventElapsedTime (&miliSeconds, context_->evBase_ , evStart_));
420
+ PI_CHECK_ERROR (
421
+ cuEventElapsedTime (&miliSeconds, _pi_platform::evBase_, evStart_));
421
422
return static_cast <pi_uint64>(miliSeconds * 1.0e6 );
422
423
}
423
424
424
425
pi_uint64 _pi_event::get_end_time () const {
425
426
float miliSeconds = 0 .0f ;
426
427
assert (is_started () && is_recorded ());
427
428
428
- PI_CHECK_ERROR (cuEventElapsedTime (&miliSeconds, context_->evBase_ , evEnd_));
429
+ PI_CHECK_ERROR (
430
+ cuEventElapsedTime (&miliSeconds, _pi_platform::evBase_, evEnd_));
429
431
return static_cast <pi_uint64>(miliSeconds * 1.0e6 );
430
432
}
431
433
@@ -1881,9 +1883,16 @@ pi_result cuda_piContextCreate(const pi_context_properties *properties,
1881
1883
_pi_context::kind::user_defined, newContext, *devices});
1882
1884
}
1883
1885
1884
- // Use default stream to record base event counter
1885
- PI_CHECK_ERROR (cuEventCreate (&piContextPtr->evBase_ , CU_EVENT_DEFAULT));
1886
- PI_CHECK_ERROR (cuEventRecord (piContextPtr->evBase_ , 0 ));
1886
+ static std::once_flag initFlag;
1887
+ std::call_once (
1888
+ initFlag,
1889
+ [](pi_result &err) {
1890
+ // Use default stream to record base event counter
1891
+ PI_CHECK_ERROR (
1892
+ cuEventCreate (&_pi_platform::evBase_, CU_EVENT_DEFAULT));
1893
+ PI_CHECK_ERROR (cuEventRecord (_pi_platform::evBase_, 0 ));
1894
+ },
1895
+ errcode_ret);
1887
1896
1888
1897
// For non-primary scoped contexts keep the last active on top of the stack
1889
1898
// as `cuCtxCreate` replaces it implicitly otherwise.
@@ -1913,8 +1922,6 @@ pi_result cuda_piContextRelease(pi_context ctxt) {
1913
1922
1914
1923
std::unique_ptr<_pi_context> context{ctxt};
1915
1924
1916
- PI_CHECK_ERROR (cuEventDestroy (context->evBase_ ));
1917
-
1918
1925
if (!ctxt->is_primary ()) {
1919
1926
CUcontext cuCtxt = ctxt->get ();
1920
1927
CUcontext current = nullptr ;
@@ -5137,3 +5144,5 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
5137
5144
}
5138
5145
5139
5146
} // extern "C"
5147
+
5148
+ CUevent _pi_platform::evBase_{nullptr };
0 commit comments