Skip to content

Commit bda6ec5

Browse files
committed
Add sanity check
1 parent a0d2f16 commit bda6ec5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/acl_mem.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,18 @@ static int acl_do_physical_buffer_allocation(unsigned physical_device_id,
279279
"Device is not configured to support SVM and device global memory.");
280280
int tmp_mem_id = acl_get_fit_device_global_memory(
281281
acl_platform.device[physical_device_id].def, mem->size);
282-
assert(tmp_mem_id >= 0 &&
283-
"Device does not have any device global memory.");
282+
assert(tmp_mem_id >= 0 && "Device does not have any device global memory "
283+
"for the allocation size.");
284284
mem->mem_id = (unsigned int)tmp_mem_id;
285285
}
286+
} else if (mem->buffer_location_set) {
287+
// Sanity check if the specified buffer location is large enough
288+
assert(
289+
ACL_RANGE_SIZE(acl_platform.device[physical_device_id]
290+
.def.autodiscovery_def.global_mem_defs[mem->mem_id]
291+
.get_usable_range()) >= mem->size &&
292+
"Specified buffer location is could not fit the requested allocation "
293+
"size");
286294
}
287295

288296
int result = 0;

0 commit comments

Comments
 (0)