Reformat paddle/operators/* strictly following Google Style Guide

cblas_new
Yi Wang 8 years ago
parent 559b02244d
commit 9620df4464

@ -0,0 +1,5 @@
---
Language: Cpp
BasedOnStyle: Google
Standard: Cpp11
...

@ -18,7 +18,7 @@ namespace paddle {
namespace operators {
class AddOp : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {
PADDLE_ENFORCE(ctx.InputSize() == 2, "Input size of AddOp must be two");
PADDLE_ENFORCE(ctx.OutputSize() == 1, "Output size of AddOp must be one");
@ -33,7 +33,7 @@ protected:
};
class AddOpMaker : public OpProtoAndCheckerMaker {
public:
public:
AddOpMaker(OpProto *proto, OpAttrChecker *op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("X", "The first input of add op");
@ -48,7 +48,7 @@ The equation is: Out = X + Y
};
class AddOpGrad : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {}
};

@ -20,7 +20,7 @@ namespace operators {
template <typename Place, typename T>
class AddKernel : public OpKernel {
public:
public:
void Compute(const ExecutionContext& context) const override {
auto input0 = context.Input<Tensor>(0);
auto input1 = context.Input<Tensor>(1);

@ -18,7 +18,7 @@ namespace paddle {
namespace operators {
class OnehotCrossEntropyOp : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {
PADDLE_ENFORCE(ctx.InputSize() == 2,
"Input size of OnehotCrossEntropyOp must be two");
@ -37,7 +37,7 @@ protected:
};
class OnehotCrossEntropyOpMaker : public OpProtoAndCheckerMaker {
public:
public:
OnehotCrossEntropyOpMaker(OpProto *proto, OpAttrChecker *op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("X", "The first input of OnehotCrossEntropyOp");
@ -54,8 +54,7 @@ OnehotCrossEntropy Operator.
} // namespace operators
} // namespace paddle
REGISTER_OP(onehot_cross_entropy,
ops::OnehotCrossEntropyOp,
REGISTER_OP(onehot_cross_entropy, ops::OnehotCrossEntropyOp,
ops::OnehotCrossEntropyOpMaker);
REGISTER_OP_CPU_KERNEL(onehot_cross_entropy,
ops::OnehotCrossEntropyOpKernel<ops::CPUPlace, float>);

@ -20,7 +20,7 @@ namespace operators {
template <typename Place, typename T>
class OnehotCrossEntropyOpKernel : public OpKernel {
public:
public:
constexpr T LOG_THRESHOLD() const { return static_cast<T>(1e-20); }
void Compute(const ExecutionContext& ctx) const override {

@ -18,31 +18,29 @@ namespace paddle {
namespace operators {
class FullyConnectedOp : public NetOp {
public:
public:
void Init() override {
AddOp(OpRegistry::CreateOp("mul",
{
Input("X"), Input("W"),
},
{Output("before_act")},
{}));
{Output("before_act")}, {}));
auto b = Input("b");
if (b != framework::kEmptyVarName) {
AddOp(OpRegistry::CreateOp("rowwise_add",
{Output("before_act"), Input("b")},
{Output("before_act")},
{}));
{Output("before_act")}, {}));
}
auto activation = GetAttr<std::string>("activation");
AddOp(OpRegistry::CreateOp(
activation, {Output("before_act")}, {Output("Y")}, {}));
AddOp(OpRegistry::CreateOp(activation, {Output("before_act")},
{Output("Y")}, {}));
CompleteAddOp(false);
}
};
class FullyConnectedOpMaker : public OpProtoAndCheckerMaker {
public:
public:
FullyConnectedOpMaker(OpProto *proto, OpAttrChecker *op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("X", "the input of fc operator");

@ -20,7 +20,7 @@ namespace paddle {
namespace operators {
class FillZerosLikeOp : public framework::OperatorWithKernel {
protected:
protected:
void InferShape(const framework::InferShapeContext &ctx) const override {
PADDLE_ENFORCE(ctx.InputSize() == 1UL,
"Input size of FillZerosLikeOp must be one.");
@ -36,7 +36,7 @@ protected:
};
class FillZerosLikeOpMaker : public framework::OpProtoAndCheckerMaker {
public:
public:
FillZerosLikeOpMaker(framework::OpProto *proto,
framework::OpAttrChecker *op_checker)
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
@ -52,8 +52,7 @@ The output will have the same size with input.
} // namespace operators
} // namespace paddle
REGISTER_OP(fill_zeros_like,
paddle::operators::FillZerosLikeOp,
REGISTER_OP(fill_zeros_like, paddle::operators::FillZerosLikeOp,
paddle::operators::FillZerosLikeOpMaker);
REGISTER_OP_CPU_KERNEL(
fill_zeros_like,

@ -22,7 +22,7 @@ namespace operators {
template <typename Place, typename T>
class FillZerosLikeKernel : public framework::OpKernel {
public:
public:
void Compute(const framework::ExecutionContext& context) const override {
auto* output = context.Output<framework::Tensor>(0);
output->mutable_data<T>(context.GetPlace());

@ -18,7 +18,7 @@ namespace paddle {
namespace operators {
class MeanOp : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {
PADDLE_ENFORCE(ctx.InputSize() == 1, "Input size of AddOp must be one");
PADDLE_ENFORCE(ctx.OutputSize() == 1, "Output size of AddOp must be one");
@ -29,7 +29,7 @@ protected:
};
class MeanOpMaker : public OpProtoAndCheckerMaker {
public:
public:
MeanOpMaker(OpProto *proto, OpAttrChecker *op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("X", "The input of mean op");
@ -39,7 +39,7 @@ public:
};
class MeanGradOp : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {
ctx.Output<Tensor>("X" + framework::kGradVarSuffix)
->Resize(ctx.Input<Tensor>("X")->dims());

@ -20,7 +20,7 @@ namespace operators {
template <typename Place, typename T>
class MeanKernel : public OpKernel {
public:
public:
void Compute(const ExecutionContext& context) const override {
auto input = context.Input<Tensor>(0);
auto output = context.Output<Tensor>(0);
@ -37,7 +37,7 @@ public:
template <typename Place, typename T>
class MeanGradKernel : public OpKernel {
public:
public:
void Compute(const ExecutionContext& context) const override {
auto OG = context.Input<Tensor>("Out" + framework::kGradVarSuffix);
PADDLE_ENFORCE(framework::product(OG->dims()) == 1,

@ -18,7 +18,7 @@ namespace paddle {
namespace operators {
class MulOp : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {
PADDLE_ENFORCE(ctx.InputSize() == 2, "The mul op must take two inputs");
auto dim0 = ctx.Input<Tensor>(0)->dims();
@ -34,7 +34,7 @@ protected:
};
class MulOpMaker : public OpProtoAndCheckerMaker {
public:
public:
MulOpMaker(OpProto *proto, OpAttrChecker *op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("X", "The first input of mul op");
@ -49,7 +49,7 @@ The equation is: Out = X * Y
};
class MulOpGrad : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {}
std::string DebugString() const override {
LOG(INFO) << "MulGrad";

@ -21,7 +21,7 @@ namespace operators {
template <typename Place, typename T>
class MulKernel : public OpKernel {
public:
public:
void Compute(const ExecutionContext& context) const override {
Eigen::array<Eigen::IndexPair<Eigen::DenseIndex>, 1> dim_pair = {
{Eigen::IndexPair<Eigen::DenseIndex>(1, 0)}};

@ -40,7 +40,7 @@ namespace operators {
* it defines.
*/
class NetOp : public framework::OperatorBase {
public:
public:
/**
* Infer all the operators' input and output variables' shapes, will be called
* before every mini-batch
@ -90,7 +90,7 @@ public:
std::vector<std::shared_ptr<OperatorBase>> ops_;
private:
private:
bool add_op_done_{false};
template <typename T, typename KeyType>

@ -12,7 +12,7 @@ static int infer_shape_cnt = 0;
static int run_cnt = 0;
class TestOp : public OperatorBase {
public:
public:
void InferShape(const framework::Scope& scope) const override {
++infer_shape_cnt;
}
@ -23,7 +23,7 @@ public:
};
class EmptyOp : public OperatorBase {
public:
public:
void InferShape(const Scope& scope) const override {}
void Run(const Scope& scope,
const platform::DeviceContext& dev_ctx) const override {}

File diff suppressed because it is too large Load Diff

@ -69,23 +69,19 @@ struct ArgumentName {
* Prepare inputs for each step net.
*/
void SegmentInputs(const std::vector<framework::Scope*>& step_scopes,
const std::vector<Link>& inlinks,
const size_t seq_len,
const std::vector<Link>& inlinks, const size_t seq_len,
bool infer_shape_mode);
/**
* Process outputs of step nets and merge to variables.
*/
void ConcatOutputs(const std::vector<framework::Scope*>& step_scopes,
const std::vector<Link>& outlinks,
const size_t seq_len,
const std::vector<Link>& outlinks, const size_t seq_len,
bool infer_shape_mode);
void LinkMemories(const std::vector<framework::Scope*>& step_scopes,
const std::vector<MemoryAttr>& memories,
const size_t step_id,
const int offset,
bool infer_shape_mode);
const std::vector<MemoryAttr>& memories, const size_t step_id,
const int offset, bool infer_shape_mode);
void InitArgument(const ArgumentName& name, Argument* arg);
@ -100,7 +96,7 @@ void InitArgument(const ArgumentName& name, Argument* arg);
// Refer to: https://arxiv.org/pdf/1502.02367.pdf
class RecurrentAlgorithm {
public:
public:
void Run(const framework::Scope& scope,
const platform::DeviceContext& dev_ctx) const;
@ -111,7 +107,7 @@ public:
*/
void InferShape(const framework::Scope& scope) const;
protected:
protected:
/*
* The step scopes will be stored in the father scope as a variable.
*
@ -128,7 +124,7 @@ protected:
void InitMemories(framework::Scope* step_scopes, bool infer_shape_mode) const;
private:
private:
std::unique_ptr<rnn::Argument> arg_;
mutable size_t seq_len_;
};
@ -144,7 +140,7 @@ class RecurrentGradientAlgorithm {
* lot, and the latter is a wrapper acts like an dapter for it to make RNN an
* operator.
*/
public:
public:
void Init(std::unique_ptr<rnn::Argument> arg) { arg_ = std::move(arg); }
void Run(const framework::Scope& scope,
@ -158,20 +154,20 @@ public:
*/
void InferShape(const framework::Scope& scope) const;
protected:
protected:
inline const std::vector<framework::Scope*>& GetStepScopes(
const framework::Scope& scope) const {
return *scope.FindVar(arg_->step_scopes)
->GetMutable<std::vector<framework::Scope*>>();
}
private:
private:
std::unique_ptr<rnn::Argument> arg_;
mutable size_t seq_len_;
};
class RecurrentOp final : public framework::OperatorBase {
public:
public:
void Init() override;
/**
@ -188,12 +184,12 @@ public:
static const rnn::ArgumentName kArgName;
private:
private:
RecurrentAlgorithm alg_;
};
class RecurrentGradientOp final : public framework::OperatorBase {
public:
public:
void Init() override;
/**
@ -210,7 +206,7 @@ public:
static const rnn::ArgumentName kArgName;
private:
private:
RecurrentGradientAlgorithm alg_;
};

@ -29,7 +29,7 @@ using framework::make_ddim;
using framework::DDim;
class RecurrentOpTest : public ::testing::Test {
protected:
protected:
virtual void SetUp() override {
CreateGlobalVariables();
CreateStepNet();
@ -174,7 +174,7 @@ TEST_F(RecurrentOpTest, Run) {
}
class RecurrentGradientAlgorithmTest : public ::testing::Test {
protected:
protected:
virtual void SetUp() override {
CreateGlobalVariables();
CreateStepScopes();
@ -277,13 +277,11 @@ protected:
LOG(INFO) << "create variable step_net";
Variable* var = scope_.NewVar("step_net");
auto net = var->GetMutable<NetOp>();
net->AddOp(OpRegistry::CreateOp("mul",
{"rnn/h_pre", "rnn/w", "rnn/s_grad"},
{"rnn/h_pre_grad", "rnn/w_grad"},
{}));
net->AddOp(OpRegistry::CreateOp("mul", {"rnn/h_pre", "rnn/w", "rnn/s_grad"},
{"rnn/h_pre_grad", "rnn/w_grad"}, {}));
net->AddOp(OpRegistry::CreateOp(
"add_two", {"rnn/h_grad"}, {"rnn/x_grad", "rnn/s_grad"}, {}));
net->AddOp(OpRegistry::CreateOp("add_two", {"rnn/h_grad"},
{"rnn/x_grad", "rnn/s_grad"}, {}));
net->CompleteAddOp();
}
@ -297,9 +295,7 @@ protected:
inlink.internal = "rnn/x";
auto step_scopes =
scope_.FindVar("step_scopes")->GetMutable<std::vector<Scope*>>();
rnn::SegmentInputs(*step_scopes,
std::vector<rnn::Link>{inlink},
10,
rnn::SegmentInputs(*step_scopes, std::vector<rnn::Link>{inlink}, 10,
true /*infer_shape_mode*/);
}
@ -314,8 +310,8 @@ protected:
auto step_scopes =
scope_.FindVar("step_scopes")->GetMutable<std::vector<Scope*>>();
for (int i = 1; i < 10; ++i) {
rnn::LinkMemories(
*step_scopes, memories, i, -1, true /*infer_shape_mode*/);
rnn::LinkMemories(*step_scopes, memories, i, -1,
true /*infer_shape_mode*/);
}
}

@ -17,7 +17,7 @@ namespace paddle {
namespace operators {
class RowWiseAddOp : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {
PADDLE_ENFORCE(ctx.InputSize() == 2UL,
"Two inputs is needed by rowwise add");
@ -33,7 +33,7 @@ protected:
};
class RowWiseAddOpMaker : public OpProtoAndCheckerMaker {
public:
public:
RowWiseAddOpMaker(OpProto *proto, OpAttrChecker *op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("X", "The left input of row-wise add op, must be matrix");

@ -20,7 +20,7 @@ namespace operators {
template <typename Place, typename T>
class RowWiseAddKernel : public OpKernel {
public:
public:
void Compute(const ExecutionContext& context) const override {
auto out = context.Output<Tensor>(0);
out->mutable_data<T>(context.GetPlace());

@ -18,7 +18,7 @@ namespace paddle {
namespace operators {
class SGDOp : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {
PADDLE_ENFORCE(ctx.InputSize() == 2, "Input size of SGDOp must be two");
PADDLE_ENFORCE(ctx.OutputSize() == 1, "Output size of SGDOp must be one");
@ -32,7 +32,7 @@ protected:
};
class SGDOpMaker : public OpProtoAndCheckerMaker {
public:
public:
SGDOpMaker(OpProto *proto, OpAttrChecker *op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("param", "input parameter");

@ -20,7 +20,7 @@ namespace operators {
template <typename Place, typename T>
class SGDOpKernel : public OpKernel {
public:
public:
void Compute(const ExecutionContext& ctx) const override {
auto param = ctx.Input<Tensor>("param");
auto grad = ctx.Input<Tensor>("grad");

@ -17,7 +17,7 @@ namespace paddle {
namespace operators {
class SigmoidOp : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {
PADDLE_ENFORCE(ctx.InputSize() == 1, "Sigmoid Op only have one input");
PADDLE_ENFORCE(ctx.OutputSize() == 1, "Sigmoid Op only have one output");
@ -26,7 +26,7 @@ protected:
};
class SigmoidOpMaker : public OpProtoAndCheckerMaker {
public:
public:
SigmoidOpMaker(OpProto *proto, OpAttrChecker *op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("X", "sigmoid input");
@ -36,7 +36,7 @@ public:
};
class SigmoidOpGrad : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {}
std::string DebugString() const override {
LOG(INFO) << "SigmoidGrad";

@ -21,7 +21,7 @@ namespace operators {
template <typename Place, typename T>
class SigmoidKernel : public OpKernel {
public:
public:
void Compute(const ExecutionContext& context) const override {
auto input = context.Input<Tensor>(0);
auto output = context.Output<Tensor>(0);

@ -18,7 +18,7 @@ namespace paddle {
namespace operators {
class SoftmaxOp : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {
PADDLE_ENFORCE(ctx.InputSize() == 1UL,
"Only one input is need for softmax");
@ -31,7 +31,7 @@ protected:
};
class SoftmaxOpMaker : public OpProtoAndCheckerMaker {
public:
public:
SoftmaxOpMaker(OpProto *proto, OpAttrChecker *op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("X", "input of softmax");
@ -41,7 +41,7 @@ public:
};
class SoftmaxOpGrad : public OperatorWithKernel {
protected:
protected:
void InferShape(const InferShapeContext &ctx) const override {
PADDLE_ENFORCE(ctx.InputSize() == 3UL,
"Input of SoftmaxOpGrad should be 3, X, Y, YG");

@ -24,7 +24,7 @@ namespace operators {
template <typename Place, typename T>
class SoftmaxKernel : public OpKernel {
public:
public:
void Compute(const ExecutionContext& context) const override {
auto input = context.Input<Tensor>("X");
auto output = context.Output<Tensor>("Y");
@ -63,7 +63,7 @@ public:
template <typename Place, typename T>
class SoftmaxGradKernel : public OpKernel {
public:
public:
void Compute(const ExecutionContext& context) const override {
std::shared_ptr<Tensor> scale_ = std::make_shared<Tensor>();

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save