[v1,19/34] ml/cnxk: support config and close of tvmdp library

Message ID 20230830155927.3566-20-syalavarthi@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Implemenation of revised ml/cnxk driver |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Srikanth Yalavarthi Aug. 30, 2023, 3:59 p.m. UTC
  Added support to configure and close TVMDP library based
on ML device configuration options.

Updated meson build to enable Jansson, TVM runtime, TVMDP
library as build dependencies.

Signed-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
---
 drivers/ml/cnxk/cnxk_ml_ops.c  | 15 ++++++++++++
 drivers/ml/cnxk/meson.build    | 45 ++++++++++++++++++++++++++++++++++
 drivers/ml/cnxk/mvtvm_ml_ops.c | 44 +++++++++++++++++++++++++++++++++
 drivers/ml/cnxk/mvtvm_ml_ops.h | 15 ++++++++++++
 4 files changed, 119 insertions(+)
 create mode 100644 drivers/ml/cnxk/mvtvm_ml_ops.c
 create mode 100644 drivers/ml/cnxk/mvtvm_ml_ops.h
  

Comments

Jerin Jacob Sept. 21, 2023, 12:32 p.m. UTC | #1
On Wed, Aug 30, 2023 at 9:34 PM Srikanth Yalavarthi
<syalavarthi@marvell.com> wrote:
>
> Added support to configure and close TVMDP library based
> on ML device configuration options.
>
> Updated meson build to enable Jansson, TVM runtime, TVMDP
> library as build dependencies.

If it is optional – please add optional

please update cnxk ml driver documentation on this dependency and
example command to build it. See DPDK mlx5 docs for dependency
documentation.


>
> Signed-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
> ---
>  drivers/ml/cnxk/cnxk_ml_ops.c  | 15 ++++++++++++
>  drivers/ml/cnxk/meson.build    | 45 ++++++++++++++++++++++++++++++++++
>  drivers/ml/cnxk/mvtvm_ml_ops.c | 44 +++++++++++++++++++++++++++++++++
>  drivers/ml/cnxk/mvtvm_ml_ops.h | 15 ++++++++++++
>  4 files changed, 119 insertions(+)
>  create mode 100644 drivers/ml/cnxk/mvtvm_ml_ops.c
>  create mode 100644 drivers/ml/cnxk/mvtvm_ml_ops.h
>
> diff --git a/drivers/ml/cnxk/cnxk_ml_ops.c b/drivers/ml/cnxk/cnxk_ml_ops.c
> index b2eb4bd0d9a..454fec33234 100644
> --- a/drivers/ml/cnxk/cnxk_ml_ops.c
> +++ b/drivers/ml/cnxk/cnxk_ml_ops.c
> @@ -9,6 +9,10 @@
>
>  #include "cn10k_ml_ops.h"
>
> +#ifdef RTE_MLDEV_CNXK_ENABLE_MVTVM
> +#include "mvtvm_ml_ops.h"
> +#endif
> +
>  #include "cnxk_ml_dev.h"
>  #include "cnxk_ml_io.h"
>  #include "cnxk_ml_model.h"
> @@ -625,6 +629,12 @@ cnxk_ml_dev_configure(struct rte_ml_dev *dev, const struct rte_ml_dev_config *co
>                 goto error;
>         }
>
> +#ifdef RTE_MLDEV_CNXK_ENABLE_MVTVM

If this #ifdef used a lot place in code like this, Please have stub
and segregate at once place in header file
and avoid ifdef main code like cnxk_ml_dev_configure().
  
Srikanth Yalavarthi Sept. 27, 2023, 6:38 p.m. UTC | #2
> -----Original Message-----
> From: Jerin Jacob <jerinjacobk@gmail.com>
> Sent: 21 September 2023 18:02
> To: Srikanth Yalavarthi <syalavarthi@marvell.com>
> Cc: dev@dpdk.org; Shivah Shankar Shankar Narayan Rao
> <sshankarnara@marvell.com>; Anup Prabhu <aprabhu@marvell.com>;
> Prince Takkar <ptakkar@marvell.com>; Srikanth Yalavarthi
> <syalavarthi@marvell.com>
> Subject: [EXT] Re: [PATCH v1 19/34] ml/cnxk: support config and close of
> tvmdp library
> 
> External Email
> 
> ----------------------------------------------------------------------
> On Wed, Aug 30, 2023 at 9:34 PM Srikanth Yalavarthi
> <syalavarthi@marvell.com> wrote:
> >
> > Added support to configure and close TVMDP library based on ML device
> > configuration options.
> >
> > Updated meson build to enable Jansson, TVM runtime, TVMDP library as
> > build dependencies.
> 
> If it is optional – please add optional
> 
> please update cnxk ml driver documentation on this dependency and
> example command to build it. See DPDK mlx5 docs for dependency
> documentation.

Updated the driver documentation with details related to external libraries in v3 patch series.
> 
> 
> >
> > Signed-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
> > ---
> >  drivers/ml/cnxk/cnxk_ml_ops.c  | 15 ++++++++++++
> >  drivers/ml/cnxk/meson.build    | 45
> ++++++++++++++++++++++++++++++++++
> >  drivers/ml/cnxk/mvtvm_ml_ops.c | 44
> +++++++++++++++++++++++++++++++++
> > drivers/ml/cnxk/mvtvm_ml_ops.h | 15 ++++++++++++
> >  4 files changed, 119 insertions(+)
> >  create mode 100644 drivers/ml/cnxk/mvtvm_ml_ops.c  create mode
> 100644
> > drivers/ml/cnxk/mvtvm_ml_ops.h
> >
> > diff --git a/drivers/ml/cnxk/cnxk_ml_ops.c
> > b/drivers/ml/cnxk/cnxk_ml_ops.c index b2eb4bd0d9a..454fec33234
> 100644
> > --- a/drivers/ml/cnxk/cnxk_ml_ops.c
> > +++ b/drivers/ml/cnxk/cnxk_ml_ops.c
> > @@ -9,6 +9,10 @@
> >
> >  #include "cn10k_ml_ops.h"
> >
> > +#ifdef RTE_MLDEV_CNXK_ENABLE_MVTVM
> > +#include "mvtvm_ml_ops.h"
> > +#endif
> > +
> >  #include "cnxk_ml_dev.h"
> >  #include "cnxk_ml_io.h"
> >  #include "cnxk_ml_model.h"
> > @@ -625,6 +629,12 @@ cnxk_ml_dev_configure(struct rte_ml_dev *dev,
> const struct rte_ml_dev_config *co
> >                 goto error;
> >         }
> >
> > +#ifdef RTE_MLDEV_CNXK_ENABLE_MVTVM
> 
> If this #ifdef used a lot place in code like this, Please have stub and segregate
> at once place in header file and avoid ifdef main code like
> cnxk_ml_dev_configure().

Reorganized the code to reduce the use of RTE_MLDEV_CNXK_ENABLE_MVTVM. Changes part of v3 series.
  

Patch

diff --git a/drivers/ml/cnxk/cnxk_ml_ops.c b/drivers/ml/cnxk/cnxk_ml_ops.c
index b2eb4bd0d9a..454fec33234 100644
--- a/drivers/ml/cnxk/cnxk_ml_ops.c
+++ b/drivers/ml/cnxk/cnxk_ml_ops.c
@@ -9,6 +9,10 @@ 
 
 #include "cn10k_ml_ops.h"
 
+#ifdef RTE_MLDEV_CNXK_ENABLE_MVTVM
+#include "mvtvm_ml_ops.h"
+#endif
+
 #include "cnxk_ml_dev.h"
 #include "cnxk_ml_io.h"
 #include "cnxk_ml_model.h"
@@ -625,6 +629,12 @@  cnxk_ml_dev_configure(struct rte_ml_dev *dev, const struct rte_ml_dev_config *co
 		goto error;
 	}
 
+#ifdef RTE_MLDEV_CNXK_ENABLE_MVTVM
+	ret = mvtvm_ml_dev_configure(cnxk_mldev, conf);
+	if (ret != 0)
+		goto error;
+#endif
+
 	/* Set device capabilities */
 	cnxk_mldev->max_nb_layers =
 		cnxk_mldev->cn10k_mldev.fw.req->cn10k_req.jd.fw_load.cap.s.max_models;
@@ -685,6 +695,11 @@  cnxk_ml_dev_close(struct rte_ml_dev *dev)
 	/* Un-initialize xstats */
 	cnxk_ml_xstats_uninit(cnxk_mldev);
 
+#ifdef RTE_MLDEV_CNXK_ENABLE_MVTVM
+	if (mvtvm_ml_dev_close(cnxk_mldev) != 0)
+		plt_err("Failed to close MVTVM ML Device");
+#endif
+
 	if (cn10k_ml_dev_close(cnxk_mldev) != 0)
 		plt_err("Failed to close CN10K ML Device");
 
diff --git a/drivers/ml/cnxk/meson.build b/drivers/ml/cnxk/meson.build
index 575f08f9c09..29dad0b0e33 100644
--- a/drivers/ml/cnxk/meson.build
+++ b/drivers/ml/cnxk/meson.build
@@ -7,6 +7,27 @@  if not is_linux or not dpdk_conf.get('RTE_ARCH_64')
     subdir_done()
 endif
 
+enable_mvtvm = true
+
+if not jansson_dep.found()
+        message('drivers/ml/cnxk: jansson not found')
+        enable_mvtvm = false
+endif
+
+tvmrt_lib = cc.find_library('tvm_runtime', required: false)
+if tvmrt_lib.found()
+        tvmrt_dep = declare_dependency(dependencies: tvmrt_lib)
+else
+        message('drivers/ml/cnxk: tvm_runtime not found')
+        enable_mvtvm = false
+endif
+
+tvmdp_dep = dependency('tvmdp', required: false)
+if not tvmdp_dep.found()
+        message('drivers/ml/cnxk: tvmdp not found')
+        enable_mvtvm = false
+endif
+
 driver_sdk_headers = files(
         'cn10k_ml_dev.h',
         'cn10k_ml_ops.h',
@@ -34,6 +55,30 @@  sources = files(
 
 deps += ['mldev', 'common_cnxk', 'kvargs', 'hash']
 
+if enable_mvtvm
+
+dpdk_conf.set('RTE_MLDEV_CNXK_ENABLE_MVTVM', true)
+
+driver_sdk_headers += files(
+        'mvtvm_ml_ops.h',
+)
+
+sources += files(
+        'mvtvm_ml_ops.c',
+)
+
+ext_deps += tvmrt_dep
+ext_deps += tvmdp_dep
+ext_deps += cc.find_library('stdc++', required: true)
+ext_deps += jansson_dep
+
+deps += ['bus_vdev']
+
+message('drivers/ml/cnxk: Enabled TVM model support')
+else
+message('drivers/ml/cnxk: Disabled TVM model support')
+endif
+
 require_iova_in_mbuf = false
 
 if get_option('buildtype').contains('debug')
diff --git a/drivers/ml/cnxk/mvtvm_ml_ops.c b/drivers/ml/cnxk/mvtvm_ml_ops.c
new file mode 100644
index 00000000000..0e1fc527daa
--- /dev/null
+++ b/drivers/ml/cnxk/mvtvm_ml_ops.c
@@ -0,0 +1,44 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 Marvell.
+ */
+
+#include <tvmdp.h>
+
+#include <rte_common.h>
+#include <rte_cycles.h>
+#include <rte_mldev.h>
+#include <rte_mldev_pmd.h>
+
+#include "mvtvm_ml_ops.h"
+
+#include "cnxk_ml_dev.h"
+
+int
+mvtvm_ml_dev_configure(struct cnxk_ml_dev *cnxk_mldev, const struct rte_ml_dev_config *conf)
+{
+	int ret;
+
+	RTE_SET_USED(conf);
+
+	/* Configure TVMDP library */
+	ret = tvmdp_configure(cnxk_mldev->mldev->data->nb_models, rte_get_tsc_cycles);
+	if (ret != 0)
+		plt_err("TVMDP configuration failed, error = %d\n", ret);
+
+	return ret;
+}
+
+int
+mvtvm_ml_dev_close(struct cnxk_ml_dev *cnxk_mldev)
+{
+	int ret;
+
+	RTE_SET_USED(cnxk_mldev);
+
+	/* Close TVMDP library configuration */
+	ret = tvmdp_close();
+	if (ret != 0)
+		plt_err("TVMDP close failed, error = %d\n", ret);
+
+	return ret;
+}
diff --git a/drivers/ml/cnxk/mvtvm_ml_ops.h b/drivers/ml/cnxk/mvtvm_ml_ops.h
new file mode 100644
index 00000000000..988f3a1fd5e
--- /dev/null
+++ b/drivers/ml/cnxk/mvtvm_ml_ops.h
@@ -0,0 +1,15 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 Marvell.
+ */
+
+#ifndef _MVTVM_ML_OPS_H_
+#define _MVTVM_ML_OPS_H_
+
+#include <rte_mldev.h>
+
+struct cnxk_ml_dev;
+
+int mvtvm_ml_dev_configure(struct cnxk_ml_dev *cnxk_mldev, const struct rte_ml_dev_config *conf);
+int mvtvm_ml_dev_close(struct cnxk_ml_dev *cnxk_mldev);
+
+#endif /* _MVTVM_ML_OPS_H_ */