You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by jx...@apache.org on 2017/10/03 18:00:48 UTC

[incubator-mxnet] branch master updated: Issue 7264: MKL supports 2D/3D/4D input tensor only for concatenation (#7868)

This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new cac948b  Issue 7264:  MKL supports 2D/3D/4D input tensor only for concatenation (#7868)
cac948b is described below

commit cac948be9a9aaed3a87a2efb527dd58568a6d204
Author: adstraw <26...@users.noreply.github.com>
AuthorDate: Tue Oct 3 11:00:38 2017 -0700

    Issue 7264:  MKL supports 2D/3D/4D input tensor only for concatenation (#7868)
    
    * Issue 7264:  MKL supports 4D input tensor only for concatenation
    
    * Fix cpplint issue
    
    * Fix GPU build error
    
    * Minor change to comments
    
    * Check in_shape[0] only as all inputs are required to have same dim
    
    * Fix build and logic error with dimension calculation
---
 src/operator/concat-inl.h |  2 +-
 src/operator/concat.cc    | 11 ++++++++---
 src/operator/concat.cu    |  2 +-
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/operator/concat-inl.h b/src/operator/concat-inl.h
index ed553c8..8c342c8 100644
--- a/src/operator/concat-inl.h
+++ b/src/operator/concat-inl.h
@@ -129,7 +129,7 @@ class ConcatOp : public Operator {
 };  // class ConcatOp
 
 template<typename xpu>
-Operator *CreateOp(ConcatParam param, int dtype);
+Operator *CreateOp(ConcatParam param, int dtype, std::vector<TShape> *in_shape);
 
 #if DMLC_USE_CXX11
 class ConcatProp : public OperatorProperty {
diff --git a/src/operator/concat.cc b/src/operator/concat.cc
index 1bee4b4..03a8b80 100644
--- a/src/operator/concat.cc
+++ b/src/operator/concat.cc
@@ -33,10 +33,15 @@
 namespace mxnet {
 namespace op {
 template<>
-Operator* CreateOp<cpu>(ConcatParam param, int dtype) {
+Operator* CreateOp<cpu>(ConcatParam param, int dtype, std::vector<TShape> *in_shape) {
   Operator *op = NULL;
 #if MXNET_USE_MKL2017 == 1
-  if ((1 == param.dim) &&
+  // MKL supports 4D input tensors only for concat operation
+  // 2D/3D input tensors are reshaped to 4D in mkl_concat-inl.h
+  // hence MKL supports 2D/3D/4D input tensors for concat operation
+  size_t dims = (*in_shape)[0].ndim();
+  bool supportedDim = (dims >= 2 && dims <= 4);
+  if ((1 == param.dim) && supportedDim &&
     (param.num_args < (dnnResourceMultipleDst - dnnResourceMultipleSrc))) {
     switch (dtype) {
       case mshadow::kFloat32:
@@ -58,7 +63,7 @@ Operator* CreateOp<cpu>(ConcatParam param, int dtype) {
 
 Operator* ConcatProp::CreateOperatorEx(Context ctx, std::vector<TShape> *in_shape,
                                        std::vector<int> *in_type) const {
-  DO_BIND_DISPATCH(CreateOp, param_, in_type->at(0));
+  DO_BIND_DISPATCH(CreateOp, param_, in_type->at(0), in_shape);
 }
 
 DMLC_REGISTER_PARAMETER(ConcatParam);
diff --git a/src/operator/concat.cu b/src/operator/concat.cu
index 06828fc..9aea42e 100644
--- a/src/operator/concat.cu
+++ b/src/operator/concat.cu
@@ -28,7 +28,7 @@
 namespace mxnet {
 namespace op {
 template<>
-Operator* CreateOp<gpu>(ConcatParam param, int dtype) {
+Operator* CreateOp<gpu>(ConcatParam param, int dtype, std::vector<TShape> *in_shape) {
   Operator *op = NULL;
   MSHADOW_TYPE_SWITCH(dtype, DType, {
     op = new ConcatOp<gpu, DType>(param);

-- 
To stop receiving notification emails like this one, please contact
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].