A high-performance inference engine for AI models
switch to generic apis (#183)
uuuvn5c55f1f0cba4
diff --git a/crates/uzu/build/metal/bindgen.rs b/crates/uzu/build/metal/bindgen.rsindex 89dba2a53..e021590e6 100644--- a/crates/uzu/build/metal/bindgen.rs+++ b/crates/uzu/build/metal/bindgen.rs@@ -295,7 +295,7 @@ pub fn bindgen(fn new(context: &MTLContext #(, #variants_extra_arguments)* #(, #specialize_args)*) -> Result<Self, MTLError> {#function_constants_init- let pipeline = context.library.compute_pipeline_state(#variants_kernel_format, #function_constants_arg)?;+ let pipeline = context.compute_pipeline_state(#variants_kernel_format, #function_constants_arg)?;Ok(Self { pipeline #(, #conditional_buffer_sets)* })}diff --git a/crates/uzu/build/metal/compiler.rs b/crates/uzu/build/metal/compiler.rsindex e32620491..08ef2e71b 100644--- a/crates/uzu/build/metal/compiler.rs+++ b/crates/uzu/build/metal/compiler.rs@@ -293,7 +293,7 @@ impl MetalCompiler {MTLSize,ProtocolObject,Retained,- metal_extensions::{ComputeEncoderConditional, LibraryPipelineExtensions},+ metal_extensions::ComputeEncoderConditional,};use metal::{MTLBuffer, MTLComputeCommandEncoder, MTLComputePipelineState};diff --git a/crates/uzu/src/backends/metal/classifier_context.rs b/crates/uzu/src/backends/metal/classifier_context.rsindex a39f5db70..dcdbf7f0a 100644--- a/crates/uzu/src/backends/metal/classifier_context.rs+++ b/crates/uzu/src/backends/metal/classifier_context.rs@@ -1,7 +1,7 @@use std::{cell::RefCell, fs::File, io::BufReader, path::Path, rc::Rc};use super::{- MTLCommandBuffer, MTLCommandQueue, MTLContext, ProtocolObject, Retained,+ MTLCommandBuffer, MTLContext, ProtocolObject, Retained,encodable_block::{Activation, ClassifierLayer, ClassifierPredictionHead, Normalization, Pooling, Rope,transformer_layer::{embed_block, linear_block},@@ -318,7 +318,6 @@ impl ClassifierContext {}pub fn reset_command_buffer(&mut self) {- self.command_buffer =- self.mtl_context.command_queue.command_buffer().expect("Failed to create command buffer").to_owned();+ self.command_buffer = self.mtl_context.create_command_buffer().expect("Failed to create command buffer");}}diff --git a/crates/uzu/src/backends/metal/context.rs b/crates/uzu/src/backends/metal/context.rsindex 40169a5af..18b22e98f 100644--- a/crates/uzu/src/backends/metal/context.rs+++ b/crates/uzu/src/backends/metal/context.rs@@ -125,8 +125,8 @@ impl DeviceArchitecture {pub struct MTLContext {pub device: Retained<ProtocolObject<dyn MTLDevice>>,pub command_queue: Retained<ProtocolObject<dyn MTLCommandQueue>>,- pub architecture: DeviceArchitecture,- pub library: Retained<ProtocolObject<dyn MTLLibrary>>,+ architecture: DeviceArchitecture,+ library: Retained<ProtocolObject<dyn MTLLibrary>>,pipeline_cache: RefCell<HashMap<String, Retained<ProtocolObject<dyn MTLComputePipelineState>>>>,allocator: Allocator<Metal>,}diff --git a/crates/uzu/src/backends/metal/kernel/matmul/gemm/dispatch_descriptor.rs b/crates/uzu/src/backends/metal/kernel/matmul/gemm/dispatch_descriptor.rsindex 47fb00a6c..8b8d5b61b 100644--- a/crates/uzu/src/backends/metal/kernel/matmul/gemm/dispatch_descriptor.rs+++ b/crates/uzu/src/backends/metal/kernel/matmul/gemm/dispatch_descriptor.rs@@ -131,7 +131,7 @@ fn select_tile(};}- match context.architecture.device_class {+ match context.device_class() {DeviceClass::Integrated | DeviceClass::Phone | DeviceClass::Unknown(_) => {if prefer_half_or_tf32 {if !arguments.transpose_a && arguments.transpose_b {diff --git a/crates/uzu/src/backends/metal/language_model_generator_context.rs b/crates/uzu/src/backends/metal/language_model_generator_context.rsindex af2d74154..45644d881 100644--- a/crates/uzu/src/backends/metal/language_model_generator_context.rs+++ b/crates/uzu/src/backends/metal/language_model_generator_context.rs@@ -15,7 +15,7 @@ use crate::{kernel::{MaskUpdateKernel, TokenCopySampledKernel, TokenCopyToResultsKernel},},metal::{- MTLBuffer, MTLCommandBuffer, MTLCommandQueue, MTLDeviceExt, MTLEvent, ProtocolObject, Retained,+ MTLBuffer, MTLCommandBuffer, MTLDeviceExt, MTLEvent, ProtocolObject, Retained,kernel::dsl::{MaskUpdateMetalKernel, TokenCopySampledMetalKernel, TokenCopyToResultsMetalKernel},},},@@ -256,7 +256,6 @@ impl LanguageModelGeneratorContext {}pub fn reset_command_buffer(&mut self) {- self.command_buffer =- self.mtl_context.command_queue.command_buffer().expect("Failed to create command buffer").to_owned();+ self.command_buffer = self.mtl_context.create_command_buffer().expect("Failed to create command buffer");}}diff --git a/crates/uzu/src/language_model/language_model_generator.rs b/crates/uzu/src/language_model/language_model_generator.rsindex affec9213..47cfafa81 100644--- a/crates/uzu/src/language_model/language_model_generator.rs+++ b/crates/uzu/src/language_model/language_model_generator.rs@@ -12,11 +12,11 @@ use super::{};use crate::{backends::{- common::kernel::{MaskUpdateKernel, TokenCopySampledKernel, TokenCopyToResultsKernel},- metal::{- MTLBuffer, MTLCommandBuffer, MTLCommandBufferExt, MTLCommandBufferHandler, MTLCommandEncoder,- MTLCommandQueue, Metal,+ common::{+ Context,+ kernel::{MaskUpdateKernel, TokenCopySampledKernel, TokenCopyToResultsKernel},},+ metal::{MTLBuffer, MTLCommandBuffer, MTLCommandBufferExt, MTLCommandBufferHandler, MTLCommandEncoder, Metal},},encodable_block::{EncodableBlock, EncodingParameters},forward_pass::{@@ -702,13 +702,7 @@ impl LanguageModelGenerator {suffix_start: Option<usize>,wait_until_completed: bool,) {- let command_buffer = self- .context- .mtl_context- .command_queue- .command_buffer()- .expect("Failed to create command buffer")- .to_owned();+ let command_buffer = self.context.mtl_context.create_command_buffer().expect("Failed to create command buffer");let root_command_buffer = command_buffer.to_owned();{