Expand description
§Borsalino — Thin GPU Compute Abstraction
One trait, two backends, zero ceremony.
Borsalino provides a minimal synchronous GPU compute interface for the Industrial Algebra ecosystem. Write WGSL compute kernels, dispatch them on Metal or Vulkan hardware, read the results back — no bind groups, no pipeline layouts, no descriptor sets.
§Design
- Synchronous:
dispatch()blocks until the GPU finishes. No async runtime, no callback hell, no completion handlers. - WGSL-first: Kernels are authored in WGSL (WebGPU Shading Language). The Metal backend translates to MSL via naga; the Vulkan backend translates to SPIR-V via naga.
- Minimal surface area: Four operations — create buffers, compile shaders, dispatch, read results. That’s it.
- Zero-cost abstraction: No allocation, no validation, no safety checks beyond what the GPU driver provides.
§Quick Start
ⓘ
use borsalino::GpuBackend;
// WGSL compute kernel
let wgsl = r#"
@group(0) @binding(0) var<storage, read> input: array<f32>;
@group(0) @binding(1) var<storage, read_write> output: array<f32>;
@compute @workgroup_size(256)
fn add_one(@builtin(global_invocation_id) gid: vec3<u32>) {
let i = gid.x;
output[i] = input[i] + 1.0;
}
"#;
let mut gpu = borsalino::init()?;
let pipeline = gpu.compile("add_one", wgsl)?;
let input = gpu.create_buffer(&[1.0f32, 2.0, 3.0, 4.0])?;
let output = gpu.create_buffer_uninit::<f32>(4)?;
gpu.dispatch(&pipeline, &[&input, &output], (1, 1, 1))?;
let result = gpu.read_buffer(&output)?;
assert_eq!(result, vec![2.0, 3.0, 4.0, 5.0]);§Backends
| Feature | Platform | Status |
|---|---|---|
metal | macOS | ✅ Active |
vulkan | Linux, Windows | ✅ Active |
The Metal backend requires no external dependencies beyond naga —
it calls the Metal framework directly via objc_msgSend.
The Vulkan backend uses ash for raw Vulkan FFI.
§Safety
The GPU driver layer uses unsafe for FFI. The public API is
safe — buffer bounds are checked, shader compilation errors
are surfaced as GpuError, and dispatch parameters are validated
before hitting the driver.
Structs§
- Compute
Pipeline - Handle to a compiled compute pipeline.
- Dispatch
Spec - Spec for a single dispatch within
GpuBackend::dispatch_many. - GpuBuffer
- Handle to a GPU buffer.
- NoBackend
Stub - Stub backend — no GPU backend compiled for this target.
- Pulse
- Handle to an in-flight asynchronous dispatch.
Enums§
- GpuError
- Errors that can occur in GPU operations.
- Memory
Strategy - Memory allocation strategy for GPU buffers.
Traits§
- GpuBackend
- Backend-agnostic GPU compute interface.
Functions§
- init
- Stub backend — returned by
init()when no GPU backend is available. Exists solely to giveResult<impl GpuBackend>a concrete type in the fallback compilation path.
Type Aliases§
- Result
- Result type alias for Borsalino operations.