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

Add skeleton for the WASM prototype #1863

Merged
merged 20 commits into from
Aug 7, 2019
Merged

Add skeleton for the WASM prototype #1863

merged 20 commits into from
Aug 7, 2019

Conversation

dsmilkov
Copy link
Contributor

@dsmilkov dsmilkov commented Jul 29, 2019

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 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

This change is Reviewable

Copy link
Contributor Author

@dsmilkov dsmilkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 approvals obtained (waiting on @nkreeger and @nsthorat)


.vscode/c_cpp_properties.json, line 7 at r2 (raw file):

            "includePath": [
                "${workspaceFolder}/**",
                "~/emsdk/fastcomp/emscripten/system/include/**"

note, vscode expects emsdk (emscripten) to be installed in your home dir under ~/emsdk/


tfjs-backend-wasm/.vscode/c_cpp_properties.json, line 7 at r2 (raw file):

            "includePath": [
                "${workspaceFolder}/src/**",
                "~/emsdk/fastcomp/emscripten/system/include/**"

note, vscode expects emsdk (emscripten) to be installed in your home dir under ~/emsdk/

Copy link
Contributor

@nsthorat nsthorat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 12 files at r1, 22 of 29 files at r2, 5 of 7 files at r3.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @dsmilkov, @nkreeger, and @nsthorat)


.vscode/settings.json, line 12 at r3 (raw file):

  },
  "tslint.enable": true,
  "tslint.run": "onType",

is this meant to be removed?


tfjs-backend-wasm/package.json, line 16 at r3 (raw file):

  },
  "peerDependencies": {
    "@tensorflow/tfjs-core": "~1.2.5"

update to 1.2.7


tfjs-backend-wasm/src/backend_wasm.ts, line 19 at r3 (raw file):

import {backend_util, DataType, KernelBackend, Rank, registerBackend, ShapeMap, Tensor, util} from '@tensorflow/tfjs-core';
import {BackendValues, TypedArray} from '@tensorflow/tfjs-core/dist/types';

this should be in backend_util now I think as of 1.2.7


tfjs-backend-wasm/src/backend_wasm.ts, line 35 at r3 (raw file):

export class BackendWasm extends KernelBackend {
  private dataIdNextNumber = 0;
  private dataIdMap: WeakMap<{}, TensorInfo> = new WeakMap();

can you make {} a named DataId interface for readability and type it here and elsewhere


tfjs-backend-wasm/src/backend_wasm.ts, line 159 at r3 (raw file):

/** Initializes the wasm module and creates the js <--> wasm bridge. */
async function init(): Promise<{wasm: BackendWasmModule}> {

quick comment here about why we return an object wpi;d ne great


tfjs-backend-wasm/src/backend_wasm.ts, line 165 at r3 (raw file):

    wasm.tfjs = {
      registerTensor: wasm.cwrap(
          'register_tensor', null,

name null


tfjs-backend-wasm/src/backend_wasm.ts, line 175 at r3 (raw file):

      disposeData: wasm.cwrap('dispose_data', null, ['number']),
      dispose: wasm.cwrap('dispose', null, []),
      add: wasm.cwrap('add', null, ['number, number, number']),

would be good to name nulls here


tfjs-backend-wasm/src/index_test.ts, line 50 at r3 (raw file):

  });

  it('element-wise add', async () => {

can we do this with core tests?


tfjs-backend-wasm/src/kernels.cc, line 1 at r3 (raw file):

/* Copyright 2019 Google Inc. All Rights Reserved.

did we want to have a cpp folder?


tfjs-backend-wasm/src/setup_test.ts, line 23 at r3 (raw file):

  name: 'test-wasm',
  backendName: 'wasm',
  flags: {},

you dont need this line


tfjs-backend-wasm/src/setup_test.ts, line 24 at r3 (raw file):

  backendName: 'wasm',
  flags: {},
  isDataSync: true,

remove the comma

Copy link
Contributor Author

@dsmilkov dsmilkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. All comments addressed.

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @nkreeger and @nsthorat)


.vscode/settings.json, line 12 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

is this meant to be removed?

Its obsolete now, and vscode highlights it.


tfjs-backend-wasm/package.json, line 16 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

update to 1.2.7

Done.


tfjs-backend-wasm/src/backend_wasm.ts, line 19 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

this should be in backend_util now I think as of 1.2.7

Done.


tfjs-backend-wasm/src/backend_wasm.ts, line 35 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

can you make {} a named DataId interface for readability and type it here and elsewhere

Done.


tfjs-backend-wasm/src/backend_wasm.ts, line 159 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

quick comment here about why we return an object wpi;d ne great

Done.


tfjs-backend-wasm/src/backend_wasm.ts, line 165 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

name null

Done.


tfjs-backend-wasm/src/backend_wasm.ts, line 175 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

would be good to name nulls here

Done.


tfjs-backend-wasm/src/index_test.ts, line 50 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

can we do this with core tests?

Good catch. This was the first test I wrote before I linked core's test, and forgot to remove. We now test against core so this test is obsolete.


tfjs-backend-wasm/src/kernels.cc, line 1 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

did we want to have a cpp folder?

Yes, but I want to move files in a follow-up PR to not risk messing up diffs. We will have src/cpp and src/ts/ (see TODOs in PR description)


tfjs-backend-wasm/src/setup_test.ts, line 23 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

you dont need this line

Done.


tfjs-backend-wasm/src/setup_test.ts, line 24 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

remove the comma

Done.

@dsmilkov
Copy link
Contributor Author

dsmilkov commented Aug 7, 2019

For some reason GitHub check didn't get updated, but the Build passed: https://console.cloud.google.com/gcr/builds/0b789b40-d7ee-4e75-b886-709f79c77f4f?project=834911136599

@dsmilkov dsmilkov merged commit 6183caf into master Aug 7, 2019
@dsmilkov dsmilkov deleted the cpp-wasm branch August 7, 2019 17:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants