A high-performance inference engine for AI models
argmax shared struct (#225)
uuuvnb50da5e3cd28
diff --git a/crates/uzu/src/backends/common/gpu_types/argmax.rs b/crates/uzu/src/backends/common/gpu_types/argmax.rsnew file mode 100644index 000000000..cd5f06874--- /dev/null+++ b/crates/uzu/src/backends/common/gpu_types/argmax.rs@@ -0,0 +1,6 @@+#[repr(C)]+#[derive(Debug, Clone, Copy)]+pub struct ArgmaxPair {+ pub value: f32,+ pub index: u32,+}diff --git a/crates/uzu/src/backends/common/gpu_types/mod.rs b/crates/uzu/src/backends/common/gpu_types/mod.rsindex a6ba1de5c..8d996182d 100644--- a/crates/uzu/src/backends/common/gpu_types/mod.rs+++ b/crates/uzu/src/backends/common/gpu_types/mod.rs@@ -3,10 +3,12 @@//! These `#[repr(C)]` structs are the source of truth. The build system uses//! cbindgen to generate C headers for Metal shaders.+pub mod argmax;pub mod attention;pub mod kv_cache_update;pub mod matmul;+pub use argmax::*;pub use attention::*;pub use kv_cache_update::*;pub use matmul::*;diff --git a/crates/uzu/src/backends/common/kernel/sampling.rs b/crates/uzu/src/backends/common/kernel/sampling.rsindex f6fd5356b..eb62dc628 100644--- a/crates/uzu/src/backends/common/kernel/sampling.rs+++ b/crates/uzu/src/backends/common/kernel/sampling.rs@@ -7,6 +7,7 @@ use crate::{DataType,backends::common::{Context,+ gpu_types::ArgmaxPair,kernel::{ArgmaxFinalKernel, ArgmaxMainKernel, ArgmaxSingleKernel, BitmaskKernel, GumbelKernel, MinPKernel,TemperatureKernel, TopKKernel, TopPKernel,@@ -21,22 +22,6 @@ pub enum ArgmaxStrategy {TwoPass, // Two-stage reduction}-#[repr(C)]-#[derive(Debug, Clone, Copy)]-struct ArgmaxPair {- value: f32,- index: u32,-}--impl Default for ArgmaxPair {- fn default() -> Self {- Self {- value: f32::NEG_INFINITY,- index: u32::MAX,- }- }-}-enum ArgmaxImplementation<B: Backend> {SinglePass {kernel: <B::Kernels as Kernels>::ArgmaxSingleKernel,diff --git a/crates/uzu/src/backends/metal/generated/argmax.h b/crates/uzu/src/backends/metal/generated/argmax.hnew file mode 100644index 000000000..8b9bcde16--- /dev/null+++ b/crates/uzu/src/backends/metal/generated/argmax.h@@ -0,0 +1,27 @@+// Auto-generated from gpu_types/argmax.rs - do not edit manually+#pragma once++#ifndef UZU_ARGMAX_H+#define UZU_ARGMAX_H++#ifdef __METAL_VERSION__+#include <metal_stdlib>+using namespace metal;++namespace uzu {+namespace argmax {+#else+#include <stdint.h>+#endif++typedef struct {+ float value;+ uint32_t index;+} ArgmaxPair;++#ifdef __METAL_VERSION__+} // namespace argmax+} // namespace uzu+#endif++#endif // UZU_ARGMAX_Hdiff --git a/crates/uzu/src/backends/metal/kernel/sampling/argmax.metal b/crates/uzu/src/backends/metal/kernel/sampling/argmax.metalindex 3cff521c7..a72dd6f4d 100644--- a/crates/uzu/src/backends/metal/kernel/sampling/argmax.metal+++ b/crates/uzu/src/backends/metal/kernel/sampling/argmax.metal@@ -2,13 +2,12 @@#include <metal_atomic>#include "../definitions.metal"+#include "argmax.h"+#define BLOCK_SIZE 1024#define GRAIN_SIZE 4-struct ArgmaxPair {- float value;- uint index;-};+using namespace uzu::argmax;constant ArgmaxPair ARGMAX_INIT = {-INFINITY, UINT_MAX};