filum
Easy GPGPU with Rust and Vulkan.
Provides a simple yet easy-to-use interface to do some computations actually done in parallel.
Example
Calculating Fibonacci sequence
let context = new.unwrap;
let num_elements = 32usize;
let view = new
.
.build
.unwrap;
// prepare compute shader
let pipeline = new
.shader
.specialization
.build
.unwrap;
// send data to GPU device
let mut v: =
.collect;
let binding = view.binding;
binding.update_array_copying;
// execute computation
pipeline.dispatch;
// receive data from GPU device
binding.fetch_array_copying;
// outputs
// [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269]
Features
- High-level interface
- Type-safe in-out buffer access
- Vulkan compute kernel
- Multiple layout binding support
- Multiple shader stages support
- Push constants
- Specialization constants
Another Example
Connected Component Labeling. This is actually an implementation of the algorithm below.
A Parallel Approach to Object Identification in Large-scale Images
let dim = ;
let table: = vec!;
let mut table: = table.into_iter
.enumerate
.map
.collect;
let len = table.len;
let context = new.unwrap;
let buffer_view = new
.
.build
.unwrap;
let buffer = buffer_view.buffer;
let column = new
.shader
.specialization
.build
.unwrap;
let merge = new
.shader
.specialization
.build
.unwrap;
let relabel = new
.shader
.build
.unwrap;
let binding = buffer_view.binding;
binding.update_array_copying;
// column
column.dispatch;
// merge
// relabel
relabel.dispatch;
binding.fetch_array_copying;
// outputs
/*
-1, -1, -1, -1, -1, -1, -1, -1,
-1, 9, 9, -1, 12, 12, 12, -1,
-1, 9, 9, -1, 12, 12, 12, -1,
9, 9, 9, -1, -1, -1, -1, 31,
-1, 9, 9, 9, -1, -1, -1, 31,
-1, -1, -1, -1, -1, 45, 45, -1,
-1, 45, -1, 45, 45, 45, 45, -1,
-1, 45, 45, 45, -1, -1, -1, -1,
*/
Performance
Connected component labeling 8K Image
GPU computation took ~210ms
including memory transfer operations.
- OS: Ubuntu 18.04 LTS
- CPU: Intel(R) Core(TM) i7-3930K CPU @ 3.20GHz
- GPU: NVIDIA GeForce RTX 2070
Runtime Environment
- Requires Vulkan 1.1 Runtime
- Vulkan 1.1 supported Graphics Driver
To compile compute shader GLSL into SPIR-V, we recommend Vulkan SDK to compile with.