diff --git a/dnn/src/x86/matrix_mul/algos.cpp b/dnn/src/x86/matrix_mul/algos.cpp index 6e0d8db21d7c178172b26fe9ba571300bba1021d..298156794f54f8ebf8309d7963a92fa972cee0b2 100644 --- a/dnn/src/x86/matrix_mul/algos.cpp +++ b/dnn/src/x86/matrix_mul/algos.cpp @@ -14,21 +14,9 @@ #include "src/common/utils.h" #include "src/fallback/matrix_mul/gemm_impl.h" #include "src/x86/matrix_mul/int8/strategy.h" -#include "src/x86/utils.h" #include "src/x86/matrix_mul/f32/strategy.h" -#if MEGDNN_X86_WITH_MKL -#include -#include -#elif MEGDNN_X86_WITH_OPENBLAS -#include -#else -#endif - -#if MEGDNN_X86_WITH_MKL_DNN -#include -#endif MIDOUT_DECL(megdnn_x86_matmul_kern) MIDOUT_DECL(megdnn_x86_matmul_kern_mk8_8x8) @@ -55,7 +43,7 @@ void f32_blas_kern(const MatrixMulImpl::KernParam& kern_param) { #endif } -#if MEGDNN_X86_WITH_MKL +#if MEGDNN_X86_WITH_MKL && SUPPORT_MKL_PACKED_GEMM void f32_blas_kern_only_packA(const MatrixMulImpl::KernParam& kern_param, const void* a_panel, const void* b_panel) { MEGDNN_MARK_USED_VAR(b_panel); @@ -93,7 +81,7 @@ MatrixMulImpl::kern_t MatrixMulImpl::AlgoF32Blas::get_kern( } /* ===================== AlgoF32BlasPackA====================== */ -#if MEGDNN_X86_WITH_MKL +#if MEGDNN_X86_WITH_MKL && SUPPORT_MKL_PACKED_GEMM bool MatrixMulImpl::AlgoF32MKLPackA::usable( const KernSizeParam& kern_size_param) const { return kern_size_param.compute_mode == Param::ComputeMode::DEFAULT && diff --git a/dnn/src/x86/matrix_mul/algos.h b/dnn/src/x86/matrix_mul/algos.h index 3664b0e7f206b4920516310b352e4ef148857289..46c085cd76af750ad43439e8b44e6495fa51d731 100644 --- a/dnn/src/x86/matrix_mul/algos.h +++ b/dnn/src/x86/matrix_mul/algos.h @@ -28,7 +28,7 @@ public: PackMode packmode() const override { return PackMode::NO_PACK; } }; -#if MEGDNN_X86_WITH_MKL +#if MEGDNN_X86_WITH_MKL && SUPPORT_MKL_PACKED_GEMM class MatrixMulImpl::AlgoF32MKLPackA : public AlgoBase { public: bool is_reproducible() const override { return true; } diff --git a/dnn/src/x86/matrix_mul/opr_impl.cpp b/dnn/src/x86/matrix_mul/opr_impl.cpp index 6101c5e6e8a0c64587ad860fac7818b5f37d8b3e..7763ba5bd641eefef0db24e14704f4eaec31a23b 100644 --- a/dnn/src/x86/matrix_mul/opr_impl.cpp +++ b/dnn/src/x86/matrix_mul/opr_impl.cpp @@ -12,7 +12,6 @@ #include "src/x86/matrix_mul/opr_impl.h" #include "src/common/metahelper.h" #include "src/x86/matrix_mul/algos.h" -#include "src/x86/utils.h" using namespace megdnn; using namespace x86; @@ -25,7 +24,7 @@ void* const MatrixMulImpl::sm_x86_algo_type = &x86_algo_type_storage; class MatrixMulImpl::AlgoPack : NonCopyableObj { AlgoF32Blas f32blas; -#if MEGDNN_X86_WITH_MKL +#if MEGDNN_X86_WITH_MKL && SUPPORT_MKL_PACKED_GEMM AlgoF32MKLPackA f32mkl_packa; #endif #if MEGDNN_X86_WITH_VNNI @@ -57,7 +56,7 @@ public: all_algos.emplace_back(&algoint8x8x32mkldnn); #endif all_algos.emplace_back(&f32blas); -#if MEGDNN_X86_WITH_MKL +#if MEGDNN_X86_WITH_MKL && SUPPORT_MKL_PACKED_GEMM all_algos.emplace_back(&f32mkl_packa); #endif } diff --git a/dnn/src/x86/matrix_mul/opr_impl.h b/dnn/src/x86/matrix_mul/opr_impl.h index 77e0dbf6bbcb498d19727e26868e4f9e808b5ab5..10af998666eb86b95430eeb3893557a6a9c77e97 100644 --- a/dnn/src/x86/matrix_mul/opr_impl.h +++ b/dnn/src/x86/matrix_mul/opr_impl.h @@ -9,8 +9,22 @@ * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #pragma once + #include "src/common/utils.h" #include "src/fallback/matrix_mul/opr_impl.h" +#include "src/x86/utils.h" + +#if MEGDNN_X86_WITH_MKL +#include +#include +#elif MEGDNN_X86_WITH_OPENBLAS +#include +#else +#endif + +#if MEGDNN_X86_WITH_MKL_DNN +#include +#endif namespace megdnn { namespace x86 { @@ -26,7 +40,7 @@ public: protected: static void* const sm_x86_algo_type; class AlgoF32Blas; -#if MEGDNN_X86_WITH_MKL +#if MEGDNN_X86_WITH_MKL && SUPPORT_MKL_PACKED_GEMM class AlgoF32MKLPackA; #endif #if MEGDNN_X86_WITH_VNNI diff --git a/dnn/src/x86/utils.h b/dnn/src/x86/utils.h index b6c3094da89b246def9fe6a63fc377b64f2c9fc0..d417d9c38976b21675cec650e2ed7537ec9bd868 100644 --- a/dnn/src/x86/utils.h +++ b/dnn/src/x86/utils.h @@ -14,6 +14,17 @@ #include #include "src/common/utils.h" +#if MEGDNN_X86_WITH_MKL +#include +//! As INTEL_MKL_VERSION >= 20190001 support SUPPORT_MKL_PACKED_GEMM +#if INTEL_MKL_VERSION >= 20190001 +#define SUPPORT_MKL_PACKED_GEMM 1 +#else +#define SUPPORT_MKL_PACKED_GEMM 0 +#endif + +#endif + namespace megdnn { namespace x86 { diff --git a/dnn/test/x86/conv_bias.cpp b/dnn/test/x86/conv_bias.cpp index 950aab12647dc47800e0fa473a60d0c8a38f329a..a0a06226549ea18deb93b8cc7c629b277b293b24 100644 --- a/dnn/test/x86/conv_bias.cpp +++ b/dnn/test/x86/conv_bias.cpp @@ -853,7 +853,7 @@ TEST_F(X86_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP32) { #undef cb } -#if MEGDNN_X86_WITH_MKL +#if MEGDNN_X86_WITH_MKL && SUPPORT_MKL_PACKED_GEMM TEST_F(X86_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP32_PACKA) { using namespace conv_bias; std::vector args; diff --git a/dnn/test/x86/matrix_mul.cpp b/dnn/test/x86/matrix_mul.cpp index 1b6d8038697dd9c0a73ac2fc6d8ed8edb3c1e68b..f58ec3122172218a151d96f480904379856a1f9a 100644 --- a/dnn/test/x86/matrix_mul.cpp +++ b/dnn/test/x86/matrix_mul.cpp @@ -52,7 +52,7 @@ TEST_F(X86, MATRIX_MUL_SSE_8X8X32) { handle(), "X86_INT8X8X32_SSE_4X8X2"); } -#if MEGDNN_X86_WITH_MKL +#if MEGDNN_X86_WITH_MKL && SUPPORT_MKL_PACKED_GEMM TEST_F(X86, MATRIX_MUL_MKL_PACKA) { matrix_mul::check_matrix_mul(dtype::Float32{}, dtype::Float32{}, dtype::Float32{}, handle(),