[PATCH v3 2/4] common/ml: add common utility functions
Srikanth Yalavarthi
syalavarthi at marvell.com
Tue Dec 20 18:52:54 CET 2022
Implemented ML common 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 <syalavarthi at marvell.com>
---
v2:
* Implemented common utility functions as part of the patch
* Dropped use of driver routines for data conversion functions
drivers/common/ml/ml_utils.c | 113 ++++++++++++++++++++++++++++++++++
drivers/common/ml/version.map | 9 +++
2 files changed, 122 insertions(+)
create mode 100644 drivers/common/ml/version.map
diff --git a/drivers/common/ml/ml_utils.c b/drivers/common/ml/ml_utils.c
index 90bc280e4b..59753c5468 100644
--- a/drivers/common/ml/ml_utils.c
+++ b/drivers/common/ml/ml_utils.c
@@ -2,4 +2,117 @@
* Copyright (c) 2022 Marvell.
*/
+#include <errno.h>
+#include <stdint.h>
+
+#include <rte_mldev.h>
+#include <rte_string_fns.h>
+
#include "ml_utils.h"
+
+/* Description:
+ * This file implements Machine Learning utility routines, except type conversion routines.
+ */
+
+int
+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
+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
+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/drivers/common/ml/version.map b/drivers/common/ml/version.map
new file mode 100644
index 0000000000..7e33755f2f
--- /dev/null
+++ b/drivers/common/ml/version.map
@@ -0,0 +1,9 @@
+INTERNAL {
+ global:
+
+ ml_io_type_size_get;
+ ml_io_type_to_str;
+ ml_io_format_to_str;
+
+ local: *;
+};
--
2.17.1
More information about the dev
mailing list