DPDK  24.11.0-rc3
rte_mldev.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2022 Marvell.
3  */
4 
5 #ifndef RTE_MLDEV_H
6 #define RTE_MLDEV_H
7 
137 #include <rte_common.h>
138 #include <rte_log.h>
139 #include <rte_mempool.h>
140 
141 #ifdef __cplusplus
142 extern "C" {
143 #endif
144 
145 /* Logging Macro */
146 extern int rte_ml_dev_logtype;
147 #define RTE_LOGTYPE_MLDEV rte_ml_dev_logtype
148 
149 #define RTE_MLDEV_LOG(level, ...) \
150  RTE_LOG_LINE_PREFIX(level, MLDEV, "%s(): ", __func__, __VA_ARGS__)
151 
152 #define RTE_ML_STR_MAX 128
153 
155 #define RTE_MLDEV_DEFAULT_MAX 32
156 
158 /* Device operations */
159 
173 __rte_experimental
174 int
175 rte_ml_dev_init(size_t dev_max);
176 
183 __rte_experimental
184 uint16_t
185 rte_ml_dev_count(void);
186 
197 __rte_experimental
198 int
199 rte_ml_dev_is_valid_dev(int16_t dev_id);
200 
212 __rte_experimental
213 int
214 rte_ml_dev_socket_id(int16_t dev_id);
215 
218  const char *driver_name;
220  uint16_t max_models;
224  uint16_t max_queue_pairs;
228  uint16_t max_desc;
232  uint16_t max_io;
234  uint16_t max_segments;
238  uint16_t align_size;
240 };
241 
254 __rte_experimental
255 int
256 rte_ml_dev_info_get(int16_t dev_id, struct rte_ml_dev_info *dev_info);
257 
262  uint16_t nb_models;
267  uint16_t nb_queue_pairs;
272 };
273 
294 __rte_experimental
295 int
296 rte_ml_dev_configure(int16_t dev_id, const struct rte_ml_dev_config *config);
297 
298 /* Forward declaration */
299 struct rte_ml_op;
300 
302 typedef void (*rte_ml_dev_stop_flush_t)(int16_t dev_id, uint16_t qp_id, struct rte_ml_op *op);
303 
306  uint32_t nb_desc;
318 };
319 
329 __rte_experimental
330 uint16_t
331 rte_ml_dev_queue_pair_count(int16_t dev_id);
332 
352 __rte_experimental
353 int
354 rte_ml_dev_queue_pair_setup(int16_t dev_id, uint16_t queue_pair_id,
355  const struct rte_ml_dev_qp_conf *qp_conf, int socket_id);
356 
370 __rte_experimental
371 int
372 rte_ml_dev_start(int16_t dev_id);
373 
385 __rte_experimental
386 int
387 rte_ml_dev_stop(int16_t dev_id);
388 
399 __rte_experimental
400 int
401 rte_ml_dev_close(int16_t dev_id);
402 
414 };
415 
421  void *addr;
423  uint32_t length;
425  uint32_t reserved;
429 };
430 
438  uint16_t model_id;
440  uint16_t nb_batches;
444  uint32_t reserved;
470  union {
471  uint64_t user_u64;
473  void *user_ptr;
475  };
476  enum rte_ml_op_status status;
478  uint64_t impl_opaque;
485 };
486 
487 /* Enqueue/Dequeue operations */
488 
519 __rte_experimental
520 uint16_t
521 rte_ml_enqueue_burst(int16_t dev_id, uint16_t qp_id, struct rte_ml_op **ops, uint16_t nb_ops);
522 
556 __rte_experimental
557 uint16_t
558 rte_ml_dequeue_burst(int16_t dev_id, uint16_t qp_id, struct rte_ml_op **ops, uint16_t nb_ops);
559 
564  char message[RTE_ML_STR_MAX];
565  uint64_t errcode;
566 };
567 
585 __rte_experimental
586 int
587 rte_ml_op_error_get(int16_t dev_id, struct rte_ml_op *op, struct rte_ml_op_error *error);
588 
589 /* Statistics operations */
590 
593  uint64_t enqueued_count;
595  uint64_t dequeued_count;
601 };
602 
615 __rte_experimental
616 int
617 rte_ml_dev_stats_get(int16_t dev_id, struct rte_ml_dev_stats *stats);
618 
625 __rte_experimental
626 void
627 rte_ml_dev_stats_reset(int16_t dev_id);
628 
637 };
638 
645  uint16_t id;
647  char name[RTE_ML_STR_MAX];
649 };
650 
677 __rte_experimental
678 int
679 rte_ml_dev_xstats_names_get(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id,
680  struct rte_ml_dev_xstats_map *xstats_map, uint32_t size);
681 
699 __rte_experimental
700 int
701 rte_ml_dev_xstats_by_name_get(int16_t dev_id, const char *name, uint16_t *stat_id, uint64_t *value);
702 
726 __rte_experimental
727 int
728 rte_ml_dev_xstats_get(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id,
729  const uint16_t stat_ids[], uint64_t values[], uint16_t nb_ids);
730 
749 __rte_experimental
750 int
751 rte_ml_dev_xstats_reset(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id,
752  const uint16_t stat_ids[], uint16_t nb_ids);
753 
765 __rte_experimental
766 int
767 rte_ml_dev_dump(int16_t dev_id, FILE *fd);
768 
779 __rte_experimental
780 int
781 rte_ml_dev_selftest(int16_t dev_id);
782 
783 /* Model operations */
784 
790  void *addr;
792  size_t size;
794 };
795 
812 __rte_experimental
813 int
814 rte_ml_model_load(int16_t dev_id, struct rte_ml_model_params *params, uint16_t *model_id);
815 
828 __rte_experimental
829 int
830 rte_ml_model_unload(int16_t dev_id, uint16_t model_id);
831 
846 __rte_experimental
847 int
848 rte_ml_model_start(int16_t dev_id, uint16_t model_id);
849 
865 __rte_experimental
866 int
867 rte_ml_model_stop(int16_t dev_id, uint16_t model_id);
868 
902 };
903 
931 };
932 
939  char name[RTE_ML_STR_MAX];
941  uint32_t nb_dims;
943  uint32_t *shape;
945  enum rte_ml_io_type type;
949  uint64_t nb_elements;
951  uint64_t size;
953  float scale;
955  int64_t zero_point;
957 };
958 
961  char name[RTE_ML_STR_MAX];
963  char version[RTE_ML_STR_MAX];
965  uint16_t model_id;
967  uint16_t device_id;
969  enum rte_ml_io_layout io_layout;
971  uint16_t min_batches;
975  uint16_t max_batches;
979  uint32_t nb_inputs;
981  const struct rte_ml_io_info *input_info;
983  uint32_t nb_outputs;
987  uint64_t wb_size;
989 };
990 
1005 __rte_experimental
1006 int
1007 rte_ml_model_info_get(int16_t dev_id, uint16_t model_id, struct rte_ml_model_info *model_info);
1008 
1027 __rte_experimental
1028 int
1029 rte_ml_model_params_update(int16_t dev_id, uint16_t model_id, void *buffer);
1030 
1031 /* IO operations */
1032 
1052 __rte_experimental
1053 int
1054 rte_ml_io_float32_to_int8(const void *fp32, void *i8, uint64_t nb_elements, float scale,
1055  int8_t zero_point);
1056 
1076 __rte_experimental
1077 int
1078 rte_ml_io_int8_to_float32(const void *i8, void *fp32, uint64_t nb_elements, float scale,
1079  int8_t zero_point);
1080 
1100 __rte_experimental
1101 int
1102 rte_ml_io_float32_to_uint8(const void *fp32, void *ui8, uint64_t nb_elements, float scale,
1103  uint8_t zero_point);
1104 
1124 __rte_experimental
1125 int
1126 rte_ml_io_uint8_to_float32(const void *ui8, void *fp32, uint64_t nb_elements, float scale,
1127  uint8_t zero_point);
1128 
1148 __rte_experimental
1149 int
1150 rte_ml_io_float32_to_int16(const void *fp32, void *i16, uint64_t nb_elements, float scale,
1151  int16_t zero_point);
1152 
1172 __rte_experimental
1173 int
1174 rte_ml_io_int16_to_float32(const void *i16, void *fp32, uint64_t nb_elements, float scale,
1175  int16_t zero_point);
1176 
1196 __rte_experimental
1197 int
1198 rte_ml_io_float32_to_uint16(const void *fp32, void *ui16, uint64_t nb_elements, float scale,
1199  uint16_t zero_point);
1200 
1220 __rte_experimental
1221 int
1222 rte_ml_io_uint16_to_float32(const void *ui16, void *fp32, uint64_t nb_elements, float scale,
1223  uint16_t zero_point);
1224 
1244 __rte_experimental
1245 int
1246 rte_ml_io_float32_to_int32(const void *fp32, void *i32, uint64_t nb_elements, float scale,
1247  int32_t zero_point);
1248 
1269 __rte_experimental
1270 int
1271 rte_ml_io_int32_to_float32(const void *i32, void *fp32, uint64_t nb_elements, float scale,
1272  int32_t zero_point);
1273 
1293 __rte_experimental
1294 int
1295 rte_ml_io_float32_to_uint32(const void *fp32, void *ui32, uint64_t nb_elements, float scale,
1296  uint32_t zero_point);
1297 
1317 __rte_experimental
1318 int
1319 rte_ml_io_uint32_to_float32(const void *ui32, void *fp32, uint64_t nb_elements, float scale,
1320  uint32_t zero_point);
1321 
1341 __rte_experimental
1342 int
1343 rte_ml_io_float32_to_int64(const void *fp32, void *i64, uint64_t nb_elements, float scale,
1344  int64_t zero_point);
1345 
1365 __rte_experimental
1366 int
1367 rte_ml_io_int64_to_float32(const void *i64, void *fp32, uint64_t nb_elements, float scale,
1368  int64_t zero_point);
1369 
1389 __rte_experimental
1390 int
1391 rte_ml_io_float32_to_uint64(const void *fp32, void *ui64, uint64_t nb_elements, float scale,
1392  uint64_t zero_point);
1393 
1413 __rte_experimental
1414 int
1415 rte_ml_io_uint64_to_float32(const void *ui64, void *fp32, uint64_t nb_elements, float scale,
1416  uint64_t zero_point);
1417 
1433 __rte_experimental
1434 int
1435 rte_ml_io_float32_to_float16(const void *fp32, void *fp16, uint64_t nb_elements);
1436 
1452 __rte_experimental
1453 int
1454 rte_ml_io_float16_to_float32(const void *fp16, void *fp32, uint64_t nb_elements);
1455 
1471 __rte_experimental
1472 int
1473 rte_ml_io_float32_to_bfloat16(const void *fp32, void *bf16, uint64_t nb_elements);
1474 
1491 __rte_experimental
1492 int
1493 rte_ml_io_bfloat16_to_float32(const void *bf16, void *fp32, uint64_t nb_elements);
1494 
1515 __rte_experimental
1516 int
1517 rte_ml_io_quantize(int16_t dev_id, uint16_t model_id, struct rte_ml_buff_seg **dbuffer,
1518  struct rte_ml_buff_seg **qbuffer);
1519 
1539 __rte_experimental
1540 int
1541 rte_ml_io_dequantize(int16_t dev_id, uint16_t model_id, struct rte_ml_buff_seg **qbuffer,
1542  struct rte_ml_buff_seg **dbuffer);
1543 
1544 /* ML op pool operations */
1545 
1564 __rte_experimental
1565 struct rte_mempool *
1566 rte_ml_op_pool_create(const char *name, unsigned int nb_elts, unsigned int cache_size,
1567  uint16_t user_size, int socket_id);
1568 
1576 __rte_experimental
1577 void
1578 rte_ml_op_pool_free(struct rte_mempool *mempool);
1579 
1580 #ifdef __cplusplus
1581 }
1582 #endif
1583 
1584 #endif /* RTE_MLDEV_H */
__rte_experimental int rte_ml_dev_selftest(int16_t dev_id)
uint32_t length
Definition: rte_mldev.h:423
__rte_experimental int rte_ml_dev_is_valid_dev(int16_t dev_id)
__rte_experimental void rte_ml_dev_stats_reset(int16_t dev_id)
__rte_experimental int rte_ml_io_float16_to_float32(const void *fp16, void *fp32, uint64_t nb_elements)
uint32_t nb_inputs
Definition: rte_mldev.h:979
__rte_experimental uint16_t rte_ml_dequeue_burst(int16_t dev_id, uint16_t qp_id, struct rte_ml_op **ops, uint16_t nb_ops)
__rte_experimental int rte_ml_io_float32_to_uint32(const void *fp32, void *ui32, uint64_t nb_elements, float scale, uint32_t zero_point)
uint32_t nb_desc
Definition: rte_mldev.h:306
__rte_experimental int rte_ml_io_uint32_to_float32(const void *ui32, void *fp32, uint64_t nb_elements, float scale, uint32_t zero_point)
__rte_experimental int rte_ml_io_float32_to_int64(const void *fp32, void *i64, uint64_t nb_elements, float scale, int64_t zero_point)
__rte_experimental int rte_ml_io_uint16_to_float32(const void *ui16, void *fp32, uint64_t nb_elements, float scale, uint16_t zero_point)
uint32_t reserved
Definition: rte_mldev.h:425
#define RTE_ML_STR_MAX
Definition: rte_mldev.h:152
struct rte_ml_buff_seg * next
Definition: rte_mldev.h:427
__rte_experimental int rte_ml_model_load(int16_t dev_id, struct rte_ml_model_params *params, uint16_t *model_id)
uint16_t align_size
Definition: rte_mldev.h:238
const char * driver_name
Definition: rte_mldev.h:218
uint16_t device_id
Definition: rte_mldev.h:967
__rte_experimental int rte_ml_io_bfloat16_to_float32(const void *bf16, void *fp32, uint64_t nb_elements)
uint64_t rte_iova_t
Definition: rte_common.h:658
struct rte_mempool * mempool
Definition: rte_mldev.h:446
__rte_experimental int rte_ml_io_float32_to_int16(const void *fp32, void *i16, uint64_t nb_elements, float scale, int16_t zero_point)
__rte_experimental int rte_ml_op_error_get(int16_t dev_id, struct rte_ml_op *op, struct rte_ml_op_error *error)
__rte_experimental int rte_ml_io_uint8_to_float32(const void *ui8, void *fp32, uint64_t nb_elements, float scale, uint8_t zero_point)
__rte_experimental int rte_ml_dev_xstats_reset(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id, const uint16_t stat_ids[], uint16_t nb_ids)
uint16_t max_models
Definition: rte_mldev.h:220
uint16_t nb_queue_pairs
Definition: rte_mldev.h:267
struct rte_ml_buff_seg ** input
Definition: rte_mldev.h:448
uint64_t impl_opaque
Definition: rte_mldev.h:478
#define __rte_cache_aligned
Definition: rte_common.h:627
uint32_t cache_size
Definition: rte_mempool.h:241
char name[RTE_MEMPOOL_NAMESIZE]
Definition: rte_mempool.h:231
__rte_experimental int rte_ml_dev_xstats_by_name_get(int16_t dev_id, const char *name, uint16_t *stat_id, uint64_t *value)
uint32_t reserved
Definition: rte_mldev.h:444
__rte_experimental int rte_ml_model_info_get(int16_t dev_id, uint16_t model_id, struct rte_ml_model_info *model_info)
rte_ml_dev_xstats_mode
Definition: rte_mldev.h:632
uint16_t nb_batches
Definition: rte_mldev.h:440
__rte_experimental int rte_ml_dev_init(size_t dev_max)
__rte_experimental uint16_t rte_ml_dev_queue_pair_count(int16_t dev_id)
uint64_t wb_size
Definition: rte_mldev.h:987
__rte_experimental int rte_ml_io_dequantize(int16_t dev_id, uint16_t model_id, struct rte_ml_buff_seg **qbuffer, struct rte_ml_buff_seg **dbuffer)
uint64_t user_u64
Definition: rte_mldev.h:471
__rte_experimental void rte_ml_op_pool_free(struct rte_mempool *mempool)
__rte_experimental int rte_ml_model_start(int16_t dev_id, uint16_t model_id)
__rte_experimental int rte_ml_model_params_update(int16_t dev_id, uint16_t model_id, void *buffer)
__rte_experimental int rte_ml_dev_stats_get(int16_t dev_id, struct rte_ml_dev_stats *stats)
rte_ml_dev_stop_flush_t cb
Definition: rte_mldev.h:311
rte_ml_io_type
Definition: rte_mldev.h:875
__rte_experimental int rte_ml_io_float32_to_uint64(const void *fp32, void *ui64, uint64_t nb_elements, float scale, uint64_t zero_point)
__rte_experimental int rte_ml_io_float32_to_bfloat16(const void *fp32, void *bf16, uint64_t nb_elements)
__rte_experimental uint16_t rte_ml_dev_count(void)
__rte_experimental int rte_ml_io_float32_to_float16(const void *fp32, void *fp16, uint64_t nb_elements)
uint32_t nb_dims
Definition: rte_mldev.h:941
__rte_experimental int rte_ml_io_quantize(int16_t dev_id, uint16_t model_id, struct rte_ml_buff_seg **dbuffer, struct rte_ml_buff_seg **qbuffer)
__rte_experimental int rte_ml_model_unload(int16_t dev_id, uint16_t model_id)
uint64_t enqueued_count
Definition: rte_mldev.h:593
rte_ml_io_layout
Definition: rte_mldev.h:905
uint16_t model_id
Definition: rte_mldev.h:438
__rte_experimental int rte_ml_io_int32_to_float32(const void *i32, void *fp32, uint64_t nb_elements, float scale, int32_t zero_point)
rte_ml_op_status
Definition: rte_mldev.h:404
uint64_t errcode
Definition: rte_mldev.h:565
uint32_t nb_outputs
Definition: rte_mldev.h:983
uint16_t max_desc
Definition: rte_mldev.h:228
__rte_experimental int rte_ml_io_float32_to_int8(const void *fp32, void *i8, uint64_t nb_elements, float scale, int8_t zero_point)
uint32_t * shape
Definition: rte_mldev.h:943
__rte_experimental int rte_ml_dev_start(int16_t dev_id)
__rte_experimental int rte_ml_io_float32_to_uint8(const void *fp32, void *ui8, uint64_t nb_elements, float scale, uint8_t zero_point)
void(* rte_ml_dev_stop_flush_t)(int16_t dev_id, uint16_t qp_id, struct rte_ml_op *op)
Definition: rte_mldev.h:302
__rte_experimental uint16_t rte_ml_enqueue_burst(int16_t dev_id, uint16_t qp_id, struct rte_ml_op **ops, uint16_t nb_ops)
__rte_experimental int rte_ml_io_float32_to_uint16(const void *fp32, void *ui16, uint64_t nb_elements, float scale, uint16_t zero_point)
__rte_experimental int rte_ml_dev_info_get(int16_t dev_id, struct rte_ml_dev_info *dev_info)
uint16_t model_id
Definition: rte_mldev.h:965
uint64_t nb_elements
Definition: rte_mldev.h:949
struct rte_ml_buff_seg ** output
Definition: rte_mldev.h:459
__rte_experimental int rte_ml_dev_xstats_names_get(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id, struct rte_ml_dev_xstats_map *xstats_map, uint32_t size)
__rte_experimental int rte_ml_dev_socket_id(int16_t dev_id)
uint16_t max_segments
Definition: rte_mldev.h:234
__rte_experimental int rte_ml_io_uint64_to_float32(const void *ui64, void *fp32, uint64_t nb_elements, float scale, uint64_t zero_point)
uint16_t max_io
Definition: rte_mldev.h:232
uint16_t min_batches
Definition: rte_mldev.h:971
uint64_t dequeued_count
Definition: rte_mldev.h:595
__rte_experimental int rte_ml_io_int64_to_float32(const void *i64, void *fp32, uint64_t nb_elements, float scale, int64_t zero_point)
void * user_ptr
Definition: rte_mldev.h:473
__rte_experimental int rte_ml_io_int8_to_float32(const void *i8, void *fp32, uint64_t nb_elements, float scale, int8_t zero_point)
uint16_t nb_models
Definition: rte_mldev.h:262
uint64_t dequeue_err_count
Definition: rte_mldev.h:599
__rte_experimental int rte_ml_dev_configure(int16_t dev_id, const struct rte_ml_dev_config *config)
__rte_experimental int rte_ml_dev_queue_pair_setup(int16_t dev_id, uint16_t queue_pair_id, const struct rte_ml_dev_qp_conf *qp_conf, int socket_id)
__rte_experimental struct rte_mempool * rte_ml_op_pool_create(const char *name, unsigned int nb_elts, unsigned int cache_size, uint16_t user_size, int socket_id)
uint64_t enqueue_err_count
Definition: rte_mldev.h:597
__rte_experimental int rte_ml_dev_xstats_get(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id, const uint16_t stat_ids[], uint64_t values[], uint16_t nb_ids)
__rte_experimental int rte_ml_dev_close(int16_t dev_id)
__rte_experimental int rte_ml_dev_stop(int16_t dev_id)
uint16_t max_batches
Definition: rte_mldev.h:975
__rte_experimental int rte_ml_io_float32_to_int32(const void *fp32, void *i32, uint64_t nb_elements, float scale, int32_t zero_point)
uint16_t max_queue_pairs
Definition: rte_mldev.h:224
__rte_experimental int rte_ml_model_stop(int16_t dev_id, uint16_t model_id)
int64_t zero_point
Definition: rte_mldev.h:955
__rte_experimental int rte_ml_io_int16_to_float32(const void *i16, void *fp32, uint64_t nb_elements, float scale, int16_t zero_point)
__rte_experimental int rte_ml_dev_dump(int16_t dev_id, FILE *fd)
const struct rte_ml_io_info * input_info
Definition: rte_mldev.h:981
const struct rte_ml_io_info * output_info
Definition: rte_mldev.h:985
uint64_t size
Definition: rte_mldev.h:951
rte_iova_t iova_addr
Definition: rte_mldev.h:419