[v1,1/4] common/ml: add initial files for ML common code

Message ID 20221208193532.16718-2-syalavarthi@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series implementation of ML common code |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Srikanth Yalavarthi Dec. 8, 2022, 7:35 p.m. UTC
  Added initial files for common ML driver code. Implemented ML
type to size conversion, type to string and format to string
conversion utility functions.

Signed-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
---
Depends-on: series-26046 ("app/mldev: implement test framework for mldev")

 MAINTAINERS                   |   8 +++
 drivers/common/meson.build    |   1 +
 drivers/common/ml/meson.build |  20 +++++++
 drivers/common/ml/ml_utils.c  | 110 ++++++++++++++++++++++++++++++++++
 drivers/common/ml/ml_utils.h  |  50 ++++++++++++++++
 drivers/common/ml/version.map |   9 +++
 6 files changed, 198 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
 create mode 100644 drivers/common/ml/version.map

--
2.17.1
  

Patch

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 <syalavarthi@marvell.com>
+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..45c1f76a54
--- /dev/null
+++ b/drivers/common/ml/ml_utils.c
@@ -0,0 +1,110 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2022 Marvell.
+ */
+
+#include <rte_mldev.h>
+
+#include "ml_utils.h"
+
+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/ml_utils.h b/drivers/common/ml/ml_utils.h
new file mode 100644
index 0000000000..b6adb98e04
--- /dev/null
+++ b/drivers/common/ml/ml_utils.h
@@ -0,0 +1,50 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2022 Marvell.
+ */
+
+#ifndef _ML_UTILS_H_
+#define _ML_UTILS_H_
+
+#include <rte_compat.h>
+#include <rte_mldev.h>
+
+/**
+ * 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);
+
+#endif /*_ML_UTILS_H_ */
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: *;
+};