Skip to content

Commit fbca6c4

Browse files
committed
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.
1 parent 4b4e732 commit fbca6c4

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

unified-runtime/source/adapters/hip/usm.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,6 @@ bool checkUSMAlignment(uint32_t &alignment, const ur_usm_desc_t *pUSMDesc) {
485485
(alignment == 0 || ((alignment & (alignment - 1)) == 0)));
486486
}
487487

488-
bool checkUSMImplAlignment(uint32_t Alignment, void **ResultPtr) {
489-
return Alignment == 0 ||
490-
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0;
491-
}
492-
493488
UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolCreateExp(ur_context_handle_t,
494489
ur_device_handle_t,
495490
ur_usm_pool_desc_t *,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,3 @@ ur_result_t USMHostAllocImpl(void **ResultPtr, ur_context_handle_t Context,
120120
uint32_t Alignment);
121121

122122
bool checkUSMAlignment(uint32_t &alignment, const ur_usm_desc_t *pUSMDesc);
123-
124-
bool checkUSMImplAlignment(uint32_t Alignment, void **ResultPtr);

unified-runtime/source/adapters/opencl/usm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill(
269269
// Have to look up the context from the kernel
270270
cl_context CLContext = hQueue->Context->CLContext;
271271

272-
if (patternSize <= 128 && isPowerOf2(patternSize)) {
272+
if (patternSize <= 128 && isPowerOf2(patternSize) &&
273+
checkUSMImplAlignment(patternSize, &ptr)) {
273274
clEnqueueMemFillINTEL_fn EnqueueMemFill = nullptr;
274275
UR_RETURN_ON_FAILURE(
275276
cl_ext::getExtFuncFromContext<clEnqueueMemFillINTEL_fn>(

unified-runtime/source/common/ur_util.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,4 +548,9 @@ static inline std::string groupDigits(Numeric numeric) {
548548

549549
template <typename T> Spinlock<Rc<T>> AtomicSingleton<T>::instance;
550550

551+
inline bool checkUSMImplAlignment(uint32_t Alignment, void **ResultPtr) {
552+
return Alignment == 0 ||
553+
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0;
554+
}
555+
551556
#endif /* UR_UTIL_H */

0 commit comments

Comments
 (0)