Skip to content

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

Merged
mbaret merged 3 commits into
apache:mainfrom
ekalda:identity_upstream
Nov 16, 2021
Merged

Add the Arm(R) Ethos(TM)-U NPU identity operator#9457
mbaret merged 3 commits into
apache:mainfrom
ekalda:identity_upstream

Conversation

@ekalda

@ekalda ekalda commented Nov 5, 2021

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

ekalda commented Nov 5, 2021

Copy link
Copy Markdown
Contributor Author

Comment thread python/tvm/relay/backend/contrib/ethosu/legalize.py Outdated
Comment thread python/tvm/relay/backend/contrib/ethosu/te/dma.py Outdated
Comment thread python/tvm/relay/backend/contrib/ethosu/te/dma.py Outdated
Comment thread python/tvm/relay/backend/contrib/ethosu/op/identity.py Outdated
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

operators

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

Comment thread python/tvm/relay/op/contrib/ethosu.py Outdated
qnn_avgpool2d_pattern(),
lambda pat: AvgPool2DParams(pat).is_valid(),
),
("ethosu.strided_slice", strided_slice_pattern(), lambda pat: True),

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

Choose a reason for hiding this comment

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

Done

Comment thread python/tvm/relay/backend/contrib/ethosu/tir/identity.py Outdated
Parameters
----------
stmt : tvm.tir.AttrStmt
The outermost attribute statement of a convolution loop nest.

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

Choose a reason for hiding this comment

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

Done

Comment thread src/relay/op/contrib/ethosu/identity.cc Outdated
.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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops, done

run_opt_pass(func, relay.transform.InferType())


def test_ethosu_identity_invalid_shape():

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

Choose a reason for hiding this comment

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

Done

@lhutton1 lhutton1 left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread python/tvm/relay/backend/contrib/ethosu/legalize.py Outdated
Comment thread python/tvm/relay/backend/contrib/ethosu/te/identity.py Outdated
Comment thread src/relay/op/contrib/ethosu/identity.cc Outdated
Comment thread tests/python/contrib/test_ethosu/test_type_inference.py Outdated
* 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

ekalda commented Nov 16, 2021

Copy link
Copy Markdown
Contributor Author

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

@NicolaLancellotti NicolaLancellotti left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@manupak manupak left a comment

Copy link
Copy Markdown
Contributor

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 ?

@lhutton1 lhutton1 left a comment

Copy link
Copy Markdown
Contributor

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

mbaret commented Nov 16, 2021

Copy link
Copy Markdown
Contributor

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