Closed Mercalyn closed 3 years ago
@Mercalyn your kernel expects a
to be an Array
but you are passing the Number
78 as an argument.
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]);
GPU.js doesn't work for me using Node. Errors:
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.