diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index 0cb59b21334..8ceb38cc334 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -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)?; diff --git a/src/gallium/frontends/rusticl/core/context.rs b/src/gallium/frontends/rusticl/core/context.rs index e38ab73adab..7f9245fce68 100644 --- a/src/gallium/frontends/rusticl/core/context.rs +++ b/src/gallium/frontends/rusticl/core/context.rs @@ -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 {