Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WASM] Add Slice and Square kernels #2269

Merged
merged 3 commits into from
Oct 26, 2019
Merged

[WASM] Add Slice and Square kernels #2269

merged 3 commits into from
Oct 26, 2019

Conversation

dsmilkov
Copy link
Contributor

@dsmilkov dsmilkov commented Oct 25, 2019

Add Slice and Square kernels.

We do the slice in JS instead of C++ since we are copying memory around, which should be fast in JS. Also I added fast rank-specific implementations for tensors up to 4D, and a generic slow implementation for rank >= 5D.


This change is Reviewable

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 8 of 8 files at r1.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @annxingyuan, @dsmilkov, and @nsthorat)


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

  memory() {
    return {
      // Unreliable due to automatic gc. The numbers above are cumulative.

I think this isn't true -- we malloc everything so this is identical to webgl. Unless slice semantics change this?


tfjs-backend-wasm/src/cc/kernels/Square.cc, line 23 at r1 (raw file):

namespace {
inline float oper(float val) { return val * val; }

s/oper/square


tfjs-core/src/ops/slice.ts, line 185 at r1 (raw file):

export const slice3d = op({slice3d_});
export const slice4d = op({slice4d_});
export {slice_util};

i dont think this is meant to be exported. If so, let's export it directly in index.ts rather than transitively from here.

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: :shipit: complete! 1 of 1 approvals obtained (waiting on @annxingyuan and @nsthorat)


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

Previously, nsthorat (Nikhil Thorat) wrote…

I think this isn't true -- we malloc everything so this is identical to webgl. Unless slice semantics change this?

Oh yeah you are right. It is reliable. Also there is no distinction here like in webgl where we differentiate between numBytes and numBytesOnGPU since everything is on cpu all the time (no lazy upload)


tfjs-backend-wasm/src/cc/kernels/Square.cc, line 23 at r1 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

s/oper/square

Done.


tfjs-core/src/ops/slice.ts, line 185 at r1 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

i dont think this is meant to be exported. If so, let's export it directly in index.ts rather than transitively from here.

I need these utils to do slicing. Exported it top level.

@dsmilkov dsmilkov merged commit 6794d7c into master Oct 26, 2019
@dsmilkov dsmilkov deleted the wasm-slice-square branch October 26, 2019 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants