From 702d620d601aafe1ce02f1dd05513049f13a84cb Mon Sep 17 00:00:00 2001 From: "B. Gawrych" Date: Thu, 15 Jul 2021 09:18:51 +0200 Subject: [PATCH 1/3] Add flag for disabling oneDNN BRGEMM implementation of FC --- src/operator/nn/mkldnn/mkldnn_base-inl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/operator/nn/mkldnn/mkldnn_base-inl.h b/src/operator/nn/mkldnn/mkldnn_base-inl.h index cb30b0b62857..f1ec16edfbf0 100644 --- a/src/operator/nn/mkldnn/mkldnn_base-inl.h +++ b/src/operator/nn/mkldnn/mkldnn_base-inl.h @@ -312,7 +312,8 @@ inline static mkldnn::memory::desc GetFCWeightDesc(const NDArray &arr, int dtype for (size_t i = 0; i < dims.size(); i++) dims[i] = arr.shape()[i]; auto format = mkldnn::memory::format_tag::any; // for batch 256 alexnet benchmark test - if (dims.size() == 2) { + const bool brgemm_disabled = dmlc::GetEnv("MXNET_DISABLE_ONEDNN_BRGEMM_FC", true); + if (dims.size() == 2 && brgemm_disabled) { format = mkldnn::memory::format_tag::ab; } From 1f26964f7fa23d6ffa6f8795211ab4db44c0bad5 Mon Sep 17 00:00:00 2001 From: "B. Gawrych" Date: Thu, 15 Jul 2021 14:04:40 +0200 Subject: [PATCH 2/3] Review fixes --- docs/static_site/src/pages/api/faq/env_var.md | 4 ++++ src/operator/nn/mkldnn/mkldnn_base-inl.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/static_site/src/pages/api/faq/env_var.md b/docs/static_site/src/pages/api/faq/env_var.md index 831f7ee3e043..11219749a890 100644 --- a/docs/static_site/src/pages/api/faq/env_var.md +++ b/docs/static_site/src/pages/api/faq/env_var.md @@ -298,6 +298,10 @@ If ctypes is used, it must be `mxnet._ctypes.ndarray.NDArrayBase`. - Values: Int ```(default=-1)``` - Flag to set num of elements that MKLDNN cache can hold. Default is -1 which means cache size is unbounded. Should only be set if your model has variable input shapes, as cache size may grow unbounded. The number represents the number of items in the cache and is proportional to the number of layers that use MKLDNN and different input shape. +* MXNET_MKLDNN_DISABLE_BRGEMM_FC + - Values: Int ```(default=-1)``` + - Flag which enables BRGEMM kernels in FullyConnected executed with MKLDNN support - Should only be set if your model has constant input shapes or FullyConnected is calculated with large tensors. Supported on machines with AVX512-VNNI. + * MXNET_ENFORCE_DETERMINISM - Values: 0(false) or 1(true) ```(default=0)``` - If set to true, MXNet will only use deterministic algorithms in forward and backward computation. diff --git a/src/operator/nn/mkldnn/mkldnn_base-inl.h b/src/operator/nn/mkldnn/mkldnn_base-inl.h index f1ec16edfbf0..b8f6f1a7bc95 100644 --- a/src/operator/nn/mkldnn/mkldnn_base-inl.h +++ b/src/operator/nn/mkldnn/mkldnn_base-inl.h @@ -312,7 +312,7 @@ inline static mkldnn::memory::desc GetFCWeightDesc(const NDArray &arr, int dtype for (size_t i = 0; i < dims.size(); i++) dims[i] = arr.shape()[i]; auto format = mkldnn::memory::format_tag::any; // for batch 256 alexnet benchmark test - const bool brgemm_disabled = dmlc::GetEnv("MXNET_DISABLE_ONEDNN_BRGEMM_FC", true); + const bool brgemm_disabled = dmlc::GetEnv("MXNET_MKLDNN_DISABLE_BRGEMM_FC", true); if (dims.size() == 2 && brgemm_disabled) { format = mkldnn::memory::format_tag::ab; } From f24049a302f6db578b2d8e49261dbba5171c1691 Mon Sep 17 00:00:00 2001 From: bgawrych Date: Fri, 16 Jul 2021 14:39:03 +0200 Subject: [PATCH 3/3] Update env_var.md --- docs/static_site/src/pages/api/faq/env_var.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/static_site/src/pages/api/faq/env_var.md b/docs/static_site/src/pages/api/faq/env_var.md index 11219749a890..6336b3da955d 100644 --- a/docs/static_site/src/pages/api/faq/env_var.md +++ b/docs/static_site/src/pages/api/faq/env_var.md @@ -299,8 +299,8 @@ If ctypes is used, it must be `mxnet._ctypes.ndarray.NDArrayBase`. - Flag to set num of elements that MKLDNN cache can hold. Default is -1 which means cache size is unbounded. Should only be set if your model has variable input shapes, as cache size may grow unbounded. The number represents the number of items in the cache and is proportional to the number of layers that use MKLDNN and different input shape. * MXNET_MKLDNN_DISABLE_BRGEMM_FC - - Values: Int ```(default=-1)``` - - Flag which enables BRGEMM kernels in FullyConnected executed with MKLDNN support - Should only be set if your model has constant input shapes or FullyConnected is calculated with large tensors. Supported on machines with AVX512-VNNI. + - Values: 0, 1 ```(default=1)``` + - Flag which disables BRGEMM kernels in FullyConnected executed with MKLDNN support - Should only be set to 0 if your model has constant input shapes or FullyConnected is calculated with large tensors. Supported on machines with AVX512-VNNI. * MXNET_ENFORCE_DETERMINISM - Values: 0(false) or 1(true) ```(default=0)```