Skip to content

Commit 74db66f

Browse files
committed
Address feedback: rename URRefCount to RefCount and put inside ur namespace. Add a constructor for the class with a default value and remove use of reset() inside the Adapter constructor, using the RefCount constructor to set default value instead.
1 parent c2782cb commit 74db66f

22 files changed

+51
-45
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,11 @@ Behavior Summary:
296296
SysMan initialization is skipped.
297297
*/
298298
ur_adapter_handle_t_::ur_adapter_handle_t_()
299-
: handle_base(), logger(logger::get_logger("level_zero")) {
299+
: handle_base(), logger(logger::get_logger("level_zero")), RefCount(0) {
300300
ZeInitDriversResult = ZE_RESULT_ERROR_UNINITIALIZED;
301301
ZeInitResult = ZE_RESULT_ERROR_UNINITIALIZED;
302302
ZesResult = ZE_RESULT_ERROR_UNINITIALIZED;
303303

304-
RefCount.reset(0);
305-
306304
#ifdef UR_STATIC_LEVEL_ZERO
307305
// Given static linking of the L0 Loader, we must delay the loader's
308306
// destruction of its context until after the UR Adapter is destroyed.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ struct ur_adapter_handle_t_ : ur::handle_base<ur::level_zero::ddi_getter> {
4545
logger::Logger &logger;
4646
HMODULE processHandle = nullptr;
4747

48-
URRefCount &getRefCount() noexcept { return RefCount; }
48+
ur::RefCount &getRefCount() noexcept { return RefCount; }
4949

5050
private:
51-
URRefCount RefCount;
51+
ur::RefCount RefCount;
5252
};
5353

5454
extern ur_adapter_handle_t_ *GlobalAdapter;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ struct ur_exp_command_buffer_handle_t_ : public ur_object {
151151
std::vector<std::unique_ptr<ur_exp_command_buffer_command_handle_t_>>
152152
CommandHandles;
153153

154-
URRefCount &getRefCount() noexcept { return RefCount; }
154+
ur::RefCount &getRefCount() noexcept { return RefCount; }
155155

156156
private:
157-
URRefCount RefCount;
157+
ur::RefCount RefCount;
158158
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ struct MemAllocRecord : ur_object {
259259
// Zero runtime.
260260
ur_context_handle_t Context;
261261

262-
URRefCount &getRefCount() noexcept { return RefCount; }
262+
ur::RefCount &getRefCount() noexcept { return RefCount; }
263263

264264
private:
265-
URRefCount RefCount;
265+
ur::RefCount RefCount;
266266
};
267267

268268
extern usm::DisjointPoolAllConfigs DisjointPoolConfigInstance;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ struct ur_context_handle_t_ : ur_object {
359359
// Get handle to the L0 context
360360
ze_context_handle_t getZeHandle() const;
361361

362-
URRefCount &getRefCount() noexcept { return RefCount; }
362+
ur::RefCount &getRefCount() noexcept { return RefCount; }
363363

364364
private:
365365
enum EventFlags {
@@ -408,7 +408,7 @@ struct ur_context_handle_t_ : ur_object {
408408
return &EventCaches[index];
409409
}
410410

411-
URRefCount RefCount;
411+
ur::RefCount RefCount;
412412
};
413413

414414
// Helper function to release the context, a caller must lock the platform-level

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ struct ur_device_handle_t_ : ur_object {
244244
// unique ephemeral identifer of the device in the adapter
245245
std::optional<DeviceId> Id;
246246

247-
URRefCount &getRefCount() noexcept { return RefCount; }
247+
ur::RefCount &getRefCount() noexcept { return RefCount; }
248248

249249
private:
250-
URRefCount RefCount;
250+
ur::RefCount RefCount;
251251
};
252252

253253
inline std::vector<ur_device_handle_t>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,10 @@ struct ur_event_handle_t_ : ur_object {
264264
// on async free to indicate when the allocation can be used again.
265265
ur_event_handle_t OriginAllocEvent = nullptr;
266266

267-
URRefCount &getRefCount() noexcept { return RefCount; }
267+
ur::RefCount &getRefCount() noexcept { return RefCount; }
268268

269269
private:
270-
URRefCount RefCount;
270+
ur::RefCount RefCount;
271271
};
272272

273273
// Helper function to implement zeHostSynchronize.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ struct ur_kernel_handle_t_ : ur_object {
109109
ZeCache<ZeStruct<ze_kernel_properties_t>> ZeKernelProperties;
110110
ZeCache<std::string> ZeKernelName;
111111

112-
URRefCount &getRefCount() noexcept { return RefCount; }
112+
ur::RefCount &getRefCount() noexcept { return RefCount; }
113113

114114
private:
115-
URRefCount RefCount;
115+
ur::RefCount RefCount;
116116
};
117117

118118
ur_result_t getZeKernel(ze_device_handle_t hDevice, ur_kernel_handle_t hKernel,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct ur_mem_handle_t_ : ur_object {
9191
// Method to get type of the derived object (image or buffer)
9292
bool isImage() const { return mem_type == mem_type_t::image; }
9393

94-
URRefCount &getRefCount() noexcept { return RefCount; }
94+
ur::RefCount &getRefCount() noexcept { return RefCount; }
9595

9696
protected:
9797
ur_mem_handle_t_(mem_type_t type, ur_context_handle_t Context)
@@ -106,7 +106,7 @@ struct ur_mem_handle_t_ : ur_object {
106106
~ur_mem_handle_t_() {};
107107

108108
private:
109-
URRefCount RefCount;
109+
ur::RefCount RefCount;
110110
};
111111

112112
struct ur_buffer final : ur_mem_handle_t_ {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ struct ur_physical_mem_handle_t_ : ur_object {
2323
// Keeps the PI context of this memory handle.
2424
ur_context_handle_t Context;
2525

26-
URRefCount &getRefCount() noexcept { return RefCount; }
26+
ur::RefCount &getRefCount() noexcept { return RefCount; }
2727

2828
private:
29-
URRefCount RefCount;
29+
ur::RefCount RefCount;
3030
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ struct ur_program_handle_t_ : ur_object {
227227
// UR_PROGRAM_INFO_BINARY_SIZES.
228228
const std::vector<ur_device_handle_t> AssociatedDevices;
229229

230-
URRefCount &getRefCount() noexcept { return RefCount; }
230+
ur::RefCount &getRefCount() noexcept { return RefCount; }
231231

232232
private:
233233
struct DeviceData {
@@ -268,5 +268,5 @@ struct ur_program_handle_t_ : ur_object {
268268
// TODO: Currently interoparability UR API does not support multiple devices.
269269
ze_module_handle_t InteropZeModule = nullptr;
270270

271-
URRefCount RefCount;
271+
ur::RefCount RefCount;
272272
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,10 @@ struct ur_queue_handle_t_ : ur_object {
694694
// Pointer to the unified handle.
695695
ur_queue_handle_t_ *UnifiedHandle;
696696

697-
URRefCount &getRefCount() noexcept { return RefCount; }
697+
ur::RefCount &getRefCount() noexcept { return RefCount; }
698698

699699
private:
700-
URRefCount RefCount;
700+
ur::RefCount RefCount;
701701
};
702702

703703
// This helper function creates a ur_event_handle_t and associate a

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ struct ur_sampler_handle_t_ : ur_object {
2020

2121
ZeStruct<ze_sampler_desc_t> ZeSamplerDesc;
2222

23-
URRefCount &getRefCount() noexcept { return RefCount; }
23+
ur::RefCount &getRefCount() noexcept { return RefCount; }
2424

2525
private:
26-
URRefCount RefCount;
26+
ur::RefCount RefCount;
2727
};
2828

2929
// Construct ZE sampler desc from UR sampler desc.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ struct ur_usm_pool_handle_t_ : ur_object {
5454

5555
ur_context_handle_t Context;
5656

57-
URRefCount &getRefCount() noexcept { return RefCount; }
57+
ur::RefCount &getRefCount() noexcept { return RefCount; }
5858

5959
private:
6060
UsmPool *getPool(const usm::pool_descriptor &Desc);
6161
usm::pool_manager<usm::pool_descriptor, UsmPool> PoolManager;
6262

63-
URRefCount RefCount;
63+
ur::RefCount RefCount;
6464
};
6565

6666
// Exception type to pass allocation errors

unified-runtime/source/adapters/level_zero/v2/command_buffer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct ur_exp_command_buffer_handle_t_ : public ur_object {
6565
ur_event_handle_t
6666
createEventIfRequested(ur_exp_command_buffer_sync_point_t *retSyncPoint);
6767

68-
URRefCount &getRefCount() noexcept { return RefCount; }
68+
ur::RefCount &getRefCount() noexcept { return RefCount; }
6969

7070
private:
7171
// Stores all sync points that are created by the command buffer.
@@ -91,5 +91,5 @@ struct ur_exp_command_buffer_handle_t_ : public ur_object {
9191

9292
v2::raii::cache_borrowed_event_pool eventPool;
9393

94-
URRefCount RefCount;
94+
ur::RefCount RefCount;
9595
};

unified-runtime/source/adapters/level_zero/v2/context.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct ur_context_handle_t_ : ur_object {
6565
// For that the Device or its root devices need to be in the context.
6666
bool isValidDevice(ur_device_handle_t Device) const;
6767

68-
URRefCount &getRefCount() noexcept { return RefCount; }
68+
ur::RefCount &getRefCount() noexcept { return RefCount; }
6969

7070
private:
7171
const v2::raii::ze_context_handle_t hContext;
@@ -85,5 +85,5 @@ struct ur_context_handle_t_ : ur_object {
8585
ur_usm_pool_handle_t_ asyncPool;
8686
std::list<ur_usm_pool_handle_t> usmPoolHandles;
8787

88-
URRefCount RefCount;
88+
ur::RefCount RefCount;
8989
};

unified-runtime/source/adapters/level_zero/v2/event.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ struct ur_event_handle_t_ : ur_object {
113113
uint64_t getEventStartTimestmap() const;
114114
uint64_t getEventEndTimestamp();
115115

116-
URRefCount &getRefCount() noexcept { return RefCount; }
116+
ur::RefCount &getRefCount() noexcept { return RefCount; }
117117

118118
private:
119119
ur_event_handle_t_(ur_context_handle_t hContext, event_variant hZeEvent,
120120
v2::event_flags_t flags, v2::event_pool *pool);
121121

122-
URRefCount RefCount;
122+
ur::RefCount RefCount;
123123

124124
protected:
125125
ur_context_handle_t hContext;

unified-runtime/source/adapters/level_zero/v2/kernel.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct ur_kernel_handle_t_ : ur_object {
9292
ze_command_list_handle_t cmdList,
9393
wait_list_view &waitListView);
9494

95-
URRefCount &getRefCount() noexcept { return RefCount; }
95+
ur::RefCount &getRefCount() noexcept { return RefCount; }
9696

9797
private:
9898
// Keep the program of the kernel.
@@ -120,5 +120,5 @@ struct ur_kernel_handle_t_ : ur_object {
120120
// pointer to any non-null kernel in deviceKernels
121121
ur_single_device_kernel_t *nonEmptyKernel;
122122

123-
URRefCount RefCount;
123+
ur::RefCount RefCount;
124124
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ struct ur_mem_handle_t_ : ur::handle_base<ur::level_zero::ddi_getter> {
282282

283283
bool isImage() const { return std::holds_alternative<ur_mem_image_t>(mem); }
284284

285-
URRefCount &getRefCount() noexcept { return RefCount; }
285+
ur::RefCount &getRefCount() noexcept { return RefCount; }
286286

287287
private:
288288
template <typename T, typename... Args>
@@ -296,5 +296,5 @@ struct ur_mem_handle_t_ : ur::handle_base<ur::level_zero::ddi_getter> {
296296
mem;
297297

298298
private:
299-
URRefCount RefCount;
299+
ur::RefCount RefCount;
300300
};

unified-runtime/source/adapters/level_zero/v2/queue_immediate_in_order.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct ur_queue_immediate_in_order_t : ur_object, ur_queue_t_ {
3333
lockable<ur_command_list_manager> commandListManager;
3434
ur_queue_flags_t flags;
3535
v2::raii::cache_borrowed_event_pool eventPool;
36-
URRefCount RefCount;
36+
ur::RefCount RefCount;
3737

3838
public:
3939
ur_queue_immediate_in_order_t(ur_context_handle_t, ur_device_handle_t,
@@ -454,7 +454,7 @@ struct ur_queue_immediate_in_order_t : ur_object, ur_queue_t_ {
454454
createEventIfRequested(eventPool.get(), phEvent, this));
455455
}
456456

457-
URRefCount &getRefCount() noexcept { return RefCount; }
457+
ur::RefCount &getRefCount() noexcept { return RefCount; }
458458
};
459459

460460
} // namespace v2

unified-runtime/source/adapters/level_zero/v2/usm.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ struct ur_usm_pool_handle_t_ : ur_object {
5050
void cleanupPools();
5151
void cleanupPoolsForQueue(void *hQueue);
5252

53-
URRefCount &getRefCount() noexcept { return RefCount; }
53+
ur::RefCount &getRefCount() noexcept { return RefCount; }
5454

5555
private:
5656
ur_context_handle_t hContext;
5757
usm::pool_manager<usm::pool_descriptor, UsmPool> poolManager;
5858

5959
UsmPool *getPool(const usm::pool_descriptor &desc);
6060

61-
URRefCount RefCount;
61+
ur::RefCount RefCount;
6262
};

unified-runtime/source/common/ur_ref_count.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,24 @@
1414
#include <atomic>
1515
#include <cstdint>
1616

17-
class URRefCount {
17+
namespace ur {
18+
19+
class RefCount {
1820
public:
21+
RefCount(uint32_t count = 1) : Count(count) {}
22+
RefCount(const RefCount &) = delete;
23+
RefCount &operator=(const RefCount &) = delete;
24+
1925
uint32_t getCount() const noexcept { return Count.load(); }
2026
uint32_t increment() { return ++Count; }
2127
uint32_t decrement() { return --Count; }
2228
bool decrementAndTest() { return --Count == 0; }
2329
void reset(uint32_t value = 1) { Count = value; }
2430

2531
private:
26-
std::atomic_uint32_t Count{1};
32+
std::atomic_uint32_t Count;
2733
};
2834

35+
} // namespace ur
36+
2937
#endif // URREFCOUNT_HPP

0 commit comments

Comments
 (0)