Skip to content

Commit b766009

Browse files
Merge pull request #2011 from nrspruit/fix_opencl_usm_align_check
[OpenCL] Fix USM alignment error check to occur always and return nulllptr
2 parents 608e918 + c3c5728 commit b766009

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

source/adapters/opencl/usm.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ urUSMHostAlloc(ur_context_handle_t hContext, const ur_usm_desc_t *pUSMDesc,
8787
void *Ptr = nullptr;
8888
uint32_t Alignment = pUSMDesc ? pUSMDesc->align : 0;
8989

90+
if (pUSMDesc && pUSMDesc->align != 0 &&
91+
((pUSMDesc->align & (pUSMDesc->align - 1)) != 0)) {
92+
return UR_RESULT_ERROR_INVALID_VALUE;
93+
}
94+
9095
std::vector<cl_mem_properties_intel> AllocProperties;
9196
if (pUSMDesc && pUSMDesc->pNext) {
9297
UR_RETURN_ON_FAILURE(usmDescToCLMemProperties(
@@ -130,6 +135,11 @@ urUSMDeviceAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
130135
void *Ptr = nullptr;
131136
uint32_t Alignment = pUSMDesc ? pUSMDesc->align : 0;
132137

138+
if (pUSMDesc && pUSMDesc->align != 0 &&
139+
((pUSMDesc->align & (pUSMDesc->align - 1)) != 0)) {
140+
return UR_RESULT_ERROR_INVALID_VALUE;
141+
}
142+
133143
std::vector<cl_mem_properties_intel> AllocProperties;
134144
if (pUSMDesc && pUSMDesc->pNext) {
135145
UR_RETURN_ON_FAILURE(usmDescToCLMemProperties(
@@ -173,6 +183,11 @@ urUSMSharedAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice,
173183
void *Ptr = nullptr;
174184
uint32_t Alignment = pUSMDesc ? pUSMDesc->align : 0;
175185

186+
if (pUSMDesc && pUSMDesc->align != 0 &&
187+
((pUSMDesc->align & (pUSMDesc->align - 1)) != 0)) {
188+
return UR_RESULT_ERROR_INVALID_VALUE;
189+
}
190+
176191
std::vector<cl_mem_properties_intel> AllocProperties;
177192
if (pUSMDesc && pUSMDesc->pNext) {
178193
UR_RETURN_ON_FAILURE(usmDescToCLMemProperties(

0 commit comments

Comments
 (0)