From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3AEA841C30; Tue, 7 Feb 2023 16:14:21 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BA23D42D29; Tue, 7 Feb 2023 16:13:57 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 056A742D38 for ; Tue, 7 Feb 2023 16:13:55 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 317BJhJn017823; Tue, 7 Feb 2023 07:13:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=VCQbREmgf1DY/HvbMRW1FU88wqMUtSCurwMgrbACnRc=; b=Ybe7jiKRv1xrxgGglI+L4mfYW4R3ZECZxhfRUQrREf4r2cJgdk80xnozE2tAxO/V7ba4 3haotOcdE3I6tZW6s1XghEbefoBG2FXYKmbdYuuxfq50b/t765u87mvGIPz+bw3oyFdb 14H3fmysBNmdSA8F/WGZhEoG55JK0L3vnY1MxGr/3yk/pfpY0aRZ3SIW+XTnxNSWpv6d Zpyc4vjJeuuIL4j4QHxrwNNYemOGa36IXMBjg6Htstqg6kmRBFO8SSJcQjDYFtzK7FVU IbvPYsk4UYD5jyY5OS50E7XOj7ExMPMhkvNR2WpwESagfYcvhSc6G5PuAKcpI2gsr1tQ 9w== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3nhqrtme5v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 07 Feb 2023 07:13:55 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Tue, 7 Feb 2023 07:13:53 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Tue, 7 Feb 2023 07:13:53 -0800 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 8EDDB3F7083; Tue, 7 Feb 2023 07:13:50 -0800 (PST) From: To: , Srikanth Yalavarthi CC: , , , , , Jerin Jacob Subject: [dpdk-dev] [PATCH v3 06/12] mldev: support input and output data handling Date: Tue, 7 Feb 2023 20:43:10 +0530 Message-ID: <20230207151316.835441-7-jerinj@marvell.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230207151316.835441-1-jerinj@marvell.com> References: <20230206202453.336280-1-jerinj@marvell.com> <20230207151316.835441-1-jerinj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: aTOxl_lh-XGNYAkbbnRAi2wfwcJ_5GG9 X-Proofpoint-ORIG-GUID: aTOxl_lh-XGNYAkbbnRAi2wfwcJ_5GG9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-07_07,2023-02-06_03,2022-06-22_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Srikanth Yalavarthi 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 Signed-off-by: Jerin Jacob --- 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 9642e62815..f9684e90ea 100644 --- a/lib/mldev/rte_mldev.c +++ b/lib/mldev/rte_mldev.c @@ -508,4 +508,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 602f541589..46e6e7a4e5 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 8da70f2443..d65b0792ab 100644 --- a/lib/mldev/version.map +++ b/lib/mldev/version.map @@ -12,6 +12,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