-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 isnan_v2、isfinite_v2、isinf_v2 to phi #40076
Changes from 5 commits
786431b
4010ee5
ba9f5fc
98d6a6e
0a7ee3b
0128ff0
074a237
059285d
3dc9849
e8daa44
687bd49
8b553b3
56abc9f
dcd1d4f
cf7700e
1582d6f
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,56 @@ | ||
// 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/kernels/funcs/isfinite_functor.h" | ||
#include "paddle/phi/kernels/isfinite_kernel.h" | ||
|
||
namespace phi { | ||
|
||
template <typename T, typename Context, typename Functor> | ||
inline void IsfiniteKernelImpl(const Context& ctx, | ||
const DenseTensor& x, | ||
DenseTensor* out); | ||
|
||
template <typename T, typename Context, typename Functor> | ||
inline void IsfiniteSRImpl(const Context& ctx, | ||
const SelectedRows& x, | ||
SelectedRows* out); | ||
|
||
#define DEFINE_ISFINITE_KERNEL(isfinite_kernel, functor) \ | ||
template <typename T, typename Context> \ | ||
void isfinite_kernel( \ | ||
const Context& ctx, const DenseTensor& x, DenseTensor* out) { \ | ||
IsfiniteKernelImpl<T, Context, functor>(ctx, x, out); \ | ||
} | ||
|
||
DEFINE_ISFINITE_KERNEL(IsinfKernel, funcs::InfinityV2Functor) | ||
DEFINE_ISFINITE_KERNEL(IsnanKernel, funcs::NANV2Functor) | ||
DEFINE_ISFINITE_KERNEL(IsfiniteKernel, funcs::IsfiniteV2Functor) | ||
#undef DEFINE_ISFINITE_KERNEL | ||
|
||
#define DEFINE_ISFINITE_SR(isfinite_sr, functor) \ | ||
template <typename T, typename Context> \ | ||
void isfinite_sr( \ | ||
const Context& ctx, const SelectedRows& x, SelectedRows* out) { \ | ||
IsfiniteSRImpl<T, Context, functor>(ctx, x, out); \ | ||
} | ||
|
||
DEFINE_ISFINITE_SR(IsinfSR, funcs::InfinityV2Functor) | ||
DEFINE_ISFINITE_SR(IsnanSR, funcs::NANV2Functor) | ||
DEFINE_ISFINITE_SR(IsfiniteSR, funcs::IsfiniteV2Functor) | ||
#undef DEFINE_ISFINITE_SR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SelectedRows相关的kernel逻辑需要放在selected_rows目录下 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
} // namespace phi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我看了下底层的TensorContainsInfV2这几个实现,还是属于cpu和gpu公用的实现,这样的话,这个还是属于应该在cpu和gpu子目录下分别创建cc和cu文件的情况,kernels根目录下是放置纯设备无关的kernel实现,比如说这个也需要在xpu和将来的其他设备上能用才行,目前的实现是不行的 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chenwhql Done.已在cpu和gpu子目录下分别创建cc和cu文件 |
||
// | ||
// 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/isfinite_kernel.h" | ||
|
||
#include "paddle/phi/backends/all_context.h" | ||
#include "paddle/phi/common/bfloat16.h" | ||
#include "paddle/phi/core/kernel_registry.h" | ||
#include "paddle/phi/kernels/impl/isfinite_kernel_impl.h" | ||
|
||
namespace phi { | ||
|
||
template <typename T, typename Context, typename Functor> | ||
inline void IsfiniteKernelImpl(const Context& dev_ctx, | ||
const DenseTensor& x, | ||
DenseTensor* out) { | ||
dev_ctx.template Alloc<T>(out); | ||
Functor functor; | ||
functor(x, out); | ||
} | ||
|
||
} // namespace phi | ||
|
||
PD_REGISTER_KERNEL(isinf, | ||
CPU, | ||
ALL_LAYOUT, | ||
phi::IsinfKernel, | ||
float, | ||
double, | ||
phi::dtype::bfloat16, | ||
int, | ||
int64_t) {} | ||
|
||
PD_REGISTER_KERNEL(isnan, | ||
CPU, | ||
ALL_LAYOUT, | ||
phi::IsnanKernel, | ||
float, | ||
double, | ||
phi::dtype::bfloat16, | ||
int, | ||
int64_t) {} | ||
|
||
PD_REGISTER_KERNEL(isfinite, | ||
CPU, | ||
ALL_LAYOUT, | ||
phi::IsfiniteKernel, | ||
float, | ||
double, | ||
phi::dtype::bfloat16, | ||
int, | ||
int64_t) {} | ||
|
||
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) | ||
PD_REGISTER_KERNEL(isinf, | ||
GPU, | ||
ALL_LAYOUT, | ||
phi::IsinfKernel, | ||
float, | ||
double, | ||
phi::dtype::bfloat16, | ||
int, | ||
int64_t) {} | ||
|
||
PD_REGISTER_KERNEL(isnan, | ||
GPU, | ||
ALL_LAYOUT, | ||
phi::IsnanKernel, | ||
float, | ||
double, | ||
phi::dtype::bfloat16, | ||
int, | ||
int64_t) {} | ||
|
||
PD_REGISTER_KERNEL(isfinite, | ||
GPU, | ||
ALL_LAYOUT, | ||
phi::IsfiniteKernel, | ||
float, | ||
double, | ||
phi::dtype::bfloat16, | ||
int, | ||
int64_t) {} | ||
#endif |
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.
op_registry这个头文件还需要吗