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 50E2C41C25; Mon, 6 Feb 2023 21:25:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 02E2A42D10; Mon, 6 Feb 2023 21:25:42 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 64C93427E9 for ; Mon, 6 Feb 2023 21:25:40 +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 316KL9I4018351; Mon, 6 Feb 2023 12:25:39 -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=+mZc70DC//TLqWwYVK2JS7eazJJ24TDkxPDq0Ph2zk4=; b=jsaE6cRQK7FgwAfJ9zW2MblvFJzZPTUoFXurUIQy9+m8CH8y7yRUQCrmyIn/yT56maSR wkCvVQHC45xRcYfyy8tYiX8WhLxubG5/Szfy24wUQZZx2J8nMu4S2xvVGrC1tv1J/vkH rWhR8rlW+R3+fNuPNJ7EOItor5EjzyukfqjYpp+OX1WA6aWQATckLnbQIdYQab9edZVa 5Fa/Zb5r1cN8YCf6MhIXfclJgRut15WZQ2pqtXJCGR5y3F0of8k2MTEBpEu5OSpwurVV mVX1G1MTB/8mRG3MLMcMFHjgexd1yJT4HtL69rP3xuD9bLxBALn+ct/M8495lwpWdBJG kg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3nhnkv5akw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 06 Feb 2023 12:25:39 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 6 Feb 2023 12:25:37 -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:37 -0800 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 27F2F3F705B; Mon, 6 Feb 2023 12:25:34 -0800 (PST) From: To: , Srikanth Yalavarthi CC: , , , , , , Jerin Jacob Subject: [dpdk-dev] [PATCH v2 07/12] mldev: support ML op pool and ops Date: Tue, 7 Feb 2023 01:54:48 +0530 Message-ID: <20230206202453.336280-8-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-ORIG-GUID: 8S7p07rkOd0ZhmsFWBTnNpjqU89QQqbg X-Proofpoint-GUID: 8S7p07rkOd0ZhmsFWBTnNpjqU89QQqbg 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 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 62f0e95c85..b669d866bf 100644 --- a/lib/mldev/rte_mldev.c +++ b/lib/mldev/rte_mldev.c @@ -11,6 +11,17 @@ static struct rte_ml_dev ml_devices[RTE_MLDEV_MAX_DEVS]; static struct rte_ml_dev_global ml_dev_globals = { .devs = ml_devices, .data = {NULL}, .nb_devs = 0, .max_devs = RTE_MLDEV_MAX_DEVS}; +/* + * 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) { @@ -559,4 +570,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 d87c7781df..b5ee45108b 100644 --- a/lib/mldev/version.map +++ b/lib/mldev/version.map @@ -21,6 +21,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: *; }; -- 2.39.1