opr_impl.cpp 2.3 KB
Newer Older
1 2 3 4 5 6 7 8
/**
 * \file dnn/src/x86/matrix_mul/opr_impl.cpp
 * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
 *
 * Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
9 10
 * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
11 12 13 14 15 16 17 18 19 20 21
 */

#include "src/x86/matrix_mul/opr_impl.h"
#include "src/common/metahelper.h"
#include "src/x86/matrix_mul/algos.h"
using namespace megdnn;
using namespace x86;

class MatrixMulImpl::AlgoPack : NonCopyableObj {
    AlgoF32Blas f32blas;

22
#if MEGDNN_X86_WITH_MKL && SUPPORT_MKL_PACKED_GEMM
23 24 25 26 27
    AlgoF32MKLPackA f32mkl_packa;
#endif
#if MEGDNN_X86_WITH_VNNI
    AlgoInt8x8x32Vnni algoint8x8x32vnni;
#endif
28
#if MEGDNN_X86_WITH_MKL_DNN
29 30 31 32 33
    AlgoInt8x8x32Mkldnn algoint8x8x32mkldnn;
#endif
    AlgoInt8x8x32AVX2M4N16K2 algoint8x8x32avx2_m4n16k2;
    AlgoInt8x8x32AVX2M2N4K16 algoint8x8x32avx2_m2n4k16;
    AlgoInt8x8x32SSEM4N8K2 algoint8x8x32sse_m4n8k2;
34
    AlgoInt8x8x16AVX2 algoint8x8x16avx2_m4n16k2;
35
    AlgoInt8x8x16SSE algoint8x8x16sse_m4n8k2;
36 37 38 39 40 41 42 43 44 45
    AlgoF32MK8_8x8 algof32mk8_8x8;

public:
    AlgoPack() {
        if (is_supported(SIMDType::VNNI)) {
#if MEGDNN_X86_WITH_VNNI
            all_algos.emplace_back(&algoint8x8x32vnni);
#endif
        }
        all_algos.emplace_back(&algoint8x8x32avx2_m4n16k2);
46
        all_algos.emplace_back(&algoint8x8x16avx2_m4n16k2);
47 48
        all_algos.emplace_back(&algoint8x8x32avx2_m2n4k16);
        all_algos.emplace_back(&algoint8x8x32sse_m4n8k2);
49
        all_algos.emplace_back(&algoint8x8x16sse_m4n8k2);
50
        all_algos.emplace_back(&algof32mk8_8x8);
51
#if MEGDNN_X86_WITH_MKL_DNN
52 53 54
        all_algos.emplace_back(&algoint8x8x32mkldnn);
#endif
        all_algos.emplace_back(&f32blas);
55
#if MEGDNN_X86_WITH_MKL && SUPPORT_MKL_PACKED_GEMM
56 57 58
        all_algos.emplace_back(&f32mkl_packa);
#endif
    }
59
    SmallVector<fallback::MatrixMulImpl::AlgoBase*> all_algos;
60 61
};

62
SmallVector<fallback::MatrixMulImpl::AlgoBase*> MatrixMulImpl::algo_pack() {
63 64 65 66 67 68 69 70
    static AlgoPack s_algo_pack;
    auto&& algos = fallback::MatrixMulImpl::algo_pack();
    algos.insert(algos.begin(), s_algo_pack.all_algos.begin(),
                 s_algo_pack.all_algos.end());
    return std::move(algos);
}

// vim: syntax=cpp.doxygen