- Notifications
You must be signed in to change notification settings - Fork 5.9k
[phi] move is_empty to phi #39919
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] move is_empty to phi #39919
Changes from 9 commits
93079a4 d577036 f86f596 093a9a6 b5e6cc3 9c9cd29 d8a432e 86e5a6a b638391 942fab1 85c6897 7617f0c 312ef41 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
| // | ||
| // 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. | ||
| | ||
| #include "paddle/phi/kernels/is_empty_kernel.h" | ||
| | ||
| #include "paddle/phi/backends/all_context.h" | ||
| #include "paddle/phi/core/kernel_registry.h" | ||
| | ||
| namespace phi { | ||
| | ||
| template <typename T, typename Context> | ||
| void IsEmptyKernel(const Context& dev_ctx, | ||
| const DenseTensor& x, | ||
| DenseTensor* out) { | ||
| // Note: is_empty is always executed on CPU and the output data should | ||
| // always be allocated for CPUPlace. We reigister CUDA kernel for this op to | ||
| // avoid the unnecessary data transform. | ||
| out->mutable_data<bool>(phi::CPUPlace())[0] = phi::product(x.dims()) == 0; | ||
| ||
| } | ||
| | ||
| } // namespace phi | ||
| | ||
| PD_REGISTER_KERNEL(is_empty, | ||
| CPU, | ||
| ALL_LAYOUT, | ||
| phi::IsEmptyKernel, | ||
| float, | ||
| double, | ||
| int, | ||
| int64_t) {} | ||
| | ||
| #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) | ||
| PD_REGISTER_KERNEL(is_empty, | ||
| GPU, | ||
| ALL_LAYOUT, | ||
| phi::IsEmptyKernel, | ||
| float, | ||
| double, | ||
| int, | ||
| int64_t) {} | ||
| #endif | ||
| ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
| // | ||
| // 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. | ||
| | ||
| #pragma once | ||
| | ||
| #include "paddle/phi/core/dense_tensor.h" | ||
| | ||
| namespace phi { | ||
| | ||
| template <typename T, typename Context> | ||
| void IsEmptyKernel(const Context& ctx, const DenseTensor& x, DenseTensor* out); | ||
| | ||
| } // namespace phi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
licence里的这些空行是固定格式,不用删,可参考其他文件
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.