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 | * Common build utilities |
22 | * \file build_common.h |
23 | */ |
24 | #ifndef TVM_TARGET_BUILD_COMMON_H_ |
25 | #define TVM_TARGET_BUILD_COMMON_H_ |
26 | |
27 | #include <tvm/ir/module.h> |
28 | #include <tvm/runtime/registry.h> |
29 | #include <tvm/target/codegen.h> |
30 | #include <tvm/tir/expr.h> |
31 | #include <tvm/tir/function.h> |
32 | #include <tvm/tir/stmt.h> |
33 | |
34 | #include <string> |
35 | #include <unordered_map> |
36 | |
37 | #include "../runtime/meta_data.h" |
38 | |
39 | namespace tvm { |
40 | namespace codegen { |
41 | |
42 | inline std::unordered_map<std::string, runtime::FunctionInfo> ExtractFuncInfo(const IRModule& mod) { |
43 | std::unordered_map<std::string, runtime::FunctionInfo> fmap; |
44 | |
45 | for (auto kv : mod->functions) { |
46 | ICHECK(kv.second->IsInstance<tir::PrimFuncNode>()) << "Can only lower IR Module with PrimFuncs"; |
47 | auto f = Downcast<tir::PrimFunc>(kv.second); |
48 | |
49 | runtime::FunctionInfo info; |
50 | for (size_t i = 0; i < f->params.size(); ++i) { |
51 | info.arg_types.push_back(f->params[i].dtype()); |
52 | } |
53 | if (auto opt = f->GetAttr<Array<tir::IterVar>>(tir::attr::kDeviceThreadAxis)) { |
54 | auto thread_axis = opt.value(); |
55 | for (size_t i = 0; i < thread_axis.size(); ++i) { |
56 | info.launch_param_tags.push_back(thread_axis[i]->thread_tag); |
57 | } |
58 | } |
59 | if (auto opt = f->GetAttr<Integer>(tir::attr::kDeviceUseDynSharedMemory)) { |
60 | if (opt.value().IntValue() != 0) { |
61 | info.launch_param_tags.push_back(runtime::launch_param::kUseDynamicSharedMemoryTag); |
62 | } |
63 | } |
64 | auto global_symbol = f->GetAttr<String>(tvm::attr::kGlobalSymbol); |
65 | fmap[static_cast<std::string>(global_symbol.value())] = info; |
66 | } |
67 | return fmap; |
68 | } |
69 | |
70 | } // namespace codegen |
71 | } // namespace tvm |
72 | #endif // TVM_TARGET_BUILD_COMMON_H_ |
73 |