Skip to content

[UR] Check for memory alignment before calling clEnqueueMemFillINTEL_fn in OpenCL #18423

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions unified-runtime/source/adapters/hip/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uintptr_t>(*ResultPtr) % Alignment == 0;
}

UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolCreateExp(ur_context_handle_t,
ur_device_handle_t,
ur_usm_pool_desc_t *,
Expand Down
2 changes: 0 additions & 2 deletions unified-runtime/source/adapters/hip/usm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
3 changes: 2 additions & 1 deletion unified-runtime/source/adapters/opencl/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<clEnqueueMemFillINTEL_fn>(
Expand Down
5 changes: 5 additions & 0 deletions unified-runtime/source/common/ur_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,9 @@ static inline std::string groupDigits(Numeric numeric) {

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

inline bool checkUSMImplAlignment(uint32_t Alignment, void **ResultPtr) {
return Alignment == 0 ||
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0;
}

#endif /* UR_UTIL_H */
Loading