Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[MKLDNN] NDArray reorder in C API and deconv #16265

Merged
merged 5 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/c_api/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,13 @@ int MXNDArrayGetData(NDArrayHandle handle,
void **out_pdata) {
API_BEGIN();
NDArray *arr = static_cast<NDArray*>(handle);
#if MXNET_USE_MKLDNN == 1
NDArray temp = *arr;
if (arr->IsMKLDNNData()) {
temp = arr->Reorder2Default();
arr = &temp;
}
#endif
if (!arr->is_none()) {
*out_pdata = arr->data().dptr_;
} else {
Expand Down
11 changes: 7 additions & 4 deletions src/operator/nn/mkldnn/mkldnn_deconvolution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,13 @@ void MKLDNNDeconvolutionBackward(const nnvm::NodeAttrs &attrs,
Stream<cpu> *s = ctx.get_stream<cpu>();
Tensor<cpu, 1, DType> gbias =
in_grad[deconv::kBias].data().get<cpu, 1, DType>(s);
// If there is bias, the out grad has already been converted to the default
// format, so this shouldn't cause any performance issues.
Tensor<cpu, 4, DType> grad =
inputs[deconv::kOut].data().get<cpu, 4, DType>(s);

NDArray temp = inputs[deconv::kOut];
if (temp.IsMKLDNNData()) {
temp = temp.Reorder2Default();
}

Tensor<cpu, 4, DType> grad = temp.data().get<cpu, 4, DType>(s);
Assign(gbias, req[deconv::kBias],
mshadow::expr::sumall_except_dim<1>(grad));
}
Expand Down