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

[4/10] Code generation for Conv2D via CMSIS-NN #9331

Merged
merged 5 commits into from
Nov 17, 2021

Conversation

ashutosh-arm
Copy link
Contributor

This PR is for support of Conv2D via CMSIS-NN.

Here is the tracking issue: #8646

@ashutosh-arm
Copy link
Contributor Author

Adding @Mousius @manupa-arm @grant-arm @areusch for review.

python/tvm/relay/op/contrib/cmsisnn.py Outdated Show resolved Hide resolved
src/relay/backend/contrib/cmsisnn/generate_constants.cc Outdated Show resolved Hide resolved
src/relay/backend/contrib/cmsisnn/relay_to_tir.cc Outdated Show resolved Hide resolved
tests/python/contrib/test_cmsisnn/test_conv2d.py Outdated Show resolved Hide resolved
tests/python/contrib/test_cmsisnn/test_conv2d.py Outdated Show resolved Hide resolved
tests/python/contrib/test_cmsisnn/test_conv2d.py Outdated Show resolved Hide resolved
tests/python/contrib/test_cmsisnn/test_conv2d.py Outdated Show resolved Hide resolved
tests/python/contrib/test_cmsisnn/test_networks.py Outdated Show resolved Hide resolved
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.

Hi @ashutosh-arm

Thanks for the work! It seems not trivial compared to other operators.
I did a pass. PTAL.

python/tvm/relay/op/contrib/cmsisnn.py Outdated Show resolved Hide resolved
src/relay/backend/contrib/cmsisnn/extract_constants.cc Outdated Show resolved Hide resolved
src/relay/backend/contrib/cmsisnn/extract_constants.cc Outdated Show resolved Hide resolved
src/relay/backend/contrib/cmsisnn/extract_constants.cc Outdated Show resolved Hide resolved
src/relay/backend/contrib/cmsisnn/generate_constants.cc Outdated Show resolved Hide resolved
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.

Broadly looks good! Thanks @ashutosh-arm.
Just a few questions.


// Since the constants are kicked out of the local partitioned functions
// a new call to local function is needed
if (auto* func_node = call->op.as<FunctionNode>()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ack

python/tvm/relay/op/contrib/cmsisnn.py Show resolved Hide resolved
primfunc_ = tir::PrimFunc(func_signature, body, VoidType(), Map<tir::Var, tir::Buffer>(),
DictAttrs(dict_attrs));
}

Array<PrimExpr> CMSISNNDimensions(const Array<PrimExpr>& shape) {
ICHECK(shape.size() == 4) << "Supports only CMSIS-NN shapes of dimension 4.";
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to test these or not ? Im not sure now. @Mousius ?

@manupak
Copy link
Contributor

manupak commented Nov 5, 2021

@ashutosh-arm could you retrigger this one? the docker image is updated now.

@Mousius
Copy link
Member

Mousius commented Nov 10, 2021

@manupa-arm / @ashutosh-arm in general if we're adding things that raise exceptions as part of their interface we should be testing them.

@manupak
Copy link
Contributor

manupak commented Nov 11, 2021

@manupa-arm / @ashutosh-arm in general if we're adding things that raise exceptions as part of their interface we should be testing them.

I agree for user facing exceptions. What about internal assertions that are not meant to be triggered in a user execution flow and are only meant to be triggered when a "developer" is changing the compilation stack ?

Generally these assertions are derived from assumptions that a user flow will never trigger them and usually are about inputs to a particularly component.

Having a test that does another assertion to check an assertion on input is working does only seem to give confidence that the function call is successfully able to pass in an argument to trigger the assertion. Ideally, a release build should remove these internal assertions as they were only dev facing assertions.

Let me know if you still think it is worthwhile adding a test check an dev facing assertion that gives us confidence that a component is successfully able to pass in an input that violate an assumption that the developer took that a user flow will never trigger. If so we might want to check the assertion in this PR (here or in a follow up)

@Mousius
Copy link
Member

Mousius commented Nov 11, 2021

Generally these assertions are derived from assumptions that a user flow will never trigger them and usually are about inputs to a particularly component.

I would question why we're adding them if they're in unreachable code paths, but if we do think they're worth adding I would consider them part of the contract of the internal function and thus should have associated tests for the behaviour (throwing an exception is now part of the functions behaviour).

As per TVM Code Review Guidelines, we should add test coverage for anything we contribute. If we're happy that at some point someone may inadvertently change the behaviour of this function, then potentially it's not a necessary line of code and we can apply the YAGNI principle from extreme programming 😸

@manupak
Copy link
Contributor

manupak commented Nov 11, 2021

I would question why we're adding them if they're in unreachable code paths, but if we do think they're worth adding I would consider them part of the contract of the internal function and thus should have associated tests for the behaviour (throwing an exception is now part of the functions behaviour).

There is a fine line between defining a failing internal assert as a "behaviour" of the function and removing the assert just because it not executed in the present organization of the components.

If we're happy that at some point someone may inadvertently change the behaviour of this function, then potentially it's not a necessary line of code and we can apply the YAGNI principle from extreme programming

Enforcing YAGNI to remove internal asserts will discourage developers from using asserts just because the execution path is not enforced today.

In a summary I would support having internal assertions that makes it easier if another developer changes this code or re-uses some of it somewhere else. If it means we need a add a borderline meaningful test that uses as an assertion to see if the assertion inside the code is triggered, lets do that then.

I guess what you are saying is we need a test for the above ICHECK in this PR?

@Mousius
Copy link
Member

Mousius commented Nov 11, 2021

If it means we need a add a borderline meaningful test that uses as an assertion to see if the assertion inside the code is triggered, lets do that then.

It doesn't, you're the committer responsible for this PR, if you genuinely disagree feel free to merge without test coverage - this has happened on other PRs I've reviewed.

I guess what you are saying is we need a test for the above ICHECK in this PR?

Yip, I would advocate for full test coverage in line with the TVM Code Review Guidelines, working on the assumption we want the code to continue working for the forsee-able future. Though I don't think we should turn this PR into a debate on software testing - that's been going for a long time now 😸 .

@manupak
Copy link
Contributor

manupak commented Nov 11, 2021

if you genuinely disagree feel free to merge without test coverage

My position is to keep the assert (as originally added by @ashutosh-arm -- not a request for a change). I only oppose removing it on the basis it is not tested. Im happy to do it in a follow up if thats what @ashutosh-arm wants to do here ?

his has happened on other PRs I've reviewed.

Hence the questioning here, because this exact point is questioned elsewhere but not here. Other places we committed to follow up if that is direction we want to take. cc : @ekalda @mbaret. Im pretty sure if we agree on this point we will do the necessary changes.

working on the assumption we want the code to continue working for the forsee-able future

Im pretty sure we all want this -- just being lenient on internal asserts -- that is all.

@ashutosh-arm
Copy link
Contributor Author

In my view, I don't wish to remove the assert as this is a code that could be reused and fail if caller does not meet asserted criterion. At the same time, testing all internal asserts should not be made into a policy. I say this because at certain times, we know that the previous flow, before this stage is reached, assumes certain things and has its own set of asserts.

On another note, this cannot be tested in the existing CMSIS-NN testing infrastructure as there is no direct interface to access it. How do we test such APIs currently? Can someone please point me to an example?

@ekalda
Copy link
Contributor

ekalda commented Nov 11, 2021

if you genuinely disagree feel free to merge without test coverage

My position is to keep the assert (as originally added by @ashutosh-arm -- not a request for a change). I only oppose removing it on the basis it is not tested. Im happy to do it in a follow up if thats what @ashutosh-arm wants to do here ?

his has happened on other PRs I've reviewed.

Hence the questioning here, because this exact point is questioned elsewhere but not here. Other places we committed to follow up if that is direction we want to take. cc : @ekalda @mbaret. Im pretty sure if we agree on this point we will do the necessary changes.

working on the assumption we want the code to continue working for the forsee-able future

Im pretty sure we all want this -- just being lenient on internal asserts -- that is all.

Yes, I think we agreed to add the tests in a follow-up PR if we decide to test the internal asserts in the future, so it would make sense for this PR to go in as it is as well.

My (unchanged) view on the topic is that I agree with @manupa-arm that we should test the user facing asserts, but not the simple developer facing asserts. While it is a good practice to test all the functionality, I think we should always evaluate these kind of guidelines in the context of the specific project if we want to avoid getting stuck in dogmas. It is a valid point that perhaps we should remove the unreachable asserts then, but I think TVM is very much still a project in progress and I have found the developer facing asserts very useful, so I don't think they do any harm. In general, the NPU side of codebase is in constant flux at the moment, so a lot of tests means a lot of extra code to maintain and makes making changes harder. So at that stage I think there is more harm in testing ICHECKs than benefits in a from maintenance overhead.

@manupak
Copy link
Contributor

manupak commented Nov 11, 2021

Alright thanks for the views! Lets not block PR on this -- it is certainly a high bandwidth discussion to be had.
I think this PR can go in and @ashutosh-arm would you be able to fix the conflicts ?-- so we could merge this.

@ashutosh-arm
Copy link
Contributor Author

I am working on resolving the conflicts.

Change-Id: Ifa9ee3bb0b5292ba9911f9c4fc2af508957cd784
Co-authored-by: Chris Sidebottom <chris.sidebottom@arm.com>

Change-Id: I15e7e7e4fa864ddc469a4e430c4f472057290e8a
Change-Id: Ie4c6f27318978d69aec9131d79f9a3f28c99f3b0
Change-Id: I47b64db6a14732420952aad58488438ac80b7816
@manupak manupak merged commit ee23013 into apache:main Nov 17, 2021
@manupak
Copy link
Contributor

manupak commented Nov 17, 2021

Thanks @ashutosh-arm @Mousius @areusch!

mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
This PR is for support of Conv2D via CMSIS-NN.
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
This PR is for support of Conv2D via CMSIS-NN.
@ashutosh-arm ashutosh-arm deleted the conv2d branch December 7, 2021 10:06
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
This PR is for support of Conv2D via CMSIS-NN.
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 11, 2022
This PR is for support of Conv2D via CMSIS-NN.
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
This PR is for support of Conv2D via CMSIS-NN.
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