Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
How to implement a for loop inside a combineKernel in GPU.js

I'm new to gpu.js and I need help. Basically I want to access my two kernel functions but I don't know how without sacrificing the expense of calling createKernel each time. I know there is combineKernel but I haven't seen an example where it uses a for loop inside.

So I have my first function which generates a square matrix from a vector

const functionA = gpu.createKernel(function(vector:number[]) {
   // just body of the code
}).setOutput([somethingLength, somethingLength])

Then from the resulting square matrix, I add each of its columns, and this return a vector. So I have another function for that

const functionB = gpu.createKernel(function (squareMatrix: number[][], initialVector: number[]) {
        let sum = initialVector[this.thread.x]
        for (let i = 0; i < squareMatrixLength ; i++) {
            sum += squareMatrix[i][this.thread.x]
        }
        return sum;
}).setOutput([initialVector.length])

I also have a combineKernel for both of them

const functionC = gpu.combineKernels(functionA as any, functionB as any, function (initialVector: number[], vector: number[]) {
        return functionB(functionA(vector), initialVector)
    })

Now, I have a number of vectors that I want to undergo functionA and then functionB, I want to do something like the code below inside the combineKernel to avoid the expense of cpu to gpu but I am having trouble how to figure it out. I want the final result to be a 2D matrix.

for(let i=0; i<vectorsLength; i++){
   newVector = functionB(functionA(vectors[i]), initialVector)
}
return newVector
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!