Skip to content

A GPGPU computation graph executor for web assembly πŸŒŸπŸ›πŸ¦‹

License

Notifications You must be signed in to change notification settings

richardanaya/metamorphosis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

metamorphosis

docs.rs docs

[dependencies]
metamorphosis = "0.0"

A GPGPU computation graph executor for web assembly.

  • 2d float matrix inputs
  • float scalar inputs
  • 2d float matrix outputs

Generate a 512x515 matrix of 42

use metamorphosis::*;

#[no_mangle]
pub fn main() -> () {
    let mut kernel = GPUKernel::new();
    // for each position in our output matrix we will execute this 
    // compute graph node that just returns 42
    kernel.set_compute_graph(ComputationGraphNode::Value(42.0));
    // run it for a 512x512 output matrix
    let output = kernel.compute_2d(512, 512);
}

Physics System

This calculate a position + velocity*time_step calculation for 10 positions in parallel

use metamorphosis::*;

#[no_mangle]
pub fn main() -> () {
    let mut kernel = GPUKernel::new();
    
    // create a matrix representing 10 positions 
    let mut position = kernel.input_2d(vec![
        0.0,0.0,0.0,
        0.0,0.0,0.0,
        0.0,0.0,0.0,
        0.0,0.0,0.0,
        0.0,0.0,0.0,
        0.0,0.0,0.0,
        0.0,0.0,0.0,
        0.0,0.0,0.0,
        0.0,0.0,0.0,
        0.0,0.0,0.0,
    ],3,10);
    
    // create a matrix representing 10 velocities 
    let velocity = kernel.input_2d(vec![
        1.0,0.0,0.0,
        0.0,1.0,0.0,
        0.0,0.0,1.0,
        0.0,1.0,0.0,
        1.0,0.0,0.0,
        0.0,1.0,0.0,
        0.0,0.0,1.0,
        0.0,1.0,0.0,
        1.0,0.0,0.0,
        0.0,1.0,0.0,
    ],3,10);
    
    // create a float that will represent a time step
    let time_step = kernel.input_float32(.1);
    
    // specify `position + velocity*time_step` as a graph of computation
    kernel.set_compute_graph({
            // for each position in output matrix, find the position component 
            // and its corresponding velocity component from our input matricies
            let p = get_2d(position,OUTPUT_X,OUTPUT_Y); 
            let v = get_2d(velocity,OUTPUT_X,OUTPUT_Y); 
            // calculate a new position component
            add(p,mul(v,time_step))
        });
    
    // calculate the output 10 positions of the physics system
    let mut output = kernel.compute_2d(3, 10);
    
    // set our output matrix as our input position matrix
    position.update(output)
    
    // run it again to step forward in simulation
    output = kernel.compute_2d(3, 10);
}

About

A GPGPU computation graph executor for web assembly πŸŒŸπŸ›πŸ¦‹

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published