• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_CCSRC_C_API_INCLUDE_ATTRIBUTE_H_
18 #define MINDSPORE_CCSRC_C_API_INCLUDE_ATTRIBUTE_H_
19 
20 #include <stdbool.h>
21 #include <stdlib.h>
22 #include "include/c_api/ms/base/macros.h"
23 #include "include/c_api/ms/base/handle_types.h"
24 #include "include/c_api/ms/base/types.h"
25 #include "include/c_api/ms/base/status.h"
26 #include "include/c_api/ms/context.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /// \brief Create a tensor with input data buffer.
33 ///
34 /// \param[in] op The Operator node handle.
35 /// \param[in] attr_name The attribute name.
36 /// \param[in] value The attribute value.
37 ///
38 /// \return Error code indicates whether the function executed successfully.
39 MIND_C_API STATUS MSOpSetScalarAttrFloat32(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, float value);
40 
41 /// \brief Set the attribute of the target node with the given name and value.
42 ///
43 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
44 /// \param[in] op Target node.
45 /// \param[in] attr_name  The attribute name associates with the node.
46 /// \param[in] value The input value of the attribute.
47 ///
48 /// \return Error code indicates whether the function executed successfully.
49 MIND_C_API STATUS MSOpSetScalarAttrBool(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, bool value);
50 
51 /// \brief Set the attribute of the target node with the given name and value.
52 ///
53 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
54 /// \param[in] op Target node.
55 /// \param[in] attr_name  The attribute name associates with the node.
56 /// \param[in] value The input value of the attribute.
57 ///
58 /// \return Error code indicates whether the function executed successfully.
59 MIND_C_API STATUS MSOpSetScalarAttrInt32(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, int32_t value);
60 
61 /// \brief Set the attribute of the target node with the given name and value.
62 ///
63 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
64 /// \param[in] op Target node.
65 /// \param[in] attr_name  The attribute name associates with the node.
66 /// \param[in] value The input value of the attribute.
67 ///
68 /// \return Error code indicates whether the function executed successfully.
69 MIND_C_API STATUS MSOpSetScalarAttrInt64(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, int64_t value);
70 
71 /// \brief Set the attribute of the target node with the given name and value.
72 ///
73 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
74 /// \param[in] op Target node.
75 /// \param[in] attr_name  The attribute name associates with the node.
76 /// \param[in] value The input value of the attribute.
77 ///
78 /// \return Error code indicates whether the function executed successfully.
79 MIND_C_API STATUS MSOpSetAttrType(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, DataTypeC value);
80 
81 /// \brief Set the attribute of the target node with the given name and value.
82 ///
83 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
84 /// \param[in] op Target node.
85 /// \param[in] attr_name  The attribute name associates with the node.
86 /// \param[in] value The input value array of the attribute.
87 /// \param[in] vec_size number of elements in the array.
88 ///
89 /// \return Error code indicates whether the function executed successfully.
90 MIND_C_API STATUS MSOpSetAttrTypeArray(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, DataTypeC value[],
91                                        size_t vec_size);
92 
93 /// \brief Set the attribute of the target node with the given name and value.
94 ///
95 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
96 /// \param[in] op Target node.
97 /// \param[in] attr_name  The attribute name associates with the node.
98 /// \param[in] value The input value array of the attribute.
99 /// \param[in] vec_size number of elements in the array.
100 /// \param[in] data_type Data type id. Currently support kNumberTypeInt32, kNumberTypeInt64, kNumberTypeFloat32,
101 /// kNumberTypeBool.
102 ///
103 /// \return Error code indicates whether the function executed successfully.
104 MIND_C_API STATUS MSOpSetAttrArray(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, void *value,
105                                    size_t vec_size, DataTypeC data_type);
106 
107 /// \brief Set the attribute of the target node with the given name and value as ValueList.
108 ///
109 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
110 /// \param[in] op Target node.
111 /// \param[in] attr_name  The attribute name associates with the node.
112 /// \param[in] value The input value array of the attribute.
113 /// \param[in] vec_size Number of elements in the array.
114 ///
115 /// \return Error code indicates whether the function executed successfully.
116 MIND_C_API STATUS MSOpSetAttrStringArray(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name,
117                                          const char *value[], size_t vec_size);
118 
119 /// \brief Set the attribute of the target node with the given name and string value.
120 ///
121 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
122 /// \param[in] op Target node.
123 /// \param[in] attr_name  The attribute name associates with the node.
124 /// \param[in] value The input value array of the attribute.
125 ///
126 /// \return Error code indicates whether the function executed successfully.
127 MIND_C_API STATUS MSOpSetAttrString(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, const char *value);
128 
129 /// \brief Get the attribute of the target node with the given attribute name.
130 ///
131 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
132 /// \param[in] op Target Node.
133 /// \param[in] attr_name The attribute name associates with the node.
134 /// \param[in] error  Error code indicates whether the function executed successfully.
135 ///
136 /// \return Attribute value
137 MIND_C_API int64_t MSOpGetScalarAttrInt64(ResMgrHandle res_mgr, ConstNodeHandle op, const char *attr_name,
138                                           STATUS *error);
139 
140 /// \brief Get the attribute of the target node with the given attribute name.
141 ///
142 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
143 /// \param[in] op Target Node.
144 /// \param[in] attr_name The attribute name associates with the node.
145 /// \param[in] values Array for storing the Atrrubute value.
146 /// \param[in] value_num Size of the given array.
147 ///
148 /// \return Error code indicates whether the function executed successfully.
149 MIND_C_API STATUS MSOpGetAttrArrayInt64(ResMgrHandle res_mgr, ConstNodeHandle op, const char *attr_name,
150                                         int64_t values[], size_t value_num);
151 
152 /// \brief Create new Int64 attribute scalar value.
153 ///
154 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
155 /// \param[in] v Given value.
156 ///
157 /// \return Attribute value handle.
158 MIND_C_API AttrHandle MSNewAttrInt64(ResMgrHandle res_mgr, const int64_t v);
159 
160 /// \brief Create new float32 attribute scalar value.
161 ///
162 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
163 /// \param[in] v Given value.
164 ///
165 /// \return Attribute value handle.
166 MIND_C_API AttrHandle MSNewAttrFloat32(ResMgrHandle res_mgr, const float v);
167 
168 /// \brief Create new Bool attribute scalar value.
169 ///
170 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
171 /// \param[in] v Given value.
172 ///
173 /// \return Attribute value handle.
174 MIND_C_API AttrHandle MSNewAttrBool(ResMgrHandle res_mgr, const bool v);
175 
176 /// \brief Create new vector of Strings attribute value.
177 ///
178 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
179 /// \param[in] strs Given value.
180 /// \param[in] vec_len Length of the string vector.
181 ///
182 /// \return Attribute value handle.
183 MIND_C_API AttrHandle MSNewAttrStrings(ResMgrHandle res_mgr, const char *strs[], size_t vec_len);
184 
185 /// \brief Create new attribute value with array.
186 ///
187 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph.
188 /// \param[in] value Given array.
189 /// \param[in] vec_size Given array size.
190 /// \param[in] data_type Datatype of the array.
191 ///
192 /// \return Attribute value handle
193 MIND_C_API AttrHandle MSNewAttrArray(ResMgrHandle res_mgr, void *value, size_t vec_size, DataTypeC data_type);
194 #ifdef __cplusplus
195 }
196 #endif
197 #endif  // MINDSPORE_CCSRC_C_API_INCLUDE_ATTRIBUTE_H_
198