The Wayback Machine - https://web.archive.org/web/20210121024851/https://github.com/gpujs/gpu.js/issues/608
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining any array constants causes input arrays to be rewritten #608

Closed
ericwong3 opened this issue May 11, 2020 · 6 comments
Closed

Defining any array constants causes input arrays to be rewritten #608

ericwong3 opened this issue May 11, 2020 · 6 comments

Comments

@ericwong3
Copy link

@ericwong3 ericwong3 commented May 11, 2020

Might be related to #520

What is wrong?

When an array constant is defined, the kernel function messes up the variables, apparently the input variables itself is overwritten by the constant array.

Where does it happen?

After running a GPU.js kernel and observing the output.

How do we replicate the issue?

Use this code:

const { GPU } = require('gpu.js');
const gpu = new GPU();
const naiveFn = gpu.createKernel(function(a, b) {
    return a[this.thread.y][this.thread.x];
    // return b[this.thread.y][this.thread.x];
}, {
  constants: {
    // zzz: [21,23],
  }
}).setOutput([2, 2]);

const c = naiveFn([[2,3], [5,7]], [[11,13],[17,19]]);
console.log(c);

A very simple function that just returns the input array.

When this is executed, the result is normal, i.e.:

[ Float32Array [ 2, 3 ], Float32Array [ 5, 7 ] ] when return a line is active, and
[ Float32Array [ 11, 13 ], Float32Array [ 17, 19 ] ] when return b line is active.

However, if I uncomment the constants property in settings object, which defines an array zzz, the output becomes:

[ Float32Array [ 21, 23 ], Float32Array [ 0, 0 ] ] when return a line is active, and
[ Float32Array [ 2, 3 ], Float32Array [ 5, 7 ] ] when return b line is active.

As you can see, b in the kernel now holds the first input array, and a in kernel becomes the array defined in constants.zzz.

How important is this (1-5)?

5

Expected behavior (i.e. solution)

The array constant definition should not affect the parameters, and the correct result (i.e. the first one) should be returned regardless.

Other Comments

@tonyg
Copy link

@tonyg tonyg commented Dec 2, 2020

Successfully reproduced the fault with node 12.19.1, gpu.js 2.10.5.

@HarshKhandeparkar
Copy link

@HarshKhandeparkar HarshKhandeparkar commented Dec 2, 2020

Interesting.... I was seeing weird things in another unrelated project but I had no idea what was happening... Maybe this was happening. Really waiting for a fix 😃

@robertleeplummerjr
Copy link
Member

@robertleeplummerjr robertleeplummerjr commented Dec 2, 2020

Looking at it now.

@robertleeplummerjr
Copy link
Member

@robertleeplummerjr robertleeplummerjr commented Dec 2, 2020

Found the issue, will have a PR up today or tomorrow with a unit test preventing regressions.

@robertleeplummerjr
Copy link
Member

@robertleeplummerjr robertleeplummerjr commented Dec 3, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.