From a3fb60c73a0703c02c8d08ce64abb41a4e758298 Mon Sep 17 00:00:00 2001 From: Bilal Kazi Date: Sun, 12 Aug 2018 21:45:00 +0100 Subject: [PATCH 1/5] Add support for using webgl in a worker via offscreen canvas Add feature to check if in worker Add types for offscreen canvas Add test for canvas when running in worker --- src/environment.ts | 2 ++ src/environment_test.ts | 21 +++++++++++++++++++++ src/environment_util.ts | 3 +++ src/kernels/backend_webgl.ts | 4 +++- tsconfig.json | 6 +++++- types/OffscreenCanvas.d.ts | 6 ++++++ types/importScripts.d.ts | 1 + 7 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 types/OffscreenCanvas.d.ts create mode 100644 types/importScripts.d.ts diff --git a/src/environment.ts b/src/environment.ts index b04406b82a..75754768bd 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -268,6 +268,8 @@ export class Environment { return false; } else if (feature === 'IS_BROWSER') { return typeof window !== 'undefined'; + } else if (feature === 'IS_WORKER') { + return typeof importScripts !== 'undefined'; } else if (feature === 'IS_NODE') { return (typeof process !== 'undefined') && (typeof process.versions.node !== 'undefined'); diff --git a/src/environment_test.ts b/src/environment_test.ts index c0b31542d5..e785374aee 100644 --- a/src/environment_test.ts +++ b/src/environment_test.ts @@ -263,6 +263,27 @@ describe('Backend', () => { ENV.removeBackend('custom-cpu'); }); + it('web worker', () => { + if (typeof OffscreenCanvas !== 'undefined') { + const features = { + 'WEBGL_VERSION': 2, + 'IS_WORKER': true, + 'IS_BROWSER': false + }; + ENV.setFeatures(features); + + let backend: MathBackendWebGL; + const success = ENV.registerBackend('worker-webgl', () => { + backend = new MathBackendWebGL(); + return backend; + }, 104); + expect(success).toBe(true); + + const canvas = backend.getCanvas(); + expect(canvas.constructor.name).toBe('OffscreenCanvas'); + } + }); + it('default custom background null', () => { expect(ENV.findBackend('custom')).toBeNull(); }); diff --git a/src/environment_util.ts b/src/environment_util.ts index 1cf8d7bfef..29e8fec3a4 100644 --- a/src/environment_util.ts +++ b/src/environment_util.ts @@ -20,6 +20,8 @@ export interface Features { 'DEBUG'?: boolean; // Whether we are in a browser (as versus, say, node.js) environment. 'IS_BROWSER'?: boolean; + // Whether we are in a web worker environment + 'IS_WORKER'?: boolean; // Whether we are in the Node.js environment. 'IS_NODE'?: boolean; // The disjoint_query_timer extension version. @@ -61,6 +63,7 @@ export enum Type { export const URL_PROPERTIES: URLProperty[] = [ {name: 'DEBUG', type: Type.BOOLEAN}, {name: 'IS_BROWSER', type: Type.BOOLEAN}, + {name: 'IS_WORKER', type: Type.BOOLEAN}, {name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION', type: Type.NUMBER}, {name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE', type: Type.BOOLEAN}, {name: 'WEBGL_VERSION', type: Type.NUMBER}, diff --git a/src/kernels/backend_webgl.ts b/src/kernels/backend_webgl.ts index 9bb6c16ad5..f745f6b13d 100644 --- a/src/kernels/backend_webgl.ts +++ b/src/kernels/backend_webgl.ts @@ -412,7 +412,9 @@ export class MathBackendWebGL implements KernelBackend { if (ENV.get('WEBGL_VERSION') < 1) { throw new Error('WebGL is not supported on this device'); } - if (ENV.get('IS_BROWSER')) { + if (ENV.get('IS_WORKER')) { + this.canvas = new OffscreenCanvas(1, 1); + } else if (ENV.get('IS_BROWSER')) { this.canvas = document.createElement('canvas'); } if (gpgpu == null) { diff --git a/tsconfig.json b/tsconfig.json index 7177eaf672..b02869fef2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,10 @@ "preserveConstEnums": true, "declaration": true, "target": "es5", - "lib": ["es2015", "dom"], + "lib": [ + "es2015", + "dom" + ], "outDir": "./dist", "noUnusedLocals": true, "noImplicitReturns": true, @@ -20,6 +23,7 @@ "allowUnreachableCode": false }, "include": [ + "types/", "src/" ] } diff --git a/types/OffscreenCanvas.d.ts b/types/OffscreenCanvas.d.ts new file mode 100644 index 0000000000..25b34c7204 --- /dev/null +++ b/types/OffscreenCanvas.d.ts @@ -0,0 +1,6 @@ +declare let OffscreenCanvas: { + new (width: number, height: number): HTMLCanvasElement; + prototype: HTMLCanvasElement; +} + +interface OffscreenCanvas extends EventTarget {} diff --git a/types/importScripts.d.ts b/types/importScripts.d.ts new file mode 100644 index 0000000000..c69335bd95 --- /dev/null +++ b/types/importScripts.d.ts @@ -0,0 +1 @@ +declare function importScripts(...urls: string[]): void; \ No newline at end of file From 403c66c10d02590e874b8321da22f3ecfcbf77cc Mon Sep 17 00:00:00 2001 From: Bilal Kazi Date: Tue, 14 Aug 2018 21:50:58 +0100 Subject: [PATCH 2/5] Add checks for is worker feature --- src/environment.ts | 17 +++++++++++------ src/environment_util.ts | 34 +++++++++++++++++++++------------- src/kernels/backend_webgl.ts | 14 ++++++++------ 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/environment.ts b/src/environment.ts index 75754768bd..155ecfdbf8 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -292,28 +292,33 @@ export class Environment { return 0; } return getWebGLDisjointQueryTimerVersion( - webGLVersion, this.get('IS_BROWSER')); + webGLVersion, this.get('IS_BROWSER'), this.get('IS_WORKER')); } else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE') { return this.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0 && !device_util.isMobile(); } else if (feature === 'HAS_WEBGL') { return this.get('WEBGL_VERSION') > 0; } else if (feature === 'WEBGL_VERSION') { - if (isWebGLVersionEnabled(2, this.get('IS_BROWSER'))) { + if (isWebGLVersionEnabled( + 2, this.get('IS_BROWSER'), this.get('IS_WORKER'))) { return 2; - } else if (isWebGLVersionEnabled(1, this.get('IS_BROWSER'))) { + } else if (isWebGLVersionEnabled( + 1, this.get('IS_BROWSER'), this.get('IS_WORKER'))) { return 1; } return 0; } else if (feature === 'WEBGL_RENDER_FLOAT32_ENABLED') { return isRenderToFloatTextureEnabled( - this.get('WEBGL_VERSION'), this.get('IS_BROWSER')); + this.get('WEBGL_VERSION'), this.get('IS_BROWSER'), + this.get('IS_WORKER')); } else if (feature === 'WEBGL_DOWNLOAD_FLOAT_ENABLED') { return isDownloadFloatTextureEnabled( - this.get('WEBGL_VERSION'), this.get('IS_BROWSER')); + this.get('WEBGL_VERSION'), this.get('IS_BROWSER'), + this.get('IS_WORKER')); } else if (feature === 'WEBGL_FENCE_API_ENABLED') { return isWebGLFenceEnabled( - this.get('WEBGL_VERSION'), this.get('IS_BROWSER')); + this.get('WEBGL_VERSION'), this.get('IS_BROWSER'), + this.get('IS_WORKER')); } else if (feature === 'TEST_EPSILON') { if (this.get('WEBGL_RENDER_FLOAT32_ENABLED')) { return TEST_EPSILON_FLOAT32_ENABLED; diff --git a/src/environment_util.ts b/src/environment_util.ts index 29e8fec3a4..3f86d97226 100644 --- a/src/environment_util.ts +++ b/src/environment_util.ts @@ -78,10 +78,11 @@ export interface URLProperty { type: Type; } -export function isWebGLVersionEnabled(webGLVersion: 1|2, isBrowser: boolean) { +export function isWebGLVersionEnabled( + webGLVersion: 1|2, isBrowser: boolean, isWorker: boolean) { let gl; try { - gl = getWebGLRenderingContext(webGLVersion, isBrowser); + gl = getWebGLRenderingContext(webGLVersion, isBrowser, isWorker); } catch (e) { return false; } @@ -94,13 +95,13 @@ export function isWebGLVersionEnabled(webGLVersion: 1|2, isBrowser: boolean) { } export function getWebGLDisjointQueryTimerVersion( - webGLVersion: number, isBrowser: boolean): number { + webGLVersion: number, isBrowser: boolean, isWorker: boolean): number { if (webGLVersion === 0) { return 0; } let queryTimerVersion: number; - const gl = getWebGLRenderingContext(webGLVersion, isBrowser); + const gl = getWebGLRenderingContext(webGLVersion, isBrowser, isWorker); if (hasExtension(gl, 'EXT_disjoint_timer_query_webgl2') && webGLVersion === 2) { @@ -118,12 +119,12 @@ export function getWebGLDisjointQueryTimerVersion( } export function isRenderToFloatTextureEnabled( - webGLVersion: number, isBrowser: boolean): boolean { + webGLVersion: number, isBrowser: boolean, isWorker: boolean): boolean { if (webGLVersion === 0) { return false; } - const gl = getWebGLRenderingContext(webGLVersion, isBrowser); + const gl = getWebGLRenderingContext(webGLVersion, isBrowser, isWorker); if (webGLVersion === 1) { if (!hasExtension(gl, 'OES_texture_float')) { @@ -145,12 +146,12 @@ export function isRenderToFloatTextureEnabled( } export function isDownloadFloatTextureEnabled( - webGLVersion: number, isBrowser: boolean): boolean { + webGLVersion: number, isBrowser: boolean, isWorker: boolean): boolean { if (webGLVersion === 0) { return false; } - const gl = getWebGLRenderingContext(webGLVersion, isBrowser); + const gl = getWebGLRenderingContext(webGLVersion, isBrowser, isWorker); if (webGLVersion === 1) { if (!hasExtension(gl, 'OES_texture_float')) { @@ -172,11 +173,12 @@ export function isDownloadFloatTextureEnabled( return readPixelsNoError; } -export function isWebGLFenceEnabled(webGLVersion: number, isBrowser: boolean) { +export function isWebGLFenceEnabled( + webGLVersion: number, isBrowser: boolean, isWorker: boolean) { if (webGLVersion !== 2) { return false; } - const gl = getWebGLRenderingContext(webGLVersion, isBrowser); + const gl = getWebGLRenderingContext(webGLVersion, isBrowser, isWorker); // tslint:disable-next-line:no-any const isEnabled = (gl as any).fenceSync != null; @@ -237,12 +239,18 @@ function hasExtension(gl: WebGLRenderingContext, extensionName: string) { } function getWebGLRenderingContext( - webGLVersion: number, isBrowser: boolean): WebGLRenderingContext { - if (webGLVersion === 0 || !isBrowser) { + webGLVersion: number, isBrowser: boolean, + isWorker: boolean): WebGLRenderingContext { + if (webGLVersion === 0 || !(isBrowser || isWorker)) { throw new Error('Cannot get WebGL rendering context, WebGL is disabled.'); } - const tempCanvas = document.createElement('canvas'); + let tempCanvas; + if (isBrowser) { + tempCanvas = document.createElement('canvas'); + } else { + tempCanvas = new OffscreenCanvas(1, 1); + } if (webGLVersion === 1) { return (tempCanvas.getContext('webgl') || diff --git a/src/kernels/backend_webgl.ts b/src/kernels/backend_webgl.ts index f745f6b13d..da23d6771b 100644 --- a/src/kernels/backend_webgl.ts +++ b/src/kernels/backend_webgl.ts @@ -414,8 +414,15 @@ export class MathBackendWebGL implements KernelBackend { } if (ENV.get('IS_WORKER')) { this.canvas = new OffscreenCanvas(1, 1); + this.NUM_BYTES_BEFORE_PAGING = (1280 * 720 * 1) * BEFORE_PAGING_CONSTANT; } else if (ENV.get('IS_BROWSER')) { this.canvas = document.createElement('canvas'); + // Use the device screen's resolution as a heuristic to decide on the + // maximum memory allocated on the GPU before starting to page. + this.NUM_BYTES_BEFORE_PAGING = + (window.screen.height * window.screen.width * + window.devicePixelRatio) * + BEFORE_PAGING_CONSTANT; } if (gpgpu == null) { this.gpgpu = new GPGPUContext(gpgpu_util.createWebGLContext(this.canvas)); @@ -423,11 +430,6 @@ export class MathBackendWebGL implements KernelBackend { } else { this.gpgpuCreatedLocally = false; } - // Use the device screen's resolution as a heuristic to decide on the - // maximum memory allocated on the GPU before starting to page. - this.NUM_BYTES_BEFORE_PAGING = - (window.screen.height * window.screen.width * window.devicePixelRatio) * - BEFORE_PAGING_CONSTANT; this.textureManager = new TextureManager(this.gpgpu); } @@ -1432,7 +1434,7 @@ export class MathBackendWebGL implements KernelBackend { } } -if (ENV.get('IS_BROWSER')) { +if (ENV.get('IS_BROWSER') || ENV.get('IS_WORKER')) { ENV.registerBackend( 'webgl', () => new MathBackendWebGL(), 2 /* priority */, setTensorTracker); From d40bafd3b88c4128cc179ba341f304a276794b0e Mon Sep 17 00:00:00 2001 From: Bilal Kazi Date: Sun, 19 Aug 2018 11:31:12 +0100 Subject: [PATCH 3/5] Add files option to ts-node Fixes failing tests on node 10 https://github.com/TypeStrong/ts-node/issues/615 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b7c3a907d..8e46b4b6f6 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "coverage": "KARMA_COVERAGE=1 karma start --browsers='Chrome' --singleRun", "test": "karma start", "test-travis": "karma start --singleRun --reporters='dots,karma-typescript,BrowserStack' --hostname='bs-local.com'", - "test-node": "ts-node src/test_node.ts", + "test-node": "ts-node --files src/test_node.ts", "test-all": "./scripts/test-all.sh" }, "dependencies": { From a2bea7f4a5c80234c4d64a71631525c870a884b5 Mon Sep 17 00:00:00 2001 From: Bilal Kazi Date: Sun, 16 Dec 2018 00:46:23 +0000 Subject: [PATCH 4/5] Remove extra flag for web worker defaults to using offscreen canvas --- src/environment.ts | 19 ++++++------------ src/environment_util.ts | 39 ++++++++++++++---------------------- src/kernels/backend_webgl.ts | 26 +++++++++++++----------- 3 files changed, 35 insertions(+), 49 deletions(-) diff --git a/src/environment.ts b/src/environment.ts index 155ecfdbf8..b04406b82a 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -268,8 +268,6 @@ export class Environment { return false; } else if (feature === 'IS_BROWSER') { return typeof window !== 'undefined'; - } else if (feature === 'IS_WORKER') { - return typeof importScripts !== 'undefined'; } else if (feature === 'IS_NODE') { return (typeof process !== 'undefined') && (typeof process.versions.node !== 'undefined'); @@ -292,33 +290,28 @@ export class Environment { return 0; } return getWebGLDisjointQueryTimerVersion( - webGLVersion, this.get('IS_BROWSER'), this.get('IS_WORKER')); + webGLVersion, this.get('IS_BROWSER')); } else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE') { return this.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0 && !device_util.isMobile(); } else if (feature === 'HAS_WEBGL') { return this.get('WEBGL_VERSION') > 0; } else if (feature === 'WEBGL_VERSION') { - if (isWebGLVersionEnabled( - 2, this.get('IS_BROWSER'), this.get('IS_WORKER'))) { + if (isWebGLVersionEnabled(2, this.get('IS_BROWSER'))) { return 2; - } else if (isWebGLVersionEnabled( - 1, this.get('IS_BROWSER'), this.get('IS_WORKER'))) { + } else if (isWebGLVersionEnabled(1, this.get('IS_BROWSER'))) { return 1; } return 0; } else if (feature === 'WEBGL_RENDER_FLOAT32_ENABLED') { return isRenderToFloatTextureEnabled( - this.get('WEBGL_VERSION'), this.get('IS_BROWSER'), - this.get('IS_WORKER')); + this.get('WEBGL_VERSION'), this.get('IS_BROWSER')); } else if (feature === 'WEBGL_DOWNLOAD_FLOAT_ENABLED') { return isDownloadFloatTextureEnabled( - this.get('WEBGL_VERSION'), this.get('IS_BROWSER'), - this.get('IS_WORKER')); + this.get('WEBGL_VERSION'), this.get('IS_BROWSER')); } else if (feature === 'WEBGL_FENCE_API_ENABLED') { return isWebGLFenceEnabled( - this.get('WEBGL_VERSION'), this.get('IS_BROWSER'), - this.get('IS_WORKER')); + this.get('WEBGL_VERSION'), this.get('IS_BROWSER')); } else if (feature === 'TEST_EPSILON') { if (this.get('WEBGL_RENDER_FLOAT32_ENABLED')) { return TEST_EPSILON_FLOAT32_ENABLED; diff --git a/src/environment_util.ts b/src/environment_util.ts index 3f86d97226..3acbfddd54 100644 --- a/src/environment_util.ts +++ b/src/environment_util.ts @@ -20,8 +20,6 @@ export interface Features { 'DEBUG'?: boolean; // Whether we are in a browser (as versus, say, node.js) environment. 'IS_BROWSER'?: boolean; - // Whether we are in a web worker environment - 'IS_WORKER'?: boolean; // Whether we are in the Node.js environment. 'IS_NODE'?: boolean; // The disjoint_query_timer extension version. @@ -63,7 +61,6 @@ export enum Type { export const URL_PROPERTIES: URLProperty[] = [ {name: 'DEBUG', type: Type.BOOLEAN}, {name: 'IS_BROWSER', type: Type.BOOLEAN}, - {name: 'IS_WORKER', type: Type.BOOLEAN}, {name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION', type: Type.NUMBER}, {name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE', type: Type.BOOLEAN}, {name: 'WEBGL_VERSION', type: Type.NUMBER}, @@ -78,11 +75,10 @@ export interface URLProperty { type: Type; } -export function isWebGLVersionEnabled( - webGLVersion: 1|2, isBrowser: boolean, isWorker: boolean) { +export function isWebGLVersionEnabled(webGLVersion: 1|2, isBrowser: boolean) { let gl; try { - gl = getWebGLRenderingContext(webGLVersion, isBrowser, isWorker); + gl = getWebGLRenderingContext(webGLVersion, isBrowser); } catch (e) { return false; } @@ -95,13 +91,13 @@ export function isWebGLVersionEnabled( } export function getWebGLDisjointQueryTimerVersion( - webGLVersion: number, isBrowser: boolean, isWorker: boolean): number { + webGLVersion: number, isBrowser: boolean): number { if (webGLVersion === 0) { return 0; } let queryTimerVersion: number; - const gl = getWebGLRenderingContext(webGLVersion, isBrowser, isWorker); + const gl = getWebGLRenderingContext(webGLVersion, isBrowser); if (hasExtension(gl, 'EXT_disjoint_timer_query_webgl2') && webGLVersion === 2) { @@ -119,12 +115,12 @@ export function getWebGLDisjointQueryTimerVersion( } export function isRenderToFloatTextureEnabled( - webGLVersion: number, isBrowser: boolean, isWorker: boolean): boolean { + webGLVersion: number, isBrowser: boolean): boolean { if (webGLVersion === 0) { return false; } - const gl = getWebGLRenderingContext(webGLVersion, isBrowser, isWorker); + const gl = getWebGLRenderingContext(webGLVersion, isBrowser); if (webGLVersion === 1) { if (!hasExtension(gl, 'OES_texture_float')) { @@ -146,12 +142,12 @@ export function isRenderToFloatTextureEnabled( } export function isDownloadFloatTextureEnabled( - webGLVersion: number, isBrowser: boolean, isWorker: boolean): boolean { + webGLVersion: number, isBrowser: boolean): boolean { if (webGLVersion === 0) { return false; } - const gl = getWebGLRenderingContext(webGLVersion, isBrowser, isWorker); + const gl = getWebGLRenderingContext(webGLVersion, isBrowser); if (webGLVersion === 1) { if (!hasExtension(gl, 'OES_texture_float')) { @@ -173,12 +169,11 @@ export function isDownloadFloatTextureEnabled( return readPixelsNoError; } -export function isWebGLFenceEnabled( - webGLVersion: number, isBrowser: boolean, isWorker: boolean) { +export function isWebGLFenceEnabled(webGLVersion: number, isBrowser: boolean) { if (webGLVersion !== 2) { return false; } - const gl = getWebGLRenderingContext(webGLVersion, isBrowser, isWorker); + const gl = getWebGLRenderingContext(webGLVersion, isBrowser); // tslint:disable-next-line:no-any const isEnabled = (gl as any).fenceSync != null; @@ -239,18 +234,14 @@ function hasExtension(gl: WebGLRenderingContext, extensionName: string) { } function getWebGLRenderingContext( - webGLVersion: number, isBrowser: boolean, - isWorker: boolean): WebGLRenderingContext { - if (webGLVersion === 0 || !(isBrowser || isWorker)) { + webGLVersion: number, isBrowser: boolean): WebGLRenderingContext { + if (webGLVersion === 0 || !isBrowser) { throw new Error('Cannot get WebGL rendering context, WebGL is disabled.'); } - let tempCanvas; - if (isBrowser) { - tempCanvas = document.createElement('canvas'); - } else { - tempCanvas = new OffscreenCanvas(1, 1); - } + const tempCanvas = (window && ('OffscreenCanvas' in window)) ? + new OffscreenCanvas(1, 1) : + document.createElement('canvas'); if (webGLVersion === 1) { return (tempCanvas.getContext('webgl') || diff --git a/src/kernels/backend_webgl.ts b/src/kernels/backend_webgl.ts index da23d6771b..fd02f89f32 100644 --- a/src/kernels/backend_webgl.ts +++ b/src/kernels/backend_webgl.ts @@ -412,17 +412,19 @@ export class MathBackendWebGL implements KernelBackend { if (ENV.get('WEBGL_VERSION') < 1) { throw new Error('WebGL is not supported on this device'); } - if (ENV.get('IS_WORKER')) { - this.canvas = new OffscreenCanvas(1, 1); - this.NUM_BYTES_BEFORE_PAGING = (1280 * 720 * 1) * BEFORE_PAGING_CONSTANT; - } else if (ENV.get('IS_BROWSER')) { - this.canvas = document.createElement('canvas'); - // Use the device screen's resolution as a heuristic to decide on the - // maximum memory allocated on the GPU before starting to page. - this.NUM_BYTES_BEFORE_PAGING = - (window.screen.height * window.screen.width * - window.devicePixelRatio) * - BEFORE_PAGING_CONSTANT; + if (ENV.get('IS_BROWSER')) { + if (window && ('OffscreenCanvas' in window)) { + this.canvas = new OffscreenCanvas(1, 1); + this.NUM_BYTES_BEFORE_PAGING = Infinity; + } else { + this.canvas = document.createElement('canvas'); + // Use the device screen's resolution as a heuristic to decide on the + // maximum memory allocated on the GPU before starting to page. + this.NUM_BYTES_BEFORE_PAGING = + (window.screen.height * window.screen.width * + window.devicePixelRatio) * + BEFORE_PAGING_CONSTANT; + } } if (gpgpu == null) { this.gpgpu = new GPGPUContext(gpgpu_util.createWebGLContext(this.canvas)); @@ -1434,7 +1436,7 @@ export class MathBackendWebGL implements KernelBackend { } } -if (ENV.get('IS_BROWSER') || ENV.get('IS_WORKER')) { +if (ENV.get('IS_BROWSER')) { ENV.registerBackend( 'webgl', () => new MathBackendWebGL(), 2 /* priority */, setTensorTracker); From a140f05a6f94e6acc70c33a9591c0da0b40fdd11 Mon Sep 17 00:00:00 2001 From: Bilal Kazi Date: Sun, 16 Dec 2018 01:03:04 +0000 Subject: [PATCH 5/5] Remove unused type declaration --- types/importScripts.d.ts | 1 - 1 file changed, 1 deletion(-) delete mode 100644 types/importScripts.d.ts diff --git a/types/importScripts.d.ts b/types/importScripts.d.ts deleted file mode 100644 index c69335bd95..0000000000 --- a/types/importScripts.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare function importScripts(...urls: string[]): void; \ No newline at end of file