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

[NPU] Support NPU kernel for nearest_interp and nearest_interp_grad op #34881

Merged
merged 5 commits into from
Aug 16, 2021

Conversation

From00
Copy link
Contributor

@From00 From00 commented Aug 13, 2021

PR types

New features

PR changes

OPs

Describe

Develop the NPU kernel for nearest_interp and nearest_interp_grad op.

Unit test result
image

@paddle-bot-old
Copy link

paddle-bot-old bot commented Aug 13, 2021

✅ This PR's description meets the template requirements!
Please wait for other CI results.

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@From00 From00 changed the title Add NPU kernel for nearest_interp op [NPU] Support NPU kernel for nearest_interp and nearest_interp_grad op Aug 13, 2021
@From00 From00 marked this pull request as ready for review August 13, 2021 13:41
namespace ops = paddle::operators;
REGISTER_OP_NPU_KERNEL(nearest_interp, ops::InterpolateNPUKernel<float>,
ops::InterpolateNPUKernel<uint8_t>);
REGISTER_OP_NPU_KERNEL(nearest_interp_grad, ops::InterpolateNPUKernel<float>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
REGISTER_OP_NPU_KERNEL(nearest_interp_grad, ops::InterpolateNPUKernel<float>,
REGISTER_OP_NPU_KERNEL(nearest_interp_grad, ops::InterpolateGradNPUKernel<float>,

Comment on lines 1 to 10
/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check the copyright format

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

class InterpolateNPUKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& ctx) const override {
// Note(Ruibiao):
Copy link
Contributor

Choose a reason for hiding this comment

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

Note -> NOTE

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

Comment on lines +40 to +42
*c = dims[1];
*h = dims[2];
*w = dims[3];
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 this op only supports tensor with Rank 4?

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, this OP only supports the nearest interpolation for 2D images, with Rank 4 for the input tensor (n, c, h, w). I got this information from the CPU kernel in "interpolate_op.h", where the "NearestNeighborInterpolate" function is only called for 2D interpolation.

Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

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

LGTM

@From00 From00 requested a review from zhiqiu August 16, 2021 06:02
@zhiqiu zhiqiu merged commit e4e8cc9 into PaddlePaddle:develop Aug 16, 2021
@From00 From00 deleted the add_npu_op_nearest_interp branch September 18, 2021 07:56
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