gpujs / gpu.js

GPU Accelerated JavaScript
https://gpu.rocks
MIT License
15.1k stars 652 forks source link

Error compiling fragment shader: ' + gl.getShaderInfoLog(fragShader) #682

Closed Mercalyn closed 3 years ago

Mercalyn commented 3 years ago
const { GPU } = require('gpu.js');
const gpu = new GPU();

const testMatrix = gpu.createKernel(function(a) {
    return a[this.thread.x];
}).setOutput([512]);

console.log(testMatrix(78));

GPU.js doesn't work for me using Node. Errors:

\node_modules\gpu.js\src\backend\web-gl\kernel.js:529
      throw new Error('Error compiling fragment shader: ' + gl.getShaderInfoLog(fragShader));
      ^

Error: Error compiling fragment shader: ERROR: 0:501: 'user_aSize' : undeclared identifier
ERROR: 0:501: 'user_aDim' : undeclared identifier
ERROR: 0:501: 'getMemoryOptimized32' : no matching overloaded function found

    at HeadlessGLKernel.build (D:\0 Projects\merch\Algo Donut\node_modules\gpu.js\src\backend\web-gl\kernel.js:529:13)
    at HeadlessGLKernel.build (D:\0 Projects\merch\Algo Donut\node_modules\gpu.js\src\backend\headless-gl\kernel.js:103:17)
    at HeadlessGLKernel.run (D:\0 Projects\merch\Algo Donut\node_modules\gpu.js\src\kernel-run-shortcut.js:10:18)
    at shortcut (D:\0 Projects\merch\Algo Donut\node_modules\gpu.js\src\kernel-run-shortcut.js:30:16)
    at Object.<anonymous> (D:\0 Projects\merch\Algo Donut\precalcio.js:10:13)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)

I'm not sure what is going on, as I'm fairly new to the GPGPU world, but I copy pasted some starting examples and I seem to get this issue every time.

ted-piotrowski commented 3 years ago

@Mercalyn your kernel expects a to be an Array but you are passing the Number 78 as an argument.

Mercalyn commented 3 years ago

Good catch. Also, I wrongly assumed that the code above would just run(almost a straight copy from github readme section on Node), but it actually needs more code found on the actual gpu.rocks website.

Full code without any errors:

const { GPU } = require('gpu.js');

const generateMatrices = () => {
    const matrices = [[], []];
    for (let y = 0; y < 512; y++){
        matrices[0].push([]);
        matrices[1].push([]);
        for (let x = 0; x < 512; x++){
            matrices[0][y].push(Math.random());
            matrices[1][y].push(Math.random());
        };
    };
    return matrices;
};

const gpu = new GPU();
    const multiplyMatrix = gpu.createKernel(function(a, b) {
        let sum = 0;
        for (let i = 0; i < 512; i++) {
        sum += a[this.thread.y][i] * b[i][this.thread.x];
    }
    return sum;
}).setOutput([512, 512]);

const matrices = generateMatrices();
const out = multiplyMatrix(matrices[0], matrices[1]);

console.log(out[10][12]);