Skip to content

Conversation

@lina128
Copy link
Collaborator

@lina128 lina128 commented Sep 14, 2020

Modularized NotEqual and refactored the kernel utils. This PR has below changes:

  1. Refactored Div and SquaredDifferences to export two things: config and kernelFunc. Exposing kernelFunc allows kernels to call kernels just through kernelFunc.
  2. Added an optional dtype to pass into binaryKernelFunc. This allows result to be created with this dtype as oppose to input's dtype. This is mainly used for comparison ops, such as Equal, NotEqual, Less, Greater, etc.
  3. Modularized NotEqual.

This change is Reviewable

const dataId = cpuBackend.write(resultData, resultShape, a.dtype);
return {dataId, shape: resultShape, dtype: a.dtype};
}
export type SimpleBinaryOperation = (a: number, b: number) => number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: might be useful to use this type to replace the type of the "op" parameter in createBinaryKernelImpl below.

Copy link
Collaborator Author

@lina128 lina128 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, @jinjingforever, and @tafsiri)


tfjs-backend-cpu/src/utils/kernel_utils.ts, line 26 at r1 (raw file):

Previously, jinjingforever (Jing Jin) wrote…

nit: might be useful to use this type to replace the type of the "op" parameter in createBinaryKernelImpl below.

Ah, good catch. Done.

Copy link
Contributor

@tafsiri tafsiri left a comment

Choose a reason for hiding this comment

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

LGTM with one suggestion.

Reviewed 4 of 5 files at r1, 1 of 1 files at r2.
Reviewable status: :shipit: complete! 2 of 1 approvals obtained (waiting on @annxingyuan, @jinjingforever, @lina128, and @tafsiri)


tfjs-backend-cpu/src/kernels/NotEqual.ts, line 22 at r2 (raw file):

createBinaryKernelConfig

More of a design/dx question. Could you pass the anonymous function directly to binaryKernelFunc below and have it call createBinaryKernelImpl internally? It seems like it is always called the same way by each caller so might as well be included in binaryKernelFunc (this would also affect your other pr with complex op examples). There could be a use case I am missing though.

Copy link
Contributor

@annxingyuan annxingyuan left a comment

Choose a reason for hiding this comment

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

LGTM

Reviewable status: :shipit: complete! 3 of 1 approvals obtained (waiting on @annxingyuan, @jinjingforever, and @lina128)

Copy link
Collaborator Author

@lina128 lina128 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! 3 of 1 approvals obtained (waiting on @jinjingforever and @tafsiri)


tfjs-backend-cpu/src/kernels/NotEqual.ts, line 22 at r2 (raw file):

Previously, tafsiri (Yannick Assogba) wrote…
createBinaryKernelConfig

More of a design/dx question. Could you pass the anonymous function directly to binaryKernelFunc below and have it call createBinaryKernelImpl internally? It seems like it is always called the same way by each caller so might as well be included in binaryKernelFunc (this would also affect your other pr with complex op examples). There could be a use case I am missing though.

Ah, good idea. Refactored.

@lina128 lina128 merged commit a6262b0 into tensorflow:master Sep 16, 2020
@lina128 lina128 deleted the notequal branch September 16, 2020 06:15
jinjingforever pushed a commit that referenced this pull request Sep 16, 2020
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.

5 participants