Module dispatch

Module dispatch 

Source
Expand description

Kernel dispatch table - Zero-cost runtime dispatch system

Este módulo implementa un sistema de dispatch que:

  1. Se inicializa UNA VEZ al startup
  2. Valida qué backends están disponibles (incluyendo WebGPU)
  3. Crea function pointers para cada operación
  4. El hot-path solo hace dispatch_table.matmul(a, b) sin branches

Arquitectura:

Startup:
  - Detectar capabilities (SIMD, GPU, BLAS, WebGPU)
  - Validar cada backend (GPU probe, BLAS test call)
  - Elegir mejor implementación por operación
  - Guardar function pointers en DispatchTable

Runtime:
  - get_dispatch_table() → &'static DispatchTable
  - table.add(a, b) → llama directamente al kernel elegido
  - ZERO overhead (direct call, no match/if)

Re-exports§

pub use get_dispatch_table as table;

Structs§

BackendValidation
Resultados de validación de backends
DispatchTable
Dispatch table con function pointers seleccionados al startup. Todos los campos son public para acceso directo sin getter overhead.
RuntimeCapabilities
Runtime-detected capabilities (features realmente disponibles en el sistema)

Functions§

dispatch_elementwise_generic
Dispatch genérico para operaciones elementwise que mantiene el tipo nativo
get_backend_override
Obtener el backend override actual
get_dispatch_table
Obtiene el dispatch table (inicializa si es necesario)
init_dispatch_table
Inicializa el dispatch table (llamar al startup)
kernel_elementwise_simd
Kernel elementwise usando SIMD
kernel_matmul_blas_direct
Kernel matmul usando BLAS directo (sin decisiones internas)
kernel_matmul_metal
Kernel matmul usando Metal (macOS only)
kernel_matmul_scalar
Kernel matmul usando scalar (siempre disponible)
kernel_matmul_simd
Kernel matmul usando SIMD
kernel_matmul_webgpu
Kernel matmul usando WebGPU
kernel_reduction_simd
Kernel reduction usando SIMD
select_kernels
Estrategia de selección basada en validation + benchmarks opcionales
set_backend_override
Forzar un backend específico (para benchmarking) Valores válidos: “scalar”, “simd”, “blas”, “webgpu”, “metal” Usar None para restaurar comportamiento adaptativo
validate_backends
Valida que cada backend realmente funciona (no solo que está compilado)

Type Aliases§

DotFn
Signature para dot product (retorna scalar)
ElementwiseFn
Signature para kernels elementwise (add, mul, etc)
MatmulFn
Signature para matmul
ReductionFn
Signature para kernels de reducción (sum, mean, max, min, etc)