From patchwork Tue Feb 7 15:13:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerin Jacob Kollanukkaran X-Patchwork-Id: 123261 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 2EB3F41C30; Tue, 7 Feb 2023 16:14:14 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A2EA342D30; Tue, 7 Feb 2023 16:13:53 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 09AC542D1D for ; Tue, 7 Feb 2023 16:13:51 +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 317Egcp3017290; Tue, 7 Feb 2023 07:13:51 -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=GJVmd5iUL+JEuv759jFyj2Pjjld8E5+/MS9EsbL6RVY=; b=gwm4mhdIDlR8W1+THFyYm+mnY93wktwavvhRVwEh4i2y5FZoj5QPktiYROj1qlHuGL1O JLIma8JxUEiWVwXXYzqIK406LSfE9PKVlEPcX9XDbBKb1dk+kGoXk5plmql7O90iYe9c BTBsvForT59gPcR5M7MEOod0mdhXr2upygRn7b01pDpdLq6ItJekMZ3LPILzf6O7MYmd rkB1hc2d6zxdTVZnuQU4cK4xpbj/x7XjoruhhfyDJ+EB7dx689Dtr8f91IctEO9TFkwQ eCXkxI6mSmVKhZZ106m9RFf8pjPo3lMIOvx6TCtxljc28vMDu/yrBOY4kBru3thFqJq/ Yg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3nkdyrsk2j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 07 Feb 2023 07:13:51 -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.42; Tue, 7 Feb 2023 07:13:49 -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:49 -0800 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id BD1F13F7089; Tue, 7 Feb 2023 07:13:46 -0800 (PST) From: To: , Srikanth Yalavarthi CC: , , , , , Jerin Jacob Subject: [dpdk-dev] [PATCH v3 05/12] mldev: support handling ML models Date: Tue, 7 Feb 2023 20:43:09 +0530 Message-ID: <20230207151316.835441-6-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 X-Proofpoint-ORIG-GUID: HNs2UaRXyjHI6JCSR9MZaSt-CBGyA87K X-Proofpoint-GUID: HNs2UaRXyjHI6JCSR9MZaSt-CBGyA87K 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 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 928ea90ab5..9642e62815 100644 --- a/lib/mldev/rte_mldev.c +++ b/lib/mldev/rte_mldev.c @@ -385,4 +385,127 @@ 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, uint16_t *model_id) +{ + 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->model_load == NULL) + return -ENOTSUP; + + if (params == NULL) { + RTE_MLDEV_LOG(ERR, "Dev %d, params cannot be NULL\n", dev_id); + return -EINVAL; + } + + if (model_id == NULL) { + RTE_MLDEV_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, uint16_t model_id) +{ + 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->model_unload == NULL) + return -ENOTSUP; + + return (*dev->dev_ops->model_unload)(dev, model_id); +} + +int +rte_ml_model_start(int16_t dev_id, uint16_t model_id) +{ + 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->model_start == NULL) + return -ENOTSUP; + + return (*dev->dev_ops->model_start)(dev, model_id); +} + +int +rte_ml_model_stop(int16_t dev_id, uint16_t model_id) +{ + 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->model_stop == NULL) + return -ENOTSUP; + + return (*dev->dev_ops->model_stop)(dev, model_id); +} + +int +rte_ml_model_info_get(int16_t dev_id, uint16_t model_id, struct rte_ml_model_info *model_info) +{ + 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->model_info_get == NULL) + return -ENOTSUP; + + if (model_info == NULL) { + RTE_MLDEV_LOG(ERR, "Dev %d, model_id %u, 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, uint16_t model_id, void *buffer) +{ + 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->model_params_update == NULL) + return -ENOTSUP; + + if (buffer == NULL) { + RTE_MLDEV_LOG(ERR, "Dev %d, buffer cannot be NULL\n", dev_id); + return -EINVAL; + } + + return (*dev->dev_ops->model_params_update)(dev, model_id, buffer); +} + 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 f8d247b43e..602f541589 100644 --- a/lib/mldev/rte_mldev_core.h +++ b/lib/mldev/rte_mldev_core.h @@ -151,6 +151,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, + uint16_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, uint16_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, uint16_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, uint16_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, uint16_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, uint16_t model_id, void *buffer); + /** * @internal * @@ -177,6 +281,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 fcf48f1760..8da70f2443 100644 --- a/lib/mldev/version.map +++ b/lib/mldev/version.map @@ -12,6 +12,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: *; };