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

[mkldnn-v1.0] Change MXNET_USE_MKLDNN from 100 back to 1 #16551

Merged
merged 1 commit into from
Oct 20, 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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ if(USE_MKLDNN)

include_directories(3rdparty/mkldnn/include)
include_directories(${PROJECT_BINARY_DIR}/3rdparty/mkldnn/include)
add_definitions(-DMXNET_USE_MKLDNN=100)
add_definitions(-DMXNET_USE_MKLDNN=1)
list(APPEND mxnet_LINKER_LIBS mkldnn)
endif()

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ ifndef LINT_LANG
endif

ifeq ($(USE_MKLDNN), 1)
CFLAGS += -DMXNET_USE_MKLDNN=100
CFLAGS += -DMXNET_USE_MKLDNN=1
CFLAGS += -I$(ROOTDIR)/src/operator/nn/mkldnn/
CFLAGS += -I$(MKLDNNROOT)/include
LDFLAGS += -L$(MKLDNNROOT)/lib -L$(MKLDNNROOT)/lib64 -lmkldnn -Wl,-rpath,'$${ORIGIN}'
Expand Down
2 changes: 1 addition & 1 deletion include/mxnet/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ inline std::ostream& operator<<(std::ostream &out, const Context &ctx) {
#define ADD_FILELINE "\n\nDefined in " __FILE__ ":L" STRINGIZE(__LINE__)


#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
constexpr size_t kMKLDNNAlign = 64;
#endif

Expand Down
14 changes: 7 additions & 7 deletions include/mxnet/ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <algorithm>
#include <memory>
#include <algorithm>
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
#include <mkldnn.hpp>
#endif
#include "./base.h"
Expand Down Expand Up @@ -699,7 +699,7 @@ class NDArray {
ptr_->CheckAndAllocAuxData(i, aux_shape);
}

#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
/*
* Create NDArray from mkldnn memory.
* mkldnn_mem The mkldnn memory to be managed.
Expand Down Expand Up @@ -825,7 +825,7 @@ class NDArray {
*/
std::vector<Storage::Handle> aux_handles;

#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
/*! This is created when data is stored in MKLDNN format.
*/
std::shared_ptr<MKLDNNMemory> mkl_mem_;
Expand Down Expand Up @@ -984,7 +984,7 @@ class NDArray {
inline void CheckAndAlloc(void) {
if (delay_alloc) {
shandle = Storage::Get()->Alloc(shandle.size, shandle.ctx);
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
mkl_mem_ = nullptr;
#endif
delay_alloc = false;
Expand All @@ -999,7 +999,7 @@ class NDArray {
dbytes = std::max(dbytes, static_cast<uint64_t>(shandle.size));
if (delay_alloc) {
shandle = Storage::Get()->Alloc(dbytes, shandle.ctx);
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
mkl_mem_ = nullptr;
#endif
delay_alloc = false;
Expand All @@ -1008,7 +1008,7 @@ class NDArray {
Storage::Get()->Free(shandle);
// init storage
shandle = Storage::Get()->Alloc(dbytes, shandle.ctx);
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
mkl_mem_ = nullptr;
#endif
}
Expand Down Expand Up @@ -1044,7 +1044,7 @@ class NDArray {
// and allocate new storage
void CheckAndAllocData(const mxnet::TShape &shape, int dtype);

#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
// Have MKL memory reference to the data in the default storage
// or create memory for MKLDNN.
void SetMKLMem(const mxnet::TShape &shape, int dtype);
Expand Down
2 changes: 1 addition & 1 deletion src/c_api/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ int MXNDArrayGetData(NDArrayHandle handle,
void **out_pdata) {
API_BEGIN();
NDArray *arr = static_cast<NDArray*>(handle);
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
if (arr->IsMKLDNNData()) {
arr->Reorder2DefaultAsync();
arr->WaitToRead();
Expand Down
8 changes: 4 additions & 4 deletions src/common/exec_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ inline bool SetupDefaultBlobsIn(const std::vector<NDArray>& src,
for (size_t i = 0; i < src.size(); i++) {
auto& nd = src[i];
bool is_default = nd.storage_type() == kDefaultStorage;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
// We have to make sure it's default storage and default layout.
is_default = nd.IsDefaultData();
#endif
if (!is_default) {
(*idx_map)[i] = temp_dst->size();
NDArray temp = bufs != nullptr ? bufs->at(i) : NDArray(nd.shape(), nd.ctx(),
true, nd.dtype());
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
CHECK(temp.IsDefaultData());
#endif
temp_src->emplace_back(nd);
Expand All @@ -91,7 +91,7 @@ inline bool SetupDefaultBlobsOut(const std::vector<NDArray>& src,
for (size_t i = 0; i < src.size(); i++) {
auto& nd = src[i];
bool is_default = nd.storage_type() == kDefaultStorage;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
if (req->at(i) == kWriteInplace && nd.IsMKLDNNData())
// If it's write inplace and the output array doesn't use the default
// layout, we'll generate a temporary output array below, which means
Expand All @@ -102,7 +102,7 @@ inline bool SetupDefaultBlobsOut(const std::vector<NDArray>& src,
is_default = nd.IsDefaultData();
#endif
if (!is_default) {
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
NDArray temp;
if (bufs != nullptr) {
temp = bufs->at(i);
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include <limits>

#include "../operator/mxnet_op.h"
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
#include "../operator/nn/mkldnn/mkldnn_base-inl.h"
#endif

Expand Down Expand Up @@ -484,7 +484,7 @@ inline void LogStorageFallback(const nnvm::NodeAttrs& attrs,
"0 to suppress this warning.";
os << "\nStorage type fallback detected:\n" << op_str << warning;
LogOnce(os.str());
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
if (!MKLDNNEnvSet()) common::LogOnce("MXNET_MKLDNN_ENABLED flag is off. "
"You can re-enable by setting MXNET_MKLDNN_ENABLED=1");
if (GetMKLDNNCacheSize() != -1) common::LogOnce("MXNET_MKLDNN_CACHE_NUM is set."
Expand Down
8 changes: 4 additions & 4 deletions src/executor/attach_op_execs_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class StatefulComputeExecutor : public StorageFallbackOpExecutor {
public:
void Run(RunContext rctx, bool is_gpu) override {
op_ctx.run_ctx = rctx;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
InvalidateOutputs(out_array, req);
#endif
PreFCompute(is_gpu);
Expand Down Expand Up @@ -155,7 +155,7 @@ class StatefulComputeExExecutor : public OpExecutor {
public:
void Run(RunContext rctx, bool is_gpu) override {
op_ctx.run_ctx = rctx;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
InvalidateOutputs(out_array, req);
// TODO(alex): (MXNET-847) Remove this fallback feature after subgraph implemented
const auto is_mkldnn = Op::GetAttr<bool>("TIsMKLDNN");
Expand Down Expand Up @@ -202,7 +202,7 @@ class FComputeExecutor : public StorageFallbackOpExecutor {
void Run(RunContext rctx, bool is_gpu) override {
using namespace common;
op_ctx.run_ctx = rctx;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
InvalidateOutputs(out_array, req);
#endif
PreFCompute(is_gpu);
Expand Down Expand Up @@ -231,7 +231,7 @@ class FComputeExExecutor : public OpExecutor {
public:
void Run(RunContext rctx, bool is_gpu) override {
op_ctx.run_ctx = rctx;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
InvalidateOutputs(out_array, req);
// TODO(alex): (MXNET-847) Remove this fallback feature after subgraph implemented
const auto is_mkldnn = Op::GetAttr<bool>("TIsMKLDNN");
Expand Down
2 changes: 1 addition & 1 deletion src/executor/graph_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace exec {
using namespace mxnet::common;

static const std::string GetDefaultSubgraphBackend() {
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
return std::string("MKLDNN");
#else
return std::string();
Expand Down
12 changes: 6 additions & 6 deletions src/imperative/imperative_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ inline void PushFCompute(const FCompute& fn,
std::vector<NDArray> pre_temp_src, pre_temp_dst, post_temp_dst, post_temp_src;
// mapping from index in input_blobs to index in pre_temp_dst
std::unordered_map<uint32_t, uint32_t> in_temp_idx_map;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
if (exec_type != ExecType::kCrossDeviceCopy) {
// kCrossDeviceCopy is used for `_copy_to` operator, which doesn't compute immediately in
// its FCcomputeEx, but AsyncPush the copy operation to engine.
Expand Down Expand Up @@ -468,7 +468,7 @@ inline void PushFComputeEx(const FComputeEx& fn,
DerefInputOutput(p_inputs, p_outputs, &inputs, &outputs);
const auto& run = [=](RunContext rctx) {
OpContext opctx{need_grad, is_train, rctx, engine::CallbackOnComplete(), requested};
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
if (exec_type != ExecType::kCrossDeviceCopy) {
// kCrossDeviceCopy is used for `_copy_to` operator, which doesn't compute immediately in
// its FCcomputeEx, but AsyncPush the copy operation to engine.
Expand All @@ -486,7 +486,7 @@ inline void PushFComputeEx(const FComputeEx& fn,
} else {
#endif
fn(attrs, opctx, inputs, req, outputs);
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
}
#endif
if (ctx.dev_mask() == gpu::kDevMask && exec_type == ExecType::kSync && !rctx.is_bulk) {
Expand Down Expand Up @@ -532,7 +532,7 @@ inline void PushOperator(const OpStatePtr& state,
const auto& run = [=](RunContext rctx,
engine::CallbackOnComplete on_complete) {
OpContext opctx{need_grad, is_train, rctx, on_complete, requested};
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
if (exec_type != ExecType::kCrossDeviceCopy) {
// kCrossDeviceCopy is used for `_copy_to` operator, which doesn't compute immediately in
// its FCcomputeEx, but AsyncPush the copy operation to engine.
Expand All @@ -550,7 +550,7 @@ inline void PushOperator(const OpStatePtr& state,
} else {
#endif
fcompute_ex(state, opctx, inputs, req, outputs);
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
}
#endif
if (ctx.dev_mask() == gpu::kDevMask && exec_type == ExecType::kSync
Expand Down Expand Up @@ -588,7 +588,7 @@ inline void PushOperator(const OpStatePtr& state,
std::vector<NDArray> pre_temp_src, pre_temp_dst, post_temp_dst, post_temp_src;
// mapping from index in input_blobs to index in pre_temp_dst
std::unordered_map<uint32_t, uint32_t> in_temp_idx_map;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
if (exec_type != ExecType::kCrossDeviceCopy) {
// kCrossDeviceCopy is used for `_copy_to` operator, which doesn't compute immediately in
// its FCcomputeEx, but AsyncPush the copy operation to engine.
Expand Down
22 changes: 11 additions & 11 deletions src/ndarray/ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void NDArray::SetShapeFromChunk() {
struct ChunkMem {
Storage::Handle h;
std::vector<Storage::Handle> aux_h;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
std::shared_ptr<MKLDNNMemory> mem;
#endif
};
Expand All @@ -113,14 +113,14 @@ NDArray::Chunk::~Chunk() {
ChunkMem mem;
mem.h = this->shandle;
mem.aux_h = this->aux_handles;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
// We want to delete mkldnn memory after deleting the variable.
mem.mem = this->mkl_mem_;
#endif
if (auto engine = engine_ref_.lock()) {
engine->DeleteVariable([mem, skip_free](RunContext s) {
if (skip_free == false) {
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
if (mem.mem) {
CHECK_LE(mem.mem->GetSize(), mem.h.size);
CHECK_EQ(mem.mem->GetDataHandle(), mem.h.dptr);
Expand All @@ -144,7 +144,7 @@ void NDArray::Chunk::CheckAndAllocData(const mxnet::TShape &shape, int dtype) {
Storage::Get()->Free(shandle);
// init storage
shandle = Storage::Get()->Alloc(dbytes, ctx);
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
mkl_mem_ = nullptr;
#endif
}
Expand Down Expand Up @@ -172,7 +172,7 @@ nnvm::Symbol NDArray::get_autograd_symbol() const {
return ret;
}

#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1

NDArray::NDArray(const mkldnn::memory::desc &md)
: storage_type_(kDefaultStorage), entry_(nullptr) {
Expand Down Expand Up @@ -387,7 +387,7 @@ void NDArray::set_fresh_out_grad(bool state) const {
info.fresh_out_grad = state;
}

#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1

bool NDArray::Chunk::IsMKLDNN() const {
if (storage_type != kDefaultStorage)
Expand Down Expand Up @@ -740,7 +740,7 @@ void NDArray::SetTBlob() const {
char *dptr = static_cast<char*>(ptr_->shandle.dptr);
auto stype = storage_type();
if (stype == kDefaultStorage) {
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
CHECK(!IsMKLDNNData()) << "We can't generate TBlob for MKLDNN data. "
<< "Please use Reorder2Default() to generate a new NDArray first";
#endif
Expand Down Expand Up @@ -1082,7 +1082,7 @@ inline void CopyFromToRspImpl(const NDArray& from, const NDArray& to, RunContext
// Make a copy of a dense NDArray
template<typename from_xpu, typename to_xpu>
inline void CopyFromToDnsImpl(const NDArray& from, const NDArray& to, RunContext ctx) {
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
// If neither is MKLDNN, we can copy data normally.
if (!from.IsMKLDNNData() && !to.IsMKLDNNData()) {
#endif
Expand All @@ -1091,7 +1091,7 @@ inline void CopyFromToDnsImpl(const NDArray& from, const NDArray& to, RunContext
TBlob tmp = to.data();
ndarray::Copy<from_xpu, to_xpu>(from.data(), &tmp,
from.ctx(), to.ctx(), ctx);
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
} else if (SupportMKLDNN(from.dtype(), from.shape())
&& SupportMKLDNN(to.dtype(), to.shape())
&& from.ctx().dev_mask() == cpu::kDevMask
Expand Down Expand Up @@ -1617,7 +1617,7 @@ void NDArray::Save(dmlc::Stream *strm) const {
} else {
this->WaitToRead();
nd_cpu = *this;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
if (nd_cpu.IsMKLDNNData()) {
nd_cpu = nd_cpu.Reorder2Default();
}
Expand Down Expand Up @@ -2007,7 +2007,7 @@ void NDArray::SyncCopyToCPU(void *data, size_t size) const {
this->WaitToRead();
RunContext rctx{this->ctx(), nullptr, nullptr, false};
NDArray src = *this;
#if MXNET_USE_MKLDNN == 100
#if MXNET_USE_MKLDNN == 1
if (src.IsMKLDNNData()) {
src = this->Reorder2Default();
}
Expand Down
Loading