From: Srikanth Yalavarthi <syalavar...@marvell.com>

Added library functions to handle model input and
output data. The APIs can be used to get the size of I/O
buffers, quantize input data and dequantize output data.

Signed-off-by: Srikanth Yalavarthi <syalavar...@marvell.com>
Signed-off-by: Jerin Jacob <jer...@marvell.com>
---
 lib/mldev/rte_mldev.c      |  94 ++++++++++++++++++++++++++++++++
 lib/mldev/rte_mldev_core.h | 106 +++++++++++++++++++++++++++++++++++++
 lib/mldev/version.map      |   4 ++
 3 files changed, 204 insertions(+)

diff --git a/lib/mldev/rte_mldev.c b/lib/mldev/rte_mldev.c
index 3b8c073615..62f0e95c85 100644
--- a/lib/mldev/rte_mldev.c
+++ b/lib/mldev/rte_mldev.c
@@ -465,4 +465,98 @@ rte_ml_model_params_update(int16_t dev_id, uint16_t 
model_id, void *buffer)
        return (*dev->dev_ops->model_params_update)(dev, model_id, buffer);
 }
 
+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)
+{
+       struct rte_ml_dev *dev;
+
+       if (!rte_ml_dev_is_valid_dev(dev_id)) {
+               RTE_MLDEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id);
+               return -EINVAL;
+       }
+
+       dev = rte_ml_dev_pmd_get_dev(dev_id);
+       if (*dev->dev_ops->io_input_size_get == NULL)
+               return -ENOTSUP;
+
+       return (*dev->dev_ops->io_input_size_get)(dev, model_id, nb_batches, 
input_qsize,
+                                                 input_dsize);
+}
+
+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)
+{
+       struct rte_ml_dev *dev;
+
+       if (!rte_ml_dev_is_valid_dev(dev_id)) {
+               RTE_MLDEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id);
+               return -EINVAL;
+       }
+
+       dev = rte_ml_dev_pmd_get_dev(dev_id);
+       if (*dev->dev_ops->io_output_size_get == NULL)
+               return -ENOTSUP;
+
+       return (*dev->dev_ops->io_output_size_get)(dev, model_id, nb_batches, 
output_qsize,
+                                                  output_dsize);
+}
+
+int
+rte_ml_io_quantize(int16_t dev_id, uint16_t model_id, uint16_t nb_batches, 
void *dbuffer,
+                  void *qbuffer)
+{
+       struct rte_ml_dev *dev;
+
+       if (!rte_ml_dev_is_valid_dev(dev_id)) {
+               RTE_MLDEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id);
+               return -EINVAL;
+       }
+
+       dev = rte_ml_dev_pmd_get_dev(dev_id);
+       if (*dev->dev_ops->io_quantize == NULL)
+               return -ENOTSUP;
+
+       if (dbuffer == NULL) {
+               RTE_MLDEV_LOG(ERR, "Dev %d, dbuffer cannot be NULL\n", dev_id);
+               return -EINVAL;
+       }
+
+       if (qbuffer == NULL) {
+               RTE_MLDEV_LOG(ERR, "Dev %d, qbuffer cannot be NULL\n", dev_id);
+               return -EINVAL;
+       }
+
+       return (*dev->dev_ops->io_quantize)(dev, model_id, nb_batches, dbuffer, 
qbuffer);
+}
+
+int
+rte_ml_io_dequantize(int16_t dev_id, uint16_t model_id, uint16_t nb_batches, 
void *qbuffer,
+                    void *dbuffer)
+{
+       struct rte_ml_dev *dev;
+
+       if (!rte_ml_dev_is_valid_dev(dev_id)) {
+               RTE_MLDEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id);
+               return -EINVAL;
+       }
+
+       dev = rte_ml_dev_pmd_get_dev(dev_id);
+       if (*dev->dev_ops->io_dequantize == NULL)
+               return -ENOTSUP;
+
+       if (qbuffer == NULL) {
+               RTE_MLDEV_LOG(ERR, "Dev %d, qbuffer cannot be NULL\n", dev_id);
+               return -EINVAL;
+       }
+
+       if (dbuffer == NULL) {
+               RTE_MLDEV_LOG(ERR, "Dev %d, dbuffer cannot be NULL\n", dev_id);
+               return -EINVAL;
+       }
+
+       return (*dev->dev_ops->io_dequantize)(dev, model_id, nb_batches, 
qbuffer, dbuffer);
+}
+
 RTE_LOG_REGISTER_DEFAULT(rte_ml_dev_logtype, INFO);
diff --git a/lib/mldev/rte_mldev_core.h b/lib/mldev/rte_mldev_core.h
index 4f1f32b583..1bbc9fda0e 100644
--- a/lib/mldev/rte_mldev_core.h
+++ b/lib/mldev/rte_mldev_core.h
@@ -255,6 +255,100 @@ typedef int (*mldev_model_info_get_t)(struct rte_ml_dev 
*dev, uint16_t model_id,
  */
 typedef int (*mldev_model_params_update_t)(struct rte_ml_dev *dev, uint16_t 
model_id, void *buffer);
 
+/**
+ * @internal
+ *
+ * Get size of input buffers.
+ *
+ * @param dev
+ *     ML device pointer.
+ * @param model_id
+ *     Model ID to use.
+ * @param nb_batches
+ *     Number of batches.
+ * @param input_qsize
+ *     Size of quantized input.
+ * @param input_dsize
+ *     Size of dequantized input.
+ *
+ * @return
+ *     - 0 on success.
+ *     - <0, error on failure.
+ */
+typedef int (*mldev_io_input_size_get_t)(struct rte_ml_dev *dev, uint16_t 
model_id,
+                                        uint32_t nb_batches, uint64_t 
*input_qsize,
+                                        uint64_t *input_dsize);
+
+/**
+ * @internal
+ *
+ * Get size of output buffers.
+ *
+ * @param dev
+ *     ML device pointer.
+ * @param model_id
+ *     Model ID to use.
+ * @param nb_batches
+ *     Number of batches.
+ * @param output_qsize
+ *     Size of quantized output.
+ * @param output_dsize
+ *     Size of dequantized output.
+ *
+ * @return
+ *     - 0 on success.
+ *     - <0, error on failure.
+ */
+typedef int (*mldev_io_output_size_get_t)(struct rte_ml_dev *dev, uint16_t 
model_id,
+                                         uint32_t nb_batches, uint64_t 
*output_qsize,
+                                         uint64_t *output_dsize);
+
+/**
+ * @internal
+ *
+ * Quantize model data.
+ *
+ * @param dev
+ *     ML device pointer.
+ * @param model_id
+ *     Model ID to use.
+ * @param nb_batches
+ *     Number of batches.
+ * @param dbuffer
+ *     Pointer t de-quantized data buffer.
+ * @param qbuffer
+ *     Pointer t de-quantized data buffer.
+ *
+ * @return
+ *     - 0 on success.
+ *     - <0, error on failure.
+ */
+typedef int (*mldev_io_quantize_t)(struct rte_ml_dev *dev, uint16_t model_id, 
uint16_t nb_batches,
+                                  void *dbuffer, void *qbuffer);
+
+/**
+ * @internal
+ *
+ * Quantize model data.
+ *
+ * @param dev
+ *     ML device pointer.
+ * @param model_id
+ *     Model ID to use.
+ * @param nb_batches
+ *     Number of batches.
+ * @param qbuffer
+ *     Pointer t de-quantized data buffer.
+ * @param dbuffer
+ *     Pointer t de-quantized data buffer.
+ *
+ * @return
+ *     - 0 on success.
+ *     - <0, error on failure.
+ */
+typedef int (*mldev_io_dequantize_t)(struct rte_ml_dev *dev, uint16_t 
model_id, uint16_t nb_batches,
+                                    void *qbuffer, void *dbuffer);
+
 /**
  * @internal
  *
@@ -299,6 +393,18 @@ struct rte_ml_dev_ops {
 
        /** Update model params. */
        mldev_model_params_update_t model_params_update;
+
+       /** Get input buffer size. */
+       mldev_io_input_size_get_t io_input_size_get;
+
+       /** Get output buffer size. */
+       mldev_io_output_size_get_t io_output_size_get;
+
+       /** Quantize data */
+       mldev_io_quantize_t io_quantize;
+
+       /** De-quantize data */
+       mldev_io_dequantize_t io_dequantize;
 };
 
 /**
diff --git a/lib/mldev/version.map b/lib/mldev/version.map
index 640671efff..d87c7781df 100644
--- a/lib/mldev/version.map
+++ b/lib/mldev/version.map
@@ -11,6 +11,10 @@ EXPERIMENTAL {
        rte_ml_dev_socket_id;
        rte_ml_dev_start;
        rte_ml_dev_stop;
+       rte_ml_io_dequantize;
+       rte_ml_io_input_size_get;
+       rte_ml_io_output_size_get;
+       rte_ml_io_quantize;
        rte_ml_model_info_get;
        rte_ml_model_load;
        rte_ml_model_params_update;
-- 
2.39.1

Reply via email to