rusticl/context: add helper to get the max mem alloc size for all devices
authorKarol Herbst <kherbst@redhat.com>
Sun, 6 Nov 2022 18:14:07 +0000 (19:14 +0100)
committerMarge Bot <emma+marge@anholt.net>
Fri, 14 Apr 2023 07:41:54 +0000 (07:41 +0000)
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>

src/gallium/frontends/rusticl/api/memory.rs
src/gallium/frontends/rusticl/core/context.rs

index 0cb59b2..8ceb38c 100644 (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)?;
index e38ab73..7f9245f 100644 (file)
@@ -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 {