16
16
/* ! \file paddle_api.h
17
17
*/
18
18
19
+ /* ! \mainpage Paddle Inference APIs
20
+ * \section intro_sec Introduction
21
+ * The Paddle inference library aims to offer an high performance inference SDK
22
+ * for Paddle users.
23
+ */
24
+
19
25
#include < cassert>
20
26
#include < memory>
21
27
#include < string>
@@ -34,26 +40,49 @@ enum PaddleDType {
34
40
};
35
41
36
42
/* *
37
- *\brief Memory menager for PaddleTensor.
43
+ * \brief Memory manager for ` PaddleTensor` .
38
44
*
39
- *The PaddleBuf holds a buffer for data input or output. The memory can be
40
- *allocated by user or by PaddleBuf itself, but in any case, the PaddleBuf
41
- *should be reused for better performance.
45
+ * The PaddleBuf holds a buffer for data input or output. The memory can be
46
+ * allocated by user or by PaddleBuf itself, but in any case, the PaddleBuf
47
+ * should be reused for better performance.
42
48
*
43
- *For user allocated memory, the following API can be used:
44
- *- PaddleBuf(void* data, size_t length) to set an external memory by
45
- *specifying
46
- * the memory address and length.
47
- *- Reset(void* data, size_t length) to reset the PaddleBuf with an external
49
+ * For user allocated memory, the following API can be used:
50
+ * - PaddleBuf(void* data, size_t length) to set an external memory by
51
+ * specifying the memory address and length.
52
+ * - Reset(void* data, size_t length) to reset the PaddleBuf with an external
48
53
*memory.
49
- *ATTENTION, for user allocated memory, deallocation should be done by users
54
+ * ATTENTION, for user allocated memory, deallocation should be done by users
50
55
*externally after the program finished. The PaddleBuf won't do any allocation
51
56
*or deallocation.
52
57
*
53
- *To have the PaddleBuf allocate and manage the memory:
54
- *- PaddleBuf(size_t length) will allocate a memory of size `length`.
55
- *- Resize(size_t length) resize the memory to no less than `length`, ATTENTION
58
+ * To have the PaddleBuf allocate and manage the memory:
59
+ * - PaddleBuf(size_t length) will allocate a memory of size `length`.
60
+ * - Resize(size_t length) resize the memory to no less than `length`, ATTENTION
56
61
* if the allocated memory is larger than `length`, nothing will done.
62
+ *
63
+ * Usage:
64
+ *
65
+ * Let PaddleBuf manage the memory internally.
66
+ * \code{cpp}
67
+ * const int num_elements = 128;
68
+ * PaddleBuf buf(num_elements * sizeof(float));
69
+ * \endcode
70
+ *
71
+ * Or
72
+ * \code{cpp}
73
+ * PaddleBuf buf;
74
+ * buf.Resize(num_elements * sizeof(float));
75
+ * \endcode
76
+ * Works the exactly the same.
77
+ *
78
+ * One can also make the `PaddleBuf` use the external memory.
79
+ * \code{cpp}
80
+ * PaddleBuf buf;
81
+ * void* external_memory = new float[num_elements];
82
+ * buf.Reset(external_memory, num_elements*sizeof(float));
83
+ * ...
84
+ * delete[] external_memory; // manage the memory lifetime outside.
85
+ * \endcode
57
86
*/
58
87
class PaddleBuf {
59
88
public:
@@ -78,7 +107,7 @@ class PaddleBuf {
78
107
/* * Tell whether the buffer is empty.
79
108
*/
80
109
bool empty () const { return length_ == 0 ; }
81
- /* * Get the memory address.
110
+ /* * Get the data's memory address.
82
111
*/
83
112
void * data () const { return data_; }
84
113
/* * Get the memory length.
@@ -110,7 +139,8 @@ struct PaddleTensor {
110
139
};
111
140
112
141
enum class PaddlePlace { kUNK = -1 , kCPU , kGPU };
113
- /* * Tensor without copy, currently only supports AnalysisPredictor.
142
+
143
+ /* * Tensor without copy, currently only supports `AnalysisPredictor`.
114
144
*/
115
145
class ZeroCopyTensor {
116
146
public:
@@ -269,9 +299,11 @@ struct NativeConfig : public PaddlePredictor::Config {
269
299
*
270
300
* Usage:
271
301
*
302
+ * \code{.cpp}
272
303
* NativeConfig config;
273
304
* ... // change the configs.
274
305
* auto native_predictor = CreatePaddlePredictor(config);
306
+ * \endcode
275
307
*
276
308
* FOR EXTENSION DEVELOPER:
277
309
* Different predictors are designated by config type. Similar configs can be
0 commit comments