提交 c602e046 编写于 作者: S Superjom

add fake interfaces to make compilable

上级 90f55b1b
...@@ -5,7 +5,7 @@ namespace framework { ...@@ -5,7 +5,7 @@ namespace framework {
PlainNet::PlainNet(const NetDesc& def) {} PlainNet::PlainNet(const NetDesc& def) {}
virtual Error PlainNet::InferShape() { Error PlainNet::InferShape(Scope* scope) {
for (auto& op : ops_) { for (auto& op : ops_) {
// wrong shape // wrong shape
auto err = op.InferShape(); auto err = op.InferShape();
...@@ -15,9 +15,11 @@ virtual Error PlainNet::InferShape() { ...@@ -15,9 +15,11 @@ virtual Error PlainNet::InferShape() {
return Error(); return Error();
} }
virtual Error PlainNet::Run(Scope* scope = nullptr, Error PlainNet::Run(Scope* scope, OpContext* context, OpIndex begin,
OpContext* context = nullptr, OpIndex begin = -1, OpIndex end) const {
OpIndex end = -1) const {} // TODO Add implementation here.
return Error();
}
} // namespace framework } // namespace framework
} // namespace paddle } // namespace paddle
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "paddle/framework/net_proto.pb.h" #include "paddle/framework/net_proto.pb.h"
#include "paddle/framework/op_proto.pb.h" #include "paddle/framework/op_proto.pb.h"
#include "paddle/framework/scope.h" #include "paddle/framework/scope.h"
#include "paddle/utils/Error.h"
namespace paddle { namespace paddle {
namespace framework { namespace framework {
...@@ -29,11 +30,16 @@ typedef int OpIndex; ...@@ -29,11 +30,16 @@ typedef int OpIndex;
* keep updating if the concepts related are implemented. * keep updating if the concepts related are implemented.
*/ */
struct OpDesc;
struct OpDef;
struct OpContext;
struct OpAttrs {};
class Operator { class Operator {
public: public:
Operator(const OpDesc &def) {} Operator(const OpDesc &def) {}
bool InferShape() {} Error InferShape() { return Error(); }
bool Run() {} Error Run() { return Error(); }
}; };
/** /**
...@@ -55,7 +61,7 @@ class Net { ...@@ -55,7 +61,7 @@ class Net {
/** /**
* @brief Infer shapes of all inputs and outputs of operators. * @brief Infer shapes of all inputs and outputs of operators.
*/ */
virtual bool InferShape(Scope *scope) override; virtual Error InferShape(Scope *scope) = 0;
/** /**
* @brief Run the network. * @brief Run the network.
* *
...@@ -64,28 +70,30 @@ class Net { ...@@ -64,28 +70,30 @@ class Net {
* environment for ops. `begin` and `end` specify the scope of `ops_` to run, * environment for ops. `begin` and `end` specify the scope of `ops_` to run,
* If no positive indexes are provided, all operators in `ops_` will run. * If no positive indexes are provided, all operators in `ops_` will run.
*/ */
virtual bool Run(Scope *scope, OpContext *context, OpIndex begin = -1, virtual Error Run(Scope *scope, OpContext *context, OpIndex begin = -1,
OpIndex end = -1) const = 0; OpIndex end = -1) const = 0;
/** /**
* @brief Add an Operator according to `def`. * @brief Add an Operator according to `def`.
*/ */
virtual OpIndex AddOp(const proto::OpDef &def) = 0; virtual OpIndex AddOp(const OpDef &def) = 0;
/** /**
* @brief Add optimizer operators acctording to `attrs`. * @brief Add optimizer operators acctording to `attrs`.
*/ */
virtual bool AddOptimizerOps(const OptAttrs &attrs) = 0; virtual Error AddOptimizerOps(const OpAttrs &attrs) = 0;
/** /**
* @brief Add backward operators. * @brief Add backward operators.
*/ */
virtual bool AddBackwardOps() = 0; virtual Error AddBackwardOps() = 0;
/** /**
* @brief Create a network. * @brief Create a network.
*/ */
static std::unique_ptr<Net> Create(const NetDesc &def = NetDesc()); static std::unique_ptr<Net> Create(const NetDesc &def = NetDesc());
virtual ~Net() = 0;
}; };
/** /**
...@@ -108,7 +116,7 @@ class PlainNet : public Net { ...@@ -108,7 +116,7 @@ class PlainNet : public Net {
* Infer all the operators' input and output varialbes' shapes, will be called * Infer all the operators' input and output varialbes' shapes, will be called
* before every mini-batch * before every mini-batch
*/ */
virtual bool InferShape(Scope *scope) override; virtual Error InferShape(Scope *scope) override;
/** /**
* @brief Run the network. * @brief Run the network.
...@@ -117,23 +125,23 @@ class PlainNet : public Net { ...@@ -117,23 +125,23 @@ class PlainNet : public Net {
* scope will be used instead. If no OpContext is provicded, default context * scope will be used instead. If no OpContext is provicded, default context
* will be used. * will be used.
*/ */
virtual bool Run(Scope *scope = nullptr, OpContext *context = nullptr, virtual Error Run(Scope *scope = nullptr, OpContext *context = nullptr,
OpIndex begin = -1, OpIndex end = -1) const override; OpIndex begin = -1, OpIndex end = -1) const override;
/** /**
* @brief Add an operator to this network. * @brief Add an operator to this network.
*/ */
virtual OpIndex AddOp(const proto::OpDef &def) override; virtual OpIndex AddOp(const OpDef &def) override;
/** /**
* @brief Add all optimizer operators related into the network. * @brief Add all optimizer operators related into the network.
*/ */
virtual bool AddOptimizerOps(const OptAttrs &attrs) override; virtual Error AddOptimizerOps(const OpAttrs &attrs) override;
/** /**
* @brief Add all backward operators related into the network. * @brief Add all backward operators related into the network.
*/ */
virtual bool AddBackwardOps() override; virtual Error AddBackwardOps() override;
protected: protected:
/** /**
...@@ -141,7 +149,7 @@ class PlainNet : public Net { ...@@ -141,7 +149,7 @@ class PlainNet : public Net {
* *
* Create operators accordding to `def`, will be called by the constructor. * Create operators accordding to `def`, will be called by the constructor.
*/ */
bool BuildNet(const NetDesc &def); Error BuildNet(const NetDesc &def);
/** /**
* @brief Add an operator into this network. * @brief Add an operator into this network.
...@@ -151,9 +159,9 @@ class PlainNet : public Net { ...@@ -151,9 +159,9 @@ class PlainNet : public Net {
* `outputs` are keys of mutable output variables. An `OpIndex` will be * `outputs` are keys of mutable output variables. An `OpIndex` will be
* returned to indicate the offset of the new operator in `ops_`. * returned to indicate the offset of the new operator in `ops_`.
*/ */
OpIndex AddOp(const std::string &type, const std::vector<string> &inputs, OpIndex AddOp(const std::string &type, const std::vector<std::string> &inputs,
const std::vector<string> &outputs, const std::vector<std::string> &outputs,
const OprAttr &attrs = OprAttr()); const OpAttrs &attrs = OpAttrs());
private: private:
// the operators owned by `Network`. // the operators owned by `Network`.
......
syntax="proto2"; syntax="proto2";
package paddle.framework; package paddle.framework;
import "op_proto.proto" import "op_proto.proto";
message NetDesc { message NetDesc {
// network identification // network identification
...@@ -13,4 +13,3 @@ message NetDesc { ...@@ -13,4 +13,3 @@ message NetDesc {
// num worker always // num worker always
optional int32 num_workers = 4; optional int32 num_workers = 4;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册