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_NODE_H_ 18 #define MINDSPORE_CCSRC_C_API_INCLUDE_NODE_H_ 19 20 #include <stdbool.h> 21 #include <stdlib.h> 22 #include "include/c_api/ms/context.h" 23 #include "include/c_api/ms/base/macros.h" 24 #include "include/c_api/ms/base/status.h" 25 #include "include/c_api/ms/base/handle_types.h" 26 #include "include/c_api/ms/base/types.h" 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 /// \brief The struct to describe custom op's basic info. For output_dtypes and dtype_infer_func, only one of them need 33 /// to be specified. For output_shapes and shape_infer_func, only one of them need to be specified as well, and 34 /// output_dims must be given if output_shapes is specified. 35 typedef struct CustomOpInfo { 36 const char *func_name; 37 const char *func_type; 38 const char *target; 39 const char **input_names; 40 size_t input_num; 41 const char **output_names; 42 size_t output_num; 43 const char **attr_names; 44 ValueHandle *attr_values; 45 size_t attr_num; 46 DTypeFormat **dtype_formats; 47 size_t dtype_formats_num; 48 int64_t **output_shapes; 49 size_t *output_dims; 50 DataTypeC *output_dtypes; 51 STATUS(*dtype_infer_func) 52 (const DataTypeC *input_types, size_t input_num, DataTypeC *output_types, size_t output_num); 53 STATUS(*shape_infer_func) 54 (int64_t **input_shapes, const size_t *input_dims, size_t input_num, int64_t **output_shapes, size_t *output_dims, 55 size_t output_num); 56 } CustomOpInfo; 57 58 /// \brief The struct to describe the extra information for single op execution. 59 typedef struct DynamicOpInfo { 60 const char **attr_names; // An array of of attribute names. 61 ValueHandle *attr_values; // An array of of attributes which has same length as [attr_names]. 62 size_t attr_num; // The number of attributes. 63 int64_t **output_shapes; // An array of each output's shapes. Auto infer will be denied if specified. 64 size_t *output_dims; // An array of each output's dimension. Must be specified if [output_shapes] is not NULL. 65 DataTypeC *output_dtypes; // An array of each output's dtypes. Must be specified if [output_shapes] is not NULL. 66 } DynamicOpInfo; 67 68 /// \brief Create a new Operator node. 69 /// 70 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 71 /// \param[in] graph The given function graph pointer handle. 72 /// \param[in] op_type The primitive name. 73 /// \param[in] inputs An array of operator's input nodes. 74 /// \param[in] input_num The number of nodes in the array. 75 /// \param[in] attr_names An array of of attribute names. 76 /// \param[in] attrs An array of of attributes which has same length as [attr_names]. 77 /// \param[in] attr_num The number of attributes. 78 /// 79 /// \return The created Operator node handle 80 MIND_C_API NodeHandle MSNewOp(ResMgrHandle res_mgr, GraphHandle graph, const char *op_type, Handle const inputs[], 81 size_t input_num, const char *const *attr_names, ValueHandle attrs[], size_t attr_num); 82 83 /// \brief Create a tensor with input data buffer. 84 /// 85 /// \param[in] op The Operator node handle. 86 /// \param[in] attr_name The attribute name. 87 /// \param[in] value The Value. 88 /// 89 /// \return Error code indicates whether the function executed successfully. 90 MIND_C_API STATUS MSOpSetAttrScalarFloat32(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, float value); 91 92 /// \brief Set the attribute of the target node with the given name and value. 93 /// 94 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph. 95 /// \param[in] op Target node. 96 /// \param[in] attr_name The attribute name associates with the node. 97 /// \param[in] value The input value of the attribute. 98 /// 99 /// \return Error code indicates whether the function executed successfully. 100 MIND_C_API STATUS MSOpSetAttrScalarBool(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, bool value); 101 102 /// \brief Set the attribute of the target node with the given name and value. 103 /// 104 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph. 105 /// \param[in] op Target node. 106 /// \param[in] attr_name The attribute name associates with the node. 107 /// \param[in] value The input value of the attribute. 108 /// 109 /// \return Error code indicates whether the function executed successfully. 110 MIND_C_API STATUS MSOpSetAttrScalarInt32(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, int32_t value); 111 112 /// \brief Set the attribute of the target node with the given name and value. 113 /// 114 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph. 115 /// \param[in] op Target node. 116 /// \param[in] attr_name The attribute name associates with the node. 117 /// \param[in] value The input value of the attribute. 118 /// 119 /// \return Error code indicates whether the function executed successfully. 120 MIND_C_API STATUS MSOpSetAttrScalarInt64(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, int64_t value); 121 122 /// \brief Set the attribute of the target node with the given name and value. 123 /// 124 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph. 125 /// \param[in] op Target node. 126 /// \param[in] attr_name The attribute name associates with the node. 127 /// \param[in] value The input value of the attribute. 128 /// 129 /// \return Error code indicates whether the function executed successfully. 130 MIND_C_API STATUS MSOpSetAttrType(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, DataTypeC value); 131 132 /// \brief Set the attribute of the target node with the given name and value. 133 /// 134 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph. 135 /// \param[in] op Target node. 136 /// \param[in] attr_name The attribute name associates with the node. 137 /// \param[in] value The input value array of the attribute. 138 /// \param[in] vec_size number of elements in the array. 139 /// 140 /// \return Error code indicates whether the function executed successfully. 141 MIND_C_API STATUS MSOpSetAttrTypeArray(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, DataTypeC value[], 142 size_t vec_size); 143 144 /// \brief Set the attribute of the target node with the given name and value. 145 /// 146 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph. 147 /// \param[in] op Target node. 148 /// \param[in] attr_name The attribute name associates with the node. 149 /// \param[in] value The input value array of the attribute. 150 /// \param[in] vec_size number of elements in the array. 151 /// \param[in] data_type Data type id. Currently support kNumberTypeInt32, kNumberTypeInt64, kNumberTypeFloat32, 152 /// kNumberTypeBool. 153 /// 154 /// \return Error code indicates whether the function executed successfully. 155 MIND_C_API STATUS MSOpSetAttrArray(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, void *value, 156 size_t vec_size, DataTypeC data_type); 157 158 /// \brief Set the attribute of the target node with the given name and value as ValueList. 159 /// 160 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph. 161 /// \param[in] op Target node. 162 /// \param[in] attr_name The attribute name associates with the node. 163 /// \param[in] value The input value array of the attribute. 164 /// \param[in] vec_size Number of elements in the array. 165 /// 166 /// \return Error code indicates whether the function executed successfully. 167 MIND_C_API STATUS MSOpSetAttrStringArray(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, 168 const char *value[], size_t vec_size); 169 170 /// \brief Set the attribute of the target node with the given name and string value. 171 /// 172 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph. 173 /// \param[in] op Target node. 174 /// \param[in] attr_name The attribute name associates with the node. 175 /// \param[in] value The input value array of the attribute. 176 /// 177 /// \return Error code indicates whether the function executed successfully. 178 MIND_C_API STATUS MSOpSetAttrString(ResMgrHandle res_mgr, NodeHandle op, const char *attr_name, const char *value); 179 180 /// \brief Get the attribute of the target node with the given attribute name. 181 /// 182 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph. 183 /// \param[in] op Target Node. 184 /// \param[in] attr_name The attribute name associates with the node. 185 /// \param[in] error Error code indicates whether the function executed successfully. 186 /// 187 /// \return Value 188 MIND_C_API int64_t MSOpGetAttrScalarInt64(ResMgrHandle res_mgr, ConstNodeHandle op, const char *attr_name, 189 STATUS *error); 190 191 /// \brief Get the attribute of the target node with the given attribute name. 192 /// 193 /// \param[in] res_mgr Resource Handle that manages the nodes of the funcGraph. 194 /// \param[in] op Target Node. 195 /// \param[in] attr_name The attribute name associates with the node. 196 /// \param[in] values Array for storing the Atrrubute value. 197 /// \param[in] value_num Size of the given array. 198 /// 199 /// \return Error code indicates whether the function executed successfully. 200 MIND_C_API STATUS MSOpGetAttrArrayInt64(ResMgrHandle res_mgr, ConstNodeHandle op, const char *attr_name, 201 int64_t values[], size_t value_num); 202 203 /// \brief Set Operator node name. 204 /// 205 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 206 /// \param[in] node The target node. 207 /// \param[in] name The op node name to be set. 208 /// 209 /// \return The error code that indicate whether the functions executed successfully. 210 MIND_C_API STATUS MSOpSetName(ResMgrHandle res_mgr, NodeHandle node, const char *name); 211 212 /// \brief Get the name of node. 213 /// 214 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 215 /// \param[in] node The target node. 216 /// \param[in] str_buf The char array to contain the name string. 217 /// \param[in] str_len The size of the char array. 218 /// 219 /// \return The error code that indicate whether the functions executed successfully. 220 MIND_C_API STATUS MSNodeGetName(ResMgrHandle res_mgr, ConstNodeHandle node, char str_buf[], size_t str_len); 221 222 /// \brief Pack nodes into a Tuple node. 223 /// 224 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 225 /// \param[in] graph The given function graph pointer handle. 226 /// \param[in] nodes The input nodes. 227 /// \param[in] node_num The number of nodes in the array. 228 /// 229 /// \return The created Tuple node handle. 230 MIND_C_API NodeHandle MSPackNodesTuple(ResMgrHandle res_mgr, GraphHandle graph, Handle const nodes[], size_t node_num); 231 232 /// \brief Get specified output branch from a multi-output Operator. 233 /// 234 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 235 /// \param[in] graph The given function graph pointer handle. 236 /// \param[in] op The Operator. 237 /// \param[in] i The index of the output branch. 238 /// 239 /// \return The obtained output node. 240 MIND_C_API NodeHandle MSOpGetSpecOutput(ResMgrHandle res_mgr, GraphHandle graph, ConstNodeHandle op, size_t i); 241 242 /// \brief Create a Switch operator for control-flow scene. 243 /// 244 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 245 /// \param[in] graph The given function graph pointer handle. 246 /// \param[in] cond The condition of Switch which can be an Operator or a Subgraph. 247 /// \param[in] true_br The true branch of Switch which must be a Subgraph. 248 /// \param[in] false_br The false branch of Switch which must be a Subgraph. 249 /// 250 /// \return The created Switch operator node. 251 MIND_C_API NodeHandle MSNewSwitch(ResMgrHandle res_mgr, GraphHandle graph, Handle cond, ConstGraphHandle true_br, 252 ConstGraphHandle false_br); 253 254 /// \brief Create a While operator for control-flow scene. 255 /// 256 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 257 /// \param[in] graph The given function graph pointer handle. 258 /// \param[in] cond The condition of While which can be an Operator or a Subgraph. 259 /// \param[in] body_graph The loop body of While which must be a Subgraph. 260 /// \param[in] after_graph The graph after stepping out the While which must be a Subgraph. 261 /// 262 /// \return The created While operator node. 263 MIND_C_API NodeHandle MSNewWhile(ResMgrHandle res_mgr, GraphHandle graph, Handle cond, GraphHandle body_graph, 264 GraphHandle after_graph); 265 266 /// \brief Create a custom operator. 267 /// 268 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 269 /// \param[in] graph The given function graph pointer handle. 270 /// \param[in] inputs An array of operator's input nodes. 271 /// \param[in] input_num The number of nodes in the array. 272 /// \param[in] info An CustomOpInfo struct which describes the information of custom operator. 273 /// 274 /// \return The created custom operator node. 275 MIND_C_API NodeHandle MSNewCustomOp(ResMgrHandle res_mgr, GraphHandle graph, Handle const inputs[], size_t input_num, 276 CustomOpInfo info); 277 278 /// \brief Get specified input node of Operator. 279 /// 280 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 281 /// \param[in] op The Operator. 282 /// \param[in] i The index of the input. 283 /// 284 /// \return The obtained input node handle. 285 MIND_C_API NodeHandle MSOpGetInput(ResMgrHandle res_mgr, ConstNodeHandle op, size_t i); 286 287 /// \brief Get the input nodes number of Operator. 288 /// 289 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 290 /// \param[in] op The Operator. 291 /// \param[in] error Records error code that indicate whether the functions executed successfully. 292 /// 293 /// \return The input nodes number. 294 MIND_C_API size_t MSOpGetInputsNum(ResMgrHandle res_mgr, ConstNodeHandle op, STATUS *error); 295 296 /// \brief Get all input nodes of the Operator. 297 /// 298 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 299 /// \param[in] op The Operator. 300 /// \param[in] inputs The array to contained the nodes' input. 301 /// \param[in] input_num The size of the input array. 302 /// 303 /// \return Error code that indicate whether the functions executed successfully. 304 MIND_C_API STATUS MSOpGetInputs(ResMgrHandle res_mgr, ConstNodeHandle op, NodeHandle inputs[], size_t input_num); 305 306 /// \brief Get dimension value of the infer shape from the given operator. 307 /// 308 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 309 /// \param[in] op The Operator. 310 /// \param[in] ret A pointer to the Error code that indicates whether the functions executed successfully. 311 /// 312 /// \return Dimension Value. 313 MIND_C_API size_t MSOpGetOutputDimension(ResMgrHandle res_mgr, ConstNodeHandle op, size_t output_index, STATUS *ret); 314 315 /// \brief Get shape vector of the infer shape from the given operator. 316 /// 317 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 318 /// \param[in] op The Operator. 319 /// \param[in] shape_ret The provided array for shape value storage. 320 /// \param[in] dim Dimenesion of shape, which also indicates the numbers of elements in the shape vector. 321 /// 322 /// \return Error code that indicates whether the functions executed successfully. 323 MIND_C_API STATUS MSOpGetOutputShape(ResMgrHandle res_mgr, ConstNodeHandle op, int64_t shape_ret[], size_t dim, 324 size_t output_index); 325 326 /// \brief Create a subgraph node. 327 /// 328 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 329 /// \param[in] graph The given function graph pointer handle. 330 /// \param[in] sub_graph The given sub function graph pointer handle. 331 /// \param[in] inputs An array of input nodes of the subgraph node. 332 /// \param[in] input_num The number of the input array. 333 /// 334 /// \return The created subgraph node handle. 335 MIND_C_API NodeHandle MSNewFuncCallNode(ResMgrHandle res_mgr, GraphHandle graph, ConstGraphHandle sub_graph, 336 Handle const inputs[], size_t input_num); 337 338 /// \brief Create a Placeholder node, which is usually the input of graph without data. 339 /// 340 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 341 /// \param[in] graph The given function graph pointer handle. 342 /// \param[in] type The data type of the Placeholder. 343 /// \param[in] shape The shape array. 344 /// \param[in] shape_size The size of shape, i.e., the dimension of the Placeholder. 345 /// 346 /// \return The created Placeholder node handle. 347 MIND_C_API NodeHandle MSNewPlaceholder(ResMgrHandle res_mgr, GraphHandle graph, DataTypeC type, const int64_t shape[], 348 size_t shape_size); 349 350 /// \brief Create a Variable node of tensor without shape, which contains variable scalar data. 351 /// 352 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 353 /// \param[in] graph The given function graph pointer handle. 354 /// \param[in] value The float scalar number. 355 /// 356 /// \return The created Variable node handle. 357 MIND_C_API NodeHandle MSNewVariableScalarFloat32(ResMgrHandle res_mgr, GraphHandle graph, float value); 358 359 /// \brief Create a Variable node of tensor without shape, which contains variable scalar data. 360 /// 361 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 362 /// \param[in] graph The given function graph pointer handle. 363 /// \param[in] value The int scalar number. 364 /// 365 /// \return The created Variable node handle. 366 MIND_C_API NodeHandle MSNewVariableScalarInt32(ResMgrHandle res_mgr, GraphHandle graph, int value); 367 368 /// \brief Create a Variable node of tensor, which contains variable array data. 369 /// 370 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 371 /// \param[in] graph The given function graph pointer handle. 372 /// \param[in] data The data address. 373 /// \param[in] shape The shape array. 374 /// \param[in] shape_size The size of shape, i.e., the dimension of the Variable. 375 /// \param[in] type The data type of the Variable. 376 /// \param[in] data_len The length of data. 377 /// 378 /// \return The created Variable node handle. 379 MIND_C_API NodeHandle MSNewVariableArray(ResMgrHandle res_mgr, GraphHandle graph, void *data, DataTypeC type, 380 const int64_t shape[], size_t shape_size, size_t data_len); 381 382 /// \brief Create a Variable node from a Tensor instance with data. 383 /// 384 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 385 /// \param[in] graph The given function graph pointer handle. 386 /// \param[in] tensor The given Tensor instance. 387 /// 388 /// \return The created Variable node handle. 389 MIND_C_API NodeHandle MSNewVariableFromTensor(ResMgrHandle res_mgr, GraphHandle graph, ConstTensorHandle tensor); 390 391 /// \brief Get data size of a Tensor Variable. 392 /// 393 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 394 /// \param[in] node The tensor variable node 395 /// \param[in] error Records error code that indicate whether the functions executed successfully. 396 /// 397 /// \return The data byte size. 398 MIND_C_API size_t MSVariableArrayGetDataSize(ResMgrHandle res_mgr, ConstNodeHandle node, STATUS *error); 399 400 /// \brief Get data from a Tensor Variable. 401 /// 402 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 403 /// \param[in] node The tensor variable node 404 /// 405 /// \return The data. 406 MIND_C_API void *MSVariableArrayGetData(ResMgrHandle res_mgr, ConstNodeHandle node); 407 408 /// \brief Create a Constant node of tensor, which contains constant tensor data. 409 /// 410 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 411 /// \param[in] data The data address. 412 /// \param[in] shape The shape array. 413 /// \param[in] shape_size The size of shape, i.e., the dimension of the Constant. 414 /// \param[in] type The data type of the Constant. 415 /// \param[in] data_len The length of data. 416 /// 417 /// \return The created Constant node handle. 418 MIND_C_API NodeHandle MSNewConstantArray(ResMgrHandle res_mgr, void *data, DataTypeC type, const int64_t shape[], 419 size_t shape_size, size_t data_len); 420 421 /// \brief Create a Constant node from a Tensor instance with data. 422 /// 423 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 424 /// \param[in] tensor The given Tensor instance. 425 /// 426 /// \return The created Constant node handle. 427 MIND_C_API NodeHandle MSNewConstantFromTensor(ResMgrHandle res_mgr, TensorHandle tensor); 428 429 /// \brief Get data size of a Tensor Constant. 430 /// 431 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 432 /// \param[in] node The tensor constant node 433 /// \param[in] error Records error code that indicate whether the functions executed successfully. 434 /// 435 /// \return The data byte size. 436 MIND_C_API size_t MSConstantArrayGetDataSize(ResMgrHandle res_mgr, ConstNodeHandle node, STATUS *error); 437 438 /// \brief Get data from a Tensor Constant. 439 /// 440 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 441 /// \param[in] node The tensor constant node 442 /// 443 /// \return The data. 444 MIND_C_API void *MSConstantArrayGetData(ResMgrHandle res_mgr, ConstNodeHandle node); 445 446 /// \brief Create Constant node of a float scalar. 447 /// 448 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 449 /// \param[in] value The float32 scalar value. 450 /// 451 /// \return The created Constant node handle. 452 MIND_C_API NodeHandle MSNewConstantScalarFloat32(ResMgrHandle res_mgr, float value); 453 454 /// \brief Create Constant node of a bool scalar. 455 /// 456 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 457 /// \param[in] value The bool scalar value. 458 /// 459 /// \return The created Constant node handle. 460 MIND_C_API NodeHandle MSNewConstantScalarBool(ResMgrHandle res_mgr, bool value); 461 462 /// \brief Create Constant node of a int32 scalar. 463 /// 464 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 465 /// \param[in] value The int32 scalar value. 466 /// 467 /// \return The created Constant node handle. 468 MIND_C_API NodeHandle MSNewConstantScalarInt32(ResMgrHandle res_mgr, int value); 469 470 /// \brief Create Constant node of a int64 scalar. 471 /// 472 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 473 /// \param[in] value The int64 scalar value. 474 /// 475 /// \return The created Constant node handle. 476 MIND_C_API NodeHandle MSNewConstantScalarInt64(ResMgrHandle res_mgr, int64_t value); 477 478 /// \brief Create Constant node of a int64 tuple. 479 /// 480 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 481 /// \param[in] vec The array of int64 value. 482 /// \param[in] vec The size of the value. 483 /// 484 /// \return The created Constant node handle. 485 MIND_C_API NodeHandle MSNewConstantTupleInt64(ResMgrHandle res_mgr, const int64_t vec[], size_t size); 486 487 /// \brief Create Constant node of a string. 488 /// 489 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 490 /// \param[in] str The string. 491 /// 492 /// \return The created Constant node handle. 493 MIND_C_API NodeHandle MSNewConstantString(ResMgrHandle res_mgr, const char *str); 494 495 /// \brief Create Constant node of a type. 496 /// 497 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 498 /// \param[in] str The type. 499 /// 500 /// \return The created Constant node handle. 501 MIND_C_API NodeHandle MSNewConstantType(ResMgrHandle res_mgr, DataTypeC type); 502 503 /// \brief Get value from the int32 scalar Constant node. 504 /// 505 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 506 /// \param[in] node The Constant node. 507 /// \param[in] error Records error code that indicate whether the functions executed successfully. 508 /// 509 /// \return The obtained int32 value. 510 MIND_C_API int MSConstantScalarGetValueInt32(ResMgrHandle res_mgr, ConstNodeHandle node, STATUS *error); 511 512 /// \brief Get value from the float32 scalar Constant node. 513 /// 514 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 515 /// \param[in] node The Constant node. 516 /// \param[in] error Records error code that indicate whether the functions executed successfully. 517 /// 518 /// \return The obtained float32 value. 519 MIND_C_API float MSConstantScalarGetValueFloat32(ResMgrHandle res_mgr, ConstNodeHandle node, STATUS *error); 520 521 /// \brief Get value from the bool scalar Constant node. 522 /// 523 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 524 /// \param[in] node The Constant node. 525 /// \param[in] error Records error code that indicate whether the functions executed successfully. 526 /// 527 /// \return The obtained bool value. 528 MIND_C_API bool MSConstantScalarGetValueBool(ResMgrHandle res_mgr, ConstNodeHandle node, STATUS *error); 529 530 /// \brief Get value from the int64 scalar Constant node. 531 /// 532 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 533 /// \param[in] node The Constant node. 534 /// \param[in] error Records error code that indicate whether the functions executed successfully. 535 /// 536 /// \return The obtained int64 value. 537 MIND_C_API int64_t MSConstantScalarGetValueInt64(ResMgrHandle res_mgr, ConstNodeHandle node, STATUS *error); 538 539 /// \brief Get value from the string Constant node. 540 /// 541 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 542 /// \param[in] node The Constant node. 543 /// \param[in] str_buf The char array to contain the string. 544 /// \param[in] str_len The size of the char array. 545 /// 546 /// \return The error code that indicate whether the functions executed successfully. 547 MIND_C_API STATUS MSConstantStringGetValue(ResMgrHandle res_mgr, ConstNodeHandle node, char str_buf[], size_t str_len); 548 549 /// \brief Get value from the tuple Constant node. 550 /// 551 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 552 /// \param[in] node The Constant node. 553 /// \param[in] error Records error code that indicate whether the functions executed successfully. 554 /// 555 /// \return The size of the Tuple. 556 MIND_C_API size_t MSConstantTupleGetSize(ResMgrHandle res_mgr, ConstNodeHandle node, STATUS *error); 557 558 /// \brief Get value from the Tuple Constant node. 559 /// 560 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 561 /// \param[in] node The Constant node. 562 /// \param[in] vec The int64 array to contain the value. 563 /// \param[in] size The size of the value vector. 564 /// 565 /// \return The error code that indicate whether the functions executed successfully. 566 MIND_C_API STATUS MSConstantTupleGetValueInt64(ResMgrHandle res_mgr, ConstNodeHandle node, int64_t vec[], size_t size); 567 568 /// \brief Get value from the Type Constant node. 569 /// 570 /// \param[in] res_mgr Resource manager that saves allocated instance resources. 571 /// \param[in] node The Constant node. 572 /// \param[in] error Records error code that indicate whether the functions executed successfully. 573 /// 574 /// \return The obtained type value. 575 MIND_C_API DataTypeC MSConstantTypeGetValue(ResMgrHandle res_mgr, ConstNodeHandle node, STATUS *error); 576 577 /// \brief Run single op in eager way. 578 /// 579 /// \param[in] op_type The primitive name. 580 /// \param[in] inputs An array of operator's input nodes. 581 /// \param[in] input_num The number of nodes in the array. 582 /// \param[in] outputs An array to store outputs tensor which is allocated by used. 583 /// \param[in] output_num The number of outputs. 584 /// 585 /// \return Error code indicates whether the function executed successfully. 586 MIND_C_API STATUS MSRunOp(ResMgrHandle res_mgr, const char *op_type, TensorHandle const inputs[], size_t input_num, 587 TensorHandle outputs[], size_t output_num); 588 589 /// \brief Run single op with extra information in eager way. 590 /// 591 /// \param[in] op_type The primitive name. 592 /// \param[in] inputs An array of operator's input nodes. 593 /// \param[in] input_num The number of nodes in the array. 594 /// \param[in] outputs An array to store outputs tensor which is allocated by used. 595 /// \param[in] output_num The number of outputs. 596 /// \param[in] extra_info A struct that holds the extra information 597 /// 598 /// \return Error code indicates whether the function executed successfully. 599 MIND_C_API STATUS MSRunOpWithInfo(ResMgrHandle res_mgr, const char *op_type, TensorHandle const inputs[], 600 size_t input_num, TensorHandle outputs[], size_t output_num, 601 DynamicOpInfo extra_info); 602 603 #ifdef __cplusplus 604 } 605 #endif 606 #endif // MINDSPORE_CCSRC_C_API_INCLUDE_NODE_H_ 607