Merge pull request #274 from gpujs/272-kernel-performance

272 kernel performance
This commit is contained in:
Robert Plummer 2018-03-03 14:26:53 -05:00 committed by GitHub
commit 2f37e8762d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 41 additions and 101 deletions

View File

@ -4,8 +4,8 @@
*
* GPU Accelerated JavaScript
*
* @version 1.0.5
* @date Thu Mar 01 2018 17:45:11 GMT-0500 (EST)
* @version 1.0.6
* @date Sat Mar 03 2018 14:24:37 GMT-0500 (EST)
*
* @license MIT
* The MIT License

6
bin/gpu-core.min.js vendored
View File

@ -4,12 +4,12 @@
*
* GPU Accelerated JavaScript
*
* @version 1.0.4
* @date Thu Mar 01 2018 15:56:51 GMT-0500 (EST)
* @version 1.0.6
* @date Sat Mar 03 2018 14:24:37 GMT-0500 (EST)
*
* @license MIT
* The MIT License
*
* Copyright (c) 2018 gpu.js Team
*/
"use strict";!function e(n,t,r){function i(u,a){if(!t[u]){if(!n[u]){var l="function"==typeof require&&require;if(!a&&l)return l(u,!0);if(o)return o(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=t[u]={exports:{}};n[u][0].call(c.exports,function(e){var t=n[u][1][e];return i(t?t:e)},c,c.exports,e,n,t,r)}return t[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)i(r[u]);return i}({1:[function(e,n,t){function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}();e("./utils-core");n.exports=function(){function e(){r(this,e)}return i(e,null,[{key:"validateKernelObj",value:function(e){if(null===e)throw"KernelObj being validated is NULL";if("string"==typeof e){try{e=JSON.parse(e)}catch(n){throw console.error(n),"Failed to convert KernelObj from JSON string"}if(null===e)throw"Invalid (NULL) KernelObj JSON string representation"}if(e.isKernelObj!==!0)throw"Failed missing isKernelObj flag check";return e}},{key:"loadKernelObj",value:function(e,n){e=validateKernelObj(e)}}]),e}()},{"./utils-core":2}],2:[function(e,n,t){function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),o=function(){function e(){r(this,e)}return i(e,null,[{key:"isCanvas",value:function(e){return null!==e&&e.nodeName&&e.getContext&&"CANVAS"===e.nodeName.toUpperCase()}},{key:"isCanvasSupported",value:function(){return u}},{key:"initCanvas",value:function(){if(!u)return null;var e=document.createElement("canvas");return e.width=2,e.height=2,e}},{key:"isWebGl",value:function(e){return e&&"function"==typeof e.getExtension}},{key:"isWebGlSupported",value:function(){return l}},{key:"isWebGlDrawBuffersSupported",value:function(){return f}},{key:"initWebGlDefaultOptions",value:function(){return{alpha:!1,depth:!1,antialias:!1}}},{key:"initWebGl",value:function(n){if(("undefined"!=typeof u||null===n)&&!u)return null;if(!e.isCanvas(n))throw new Error("Invalid canvas object - "+n);var t=n.getContext("experimental-webgl",e.initWebGlDefaultOptions())||n.getContext("webgl",e.initWebGlDefaultOptions());return t&&(t.OES_texture_float=t.getExtension("OES_texture_float"),t.OES_texture_float_linear=t.getExtension("OES_texture_float_linear"),t.OES_element_index_uint=t.getExtension("OES_element_index_uint")),t}}]),e}(),u="undefined"!=typeof document&&o.isCanvas(document.createElement("canvas")),a=o.initWebGl(o.initCanvas()),l=o.isWebGl(a),f=l&&Boolean(a.getExtension("WEBGL_draw_buffers"));l?(o.OES_texture_float=a.OES_texture_float,o.OES_texture_float_linear=a.OES_texture_float_linear,o.OES_element_index_uint=a.OES_element_index_uint):(o.OES_texture_float=!1,o.OES_texture_float_linear=!1,o.OES_element_index_uint=!1),n.exports=o},{}],3:[function(e,n,t){var r=e("./core/gpu-core");"undefined"!=typeof n&&(n.exports=r),"undefined"!=typeof window&&(window.GPUCore=r,null===window.GPU&&(window.GPU=r))},{"./core/gpu-core":1}]},{},[3]);
"use strict";!function(){function e(n,t,r){function i(u,a){if(!t[u]){if(!n[u]){var l="function"==typeof require&&require;if(!a&&l)return l(u,!0);if(o)return o(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=t[u]={exports:{}};n[u][0].call(c.exports,function(e){var t=n[u][1][e];return i(t?t:e)},c,c.exports,e,n,t,r)}return t[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)i(r[u]);return i}return e}()({1:[function(e,n,t){function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}();e("./utils-core");n.exports=function(){function e(){r(this,e)}return i(e,null,[{key:"validateKernelObj",value:function(e){if(null===e)throw"KernelObj being validated is NULL";if("string"==typeof e){try{e=JSON.parse(e)}catch(n){throw console.error(n),"Failed to convert KernelObj from JSON string"}if(null===e)throw"Invalid (NULL) KernelObj JSON string representation"}if(e.isKernelObj!==!0)throw"Failed missing isKernelObj flag check";return e}},{key:"loadKernelObj",value:function(e,n){e=validateKernelObj(e)}}]),e}()},{"./utils-core":2}],2:[function(e,n,t){function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),o=function(){function e(){r(this,e)}return i(e,null,[{key:"isCanvas",value:function(e){return null!==e&&e.nodeName&&e.getContext&&"CANVAS"===e.nodeName.toUpperCase()}},{key:"isCanvasSupported",value:function(){return u}},{key:"initCanvas",value:function(){if(!u)return null;var e=document.createElement("canvas");return e.width=2,e.height=2,e}},{key:"isWebGl",value:function(e){return e&&"function"==typeof e.getExtension}},{key:"isWebGlSupported",value:function(){return l}},{key:"isWebGlDrawBuffersSupported",value:function(){return f}},{key:"initWebGlDefaultOptions",value:function(){return{alpha:!1,depth:!1,antialias:!1}}},{key:"initWebGl",value:function(n){if(("undefined"!=typeof u||null===n)&&!u)return null;if(!e.isCanvas(n))throw new Error("Invalid canvas object - "+n);var t=n.getContext("experimental-webgl",e.initWebGlDefaultOptions())||n.getContext("webgl",e.initWebGlDefaultOptions());return t&&(t.OES_texture_float=t.getExtension("OES_texture_float"),t.OES_texture_float_linear=t.getExtension("OES_texture_float_linear"),t.OES_element_index_uint=t.getExtension("OES_element_index_uint")),t}}]),e}(),u="undefined"!=typeof document&&o.isCanvas(document.createElement("canvas")),a=o.initWebGl(o.initCanvas()),l=o.isWebGl(a),f=l&&Boolean(a.getExtension("WEBGL_draw_buffers"));l?(o.OES_texture_float=a.OES_texture_float,o.OES_texture_float_linear=a.OES_texture_float_linear,o.OES_element_index_uint=a.OES_element_index_uint):(o.OES_texture_float=!1,o.OES_texture_float_linear=!1,o.OES_element_index_uint=!1),n.exports=o},{}],3:[function(e,n,t){var r=e("./core/gpu-core");"undefined"!=typeof n&&(n.exports=r),"undefined"!=typeof window&&(window.GPUCore=r,null===window.GPU&&(window.GPU=r))},{"./core/gpu-core":1}]},{},[3]);

View File

@ -4,8 +4,8 @@
*
* GPU Accelerated JavaScript
*
* @version 1.0.5
* @date Thu Mar 01 2018 17:45:11 GMT-0500 (EST)
* @version 1.0.6
* @date Sat Mar 03 2018 14:24:37 GMT-0500 (EST)
*
* @license MIT
* The MIT License
@ -1540,7 +1540,6 @@ module.exports = function () {
this.addFunction = null;
this.functions = null;
this.nativeFunctions = null;
this.copyData = true;
this.subKernels = null;
this.subKernelProperties = null;
this.subKernelNames = null;
@ -1706,12 +1705,6 @@ module.exports = function () {
this._webGl = webGl;
return this;
}
}, {
key: 'setCopyData',
value: function setCopyData(copyData) {
this.copyData = copyData;
return this;
}
}, {
@ -3064,7 +3057,7 @@ module.exports = function (_KernelBase) {
var output = [];
output.result = this.renderOutput(outputTexture);
for (var _i = 0; _i < this.subKernels.length; _i++) {
output.push(new Texture(this.subKernelOutputTextures[_i], texSize, this.output, this._webGl));
output.push(new Texture(this.subKernelOutputTextures[_i], texSize, this.threadDim, this.output, this._webGl));
}
return output;
} else if (this.subKernelProperties !== null) {
@ -3074,7 +3067,7 @@ module.exports = function (_KernelBase) {
var _i2 = 0;
for (var p in this.subKernelProperties) {
if (!this.subKernelProperties.hasOwnProperty(p)) continue;
_output[p] = new Texture(this.subKernelOutputTextures[_i2], texSize, this.output, this._webGl);
_output[p] = new Texture(this.subKernelOutputTextures[_i2], texSize, this.threadDim, this.output, this._webGl);
_i2++;
}
return _output;
@ -3093,7 +3086,7 @@ module.exports = function (_KernelBase) {
var threadDim = this.threadDim;
var output = this.output;
if (this.outputToTexture) {
return new Texture(outputTexture, texSize, output, this._webGl);
return new Texture(outputTexture, texSize, this.threadDim, output, this._webGl);
} else {
var result = void 0;
if (this.floatOutput) {
@ -3181,13 +3174,6 @@ module.exports = function (_KernelBase) {
}
}, {
key: 'getSubKernelTexture',
value: function getSubKernelTexture(name) {
return this.getTextureCache('SUB_KERNEL_' + name);
}
}, {
key: 'getTextureCache',
value: function getTextureCache(name) {
@ -3338,8 +3324,7 @@ module.exports = function (_KernelBase) {
case 'Texture':
{
var inputTexture = value;
var _dim2 = utils.getDimensions(inputTexture, true);
var _dim2 = inputTexture.dimensions;
var _size2 = inputTexture.size;
gl.activeTexture(gl.TEXTURE0 + this.argumentsLength);
@ -4091,11 +4076,12 @@ var gpu = null;
module.exports = function () {
function Texture(texture, size, output, webGl) {
function Texture(texture, size, dimensions, output, webGl) {
_classCallCheck(this, Texture);
this.texture = texture;
this.size = size;
this.dimensions = dimensions;
this.output = output;
this.webGl = webGl;
this.kernel = null;

16
bin/gpu.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -53,7 +53,6 @@ module.exports = function () {
this.addFunction = null;
this.functions = null;
this.nativeFunctions = null;
this.copyData = true;
this.subKernels = null;
this.subKernelProperties = null;
this.subKernelNames = null;
@ -316,12 +315,6 @@ module.exports = function () {
this._webGl = webGl;
return this;
}
}, {
key: 'setCopyData',
value: function setCopyData(copyData) {
this.copyData = copyData;
return this;
}
/**
* @memberOf BaseKernel#

View File

@ -327,7 +327,7 @@ module.exports = function (_KernelBase) {
var output = [];
output.result = this.renderOutput(outputTexture);
for (var _i = 0; _i < this.subKernels.length; _i++) {
output.push(new Texture(this.subKernelOutputTextures[_i], texSize, this.output, this._webGl));
output.push(new Texture(this.subKernelOutputTextures[_i], texSize, this.threadDim, this.output, this._webGl));
}
return output;
} else if (this.subKernelProperties !== null) {
@ -337,7 +337,7 @@ module.exports = function (_KernelBase) {
var _i2 = 0;
for (var p in this.subKernelProperties) {
if (!this.subKernelProperties.hasOwnProperty(p)) continue;
_output[p] = new Texture(this.subKernelOutputTextures[_i2], texSize, this.output, this._webGl);
_output[p] = new Texture(this.subKernelOutputTextures[_i2], texSize, this.threadDim, this.output, this._webGl);
_i2++;
}
return _output;
@ -374,7 +374,7 @@ module.exports = function (_KernelBase) {
var threadDim = this.threadDim;
var output = this.output;
if (this.outputToTexture) {
return new Texture(outputTexture, texSize, output, this._webGl);
return new Texture(outputTexture, texSize, this.threadDim, output, this._webGl);
} else {
var result = void 0;
if (this.floatOutput) {
@ -500,25 +500,6 @@ module.exports = function (_KernelBase) {
/**
* @memberOf WebGLKernel#
* @name getSubKernelTexture
* @function
*
* @desc This uses *getTextureCache* to get the Texture Cache of the sub-kernel
*
* @param {String} name - Name of the subKernel
*
* @returns {Object} Texture cache for the subKernel
*
*/
}, {
key: 'getSubKernelTexture',
value: function getSubKernelTexture(name) {
return this.getTextureCache('SUB_KERNEL_' + name);
}
/**
* @memberOf WebGLKernel#
* @name getTextureCache
* @function
*
@ -723,8 +704,7 @@ module.exports = function (_KernelBase) {
case 'Texture':
{
var inputTexture = value;
var _dim2 = utils.getDimensions(inputTexture, true);
var _dim2 = inputTexture.dimensions;
var _size2 = inputTexture.size;
gl.activeTexture(gl.TEXTURE0 + this.argumentsLength);

View File

@ -11,16 +11,18 @@ module.exports = function () {
/**
* @desc WebGl Texture implementation in JS
* @constructor Texture
* @param {Object} texture
* @param {Array} size
* @param {Object} texture
* @param {Array} size
* @param dimensions
* @param {Array} output
* @param {Object} webGl
*/
function Texture(texture, size, output, webGl) {
function Texture(texture, size, dimensions, output, webGl) {
_classCallCheck(this, Texture);
this.texture = texture;
this.size = size;
this.dimensions = dimensions;
this.output = output;
this.webGl = webGl;
this.kernel = null;

View File

@ -1,6 +1,6 @@
{
"name": "gpu.js",
"version": "1.0.5",
"version": "1.0.6",
"description": "GPU Accelerated JavaScript",
"main": "./dist/index.js",
"directories": {

View File

@ -47,7 +47,6 @@ module.exports = class BaseKernel {
this.addFunction = null;
this.functions = null;
this.nativeFunctions = null;
this.copyData = true;
this.subKernels = null;
this.subKernelProperties = null;
this.subKernelNames = null;
@ -272,11 +271,6 @@ module.exports = class BaseKernel {
return this;
}
setCopyData(copyData) {
this.copyData = copyData;
return this;
}
/**
* @memberOf BaseKernel#
* @function

View File

@ -315,7 +315,7 @@ module.exports = class WebGLKernel extends KernelBase {
const output = [];
output.result = this.renderOutput(outputTexture);
for (let i = 0; i < this.subKernels.length; i++) {
output.push(new Texture(this.subKernelOutputTextures[i], texSize, this.output, this._webGl));
output.push(new Texture(this.subKernelOutputTextures[i], texSize, this.threadDim, this.output, this._webGl));
}
return output;
} else if (this.subKernelProperties !== null) {
@ -325,7 +325,7 @@ module.exports = class WebGLKernel extends KernelBase {
let i = 0;
for (let p in this.subKernelProperties) {
if (!this.subKernelProperties.hasOwnProperty(p)) continue;
output[p] = new Texture(this.subKernelOutputTextures[i], texSize, this.output, this._webGl);
output[p] = new Texture(this.subKernelOutputTextures[i], texSize, this.threadDim, this.output, this._webGl);
i++;
}
return output;
@ -359,7 +359,7 @@ module.exports = class WebGLKernel extends KernelBase {
const threadDim = this.threadDim;
const output = this.output;
if (this.outputToTexture) {
return new Texture(outputTexture, texSize, output, this._webGl);
return new Texture(outputTexture, texSize, this.threadDim, output, this._webGl);
} else {
let result;
if (this.floatOutput) {
@ -471,22 +471,6 @@ module.exports = class WebGLKernel extends KernelBase {
return this.getTextureCache(`ARGUMENT_${ name }`);
}
/**
* @memberOf WebGLKernel#
* @name getSubKernelTexture
* @function
*
* @desc This uses *getTextureCache* to get the Texture Cache of the sub-kernel
*
* @param {String} name - Name of the subKernel
*
* @returns {Object} Texture cache for the subKernel
*
*/
getSubKernelTexture(name) {
return this.getTextureCache(`SUB_KERNEL_${ name }`);
}
/**
* @memberOf WebGLKernel#
* @name getTextureCache
@ -678,8 +662,7 @@ module.exports = class WebGLKernel extends KernelBase {
case 'Texture':
{
const inputTexture = value;
const dim = utils.getDimensions(inputTexture, true);
const dim = inputTexture.dimensions;
const size = inputTexture.size;
gl.activeTexture(gl.TEXTURE0 + this.argumentsLength);

View File

@ -7,14 +7,16 @@ module.exports = class Texture {
/**
* @desc WebGl Texture implementation in JS
* @constructor Texture
* @param {Object} texture
* @param {Array} size
* @param {Object} texture
* @param {Array} size
* @param dimensions
* @param {Array} output
* @param {Object} webGl
*/
constructor(texture, size, output, webGl) {
constructor(texture, size, dimensions, output, webGl) {
this.texture = texture;
this.size = size;
this.dimensions = dimensions;
this.output = output;
this.webGl = webGl;
this.kernel = null;

View File

@ -2,7 +2,7 @@ QUnit.test( "Issue #195 Read from Texture 2D", function() {
var matrixSize = 4;
var A = Array.apply(null, Array(matrixSize*matrixSize)).map(function (_, i) {return i;});
A = splitArray(A, matrixSize)
A = splitArray(A, matrixSize);
const gpu = new GPU({ mode: 'gpu' });