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

[PHI] Sum op migration #46239

Merged
merged 9 commits into from
Sep 22, 2022
Merged

[PHI] Sum op migration #46239

merged 9 commits into from
Sep 22, 2022

Conversation

paulinagacek
Copy link
Contributor

PR types

Others

PR changes

Others

Describe

Migrate sum(add) operator to phi

@paddle-bot
Copy link

paddle-bot bot commented Sep 19, 2022

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@CLAassistant
Copy link

CLAassistant commented Sep 19, 2022

CLA assistant check
All committers have signed the CLA.

@paddle-bot paddle-bot bot added contributor External developers status: proposed labels Sep 19, 2022
@paulinagacek paulinagacek marked this pull request as ready for review September 20, 2022 19:08
@paulinagacek
Copy link
Contributor Author

@piotrekobi, @Silv3S can you review please?

Silv3S
Silv3S previously approved these changes Sep 21, 2022
Copy link
Member

@Silv3S Silv3S left a comment

Choose a reason for hiding this comment

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

I left a few minor comments but overall a very good job
LGTM 👍

AddOneDNNHandler(dnnl::engine engine,
const phi::Place& cpu_place,
const std::vector<const TensorBase*>& x,
DenseTensor* z)
Copy link
Member

Choose a reason for hiding this comment

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

maybe change it to out because z is unintuitive

PADDLE_ENFORCE_EQ(
dev_ctx.GetPlace().GetType() == phi::AllocationType::CPU,
true,
phi::errors::PreconditionNotMet("Operator DNNL Sum must use CPUPlace"));
Copy link
Member

Choose a reason for hiding this comment

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

DNNL is deprecated, please replace with oneDNN.
I'd change Operator DNNL Sum either to oneDNN Sum primitive or oneDNN AddN kernel.

namespace phi {
namespace funcs {
template <typename T>
class AddOneDNNHandler
Copy link
Member

Choose a reason for hiding this comment

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

We usually name handlers after oneDNN primitive names. For example scale or gelu kernels use ActivationKernel, because oneDNN treats such linear operations as activations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what name do you suggest instead?

Copy link
Member

Choose a reason for hiding this comment

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

SumOneDNNHandler

Comment on lines 123 to 127
if (in_place) {
dst_mem = srcs_mem[0];
} else {
dst_mem = handler.AcquireDstMemory(out);
}
Copy link
Member

Choose a reason for hiding this comment

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

auto dst_mem = in_place ? srcs_mem[0] : handler.AcquireDstMemory(out);

Copy link
Contributor

@piotrekobi piotrekobi left a comment

Choose a reason for hiding this comment

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

Please remove the unnecessary namespace names. Great job once again :D!

namespace funcs {
template <typename T>
class AddOneDNNHandler
: public phi::funcs::OneDNNHandlerNoCachingT<T, dnnl::sum> {
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
: public phi::funcs::OneDNNHandlerNoCachingT<T, dnnl::sum> {
: public OneDNNHandlerNoCachingT<T, dnnl::sum> {

const std::vector<const TensorBase*>& x,
DenseTensor* z)

: phi::funcs::OneDNNHandlerNoCachingT<T, dnnl::sum>(engine, cpu_place),
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
: phi::funcs::OneDNNHandlerNoCachingT<T, dnnl::sum>(engine, cpu_place),
: OneDNNHandlerNoCachingT<T, dnnl::sum>(engine, cpu_place),


: phi::funcs::OneDNNHandlerNoCachingT<T, dnnl::sum>(engine, cpu_place),
num_inputs_(0) {
auto dst_tz = phi::vectorize<int64_t>(z->dims());
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
auto dst_tz = phi::vectorize<int64_t>(z->dims());
auto dst_tz = vectorize<int64_t>(z->dims());

to_void_cast<T>(input_data));
}

using phi::funcs::OneDNNHandlerNoCachingT<T, dnnl::sum>::AcquireDstMemory;
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
using phi::funcs::OneDNNHandlerNoCachingT<T, dnnl::sum>::AcquireDstMemory;
using OneDNNHandlerNoCachingT<T, dnnl::sum>::AcquireDstMemory;

const std::vector<const TensorBase*>& x,
DenseTensor* out) {
PADDLE_ENFORCE_EQ(
dev_ctx.GetPlace().GetType() == phi::AllocationType::CPU,
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
dev_ctx.GetPlace().GetType() == phi::AllocationType::CPU,
dev_ctx.GetPlace().GetType() == AllocationType::CPU,

PADDLE_ENFORCE_EQ(
dev_ctx.GetPlace().GetType() == phi::AllocationType::CPU,
true,
phi::errors::PreconditionNotMet("Operator DNNL Sum must use CPUPlace"));
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
phi::errors::PreconditionNotMet("Operator DNNL Sum must use CPUPlace"));
errors::PreconditionNotMet("Operator DNNL Sum must use CPUPlace"));


PADDLE_ENFORCE_NE(x.empty(),
true,
phi::errors::InvalidArgument("Input variable is empty."));
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
phi::errors::InvalidArgument("Input variable is empty."));
errors::InvalidArgument("Input variable is empty."));

Copy link
Contributor

@piotrekobi piotrekobi left a comment

Choose a reason for hiding this comment

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

LGTM

@paulinagacek
Copy link
Contributor Author

@jczaja I think it is ready to be merged

Copy link
Contributor

@jczaja jczaja left a comment

Choose a reason for hiding this comment

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

LGTM

@jczaja jczaja merged commit 3448afc into PaddlePaddle:develop Sep 22, 2022
@paddle-bot
Copy link

paddle-bot bot commented Sep 22, 2022

你的PR已合入Paddle库,请关注后续测试结果。
Your PR has been merged into the repository. An official integration test will be conducted later. Stay tuned.

umiswing pushed a commit to umiswing/Paddle that referenced this pull request Sep 28, 2022
* Sum kernel migrated to phi

* Static cast added, file name changed

* OneDNNGetDataType to uppercase

* refactoring

* AddOneDNNHandler changed to SumOneDNNHandler
Silv3S pushed a commit to Silv3S/Paddle that referenced this pull request Oct 3, 2022
* Sum kernel migrated to phi

* Static cast added, file name changed

* OneDNNGetDataType to uppercase

* refactoring

* AddOneDNNHandler changed to SumOneDNNHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers Intel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants