Skip to content

Commit

Permalink
Merge pull request #1457 from ldrumm/usm-flags-by-val
Browse files Browse the repository at this point in the history
 [l0][HIP][CUDA] Prefer values over pointers-to
  • Loading branch information
kbenzie authored May 3, 2024
2 parents 9990d44 + b69b96d commit 23b8630
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 47 deletions.
24 changes: 12 additions & 12 deletions source/adapters/cuda/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ urUSMHostAlloc(ur_context_handle_t hContext, const ur_usm_desc_t *pUSMDesc,
UR_RESULT_ERROR_INVALID_VALUE);

if (!hPool) {
return USMHostAllocImpl(ppMem, hContext, nullptr, size, alignment);
return USMHostAllocImpl(ppMem, hContext, /* flags */ 0, size, alignment);
}

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

if (!hPool) {
return USMDeviceAllocImpl(ppMem, hContext, hDevice, nullptr, size,
return USMDeviceAllocImpl(ppMem, hContext, hDevice, /* flags */ 0, size,
alignment);
}

Expand All @@ -82,8 +82,8 @@ urUSMSharedAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
UR_RESULT_ERROR_INVALID_VALUE);

if (!hPool) {
return USMSharedAllocImpl(ppMem, hContext, hDevice, nullptr, nullptr, size,
alignment);
return USMSharedAllocImpl(ppMem, hContext, hDevice, /*host flags*/ 0,
/*device flags*/ 0, size, alignment);
}

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

ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t Context,
ur_device_handle_t, ur_usm_device_mem_flags_t *,
ur_device_handle_t, ur_usm_device_mem_flags_t,
size_t Size, uint32_t Alignment) {
try {
ScopedContext Active(Context);
Expand All @@ -151,8 +151,8 @@ ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t Context,
}

ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t Context,
ur_device_handle_t, ur_usm_host_mem_flags_t *,
ur_usm_device_mem_flags_t *, size_t Size,
ur_device_handle_t, ur_usm_host_mem_flags_t,
ur_usm_device_mem_flags_t, size_t Size,
uint32_t Alignment) {
try {
ScopedContext Active(Context);
Expand All @@ -172,7 +172,7 @@ ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t Context,
}

ur_result_t USMHostAllocImpl(void **ResultPtr, ur_context_handle_t Context,
ur_usm_host_mem_flags_t *, size_t Size,
ur_usm_host_mem_flags_t, size_t Size,
uint32_t Alignment) {
try {
ScopedContext Active(Context);
Expand Down Expand Up @@ -358,19 +358,19 @@ umf_result_t USMMemoryProvider::get_min_page_size(void *Ptr, size_t *PageSize) {

ur_result_t USMSharedMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
uint32_t Alignment) {
return USMSharedAllocImpl(ResultPtr, Context, Device, nullptr, nullptr, Size,
Alignment);
return USMSharedAllocImpl(ResultPtr, Context, Device, /*host flags*/ 0,
/*device flags*/ 0, Size, Alignment);
}

ur_result_t USMDeviceMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
uint32_t Alignment) {
return USMDeviceAllocImpl(ResultPtr, Context, Device, nullptr, Size,
return USMDeviceAllocImpl(ResultPtr, Context, Device, /* flags */ 0, Size,
Alignment);
}

ur_result_t USMHostMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
uint32_t Alignment) {
return USMHostAllocImpl(ResultPtr, Context, nullptr, Size, Alignment);
return USMHostAllocImpl(ResultPtr, Context, /* flags */ 0, Size, Alignment);
}

ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
Expand Down
8 changes: 4 additions & 4 deletions source/adapters/cuda/usm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ class USMHostMemoryProvider final : public USMMemoryProvider {

ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t Context,
ur_device_handle_t Device,
ur_usm_device_mem_flags_t *Flags, size_t Size,
ur_usm_device_mem_flags_t Flags, size_t Size,
uint32_t Alignment);

ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t Context,
ur_device_handle_t Device,
ur_usm_host_mem_flags_t *,
ur_usm_device_mem_flags_t *, size_t Size,
ur_usm_host_mem_flags_t,
ur_usm_device_mem_flags_t, size_t Size,
uint32_t Alignment);

ur_result_t USMHostAllocImpl(void **ResultPtr, ur_context_handle_t Context,
ur_usm_host_mem_flags_t *Flags, size_t Size,
ur_usm_host_mem_flags_t Flags, size_t Size,
uint32_t Alignment);
24 changes: 12 additions & 12 deletions source/adapters/hip/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ urUSMHostAlloc(ur_context_handle_t hContext, const ur_usm_desc_t *pUSMDesc,
UR_RESULT_ERROR_INVALID_VALUE);

if (!hPool) {
return USMHostAllocImpl(ppMem, hContext, nullptr, size, alignment);
return USMHostAllocImpl(ppMem, hContext, /* flags */ 0, size, alignment);
}

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

if (!hPool) {
return USMDeviceAllocImpl(ppMem, hContext, hDevice, nullptr, size,
return USMDeviceAllocImpl(ppMem, hContext, hDevice, /* flags */ 0, size,
alignment);
}

Expand All @@ -60,8 +60,8 @@ urUSMSharedAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
UR_RESULT_ERROR_INVALID_VALUE);

if (!hPool) {
return USMSharedAllocImpl(ppMem, hContext, hDevice, nullptr, nullptr, size,
alignment);
return USMSharedAllocImpl(ppMem, hContext, hDevice, /*host flags*/ 0,
/*device flags*/ 0, size, alignment);
}

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

ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t,
ur_device_handle_t Device,
ur_usm_device_mem_flags_t *, size_t Size,
ur_usm_device_mem_flags_t, size_t Size,
[[maybe_unused]] uint32_t Alignment) {
try {
ScopedContext Active(Device);
Expand All @@ -120,8 +120,8 @@ ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t,

ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t,
ur_device_handle_t Device,
ur_usm_host_mem_flags_t *,
ur_usm_device_mem_flags_t *, size_t Size,
ur_usm_host_mem_flags_t,
ur_usm_device_mem_flags_t, size_t Size,
[[maybe_unused]] uint32_t Alignment) {
try {
ScopedContext Active(Device);
Expand All @@ -136,7 +136,7 @@ ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t,

ur_result_t USMHostAllocImpl(void **ResultPtr,
[[maybe_unused]] ur_context_handle_t Context,
ur_usm_host_mem_flags_t *, size_t Size,
ur_usm_host_mem_flags_t, size_t Size,
[[maybe_unused]] uint32_t Alignment) {
try {
UR_CHECK_ERROR(hipHostMalloc(ResultPtr, Size));
Expand Down Expand Up @@ -309,19 +309,19 @@ umf_result_t USMMemoryProvider::get_min_page_size(void *Ptr, size_t *PageSize) {

ur_result_t USMSharedMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
uint32_t Alignment) {
return USMSharedAllocImpl(ResultPtr, Context, Device, nullptr, nullptr, Size,
Alignment);
return USMSharedAllocImpl(ResultPtr, Context, Device, /*host flags*/ 0,
/*device flags*/ 0, Size, Alignment);
}

ur_result_t USMDeviceMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
uint32_t Alignment) {
return USMDeviceAllocImpl(ResultPtr, Context, Device, nullptr, Size,
return USMDeviceAllocImpl(ResultPtr, Context, Device, /* flags */ 0, Size,
Alignment);
}

ur_result_t USMHostMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
uint32_t Alignment) {
return USMHostAllocImpl(ResultPtr, Context, nullptr, Size, Alignment);
return USMHostAllocImpl(ResultPtr, Context, /* flags */ 0, Size, Alignment);
}

ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
Expand Down
8 changes: 4 additions & 4 deletions source/adapters/hip/usm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ class USMHostMemoryProvider final : public USMMemoryProvider {

ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t Context,
ur_device_handle_t Device,
ur_usm_device_mem_flags_t *Flags, size_t Size,
ur_usm_device_mem_flags_t Flags, size_t Size,
uint32_t Alignment);

ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t Context,
ur_device_handle_t Device,
ur_usm_host_mem_flags_t *,
ur_usm_device_mem_flags_t *, size_t Size,
ur_usm_host_mem_flags_t,
ur_usm_device_mem_flags_t, size_t Size,
uint32_t Alignment);

ur_result_t USMHostAllocImpl(void **ResultPtr, ur_context_handle_t Context,
ur_usm_host_mem_flags_t *Flags, size_t Size,
ur_usm_host_mem_flags_t Flags, size_t Size,
uint32_t Alignment);

bool checkUSMAlignment(uint32_t &alignment, const ur_usm_desc_t *pUSMDesc);
Expand Down
27 changes: 12 additions & 15 deletions source/adapters/level_zero/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static ur_result_t USMAllocationMakeResident(
static ur_result_t USMDeviceAllocImpl(void **ResultPtr,
ur_context_handle_t Context,
ur_device_handle_t Device,
ur_usm_device_mem_flags_t *Flags,
ur_usm_device_mem_flags_t Flags,
size_t Size, uint32_t Alignment) {
std::ignore = Flags;
// TODO: translate PI properties to Level Zero flags
Expand Down Expand Up @@ -213,12 +213,10 @@ static ur_result_t USMDeviceAllocImpl(void **ResultPtr,
return UR_RESULT_SUCCESS;
}

static ur_result_t USMSharedAllocImpl(void **ResultPtr,
ur_context_handle_t Context,
ur_device_handle_t Device,
ur_usm_host_mem_flags_t *,
ur_usm_device_mem_flags_t *, size_t Size,
uint32_t Alignment) {
static ur_result_t
USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t Context,
ur_device_handle_t Device, ur_usm_host_mem_flags_t,
ur_usm_device_mem_flags_t, size_t Size, uint32_t Alignment) {

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

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

ur_result_t L0SharedMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
uint32_t Alignment) {
return USMSharedAllocImpl(ResultPtr, Context, Device, nullptr, nullptr, Size,
Alignment);
return USMSharedAllocImpl(ResultPtr, Context, Device, /*host flags*/ 0,
/*device flags*/ 0, Size, Alignment);
}

ur_result_t L0SharedReadOnlyMemoryProvider::allocateImpl(void **ResultPtr,
size_t Size,
uint32_t Alignment) {
ur_usm_device_desc_t UsmDeviceDesc{};
UsmDeviceDesc.flags = UR_USM_DEVICE_MEM_FLAG_DEVICE_READ_ONLY;
ur_usm_host_desc_t UsmHostDesc{};
return USMSharedAllocImpl(ResultPtr, Context, Device, &UsmDeviceDesc.flags,
&UsmHostDesc.flags, Size, Alignment);
return USMSharedAllocImpl(ResultPtr, Context, Device, UsmDeviceDesc.flags,
/*host flags*/ 0, Size, Alignment);
}

ur_result_t L0DeviceMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
uint32_t Alignment) {
return USMDeviceAllocImpl(ResultPtr, Context, Device, nullptr, Size,
return USMDeviceAllocImpl(ResultPtr, Context, Device, /* flags */ 0, Size,
Alignment);
}

ur_result_t L0HostMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
uint32_t Alignment) {
return USMHostAllocImpl(ResultPtr, Context, nullptr, Size, Alignment);
return USMHostAllocImpl(ResultPtr, Context, /* flags */ 0, Size, Alignment);
}

ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
Expand Down

0 comments on commit 23b8630

Please sign in to comment.