From patchwork Tue Feb 7 15:13:11 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: 123263 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 BD83041C30; Tue, 7 Feb 2023 16:14:27 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B510042D2F; Tue, 7 Feb 2023 16:14:00 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 6A25E42D2F for ; Tue, 7 Feb 2023 16:13:59 +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 317EYvXU001487; Tue, 7 Feb 2023 07:13:58 -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=rIpTIyswQp8PspQcazsE6FjGPzvK+K0oTQqGrKlzQFs=; b=E1w/Dp3Kz+Lok6MrjUOjhUwYk/RwTgnSzAvZ5uzrqxh26FAb5+aLAXATS1G+hVfFXNBj iITGttRqShgPRW/Dccz/lFNU4cYmvbz6RyswFbf1GqiFeDsRVXJdySWKfN+q10dFhvda KN2dowMCQ9twDPDI83hdhZtQx3HxWhPukVlAnPYkE0UxcKDE1PIMJ5bS830DllgAkaed VreSBJKiLiFcIZ8igLwB6fHrCwa1DgRL5tl98sl3Yt4YecPqmA7akq9GnhOp4SBDfqbh ohbDP46ojzjy6OfK116aC19yc2JMe2m9xZaEK7IUfD4lPtPvpahjBV1dlcD2LNw+ykkh LA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3nkdyrsk33-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 07 Feb 2023 07:13:58 -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; Tue, 7 Feb 2023 07:13:56 -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; Tue, 7 Feb 2023 07:13:56 -0800 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 57E943F7082; Tue, 7 Feb 2023 07:13:54 -0800 (PST) From: To: , Srikanth Yalavarthi CC: , , , , , Jerin Jacob Subject: [dpdk-dev] [PATCH v3 07/12] mldev: support ML op pool and ops Date: Tue, 7 Feb 2023 20:43:11 +0530 Message-ID: <20230207151316.835441-8-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: UyA9CFxA9iLVVZ231avn5D2Ye0XBP4eA X-Proofpoint-GUID: UyA9CFxA9iLVVZ231avn5D2Ye0XBP4eA 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 create and free ML op pool. Create function allocates new ML op pool and initializes ML ops to their defaults. Signed-off-by: Srikanth Yalavarthi Signed-off-by: Jerin Jacob --- lib/mldev/rte_mldev.c | 69 +++++++++++++++++++++++++++++++++++++++++++ lib/mldev/version.map | 2 ++ 2 files changed, 71 insertions(+) diff --git a/lib/mldev/rte_mldev.c b/lib/mldev/rte_mldev.c index f9684e90ea..da65819c08 100644 --- a/lib/mldev/rte_mldev.c +++ b/lib/mldev/rte_mldev.c @@ -12,6 +12,17 @@ static struct rte_ml_dev_global ml_dev_globals = { .devs = NULL, .data = NULL, .nb_devs = 0, .max_devs = RTE_MLDEV_DEFAULT_MAX}; +/* + * Private data structure of an operation pool. + * + * A structure that contains ml op_pool specific data that is + * appended after the mempool structure (in private data). + */ +struct rte_ml_op_pool_private { + uint16_t user_size; + /*< Size of private user data with each operation. */ +}; + struct rte_ml_dev * rte_ml_dev_pmd_get_dev(int16_t dev_id) { @@ -602,4 +613,62 @@ rte_ml_io_dequantize(int16_t dev_id, uint16_t model_id, uint16_t nb_batches, voi return (*dev->dev_ops->io_dequantize)(dev, model_id, nb_batches, qbuffer, dbuffer); } +/** Initialise rte_ml_op mempool element */ +static void +ml_op_init(struct rte_mempool *mempool, __rte_unused void *opaque_arg, void *_op_data, + __rte_unused unsigned int i) +{ + struct rte_ml_op *op = _op_data; + + memset(_op_data, 0, mempool->elt_size); + op->status = RTE_ML_OP_STATUS_NOT_PROCESSED; + op->mempool = mempool; +} + +struct rte_mempool * +rte_ml_op_pool_create(const char *name, unsigned int nb_elts, unsigned int cache_size, + uint16_t user_size, int socket_id) +{ + struct rte_ml_op_pool_private *priv; + struct rte_mempool *mp; + unsigned int elt_size; + + /* lookup mempool in case already allocated */ + mp = rte_mempool_lookup(name); + elt_size = sizeof(struct rte_ml_op) + user_size; + + if (mp != NULL) { + priv = (struct rte_ml_op_pool_private *)rte_mempool_get_priv(mp); + if (mp->elt_size != elt_size || mp->cache_size < cache_size || mp->size < nb_elts || + priv->user_size < user_size) { + mp = NULL; + RTE_MLDEV_LOG(ERR, + "Mempool %s already exists but with incompatible parameters", + name); + return NULL; + } + return mp; + } + + mp = rte_mempool_create(name, nb_elts, elt_size, cache_size, + sizeof(struct rte_ml_op_pool_private), NULL, NULL, ml_op_init, NULL, + socket_id, 0); + if (mp == NULL) { + RTE_MLDEV_LOG(ERR, "Failed to create mempool %s", name); + return NULL; + } + + priv = (struct rte_ml_op_pool_private *)rte_mempool_get_priv(mp); + priv->user_size = user_size; + + return mp; +} + +void +rte_ml_op_pool_free(struct rte_mempool *mempool) +{ + if (mempool != NULL) + rte_mempool_free(mempool); +} + RTE_LOG_REGISTER_DEFAULT(rte_ml_dev_logtype, INFO); diff --git a/lib/mldev/version.map b/lib/mldev/version.map index d65b0792ab..7665226d0e 100644 --- a/lib/mldev/version.map +++ b/lib/mldev/version.map @@ -22,6 +22,8 @@ EXPERIMENTAL { rte_ml_model_start; rte_ml_model_stop; rte_ml_model_unload; + rte_ml_op_pool_create; + rte_ml_op_pool_free; local: *; };