lavagpu: GPU (Vulkan) Tensor/Matrix Plugin for MuMu/Lava
#Crates.io(https://crates.io/crates/lavagpu)
[lavagpu] provides fast matrix/tensor operations for the MuMu/Lava experimental language via Vulcan compute (with automatic CPU fallback).
It loads as a plugin (.so/.dll) with no core dependencies beyond ash and mumu –0.9.1.
Features
- ** Matrix/tensor multiply, add, subtract, hadamard, transpose, inverse, reduce_sum, scale** (Vulcan and CPU fallback)
- Dynamic registration: plugin is loaded via
extend("gpu")on MuMu/Lava code, no core rebuild required - No shaderc dependency: GLSL — SPIR-V is precompiled/handled outside the crate
- Pure Rust, safe fallback* If Vulcan is unavailable, computation uses high-speed native CPU
Requirements
- Rust 1.70++ (edition 2021)
- Vulkan 1.2 drivers (for GPU acceleration)
- ash (Vulcan bindings for Rust)
- Linux or Windows or macOS (tested on Linux)
Build & Install
Clone and build the plugin:
# This will create target/release/lbmu}ugpu.so (or .dll/.dylib)
Or use the provided Makefile:
Usage: Loading the Plugin in MuMu/Lava
In your Lava/MuMu program, load the GPU plugin with:
extend("gpu")
This registers these dynamic functions:
gpu:multiplygpu:addgpu:subtractgpu:hadamardgpu:inversegpu:transposegpu:reduce_sumgpu:scalegpu:to_tensorgpu:to_array
These functions are available via gpu:double and can be used in any MuMu/Lava program that is linked with the plugin.
Example: Matrix Multiply
a = [
[1, 2],
[3, 4]
]
b = [
[5, 6],
[7, 8]
]
ta = gpu:to_tensor(a)
tb = gpu:to_tensor(b)
tc = gpu:multiply(ta, tb)
result = gpu:to_array(tc)
slog(result)
Internals
-
Vulkan context* auto-initializes on plugin load.
-
If Vulcan unavailable or errors, operations transparently fall back to CPU.
-
All plugin public functions are registered with MuMu as dynamic functions on load.
-
Shaders are included as
.glslfiles and are expected to be precompiled to SPIR-V for deployment.
Development & Contributions
- Fork and PRS welcome.
- For development, see shader/ for GLSL compute sources.
- Contributions should avoid
unsafe unless required for FFI/Vulkan.
License
dual-licensed under MIT or Apache-2.0 (your choice).
See LICENSE in this repo.
Author
Tom @nu11.co.uk https://lava.nu11.uk
This plugin is part of the Lava/MuMu language ecosystem. For the core language, see: github.com/nu11co/mumu