|
|
|
@ -13,8 +13,47 @@
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
#include "paddle/fluid/operators/reduce_ops/reduce_sum_op.h"
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
namespace paddle {
|
|
|
|
|
namespace operators {
|
|
|
|
|
|
|
|
|
|
// NOTE: Input(Out) is unnecessary in reduce_sum_grad, and Input(X) needs no
|
|
|
|
|
// buffer
|
|
|
|
|
class ReduceSumOpGradDescMaker : public framework::SingleGradOpDescMaker {
|
|
|
|
|
public:
|
|
|
|
|
using framework::SingleGradOpDescMaker::SingleGradOpDescMaker;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
std::unique_ptr<framework::OpDesc> Apply() const override {
|
|
|
|
|
std::unique_ptr<framework::OpDesc> op(new framework::OpDesc());
|
|
|
|
|
op->SetType("reduce_sum_grad");
|
|
|
|
|
op->SetInput("X", Input("X"));
|
|
|
|
|
op->SetInput(framework::GradVarName("Out"), OutputGrad("Out"));
|
|
|
|
|
op->SetAttrMap(Attrs());
|
|
|
|
|
op->SetOutput(framework::GradVarName("X"), InputGrad("X"));
|
|
|
|
|
return op;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DECLARE_NO_NEED_BUFFER_VARS_INFERENCE(ReduceSumGradNoNeedBufferVarInference,
|
|
|
|
|
"X");
|
|
|
|
|
|
|
|
|
|
} // namespace operators
|
|
|
|
|
} // namespace paddle
|
|
|
|
|
|
|
|
|
|
class ReduceSumOpMaker : public ops::ReduceOpMaker {
|
|
|
|
|
protected:
|
|
|
|
|
virtual std::string GetName() const { return "reduce_sum"; }
|
|
|
|
|
virtual std::string GetOpType() const { return "Reduce reduce_sum"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
REGISTER_OPERATOR(reduce_sum, ops::ReduceOp, ReduceSumOpMaker,
|
|
|
|
|
ops::ReduceSumOpGradDescMaker);
|
|
|
|
|
REGISTER_OPERATOR(reduce_sum_grad, ops::ReduceGradOp,
|
|
|
|
|
ops::ReduceSumGradNoNeedBufferVarInference);
|
|
|
|
|
|
|
|
|
|
REGISTER_REDUCE_OP(reduce_sum);
|
|
|
|
|
REGISTER_OP_CPU_KERNEL(
|
|
|
|
|
reduce_sum, ops::ReduceKernel<paddle::platform::CPUDeviceContext, float,
|
|
|
|
|
ops::SumFunctor>,
|
|
|
|
@ -23,13 +62,13 @@ REGISTER_OP_CPU_KERNEL(
|
|
|
|
|
ops::ReduceKernel<paddle::platform::CPUDeviceContext, int, ops::SumFunctor>,
|
|
|
|
|
ops::ReduceKernel<paddle::platform::CPUDeviceContext, int64_t,
|
|
|
|
|
ops::SumFunctor>);
|
|
|
|
|
REGISTER_OP_CPU_KERNEL(
|
|
|
|
|
reduce_sum_grad,
|
|
|
|
|
ops::ReduceSumGradKernel<paddle::platform::CPUDeviceContext, float,
|
|
|
|
|
ops::SumGradFunctor>,
|
|
|
|
|
ops::ReduceSumGradKernel<paddle::platform::CPUDeviceContext, double,
|
|
|
|
|
ops::SumGradFunctor>,
|
|
|
|
|
ops::ReduceSumGradKernel<paddle::platform::CPUDeviceContext, int,
|
|
|
|
|
ops::SumGradFunctor>,
|
|
|
|
|
ops::ReduceSumGradKernel<paddle::platform::CPUDeviceContext, int64_t,
|
|
|
|
|
ops::SumGradFunctor>);
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
using CPUReduceSumGradKernel =
|
|
|
|
|
ops::ReduceSumGradKernel<paddle::platform::CPUDeviceContext, T,
|
|
|
|
|
ops::SumGradFunctor, true>;
|
|
|
|
|
|
|
|
|
|
REGISTER_OP_CPU_KERNEL(reduce_sum_grad, CPUReduceSumGradKernel<float>,
|
|
|
|
|
CPUReduceSumGradKernel<double>,
|
|
|
|
|
CPUReduceSumGradKernel<int>,
|
|
|
|
|
CPUReduceSumGradKernel<int64_t>);
|
|
|
|
|