gpu.js icon indicating copy to clipboard operation
gpu.js copied to clipboard

How to create Float32Array inside GPU Kernel

Open zlelik opened this issue 4 years ago • 1 comments

What is wrong?

I am trying to create an array inside GPU kernel for internal calculation like this

var testArray1 = new Float32Array(16);
var testArray2 = new Array(16);

and I am getting this error.

gpu-browser.min.js:14 Uncaught Error: unhandled type "NewExpression"
    at FunctionTracer.scan (gpu-browser.min.js:14)
    at FunctionTracer.scan (gpu-browser.min.js:14)
    at FunctionTracer.scan (gpu-browser.min.js:14)
    at gpu-browser.min.js:14
    at FunctionTracer.useFunctionContext (gpu-browser.min.js:14)
    at FunctionTracer.scan (gpu-browser.min.js:14)
    at FunctionTracer.scan (gpu-browser.min.js:14)
    at gpu-browser.min.js:14
    at FunctionTracer.newContext (gpu-browser.min.js:14)
    at FunctionTracer.scan (gpu-browser.min.js:14)

Where does it happen?

Inside GPU kerneI code.

How do we replicate the issue?

add this code below to the GPU kernel.

var testArray1 = new Float32Array(16);

How important is this (1-5)?

4

Expected behavior (i.e. solution)

Array should be created without any errors.

Other Comments

I can create this array outside GPU Kernel and pass it to GPU kernel, but because it is for internal calculation I would prefer to create it inside.

zlelik avatar Jul 05 '21 18:07 zlelik

GPU doesnt use javascript vars, Float32Arrays, etc. Those are whats copied into GPU, then it does alot of work, then copied from GPU to CPU as those. It probably would have no effect on GPU efficiency to do that, other than floats are much faster than doubles in GPU.

benrayfield avatar Jul 08 '21 15:07 benrayfield