DPDK  23.07.0
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 
148 #define RTE_MLDEV_LOG(level, fmt, args...) \
149  rte_log(RTE_LOG_##level, rte_ml_dev_logtype, "%s(): " fmt "\n", __func__, ##args)
150 
151 #define RTE_ML_STR_MAX 128
152 
154 #define RTE_MLDEV_DEFAULT_MAX 32
155 
157 /* Device operations */
158 
172 __rte_experimental
173 int
174 rte_ml_dev_init(size_t dev_max);
175 
182 __rte_experimental
183 uint16_t
184 rte_ml_dev_count(void);
185 
196 __rte_experimental
197 int
198 rte_ml_dev_is_valid_dev(int16_t dev_id);
199 
211 __rte_experimental
212 int
213 rte_ml_dev_socket_id(int16_t dev_id);
214 
217  const char *driver_name;
219  uint16_t max_models;
223  uint16_t max_queue_pairs;
227  uint16_t max_desc;
231  uint16_t max_segments;
235  uint16_t min_align_size;
237 };
238 
251 __rte_experimental
252 int
253 rte_ml_dev_info_get(int16_t dev_id, struct rte_ml_dev_info *dev_info);
254 
259  uint16_t nb_models;
264  uint16_t nb_queue_pairs;
269 };
270 
291 __rte_experimental
292 int
293 rte_ml_dev_configure(int16_t dev_id, const struct rte_ml_dev_config *config);
294 
295 /* Forward declaration */
296 struct rte_ml_op;
297 
299 typedef void (*rte_ml_dev_stop_flush_t)(int16_t dev_id, uint16_t qp_id, struct rte_ml_op *op);
300 
303  uint32_t nb_desc;
315 };
316 
336 __rte_experimental
337 int
338 rte_ml_dev_queue_pair_setup(int16_t dev_id, uint16_t queue_pair_id,
339  const struct rte_ml_dev_qp_conf *qp_conf, int socket_id);
340 
354 __rte_experimental
355 int
356 rte_ml_dev_start(int16_t dev_id);
357 
369 __rte_experimental
370 int
371 rte_ml_dev_stop(int16_t dev_id);
372 
383 __rte_experimental
384 int
385 rte_ml_dev_close(int16_t dev_id);
386 
398 };
399 
405  void *addr;
407  uint32_t length;
409  uint32_t reserved;
413 };
414 
421 struct rte_ml_op {
422  uint16_t model_id;
424  uint16_t nb_batches;
428  uint32_t reserved;
432  struct rte_ml_buff_seg input;
434  struct rte_ml_buff_seg output;
437  union {
438  uint64_t user_u64;
440  void *user_ptr;
442  };
443  enum rte_ml_op_status status;
445  uint64_t impl_opaque;
453 
454 /* Enqueue/Dequeue operations */
455 
486 __rte_experimental
487 uint16_t
488 rte_ml_enqueue_burst(int16_t dev_id, uint16_t qp_id, struct rte_ml_op **ops, uint16_t nb_ops);
489 
523 __rte_experimental
524 uint16_t
525 rte_ml_dequeue_burst(int16_t dev_id, uint16_t qp_id, struct rte_ml_op **ops, uint16_t nb_ops);
526 
531  char message[RTE_ML_STR_MAX];
532  uint64_t errcode;
533 };
534 
552 __rte_experimental
553 int
554 rte_ml_op_error_get(int16_t dev_id, struct rte_ml_op *op, struct rte_ml_op_error *error);
555 
556 /* Statistics operations */
557 
560  uint64_t enqueued_count;
562  uint64_t dequeued_count;
568 };
569 
582 __rte_experimental
583 int
584 rte_ml_dev_stats_get(int16_t dev_id, struct rte_ml_dev_stats *stats);
585 
592 __rte_experimental
593 void
594 rte_ml_dev_stats_reset(int16_t dev_id);
595 
604 };
605 
612  uint16_t id;
614  char name[RTE_ML_STR_MAX];
616 };
617 
644 __rte_experimental
645 int
646 rte_ml_dev_xstats_names_get(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id,
647  struct rte_ml_dev_xstats_map *xstats_map, uint32_t size);
648 
666 __rte_experimental
667 int
668 rte_ml_dev_xstats_by_name_get(int16_t dev_id, const char *name, uint16_t *stat_id, uint64_t *value);
669 
693 __rte_experimental
694 int
695 rte_ml_dev_xstats_get(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id,
696  const uint16_t stat_ids[], uint64_t values[], uint16_t nb_ids);
697 
716 __rte_experimental
717 int
718 rte_ml_dev_xstats_reset(int16_t dev_id, enum rte_ml_dev_xstats_mode mode, int32_t model_id,
719  const uint16_t stat_ids[], uint16_t nb_ids);
720 
732 __rte_experimental
733 int
734 rte_ml_dev_dump(int16_t dev_id, FILE *fd);
735 
746 __rte_experimental
747 int
748 rte_ml_dev_selftest(int16_t dev_id);
749 
750 /* Model operations */
751 
757  void *addr;
759  size_t size;
761 };
762 
779 __rte_experimental
780 int
781 rte_ml_model_load(int16_t dev_id, struct rte_ml_model_params *params, uint16_t *model_id);
782 
795 __rte_experimental
796 int
797 rte_ml_model_unload(int16_t dev_id, uint16_t model_id);
798 
813 __rte_experimental
814 int
815 rte_ml_model_start(int16_t dev_id, uint16_t model_id);
816 
832 __rte_experimental
833 int
834 rte_ml_model_stop(int16_t dev_id, uint16_t model_id);
835 
865 };
866 
886 };
887 
896  enum rte_ml_io_format format;
898  uint32_t w;
900  uint32_t x;
902  uint32_t y;
904  uint32_t z;
906 };
907 
913  char name[RTE_ML_STR_MAX];
915  struct rte_ml_io_shape shape;
917  enum rte_ml_io_type qtype;
919  enum rte_ml_io_type dtype;
921 };
922 
925  char name[RTE_ML_STR_MAX];
927  char version[RTE_ML_STR_MAX];
929  uint16_t model_id;
931  uint16_t device_id;
933  uint16_t batch_size;
935  uint32_t nb_inputs;
937  const struct rte_ml_io_info *input_info;
939  uint32_t nb_outputs;
943  uint64_t wb_size;
945 };
946 
961 __rte_experimental
962 int
963 rte_ml_model_info_get(int16_t dev_id, uint16_t model_id, struct rte_ml_model_info *model_info);
964 
983 __rte_experimental
984 int
985 rte_ml_model_params_update(int16_t dev_id, uint16_t model_id, void *buffer);
986 
987 /* IO operations */
988 
1014 __rte_experimental
1015 int
1016 rte_ml_io_input_size_get(int16_t dev_id, uint16_t model_id, uint32_t nb_batches,
1017  uint64_t *input_qsize, uint64_t *input_dsize);
1018 
1044 __rte_experimental
1045 int
1046 rte_ml_io_output_size_get(int16_t dev_id, uint16_t model_id, uint32_t nb_batches,
1047  uint64_t *output_qsize, uint64_t *output_dsize);
1048 
1071 __rte_experimental
1072 int
1073 rte_ml_io_quantize(int16_t dev_id, uint16_t model_id, uint16_t nb_batches, void *dbuffer,
1074  void *qbuffer);
1075 
1097 __rte_experimental
1098 int
1099 rte_ml_io_dequantize(int16_t dev_id, uint16_t model_id, uint16_t nb_batches, void *qbuffer,
1100  void *dbuffer);
1101 
1102 /* ML op pool operations */
1103 
1122 __rte_experimental
1123 struct rte_mempool *
1124 rte_ml_op_pool_create(const char *name, unsigned int nb_elts, unsigned int cache_size,
1125  uint16_t user_size, int socket_id);
1126 
1134 __rte_experimental
1135 void
1136 rte_ml_op_pool_free(struct rte_mempool *mempool);
1137 
1138 #ifdef __cplusplus
1139 }
1140 #endif
1141 
1142 #endif /* RTE_MLDEV_H */
__rte_experimental int rte_ml_dev_selftest(int16_t dev_id)
uint32_t length
Definition: rte_mldev.h:407
__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)
uint32_t nb_inputs
Definition: rte_mldev.h:935
__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)
uint32_t nb_desc
Definition: rte_mldev.h:303
__rte_experimental int rte_ml_io_quantize(int16_t dev_id, uint16_t model_id, uint16_t nb_batches, void *dbuffer, void *qbuffer)
rte_ml_io_format
Definition: rte_mldev.h:871
uint32_t reserved
Definition: rte_mldev.h:409
#define RTE_ML_STR_MAX
Definition: rte_mldev.h:151
struct rte_ml_buff_seg * next
Definition: rte_mldev.h:411
__rte_experimental int rte_ml_model_load(int16_t dev_id, struct rte_ml_model_params *params, uint16_t *model_id)
const char * driver_name
Definition: rte_mldev.h:217
uint16_t device_id
Definition: rte_mldev.h:931
uint64_t rte_iova_t
Definition: rte_common.h:458
struct rte_mempool * mempool
Definition: rte_mldev.h:430
uint16_t min_align_size
Definition: rte_mldev.h:235
__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_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 batch_size
Definition: rte_mldev.h:933
uint16_t max_models
Definition: rte_mldev.h:219
uint16_t nb_queue_pairs
Definition: rte_mldev.h:264
uint32_t z
Definition: rte_mldev.h:904
uint64_t impl_opaque
Definition: rte_mldev.h:445
uint32_t cache_size
Definition: rte_mempool.h:231
char name[RTE_MEMPOOL_NAMESIZE]
Definition: rte_mempool.h:220
__rte_experimental int rte_ml_io_input_size_get(int16_t dev_id, uint16_t model_id, uint32_t nb_batches, uint64_t *input_qsize, uint64_t *input_dsize)
__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:428
__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:599
uint16_t nb_batches
Definition: rte_mldev.h:424
__rte_experimental int rte_ml_dev_init(size_t dev_max)
uint64_t wb_size
Definition: rte_mldev.h:943
uint64_t user_u64
Definition: rte_mldev.h:438
__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:308
rte_ml_io_type
Definition: rte_mldev.h:842
__rte_experimental uint16_t rte_ml_dev_count(void)
__rte_experimental int rte_ml_model_unload(int16_t dev_id, uint16_t model_id)
uint64_t enqueued_count
Definition: rte_mldev.h:560
uint32_t w
Definition: rte_mldev.h:898
uint16_t model_id
Definition: rte_mldev.h:422
rte_ml_op_status
Definition: rte_mldev.h:388
uint64_t errcode
Definition: rte_mldev.h:532
uint32_t nb_outputs
Definition: rte_mldev.h:939
uint16_t max_desc
Definition: rte_mldev.h:227
__rte_experimental int rte_ml_dev_start(int16_t dev_id)
void(* rte_ml_dev_stop_flush_t)(int16_t dev_id, uint16_t qp_id, struct rte_ml_op *op)
Definition: rte_mldev.h:299
__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_dev_info_get(int16_t dev_id, struct rte_ml_dev_info *dev_info)
uint16_t model_id
Definition: rte_mldev.h:929
#define __rte_cache_aligned
Definition: rte_common.h:440
__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)
#define RTE_STD_C11
Definition: rte_common.h:39
__rte_experimental int rte_ml_dev_socket_id(int16_t dev_id)
uint16_t max_segments
Definition: rte_mldev.h:231
uint64_t dequeued_count
Definition: rte_mldev.h:562
void * user_ptr
Definition: rte_mldev.h:440
uint16_t nb_models
Definition: rte_mldev.h:259
uint32_t x
Definition: rte_mldev.h:900
uint64_t dequeue_err_count
Definition: rte_mldev.h:566
__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 int rte_ml_io_output_size_get(int16_t dev_id, uint16_t model_id, uint32_t nb_batches, uint64_t *output_qsize, uint64_t *output_dsize)
__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:564
__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_queue_pairs
Definition: rte_mldev.h:223
__rte_experimental int rte_ml_model_stop(int16_t dev_id, uint16_t model_id)
uint32_t y
Definition: rte_mldev.h:902
__rte_experimental int rte_ml_io_dequantize(int16_t dev_id, uint16_t model_id, uint16_t nb_batches, void *qbuffer, void *dbuffer)
__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:937
const struct rte_ml_io_info * output_info
Definition: rte_mldev.h:941
rte_iova_t iova_addr
Definition: rte_mldev.h:403