A high-performance inference engine for AI models
Improve DeviceProfile for better tuning (#731)
CCYeh8be3a99dae06
diff --git a/crates/backend-uzu/src/backends/metal/context.rs b/crates/backend-uzu/src/backends/metal/context.rsindex 9c7f350fc..0670d313b 100644--- a/crates/backend-uzu/src/backends/metal/context.rs+++ b/crates/backend-uzu/src/backends/metal/context.rs@@ -19,7 +19,7 @@ use parking_lot::{Mutex, MutexGuard};use super::{Metal,- device_tier::{DeviceTier, device_tier_for_device},+ device_profile::{DeviceProfile, classify_device},error::MetalError,metal_extensions::{DeviceExt, LibraryPipelineExtensions},};@@ -42,7 +42,7 @@ pub struct MetalContext {library_cache: Mutex<HashMap<usize, Retained<ProtocolObject<dyn MTLLibrary>>>>,pipeline_cache: Mutex<HashMap<String, Retained<ProtocolObject<dyn MTLComputePipelineState>>>>,sparse_heap_pool: Mutex<MetalSparseHeapPool>,- device_tier: DeviceTier,+ device_profile: DeviceProfile,weak_self: Weak<MetalContext>,#[cfg(test)]timeline_shared_event: Retained<ProtocolObject<dyn MTLSharedEvent>>,@@ -53,8 +53,8 @@ impl MetalContext {self.device.supports_mxu()}- pub(crate) fn device_tier(&self) -> DeviceTier {- self.device_tier+ pub fn device_profile(&self) -> DeviceProfile {+ self.device_profile}pub(super) fn update_peak_memory_usage(&self) {@@ -155,7 +155,12 @@ impl Context for MetalContext {let command_queue4 = device.new_mtl4_command_queue().ok_or(MetalError::CannotCreateCommandQueueMtl4)?;let gpu_core_count = device.gpu_core_count();- let device_tier = device_tier_for_device(gpu_core_count, device.as_ref());+ let device_profile = classify_device(+ gpu_core_count,+ device.supports_family(metal::MTLGPUFamily::Apple8),+ device.supports_family(metal::MTLGPUFamily::Apple9),+ device.supports_mxu(),+ );let page_size = MTLSparsePageSize::KB256;let heap_capacity = Metal::ALLOCATION_GRANULARITY;let sparse_pool = MetalSparseHeapPool::new(page_size, heap_capacity);@@ -174,7 +179,7 @@ impl Context for MetalContext {library_cache: Mutex::new(HashMap::new()),pipeline_cache: Mutex::new(HashMap::new()),sparse_heap_pool: Mutex::new(sparse_pool),- device_tier,+ device_profile,weak_self: weak_self.clone(),#[cfg(test)]timeline_shared_event,diff --git a/crates/backend-uzu/src/backends/metal/device_profile.rs b/crates/backend-uzu/src/backends/metal/device_profile.rsnew file mode 100644index 000000000..333908705--- /dev/null+++ b/crates/backend-uzu/src/backends/metal/device_profile.rs@@ -0,0 +1,78 @@+//TODO: remove after retune with gpu core counts+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum DeviceSize {+ /// Below Max/Ultra class: base and Pro dies, plus Max parts binned under+ /// the core-count cutoff (a 24-core M1 Max lands here, a 32-core one does not).+ Small,+ /// Max/Ultra-class GPUs, currently classified by >= 30 GPU cores.+ Large,+}++#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum DeviceGeneration {+ Legacy, // M1 (G13) and A14 or older+ Apple8, // M2, A15/16+ Apple9, // M3/4, A17 Pro, A18+ M5Plus, // M5 (Apple9 + MXU support)+}++#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub struct DeviceProfile {+ gpu_core_count: u32,+ generation: DeviceGeneration,+}++const LARGE_MIN_GPU_CORES: u32 = 30;++impl DeviceProfile {+ pub const fn new(+ gpu_core_count: u32,+ generation: DeviceGeneration,+ ) -> Self {+ Self {+ gpu_core_count,+ generation,+ }+ }++ pub const fn size(self) -> DeviceSize {+ if self.gpu_core_count >= LARGE_MIN_GPU_CORES {+ DeviceSize::Large+ } else {+ DeviceSize::Small+ }+ }++ // TODO: retune based on gpu core counts+ pub const fn gpu_core_count(self) -> u32 {+ self.gpu_core_count+ }++ pub const fn generation(self) -> DeviceGeneration {+ self.generation+ }+}++pub(super) fn classify_device(+ gpu_core_count: u32,+ supports_apple8_family: bool,+ supports_apple9_family: bool,+ supports_mxu: bool,+) -> DeviceProfile {+ // MXU is probed first: M5 also reports Apple9, so a family check alone+ // cannot separate the two generations.+ let generation = if supports_mxu {+ DeviceGeneration::M5Plus+ } else if supports_apple9_family {+ DeviceGeneration::Apple9+ } else if supports_apple8_family {+ DeviceGeneration::Apple8+ } else {+ DeviceGeneration::Legacy+ };+ DeviceProfile::new(gpu_core_count, generation)+}++#[cfg(test)]+#[path = "../../../tests/unit/backends/metal/device_profile_test.rs"]+mod tests;diff --git a/crates/backend-uzu/src/backends/metal/device_tier.rs b/crates/backend-uzu/src/backends/metal/device_tier.rsdeleted file mode 100644index 09e65cf86..000000000--- a/crates/backend-uzu/src/backends/metal/device_tier.rs+++ /dev/null@@ -1,45 +0,0 @@-use metal::MTLDevice;-use objc2::runtime::ProtocolObject;--#[derive(Debug, Clone, Copy, PartialEq, Eq)]-pub(crate) enum DeviceTier {- /// Small Apple9+ GPUs (M3/A17 and newer, below Max/Ultra class).- SmallApple9,- /// Small Apple8 GPUs (M2/A15/A16 generation).- SmallApple8,- /// Small pre-Apple8 GPUs (M1/A14 generation).- SmallLegacy,- /// Max/Ultra-class GPUs, currently classified by >= 30 GPU cores.- Large,-}--pub(crate) fn device_tier_for_device(- gpu_core_count: u32,- device: &ProtocolObject<dyn MTLDevice>,-) -> DeviceTier {- device_tier_for(- gpu_core_count,- device.supports_family(metal::MTLGPUFamily::Apple8),- device.supports_family(metal::MTLGPUFamily::Apple9),- )-}--fn device_tier_for(- gpu_core_count: u32,- supports_apple8_family: bool,- supports_apple9_family: bool,-) -> DeviceTier {- if gpu_core_count >= 30 {- DeviceTier::Large- } else if supports_apple9_family {- DeviceTier::SmallApple9- } else if supports_apple8_family {- DeviceTier::SmallApple8- } else {- DeviceTier::SmallLegacy- }-}--#[cfg(test)]-#[path = "../../../tests/unit/backends/metal/device_tier_test.rs"]-mod tests;diff --git a/crates/backend-uzu/src/backends/metal/kernel/gdn/tree_verify.rs b/crates/backend-uzu/src/backends/metal/kernel/gdn/tree_verify.rsindex 095d6c161..13578fedd 100644--- a/crates/backend-uzu/src/backends/metal/kernel/gdn/tree_verify.rs+++ b/crates/backend-uzu/src/backends/metal/kernel/gdn/tree_verify.rs@@ -7,7 +7,12 @@ use crate::{delta_net_tree_verify::DeltaNetTreeVerify,},},- metal::{Metal, MetalContext, device_tier::DeviceTier, error::MetalError, kernel::MetalKernels},+ metal::{+ Metal, MetalContext,+ device_profile::{DeviceGeneration, DeviceSize},+ error::MetalError,+ kernel::MetalKernels,+ },},data_type::DataType,encodable_block::mixer::delta_net::tree_verify::{TreeVerifyEncodeArguments, TreeVerifyNewArguments},@@ -67,8 +72,9 @@ impl DeltaNetTreeVerify<Metal> for MetalDeltaNetTreeVerify {arguments: &TreeVerifyNewArguments,) -> Result<Self, MetalError> {let use_mxu = arguments.data_type == DataType::BF16 && context.supports_mxu();- let transposed_h0 =- !use_mxu && matches!(context.device_tier(), DeviceTier::SmallLegacy | DeviceTier::SmallApple8);+ let transposed_h0 = !use_mxu+ && context.device_profile().size() == DeviceSize::Small+ && matches!(context.device_profile().generation(), DeviceGeneration::Legacy | DeviceGeneration::Apple8);Ok(Self {arguments: *arguments,prefix: <MetalKernels as Kernels>::BuildTreePrefixKernel::new(context)?,diff --git a/crates/backend-uzu/src/backends/metal/kernel/matmul/gemv/kernel.rs b/crates/backend-uzu/src/backends/metal/kernel/matmul/gemv/kernel.rsindex 77ff41cd0..f9326cf43 100644--- a/crates/backend-uzu/src/backends/metal/kernel/matmul/gemv/kernel.rs+++ b/crates/backend-uzu/src/backends/metal/kernel/matmul/gemv/kernel.rs@@ -14,7 +14,7 @@ use crate::{},kernel::matmul::{MatmulA, MatmulArguments, MatmulB, MatmulError, MatmulShape},},- metal::{Metal, context::MetalContext, device_tier::DeviceTier, kernel::GemvMetalKernel},+ metal::{Metal, context::MetalContext, device_profile::DeviceProfile, kernel::GemvMetalKernel},},data_type::DataType,};@@ -49,7 +49,7 @@ impl GemvSpecialization {weights_data_type: DataType,input_data_type: DataType,output_data_type: DataType,- device_tier: DeviceTier,+ device_profile: DeviceProfile,) -> Option<GemvSpecialization> {if !shape.b_transpose || !shape.a_full_precision {return None;@@ -92,13 +92,13 @@ impl GemvSpecialization {let has_rht = shape.d_transform.contains(GemmDTransform::RHT);let bf16_io = input_data_type == DataType::BF16 && output_data_type == DataType::BF16;let tile = if is_quant && bf16_io {- policy::quant_tile(shape.m, shape.n, shape.k, bits, has_rht, device_tier)+ policy::quant_tile(shape.m, shape.n, shape.k, bits, has_rht, device_profile)} else if is_quant || has_rht {// Non-bf16 quant IO and fp+RHT keep the default tile (the only// one instantiated for those modes).policy::DEFAULT_TILE} else {- policy::fp_tile(shape.m, shape.n, shape.k, input_aligned, device_tier)+ policy::fp_tile(shape.m, shape.n, shape.k, input_aligned, device_profile)};Some(Self {b_prologue: shape.b_prologue,diff --git a/crates/backend-uzu/src/backends/metal/kernel/matmul/gemv/policy.rs b/crates/backend-uzu/src/backends/metal/kernel/matmul/gemv/policy.rsindex 12573b6ca..315440112 100644--- a/crates/backend-uzu/src/backends/metal/kernel/matmul/gemv/policy.rs+++ b/crates/backend-uzu/src/backends/metal/kernel/matmul/gemv/policy.rs@@ -1,4 +1,4 @@-use crate::backends::metal::device_tier::DeviceTier;+use crate::backends::metal::device_profile::{DeviceGeneration, DeviceProfile, DeviceSize};// Full-precision GEMV accumulates four K values per SIMD lane, so one full// vectorized K block is 4 * 32 lanes.@@ -124,13 +124,15 @@ pub(crate) fn fp_tile(n: u32,k: u32,input_aligned: bool,- tier: DeviceTier,+ profile: DeviceProfile,) -> GemvTile {+ let size = profile.size();+ let is_small_g13 = size == DeviceSize::Small && profile.generation() == DeviceGeneration::Legacy;// FP sweeps covered SG2/SG4/SG8; SG changes did not produce portable// confirmed wins, so shipped FP policy keeps SG8 and tunes KS/R only.let should_disable_k_split = !input_aligned- || (m == 1 && tier == DeviceTier::Large && k < FP_LARGE_SPLIT_K_MIN_DEPTH)- || (m == 1 && tier == DeviceTier::SmallLegacy && n >= SMALL_G13_HUGE_N);+ || (m == 1 && size == DeviceSize::Large && k < FP_LARGE_SPLIT_K_MIN_DEPTH)+ || (m == 1 && is_small_g13 && n >= SMALL_G13_HUGE_N);let k_split = if should_disable_k_split {1@@ -140,9 +142,9 @@ pub(crate) fn fp_tile(// R1 won most single-row FP sweeps; Large devices only switch back to R4// for deep-K rows, while legacy wide rows keep R4.- let results_per_simdgroup = if tier == DeviceTier::SmallLegacy && m == 1 && n >= SMALL_G13_WIDE_ROW_N {+ let results_per_simdgroup = if is_small_g13 && m == 1 && n >= SMALL_G13_WIDE_ROW_N {DEFAULT_RESULTS_PER_SIMDGROUP- } else if m == 1 && (k <= DEEP_K || tier != DeviceTier::Large) {+ } else if m == 1 && (k <= DEEP_K || size != DeviceSize::Large) {1} else {DEFAULT_RESULTS_PER_SIMDGROUP@@ -159,8 +161,10 @@ pub(crate) fn quant_tile(k: u32,bits: u32,has_rht: bool,- tier: DeviceTier,+ profile: DeviceProfile,) -> GemvTile {+ let size = profile.size();+ let generation = profile.generation();// These tables are fitted for batch-1 Q4 only; Q8/future widths keep the// deterministic default until they have their own cold sweep.if m != 1 || bits != 4 {@@ -169,7 +173,7 @@ pub(crate) fn quant_tile(if has_rht {// This special case mirrors quant bucket edges: n in (2048, 4096]// and k at or above the 2048 boundary.- return if tier == DeviceTier::Large+ return if size == DeviceSize::Large&& n > QUANT_RHT_TUNED_N_MIN_EXCLUSIVE&& n <= QUANT_RHT_TUNED_N_MAX&& k >= QUANT_RHT_TUNED_K_MIN@@ -184,29 +188,31 @@ pub(crate) fn quant_tile(let n_bucket = table_bucket_index(n, &QUANT_N_BUCKET_MAXES);// Q4 BF16 decode choices from June 2026 gemv_fine_tune sweeps; omitted// cells keep SG8_KS1_R4. Other quant widths keep DEFAULT_TILE until swept.- let selected = match (tier, k_bucket, n_bucket) {- (DeviceTier::Large, 0, 1) => Q42,- (DeviceTier::Large, 1, 0) => Q21,- (DeviceTier::Large, 1, 1..=3) => Q22,- (DeviceTier::Large, 1, 4) => Q21,- (DeviceTier::Large, 1, 5) => Q24,- (DeviceTier::Large, 2, 1) => Q42,- (DeviceTier::Large, 3, 1) => Q22,-- (DeviceTier::SmallApple9, 0, 1) => Q44,- (DeviceTier::SmallApple9, 1, 0) => Q42,- (DeviceTier::SmallApple9, 1, 1) => Q22,- (DeviceTier::SmallApple9, 1, 2) => Q42,- (DeviceTier::SmallApple9, 1, 4) => Q22,- (DeviceTier::SmallApple9, 1, 5) => Q42,- (DeviceTier::SmallApple9, 2, 1) => Q42,- (DeviceTier::SmallApple9, 3, 1) => Q22,-- (DeviceTier::SmallApple8, 0, 1) => Q44,- (DeviceTier::SmallApple8, 1, _) | (DeviceTier::SmallApple8, 2, 1) => Q82,-- (DeviceTier::SmallLegacy, 0, 1) => Q48,- (DeviceTier::SmallLegacy, 1, 0..=3) => Q82,+ let selected = match (size, generation, k_bucket, n_bucket) {+ (DeviceSize::Large, _, 0, 1) => Q42,+ (DeviceSize::Large, _, 1, 0) => Q21,+ (DeviceSize::Large, _, 1, 1..=3) => Q22,+ (DeviceSize::Large, _, 1, 4) => Q21,+ (DeviceSize::Large, _, 1, 5) => Q24,+ (DeviceSize::Large, _, 2, 1) => Q42,+ (DeviceSize::Large, _, 3, 1) => Q22,++ (DeviceSize::Small, DeviceGeneration::Apple9 | DeviceGeneration::M5Plus, 0, 1) => Q44,+ (DeviceSize::Small, DeviceGeneration::Apple9 | DeviceGeneration::M5Plus, 1, 0) => Q42,+ (DeviceSize::Small, DeviceGeneration::Apple9 | DeviceGeneration::M5Plus, 1, 1) => Q22,+ (DeviceSize::Small, DeviceGeneration::Apple9 | DeviceGeneration::M5Plus, 1, 2) => Q42,+ (DeviceSize::Small, DeviceGeneration::Apple9 | DeviceGeneration::M5Plus, 1, 4) => Q22,+ (DeviceSize::Small, DeviceGeneration::Apple9 | DeviceGeneration::M5Plus, 1, 5) => Q42,+ (DeviceSize::Small, DeviceGeneration::Apple9 | DeviceGeneration::M5Plus, 2, 1) => Q42,+ (DeviceSize::Small, DeviceGeneration::Apple9 | DeviceGeneration::M5Plus, 3, 1) => Q22,++ (DeviceSize::Small, DeviceGeneration::Apple8, 0, 1) => Q44,+ (DeviceSize::Small, DeviceGeneration::Apple8, 1, _) | (DeviceSize::Small, DeviceGeneration::Apple8, 2, 1) => {+ Q82+ },++ (DeviceSize::Small, DeviceGeneration::Legacy, 0, 1) => Q48,+ (DeviceSize::Small, DeviceGeneration::Legacy, 1, 0..=3) => Q82,_ => DEFAULT_TILE,};diff --git a/crates/backend-uzu/src/backends/metal/kernel/matmul/mod.rs b/crates/backend-uzu/src/backends/metal/kernel/matmul/mod.rsindex e6bfdba49..c07e956eb 100644--- a/crates/backend-uzu/src/backends/metal/kernel/matmul/mod.rs+++ b/crates/backend-uzu/src/backends/metal/kernel/matmul/mod.rs@@ -74,7 +74,7 @@ impl MatmulMetalKernel {self.weights_data_type,self.input_data_type,self.output_data_type,- context.device_tier(),+ context.device_profile(),);let problem = GemmProblem::new(*shape, self.weights_data_type, self.output_data_type, context.supports_mxu());let plan = problem.select_plan();diff --git a/crates/backend-uzu/src/backends/metal/mod.rs b/crates/backend-uzu/src/backends/metal/mod.rsindex 1d182db33..c6483b9c1 100644--- a/crates/backend-uzu/src/backends/metal/mod.rs+++ b/crates/backend-uzu/src/backends/metal/mod.rs@@ -3,7 +3,7 @@ mod buffer;mod command_buffer;mod context;mod dense_buffer;-mod device_tier;+mod device_profile;mod error;mod kernel;mod metal_extensions;@@ -11,7 +11,7 @@ mod sparse;use crate::backends::common::gpu_types::HADAMARD_TRANSFORM_BLOCK_SIZE;-pub(crate) const METAL_SIMD_SIZE: u32 = 32;+const METAL_SIMD_SIZE: u32 = 32;const _: () = {assert!(HADAMARD_TRANSFORM_BLOCK_SIZE == METAL_SIMD_SIZE);@@ -20,7 +20,7 @@ const _: () = {pub use backend::Metal;pub use context::MetalContext;#[cfg(test)]-pub(crate) use device_tier::DeviceTier;+pub use device_profile::{DeviceGeneration, DeviceProfile, DeviceSize};#[cfg(test)]pub use kernel::matmul::gemm::GemmEngine;#[cfg(test)]diff --git a/crates/backend-uzu/tests/unit/backends/common/kernel/matmul/a8w_bench.rs b/crates/backend-uzu/tests/unit/backends/common/kernel/matmul/a8w_bench.rsindex 37877e30a..5488f27e2 100644--- a/crates/backend-uzu/tests/unit/backends/common/kernel/matmul/a8w_bench.rs+++ b/crates/backend-uzu/tests/unit/backends/common/kernel/matmul/a8w_bench.rs@@ -17,7 +17,7 @@ use crate::{matmul::{MatmulA, MatmulArguments, MatmulB, MatmulDOps, MatmulKernel, MatmulShape},},},- metal::{DeviceTier, GemmEngine, GemvDispatch, GemvSpecialization, Metal, MetalContext},+ metal::{DeviceProfile, GemmEngine, GemvDispatch, GemvSpecialization, Metal, MetalContext},},data_type::DataType,tests::{@@ -150,7 +150,7 @@ fn encode_step(hadamard: &ActivationTransform<Metal>,matmul: &mut MetalMatmul,gemv: &mut GemvDispatch,- device_tier: DeviceTier,+ device_profile: DeviceProfile,encoder: &mut Encoder<Metal>,) {match path {@@ -205,7 +205,7 @@ fn encode_step(DataType::BF16,DataType::BF16,DataType::BF16,- device_tier,+ device_profile,).expect("bf16 gemv specialization");gemv.encode(args, spec, encoder).expect("bf16 gemv encode");@@ -216,7 +216,7 @@ fn encode_step(fn bench_bits(c: &mut Criterion,context: &MetalContext,- device_tier: DeviceTier,+ device_profile: DeviceProfile,prepare: &ActivationTransform<Metal>,hadamard: &ActivationTransform<Metal>,bits: u32,@@ -249,7 +249,7 @@ fn bench_bits(DataType::BF16,DataType::BF16,DataType::BF16,- device_tier,+ device_profile,).is_some();@@ -272,7 +272,7 @@ fn bench_bits(hadamard,&mut matmul,&mut gemv,- device_tier,+ device_profile,encoder,);});@@ -288,12 +288,12 @@ fn bench_a8w(c: &mut Criterion) {if !context.supports_mxu() {return;}- let device_tier = context.device_tier();+ let device_profile = context.device_profile();let prepare = ActivationTransform::<Metal>::quantize(&context, DataType::BF16, 128, None).expect("prepare kernel");let hadamard = ActivationTransform::<Metal>::input_rht(&context, DataType::BF16, true).expect("hadamard kernel");for bits in [8u32, 4u32] {- bench_bits(c, &context, device_tier, &prepare, &hadamard, bits);+ bench_bits(c, &context, device_profile, &prepare, &hadamard, bits);}}diff --git a/crates/backend-uzu/tests/unit/backends/metal/device_profile_test.rs b/crates/backend-uzu/tests/unit/backends/metal/device_profile_test.rsnew file mode 100644index 000000000..23ba10b46--- /dev/null+++ b/crates/backend-uzu/tests/unit/backends/metal/device_profile_test.rs@@ -0,0 +1,20 @@+use proc_macros::uzu_test;++use super::*;++#[uzu_test]+fn device_profile_detection() {+ assert_eq!(classify_device(40, true, true, false), DeviceProfile::new(40, DeviceGeneration::Apple9));+ assert_eq!(classify_device(40, true, true, true), DeviceProfile::new(40, DeviceGeneration::M5Plus));+ assert_eq!(classify_device(20, true, true, false), DeviceProfile::new(20, DeviceGeneration::Apple9));+ assert_eq!(classify_device(10, true, false, false), DeviceProfile::new(10, DeviceGeneration::Apple8));+ assert_eq!(classify_device(8, false, false, false), DeviceProfile::new(8, DeviceGeneration::Legacy));+}++#[uzu_test]+fn size_derives_from_core_count() {+ // M1 Max ships in two bins that straddle the cutoff, on identical silicon.+ assert_eq!(classify_device(24, false, false, false).size(), DeviceSize::Small);+ assert_eq!(classify_device(32, false, false, false).size(), DeviceSize::Large);+ assert_eq!(classify_device(8, false, false, false).gpu_core_count(), 8);+}diff --git a/crates/backend-uzu/tests/unit/backends/metal/device_tier_test.rs b/crates/backend-uzu/tests/unit/backends/metal/device_tier_test.rsdeleted file mode 100644index 780535713..000000000--- a/crates/backend-uzu/tests/unit/backends/metal/device_tier_test.rs+++ /dev/null@@ -1,11 +0,0 @@-use proc_macros::uzu_test;--use super::*;--#[uzu_test]-fn device_tier_detection() {- assert_eq!(device_tier_for(40, true, true), DeviceTier::Large);- assert_eq!(device_tier_for(20, true, true), DeviceTier::SmallApple9);- assert_eq!(device_tier_for(10, true, false), DeviceTier::SmallApple8);- assert_eq!(device_tier_for(8, false, false), DeviceTier::SmallLegacy);-}diff --git a/crates/backend-uzu/tests/unit/backends/metal/kernel/matmul/gemv/policy_test.rs b/crates/backend-uzu/tests/unit/backends/metal/kernel/matmul/gemv/policy_test.rsindex 21e77352c..e842f4ee8 100644--- a/crates/backend-uzu/tests/unit/backends/metal/kernel/matmul/gemv/policy_test.rs+++ b/crates/backend-uzu/tests/unit/backends/metal/kernel/matmul/gemv/policy_test.rs@@ -1,22 +1,33 @@use proc_macros::uzu_test;use super::*;+use crate::backends::metal::device_profile::DeviceGeneration;++const LARGE: DeviceProfile = DeviceProfile::new(40, DeviceGeneration::Apple9);+const SMALL_APPLE9: DeviceProfile = DeviceProfile::new(10, DeviceGeneration::Apple9);+const SMALL_APPLE8: DeviceProfile = DeviceProfile::new(10, DeviceGeneration::Apple8);+const SMALL_LEGACY: DeviceProfile = DeviceProfile::new(8, DeviceGeneration::Legacy);+const SMALL_M5: DeviceProfile = DeviceProfile::new(10, DeviceGeneration::M5Plus);+/// 32-core M1 Max: Legacy generation on a Large die, so the G13 rules must not fire.+const LARGE_LEGACY: DeviceProfile = DeviceProfile::new(32, DeviceGeneration::Legacy);#[uzu_test]fn fp_policy_cases() {#[rustfmt::skip]let cases = [- (DeviceTier::Large, 1, 12288, 1536, true, tile(8, 8, 1)),- (DeviceTier::Large, 1, 12288, 1536, false, tile(8, 1, 1)),- (DeviceTier::Large, 1, 1536, 256, true, tile(8, 1, 1)),- (DeviceTier::SmallApple9, 1, 1536, 256, true, tile(8, 2, 1)),- (DeviceTier::Large, 8, 12288, 1536, true, tile(8, 1, 4)),- (DeviceTier::Large, 1, 1536, 12288, true, tile(8, 8, 4)),- (DeviceTier::SmallLegacy, 1, 262144, 1536, true, tile(8, 1, 4)),+ (LARGE, 1, 12288, 1536, true, tile(8, 8, 1)),+ (LARGE, 1, 12288, 1536, false, tile(8, 1, 1)),+ (LARGE, 1, 1536, 256, true, tile(8, 1, 1)),+ (SMALL_APPLE9, 1, 1536, 256, true, tile(8, 2, 1)),+ (LARGE, 8, 12288, 1536, true, tile(8, 1, 4)),+ (LARGE, 1, 1536, 12288, true, tile(8, 8, 4)),+ (SMALL_LEGACY, 1, 262144, 1536, true, tile(8, 1, 4)),+ (LARGE_LEGACY, 1, 262144, 1536, true, tile(8, 8, 1)),+ (LARGE_LEGACY, 1, 6144, 1536, true, tile(8, 8, 1)),];- for (tier, m, n, k, aligned, expected) in cases {- assert_eq!(fp_tile(m, n, k, aligned, tier), expected, "tier={tier:?} m={m} n={n} k={k}");+ for (profile, m, n, k, aligned, expected) in cases {+ assert_eq!(fp_tile(m, n, k, aligned, profile), expected, "profile={profile:?} m={m} n={n} k={k}");}}@@ -24,18 +35,25 @@ fn fp_policy_cases() {fn quant_policy_cases() {#[rustfmt::skip]let cases = [- (DeviceTier::Large, 1, 256, 1536, 4, false, qtile(2, 1)),- (DeviceTier::Large, 1, 262144, 1536, 4, false, DEFAULT_TILE),- (DeviceTier::SmallApple9, 1, 1536, 256, 4, false, qtile(4, 4)),- (DeviceTier::SmallApple8, 1, 2048, 1536, 4, false, qtile(8, 2)),- (DeviceTier::SmallLegacy, 1, 256, 1536, 4, false, qtile(8, 2)),- (DeviceTier::SmallLegacy, 1, 1536, 256, 4, false, qtile(4, 8)),- (DeviceTier::Large, 2, 2048, 1536, 4, false, DEFAULT_TILE),- (DeviceTier::Large, 1, 2048, 1536, 8, false, DEFAULT_TILE),- (DeviceTier::Large, 1, 2560, 9216, 4, true, qtile(4, 8)),+ (LARGE, 1, 256, 1536, 4, false, qtile(2, 1)),+ (LARGE, 1, 262144, 1536, 4, false, DEFAULT_TILE),+ (SMALL_APPLE9, 1, 1536, 256, 4, false, qtile(4, 4)),+ (SMALL_APPLE8, 1, 2048, 1536, 4, false, qtile(8, 2)),+ (SMALL_LEGACY, 1, 256, 1536, 4, false, qtile(8, 2)),+ (SMALL_LEGACY, 1, 1536, 256, 4, false, qtile(4, 8)),+ (LARGE, 2, 2048, 1536, 4, false, DEFAULT_TILE),+ (LARGE, 1, 2048, 1536, 8, false, DEFAULT_TILE),+ (LARGE, 1, 2560, 9216, 4, true, qtile(4, 8)),+ // Small M5 dies classified as SmallApple9 before the split; keep those rows.+ (SMALL_M5, 1, 1536, 256, 4, false, qtile(4, 4)),+ (SMALL_M5, 1, 256, 1536, 4, false, qtile(4, 2)),];- for (tier, m, n, k, bits, has_rht, expected) in cases {- assert_eq!(quant_tile(m, n, k, bits, has_rht, tier), expected, "tier={tier:?} m={m} n={n} k={k} bits={bits}");+ for (profile, m, n, k, bits, has_rht, expected) in cases {+ assert_eq!(+ quant_tile(m, n, k, bits, has_rht, profile),+ expected,+ "profile={profile:?} m={m} n={n} k={k} bits={bits}"+ );}}