Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions tfjs-backend-wasm/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
],
Expand Down
12 changes: 6 additions & 6 deletions tfjs-backend-wasm/src/backend_wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
}

Expand Down
40 changes: 39 additions & 1 deletion tfjs-backend-wasm/src/index_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
Expand All @@ -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;
Expand Down