未验证 提交 7eb9593e 编写于 作者: F Feiyu Chan 提交者: GitHub

move algorithm.h (#39502)

Move paddle/fluid/operators/math/algorithm.h to paddle/pten/kernels/funcs and rename all references to symbols in it.
上级 2d16d69b
......@@ -104,7 +104,7 @@ __global__ void SparseAdamCUDAKernelREG(
for (; id < ndim; id += blockDim.x * gridDim.x) {
auto row_idx =
math::BinarySearch<int64_t>(rows_, row_count, id / row_numel);
pten::funcs::BinarySearch<int64_t>(rows_, row_count, id / row_numel);
if (lazy_mode && row_idx < 0) {
return;
} else {
......
......@@ -21,10 +21,10 @@ limitations under the License. */
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/threadpool.h"
#include "paddle/fluid/operators/jit/kernels.h"
#include "paddle/fluid/operators/math/algorithm.h"
#include "paddle/fluid/operators/math/selected_rows_functor.h"
#include "paddle/fluid/platform/for_range.h"
#include "paddle/fluid/platform/profiler.h"
#include "paddle/pten/kernels/funcs/algorithm.h"
namespace paddle {
namespace operators {
......@@ -279,7 +279,7 @@ class SparseAdamFunctor<T, GPUAdam, MT> {
inline HOSTDEVICE void operator()(size_t i) const {
auto row_idx =
math::BinarySearch<int64_t>(rows_, row_count_, i / row_numel_);
pten::funcs::BinarySearch<int64_t>(rows_, row_count_, i / row_numel_);
if (lazy_mode_ && row_idx < 0) {
return;
} else {
......
......@@ -112,7 +112,7 @@ __global__ void SparseAdamWCUDAKernelREG(
for (; id < ndim; id += blockDim.x * gridDim.x) {
auto row_idx =
math::BinarySearch<int64_t>(rows_, row_count, id / row_numel);
pten::funcs::BinarySearch<int64_t>(rows_, row_count, id / row_numel);
if (lazy_mode && row_idx < 0) {
return;
} else {
......
......@@ -142,7 +142,7 @@ class SparseAdamWFunctor<T, GPUAdamW, MT> {
inline HOSTDEVICE void operator()(size_t i) const {
auto row_idx =
math::BinarySearch<int64_t>(rows_, row_count_, i / row_numel_);
pten::funcs::BinarySearch<int64_t>(rows_, row_count_, i / row_numel_);
if (lazy_mode_ && row_idx < 0) {
return;
} else {
......
......@@ -19,10 +19,10 @@ limitations under the License. */
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/memory/buffer.h"
#include "paddle/fluid/operators/amp/fp16_type_traits.h"
#include "paddle/fluid/operators/math/algorithm.h"
#include "paddle/fluid/operators/math/selected_rows_functor.h"
#include "paddle/fluid/operators/math/squared_l2_norm.h"
#include "paddle/fluid/platform/for_range.h"
#include "paddle/pten/kernels/funcs/algorithm.h"
#include "paddle/pten/kernels/funcs/eigen/extensions.h"
namespace paddle {
......@@ -233,7 +233,7 @@ struct SparseLambMomentREGUpdateFunctor {
inline HOSTDEVICE void operator()(size_t i) const {
if (skip_update_ && *skip_update_) return;
auto row_idx =
math::BinarySearch<int64_t>(rows_, row_count_, i / row_numel_);
pten::funcs::BinarySearch<int64_t>(rows_, row_count_, i / row_numel_);
T g = row_idx >= 0 ? grad_[row_idx * row_numel_ + i % row_numel_]
: static_cast<T>(0);
update(i, g);
......@@ -312,7 +312,7 @@ struct SparseLambMomentMENUpdateFunctor {
inline HOSTDEVICE void operator()(size_t i) const {
if (skip_update_ && *skip_update_) return;
auto row_idx =
math::BinarySearch<int64_t>(rows_, row_count_, i / row_numel_);
pten::funcs::BinarySearch<int64_t>(rows_, row_count_, i / row_numel_);
T g = row_idx >= 0 ? grad_[row_idx * row_numel_ + i % row_numel_]
: static_cast<T>(0);
update(i, g);
......
......@@ -18,10 +18,10 @@ limitations under the License. */
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/operators/amp/fp16_type_traits.h"
#include "paddle/fluid/operators/math/algorithm.h"
#include "paddle/fluid/operators/math/selected_rows_functor.h"
#include "paddle/fluid/platform/float16.h"
#include "paddle/fluid/platform/for_range.h"
#include "paddle/pten/kernels/funcs/algorithm.h"
namespace paddle {
namespace operators {
......@@ -345,7 +345,7 @@ class SparseMomentumFunctor<T, MT, UseNesterov> {
inline HOSTDEVICE void operator()(size_t i) {
auto row_idx =
math::BinarySearch<int64_t>(rows_, row_height_, i / row_numel_);
pten::funcs::BinarySearch<int64_t>(rows_, row_height_, i / row_numel_);
MT grad =
row_idx >= 0
? static_cast<MT>(grad_[row_idx * row_numel_ + i % row_numel_]) *
......@@ -418,7 +418,7 @@ class SparseMomentumFunctor<T, MT, NoNesterov> {
inline HOSTDEVICE void operator()(size_t i) {
auto row_idx =
math::BinarySearch<int64_t>(rows_, row_height_, i / row_numel_);
pten::funcs::BinarySearch<int64_t>(rows_, row_height_, i / row_numel_);
MT grad =
row_idx >= 0
? static_cast<MT>(grad_[row_idx * row_numel_ + i % row_numel_]) *
......
......@@ -16,9 +16,9 @@ limitations under the License. */
#include <math.h>
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/operators/math/algorithm.h"
#include "paddle/fluid/operators/math/selected_rows_functor.h"
#include "paddle/fluid/platform/for_range.h"
#include "paddle/pten/kernels/funcs/algorithm.h"
namespace paddle {
namespace operators {
......@@ -42,7 +42,8 @@ struct SparseRmspropGradFunctor {
row_count_(row_count) {}
HOSTDEVICE inline T operator()(int64_t idx) const {
auto row_idx = math::BinarySearch(rows_, row_count_, idx / row_numel_);
auto row_idx =
pten::funcs::BinarySearch(rows_, row_count_, idx / row_numel_);
return row_idx >= 0 ? grad_[row_idx * row_numel_ + idx % row_numel_] : 0;
}
......
......@@ -21,7 +21,6 @@
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/operators/amp/fp16_type_traits.h"
#include "paddle/fluid/operators/math/algorithm.h"
#include "paddle/fluid/platform/float16.h"
#include "paddle/fluid/platform/for_range.h"
......
......@@ -19,9 +19,9 @@
#include "paddle/fluid/framework/ddim.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/operators/math/algorithm.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/for_range.h"
#include "paddle/pten/kernels/funcs/algorithm.h"
namespace paddle {
namespace operators {
......@@ -85,11 +85,11 @@ class GpuAndCpuSearchSortedCompute {
out_data_[idx] = seq_size_;
} else {
if (right_) {
out_data_[idx] = static_cast<OutType>(
math::UpperBound<T1, T2>(sequence_ptr, seq_size_, *value_ptr));
out_data_[idx] = static_cast<OutType>(pten::funcs::UpperBound<T1, T2>(
sequence_ptr, seq_size_, *value_ptr));
} else {
out_data_[idx] = static_cast<OutType>(
math::LowerBound<T1, T2>(sequence_ptr, seq_size_, *value_ptr));
out_data_[idx] = static_cast<OutType>(pten::funcs::LowerBound<T1, T2>(
sequence_ptr, seq_size_, *value_ptr));
}
}
}
......
......@@ -16,8 +16,8 @@
#include <memory>
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/operators/math/algorithm.h"
#include "paddle/fluid/platform/for_range.h"
#include "paddle/pten/kernels/funcs/algorithm.h"
namespace paddle {
namespace operators {
......@@ -94,7 +94,7 @@ struct SequenceReverseFunctor {
HOSTDEVICE void operator()(size_t idx_x) const {
auto row_idx_x = idx_x / row_numel_;
auto lod_idx = math::UpperBound(lod_, lod_count_, row_idx_x);
auto lod_idx = pten::funcs::UpperBound(lod_, lod_count_, row_idx_x);
auto row_idx_y = lod_[lod_idx - 1] + (lod_[lod_idx] - 1 - row_idx_x);
auto idx_y = row_idx_y * row_numel_ + idx_x % row_numel_;
y_[idx_y] = x_[idx_x];
......
......@@ -20,9 +20,8 @@
#include "paddle/pten/core/hostdevice.h"
namespace paddle {
namespace operators {
namespace math {
namespace pten {
namespace funcs {
template <typename T>
HOSTDEVICE inline int64_t BinarySearch(const T *x, int64_t num, const T &val) {
......@@ -85,6 +84,5 @@ HOSTDEVICE inline size_t UpperBound(const T1 *x, size_t num, const T2 &val) {
#endif // @} End Group UpperBound
}
} // namespace math
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册