#ifndef CAFFE2_OPERATORS_ACCUMULATE_OP_H_ #define CAFFE2_OPERATORS_ACCUMULATE_OP_H_ #include "caffe2/core/context.h" #include "caffe2/core/operator.h" #include "caffe2/utils/math.h" namespace caffe2 { template class AccumulateOp final : public Operator { public: AccumulateOp(const OperatorDef& operator_def, Workspace* ws) : Operator(operator_def, ws), gamma_(static_cast( this->template GetSingleArgument("gamma", 1.0))) {} USE_OPERATOR_CONTEXT_FUNCTIONS; bool RunOnDevice() override { auto& input = Input(0); // TODO: the operator depends on output being set to 0 before the run auto* output = Output(0, input.sizes(), at::dtype()); math::Axpby( input.numel(), static_cast(1), input.template data(), gamma_, output->template mutable_data(), &context_); return true; } protected: T gamma_; }; } // namespace caffe2 #endif // CAFFE2_OPERATORS_ACCUMULATE_OP_H_