Skip to content

Conversation

@xhcao
Copy link
Contributor

@xhcao xhcao commented Jan 5, 2023

To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.


This change is Reviewable

@xhcao xhcao requested review from gyagp and qjia7 January 5, 2023 06:16
Copy link

@gyagp gyagp 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 nit

if (index < uniforms.size) {
var s0 = 1.0;
var s1 = 1.0;
let indexS0 = index - uniforms.size + uniforms.s0Length;
Copy link

Choose a reason for hiding this comment

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

nit, maybe

Suggested change
let indexS0 = index - uniforms.size + uniforms.s0Length;
let indexS0 = index - uniforms.size + uniforms.s0Size;

const program = new BroadcastArgsProgram(outputSize);
const uniformData =
[{type: 'int32', data: [s0Size]}, {type: 'int32', data: [s1Size]}];
return backend.runWebGPUProgram(program, [s0, s1], 'int32', uniformData);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add a cpu path if s0 and s1 is on cpu since the inputs are really small?

Copy link
Contributor

@qjia7 qjia7 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 nit.

const {s0, s1} = inputs;

if (backend.shouldExecuteOnCPU([s0, s1])) {
const s0BufferInfo = backend.tensorMap.get(s0.dataId);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: s0BufferInfo -> s0TensorInfo

@xhcao
Copy link
Contributor Author

xhcao commented Jan 16, 2023

@gyagp Could you review it again, because I added cpu path after you approved.

const {s0, s1} = inputs;

if (backend.shouldExecuteOnCPU([s0, s1])) {
const s0TensorInfo = backend.tensorMap.get(s0.dataId);
Copy link

Choose a reason for hiding this comment

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

Why don't we reuse the CPU impl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. cpu backend does not export the CPU impl for other backends.
  2. cpu backend also calls the tfjs-core common function to implement the feature, it is better for other backends to call the tfjs-core common function directly.

Copy link

Choose a reason for hiding this comment

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

Per discussion, a similar interface (xxxImplCPU) to be used as CPU fallback is a good approach. However, this may need some changes at CPU backend, so let's refine this in a future PR. LGTM with this one.

@xhcao xhcao merged commit 498ba85 into tensorflow:master Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants