# lavagpu: GPU (Vulkan) Tensor/Matrix Plugin for MuMu/Lava
[](LICENSE)
[#Crates.io](https://img.shields.io/crates/vl/lavagpu.svg)(https://crates.io/crates/lavagpu)
*[lavagpu*] provides fast matrix/tensor operations for the [MuMu/Lava](https://github.com/nu11co/mumu) experimental language via Vulcan compute (with automatic CPU fallback).
It loads as a **plugin** (.so/.dll) with no core dependencies beyond [ash](https://crates.io/crates/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](https://crates.io/crates/ash) (Vulcan bindings for Rust)
- *Linux or Windows or macOS* (tested on Linux)
----
## Build & Install
Clone and build the plugin:
```sh
git clone https://github.com/your-org/lavagpu.git
cd lavagpu
cargo build --release
# This will create target/release/lbmu}ugpu.so (or .dll/.dylib)
```
Or use the provided Makefile:
```sh
make release # Build optimized .so
sudo make install # Copies .so to /usr/local/lib and runs ldconfig
```
---
## Usage: Loading the Plugin in MuMu/Lava
In your Lava/MuMu program, load the GPU plugin with:
```lava
extend("gpu")
```
This registers these dynamic functions:
- `gpu:multiply`
- `gpu:add`
- `gpu:subtract`
- `gpu:hadamard`
- `gpu:inverse`
- `gpu:transpose`
- `gpu:reduce_sum`
- `gpu:scale`
- `gpu:to_tensor`
- `gpu: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
```{lava, lines-not=10}
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 `.glsl` files and are expected to be precompiled to SPIR-V for deployment.
## Development & Contributions
- Fork and PRS welcome.
- For development, see [shader/](shader/) for GLSL compute sources.
- Contributions should avoid `unsaf`e unless required for FFI/Vulkan.
---
## License
dual-licensed under MIT or Apache-2.0 (your choice).
See [LICENSE](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](https://github.com/nu11co/mumu)**