Skip to content

Commit 4bd9644

Browse files
author
niuliling123
committed
reset reduce_any and reduce_all
1 parent a60b90a commit 4bd9644

File tree

2 files changed

+6
-81
lines changed

2 files changed

+6
-81
lines changed

paddle/fluid/operators/reduce_ops/reduce_all_op.cu

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "paddle/fluid/operators/reduce_ops/reduce_all_op.h"
16-
#include "paddle/fluid/operators/reduce_ops/reduce_functor_op.h"
17-
#include "paddle/fluid/operators/reduce_ops/reduce_op.cuh"
18-
#include "paddle/fluid/operators/reduce_ops/reduce_op.h"
1916

20-
namespace paddle {
21-
namespace operators {
22-
23-
template <typename T>
24-
class BoolReduceAllKernel : public framework::OpKernel<T> {
25-
public:
26-
void Compute(const framework::ExecutionContext& context) const override {
27-
bool reduce_all = context.Attr<bool>("reduce_all");
28-
auto* input = context.Input<Tensor>("X");
29-
auto* output = context.Output<Tensor>("Out");
30-
31-
auto dims = context.Attr<std::vector<int>>("dim");
32-
bool keep_dim = context.Attr<bool>("keep_dim");
33-
34-
std::vector<int> reduce_dims;
35-
if (reduce_all) {
36-
reduce_dims.resize(input->dims().size());
37-
for (int i = 0; i < reduce_dims.size(); ++i) {
38-
reduce_dims[i] = i;
39-
}
40-
} else {
41-
for (auto e : dims) {
42-
reduce_dims.push_back(e >= 0 ? e : e + input->dims().size());
43-
}
44-
}
45-
46-
auto stream = context.cuda_device_context().stream();
47-
TensorReduceFunc<T, T, CustomLogicalAnd<T>, detail::IdentityFunctor<T>>(
48-
*input, output, reduce_dims, static_cast<T>(true),
49-
CustomLogicalAnd<T>(), detail::IdentityFunctor<T>(), stream);
50-
}
51-
};
52-
53-
} // namespace operators
54-
} // namespace paddle
55-
56-
REGISTER_OP_CUDA_KERNEL(reduce_all, ops::BoolReduceAllKernel<bool>);
17+
REGISTER_OP_CUDA_KERNEL(
18+
reduce_all, ops::BoolReduceKernel<paddle::platform::CUDADeviceContext, bool,
19+
ops::AllFunctor>);

paddle/fluid/operators/reduce_ops/reduce_any_op.cu

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "paddle/fluid/operators/reduce_ops/reduce_any_op.h"
16-
#include "paddle/fluid/operators/reduce_ops/reduce_functor_op.h"
17-
#include "paddle/fluid/operators/reduce_ops/reduce_op.cuh"
18-
#include "paddle/fluid/operators/reduce_ops/reduce_op.h"
1916

20-
namespace paddle {
21-
namespace operators {
22-
23-
template <typename T>
24-
class BoolReduceAnyKernel : public framework::OpKernel<T> {
25-
public:
26-
void Compute(const framework::ExecutionContext& context) const override {
27-
bool reduce_all = context.Attr<bool>("reduce_all");
28-
auto* input = context.Input<Tensor>("X");
29-
auto* output = context.Output<Tensor>("Out");
30-
31-
auto dims = context.Attr<std::vector<int>>("dim");
32-
bool keep_dim = context.Attr<bool>("keep_dim");
33-
34-
std::vector<int> reduce_dims;
35-
if (reduce_all) {
36-
reduce_dims.resize(input->dims().size());
37-
for (int i = 0; i < reduce_dims.size(); ++i) {
38-
reduce_dims[i] = i;
39-
}
40-
41-
} else {
42-
for (auto e : dims) {
43-
reduce_dims.push_back(e >= 0 ? e : e + input->dims().size());
44-
}
45-
}
46-
47-
auto stream = context.cuda_device_context().stream();
48-
TensorReduceFunc<T, T, CustomLogicalOr<T>, detail::IdentityFunctor<T>>(
49-
*input, output, reduce_dims, static_cast<T>(false),
50-
CustomLogicalOr<T>(), detail::IdentityFunctor<T>(), stream);
51-
}
52-
};
53-
54-
} // namespace operators
55-
} // namespace paddle
56-
57-
REGISTER_OP_CUDA_KERNEL(reduce_any, ops::BoolReduceAnyKernel<bool>);
17+
REGISTER_OP_CUDA_KERNEL(
18+
reduce_any, ops::BoolReduceKernel<paddle::platform::CUDADeviceContext, bool,
19+
ops::AnyFunctor>);

0 commit comments

Comments
 (0)