Hello I’m really new with using GPU.js and I am having trouble understanding createKernel and its output. I want to have a 3D array that stores the outputs from my current function. For example, below, is a gpu matrix multiplication that multiplies matrix a and b, and the result of this function is a 2D array. There are more than one matrix that I want to multiply to a and I want to store all their output in one 3D array.
const gpu = new GPU();
const multiplyMatrix = gpu.createKernel(function(a, b) {
let sum = 0;
for (let i = 0; i < 10; i++) {
sum += a[this.thread.y][i] * b[i][this.thread.x];
}
return sum;
}).setOutput([10, 10])
Can anyone please help me. I tried using for loop but it’s so slow and I read because it is expensive to keep using createKernel?
let big3Dmatrix = []
for(let i=0; i<matrices.length; i++){
big3Dmatrix.push(multiplyMatrix(a,matrices[i]))
}
I would appreciate any help. Thank you!