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

Pipeline mode output value used argument in same functions causes throw on GPU #535

Closed
robertleeplummerjr opened this issue Nov 26, 2019 · 0 comments
Assignees

Comments

@robertleeplummerjr
Copy link
Member

A GIF or MEME to give some spice of the internet

As outlined in https://jsfiddle.net/robertleeplummerjr/jtoyua1w/7/ the following throws an error:

What is wrong?

const gpu = new GPU();
const kernel = gpu.createKernel(function(v) {
  return 1 + v[this.thread.x];
}, {
  output: [1],
  pipeline: true
});
const { context } = kernel;
const result1 = kernel([1]);
checkError(context);
console.log(result1.toArray());
const result2 = kernel(result1);
checkError(context);
console.log(result2.toArray());
// this makes a warning
const result3 = kernel(result2);
checkError(context);
console.log(result3.toArray());


function checkError(context) {
  const error = context.getError();
  if (error > 0) {
    throw new Error(`The error is ${ error }`);
  }
}

NOTE: this is kind of confusing, but what happens is:

  1. A standard kernel is built
  2. A kernel is ran and returns a texture
  3. That output texture is used with the same kernel
  4. Because the input type differs from the initial run, a new internal kernel is built just in time to handle this new value.
  5. The new kernel returns a texture.
  6. That texture is used with the same kernel, because the output of the same kernel is compatible with this same input type, the kernel is trying to overwrite the very value it is reading from, and since the kernel isn't creating a new texture each time (ie: immutable: true) the kernel has a warning, and essentially throws.
  7. The output can be different in different browsers, I think Firefox is smart enough to handle this scenario, but Chrome dies, for example.

Where does it happen?

How do we replicate the issue?

How important is this (1-5)?

5 We should simply have a check that checks for this exact scenario and resolves it internally, so the end user doesn't have to think about it.

Expected behavior (i.e. solution)

Other Comments

@robertleeplummerjr robertleeplummerjr self-assigned this Nov 26, 2019
ammyk9 pushed a commit to ammyk9/gpu.js that referenced this issue Aug 8, 2024
...it kind of snowballed from some needs
Fixes gpujs#521 - If `tactic` is not set, check precision allowed from WebGL, and automatically change based off needs, otherwise use value from `tactic`.
Fixes gpujs#535 - Internally check if texture from argument is the same as output, if so, clone this texture, and then clean it up after the kernel runs.
Fixes gpujs#536 - Normalize all declarations to non-destructured, and then parse
Fixes gpujs#537 - Change logic
Fixes gpujs#538 - Found the GL script that would work, and reduced the methods to use it
Fixes gpujs#539 - Found a better way of testing random, and this gives me an error for 1 in 10 runs, acceptable

Some refactoring for less duplicate code and documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant