From patchwork Mon Nov 14 12:02:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerin Jacob Kollanukkaran X-Patchwork-Id: 119827 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A3957A00C4; Mon, 14 Nov 2022 13:08:16 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 91E9940150; Mon, 14 Nov 2022 13:08:16 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id BB71D4014F for ; Mon, 14 Nov 2022 13:08:14 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AE7v5FX024488; Mon, 14 Nov 2022 04:05:27 -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=Q6DiOefvbajoO0aKtP+WNDlBuQr/3EMi7lpu86kkVr4=; b=b0t+tOPKaS2a7/y9N2diUJi07gQW3ejV8R3/Gz39F+L9El/1L/uCVPbpBxsv1tWbW5Dl cqrhLfcHD6fn06RV2b4J+h9u8/GS4f8LYa58rPHpOWU26/MVT0v7LoAFgLOjYgcOgFum tnJbzxi5IOi8hajcvlter3AQlPibWck+jA6H7pR+8yYoW/Ilh+Vb62W8crywk4eIVjoM cZFzl9fSU0/TTC6gUMqgYl393hVk2qrMIs9tLSoTbVTvi3eCWJmggjQrIs8f3G3c/Pba EaVoxK/PGeNoTNRhxaLwECciSusJg6JCRQwLZY/JTp6jRhQX8BJp/qEYqI6bykZlRDgW ow== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3kuhr3gn5j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 14 Nov 2022 04:05:27 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 14 Nov 2022 04:05:25 -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.18 via Frontend Transport; Mon, 14 Nov 2022 04:05:25 -0800 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id EAD1A5C68E2; Mon, 14 Nov 2022 04:05:00 -0800 (PST) From: To: , Srikanth Yalavarthi CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Jerin Jacob Subject: [dpdk-dev] [PATCH v1 05/12] mldev: support handling ML models Date: Mon, 14 Nov 2022 17:32:31 +0530 Message-ID: <20221114120238.2143832-6-jerinj@marvell.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114120238.2143832-1-jerinj@marvell.com> References: <20220803132839.2747858-2-jerinj@marvell.com> <20221114120238.2143832-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: 4aCDmd0pYczB3EZx8Jh1Rl1PVEGaOwQt X-Proofpoint-ORIG-GUID: 4aCDmd0pYczB3EZx8Jh1Rl1PVEGaOwQt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-14_10,2022-11-11_01,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 RTE functions to handle ML models. These APIs can load, unload, start, and stop an ML model. Additional APIs to update model parameters and get model information are added. Signed-off-by: Srikanth Yalavarthi Signed-off-by: Jerin Jacob --- lib/mldev/rte_mldev.c | 123 +++++++++++++++++++++++++++++++++++++ lib/mldev/rte_mldev_core.h | 122 ++++++++++++++++++++++++++++++++++++ lib/mldev/version.map | 6 ++ 3 files changed, 251 insertions(+) diff --git a/lib/mldev/rte_mldev.c b/lib/mldev/rte_mldev.c index c8672cff8e..327ed7144d 100644 --- a/lib/mldev/rte_mldev.c +++ b/lib/mldev/rte_mldev.c @@ -339,3 +339,126 @@ rte_ml_dev_queue_pair_setup(int16_t dev_id, uint16_t queue_pair_id, return (*dev->dev_ops->dev_queue_pair_setup)(dev, queue_pair_id, qp_conf, socket_id); } + +int +rte_ml_model_load(int16_t dev_id, struct rte_ml_model_params *params, int16_t *model_id) +{ + struct rte_ml_dev *dev; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (*dev->dev_ops->model_load == NULL) + return -ENOTSUP; + + if (params == NULL) { + ML_DEV_LOG(ERR, "Dev %d, params cannot be NULL\n", dev_id); + return -EINVAL; + } + + if (model_id == NULL) { + ML_DEV_LOG(ERR, "Dev %d, model_id cannot be NULL\n", dev_id); + return -EINVAL; + } + + return (*dev->dev_ops->model_load)(dev, params, model_id); +} + +int +rte_ml_model_unload(int16_t dev_id, int16_t model_id) +{ + struct rte_ml_dev *dev; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (*dev->dev_ops->model_unload == NULL) + return -ENOTSUP; + + return (*dev->dev_ops->model_unload)(dev, model_id); +} + +int +rte_ml_model_start(int16_t dev_id, int16_t model_id) +{ + struct rte_ml_dev *dev; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (*dev->dev_ops->model_start == NULL) + return -ENOTSUP; + + return (*dev->dev_ops->model_start)(dev, model_id); +} + +int +rte_ml_model_stop(int16_t dev_id, int16_t model_id) +{ + struct rte_ml_dev *dev; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (*dev->dev_ops->model_stop == NULL) + return -ENOTSUP; + + return (*dev->dev_ops->model_stop)(dev, model_id); +} + +int +rte_ml_model_info_get(int16_t dev_id, int16_t model_id, struct rte_ml_model_info *model_info) +{ + struct rte_ml_dev *dev; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (*dev->dev_ops->model_info_get == NULL) + return -ENOTSUP; + + if (model_info == NULL) { + ML_DEV_LOG(ERR, "Dev %d, model_id %d, model_info cannot be NULL\n", dev_id, + model_id); + return -EINVAL; + } + + return (*dev->dev_ops->model_info_get)(dev, model_id, model_info); +} + +int +rte_ml_model_params_update(int16_t dev_id, int16_t model_id, void *buffer) +{ + struct rte_ml_dev *dev; + + if (!rte_ml_dev_is_valid_dev(dev_id)) { + ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id); + return -EINVAL; + } + + dev = rte_ml_dev_pmd_get_dev(dev_id); + if (*dev->dev_ops->model_params_update == NULL) + return -ENOTSUP; + + if (buffer == NULL) { + ML_DEV_LOG(ERR, "Dev %d, buffer cannot be NULL\n", dev_id); + return -EINVAL; + } + + return (*dev->dev_ops->model_params_update)(dev, model_id, buffer); +} diff --git a/lib/mldev/rte_mldev_core.h b/lib/mldev/rte_mldev_core.h index e2a16034d6..172454c2aa 100644 --- a/lib/mldev/rte_mldev_core.h +++ b/lib/mldev/rte_mldev_core.h @@ -155,6 +155,110 @@ typedef int (*mldev_queue_pair_setup_t)(struct rte_ml_dev *dev, uint16_t queue_p */ typedef int (*mldev_queue_pair_release_t)(struct rte_ml_dev *dev, uint16_t queue_pair_id); +/** + * @internal + * + * Function used to load an ML model. + * + * @param dev + * ML device pointer. + * @param params + * Model load params. + * @param model_id + * Model ID returned by the library. + * + * @return + * - 0 on success. + * - < 0, error on failure. + */ +typedef int (*mldev_model_load_t)(struct rte_ml_dev *dev, struct rte_ml_model_params *params, + int16_t *model_id); + +/** + * @internal + * + * Function used to unload an ML model. + * + * @param dev + * ML device pointer. + * @param model_id + * Model ID to use. + * + * @return + * - 0 on success. + * - < 0, error on failure. + */ +typedef int (*mldev_model_unload_t)(struct rte_ml_dev *dev, int16_t model_id); + +/** + * @internal + * + * Function used to start an ML model. + * + * @param dev + * ML device pointer. + * @param model_id + * Model ID to use. + * + * @return + * - 0 on success. + * - <0, error on failure. + */ +typedef int (*mldev_model_start_t)(struct rte_ml_dev *dev, int16_t model_id); + +/** + * @internal + * + * Function used to stop an ML model. + * + * @param dev + * ML device pointer. + * @param model_id + * Model ID to use. + * + * @return + * - 0 on success. + * - <0, error on failure. + */ +typedef int (*mldev_model_stop_t)(struct rte_ml_dev *dev, int16_t model_id); + +/** + * @internal + * + * Get info about a model. + * + * @param dev + * ML device pointer. + * @param model_id + * Model ID to use. + * @param model_info + * Pointer to model info structure. + * + * @return + * - 0 on success. + * - <0, error on failure. + */ +typedef int (*mldev_model_info_get_t)(struct rte_ml_dev *dev, int16_t model_id, + struct rte_ml_model_info *model_info); + +/** + * @internal + * + * Update model params. + * + * @param dev + * ML device pointer. + * @param model_id + * Model ID to use. + * @param buffer + * Pointer to model params. + * + * @return + * - 0 on success. + * - <0, error on failure. + */ +typedef int (*mldev_model_params_update_t)(struct rte_ml_dev *dev, int16_t model_id, void *buffer); + /** * @internal * @@ -181,6 +285,24 @@ struct rte_ml_dev_ops { /** Release a device queue pair. */ mldev_queue_pair_release_t dev_queue_pair_release; + + /** Load an ML model. */ + mldev_model_load_t model_load; + + /** Unload an ML model. */ + mldev_model_unload_t model_unload; + + /** Start an ML model. */ + mldev_model_start_t model_start; + + /** Stop an ML model. */ + mldev_model_stop_t model_stop; + + /** Get model information. */ + mldev_model_info_get_t model_info_get; + + /** Update model params. */ + mldev_model_params_update_t model_params_update; }; /** diff --git a/lib/mldev/version.map b/lib/mldev/version.map index cd44c05f3a..4459f02925 100644 --- a/lib/mldev/version.map +++ b/lib/mldev/version.map @@ -10,6 +10,12 @@ EXPERIMENTAL { rte_ml_dev_socket_id; rte_ml_dev_start; rte_ml_dev_stop; + rte_ml_model_info_get; + rte_ml_model_load; + rte_ml_model_params_update; + rte_ml_model_start; + rte_ml_model_stop; + rte_ml_model_unload; local: *; };