You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

model_c.h 5.6 kB

4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * Copyright 2021 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. #ifndef MINDSPORE_INCLUDE_C_API_MODEL_C_H
  17. #define MINDSPORE_INCLUDE_C_API_MODEL_C_H
  18. #include "include/c_api/tensor_c.h"
  19. #include "include/c_api/context_c.h"
  20. #include "include/c_api/status_c.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. typedef void *MSModelHandle;
  25. typedef struct MSTensorHandleArray {
  26. size_t handle_num;
  27. MSTensorHandle *handle_list;
  28. } MSTensorHandleArray;
  29. #define MS_MAX_SHAPE_NUM 32
  30. typedef struct MSShapeInfo {
  31. size_t shape_num;
  32. int64_t shape[MS_MAX_SHAPE_NUM];
  33. } MSShapeInfo;
  34. typedef struct MSCallBackParamC {
  35. char *node_name;
  36. char *node_type;
  37. } MSCallBackParamC;
  38. typedef bool (*MSKernelCallBackC)(const MSTensorHandleArray inputs, const MSTensorHandleArray outputs,
  39. const MSCallBackParamC kernel_Info);
  40. /// \brief Create a model object. Only valid for Lite.
  41. ///
  42. /// \return Model object handle.
  43. MS_API MSModelHandle MSModelCreate();
  44. /// \brief Destroy the model object. Only valid for Lite.
  45. ///
  46. /// \param[in] model Model object handle address.
  47. MS_API void MSModelDestroy(MSModelHandle *model);
  48. /// \brief Set workspace for the model object. Only valid for Iot.
  49. ///
  50. /// \param[in] model Model object handle.
  51. /// \param[in] workspace Define the workspace address.
  52. /// \param[in] workspace_size Define the workspace size.
  53. MS_API void MSModelSetWorkspace(MSModelHandle model, void *workspace, size_t workspace_size);
  54. /// \brief Build the model from model file buffer so that it can run on a device. Only valid for Lite.
  55. ///
  56. /// \param[in] model Model object handle.
  57. /// \param[in] model_data Define the buffer read from a model file.
  58. /// \param[in] data_size Define bytes number of model file buffer.
  59. /// \param[in] model_type Define The type of model file.
  60. /// \param[in] model_context Define the context used to store options during execution.
  61. ///
  62. /// \return MSStatus.
  63. MS_API MSStatus MSModelBuild(MSModelHandle model, const void *model_data, size_t data_size, MSModelType model_type,
  64. const MSContextHandle model_context);
  65. /// \brief Load and build the model from model path so that it can run on a device. Only valid for Lite.
  66. ///
  67. /// \param[in] model Model object handle.
  68. /// \param[in] model_path Define the model file path.
  69. /// \param[in] model_type Define The type of model file.
  70. /// \param[in] model_context Define the context used to store options during execution.
  71. ///
  72. /// \return MSStatus.
  73. MS_API MSStatus MSModelBuildFromFile(MSModelHandle model, const char *model_path, MSModelType model_type,
  74. const MSContextHandle model_context);
  75. /// \brief Resizes the shapes of inputs.
  76. ///
  77. /// \param[in] model Model object handle.
  78. /// \param[in] inputs The array that includes all input tensor handles.
  79. /// \param[in] shape_infos Defines the new shapes of inputs, should be consistent with inputs.
  80. /// \param[in] shape_info_num The num of shape_infos.
  81. ///
  82. /// \return MSStatus.
  83. MS_API MSStatus MSModelResize(MSModelHandle model, const MSTensorHandleArray inputs, MSShapeInfo *shape_infos,
  84. size_t shape_info_num);
  85. /// \brief Inference model.
  86. ///
  87. /// \param[in] model Model object handle.
  88. /// \param[in] inputs The array that includes all input tensor handles.
  89. /// \param[out] outputs The array that includes all output tensor handles.
  90. /// \param[in] before CallBack before predict.
  91. /// \param[in] after CallBack after predict.
  92. ///
  93. /// \return MSStatus.
  94. MS_API MSStatus MSModelPredict(MSModelHandle model, const MSTensorHandleArray inputs, MSTensorHandleArray *outputs,
  95. const MSKernelCallBackC before, const MSKernelCallBackC after);
  96. /// \brief Obtains all input tensor handles of the model.
  97. ///
  98. /// \param[in] model Model object handle.
  99. ///
  100. /// \return The array that includes all input tensor handles.
  101. MS_API MSTensorHandleArray MSModelGetInputs(const MSModelHandle model);
  102. /// \brief Obtains all output tensor handles of the model.
  103. ///
  104. /// \param[in] model Model object handle.
  105. ///
  106. /// \return The array that includes all output tensor handles.
  107. MS_API MSTensorHandleArray MSModelGetOutputs(const MSModelHandle model);
  108. /// \brief Obtains the input tensor handle of the model by name.
  109. ///
  110. /// \param[in] model Model object handle.
  111. /// \param[in] tensor_name The name of tensor.
  112. ///
  113. /// \return The input tensor handle with the given name, if the name is not found, an NULL is returned.
  114. MS_API MSTensorHandle MSModelGetInputByTensorName(const MSModelHandle model, const char *tensor_name);
  115. /// \brief Obtains the output tensor handle of the model by name.
  116. ///
  117. /// \param[in] model Model object handle.
  118. /// \param[in] tensor_name The name of tensor.
  119. ///
  120. /// \return The output tensor handle with the given name, if the name is not found, an NULL is returned.
  121. MS_API MSTensorHandle MSModelGetOutputByTensorName(const MSModelHandle model, const char *tensor_name);
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #endif // MINDSPORE_INCLUDE_C_API_MODEL_C_H