diff --git a/architecture-baseline.json b/architecture-baseline.json index 7e9fa926..43518773 100644 --- a/architecture-baseline.json +++ b/architecture-baseline.json @@ -49,7 +49,7 @@ "dyn-trait:leleka-deploy": 17, "dyn-trait:leleka-engine-core": 18, "dyn-trait:leleka-engine-fake": 1, - "dyn-trait:leleka-engine-qwen35-cuda": 52, + "dyn-trait:leleka-engine-qwen35-cuda": 51, "dyn-trait:leleka-experimental-ref": 3, "dyn-trait:leleka-gateway-domain": 5, "dyn-trait:leleka-gptoss": 10, diff --git a/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch.rs b/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch.rs index 8b30f20c..a5441491 100644 --- a/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch.rs +++ b/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch.rs @@ -21,6 +21,9 @@ const ALPHA_BETA: usize = 96; const BATCH_RESERVE: usize = 128 * 1024 * 1024; const EAGER_TOKENS: usize = 64; /// Largest dequantized GDN matrix (attn_qkv, 10240 x 2560) in FP16 bytes. +/// The shared exclusively loaned GEMM adapter every batched step receives. +type GemmRef<'a> = &'a dyn GdnGemm; + pub(in crate::qwen_forward) const BATCH_SCRATCH_BYTES: usize = CHANNELS * MIXED * 2; /// BF16 alpha/beta GEMM profile. `HighOnly` is the original default diff --git a/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch/impl_gdnstage.rs b/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch/impl_gdnstage.rs index 6f3abeb9..28674fec 100644 --- a/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch/impl_gdnstage.rs +++ b/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch/impl_gdnstage.rs @@ -26,7 +26,7 @@ impl GdnStage { cache: &DenseWeightCache<'ctx>, owner: &mut GdnChunkDevice<'ctx>, resources: &mut GdnBatchResources<'ctx>, - gemm: &dyn GdnGemm, + gemm: GemmRef<'_>, ) -> Result> { #[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] let _owner_wall_scope = diff --git a/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch/step_batch_fns.rs b/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch/step_batch_fns.rs index cacc106f..295e0552 100644 --- a/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch/step_batch_fns.rs +++ b/crates/engine-qwen35-cuda/src/qwen_forward/gdn_prefill_batch/step_batch_fns.rs @@ -155,7 +155,7 @@ pub(super) fn window_bytes<'a, 'ctx>( /// Upload, run the closed GDN program and read back the next history and the Out projection. pub(super) fn run_gdn_program<'ctx>( resources: &mut GdnBatchResources<'ctx>, - gemm: &dyn GdnGemm, + gemm: GemmRef<'_>, tokens: usize, ops: &GdnOperands<'_, 'ctx>, bytes: &WindowBytes<'_, 'ctx>, diff --git a/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch.rs b/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch.rs index 7104c495..7b725f73 100644 --- a/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch.rs +++ b/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch.rs @@ -21,6 +21,9 @@ use leleka_cuda_driver::{ MoeRouteBatch, }; +/// The shared exclusively loaned GEMM adapter every batched step receives. +type GemmRef<'a> = &'a dyn GdnGemm; + const MIXED: usize = 2560; const EXPERTS: usize = 512; const SELECTED: usize = 10; diff --git a/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch/impl_moeprefillstage.rs b/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch/impl_moeprefillstage.rs index da6da20d..be03bec2 100644 --- a/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch/impl_moeprefillstage.rs +++ b/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch/impl_moeprefillstage.rs @@ -27,7 +27,7 @@ impl MoePrefillStage { weights: SharedWeights<'_, 'ctx>, combine: Option>, resources: &mut MoePrefillResources<'ctx>, - gemm: &dyn GdnGemm, + gemm: GemmRef<'_>, ) -> Result> { resources.validate_context(current)?; let plan = validate_micro(binding, layer, reads, router, &weights, combine.as_ref())?; @@ -64,7 +64,7 @@ impl MoePrefillStage { products: &mut MoeMicroProducts<'ctx>, combine: CombineInput<'_, 'ctx>, resources: &mut MoePrefillResources<'ctx>, - gemm: &dyn GdnGemm, + gemm: GemmRef<'_>, ) -> Result<()> { resources.validate_context(current)?; let tokens = check_combine_window(binding, layer, expected, products, &combine)?; diff --git a/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch/route_micro_fns.rs b/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch/route_micro_fns.rs index caec9848..269d36bc 100644 --- a/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch/route_micro_fns.rs +++ b/crates/engine-qwen35-cuda/src/qwen_forward/moe_prefill_batch/route_micro_fns.rs @@ -123,7 +123,7 @@ fn check_shared(weights: &SharedWeights<'_, '_>, layer: LayerId) -> Result<[GdnN pub(super) fn route_on_device<'ctx>( mut buffers: Buffers<'ctx>, resources: &mut MoePrefillResources<'ctx>, - gemm: &dyn GdnGemm, + gemm: GemmRef<'_>, inputs: &MicroInputs<'_, 'ctx>, mixed_bytes: &[u8], ) -> Result<(Buffers<'ctx>, MoeRouteBatch)> { @@ -139,7 +139,7 @@ pub(super) fn route_on_device<'ctx>( fn launch_route<'ctx>( buffers: &mut Buffers<'ctx>, resources: &mut MoePrefillResources<'ctx>, - gemm: &dyn GdnGemm, + gemm: GemmRef<'_>, inputs: &MicroInputs<'_, 'ctx>, mixed_bytes: &[u8], ) -> Result { @@ -267,7 +267,7 @@ pub(super) fn combine_on_device<'ctx>( resources: &mut MoePrefillResources<'ctx>, products: &MoeMicroProducts<'ctx>, tokens: usize, - gemm: &dyn GdnGemm, + gemm: GemmRef<'_>, combine: &CombineInput<'_, 'ctx>, bo: &DeviceBuffer<'ctx>, ) -> Result<()> {