Skip to content

Run Two Nodes

Pass an array to v.run() when you have multiple nodes ready to execute.

import { volten, Buffer, Kernel } from '@volten/core';
const v = await volten();
const a = new Buffer([1, 2, 3, 4], 'f32', 'rw');
const b = new Buffer([10, 20, 30, 40], 'f32', 'rw');
const doubleA = new Kernel(`
fn main(gid: vec3u) {
a[gid.x] = a[gid.x] * 2.0;
}
`);
const addOneToB = new Kernel(`
fn main(gid: vec3u) {
b[gid.x] = b[gid.x] + 1.0;
}
`);
const A = v.pass(doubleA, { a });
const B = v.pass(addOneToB, { b });
v.run([A, B]);
const [aResult, bResult] = await v.read([a, b]);
console.log(aResult);
// Float32Array [2, 4, 6, 8]
console.log(bResult);
// Float32Array [11, 21, 31, 41]

This will batch GPU execution for optimal resource usage, Volten can combine compatible GPU work while preserving ordering when resources require it.

Learn more: Execution Overview, v.run().