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

Commit 29f2e32

Browse files
xziyapengzhao-intel
authored andcommitted
Add some annotations and log strings, rename mem_desc variables (#16609)
1 parent 2210b21 commit 29f2e32

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/ndarray/ndarray.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -532,16 +532,15 @@ const mkldnn::memory *NDArray::GetMKLDNNDataReorder(
532532
return GetMKLDNNExact(mem, new_desc);
533533
}
534534

535-
mkldnn::memory::desc desc1 = mem->get_desc();
536-
mkldnn::memory::desc desc2 = new_desc;
535+
mkldnn::memory::desc old_desc = mem->get_desc();
537536
// Now we need to determine if we should reorder the memory.
538537
// If both use the default formats, we think we don't need to reorder.
539-
if ((!mxnet::IsMKLDNN(desc1)) && (!mxnet::IsMKLDNN(desc2))) {
538+
if ((!mxnet::IsMKLDNN(old_desc)) && (!mxnet::IsMKLDNN(new_desc))) {
540539
mkldnn_mem_ptr ret(new mkldnn::memory(new_desc,
541540
CpuEngine::Get()->get_engine(), mem->get_data_handle()));
542541
stream->RegisterMem(ret);
543542
return ret.get();
544-
} else if (same_shape(desc1, desc2)) {
543+
} else if (same_shape(old_desc, new_desc)) {
545544
// If they have the same shape, we can reorder data directly.
546545
mkldnn::memory *ret = TmpMemMgr::Get()->Alloc(new_desc);
547546
std::unordered_map<int, mkldnn::memory> args({{MKLDNN_ARG_FROM, *mem }, {MKLDNN_ARG_TO, *ret}});
@@ -551,9 +550,9 @@ const mkldnn::memory *NDArray::GetMKLDNNDataReorder(
551550
// If they have different shapes, we need to reshape the array first.
552551
// Since this method will only be used inside an operator, we can call
553552
// MKLDNNDataReshape to reshape an array.
554-
mxnet::TShape required_shape(desc2.data.ndims, -1);
555-
for (int i = 0; i < desc2.data.ndims; i++)
556-
required_shape[i] = desc2.data.dims[i];
553+
mxnet::TShape required_shape(new_desc.data.ndims, -1);
554+
for (int i = 0; i < new_desc.data.ndims; i++)
555+
required_shape[i] = new_desc.data.dims[i];
557556
NDArray reshaped = MKLDNNDataReshape(required_shape);
558557
const mkldnn::memory *ret = reshaped.GetMKLDNNData();
559558
if (ret->get_desc() == new_desc) {
@@ -684,7 +683,9 @@ void NDArray::CopyFrom(const mkldnn::memory &mem) {
684683

685684
mkldnn::memory *NDArray::CreateMKLDNNData(const mkldnn::memory::desc &desc) {
686685
if (desc.get_size() != shape().Size() * GetTypeSize(dtype_)) {
687-
LOG(FATAL) << "The size of NDArray doesn't match the requested MKLDNN memory desc ";
686+
LOG(FATAL) << "The size of NDArray doesn't match the requested MKLDNN memory desc. "
687+
<< "MKLDNN memory requests for " << desc.get_size() << " bytes, but got "
688+
<< shape().Size() * GetTypeSize(dtype_) << " bytes from NDArray";
688689
return nullptr;
689690
}
690691
bool isDefaultFormat = IsDefaultFormat(desc);

src/operator/nn/mkldnn/mkldnn_base.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ mkldnn::memory *TmpMemMgr::Alloc(const mkldnn::memory::desc &md) {
6868
this->curr_mem = static_cast<char *>(mem) + md.get_size();
6969
return ret.get();
7070
} else {
71-
// If curr_mem has been initialized and we still reach here. It means
72-
// the current allocated memory isn't enough.
71+
// If curr_mem has been initialized and we still reach here, it means the current
72+
// allocated memory isn't enough. But it doesn't matter for multiple invokes of a
73+
// operator, as the TmpMemMgr could estimate the space at the first iteration and
74+
// then re-requests abundant space from MXNet resource. MKL-DNN could allocate
75+
// the space by itself. Thus, we just let it continue for estimating the maximum
76+
// required space size. It will be allocated at next call.
7377
if (this->curr_mem && dmlc::GetEnv("MXNET_MKLDNN_DEBUG", false)) {
74-
LOG(WARNING) << "Allocate " << md.get_size()
75-
<< " bytes with malloc directly";
78+
LOG(WARNING) << "mkl-dnn debug message: The rest of the temporary space is not "
79+
<< "adequate for allocating " << md.get_size() << " bytes. Thus, mkl-dnn "
80+
<< "allocate the space by itself.";
7681
}
7782
mkldnn_mem_ptr ret(new mkldnn::memory(md, CpuEngine::Get()->get_engine()));
7883
MKLDNNStream::Get()->RegisterMem(ret);

0 commit comments

Comments
 (0)