From fb82c253dafccc695a6926b08d0e236feccb3174 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Mon, 29 Jul 2024 16:00:29 +0200 Subject: [PATCH] rusticl: use div_ceil It got stabilized with 1.73 Part-of: --- src/gallium/frontends/rusticl/core/kernel.rs | 10 +++++----- src/gallium/frontends/rusticl/core/memory.rs | 5 ++--- src/gallium/frontends/rusticl/util/math.rs | 14 -------------- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index 93e014663ec..b2e367f5b19 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -1293,9 +1293,9 @@ impl Kernel { .map(|val| cmp::min(val, u32::MAX as usize)) .collect(); - for z in 0..div_round_up(grid[2], hw_max_grid[2]) { - for y in 0..div_round_up(grid[1], hw_max_grid[1]) { - for x in 0..div_round_up(grid[0], hw_max_grid[0]) { + for z in 0..grid[2].div_ceil(hw_max_grid[2]) { + for y in 0..grid[1].div_ceil(hw_max_grid[1]) { + for x in 0..grid[0].div_ceil(hw_max_grid[0]) { if let Some(workgroup_id_offset_loc) = workgroup_id_offset_loc { let this_offsets = [x * hw_max_grid[0], y * hw_max_grid[1], z * hw_max_grid[2]]; @@ -1479,8 +1479,8 @@ impl Kernel { return 0; } - let threads = block.iter().product(); - div_round_up(threads, subgroup_size) + let threads: usize = block.iter().product(); + threads.div_ceil(subgroup_size) } pub fn subgroup_size_for_block(&self, dev: &Device, block: &[usize]) -> usize { diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 82b54b53c04..303304c150d 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -16,7 +16,6 @@ use mesa_rust::pipe::resource::*; use mesa_rust::pipe::screen::ResourceType; use mesa_rust::pipe::transfer::*; use mesa_rust_gen::*; -use mesa_rust_util::math::*; use mesa_rust_util::properties::Properties; use mesa_rust_util::ptr::AllocSize; use mesa_rust_util::ptr::TrackedPointers; @@ -1271,8 +1270,8 @@ impl Image { // make sure we allocate multiples of 4 bytes so drivers don't read out of bounds or // unaligned. // TODO: use div_ceil once it's available - let pixel_size = self.image_format.pixel_size().unwrap().into(); - let mut new_pattern: Vec = vec![0; div_round_up(pixel_size, size_of::())]; + let pixel_size: usize = self.image_format.pixel_size().unwrap().into(); + let mut new_pattern: Vec = vec![0; pixel_size.div_ceil(size_of::())]; // we don't support CL_DEPTH for now assert!(pattern.len() == 4); diff --git a/src/gallium/frontends/rusticl/util/math.rs b/src/gallium/frontends/rusticl/util/math.rs index 28dd5ede2e6..267c288c52c 100644 --- a/src/gallium/frontends/rusticl/util/math.rs +++ b/src/gallium/frontends/rusticl/util/math.rs @@ -1,5 +1,4 @@ use std::ops::Add; -use std::ops::Div; use std::ops::Rem; use std::ops::Sub; @@ -35,19 +34,6 @@ where } } -pub fn div_round_up(a: T, b: T) -> T -where - T: Copy, - T: Add, - T: Div, - T: Sub, -{ - #[allow(clippy::eq_op)] - let one = b / b; - - (a + b - one) / b -} - pub struct SetBitIndices { val: T, }