diff --git a/.gitignore b/.gitignore index a784f2a1fd7..84f2bfa1c6b 100644 --- a/.gitignore +++ b/.gitignore @@ -56,6 +56,5 @@ tensorflow-tfjs-*.tgz tfjs-backend-wasm/dist tfjs-backend-wasm/wasm-out/*.js tfjs-backend-wasm/wasm-out/*.wasm -tfjs-backend-wasm/wasm-out/*.worker.ts yalc.lock yarn-error.log diff --git a/tfjs-backend-wasm/karma.conf.js b/tfjs-backend-wasm/karma.conf.js index 86b2c5544a0..796311cd15c 100644 --- a/tfjs-backend-wasm/karma.conf.js +++ b/tfjs-backend-wasm/karma.conf.js @@ -61,8 +61,6 @@ module.exports = function(config) { {pattern: 'wasm-out/**/*.wasm', included: false}, // Import the generated js library from emscripten. {pattern: 'wasm-out/**/*.js'}, - // Import the generated worker file from emscripten. - {pattern: 'wasm-out/tfjs-backend-wasm-threaded-simd.worker.ts'}, // Import the rest of the sources. {pattern: 'src/**/*.ts'}, ], diff --git a/tfjs-backend-wasm/src/backend_wasm.ts b/tfjs-backend-wasm/src/backend_wasm.ts index 395a6921362..321d490e16c 100644 --- a/tfjs-backend-wasm/src/backend_wasm.ts +++ b/tfjs-backend-wasm/src/backend_wasm.ts @@ -418,12 +418,12 @@ export function setWasmPaths( wasmFileMap = prefixOrFileMap; const missingPaths = wasmBinaryNames.filter(name => wasmFileMap[name] == null); - if (missingPaths.length) { - console.warn( - `You provided a map of overrides for WASM binaries, but there ` + - `were no entries found for the following binaries: ` + - `${missingPaths.join(',')}. We will fall back to their ` + - `default locations.`); + if (missingPaths.length > 0) { + throw new Error( + `There were no entries found for the following binaries: ` + + `${missingPaths.join(',')}. Please either call setWasmPaths with a ` + + `map providing a path for each binary, or with a string indicating ` + + `the directory where all the binaries can be found.`); } } diff --git a/tfjs-backend-wasm/src/index_test.ts b/tfjs-backend-wasm/src/index_test.ts index 47d406f02c2..d009ef56025 100644 --- a/tfjs-backend-wasm/src/index_test.ts +++ b/tfjs-backend-wasm/src/index_test.ts @@ -111,7 +111,11 @@ describeWithFlags('wasm init', BROWSER_ENVS, () => { it('backend init fails when setWasmPaths is called with ' + 'an invalid fileMap', async () => { - setWasmPaths({'tfjs-backend-wasm.wasm': 'invalid/path'}); + setWasmPaths({ + 'tfjs-backend-wasm.wasm': 'invalid/path', + 'tfjs-backend-wasm-simd.wasm': 'invalid/path', + 'tfjs-backend-wasm-threaded-simd.wasm': 'invalid/path' + }); let wasmPathPrefix: string; const realFetch = fetch; spyOn(self, 'fetch').and.callFake((path: string) => { @@ -122,6 +126,16 @@ describeWithFlags('wasm init', BROWSER_ENVS, () => { expect(wasmPathPrefix).toBe('invalid/path'); }); + it('setWasmPaths throws error when called without specifying a path for ' + + 'each binary', + async () => { + expect(() => { + setWasmPaths({ + 'tfjs-backend-wasm.wasm': '/base/wasm-out/tfjs-backend-wasm.wasm' + }); + }).toThrow(); + }); + it('backend init works when the path is valid and use platform fetch', async () => { const usePlatformFetch = true; @@ -137,6 +151,30 @@ describeWithFlags('wasm init', BROWSER_ENVS, () => { expect(wasmPath).toBe(validPrefix + 'tfjs-backend-wasm.wasm'); }); + it('backend init works when the wasm paths overrides map is valid and ' + + 'using platform fetch', + async () => { + const usePlatformFetch = true; + const validPrefix = '/base/wasm-out/'; + setWasmPaths( + { + 'tfjs-backend-wasm.wasm': '/base/wasm-out/tfjs-backend-wasm.wasm', + 'tfjs-backend-wasm-simd.wasm': + '/base/wasm-out/tfjs-backend-wasm.wasm', + 'tfjs-backend-wasm-threaded-simd.wasm': + '/base/wasm-out/tfjs-backend-wasm.wasm' + }, + usePlatformFetch); + let wasmPath: string; + const realFetch = util.fetch; + spyOn(util, 'fetch').and.callFake((path: string) => { + wasmPath = path; + return realFetch(path); + }); + expect(await tf.setBackend('wasm-test')).toBe(true); + expect(wasmPath).toBe(validPrefix + 'tfjs-backend-wasm.wasm'); + }); + it('backend init works when the path is valid and use platform fetch', async () => { const usePlatformFetch = true;