Skip to content

Commit

Permalink
Remove assertions to instead return error code
Browse files Browse the repository at this point in the history
  • Loading branch information
lbushi25 committed May 27, 2024
1 parent b604f08 commit cd29bd7
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions source/adapters/opencl/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ urUSMHostAlloc(ur_context_handle_t hContext, const ur_usm_desc_t *pUSMDesc,

*ppMem = Ptr;

assert((Alignment == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % Alignment == 0) &&
"Allocation not aligned correctly!");
if (!(Alignment == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % Alignment == 0)) {
urUSMFree(hContext, Ptr);
return UR_RESULT_ERROR_UNSUPPORTED_ALIGNMENT;
}

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -159,9 +161,11 @@ urUSMDeviceAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,

*ppMem = Ptr;

assert((Alignment == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % Alignment == 0) &&
"Allocation not aligned correctly!");
if (!(Alignment == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % Alignment == 0)) {
urUSMFree(hContext, Ptr);
return UR_RESULT_ERROR_UNSUPPORTED_ALIGNMENT;
}

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -202,9 +206,11 @@ urUSMSharedAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,

*ppMem = Ptr;

assert((Alignment == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % Alignment == 0) &&
"Allocation not aligned correctly!");
if (!(Alignment == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % Alignment == 0)) {
urUSMFree(hContext, Ptr);
return UR_RESULT_ERROR_UNSUPPORTED_ALIGNMENT;
}
return UR_RESULT_SUCCESS;
}

Expand Down

0 comments on commit cd29bd7

Please sign in to comment.