From patchwork Thu Dec 8 19:35:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 120597 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 28A6DA0032; Thu, 8 Dec 2022 20:35:49 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DAC9D42D27; Thu, 8 Dec 2022 20:35:40 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 8FBEA410D2 for ; Thu, 8 Dec 2022 20:35:38 +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 2B8J8KK8001363 for ; Thu, 8 Dec 2022 11:35:37 -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=YjhSfWFRzYTCB8hV5Vng6uczzkRf82PsVucbQYWLrQY=; b=h8ECJBuEGg7e0c8vtY9AKrXUwC38cvEe9D1O+z89GoJLPOIze/BM4YnWh1FW7cvbxDps oj/E0AzVIWJVQWcuHLvjY9gN5GukWsIbR1ijJ+lp/R+/genLWXSc29m82swaaYmDmQUm RSnNh4bRp7CTcD7qBOTf8KXMmEIoIj81dNic57JUzofRdS3xAzPqdbK0T5Jjh7CoWAXQ uIjHN8mpcHZ6NhYf/1q3bGD0xgn50DrDtRNKXQnXFRrDNU5Y29vYAr9DAlAVQE6thza0 Zwf4XQVvS1LqV5t+n2MQde/7c01MrfpDN/wjvrhtdktvvBOymwNLo4YI5IX4egNAP1HQ Pw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3mb22svkjj-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 08 Dec 2022 11:35:37 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 8 Dec 2022 11:35:35 -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.18 via Frontend Transport; Thu, 8 Dec 2022 11:35:35 -0800 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 82E273F7072; Thu, 8 Dec 2022 11:35:35 -0800 (PST) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , Subject: [PATCH v1 2/4] common/ml: add data type conversion routines Date: Thu, 8 Dec 2022 11:35:30 -0800 Message-ID: <20221208193532.16718-3-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221208193532.16718-1-syalavarthi@marvell.com> References: <20221208193532.16718-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: xk5HmOpxlL8hOfy7cG-_eVrW8WQiSGZX X-Proofpoint-GUID: xk5HmOpxlL8hOfy7cG-_eVrW8WQiSGZX 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-08_11,2022-12-08_01,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 Type conversion routines transform data from higher to lower precision data types or vice-versa. These conversion functions can be used by the ML driver implementations for quantization and de-quantization. Added driver routines for type conversion. These driver routines invoke the architecture specific functions. Signed-off-by: Srikanth Yalavarthi --- drivers/common/ml/ml_utils.c | 132 +++++++++++++++++++ drivers/common/ml/ml_utils.h | 233 ++++++++++++++++++++++++++++++++++ drivers/common/ml/version.map | 16 +++ 3 files changed, 381 insertions(+) diff --git a/drivers/common/ml/ml_utils.c b/drivers/common/ml/ml_utils.c index 45c1f76a54..553e906172 100644 --- a/drivers/common/ml/ml_utils.c +++ b/drivers/common/ml/ml_utils.c @@ -2,6 +2,10 @@ * Copyright (c) 2022 Marvell. */ +#include +#include + +#include #include #include "ml_utils.h" @@ -108,3 +112,131 @@ ml_io_format_to_str(enum rte_ml_io_format format, char *str, int len) rte_strlcpy(str, "invalid", len); } } + +int +ml_float32_to_int8(float scale, uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(scale); + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} + +int +ml_int8_to_float32(float scale, uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(scale); + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} + +int +ml_float32_to_uint8(float scale, uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(scale); + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} + +int +ml_uint8_to_float32(float scale, uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(scale); + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} + +int +ml_float32_to_int16(float scale, uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(scale); + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} + +int +ml_int16_to_float32(float scale, uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(scale); + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} + +int +ml_float32_to_uint16(float scale, uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(scale); + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} + +int +ml_uint16_to_float32(float scale, uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(scale); + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} + +int +ml_float32_to_float16(uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} + +int +ml_float16_to_float32(uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} + +int +ml_float32_to_bfloat16(uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} + +int +ml_bfloat16_to_float32(uint64_t nb_elements, void *input, void *output) +{ + RTE_SET_USED(nb_elements); + RTE_SET_USED(input); + RTE_SET_USED(output); + + return -ENOTSUP; +} diff --git a/drivers/common/ml/ml_utils.h b/drivers/common/ml/ml_utils.h index b6adb98e04..9726c6e3b5 100644 --- a/drivers/common/ml/ml_utils.h +++ b/drivers/common/ml/ml_utils.h @@ -47,4 +47,237 @@ void ml_io_type_to_str(enum rte_ml_io_type type, char *str, int len); __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_ */ diff --git a/drivers/common/ml/version.map b/drivers/common/ml/version.map index 7e33755f2f..35f270f637 100644 --- a/drivers/common/ml/version.map +++ b/drivers/common/ml/version.map @@ -5,5 +5,21 @@ INTERNAL { ml_io_type_to_str; ml_io_format_to_str; + ml_float32_to_int8; + ml_int8_to_float32; + ml_float32_to_uint8; + ml_uint8_to_float32; + + ml_float32_to_int16; + ml_int16_to_float32; + ml_float32_to_uint16; + ml_uint16_to_float32; + + ml_float32_to_float16; + ml_float16_to_float32; + + ml_float32_to_bfloat16; + ml_bfloat16_to_float32; + local: *; };