Skip to content

Conversation

@asparkhi
Copy link
Contributor

@asparkhi asparkhi commented Nov 18, 2021

Support for Maxpool and AvgPool via CMSIS-NN.
Code generation for fully connected layer via CMSIS-NN

This PR depends on #9456.

Tracking issue #8646.

@asparkhi asparkhi changed the title Pooling Code generation for Pooling via CMSIS-NN Nov 18, 2021
@asparkhi asparkhi changed the title Code generation for Pooling via CMSIS-NN [7/10] Code generation for Pooling via CMSIS-NN Nov 18, 2021
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.

Similiar to other one. Seems like this contains contents from FC PR as well ?

tvm::Array<PrimExpr> context_buffer_args = {tir::StringImm(context_buffer_name),
ToArg(context_buffer_size)};

scalar_args = tvm::runtime::Concat(context_buffer_args, scalar_args);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to keep the declaration/initiatlization vectors that get concat closer to the concat.

@asparkhi
Copy link
Contributor Author

asparkhi commented Dec 2, 2021

@manupa-arm I think we should merge this one as this contains both of those changes once I've finally pushed changes addressing your comments.

@manupak
Copy link
Contributor

manupak commented Dec 2, 2021

If we want to do that please close the other PR and adjust titles and descriptions of this PR to reflect its contents.

@asparkhi
Copy link
Contributor Author

asparkhi commented Dec 2, 2021

If we want to do that please close the other PR and adjust titles and descriptions of this PR to reflect its contents.

Done

Change-Id: I67f65e69dfa2c6d31c2ea928d92a827df80bc51a
Ashutosh Parkhi added 3 commits December 3, 2021 10:33
Change-Id: Ibf22250d961a683208faee362d1960ea266347e8
Change-Id: I0675c3248515c9ddc6f25393a3756f907c98fd46
Change-Id: I2e9ca3edec85991be394bbdb2d1739c3afc62d5e
Change-Id: I38fbde65016713956371fa27dbd2a36f844f5799
@asparkhi asparkhi changed the title [7/10] Code generation for Pooling via CMSIS-NN [7/10] Code generation for Pooling and Fully Connected via CMSIS-NN Dec 6, 2021
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! There are few minor comments related to clarity which I dont want to block the PR for another CI cycle. Would you be able to address them in a follow up ?

ToArg(clip_max)};

// cmsis_nn_dims *input_dims (NHWC)
// layout NHWC
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry Ashutosh, I dont still follow what this comment mean. How is this related to the following line ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was to help understand that the following shape is in NHWC layout which will be passed on to CMSIS-NN API eventually.

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 might worth saying that explicitly :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

Array<PrimExpr> input_dims = CMSISNNDimensions(input_shape);

// cmsis_nn_dims *filter_dims (OHWI for Conv2D and IHWO for depthwise)
// OHWI for Conv2D and IHWO for depthwise
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, where is the information OHWI is used ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above. Maybe I should explicitly say that this is for CMSIS-NN API?

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 the information is that the following line produces a tensor is that layout and subsequent access assume that ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, comment got displaced in the process of review and new edits 😆

@@ -194,7 +180,7 @@ class RelayToTIRVisitor : public MixedModeMutator {
if (depth_multiplier != -1) {
cmsisnn_api = "arm_depthwise_conv_wrapper_s8";
Array<PrimExpr> depthwise_filter_shape{1, filter_shape[0], filter_shape[1], out_channels};
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to use something like
int kernel_pos_o = kernel_layout.find("O");
instead of the numbers ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, partly done above. Missed here.

ToArg(context_buffer_size)};

scalar_args = tvm::runtime::Concat(context_buffer_args, scalar_args);
scalar_args = tvm::runtime::Concat(scalar_args, cmsisnn_input_shape);
Copy link
Contributor

Choose a reason for hiding this comment

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

[Clarity] I think we can bring the declaration "cmsisnn_input_shape" closer to here as it is not used before this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We cannot. Its being used to derive another size in the middle. Also, I would prefer to keep concatenation of arguments at one place. Locating all arguments at same place has helped me with debugs.

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 Im missing something here :). Isn't it defined in line 291 and is there a use in between ?
Anyway, if it helps debugging, lets have it this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I was looking at a different operator. For some of the others, context buffer creation requires this shape. Just to be consistent, I didn't want to change the code layout.


scalar_args = tvm::runtime::Concat(context_buffer_args, scalar_args);
scalar_args = tvm::runtime::Concat(scalar_args, cmsisnn_input_shape);
scalar_args = tvm::runtime::Concat(scalar_args, cmsisnn_filter_shape);
Copy link
Contributor

Choose a reason for hiding this comment

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

[Clarity] I think we can bring the declaration "cmsisnn_filter_shape" closer to here as it is not used before this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

scalar_args = tvm::runtime::Concat(context_buffer_args, scalar_args);
scalar_args = tvm::runtime::Concat(scalar_args, cmsisnn_input_shape);
scalar_args = tvm::runtime::Concat(scalar_args, cmsisnn_filter_shape);
scalar_args = tvm::runtime::Concat(scalar_args, bias_shape);
Copy link
Contributor

Choose a reason for hiding this comment

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

[Clarity] I think we can bring the declaration "bias_shape" closer to here as it is not used before this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

scalar_args = tvm::runtime::Concat(scalar_args, cmsisnn_input_shape);
scalar_args = tvm::runtime::Concat(scalar_args, cmsisnn_filter_shape);
scalar_args = tvm::runtime::Concat(scalar_args, bias_shape);
scalar_args = tvm::runtime::Concat(scalar_args, cmsisnn_output_shape);
Copy link
Contributor

Choose a reason for hiding this comment

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

[Clarity] I think we can bring the declaration "cmsisnn_output_shape" closer to here as it is not used before this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

@asparkhi
Copy link
Contributor Author

asparkhi commented Dec 6, 2021

Thanks for the reviews.
Sure @manupa-arm, I can create a follow up for this. Please feel free to merge.

@asparkhi
Copy link
Contributor Author

asparkhi commented Dec 6, 2021

@manupa-arm Could you please put commit message as "Support for code generation of Maxpool, AvgPool and Fully Connected layers via CMSIS-NN"

@manupak manupak merged commit 3f1c931 into apache:main Dec 6, 2021
@manupak
Copy link
Contributor

manupak commented Dec 6, 2021

Thanks @ashutosh-arm ! This is merged now.

@asparkhi asparkhi deleted the pooling branch December 7, 2021 10:05
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
…pache#9531)

Support for code generation of Maxpool, AvgPool and Fully Connected layers via CMSIS-NN
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 11, 2022
…pache#9531)

Support for code generation of Maxpool, AvgPool and Fully Connected layers via CMSIS-NN
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 12, 2022
…pache#9531)

Support for code generation of Maxpool, AvgPool and Fully Connected layers via CMSIS-NN
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
…pache#9531)

Support for code generation of Maxpool, AvgPool and Fully Connected layers via CMSIS-NN
qsqqsqqsq-intellif pushed a commit to qsqqsqqsq-intellif/tvm that referenced this pull request Apr 29, 2022
…pache#9531)

Support for code generation of Maxpool, AvgPool and Fully Connected layers 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.

2 participants