-
Notifications
You must be signed in to change notification settings - Fork 666
Open
Labels
Milestone
Description
Sorry for poor title. Feel free to modify it if you know how to phrase it.
Here is a simple example:
This will bring trouble:
this.matMult = gpu.createKernel(function (Vw, weights, bias) {
var a = 0.0;
var wi = weights[this.thread.x];
for (var i = 0; i < this.constants.num_inputs; i++) {
a += Vw[i] * wi[i];
}
a += bias[this.thread.x];
return a;
}, {
constants: { num_inputs: this.num_inputs },
output: [this.out_depth],
});
But this won't:
this.matMult = gpu.createKernel(function (Vw, weights, bias) {
var a = 0.0;
for (var i = 0; i < this.constants.num_inputs; i++) {
a += Vw[i] * weights[this.thread.x][i];
}
a += bias[this.thread.x];
return a;
}, {
constants: { num_inputs: this.num_inputs },
output: [this.out_depth],
});
This is what has been generated for the first example:
return function (user_Vw, user_weights, user_bias) {
const constants_num_inputs = this.constants.num_inputs;
const result = new Float32Array(5);
for (let x = 0; x < 5; x++) {
this.thread.x = x;
this.thread.y = 0;
this.thread.z = 0;
let kernelResult;
var user_a=0;
var user_wi=user_weights[_this.thread.x];
for (var user_i=0;(user_i<constants_num_inputs);user_i++){
user_a+=(user_Vw[user_i]*user_wi);}
user_a+=user_bias[_this.thread.x];
kernelResult = user_a;
result[x] = kernelResult;
}
See how user_wi
is not indexed.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
robertleeplummerjr commentedon Mar 17, 2019
You have to look up arrays directly for compatibility on GPU. This type of behavior isn't supported.
soswow commentedon Mar 17, 2019
@robertleeplummerjr considering you allow write JS code it might give an impression that this is normal. The fact it's not supported is not intuitive. It took me some time to understand why I was getting
NaN
all over the place. Maybe this needs to be mentioned in Docs. Maybe it is already there. Sorry if I missed it.Thank you for your work.
robertleeplummerjr commentedon Mar 17, 2019
We are always looking for ways to make the project better. Do you have a suggestion as to the verbiage that would help ones like yourself in the future? Perhaps we need to throw an error on compilation, as well? Ty for the feedback, I joined the project far after it was initially conceptualized, and loved the core idea which is to accelerate using GPU with simple javascript. Together we can make it far better.
soswow commentedon Mar 17, 2019
I am not sure how you do the transformation (compilation). But if you can detect these cases easily - yeah, blowing up with an exception would be perfect, since this result is clearly not what user would expect.
And please, change the title of this issue for something more SEOable so that someone else might find it. I don't know how to describe this =(
[-]Wrong re-compilation[/-][+]Multidimensional arrays with partial lookups fail[/+]robertleeplummerjr commentedon Mar 17, 2019
Lets reopen this and add that to the list then. Ty for the suggestion and viewpoint!