From 0cd4907ebae1f3b096b0a004785d0f6966a26e62 Mon Sep 17 00:00:00 2001 From: "joanna.wozna.intel" Date: Wed, 30 Sep 2020 17:15:39 +0200 Subject: [PATCH] Add avx512 core instructions check (#27732) * Add avx instructions check * Small fix * Change function name * Change uint to unsigned int --- paddle/fluid/platform/cpu_info.cc | 7 +++++++ paddle/fluid/pybind/pybind.cc | 12 ++++++++++++ .../unittests/mkldnn/test_conv2d_bf16_mkldnn_op.py | 5 +++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/platform/cpu_info.cc b/paddle/fluid/platform/cpu_info.cc index e379832593..2df1f291f9 100644 --- a/paddle/fluid/platform/cpu_info.cc +++ b/paddle/fluid/platform/cpu_info.cc @@ -164,6 +164,13 @@ bool MayIUse(const cpu_isa_t cpu_isa) { // AVX512F: EBX Bit 16 int avx512f_mask = (1 << 16); return (reg[1] & avx512f_mask) != 0; + } else if (cpu_isa == avx512_core) { + unsigned int avx512f_mask = (1 << 16); + unsigned int avx512dq_mask = (1 << 17); + unsigned int avx512bw_mask = (1 << 30); + unsigned int avx512vl_mask = (1 << 31); + return ((reg[1] & avx512f_mask) && (reg[1] & avx512dq_mask) && + (reg[1] & avx512bw_mask) && (reg[1] & avx512vl_mask)); } } #endif diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 0929febc4d..b303ddde13 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -142,6 +142,17 @@ bool IsCompiledWithMKLDNN() { #endif } +bool SupportsBfloat16() { +#ifndef PADDLE_WITH_MKLDNN + return false; +#else + if (platform::MayIUse(platform::cpu_isa_t::avx512_core)) + return true; + else + return false; +#endif +} + bool IsCompiledWithBrpc() { #ifndef PADDLE_WITH_DISTRIBUTE return false; @@ -1661,6 +1672,7 @@ All parameter, weight, gradient are variables in Paddle. m.def("is_compiled_with_cuda", IsCompiledWithCUDA); m.def("is_compiled_with_xpu", IsCompiledWithXPU); m.def("is_compiled_with_mkldnn", IsCompiledWithMKLDNN); + m.def("supports_bfloat16", SupportsBfloat16); m.def("is_compiled_with_brpc", IsCompiledWithBrpc); m.def("is_compiled_with_dist", IsCompiledWithDIST); m.def("_cuda_synchronize", [](const platform::CUDAPlace &place) { diff --git a/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_bf16_mkldnn_op.py b/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_bf16_mkldnn_op.py index 0ac33383fb..4b7b4b5811 100644 --- a/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_bf16_mkldnn_op.py +++ b/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_bf16_mkldnn_op.py @@ -19,7 +19,7 @@ import numpy as np import struct import paddle.fluid.core as core -from paddle.fluid.tests.unittests.op_test import OpTest, skip_check_grad_ci, convert_float_to_uint16 +from paddle.fluid.tests.unittests.op_test import OpTest, convert_float_to_uint16 from paddle.fluid.tests.unittests.test_conv2d_op import conv2d_forward_naive, TestConv2dOp @@ -205,4 +205,5 @@ class TestWithInput1x1Filter1x1(TestConv2dBf16Op): if __name__ == '__main__': - unittest.main() + if core.supports_bfloat16(): + unittest.main() -- GitLab