From patchwork Thu Oct 26 12:43:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 133409 X-Patchwork-Delegate: jerinj@marvell.com 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 2D2C643208; Thu, 26 Oct 2023 14:48:13 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 581A942E9C; Thu, 26 Oct 2023 14:44:25 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 2CAE442E0C for ; Thu, 26 Oct 2023 14:44:03 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39QAKqcY006841; Thu, 26 Oct 2023 05:44:00 -0700 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-transfer-encoding : content-type; s=pfpt0220; bh=gMRozJKY7Ntb7Et2jFMq2kpzjKhpRC3klSZYIfWeAvQ=; b=kFXaMZGo7Spx84A3CpbWFAmzNQ2uK8ngWG+JRgs6kKC7mgsOj6IBclaw8EWipyRwoyMY lKfcxoliVC5HR9jwKQFWUdfsINe5IEBahRoLt9kjGI9Xg6nCvs9i2RLJhGEZY86Otso9 D6SFcHauR0LyOLf55Z5DsyLq9qNRw2hpUhpiiPdVhqNBM0MbqBOnUfkZVmyXG0HT5pyS f7paTMQDKFXPsPTFhTk/KMGZHAVeA+JvNtffYN7u8C0PSkUUCAtkIW3ZCugw/ko4xNdj 2SrwcLs9wUaNTBHZTYjlQmgNQm9ZEaLXizsMKVz4X5koh2Sy9rmS1rC+4VaUtuj6eHLa nw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3txcsr25pj-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 26 Oct 2023 05:44:00 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 26 Oct 2023 05:43:58 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Thu, 26 Oct 2023 05:43:58 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 973613F70C1; Thu, 26 Oct 2023 05:43:57 -0700 (PDT) From: Srikanth Yalavarthi To: Ruifeng Wang , Bruce Richardson , Srikanth Yalavarthi CC: , , , Subject: [PATCH v9 18/34] ml/cnxk: support config and close of tvmdp library Date: Thu, 26 Oct 2023 05:43:27 -0700 Message-ID: <20231026124347.22477-19-syalavarthi@marvell.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231026124347.22477-1-syalavarthi@marvell.com> References: <20230830155927.3566-1-syalavarthi@marvell.com> <20231026124347.22477-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: l6eqiFHYwT0SszUNn6auTEJsdIADIfwo X-Proofpoint-GUID: l6eqiFHYwT0SszUNn6auTEJsdIADIfwo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-26_10,2023-10-26_01,2023-05-22_02 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 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 --- config/arm/arm64_cn10k_linux_gcc | 1 + config/arm/arm64_cn9k_linux_gcc | 1 + doc/guides/mldevs/cnxk.rst | 169 +++++++++++++++++++++++++++++++ drivers/ml/cnxk/cnxk_ml_ops.c | 7 ++ drivers/ml/cnxk/cnxk_ml_ops.h | 6 ++ drivers/ml/cnxk/meson.build | 58 +++++++++++ drivers/ml/cnxk/mvtvm_ml_ops.c | 41 ++++++++ drivers/ml/cnxk/mvtvm_ml_ops.h | 19 ++++ drivers/ml/cnxk/mvtvm_ml_stubs.c | 26 +++++ drivers/ml/cnxk/mvtvm_ml_stubs.h | 15 +++ 10 files changed, 343 insertions(+) create mode 100644 drivers/ml/cnxk/mvtvm_ml_ops.c create mode 100644 drivers/ml/cnxk/mvtvm_ml_ops.h create mode 100644 drivers/ml/cnxk/mvtvm_ml_stubs.c create mode 100644 drivers/ml/cnxk/mvtvm_ml_stubs.h diff --git a/config/arm/arm64_cn10k_linux_gcc b/config/arm/arm64_cn10k_linux_gcc index 05d2d64cf2..fa904af5d0 100644 --- a/config/arm/arm64_cn10k_linux_gcc +++ b/config/arm/arm64_cn10k_linux_gcc @@ -5,6 +5,7 @@ ar = 'aarch64-linux-gnu-gcc-ar' strip = 'aarch64-linux-gnu-strip' pkgconfig = 'aarch64-linux-gnu-pkg-config' pcap-config = '' +cmake = 'cmake' [host_machine] system = 'linux' diff --git a/config/arm/arm64_cn9k_linux_gcc b/config/arm/arm64_cn9k_linux_gcc index 7416454de0..646ce4b5d3 100644 --- a/config/arm/arm64_cn9k_linux_gcc +++ b/config/arm/arm64_cn9k_linux_gcc @@ -5,6 +5,7 @@ ar = 'aarch64-linux-gnu-gcc-ar' strip = 'aarch64-linux-gnu-strip' pkgconfig = 'aarch64-linux-gnu-pkg-config' pcap-config = '' +cmake = 'cmake' [host_machine] system = 'linux' diff --git a/doc/guides/mldevs/cnxk.rst b/doc/guides/mldevs/cnxk.rst index 1834b1f905..a4d8903896 100644 --- a/doc/guides/mldevs/cnxk.rst +++ b/doc/guides/mldevs/cnxk.rst @@ -46,6 +46,175 @@ or cross-compiled on an x86 platform. Refer to :doc:`../platform/cnxk` for instructions to build your DPDK application. +Compilation Prerequisites +------------------------- + +This driver requires external libraries to optionally enable support for +models compiled using Apache TVM framework. The following dependencies are +not part of DPDK and must be installed separately: + +- **Jansson** + + This library enables support to parse and read JSON files. + +- **DLPack** + + This library provides headers for open in-memory tensor structures. + +.. note:: + + DPDK CNXK ML driver requires DLPack version 0.7 + +.. code-block:: console + + git clone https://github.com/dmlc/dlpack.git + cd dlpack + git checkout v0.7 -b v0.7 + cmake -S ./ -B build \ + -DCMAKE_INSTALL_PREFIX= \ + -DBUILD_MOCK=OFF + make -C build + make -C build install + +*Cross-compiling for AArch64* + +.. code-block:: console + + git clone https://github.com/dmlc/dlpack.git + cd dlpack + git checkout v0.7 -b v0.7 + cmake -S ./ -B build \ + -DCMAKE_INSTALL_PREFIX= + -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \ + -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \ + -DBUILD_MOCK=OFF + make -C build + make -C build install + +- **DMLC** + + This is a common bricks library for building scalable and portable distributed + machine learning. + +.. code-block:: console + + git clone https://github.com/dmlc/dmlc-core.git + cd dmlc-core + git checkout main + cmake -S ./ -B build \ + -DCMAKE_INSTALL_PREFIX= \ + -DCMAKE_C_FLAGS="-fpermissive" \ + -DCMAKE_CXX_FLAGS="-fpermissive" \ + -DUSE_OPENMP=OFF + make -C build + make -C build install + +*Cross-compiling for AArch64* + +.. code-block:: console + + git clone https://github.com/dmlc/dmlc-core.git + cd dmlc-core + git checkout main + cmake -S ./ -B build \ + -DCMAKE_INSTALL_PREFIX= \ + -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \ + -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \ + -DCMAKE_C_FLAGS="-fpermissive" \ + -DCMAKE_CXX_FLAGS="-fpermissive" \ + -DUSE_OPENMP=OFF + make -C build + make -C build install + +- **TVM** + + Apache TVM provides a runtime libraries used to execute models on CPU cores + or hardware accelerators. + +.. note:: + + DPDK CNXK ML driver requires TVM version 0.10.0 + +.. code-block:: console + + git clone https://github.com/apache/tvm.git + cd tvm + git checkout v0.11.0 -b v0.11.0 + git submodule update --init + cmake -S ./ -B build \ + -DCMAKE_INSTALL_PREFIX= \ + -DBUILD_STATIC_RUNTIME=OFF + make -C build + make -C build install + +*Cross-compiling for AArch64* + +.. code-block:: console + + git clone https://github.com/apache/tvm.git + cd tvm + git checkout v0.11.0 -b v0.11.0 + git submodule update --init + cmake -S ./ -B build \ + -DCMAKE_INSTALL_PREFIX= \ + -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \ + -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \ + -DMACHINE_NAME=aarch64-linux-gnu \ + -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \ + -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ + -DBUILD_STATIC_RUNTIME=OFF + make -C build + make -C build install + +- **TVMDP** + + Marvell's `TVM Dataplane Library `_ + works as an interface between TVM runtime and DPDK drivers. TVMDP library + provides a simplified C interface for TVM's runtime based on C++. + +.. note:: + + TVMDP library is dependent on TVM, dlpack, jansson and dmlc-core libraries. + +.. code-block:: console + + git clone https://github.com/MarvellEmbeddedProcessors/tvmdp.git + cd tvmdp + git checkout main + cmake -S ./ -B build \ + -DCMAKE_INSTALL_PREFIX= \ + -DBUILD_SHARED_LIBS=ON + make -C build + make -C build install + +*Cross-compiling for AArch64* + +.. code-block:: console + + git clone https://github.com/MarvellEmbeddedProcessors/tvmdp.git + cd tvmdp + git checkout main + cmake -S ./ -B build \ + -DCMAKE_INSTALL_PREFIX= \ + -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \ + -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \ + -DCMAKE_FIND_ROOT_PATH= \ + -DBUILD_SHARED_LIBS=ON + make -C build + make -C build install + +- **libarchive** + + Apached TVM framework generates compiled models as tar archives. This + library enables support to decompress and read archive files in tar, + xz and other formats. + +.. note:: + + In order for meson to find the dependencies during the configure stage, + it is required to add the cmake paths /lib/cmake/dlpack, + /lib/cmake/dmlc and /lib/cmake/tvm to + CMAKE_PREFIX_PATH and /lib/pkgconfig to PKG_CONFIG_PATH. Initialization -------------- diff --git a/drivers/ml/cnxk/cnxk_ml_ops.c b/drivers/ml/cnxk/cnxk_ml_ops.c index 3d21a31374..33d13d5514 100644 --- a/drivers/ml/cnxk/cnxk_ml_ops.c +++ b/drivers/ml/cnxk/cnxk_ml_ops.c @@ -564,6 +564,10 @@ cnxk_ml_dev_configure(struct rte_ml_dev *dev, const struct rte_ml_dev_config *co goto error; } + ret = mvtvm_ml_dev_configure(cnxk_mldev, conf); + if (ret != 0) + goto error; + /* Set device capabilities */ cnxk_mldev->max_nb_layers = cnxk_mldev->cn10k_mldev.fw.req->cn10k_req.jd.fw_load.cap.s.max_models; @@ -624,6 +628,9 @@ cnxk_ml_dev_close(struct rte_ml_dev *dev) /* Un-initialize xstats */ cnxk_ml_xstats_uninit(cnxk_mldev); + if (mvtvm_ml_dev_close(cnxk_mldev) != 0) + plt_err("Failed to close MVTVM ML Device"); + if (cn10k_ml_dev_close(cnxk_mldev) != 0) plt_err("Failed to close CN10K ML Device"); diff --git a/drivers/ml/cnxk/cnxk_ml_ops.h b/drivers/ml/cnxk/cnxk_ml_ops.h index d0c126f34b..b22a2b0d95 100644 --- a/drivers/ml/cnxk/cnxk_ml_ops.h +++ b/drivers/ml/cnxk/cnxk_ml_ops.h @@ -12,6 +12,12 @@ #include "cn10k_ml_ops.h" +#ifdef RTE_MLDEV_CNXK_ENABLE_MVTVM +#include "mvtvm_ml_ops.h" +#else +#include "mvtvm_ml_stubs.h" +#endif + /* Request structure */ struct cnxk_ml_req { /* Device specific request */ diff --git a/drivers/ml/cnxk/meson.build b/drivers/ml/cnxk/meson.build index 5d27a87d91..1ef2b3c335 100644 --- a/drivers/ml/cnxk/meson.build +++ b/drivers/ml/cnxk/meson.build @@ -7,6 +7,37 @@ 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 + +dlpack_dep = dependency('dlpack', method: 'cmake', required: false, cmake_args: 'CONFIG') +if not dlpack_dep.found() + message('drivers/ml/cnxk: dlpack not found') + enable_mvtvm = false +endif + +dmlc_dep = dependency('dmlc', method: 'cmake', required: false, cmake_args: 'CONFIG') +if not dmlc_dep.found() + message('drivers/ml/cnxk: dmlc not found') + enable_mvtvm = false +endif + +tvm_dep = dependency('tvm', method: 'cmake', required: false, cmake_args: 'CONFIG', modules : ['tvm::tvm_runtime']) +if not tvm_dep.found() + message('drivers/ml/cnxk: tvm_runtime not found') + enable_mvtvm = false +endif + +tvmdp_dep = dependency('tvmdp', method: 'pkg-config', required: false) +if not tvmdp_dep.found() + message('drivers/ml/cnxk: tvmdp not found') + enable_mvtvm = false +endif + sources = files( 'cn10k_ml_dev.c', 'cn10k_ml_ops.c', @@ -21,6 +52,33 @@ sources = files( deps += ['mldev', 'common_cnxk', 'kvargs', 'hash'] +if enable_mvtvm + +dpdk_conf.set('RTE_MLDEV_CNXK_ENABLE_MVTVM', 1) + +sources += files( + 'mvtvm_ml_ops.c', +) + +ext_deps += jansson_dep +ext_deps += dlpack_dep +ext_deps += dmlc_dep +ext_deps += tvm_dep +ext_deps += tvmdp_dep +ext_deps += cc.find_library('stdc++', required: true) + +deps += ['bus_vdev'] + +message('drivers/ml/cnxk: Enabled TVM model support') +else +message('drivers/ml/cnxk: Disabled TVM model support') + +sources += files( + 'mvtvm_ml_stubs.c', +) + +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 0000000000..88c6d5a864 --- /dev/null +++ b/drivers/ml/cnxk/mvtvm_ml_ops.c @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Marvell. + */ + +#include +#include +#include +#include + +#include "cnxk_ml_dev.h" +#include "cnxk_ml_ops.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 0000000000..305b4681ed --- /dev/null +++ b/drivers/ml/cnxk/mvtvm_ml_ops.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Marvell. + */ + +#ifndef _MVTVM_ML_OPS_H_ +#define _MVTVM_ML_OPS_H_ + +#include + +#include + +#include + +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_ */ diff --git a/drivers/ml/cnxk/mvtvm_ml_stubs.c b/drivers/ml/cnxk/mvtvm_ml_stubs.c new file mode 100644 index 0000000000..a31cd39cfa --- /dev/null +++ b/drivers/ml/cnxk/mvtvm_ml_stubs.c @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Marvell. + */ + +#include + +#include "mvtvm_ml_stubs.h" + +#include "cnxk_ml_dev.h" + +int +mvtvm_ml_dev_configure(struct cnxk_ml_dev *cnxk_mldev, const struct rte_ml_dev_config *conf) +{ + RTE_SET_USED(cnxk_mldev); + RTE_SET_USED(conf); + + return 0; +} + +int +mvtvm_ml_dev_close(struct cnxk_ml_dev *cnxk_mldev) +{ + RTE_SET_USED(cnxk_mldev); + + return 0; +} diff --git a/drivers/ml/cnxk/mvtvm_ml_stubs.h b/drivers/ml/cnxk/mvtvm_ml_stubs.h new file mode 100644 index 0000000000..11c56e5144 --- /dev/null +++ b/drivers/ml/cnxk/mvtvm_ml_stubs.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Marvell. + */ + +#ifndef _MVTVM_ML_STUBS_H_ +#define _MVTVM_ML_STUBS_H_ + +#include + +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_STUBS_H_ */