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 16E2EA034C; Mon, 12 Dec 2022 18:21:29 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6337241181; Mon, 12 Dec 2022 18:21:20 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 40D2F40684 for ; Mon, 12 Dec 2022 18:21:17 +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 2BCGA4hJ016221; Mon, 12 Dec 2022 09:21:16 -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=NyZiqqbDtfS3dHZ30qvgTqH/an9cEib6JRhkfUB4O4M=; b=KK9meDyMzTkEbpRrADiZRHqj3exb8qDiaez69l6SfTRYHzQbH05I7FBVqMmf/9cT2Ai+ ZMffrB/EdrLjml8MLuylypDka9XgvnCEZtLE4rqeNj4dylYzVVgDG3Yc6O5UJ5fcUQS1 j4ClRcjOxIKF4b+5owEGI2Co9l4f6Kze/N2UzxiH9OiFf2arwAsQW2MJqDD+wclM/0YI ViXKYweige7FuJeQFsAecfbk9oCqsAE2OYbW4p7AtDEUDhRD37xOmr6v3d2zuUKRv4BG Zltx1oyunQTs5Eh2NWd12akxMHlRRg/ChSBR7K8R34WMl7E7xK8nMoppOw+8URWC59ub 4w== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3mcrbveqpn-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 12 Dec 2022 09:21:16 -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; Mon, 12 Dec 2022 09:21:14 -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; Mon, 12 Dec 2022 09:21:14 -0800 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 1E1593F7041; Mon, 12 Dec 2022 09:21:14 -0800 (PST) From: Srikanth Yalavarthi To: Thomas Monjalon , Srikanth Yalavarthi CC: , , , Subject: [PATCH v2 1/4] common/ml: add initial files for ML common code Date: Mon, 12 Dec 2022 09:21:05 -0800 Message-ID: <20221212172108.17993-2-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221212172108.17993-1-syalavarthi@marvell.com> References: <20221208193532.16718-1-syalavarthi@marvell.com> <20221212172108.17993-1-syalavarthi@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-GUID: ITnIPqBLv79Gn-0cMbzS_p-SpQ6gl-ff X-Proofpoint-ORIG-GUID: ITnIPqBLv79Gn-0cMbzS_p-SpQ6gl-ff X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-12_02,2022-12-12_02,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 Added ML common header files and skeleton code. Common ML code includes utility routines to convert ML IO type and format to string, IO type to size and routines to convert data types. Signed-off-by: Srikanth Yalavarthi --- Depends-on: series-26046 ("app/mldev: implement test framework for mldev") v2: * Moved implementation out of patch. Only headers are included. MAINTAINERS | 8 + drivers/common/meson.build | 1 + drivers/common/ml/meson.build | 20 +++ drivers/common/ml/ml_utils.c | 5 + drivers/common/ml/ml_utils.h | 283 ++++++++++++++++++++++++++++++++++ 5 files changed, 317 insertions(+) create mode 100644 drivers/common/ml/meson.build create mode 100644 drivers/common/ml/ml_utils.c create mode 100644 drivers/common/ml/ml_utils.h diff --git a/MAINTAINERS b/MAINTAINERS index 5fa276fafa..6412209bff 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1431,6 +1431,14 @@ F: drivers/raw/dpaa2_cmdif/ F: doc/guides/rawdevs/dpaa2_cmdif.rst +ML Device Drivers +------------------------ + +ML common code +M: Srikanth Yalavarthi +F: drivers/common/ml/ + + Packet processing ----------------- diff --git a/drivers/common/meson.build b/drivers/common/meson.build index b63d899d50..0878dde0a0 100644 --- a/drivers/common/meson.build +++ b/drivers/common/meson.build @@ -9,4 +9,5 @@ drivers = [ 'idpf', 'mvep', 'octeontx', + 'ml', ] diff --git a/drivers/common/ml/meson.build b/drivers/common/ml/meson.build new file mode 100644 index 0000000000..2749ab6c2e --- /dev/null +++ b/drivers/common/ml/meson.build @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (c) 2022 Marvell. + +if not is_linux or not dpdk_conf.get('RTE_ARCH_64') + build = false + reason = 'only supported on 64-bit Linux' + subdir_done() +endif + +headers = files( + 'ml_utils.h', +) + +sources = files( + 'ml_utils.c', +) + +deps += ['mldev'] + +pmd_supports_disable_iova_as_pa = true diff --git a/drivers/common/ml/ml_utils.c b/drivers/common/ml/ml_utils.c new file mode 100644 index 0000000000..90bc280e4b --- /dev/null +++ b/drivers/common/ml/ml_utils.c @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include "ml_utils.h" diff --git a/drivers/common/ml/ml_utils.h b/drivers/common/ml/ml_utils.h new file mode 100644 index 0000000000..9726c6e3b5 --- /dev/null +++ b/drivers/common/ml/ml_utils.h @@ -0,0 +1,283 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#ifndef _ML_UTILS_H_ +#define _ML_UTILS_H_ + +#include +#include + +/** + * Get the size an ML IO type in bytes. + * + * @param[in] type + * Enumeration of ML IO data type. + * + * @return + * - > 0, Size of the data type in bytes. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_io_type_size_get(enum rte_ml_io_type type); + +/** + * Get the name of an ML IO type. + * + * @param[in] type + * Enumeration of ML IO data type. + * @param[in] str + * Address of character array. + * @param[in] len + * Length of character array. + */ +__rte_internal +void ml_io_type_to_str(enum rte_ml_io_type type, char *str, int len); + +/** + * Get the name of an ML IO format. + * + * @param[in] type + * Enumeration of ML IO format. + * @param[in] str + * Address of character array. + * @param[in] len + * Length of character array. + */ +__rte_internal +void ml_io_format_to_str(enum rte_ml_io_format format, char *str, int len); + +/** + * Convert a buffer containing numbers in single precision floating format (float32) to signed 8-bit + * integer format (INT8). + * + * @param[in] scale + * Scale factor for conversion. + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing float32 numbers. Size of buffer is equal to (nb_elements * 4) bytes. + * @param[out] output + * Output buffer to store INT8 numbers. Size of buffer is equal to (nb_elements * 1) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_float32_to_int8(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * Convert a buffer containing numbers in signed 8-bit integer format (INT8) to single precision + * floating format (float32). + * + * @param[in] scale + * Scale factor for conversion. + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing INT8 numbers. Size of buffer is equal to (nb_elements * 1) bytes. + * @param[out] output + * Output buffer to store float32 numbers. Size of buffer is equal to (nb_elements * 4) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_int8_to_float32(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * Convert a buffer containing numbers in single precision floating format (float32) to unsigned + * 8-bit integer format (UINT8). + * + * @param[in] scale + * Scale factor for conversion. + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing float32 numbers. Size of buffer is equal to (nb_elements * 4) bytes. + * @param[out] output + * Output buffer to store UINT8 numbers. Size of buffer is equal to (nb_elements * 1) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_float32_to_uint8(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * Convert a buffer containing numbers in unsigned 8-bit integer format (UINT8) to single precision + * floating format (float32). + * + * @param[in] scale + * Scale factor for conversion. + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing UINT8 numbers. Size of buffer is equal to (nb_elements * 1) bytes. + * @param[out] output + * Output buffer to store float32 numbers. Size of buffer is equal to (nb_elements * 4) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_uint8_to_float32(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * Convert a buffer containing numbers in single precision floating format (float32) to signed + * 16-bit integer format (INT16). + * + * @param[in] scale + * Scale factor for conversion. + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing float32 numbers. Size of buffer is equal to (nb_elements * 4) bytes. + * @param[out] output + * Output buffer to store INT16 numbers. Size of buffer is equal to (nb_elements * 2) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_float32_to_int16(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * Convert a buffer containing numbers in signed 16-bit integer format (INT16) to single precision + * floating format (float32). + * + * @param[in] scale + * Scale factor for conversion. + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing INT16 numbers. Size of buffer is equal to (nb_elements * 2) bytes. + * @param[out] output + * Output buffer to store float32 numbers. Size of buffer is equal to (nb_elements * 4) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_int16_to_float32(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * Convert a buffer containing numbers in single precision floating format (float32) to unsigned + * 16-bit integer format (UINT16). + * + * @param[in] scale + * Scale factor for conversion. + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing float32 numbers. Size of buffer is equal to (nb_elements * 4) bytes. + * @param[out] output + * Output buffer to store UINT16 numbers. Size of buffer is equal to (nb_elements * 2) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_float32_to_uint16(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * Convert a buffer containing numbers in unsigned 16-bit integer format (UINT16) to single + * precision floating format (float32). + * + * @param[in] scale + * Scale factor for conversion. + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing UINT16 numbers. Size of buffer is equal to (nb_elements * 2) bytes. + * @param[out] output + * Output buffer to store float32 numbers. Size of buffer is equal to (nb_elements * 4) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_uint16_to_float32(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * Convert a buffer containing numbers in single precision floating format (float32) to half + * precision floating point format (FP16). + * + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing float32 numbers. Size of buffer is equal to (nb_elements *4) bytes. + * @param[out] output + * Output buffer to store float16 numbers. Size of buffer is equal to (nb_elements * 2) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_float32_to_float16(uint64_t nb_elements, void *input, void *output); + +/** + * Convert a buffer containing numbers in half precision floating format (FP16) to single precision + * floating point format (float32). + * + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing float16 numbers. Size of buffer is equal to (nb_elements * 2) bytes. + * @param[out] output + * Output buffer to store float32 numbers. Size of buffer is equal to (nb_elements * 4) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_float16_to_float32(uint64_t nb_elements, void *input, void *output); + +/** + * Convert a buffer containing numbers in single precision floating format (float32) to brain + * floating point format (bfloat16). + * + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing float32 numbers. Size of buffer is equal to (nb_elements *4) bytes. + * @param[out] output + * Output buffer to store bfloat16 numbers. Size of buffer is equal to (nb_elements * 2) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_float32_to_bfloat16(uint64_t nb_elements, void *input, void *output); + +/** + * Convert a buffer containing numbers in brain floating point format (bfloat16) to single precision + * floating point format (float32). + * + * @param[in] nb_elements + * Number of elements in the buffer. + * @param[in] input + * Input buffer containing bfloat16 numbers. Size of buffer is equal to (nb_elements * 2) + * bytes. + * @param[out] output + * Output buffer to store float32 numbers. Size of buffer is equal to (nb_elements * 4) bytes. + * + * @return + * - 0, Success. + * - < 0, Error code on failure. + */ +__rte_internal +int ml_bfloat16_to_float32(uint64_t nb_elements, void *input, void *output); + +#endif /*_ML_UTILS_H_ */ -- 2.17.1