Skip to content

Commit 772eaec

Browse files
fix: Build
1 parent a37fe28 commit 772eaec

File tree

5 files changed

+101
-86
lines changed

5 files changed

+101
-86
lines changed

dist/gpu-browser-core.js

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.8.4
8-
* @date Mon Mar 16 2020 10:58:11 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.8.5
8+
* @date Fri Mar 20 2020 08:27:36 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -1490,6 +1490,7 @@ class CPUKernel extends Kernel {
14901490
}
14911491

14921492
build() {
1493+
if (this.built) return;
14931494
this.setupConstants();
14941495
this.setupArguments(arguments);
14951496
this.validateSettings(arguments);
@@ -6525,7 +6526,6 @@ class Kernel {
65256526

65266527
static getSignature(kernel, argumentTypes) {
65276528
throw new Error(`"getSignature" not implemented on ${ this.name }`);
6528-
return argumentTypes.length > 0 ? ':' + argumentTypes.join(',') : '';
65296529
}
65306530

65316531
functionToIGPUFunction(source, settings = {}) {
@@ -10105,6 +10105,7 @@ class WebGLKernel extends GLKernel {
1010510105
}
1010610106

1010710107
build() {
10108+
if (this.built) return;
1010810109
this.initExtensions();
1010910110
this.validateSettings(arguments);
1011010111
this.setupConstants(arguments);
@@ -11001,6 +11002,7 @@ float integerCorrectionModulo(float number, float divisor) {
1100111002
}
1100211003

1100311004
destroy(removeCanvasReferences) {
11005+
if (!this.context) return;
1100411006
if (this.buffer) {
1100511007
this.context.deleteBuffer(this.buffer);
1100611008
}
@@ -11059,6 +11061,10 @@ float integerCorrectionModulo(float number, float divisor) {
1105911061
this.destroyExtensions();
1106011062
delete this.context;
1106111063
delete this.canvas;
11064+
if (!this.gpu) return;
11065+
const i = this.gpu.kernels.indexOf(this);
11066+
if (i === -1) return;
11067+
this.gpu.kernels.splice(i, 1);
1106211068
}
1106311069

1106411070
destroyExtensions() {
@@ -13204,15 +13210,15 @@ class GPU {
1320413210
return result;
1320513211
}
1320613212

13207-
function onRequestSwitchKernel(reasons, args, kernel) {
13208-
if (kernel.debug) {
13213+
function onRequestSwitchKernel(reasons, args, _kernel) {
13214+
if (_kernel.debug) {
1320913215
console.warn('Switching kernels');
1321013216
}
1321113217
let newOutput = null;
13212-
if (kernel.signature && !switchableKernels[kernel.signature]) {
13213-
switchableKernels[kernel.signature] = kernel;
13218+
if (_kernel.signature && !switchableKernels[_kernel.signature]) {
13219+
switchableKernels[_kernel.signature] = _kernel;
1321413220
}
13215-
if (kernel.dynamicOutput) {
13221+
if (_kernel.dynamicOutput) {
1321613222
for (let i = reasons.length - 1; i >= 0; i--) {
1321713223
const reason = reasons[i];
1321813224
if (reason.type === 'outputPrecisionMismatch') {
@@ -13221,42 +13227,42 @@ class GPU {
1322113227
}
1322213228
}
1322313229

13224-
const Constructor = kernel.constructor;
13225-
const argumentTypes = Constructor.getArgumentTypes(kernel, args);
13226-
const signature = Constructor.getSignature(kernel, argumentTypes);
13230+
const Constructor = _kernel.constructor;
13231+
const argumentTypes = Constructor.getArgumentTypes(_kernel, args);
13232+
const signature = Constructor.getSignature(_kernel, argumentTypes);
1322713233
const existingKernel = switchableKernels[signature];
1322813234
if (existingKernel) {
1322913235
return existingKernel;
1323013236
}
1323113237

1323213238
const newKernel = switchableKernels[signature] = new Constructor(source, {
1323313239
argumentTypes,
13234-
constantTypes: kernel.constantTypes,
13235-
graphical: kernel.graphical,
13236-
loopMaxIterations: kernel.loopMaxIterations,
13237-
constants: kernel.constants,
13238-
dynamicOutput: kernel.dynamicOutput,
13239-
dynamicArgument: kernel.dynamicArguments,
13240-
context: kernel.context,
13241-
canvas: kernel.canvas,
13242-
output: newOutput || kernel.output,
13243-
precision: kernel.precision,
13244-
pipeline: kernel.pipeline,
13245-
immutable: kernel.immutable,
13246-
optimizeFloatMemory: kernel.optimizeFloatMemory,
13247-
fixIntegerDivisionAccuracy: kernel.fixIntegerDivisionAccuracy,
13248-
functions: kernel.functions,
13249-
nativeFunctions: kernel.nativeFunctions,
13250-
injectedNative: kernel.injectedNative,
13251-
subKernels: kernel.subKernels,
13252-
strictIntegers: kernel.strictIntegers,
13253-
debug: kernel.debug,
13254-
gpu: kernel.gpu,
13240+
constantTypes: _kernel.constantTypes,
13241+
graphical: _kernel.graphical,
13242+
loopMaxIterations: _kernel.loopMaxIterations,
13243+
constants: _kernel.constants,
13244+
dynamicOutput: _kernel.dynamicOutput,
13245+
dynamicArgument: _kernel.dynamicArguments,
13246+
context: _kernel.context,
13247+
canvas: _kernel.canvas,
13248+
output: newOutput || _kernel.output,
13249+
precision: _kernel.precision,
13250+
pipeline: _kernel.pipeline,
13251+
immutable: _kernel.immutable,
13252+
optimizeFloatMemory: _kernel.optimizeFloatMemory,
13253+
fixIntegerDivisionAccuracy: _kernel.fixIntegerDivisionAccuracy,
13254+
functions: _kernel.functions,
13255+
nativeFunctions: _kernel.nativeFunctions,
13256+
injectedNative: _kernel.injectedNative,
13257+
subKernels: _kernel.subKernels,
13258+
strictIntegers: _kernel.strictIntegers,
13259+
debug: _kernel.debug,
13260+
gpu: _kernel.gpu,
1325513261
validate,
13256-
returnType: kernel.returnType,
13257-
onIstanbulCoverageVariable: kernel.onIstanbulCoverageVariable,
13258-
removeIstanbulCoverage: kernel.removeIstanbulCoverage,
13259-
tactic: kernel.tactic,
13262+
returnType: _kernel.returnType,
13263+
onIstanbulCoverageVariable: _kernel.onIstanbulCoverageVariable,
13264+
removeIstanbulCoverage: _kernel.removeIstanbulCoverage,
13265+
tactic: _kernel.tactic,
1326013266
onRequestFallback,
1326113267
onRequestSwitchKernel,
1326213268
});
@@ -13278,17 +13284,18 @@ class GPU {
1327813284
onRequestSwitchKernel
1327913285
}, settingsCopy);
1328013286

13281-
const kernelRun = kernelRunShortcut(new this.Kernel(source, mergedSettings));
13287+
const kernel = new this.Kernel(source, mergedSettings);
13288+
const kernelRun = kernelRunShortcut(kernel);
1328213289

1328313290
if (!this.canvas) {
13284-
this.canvas = kernelRun.canvas;
13291+
this.canvas = kernel.canvas;
1328513292
}
1328613293

1328713294
if (!this.context) {
13288-
this.context = kernelRun.context;
13295+
this.context = kernel.context;
1328913296
}
1329013297

13291-
this.kernels.push(kernelRun);
13298+
this.kernels.push(kernel);
1329213299

1329313300
return kernelRun;
1329413301
}

dist/gpu-browser-core.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gpu-browser.js

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.8.4
8-
* @date Mon Mar 16 2020 10:58:11 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.8.5
8+
* @date Fri Mar 20 2020 08:27:36 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -5943,6 +5943,7 @@ class CPUKernel extends Kernel {
59435943
}
59445944

59455945
build() {
5946+
if (this.built) return;
59465947
this.setupConstants();
59475948
this.setupArguments(arguments);
59485949
this.validateSettings(arguments);
@@ -10978,7 +10979,6 @@ class Kernel {
1097810979

1097910980
static getSignature(kernel, argumentTypes) {
1098010981
throw new Error(`"getSignature" not implemented on ${ this.name }`);
10981-
return argumentTypes.length > 0 ? ':' + argumentTypes.join(',') : '';
1098210982
}
1098310983

1098410984
functionToIGPUFunction(source, settings = {}) {
@@ -14558,6 +14558,7 @@ class WebGLKernel extends GLKernel {
1455814558
}
1455914559

1456014560
build() {
14561+
if (this.built) return;
1456114562
this.initExtensions();
1456214563
this.validateSettings(arguments);
1456314564
this.setupConstants(arguments);
@@ -15454,6 +15455,7 @@ float integerCorrectionModulo(float number, float divisor) {
1545415455
}
1545515456

1545615457
destroy(removeCanvasReferences) {
15458+
if (!this.context) return;
1545715459
if (this.buffer) {
1545815460
this.context.deleteBuffer(this.buffer);
1545915461
}
@@ -15512,6 +15514,10 @@ float integerCorrectionModulo(float number, float divisor) {
1551215514
this.destroyExtensions();
1551315515
delete this.context;
1551415516
delete this.canvas;
15517+
if (!this.gpu) return;
15518+
const i = this.gpu.kernels.indexOf(this);
15519+
if (i === -1) return;
15520+
this.gpu.kernels.splice(i, 1);
1551515521
}
1551615522

1551715523
destroyExtensions() {
@@ -17657,15 +17663,15 @@ class GPU {
1765717663
return result;
1765817664
}
1765917665

17660-
function onRequestSwitchKernel(reasons, args, kernel) {
17661-
if (kernel.debug) {
17666+
function onRequestSwitchKernel(reasons, args, _kernel) {
17667+
if (_kernel.debug) {
1766217668
console.warn('Switching kernels');
1766317669
}
1766417670
let newOutput = null;
17665-
if (kernel.signature && !switchableKernels[kernel.signature]) {
17666-
switchableKernels[kernel.signature] = kernel;
17671+
if (_kernel.signature && !switchableKernels[_kernel.signature]) {
17672+
switchableKernels[_kernel.signature] = _kernel;
1766717673
}
17668-
if (kernel.dynamicOutput) {
17674+
if (_kernel.dynamicOutput) {
1766917675
for (let i = reasons.length - 1; i >= 0; i--) {
1767017676
const reason = reasons[i];
1767117677
if (reason.type === 'outputPrecisionMismatch') {
@@ -17674,42 +17680,42 @@ class GPU {
1767417680
}
1767517681
}
1767617682

17677-
const Constructor = kernel.constructor;
17678-
const argumentTypes = Constructor.getArgumentTypes(kernel, args);
17679-
const signature = Constructor.getSignature(kernel, argumentTypes);
17683+
const Constructor = _kernel.constructor;
17684+
const argumentTypes = Constructor.getArgumentTypes(_kernel, args);
17685+
const signature = Constructor.getSignature(_kernel, argumentTypes);
1768017686
const existingKernel = switchableKernels[signature];
1768117687
if (existingKernel) {
1768217688
return existingKernel;
1768317689
}
1768417690

1768517691
const newKernel = switchableKernels[signature] = new Constructor(source, {
1768617692
argumentTypes,
17687-
constantTypes: kernel.constantTypes,
17688-
graphical: kernel.graphical,
17689-
loopMaxIterations: kernel.loopMaxIterations,
17690-
constants: kernel.constants,
17691-
dynamicOutput: kernel.dynamicOutput,
17692-
dynamicArgument: kernel.dynamicArguments,
17693-
context: kernel.context,
17694-
canvas: kernel.canvas,
17695-
output: newOutput || kernel.output,
17696-
precision: kernel.precision,
17697-
pipeline: kernel.pipeline,
17698-
immutable: kernel.immutable,
17699-
optimizeFloatMemory: kernel.optimizeFloatMemory,
17700-
fixIntegerDivisionAccuracy: kernel.fixIntegerDivisionAccuracy,
17701-
functions: kernel.functions,
17702-
nativeFunctions: kernel.nativeFunctions,
17703-
injectedNative: kernel.injectedNative,
17704-
subKernels: kernel.subKernels,
17705-
strictIntegers: kernel.strictIntegers,
17706-
debug: kernel.debug,
17707-
gpu: kernel.gpu,
17693+
constantTypes: _kernel.constantTypes,
17694+
graphical: _kernel.graphical,
17695+
loopMaxIterations: _kernel.loopMaxIterations,
17696+
constants: _kernel.constants,
17697+
dynamicOutput: _kernel.dynamicOutput,
17698+
dynamicArgument: _kernel.dynamicArguments,
17699+
context: _kernel.context,
17700+
canvas: _kernel.canvas,
17701+
output: newOutput || _kernel.output,
17702+
precision: _kernel.precision,
17703+
pipeline: _kernel.pipeline,
17704+
immutable: _kernel.immutable,
17705+
optimizeFloatMemory: _kernel.optimizeFloatMemory,
17706+
fixIntegerDivisionAccuracy: _kernel.fixIntegerDivisionAccuracy,
17707+
functions: _kernel.functions,
17708+
nativeFunctions: _kernel.nativeFunctions,
17709+
injectedNative: _kernel.injectedNative,
17710+
subKernels: _kernel.subKernels,
17711+
strictIntegers: _kernel.strictIntegers,
17712+
debug: _kernel.debug,
17713+
gpu: _kernel.gpu,
1770817714
validate,
17709-
returnType: kernel.returnType,
17710-
onIstanbulCoverageVariable: kernel.onIstanbulCoverageVariable,
17711-
removeIstanbulCoverage: kernel.removeIstanbulCoverage,
17712-
tactic: kernel.tactic,
17715+
returnType: _kernel.returnType,
17716+
onIstanbulCoverageVariable: _kernel.onIstanbulCoverageVariable,
17717+
removeIstanbulCoverage: _kernel.removeIstanbulCoverage,
17718+
tactic: _kernel.tactic,
1771317719
onRequestFallback,
1771417720
onRequestSwitchKernel,
1771517721
});
@@ -17731,17 +17737,18 @@ class GPU {
1773117737
onRequestSwitchKernel
1773217738
}, settingsCopy);
1773317739

17734-
const kernelRun = kernelRunShortcut(new this.Kernel(source, mergedSettings));
17740+
const kernel = new this.Kernel(source, mergedSettings);
17741+
const kernelRun = kernelRunShortcut(kernel);
1773517742

1773617743
if (!this.canvas) {
17737-
this.canvas = kernelRun.canvas;
17744+
this.canvas = kernel.canvas;
1773817745
}
1773917746

1774017747
if (!this.context) {
17741-
this.context = kernelRun.context;
17748+
this.context = kernel.context;
1774217749
}
1774317750

17744-
this.kernels.push(kernelRun);
17751+
this.kernels.push(kernel);
1774517752

1774617753
return kernelRun;
1774717754
}

dist/gpu-browser.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/all.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
<script type="module" src="issues/91-create-kernel-map-array.js"></script>
181181
<script type="module" src="issues/96-param-names.js"></script>
182182
<script type="module" src="features/to-string/as-file.js"></script>
183+
<script type="module" src="internal/backend/cpu-kernel.js"></script>
183184
<script type="module" src="internal/backend/gl-kernel.js"></script>
184185
<script type="module" src="internal/backend/function-node/isSafe.js"></script>
185186
<script type="module" src="internal/backend/function-node/isSafeDependencies.js"></script>

0 commit comments

Comments
 (0)