WIP Add headless gl for node support - #404
Conversation
|
I tried to run this code on a node, The speed on the node was But unexpectedly, I tested on Windows 10 x64(node 11.3.0). Issue 1. Some kernel validateOptions are failureIn 'src/backend/web-gl/kernel.js' Issue 2. Some kernel code are failurecrashes are detected for the following test codes: var GPU = require('gpu.js/src/index')
const gpu = new GPU({mode:'webgl'});
console.time('Kernel init')
const matMult = gpu.createKernel(function(a, b) {
var sum = 0;
for (var i = 0; i < 512; i++) {
sum += a[this.thread.y][i] * b[i][this.thread.x];
}
return sum;
}).setOutput([512, 512]);
console.timeEnd('Kernel init')
function fillArrayRandom(array) {
for(var i = 0; i < array.length; i++) {
array[i] = Math.random();
}
return array;
}
function splitArray(array, part) {
var result = [];
for(var i = 0; i < array.length; i += part) {
result.push(array.slice(i, i + part));
}
return result;
}
// Perform matrix multiplication on 2 matrices of size 512 x 512
var matrixSize = 512;
var allowChangeOutput = true;
var a = new Array(matrixSize * matrixSize);
var b = new Array(matrixSize * matrixSize);
a = splitArray(fillArrayRandom(a), matrixSize);
b = splitArray(fillArrayRandom(b), matrixSize);
for(let i=1;i<=5;i++){
console.log(`sequence ${i}`)
console.time('gpu calc')
const c = matMult(a, b)
console.timeEnd('gpu calc')
}Through several checks, In 'src/backend/web-gl/kernel.js' gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);is executed within the run function. If the code is annotated, all functions are executed normally. I have doubted that the drawArrays function is unable to use, I think it's almost done,,,? |
|
Additionally, the headless-gl appears to require the following patching process to be used in the Windows 10 operating system. (If the use of headless-gl is actually decided, it may be necessary to fill out the contents at readme.md.) |
|
@hmmhmmhm Thank you so much for your investigation! Can you confirm that you get expected results (exact same values) when you import and instantiate a new GL context? That seems very odd. I don't have a Windows machine to test on, so your help is much appreciated. Can you also see if changing the size of the |
|
Been on vacation for a few days, I will work on this shortly. |
|
very promising |




Proof of concept work in progress to use headless-gl and node-canvas to provide 1:1 API support.