pd_config.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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_config.h
  16. ///
  17. /// \brief interface for paddle config
  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. #include "pd_types.h" // NOLINT
  26. typedef struct PD_Config PD_Config;
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. ///
  31. /// \brief Create a paddle config
  32. ///
  33. /// \return new config.
  34. ///
  35. PADDLE_CAPI_EXPORT extern __pd_give PD_Config* PD_ConfigCreate();
  36. ///
  37. /// \brief Destroy the paddle config
  38. ///
  39. /// \param[in] pd_onfig config
  40. ///
  41. PADDLE_CAPI_EXPORT extern void PD_ConfigDestroy(__pd_take PD_Config* pd_config);
  42. ///
  43. /// \brief Set the combined model with two specific pathes for program and
  44. /// parameters.
  45. ///
  46. /// \param[in] pd_onfig config
  47. /// \param[in] prog_file_path model file path of the combined model.
  48. /// \param[in] params_file_path params file path of the combined model.
  49. ///
  50. PADDLE_CAPI_EXPORT extern void PD_ConfigSetModel(__pd_keep PD_Config* pd_config,
  51. const char* prog_file_path,
  52. const char* params_file_path);
  53. ///
  54. /// \brief Set the model file path of a combined model.
  55. ///
  56. /// \param[in] pd_onfig config
  57. /// \param[in] prog_file_path model file path.
  58. ///
  59. PADDLE_CAPI_EXPORT extern void PD_ConfigSetProgFile(
  60. __pd_keep PD_Config* pd_config, const char* prog_file_path);
  61. ///
  62. /// \brief Set the params file path of a combined model.
  63. ///
  64. /// \param[in] pd_onfig config
  65. /// \param[in] params_file_path params file path.
  66. ///
  67. PADDLE_CAPI_EXPORT extern void PD_ConfigSetParamsFile(
  68. __pd_keep PD_Config* pd_config, const char* params_file_path);
  69. ///
  70. /// \brief Set the path of optimization cache directory.
  71. /// \param[in] pd_onfig config
  72. /// \param[in] opt_cache_dir the path of optimization cache directory.
  73. ///
  74. PADDLE_CAPI_EXPORT extern void PD_ConfigSetOptimCacheDir(
  75. __pd_keep PD_Config* pd_config, const char* opt_cache_dir);
  76. ///
  77. /// \brief Set the no-combined model dir path.
  78. /// \param[in] pd_onfig config
  79. /// \param[in] model_dir model dir path.
  80. ///
  81. PADDLE_CAPI_EXPORT extern void PD_ConfigSetModelDir(
  82. __pd_keep PD_Config* pd_config, const char* model_dir);
  83. ///
  84. /// \brief Get the model directory path.
  85. ///
  86. /// \param[in] pd_onfig config
  87. /// \return The model directory path.
  88. ///
  89. PADDLE_CAPI_EXPORT extern const char* PD_ConfigGetModelDir(
  90. __pd_keep PD_Config* pd_config);
  91. ///
  92. /// \brief Get the program file path.
  93. ///
  94. /// \param[in] pd_onfig config
  95. /// \return The program file path.
  96. ///
  97. PADDLE_CAPI_EXPORT extern const char* PD_ConfigGetProgFile(
  98. __pd_keep PD_Config* pd_config);
  99. ///
  100. /// \brief Get the params file path.
  101. ///
  102. /// \param[in] pd_onfig config
  103. /// \return The params file path.
  104. ///
  105. PADDLE_CAPI_EXPORT extern const char* PD_ConfigGetParamsFile(
  106. __pd_keep PD_Config* pd_config);
  107. ///
  108. /// \brief Turn off FC Padding.
  109. ///
  110. /// \param[in] pd_onfig config
  111. ///
  112. PADDLE_CAPI_EXPORT extern void PD_ConfigDisableFCPadding(
  113. __pd_keep PD_Config* pd_config);
  114. ///
  115. /// \brief A boolean state telling whether fc padding is used.
  116. ///
  117. /// \param[in] pd_onfig config
  118. /// \return Whether fc padding is used.
  119. ///
  120. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigUseFcPadding(
  121. __pd_keep PD_Config* pd_config);
  122. ///
  123. /// \brief Turn on GPU.
  124. ///
  125. /// \param[in] pd_onfig config
  126. /// \param[in] memory_pool_init_size_mb initial size of the GPU memory pool in
  127. /// MB.
  128. /// \param[in] device_id device_id the GPU card to use.
  129. ///
  130. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableUseGpu(
  131. __pd_keep PD_Config* pd_config,
  132. uint64_t memory_pool_init_size_mb,
  133. int32_t device_id);
  134. ///
  135. /// \brief Turn off GPU.
  136. ///
  137. /// \param[in] pd_onfig config
  138. ///
  139. PADDLE_CAPI_EXPORT extern void PD_ConfigDisableGpu(
  140. __pd_keep PD_Config* pd_config);
  141. ///
  142. /// \brief A boolean state telling whether the GPU is turned on.
  143. ///
  144. /// \brief Turn off GPU.
  145. /// \return Whether the GPU is turned on.
  146. ///
  147. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigUseGpu(
  148. __pd_keep PD_Config* pd_config);
  149. ///
  150. /// \brief Turn on ONNXRuntime.
  151. ///
  152. /// \param[in] pd_onfig config
  153. ///
  154. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableONNXRuntime(
  155. __pd_keep PD_Config* pd_config);
  156. ///
  157. /// \brief Turn off ONNXRuntime.
  158. ///
  159. /// \param[in] pd_onfig config
  160. ///
  161. PADDLE_CAPI_EXPORT extern void PD_ConfigDisableONNXRuntime(
  162. __pd_keep PD_Config* pd_config);
  163. ///
  164. /// \brief A boolean state telling whether the ONNXRutnime is turned on.
  165. ///
  166. /// \return Whether the ONNXRuntime is turned on.
  167. ///
  168. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigONNXRuntimeEnabled(
  169. __pd_keep PD_Config* pd_config);
  170. ///
  171. /// \brief Turn on ONNXRuntime Optimization.
  172. ///
  173. /// \param[in] pd_onfig config
  174. ///
  175. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableORTOptimization(
  176. __pd_keep PD_Config* pd_config);
  177. ///
  178. /// \brief Turn on XPU.
  179. ///
  180. /// \param[in] pd_onfig config
  181. /// \param l3_workspace_size The size of the video memory allocated by the l3
  182. /// cache, the maximum is 16M.
  183. /// \param locked Whether the allocated L3 cache can be locked. If false,
  184. /// it means that the L3 cache is not locked, and the allocated L3
  185. /// cache can be shared by multiple models, and multiple models
  186. /// sharing the L3 cache will be executed sequentially on the card.
  187. /// \param autotune Whether to autotune the conv operator in the model. If
  188. /// true, when the conv operator of a certain dimension is executed
  189. /// for the first time, it will automatically search for a better
  190. /// algorithm to improve the performance of subsequent conv operators
  191. /// of the same dimension.
  192. /// \param autotune_file Specify the path of the autotune file. If
  193. /// autotune_file is specified, the algorithm specified in the
  194. /// file will be used and autotune will not be performed again.
  195. /// \param precision Calculation accuracy of multi_encoder
  196. /// \param adaptive_seqlen Is the input of multi_encoder variable length
  197. ///
  198. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableXpu(
  199. __pd_keep PD_Config* pd_config,
  200. int32_t l3_workspace_size,
  201. PD_Bool locked,
  202. PD_Bool autotune,
  203. const char* autotune_file,
  204. const char* precision,
  205. PD_Bool adaptive_seqlen);
  206. ///
  207. /// \brief Turn on NPU.
  208. ///
  209. /// \param[in] pd_onfig config
  210. /// \param[in] device_id device_id the NPU card to use.
  211. ///
  212. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableNpu(
  213. __pd_keep PD_Config* pd_config, int32_t device_id);
  214. ///
  215. /// \brief A boolean state telling whether the XPU is turned on.
  216. ///
  217. /// \param[in] pd_onfig config
  218. /// \return Whether the XPU is turned on.
  219. ///
  220. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigUseXpu(
  221. __pd_keep PD_Config* pd_config);
  222. ///
  223. /// \brief A boolean state telling whether the NPU is turned on.
  224. ///
  225. /// \param[in] pd_onfig config
  226. /// \return Whether the NPU is turned on.
  227. ///
  228. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigUseNpu(
  229. __pd_keep PD_Config* pd_config);
  230. ///
  231. /// \brief Get the GPU device id.
  232. ///
  233. /// \param[in] pd_onfig config
  234. /// \return The GPU device id.
  235. ///
  236. PADDLE_CAPI_EXPORT extern int32_t PD_ConfigGpuDeviceId(
  237. __pd_keep PD_Config* pd_config);
  238. ///
  239. /// \brief Get the XPU device id.
  240. ///
  241. /// \param[in] pd_onfig config
  242. /// \return The XPU device id.
  243. ///
  244. PADDLE_CAPI_EXPORT extern int32_t PD_ConfigXpuDeviceId(
  245. __pd_keep PD_Config* pd_config);
  246. ///
  247. /// \brief Get the NPU device id.
  248. ///
  249. /// \param[in] pd_onfig config
  250. /// \return The NPU device id.
  251. ///
  252. PADDLE_CAPI_EXPORT extern int32_t PD_ConfigNpuDeviceId(
  253. __pd_keep PD_Config* pd_config);
  254. ///
  255. /// \brief Get the initial size in MB of the GPU memory pool.
  256. ///
  257. /// \param[in] pd_onfig config
  258. /// \return The initial size in MB of the GPU memory pool.
  259. ///
  260. PADDLE_CAPI_EXPORT extern int32_t PD_ConfigMemoryPoolInitSizeMb(
  261. __pd_keep PD_Config* pd_config);
  262. ///
  263. /// \brief Get the proportion of the initial memory pool size compared to the
  264. /// device.
  265. ///
  266. /// \param[in] pd_onfig config
  267. /// \return The proportion of the initial memory pool size.
  268. ///
  269. PADDLE_CAPI_EXPORT extern float PD_ConfigFractionOfGpuMemoryForPool(
  270. __pd_keep PD_Config* pd_config);
  271. ///
  272. /// \brief Turn on CUDNN.
  273. ///
  274. /// \param[in] pd_onfig config
  275. ///
  276. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableCudnn(
  277. __pd_keep PD_Config* pd_config);
  278. ///
  279. /// \brief A boolean state telling whether to use CUDNN.
  280. ///
  281. /// \param[in] pd_onfig config
  282. /// \return Whether to use CUDNN.
  283. ///
  284. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigCudnnEnabled(
  285. __pd_keep PD_Config* pd_config);
  286. ///
  287. /// \brief Control whether to perform IR graph optimization.
  288. /// If turned off, the AnalysisConfig will act just like a NativeConfig.
  289. ///
  290. /// \param[in] pd_onfig config
  291. /// \param[in] x Whether the ir graph optimization is actived.
  292. ///
  293. PADDLE_CAPI_EXPORT extern void PD_ConfigSwitchIrOptim(
  294. __pd_keep PD_Config* pd_config, PD_Bool x);
  295. ///
  296. /// \brief A boolean state telling whether the ir graph optimization is
  297. /// actived.
  298. ///
  299. /// \param[in] pd_onfig config
  300. /// \return Whether to use ir graph optimization.
  301. ///
  302. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigIrOptim(
  303. __pd_keep PD_Config* pd_config);
  304. ///
  305. /// \brief Turn on the TensorRT engine.
  306. /// The TensorRT engine will accelerate some subgraphes in the original Fluid
  307. /// computation graph. In some models such as resnet50, GoogleNet and so on,
  308. /// it gains significant performance acceleration.
  309. ///
  310. /// \param[in] pd_onfig config
  311. /// \param[in] workspace_size The memory size(in byte) used for TensorRT
  312. /// workspace.
  313. /// \param[in] max_batch_size The maximum batch size of this prediction task,
  314. /// better set as small as possible for less performance loss.
  315. /// \param[in] min_subgrpah_size The minimum TensorRT subgraph size needed, if a
  316. /// subgraph is smaller than this, it will not be transferred to TensorRT
  317. /// engine.
  318. /// \param[in] precision The precision used in TensorRT.
  319. /// \param[in] use_static Serialize optimization information to disk for
  320. /// reusing.
  321. /// \param[in] use_calib_mode Use TRT int8 calibration(post training
  322. /// quantization).
  323. ///
  324. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableTensorRtEngine(
  325. __pd_keep PD_Config* pd_config,
  326. int64_t workspace_size,
  327. int32_t max_batch_size,
  328. int32_t min_subgraph_size,
  329. PD_PrecisionType precision,
  330. PD_Bool use_static,
  331. PD_Bool use_calib_mode);
  332. ///
  333. /// \brief A boolean state telling whether the TensorRT engine is used.
  334. ///
  335. /// \param[in] pd_onfig config
  336. /// \return Whether the TensorRT engine is used.
  337. ///
  338. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigTensorRtEngineEnabled(
  339. __pd_keep PD_Config* pd_config);
  340. ///
  341. /// \brief Set min, max, opt shape for TensorRT Dynamic shape mode.
  342. ///
  343. /// \param[in] pd_onfig config
  344. /// \param[in] tensor_num The number of the subgraph input.
  345. /// \param[in] tensor_name The name of every subgraph input.
  346. /// \param[in] shapes_num The shape size of every subgraph input.
  347. /// \param[in] min_shape The min input shape of every subgraph input.
  348. /// \param[in] max_shape The max input shape of every subgraph input.
  349. /// \param[in] optim_shape The opt input shape of every subgraph input.
  350. /// \param[in] disable_trt_plugin_fp16 Setting this parameter to true means that
  351. /// TRT plugin will not run fp16.
  352. ///
  353. PADDLE_CAPI_EXPORT extern void PD_ConfigSetTrtDynamicShapeInfo(
  354. __pd_keep PD_Config* pd_config,
  355. size_t tensor_num,
  356. const char** tensor_name,
  357. size_t* shapes_num,
  358. int32_t** min_shape,
  359. int32_t** max_shape,
  360. int32_t** optim_shape,
  361. PD_Bool disable_trt_plugin_fp16);
  362. ///
  363. /// \brief A boolean state telling whether the trt dynamic_shape is used.
  364. ///
  365. /// \param[in] pd_onfig config
  366. ///
  367. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigTensorRtDynamicShapeEnabled(
  368. __pd_keep PD_Config* pd_config);
  369. ///
  370. /// \brief Enable tuned tensorrt dynamic shape.
  371. ///
  372. /// \param[in] pd_onfig config
  373. /// \param[in] shape_range_info_path the path to shape_info file got in
  374. /// CollectShapeInfo mode.
  375. /// \param[in] allow_build_at_runtime allow build trt engine at runtime.
  376. ///
  377. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableTunedTensorRtDynamicShape(
  378. __pd_keep PD_Config* pd_config,
  379. const char* shape_range_info_path,
  380. PD_Bool allow_build_at_runtime);
  381. ///
  382. /// \brief A boolean state telling whether to use tuned tensorrt dynamic
  383. /// shape.
  384. ///
  385. /// \param[in] pd_onfig config
  386. ///
  387. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigTunedTensorRtDynamicShape(
  388. __pd_keep PD_Config* pd_config);
  389. ///
  390. /// \brief A boolean state telling whether to allow building trt engine at
  391. /// runtime.
  392. ///
  393. /// \param[in] pd_onfig config
  394. ///
  395. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigTrtAllowBuildAtRuntime(
  396. __pd_keep PD_Config* pd_config);
  397. ///
  398. /// \brief Collect shape info of all tensors in compute graph.
  399. ///
  400. /// \param[in] pd_onfig config
  401. /// \param[in] shape_range_info_path the path to save shape info.
  402. ///
  403. PADDLE_CAPI_EXPORT extern void PD_ConfigCollectShapeRangeInfo(
  404. __pd_keep PD_Config* pd_config, const char* shape_range_info_path);
  405. ///
  406. /// \brief the shape info path in CollectShapeInfo mode.
  407. /// Attention, Please release the string manually.
  408. ///
  409. /// \param[in] pd_onfig config
  410. ///
  411. PADDLE_CAPI_EXPORT extern const char* PD_ConfigShapeRangeInfoPath(
  412. __pd_keep PD_Config* pd_config);
  413. ///
  414. /// \brief A boolean state telling whether to collect shape info.
  415. ///
  416. /// \param[in] pd_onfig config
  417. ///
  418. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigShapeRangeInfoCollected(
  419. __pd_keep PD_Config* pd_config);
  420. ///
  421. /// \brief Prevent ops running in Paddle-TRT
  422. /// NOTE: just experimental, not an official stable API, easy to be broken.
  423. ///
  424. /// \param[in] pd_onfig config
  425. /// \param[in] ops_num ops number
  426. /// \param[in] ops_name ops name
  427. ///
  428. PADDLE_CAPI_EXPORT extern void PD_ConfigDisableTensorRtOPs(
  429. __pd_keep PD_Config* pd_config, size_t ops_num, const char** ops_name);
  430. ///
  431. /// \brief Replace some TensorRT plugins to TensorRT OSS(
  432. /// https://github.com/NVIDIA/TensorRT), with which some models's inference
  433. /// may be more high-performance. Libnvinfer_plugin.so greater than
  434. /// V7.2.1 is needed.
  435. ///
  436. /// \param[in] pd_onfig config
  437. ///
  438. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableVarseqlen(
  439. __pd_keep PD_Config* pd_config);
  440. ///
  441. /// \brief A boolean state telling whether to use the TensorRT OSS.
  442. ///
  443. /// \param[in] pd_onfig config
  444. /// \return Whether to use the TensorRT OSS.
  445. ///
  446. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigTensorRtOssEnabled(
  447. __pd_keep PD_Config* pd_config);
  448. ///
  449. /// \brief Enable TensorRT DLA
  450. ///
  451. /// \param[in] pd_onfig config
  452. /// \param[in] dla_core ID of DLACore, which should be 0, 1,
  453. /// ..., IBuilder.getNbDLACores() - 1
  454. ///
  455. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableTensorRtDla(
  456. __pd_keep PD_Config* pd_config, int32_t dla_core);
  457. ///
  458. /// \brief A boolean state telling whether to use the TensorRT DLA.
  459. ///
  460. /// \param[in] pd_onfig config
  461. /// \return Whether to use the TensorRT DLA.
  462. ///
  463. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigTensorRtDlaEnabled(
  464. __pd_keep PD_Config* pd_config);
  465. ///
  466. /// \brief Turn on the usage of Lite sub-graph engine.
  467. ///
  468. /// \param[in] pd_onfig config
  469. /// \param[in] precision Precion used in Lite sub-graph engine.
  470. /// \param[in] zero_copy whether use zero copy.
  471. /// \param[in] passes_filter_num The number of passes used in Lite sub-graph
  472. /// engine.
  473. /// \param[in] passes_filter The name of passes used in Lite sub-graph engine.
  474. /// \param[in] ops_filter_num The number of operators not supported by Lite.
  475. /// \param[in] ops_filter The name of operators not supported by Lite.
  476. ///
  477. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableLiteEngine(
  478. __pd_keep PD_Config* pd_config,
  479. PD_PrecisionType precision,
  480. PD_Bool zero_copy,
  481. size_t passes_filter_num,
  482. const char** passes_filter,
  483. size_t ops_filter_num,
  484. const char** ops_filter);
  485. ///
  486. /// \brief A boolean state indicating whether the Lite sub-graph engine is
  487. /// used.
  488. ///
  489. /// \param[in] pd_onfig config
  490. /// \return Whether the Lite sub-graph engine is used.
  491. ///
  492. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigLiteEngineEnabled(
  493. __pd_keep PD_Config* pd_config);
  494. ///
  495. /// \brief Control whether to debug IR graph analysis phase.
  496. /// This will generate DOT files for visualizing the computation graph after
  497. /// each analysis pass applied.
  498. ///
  499. /// \param[in] pd_onfig config
  500. /// \param[in] x whether to debug IR graph analysis phase.
  501. ///
  502. PADDLE_CAPI_EXPORT extern void PD_ConfigSwitchIrDebug(
  503. __pd_keep PD_Config* pd_config, PD_Bool x);
  504. ///
  505. /// \brief Turn on MKLDNN.
  506. ///
  507. /// \param[in] pd_onfig config
  508. ///
  509. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableMKLDNN(
  510. __pd_keep PD_Config* pd_config);
  511. ///
  512. /// \brief Set the cache capacity of different input shapes for MKLDNN.
  513. /// Default value 0 means not caching any shape.
  514. /// Please see MKL-DNN Data Caching Design Document:
  515. /// https://github.com/PaddlePaddle/FluidDoc/blob/develop/doc/fluid/design/mkldnn/caching/caching.md
  516. ///
  517. /// \param[in] pd_onfig config
  518. /// \param[in] capacity The cache capacity.
  519. ///
  520. PADDLE_CAPI_EXPORT extern void PD_ConfigSetMkldnnCacheCapacity(
  521. __pd_keep PD_Config* pd_config, int32_t capacity);
  522. ///
  523. /// \brief A boolean state telling whether to use the MKLDNN.
  524. ///
  525. /// \param[in] pd_onfig config
  526. /// \return Whether to use the MKLDNN.
  527. ///
  528. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigMkldnnEnabled(
  529. __pd_keep PD_Config* pd_config);
  530. ///
  531. /// \brief Set the number of cpu math library threads.
  532. ///
  533. /// \param[in] pd_onfig config
  534. /// \param cpu_math_library_num_threads The number of cpu math library
  535. /// threads.
  536. ///
  537. PADDLE_CAPI_EXPORT extern void PD_ConfigSetCpuMathLibraryNumThreads(
  538. __pd_keep PD_Config* pd_config, int32_t cpu_math_library_num_threads);
  539. ///
  540. /// \brief An int state telling how many threads are used in the CPU math
  541. /// library.
  542. ///
  543. /// \param[in] pd_onfig config
  544. /// \return The number of threads used in the CPU math library.
  545. ///
  546. PADDLE_CAPI_EXPORT extern int32_t PD_ConfigGetCpuMathLibraryNumThreads(
  547. __pd_keep PD_Config* pd_config);
  548. ///
  549. /// \brief Specify the operator type list to use MKLDNN acceleration.
  550. ///
  551. /// \param[in] pd_onfig config
  552. /// \param[in] ops_num The number of operator type list.
  553. /// \param[in] op_list The name of operator type list.
  554. ///
  555. PADDLE_CAPI_EXPORT extern void PD_ConfigSetMkldnnOp(
  556. __pd_keep PD_Config* pd_config, size_t ops_num, const char** op_list);
  557. ///
  558. /// \brief Turn on MKLDNN quantization.
  559. ///
  560. /// \param[in] pd_onfig config
  561. ///
  562. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableMkldnnQuantizer(
  563. __pd_keep PD_Config* pd_config);
  564. ///
  565. /// \brief A boolean state telling whether the MKLDNN quantization is enabled.
  566. ///
  567. /// \param[in] pd_onfig config
  568. /// \return Whether the MKLDNN quantization is enabled.
  569. ///
  570. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigMkldnnQuantizerEnabled(
  571. __pd_keep PD_Config* pd_config);
  572. ///
  573. /// \brief Turn on MKLDNN bfloat16.
  574. ///
  575. /// \param[in] pd_onfig config
  576. ///
  577. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableMkldnnBfloat16(
  578. __pd_keep PD_Config* pd_config);
  579. ///
  580. /// \brief A boolean state telling whether to use the MKLDNN Bfloat16.
  581. ///
  582. /// \param[in] pd_onfig config
  583. /// \return Whether to use the MKLDNN Bfloat16.
  584. ///
  585. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigMkldnnBfloat16Enabled(
  586. __pd_keep PD_Config* pd_config);
  587. /// \brief Specify the operator type list to use Bfloat16 acceleration.
  588. ///
  589. /// \param[in] pd_onfig config
  590. /// \param[in] ops_num The number of operator type list.
  591. /// \param[in] op_list The name of operator type list.
  592. ///
  593. PADDLE_CAPI_EXPORT extern void PD_ConfigSetBfloat16Op(
  594. __pd_keep PD_Config* pd_config, size_t ops_num, const char** op_list);
  595. ///
  596. /// \brief Enable the GPU multi-computing stream feature.
  597. /// NOTE: The current behavior of this interface is to bind the computation
  598. /// stream to the thread, and this behavior may be changed in the future.
  599. ///
  600. /// \param[in] pd_onfig config
  601. ///
  602. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableGpuMultiStream(
  603. __pd_keep PD_Config* pd_config);
  604. ///
  605. /// \brief A boolean state telling whether the thread local CUDA stream is
  606. /// enabled.
  607. ///
  608. /// \param[in] pd_onfig config
  609. /// \return Whether the thread local CUDA stream is enabled.
  610. ///
  611. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigThreadLocalStreamEnabled(
  612. __pd_keep PD_Config* pd_config);
  613. ///
  614. /// \brief Specify the memory buffer of program and parameter.
  615. /// Used when model and params are loaded directly from memory.
  616. ///
  617. /// \param[in] pd_onfig config
  618. /// \param[in] prog_buffer The memory buffer of program.
  619. /// \param[in] prog_buffer_size The size of the model data.
  620. /// \param[in] params_buffer The memory buffer of the combined parameters file.
  621. /// \param[in] params_buffer_size The size of the combined parameters data.
  622. ///
  623. PADDLE_CAPI_EXPORT extern void PD_ConfigSetModelBuffer(
  624. __pd_keep PD_Config* pd_config,
  625. const char* prog_buffer,
  626. size_t prog_buffer_size,
  627. const char* params_buffer,
  628. size_t params_buffer_size);
  629. ///
  630. /// \brief A boolean state telling whether the model is set from the CPU
  631. /// memory.
  632. ///
  633. /// \param[in] pd_onfig config
  634. /// \return Whether model and params are loaded directly from memory.
  635. ///
  636. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigModelFromMemory(
  637. __pd_keep PD_Config* pd_config);
  638. ///
  639. /// \brief Turn on memory optimize
  640. /// NOTE still in development.
  641. ///
  642. /// \param[in] pd_onfig config
  643. ///
  644. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableMemoryOptim(
  645. __pd_keep PD_Config* pd_config, PD_Bool x);
  646. ///
  647. /// \brief A boolean state telling whether the memory optimization is
  648. /// activated.
  649. ///
  650. /// \param[in] pd_onfig config
  651. /// \return Whether the memory optimization is activated.
  652. ///
  653. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigMemoryOptimEnabled(
  654. __pd_keep PD_Config* pd_config);
  655. ///
  656. /// \brief Turn on profiling report.
  657. /// If not turned on, no profiling report will be generated.
  658. ///
  659. /// \param[in] pd_onfig config
  660. ///
  661. PADDLE_CAPI_EXPORT extern void PD_ConfigEnableProfile(
  662. __pd_keep PD_Config* pd_config);
  663. ///
  664. /// \brief A boolean state telling whether the profiler is activated.
  665. ///
  666. /// \param[in] pd_onfig config
  667. /// \return bool Whether the profiler is activated.
  668. ///
  669. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigProfileEnabled(
  670. __pd_keep PD_Config* pd_config);
  671. ///
  672. /// \brief Mute all logs in Paddle inference.
  673. ///
  674. /// \param[in] pd_onfig config
  675. ///
  676. PADDLE_CAPI_EXPORT extern void PD_ConfigDisableGlogInfo(
  677. __pd_keep PD_Config* pd_config);
  678. ///
  679. /// \brief A boolean state telling whether logs in Paddle inference are muted.
  680. ///
  681. /// \param[in] pd_onfig config
  682. /// \return Whether logs in Paddle inference are muted.
  683. ///
  684. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigGlogInfoDisabled(
  685. __pd_keep PD_Config* pd_config);
  686. ///
  687. /// \brief Set the Config to be invalid.
  688. /// This is to ensure that an Config can only be used in one
  689. /// Predictor.
  690. ///
  691. /// \param[in] pd_onfig config
  692. ///
  693. PADDLE_CAPI_EXPORT extern void PD_ConfigSetInvalid(
  694. __pd_keep PD_Config* pd_config);
  695. ///
  696. /// \brief A boolean state telling whether the Config is valid.
  697. ///
  698. /// \param[in] pd_onfig config
  699. /// \return Whether the Config is valid.
  700. ///
  701. PADDLE_CAPI_EXPORT extern PD_Bool PD_ConfigIsValid(
  702. __pd_keep PD_Config* pd_config);
  703. ///
  704. /// \brief Partially release the memory
  705. ///
  706. /// \param[in] pd_onfig config
  707. ///
  708. PADDLE_CAPI_EXPORT extern void PD_ConfigPartiallyRelease(
  709. __pd_keep PD_Config* pd_config);
  710. ///
  711. /// \brief Delete all passes that has a certain type 'pass'.
  712. ///
  713. /// \param[in] pass the certain pass type to be deleted.
  714. ///
  715. PADDLE_CAPI_EXPORT extern void PD_ConfigDeletePass(
  716. __pd_keep PD_Config* pd_config, const char* pass);
  717. ///
  718. /// \brief Insert a pass to a specific position
  719. ///
  720. /// \param[in] idx the position to insert.
  721. /// \param[in] pass the new pass.
  722. ///
  723. PADDLE_CAPI_EXPORT extern void PD_ConfigInsertPass(
  724. __pd_keep PD_Config* pd_config, size_t idx, const char* pass);
  725. ///
  726. /// \brief Append a pass to the end of the passes
  727. ///
  728. /// \param[in] pass the new pass.
  729. ///
  730. PADDLE_CAPI_EXPORT extern void PD_ConfigAppendPass(
  731. __pd_keep PD_Config* pd_config, const char* pass);
  732. ///
  733. /// \brief Get information of passes.
  734. ///
  735. /// \return Return list of the passes.
  736. ///
  737. PADDLE_CAPI_EXPORT extern __pd_give PD_OneDimArrayCstr* PD_ConfigAllPasses(
  738. __pd_keep PD_Config* pd_config);
  739. ///
  740. /// \brief Get information of config.
  741. /// Attention, Please release the string manually.
  742. ///
  743. /// \return Return config info.
  744. ///
  745. PADDLE_CAPI_EXPORT extern __pd_give PD_Cstr* PD_ConfigSummary(
  746. __pd_keep PD_Config* pd_config);
  747. #ifdef __cplusplus
  748. } // extern "C"
  749. #endif