From 43919d0a9eb3abecb1621dc9470ab5dbebd0eb4a Mon Sep 17 00:00:00 2001 From: Jacek Czaja Date: Mon, 24 Jan 2022 11:15:31 +0100 Subject: [PATCH] Remved redundant defintions of likely/unlikely (#38911) * - more unlikely * - compilation fix * - removed redundant definition * - fix * - Fixes * - compilation fix for windows --- paddle/fluid/framework/expect.h | 12 ++++++++---- .../operators/fused/mkldnn/fusion_gru_mkldnn_op.cc | 3 ++- .../operators/fused/mkldnn/fusion_lstm_mkldnn_op.cc | 3 ++- paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc | 5 +++-- paddle/fluid/operators/mkldnn/prelu_mkldnn_op.cc | 3 ++- paddle/fluid/platform/device_context.cc | 10 +--------- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/paddle/fluid/framework/expect.h b/paddle/fluid/framework/expect.h index 146f4de9382..686a14fca15 100644 --- a/paddle/fluid/framework/expect.h +++ b/paddle/fluid/framework/expect.h @@ -19,14 +19,18 @@ #define _LINUX #endif -#ifdef _LINUX #ifndef likely -#define likely(x) __builtin_expect((x), 1) +#ifdef _LINUX +#define likely(expr) (__builtin_expect(!!(expr), 1)) +#else +#define likely(expr) (expr) #endif #endif -#ifdef _LINUX #ifndef unlikely -#define unlikely(x) __builtin_expect((x), 0) +#ifdef _LINUX +#define unlikely(expr) (__builtin_expect(!!(expr), 0)) +#else +#define unlikely(expr) (expr) #endif #endif diff --git a/paddle/fluid/operators/fused/mkldnn/fusion_gru_mkldnn_op.cc b/paddle/fluid/operators/fused/mkldnn/fusion_gru_mkldnn_op.cc index 6ef49e2cf3d..f1deab3e652 100644 --- a/paddle/fluid/operators/fused/mkldnn/fusion_gru_mkldnn_op.cc +++ b/paddle/fluid/operators/fused/mkldnn/fusion_gru_mkldnn_op.cc @@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +#include "paddle/fluid/framework/expect.h" #include "paddle/fluid/operators/fused/fusion_gru_op.h" #include "paddle/fluid/operators/fused/mkldnn/fusion_rnn_mkldnn.h" @@ -41,7 +42,7 @@ class GRUMKLDNNHandler : public RNNMKLDNNHandler { ctx.InputName("X") + ctx.InputName("WeightH")) { const bool is_INT8 = std::is_same::value; - if (!this->isCached()) { + if (unlikely(!this->isCached())) { // oneDNN kernel has hardcoded activation functions PADDLE_ENFORCE_EQ( ctx.Attr("gate_activation"), "sigmoid", diff --git a/paddle/fluid/operators/fused/mkldnn/fusion_lstm_mkldnn_op.cc b/paddle/fluid/operators/fused/mkldnn/fusion_lstm_mkldnn_op.cc index 385e4ad8808..dfd88248ede 100644 --- a/paddle/fluid/operators/fused/mkldnn/fusion_lstm_mkldnn_op.cc +++ b/paddle/fluid/operators/fused/mkldnn/fusion_lstm_mkldnn_op.cc @@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +#include "paddle/fluid/framework/expect.h" #include "paddle/fluid/operators/fused/fusion_lstm_op.h" #include "paddle/fluid/operators/fused/mkldnn/fusion_rnn_mkldnn.h" @@ -40,7 +41,7 @@ class LSTMMKLDNNHandler ctx, dev_ctx, mkldnn_engine, ctx.GetPlace(), input, weight_h, h0, is_reverse, N, Ti, IC, OC, 4, ctx.InputName("X") + ctx.InputName("WeightH")) { - if (!this->isCached()) { + if (unlikely(!this->isCached())) { const bool is_INT8 = std::is_same::value; const bool use_peepholes = ctx.Attr("use_peepholes"); // oneDNN kernel has hardcoded activation functions diff --git a/paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc b/paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc index 68e2a7c8a91..eef38bf99b1 100644 --- a/paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc +++ b/paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc @@ -14,6 +14,7 @@ #include +#include "paddle/fluid/framework/expect.h" #include "paddle/fluid/operators/conv_op.h" #include "paddle/fluid/platform/cpu_info.h" #include "paddle/fluid/platform/mkldnn_helper.h" @@ -79,7 +80,7 @@ class ConvMKLDNNHandlerT dev_ctx, mkldnn_engine, cpu_place, platform::CreateKey(dev_ctx, framework::vectorize(input->dims()), unique_name)) { - if (!this->isCached()) { + if (unlikely(!this->isCached())) { PADDLE_ENFORCE_EQ( input->layout(), framework::DataLayout::kMKLDNN, platform::errors::InvalidArgument( @@ -264,7 +265,7 @@ class ConvMKLDNNHandlerT dev_ctx, dev_ctx.GetEngine(), cpu_place, platform::CreateKey(dev_ctx, framework::vectorize(in->dims()), unique_name)) { - if (!this->isBwdCached()) { + if (unlikely(!this->isBwdCached())) { PADDLE_ENFORCE_EQ( in->layout(), framework::DataLayout::kMKLDNN, platform::errors::InvalidArgument( diff --git a/paddle/fluid/operators/mkldnn/prelu_mkldnn_op.cc b/paddle/fluid/operators/mkldnn/prelu_mkldnn_op.cc index 8c7113d963b..7119d68d583 100644 --- a/paddle/fluid/operators/mkldnn/prelu_mkldnn_op.cc +++ b/paddle/fluid/operators/mkldnn/prelu_mkldnn_op.cc @@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +#include "paddle/fluid/framework/expect.h" #include "paddle/fluid/platform/mkldnn_reuse.h" namespace paddle { @@ -39,7 +40,7 @@ class PReluMKLDNNHandler dev_ctx, engine, cpu_place, platform::CreateKey(dev_ctx, framework::vectorize(x->dims()), uniq_name)) { - if (!this->isCached()) { + if (unlikely(!this->isCached())) { auto x_md = memory::desc(framework::vectorize(x->dims()), MKLDNNGetDataType(), x->format()); diff --git a/paddle/fluid/platform/device_context.cc b/paddle/fluid/platform/device_context.cc index 27b900198bc..6ffeaf101fe 100644 --- a/paddle/fluid/platform/device_context.cc +++ b/paddle/fluid/platform/device_context.cc @@ -25,6 +25,7 @@ limitations under the License. */ #include "paddle/fluid/platform/ipu/ipu_backend.h" #endif #include "glog/logging.h" +#include "paddle/fluid/framework/expect.h" #include "paddle/fluid/platform/profiler.h" namespace paddle { @@ -841,15 +842,6 @@ unsigned int MKLDNNDeviceContext::GetCachedObjectsNumber(void) const { return num_entries; } -// TODO(jczaja): Replace with C++20 equivalents when applicable -#ifdef _WIN32 -#define likely(expr) (expr) -#define unlikely(expr) (expr) -#else -#define likely(expr) (__builtin_expect(!!(expr), 1)) -#define unlikely(expr) (__builtin_expect(!!(expr), 0)) -#endif - MKLDNNDeviceContext::BlobPtr_t MKLDNNDeviceContext::GetBlob( const std::string& name) const { BlobMap* pMap = p_blobmap_.get(); -- GitLab