Skip to content

Commit 9dbc325

Browse files
committed
change resetRefCount to have a param and a default value so l0 adapter can start ref count from 0
1 parent c4b1608 commit 9dbc325

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

unified-runtime/source/adapters/level_zero/adapter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
301301
ZeInitResult = ZE_RESULT_ERROR_UNINITIALIZED;
302302
ZesResult = ZE_RESULT_ERROR_UNINITIALIZED;
303303

304+
resetRefCount(0);
305+
304306
#ifdef UR_STATIC_LEVEL_ZERO
305307
// Given static linking of the L0 Loader, we must delay the loader's
306308
// destruction of its context until after the UR Adapter is destroyed.
@@ -667,15 +669,15 @@ ur_result_t urAdapterGet(
667669
uint32_t *NumAdapters) {
668670
if (NumEntries > 0 && Adapters) {
669671
if (GlobalAdapter) {
670-
if (GlobalAdapter->incrementRefCount() == 1) {
672+
if (GlobalAdapter->incrementRefCount() == 0) {
671673
adapterStateInit();
672674
}
673675
} else {
674676
// If the GetAdapter is called after the Library began or was torndown,
675677
// then temporarily create a new Adapter handle and register a new
676678
// cleanup.
677679
GlobalAdapter = new ur_adapter_handle_t_();
678-
if (GlobalAdapter->incrementRefCount() == 1) {
680+
if (GlobalAdapter->incrementRefCount() == 0) {
679681
adapterStateInit();
680682
}
681683
std::atexit(globalAdapterOnDemandCleanup);
@@ -693,7 +695,7 @@ ur_result_t urAdapterGet(
693695
ur_result_t urAdapterRelease(ur_adapter_handle_t) {
694696
// Check first if the Adapter pointer is valid
695697
if (GlobalAdapter) {
696-
if (GlobalAdapter->decrementRefCount() == 0) {
698+
if (GlobalAdapter->decrementAndTest()) {
697699
auto result = adapterStateTeardown();
698700
#ifdef UR_STATIC_LEVEL_ZERO
699701
// Given static linking of the L0 Loader, we must delay the loader's

unified-runtime/source/ur/ur.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ template <typename getddi> struct handle_base {
237237
uint32_t incrementRefCount() { return ++Count; }
238238
uint32_t decrementRefCount() { return --Count; }
239239
bool decrementAndTest() { return --Count == 0; }
240-
void resetRefCount() { Count = 1; }
240+
void resetRefCount(uint32_t value = 1) { Count = value; }
241241

242242
private:
243243
std::atomic_uint32_t Count{1};

0 commit comments

Comments
 (0)