Skip to content

Commit 44b4c09

Browse files
committed
Address pr feedback: rename ref count functions increment -> retain and decrementAndTest -> release, and remove decrement as it doesn't get used.
1 parent 819a1f1 commit 44b4c09

27 files changed

+69
-65
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ ur_result_t urAdapterGet(
675675
}
676676
*Adapters = GlobalAdapter;
677677

678-
if (GlobalAdapter->getRefCount().increment() == 0) {
678+
if (GlobalAdapter->getRefCount().retain() == 0) {
679679
adapterStateInit();
680680
}
681681
}
@@ -692,7 +692,7 @@ ur_result_t urAdapterRelease([[maybe_unused]] ur_adapter_handle_t Adapter) {
692692

693693
// NOTE: This does not require guarding with a mutex; the instant the ref
694694
// count hits zero, both Get and Retain are UB.
695-
if (GlobalAdapter->getRefCount().decrementAndTest()) {
695+
if (GlobalAdapter->getRefCount().release()) {
696696
auto result = adapterStateTeardown();
697697
#ifdef UR_STATIC_LEVEL_ZERO
698698
// Given static linking of the L0 Loader, we must delay the loader's
@@ -711,7 +711,7 @@ ur_result_t urAdapterRelease([[maybe_unused]] ur_adapter_handle_t Adapter) {
711711

712712
ur_result_t urAdapterRetain([[maybe_unused]] ur_adapter_handle_t Adapter) {
713713
assert(GlobalAdapter && GlobalAdapter == Adapter);
714-
GlobalAdapter->getRefCount().increment();
714+
GlobalAdapter->getRefCount().retain();
715715

716716
return UR_RESULT_SUCCESS;
717717
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ ur_result_t urEnqueueUSMFreeExp(
247247
}
248248

249249
size_t size = umfPoolMallocUsableSize(hPool, Mem);
250-
(*Event)->getRefCount().increment();
250+
(*Event)->getRefCount().retain();
251251
usmPool->AsyncPool.insert(Mem, size, *Event, Queue);
252252

253253
// Signal that USM free event was finished

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,13 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
842842

843843
ur_result_t
844844
urCommandBufferRetainExp(ur_exp_command_buffer_handle_t CommandBuffer) {
845-
CommandBuffer->getRefCount().increment();
845+
CommandBuffer->getRefCount().retain();
846846
return UR_RESULT_SUCCESS;
847847
}
848848

849849
ur_result_t
850850
urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t CommandBuffer) {
851-
if (!CommandBuffer->getRefCount().decrementAndTest())
851+
if (!CommandBuffer->getRefCount().release())
852852
return UR_RESULT_SUCCESS;
853853

854854
UR_CALL(waitForOngoingExecution(CommandBuffer));
@@ -1643,7 +1643,7 @@ ur_result_t enqueueImmediateAppendPath(
16431643
if (CommandBuffer->CurrentSubmissionEvent) {
16441644
UR_CALL(urEventReleaseInternal(CommandBuffer->CurrentSubmissionEvent));
16451645
}
1646-
(*Event)->getRefCount().increment();
1646+
(*Event)->getRefCount().retain();
16471647
CommandBuffer->CurrentSubmissionEvent = *Event;
16481648

16491649
UR_CALL(Queue->executeCommandList(CommandListHelper, false, false));
@@ -1726,7 +1726,7 @@ ur_result_t enqueueWaitEventPath(ur_exp_command_buffer_handle_t CommandBuffer,
17261726
if (CommandBuffer->CurrentSubmissionEvent) {
17271727
UR_CALL(urEventReleaseInternal(CommandBuffer->CurrentSubmissionEvent));
17281728
}
1729-
(*Event)->getRefCount().increment();
1729+
(*Event)->getRefCount().retain();
17301730
CommandBuffer->CurrentSubmissionEvent = *Event;
17311731

17321732
UR_CALL(Queue->executeCommandList(SignalCommandList, false /*IsBlocking*/,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ur_result_t urContextRetain(
6161

6262
/// [in] handle of the context to get a reference of.
6363
ur_context_handle_t Context) {
64-
Context->getRefCount().increment();
64+
Context->getRefCount().retain();
6565
return UR_RESULT_SUCCESS;
6666
}
6767

@@ -251,7 +251,7 @@ ur_device_handle_t ur_context_handle_t_::getRootDevice() const {
251251
// from the list of tracked contexts.
252252
ur_result_t ContextReleaseHelper(ur_context_handle_t Context) {
253253

254-
if (!Context->getRefCount().decrementAndTest())
254+
if (!Context->getRefCount().release())
255255
return UR_RESULT_SUCCESS;
256256

257257
if (IndirectAccessTrackingEnabled) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,15 +1666,15 @@ ur_result_t urDeviceGetGlobalTimestamps(
16661666
ur_result_t urDeviceRetain(ur_device_handle_t Device) {
16671667
// The root-device ref-count remains unchanged (always 1).
16681668
if (Device->isSubDevice()) {
1669-
Device->getRefCount().increment();
1669+
Device->getRefCount().retain();
16701670
}
16711671
return UR_RESULT_SUCCESS;
16721672
}
16731673

16741674
ur_result_t urDeviceRelease(ur_device_handle_t Device) {
16751675
// Root devices are destroyed during the piTearDown process.
16761676
if (Device->isSubDevice()) {
1677-
if (Device->getRefCount().decrementAndTest()) {
1677+
if (Device->getRefCount().release()) {
16781678
delete Device;
16791679
}
16801680
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ ur_result_t
874874
/// [in] handle of the event object
875875
urEventRetain(/** [in] handle of the event object */ ur_event_handle_t Event) {
876876
Event->RefCountExternal++;
877-
Event->getRefCount().increment();
877+
Event->getRefCount().retain();
878878

879879
return UR_RESULT_SUCCESS;
880880
}
@@ -1088,7 +1088,7 @@ ur_event_handle_t_::~ur_event_handle_t_() {
10881088

10891089
ur_result_t urEventReleaseInternal(ur_event_handle_t Event,
10901090
bool *isEventDeleted) {
1091-
if (!Event->getRefCount().decrementAndTest())
1091+
if (!Event->getRefCount().release())
10921092
return UR_RESULT_SUCCESS;
10931093

10941094
if (Event->OriginAllocEvent) {
@@ -1524,7 +1524,7 @@ ur_result_t ur_ze_event_list_t::createAndRetainUrZeEventList(
15241524
std::shared_lock<ur_shared_mutex> Lock(CurQueue->LastCommandEvent->Mutex);
15251525
this->ZeEventList[0] = CurQueue->LastCommandEvent->ZeEvent;
15261526
this->UrEventList[0] = CurQueue->LastCommandEvent;
1527-
this->UrEventList[0]->getRefCount().increment();
1527+
this->UrEventList[0]->getRefCount().retain();
15281528
TmpListLength = 1;
15291529
} else if (EventListLength > 0) {
15301530
this->ZeEventList = new ze_event_handle_t[EventListLength];
@@ -1660,7 +1660,7 @@ ur_result_t ur_ze_event_list_t::createAndRetainUrZeEventList(
16601660
IsInternal, IsMultiDevice));
16611661
MultiDeviceZeEvent = MultiDeviceEvent->ZeEvent;
16621662
const auto &ZeCommandList = CommandList->first;
1663-
EventList[I]->getRefCount().increment();
1663+
EventList[I]->getRefCount().retain();
16641664

16651665
// Append a Barrier to wait on the original event while signalling the
16661666
// new multi device event.
@@ -1676,11 +1676,11 @@ ur_result_t ur_ze_event_list_t::createAndRetainUrZeEventList(
16761676

16771677
this->ZeEventList[TmpListLength] = MultiDeviceZeEvent;
16781678
this->UrEventList[TmpListLength] = MultiDeviceEvent;
1679-
this->UrEventList[TmpListLength]->getRefCount().increment();
1679+
this->UrEventList[TmpListLength]->getRefCount().retain();
16801680
} else {
16811681
this->ZeEventList[TmpListLength] = EventList[I]->ZeEvent;
16821682
this->UrEventList[TmpListLength] = EventList[I];
1683-
this->UrEventList[TmpListLength]->getRefCount().increment();
1683+
this->UrEventList[TmpListLength]->getRefCount().retain();
16841684
}
16851685

16861686
if (QueueLock.has_value()) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,15 +938,15 @@ ur_result_t urKernelGetSubGroupInfo(
938938
ur_result_t urKernelRetain(
939939
/// [in] handle for the Kernel to retain
940940
ur_kernel_handle_t Kernel) {
941-
Kernel->getRefCount().increment();
941+
Kernel->getRefCount().retain();
942942

943943
return UR_RESULT_SUCCESS;
944944
}
945945

946946
ur_result_t urKernelRelease(
947947
/// [in] handle for the Kernel to release
948948
ur_kernel_handle_t Kernel) {
949-
if (!Kernel->getRefCount().decrementAndTest())
949+
if (!Kernel->getRefCount().release())
950950
return UR_RESULT_SUCCESS;
951951

952952
auto KernelProgram = Kernel->Program;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ ur_result_t urEnqueueMemBufferMap(
10521052

10531053
// Add the event to the command list.
10541054
CommandList->second.append(reinterpret_cast<ur_event_handle_t>(*Event));
1055-
(*Event)->getRefCount().increment();
1055+
(*Event)->getRefCount().retain();
10561056

10571057
const auto &ZeCommandList = CommandList->first;
10581058
const auto &WaitList = (*Event)->WaitList;
@@ -1183,7 +1183,7 @@ ur_result_t urEnqueueMemUnmap(
11831183
nullptr /*ForcedCmdQueue*/));
11841184

11851185
CommandList->second.append(reinterpret_cast<ur_event_handle_t>(*Event));
1186-
(*Event)->getRefCount().increment();
1186+
(*Event)->getRefCount().retain();
11871187

11881188
const auto &ZeCommandList = CommandList->first;
11891189

@@ -1635,14 +1635,14 @@ ur_result_t urMemBufferCreate(
16351635
ur_result_t urMemRetain(
16361636
/// [in] handle of the memory object to get access
16371637
ur_mem_handle_t Mem) {
1638-
Mem->getRefCount().increment();
1638+
Mem->getRefCount().retain();
16391639
return UR_RESULT_SUCCESS;
16401640
}
16411641

16421642
ur_result_t urMemRelease(
16431643
/// [in] handle of the memory object to release
16441644
ur_mem_handle_t Mem) {
1645-
if (!Mem->getRefCount().decrementAndTest())
1645+
if (!Mem->getRefCount().release())
16461646
return UR_RESULT_SUCCESS;
16471647

16481648
if (Mem->isImage()) {

unified-runtime/source/adapters/level_zero/memory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct ur_buffer final : ur_mem_handle_t_ {
122122
: ur_mem_handle_t_(mem_type_t::buffer, Parent->UrContext), Size(Size),
123123
SubBuffer{{Parent, Origin}} {
124124
// Retain the Parent Buffer due to the Creation of the SubBuffer.
125-
Parent->getRefCount().increment();
125+
Parent->getRefCount().retain();
126126
}
127127

128128
// Interop-buffer constructor

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ ur_result_t urPhysicalMemCreate(
4242
}
4343

4444
ur_result_t urPhysicalMemRetain(ur_physical_mem_handle_t hPhysicalMem) {
45-
hPhysicalMem->getRefCount().increment();
45+
hPhysicalMem->getRefCount().retain();
4646
return UR_RESULT_SUCCESS;
4747
}
4848

4949
ur_result_t urPhysicalMemRelease(ur_physical_mem_handle_t hPhysicalMem) {
50-
if (!hPhysicalMem->getRefCount().decrementAndTest())
50+
if (!hPhysicalMem->getRefCount().release())
5151
return UR_RESULT_SUCCESS;
5252

5353
if (checkL0LoaderTeardown()) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,14 @@ ur_result_t urProgramLinkExp(
558558
ur_result_t urProgramRetain(
559559
/// [in] handle for the Program to retain
560560
ur_program_handle_t Program) {
561-
Program->getRefCount().increment();
561+
Program->getRefCount().retain();
562562
return UR_RESULT_SUCCESS;
563563
}
564564

565565
ur_result_t urProgramRelease(
566566
/// [in] handle for the Program to release
567567
ur_program_handle_t Program) {
568-
if (!Program->getRefCount().decrementAndTest())
568+
if (!Program->getRefCount().release())
569569
return UR_RESULT_SUCCESS;
570570

571571
delete Program;
@@ -1115,7 +1115,7 @@ void ur_program_handle_t_::ur_release_program_resources(bool deletion) {
11151115
// must be destroyed before the Module can be destroyed. So, be sure
11161116
// to destroy build log before destroying the module.
11171117
if (!deletion) {
1118-
if (!RefCount.decrementAndTest()) {
1118+
if (!RefCount.release()) {
11191119
return;
11201120
}
11211121
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ ur_result_t urQueueRetain(
593593
std::scoped_lock<ur_shared_mutex> Lock(Queue->Mutex);
594594
Queue->RefCountExternal++;
595595
}
596-
Queue->getRefCount().increment();
596+
Queue->getRefCount().retain();
597597
return UR_RESULT_SUCCESS;
598598
}
599599

@@ -612,7 +612,7 @@ ur_result_t urQueueRelease(
612612
// internal reference count. When the External Reference count == 0, then
613613
// cleanup of the queue begins and the final decrement of the internal
614614
// reference count is completed.
615-
static_cast<void>(Queue->getRefCount().decrementAndTest());
615+
static_cast<void>(Queue->getRefCount().release());
616616
return UR_RESULT_SUCCESS;
617617
}
618618

@@ -1389,7 +1389,7 @@ ur_queue_handle_t_::executeCommandList(ur_command_list_ptr_t CommandList,
13891389
if (!Event->HostVisibleEvent) {
13901390
Event->HostVisibleEvent =
13911391
reinterpret_cast<ur_event_handle_t>(HostVisibleEvent);
1392-
HostVisibleEvent->getRefCount().increment();
1392+
HostVisibleEvent->getRefCount().retain();
13931393
}
13941394
}
13951395

@@ -1550,7 +1550,7 @@ ur_result_t ur_queue_handle_t_::addEventToQueueCache(ur_event_handle_t Event) {
15501550
}
15511551

15521552
void ur_queue_handle_t_::active_barriers::add(ur_event_handle_t &Event) {
1553-
Event->getRefCount().increment();
1553+
Event->getRefCount().retain();
15541554
Events.push_back(Event);
15551555
}
15561556

@@ -1588,7 +1588,7 @@ void ur_queue_handle_t_::clearEndTimeRecordings() {
15881588
}
15891589

15901590
ur_result_t urQueueReleaseInternal(ur_queue_handle_t Queue) {
1591-
if (!Queue->getRefCount().decrementAndTest())
1591+
if (!Queue->getRefCount().release())
15921592
return UR_RESULT_SUCCESS;
15931593

15941594
for (auto &Cache : Queue->EventCaches) {
@@ -1921,15 +1921,15 @@ ur_result_t createEventAndAssociateQueue(ur_queue_handle_t Queue,
19211921
// Append this Event to the CommandList, if any
19221922
if (CommandList != Queue->CommandListMap.end()) {
19231923
CommandList->second.append(*Event);
1924-
(*Event)->getRefCount().increment();
1924+
(*Event)->getRefCount().retain();
19251925
}
19261926

19271927
// We need to increment the reference counter here to avoid ur_queue_handle_t
19281928
// being released before the associated ur_event_handle_t is released because
19291929
// urEventRelease requires access to the associated ur_queue_handle_t.
19301930
// In urEventRelease, the reference counter of the Queue is decremented
19311931
// to release it.
1932-
Queue->getRefCount().increment();
1932+
Queue->getRefCount().retain();
19331933

19341934
// SYCL RT does not track completion of the events, so it could
19351935
// release a PI event as soon as that's not being waited in the app.
@@ -1961,7 +1961,7 @@ void ur_queue_handle_t_::CaptureIndirectAccesses() {
19611961
// SubmissionsCount turns to 0. We don't want to know how many times
19621962
// allocation was retained by each submission.
19631963
if (Pair.second)
1964-
Elem.second.getRefCount().increment();
1964+
Elem.second.getRefCount().retain();
19651965
}
19661966
}
19671967
Kernel->SubmissionsCount++;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ ur_result_t urSamplerCreate(
124124
ur_result_t urSamplerRetain(
125125
/// [in] handle of the sampler object to get access
126126
ur_sampler_handle_t Sampler) {
127-
Sampler->getRefCount().increment();
127+
Sampler->getRefCount().retain();
128128
return UR_RESULT_SUCCESS;
129129
}
130130

131131
ur_result_t urSamplerRelease(
132132
/// [in] handle of the sampler object to release
133133
ur_sampler_handle_t Sampler) {
134-
if (!Sampler->getRefCount().decrementAndTest())
134+
if (!Sampler->getRefCount().release())
135135
return UR_RESULT_SUCCESS;
136136

137137
if (checkL0LoaderTeardown()) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,14 @@ ur_result_t urUSMPoolCreate(
523523
ur_result_t
524524
/// [in] pointer to USM memory pool
525525
urUSMPoolRetain(ur_usm_pool_handle_t Pool) {
526-
Pool->getRefCount().increment();
526+
Pool->getRefCount().retain();
527527
return UR_RESULT_SUCCESS;
528528
}
529529

530530
ur_result_t
531531
/// [in] pointer to USM memory pool
532532
urUSMPoolRelease(ur_usm_pool_handle_t Pool) {
533-
if (Pool->getRefCount().decrementAndTest()) {
533+
if (Pool->getRefCount().release()) {
534534
std::scoped_lock<ur_shared_mutex> ContextLock(Pool->Context->Mutex);
535535
Pool->Context->UsmPoolHandles.remove(Pool);
536536
delete Pool;
@@ -1250,7 +1250,7 @@ ur_result_t ZeMemFreeHelper(ur_context_handle_t Context, void *Ptr) {
12501250
if (It == std::end(Context->MemAllocs)) {
12511251
die("All memory allocations must be tracked!");
12521252
}
1253-
if (!It->second.getRefCount().decrementAndTest()) {
1253+
if (!It->second.getRefCount().release()) {
12541254
// Memory can't be deallocated yet.
12551255
return UR_RESULT_SUCCESS;
12561256
}
@@ -1297,7 +1297,7 @@ ur_result_t USMFreeHelper(ur_context_handle_t Context, void *Ptr,
12971297
if (It == std::end(Context->MemAllocs)) {
12981298
die("All memory allocations must be tracked!");
12991299
}
1300-
if (!It->second.getRefCount().decrementAndTest()) {
1300+
if (!It->second.getRefCount().release()) {
13011301
// Memory can't be deallocated yet.
13021302
return UR_RESULT_SUCCESS;
13031303
}

0 commit comments

Comments
 (0)