Skip to content

WIP Add headless gl for node support - #404

Merged
robertleeplummerjr merged 6 commits into
gpujs:gl-headless-experimentalfrom
arjunmehta:use-headless-gl
Dec 17, 2018
Merged

WIP Add headless gl for node support#404
robertleeplummerjr merged 6 commits into
gpujs:gl-headless-experimentalfrom
arjunmehta:use-headless-gl

Conversation

@arjunmehta

@arjunmehta arjunmehta commented Dec 2, 2018

Copy link
Copy Markdown
Contributor

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

@hmmhmmhm

hmmhmmhm commented Dec 3, 2018

Copy link
Copy Markdown

I tried to run this code on a node,
This test code worked very successfully.

The speed on the node was
also very same as the browser.

But unexpectedly,
I discovered a new problem first.

I tested on Windows 10 x64(node 11.3.0).
and i didn't test it in a separate operating system.
Maybe it's just a problem with Windows.

Issue 1. Some kernel validateOptions are failure

_2

In 'src/backend/web-gl/kernel.js'
Once the corresponding test code is removed, it can be executed.
I annotated the code for implementation and debugging.
And the default test code works successfully.

Issue 2. Some kernel code are failure

crashes 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,
I identified where the problem occurred.

_3

In 'src/backend/web-gl/kernel.js'
An error occurs when the code

gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);

is executed within the run function.

_4

If the code is annotated, all functions are executed normally.
(I don't know what's exactly going on. I don't know much about webgl.)

I have doubted that the drawArrays function is unable to use,
but it looks not a problem in the test results.

_5

I think it's almost done,,,?
and I think someone can solve this problem.

@hmmhmmhm

hmmhmmhm commented Dec 3, 2018

Copy link
Copy Markdown

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.)

mapbox/mapbox-gl-js#7559 (comment)

@arjunmehta

arjunmehta commented Dec 6, 2018

Copy link
Copy Markdown
Contributor Author

@hmmhmmhm Thank you so much for your investigation!
Very good to know about the Windows issues with headless-gl.

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 WebGLRenderingContext so that it's the same as your kernel output (ie 512x512) helps? @src/core/gpu.js

@robertleeplummerjr

Copy link
Copy Markdown
Member

Been on vacation for a few days, I will work on this shortly.

@jacobbogers

Copy link
Copy Markdown

very promising

@robertleeplummerjr
robertleeplummerjr changed the base branch from develop to gl-headless-experimental December 17, 2018 12:54
@robertleeplummerjr
robertleeplummerjr merged commit d4212cd into gpujs:gl-headless-experimental Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants