From 88ce0a280e08ce3f90afc2cbacabc309d47b1cfb Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Fri, 27 Jun 2025 17:11:21 +0100 Subject: [PATCH 1/2] Refactor UR reference counting with new common RefCount class, specifically for Native CPU adapter. --- .../source/adapters/native_cpu/adapter.cpp | 15 ++++++++++----- .../source/adapters/native_cpu/common.hpp | 13 ++----------- .../source/adapters/native_cpu/context.cpp | 4 ++-- .../source/adapters/native_cpu/context.hpp | 6 +++++- .../source/adapters/native_cpu/event.cpp | 4 ++-- .../source/adapters/native_cpu/event.hpp | 12 +++++++++--- .../source/adapters/native_cpu/kernel.cpp | 4 ++-- .../source/adapters/native_cpu/kernel.hpp | 13 +++++++++---- .../source/adapters/native_cpu/memory.hpp | 4 ++++ .../source/adapters/native_cpu/program.cpp | 4 ++-- .../source/adapters/native_cpu/program.hpp | 16 ++++++++++------ .../source/adapters/native_cpu/queue.cpp | 4 ++-- .../source/adapters/native_cpu/queue.hpp | 12 +++++++++--- 13 files changed, 68 insertions(+), 43 deletions(-) diff --git a/unified-runtime/source/adapters/native_cpu/adapter.cpp b/unified-runtime/source/adapters/native_cpu/adapter.cpp index 3fd6d4256825b..91b8c9976be61 100644 --- a/unified-runtime/source/adapters/native_cpu/adapter.cpp +++ b/unified-runtime/source/adapters/native_cpu/adapter.cpp @@ -10,17 +10,22 @@ #include "adapter.hpp" #include "common.hpp" +#include "common/ur_ref_count.hpp" #include "ur_api.h" struct ur_adapter_handle_t_ : ur::native_cpu::handle_base { - std::atomic RefCount = 0; logger::Logger &logger = logger::get_logger("native_cpu"); + + ur::RefCount &getRefCount() noexcept { return RefCount; } + +private: + ur::RefCount RefCount; } Adapter; UR_APIEXPORT ur_result_t UR_APICALL urAdapterGet( uint32_t, ur_adapter_handle_t *phAdapters, uint32_t *pNumAdapters) { if (phAdapters) { - Adapter.RefCount++; + Adapter.getRefCount().retain(); *phAdapters = &Adapter; } if (pNumAdapters) { @@ -30,12 +35,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGet( } UR_APIEXPORT ur_result_t UR_APICALL urAdapterRelease(ur_adapter_handle_t) { - Adapter.RefCount--; + Adapter.getRefCount().release(); return UR_RESULT_SUCCESS; } UR_APIEXPORT ur_result_t UR_APICALL urAdapterRetain(ur_adapter_handle_t) { - Adapter.RefCount++; + Adapter.getRefCount().retain(); return UR_RESULT_SUCCESS; } @@ -57,7 +62,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t, case UR_ADAPTER_INFO_BACKEND: return ReturnValue(UR_BACKEND_NATIVE_CPU); case UR_ADAPTER_INFO_REFERENCE_COUNT: - return ReturnValue(Adapter.RefCount.load()); + return ReturnValue(Adapter.getRefCount().getCount()); case UR_ADAPTER_INFO_VERSION: return ReturnValue(uint32_t{1}); default: diff --git a/unified-runtime/source/adapters/native_cpu/common.hpp b/unified-runtime/source/adapters/native_cpu/common.hpp index e768a4b2ac7f4..7ca8964d514a8 100644 --- a/unified-runtime/source/adapters/native_cpu/common.hpp +++ b/unified-runtime/source/adapters/native_cpu/common.hpp @@ -44,22 +44,13 @@ struct ddi_getter { using handle_base = ur::handle_base; } // namespace ur::native_cpu -// Todo: replace this with a common helper once it is available -struct RefCounted : ur::native_cpu::handle_base { - std::atomic_uint32_t _refCount; - uint32_t incrementReferenceCount() { return ++_refCount; } - uint32_t decrementReferenceCount() { return --_refCount; } - RefCounted() : handle_base(), _refCount{1} {} - uint32_t getReferenceCount() const { return _refCount; } -}; - // Base class to store common data -struct ur_object : RefCounted { +struct ur_object { ur_shared_mutex Mutex; }; template inline void decrementOrDelete(T *refC) { - if (refC->decrementReferenceCount() == 0) + if (refC->getRefCount().release() == 0) delete refC; } diff --git a/unified-runtime/source/adapters/native_cpu/context.cpp b/unified-runtime/source/adapters/native_cpu/context.cpp index 5b7e8fc839884..38cb4efe0c45e 100644 --- a/unified-runtime/source/adapters/native_cpu/context.cpp +++ b/unified-runtime/source/adapters/native_cpu/context.cpp @@ -30,7 +30,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextCreate( UR_APIEXPORT ur_result_t UR_APICALL urContextRetain(ur_context_handle_t hContext) { - hContext->incrementReferenceCount(); + hContext->getRefCount().retain(); return UR_RESULT_SUCCESS; } @@ -51,7 +51,7 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName, case UR_CONTEXT_INFO_DEVICES: return returnValue(hContext->_device); case UR_CONTEXT_INFO_REFERENCE_COUNT: - return returnValue(uint32_t{hContext->getReferenceCount()}); + return returnValue(uint32_t{hContext->getRefCount().getCount()}); case UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT: return returnValue(true); case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT: diff --git a/unified-runtime/source/adapters/native_cpu/context.hpp b/unified-runtime/source/adapters/native_cpu/context.hpp index b9d2d22dd1565..7acdffefc8dc8 100644 --- a/unified-runtime/source/adapters/native_cpu/context.hpp +++ b/unified-runtime/source/adapters/native_cpu/context.hpp @@ -15,6 +15,7 @@ #include #include "common.hpp" +#include "common/ur_ref_count.hpp" #include "device.hpp" #include "ur/ur.hpp" @@ -83,7 +84,7 @@ static usm_alloc_info get_alloc_info(void *ptr) { } // namespace native_cpu -struct ur_context_handle_t_ : RefCounted { +struct ur_context_handle_t_ { ur_context_handle_t_(ur_device_handle_t_ *phDevices) : _device{phDevices} {} ur_device_handle_t _device; @@ -135,7 +136,10 @@ struct ur_context_handle_t_ : RefCounted { return ptr; } + ur::RefCount &getRefCount() noexcept { return RefCount; } + private: std::mutex alloc_mutex; std::set allocations; + ur::RefCount RefCount; }; diff --git a/unified-runtime/source/adapters/native_cpu/event.cpp b/unified-runtime/source/adapters/native_cpu/event.cpp index 91b8fb302eb18..836404d4e30ff 100644 --- a/unified-runtime/source/adapters/native_cpu/event.cpp +++ b/unified-runtime/source/adapters/native_cpu/event.cpp @@ -28,7 +28,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent, case UR_EVENT_INFO_COMMAND_TYPE: return ReturnValue(hEvent->getCommandType()); case UR_EVENT_INFO_REFERENCE_COUNT: - return ReturnValue(hEvent->getReferenceCount()); + return ReturnValue(hEvent->getRefCount().getCount()); case UR_EVENT_INFO_COMMAND_EXECUTION_STATUS: return ReturnValue(hEvent->getExecutionStatus()); case UR_EVENT_INFO_CONTEXT: @@ -69,7 +69,7 @@ urEventWait(uint32_t numEvents, const ur_event_handle_t *phEventWaitList) { } UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) { - hEvent->incrementReferenceCount(); + hEvent->getRefCount().retain(); return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/adapters/native_cpu/event.hpp b/unified-runtime/source/adapters/native_cpu/event.hpp index 479c671b38cd1..d5587ec5543a4 100644 --- a/unified-runtime/source/adapters/native_cpu/event.hpp +++ b/unified-runtime/source/adapters/native_cpu/event.hpp @@ -8,14 +8,17 @@ // //===----------------------------------------------------------------------===// #pragma once -#include "common.hpp" -#include "ur_api.h" + #include #include #include #include -struct ur_event_handle_t_ : RefCounted { +#include "common.hpp" +#include "common/ur_ref_count.hpp" +#include "ur_api.h" + +struct ur_event_handle_t_ { ur_event_handle_t_(ur_queue_handle_t queue, ur_command_t command_type); @@ -55,6 +58,8 @@ struct ur_event_handle_t_ : RefCounted { uint64_t get_end_timestamp() const { return timestamp_end; } + ur::RefCount &getRefCount() noexcept { return RefCount; } + private: ur_queue_handle_t queue; ur_context_handle_t context; @@ -65,4 +70,5 @@ struct ur_event_handle_t_ : RefCounted { std::packaged_task callback; uint64_t timestamp_start = 0; uint64_t timestamp_end = 0; + ur::RefCount RefCount; }; diff --git a/unified-runtime/source/adapters/native_cpu/kernel.cpp b/unified-runtime/source/adapters/native_cpu/kernel.cpp index ac11331357f39..d8742f52cfb67 100644 --- a/unified-runtime/source/adapters/native_cpu/kernel.cpp +++ b/unified-runtime/source/adapters/native_cpu/kernel.cpp @@ -95,7 +95,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel, case UR_KERNEL_INFO_FUNCTION_NAME: return ReturnValue(hKernel->_name.c_str()); case UR_KERNEL_INFO_REFERENCE_COUNT: - return ReturnValue(uint32_t{hKernel->getReferenceCount()}); + return ReturnValue(uint32_t{hKernel->getRefCount().getCount()}); case UR_KERNEL_INFO_ATTRIBUTES: return ReturnValue(""); case UR_KERNEL_INFO_SPILL_MEM_SIZE: @@ -194,7 +194,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetSubGroupInfo( } UR_APIEXPORT ur_result_t UR_APICALL urKernelRetain(ur_kernel_handle_t hKernel) { - hKernel->incrementReferenceCount(); + hKernel->getRefCount().retain(); return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/adapters/native_cpu/kernel.hpp b/unified-runtime/source/adapters/native_cpu/kernel.hpp index 8daf23feb65f5..32d4f7edd46a3 100644 --- a/unified-runtime/source/adapters/native_cpu/kernel.hpp +++ b/unified-runtime/source/adapters/native_cpu/kernel.hpp @@ -8,13 +8,15 @@ #pragma once +#include +#include + #include "common.hpp" +#include "common/ur_ref_count.hpp" #include "memory.hpp" #include "nativecpu_state.hpp" #include "program.hpp" -#include #include -#include using nativecpu_kernel_t = void(void *const *, native_cpu::state *); using nativecpu_ptr_t = nativecpu_kernel_t *; @@ -27,7 +29,7 @@ struct local_arg_info_t { : argIndex(argIndex), argSize(argSize) {} }; -struct ur_kernel_handle_t_ : RefCounted { +struct ur_kernel_handle_t_ { ur_kernel_handle_t_(ur_program_handle_t hProgram, const char *name, nativecpu_task_t subhandler) @@ -188,10 +190,12 @@ struct ur_kernel_handle_t_ : RefCounted { void addPtrArg(void *Ptr, size_t Index) { Args.addPtrArg(Index, Ptr); } void addArgReference(ur_mem_handle_t Arg) { - Arg->incrementReferenceCount(); + Arg->getRefCount().getCount(); ReferencedArgs.push_back(Arg); } + ur::RefCount &getRefCount() noexcept { return RefCount; } + private: void removeArgReferences() { for (auto arg : ReferencedArgs) @@ -209,4 +213,5 @@ struct ur_kernel_handle_t_ : RefCounted { std::optional MaxWGSize = std::nullopt; std::optional MaxLinearWGSize = std::nullopt; std::vector ReferencedArgs; + ur::RefCount RefCount; }; diff --git a/unified-runtime/source/adapters/native_cpu/memory.hpp b/unified-runtime/source/adapters/native_cpu/memory.hpp index ca6e3e77f5e87..2e3c2d5531ea0 100644 --- a/unified-runtime/source/adapters/native_cpu/memory.hpp +++ b/unified-runtime/source/adapters/native_cpu/memory.hpp @@ -15,6 +15,7 @@ #include #include "common.hpp" +#include "common/ur_ref_count.hpp" #include "context.hpp" struct ur_mem_handle_t_ : ur_object { @@ -43,8 +44,11 @@ struct ur_mem_handle_t_ : ur_object { char *_mem; bool _ownsMem; + ur::RefCount &getRefCount() noexcept { return RefCount; } + private: const bool IsImage; + ur::RefCount RefCount; }; struct ur_buffer final : ur_mem_handle_t_ { diff --git a/unified-runtime/source/adapters/native_cpu/program.cpp b/unified-runtime/source/adapters/native_cpu/program.cpp index fee72f8a6bc3c..666d74a5e7132 100644 --- a/unified-runtime/source/adapters/native_cpu/program.cpp +++ b/unified-runtime/source/adapters/native_cpu/program.cpp @@ -171,7 +171,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp( UR_APIEXPORT ur_result_t UR_APICALL urProgramRetain(ur_program_handle_t hProgram) { - hProgram->incrementReferenceCount(); + hProgram->getRefCount().retain(); return UR_RESULT_SUCCESS; } @@ -205,7 +205,7 @@ urProgramGetInfo(ur_program_handle_t hProgram, ur_program_info_t propName, switch (propName) { case UR_PROGRAM_INFO_REFERENCE_COUNT: - return returnValue(hProgram->getReferenceCount()); + return returnValue(hProgram->getRefCount().getCount()); case UR_PROGRAM_INFO_CONTEXT: return returnValue(nullptr); case UR_PROGRAM_INFO_NUM_DEVICES: diff --git a/unified-runtime/source/adapters/native_cpu/program.hpp b/unified-runtime/source/adapters/native_cpu/program.hpp index d58412751e8f2..9e51f68b362c4 100644 --- a/unified-runtime/source/adapters/native_cpu/program.hpp +++ b/unified-runtime/source/adapters/native_cpu/program.hpp @@ -10,23 +10,22 @@ #pragma once +#include +#include + #include +#include "common/ur_ref_count.hpp" #include "context.hpp" -#include -#include - namespace native_cpu { using WGSize_t = std::array; } -struct ur_program_handle_t_ : RefCounted { +struct ur_program_handle_t_ { ur_program_handle_t_(ur_context_handle_t ctx, const unsigned char *pBinary) : _ctx{ctx}, _ptr{pBinary} {} - uint32_t getReferenceCount() const noexcept { return _refCount; } - ur_context_handle_t _ctx; const unsigned char *_ptr; struct _compare { @@ -41,6 +40,11 @@ struct ur_program_handle_t_ : RefCounted { std::unordered_map KernelMaxWorkGroupSizeMD; std::unordered_map KernelMaxLinearWorkGroupSizeMD; + + ur::RefCount &getRefCount() noexcept { return RefCount; } + +private: + ur::RefCount RefCount; }; // The nativecpu_entry struct is also defined as LLVM-IR in the diff --git a/unified-runtime/source/adapters/native_cpu/queue.cpp b/unified-runtime/source/adapters/native_cpu/queue.cpp index 5de7037519490..0bfaf83ee8afe 100644 --- a/unified-runtime/source/adapters/native_cpu/queue.cpp +++ b/unified-runtime/source/adapters/native_cpu/queue.cpp @@ -28,7 +28,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueGetInfo(ur_queue_handle_t hQueue, case UR_QUEUE_INFO_DEVICE: return ReturnValue(hQueue->getDevice()); case UR_QUEUE_INFO_REFERENCE_COUNT: - return ReturnValue(hQueue->getReferenceCount()); + return ReturnValue(hQueue->getRefCount().getCount()); case UR_QUEUE_INFO_EMPTY: return ReturnValue(hQueue->isEmpty()); default: @@ -48,7 +48,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate( } UR_APIEXPORT ur_result_t UR_APICALL urQueueRetain(ur_queue_handle_t hQueue) { - hQueue->incrementReferenceCount(); + hQueue->getRefCount().retain(); return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/adapters/native_cpu/queue.hpp b/unified-runtime/source/adapters/native_cpu/queue.hpp index 9fd28c3e7ff00..da831708fbcab 100644 --- a/unified-runtime/source/adapters/native_cpu/queue.hpp +++ b/unified-runtime/source/adapters/native_cpu/queue.hpp @@ -8,12 +8,15 @@ // //===----------------------------------------------------------------------===// #pragma once + +#include + #include "common.hpp" +#include "common/ur_ref_count.hpp" #include "event.hpp" #include "ur_api.h" -#include -struct ur_queue_handle_t_ : RefCounted { +struct ur_queue_handle_t_ { ur_queue_handle_t_(ur_device_handle_t device, ur_context_handle_t context, const ur_queue_properties_t *pProps) : device(device), context(context), @@ -43,7 +46,7 @@ struct ur_queue_handle_t_ : RefCounted { auto ev = *events.begin(); // ur_event_handle_t_::wait removes itself from the events set in the // queue. - ev->incrementReferenceCount(); + ev->getRefCount().retain(); // Unlocking mutex for removeEvent and for event callbacks that may need // to acquire it. lock.unlock(); @@ -64,6 +67,8 @@ struct ur_queue_handle_t_ : RefCounted { return events.size() == 0; } + ur::RefCount &getRefCount() noexcept { return RefCount; } + private: ur_device_handle_t device; ur_context_handle_t context; @@ -71,4 +76,5 @@ struct ur_queue_handle_t_ : RefCounted { const bool inOrder; const bool profilingEnabled; std::mutex mutex; + ur::RefCount RefCount; }; From 7b7cf5a65d7115d2638e3d46279025a8ede32c46 Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Wed, 2 Jul 2025 10:17:57 +0100 Subject: [PATCH 2/2] make RefCount public and remove getRefCount(). --- .../source/adapters/native_cpu/adapter.cpp | 12 ++++-------- .../source/adapters/native_cpu/common.hpp | 2 +- .../source/adapters/native_cpu/context.cpp | 4 ++-- .../source/adapters/native_cpu/context.hpp | 3 +-- unified-runtime/source/adapters/native_cpu/event.cpp | 4 ++-- unified-runtime/source/adapters/native_cpu/event.hpp | 3 +-- .../source/adapters/native_cpu/kernel.cpp | 4 ++-- .../source/adapters/native_cpu/kernel.hpp | 5 ++--- .../source/adapters/native_cpu/memory.hpp | 3 +-- .../source/adapters/native_cpu/program.cpp | 4 ++-- .../source/adapters/native_cpu/program.hpp | 3 --- unified-runtime/source/adapters/native_cpu/queue.cpp | 4 ++-- unified-runtime/source/adapters/native_cpu/queue.hpp | 5 ++--- 13 files changed, 22 insertions(+), 34 deletions(-) diff --git a/unified-runtime/source/adapters/native_cpu/adapter.cpp b/unified-runtime/source/adapters/native_cpu/adapter.cpp index 91b8c9976be61..19333ddc10654 100644 --- a/unified-runtime/source/adapters/native_cpu/adapter.cpp +++ b/unified-runtime/source/adapters/native_cpu/adapter.cpp @@ -15,17 +15,13 @@ struct ur_adapter_handle_t_ : ur::native_cpu::handle_base { logger::Logger &logger = logger::get_logger("native_cpu"); - - ur::RefCount &getRefCount() noexcept { return RefCount; } - -private: ur::RefCount RefCount; } Adapter; UR_APIEXPORT ur_result_t UR_APICALL urAdapterGet( uint32_t, ur_adapter_handle_t *phAdapters, uint32_t *pNumAdapters) { if (phAdapters) { - Adapter.getRefCount().retain(); + Adapter.RefCount.retain(); *phAdapters = &Adapter; } if (pNumAdapters) { @@ -35,12 +31,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGet( } UR_APIEXPORT ur_result_t UR_APICALL urAdapterRelease(ur_adapter_handle_t) { - Adapter.getRefCount().release(); + Adapter.RefCount.release(); return UR_RESULT_SUCCESS; } UR_APIEXPORT ur_result_t UR_APICALL urAdapterRetain(ur_adapter_handle_t) { - Adapter.getRefCount().retain(); + Adapter.RefCount.retain(); return UR_RESULT_SUCCESS; } @@ -62,7 +58,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t, case UR_ADAPTER_INFO_BACKEND: return ReturnValue(UR_BACKEND_NATIVE_CPU); case UR_ADAPTER_INFO_REFERENCE_COUNT: - return ReturnValue(Adapter.getRefCount().getCount()); + return ReturnValue(Adapter.RefCount.getCount()); case UR_ADAPTER_INFO_VERSION: return ReturnValue(uint32_t{1}); default: diff --git a/unified-runtime/source/adapters/native_cpu/common.hpp b/unified-runtime/source/adapters/native_cpu/common.hpp index 7ca8964d514a8..d54b315664083 100644 --- a/unified-runtime/source/adapters/native_cpu/common.hpp +++ b/unified-runtime/source/adapters/native_cpu/common.hpp @@ -50,7 +50,7 @@ struct ur_object { }; template inline void decrementOrDelete(T *refC) { - if (refC->getRefCount().release() == 0) + if (refC->RefCount.release() == 0) delete refC; } diff --git a/unified-runtime/source/adapters/native_cpu/context.cpp b/unified-runtime/source/adapters/native_cpu/context.cpp index 38cb4efe0c45e..ee5ad0d926e91 100644 --- a/unified-runtime/source/adapters/native_cpu/context.cpp +++ b/unified-runtime/source/adapters/native_cpu/context.cpp @@ -30,7 +30,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextCreate( UR_APIEXPORT ur_result_t UR_APICALL urContextRetain(ur_context_handle_t hContext) { - hContext->getRefCount().retain(); + hContext->RefCount.retain(); return UR_RESULT_SUCCESS; } @@ -51,7 +51,7 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName, case UR_CONTEXT_INFO_DEVICES: return returnValue(hContext->_device); case UR_CONTEXT_INFO_REFERENCE_COUNT: - return returnValue(uint32_t{hContext->getRefCount().getCount()}); + return returnValue(uint32_t{hContext->RefCount.getCount()}); case UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT: return returnValue(true); case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT: diff --git a/unified-runtime/source/adapters/native_cpu/context.hpp b/unified-runtime/source/adapters/native_cpu/context.hpp index 7acdffefc8dc8..5c775a9234c86 100644 --- a/unified-runtime/source/adapters/native_cpu/context.hpp +++ b/unified-runtime/source/adapters/native_cpu/context.hpp @@ -136,10 +136,9 @@ struct ur_context_handle_t_ { return ptr; } - ur::RefCount &getRefCount() noexcept { return RefCount; } + ur::RefCount RefCount; private: std::mutex alloc_mutex; std::set allocations; - ur::RefCount RefCount; }; diff --git a/unified-runtime/source/adapters/native_cpu/event.cpp b/unified-runtime/source/adapters/native_cpu/event.cpp index 836404d4e30ff..87897fe66ad5e 100644 --- a/unified-runtime/source/adapters/native_cpu/event.cpp +++ b/unified-runtime/source/adapters/native_cpu/event.cpp @@ -28,7 +28,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent, case UR_EVENT_INFO_COMMAND_TYPE: return ReturnValue(hEvent->getCommandType()); case UR_EVENT_INFO_REFERENCE_COUNT: - return ReturnValue(hEvent->getRefCount().getCount()); + return ReturnValue(hEvent->RefCount.getCount()); case UR_EVENT_INFO_COMMAND_EXECUTION_STATUS: return ReturnValue(hEvent->getExecutionStatus()); case UR_EVENT_INFO_CONTEXT: @@ -69,7 +69,7 @@ urEventWait(uint32_t numEvents, const ur_event_handle_t *phEventWaitList) { } UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) { - hEvent->getRefCount().retain(); + hEvent->RefCount.retain(); return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/adapters/native_cpu/event.hpp b/unified-runtime/source/adapters/native_cpu/event.hpp index d5587ec5543a4..778cd4eef6abe 100644 --- a/unified-runtime/source/adapters/native_cpu/event.hpp +++ b/unified-runtime/source/adapters/native_cpu/event.hpp @@ -58,7 +58,7 @@ struct ur_event_handle_t_ { uint64_t get_end_timestamp() const { return timestamp_end; } - ur::RefCount &getRefCount() noexcept { return RefCount; } + ur::RefCount RefCount; private: ur_queue_handle_t queue; @@ -70,5 +70,4 @@ struct ur_event_handle_t_ { std::packaged_task callback; uint64_t timestamp_start = 0; uint64_t timestamp_end = 0; - ur::RefCount RefCount; }; diff --git a/unified-runtime/source/adapters/native_cpu/kernel.cpp b/unified-runtime/source/adapters/native_cpu/kernel.cpp index d8742f52cfb67..622bbc5cab38d 100644 --- a/unified-runtime/source/adapters/native_cpu/kernel.cpp +++ b/unified-runtime/source/adapters/native_cpu/kernel.cpp @@ -95,7 +95,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel, case UR_KERNEL_INFO_FUNCTION_NAME: return ReturnValue(hKernel->_name.c_str()); case UR_KERNEL_INFO_REFERENCE_COUNT: - return ReturnValue(uint32_t{hKernel->getRefCount().getCount()}); + return ReturnValue(uint32_t{hKernel->RefCount.getCount()}); case UR_KERNEL_INFO_ATTRIBUTES: return ReturnValue(""); case UR_KERNEL_INFO_SPILL_MEM_SIZE: @@ -194,7 +194,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetSubGroupInfo( } UR_APIEXPORT ur_result_t UR_APICALL urKernelRetain(ur_kernel_handle_t hKernel) { - hKernel->getRefCount().retain(); + hKernel->RefCount.retain(); return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/adapters/native_cpu/kernel.hpp b/unified-runtime/source/adapters/native_cpu/kernel.hpp index 32d4f7edd46a3..09a02578ccf36 100644 --- a/unified-runtime/source/adapters/native_cpu/kernel.hpp +++ b/unified-runtime/source/adapters/native_cpu/kernel.hpp @@ -190,11 +190,11 @@ struct ur_kernel_handle_t_ { void addPtrArg(void *Ptr, size_t Index) { Args.addPtrArg(Index, Ptr); } void addArgReference(ur_mem_handle_t Arg) { - Arg->getRefCount().getCount(); + Arg->RefCount.getCount(); ReferencedArgs.push_back(Arg); } - ur::RefCount &getRefCount() noexcept { return RefCount; } + ur::RefCount RefCount; private: void removeArgReferences() { @@ -213,5 +213,4 @@ struct ur_kernel_handle_t_ { std::optional MaxWGSize = std::nullopt; std::optional MaxLinearWGSize = std::nullopt; std::vector ReferencedArgs; - ur::RefCount RefCount; }; diff --git a/unified-runtime/source/adapters/native_cpu/memory.hpp b/unified-runtime/source/adapters/native_cpu/memory.hpp index 2e3c2d5531ea0..1fd2962e4d342 100644 --- a/unified-runtime/source/adapters/native_cpu/memory.hpp +++ b/unified-runtime/source/adapters/native_cpu/memory.hpp @@ -44,11 +44,10 @@ struct ur_mem_handle_t_ : ur_object { char *_mem; bool _ownsMem; - ur::RefCount &getRefCount() noexcept { return RefCount; } + ur::RefCount RefCount; private: const bool IsImage; - ur::RefCount RefCount; }; struct ur_buffer final : ur_mem_handle_t_ { diff --git a/unified-runtime/source/adapters/native_cpu/program.cpp b/unified-runtime/source/adapters/native_cpu/program.cpp index 666d74a5e7132..d408588ecbfc5 100644 --- a/unified-runtime/source/adapters/native_cpu/program.cpp +++ b/unified-runtime/source/adapters/native_cpu/program.cpp @@ -171,7 +171,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp( UR_APIEXPORT ur_result_t UR_APICALL urProgramRetain(ur_program_handle_t hProgram) { - hProgram->getRefCount().retain(); + hProgram->RefCount.retain(); return UR_RESULT_SUCCESS; } @@ -205,7 +205,7 @@ urProgramGetInfo(ur_program_handle_t hProgram, ur_program_info_t propName, switch (propName) { case UR_PROGRAM_INFO_REFERENCE_COUNT: - return returnValue(hProgram->getRefCount().getCount()); + return returnValue(hProgram->RefCount.getCount()); case UR_PROGRAM_INFO_CONTEXT: return returnValue(nullptr); case UR_PROGRAM_INFO_NUM_DEVICES: diff --git a/unified-runtime/source/adapters/native_cpu/program.hpp b/unified-runtime/source/adapters/native_cpu/program.hpp index 9e51f68b362c4..82d7a7ea4ec35 100644 --- a/unified-runtime/source/adapters/native_cpu/program.hpp +++ b/unified-runtime/source/adapters/native_cpu/program.hpp @@ -41,9 +41,6 @@ struct ur_program_handle_t_ { KernelMaxWorkGroupSizeMD; std::unordered_map KernelMaxLinearWorkGroupSizeMD; - ur::RefCount &getRefCount() noexcept { return RefCount; } - -private: ur::RefCount RefCount; }; diff --git a/unified-runtime/source/adapters/native_cpu/queue.cpp b/unified-runtime/source/adapters/native_cpu/queue.cpp index 0bfaf83ee8afe..31732763687ef 100644 --- a/unified-runtime/source/adapters/native_cpu/queue.cpp +++ b/unified-runtime/source/adapters/native_cpu/queue.cpp @@ -28,7 +28,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueGetInfo(ur_queue_handle_t hQueue, case UR_QUEUE_INFO_DEVICE: return ReturnValue(hQueue->getDevice()); case UR_QUEUE_INFO_REFERENCE_COUNT: - return ReturnValue(hQueue->getRefCount().getCount()); + return ReturnValue(hQueue->RefCount.getCount()); case UR_QUEUE_INFO_EMPTY: return ReturnValue(hQueue->isEmpty()); default: @@ -48,7 +48,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate( } UR_APIEXPORT ur_result_t UR_APICALL urQueueRetain(ur_queue_handle_t hQueue) { - hQueue->getRefCount().retain(); + hQueue->RefCount.retain(); return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/adapters/native_cpu/queue.hpp b/unified-runtime/source/adapters/native_cpu/queue.hpp index da831708fbcab..a7fe86305953f 100644 --- a/unified-runtime/source/adapters/native_cpu/queue.hpp +++ b/unified-runtime/source/adapters/native_cpu/queue.hpp @@ -46,7 +46,7 @@ struct ur_queue_handle_t_ { auto ev = *events.begin(); // ur_event_handle_t_::wait removes itself from the events set in the // queue. - ev->getRefCount().retain(); + ev->RefCount.retain(); // Unlocking mutex for removeEvent and for event callbacks that may need // to acquire it. lock.unlock(); @@ -67,7 +67,7 @@ struct ur_queue_handle_t_ { return events.size() == 0; } - ur::RefCount &getRefCount() noexcept { return RefCount; } + ur::RefCount RefCount; private: ur_device_handle_t device; @@ -76,5 +76,4 @@ struct ur_queue_handle_t_ { const bool inOrder; const bool profilingEnabled; std::mutex mutex; - ur::RefCount RefCount; };