diff options
author | Marcin Junczys-Dowmunt <junczys@amu.edu.pl> | 2018-02-22 04:44:04 +0300 |
---|---|---|
committer | Marcin Junczys-Dowmunt <junczys@amu.edu.pl> | 2018-02-22 04:44:04 +0300 |
commit | d9d66f416b3284516f44e5b8e7b1fc7a0623e33f (patch) | |
tree | 59cd81a1b74c4ce395279b552bf7e6b724e82a4a /src/graph/node_operators_unary.h | |
parent | 6e421f7a741dca8d7181f87acd398da60bb77f7d (diff) |
prototype cpu version
Diffstat (limited to 'src/graph/node_operators_unary.h')
-rw-r--r-- | src/graph/node_operators_unary.h | 171 |
1 files changed, 86 insertions, 85 deletions
diff --git a/src/graph/node_operators_unary.h b/src/graph/node_operators_unary.h index 0170fc73..07c06fda 100644 --- a/src/graph/node_operators_unary.h +++ b/src/graph/node_operators_unary.h @@ -4,10 +4,11 @@ #include "tensors/gpu/backend.h" #include "graph/node.h" -#include "kernels/sparse.h" -#include "kernels/tensor_operators.h" +//#include "kernels/sparse.h" +#include "tensors/tensor_operators.h" #include "functional/functional.h" -#include "kernels/cudnn_wrappers.h" + +#include "tensors/gpu/cudnn_wrappers.h" namespace marian { @@ -735,12 +736,12 @@ struct SelectNodeOp : public UnaryNodeOp { NodeOps forwardOps() { return {NodeOp( - Select(graph()->allocator(), val_, child(0)->val(), axis_, indices_))}; + Select(val_, child(0)->val(), axis_, indices_, graph()->allocator()))}; } NodeOps backwardOps() { return {NodeOp( - Insert(graph()->allocator(), child(0)->grad(), adj_, axis_, indices_))}; + Insert(child(0)->grad(), adj_, axis_, indices_, graph()->allocator()))}; } Shape newShape(Expr a, int axis, const std::vector<size_t>& indeces) { @@ -985,7 +986,7 @@ struct ShiftNodeOp : public UnaryNodeOp { : UnaryNodeOp(a, keywords::shape = a->shape(), args...), shift_(shift) {} NodeOps forwardOps() { - return {NodeOp(Shift(val_, child(0)->val(), shift_))}; + return {NodeOp(Shift(val_, child(0)->val(), shift_, false))}; } NodeOps backwardOps() { @@ -1054,84 +1055,84 @@ struct ShiftNodeOp : public UnaryNodeOp { // Ptr<sparse::CSR> lf_; //}; -class PoolingOp : public UnaryNodeOp { -public: - PoolingOp(Expr x, - int height, - int width, - int padHeight, - int padWidth, - int strideHeight, - int strideWidth, - std::string mode) - : UnaryNodeOp(x), - pooling_(height, - width, - padHeight, - padWidth, - strideHeight, - strideWidth, - mode) { - } - - NodeOps forwardOps() { - return {NodeOp(pooling_.forward(child(0)->val(), val_))}; - } - - NodeOps backwardOps() { - return {NodeOp(pooling_.backward( - child(0)->val(), - child(0)->grad(), - val_, - adj_))}; - } - - const std::string type() { return "layer_pooling"; } - - -protected: - PoolingWrapper pooling_; -}; - -class PoolingWithMaskingOp : public UnaryNodeOp { - public: - PoolingWithMaskingOp( Expr x, Expr mask, int width, bool isEven=false) - : UnaryNodeOp(x), - mask_(mask), - width_(width), - isEven_(isEven) - { - auto xShape = x->shape(); - int dimBatch = xShape[0]; - int dimWord = xShape[1]; - int cols = (isEven_) ? xShape[2] - 1 : xShape[2]; - int dimSentence = (cols / width_) + (cols % width_ != 0); - shape_ = {dimBatch, dimWord, dimSentence}; - } - - NodeOps forwardOps() { - return {NodeOp(PoolingWithMaskingForward(val_, - child(0)->val(), - mask_->val(), - width_, - isEven_))}; - } - - NodeOps backwardOps() { - return {NodeOp(PoolingWithMaskingBackward(adj_, - child(0)->grad(), - child(0)->val(), - mask_->val(), - width_, - isEven_))}; - } - - const std::string type() {return "layer_pooling";} - - protected: - Expr mask_; - int width_; - bool isEven_; -}; +//class PoolingOp : public UnaryNodeOp { +//public: +// PoolingOp(Expr x, +// int height, +// int width, +// int padHeight, +// int padWidth, +// int strideHeight, +// int strideWidth, +// std::string mode) +// : UnaryNodeOp(x), +// pooling_(height, +// width, +// padHeight, +// padWidth, +// strideHeight, +// strideWidth, +// mode) { +// } +// +// NodeOps forwardOps() { +// return {NodeOp(pooling_.forward(child(0)->val(), val_))}; +// } +// +// NodeOps backwardOps() { +// return {NodeOp(pooling_.backward( +// child(0)->val(), +// child(0)->grad(), +// val_, +// adj_))}; +// } +// +// const std::string type() { return "layer_pooling"; } +// +// +//protected: +// PoolingWrapper pooling_; +//}; +// +//class PoolingWithMaskingOp : public UnaryNodeOp { +// public: +// PoolingWithMaskingOp( Expr x, Expr mask, int width, bool isEven=false) +// : UnaryNodeOp(x), +// mask_(mask), +// width_(width), +// isEven_(isEven) +// { +// auto xShape = x->shape(); +// int dimBatch = xShape[0]; +// int dimWord = xShape[1]; +// int cols = (isEven_) ? xShape[2] - 1 : xShape[2]; +// int dimSentence = (cols / width_) + (cols % width_ != 0); +// shape_ = {dimBatch, dimWord, dimSentence}; +// } +// +// NodeOps forwardOps() { +// return {NodeOp(PoolingWithMaskingForward(val_, +// child(0)->val(), +// mask_->val(), +// width_, +// isEven_))}; +// } +// +// NodeOps backwardOps() { +// return {NodeOp(PoolingWithMaskingBackward(adj_, +// child(0)->grad(), +// child(0)->val(), +// mask_->val(), +// width_, +// isEven_))}; +// } +// +// const std::string type() {return "layer_pooling";} +// +// protected: +// Expr mask_; +// int width_; +// bool isEven_; +//}; } |