Skip to content

Commit

Permalink
[OpenCL] Fix USM alignment error check to occur always and return nul…
Browse files Browse the repository at this point in the history
…lptr

- USM calls to alloc must return a nullptr and error given invalid
  alignment. This cannot be relied upon in the validation layer.

Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
  • Loading branch information
nrspruit authored and kbenzie committed Aug 27, 2024
1 parent a4e2219 commit c3c5728
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions source/adapters/opencl/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ urUSMHostAlloc(ur_context_handle_t hContext, const ur_usm_desc_t *pUSMDesc,
void *Ptr = nullptr;
uint32_t Alignment = pUSMDesc ? pUSMDesc->align : 0;

if (pUSMDesc && pUSMDesc->align != 0 &&
((pUSMDesc->align & (pUSMDesc->align - 1)) != 0)) {
return UR_RESULT_ERROR_INVALID_VALUE;
}

std::vector<cl_mem_properties_intel> AllocProperties;
if (pUSMDesc && pUSMDesc->pNext) {
UR_RETURN_ON_FAILURE(usmDescToCLMemProperties(
Expand Down Expand Up @@ -130,6 +135,11 @@ urUSMDeviceAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
void *Ptr = nullptr;
uint32_t Alignment = pUSMDesc ? pUSMDesc->align : 0;

if (pUSMDesc && pUSMDesc->align != 0 &&
((pUSMDesc->align & (pUSMDesc->align - 1)) != 0)) {
return UR_RESULT_ERROR_INVALID_VALUE;
}

std::vector<cl_mem_properties_intel> AllocProperties;
if (pUSMDesc && pUSMDesc->pNext) {
UR_RETURN_ON_FAILURE(usmDescToCLMemProperties(
Expand Down Expand Up @@ -173,6 +183,11 @@ urUSMSharedAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
void *Ptr = nullptr;
uint32_t Alignment = pUSMDesc ? pUSMDesc->align : 0;

if (pUSMDesc && pUSMDesc->align != 0 &&
((pUSMDesc->align & (pUSMDesc->align - 1)) != 0)) {
return UR_RESULT_ERROR_INVALID_VALUE;
}

std::vector<cl_mem_properties_intel> AllocProperties;
if (pUSMDesc && pUSMDesc->pNext) {
UR_RETURN_ON_FAILURE(usmDescToCLMemProperties(
Expand Down

0 comments on commit c3c5728

Please sign in to comment.