// Test if turbo.js is availableif (turbojs) {// Allocate a float-array of size 1,000,000var blah = turbojs.alloc(1e6);// Initialize datafor (i = 0; i <= 1e6; i++) blah.data[i] = i;// [0, 1, 2, 3, 4]console.log(blah.data.subarray(0, 5));// A simple kernel that calculates input *= 4// for all 1e6 floats in parallelturbojs.run(blah, `void main(void) {commit(read() * 4.);}`);// [0, 4, 8, 12, 16]console.log(blah.data.subarray(0, 5));// That's it :-)}
Non-volatile
Data is always accessible from the GPU and JavaScript side. Typed arrays ensure data integrity and low transfer overhead. Each run debugs the kernel code on the fly.
Dynamic Data Layout
Work on a flat float array (example to the left) or use 4D vectors, utilizing four 32bit floats I/O per parallel operation. turbo.js takes care of data transformation for you.