From 9ff7f0b208d8fe0c7c852c8523ba76685b2d5a95 Mon Sep 17 00:00:00 2001 From: Da Zheng Date: Mon, 7 May 2018 22:41:14 +0000 Subject: [PATCH] Fix a bug in mkldnn copy. --- src/operator/nn/mkldnn/mkldnn_copy.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/operator/nn/mkldnn/mkldnn_copy.cc b/src/operator/nn/mkldnn/mkldnn_copy.cc index 4bfb7faad968..75e51aff0066 100644 --- a/src/operator/nn/mkldnn/mkldnn_copy.cc +++ b/src/operator/nn/mkldnn/mkldnn_copy.cc @@ -35,7 +35,13 @@ void MKLDNNCopy(const nnvm::NodeAttrs& attrs, const OpContext &ctx, const NDArray &in_data, const OpReqType &req, const NDArray &out_data) { TmpMemMgr::Get()->Init(ctx.requested[0]); - auto in_mem = in_data.GetMKLDNNData(); + + // If the input data is a view of an MKLDNN array, we should create a new + // NDArray with reordered data. + NDArray data = in_data; + if (data.IsMKLDNNData() && data.IsView()) + data = data.Reorder2Default(); + auto in_mem = data.GetMKLDNNData(); if (req == kAddTo) { TmpMemMgr::Get()->Init(ctx.requested[0]); // We should try and force the output memory has the same format