-
Notifications
You must be signed in to change notification settings - Fork 950
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jgartman - thank you so much for this! I left some mostly stylistic suggestions - otherwise this is good to go.
Could you also add a test for reverse on an array with odd number of rows and columns (final two dimensions)?
Thanks - we'll merge this soon!
|
||
this.userCode = ` | ||
void main() { | ||
${type} rc = getOutputCoords(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent these lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -0,0 +1,80 @@ | |||
/** | |||
* @license | |||
* Copyright 2019 Google Inc. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
this.outputShape = xShape; | ||
const channels = getChannels('rc', rank); | ||
const nextColumn = | ||
`++${channels[rank - 1]} < ${this.outputShape[rank - 1]}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that we have this pattern elsewhere in the packed shaders, but could we instead test for adding 1 to the coordinate rather than mutating the coordinate? That way we don't have to remember to clean up after ourselves and decrement the coordinate. I think it'll be a little bit easier to read as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @annxingyuan, I refactored the code a bit and updated the compiled shader code at the top of the PR as well. Let me know what you think.
const type = getCoordsDataType(rank); | ||
const getc = `getChannel(getX(${inCoords}), ${innerDims})`; | ||
|
||
const upperRow = ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about restructuring this shader to match the unpacked shader so that all the logic for rank = 1 is nested under one if-statement? I wonder whether it might be easier to read that way - avoids having to test for rank = 1 in so many places. If we did it this way we should also be able to inline upperRow
and lowerRow
in the body of void main
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Thanks @jgartman ! |
Adds a packed kernel for reverse:
Benchmark code:
Compiled shader code for reverse of tensor of
shape = [2, 3, 4
] alongaxis = 1
:This change is