opr_algo_proxy.h 2.2 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
/**
 * \file dnn/test/common/opr_algo_proxy.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 "megdnn/basic_types.h"
#include "test/common/opr_trait.h"
#include "test/common/utils.h"

namespace megdnn {
namespace test {

template <typename Opr, size_t Arity>
struct AlgoProxy;

template <typename Opr>
struct AlgoProxy<Opr, 3> {
25
    static std::vector<typename Opr::AlgorithmInfo> get_all_algorithms_info(
26 27
            Opr* opr, TensorLayoutArray& layouts) {
        megdnn_assert(layouts.size() == 3);
28
        return opr->get_all_algorithms_info(layouts[0], layouts[1], layouts[2]);
29
    }
30
    static typename Opr::AlgorithmInfo get_algorithm_info_heuristic(
31 32
            Opr* opr, TensorLayoutArray& layouts) {
        megdnn_assert(layouts.size() == 3);
33 34
        return opr->get_algorithm_info_heuristic(layouts[0], layouts[1],
                                                 layouts[2]);
35 36 37 38 39
    }
};

template <typename Opr>
struct AlgoProxy<Opr, 5> {
40
    static std::vector<typename Opr::AlgorithmInfo> get_all_algorithms_info(
41 42
            Opr* opr, TensorLayoutArray& layouts) {
        megdnn_assert(layouts.size() == 5);
43 44
        return opr->get_all_algorithms_info(layouts[0], layouts[1], layouts[2],
                                            layouts[3], layouts[4]);
45
    }
46
    static typename Opr::AlgorithmInfo get_algorithm_info_heuristic(
47 48
            Opr* opr, TensorLayoutArray& layouts) {
        megdnn_assert(layouts.size() == 5);
49 50
        return opr->get_algorithm_info_heuristic(
                layouts[0], layouts[1], layouts[2], layouts[3], layouts[4]);
51 52 53 54 55 56 57 58 59 60 61 62 63
    }
};

template <typename Opr, size_t arity = OprTrait<Opr>::arity>
struct OprAlgoProxyDefaultImpl : public AlgoProxy<Opr, arity> {};

template <typename Opr>
struct OprAlgoProxy : public OprAlgoProxyDefaultImpl<Opr> {};

}  // namespace test
}  // namespace megdnn

// vim: syntax=cpp.doxygen