From patchwork Tue Feb 7 16:00:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 123312 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 048BF41C30; Tue, 7 Feb 2023 17:00:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D5E9F40A84; Tue, 7 Feb 2023 17:00:21 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 49F224021F 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 317EdPa0011264 for ; Tue, 7 Feb 2023 08:00:17 -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=OvCqXlbONnL/i+nr6fWOhpz6C1ak62fo2O8HNVr78Zg=; b=kMRXWsL0Ut/gxWc1XjUA5yAh6SdbfJNewmmp9jONLX3ztzBjJOJ3IZ3JG4idNhD6IKmT yLoFt8iDB3cQnWp/ln6FCiSOZgOICWVOoCQBezGwMjU9+mG1kyQFYFbo5lh/beXmlvHb w9Id6PH/YH1FsxIw6SbKlx0WkjCnFk3o9Bxkd8myZDlDLwNeyLA501qTLnZHGUqOIyrG edMUExQ+1ARPWlZL4A5N1D4fNp2056mnXtx5w33NEYzu2RqrDtjlvNL4fuIpNSFcU+UB C5HzQDrAZy0lOOiBF785w7P/MwIrQrvgfbqcqNIOrul98cFs4OWAEXxov8FIZR/n34HH 7g== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3nkdyrsrbj-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 07 Feb 2023 08:00:17 -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:15 -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:15 -0800 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 9D8D33F70AE; Tue, 7 Feb 2023 08:00:10 -0800 (PST) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v6 1/4] mldev: add headers for internal ML functions Date: Tue, 7 Feb 2023 08:00:05 -0800 Message-ID: <20230207160008.30182-2-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 X-Proofpoint-ORIG-GUID: 7sOkM9pHB9gKAGVVPYyuMK_lYSrB44hy X-Proofpoint-GUID: 7sOkM9pHB9gKAGVVPYyuMK_lYSrB44hy 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 Added header files for internal ML utility routines to convert IO type and format to string, IO type to size and routines to convert data types. Signed-off-by: Srikanth Yalavarthi --- Depends-on: series-26858 ("Implementation of mldev test application") v6: * Updated release notes and series dependencies v5: * Moved the code from drivers/common/ml to lib/mldev * Added rte_ml_io_ prefix to the functions v3: * Skip installation of internal common/ml headers v2: * Moved implementation out of patch. Only headers are included. doc/guides/rel_notes/release_23_03.rst | 5 + lib/mldev/meson.build | 2 + lib/mldev/mldev_utils.c | 5 + lib/mldev/mldev_utils.h | 345 +++++++++++++++++++++++++ 4 files changed, 357 insertions(+) create mode 100644 lib/mldev/mldev_utils.c create mode 100644 lib/mldev/mldev_utils.h -- 2.17.1 diff --git a/doc/guides/rel_notes/release_23_03.rst b/doc/guides/rel_notes/release_23_03.rst index cd1ac98abe..425323241e 100644 --- a/doc/guides/rel_notes/release_23_03.rst +++ b/doc/guides/rel_notes/release_23_03.rst @@ -95,6 +95,11 @@ New Features * Test case for inferences from multiple models in ordered mode. * Test case for inferences from multiple models.in interleaving mode. +* **Added common driver functions for machine learning device library.** + + * Added functions to translate IO type and format to string. + * Added functions to quantize and dequantize inference IO data. + Removed Items ------------- diff --git a/lib/mldev/meson.build b/lib/mldev/meson.build index 5c99532c1a..452b83a480 100644 --- a/lib/mldev/meson.build +++ b/lib/mldev/meson.build @@ -4,6 +4,7 @@ sources = files( 'rte_mldev_pmd.c', 'rte_mldev.c', + 'mldev_utils.c', ) headers = files( @@ -16,6 +17,7 @@ indirect_headers += files( driver_sdk_headers += files( 'rte_mldev_pmd.h', + 'mldev_utils.h', ) deps += ['mempool'] diff --git a/lib/mldev/mldev_utils.c b/lib/mldev/mldev_utils.c new file mode 100644 index 0000000000..9dbbf013a0 --- /dev/null +++ b/lib/mldev/mldev_utils.c @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include "mldev_utils.h" diff --git a/lib/mldev/mldev_utils.h b/lib/mldev/mldev_utils.h new file mode 100644 index 0000000000..04cdaab567 --- /dev/null +++ b/lib/mldev/mldev_utils.h @@ -0,0 +1,345 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#ifndef _RTE_MLDEV_UTILS_H_ +#define _RTE_MLDEV_UTILS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * + * RTE ML Device PMD utility API + * + * These APIs for the use from ML drivers, user applications shouldn't use them. + * + */ + +#include +#include + +/** + * @internal + * + * 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 +rte_ml_io_type_size_get(enum rte_ml_io_type type); + +/** + * @internal + * + * 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 +rte_ml_io_type_to_str(enum rte_ml_io_type type, char *str, int len); + +/** + * @internal + * + * 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 +rte_ml_io_format_to_str(enum rte_ml_io_format format, char *str, int len); + +/** + * @internal + * + * 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 +rte_ml_io_float32_to_int8(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * @internal + * + * 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 +rte_ml_io_int8_to_float32(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * @internal + * + * 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 +rte_ml_io_float32_to_uint8(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * @internal + * + * 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 +rte_ml_io_uint8_to_float32(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * @internal + * + * 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 +rte_ml_io_float32_to_int16(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * @internal + * + * 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 +rte_ml_io_int16_to_float32(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * @internal + * + * 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 +rte_ml_io_float32_to_uint16(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * @internal + * + * 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 +rte_ml_io_uint16_to_float32(float scale, uint64_t nb_elements, void *input, void *output); + +/** + * @internal + * + * 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 +rte_ml_io_float32_to_float16(uint64_t nb_elements, void *input, void *output); + +/** + * @internal + * + * 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 +rte_ml_io_float16_to_float32(uint64_t nb_elements, void *input, void *output); + +/** + * @internal + * + * 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 +rte_ml_io_float32_to_bfloat16(uint64_t nb_elements, void *input, void *output); + +/** + * @internal + * + * 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 +rte_ml_io_bfloat16_to_float32(uint64_t nb_elements, void *input, void *output); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_MLDEV_UTILS_H_ */