From fbca6c4524a2ad4a63f408078e825961215a2fbb Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Mon, 12 May 2025 17:31:51 +0100 Subject: [PATCH 1/3] Check for memory alignment before calling clEnqueueMemFillINTEL_fn in OpenCL. Use checkUSMImplAlignment from the Hip adapter for this but moved it to a common header. --- unified-runtime/source/adapters/hip/usm.cpp | 5 ----- unified-runtime/source/adapters/hip/usm.hpp | 2 -- unified-runtime/source/adapters/opencl/usm.cpp | 3 ++- unified-runtime/source/common/ur_util.hpp | 5 +++++ 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/unified-runtime/source/adapters/hip/usm.cpp b/unified-runtime/source/adapters/hip/usm.cpp index e61d14bfb6a84..80407ba26744c 100644 --- a/unified-runtime/source/adapters/hip/usm.cpp +++ b/unified-runtime/source/adapters/hip/usm.cpp @@ -485,11 +485,6 @@ bool checkUSMAlignment(uint32_t &alignment, const ur_usm_desc_t *pUSMDesc) { (alignment == 0 || ((alignment & (alignment - 1)) == 0))); } -bool checkUSMImplAlignment(uint32_t Alignment, void **ResultPtr) { - return Alignment == 0 || - reinterpret_cast(*ResultPtr) % Alignment == 0; -} - UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolCreateExp(ur_context_handle_t, ur_device_handle_t, ur_usm_pool_desc_t *, diff --git a/unified-runtime/source/adapters/hip/usm.hpp b/unified-runtime/source/adapters/hip/usm.hpp index 79408570f9500..d35c4c5e1f989 100644 --- a/unified-runtime/source/adapters/hip/usm.hpp +++ b/unified-runtime/source/adapters/hip/usm.hpp @@ -120,5 +120,3 @@ ur_result_t USMHostAllocImpl(void **ResultPtr, ur_context_handle_t Context, uint32_t Alignment); bool checkUSMAlignment(uint32_t &alignment, const ur_usm_desc_t *pUSMDesc); - -bool checkUSMImplAlignment(uint32_t Alignment, void **ResultPtr); diff --git a/unified-runtime/source/adapters/opencl/usm.cpp b/unified-runtime/source/adapters/opencl/usm.cpp index 6f39e505ca5f6..b11c2a8f48bc8 100644 --- a/unified-runtime/source/adapters/opencl/usm.cpp +++ b/unified-runtime/source/adapters/opencl/usm.cpp @@ -269,7 +269,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill( // Have to look up the context from the kernel cl_context CLContext = hQueue->Context->CLContext; - if (patternSize <= 128 && isPowerOf2(patternSize)) { + if (patternSize <= 128 && isPowerOf2(patternSize) && + checkUSMImplAlignment(patternSize, &ptr)) { clEnqueueMemFillINTEL_fn EnqueueMemFill = nullptr; UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( diff --git a/unified-runtime/source/common/ur_util.hpp b/unified-runtime/source/common/ur_util.hpp index 47a39e0ead8c0..99d0f767058b4 100644 --- a/unified-runtime/source/common/ur_util.hpp +++ b/unified-runtime/source/common/ur_util.hpp @@ -548,4 +548,9 @@ static inline std::string groupDigits(Numeric numeric) { template Spinlock> AtomicSingleton::instance; +inline bool checkUSMImplAlignment(uint32_t Alignment, void **ResultPtr) { + return Alignment == 0 || + reinterpret_cast(*ResultPtr) % Alignment == 0; +} + #endif /* UR_UTIL_H */ From 9455b959c0a937f1942c10cf217e34fc4df18c9e Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Wed, 14 May 2025 10:19:21 +0100 Subject: [PATCH 2/3] Re-enable fill_any_size.cpp test for OpenCL. --- sycl/test-e2e/USM/fill_any_size.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/sycl/test-e2e/USM/fill_any_size.cpp b/sycl/test-e2e/USM/fill_any_size.cpp index 037ac4b884cae..43ef883cdde35 100644 --- a/sycl/test-e2e/USM/fill_any_size.cpp +++ b/sycl/test-e2e/USM/fill_any_size.cpp @@ -1,8 +1,6 @@ // RUN: %{build} -o %t1.out // RUN: %{run} %t1.out // clang-format off -// UNSUPPORTED: opencl -// UNSUPPORTED-TRACKER: https://github.com/oneapi-src/unified-runtime/issues/2440 // clang-format on /** From 4aa4f892e8564850ebd819665a8c7bc8ec73c5b7 Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Wed, 21 May 2025 11:24:28 +0100 Subject: [PATCH 3/3] Rename checkUSMImplAlignment to isPointerAlignedTo. Change func to take single *pointer and deference at calls sites where double** was being passed. --- unified-runtime/source/adapters/hip/usm.cpp | 6 +++--- unified-runtime/source/adapters/opencl/usm.cpp | 2 +- unified-runtime/source/common/ur_util.hpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/unified-runtime/source/adapters/hip/usm.cpp b/unified-runtime/source/adapters/hip/usm.cpp index 80407ba26744c..ad337cc8f9dfd 100644 --- a/unified-runtime/source/adapters/hip/usm.cpp +++ b/unified-runtime/source/adapters/hip/usm.cpp @@ -144,7 +144,7 @@ ur_result_t USMDeviceAllocImpl(void **ResultPtr, ur_context_handle_t, return Err; } - assert(checkUSMImplAlignment(Alignment, ResultPtr)); + assert(isPointerAlignedTo(Alignment, *ResultPtr)); return UR_RESULT_SUCCESS; } @@ -160,7 +160,7 @@ ur_result_t USMSharedAllocImpl(void **ResultPtr, ur_context_handle_t, return Err; } - assert(checkUSMImplAlignment(Alignment, ResultPtr)); + assert(isPointerAlignedTo(Alignment, *ResultPtr)); return UR_RESULT_SUCCESS; } @@ -174,7 +174,7 @@ ur_result_t USMHostAllocImpl(void **ResultPtr, return Err; } - assert(checkUSMImplAlignment(Alignment, ResultPtr)); + assert(isPointerAlignedTo(Alignment, *ResultPtr)); return UR_RESULT_SUCCESS; } diff --git a/unified-runtime/source/adapters/opencl/usm.cpp b/unified-runtime/source/adapters/opencl/usm.cpp index b11c2a8f48bc8..76ee6a2a0497a 100644 --- a/unified-runtime/source/adapters/opencl/usm.cpp +++ b/unified-runtime/source/adapters/opencl/usm.cpp @@ -270,7 +270,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill( cl_context CLContext = hQueue->Context->CLContext; if (patternSize <= 128 && isPowerOf2(patternSize) && - checkUSMImplAlignment(patternSize, &ptr)) { + isPointerAlignedTo(patternSize, ptr)) { clEnqueueMemFillINTEL_fn EnqueueMemFill = nullptr; UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( diff --git a/unified-runtime/source/common/ur_util.hpp b/unified-runtime/source/common/ur_util.hpp index 99d0f767058b4..b76223a63bfa2 100644 --- a/unified-runtime/source/common/ur_util.hpp +++ b/unified-runtime/source/common/ur_util.hpp @@ -548,9 +548,9 @@ static inline std::string groupDigits(Numeric numeric) { template Spinlock> AtomicSingleton::instance; -inline bool checkUSMImplAlignment(uint32_t Alignment, void **ResultPtr) { +inline bool isPointerAlignedTo(uint32_t Alignment, void *Ptr) { return Alignment == 0 || - reinterpret_cast(*ResultPtr) % Alignment == 0; + reinterpret_cast(Ptr) % Alignment == 0; } #endif /* UR_UTIL_H */