Skip to content

Commit

Permalink
fix: #483 Handle and test Int32Array, Int16Array, and Int8Array trans…
Browse files Browse the repository at this point in the history
…fer 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
  • Loading branch information
robertleeplummerjr committed Jun 20, 2019
1 parent 7bcfbed commit 914bae0
Show file tree
Hide file tree
Showing 13 changed files with 472 additions and 133 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,9 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
![](https://www.leadergpu.com/assets/main/logo_leadergpu-a8cacac0c90d204b7f7f6c8420c6a149e71ebe53f3f28f3fc94a01cd05c0bd93.png)
Sponsored NodeJS GPU environment from [LeaderGPU](https://www.leadergpu.com) - These guys rock!

![](https://3fxtqy18kygf3on3bu39kh93-wpengine.netdna-ssl.com/wp-content/themes/browserstack/img/browserstack-logo.svg)
Sponsored Browser GPU environment's from [BrowserStack](https://i.ibb.co/KbcB3SL/browserstack-logo-600x315.png) - Second to none!

<a href="https://opencollective.com/gpujs/sponsor/0/website" target="_blank"><img src="https://opencollective.com/gpujs/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/gpujs/sponsor/1/website" target="_blank"><img src="https://opencollective.com/gpujs/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/gpujs/sponsor/2/website" target="_blank"><img src="https://opencollective.com/gpujs/sponsor/2/avatar.svg"></a>
Expand Down
46 changes: 38 additions & 8 deletions bin/gpu-browser-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* GPU Accelerated JavaScript
*
* @version 2.0.0-rc.15
* @date Mon Jun 17 2019 18:00:12 GMT-0400 (Eastern Daylight Time)
* @version 2.0.0-rc.16
* @date Thu Jun 20 2019 10:09:00 GMT-0400 (Eastern Daylight Time)
*
* @license MIT
* The MIT License
Expand Down Expand Up @@ -2021,7 +2021,13 @@ class FunctionBuilder {
if (node.argumentTypes.length === 0 && ast.arguments.length > 0) {
const args = ast.arguments;
for (let j = 0; j < args.length; j++) {
this.lookupChain.push({
name: requestingNode.name,
ast: args[i],
requestingNode
});
node.argumentTypes[j] = requestingNode.getType(args[j]);
this.lookupChain.pop();
}
return node.returnType = node.getType(node.getJsAST());
}
Expand Down Expand Up @@ -2109,7 +2115,10 @@ class FunctionBuilder {

assignArgumentType(functionName, i, argumentType, requestingNode) {
if (!this._isFunction(functionName)) return;
this._getFunction(functionName).argumentTypes[i] = argumentType;
const fnNode = this._getFunction(functionName);
if (!fnNode.argumentTypes[i]) {
fnNode.argumentTypes[i] = argumentType;
}
}

trackArgumentSynonym(functionName, argumentName, calleeFunctionName, argumentIndex) {
Expand Down Expand Up @@ -2454,7 +2463,11 @@ class FunctionNode {
if (argumentType) {
type = argumentType;
} else if (this.lookupArgumentType) {
type = this.argumentTypes[argumentIndex] = this.lookupArgumentType(ast.name, this);
const foundArgumentType = this.lookupArgumentType(ast.name, this);
if (!this.argumentTypes[argumentIndex]) {
this.argumentTypes[argumentIndex] = foundArgumentType;
}
type = foundArgumentType;
}
}
if (!type && this.strictTypingChecking) {
Expand Down Expand Up @@ -2647,6 +2660,7 @@ class FunctionNode {
return this.getLookupType(this.getVariableType(ast.object.object.object));
case 'value[][][][]':
return this.getLookupType(this.getVariableType(ast.object.object.object.object));
case 'value.thread.value':
case 'this.thread.value':
return 'Integer';
case 'this.output.value':
Expand Down Expand Up @@ -2930,6 +2944,7 @@ class FunctionNode {
'value[][][]',
'value[][][][]',
'value.value',
'value.thread.value',
'this.thread.value',
'this.output.value',
'this.constants.value',
Expand Down Expand Up @@ -3252,6 +3267,7 @@ class FunctionNode {
switch (variableSignature) {
case 'value':
return null;
case 'value.thread.value':
case 'this.thread.value':
case 'this.output.value':
return {
Expand Down Expand Up @@ -3514,7 +3530,6 @@ const typeLookupMap = {
module.exports = {
FunctionNode
};

},{"../utils":89,"./function-tracer":10,"acorn":1}],10:[function(require,module,exports){
class FunctionTracer {
constructor(ast) {
Expand Down Expand Up @@ -6975,6 +6990,7 @@ class WebGLFunctionNode extends FunctionNode {
zProperty
} = this.getMemberExpressionDetails(mNode);
switch (signature) {
case 'value.thread.value':
case 'this.thread.value':
if (name !== 'x' && name !== 'y' && name !== 'z') {
throw this.astErrorOutput('Unexpected expression, expected `this.thread.x`, `this.thread.y`, or `this.thread.z`', mNode);
Expand Down Expand Up @@ -7140,7 +7156,9 @@ class WebGLFunctionNode extends FunctionNode {
case 'Array3D':
case 'Array4D':
case 'Input':

case 'Number':
case 'Float':
case 'Integer':
if (this.precision === 'single') {
retArr.push(`getMemoryOptimized32(${markupName}, ${markupName}Size, ${markupName}Dim, `);
this.memberExpressionXYZ(xProperty, yProperty, zProperty, retArr);
Expand Down Expand Up @@ -7849,9 +7867,21 @@ class WebGLKernelValue extends KernelValue {
if (Array.isArray(value[0])) {
return this.getTransferArrayType(value[0]);
}
if (value.constructor === Array) {
return Float32Array;
switch (value.constructor) {
case Array:
case Int32Array:
case Int16Array:
case Int8Array:
return Float32Array;
case Uint8ClampedArray:
case Uint8Array:
case Uint16Array:
case Uint32Array:
case Float32Array:
case Float64Array:
return value.constructor;
}
console.warn('Unfamiliar constructor type. Will go ahead and use, but likley this may result in a transfer of zeros');
return value.constructor;
}
formatArrayTransfer(value, length, Type) {
Expand Down
50 changes: 40 additions & 10 deletions bin/gpu-browser-core.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* GPU Accelerated JavaScript
*
* @version 2.0.0-rc.15
* @date Mon Jun 17 2019 18:00:14 GMT-0400 (Eastern Daylight Time)
* @version 2.0.0-rc.16
* @date Thu Jun 20 2019 10:09:02 GMT-0400 (Eastern Daylight Time)
*
* @license MIT
* The MIT License
Expand All @@ -17,8 +17,8 @@
*
* GPU Accelerated JavaScript
*
* @version 2.0.0-rc.15
* @date Mon Jun 17 2019 18:00:12 GMT-0400 (Eastern Daylight Time)
* @version 2.0.0-rc.16
* @date Thu Jun 20 2019 10:09:00 GMT-0400 (Eastern Daylight Time)
*
* @license MIT
* The MIT License
Expand Down Expand Up @@ -2034,7 +2034,13 @@ class FunctionBuilder {
if (node.argumentTypes.length === 0 && ast.arguments.length > 0) {
const args = ast.arguments;
for (let j = 0; j < args.length; j++) {
this.lookupChain.push({
name: requestingNode.name,
ast: args[i],
requestingNode
});
node.argumentTypes[j] = requestingNode.getType(args[j]);
this.lookupChain.pop();
}
return node.returnType = node.getType(node.getJsAST());
}
Expand Down Expand Up @@ -2122,7 +2128,10 @@ class FunctionBuilder {

assignArgumentType(functionName, i, argumentType, requestingNode) {
if (!this._isFunction(functionName)) return;
this._getFunction(functionName).argumentTypes[i] = argumentType;
const fnNode = this._getFunction(functionName);
if (!fnNode.argumentTypes[i]) {
fnNode.argumentTypes[i] = argumentType;
}
}

trackArgumentSynonym(functionName, argumentName, calleeFunctionName, argumentIndex) {
Expand Down Expand Up @@ -2467,7 +2476,11 @@ class FunctionNode {
if (argumentType) {
type = argumentType;
} else if (this.lookupArgumentType) {
type = this.argumentTypes[argumentIndex] = this.lookupArgumentType(ast.name, this);
const foundArgumentType = this.lookupArgumentType(ast.name, this);
if (!this.argumentTypes[argumentIndex]) {
this.argumentTypes[argumentIndex] = foundArgumentType;
}
type = foundArgumentType;
}
}
if (!type && this.strictTypingChecking) {
Expand Down Expand Up @@ -2660,6 +2673,7 @@ class FunctionNode {
return this.getLookupType(this.getVariableType(ast.object.object.object));
case 'value[][][][]':
return this.getLookupType(this.getVariableType(ast.object.object.object.object));
case 'value.thread.value':
case 'this.thread.value':
return 'Integer';
case 'this.output.value':
Expand Down Expand Up @@ -2943,6 +2957,7 @@ class FunctionNode {
'value[][][]',
'value[][][][]',
'value.value',
'value.thread.value',
'this.thread.value',
'this.output.value',
'this.constants.value',
Expand Down Expand Up @@ -3265,6 +3280,7 @@ class FunctionNode {
switch (variableSignature) {
case 'value':
return null;
case 'value.thread.value':
case 'this.thread.value':
case 'this.output.value':
return {
Expand Down Expand Up @@ -3527,7 +3543,6 @@ const typeLookupMap = {
module.exports = {
FunctionNode
};

},{"../utils":89,"./function-tracer":10,"acorn":1}],10:[function(require,module,exports){
class FunctionTracer {
constructor(ast) {
Expand Down Expand Up @@ -6988,6 +7003,7 @@ class WebGLFunctionNode extends FunctionNode {
zProperty
} = this.getMemberExpressionDetails(mNode);
switch (signature) {
case 'value.thread.value':
case 'this.thread.value':
if (name !== 'x' && name !== 'y' && name !== 'z') {
throw this.astErrorOutput('Unexpected expression, expected `this.thread.x`, `this.thread.y`, or `this.thread.z`', mNode);
Expand Down Expand Up @@ -7153,7 +7169,9 @@ class WebGLFunctionNode extends FunctionNode {
case 'Array3D':
case 'Array4D':
case 'Input':

case 'Number':
case 'Float':
case 'Integer':
if (this.precision === 'single') {
retArr.push(`getMemoryOptimized32(${markupName}, ${markupName}Size, ${markupName}Dim, `);
this.memberExpressionXYZ(xProperty, yProperty, zProperty, retArr);
Expand Down Expand Up @@ -7862,9 +7880,21 @@ class WebGLKernelValue extends KernelValue {
if (Array.isArray(value[0])) {
return this.getTransferArrayType(value[0]);
}
if (value.constructor === Array) {
return Float32Array;
switch (value.constructor) {
case Array:
case Int32Array:
case Int16Array:
case Int8Array:
return Float32Array;
case Uint8ClampedArray:
case Uint8Array:
case Uint16Array:
case Uint32Array:
case Float32Array:
case Float64Array:
return value.constructor;
}
console.warn('Unfamiliar constructor type. Will go ahead and use, but likley this may result in a transfer of zeros');
return value.constructor;
}
formatArrayTransfer(value, length, Type) {
Expand Down
46 changes: 38 additions & 8 deletions bin/gpu-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* GPU Accelerated JavaScript
*
* @version 2.0.0-rc.15
* @date Mon Jun 17 2019 18:00:12 GMT-0400 (Eastern Daylight Time)
* @version 2.0.0-rc.16
* @date Thu Jun 20 2019 10:09:00 GMT-0400 (Eastern Daylight Time)
*
* @license MIT
* The MIT License
Expand Down Expand Up @@ -6785,7 +6785,13 @@ class FunctionBuilder {
if (node.argumentTypes.length === 0 && ast.arguments.length > 0) {
const args = ast.arguments;
for (let j = 0; j < args.length; j++) {
this.lookupChain.push({
name: requestingNode.name,
ast: args[i],
requestingNode
});
node.argumentTypes[j] = requestingNode.getType(args[j]);
this.lookupChain.pop();
}
return node.returnType = node.getType(node.getJsAST());
}
Expand Down Expand Up @@ -6873,7 +6879,10 @@ class FunctionBuilder {

assignArgumentType(functionName, i, argumentType, requestingNode) {
if (!this._isFunction(functionName)) return;
this._getFunction(functionName).argumentTypes[i] = argumentType;
const fnNode = this._getFunction(functionName);
if (!fnNode.argumentTypes[i]) {
fnNode.argumentTypes[i] = argumentType;
}
}

trackArgumentSynonym(functionName, argumentName, calleeFunctionName, argumentIndex) {
Expand Down Expand Up @@ -7218,7 +7227,11 @@ class FunctionNode {
if (argumentType) {
type = argumentType;
} else if (this.lookupArgumentType) {
type = this.argumentTypes[argumentIndex] = this.lookupArgumentType(ast.name, this);
const foundArgumentType = this.lookupArgumentType(ast.name, this);
if (!this.argumentTypes[argumentIndex]) {
this.argumentTypes[argumentIndex] = foundArgumentType;
}
type = foundArgumentType;
}
}
if (!type && this.strictTypingChecking) {
Expand Down Expand Up @@ -7411,6 +7424,7 @@ class FunctionNode {
return this.getLookupType(this.getVariableType(ast.object.object.object));
case 'value[][][][]':
return this.getLookupType(this.getVariableType(ast.object.object.object.object));
case 'value.thread.value':
case 'this.thread.value':
return 'Integer';
case 'this.output.value':
Expand Down Expand Up @@ -7694,6 +7708,7 @@ class FunctionNode {
'value[][][]',
'value[][][][]',
'value.value',
'value.thread.value',
'this.thread.value',
'this.output.value',
'this.constants.value',
Expand Down Expand Up @@ -8016,6 +8031,7 @@ class FunctionNode {
switch (variableSignature) {
case 'value':
return null;
case 'value.thread.value':
case 'this.thread.value':
case 'this.output.value':
return {
Expand Down Expand Up @@ -8278,7 +8294,6 @@ const typeLookupMap = {
module.exports = {
FunctionNode
};

},{"../utils":90,"./function-tracer":11,"acorn":1}],11:[function(require,module,exports){
class FunctionTracer {
constructor(ast) {
Expand Down Expand Up @@ -11739,6 +11754,7 @@ class WebGLFunctionNode extends FunctionNode {
zProperty
} = this.getMemberExpressionDetails(mNode);
switch (signature) {
case 'value.thread.value':
case 'this.thread.value':
if (name !== 'x' && name !== 'y' && name !== 'z') {
throw this.astErrorOutput('Unexpected expression, expected `this.thread.x`, `this.thread.y`, or `this.thread.z`', mNode);
Expand Down Expand Up @@ -11904,7 +11920,9 @@ class WebGLFunctionNode extends FunctionNode {
case 'Array3D':
case 'Array4D':
case 'Input':

case 'Number':
case 'Float':
case 'Integer':
if (this.precision === 'single') {
retArr.push(`getMemoryOptimized32(${markupName}, ${markupName}Size, ${markupName}Dim, `);
this.memberExpressionXYZ(xProperty, yProperty, zProperty, retArr);
Expand Down Expand Up @@ -12613,9 +12631,21 @@ class WebGLKernelValue extends KernelValue {
if (Array.isArray(value[0])) {
return this.getTransferArrayType(value[0]);
}
if (value.constructor === Array) {
return Float32Array;
switch (value.constructor) {
case Array:
case Int32Array:
case Int16Array:
case Int8Array:
return Float32Array;
case Uint8ClampedArray:
case Uint8Array:
case Uint16Array:
case Uint32Array:
case Float32Array:
case Float64Array:
return value.constructor;
}
console.warn('Unfamiliar constructor type. Will go ahead and use, but likley this may result in a transfer of zeros');
return value.constructor;
}
formatArrayTransfer(value, length, Type) {
Expand Down
Loading

0 comments on commit 914bae0

Please sign in to comment.