xref: /dpdk/lib/mldev/rte_mldev.h (revision c6552d9a8deffa448de2d5e2e726f50508c1efd2)
1d82cac58SJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause
2d82cac58SJerin Jacob  * Copyright (c) 2022 Marvell.
3d82cac58SJerin Jacob  */
4d82cac58SJerin Jacob 
5d82cac58SJerin Jacob #ifndef RTE_MLDEV_H
6d82cac58SJerin Jacob #define RTE_MLDEV_H
7d82cac58SJerin Jacob 
8d82cac58SJerin Jacob /**
9d82cac58SJerin Jacob  * @file rte_mldev.h
10d82cac58SJerin Jacob  *
11d82cac58SJerin Jacob  * @warning
12d82cac58SJerin Jacob  * @b EXPERIMENTAL:
13d82cac58SJerin Jacob  * All functions in this file may be changed or removed without prior notice.
14d82cac58SJerin Jacob  *
15d82cac58SJerin Jacob  * ML (Machine Learning) device API.
16d82cac58SJerin Jacob  *
17d82cac58SJerin Jacob  * The ML framework is built on the following model:
18d82cac58SJerin Jacob  *
19d82cac58SJerin Jacob  *
20d82cac58SJerin Jacob  *     +-----------------+               rte_ml_[en|de]queue_burst()
21d82cac58SJerin Jacob  *     |                 |                          |
22d82cac58SJerin Jacob  *     |     Machine     o------+     +--------+    |
23d82cac58SJerin Jacob  *     |     Learning    |      |     | queue  |    |    +------+
24d82cac58SJerin Jacob  *     |     Inference   o------+-----o        |<===o===>|Core 0|
25d82cac58SJerin Jacob  *     |     Engine      |      |     | pair 0 |         +------+
26d82cac58SJerin Jacob  *     |                 o----+ |     +--------+
27d82cac58SJerin Jacob  *     |                 |    | |
28d82cac58SJerin Jacob  *     +-----------------+    | |     +--------+
29d82cac58SJerin Jacob  *              ^             | |     | queue  |         +------+
30d82cac58SJerin Jacob  *              |             | +-----o        |<=======>|Core 1|
31d82cac58SJerin Jacob  *              |             |       | pair 1 |         +------+
32d82cac58SJerin Jacob  *              |             |       +--------+
33d82cac58SJerin Jacob  *     +--------+--------+    |
34d82cac58SJerin Jacob  *     | +-------------+ |    |       +--------+
35d82cac58SJerin Jacob  *     | |   Model 0   | |    |       | queue  |         +------+
36d82cac58SJerin Jacob  *     | +-------------+ |    +-------o        |<=======>|Core N|
37d82cac58SJerin Jacob  *     | +-------------+ |            | pair N |         +------+
38d82cac58SJerin Jacob  *     | |   Model 1   | |            +--------+
39d82cac58SJerin Jacob  *     | +-------------+ |
40d82cac58SJerin Jacob  *     | +-------------+ |<------> rte_ml_model_load()
41d82cac58SJerin Jacob  *     | |   Model ..  | |-------> rte_ml_model_info_get()
42d82cac58SJerin Jacob  *     | +-------------+ |<------- rte_ml_model_start()
43d82cac58SJerin Jacob  *     | +-------------+ |<------- rte_ml_model_stop()
44d82cac58SJerin Jacob  *     | |   Model N   | |<------- rte_ml_model_params_update()
45d82cac58SJerin Jacob  *     | +-------------+ |<------- rte_ml_model_unload()
46d82cac58SJerin Jacob  *     +-----------------+
47d82cac58SJerin Jacob  *
48d82cac58SJerin Jacob  * ML Device: A hardware or software-based implementation of ML device API for
49d82cac58SJerin Jacob  * running inferences using a pre-trained ML model.
50d82cac58SJerin Jacob  *
51d82cac58SJerin Jacob  * ML Model: An ML model is an algorithm trained over a dataset. A model consists of
52d82cac58SJerin Jacob  * procedure/algorithm and data/pattern required to make predictions on live data.
53d82cac58SJerin Jacob  * Once the model is created and trained outside of the DPDK scope, the model can be loaded
54d82cac58SJerin Jacob  * via rte_ml_model_load() and then start it using rte_ml_model_start() API.
55d82cac58SJerin Jacob  * The rte_ml_model_params_update() can be used to update the model parameters such as weight
56d82cac58SJerin Jacob  * and bias without unloading the model using rte_ml_model_unload().
57d82cac58SJerin Jacob  *
58d82cac58SJerin Jacob  * ML Inference: ML inference is the process of feeding data to the model via
59d82cac58SJerin Jacob  * rte_ml_enqueue_burst() API and use rte_ml_dequeue_burst() API to get the calculated
60d82cac58SJerin Jacob  * outputs/predictions from the started model.
61d82cac58SJerin Jacob  *
62d82cac58SJerin Jacob  * In all functions of the ML device API, the ML device is designated by an
63d82cac58SJerin Jacob  * integer >= 0 named as device identifier *dev_id*.
64d82cac58SJerin Jacob  *
65d82cac58SJerin Jacob  * The functions exported by the ML device API to setup a device designated by
66d82cac58SJerin Jacob  * its device identifier must be invoked in the following order:
67d82cac58SJerin Jacob  *
68d82cac58SJerin Jacob  *      - rte_ml_dev_configure()
69d82cac58SJerin Jacob  *      - rte_ml_dev_queue_pair_setup()
70d82cac58SJerin Jacob  *      - rte_ml_dev_start()
71d82cac58SJerin Jacob  *
72d82cac58SJerin Jacob  * A model is required to run the inference operations with the user specified inputs.
73d82cac58SJerin Jacob  * Application needs to invoke the ML model API in the following order before queueing
74d82cac58SJerin Jacob  * inference jobs.
75d82cac58SJerin Jacob  *
76d82cac58SJerin Jacob  *      - rte_ml_model_load()
77d82cac58SJerin Jacob  *      - rte_ml_model_start()
78d82cac58SJerin Jacob  *
79d82cac58SJerin Jacob  * A model can be loaded on a device only after the device has been configured and can be
80d82cac58SJerin Jacob  * started or stopped only after a device has been started.
81d82cac58SJerin Jacob  *
82d82cac58SJerin Jacob  * The rte_ml_model_info_get() API is provided to retrieve the information related to the model.
83d82cac58SJerin Jacob  * The information would include the shape and type of input and output required for the inference.
84d82cac58SJerin Jacob  *
85d82cac58SJerin Jacob  * Data quantization and dequantization is one of the main aspects in ML domain. This involves
86d82cac58SJerin Jacob  * conversion of input data from a higher precision to a lower precision data type and vice-versa
87d82cac58SJerin Jacob  * for the output. APIs are provided to enable quantization through rte_ml_io_quantize() and
88d82cac58SJerin Jacob  * dequantization through rte_ml_io_dequantize(). These APIs have the capability to handle input
89d82cac58SJerin Jacob  * and output buffers holding data for multiple batches.
90d82cac58SJerin Jacob  *
91d82cac58SJerin Jacob  * Two utility APIs rte_ml_io_input_size_get() and rte_ml_io_output_size_get() can used to get the
92d82cac58SJerin Jacob  * size of quantized and de-quantized multi-batch input and output buffers.
93d82cac58SJerin Jacob  *
94d82cac58SJerin Jacob  * User can optionally update the model parameters with rte_ml_model_params_update() after
95d82cac58SJerin Jacob  * invoking rte_ml_model_stop() API on a given model ID.
96d82cac58SJerin Jacob  *
97d82cac58SJerin Jacob  * The application can invoke, in any order, the functions exported by the ML API to enqueue
98d82cac58SJerin Jacob  * inference jobs and dequeue inference response.
99d82cac58SJerin Jacob  *
100d82cac58SJerin Jacob  * If the application wants to change the device configuration (i.e., call
101d82cac58SJerin Jacob  * rte_ml_dev_configure() or rte_ml_dev_queue_pair_setup()), then application must stop the
102d82cac58SJerin Jacob  * device using rte_ml_dev_stop() API. Likewise, if model parameters need to be updated then
103d82cac58SJerin Jacob  * the application must call rte_ml_model_stop() followed by rte_ml_model_params_update() API
104d82cac58SJerin Jacob  * for the given model. The application does not need to call rte_ml_dev_stop() API for
105d82cac58SJerin Jacob  * any model re-configuration such as rte_ml_model_params_update(), rte_ml_model_unload() etc.
106d82cac58SJerin Jacob  *
107d82cac58SJerin Jacob  * Once the device is in the start state after invoking rte_ml_dev_start() API and the model is in
108d82cac58SJerin Jacob  * start state after invoking rte_ml_model_start() API, then the application can call
109d82cac58SJerin Jacob  * rte_ml_enqueue_burst() and rte_ml_dequeue_burst() API on the destined device and model ID.
110d82cac58SJerin Jacob  *
111d82cac58SJerin Jacob  * Finally, an application can close an ML device by invoking the rte_ml_dev_close() function.
112d82cac58SJerin Jacob  *
113d82cac58SJerin Jacob  * Typical application utilisation of the ML API will follow the following
114d82cac58SJerin Jacob  * programming flow.
115d82cac58SJerin Jacob  *
116d82cac58SJerin Jacob  * - rte_ml_dev_configure()
117d82cac58SJerin Jacob  * - rte_ml_dev_queue_pair_setup()
118d82cac58SJerin Jacob  * - rte_ml_model_load()
119d82cac58SJerin Jacob  * - rte_ml_dev_start()
120d82cac58SJerin Jacob  * - rte_ml_model_start()
121d82cac58SJerin Jacob  * - rte_ml_model_info_get()
122d82cac58SJerin Jacob  * - rte_ml_enqueue_burst()
123d82cac58SJerin Jacob  * - rte_ml_dequeue_burst()
124d82cac58SJerin Jacob  * - rte_ml_model_stop()
125d82cac58SJerin Jacob  * - rte_ml_model_unload()
126d82cac58SJerin Jacob  * - rte_ml_dev_stop()
127d82cac58SJerin Jacob  * - rte_ml_dev_close()
128d82cac58SJerin Jacob  *
129d82cac58SJerin Jacob  * Regarding multi-threading, by default, all the functions of the ML Device API exported by a PMD
130d82cac58SJerin Jacob  * are lock-free functions which assume to not be invoked in parallel on different logical cores
131d82cac58SJerin Jacob  * on the same target object. For instance, the dequeue function of a poll mode driver cannot be
132d82cac58SJerin Jacob  * invoked in parallel on two logical cores to operate on same queue pair. Of course, this function
133d82cac58SJerin Jacob  * can be invoked in parallel by different logical core on different queue pair.
134d82cac58SJerin Jacob  * It is the responsibility of the user application to enforce this rule.
135d82cac58SJerin Jacob  */
136d82cac58SJerin Jacob 
137d82cac58SJerin Jacob #include <rte_common.h>
138d82cac58SJerin Jacob #include <rte_log.h>
139d82cac58SJerin Jacob #include <rte_mempool.h>
140d82cac58SJerin Jacob 
141d82cac58SJerin Jacob #ifdef __cplusplus
142d82cac58SJerin Jacob extern "C" {
143d82cac58SJerin Jacob #endif
144d82cac58SJerin Jacob 
145d82cac58SJerin Jacob /* Logging Macro */
146d82cac58SJerin Jacob extern int rte_ml_dev_logtype;
14797433132SDavid Marchand #define RTE_LOGTYPE_MLDEV rte_ml_dev_logtype
148d82cac58SJerin Jacob 
1490f1dc8cbSTyler Retzlaff #define RTE_MLDEV_LOG(level, ...) \
1500f1dc8cbSTyler Retzlaff 	RTE_LOG_LINE_PREFIX(level, MLDEV, "%s(): ", __func__, __VA_ARGS__)
151d82cac58SJerin Jacob 
152d82cac58SJerin Jacob #define RTE_ML_STR_MAX 128
153d82cac58SJerin Jacob /**< Maximum length of name string */
154d82cac58SJerin Jacob 
155d82cac58SJerin Jacob #define RTE_MLDEV_DEFAULT_MAX 32
156d82cac58SJerin Jacob /** Maximum number of devices if rte_ml_dev_init() is not called. */
157d82cac58SJerin Jacob 
158d82cac58SJerin Jacob /* Device operations */
159d82cac58SJerin Jacob 
160d82cac58SJerin Jacob /**
161d82cac58SJerin Jacob  * Initialize the device array before probing devices. If not called, the first device probed would
162d82cac58SJerin Jacob  * initialize the array to a size of RTE_MLDEV_DEFAULT_MAX.
163d82cac58SJerin Jacob  *
164d82cac58SJerin Jacob  * @param dev_max
165d82cac58SJerin Jacob  *   Maximum number of devices.
166d82cac58SJerin Jacob  *
167d82cac58SJerin Jacob  * @return
168d82cac58SJerin Jacob  *   0 on success, -rte_errno otherwise:
169d82cac58SJerin Jacob  *   - ENOMEM if out of memory
170d82cac58SJerin Jacob  *   - EINVAL if 0 size
171d82cac58SJerin Jacob  *   - EBUSY if already initialized
172d82cac58SJerin Jacob  */
173d82cac58SJerin Jacob __rte_experimental
174d82cac58SJerin Jacob int
175d82cac58SJerin Jacob rte_ml_dev_init(size_t dev_max);
176d82cac58SJerin Jacob 
177d82cac58SJerin Jacob /**
178d82cac58SJerin Jacob  * Get the total number of ML devices that have been successfully initialised.
179d82cac58SJerin Jacob  *
180d82cac58SJerin Jacob  * @return
181d82cac58SJerin Jacob  *   - The total number of usable ML devices.
182d82cac58SJerin Jacob  */
183d82cac58SJerin Jacob __rte_experimental
184d82cac58SJerin Jacob uint16_t
185d82cac58SJerin Jacob rte_ml_dev_count(void);
186d82cac58SJerin Jacob 
187d82cac58SJerin Jacob /**
188d82cac58SJerin Jacob  * Check if the device is in ready state.
189d82cac58SJerin Jacob  *
190d82cac58SJerin Jacob  * @param dev_id
191d82cac58SJerin Jacob  *   The identifier of the device.
192d82cac58SJerin Jacob  *
193d82cac58SJerin Jacob  * @return
194d82cac58SJerin Jacob  *   - 0 if device state is not in ready state.
195d82cac58SJerin Jacob  *   - 1 if device state is ready state.
196d82cac58SJerin Jacob  */
197d82cac58SJerin Jacob __rte_experimental
198d82cac58SJerin Jacob int
199d82cac58SJerin Jacob rte_ml_dev_is_valid_dev(int16_t dev_id);
200d82cac58SJerin Jacob 
201d82cac58SJerin Jacob /**
202d82cac58SJerin Jacob  * Return the NUMA socket to which a device is connected.
203d82cac58SJerin Jacob  *
204d82cac58SJerin Jacob  * @param dev_id
205d82cac58SJerin Jacob  *   The identifier of the device.
206d82cac58SJerin Jacob  *
207d82cac58SJerin Jacob  * @return
208d82cac58SJerin Jacob  *   - The NUMA socket id to which the device is connected
209d82cac58SJerin Jacob  *   - 0 If the socket could not be determined.
210d82cac58SJerin Jacob  *   - -EINVAL: if the dev_id value is not valid.
211d82cac58SJerin Jacob  */
212d82cac58SJerin Jacob __rte_experimental
213d82cac58SJerin Jacob int
214d82cac58SJerin Jacob rte_ml_dev_socket_id(int16_t dev_id);
215d82cac58SJerin Jacob 
216d82cac58SJerin Jacob /**  ML device information */
217d82cac58SJerin Jacob struct rte_ml_dev_info {
218d82cac58SJerin Jacob 	const char *driver_name;
219d82cac58SJerin Jacob 	/**< Driver name */
220d82cac58SJerin Jacob 	uint16_t max_models;
221d82cac58SJerin Jacob 	/**< Maximum number of models supported by the device.
222d82cac58SJerin Jacob 	 * @see struct rte_ml_dev_config::nb_models
223d82cac58SJerin Jacob 	 */
224d82cac58SJerin Jacob 	uint16_t max_queue_pairs;
225d82cac58SJerin Jacob 	/**< Maximum number of queues pairs supported by the device.
226d82cac58SJerin Jacob 	 * @see struct rte_ml_dev_config::nb_queue_pairs
227d82cac58SJerin Jacob 	 */
228d82cac58SJerin Jacob 	uint16_t max_desc;
229d82cac58SJerin Jacob 	/**< Maximum allowed number of descriptors for queue pair by the device.
230d82cac58SJerin Jacob 	 * @see struct rte_ml_dev_qp_conf::nb_desc
231d82cac58SJerin Jacob 	 */
23224364292SSrikanth Yalavarthi 	uint16_t max_io;
23324364292SSrikanth Yalavarthi 	/**< Maximum number of inputs/outputs supported per model. */
234d82cac58SJerin Jacob 	uint16_t max_segments;
235d82cac58SJerin Jacob 	/**< Maximum number of scatter-gather entries supported by the device.
236d82cac58SJerin Jacob 	 * @see struct rte_ml_buff_seg  struct rte_ml_buff_seg::next
237d82cac58SJerin Jacob 	 */
23824364292SSrikanth Yalavarthi 	uint16_t align_size;
23924364292SSrikanth Yalavarthi 	/**< Alignment size of IO buffers used by the device. */
240d82cac58SJerin Jacob };
241d82cac58SJerin Jacob 
242d82cac58SJerin Jacob /**
243d82cac58SJerin Jacob  * Retrieve the information of the device.
244d82cac58SJerin Jacob  *
245d82cac58SJerin Jacob  * @param dev_id
246d82cac58SJerin Jacob  *   The identifier of the device.
247d82cac58SJerin Jacob  * @param dev_info
248d82cac58SJerin Jacob  *   A pointer to a structure of type *rte_ml_dev_info* to be filled with the info of the device.
249d82cac58SJerin Jacob  *
250d82cac58SJerin Jacob  * @return
251d82cac58SJerin Jacob  *   - 0: Success, driver updates the information of the ML device
252d82cac58SJerin Jacob  *   - < 0: Error code returned by the driver info get function.
253d82cac58SJerin Jacob  */
254d82cac58SJerin Jacob __rte_experimental
255d82cac58SJerin Jacob int
256d82cac58SJerin Jacob rte_ml_dev_info_get(int16_t dev_id, struct rte_ml_dev_info *dev_info);
257d82cac58SJerin Jacob 
258d82cac58SJerin Jacob /** ML device configuration structure */
259d82cac58SJerin Jacob struct rte_ml_dev_config {
260d82cac58SJerin Jacob 	int socket_id;
261d82cac58SJerin Jacob 	/**< Socket to allocate resources on. */
262d82cac58SJerin Jacob 	uint16_t nb_models;
263d82cac58SJerin Jacob 	/**< Number of models to be loaded on the device.
264d82cac58SJerin Jacob 	 * This value cannot exceed the max_models which is previously provided in
265d82cac58SJerin Jacob 	 * struct rte_ml_dev_info::max_models
266d82cac58SJerin Jacob 	 */
267d82cac58SJerin Jacob 	uint16_t nb_queue_pairs;
268d82cac58SJerin Jacob 	/**< Number of queue pairs to configure on this device.
269d82cac58SJerin Jacob 	 * This value cannot exceed the max_models which is previously provided in
270d82cac58SJerin Jacob 	 * struct rte_ml_dev_info::max_queue_pairs
271d82cac58SJerin Jacob 	 */
272d82cac58SJerin Jacob };
273d82cac58SJerin Jacob 
274d82cac58SJerin Jacob /**
275d82cac58SJerin Jacob  * Configure an ML device.
276d82cac58SJerin Jacob  *
277d82cac58SJerin Jacob  * This function must be invoked first before any other function in the API.
278d82cac58SJerin Jacob  *
279d82cac58SJerin Jacob  * ML Device can be re-configured, when in a stopped state. Device cannot be re-configured after
280d82cac58SJerin Jacob  * rte_ml_dev_close() is called.
281d82cac58SJerin Jacob  *
282d82cac58SJerin Jacob  * The caller may use rte_ml_dev_info_get() to get the capability of each resources available for
283d82cac58SJerin Jacob  * this ML device.
284d82cac58SJerin Jacob  *
285d82cac58SJerin Jacob  * @param dev_id
286d82cac58SJerin Jacob  *   The identifier of the device to configure.
287d82cac58SJerin Jacob  * @param config
288d82cac58SJerin Jacob  *   The ML device configuration structure.
289d82cac58SJerin Jacob  *
290d82cac58SJerin Jacob  * @return
291d82cac58SJerin Jacob  *   - 0: Success, device configured.
292d82cac58SJerin Jacob  *   - < 0: Error code returned by the driver configuration function.
293d82cac58SJerin Jacob  */
294d82cac58SJerin Jacob __rte_experimental
295d82cac58SJerin Jacob int
296d82cac58SJerin Jacob rte_ml_dev_configure(int16_t dev_id, const struct rte_ml_dev_config *config);
297d82cac58SJerin Jacob 
298d82cac58SJerin Jacob /* Forward declaration */
299d82cac58SJerin Jacob struct rte_ml_op;
300d82cac58SJerin Jacob 
301d82cac58SJerin Jacob /**< Callback function called during rte_ml_dev_stop(), invoked once per flushed ML op */
302d82cac58SJerin Jacob typedef void (*rte_ml_dev_stop_flush_t)(int16_t dev_id, uint16_t qp_id, struct rte_ml_op *op);
303d82cac58SJerin Jacob 
304d82cac58SJerin Jacob /** ML device queue pair configuration structure. */
305d82cac58SJerin Jacob struct rte_ml_dev_qp_conf {
306d82cac58SJerin Jacob 	uint32_t nb_desc;
307d82cac58SJerin Jacob 	/**< Number of descriptors per queue pair.
308d82cac58SJerin Jacob 	 * This value cannot exceed the max_desc which previously provided in
309d82cac58SJerin Jacob 	 * struct rte_ml_dev_info:max_desc
310d82cac58SJerin Jacob 	 */
311d82cac58SJerin Jacob 	rte_ml_dev_stop_flush_t cb;
312d82cac58SJerin Jacob 	/**< Callback function called during rte_ml_dev_stop(), invoked once per active ML op.
313d82cac58SJerin Jacob 	 * Value NULL is allowed, in which case callback will not be invoked.
314d82cac58SJerin Jacob 	 * This function can be used to properly dispose of outstanding ML ops from all
315d82cac58SJerin Jacob 	 * queue pairs, for example ops containing  memory pointers.
316d82cac58SJerin Jacob 	 * @see rte_ml_dev_stop()
317d82cac58SJerin Jacob 	 */
318d82cac58SJerin Jacob };
319d82cac58SJerin Jacob 
320d82cac58SJerin Jacob /**
321d82cac58SJerin Jacob  * Set up a queue pair for a device. This should only be called when the device is stopped.
322d82cac58SJerin Jacob  *
323d82cac58SJerin Jacob  * @param dev_id
324d82cac58SJerin Jacob  *   The identifier of the device.
325d82cac58SJerin Jacob  * @param queue_pair_id
326d82cac58SJerin Jacob  *   The index of the queue pairs to set up. The value must be in the range [0, nb_queue_pairs - 1]
327d82cac58SJerin Jacob  * previously supplied to rte_ml_dev_configure().
328d82cac58SJerin Jacob  * @param qp_conf
329d82cac58SJerin Jacob  *   The pointer to the configuration data to be used for the queue pair.
330d82cac58SJerin Jacob  * @param socket_id
331d82cac58SJerin Jacob  *   The *socket_id* argument is the socket identifier in case of NUMA.
332d82cac58SJerin Jacob  * The value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the memory allocated
333d82cac58SJerin Jacob  * for the queue pair.
334d82cac58SJerin Jacob  *
335d82cac58SJerin Jacob  * @return
336d82cac58SJerin Jacob  *   - 0: Success, queue pair correctly set up.
337d82cac58SJerin Jacob  *   - < 0: Queue pair configuration failed.
338d82cac58SJerin Jacob  */
339d82cac58SJerin Jacob __rte_experimental
340d82cac58SJerin Jacob int
341d82cac58SJerin Jacob rte_ml_dev_queue_pair_setup(int16_t dev_id, uint16_t queue_pair_id,
342d82cac58SJerin Jacob 			    const struct rte_ml_dev_qp_conf *qp_conf, int socket_id);
343d82cac58SJerin Jacob 
344d82cac58SJerin Jacob /**
345d82cac58SJerin Jacob  * Start an ML device.
346d82cac58SJerin Jacob  *
347d82cac58SJerin Jacob  * The device start step consists of setting the configured features and enabling the ML device
348d82cac58SJerin Jacob  * to accept inference jobs.
349d82cac58SJerin Jacob  *
350d82cac58SJerin Jacob  * @param dev_id
351d82cac58SJerin Jacob  *   The identifier of the device.
352d82cac58SJerin Jacob  *
353d82cac58SJerin Jacob  * @return
354d82cac58SJerin Jacob  *   - 0: Success, device started.
355d82cac58SJerin Jacob  *   - <0: Error code of the driver device start function.
356d82cac58SJerin Jacob  */
357d82cac58SJerin Jacob __rte_experimental
358d82cac58SJerin Jacob int
359d82cac58SJerin Jacob rte_ml_dev_start(int16_t dev_id);
360d82cac58SJerin Jacob 
361d82cac58SJerin Jacob /**
362d82cac58SJerin Jacob  * Stop an ML device. A stopped device cannot accept inference jobs.
363d82cac58SJerin Jacob  * The device can be restarted with a call to rte_ml_dev_start().
364d82cac58SJerin Jacob  *
365d82cac58SJerin Jacob  * @param dev_id
366d82cac58SJerin Jacob  *   The identifier of the device.
367d82cac58SJerin Jacob  *
368d82cac58SJerin Jacob  * @return
369d82cac58SJerin Jacob  *   - 0: Success, device stopped.
370d82cac58SJerin Jacob  *   - <0: Error code of the driver device stop function.
371d82cac58SJerin Jacob  */
372d82cac58SJerin Jacob __rte_experimental
373d82cac58SJerin Jacob int
374d82cac58SJerin Jacob rte_ml_dev_stop(int16_t dev_id);
375d82cac58SJerin Jacob 
376d82cac58SJerin Jacob /**
377d82cac58SJerin Jacob  * Close an ML device. The device cannot be restarted!
378d82cac58SJerin Jacob  *
379d82cac58SJerin Jacob  * @param dev_id
380d82cac58SJerin Jacob  *   The identifier of the device.
381d82cac58SJerin Jacob  *
382d82cac58SJerin Jacob  * @return
383d82cac58SJerin Jacob  *  - 0 on successfully closing device.
384d82cac58SJerin Jacob  *  - <0 on failure to close device.
385d82cac58SJerin Jacob  */
386d82cac58SJerin Jacob __rte_experimental
387d82cac58SJerin Jacob int
388d82cac58SJerin Jacob rte_ml_dev_close(int16_t dev_id);
389d82cac58SJerin Jacob 
390d82cac58SJerin Jacob /** Status of ML operation */
391d82cac58SJerin Jacob enum rte_ml_op_status {
392d82cac58SJerin Jacob 	RTE_ML_OP_STATUS_SUCCESS = 0,
393d82cac58SJerin Jacob 	/**< Operation completed successfully */
394d82cac58SJerin Jacob 	RTE_ML_OP_STATUS_NOT_PROCESSED,
395d82cac58SJerin Jacob 	/**< Operation has not yet been processed by the device. */
396d82cac58SJerin Jacob 	RTE_ML_OP_STATUS_ERROR,
397d82cac58SJerin Jacob 	/**< Operation completed with error.
398d82cac58SJerin Jacob 	 * Application can invoke rte_ml_op_error_get() to get PMD specific
399d82cac58SJerin Jacob 	 * error code if needed.
400d82cac58SJerin Jacob 	 */
401d82cac58SJerin Jacob };
402d82cac58SJerin Jacob 
403d82cac58SJerin Jacob /** ML operation's input and output buffer representation as scatter gather list
404d82cac58SJerin Jacob  */
405d82cac58SJerin Jacob struct rte_ml_buff_seg {
406d82cac58SJerin Jacob 	rte_iova_t iova_addr;
407d82cac58SJerin Jacob 	/**< IOVA address of segment buffer. */
408d82cac58SJerin Jacob 	void *addr;
409d82cac58SJerin Jacob 	/**< Virtual address of segment buffer. */
410d82cac58SJerin Jacob 	uint32_t length;
411d82cac58SJerin Jacob 	/**< Segment length. */
412d82cac58SJerin Jacob 	uint32_t reserved;
413d82cac58SJerin Jacob 	/**< Reserved for future use. */
414d82cac58SJerin Jacob 	struct rte_ml_buff_seg *next;
415d82cac58SJerin Jacob 	/**< Points to next segment. Value NULL represents the last segment. */
416d82cac58SJerin Jacob };
417d82cac58SJerin Jacob 
418d82cac58SJerin Jacob /**
419d82cac58SJerin Jacob  * ML Operation.
420d82cac58SJerin Jacob  *
421d82cac58SJerin Jacob  * This structure contains data related to performing an ML operation on the buffers using
422d82cac58SJerin Jacob  * the model specified through model_id.
423d82cac58SJerin Jacob  */
424*c6552d9aSTyler Retzlaff struct __rte_cache_aligned rte_ml_op {
425d82cac58SJerin Jacob 	uint16_t model_id;
426d82cac58SJerin Jacob 	/**< Model ID to be used for the operation. */
427d82cac58SJerin Jacob 	uint16_t nb_batches;
428d82cac58SJerin Jacob 	/**< Number of batches. Minimum value must be one.
429d82cac58SJerin Jacob 	 * Input buffer must hold inference data for each batch as contiguous.
430d82cac58SJerin Jacob 	 */
431d82cac58SJerin Jacob 	uint32_t reserved;
432d82cac58SJerin Jacob 	/**< Reserved for future use. */
433d82cac58SJerin Jacob 	struct rte_mempool *mempool;
434d82cac58SJerin Jacob 	/**< Pool from which operation is allocated. */
43524364292SSrikanth Yalavarthi 	struct rte_ml_buff_seg **input;
43624364292SSrikanth Yalavarthi 	/**< Array of buffer segments to hold the inference input data.
43724364292SSrikanth Yalavarthi 	 *
43824364292SSrikanth Yalavarthi 	 * When the model supports IO layout RTE_ML_IO_LAYOUT_PACKED, size of
43924364292SSrikanth Yalavarthi 	 * the array is 1.
44024364292SSrikanth Yalavarthi 	 *
44124364292SSrikanth Yalavarthi 	 * When the model supports IO layout RTE_ML_IO_LAYOUT_SPLIT, size of
44224364292SSrikanth Yalavarthi 	 * the array is rte_ml_model_info::nb_inputs.
44324364292SSrikanth Yalavarthi 	 *
44424364292SSrikanth Yalavarthi 	 * @see struct rte_ml_dev_info::io_layout
44524364292SSrikanth Yalavarthi 	 */
44624364292SSrikanth Yalavarthi 	struct rte_ml_buff_seg **output;
44724364292SSrikanth Yalavarthi 	/**< Array of buffer segments to hold the inference output data.
44824364292SSrikanth Yalavarthi 	 *
44924364292SSrikanth Yalavarthi 	 * When the model supports IO layout RTE_ML_IO_LAYOUT_PACKED, size of
45024364292SSrikanth Yalavarthi 	 * the array is 1.
45124364292SSrikanth Yalavarthi 	 *
45224364292SSrikanth Yalavarthi 	 * When the model supports IO layout RTE_ML_IO_LAYOUT_SPLIT, size of
45324364292SSrikanth Yalavarthi 	 * the array is rte_ml_model_info::nb_outputs.
45424364292SSrikanth Yalavarthi 	 *
45524364292SSrikanth Yalavarthi 	 * @see struct rte_ml_dev_info::io_layout
45624364292SSrikanth Yalavarthi 	 */
457d82cac58SJerin Jacob 	union {
458d82cac58SJerin Jacob 		uint64_t user_u64;
459d82cac58SJerin Jacob 		/**< User data as uint64_t.*/
460d82cac58SJerin Jacob 		void *user_ptr;
461d82cac58SJerin Jacob 		/**< User data as void*.*/
462d82cac58SJerin Jacob 	};
463d82cac58SJerin Jacob 	enum rte_ml_op_status status;
464d82cac58SJerin Jacob 	/**< Operation status. */
465d82cac58SJerin Jacob 	uint64_t impl_opaque;
466d82cac58SJerin Jacob 	/**< Implementation specific opaque value.
467d82cac58SJerin Jacob 	 * An implementation may use this field to hold
468d82cac58SJerin Jacob 	 * implementation specific value to share between
469d82cac58SJerin Jacob 	 * dequeue and enqueue operation.
470d82cac58SJerin Jacob 	 * The application should not modify this field.
471d82cac58SJerin Jacob 	 */
472*c6552d9aSTyler Retzlaff };
473d82cac58SJerin Jacob 
474d82cac58SJerin Jacob /* Enqueue/Dequeue operations */
475d82cac58SJerin Jacob 
476d82cac58SJerin Jacob /**
477d82cac58SJerin Jacob  * Enqueue a burst of ML inferences for processing on an ML device.
478d82cac58SJerin Jacob  *
479d82cac58SJerin Jacob  * The rte_ml_enqueue_burst() function is invoked to place ML inference
480d82cac58SJerin Jacob  * operations on the queue *qp_id* of the device designated by its *dev_id*.
481d82cac58SJerin Jacob  *
482d82cac58SJerin Jacob  * The *nb_ops* parameter is the number of inferences to process which are
483d82cac58SJerin Jacob  * supplied in the *ops* array of *rte_ml_op* structures.
484d82cac58SJerin Jacob  *
485d82cac58SJerin Jacob  * The rte_ml_enqueue_burst() function returns the number of inferences it
486d82cac58SJerin Jacob  * actually enqueued for processing. A return value equal to *nb_ops* means that
487d82cac58SJerin Jacob  * all packets have been enqueued.
488d82cac58SJerin Jacob  *
489d82cac58SJerin Jacob  * @param dev_id
490d82cac58SJerin Jacob  *   The identifier of the device.
491d82cac58SJerin Jacob  * @param qp_id
492d82cac58SJerin Jacob  *   The index of the queue pair which inferences are to be enqueued for processing.
493d82cac58SJerin Jacob  * The value must be in the range [0, nb_queue_pairs - 1] previously supplied to
494d82cac58SJerin Jacob  * *rte_ml_dev_configure*.
495d82cac58SJerin Jacob  * @param ops
496d82cac58SJerin Jacob  *   The address of an array of *nb_ops* pointers to *rte_ml_op* structures which contain the
497d82cac58SJerin Jacob  * ML inferences to be processed.
498d82cac58SJerin Jacob  * @param nb_ops
499d82cac58SJerin Jacob  *   The number of operations to process.
500d82cac58SJerin Jacob  *
501d82cac58SJerin Jacob  * @return
502d82cac58SJerin Jacob  *   The number of inference operations actually enqueued to the ML device.
503d82cac58SJerin Jacob  * The return value can be less than the value of the *nb_ops* parameter when the ML device queue
504d82cac58SJerin Jacob  * is full or if invalid parameters are specified in a *rte_ml_op*.
505d82cac58SJerin Jacob  */
506d82cac58SJerin Jacob __rte_experimental
507d82cac58SJerin Jacob uint16_t
508d82cac58SJerin Jacob rte_ml_enqueue_burst(int16_t dev_id, uint16_t qp_id, struct rte_ml_op **ops, uint16_t nb_ops);
509d82cac58SJerin Jacob 
510d82cac58SJerin Jacob /**
511d82cac58SJerin Jacob  * Dequeue a burst of processed ML inferences operations from a queue on the ML device.
512d82cac58SJerin Jacob  * The dequeued operations are stored in *rte_ml_op* structures whose pointers are supplied
513d82cac58SJerin Jacob  * in the *ops* array.
514d82cac58SJerin Jacob  *
515d82cac58SJerin Jacob  * The rte_ml_dequeue_burst() function returns the number of inferences actually dequeued,
516d82cac58SJerin Jacob  * which is the number of *rte_ml_op* data structures effectively supplied into the *ops* array.
517d82cac58SJerin Jacob  *
518d82cac58SJerin Jacob  * A return value equal to *nb_ops* indicates that the queue contained at least nb_ops* operations,
519d82cac58SJerin Jacob  * and this is likely to signify that other processed operations remain in the devices output queue.
520d82cac58SJerin Jacob  * Application implementing a "retrieve as many processed operations as possible" policy can check
521d82cac58SJerin Jacob  * this specific case and keep invoking the rte_ml_dequeue_burst() function until a value less than
522d82cac58SJerin Jacob  * *nb_ops* is returned.
523d82cac58SJerin Jacob  *
524d82cac58SJerin Jacob  * The rte_ml_dequeue_burst() function does not provide any error notification to avoid
525d82cac58SJerin Jacob  * the corresponding overhead.
526d82cac58SJerin Jacob  *
527d82cac58SJerin Jacob  * @param dev_id
528d82cac58SJerin Jacob  *   The identifier of the device.
529d82cac58SJerin Jacob  * @param qp_id
530d82cac58SJerin Jacob  *   The index of the queue pair from which to retrieve processed packets.
531d82cac58SJerin Jacob  * The value must be in the range [0, nb_queue_pairs - 1] previously supplied to
532d82cac58SJerin Jacob  * rte_ml_dev_configure().
533d82cac58SJerin Jacob  * @param ops
534d82cac58SJerin Jacob  *   The address of an array of pointers to *rte_ml_op* structures that must be large enough to
535d82cac58SJerin Jacob  * store *nb_ops* pointers in it.
536d82cac58SJerin Jacob  * @param nb_ops
537d82cac58SJerin Jacob  *   The maximum number of inferences to dequeue.
538d82cac58SJerin Jacob  *
539d82cac58SJerin Jacob  * @return
540d82cac58SJerin Jacob  *   The number of operations actually dequeued, which is the number of pointers
541d82cac58SJerin Jacob  * to *rte_ml_op* structures effectively supplied to the *ops* array.
542d82cac58SJerin Jacob  */
543d82cac58SJerin Jacob __rte_experimental
544d82cac58SJerin Jacob uint16_t
545d82cac58SJerin Jacob rte_ml_dequeue_burst(int16_t dev_id, uint16_t qp_id, struct rte_ml_op **ops, uint16_t nb_ops);
546d82cac58SJerin Jacob 
547d82cac58SJerin Jacob /**
548d82cac58SJerin Jacob  * Verbose error structure definition.
549d82cac58SJerin Jacob  */
550d82cac58SJerin Jacob struct rte_ml_op_error {
551d82cac58SJerin Jacob 	char message[RTE_ML_STR_MAX]; /**< Human-readable error message. */
552d82cac58SJerin Jacob 	uint64_t errcode;	      /**< Vendor specific error code. */
553d82cac58SJerin Jacob };
554d82cac58SJerin Jacob 
555d82cac58SJerin Jacob /**
556d82cac58SJerin Jacob  * Get PMD specific error information for an ML op.
557d82cac58SJerin Jacob  *
558d82cac58SJerin Jacob  * When an ML operation completed with RTE_ML_OP_STATUS_ERROR as status,
559d82cac58SJerin Jacob  * This API allows to get PMD specific error details.
560d82cac58SJerin Jacob  *
561d82cac58SJerin Jacob  * @param[in] dev_id
562d82cac58SJerin Jacob  *   Device identifier
563d82cac58SJerin Jacob  * @param[in] op
564d82cac58SJerin Jacob  *   Handle of ML operation
565d82cac58SJerin Jacob  * @param[in] error
566d82cac58SJerin Jacob  *   Address of structure rte_ml_op_error to be filled
567d82cac58SJerin Jacob  *
568d82cac58SJerin Jacob  * @return
569d82cac58SJerin Jacob  *   - Returns 0 on success
570d82cac58SJerin Jacob  *   - Returns negative value on failure
571d82cac58SJerin Jacob  */
572d82cac58SJerin Jacob __rte_experimental
573d82cac58SJerin Jacob int
574d82cac58SJerin Jacob rte_ml_op_error_get(int16_t dev_id, struct rte_ml_op *op, struct rte_ml_op_error *error);
575d82cac58SJerin Jacob 
576d82cac58SJerin Jacob /* Statistics operations */
577d82cac58SJerin Jacob 
578d82cac58SJerin Jacob /** Device statistics. */
579d82cac58SJerin Jacob struct rte_ml_dev_stats {
580d82cac58SJerin Jacob 	uint64_t enqueued_count;
581d82cac58SJerin Jacob 	/**< Count of all operations enqueued */
582d82cac58SJerin Jacob 	uint64_t dequeued_count;
583d82cac58SJerin Jacob 	/**< Count of all operations dequeued */
584d82cac58SJerin Jacob 	uint64_t enqueue_err_count;
585d82cac58SJerin Jacob 	/**< Total error count on operations enqueued */
586d82cac58SJerin Jacob 	uint64_t dequeue_err_count;
587d82cac58SJerin Jacob 	/**< Total error count on operations dequeued */
588d82cac58SJerin Jacob };
589d82cac58SJerin Jacob 
590d82cac58SJerin Jacob /**
591d82cac58SJerin Jacob  * Retrieve the general I/O statistics of a device.
592d82cac58SJerin Jacob  *
593d82cac58SJerin Jacob  * @param dev_id
594d82cac58SJerin Jacob  *   The identifier of the device.
595d82cac58SJerin Jacob  * @param stats
596d82cac58SJerin Jacob  *   Pointer to structure to where statistics will be copied.
597d82cac58SJerin Jacob  * On error, this location may or may not have been modified.
598d82cac58SJerin Jacob  * @return
599d82cac58SJerin Jacob  *   - 0 on success
600d82cac58SJerin Jacob  *   - -EINVAL: If invalid parameter pointer is provided.
601d82cac58SJerin Jacob  */
602d82cac58SJerin Jacob __rte_experimental
603d82cac58SJerin Jacob int
604d82cac58SJerin Jacob rte_ml_dev_stats_get(int16_t dev_id, struct rte_ml_dev_stats *stats);
605d82cac58SJerin Jacob 
606d82cac58SJerin Jacob /**
607d82cac58SJerin Jacob  * Reset the statistics of a device.
608d82cac58SJerin Jacob  *
609d82cac58SJerin Jacob  * @param dev_id
610d82cac58SJerin Jacob  *   The identifier of the device.
611d82cac58SJerin Jacob  */
612d82cac58SJerin Jacob __rte_experimental
613d82cac58SJerin Jacob void
614d82cac58SJerin Jacob rte_ml_dev_stats_reset(int16_t dev_id);
615d82cac58SJerin Jacob 
616d82cac58SJerin Jacob /**
617f06968e9SSrikanth Yalavarthi  * Selects the component of the mldev to retrieve statistics from.
618f06968e9SSrikanth Yalavarthi  */
619f06968e9SSrikanth Yalavarthi enum rte_ml_dev_xstats_mode {
620f06968e9SSrikanth Yalavarthi 	RTE_ML_DEV_XSTATS_DEVICE,
621f06968e9SSrikanth Yalavarthi 	/**< Device xstats */
622f06968e9SSrikanth Yalavarthi 	RTE_ML_DEV_XSTATS_MODEL,
623f06968e9SSrikanth Yalavarthi 	/**< Model xstats */
624f06968e9SSrikanth Yalavarthi };
625f06968e9SSrikanth Yalavarthi 
626f06968e9SSrikanth Yalavarthi /**
627d82cac58SJerin Jacob  * A name-key lookup element for extended statistics.
628d82cac58SJerin Jacob  *
629d82cac58SJerin Jacob  * This structure is used to map between names and ID numbers for extended ML device statistics.
630d82cac58SJerin Jacob  */
631d82cac58SJerin Jacob struct rte_ml_dev_xstats_map {
632d82cac58SJerin Jacob 	uint16_t id;
633d82cac58SJerin Jacob 	/**< xstat identifier */
634d82cac58SJerin Jacob 	char name[RTE_ML_STR_MAX];
635d82cac58SJerin Jacob 	/**< xstat name */
636d82cac58SJerin Jacob };
637d82cac58SJerin Jacob 
638d82cac58SJerin Jacob /**
639f06968e9SSrikanth Yalavarthi  * Retrieve names of extended statistics of an ML device.
640f06968e9SSrikanth Yalavarthi  *
641f06968e9SSrikanth Yalavarthi  * @param dev_id
642f06968e9SSrikanth Yalavarthi  *   The identifier of the device.
643f06968e9SSrikanth Yalavarthi  * @param mode
644f06968e9SSrikanth Yalavarthi  *   Mode of statistics to retrieve. Choices include the device statistics and model statistics.
645f06968e9SSrikanth Yalavarthi  * @param model_id
646f06968e9SSrikanth Yalavarthi  *   Used to specify the model number in model mode, and is ignored in device mode.
647f06968e9SSrikanth Yalavarthi  * @param[out] xstats_map
648f06968e9SSrikanth Yalavarthi  *   Block of memory to insert names and ids into. Must be at least size in capacity. If set to
649f06968e9SSrikanth Yalavarthi  * NULL, function returns required capacity. The id values returned can be passed to
650f06968e9SSrikanth Yalavarthi  * *rte_ml_dev_xstats_get* to select statistics.
651f06968e9SSrikanth Yalavarthi  * @param size
652f06968e9SSrikanth Yalavarthi  *   Capacity of xstats_names (number of xstats_map).
653f06968e9SSrikanth Yalavarthi  * @return
654f06968e9SSrikanth Yalavarthi  *   - Positive value lower or equal to size: success. The return value is the number of entries
655f06968e9SSrikanth Yalavarthi  * filled in the stats table.
656f06968e9SSrikanth Yalavarthi  *   - Positive value higher than size: error, the given statistics table is too small. The return
657f06968e9SSrikanth Yalavarthi  * value corresponds to the size that should be given to succeed. The entries in the table are not
658f06968e9SSrikanth Yalavarthi  * valid and shall not be used by the caller.
659f06968e9SSrikanth Yalavarthi  *   - Negative value on error:
660f06968e9SSrikanth Yalavarthi  *        -ENODEV for invalid *dev_id*.
661f06968e9SSrikanth Yalavarthi  *        -EINVAL for invalid mode, model parameters.
662f06968e9SSrikanth Yalavarthi  *        -ENOTSUP if the device doesn't support this function.
663f06968e9SSrikanth Yalavarthi  */
664f06968e9SSrikanth Yalavarthi __rte_experimental
665f06968e9SSrikanth Yalavarthi int
666f06968e9SSrikanth Yalavarthi rte_ml_dev_xstats_names_get(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id,
667f06968e9SSrikanth Yalavarthi 			    struct rte_ml_dev_xstats_map *xstats_map, uint32_t size);
668f06968e9SSrikanth Yalavarthi 
669f06968e9SSrikanth Yalavarthi /**
670f06968e9SSrikanth Yalavarthi  * Retrieve the value of a single stat by requesting it by name.
671f06968e9SSrikanth Yalavarthi  *
672f06968e9SSrikanth Yalavarthi  * @param dev_id
673f06968e9SSrikanth Yalavarthi  *   The identifier of the device.
674f06968e9SSrikanth Yalavarthi  * @param name
675f06968e9SSrikanth Yalavarthi  *   Name of stat name to retrieve.
676f06968e9SSrikanth Yalavarthi  * @param[out] stat_id
677f06968e9SSrikanth Yalavarthi  *   If non-NULL, the numerical id of the stat will be returned, so that further requests for the
678f06968e9SSrikanth Yalavarthi  * stat can be got using rte_ml_dev_xstats_get, which will be faster as it doesn't need to scan a
679f06968e9SSrikanth Yalavarthi  * list of names for the stat. If the stat cannot be found, the id returned will be (unsigned)-1.
680f06968e9SSrikanth Yalavarthi  * @param[out] value
681f06968e9SSrikanth Yalavarthi  *   Value of the stat to be returned.
682f06968e9SSrikanth Yalavarthi  * @return
683f06968e9SSrikanth Yalavarthi  *   - Zero: No error.
684f06968e9SSrikanth Yalavarthi  *   - Negative value: -EINVAL if stat not found, -ENOTSUP if not supported.
685f06968e9SSrikanth Yalavarthi  */
686f06968e9SSrikanth Yalavarthi __rte_experimental
687f06968e9SSrikanth Yalavarthi int
688f06968e9SSrikanth Yalavarthi rte_ml_dev_xstats_by_name_get(int16_t dev_id, const char *name, uint16_t *stat_id, uint64_t *value);
689f06968e9SSrikanth Yalavarthi 
690f06968e9SSrikanth Yalavarthi /**
691f06968e9SSrikanth Yalavarthi  * Retrieve extended statistics of an ML device.
692f06968e9SSrikanth Yalavarthi  *
693f06968e9SSrikanth Yalavarthi  * @param dev_id
694f06968e9SSrikanth Yalavarthi  *   The identifier of the device.
695f06968e9SSrikanth Yalavarthi  * @param mode
696f06968e9SSrikanth Yalavarthi  *  Mode of statistics to retrieve. Choices include the device statistics and model statistics.
697f06968e9SSrikanth Yalavarthi  * @param model_id
698f06968e9SSrikanth Yalavarthi  *   Used to specify the model id in model mode, and is ignored in device mode.
699f06968e9SSrikanth Yalavarthi  * @param stat_ids
700f06968e9SSrikanth Yalavarthi  *   ID numbers of the stats to get. The ids can be got from the stat position in the stat list from
701f06968e9SSrikanth Yalavarthi  * rte_ml_dev_xstats_names_get(), or by using rte_ml_dev_xstats_by_name_get().
702f06968e9SSrikanth Yalavarthi  * @param[out] values
703f06968e9SSrikanth Yalavarthi  *   Values for each stats request by ID.
704f06968e9SSrikanth Yalavarthi  * @param nb_ids
705f06968e9SSrikanth Yalavarthi  *   Number of stats requested.
706f06968e9SSrikanth Yalavarthi  * @return
707f06968e9SSrikanth Yalavarthi  *   - Positive value: number of stat entries filled into the values array
708f06968e9SSrikanth Yalavarthi  *   - Negative value on error:
709f06968e9SSrikanth Yalavarthi  *        -ENODEV for invalid *dev_id*.
710f06968e9SSrikanth Yalavarthi  *        -EINVAL for invalid mode, model id or stat id parameters.
711f06968e9SSrikanth Yalavarthi  *        -ENOTSUP if the device doesn't support this function.
712f06968e9SSrikanth Yalavarthi  */
713f06968e9SSrikanth Yalavarthi __rte_experimental
714f06968e9SSrikanth Yalavarthi int
715f06968e9SSrikanth Yalavarthi rte_ml_dev_xstats_get(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id,
716f06968e9SSrikanth Yalavarthi 		      const uint16_t stat_ids[], uint64_t values[], uint16_t nb_ids);
717f06968e9SSrikanth Yalavarthi 
718f06968e9SSrikanth Yalavarthi /**
719f06968e9SSrikanth Yalavarthi  * Reset the values of the xstats of the selected component in the device.
720f06968e9SSrikanth Yalavarthi  *
721f06968e9SSrikanth Yalavarthi  * @param dev_id
722f06968e9SSrikanth Yalavarthi  *   The identifier of the device.
723f06968e9SSrikanth Yalavarthi  * @param mode
724f06968e9SSrikanth Yalavarthi  *   Mode of the statistics to reset. Choose from device or model.
725f06968e9SSrikanth Yalavarthi  * @param model_id
726f06968e9SSrikanth Yalavarthi  *   Model stats to reset. 0 and positive values select models, while -1 indicates all models.
727f06968e9SSrikanth Yalavarthi  * @param stat_ids
728f06968e9SSrikanth Yalavarthi  *   Selects specific statistics to be reset. When NULL, all statistics selected by *mode* will be
729f06968e9SSrikanth Yalavarthi  * reset. If non-NULL, must point to array of at least *nb_ids* size.
730f06968e9SSrikanth Yalavarthi  * @param nb_ids
731f06968e9SSrikanth Yalavarthi  *   The number of ids available from the *ids* array. Ignored when ids is NULL.
732f06968e9SSrikanth Yalavarthi  * @return
733f06968e9SSrikanth Yalavarthi  *   - Zero: successfully reset the statistics.
734f06968e9SSrikanth Yalavarthi  *   - Negative value: -EINVAL invalid parameters, -ENOTSUP if not supported.
735f06968e9SSrikanth Yalavarthi  */
736f06968e9SSrikanth Yalavarthi __rte_experimental
737f06968e9SSrikanth Yalavarthi int
738f06968e9SSrikanth Yalavarthi rte_ml_dev_xstats_reset(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id,
739f06968e9SSrikanth Yalavarthi 			const uint16_t stat_ids[], uint16_t nb_ids);
740f06968e9SSrikanth Yalavarthi 
741f06968e9SSrikanth Yalavarthi /**
742d82cac58SJerin Jacob  * Dump internal information about *dev_id* to the FILE* provided in *fd*.
743d82cac58SJerin Jacob  *
744d82cac58SJerin Jacob  * @param dev_id
745d82cac58SJerin Jacob  *   The identifier of the device.
746d82cac58SJerin Jacob  * @param fd
747d82cac58SJerin Jacob  *   A pointer to a file for output.
748d82cac58SJerin Jacob  * @return
749d82cac58SJerin Jacob  *   - 0: on success.
750d82cac58SJerin Jacob  *   - <0: on failure.
751d82cac58SJerin Jacob  */
752d82cac58SJerin Jacob __rte_experimental
753d82cac58SJerin Jacob int
754d82cac58SJerin Jacob rte_ml_dev_dump(int16_t dev_id, FILE *fd);
755d82cac58SJerin Jacob 
756d82cac58SJerin Jacob /**
757d82cac58SJerin Jacob  * Trigger the ML device self test.
758d82cac58SJerin Jacob  *
759d82cac58SJerin Jacob  * @param dev_id
760d82cac58SJerin Jacob  *   The identifier of the device.
761d82cac58SJerin Jacob  * @return
762d82cac58SJerin Jacob  *   - 0: Selftest successful.
763d82cac58SJerin Jacob  *   - -ENOTSUP: if the device doesn't support selftest.
764d82cac58SJerin Jacob  *   - other values < 0 on failure.
765d82cac58SJerin Jacob  */
766d82cac58SJerin Jacob __rte_experimental
767d82cac58SJerin Jacob int
768d82cac58SJerin Jacob rte_ml_dev_selftest(int16_t dev_id);
769d82cac58SJerin Jacob 
770d82cac58SJerin Jacob /* Model operations */
771d82cac58SJerin Jacob 
772d82cac58SJerin Jacob /** ML model load parameters
773d82cac58SJerin Jacob  *
774d82cac58SJerin Jacob  * Parameters required to load an ML model.
775d82cac58SJerin Jacob  */
776d82cac58SJerin Jacob struct rte_ml_model_params {
777d82cac58SJerin Jacob 	void *addr;
778d82cac58SJerin Jacob 	/**< Address of model buffer */
779d82cac58SJerin Jacob 	size_t size;
780d82cac58SJerin Jacob 	/**< Size of model buffer */
781d82cac58SJerin Jacob };
782d82cac58SJerin Jacob 
783d82cac58SJerin Jacob /**
784d82cac58SJerin Jacob  * Load an ML model to the device.
785d82cac58SJerin Jacob  *
786d82cac58SJerin Jacob  * Load an ML model to the device with parameters requested in the structure rte_ml_model_params.
787d82cac58SJerin Jacob  *
788d82cac58SJerin Jacob  * @param[in] dev_id
789d82cac58SJerin Jacob  *   The identifier of the device.
790d82cac58SJerin Jacob  * @param[in] params
791d82cac58SJerin Jacob  *   Parameters for the model to be loaded.
792d82cac58SJerin Jacob  * @param[out] model_id
793d82cac58SJerin Jacob  *   Identifier of the model loaded.
794d82cac58SJerin Jacob  *
795d82cac58SJerin Jacob  * @return
796d82cac58SJerin Jacob  *   - 0: Success, Model loaded.
797d82cac58SJerin Jacob  *   - < 0: Failure, Error code of the model load driver function.
798d82cac58SJerin Jacob  */
799d82cac58SJerin Jacob __rte_experimental
800d82cac58SJerin Jacob int
801d82cac58SJerin Jacob rte_ml_model_load(int16_t dev_id, struct rte_ml_model_params *params, uint16_t *model_id);
802d82cac58SJerin Jacob 
803d82cac58SJerin Jacob /**
804d82cac58SJerin Jacob  * Unload an ML model from the device.
805d82cac58SJerin Jacob  *
806d82cac58SJerin Jacob  * @param[in] dev_id
807d82cac58SJerin Jacob  *   The identifier of the device.
808d82cac58SJerin Jacob  * @param[in] model_id
809d82cac58SJerin Jacob  *   Identifier of the model to be unloaded.
810d82cac58SJerin Jacob  *
811d82cac58SJerin Jacob  * @return
812d82cac58SJerin Jacob  *   - 0: Success, Model unloaded.
813d82cac58SJerin Jacob  *   - < 0: Failure, Error code of the model unload driver function.
814d82cac58SJerin Jacob  */
815d82cac58SJerin Jacob __rte_experimental
816d82cac58SJerin Jacob int
817d82cac58SJerin Jacob rte_ml_model_unload(int16_t dev_id, uint16_t model_id);
818d82cac58SJerin Jacob 
819d82cac58SJerin Jacob /**
820d82cac58SJerin Jacob  * Start an ML model for the given device ID.
821d82cac58SJerin Jacob  *
822d82cac58SJerin Jacob  * Start an ML model to accept inference requests.
823d82cac58SJerin Jacob  *
824d82cac58SJerin Jacob  * @param[in] dev_id
825d82cac58SJerin Jacob  *   The identifier of the device.
826d82cac58SJerin Jacob  * @param[in] model_id
827d82cac58SJerin Jacob  *   Identifier of the model to be started.
828d82cac58SJerin Jacob  *
829d82cac58SJerin Jacob  * @return
830d82cac58SJerin Jacob  *   - 0: Success, Model loaded.
831d82cac58SJerin Jacob  *   - < 0: Failure, Error code of the model start driver function.
832d82cac58SJerin Jacob  */
833d82cac58SJerin Jacob __rte_experimental
834d82cac58SJerin Jacob int
835d82cac58SJerin Jacob rte_ml_model_start(int16_t dev_id, uint16_t model_id);
836d82cac58SJerin Jacob 
837d82cac58SJerin Jacob /**
838d82cac58SJerin Jacob  * Stop an ML model for the given device ID.
839d82cac58SJerin Jacob  *
840d82cac58SJerin Jacob  * Model stop would disable the ML model to be used for inference jobs.
841d82cac58SJerin Jacob  * All inference jobs must have been completed before model stop is attempted.
842d82cac58SJerin Jacob 
843d82cac58SJerin Jacob  * @param[in] dev_id
844d82cac58SJerin Jacob  *   The identifier of the device.
845d82cac58SJerin Jacob  * @param[in] model_id
846d82cac58SJerin Jacob  *   Identifier of the model to be stopped.
847d82cac58SJerin Jacob  *
848d82cac58SJerin Jacob  * @return
849d82cac58SJerin Jacob  *   - 0: Success, Model unloaded.
850d82cac58SJerin Jacob  *   - < 0: Failure, Error code of the model stop driver function.
851d82cac58SJerin Jacob  */
852d82cac58SJerin Jacob __rte_experimental
853d82cac58SJerin Jacob int
854d82cac58SJerin Jacob rte_ml_model_stop(int16_t dev_id, uint16_t model_id);
855d82cac58SJerin Jacob 
856d82cac58SJerin Jacob /**
857d82cac58SJerin Jacob  * Input and output data types. ML models can operate on reduced precision
858d82cac58SJerin Jacob  * datatypes to achieve better power efficiency, lower network latency and lower memory footprint.
859d82cac58SJerin Jacob  * This enum is used to represent the lower precision integer and floating point types used
860d82cac58SJerin Jacob  * by ML models.
861d82cac58SJerin Jacob  */
862d82cac58SJerin Jacob enum rte_ml_io_type {
863d82cac58SJerin Jacob 	RTE_ML_IO_TYPE_UNKNOWN = 0,
864d82cac58SJerin Jacob 	/**< Invalid or unknown type */
865d82cac58SJerin Jacob 	RTE_ML_IO_TYPE_INT8,
866d82cac58SJerin Jacob 	/**< 8-bit integer */
867d82cac58SJerin Jacob 	RTE_ML_IO_TYPE_UINT8,
868d82cac58SJerin Jacob 	/**< 8-bit unsigned integer */
869d82cac58SJerin Jacob 	RTE_ML_IO_TYPE_INT16,
870d82cac58SJerin Jacob 	/**< 16-bit integer */
871d82cac58SJerin Jacob 	RTE_ML_IO_TYPE_UINT16,
872d82cac58SJerin Jacob 	/**< 16-bit unsigned integer */
873d82cac58SJerin Jacob 	RTE_ML_IO_TYPE_INT32,
874d82cac58SJerin Jacob 	/**< 32-bit integer */
875d82cac58SJerin Jacob 	RTE_ML_IO_TYPE_UINT32,
876d82cac58SJerin Jacob 	/**< 32-bit unsigned integer */
87742f3dcd9SSrikanth Yalavarthi 	RTE_ML_IO_TYPE_INT64,
87842f3dcd9SSrikanth Yalavarthi 	/**< 32-bit integer */
87942f3dcd9SSrikanth Yalavarthi 	RTE_ML_IO_TYPE_UINT64,
88042f3dcd9SSrikanth Yalavarthi 	/**< 32-bit unsigned integer */
881d82cac58SJerin Jacob 	RTE_ML_IO_TYPE_FP8,
882d82cac58SJerin Jacob 	/**< 8-bit floating point number */
883d82cac58SJerin Jacob 	RTE_ML_IO_TYPE_FP16,
884d82cac58SJerin Jacob 	/**< IEEE 754 16-bit floating point number */
885d82cac58SJerin Jacob 	RTE_ML_IO_TYPE_FP32,
886d82cac58SJerin Jacob 	/**< IEEE 754 32-bit floating point number */
887d82cac58SJerin Jacob 	RTE_ML_IO_TYPE_BFLOAT16
888d82cac58SJerin Jacob 	/**< 16-bit brain floating point number. */
889d82cac58SJerin Jacob };
890d82cac58SJerin Jacob 
89124364292SSrikanth Yalavarthi /** ML I/O buffer layout */
89224364292SSrikanth Yalavarthi enum rte_ml_io_layout {
89324364292SSrikanth Yalavarthi 	RTE_ML_IO_LAYOUT_PACKED,
89424364292SSrikanth Yalavarthi 	/**< All inputs for the model should packed in a single buffer with
89524364292SSrikanth Yalavarthi 	 * no padding between individual inputs. The buffer is expected to
89624364292SSrikanth Yalavarthi 	 * be aligned to rte_ml_dev_info::align_size.
89724364292SSrikanth Yalavarthi 	 *
89824364292SSrikanth Yalavarthi 	 * When I/O segmentation is supported by the device, the packed
89924364292SSrikanth Yalavarthi 	 * data can be split into multiple segments. In this case, each
90024364292SSrikanth Yalavarthi 	 * segment is expected to be aligned to rte_ml_dev_info::align_size
90124364292SSrikanth Yalavarthi 	 *
90224364292SSrikanth Yalavarthi 	 * Same applies to output.
90324364292SSrikanth Yalavarthi 	 *
90424364292SSrikanth Yalavarthi 	 * @see struct rte_ml_dev_info::max_segments
90524364292SSrikanth Yalavarthi 	 */
90624364292SSrikanth Yalavarthi 	RTE_ML_IO_LAYOUT_SPLIT
90724364292SSrikanth Yalavarthi 	/**< Each input for the model should be stored as separate buffers
90824364292SSrikanth Yalavarthi 	 * and each input should be aligned to rte_ml_dev_info::align_size.
90924364292SSrikanth Yalavarthi 	 *
91024364292SSrikanth Yalavarthi 	 * When I/O segmentation is supported, each input can be split into
91124364292SSrikanth Yalavarthi 	 * multiple segments. In this case, each segment is expected to be
91224364292SSrikanth Yalavarthi 	 * aligned to rte_ml_dev_info::align_size
91324364292SSrikanth Yalavarthi 	 *
91424364292SSrikanth Yalavarthi 	 * Same applies to output.
91524364292SSrikanth Yalavarthi 	 *
91624364292SSrikanth Yalavarthi 	 * @see struct rte_ml_dev_info::max_segments
91724364292SSrikanth Yalavarthi 	 */
91824364292SSrikanth Yalavarthi };
91924364292SSrikanth Yalavarthi 
92024364292SSrikanth Yalavarthi /**
92124364292SSrikanth Yalavarthi  * Input and output data information structure
922d82cac58SJerin Jacob  *
923d82cac58SJerin Jacob  * Specifies the type and shape of input and output data.
924d82cac58SJerin Jacob  */
925d82cac58SJerin Jacob struct rte_ml_io_info {
926d82cac58SJerin Jacob 	char name[RTE_ML_STR_MAX];
927d82cac58SJerin Jacob 	/**< Name of data */
9286ebb6f98SSrikanth Yalavarthi 	uint32_t nb_dims;
9296ebb6f98SSrikanth Yalavarthi 	/**< Number of dimensions in shape */
9306ebb6f98SSrikanth Yalavarthi 	uint32_t *shape;
93124364292SSrikanth Yalavarthi 	/**< Shape of the tensor for rte_ml_model_info::min_batches of the model. */
9326ebb6f98SSrikanth Yalavarthi 	enum rte_ml_io_type type;
9336ebb6f98SSrikanth Yalavarthi 	/**< Type of data
9346ebb6f98SSrikanth Yalavarthi 	 * @see enum rte_ml_io_type
9356ebb6f98SSrikanth Yalavarthi 	 */
9366ebb6f98SSrikanth Yalavarthi 	uint64_t nb_elements;
9376ebb6f98SSrikanth Yalavarthi 	/** Number of elements in tensor */
9386ebb6f98SSrikanth Yalavarthi 	uint64_t size;
9396ebb6f98SSrikanth Yalavarthi 	/** Size of tensor in bytes */
940d82cac58SJerin Jacob };
941d82cac58SJerin Jacob 
942d82cac58SJerin Jacob /** Model information structure */
943d82cac58SJerin Jacob struct rte_ml_model_info {
944d82cac58SJerin Jacob 	char name[RTE_ML_STR_MAX];
945d82cac58SJerin Jacob 	/**< Model name. */
946d82cac58SJerin Jacob 	char version[RTE_ML_STR_MAX];
947d82cac58SJerin Jacob 	/**< Model version */
948d82cac58SJerin Jacob 	uint16_t model_id;
949d82cac58SJerin Jacob 	/**< Model ID */
950d82cac58SJerin Jacob 	uint16_t device_id;
951d82cac58SJerin Jacob 	/**< Device ID */
95224364292SSrikanth Yalavarthi 	enum rte_ml_io_layout io_layout;
95324364292SSrikanth Yalavarthi 	/**< I/O buffer layout for the model */
95424364292SSrikanth Yalavarthi 	uint16_t min_batches;
95524364292SSrikanth Yalavarthi 	/**< Minimum number of batches that the model can process
95624364292SSrikanth Yalavarthi 	 * in one inference request
95724364292SSrikanth Yalavarthi 	 */
95824364292SSrikanth Yalavarthi 	uint16_t max_batches;
95924364292SSrikanth Yalavarthi 	/**< Maximum number of batches that the model can process
96024364292SSrikanth Yalavarthi 	 * in one inference request
96124364292SSrikanth Yalavarthi 	 */
962d82cac58SJerin Jacob 	uint32_t nb_inputs;
963d82cac58SJerin Jacob 	/**< Number of inputs */
964d82cac58SJerin Jacob 	const struct rte_ml_io_info *input_info;
965d82cac58SJerin Jacob 	/**< Input info array. Array size is equal to nb_inputs */
966d82cac58SJerin Jacob 	uint32_t nb_outputs;
967d82cac58SJerin Jacob 	/**< Number of outputs */
968d82cac58SJerin Jacob 	const struct rte_ml_io_info *output_info;
969d82cac58SJerin Jacob 	/**< Output info array. Array size is equal to nb_output */
970d82cac58SJerin Jacob 	uint64_t wb_size;
971d82cac58SJerin Jacob 	/**< Size of model weights and bias */
972d82cac58SJerin Jacob };
973d82cac58SJerin Jacob 
974d82cac58SJerin Jacob /**
975d82cac58SJerin Jacob  * Get ML model information.
976d82cac58SJerin Jacob  *
977d82cac58SJerin Jacob  * @param[in] dev_id
978d82cac58SJerin Jacob  *   The identifier of the device.
979d82cac58SJerin Jacob  * @param[in] model_id
980d82cac58SJerin Jacob  *   Identifier for the model created
981d82cac58SJerin Jacob  * @param[out] model_info
982d82cac58SJerin Jacob  *   Pointer to a model info structure
983d82cac58SJerin Jacob  *
984d82cac58SJerin Jacob  * @return
985d82cac58SJerin Jacob  *   - Returns 0 on success
986d82cac58SJerin Jacob  *   - Returns negative value on failure
987d82cac58SJerin Jacob  */
988d82cac58SJerin Jacob __rte_experimental
989d82cac58SJerin Jacob int
990d82cac58SJerin Jacob rte_ml_model_info_get(int16_t dev_id, uint16_t model_id, struct rte_ml_model_info *model_info);
991d82cac58SJerin Jacob 
992d82cac58SJerin Jacob /**
993d82cac58SJerin Jacob  * Update the model parameters without unloading model.
994d82cac58SJerin Jacob  *
995d82cac58SJerin Jacob  * Update model parameters such as weights and bias without unloading the model.
996d82cac58SJerin Jacob  * rte_ml_model_stop() must be called before invoking this API.
997d82cac58SJerin Jacob  *
998d82cac58SJerin Jacob  * @param[in] dev_id
999d82cac58SJerin Jacob  *   The identifier of the device.
1000d82cac58SJerin Jacob  * @param[in] model_id
1001d82cac58SJerin Jacob  *   Identifier for the model created
1002d82cac58SJerin Jacob  * @param[in] buffer
1003d82cac58SJerin Jacob  *   Pointer to the model weights and bias buffer.
1004d82cac58SJerin Jacob  * Size of the buffer is equal to wb_size returned in *rte_ml_model_info*.
1005d82cac58SJerin Jacob  *
1006d82cac58SJerin Jacob  * @return
1007d82cac58SJerin Jacob  *   - Returns 0 on success
1008d82cac58SJerin Jacob  *   - Returns negative value on failure
1009d82cac58SJerin Jacob  */
1010d82cac58SJerin Jacob __rte_experimental
1011d82cac58SJerin Jacob int
1012d82cac58SJerin Jacob rte_ml_model_params_update(int16_t dev_id, uint16_t model_id, void *buffer);
1013d82cac58SJerin Jacob 
1014d82cac58SJerin Jacob /* IO operations */
1015d82cac58SJerin Jacob 
1016d82cac58SJerin Jacob /**
1017d82cac58SJerin Jacob  * Quantize input data.
1018d82cac58SJerin Jacob  *
1019d82cac58SJerin Jacob  * Quantization converts data from a higher precision types to a lower precision types to improve
1020d82cac58SJerin Jacob  * the throughput and efficiency of the model execution with minimal loss of accuracy.
1021d82cac58SJerin Jacob  * Types of dequantized data and quantized data are specified by the model.
1022d82cac58SJerin Jacob  *
1023d82cac58SJerin Jacob  * @param[in] dev_id
1024d82cac58SJerin Jacob  *   The identifier of the device.
1025d82cac58SJerin Jacob  * @param[in] model_id
1026d82cac58SJerin Jacob  *   Identifier for the model
1027d82cac58SJerin Jacob  * @param[in] dbuffer
1028d82cac58SJerin Jacob  *   Address of dequantized input data
1029d82cac58SJerin Jacob  * @param[in] qbuffer
1030d82cac58SJerin Jacob  *   Address of quantized input data
1031d82cac58SJerin Jacob  *
1032d82cac58SJerin Jacob  * @return
1033d82cac58SJerin Jacob  *   - Returns 0 on success
1034d82cac58SJerin Jacob  *   - Returns negative value on failure
1035d82cac58SJerin Jacob  */
1036d82cac58SJerin Jacob __rte_experimental
1037d82cac58SJerin Jacob int
103824364292SSrikanth Yalavarthi rte_ml_io_quantize(int16_t dev_id, uint16_t model_id, struct rte_ml_buff_seg **dbuffer,
103924364292SSrikanth Yalavarthi 		   struct rte_ml_buff_seg **qbuffer);
1040d82cac58SJerin Jacob 
1041d82cac58SJerin Jacob /**
1042d82cac58SJerin Jacob  * Dequantize output data.
1043d82cac58SJerin Jacob  *
1044d82cac58SJerin Jacob  * Dequantization converts data from a lower precision type to a higher precision type.
1045d82cac58SJerin Jacob  * Types of quantized data and dequantized are specified by the model.
1046d82cac58SJerin Jacob  *
1047d82cac58SJerin Jacob  * @param[in] dev_id
1048d82cac58SJerin Jacob  *   The identifier of the device.
1049d82cac58SJerin Jacob  * @param[in] model_id
1050d82cac58SJerin Jacob  *   Identifier for the model
1051d82cac58SJerin Jacob  * @param[in] qbuffer
1052d82cac58SJerin Jacob  *   Address of quantized output data
1053d82cac58SJerin Jacob  * @param[in] dbuffer
1054d82cac58SJerin Jacob  *   Address of dequantized output data
1055d82cac58SJerin Jacob  *
1056d82cac58SJerin Jacob  * @return
1057d82cac58SJerin Jacob  *   - Returns 0 on success
1058d82cac58SJerin Jacob  *   - Returns negative value on failure
1059d82cac58SJerin Jacob  */
1060d82cac58SJerin Jacob __rte_experimental
1061d82cac58SJerin Jacob int
106224364292SSrikanth Yalavarthi rte_ml_io_dequantize(int16_t dev_id, uint16_t model_id, struct rte_ml_buff_seg **qbuffer,
106324364292SSrikanth Yalavarthi 		     struct rte_ml_buff_seg **dbuffer);
1064d82cac58SJerin Jacob 
1065d82cac58SJerin Jacob /* ML op pool operations */
1066d82cac58SJerin Jacob 
1067d82cac58SJerin Jacob /**
1068d82cac58SJerin Jacob  * Create an ML operation pool
1069d82cac58SJerin Jacob  *
1070d82cac58SJerin Jacob  * @param name
1071d82cac58SJerin Jacob  *   ML operations pool name
1072d82cac58SJerin Jacob  * @param nb_elts
1073d82cac58SJerin Jacob  *   Number of elements in pool
1074d82cac58SJerin Jacob  * @param cache_size
1075d82cac58SJerin Jacob  *   Number of elements to cache on lcore, see
1076d82cac58SJerin Jacob  *   *rte_mempool_create* for further details about cache size
1077d82cac58SJerin Jacob  * @param user_size
1078d82cac58SJerin Jacob  *   Size of private data to allocate for user with each operation
1079d82cac58SJerin Jacob  * @param socket_id
1080d82cac58SJerin Jacob  *   Socket to identifier allocate memory on
1081d82cac58SJerin Jacob  * @return
1082d82cac58SJerin Jacob  *  - On success pointer to mempool
1083d82cac58SJerin Jacob  *  - On failure NULL
1084d82cac58SJerin Jacob  */
1085d82cac58SJerin Jacob __rte_experimental
1086d82cac58SJerin Jacob struct rte_mempool *
1087d82cac58SJerin Jacob rte_ml_op_pool_create(const char *name, unsigned int nb_elts, unsigned int cache_size,
1088d82cac58SJerin Jacob 		      uint16_t user_size, int socket_id);
1089d82cac58SJerin Jacob 
1090d82cac58SJerin Jacob /**
1091d82cac58SJerin Jacob  * Free an ML operation pool
1092d82cac58SJerin Jacob  *
1093d82cac58SJerin Jacob  * @param mempool
1094d82cac58SJerin Jacob  *   A pointer to the mempool structure.
1095d82cac58SJerin Jacob  *   If NULL then, the function does nothing.
1096d82cac58SJerin Jacob  */
1097d82cac58SJerin Jacob __rte_experimental
1098d82cac58SJerin Jacob void
1099d82cac58SJerin Jacob rte_ml_op_pool_free(struct rte_mempool *mempool);
1100d82cac58SJerin Jacob 
1101d82cac58SJerin Jacob #ifdef __cplusplus
1102d82cac58SJerin Jacob }
1103d82cac58SJerin Jacob #endif
1104d82cac58SJerin Jacob 
1105d82cac58SJerin Jacob #endif /* RTE_MLDEV_H */
1106