Skip to content

Commit 3351916

Browse files
[SYCL] Fix to alignment assertion (#3671)
There are several reasons sycl::aligned_alloc_host might fail, for example if there is not enough memory. The present assertion seems to want to ensure that if the alignment is used that the memory is, ultimately, properly aligned. But it is too open and could instead assert if an alignment was specified and any failure occurred (even one not associated with alignment). This fix tightens that. Signed-off-by: Chris Perkins [email protected]
1 parent 3fc66cc commit 3351916

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

sycl/plugins/opencl/pi_opencl.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,11 @@ pi_result piextUSMHostAlloc(void **result_ptr, pi_context context,
754754

755755
*result_ptr = Ptr;
756756

757-
assert(alignment == 0 ||
758-
(RetVal == PI_SUCCESS &&
759-
reinterpret_cast<std::uintptr_t>(*result_ptr) % alignment == 0));
757+
// ensure we aligned the allocation correctly
758+
if (RetVal == PI_SUCCESS && alignment != 0)
759+
assert(reinterpret_cast<std::uintptr_t>(*result_ptr) % alignment == 0 &&
760+
"allocation not aligned correctly");
761+
760762
return RetVal;
761763
}
762764

@@ -790,9 +792,11 @@ pi_result piextUSMDeviceAlloc(void **result_ptr, pi_context context,
790792

791793
*result_ptr = Ptr;
792794

793-
assert(alignment == 0 ||
794-
(RetVal == PI_SUCCESS &&
795-
reinterpret_cast<std::uintptr_t>(*result_ptr) % alignment == 0));
795+
// ensure we aligned the allocation correctly
796+
if (RetVal == PI_SUCCESS && alignment != 0)
797+
assert(reinterpret_cast<std::uintptr_t>(*result_ptr) % alignment == 0 &&
798+
"allocation not aligned correctly");
799+
796800
return RetVal;
797801
}
798802

0 commit comments

Comments
 (0)