#tile
Xu 0.13.1 API
import: #tile
counts: 33 functions, 0 methods, 5 types, 16 constants, 0 method sets
Explicit 1D/2D tile movement, reduction, and matrix multiplication primitives. On hosted arm64 and x64 targets at -O1+, `gemm_i64` and canonical 1D loops are automatically lowered by `MirTilePlan` (`tile_gemm`) and the whole-loop SIMD matchers into L1-blocked 2D register-tile and vector micro-kernels; all other targets and -O0 execute the portable reference loops below with identical bounds and wrapping semantics. Submodules dlpack.xu: DLPack v0.8+ C-ABI compliant tensor descriptor and zero-copy view (TVM-FFI). profile.xu: Microarchitecture cache-hierarchy tuning profiles and dynamic tile bounds (TransTuning / MetaSchedule). lut.xu: Table Lookup GEMM (LUT-GEMM) for low-bit u4/s4/u2 weights (T-MAC). pipe.xu: Pipelined operator fusion and online algebraic softmax reduction (Neptune).
gemm_i64
pub fn gemm_i64(c $&[]int, a &[]int, b &[]int, m int, n int, k int)
Purpose
2D integer matrix multiply-accumulate C[m x n] += A[m x k] * B[k x n]
Parameters
c $&[]int- byte or character code (exclusive borrow; may modify the original; type $&[]int)
a &[]int- slice to operate on (read-only borrow; caller keeps the original; type &[]int)
b &[]int- slice to operate on (read-only borrow; caller keeps the original; type &[]int)
m int- m (int)
n int- count, length, or limit (int)
k int- key or index (int)
Returns
This call does not return a value.
gemm_f64
pub fn gemm_f64(c $&[]f64, a &[]f64, b &[]f64, m int, n int, k int)
Purpose
2D double-precision matrix multiply-accumulate C[m x n] += A[m x k] * B[k x n]
Parameters
c $&[]f64- byte or character code (exclusive borrow; may modify the original; type $&[]f64)
a &[]f64- slice to operate on (read-only borrow; caller keeps the original; type &[]f64)
b &[]f64- slice to operate on (read-only borrow; caller keeps the original; type &[]f64)
m int- m (int)
n int- count, length, or limit (int)
k int- key or index (int)
Returns
This call does not return a value.
madd_i64
pub fn madd_i64(c $&[]int, off_c int, b &[]int, off_b int, factor int, len int)
Purpose
1D tile multiply-accumulate c[off_c + j] += factor * b[off_b + j] for j in 0:len
Parameters
c $&[]int- byte or character code (exclusive borrow; may modify the original; type $&[]int)
off_c int- off_c (int)
b &[]int- slice to operate on (read-only borrow; caller keeps the original; type &[]int)
off_b int- off_b (int)
factor int- factor (int)
len int- len (int)
Returns
This call does not return a value.
fill_i64
pub fn fill_i64(dst $&[]int, val int, len int)
Purpose
1D tile fill dst[j] = val for j in 0:len
Parameters
dst $&[]int- destination (exclusive borrow; may modify the original; type $&[]int)
val int- value (int)
len int- len (int)
Returns
This call does not return a value.
copy_i64
pub fn copy_i64(dst $&[]int, src &[]int, len int)
Purpose
1D tile copy dst[j] = src[j] for j in 0:len
Parameters
dst $&[]int- destination (exclusive borrow; may modify the original; type $&[]int)
src &[]int- source (read-only borrow; caller keeps the original; type &[]int)
len int- len (int)
Returns
This call does not return a value.
sum_i64
pub fn sum_i64(src &[]int, len int) int
Purpose
1D tile reduction sum sum(src[0:len])
Parameters
src &[]int- source (read-only borrow; caller keeps the original; type &[]int)
len int- len (int)
Returns
int — a value of this type
const DL_DEVICE_CPU
pub const DL_DEVICE_CPU = 1
Purpose
Constant DL_DEVICE_CPU, defining protocol or algorithm parameters.
const DL_DEVICE_CUDA
pub const DL_DEVICE_CUDA = 2
Purpose
Constant DL_DEVICE_CUDA, defining protocol or algorithm parameters.
const DL_DEVICE_CPU_PINNED
pub const DL_DEVICE_CPU_PINNED = 3
Purpose
Constant DL_DEVICE_CPU_PINNED, defining protocol or algorithm parameters.
const DL_DEVICE_OPENCL
pub const DL_DEVICE_OPENCL = 4
Purpose
Constant DL_DEVICE_OPENCL, defining protocol or algorithm parameters.
const DL_DEVICE_VULKAN
pub const DL_DEVICE_VULKAN = 7
Purpose
Constant DL_DEVICE_VULKAN, defining protocol or algorithm parameters.
const DL_DEVICE_METAL
pub const DL_DEVICE_METAL = 8
Purpose
Constant DL_DEVICE_METAL, defining protocol or algorithm parameters.
const DL_DEVICE_VPI
pub const DL_DEVICE_VPI = 9
Purpose
Constant DL_DEVICE_VPI, defining protocol or algorithm parameters.
const DL_DEVICE_ROCM
pub const DL_DEVICE_ROCM = 10
Purpose
Constant DL_DEVICE_ROCM, defining protocol or algorithm parameters.
const DL_DEVICE_ONEAPI
pub const DL_DEVICE_ONEAPI = 14
Purpose
Constant DL_DEVICE_ONEAPI, defining protocol or algorithm parameters.
const DL_DTYPE_INT
pub const DL_DTYPE_INT = 0
Purpose
Constant DL_DTYPE_INT, defining protocol or algorithm parameters.
const DL_DTYPE_UINT
pub const DL_DTYPE_UINT = 1
Purpose
Constant DL_DTYPE_UINT, defining protocol or algorithm parameters.
const DL_DTYPE_FLOAT
pub const DL_DTYPE_FLOAT = 2
Purpose
Constant DL_DTYPE_FLOAT, defining protocol or algorithm parameters.
const DL_DTYPE_OPAQUE
pub const DL_DTYPE_OPAQUE = 3
Purpose
Constant DL_DTYPE_OPAQUE, defining protocol or algorithm parameters.
const DL_DTYPE_BFLOAT
pub const DL_DTYPE_BFLOAT = 4
Purpose
Constant DL_DTYPE_BFLOAT, defining protocol or algorithm parameters.
const DL_DTYPE_COMPLEX
pub const DL_DTYPE_COMPLEX = 5
Purpose
Constant DL_DTYPE_COMPLEX, defining protocol or algorithm parameters.
const DL_DTYPE_BOOL
pub const DL_DTYPE_BOOL = 6
Purpose
Constant DL_DTYPE_BOOL, defining protocol or algorithm parameters.
struct DLDevice
pub struct DLDevice {
pub device_type int
pub device_id int
}
Purpose
Structure encapsulating device_type, device_id.
Public fields
device_type int- field (int)
device_id int- field (int)
struct DLDataType
pub struct DLDataType {
pub code int
pub bits int
pub lanes int
}
Purpose
Structure encapsulating code, bits, lanes.
Public fields
code int- code
bits int- bit count
lanes int- field (int)
struct DLTensor
pub struct DLTensor {
pub data_ptr int
pub device DLDevice
pub ndim int
pub dtype DLDataType
pub shape []int
pub strides []int
pub byte_offset int
}
Purpose
Structure encapsulating data_ptr, device, ndim, dtype, shape.
Public fields
data_ptr int- field (int)
device DLDevice- field (DLDevice)
ndim int- field (int)
dtype DLDataType- field (DLDataType)
shape []int- field ([]int)
strides []int- field ([]int)
byte_offset int- field (int)
dlpack_cpu_device
pub fn dlpack_cpu_device() DLDevice
Purpose
Dlpack cpu device.
Parameters
No arguments are required.
Returns
DLDevice — a value of this type
dlpack_dtype_i64
pub fn dlpack_dtype_i64() DLDataType
Purpose
Dlpack dtype i64.
Parameters
No arguments are required.
Returns
DLDataType — a value of this type
dlpack_dtype_f64
pub fn dlpack_dtype_f64() DLDataType
Purpose
Dlpack dtype f64.
Parameters
No arguments are required.
Returns
DLDataType — a value of this type
dlpack_dtype_u8
pub fn dlpack_dtype_u8() DLDataType
Purpose
Dlpack dtype u8.
Parameters
No arguments are required.
Returns
DLDataType — a value of this type
dlpack_tensor_1d
pub fn dlpack_tensor_1d(data_ptr int, length int, dtype DLDataType) DLTensor
Purpose
Dlpack tensor 1d.
Parameters
data_ptr int- data_ptr (int)
length int- length (int)
dtype DLDataType- dtype (DLDataType)
Returns
DLTensor — a value of this type
dlpack_tensor_2d
pub fn dlpack_tensor_2d(data_ptr int, m int, n int, dtype DLDataType) DLTensor
Purpose
Dlpack tensor 2d.
Parameters
data_ptr int- data_ptr (int)
m int- m (int)
n int- count, length, or limit (int)
dtype DLDataType- dtype (DLDataType)
Returns
DLTensor — a value of this type
dlpack_element_count
pub fn dlpack_element_count(t &DLTensor) int
Purpose
Dlpack element count.
Parameters
t &DLTensor- t (read-only borrow; caller keeps the original; type &DLTensor)
Returns
int — a value of this type
dlpack_byte_size
pub fn dlpack_byte_size(t &DLTensor) int
Purpose
Dlpack byte size.
Parameters
t &DLTensor- t (read-only borrow; caller keeps the original; type &DLTensor)
Returns
int — a value of this type
dlpack_validate
pub fn dlpack_validate(t &DLTensor) bool
Purpose
Dlpack validate.
Parameters
t &DLTensor- t (read-only borrow; caller keeps the original; type &DLTensor)
Returns
bool — true or false
lut_gemm_u4_reference
pub fn lut_gemm_u4_reference(c $&[]int, a &[]int, w_packed &[]int, m int, n int, k_pairs int)
Purpose
Reference dequantization matrix multiplication C[m x n] += A[m x 2*k_pairs] * W[2*k_pairs x n]
Parameters
c $&[]int- byte or character code (exclusive borrow; may modify the original; type $&[]int)
a &[]int- slice to operate on (read-only borrow; caller keeps the original; type &[]int)
w_packed &[]int- w_packed (read-only borrow; caller keeps the original; type &[]int)
m int- m (int)
n int- count, length, or limit (int)
k_pairs int- k_pairs (int)
Returns
This call does not return a value.
lut_gemm_u4
pub fn lut_gemm_u4(c $&[]int, a &[]int, w_packed &[]int, m int, n int, k_pairs int)
Purpose
Table Lookup GEMM (LUT-GEMM) Precomputes a 16-entry LUT for a0 and a1, eliminating all multiplications across the inner column accumulation loop.
Parameters
c $&[]int- byte or character code (exclusive borrow; may modify the original; type $&[]int)
a &[]int- slice to operate on (read-only borrow; caller keeps the original; type &[]int)
w_packed &[]int- w_packed (read-only borrow; caller keeps the original; type &[]int)
m int- m (int)
n int- count, length, or limit (int)
k_pairs int- k_pairs (int)
Returns
This call does not return a value.
lut_gemm_s4_reference
pub fn lut_gemm_s4_reference(c $&[]int, a &[]int, w_packed &[]int, m int, n int, k_pairs int)
Purpose
Signed 4-bit weight (-8..7) reference matrix multiplication
Parameters
c $&[]int- byte or character code (exclusive borrow; may modify the original; type $&[]int)
a &[]int- slice to operate on (read-only borrow; caller keeps the original; type &[]int)
w_packed &[]int- w_packed (read-only borrow; caller keeps the original; type &[]int)
m int- m (int)
n int- count, length, or limit (int)
k_pairs int- k_pairs (int)
Returns
This call does not return a value.
lut_gemm_s4
pub fn lut_gemm_s4(c $&[]int, a &[]int, w_packed &[]int, m int, n int, k_pairs int)
Purpose
Signed 4-bit Table Lookup GEMM
Parameters
c $&[]int- byte or character code (exclusive borrow; may modify the original; type $&[]int)
a &[]int- slice to operate on (read-only borrow; caller keeps the original; type &[]int)
w_packed &[]int- w_packed (read-only borrow; caller keeps the original; type &[]int)
m int- m (int)
n int- count, length, or limit (int)
k_pairs int- k_pairs (int)
Returns
This call does not return a value.
lut_gemm_u2_reference
pub fn lut_gemm_u2_reference(c $&[]int, a &[]int, w_packed &[]int, m int, n int, k_quads int)
Purpose
2-bit unsigned weight (0..3, four weights per byte) reference
Parameters
c $&[]int- byte or character code (exclusive borrow; may modify the original; type $&[]int)
a &[]int- slice to operate on (read-only borrow; caller keeps the original; type &[]int)
w_packed &[]int- w_packed (read-only borrow; caller keeps the original; type &[]int)
m int- m (int)
n int- count, length, or limit (int)
k_quads int- k_quads (int)
Returns
This call does not return a value.
lut_gemm_u2
pub fn lut_gemm_u2(c $&[]int, a &[]int, w_packed &[]int, m int, n int, k_quads int)
Purpose
2-bit unsigned Table Lookup GEMM
Parameters
c $&[]int- byte or character code (exclusive borrow; may modify the original; type $&[]int)
a &[]int- slice to operate on (read-only borrow; caller keeps the original; type &[]int)
w_packed &[]int- w_packed (read-only borrow; caller keeps the original; type &[]int)
m int- m (int)
n int- count, length, or limit (int)
k_quads int- k_quads (int)
Returns
This call does not return a value.
fused_saxpy_sum_i64
pub fn fused_saxpy_sum_i64(x &[]int, y &[]int, a int, len int) int
Purpose
Fused saxpy digest i64.
Parameters
x &[]int- value (read-only borrow; caller keeps the original; type &[]int)
y &[]int- value (read-only borrow; caller keeps the original; type &[]int)
a int- value (int)
len int- len (int)
Returns
int — a value of this type
fused_norm2_i64
pub fn fused_norm2_i64(x &[]int, len int) int
Purpose
Fused norm2 i64.
Parameters
x &[]int- value (read-only borrow; caller keeps the original; type &[]int)
len int- len (int)
Returns
int — a value of this type
fused_norm2_f64
pub fn fused_norm2_f64(x &[]f64, len int) f64
Purpose
Fused norm2 f64.
Parameters
x &[]f64- value (read-only borrow; caller keeps the original; type &[]f64)
len int- len (int)
Returns
f64 — a value of this type
struct OnlineSoftmaxState
pub struct OnlineSoftmaxState {
pub max_val f64
pub sum_exp f64
}
Purpose
Structure encapsulating max_val, sum_exp.
Public fields
max_val f64- field (f64)
sum_exp f64- field (f64)
online_softmax_init
pub fn online_softmax_init(init_val f64) OnlineSoftmaxState
Purpose
Online softmax init.
Parameters
init_val f64- init_val (f64)
Returns
OnlineSoftmaxState — a value of this type
online_softmax_update
pub fn online_softmax_update(state $&OnlineSoftmaxState, val f64)
Purpose
Online softmax update.
Parameters
state $&OnlineSoftmaxState- state (exclusive borrow; may modify the original; type $&OnlineSoftmaxState)
val f64- value (f64)
Returns
This call does not return a value.
online_softmax_vector
pub fn online_softmax_vector(vals &[]f64) OnlineSoftmaxState
Purpose
Online softmax vector.
Parameters
vals &[]f64- vals (read-only borrow; caller keeps the original; type &[]f64)
Returns
OnlineSoftmaxState — a value of this type
struct TileArchProfile
pub struct TileArchProfile {
pub arch_name string
pub l1d_bytes int
pub l2_bytes int
pub simd_bits int
pub pref_bm int
pub pref_bn int
pub pref_bk int
pub reg_m int
pub reg_n int
}
Purpose
Structure encapsulating arch_name, l1d_bytes, l2_bytes, simd_bits, pref_bm.
Public fields
arch_name string- field (string)
l1d_bytes int- field (int)
l2_bytes int- field (int)
simd_bits int- field (int)
pref_bm int- field (int)
pref_bn int- field (int)
pref_bk int- field (int)
reg_m int- field (int)
reg_n int- field (int)
tile_arch_generic
pub fn tile_arch_generic() TileArchProfile
Purpose
Tile arch generic.
Parameters
No arguments are required.
Returns
TileArchProfile — a value of this type
tile_arch_apple_m
pub fn tile_arch_apple_m() TileArchProfile
Purpose
Tile arch apple m.
Parameters
No arguments are required.
Returns
TileArchProfile — a value of this type
tile_arch_avx512
pub fn tile_arch_avx512() TileArchProfile
Purpose
Tile arch avx512.
Parameters
No arguments are required.
Returns
TileArchProfile — a value of this type
tile_arch_detect
pub fn tile_arch_detect() TileArchProfile
Purpose
Tile arch detect.
Parameters
No arguments are required.
Returns
TileArchProfile — a value of this type
tile_compute_blocking
pub fn tile_compute_blocking(prof &TileArchProfile, m int, n int, k int) []int
Purpose
Compute bounded tile blocking (bm, bn, bk) for a given matrix dimension (m, n, k).
Parameters
prof &TileArchProfile- prof (read-only borrow; caller keeps the original; type &TileArchProfile)
m int- m (int)
n int- count, length, or limit (int)
k int- key or index (int)
Returns
[]int — slice result
tile_working_set_fits_l1
pub fn tile_working_set_fits_l1(prof &TileArchProfile, bm int, bn int, bk int, elem_bytes int) bool
Purpose
Check if a tile working set (A_tile + B_tile + C_tile) fits within L1D cache.
Parameters
prof &TileArchProfile- prof (read-only borrow; caller keeps the original; type &TileArchProfile)
bm int- bm (int)
bn int- bn (int)
bk int- bk (int)
elem_bytes int- elem_bytes (int)
Returns
bool — true or false