rusticl: replace get_compute_param with pipe_compute_caps

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33176>
This commit is contained in:
Qiang Yu
2025-01-22 21:18:24 +08:00
parent e08664cf85
commit c46aacc216
5 changed files with 20 additions and 104 deletions
+14 -39
View File
@@ -761,8 +761,7 @@ impl Device {
}
pub fn address_bits(&self) -> cl_uint {
self.screen
.compute_param(pipe_compute_cap::PIPE_COMPUTE_CAP_ADDRESS_BITS)
self.screen.compute_caps().address_bits
}
pub fn const_max_size(&self) -> cl_ulong {
@@ -921,8 +920,7 @@ impl Device {
};
memory * 1024
} else {
self.screen
.compute_param(pipe_compute_cap::PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE)
self.screen.compute_caps().max_global_size
}
}
@@ -991,51 +989,37 @@ impl Device {
}
pub fn local_mem_size(&self) -> cl_ulong {
self.screen
.compute_param(pipe_compute_cap::PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE)
self.screen.compute_caps().max_local_size as cl_ulong
}
pub fn max_block_sizes(&self) -> Vec<usize> {
let v: Vec<u64> = self
.screen
.compute_param(pipe_compute_cap::PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE);
let v: [u32; 3] = self.screen.compute_caps().max_block_size;
v.into_iter().map(|v| v as usize).collect()
}
pub fn max_grid_size(&self) -> Vec<u64> {
let v: Vec<u64> = self
.screen
.compute_param(pipe_compute_cap::PIPE_COMPUTE_CAP_MAX_GRID_SIZE);
pub fn max_grid_size(&self) -> Vec<usize> {
let v: [u32; 3] = self.screen.compute_caps().max_grid_size;
v.into_iter()
.map(|a| min(a, Platform::dbg().max_grid_size))
.map(|v| v as usize)
.collect()
}
pub fn max_clock_freq(&self) -> cl_uint {
self.screen
.compute_param(pipe_compute_cap::PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY)
self.screen.compute_caps().max_clock_frequency
}
pub fn max_compute_units(&self) -> cl_uint {
self.screen
.compute_param(pipe_compute_cap::PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS)
self.screen.compute_caps().max_compute_units
}
pub fn max_grid_dimensions(&self) -> cl_uint {
ComputeParam::<u64>::compute_param(
self.screen.as_ref(),
pipe_compute_cap::PIPE_COMPUTE_CAP_GRID_DIMENSION,
) as cl_uint
self.screen.compute_caps().grid_dimension
}
pub fn max_mem_alloc(&self) -> cl_ulong {
// TODO: at the moment gallium doesn't support bigger buffers
min(
self.screen
.compute_param(pipe_compute_cap::PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE),
0x80000000,
)
min(self.screen.compute_caps().max_mem_alloc_size, 0x80000000)
}
pub fn max_samplers(&self) -> cl_uint {
@@ -1043,10 +1027,7 @@ impl Device {
}
pub fn max_threads_per_block(&self) -> usize {
ComputeParam::<u64>::compute_param(
self.screen.as_ref(),
pipe_compute_cap::PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK,
) as usize
self.screen.compute_caps().max_threads_per_block as usize
}
pub fn param_max_size(&self) -> usize {
@@ -1096,10 +1077,7 @@ impl Device {
}
pub fn subgroup_sizes(&self) -> Vec<usize> {
let subgroup_size = ComputeParam::<u32>::compute_param(
self.screen.as_ref(),
pipe_compute_cap::PIPE_COMPUTE_CAP_SUBGROUP_SIZES,
);
let subgroup_size = self.screen.compute_caps().subgroup_sizes;
SetBitIndices::from_msb(subgroup_size)
.map(|bit| 1 << bit)
@@ -1107,10 +1085,7 @@ impl Device {
}
pub fn max_subgroups(&self) -> u32 {
ComputeParam::<u32>::compute_param(
self.screen.as_ref(),
pipe_compute_cap::PIPE_COMPUTE_CAP_MAX_SUBGROUPS,
)
self.screen.compute_caps().max_subgroups
}
pub fn subgroups_supported(&self) -> bool {
+1 -8
View File
@@ -1324,14 +1324,7 @@ impl Kernel {
self.optimize_local_size(q.device, &mut grid, &mut block);
Ok(Box::new(move |q, ctx| {
let hw_max_grid: Vec<usize> = q
.device
.max_grid_size()
.into_iter()
.map(|val| val.try_into().unwrap_or(usize::MAX))
// clamped as pipe_launch_grid::grid is only u32
.map(|val| cmp::min(val, u32::MAX as usize))
.collect();
let hw_max_grid: Vec<usize> = q.device.max_grid_size();
let variant = if offsets == [0; 3]
&& grid[0] <= hw_max_grid[0]
@@ -30,7 +30,7 @@ pub enum PerfDebugLevel {
pub struct PlatformDebug {
pub allow_invalid_spirv: bool,
pub clc: bool,
pub max_grid_size: u64,
pub max_grid_size: u32,
pub nir: bool,
pub no_variants: bool,
pub perf: PerfDebugLevel,
@@ -119,7 +119,7 @@ fn load_env() {
debug.max_grid_size = env::var("RUSTICL_MAX_WORK_GROUPS")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(u64::MAX);
.unwrap_or(u32::MAX);
// SAFETY: no other references exist at this point
let features = unsafe { &mut *addr_of_mut!(PLATFORM_FEATURES) };
@@ -375,7 +375,7 @@ impl SPIRVBin {
pub fn get_lib_clc(screen: &PipeScreen) -> Option<NirShader> {
let nir_options = screen.nir_shader_compiler_options(pipe_shader_type::PIPE_SHADER_COMPUTE);
let address_bits = screen.compute_param(pipe_compute_cap::PIPE_COMPUTE_CAP_ADDRESS_BITS);
let address_bits = screen.compute_caps().address_bits;
let spirv_caps = Self::get_spirv_capabilities();
let spirv_options =
Self::get_spirv_options(false, ptr::null(), address_bits, &spirv_caps, None);
@@ -8,9 +8,7 @@ use mesa_rust_gen::*;
use mesa_rust_util::has_required_feature;
use mesa_rust_util::ptr::ThreadSafeCPtr;
use std::convert::TryInto;
use std::ffi::CStr;
use std::mem::size_of;
use std::os::raw::c_schar;
use std::os::raw::c_uchar;
use std::os::raw::c_void;
@@ -26,49 +24,6 @@ pub struct PipeScreen {
pub const UUID_SIZE: usize = PIPE_UUID_SIZE as usize;
const LUID_SIZE: usize = PIPE_LUID_SIZE as usize;
// until we have a better solution
pub trait ComputeParam<T> {
fn compute_param(&self, cap: pipe_compute_cap) -> T;
}
macro_rules! compute_param_impl {
($ty:ty) => {
impl ComputeParam<$ty> for PipeScreen {
fn compute_param(&self, cap: pipe_compute_cap) -> $ty {
let size = self.compute_param_wrapped(cap, ptr::null_mut());
let mut d = [0; size_of::<$ty>()];
if size == 0 {
return Default::default();
}
assert_eq!(size as usize, d.len());
self.compute_param_wrapped(cap, d.as_mut_ptr().cast());
<$ty>::from_ne_bytes(d)
}
}
};
}
compute_param_impl!(u32);
compute_param_impl!(u64);
impl ComputeParam<Vec<u64>> for PipeScreen {
fn compute_param(&self, cap: pipe_compute_cap) -> Vec<u64> {
let size = self.compute_param_wrapped(cap, ptr::null_mut());
let elems = (size / 8) as usize;
let mut res: Vec<u64> = Vec::new();
let mut d: Vec<u8> = vec![0; size as usize];
self.compute_param_wrapped(cap, d.as_mut_ptr().cast());
for i in 0..elems {
let offset = i * 8;
let slice = &d[offset..offset + 8];
res.push(u64::from_ne_bytes(slice.try_into().expect("")));
}
res
}
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum ResourceType {
Normal,
@@ -294,14 +249,8 @@ impl PipeScreen {
&self.screen().shader_caps[t as usize]
}
fn compute_param_wrapped(&self, cap: pipe_compute_cap, ptr: *mut c_void) -> i32 {
unsafe {
self.screen().get_compute_param.unwrap()(
self.screen.as_ptr(),
cap,
ptr,
)
}
pub fn compute_caps(&self) -> &pipe_compute_caps {
&self.screen().compute_caps
}
pub fn driver_name(&self) -> &CStr {
@@ -480,7 +429,6 @@ fn has_required_cbs(screen: *mut pipe_screen) -> bool {
& has_required_feature!(screen, fence_finish)
& has_required_feature!(screen, fence_reference)
& has_required_feature!(screen, get_compiler_options)
& has_required_feature!(screen, get_compute_param)
& has_required_feature!(screen, get_name)
& has_required_feature!(screen, is_format_supported)
& has_required_feature!(screen, resource_create)