From b69b96d8b7506755ffd51e2e1dfc8b2d49a8edb1 Mon Sep 17 00:00:00 2001 From: Luke Drummond Date: Tue, 19 Mar 2024 17:03:54 +0000 Subject: [PATCH] [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. --- source/adapters/cuda/usm.cpp | 24 ++++++++++++------------ source/adapters/cuda/usm.hpp | 8 ++++---- source/adapters/hip/usm.cpp | 24 ++++++++++++------------ source/adapters/hip/usm.hpp | 8 ++++---- source/adapters/level_zero/usm.cpp | 27 ++++++++++++--------------- 5 files changed, 44 insertions(+), 47 deletions(-) diff --git a/source/adapters/cuda/usm.cpp b/source/adapters/cuda/usm.cpp index 59d3ba70fd..6faa1e5320 100644 --- a/source/adapters/cuda/usm.cpp +++ b/source/adapters/cuda/usm.cpp @@ -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(); @@ -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); } @@ -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(); @@ -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); @@ -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); @@ -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); @@ -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, diff --git a/source/adapters/cuda/usm.hpp b/source/adapters/cuda/usm.hpp index 2ec3df150f..e5d1f7fbaa 100644 --- a/source/adapters/cuda/usm.hpp +++ b/source/adapters/cuda/usm.hpp @@ -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); diff --git a/source/adapters/hip/usm.cpp b/source/adapters/hip/usm.cpp index 4068c1d865..e871f394f2 100644 --- a/source/adapters/hip/usm.cpp +++ b/source/adapters/hip/usm.cpp @@ -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); @@ -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); } @@ -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); @@ -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); @@ -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); @@ -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)); @@ -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, diff --git a/source/adapters/hip/usm.hpp b/source/adapters/hip/usm.hpp index d02145584f..a1c3964263 100644 --- a/source/adapters/hip/usm.hpp +++ b/source/adapters/hip/usm.hpp @@ -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); diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index 09e340dfe0..2531dd8e15 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -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 @@ -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 ZeHostDesc; @@ -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 @@ -776,8 +774,8 @@ 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, @@ -785,20 +783,19 @@ ur_result_t L0SharedReadOnlyMemoryProvider::allocateImpl(void **ResultPtr, 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,