提交 df8ad667 编写于 作者: W wangliu

modify code style

上级 5a152298
...@@ -21,22 +21,22 @@ SOFTWARE. ...@@ -21,22 +21,22 @@ SOFTWARE.
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
template <typename Dtype>
OperatorBase<Dtype>::OperatorBase(const std::string &type,
const VariableNameMap &inputs,
const VariableNameMap &outputs,
const AttributeMap &attrs,
std::shared_ptr<Scope> scope)
: type_(type), inputs_(inputs), outputs_(outputs), attrs_(attrs),
scope_(scope) {
CheckAllInputOutputSet();
}
template <typename Dtype>
void OperatorBase<Dtype>::CheckAllInputOutputSet() const {}
template class OperatorBase<CPU>; template <typename Dtype>
template class OperatorWithKernel<CPU>; OperatorBase<Dtype>::OperatorBase(const std::string &type,
const VariableNameMap &inputs,
const VariableNameMap &outputs,
const AttributeMap &attrs,
std::shared_ptr<Scope> scope)
: type_(type), inputs_(inputs), outputs_(outputs), attrs_(attrs),
scope_(scope) {
CheckAllInputOutputSet();
}
template <typename Dtype>
void OperatorBase<Dtype>::CheckAllInputOutputSet() const {}
template class OperatorBase<CPU>;
template class OperatorWithKernel<CPU>;
} // namespace framework } // namespace framework
} // namespace paddle_mobile } // namespace paddle_mobile
...@@ -22,32 +22,33 @@ SOFTWARE. ...@@ -22,32 +22,33 @@ SOFTWARE.
#include "operators/kernel/pool_kernel.h" #include "operators/kernel/pool_kernel.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace operators { namespace operators {
using namespace framework; using namespace framework;
template <typename DeviceType, typename T> template <typename DeviceType, typename T>
class ConvOp : public framework::OperatorWithKernel<DeviceType> { class ConvOp : public framework::OperatorWithKernel<DeviceType> {
public: public:
ConvOp(const std::string &type, const VariableNameMap &inputs, ConvOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs,
std::shared_ptr<framework::Scope> scope) const framework::AttributeMap &attrs,
: framework::OperatorWithKernel<DeviceType>(type, inputs, outputs, attrs, std::shared_ptr<framework::Scope> scope)
scope), : framework::OperatorWithKernel<DeviceType>(
param_(inputs, outputs, attrs, *scope) {} type, inputs, outputs, attrs, scope),
param_(inputs, outputs, attrs, *scope) {}
using framework::OperatorWithKernel<DeviceType>::OperatorWithKernel;
void InferShape() const override; using framework::OperatorWithKernel<DeviceType>::OperatorWithKernel;
void InferShape() const override;
void Run() const {
operators::ConvKernel<DeviceType, T, ConvParam> kernel; void Run() const {
kernel.Compute(param_); operators::ConvKernel<DeviceType, T, ConvParam> kernel;
this->ClearVariables(); kernel.Compute(param_);
} this->ClearVariables();
}
private:
ConvParam param_; private:
}; ConvParam param_;
};
} // operators
} // operators
} // paddle_mobile } // paddle_mobile
...@@ -26,69 +26,71 @@ SOFTWARE. ...@@ -26,69 +26,71 @@ SOFTWARE.
#include <typeinfo> #include <typeinfo>
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
class Variable : public PaddleMobileObject { class Variable : public PaddleMobileObject {
public: public:
template <typename T> const T *Get() const { template <typename T> const T *Get() const {
return static_cast<const T *>(holder_->Ptr()); return static_cast<const T *>(holder_->Ptr());
} }
bool IsInitialized() const { return holder_ != nullptr; } bool IsInitialized() const { return holder_ != nullptr; }
const std::string *Name() { return name_; } const std::string *Name() { return name_; }
template <typename T> T *GetMutable() { template <typename T> T *GetMutable() {
if (!IsType<T>()) { if (!IsType<T>()) {
if (*Name() == "pixel") { if (*Name() == "pixel") {
// std::cout << " reset " << *Name() << std::endl; // std::cout << " reset " << *Name() <<
} // std::endl;
holder_.reset(new PlaceholderImp<T>(new T())); }
} holder_.reset(new PlaceholderImp<T>(new T()));
return static_cast<T *>(holder_->Ptr()); }
} return static_cast<T *>(holder_->Ptr());
}
template <typename T> bool IsType() const {
if (holder_) { template <typename T> bool IsType() const {
// printf("not null \n"); if (holder_) {
printf(" holder type : %s, this type %s \n", holder_->Type().name(), // printf("not null \n");
typeid(T).name()); printf(" holder type : %s, this type %s \n",
} holder_->Type().name(), typeid(T).name());
}
// std::cout << " " << holder_->Type() << " " << typeid(T) <<
// std::endl; // std::cout << " " << holder_->Type() << " " <<
return holder_ != nullptr && holder_->Type() == typeid(T); // typeid(T) <<
} // std::endl;
return holder_ != nullptr && holder_->Type() == typeid(T);
void Clear() { holder_.reset(); } }
std::type_index Type() const { return holder_->Type(); } void Clear() { holder_.reset(); }
void SetName(const std::string *name) { name_ = name; } std::type_index Type() const { return holder_->Type(); }
private: void SetName(const std::string *name) { name_ = name; }
struct Placeholder {
Placeholder() = default; private:
virtual ~Placeholder() = default; struct Placeholder {
Placeholder() = default;
virtual const std::type_info &Type() const = 0; virtual ~Placeholder() = default;
virtual void *Ptr() const = 0;
}; virtual const std::type_info &Type() const = 0;
virtual void *Ptr() const = 0;
template <typename T> struct PlaceholderImp : public Placeholder { };
explicit PlaceholderImp(T *ptr) : ptr_(ptr), type_(typeid(T)) {}
template <typename T> struct PlaceholderImp : public Placeholder {
virtual const std::type_info &Type() const { return type_; } explicit PlaceholderImp(T *ptr) : ptr_(ptr), type_(typeid(T)) {}
virtual void *Ptr() const override {
return static_cast<void *>(ptr_.get()); virtual const std::type_info &Type() const { return type_; }
} virtual void *Ptr() const override {
return static_cast<void *>(ptr_.get());
std::unique_ptr<T> ptr_; }
const std::type_info &type_;
}; std::unique_ptr<T> ptr_;
const std::type_info &type_;
std::unique_ptr<Placeholder> holder_; };
friend class Scope;
const std::string *name_; std::unique_ptr<Placeholder> holder_;
}; friend class Scope;
} // namespace framework const std::string *name_;
};
} // namespace framework
} // namespace paddle_mobile } // namespace paddle_mobile
...@@ -22,32 +22,33 @@ SOFTWARE. ...@@ -22,32 +22,33 @@ SOFTWARE.
#include "operators/kernel/conv_kernel.h" #include "operators/kernel/conv_kernel.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace operators { namespace operators {
using namespace framework; using namespace framework;
template <typename DeviceType, typename T> template <typename DeviceType, typename T>
class ConvOp : public framework::OperatorWithKernel<DeviceType> { class ConvOp : public framework::OperatorWithKernel<DeviceType> {
public: public:
ConvOp(const std::string &type, const VariableNameMap &inputs, ConvOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs,
std::shared_ptr<framework::Scope> scope) const framework::AttributeMap &attrs,
: framework::OperatorWithKernel<DeviceType>(type, inputs, outputs, attrs, std::shared_ptr<framework::Scope> scope)
scope), : framework::OperatorWithKernel<DeviceType>(
param_(inputs, outputs, attrs, *scope) {} type, inputs, outputs, attrs, scope),
param_(inputs, outputs, attrs, *scope) {}
using framework::OperatorWithKernel<DeviceType>::OperatorWithKernel;
void InferShape() const override; using framework::OperatorWithKernel<DeviceType>::OperatorWithKernel;
void InferShape() const override;
void Run() const {
operators::ConvKernel<DeviceType, T, ConvParam> kernel; void Run() const {
kernel.Compute(param_); operators::ConvKernel<DeviceType, T, ConvParam> kernel;
this->ClearVariables(); kernel.Compute(param_);
} this->ClearVariables();
}
private:
ConvParam param_; private:
}; ConvParam param_;
};
} // operators
} // operators
} // paddle_mobile } // paddle_mobile
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册