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/relay/collage/utils.h |
22 | * \brief Misc helpers. |
23 | */ |
24 | |
25 | #ifndef TVM_RELAY_COLLAGE_UTILS_H_ |
26 | #define TVM_RELAY_COLLAGE_UTILS_H_ |
27 | |
28 | #include <tvm/relay/expr.h> |
29 | #include <tvm/relay/function.h> |
30 | #include <tvm/relay/op_attr_types.h> |
31 | #include <tvm/runtime/container/string.h> |
32 | |
33 | #include <string> |
34 | #include <vector> |
35 | |
36 | namespace tvm { |
37 | namespace relay { |
38 | namespace collage { |
39 | |
40 | /*! |
41 | * \brief Distinguished partition spec names. |
42 | */ |
43 | constexpr const char* kTVMSpecNamePrefix = "tvm_" ; |
44 | constexpr const char* kHostSpecName = "host" ; |
45 | |
46 | /*! |
47 | * \brief Returns the partition spec name to use for \p target. For external codegen targets the |
48 | * spec name is just the target kind name. For TVM native targets the spec name is of the form |
49 | * "tvm_<kind_name>". |
50 | */ |
51 | String GetSpecName(const Target& target); |
52 | |
53 | /*! \brief Returns \p "<left>+<right>". */ |
54 | String UnionLabels(String left, String right); |
55 | |
56 | /*! \brief Returns \p "<outer>.<inner>". */ |
57 | String NestLabels(String outer, String inner); |
58 | |
59 | /*! \brief Returns abbreviation for \p kind. */ |
60 | std::string KindToString(OpPatternKind kind); |
61 | |
62 | /*! \brief Returns maximum of \p left and \p right. */ |
63 | OpPatternKind CombineKinds(OpPatternKind left, OpPatternKind right); |
64 | |
65 | /*! |
66 | * \brief Returns true if \p expr can be safely inlined in body of function extracted |
67 | * from sub-graph, even if \p expr was not technically matched by the pattern which produced |
68 | * the sub-graph. |
69 | */ |
70 | bool CanInline(const Expr& expr); |
71 | |
72 | /*! |
73 | * \brief Returns true if \p op_node can be directly handled by the VM. |
74 | */ |
75 | bool IsSpecialOp(const OpNode* op_node); |
76 | |
77 | /*! |
78 | * \brief Return true if the Relay expression node given by \p expr cannot be evaluated by |
79 | * the VM and must end up in a kernel. |
80 | */ |
81 | bool MustBeLowered(const Expr& expr); |
82 | |
83 | /*! |
84 | * \brief Returns the list of split strings of given statement with delimiter. |
85 | */ |
86 | std::vector<std::string> SplitString(std::string stmt, const char* del); |
87 | |
88 | } // namespace collage |
89 | } // namespace relay |
90 | } // namespace tvm |
91 | |
92 | #endif // TVM_RELAY_COLLAGE_UTILS_H_ |
93 | |