viva_tensor/optim/backend
Auto-Backend Selector - Smart tensor backend selection
Automatically chooses optimal backend (list vs strided) based on:
- Operation type (sequential, random access, matrix)
- Tensor size
- User configuration
Benchmarked on RTX 4090 + BEAM VM
Types
Operation type for backend selection
pub type OperationType {
Sequential
RandomAccess
MatrixOp
}
Constructors
-
SequentialSequential operations - better with lists (dot, sum, reduce)
-
RandomAccessRandom access operations - better with strided (get, get2d, indexing)
-
MatrixOpMatrix operations - strided for large, lists for small (matmul)
Configuration for automatic backend selection
pub type TensorConfig {
TensorConfig(
strided_threshold_random: Int,
strided_threshold_matmul: Int,
force_strided: Bool,
force_list: Bool,
)
}
Constructors
-
TensorConfig( strided_threshold_random: Int, strided_threshold_matmul: Int, force_strided: Bool, force_list: Bool, )Arguments
- strided_threshold_random
-
Minimum size to use strided for random access (default: 500)
- strided_threshold_matmul
-
Minimum size to use strided for matmul (default: 64 = 8x8)
- force_strided
-
Force strided for all operations (override)
- force_list
-
Force list for all operations (override)
Values
pub fn default_config() -> TensorConfig
Default configuration based on benchmarks
pub fn ensure_optimal(
t: tensor.Tensor,
op: OperationType,
config: TensorConfig,
) -> tensor.Tensor
Ensure tensor is in optimal format for operation
pub fn for_indexing(t: tensor.Tensor) -> tensor.Tensor
Auto-optimize tensor for indexing
pub fn for_reduction(t: tensor.Tensor) -> tensor.Tensor
Auto-optimize tensor for reduction operations
pub fn gpu_config() -> TensorConfig
GPU-optimized config (always strided for batched ops)
pub fn performance_config() -> TensorConfig
High-performance config (prefer strided for large tensors)
pub fn should_use_strided(
t: tensor.Tensor,
op: OperationType,
config: TensorConfig,
) -> Bool
Check if should use strided backend for given operation