1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one |
3 | * or more contributor license agreements. See the NOTICE file |
4 | * distributed with this work for additional information |
5 | * regarding copyright ownership. The ASF licenses this file |
6 | * to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance |
8 | * with the License. You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, |
13 | * software distributed under the License is distributed on an |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | * KIND, either express or implied. See the License for the |
16 | * specific language governing permissions and limitations |
17 | * under the License. |
18 | */ |
19 | |
20 | /*! |
21 | * \file src/contrib/ethosu/cascader/pareto.h |
22 | * \brief Pareto optimisation functions for the NPU cascader |
23 | */ |
24 | #ifndef TVM_CONTRIB_ETHOSU_CASCADER_PARETO_H_ |
25 | #define TVM_CONTRIB_ETHOSU_CASCADER_PARETO_H_ |
26 | |
27 | #include <tvm/ir/expr.h> |
28 | #include <tvm/runtime/container/array.h> |
29 | |
30 | #include <algorithm> |
31 | #include <array> |
32 | #include <vector> |
33 | |
34 | namespace tvm { |
35 | namespace contrib { |
36 | namespace ethosu { |
37 | namespace cascader { |
38 | |
39 | class Plan; |
40 | class MemoryRegion; |
41 | class Proposal; |
42 | |
43 | /*! |
44 | * \brief Determine the Pareto optimal points. |
45 | * \param costs The points as a vector of N-dimensional costs. |
46 | * \return A vector that is true where a point is Pareto optimal and false otherwise. |
47 | */ |
48 | template <int N> |
49 | std::vector<bool> GetParetoFrontier(const std::vector<std::array<float, N>>& costs); |
50 | |
51 | /*! |
52 | * \brief Evenly sample items from a vector to reduce its size. |
53 | * \param vec The vector to thin. |
54 | * \param max_size The maximum size of the thinned vector. |
55 | * \return The thinned vector. |
56 | */ |
57 | template <class T> |
58 | std::vector<T> ThinVector(const std::vector<T>& vec, size_t max_size); |
59 | |
60 | /*! |
61 | * \brief Cull plans which are not Pareto optimal then thin them down. |
62 | * \param plans The plans to apply the Pareto culling to. |
63 | * \param max_plans The maximum number of plans after the culling. |
64 | * \param disable_pareto_metric Whether to only select from Pareto frontier or not. |
65 | * \return The culled plans. |
66 | * \note Plan Pareto-optimality is determined based upon a Plan's memory_usage |
67 | * and cycles. |
68 | */ |
69 | std::vector<Plan> ParetoCullPlans(std::vector<Plan> plans, size_t max_plans, |
70 | bool disable_pareto_metric); |
71 | |
72 | std::vector<Proposal> ParetoCullProposals(std::vector<Proposal> proposals, size_t max_proposals, |
73 | bool disable_pareto_metric); |
74 | |
75 | } // namespace cascader |
76 | } // namespace ethosu |
77 | } // namespace contrib |
78 | } // namespace tvm |
79 | |
80 | #endif // TVM_CONTRIB_ETHOSU_CASCADER_PARETO_H_ |
81 | |