Skip to content

Commit b69b96d

Browse files
ldrummkbenzie
authored andcommitted
[l0][HIP][CUDA] Prefer values over pointers-to
Flags are 32bit here and none of these implementations functions need modify their argument. Passing by reference is opaque, slower, and superfluous in this case, so let's just pass by value.
1 parent ebf873f commit b69b96d

File tree

5 files changed

+44
-47
lines changed

5 files changed

+44
-47
lines changed

source/adapters/cuda/usm.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ urUSMHostAlloc(ur_context_handle_t hContext, const ur_usm_desc_t *pUSMDesc,
3333
UR_RESULT_ERROR_INVALID_VALUE);
3434

3535
if (!hPool) {
36-
return USMHostAllocImpl(ppMem, hContext, nullptr, size, alignment);
36+
return USMHostAllocImpl(ppMem, hContext, /* flags */ 0, size, alignment);
3737
}
3838

3939
auto UMFPool = hPool->HostMemPool.get();
@@ -57,7 +57,7 @@ urUSMDeviceAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
5757
UR_RESULT_ERROR_INVALID_VALUE);
5858

5959
if (!hPool) {
60-
return USMDeviceAllocImpl(ppMem, hContext, hDevice, nullptr, size,
60+
return USMDeviceAllocImpl(ppMem, hContext, hDevice, /* flags */ 0, size,
6161
alignment);
6262
}
6363

@@ -82,8 +82,8 @@ urUSMSharedAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
8282
UR_RESULT_ERROR_INVALID_VALUE);
8383

8484
if (!hPool) {
85-
return USMSharedAllocImpl(ppMem, hContext, hDevice, nullptr, nullptr, size,
86-
alignment);
85+
return USMSharedAllocImpl(ppMem, hContext, hDevice, /*host flags*/ 0,
86+
/*device flags*/ 0, size, alignment);
8787
}
8888

8989
auto UMFPool = hPool->SharedMemPool.get();
@@ -132,7 +132,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMFree(ur_context_handle_t hContext,
132132
}
133133

134134
ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t Context,
135-
ur_device_handle_t, ur_usm_device_mem_flags_t *,
135+
ur_device_handle_t, ur_usm_device_mem_flags_t,
136136
size_t Size, uint32_t Alignment) {
137137
try {
138138
ScopedContext Active(Context);
@@ -151,8 +151,8 @@ ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t Context,
151151
}
152152

153153
ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t Context,
154-
ur_device_handle_t, ur_usm_host_mem_flags_t *,
155-
ur_usm_device_mem_flags_t *, size_t Size,
154+
ur_device_handle_t, ur_usm_host_mem_flags_t,
155+
ur_usm_device_mem_flags_t, size_t Size,
156156
uint32_t Alignment) {
157157
try {
158158
ScopedContext Active(Context);
@@ -172,7 +172,7 @@ ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t Context,
172172
}
173173

174174
ur_result_t USMHostAllocImpl(void **ResultPtr, ur_context_handle_t Context,
175-
ur_usm_host_mem_flags_t *, size_t Size,
175+
ur_usm_host_mem_flags_t, size_t Size,
176176
uint32_t Alignment) {
177177
try {
178178
ScopedContext Active(Context);
@@ -358,19 +358,19 @@ umf_result_t USMMemoryProvider::get_min_page_size(void *Ptr, size_t *PageSize) {
358358

359359
ur_result_t USMSharedMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
360360
uint32_t Alignment) {
361-
return USMSharedAllocImpl(ResultPtr, Context, Device, nullptr, nullptr, Size,
362-
Alignment);
361+
return USMSharedAllocImpl(ResultPtr, Context, Device, /*host flags*/ 0,
362+
/*device flags*/ 0, Size, Alignment);
363363
}
364364

365365
ur_result_t USMDeviceMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
366366
uint32_t Alignment) {
367-
return USMDeviceAllocImpl(ResultPtr, Context, Device, nullptr, Size,
367+
return USMDeviceAllocImpl(ResultPtr, Context, Device, /* flags */ 0, Size,
368368
Alignment);
369369
}
370370

371371
ur_result_t USMHostMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
372372
uint32_t Alignment) {
373-
return USMHostAllocImpl(ResultPtr, Context, nullptr, Size, Alignment);
373+
return USMHostAllocImpl(ResultPtr, Context, /* flags */ 0, Size, Alignment);
374374
}
375375

376376
ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,

source/adapters/cuda/usm.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ class USMHostMemoryProvider final : public USMMemoryProvider {
118118

119119
ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t Context,
120120
ur_device_handle_t Device,
121-
ur_usm_device_mem_flags_t *Flags, size_t Size,
121+
ur_usm_device_mem_flags_t Flags, size_t Size,
122122
uint32_t Alignment);
123123

124124
ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t Context,
125125
ur_device_handle_t Device,
126-
ur_usm_host_mem_flags_t *,
127-
ur_usm_device_mem_flags_t *, size_t Size,
126+
ur_usm_host_mem_flags_t,
127+
ur_usm_device_mem_flags_t, size_t Size,
128128
uint32_t Alignment);
129129

130130
ur_result_t USMHostAllocImpl(void **ResultPtr, ur_context_handle_t Context,
131-
ur_usm_host_mem_flags_t *Flags, size_t Size,
131+
ur_usm_host_mem_flags_t Flags, size_t Size,
132132
uint32_t Alignment);

source/adapters/hip/usm.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ urUSMHostAlloc(ur_context_handle_t hContext, const ur_usm_desc_t *pUSMDesc,
2727
UR_RESULT_ERROR_INVALID_VALUE);
2828

2929
if (!hPool) {
30-
return USMHostAllocImpl(ppMem, hContext, nullptr, size, alignment);
30+
return USMHostAllocImpl(ppMem, hContext, /* flags */ 0, size, alignment);
3131
}
3232

3333
return umfPoolMallocHelper(hPool, ppMem, size, alignment);
@@ -43,7 +43,7 @@ urUSMDeviceAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
4343
UR_RESULT_ERROR_INVALID_VALUE);
4444

4545
if (!hPool) {
46-
return USMDeviceAllocImpl(ppMem, hContext, hDevice, nullptr, size,
46+
return USMDeviceAllocImpl(ppMem, hContext, hDevice, /* flags */ 0, size,
4747
alignment);
4848
}
4949

@@ -60,8 +60,8 @@ urUSMSharedAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
6060
UR_RESULT_ERROR_INVALID_VALUE);
6161

6262
if (!hPool) {
63-
return USMSharedAllocImpl(ppMem, hContext, hDevice, nullptr, nullptr, size,
64-
alignment);
63+
return USMSharedAllocImpl(ppMem, hContext, hDevice, /*host flags*/ 0,
64+
/*device flags*/ 0, size, alignment);
6565
}
6666

6767
return umfPoolMallocHelper(hPool, ppMem, size, alignment);
@@ -105,7 +105,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMFree(ur_context_handle_t hContext,
105105

106106
ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t,
107107
ur_device_handle_t Device,
108-
ur_usm_device_mem_flags_t *, size_t Size,
108+
ur_usm_device_mem_flags_t, size_t Size,
109109
[[maybe_unused]] uint32_t Alignment) {
110110
try {
111111
ScopedContext Active(Device);
@@ -120,8 +120,8 @@ ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t,
120120

121121
ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t,
122122
ur_device_handle_t Device,
123-
ur_usm_host_mem_flags_t *,
124-
ur_usm_device_mem_flags_t *, size_t Size,
123+
ur_usm_host_mem_flags_t,
124+
ur_usm_device_mem_flags_t, size_t Size,
125125
[[maybe_unused]] uint32_t Alignment) {
126126
try {
127127
ScopedContext Active(Device);
@@ -136,7 +136,7 @@ ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t,
136136

137137
ur_result_t USMHostAllocImpl(void **ResultPtr,
138138
[[maybe_unused]] ur_context_handle_t Context,
139-
ur_usm_host_mem_flags_t *, size_t Size,
139+
ur_usm_host_mem_flags_t, size_t Size,
140140
[[maybe_unused]] uint32_t Alignment) {
141141
try {
142142
UR_CHECK_ERROR(hipHostMalloc(ResultPtr, Size));
@@ -309,19 +309,19 @@ umf_result_t USMMemoryProvider::get_min_page_size(void *Ptr, size_t *PageSize) {
309309

310310
ur_result_t USMSharedMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
311311
uint32_t Alignment) {
312-
return USMSharedAllocImpl(ResultPtr, Context, Device, nullptr, nullptr, Size,
313-
Alignment);
312+
return USMSharedAllocImpl(ResultPtr, Context, Device, /*host flags*/ 0,
313+
/*device flags*/ 0, Size, Alignment);
314314
}
315315

316316
ur_result_t USMDeviceMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
317317
uint32_t Alignment) {
318-
return USMDeviceAllocImpl(ResultPtr, Context, Device, nullptr, Size,
318+
return USMDeviceAllocImpl(ResultPtr, Context, Device, /* flags */ 0, Size,
319319
Alignment);
320320
}
321321

322322
ur_result_t USMHostMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
323323
uint32_t Alignment) {
324-
return USMHostAllocImpl(ResultPtr, Context, nullptr, Size, Alignment);
324+
return USMHostAllocImpl(ResultPtr, Context, /* flags */ 0, Size, Alignment);
325325
}
326326

327327
ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,

source/adapters/hip/usm.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ class USMHostMemoryProvider final : public USMMemoryProvider {
118118

119119
ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t Context,
120120
ur_device_handle_t Device,
121-
ur_usm_device_mem_flags_t *Flags, size_t Size,
121+
ur_usm_device_mem_flags_t Flags, size_t Size,
122122
uint32_t Alignment);
123123

124124
ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t Context,
125125
ur_device_handle_t Device,
126-
ur_usm_host_mem_flags_t *,
127-
ur_usm_device_mem_flags_t *, size_t Size,
126+
ur_usm_host_mem_flags_t,
127+
ur_usm_device_mem_flags_t, size_t Size,
128128
uint32_t Alignment);
129129

130130
ur_result_t USMHostAllocImpl(void **ResultPtr, ur_context_handle_t Context,
131-
ur_usm_host_mem_flags_t *Flags, size_t Size,
131+
ur_usm_host_mem_flags_t Flags, size_t Size,
132132
uint32_t Alignment);
133133

134134
bool checkUSMAlignment(uint32_t &alignment, const ur_usm_desc_t *pUSMDesc);

source/adapters/level_zero/usm.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static ur_result_t USMAllocationMakeResident(
171171
static ur_result_t USMDeviceAllocImpl(void **ResultPtr,
172172
ur_context_handle_t Context,
173173
ur_device_handle_t Device,
174-
ur_usm_device_mem_flags_t *Flags,
174+
ur_usm_device_mem_flags_t Flags,
175175
size_t Size, uint32_t Alignment) {
176176
std::ignore = Flags;
177177
// TODO: translate PI properties to Level Zero flags
@@ -213,12 +213,10 @@ static ur_result_t USMDeviceAllocImpl(void **ResultPtr,
213213
return UR_RESULT_SUCCESS;
214214
}
215215

216-
static ur_result_t USMSharedAllocImpl(void **ResultPtr,
217-
ur_context_handle_t Context,
218-
ur_device_handle_t Device,
219-
ur_usm_host_mem_flags_t *,
220-
ur_usm_device_mem_flags_t *, size_t Size,
221-
uint32_t Alignment) {
216+
static ur_result_t
217+
USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t Context,
218+
ur_device_handle_t Device, ur_usm_host_mem_flags_t,
219+
ur_usm_device_mem_flags_t, size_t Size, uint32_t Alignment) {
222220

223221
// TODO: translate PI properties to Level Zero flags
224222
ZeStruct<ze_host_mem_alloc_desc_t> ZeHostDesc;
@@ -263,7 +261,7 @@ static ur_result_t USMSharedAllocImpl(void **ResultPtr,
263261

264262
static ur_result_t USMHostAllocImpl(void **ResultPtr,
265263
ur_context_handle_t Context,
266-
ur_usm_host_mem_flags_t *Flags, size_t Size,
264+
ur_usm_host_mem_flags_t Flags, size_t Size,
267265
uint32_t Alignment) {
268266
std::ignore = Flags;
269267
// TODO: translate PI properties to Level Zero flags
@@ -776,29 +774,28 @@ umf_result_t L0MemoryProvider::get_min_page_size(void *Ptr, size_t *PageSize) {
776774

777775
ur_result_t L0SharedMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
778776
uint32_t Alignment) {
779-
return USMSharedAllocImpl(ResultPtr, Context, Device, nullptr, nullptr, Size,
780-
Alignment);
777+
return USMSharedAllocImpl(ResultPtr, Context, Device, /*host flags*/ 0,
778+
/*device flags*/ 0, Size, Alignment);
781779
}
782780

783781
ur_result_t L0SharedReadOnlyMemoryProvider::allocateImpl(void **ResultPtr,
784782
size_t Size,
785783
uint32_t Alignment) {
786784
ur_usm_device_desc_t UsmDeviceDesc{};
787785
UsmDeviceDesc.flags = UR_USM_DEVICE_MEM_FLAG_DEVICE_READ_ONLY;
788-
ur_usm_host_desc_t UsmHostDesc{};
789-
return USMSharedAllocImpl(ResultPtr, Context, Device, &UsmDeviceDesc.flags,
790-
&UsmHostDesc.flags, Size, Alignment);
786+
return USMSharedAllocImpl(ResultPtr, Context, Device, UsmDeviceDesc.flags,
787+
/*host flags*/ 0, Size, Alignment);
791788
}
792789

793790
ur_result_t L0DeviceMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
794791
uint32_t Alignment) {
795-
return USMDeviceAllocImpl(ResultPtr, Context, Device, nullptr, Size,
792+
return USMDeviceAllocImpl(ResultPtr, Context, Device, /* flags */ 0, Size,
796793
Alignment);
797794
}
798795

799796
ur_result_t L0HostMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
800797
uint32_t Alignment) {
801-
return USMHostAllocImpl(ResultPtr, Context, nullptr, Size, Alignment);
798+
return USMHostAllocImpl(ResultPtr, Context, /* flags */ 0, Size, Alignment);
802799
}
803800

804801
ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,

0 commit comments

Comments
 (0)