Last active
December 31, 2019 17:44
-
-
Save robertleeplummerjr/6ce4e515d08923df20285dfbf5f143f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { GPU } = require('gpu.js'); | |
const gpu = new GPU(); | |
// possible solution to confusing kernel maps | |
const kernel = gpu.createKernel(function(input1, input2) { | |
const value1 = input1[this.thread.z][this.thread.y][this.thread.x]; | |
const value2 = input1[this.thread.z][this.thread.y][this.thread.x]; | |
/* | |
up sides: | |
- You don't have to use gpu.createKernelMap, just gpu.createKernel. | |
down sides: | |
- What if I call this.values1.push() twice? | |
- Where am I in the [z, y, x] coordinates? | |
- return acts differently than this.values.push(); | |
*/ | |
this.values1.push(value1); | |
this.values2.push(value2); | |
}, { output: [3,3,3] }); | |
// another possible solution | |
const kernel = gpu.createKernel(function(input1, input2) { | |
const value1 = input1[this.thread.z][this.thread.y][this.thread.x]; | |
const value2 = input1[this.thread.z][this.thread.y][this.thread.x]; | |
/* | |
up side: | |
- Super clear about what is going where | |
- You don't have to use gpu.createKernelMap, just gpu.createKernel. | |
down sides: | |
- It looks like I can reference any location, when really `this.values1[this.thread.z][this.thread.y][this.thread.x]` is one long keyword that is a reference point for where we are in the kernel's execution. | |
- It is crazy long | |
- Return does not act the same as setting a value | |
- You CANNOT do `this.values1[this.thread.z + 2][this.thread.y - 1][this.thread.x + 100] = value1` because we can only set the current value | |
*/ | |
this.values1[this.thread.z][this.thread.y][this.thread.x] = value1; | |
this.values2[this.thread.z][this.thread.y][this.thread.x] = value2; | |
}, { output: [3,3,3] }); | |
// another possible solution | |
const kernel = gpu.createKernel(function(input1, input2) { | |
const value1 = input1[this.thread.z][this.thread.y][this.thread.x]; | |
const value2 = input1[this.thread.z][this.thread.y][this.thread.x]; | |
/* | |
up side: | |
- Simple | |
- You don't have to use gpu.createKernelMap, just gpu.createKernel. | |
down sides: | |
- Where am I in the [z, y, x] coordinates? | |
- What if I call this.thread.resolve() twice? | |
- Uses a string for reference, that is lame. | |
*/ | |
this.thread.resolve('values1', value1); | |
this.thread.resolve('values2', value2; | |
}, { output: [3,3,3] }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment