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 DDA6E41C30; Tue, 7 Feb 2023 17:00:27 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0B751427F2; Tue, 7 Feb 2023 17:00:23 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 4A17F40A84 for ; Tue, 7 Feb 2023 17:00:20 +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 317EdPa2011264 for ; Tue, 7 Feb 2023 08:00:18 -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-type; s=pfpt0220; bh=OcXiFop2NiZ7y5kWoqlZ1KEmeMNNkXYO+YOoxaMIGJ8=; b=CWzAvXotedREJG6igF7XLS+rrcHGzzSAWOdCxLmR7uwDp9DxTF29kkGNgQJW9+cfB/sV 50XzRPC826ZLlHy+JVmhuLWNo3gkQTUDUEEaAcsgQwKJhypj2gZ6tElX/zV7hQ2C6Ebp nNynLctK+U8yCAen5yC1jdvNC4q9QqZ4/Mi1NHzASKK6HZhLQ5y/k5PrPkTLX6dzXzwT 8YalK68G3/QHqwiUlGCotjP0gHWFvsYgXRPMs9/344Y9kd0LRnig/m2Cet9oeGXdw7Um 57XlOoaoCsHlot4Zcx37DGkTbpBLok5Jn4Yb7C+4hoefPbOr/iCIs54qiWRPBNbkH4t8 fg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3nkdyrsrbj-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 07 Feb 2023 08:00:18 -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 08:00:16 -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 08:00:16 -0800 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 002AC3F70BE; Tue, 7 Feb 2023 08:00:10 -0800 (PST) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v6 2/4] mldev: implement ML IO type handling functions Date: Tue, 7 Feb 2023 08:00:06 -0800 Message-ID: <20230207160008.30182-3-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230207160008.30182-1-syalavarthi@marvell.com> References: <20221208193532.16718-1-syalavarthi@marvell.com> <20230207160008.30182-1-syalavarthi@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-ORIG-GUID: 7-LdFhEWh0BlYXAYMrLHiNScHpw8XQAB X-Proofpoint-GUID: 7-LdFhEWh0BlYXAYMrLHiNScHpw8XQAB 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 Implemented ML utility functions to convert IO data type to name, IO format to name and routine to get the size of an IO data type in bytes. Signed-off-by: Srikanth Yalavarthi --- v5: * Moved the code from drivers/common/ml to lib/mldev * Added rte_ml_io_ prefix to the functions v2: * Implemented common utility functions as part of the patch * Dropped use of driver routines for data conversion functions lib/mldev/mldev_utils.c | 113 ++++++++++++++++++++++++++++++++++++++++ lib/mldev/version.map | 4 ++ 2 files changed, 117 insertions(+) diff --git a/lib/mldev/mldev_utils.c b/lib/mldev/mldev_utils.c index 9dbbf013a0..d2442b123b 100644 --- a/lib/mldev/mldev_utils.c +++ b/lib/mldev/mldev_utils.c @@ -2,4 +2,117 @@ * Copyright (c) 2022 Marvell. */ +#include +#include + +#include +#include + #include "mldev_utils.h" + +/* Description: + * This file implements Machine Learning utility routines, except type conversion routines. + */ + +int +rte_ml_io_type_size_get(enum rte_ml_io_type type) +{ + switch (type) { + case RTE_ML_IO_TYPE_UNKNOWN: + return -EINVAL; + case RTE_ML_IO_TYPE_INT8: + return sizeof(int8_t); + case RTE_ML_IO_TYPE_UINT8: + return sizeof(uint8_t); + case RTE_ML_IO_TYPE_INT16: + return sizeof(int16_t); + case RTE_ML_IO_TYPE_UINT16: + return sizeof(uint16_t); + case RTE_ML_IO_TYPE_INT32: + return sizeof(int32_t); + case RTE_ML_IO_TYPE_UINT32: + return sizeof(uint32_t); + case RTE_ML_IO_TYPE_FP8: + return sizeof(uint8_t); + case RTE_ML_IO_TYPE_FP16: + return sizeof(uint8_t) * 2; + case RTE_ML_IO_TYPE_FP32: + return sizeof(uint8_t) * 4; + case RTE_ML_IO_TYPE_BFLOAT16: + return sizeof(uint8_t) * 2; + default: + return -EINVAL; + } +} + +void +rte_ml_io_type_to_str(enum rte_ml_io_type type, char *str, int len) +{ + switch (type) { + case RTE_ML_IO_TYPE_UNKNOWN: + rte_strlcpy(str, "unknown", len); + break; + case RTE_ML_IO_TYPE_INT8: + rte_strlcpy(str, "int8", len); + break; + case RTE_ML_IO_TYPE_UINT8: + rte_strlcpy(str, "uint8", len); + break; + case RTE_ML_IO_TYPE_INT16: + rte_strlcpy(str, "int16", len); + break; + case RTE_ML_IO_TYPE_UINT16: + rte_strlcpy(str, "uint16", len); + break; + case RTE_ML_IO_TYPE_INT32: + rte_strlcpy(str, "int32", len); + break; + case RTE_ML_IO_TYPE_UINT32: + rte_strlcpy(str, "uint32", len); + break; + case RTE_ML_IO_TYPE_FP8: + rte_strlcpy(str, "float8", len); + break; + case RTE_ML_IO_TYPE_FP16: + rte_strlcpy(str, "float16", len); + break; + case RTE_ML_IO_TYPE_FP32: + rte_strlcpy(str, "float32", len); + break; + case RTE_ML_IO_TYPE_BFLOAT16: + rte_strlcpy(str, "bfloat16", len); + break; + default: + rte_strlcpy(str, "invalid", len); + } +} + +void +rte_ml_io_format_to_str(enum rte_ml_io_format format, char *str, int len) +{ + switch (format) { + case RTE_ML_IO_FORMAT_NCHW: + rte_strlcpy(str, "NCHW", len); + break; + case RTE_ML_IO_FORMAT_NHWC: + rte_strlcpy(str, "NHWC", len); + break; + case RTE_ML_IO_FORMAT_CHWN: + rte_strlcpy(str, "CHWN", len); + break; + case RTE_ML_IO_FORMAT_3D: + rte_strlcpy(str, "3D", len); + break; + case RTE_ML_IO_FORMAT_2D: + rte_strlcpy(str, "Matrix", len); + break; + case RTE_ML_IO_FORMAT_1D: + rte_strlcpy(str, "Vector", len); + break; + case RTE_ML_IO_FORMAT_SCALAR: + rte_strlcpy(str, "Scalar", len); + break; + default: + rte_strlcpy(str, "invalid", len); + } +} diff --git a/lib/mldev/version.map b/lib/mldev/version.map index d2b30a991a..9d06659493 100644 --- a/lib/mldev/version.map +++ b/lib/mldev/version.map @@ -48,4 +48,8 @@ INTERNAL { rte_ml_dev_pmd_get_dev; rte_ml_dev_pmd_get_named_dev; rte_ml_dev_pmd_release; + + rte_ml_io_type_size_get; + rte_ml_io_type_to_str; + rte_ml_io_format_to_str; }; -- 2.17.1