//go:build !cuda // Package compute provides device-agnostic computation dispatching. package compute import ( "fmt" "makarna/pkg/backend/cpu" "makarna/pkg/backend/cpu/matmul" "makarna/pkg/tensor" ) // Linear performs a linear layer: output = input @ weight.T // CPU-only build: always uses CPU path. func Linear(ctx *Context, input, weight, output tensor.Tensor) error { return linearCPU(input, weight, output) } // linearCPU executes matmul on CPU func linearCPU(input, weight, output tensor.Tensor) error { inCPU, ok := input.(*cpu.Tensor) if !ok { var err error inCPU, err = ToCPU(input) if err != nil { return fmt.Errorf("linear: failed to get CPU input: %w", err) } } wCPU, ok := weight.(*cpu.Tensor) if !ok { return fmt.Errorf("linear: weight must be CPU tensor for CPU path") } outCPU, ok := output.(*cpu.Tensor) if !ok { return fmt.Errorf("linear: output must be CPU tensor for CPU path") } return matmul.Linear(inCPU, wCPU, outCPU) }