Skip to content

Commit b5901e4

Browse files
committed
Fix unspecified alignment
It's plausible that a user will pass a non-null `ur_usm_desc_t` argument that itself has a zero `align` member. We need to gracefully accept such a case.
1 parent ffeb1ea commit b5901e4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

source/adapters/native_cpu/usm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ namespace native_cpu {
2020
static ur_result_t alloc_helper(ur_context_handle_t hContext,
2121
const ur_usm_desc_t *pUSMDesc, size_t size,
2222
void **ppMem, ur_usm_type_t type) {
23-
auto alignment = pUSMDesc ? pUSMDesc->align : 1u;
24-
UR_ASSERT((alignment & (alignment - 1)) == 0, UR_RESULT_ERROR_INVALID_VALUE);
23+
auto alignment = (pUSMDesc && pUSMDesc->align) ? pUSMDesc->align : 1u;
24+
UR_ASSERT(isPowerOf2(alignment), UR_RESULT_ERROR_UNSUPPORTED_ALIGNMENT);
2525
UR_ASSERT(ppMem, UR_RESULT_ERROR_INVALID_NULL_POINTER);
2626
// TODO: Check Max size when UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE is implemented
2727
UR_ASSERT(size > 0, UR_RESULT_ERROR_INVALID_USM_SIZE);

0 commit comments

Comments
 (0)