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 25EE441C25; Mon, 6 Feb 2023 21:25:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B2DB442D55; Mon, 6 Feb 2023 21:25:36 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 69E1F42D4B for ; Mon, 6 Feb 2023 21:25:35 +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 316FEpEW005847; Mon, 6 Feb 2023 12:25:34 -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=BnB+cylrbuB9gxTmlMvR2jMx+cT9ETEwfo8oMGU5JSk=; b=VaX0j081qcvvJioSpawaSoVQKQFgElNTn+MzJTy4+qnaXEr5B6qysAgXc4FrgoQFMoKO G8Du2Vffeead2cfhdwg1rFFEbwUSbHcq4sxfKwnGNYTUUXPFESx0lhQEfqBeKcXl/+09 jJf7ayhGJ2MHaiFSPKNF/ZsROxaMGL+UE7vuSB/pY5pfybrdZLNVoTR3eOb5Y1u5pJXH u5MgAQT8fPkyHnlcwOYVDj4cj8tbOCdOtsHSl7gIuqsbV1nMI4EepyPDgHD8viNdBtQG T9XMFZhPxrj0kHhxtOK2MIYAuipWxlS0Gtxo9q0Q1pqa9eUCqcsIAHHwKUMWWC0mOf5R mw== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3nhqrte0qu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 06 Feb 2023 12:25:34 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 6 Feb 2023 12:25:32 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Mon, 6 Feb 2023 12:25:32 -0800 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id A3BAB3F705B; Mon, 6 Feb 2023 12:25:29 -0800 (PST) From: To: , Srikanth Yalavarthi CC: , , , , , , Jerin Jacob Subject: [dpdk-dev] [PATCH v2 06/12] mldev: support input and output data handling Date: Tue, 7 Feb 2023 01:54:47 +0530 Message-ID: <20230206202453.336280-7-jerinj@marvell.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206202453.336280-1-jerinj@marvell.com> References: <20221114120238.2143832-1-jerinj@marvell.com> <20230206202453.336280-1-jerinj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: EaqM2iLanIRHKifaSgQt0pfNZPeP6qt6 X-Proofpoint-ORIG-GUID: EaqM2iLanIRHKifaSgQt0pfNZPeP6qt6 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-06_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 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