Skip to content

Commit c823c1f

Browse files
authored
move webgl backend out of core (#3056)
BREAKING This moves the webgl backend out of tfjs-core into its own package. It can be used as a peer dependency alongside tfjs-core and is part of our larger work to modularise tfjs.
1 parent 6f14e2c commit c823c1f

File tree

132 files changed

+4415
-437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+4415
-437
lines changed

cloudbuild.yml

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ steps:
3232
waitFor: ['find-affected-packages']
3333
env: ['NIGHTLY=$_NIGHTLY']
3434

35+
# Webgl backend.
36+
- name: 'gcr.io/cloud-builders/gcloud'
37+
entrypoint: 'bash'
38+
id: 'tfjs-backend-webgl'
39+
args: ['./scripts/run-build.sh', 'tfjs-backend-webgl']
40+
waitFor: ['find-affected-packages']
41+
env: ['NIGHTLY=$_NIGHTLY']
42+
3543
# Converter.
3644
- name: 'gcr.io/cloud-builders/gcloud'
3745
entrypoint: 'bash'

tfjs-backend-webgl/.npmignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.babelrc
2+
.DS_Store
3+
.idea/
4+
.rpt2_cache
5+
.travis.yml
6+
.vscode
7+
*.tgz
8+
*.txt
9+
**.yalc
10+
**yalc.lock
11+
cloudbuild.yml
12+
coverage/
13+
demo/
14+
dist/**/*_test.d.ts
15+
dist/**/*_test.js
16+
karma.conf.js
17+
node_modules/
18+
npm-debug.log
19+
package-lock.json
20+
package/
21+
rollup.config.js
22+
scripts/
23+
src/**/*_test.ts
24+
tsconfig.json
25+
tslint.json
26+
yarn-error.log
27+
yarn.lock

tfjs-backend-webgl/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

tfjs-backend-webgl/cloudbuild.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
steps:
2+
# Install common dependencies.
3+
- name: 'node:10'
4+
id: 'yarn-common'
5+
entrypoint: 'yarn'
6+
args: ['install']
7+
8+
# Install webgl dependencies.
9+
- name: 'node:10'
10+
dir: 'tfjs-backend-webgl'
11+
id: 'yarn'
12+
entrypoint: 'yarn'
13+
args: ['install']
14+
waitFor: ['yarn-common']
15+
16+
# Build core from master.
17+
- name: 'node:10'
18+
dir: 'tfjs-backend-webgl'
19+
id: 'build-core'
20+
entrypoint: 'yarn'
21+
args: ['build-core-ci']
22+
waitFor: ['yarn-common']
23+
24+
# Run tests.
25+
- name: 'node:10'
26+
dir: 'tfjs-backend-webgl'
27+
entrypoint: 'yarn'
28+
id: 'test-backend-webgl'
29+
args: ['test-ci']
30+
waitFor: ['build-core']
31+
env: ['BROWSERSTACK_USERNAME=deeplearnjs1']
32+
secretEnv: ['BROWSERSTACK_KEY']
33+
34+
# General configuration
35+
secrets:
36+
- kmsKeyName: projects/learnjs-174218/locations/global/keyRings/tfjs/cryptoKeys/enc
37+
secretEnv:
38+
BROWSERSTACK_KEY: CiQAkwyoIW0LcnxymzotLwaH4udVTQFBEN4AEA5CA+a3+yflL2ASPQAD8BdZnGARf78MhH5T9rQqyz9HNODwVjVIj64CTkFlUCGrP1B2HX9LXHWHLmtKutEGTeFFX9XhuBzNExA=
39+
timeout: 1800s
40+
logsBucket: 'gs://tfjs-build-logs'
41+
substitutions:
42+
_NIGHTLY: ''
43+
options:
44+
logStreamingOption: 'STREAM_ON'
45+
substitution_option: 'ALLOW_LOOSE'

tfjs-backend-webgl/karma.conf.js

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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+
// Disable coverage reports and instrumentation by default for tests
21+
coverageOptions: {instrumentation: false},
22+
reports: {},
23+
bundlerOptions: {
24+
sourceMap: true,
25+
// Ignore the import of the `worker_threads` package used in a core test
26+
// meant to run in node.
27+
exclude: ['worker_threads'],
28+
// worker_node_test in tfjs-core contains a conditional require statement
29+
// that confuses the bundler of karma-typescript.
30+
ignore: ['./worker_node_test']
31+
}
32+
};
33+
34+
module.exports = function(config) {
35+
const args = [];
36+
if (config.grep) {
37+
args.push('--grep', config.grep);
38+
}
39+
if (config.flags) {
40+
args.push('--flags', config.flags);
41+
}
42+
let exclude = [];
43+
if (config.excludeTest != null) {
44+
exclude.push(config.excludeTest);
45+
}
46+
47+
config.set({
48+
frameworks: ['jasmine', 'karma-typescript'],
49+
files: [
50+
'src/setup_test.ts',
51+
{pattern: 'src/**/*.ts'},
52+
],
53+
preprocessors: {'**/*.ts': ['karma-typescript']},
54+
karmaTypescriptConfig,
55+
reporters: ['dots', 'karma-typescript'],
56+
exclude,
57+
colors: true,
58+
autoWatch: false,
59+
browsers: ['Chrome'],
60+
singleRun: true,
61+
client: {jasmine: {random: false}, args: args},
62+
browserStack: {
63+
username: process.env.BROWSERSTACK_USERNAME,
64+
accessKey: process.env.BROWSERSTACK_KEY
65+
},
66+
captureTimeout: 120000,
67+
reportSlowerThan: 500,
68+
browserNoActivityTimeout: 240000,
69+
customLaunchers: {
70+
// For browserstack configs see:
71+
// https://www.browserstack.com/automate/node
72+
bs_chrome_mac: {
73+
base: 'BrowserStack',
74+
browser: 'chrome',
75+
browser_version: 'latest',
76+
os: 'OS X',
77+
os_version: 'High Sierra'
78+
},
79+
bs_firefox_mac: {
80+
base: 'BrowserStack',
81+
browser: 'firefox',
82+
browser_version: 'latest',
83+
os: 'OS X',
84+
os_version: 'High Sierra'
85+
},
86+
bs_safari_mac: {
87+
base: 'BrowserStack',
88+
browser: 'safari',
89+
browser_version: 'latest',
90+
os: 'OS X',
91+
os_version: 'High Sierra'
92+
},
93+
bs_ios_11: {
94+
base: 'BrowserStack',
95+
device: 'iPhone X',
96+
os: 'iOS',
97+
os_version: '11.0',
98+
real_mobile: true
99+
},
100+
bs_android_9: {
101+
base: 'BrowserStack',
102+
device: 'Google Pixel 3 XL',
103+
os: 'android',
104+
os_version: '9.0',
105+
real_mobile: true
106+
},
107+
win_10_chrome: {
108+
base: 'BrowserStack',
109+
browser: 'chrome',
110+
// Latest Chrome on Windows has WebGL problems:
111+
// https://github.com/tensorflow/tfjs/issues/2272
112+
browser_version: '77.0',
113+
os: 'Windows',
114+
os_version: '10'
115+
},
116+
},
117+
})
118+
}

tfjs-backend-webgl/package.json

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"name": "@tensorflow/tfjs-backend-webgl",
3+
"version": "0.0.0",
4+
"description": "GPU accelerated WebGL backend for TensorFlow.js",
5+
"private": false,
6+
"main": "dist/index.js",
7+
"jsdelivr": "dist/tf-backend-webgl.min.js",
8+
"unpkg": "dist/tf-backend-webgl.min.js",
9+
"types": "dist/index.d.ts",
10+
"jsnext:main": "dist/tf-backend-webgl.esm.js",
11+
"module": "dist/tf-backend-webgl.esm.js",
12+
"engines": {
13+
"yarn": ">= 1.3.2"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/tensorflow/tfjs.git"
18+
},
19+
"license": "Apache-2.0",
20+
"devDependencies": {
21+
"@rollup/plugin-commonjs": "^11.0.2",
22+
"@rollup/plugin-node-resolve": "^7.1.1",
23+
"@rollup/plugin-typescript": "^3.0.0",
24+
"@tensorflow/tfjs-core": "link:../tfjs-core",
25+
"@types/jasmine": "~3.0.0",
26+
"clang-format": "~1.2.4",
27+
"jasmine": "~3.1.0",
28+
"jasmine-core": "~3.1.0",
29+
"karma": "~4.4.1",
30+
"karma-browserstack-launcher": "~1.4.0",
31+
"karma-chrome-launcher": "~2.2.0",
32+
"karma-jasmine": "~1.1.0",
33+
"karma-typescript": "~4.1.1",
34+
"npm-run-all": "~4.1.3",
35+
"rimraf": "~2.6.2",
36+
"rollup": "~2.3.2",
37+
"rollup-plugin-terser": "~5.3.0",
38+
"rollup-plugin-visualizer": "~3.3.2",
39+
"ts-node": "~7.0.0",
40+
"tslint": "~5.11.0",
41+
"tslint-no-circular-imports": "~0.5.0",
42+
"typescript": "3.5.3",
43+
"yalc": "~1.0.0-pre.21"
44+
},
45+
"scripts": {
46+
"build-ci": "tsc",
47+
"build": "tsc",
48+
"build-core": "cd ../tfjs-core && yarn && yarn build",
49+
"build-core-ci": "cd ../tfjs-core && yarn && yarn build-ci",
50+
"build-npm": "./scripts/build-npm.sh",
51+
"link-local": "yalc link",
52+
"publish-local": "rimraf dist/ && yarn build && rollup -c && yalc push",
53+
"publish-npm": "npm publish",
54+
"lint": "tslint -p . -t verbose",
55+
"test": "yarn build-core && karma start",
56+
"run-browserstack": "karma start --browserstack",
57+
"test-ci": "./scripts/test-ci.sh"
58+
},
59+
"dependencies": {
60+
"@types/offscreencanvas": "~2019.3.0",
61+
"@types/seedrandom": "2.4.27",
62+
"@types/webgl-ext": "0.0.30",
63+
"@types/webgl2": "0.0.4",
64+
"seedrandom": "2.4.3"
65+
},
66+
"peerDependencies": {
67+
"@tensorflow/tfjs-core": "link:../tfjs-core"
68+
},
69+
"browser": {
70+
"util": false,
71+
"crypto": false
72+
}
73+
}

0 commit comments

Comments
 (0)