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

[MKLDNN]Fix reorder2default #16602

Merged
merged 5 commits into from
Oct 24, 2019
Merged
Changes from 3 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
23 changes: 13 additions & 10 deletions src/ndarray/ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1635,11 +1635,11 @@ void NDArray::Save(dmlc::Stream *strm) const {
nd_cpu.WaitToRead();
save_data = nd_cpu.data();
} else {
this->WaitToRead();
nd_cpu = *this;
#if MXNET_USE_MKLDNN == 1
if (nd_cpu.IsMKLDNNData())
nd_cpu = nd_cpu.Reorder2Default();
// For mkldnn, a copy of *this can ensure no write access pending on *this.
nd_cpu = this->Copy(Context::CPU());
nd_cpu.WaitToRead();
#endif
save_data = nd_cpu.data();
}
Expand Down Expand Up @@ -2023,15 +2023,18 @@ void NDArray::SyncCopyToCPU(void *data, size_t size) const {
TBlob dst(data, dshape, cpu::kDevMask, this->dtype_, 0); // NOLINT(*)

if (this->ctx().dev_mask() == cpu::kDevMask) {
this->WaitToRead();
RunContext rctx{this->ctx(), nullptr, nullptr, false};
NDArray src = *this;
Engine::Get()->PushAsync(
[&](RunContext rctx, Engine::CallbackOnComplete on_complete) {
RunContext ctx{this->ctx(), nullptr, nullptr, false};
NDArray src = *this;
#if MXNET_USE_MKLDNN == 1
if (src.IsMKLDNNData())
src = this->Reorder2Default();
src = this->Reorder2Default();
#endif
ndarray::Copy<cpu, cpu>(src.data(), &dst,
Context::CPU(), Context::CPU(), rctx);
ndarray::Copy<cpu, cpu>(src.data(), &dst, Context::CPU(), Context::CPU(), ctx);
on_complete();
},
this->ctx(), {this->var()}, {}, FnProperty::kNormal, 0, "SyncCopyCPU2CPU");
this->WaitToWrite();
} else {
#if MXNET_USE_CUDA
Engine::Get()->PushAsync(
Expand Down