Skip to content

Commit 914bae0

Browse files
fix: #483 Handle and test Int32Array, Int16Array, and Int8Array transfer types
feat: Allow for arrow functions as kernels fix: Deep types where the argument contains a function call, and test fix: Only set argument type if it isn't already set fix: Bump version and build fix: Add Sponsorship from browser-stack
1 parent 7bcfbed commit 914bae0

File tree

13 files changed

+472
-133
lines changed

13 files changed

+472
-133
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,9 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
912912
![](https://www.leadergpu.com/assets/main/logo_leadergpu-a8cacac0c90d204b7f7f6c8420c6a149e71ebe53f3f28f3fc94a01cd05c0bd93.png)
913913
Sponsored NodeJS GPU environment from [LeaderGPU](https://www.leadergpu.com) - These guys rock!
914914

915+
![](https://3fxtqy18kygf3on3bu39kh93-wpengine.netdna-ssl.com/wp-content/themes/browserstack/img/browserstack-logo.svg)
916+
Sponsored Browser GPU environment's from [BrowserStack](https://i.ibb.co/KbcB3SL/browserstack-logo-600x315.png) - Second to none!
917+
915918
<a href="https://opencollective.com/gpujs/sponsor/0/website" target="_blank"><img src="https://opencollective.com/gpujs/sponsor/0/avatar.svg"></a>
916919
<a href="https://opencollective.com/gpujs/sponsor/1/website" target="_blank"><img src="https://opencollective.com/gpujs/sponsor/1/avatar.svg"></a>
917920
<a href="https://opencollective.com/gpujs/sponsor/2/website" target="_blank"><img src="https://opencollective.com/gpujs/sponsor/2/avatar.svg"></a>

bin/gpu-browser-core.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.0.0-rc.15
8-
* @date Mon Jun 17 2019 18:00:12 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.0.0-rc.16
8+
* @date Thu Jun 20 2019 10:09:00 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -2021,7 +2021,13 @@ class FunctionBuilder {
20212021
if (node.argumentTypes.length === 0 && ast.arguments.length > 0) {
20222022
const args = ast.arguments;
20232023
for (let j = 0; j < args.length; j++) {
2024+
this.lookupChain.push({
2025+
name: requestingNode.name,
2026+
ast: args[i],
2027+
requestingNode
2028+
});
20242029
node.argumentTypes[j] = requestingNode.getType(args[j]);
2030+
this.lookupChain.pop();
20252031
}
20262032
return node.returnType = node.getType(node.getJsAST());
20272033
}
@@ -2109,7 +2115,10 @@ class FunctionBuilder {
21092115

21102116
assignArgumentType(functionName, i, argumentType, requestingNode) {
21112117
if (!this._isFunction(functionName)) return;
2112-
this._getFunction(functionName).argumentTypes[i] = argumentType;
2118+
const fnNode = this._getFunction(functionName);
2119+
if (!fnNode.argumentTypes[i]) {
2120+
fnNode.argumentTypes[i] = argumentType;
2121+
}
21132122
}
21142123

21152124
trackArgumentSynonym(functionName, argumentName, calleeFunctionName, argumentIndex) {
@@ -2454,7 +2463,11 @@ class FunctionNode {
24542463
if (argumentType) {
24552464
type = argumentType;
24562465
} else if (this.lookupArgumentType) {
2457-
type = this.argumentTypes[argumentIndex] = this.lookupArgumentType(ast.name, this);
2466+
const foundArgumentType = this.lookupArgumentType(ast.name, this);
2467+
if (!this.argumentTypes[argumentIndex]) {
2468+
this.argumentTypes[argumentIndex] = foundArgumentType;
2469+
}
2470+
type = foundArgumentType;
24582471
}
24592472
}
24602473
if (!type && this.strictTypingChecking) {
@@ -2647,6 +2660,7 @@ class FunctionNode {
26472660
return this.getLookupType(this.getVariableType(ast.object.object.object));
26482661
case 'value[][][][]':
26492662
return this.getLookupType(this.getVariableType(ast.object.object.object.object));
2663+
case 'value.thread.value':
26502664
case 'this.thread.value':
26512665
return 'Integer';
26522666
case 'this.output.value':
@@ -2930,6 +2944,7 @@ class FunctionNode {
29302944
'value[][][]',
29312945
'value[][][][]',
29322946
'value.value',
2947+
'value.thread.value',
29332948
'this.thread.value',
29342949
'this.output.value',
29352950
'this.constants.value',
@@ -3252,6 +3267,7 @@ class FunctionNode {
32523267
switch (variableSignature) {
32533268
case 'value':
32543269
return null;
3270+
case 'value.thread.value':
32553271
case 'this.thread.value':
32563272
case 'this.output.value':
32573273
return {
@@ -3514,7 +3530,6 @@ const typeLookupMap = {
35143530
module.exports = {
35153531
FunctionNode
35163532
};
3517-
35183533
},{"../utils":89,"./function-tracer":10,"acorn":1}],10:[function(require,module,exports){
35193534
class FunctionTracer {
35203535
constructor(ast) {
@@ -6975,6 +6990,7 @@ class WebGLFunctionNode extends FunctionNode {
69756990
zProperty
69766991
} = this.getMemberExpressionDetails(mNode);
69776992
switch (signature) {
6993+
case 'value.thread.value':
69786994
case 'this.thread.value':
69796995
if (name !== 'x' && name !== 'y' && name !== 'z') {
69806996
throw this.astErrorOutput('Unexpected expression, expected `this.thread.x`, `this.thread.y`, or `this.thread.z`', mNode);
@@ -7140,7 +7156,9 @@ class WebGLFunctionNode extends FunctionNode {
71407156
case 'Array3D':
71417157
case 'Array4D':
71427158
case 'Input':
7143-
7159+
case 'Number':
7160+
case 'Float':
7161+
case 'Integer':
71447162
if (this.precision === 'single') {
71457163
retArr.push(`getMemoryOptimized32(${markupName}, ${markupName}Size, ${markupName}Dim, `);
71467164
this.memberExpressionXYZ(xProperty, yProperty, zProperty, retArr);
@@ -7849,9 +7867,21 @@ class WebGLKernelValue extends KernelValue {
78497867
if (Array.isArray(value[0])) {
78507868
return this.getTransferArrayType(value[0]);
78517869
}
7852-
if (value.constructor === Array) {
7853-
return Float32Array;
7870+
switch (value.constructor) {
7871+
case Array:
7872+
case Int32Array:
7873+
case Int16Array:
7874+
case Int8Array:
7875+
return Float32Array;
7876+
case Uint8ClampedArray:
7877+
case Uint8Array:
7878+
case Uint16Array:
7879+
case Uint32Array:
7880+
case Float32Array:
7881+
case Float64Array:
7882+
return value.constructor;
78547883
}
7884+
console.warn('Unfamiliar constructor type. Will go ahead and use, but likley this may result in a transfer of zeros');
78557885
return value.constructor;
78567886
}
78577887
formatArrayTransfer(value, length, Type) {

bin/gpu-browser-core.min.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.0.0-rc.15
8-
* @date Mon Jun 17 2019 18:00:14 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.0.0-rc.16
8+
* @date Thu Jun 20 2019 10:09:02 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -17,8 +17,8 @@
1717
*
1818
* GPU Accelerated JavaScript
1919
*
20-
* @version 2.0.0-rc.15
21-
* @date Mon Jun 17 2019 18:00:12 GMT-0400 (Eastern Daylight Time)
20+
* @version 2.0.0-rc.16
21+
* @date Thu Jun 20 2019 10:09:00 GMT-0400 (Eastern Daylight Time)
2222
*
2323
* @license MIT
2424
* The MIT License
@@ -2034,7 +2034,13 @@ class FunctionBuilder {
20342034
if (node.argumentTypes.length === 0 && ast.arguments.length > 0) {
20352035
const args = ast.arguments;
20362036
for (let j = 0; j < args.length; j++) {
2037+
this.lookupChain.push({
2038+
name: requestingNode.name,
2039+
ast: args[i],
2040+
requestingNode
2041+
});
20372042
node.argumentTypes[j] = requestingNode.getType(args[j]);
2043+
this.lookupChain.pop();
20382044
}
20392045
return node.returnType = node.getType(node.getJsAST());
20402046
}
@@ -2122,7 +2128,10 @@ class FunctionBuilder {
21222128

21232129
assignArgumentType(functionName, i, argumentType, requestingNode) {
21242130
if (!this._isFunction(functionName)) return;
2125-
this._getFunction(functionName).argumentTypes[i] = argumentType;
2131+
const fnNode = this._getFunction(functionName);
2132+
if (!fnNode.argumentTypes[i]) {
2133+
fnNode.argumentTypes[i] = argumentType;
2134+
}
21262135
}
21272136

21282137
trackArgumentSynonym(functionName, argumentName, calleeFunctionName, argumentIndex) {
@@ -2467,7 +2476,11 @@ class FunctionNode {
24672476
if (argumentType) {
24682477
type = argumentType;
24692478
} else if (this.lookupArgumentType) {
2470-
type = this.argumentTypes[argumentIndex] = this.lookupArgumentType(ast.name, this);
2479+
const foundArgumentType = this.lookupArgumentType(ast.name, this);
2480+
if (!this.argumentTypes[argumentIndex]) {
2481+
this.argumentTypes[argumentIndex] = foundArgumentType;
2482+
}
2483+
type = foundArgumentType;
24712484
}
24722485
}
24732486
if (!type && this.strictTypingChecking) {
@@ -2660,6 +2673,7 @@ class FunctionNode {
26602673
return this.getLookupType(this.getVariableType(ast.object.object.object));
26612674
case 'value[][][][]':
26622675
return this.getLookupType(this.getVariableType(ast.object.object.object.object));
2676+
case 'value.thread.value':
26632677
case 'this.thread.value':
26642678
return 'Integer';
26652679
case 'this.output.value':
@@ -2943,6 +2957,7 @@ class FunctionNode {
29432957
'value[][][]',
29442958
'value[][][][]',
29452959
'value.value',
2960+
'value.thread.value',
29462961
'this.thread.value',
29472962
'this.output.value',
29482963
'this.constants.value',
@@ -3265,6 +3280,7 @@ class FunctionNode {
32653280
switch (variableSignature) {
32663281
case 'value':
32673282
return null;
3283+
case 'value.thread.value':
32683284
case 'this.thread.value':
32693285
case 'this.output.value':
32703286
return {
@@ -3527,7 +3543,6 @@ const typeLookupMap = {
35273543
module.exports = {
35283544
FunctionNode
35293545
};
3530-
35313546
},{"../utils":89,"./function-tracer":10,"acorn":1}],10:[function(require,module,exports){
35323547
class FunctionTracer {
35333548
constructor(ast) {
@@ -6988,6 +7003,7 @@ class WebGLFunctionNode extends FunctionNode {
69887003
zProperty
69897004
} = this.getMemberExpressionDetails(mNode);
69907005
switch (signature) {
7006+
case 'value.thread.value':
69917007
case 'this.thread.value':
69927008
if (name !== 'x' && name !== 'y' && name !== 'z') {
69937009
throw this.astErrorOutput('Unexpected expression, expected `this.thread.x`, `this.thread.y`, or `this.thread.z`', mNode);
@@ -7153,7 +7169,9 @@ class WebGLFunctionNode extends FunctionNode {
71537169
case 'Array3D':
71547170
case 'Array4D':
71557171
case 'Input':
7156-
7172+
case 'Number':
7173+
case 'Float':
7174+
case 'Integer':
71577175
if (this.precision === 'single') {
71587176
retArr.push(`getMemoryOptimized32(${markupName}, ${markupName}Size, ${markupName}Dim, `);
71597177
this.memberExpressionXYZ(xProperty, yProperty, zProperty, retArr);
@@ -7862,9 +7880,21 @@ class WebGLKernelValue extends KernelValue {
78627880
if (Array.isArray(value[0])) {
78637881
return this.getTransferArrayType(value[0]);
78647882
}
7865-
if (value.constructor === Array) {
7866-
return Float32Array;
7883+
switch (value.constructor) {
7884+
case Array:
7885+
case Int32Array:
7886+
case Int16Array:
7887+
case Int8Array:
7888+
return Float32Array;
7889+
case Uint8ClampedArray:
7890+
case Uint8Array:
7891+
case Uint16Array:
7892+
case Uint32Array:
7893+
case Float32Array:
7894+
case Float64Array:
7895+
return value.constructor;
78677896
}
7897+
console.warn('Unfamiliar constructor type. Will go ahead and use, but likley this may result in a transfer of zeros');
78687898
return value.constructor;
78697899
}
78707900
formatArrayTransfer(value, length, Type) {

bin/gpu-browser.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.0.0-rc.15
8-
* @date Mon Jun 17 2019 18:00:12 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.0.0-rc.16
8+
* @date Thu Jun 20 2019 10:09:00 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -6785,7 +6785,13 @@ class FunctionBuilder {
67856785
if (node.argumentTypes.length === 0 && ast.arguments.length > 0) {
67866786
const args = ast.arguments;
67876787
for (let j = 0; j < args.length; j++) {
6788+
this.lookupChain.push({
6789+
name: requestingNode.name,
6790+
ast: args[i],
6791+
requestingNode
6792+
});
67886793
node.argumentTypes[j] = requestingNode.getType(args[j]);
6794+
this.lookupChain.pop();
67896795
}
67906796
return node.returnType = node.getType(node.getJsAST());
67916797
}
@@ -6873,7 +6879,10 @@ class FunctionBuilder {
68736879

68746880
assignArgumentType(functionName, i, argumentType, requestingNode) {
68756881
if (!this._isFunction(functionName)) return;
6876-
this._getFunction(functionName).argumentTypes[i] = argumentType;
6882+
const fnNode = this._getFunction(functionName);
6883+
if (!fnNode.argumentTypes[i]) {
6884+
fnNode.argumentTypes[i] = argumentType;
6885+
}
68776886
}
68786887

68796888
trackArgumentSynonym(functionName, argumentName, calleeFunctionName, argumentIndex) {
@@ -7218,7 +7227,11 @@ class FunctionNode {
72187227
if (argumentType) {
72197228
type = argumentType;
72207229
} else if (this.lookupArgumentType) {
7221-
type = this.argumentTypes[argumentIndex] = this.lookupArgumentType(ast.name, this);
7230+
const foundArgumentType = this.lookupArgumentType(ast.name, this);
7231+
if (!this.argumentTypes[argumentIndex]) {
7232+
this.argumentTypes[argumentIndex] = foundArgumentType;
7233+
}
7234+
type = foundArgumentType;
72227235
}
72237236
}
72247237
if (!type && this.strictTypingChecking) {
@@ -7411,6 +7424,7 @@ class FunctionNode {
74117424
return this.getLookupType(this.getVariableType(ast.object.object.object));
74127425
case 'value[][][][]':
74137426
return this.getLookupType(this.getVariableType(ast.object.object.object.object));
7427+
case 'value.thread.value':
74147428
case 'this.thread.value':
74157429
return 'Integer';
74167430
case 'this.output.value':
@@ -7694,6 +7708,7 @@ class FunctionNode {
76947708
'value[][][]',
76957709
'value[][][][]',
76967710
'value.value',
7711+
'value.thread.value',
76977712
'this.thread.value',
76987713
'this.output.value',
76997714
'this.constants.value',
@@ -8016,6 +8031,7 @@ class FunctionNode {
80168031
switch (variableSignature) {
80178032
case 'value':
80188033
return null;
8034+
case 'value.thread.value':
80198035
case 'this.thread.value':
80208036
case 'this.output.value':
80218037
return {
@@ -8278,7 +8294,6 @@ const typeLookupMap = {
82788294
module.exports = {
82798295
FunctionNode
82808296
};
8281-
82828297
},{"../utils":90,"./function-tracer":11,"acorn":1}],11:[function(require,module,exports){
82838298
class FunctionTracer {
82848299
constructor(ast) {
@@ -11739,6 +11754,7 @@ class WebGLFunctionNode extends FunctionNode {
1173911754
zProperty
1174011755
} = this.getMemberExpressionDetails(mNode);
1174111756
switch (signature) {
11757+
case 'value.thread.value':
1174211758
case 'this.thread.value':
1174311759
if (name !== 'x' && name !== 'y' && name !== 'z') {
1174411760
throw this.astErrorOutput('Unexpected expression, expected `this.thread.x`, `this.thread.y`, or `this.thread.z`', mNode);
@@ -11904,7 +11920,9 @@ class WebGLFunctionNode extends FunctionNode {
1190411920
case 'Array3D':
1190511921
case 'Array4D':
1190611922
case 'Input':
11907-
11923+
case 'Number':
11924+
case 'Float':
11925+
case 'Integer':
1190811926
if (this.precision === 'single') {
1190911927
retArr.push(`getMemoryOptimized32(${markupName}, ${markupName}Size, ${markupName}Dim, `);
1191011928
this.memberExpressionXYZ(xProperty, yProperty, zProperty, retArr);
@@ -12613,9 +12631,21 @@ class WebGLKernelValue extends KernelValue {
1261312631
if (Array.isArray(value[0])) {
1261412632
return this.getTransferArrayType(value[0]);
1261512633
}
12616-
if (value.constructor === Array) {
12617-
return Float32Array;
12634+
switch (value.constructor) {
12635+
case Array:
12636+
case Int32Array:
12637+
case Int16Array:
12638+
case Int8Array:
12639+
return Float32Array;
12640+
case Uint8ClampedArray:
12641+
case Uint8Array:
12642+
case Uint16Array:
12643+
case Uint32Array:
12644+
case Float32Array:
12645+
case Float64Array:
12646+
return value.constructor;
1261812647
}
12648+
console.warn('Unfamiliar constructor type. Will go ahead and use, but likley this may result in a transfer of zeros');
1261912649
return value.constructor;
1262012650
}
1262112651
formatArrayTransfer(value, length, Type) {

0 commit comments

Comments
 (0)