A bounded Tensor matrix stress test
Repeat matched CPU and available accelerator matrix products with explicit synchronization, device metadata, and numerical agreement checks.
Download .aner source// Bounded Tensor stress. Use aner_gpu_benchmark for synchronized measurements.
// Increase repetitions deliberately; dimensions stay below Tensor/work limits.
import aner.nn
import aner.dev
fn stress(device: String) {
nn.require_device(device)
let left = nn.random(256, 256, seed: 2026, scale: 0.1)
.astype(dtype: "Float32").to(device: device)
let right = nn.random(256, 256, seed: 2027, scale: 0.1)
.astype(dtype: "Float32").to(device: device)
var output = nn.matmul(left, right)
var iteration = 0
while iteration < 10 {
output = nn.matmul(left, right)
iteration = iteration + 1
}
nn.synchronize(device)
print(device)
print(output.dtype())
print(output.backend())
print(nn.item(nn.mean(output)))
dev.capture("resident matrix product", output)
}
print(nn.devices())
stress("cpu")
if nn.device_available("mps") { stress("mps") }
if nn.device_available("cuda") { stress("cuda") }
Make it your experiment.
With Aner installed, save this program as examples/tensor_gpu_stress.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/tensor_gpu_stress.aner
aner run examples/tensor_gpu_stress.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Use the updated native Aner interpreter and VS Code extension 0.1.29 or newer. CPU is always available; MPS requires a compatible macOS Metal build, and CUDA requires a compatible NVIDIA driver and CUDA enabled Aner build. Explicit GPU Tensor transfer requires Float32. These examples query availability and label unavailable backends as skipped. See Tensor devices and performance for prerequisites, synchronization, complexity, and matched measurements.
Iris and Wine are teaching datasets with their own attribution. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution