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

[mkldnn-1.0]Fix reorder2default #16608

Closed
Closed
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
22 changes: 15 additions & 7 deletions src/ndarray/ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1615,12 +1615,13 @@ void NDArray::Save(dmlc::Stream *strm) const {
nd_cpu.WaitToRead();
save_data = nd_cpu.data();
} else {
#if MXNET_USE_MKLDNN == 1
// For mkldnn, a copy of *this can ensure no write access pending on *this.
nd_cpu = this->Copy(Context::CPU());
nd_cpu.WaitToRead();
#else
this->WaitToRead();
nd_cpu = *this;
#if MXNET_USE_MKLDNN == 1
if (nd_cpu.IsMKLDNNData()) {
nd_cpu = nd_cpu.Reorder2Default();
}
#endif
save_data = nd_cpu.data();
}
Expand Down Expand Up @@ -1869,10 +1870,17 @@ void NDArray::SyncCopyFromCPU(const void *data, size_t size) const {
TBlob src((void*)data, dshape, cpu::kDevMask, this->dtype_, 0); // NOLINT(*)

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