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 | // LINT_C_FILE |
21 | |
22 | /*! |
23 | * \file tvm/runtime/metadata_types.h |
24 | * \brief Defines types which can be used in metadata here which |
25 | * are also shared between C and C++ code bases. |
26 | */ |
27 | #ifndef TVM_RUNTIME_METADATA_TYPES_H_ |
28 | #define TVM_RUNTIME_METADATA_TYPES_H_ |
29 | |
30 | #include <inttypes.h> |
31 | #include <tvm/runtime/c_runtime_api.h> |
32 | |
33 | #ifdef __cplusplus |
34 | extern "C" { |
35 | #endif |
36 | |
37 | /*! |
38 | * \brief Top-level metadata structure. Holds all other metadata types. |
39 | */ |
40 | struct TVMMetadata { |
41 | /*! \brief Version identifier for this metadata. */ |
42 | int64_t version; |
43 | /*! \brief Inputs to the AOT run_model function. |
44 | * The order of the elements is the same as in the arguments to run_model. That is to say, |
45 | * this array specifies the first `num_inputs` arguments to run_model. |
46 | */ |
47 | const struct TVMTensorInfo* inputs; |
48 | /*! \brief Number of elements in `inputs` array. */ |
49 | int64_t num_inputs; |
50 | /*! \brief Outputs of the AOT run_model function. |
51 | * The order of the elements is the same as in the arguments to run_model. That is to say, |
52 | * this array specifies the last `num_outputs` arguments to run_model. |
53 | */ |
54 | const struct TVMTensorInfo* outputs; |
55 | /*! \brief Number of elements in `outputs` array. */ |
56 | int64_t num_outputs; |
57 | /*! \brief Workspace Memory Pools needed by the AOT main function. |
58 | * The order of the elements is the same as in the arguments to run_model. That is to say, |
59 | * this array specifies the last `num_workspace_pools` arguments to run_model. |
60 | */ |
61 | const struct TVMTensorInfo* workspace_pools; |
62 | /*! \brief Number of elements in `workspace_pools` array. */ |
63 | int64_t num_workspace_pools; |
64 | /*! \brief Constant pools needed by the AOT main function. |
65 | */ |
66 | const struct TVMConstantInfo* constant_pools; |
67 | /*! \brief Number of elements in `constant_pools` array. */ |
68 | int64_t num_constant_pools; |
69 | /*! \brief Name of the model, as passed to tvm.relay.build. */ |
70 | const char* mod_name; |
71 | }; |
72 | |
73 | /*! |
74 | * \brief Describes one tensor argument to `run_model`. |
75 | * NOTE: while TIR allows for other types of arguments, such as scalars, the AOT run_model |
76 | * function does not currently accept these. Therefore it's not possible to express those |
77 | * in this metadata. A future patch may modify this. |
78 | */ |
79 | struct TVMTensorInfo { |
80 | /*! \brief Name of the tensor, as specified in the Relay program. */ |
81 | const char* name; |
82 | /*! \brief Shape of the tensor. */ |
83 | const int64_t* shape; |
84 | /*! \brief Rank of this tensor. */ |
85 | int64_t num_shape; |
86 | /*! \brief Data type of one element of this tensor. */ |
87 | DLDataType dtype; |
88 | }; |
89 | |
90 | /*! |
91 | * \brief Describes one constant argument to `run_model`. |
92 | * |
93 | */ |
94 | struct TVMConstantInfo { |
95 | /*! \brief Name of the constant */ |
96 | const char* name_hint; |
97 | /*! \brief Offset in bytes of the constant */ |
98 | int64_t byte_offset; |
99 | /*! \brief length of the data_bytes field */ |
100 | int64_t data_len; |
101 | /*! \brief data bytes of serialized NDArray */ |
102 | const void* data_bytes; |
103 | }; |
104 | |
105 | #ifdef __cplusplus |
106 | } // extern "C" |
107 | #endif |
108 | |
109 | #endif // TVM_RUNTIME_METADATA_TYPES_H_ |
110 | |