-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add the Arm(R) Ethos(TM)-U NPU identity operator #9457
Conversation
ekalda
commented
Nov 5, 2021
- Add the ethosu.identity operator which returns the input tensor
- Add an opportunity to requantize the tensor
- Add legalization for reshape and strided slice
- Add a pass that puts an indentity op after a no-op
@@ -423,11 +526,15 @@ class LegalizeEthosU: | |||
def transform_module( | |||
self, mod: tvm.ir.IRModule, ctx: tvm.ir.transform.PassContext | |||
) -> tvm.ir.IRModule: | |||
"""Legalize the oerators that can be offloaded to the NPU""" |
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.
operators
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.
A different docstring appeared in the rebase, so I kept that that different docstring
@@ -481,6 +493,8 @@ def pattern_table() -> List[Tuple[str, tvm.relay.dataflow_pattern.DFPattern, Cal | |||
qnn_avgpool2d_pattern(), | |||
lambda pat: AvgPool2DParams(pat).is_valid(), | |||
), | |||
("ethosu.strided_slice", strided_slice_pattern(), lambda pat: True), |
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.
Let's put the proper restrictions here so we don't accidentally offload, for example, floating point tensors.
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
Parameters | ||
---------- | ||
stmt : tvm.tir.AttrStmt | ||
The outermost attribute statement of a convolution loop nest. |
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.
identity pooling loop nest
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
.describe(R"code(Identity operator for Ethos-U NPUs. | ||
|
||
This Relay operator performs the identity operation on Ethos(TM)-U NPU with a capability | ||
to requantize the data. It accepts input with any shape that is less or equal to 4. |
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.
Maybe 'It accepts input tensors of 4 dimensions or less.'?
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
|
||
|
||
@pytest.mark.parametrize("accel_type", ACCEL_TYPES) | ||
@pytest.mark.parametrize( |
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.
We should either test the 'special' indices for reshape (-1 and -2), or we should explicitly disallow these.
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
], | ||
) | ||
def test_relay_reshape_codegen(ifm_shape, new_shape, accel_type): | ||
# Create a "partitioned" Relay graph |
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.
It seems like some of this could be refactored out into a common function and reused between tests.
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
run_opt_pass(func, relay.transform.InferType()) | ||
|
||
|
||
def test_ethosu_invalid_invalid_dtype(): |
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.
test_ethosu_identity_invalid_dtype
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.
Oops, done
@@ -171,5 +180,26 @@ def test_ethosu_pooling_invalid_dtype(): | |||
run_opt_pass(func, relay.transform.InferType()) | |||
|
|||
|
|||
def test_ethosu_identity_invalid_shape(): |
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 think we need to test the valid cases 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.
Done
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 @ekalda, great work :) Just a few small things below..
* Add the ethosu.identity operator which returns the input tensor * Add an opportunity to requantize the tensor * Add legalization for reshape and strided slice * Add a pass that puts an indentity op after a no-op Change-Id: I0adb5ca269f8529c79e0e7681ca4b5147d8f53c8
Change-Id: Icc9b6507f164681a5d6b1fcff2ae4a5051d44734
Change-Id: I63f30f84ad481789fc047ad8c2107f5313562f7f
75d1117
to
ac87b0b
Compare
@mbaret @NicolaLancellotti @lhutton1 thanks for the reviews, much appreciated! :) |
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.
LGTM
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.
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.
LGTM, thanks @ekalda!
Thanks everyone, this is now merged! |
* Add the Arm(R) Ethos(TM)-U NPU identity operator * Add the ethosu.identity operator which returns the input tensor * Add an opportunity to requantize the tensor * Add legalization for reshape and strided slice * Add a pass that puts an indentity op after a no-op Change-Id: I0adb5ca269f8529c79e0e7681ca4b5147d8f53c8 * Fix the pylint errors Change-Id: Icc9b6507f164681a5d6b1fcff2ae4a5051d44734 * Changes in response to review comments Change-Id: I63f30f84ad481789fc047ad8c2107f5313562f7f
* Add the Arm(R) Ethos(TM)-U NPU identity operator * Add the ethosu.identity operator which returns the input tensor * Add an opportunity to requantize the tensor * Add legalization for reshape and strided slice * Add a pass that puts an indentity op after a no-op Change-Id: I0adb5ca269f8529c79e0e7681ca4b5147d8f53c8 * Fix the pylint errors Change-Id: Icc9b6507f164681a5d6b1fcff2ae4a5051d44734 * Changes in response to review comments Change-Id: I63f30f84ad481789fc047ad8c2107f5313562f7f
* Add the Arm(R) Ethos(TM)-U NPU identity operator * Add the ethosu.identity operator which returns the input tensor * Add an opportunity to requantize the tensor * Add legalization for reshape and strided slice * Add a pass that puts an indentity op after a no-op Change-Id: I0adb5ca269f8529c79e0e7681ca4b5147d8f53c8 * Fix the pylint errors Change-Id: Icc9b6507f164681a5d6b1fcff2ae4a5051d44734 * Changes in response to review comments Change-Id: I63f30f84ad481789fc047ad8c2107f5313562f7f
* Add the Arm(R) Ethos(TM)-U NPU identity operator * Add the ethosu.identity operator which returns the input tensor * Add an opportunity to requantize the tensor * Add legalization for reshape and strided slice * Add a pass that puts an indentity op after a no-op Change-Id: I0adb5ca269f8529c79e0e7681ca4b5147d8f53c8 * Fix the pylint errors Change-Id: Icc9b6507f164681a5d6b1fcff2ae4a5051d44734 * Changes in response to review comments Change-Id: I63f30f84ad481789fc047ad8c2107f5313562f7f
* Add the Arm(R) Ethos(TM)-U NPU identity operator * Add the ethosu.identity operator which returns the input tensor * Add an opportunity to requantize the tensor * Add legalization for reshape and strided slice * Add a pass that puts an indentity op after a no-op Change-Id: I0adb5ca269f8529c79e0e7681ca4b5147d8f53c8 * Fix the pylint errors Change-Id: Icc9b6507f164681a5d6b1fcff2ae4a5051d44734 * Changes in response to review comments Change-Id: I63f30f84ad481789fc047ad8c2107f5313562f7f