-----Original Message----- From: Srikanth Yalavarthi Sent: Wednesday, February 1, 2023 2:35 PM To: Srikanth Yalavarthi Cc: dev@dpdk.org; Shivah Shankar Shankar Narayan Rao ; Jerin Jacob Kollanukkaran ; Anup Prabhu Subject: [PATCH v4 1/4] mldev: add headers for internal ML functions 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 --- lib/mldev/meson.build | 2 + lib/mldev/mldev_utils.c | 5 + lib/mldev/mldev_utils.h | 345 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 352 insertions(+) create mode 100644 lib/mldev/mldev_utils.c create mode 100644 lib/mldev/mldev_utils.h Acked-by: Anup Prabhu 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_ */ -- 2.17.1