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

[CMSIS-NN] Add int16 add and mul operator support #13920

Merged
merged 1 commit into from
Feb 8, 2023

Conversation

FranklandJack
Copy link
Contributor

The CMSIS-NN backend will now partition quantized int16 additions and multiplication operators and emit calls to arm_elementwise_add_s16 and arm_elementwise_mul_s16 respectively during codegen.

Because arm_elementwise_mul_s16 and arm_elementwise_add_s16 do not handle non-zero shift parameters at present, for non-zero zero point values (which map directly to shift in the CMSIS-NN backend) partitioning fails and we fall back on the regular C codegen path.

This patch also adds int16 tests, including testing for the non-zero zero point edge case described above.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Feb 6, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

@FranklandJack
Copy link
Contributor Author

@ashutosh-arm
@Mousius

Would be great to get some reviews on this if/when you folk have time! 😀

Copy link
Member

@Mousius Mousius left a comment

Choose a reason for hiding this comment

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

Just a few minor points @FranklandJack, otherwise seems sensible to me 😸

python/tvm/relay/op/contrib/cmsisnn.py Outdated Show resolved Hide resolved
tests/python/contrib/test_cmsisnn/test_binary_ops.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ashutosh-arm ashutosh-arm left a comment

Choose a reason for hiding this comment

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

Looks good overall @FranklandJack. Just a nit below.

const auto& pattern = ParseBinaryElementwiseOpClipPattern(expr);
Call mul_call = pattern.binary_op;
const auto bit_width = mul_call->type_as<TensorTypeNode>()->dtype.bits();
int32_t output_min = -(1 << (bit_width - 1));
int32_t output_max = (1 << (bit_width - 1)) - 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can we savestd::numeric_limits() as part of the class and use it where needed? Looks more standard than bit based calculations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good shout. I've tried to replace some code duplication throughout this file, so let me konw if that's what you had in mind :D

@lhutton1 lhutton1 changed the title Add CMSIS-NN int16 add and mul operator support [CMSIS-NN] Add int16 add and mul operator support Feb 7, 2023
The CMSIS-NN backend will now partition quantized `int16` additions and
multiplication operators and emit calls to `arm_elementwise_add_s16`
and `arm_elementwise_mul_s16` respectively during codegen.

Because `arm_elementwise_mul_s16` and `arm_elementwise_add_s16` do not
handle non-zero shift parameters at present, for non-zero zero point
values (which map directly to shift in the CMSIS-NN backend)
partitioning fails and we fall back on the regular C codegen path.

This patch also adds `int16` tests, including testing for the non-zero
zero point edge case described above.
Copy link
Contributor

@ashutosh-arm ashutosh-arm left a comment

Choose a reason for hiding this comment

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

LGTM @FranklandJack! Thanks @Mousius for the reviews.

@Mousius Mousius merged commit 2e30e77 into apache:main Feb 8, 2023
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.

4 participants