pd_predictor.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. ///
  15. /// \file pd_predictor.h
  16. ///
  17. /// \brief interface for paddle predictor
  18. ///
  19. /// \author paddle-infer@baidu.com
  20. /// \date 2021-04-21
  21. /// \since 2.1
  22. ///
  23. #pragma once
  24. #include "pd_common.h" // NOLINT
  25. typedef struct PD_Predictor PD_Predictor;
  26. typedef struct PD_Config PD_Config;
  27. typedef struct PD_Tensor PD_Tensor;
  28. typedef struct PD_OneDimArrayCstr PD_OneDimArrayCstr;
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. ///
  33. /// \brief Create a new Predictor
  34. ///
  35. /// \param[in] Config config
  36. /// \return new predicor.
  37. ///
  38. PADDLE_CAPI_EXPORT extern __pd_give PD_Predictor* PD_PredictorCreate(
  39. __pd_take PD_Config* pd_config);
  40. ///
  41. /// \brief Clone a new Predictor
  42. ///
  43. /// \param[in] pd_predictor predictor
  44. /// \return new predictor.
  45. ///
  46. PADDLE_CAPI_EXPORT extern __pd_give PD_Predictor* PD_PredictorClone(
  47. __pd_keep PD_Predictor* pd_predictor);
  48. ///
  49. /// \brief Get the input names
  50. ///
  51. /// \param[in] pd_predictor predictor
  52. /// \return input names
  53. ///
  54. PADDLE_CAPI_EXPORT extern __pd_give PD_OneDimArrayCstr*
  55. PD_PredictorGetInputNames(__pd_keep PD_Predictor* pd_predictor);
  56. ///
  57. /// \brief Get the output names
  58. ///
  59. /// \param[in] pd_predictor predictor
  60. /// \return output names
  61. ///
  62. PADDLE_CAPI_EXPORT extern __pd_give PD_OneDimArrayCstr*
  63. PD_PredictorGetOutputNames(__pd_keep PD_Predictor* pd_predictor);
  64. ///
  65. /// \brief Get the input number
  66. ///
  67. /// \param[in] pd_predictor predictor
  68. /// \return input number
  69. ///
  70. PADDLE_CAPI_EXPORT extern size_t PD_PredictorGetInputNum(
  71. __pd_keep PD_Predictor* pd_predictor);
  72. ///
  73. /// \brief Get the output number
  74. ///
  75. /// \param[in] pd_predictor predictor
  76. /// \return output number
  77. ///
  78. PADDLE_CAPI_EXPORT extern size_t PD_PredictorGetOutputNum(
  79. __pd_keep PD_Predictor* pd_predictor);
  80. ///
  81. /// \brief Get the Input Tensor object
  82. ///
  83. /// \param[in] pd_predictor predictor
  84. /// \param[in] name input name
  85. /// \return input tensor
  86. ///
  87. PADDLE_CAPI_EXPORT extern __pd_give PD_Tensor* PD_PredictorGetInputHandle(
  88. __pd_keep PD_Predictor* pd_predictor, const char* name);
  89. ///
  90. /// \brief Get the Output Tensor object
  91. ///
  92. /// \param[in] pd_predictor predictor
  93. /// \param[in] name output name
  94. /// \return output tensor
  95. ///
  96. PADDLE_CAPI_EXPORT extern __pd_give PD_Tensor* PD_PredictorGetOutputHandle(
  97. __pd_keep PD_Predictor* pd_predictor, const char* name);
  98. ///
  99. /// \brief Run the prediction engine
  100. ///
  101. /// \param[in] pd_predictor predictor
  102. /// \return Whether the function executed successfully
  103. ///
  104. PADDLE_CAPI_EXPORT extern PD_Bool PD_PredictorRun(
  105. __pd_keep PD_Predictor* pd_predictor);
  106. /// \brief Clear the intermediate tensors of the predictor
  107. ///
  108. /// \param[in] pd_predictor predictor
  109. ///
  110. PADDLE_CAPI_EXPORT extern void PD_PredictorClearIntermediateTensor(
  111. __pd_keep PD_Predictor* pd_predictor);
  112. ///
  113. /// \brief Release all tmp tensor to compress the size of the memory pool.
  114. /// The memory pool is considered to be composed of a list of chunks, if
  115. /// the chunk is not occupied, it can be released.
  116. ///
  117. /// \param[in] pd_predictor predictor
  118. /// \return Number of bytes released. It may be smaller than the actual
  119. /// released memory, because part of the memory is not managed by the
  120. /// MemoryPool.
  121. ///
  122. PADDLE_CAPI_EXPORT extern uint64_t PD_PredictorTryShrinkMemory(
  123. __pd_keep PD_Predictor* pd_predictor);
  124. ///
  125. /// \brief Destroy a predictor object
  126. ///
  127. /// \param[in] pd_predictor predictor
  128. ///
  129. PADDLE_CAPI_EXPORT extern void PD_PredictorDestroy(
  130. __pd_take PD_Predictor* pd_predictor);
  131. ///
  132. /// \brief Get version info.
  133. ///
  134. /// \return version
  135. ///
  136. PADDLE_CAPI_EXPORT extern const char* PD_GetVersion();
  137. #ifdef __cplusplus
  138. } // extern "C"
  139. #endif