Home > Net >  GPU-JS: Error: too many arguments for kernel
GPU-JS: Error: too many arguments for kernel

Time:09-13

I was trying to make simple script that uses GPU for multiplying arrays, but when I turn on the code, it shows error as in title. I don't know if it's my fault and I didn't installed every library or its a bug. Code is from gpu-js github example:

const { GPU } = require('gpu.js');
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 c = multiplyMatrix(a, b);

Thanks in advance.

CodePudding user response:

A and B are not defined, you need to define your matrices first and then call the function. Here's the full example from their website, comments mine:

// Function to create the 512x512 matrix
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
  }

//Define the function to be ran on GPU
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])
// Create the matrices
const matrices = generateMatrices()
// Run multiplyMatrix using the 2 matrices created.
  const out = multiplyMatrix(matrices[0], matrices[1])
  • Related