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

#pragma once

#include "src/arm_common/matrix_mul/opr_impl.h"
15
#include "src/fallback/matrix_mul/gemm_common.h"
16 17 18 19 20 21

namespace megdnn {
namespace arm_common {

class MatrixMulImpl::AlgoInt8x8x16 final : public AlgoBase {
public:
22 23 24
    AlgoAttribute attribute() const override {
        return AlgoAttribute::REPRODUCIBLE;
    }
25 26 27 28 29
    const char* name() const override { return "ARM_COMMON_INT8X8X16"; }
    bool usable(const KernSizeParam&) const override;
    size_t get_workspace(const KernSizeParam&) const override;
    kern_t get_kern(const KernSizeParam&) const override;
    PackMode packmode() const override { return PackMode::NO_PACK; }
30
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 4, AlgoDataType::INT8X8X16, DEFAULT)
31
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_INT8X8X16)
32 33 34 35
};

class MatrixMulImpl::AlgoInt8x8x32Gemv : public AlgoBase {
public:
36 37 38
    AlgoAttribute attribute() const override {
        return AlgoAttribute::REPRODUCIBLE;
    }
39 40 41 42 43 44 45
    const char* name() const override { return "ARM_COMMON_INT8X8X32_GEMV"; }
    bool usable(const KernSizeParam&) const override;
    bool preferred(const KernSizeParam&) const override;
    size_t get_workspace(const KernSizeParam&) const override { return 0; }
    kern_t get_kern(const KernSizeParam&) const override;
    AlgoSet algoset() const override { return AlgoSet::ALGO_TYPE_GEMV; }
    PackMode packmode() const override { return PackMode::NO_PACK; }
46
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 2, AlgoDataType::QINT8X8X32, DEFAULT)
47
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_INT8X8X32_GEMV)
48 49
};

50 51
class MatrixMulImpl::AlgoInt8x8x32GemvMK4 : public AlgoBase {
public:
52 53 54
    AlgoAttribute attribute() const override {
        return AlgoAttribute::REPRODUCIBLE;
    }
55 56 57 58 59 60 61
    const char* name() const override { return "ARM_COMMON_INT8X8X32_GEMV_MK4"; }
    bool usable(const KernSizeParam&) const override;
    bool preferred(const KernSizeParam&) const override;
    size_t get_workspace(const KernSizeParam&) const override { return 0; }
    kern_t get_kern(const KernSizeParam&) const override;
    AlgoSet algoset() const override { return AlgoSet::ALGO_TYPE_GEMV; }
    PackMode packmode() const override { return PackMode::NO_PACK; }
62
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 2, AlgoDataType::QINT8X8X32, MK4)
63
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_INT8X8X32_GEMV_MK4)
64 65 66 67 68
};

#if __ARM_FEATURE_DOTPROD
class MatrixMulImpl::AlgoInt8x8x32GemvMK4Dot : public AlgoBase {
public:
69 70 71
    AlgoAttribute attribute() const override {
        return AlgoAttribute::REPRODUCIBLE;
    }
72 73 74 75 76 77 78
    const char* name() const override { return "ARM_COMMON_INT8X8X32_GEMV_MK4_DOT"; }
    bool usable(const KernSizeParam&) const override;
    bool preferred(const KernSizeParam&) const override;
    size_t get_workspace(const KernSizeParam&) const override { return 0; }
    kern_t get_kern(const KernSizeParam&) const override;
    AlgoSet algoset() const override { return AlgoSet::ALGO_TYPE_GEMV; }
    PackMode packmode() const override { return PackMode::NO_PACK; }
79
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 2, AlgoDataType::QINT8X8X32, MK4_DOT)
80
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_INT8X8X32_GEMV_MK4_DOT)
81 82 83
};
#endif

84 85 86 87 88
class MatrixMulImpl::AlgoF32Gemv : public AlgoBase {
protected:
    ~AlgoF32Gemv() = default;

public:
89 90 91
    AlgoAttribute attribute() const override {
        return AlgoAttribute::REPRODUCIBLE;
    }
92 93 94 95 96 97 98
    const char* name() const override { return "ARM_COMMON_F32_GEMV"; }
    bool usable(const KernSizeParam&) const override;
    bool preferred(const KernSizeParam&) const override;
    size_t get_workspace(const KernSizeParam&) const override { return 0; }
    kern_t get_kern(const KernSizeParam&) const override;
    AlgoSet algoset() const override { return AlgoSet::ALGO_TYPE_GEMV; }
    PackMode packmode() const override { return PackMode::NO_PACK; }
99
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 4, AlgoDataType::FLOAT32, DEFAULT)
100 101
};

102 103
class MatrixMulImpl::AlgoF32GemvMK4 : public AlgoBase {
public:
104 105 106
    AlgoAttribute attribute() const override {
        return AlgoAttribute::REPRODUCIBLE;
    }
107 108 109 110 111 112 113
    const char* name() const override { return "ARM_COMMON_F32_GEMV_MK4"; }
    bool usable(const KernSizeParam&) const override;
    bool preferred(const KernSizeParam&) const override;
    size_t get_workspace(const KernSizeParam&) const override { return 0; }
    kern_t get_kern(const KernSizeParam&) const override;
    AlgoSet algoset() const override { return AlgoSet::ALGO_TYPE_GEMV; }
    PackMode packmode() const override { return PackMode::NO_PACK; }
114
    MEGDNN_OVERRIDE_MATMUL_DESC(4, 1, 1, 4, AlgoDataType::FLOAT32, MK4)
115
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_F32_GEMV_MK4)
116 117
};

118 119 120
#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
class MatrixMulImpl::AlgoF16Gemv : public AlgoBase {
public:
121 122 123
    AlgoAttribute attribute() const override {
        return AlgoAttribute::REPRODUCIBLE;
    }
124 125 126 127 128 129 130
    const char* name() const override { return "ARM_COMMON_F16_GEMV"; }
    bool usable(const KernSizeParam&) const override;
    bool preferred(const KernSizeParam&) const override;
    size_t get_workspace(const KernSizeParam&) const override { return 0; }
    kern_t get_kern(const KernSizeParam&) const override;
    AlgoSet algoset() const override { return AlgoSet::ALGO_TYPE_GEMV; }
    PackMode packmode() const override { return PackMode::NO_PACK; }
131
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 2, AlgoDataType::FLOAT16, DEFAULT)
132
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_F16_GEMV)
133 134
};
#endif
135 136 137

class MatrixMulImpl::AlgoGevm : public AlgoBase {
public:
138 139 140
    AlgoAttribute attribute() const override {
        return AlgoAttribute::REPRODUCIBLE;
    }
141 142 143 144 145 146 147
    const char* name() const override { return "ARM_COMMON_GEVM"; }
    bool usable(const KernSizeParam&) const override;
    bool preferred(const KernSizeParam&) const override;
    size_t get_workspace(const KernSizeParam&) const override { return 0; }
    kern_t get_kern(const KernSizeParam&) const override;
    AlgoSet algoset() const override { return AlgoSet::ALGO_TYPE_GEMV; }
    PackMode packmode() const override { return PackMode::NO_PACK; }
148 149 150 151 152 153 154
    MEGDNN_OVERRIDE_MATMUL_DESC(
            1, 1, 1, 4,
            static_cast<AlgoDataType>(
                    static_cast<uint32_t>(AlgoDataType::FLOAT16) |
                    static_cast<uint32_t>(AlgoDataType::FLOAT32) |
                    static_cast<uint32_t>(AlgoDataType::QINT8X8X32)),
            DEFAULT)
155
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_GEVM)
156 157
};

158 159 160 161
}  // namespace arm_common
}  // namespace megdnn

// vim: syntax=cpp.doxygen