rusticl/context: add helper to get the max mem alloc size for all devices

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19712>
This commit is contained in:
Karol Herbst
2022-11-06 19:14:07 +01:00
committed by Marge Bot
parent 50097ffae0
commit 2ee082ef8a
2 changed files with 11 additions and 4 deletions
+2 -4
View File
@@ -247,10 +247,8 @@ pub fn create_buffer_with_properties(
}
// ... or if size is greater than CL_DEVICE_MAX_MEM_ALLOC_SIZE for all devices in context.
for dev in &c.devs {
if checked_compare(size, Ordering::Greater, dev.max_mem_alloc()) {
return Err(CL_INVALID_BUFFER_SIZE);
}
if checked_compare(size, Ordering::Greater, c.max_mem_alloc()) {
return Err(CL_INVALID_BUFFER_SIZE);
}
validate_host_ptr(host_ptr, flags)?;
@@ -141,6 +141,15 @@ impl Context {
Ok(res)
}
/// Returns the max allocation size supported by all devices
pub fn max_mem_alloc(&self) -> u64 {
self.devs
.iter()
.map(|dev| dev.max_mem_alloc())
.min()
.unwrap()
}
}
impl Drop for Context {