algos.h 6.1 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:
M
Megvii Engine Team 已提交
22
    AlgoAttribute attribute() const override { return AlgoAttribute::REPRODUCIBLE; }
23 24 25 26 27
    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; }
28
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 4, AlgoDataType::INT8X8X16, DEFAULT)
29
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_INT8X8X16)
30 31 32 33
};

class MatrixMulImpl::AlgoInt8x8x32Gemv : public AlgoBase {
public:
34
    AlgoAttribute attribute() const override {
M
Megvii Engine Team 已提交
35
        return AlgoAttribute::REPRODUCIBLE | AlgoAttribute::USABLE_DEPEND_ON_SHAPE;
36
    }
37 38 39 40 41 42 43
    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; }
44
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 2, AlgoDataType::QINT8X8X32, DEFAULT)
45
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_INT8X8X32_GEMV)
46 47
};

48 49
class MatrixMulImpl::AlgoInt8x8x32GemvMK4 : public AlgoBase {
public:
50
    AlgoAttribute attribute() const override {
M
Megvii Engine Team 已提交
51
        return AlgoAttribute::REPRODUCIBLE | AlgoAttribute::USABLE_DEPEND_ON_SHAPE;
52
    }
53 54 55 56 57 58 59
    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; }
60
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 2, AlgoDataType::QINT8X8X32, MK4)
61
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_INT8X8X32_GEMV_MK4)
62 63
};

64
#if MGB_ENABLE_DOT
65 66
class MatrixMulImpl::AlgoInt8x8x32GemvMK4Dot : public AlgoBase {
public:
67
    AlgoAttribute attribute() const override {
M
Megvii Engine Team 已提交
68
        return AlgoAttribute::REPRODUCIBLE | AlgoAttribute::USABLE_DEPEND_ON_SHAPE;
69
    }
70 71 72 73 74 75 76
    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; }
77
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 2, AlgoDataType::QINT8X8X32, MK4_DOT)
78
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_INT8X8X32_GEMV_MK4_DOT)
79 80 81
};
#endif

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

public:
M
Megvii Engine Team 已提交
87
    AlgoAttribute attribute() const override { return AlgoAttribute::REPRODUCIBLE; }
88 89 90 91 92 93 94
    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; }
95
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 4, AlgoDataType::FLOAT32, DEFAULT)
96 97 98 99 100
};

#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
class MatrixMulImpl::AlgoF16Gemv : public AlgoBase {
public:
M
Megvii Engine Team 已提交
101
    AlgoAttribute attribute() const override { return AlgoAttribute::REPRODUCIBLE; }
102 103 104 105 106 107 108
    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; }
109
    MEGDNN_OVERRIDE_MATMUL_DESC(8, 16, 1, 2, AlgoDataType::FLOAT16, DEFAULT)
110
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_F16_GEMV)
111 112
};
#endif
113 114 115

class MatrixMulImpl::AlgoGevm : public AlgoBase {
public:
M
Megvii Engine Team 已提交
116
    AlgoAttribute attribute() const override { return AlgoAttribute::REPRODUCIBLE; }
117 118 119 120 121 122 123
    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; }
124 125 126 127 128 129 130
    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)
131
    MEGDNN_DECL_ALGO_TYPE(ARM_COMMON_GEVM)
132 133
};

134 135 136 137
}  // namespace arm_common
}  // namespace megdnn

// vim: syntax=cpp.doxygen