algos.h 4.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/**
 * \file dnn/src/arm_common/conv_bias/f16/algos.h
 * 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
 * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */

#pragma once

#include "src/arm_common/conv_bias/opr_impl.h"
#include "src/fallback/matrix_mul/opr_impl.h"
#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
namespace megdnn {
namespace arm_common {

class ConvBiasImpl::AlgoFP16WinogradF23 final : public AlgoBase {
public:
    AlgoFP16WinogradF23(fallback::MatrixMulImpl::AlgoBase* matmul_algo,
                        uint32_t tile_size)
            : m_matmul_algo{matmul_algo}, m_tile_size{tile_size} {}
    const char* name() const override {
        if (m_name.empty()) {
            m_name = ConvBiasImpl::algo_name<ConvBias::WinogradParam>(
                    m_matmul_algo->name(), {1, 2, m_tile_size});
        }
        return m_name.c_str();
    }
32
    MEGDNN_WINOGRAD_ALGO_FUN_DECLARE();
33 34 35 36 37 38 39 40 41 42 43 44 45 46
};

class ConvBiasImpl::AlgoFP16WinogradF45 final : public AlgoBase {
public:
    AlgoFP16WinogradF45(fallback::MatrixMulImpl::AlgoBase* matmul_algo,
                        uint32_t tile_size)
            : m_matmul_algo{matmul_algo}, m_tile_size{tile_size} {}
    const char* name() const override {
        if (m_name.empty()) {
            m_name = ConvBiasImpl::algo_name<ConvBias::WinogradParam>(
                    m_matmul_algo->name(), {1, 4, m_tile_size});
        }
        return m_name.c_str();
    }
47
    MEGDNN_WINOGRAD_ALGO_FUN_DECLARE();
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

};
class ConvBiasImpl::AlgoFP16WinogradF63 final : public AlgoBase {
public:
    AlgoFP16WinogradF63(fallback::MatrixMulImpl::AlgoBase* matmul_algo,
                        uint32_t tile_size)
            : m_matmul_algo{matmul_algo}, m_tile_size{tile_size} {}
    const char* name() const override {
        if (m_name.empty()) {
            m_name = ConvBiasImpl::algo_name<ConvBias::WinogradParam>(
                    m_matmul_algo->name(), {1, 6, m_tile_size});
        }
        return m_name.c_str();
    }

63
    MEGDNN_WINOGRAD_ALGO_FUN_DECLARE();
64 65 66 67 68 69 70 71 72 73 74 75 76
};
class ConvBiasImpl::AlgoFP16WinogradF23_8x8 final : public AlgoBase {
public:
    AlgoFP16WinogradF23_8x8(fallback::MatrixMulImpl::AlgoBase* matmul_algo,
                            uint32_t tile_size)
            : m_matmul_algo{matmul_algo}, m_tile_size{tile_size} {}
    const char* name() const override {
        if (m_name.empty()) {
            m_name = ConvBiasImpl::algo_name<ConvBias::WinogradParam>(
                    m_matmul_algo->name(), {8, 2, m_tile_size});
        }
        return m_name.c_str();
    }
77
    MEGDNN_WINOGRAD_ALGO_FUN_DECLARE();
78 79 80 81 82 83 84 85 86 87 88 89 90
};

class ConvBiasImpl::AlgoF16Direct final : public AlgoBase {
    SmallVector<NCBKern> get_kimpls(const NCBKernSizeParam& param) const;
    bool m_large_group;

public:
    AlgoF16Direct(bool is_large_group) : m_large_group{is_large_group} {}
    bool is_reproducible() const override { return true; }
    const char* name() const override {
        return m_large_group ? "F16DIRECT_LARGE_GROUP"
                             : "F16DIRECT_SMALL_GROUP";
    }
91
    bool usable(const NCBKernSizeParam& param,
92 93
                AlgoSelectionStrategy algo_selection_strategy) const override;

94
    size_t get_workspace(const NCBKernSizeParam& param) const override;
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

    virtual SmallVector<NCBKern> dispatch_kerns(
            const NCBKernSizeParam& param) const override;
};

class ConvBiasImpl::AlgoF16DirectStride1 final : public AlgoBase {
    SmallVector<NCBKern> get_kimpls(const NCBKernSizeParam& param) const;
    bool m_large_group;

public:
    AlgoF16DirectStride1(bool is_large_group) : m_large_group{is_large_group} {}
    bool is_reproducible() const override { return true; }
    const char* name() const override {
        return m_large_group ? "F16STRD1_LARGE_GROUP" : "F16STRD1_SMALL_GROUP";
    }
110
    bool usable(const NCBKernSizeParam& param,
111
                AlgoSelectionStrategy algo_selection_strategy) const override;
112
    size_t get_workspace(const NCBKernSizeParam& param) const override;
113 114 115 116 117 118 119 120
    virtual SmallVector<NCBKern> dispatch_kerns(
            const NCBKernSizeParam& param) const override;
};

}  // namespace arm_common
}  // namespace megdnn
#endif
// vim: syntax=cpp.doxygen