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

Add the Arm(R) Ethos(TM)-U NPU identity operator #9457

Merged
merged 3 commits into from
Nov 16, 2021

Conversation

ekalda
Copy link
Contributor

@ekalda 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

@ekalda
Copy link
Contributor Author

ekalda commented Nov 5, 2021

python/tvm/relay/backend/contrib/ethosu/op/identity.py Outdated Show resolved Hide resolved
@@ -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"""
Copy link
Contributor

Choose a reason for hiding this comment

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

operators

Copy link
Contributor Author

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),
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

python/tvm/relay/backend/contrib/ethosu/tir/identity.py Outdated Show resolved Hide resolved
Parameters
----------
stmt : tvm.tir.AttrStmt
The outermost attribute statement of a convolution loop nest.
Copy link
Contributor

Choose a reason for hiding this comment

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

identity pooling loop nest

Copy link
Contributor Author

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.
Copy link
Contributor

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.'?

Copy link
Contributor Author

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(
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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():
Copy link
Contributor

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

Copy link
Contributor Author

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():
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@lhutton1 lhutton1 left a 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..

python/tvm/relay/backend/contrib/ethosu/legalize.py Outdated Show resolved Hide resolved
python/tvm/relay/backend/contrib/ethosu/te/identity.py Outdated Show resolved Hide resolved
src/relay/op/contrib/ethosu/identity.cc Outdated Show resolved Hide resolved
tests/python/contrib/test_ethosu/test_type_inference.py Outdated Show resolved Hide resolved
* 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
@ekalda
Copy link
Contributor Author

ekalda commented Nov 16, 2021

@mbaret @NicolaLancellotti @lhutton1 thanks for the reviews, much appreciated! :)

Copy link
Contributor

@NicolaLancellotti NicolaLancellotti left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@manupak manupak left a comment

Choose a reason for hiding this comment

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

Thanks @ekalda . LGTM!

@mbaret, @lhutton1 could you take an another look ?

Copy link
Contributor

@lhutton1 lhutton1 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @ekalda!

@mbaret mbaret merged commit c3a06ee into apache:main Nov 16, 2021
@mbaret
Copy link
Contributor

mbaret commented Nov 16, 2021

Thanks everyone, this is now merged!

mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
* 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
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
* 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
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
* 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
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 11, 2022
* 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
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
* 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
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.

5 participants