Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit 6183caf

Browse files
authored
Add skeleton for the WASM prototype (#1863)
Add skeleton code for the WASM backend. Co-author: @nsthorat - Add `tfjs-backend-wasm` top-level folder (mono-repo style). - Add settings/lint/npm configurations (`tslint.json`, `settings.json`, `package.json`, ...). - Add initial sketch of the C++ backend. - Reuse core's unit tests. - Implement element-wise operation `add()` and test against core unit tests. - Setup building npm package. - Add a simple `build.sh` script (will move to Bazel later) - Add a [multi-root workspace](https://code.visualstudio.com/docs/editor/multi-root-workspaces) file so vscode can understand the mono-repo. Short-term TODOs: - Move c++ files to `src/cpp/` - Move ts files to `src/ts/` - Migrate to Bazel as a build system. - Have the `add` kernel live in its own file so we can drop it in modular builds. - Remove dependency on stdio.h
1 parent 6311b21 commit 6183caf

File tree

28 files changed

+4878
-8
lines changed

28 files changed

+4878
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ bazel-out/
1313
yalc.lock
1414
.rpt2_cache/
1515
package/
16+
17+
tfjs-backend-wasm/dist
18+
tfjs-backend-wasm/wasm-out

.vscode/c_cpp_properties.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"~/emsdk/fastcomp/emscripten/system/include/**"
8+
],
9+
"defines": [],
10+
"macFrameworkPath": [
11+
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
12+
],
13+
"compilerPath": "/usr/bin/clang",
14+
"cStandard": "c11",
15+
"cppStandard": "c++11",
16+
"intelliSenseMode": "clang-x64"
17+
}
18+
],
19+
"version": 4
20+
}

.vscode/settings.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"**/.rpt2_cache/": true,
99
"**/.yalc/**/*": true
1010
},
11-
"tslint.enable": true,
12-
"tslint.run": "onType",
1311
"tslint.configFile": "tslint.json",
1412
"files.trimTrailingWhitespace": true,
1513
"editor.tabSize": 2,

tfjs-backend-nodegl/settings.json renamed to tfjs-backend-nodegl/.vscode/settings.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"**/.rpt2_cache/": true,
99
"**/.yalc/**/*": true
1010
},
11-
"tslint.enable": true,
12-
"tslint.run": "onType",
1311
"tslint.configFile": "tslint.json",
1412
"files.trimTrailingWhitespace": true,
1513
"editor.tabSize": 2,

tfjs-backend-wasm/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/src/**",
7+
"~/emsdk/fastcomp/emscripten/system/include/**"
8+
],
9+
"defines": [],
10+
"compilerPath": "/usr/bin/clang",
11+
"cStandard": "c11",
12+
"cppStandard": "c++11",
13+
"intelliSenseMode": "clang-x64"
14+
}
15+
],
16+
"version": 4
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"search.exclude": {
4+
"**/node_modules": true,
5+
"**/coverage/": true,
6+
"**/dist/": true,
7+
"**/yarn.lock": true,
8+
"**/.rpt2_cache/": true,
9+
"**/.yalc/**/*": true
10+
},
11+
"tslint.configFile": "tslint.json",
12+
"files.trimTrailingWhitespace": true,
13+
"editor.tabSize": 2,
14+
"editor.insertSpaces": true,
15+
"[typescript]": {
16+
"editor.formatOnSave": true
17+
},
18+
"[javascript]": {
19+
"editor.formatOnSave": true
20+
},
21+
"[cpp]": {
22+
"editor.formatOnSave": true
23+
},
24+
"editor.rulers": [80],
25+
"clang-format.style": "Google",
26+
"files.insertFinalNewline": true,
27+
"editor.detectIndentation": false,
28+
"editor.wrappingIndent": "none",
29+
"typescript.tsdk": "./node_modules/typescript/lib",
30+
"clang-format.executable": "${workspaceRoot}/node_modules/.bin/clang-format",
31+
"files.associations": {
32+
"vector": "cpp",
33+
"map": "cpp",
34+
"algorithm": "cpp"
35+
}
36+
}

tfjs-backend-wasm/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Emscripten installation
2+
3+
Install emscripten [here](https://emscripten.org/docs/getting_started/downloads.html)
4+
5+
6+
# Building
7+
8+
```sh
9+
yarn build
10+
```
11+
12+
# Testing
13+
14+
```sh
15+
yarn test
16+
```
17+
18+
# Deployment
19+
```sh
20+
./scripts/build-npm.sh
21+
npm publish
22+
```

tfjs-backend-wasm/karma.conf.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google LLC. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
* =============================================================================
16+
*/
17+
18+
const karmaTypescriptConfig = {
19+
tsconfig: 'tsconfig.json',
20+
compilerOptions: {allowJs: true, declaration: false},
21+
bundlerOptions: {
22+
sourceMap: true,
23+
// Ignore the import of the `worker_threads` package used in a core test
24+
// meant to run in node.
25+
exclude: ['worker_threads']
26+
},
27+
// Disable coverage reports and instrumentation by default for tests
28+
coverageOptions: {instrumentation: false},
29+
reports: {},
30+
include: ['src/', 'wasm-out/']
31+
};
32+
33+
module.exports = function(config) {
34+
const args = [];
35+
if (config.grep) {
36+
args.push('--grep', config.grep);
37+
}
38+
if (config.flags) {
39+
args.push('--flags', config.flags);
40+
}
41+
config.set({
42+
basePath: '',
43+
frameworks: ['jasmine', 'karma-typescript'],
44+
files: [
45+
// Setup the environment for the tests.
46+
'src/setup_test.ts',
47+
// Serve the wasm file as a static resource.
48+
{pattern: 'wasm-out/**/*.wasm', included: false},
49+
// Import the generated js library from emscripten.
50+
{pattern: 'wasm-out/**/*.js'},
51+
// Import the rest of the sources.
52+
{pattern: 'src/**/*.ts'},
53+
],
54+
preprocessors: {
55+
'wasm-out/**/*.js': ['karma-typescript'],
56+
'**/*.ts': ['karma-typescript']
57+
},
58+
karmaTypescriptConfig,
59+
// Redirect the request for the wasm file so karma can find it.
60+
proxies: {
61+
'/base/node_modules/karma-typescript/dist/client/tfjs-backend-wasm.wasm':
62+
'/base/wasm-out/tfjs-backend-wasm.wasm',
63+
},
64+
reporters: ['progress', 'karma-typescript'],
65+
port: 9876,
66+
colors: true,
67+
autoWatch: true,
68+
browsers: ['Chrome'],
69+
singleRun: false,
70+
client: {jasmine: {random: false}, args: args}
71+
})
72+
}

tfjs-backend-wasm/package.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "@tensorflow/tfjs-backend-wasm",
3+
"version": "0.0.1",
4+
"main": "dist/index.js",
5+
"types": "dist/index.d.ts",
6+
"jsnext:main": "dist/tf-wasm.esm.js",
7+
"module": "dist/tf-wasm.esm.js",
8+
"unpkg": "dist/tf-wasm.min.js",
9+
"jsdelivr": "dist/tf-wasm.min.js",
10+
"scripts": {
11+
"build": "rimraf dist/ && ./scripts/build-wasm.sh && tsc && cp wasm-out/*.wasm dist/",
12+
"lint": "tslint -p . -t verbose",
13+
"test": "./scripts/build-wasm.sh && karma start"
14+
},
15+
"peerDependencies": {
16+
"@tensorflow/tfjs-core": "~1.2.7"
17+
},
18+
"devDependencies": {
19+
"@tensorflow/tfjs-core": "~1.2.7",
20+
"@types/emscripten": "~0.0.34",
21+
"clang-format": "^1.2.4",
22+
"jasmine-core": "~3.1.0",
23+
"karma": "~4.0.0",
24+
"karma-browserstack-launcher": "~1.4.0",
25+
"karma-chrome-launcher": "~2.2.0",
26+
"karma-firefox-launcher": "~1.1.0",
27+
"karma-jasmine": "~1.1.1",
28+
"karma-typescript": "~4.0.0",
29+
"rimraf": "~2.6.2",
30+
"rollup": "^1.17.0",
31+
"rollup-plugin-commonjs": "^10.0.1",
32+
"rollup-plugin-node-resolve": "^5.2.0",
33+
"rollup-plugin-terser": "^5.1.1",
34+
"rollup-plugin-typescript2": "^0.22.1",
35+
"tslint": "~5.11.0",
36+
"tslint-no-circular-imports": "^0.5.0",
37+
"typescript": "3.3.3333",
38+
"yalc": "~1.0.0-pre.21"
39+
},
40+
"license": "Apache-2.0"
41+
}

0 commit comments

Comments
 (0)