From patchwork Thu Mar 16 21:14:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 125200 X-Patchwork-Delegate: thomas@monjalon.net 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 E226741EB5; Thu, 16 Mar 2023 22:14:57 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D209C42DC8; Thu, 16 Mar 2023 22:14:46 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 2B66240DF6 for ; Thu, 16 Mar 2023 22:14:43 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32GKcQta004129; Thu, 16 Mar 2023 14:14:42 -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-type; s=pfpt0220; bh=h1oxW1wtuy9QRFPBYt780XXP3GjU74loPYeGNV8OJ5M=; b=P1Jk2NHtl/19IiCInfCrVGOZxMLJtmZyj4cdyDLuyGLLndAegJmHEl1q34mRpNsrnwUB jNzhqlZAE/6PoptHLf2l2l1zWd709iIAdT3cJA0ahCqarM9k1+VCBwFTcrNsDqcEK1TU WKsyP/kzxVmH0KP+xsTlcpo9IDwWJ/UnqUjkby9lXfy1LYpmSaRX7EgeF6EHZ+Xa+mIP 10ZCo+RB4ZHhUD6WG7+FCxDlS8HxnAQ8frZADJzbjoqRGhgDd0lAMZe+7YEDaQ1p9Msb VdeOFZvyySQeR+UOZ9cge1UdSl7g48tCPmOQlhj99f08En0B5SGV1w610f4rF1uUSxSF cQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3pbxq2ub11-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 16 Mar 2023 14:14:41 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 16 Mar 2023 14:14:39 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 16 Mar 2023 14:14:39 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 854863F707A; Thu, 16 Mar 2023 14:14:39 -0700 (PDT) From: Srikanth Yalavarthi To: Thomas Monjalon , Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v7 01/11] app/mldev: implement test framework for mldev Date: Thu, 16 Mar 2023 14:14:24 -0700 Message-ID: <20230316211434.13409-2-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316211434.13409-1-syalavarthi@marvell.com> References: <20221129070746.20396-1-syalavarthi@marvell.com> <20230316211434.13409-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: gIZu8BlUfIA4F_4e6zZKv3N19Vb6Zd_0 X-Proofpoint-ORIG-GUID: gIZu8BlUfIA4F_4e6zZKv3N19Vb6Zd_0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 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 Implemented framework for mldev test application. New test cases can be added using the framework. Support is also enabled to add options specific to the test cases. User can launch the tests by specifying the name of test as part of launch arguments. Code to parse command line arguments is imported from test-eventdev, with support to parse additional data types. Common arguments supported include: test : name of the test application to run dev_id : device id of the ML device socket_id : socket_id of application resources debug : enable debugging help : print help Sample launch command: ./dpdk-test-mldev -- --test --dev_id \ --socket_id Signed-off-by: Srikanth Yalavarthi Acked-by: Shivah Shankar S Acked-by: Anup Prabhu --- .mailmap | 1 + MAINTAINERS | 2 + app/meson.build | 1 + app/test-mldev/meson.build | 17 ++ app/test-mldev/ml_common.h | 29 ++ app/test-mldev/ml_main.c | 113 ++++++++ app/test-mldev/ml_options.c | 159 +++++++++++ app/test-mldev/ml_options.h | 31 ++ app/test-mldev/ml_test.c | 41 +++ app/test-mldev/ml_test.h | 76 +++++ app/test-mldev/parser.c | 380 +++++++++++++++++++++++++ app/test-mldev/parser.h | 55 ++++ doc/guides/rel_notes/release_23_03.rst | 8 + doc/guides/tools/index.rst | 1 + doc/guides/tools/testmldev.rst | 70 +++++ 15 files changed, 984 insertions(+) create mode 100644 app/test-mldev/meson.build create mode 100644 app/test-mldev/ml_common.h create mode 100644 app/test-mldev/ml_main.c create mode 100644 app/test-mldev/ml_options.c create mode 100644 app/test-mldev/ml_options.h create mode 100644 app/test-mldev/ml_test.c create mode 100644 app/test-mldev/ml_test.h create mode 100644 app/test-mldev/parser.c create mode 100644 app/test-mldev/parser.h create mode 100644 doc/guides/tools/testmldev.rst diff --git a/.mailmap b/.mailmap index 6a56239c3a..0712888c03 100644 --- a/.mailmap +++ b/.mailmap @@ -112,6 +112,7 @@ Anoob Joseph Antara Ganesh Kolar Anthony Fee Antonio Fischetti +Anup Prabhu Anupam Kapoor Apeksha Gupta Archana Muniganti diff --git a/MAINTAINERS b/MAINTAINERS index f70df9f297..df056e2b04 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -480,6 +480,8 @@ Machine Learning device API - EXPERIMENTAL M: Srikanth Yalavarthi F: lib/mldev/ F: doc/guides/prog_guide/mldev.rst +F: app/test-mldev +F: doc/guides/tools/testmldev.rst DMA device API - EXPERIMENTAL M: Chengwen Feng diff --git a/app/meson.build b/app/meson.build index e32ea4bd5c..74d2420f67 100644 --- a/app/meson.build +++ b/app/meson.build @@ -23,6 +23,7 @@ apps = [ 'test-fib', 'test-flow-perf', 'test-gpudev', + 'test-mldev', 'test-pipeline', 'test-pmd', 'test-regex', diff --git a/app/test-mldev/meson.build b/app/test-mldev/meson.build new file mode 100644 index 0000000000..8ca2e1a1c1 --- /dev/null +++ b/app/test-mldev/meson.build @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (c) 2022 Marvell. + +if is_windows + build = false + reason = 'not supported on Windows' + subdir_done() +endif + +sources = files( + 'ml_main.c', + 'ml_options.c', + 'ml_test.c', + 'parser.c', +) + +deps += ['mldev'] diff --git a/app/test-mldev/ml_common.h b/app/test-mldev/ml_common.h new file mode 100644 index 0000000000..065180b619 --- /dev/null +++ b/app/test-mldev/ml_common.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#ifndef _ML_COMMON_ +#define _ML_COMMON_ + +#include + +#define CLNRM "\x1b[0m" +#define CLRED "\x1b[31m" +#define CLGRN "\x1b[32m" +#define CLYEL "\x1b[33m" + +#define ML_STR_FMT 20 + +#define ml_err(fmt, args...) fprintf(stderr, CLRED "error: %s() " fmt CLNRM "\n", __func__, ##args) + +#define ml_info(fmt, args...) fprintf(stdout, CLYEL "" fmt CLNRM "\n", ##args) + +#define ml_dump(str, fmt, val...) printf("\t%-*s : " fmt "\n", ML_STR_FMT, str, ##val) + +#define ml_dump_begin(str) printf("\t%-*s :\n\t{\n", ML_STR_FMT, str) + +#define ml_dump_list(str, id, val) printf("\t%*s[%2u] : %s\n", ML_STR_FMT - 4, str, id, val) + +#define ml_dump_end printf("\b\t}\n\n") + +#endif /* _ML_COMMON_*/ diff --git a/app/test-mldev/ml_main.c b/app/test-mldev/ml_main.c new file mode 100644 index 0000000000..940e609c9a --- /dev/null +++ b/app/test-mldev/ml_main.c @@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include +#include +#include + +#include "ml_common.h" +#include "ml_test.h" + +struct ml_options opt; +struct ml_test *test; + +int +main(int argc, char **argv) +{ + uint16_t mldevs; + int ret; + + ret = rte_eal_init(argc, argv); + if (ret < 0) + rte_panic("invalid EAL arguments\n"); + argc -= ret; + argv += ret; + + mldevs = rte_ml_dev_count(); + if (!mldevs) + rte_panic("no mldev devices found\n"); + + /* set default values for options */ + ml_options_default(&opt); + + /* parse the command line arguments */ + ret = ml_options_parse(&opt, argc, argv); + if (ret) { + ml_err("parsing one or more user options failed"); + goto error; + } + + /* get test struct from name */ + test = ml_test_get(opt.test_name); + if (test == NULL) { + ml_err("failed to find requested test: %s", opt.test_name); + goto error; + } + + if (test->ops.test_result == NULL) { + ml_err("%s: ops.test_result not found", opt.test_name); + goto error; + } + + /* check test options */ + if (test->ops.opt_check) { + if (test->ops.opt_check(&opt)) { + ml_err("invalid command line argument"); + goto error; + } + } + + /* check the device capability */ + if (test->ops.cap_check) { + if (test->ops.cap_check(&opt) == false) { + ml_info("unsupported test: %s", opt.test_name); + ret = ML_TEST_UNSUPPORTED; + goto no_cap; + } + } + + /* dump options */ + if (opt.debug) { + if (test->ops.opt_dump) + test->ops.opt_dump(&opt); + } + + /* test specific setup */ + if (test->ops.test_setup) { + if (test->ops.test_setup(test, &opt)) { + ml_err("failed to setup test: %s", opt.test_name); + goto error; + } + } + + /* test driver */ + if (test->ops.test_driver) + test->ops.test_driver(test, &opt); + + /* get result */ + if (test->ops.test_result) + ret = test->ops.test_result(test, &opt); + + if (test->ops.test_destroy) + test->ops.test_destroy(test, &opt); + +no_cap: + if (ret == ML_TEST_SUCCESS) { + printf("Result: " CLGRN "%s" CLNRM "\n", "Success"); + } else if (ret == ML_TEST_FAILED) { + printf("Result: " CLRED "%s" CLNRM "\n", "Failed"); + return EXIT_FAILURE; + } else if (ret == ML_TEST_UNSUPPORTED) { + printf("Result: " CLYEL "%s" CLNRM "\n", "Unsupported"); + } + + rte_eal_cleanup(); + + return 0; + +error: + rte_eal_cleanup(); + + return EXIT_FAILURE; +} diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c new file mode 100644 index 0000000000..37559614b1 --- /dev/null +++ b/app/test-mldev/ml_options.c @@ -0,0 +1,159 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include +#include + +#include +#include +#include + +#include "ml_common.h" +#include "ml_test.h" +#include "parser.h" + +typedef int (*option_parser_t)(struct ml_options *opt, const char *arg); + +void +ml_options_default(struct ml_options *opt) +{ + memset(opt, 0, sizeof(*opt)); + strlcpy(opt->test_name, "ml_test", ML_TEST_NAME_MAX_LEN); + opt->dev_id = 0; + opt->socket_id = SOCKET_ID_ANY; + opt->debug = false; +} + +struct long_opt_parser { + const char *lgopt_name; + option_parser_t parser_fn; +}; + +static int +ml_parse_test_name(struct ml_options *opt, const char *arg) +{ + strlcpy(opt->test_name, arg, ML_TEST_NAME_MAX_LEN); + return 0; +} + +static int +ml_parse_dev_id(struct ml_options *opt, const char *arg) +{ + int ret; + + ret = parser_read_int16(&opt->dev_id, arg); + + if (ret < 0) + return -EINVAL; + + return ret; +} + +static int +ml_parse_socket_id(struct ml_options *opt, const char *arg) +{ + opt->socket_id = atoi(arg); + + return 0; +} + +static void +ml_dump_test_options(const char *testname) +{ + RTE_SET_USED(testname); +} + +static void +print_usage(char *program) +{ + printf("\nusage : %s [EAL options] -- [application options]\n", program); + printf("application options:\n"); + printf("\t--test : name of the test application to run\n" + "\t--dev_id : device id of the ML device\n" + "\t--socket_id : socket_id of application resources\n" + "\t--debug : enable debug mode\n" + "\t--help : print help\n"); + printf("\n"); + printf("available tests and test specific application options:\n"); + ml_test_dump_names(ml_dump_test_options); +} + +static struct option lgopts[] = { + {ML_TEST, 1, 0, 0}, + {ML_DEVICE_ID, 1, 0, 0}, + {ML_SOCKET_ID, 1, 0, 0}, + {ML_DEBUG, 0, 0, 0}, + {ML_HELP, 0, 0, 0}, + {NULL, 0, 0, 0}}; + +static int +ml_opts_parse_long(int opt_idx, struct ml_options *opt) +{ + unsigned int i; + + struct long_opt_parser parsermap[] = { + {ML_TEST, ml_parse_test_name}, + {ML_DEVICE_ID, ml_parse_dev_id}, + {ML_SOCKET_ID, ml_parse_socket_id}, + }; + + for (i = 0; i < RTE_DIM(parsermap); i++) { + if (strncmp(lgopts[opt_idx].name, parsermap[i].lgopt_name, + strlen(lgopts[opt_idx].name)) == 0) + return parsermap[i].parser_fn(opt, optarg); + } + + return -EINVAL; +} + +int +ml_options_parse(struct ml_options *opt, int argc, char **argv) +{ + int opt_idx; + int retval; + int opts; + + while ((opts = getopt_long(argc, argv, "", lgopts, &opt_idx)) != EOF) { + switch (opts) { + case 0: /* parse long options */ + if (!strcmp(lgopts[opt_idx].name, "debug")) { + opt->debug = true; + break; + } + + if (!strcmp(lgopts[opt_idx].name, "help")) { + print_usage(argv[0]); + exit(EXIT_SUCCESS); + } + + retval = ml_opts_parse_long(opt_idx, opt); + if (retval != 0) + return retval; + break; + default: + return -EINVAL; + } + } + + return 0; +} + +void +ml_options_dump(struct ml_options *opt) +{ + struct rte_ml_dev_info dev_info; + + rte_ml_dev_info_get(opt->dev_id, &dev_info); + + ml_dump("driver", "%s", dev_info.driver_name); + ml_dump("test", "%s", opt->test_name); + ml_dump("dev_id", "%d", opt->dev_id); + + if (opt->socket_id == SOCKET_ID_ANY) + ml_dump("socket_id", "%d (SOCKET_ID_ANY)", opt->socket_id); + else + ml_dump("socket_id", "%d", opt->socket_id); + + ml_dump("debug", "%s", (opt->debug ? "true" : "false")); +} diff --git a/app/test-mldev/ml_options.h b/app/test-mldev/ml_options.h new file mode 100644 index 0000000000..05311a9a47 --- /dev/null +++ b/app/test-mldev/ml_options.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#ifndef _ML_OPTIONS_ +#define _ML_OPTIONS_ + +#include +#include + +#define ML_TEST_NAME_MAX_LEN 32 + +/* Options names */ +#define ML_TEST ("test") +#define ML_DEVICE_ID ("dev_id") +#define ML_SOCKET_ID ("socket_id") +#define ML_DEBUG ("debug") +#define ML_HELP ("help") + +struct ml_options { + char test_name[ML_TEST_NAME_MAX_LEN]; + int16_t dev_id; + int socket_id; + bool debug; +}; + +void ml_options_default(struct ml_options *opt); +int ml_options_parse(struct ml_options *opt, int argc, char **argv); +void ml_options_dump(struct ml_options *opt); + +#endif /* _ML_OPTIONS_ */ diff --git a/app/test-mldev/ml_test.c b/app/test-mldev/ml_test.c new file mode 100644 index 0000000000..dcdeabe0bd --- /dev/null +++ b/app/test-mldev/ml_test.c @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include "ml_test.h" + +static STAILQ_HEAD(, ml_test_entry) head = STAILQ_HEAD_INITIALIZER(head); + +void +ml_test_register(struct ml_test_entry *entry) +{ + STAILQ_INSERT_TAIL(&head, entry, next); +} + +struct ml_test * +ml_test_get(const char *name) +{ + struct ml_test_entry *entry; + + if (!name) + return NULL; + + STAILQ_FOREACH(entry, &head, next) + if (!strncmp(entry->test.name, name, strlen(name))) + return &entry->test; + + return NULL; +} + +void +ml_test_dump_names(void (*f)(const char *name)) +{ + struct ml_test_entry *entry; + + STAILQ_FOREACH(entry, &head, next) + { + if (entry->test.name) + printf("\t %s\n", entry->test.name); + f(entry->test.name); + } +} diff --git a/app/test-mldev/ml_test.h b/app/test-mldev/ml_test.h new file mode 100644 index 0000000000..f7e6bf2f44 --- /dev/null +++ b/app/test-mldev/ml_test.h @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#ifndef _ML_TEST_ +#define _ML_TEST_ + +#include +#include +#include +#include + +#include + +#include "ml_options.h" + +#define ML_TEST_MAX_POOL_SIZE 256 + +enum ml_test_result { + ML_TEST_SUCCESS, + ML_TEST_FAILED, + ML_TEST_UNSUPPORTED, +}; + +struct ml_test; + +typedef bool (*ml_test_capability_check_t)(struct ml_options *opt); +typedef int (*ml_test_options_check_t)(struct ml_options *opt); +typedef void (*ml_test_options_dump_t)(struct ml_options *opt); +typedef int (*ml_test_setup_t)(struct ml_test *test, struct ml_options *opt); +typedef void (*ml_test_destroy_t)(struct ml_test *test, struct ml_options *opt); +typedef int (*ml_test_driver_t)(struct ml_test *test, struct ml_options *opt); +typedef int (*ml_test_result_t)(struct ml_test *test, struct ml_options *opt); + +struct ml_test_ops { + ml_test_capability_check_t cap_check; + ml_test_options_check_t opt_check; + ml_test_options_dump_t opt_dump; + ml_test_setup_t test_setup; + ml_test_destroy_t test_destroy; + ml_test_driver_t test_driver; + ml_test_result_t test_result; +}; + +struct ml_test { + const char *name; + void *test_priv; + struct ml_test_ops ops; +}; + +struct ml_test_entry { + struct ml_test test; + + STAILQ_ENTRY(ml_test_entry) next; +}; + +static inline void * +ml_test_priv(struct ml_test *test) +{ + return test->test_priv; +} + +struct ml_test *ml_test_get(const char *name); +void ml_test_register(struct ml_test_entry *test); +void ml_test_dump_names(void (*f)(const char *)); + +#define ML_TEST_REGISTER(nm) \ + static struct ml_test_entry _ml_test_entry_##nm; \ + RTE_INIT(ml_test_##nm) \ + { \ + _ml_test_entry_##nm.test.name = RTE_STR(nm); \ + memcpy(&_ml_test_entry_##nm.test.ops, &nm, sizeof(struct ml_test_ops)); \ + ml_test_register(&_ml_test_entry_##nm); \ + } + +#endif /* _ML_TEST_ */ diff --git a/app/test-mldev/parser.c b/app/test-mldev/parser.c new file mode 100644 index 0000000000..0b7fb63fe5 --- /dev/null +++ b/app/test-mldev/parser.c @@ -0,0 +1,380 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2016 Intel Corporation. + * Copyright (c) 2017 Cavium, Inc. + * Copyright (c) 2022 Marvell. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "parser.h" + +static uint32_t +get_hex_val(char c) +{ + switch (c) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return c - '0'; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + return c - 'A' + 10; + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + return c - 'a' + 10; + default: + return 0; + } +} + +int +parser_read_arg_bool(const char *p) +{ + p = skip_white_spaces(p); + int result = -EINVAL; + + if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) || + ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) { + p += 3; + result = 1; + } + + if (((p[0] == 'o') && (p[1] == 'n')) || ((p[0] == 'O') && (p[1] == 'N'))) { + p += 2; + result = 1; + } + + if (((p[0] == 'n') && (p[1] == 'o')) || ((p[0] == 'N') && (p[1] == 'O'))) { + p += 2; + result = 0; + } + + if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) || + ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) { + p += 3; + result = 0; + } + + p = skip_white_spaces(p); + + if (p[0] != '\0') + return -EINVAL; + + return result; +} + +int +parser_read_uint64(uint64_t *value, const char *p) +{ + char *next; + uint64_t val; + + p = skip_white_spaces(p); + if (!isdigit(*p)) + return -EINVAL; + + val = strtoul(p, &next, 10); + if (p == next) + return -EINVAL; + + p = next; + switch (*p) { + case 'T': + val *= 1024ULL; + /* fall through */ + case 'G': + val *= 1024ULL; + /* fall through */ + case 'M': + val *= 1024ULL; + /* fall through */ + case 'k': + case 'K': + val *= 1024ULL; + p++; + break; + } + + p = skip_white_spaces(p); + if (*p != '\0') + return -EINVAL; + + *value = val; + return 0; +} + +int +parser_read_int32(int32_t *value, const char *p) +{ + char *next; + int32_t val; + + p = skip_white_spaces(p); + if (!isdigit(*p)) + return -EINVAL; + + val = strtol(p, &next, 10); + if (p == next) + return -EINVAL; + + *value = val; + return 0; +} + +int +parser_read_int16(int16_t *value, const char *p) +{ + char *next; + int16_t val; + + p = skip_white_spaces(p); + if (!isdigit(*p)) + return -EINVAL; + + val = strtol(p, &next, 10); + if (p == next) + return -EINVAL; + + *value = val; + return 0; +} + +int +parser_read_uint64_hex(uint64_t *value, const char *p) +{ + char *next; + uint64_t val; + + p = skip_white_spaces(p); + + val = strtoul(p, &next, 16); + if (p == next) + return -EINVAL; + + p = skip_white_spaces(next); + if (*p != '\0') + return -EINVAL; + + *value = val; + return 0; +} + +int +parser_read_uint32(uint32_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT32_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parser_read_uint32_hex(uint32_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64_hex(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT32_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parser_read_uint16(uint16_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT16_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parser_read_uint16_hex(uint16_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64_hex(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT16_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parser_read_uint8(uint8_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT8_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parser_read_uint8_hex(uint8_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64_hex(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT8_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens) +{ + uint32_t i; + + if ((string == NULL) || (tokens == NULL) || (*n_tokens < 1)) + return -EINVAL; + + for (i = 0; i < *n_tokens; i++) { + tokens[i] = strtok_r(string, PARSE_DELIMITER, &string); + if (tokens[i] == NULL) + break; + } + + if ((i == *n_tokens) && (strtok_r(string, PARSE_DELIMITER, &string) != NULL)) + return -E2BIG; + + *n_tokens = i; + return 0; +} + +int +parse_hex_string(char *src, uint8_t *dst, uint32_t *size) +{ + char *c; + uint32_t len, i; + + /* Check input parameters */ + if ((src == NULL) || (dst == NULL) || (size == NULL) || (*size == 0)) + return -1; + + len = strlen(src); + if (((len & 3) != 0) || (len > (*size) * 2)) + return -1; + *size = len / 2; + + for (c = src; *c != 0; c++) { + if ((((*c) >= '0') && ((*c) <= '9')) || (((*c) >= 'A') && ((*c) <= 'F')) || + (((*c) >= 'a') && ((*c) <= 'f'))) + continue; + + return -1; + } + + /* Convert chars to bytes */ + for (i = 0; i < *size; i++) + dst[i] = get_hex_val(src[2 * i]) * 16 + get_hex_val(src[2 * i + 1]); + + return 0; +} + +int +parse_lcores_list(bool lcores[], int lcores_num, const char *corelist) +{ + int i, idx = 0; + int min, max; + char *end = NULL; + + if (corelist == NULL) + return -1; + while (isblank(*corelist)) + corelist++; + i = strlen(corelist); + while ((i > 0) && isblank(corelist[i - 1])) + i--; + + /* Get list of lcores */ + min = RTE_MAX_LCORE; + do { + while (isblank(*corelist)) + corelist++; + if (*corelist == '\0') + return -1; + idx = strtoul(corelist, &end, 10); + if (idx < 0 || idx > lcores_num) + return -1; + + if (end == NULL) + return -1; + while (isblank(*end)) + end++; + if (*end == '-') { + min = idx; + } else if ((*end == ',') || (*end == '\0')) { + max = idx; + if (min == RTE_MAX_LCORE) + min = idx; + for (idx = min; idx <= max; idx++) { + if (lcores[idx] == 1) + return -E2BIG; + lcores[idx] = 1; + } + + min = RTE_MAX_LCORE; + } else + return -1; + corelist = end + 1; + } while (*end != '\0'); + + return 0; +} diff --git a/app/test-mldev/parser.h b/app/test-mldev/parser.h new file mode 100644 index 0000000000..f0d5e79e4b --- /dev/null +++ b/app/test-mldev/parser.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2010-2016 Intel Corporation. + * Copyright (c) 2022 Marvell. + */ + +#ifndef __INCLUDE_PARSER_H__ +#define __INCLUDE_PARSER_H__ + +#include +#include +#include + +#define PARSE_DELIMITER " \f\n\r\t\v" + +#define skip_white_spaces(pos) \ + ({ \ + __typeof__(pos) _p = (pos); \ + for (; isspace(*_p); _p++) \ + ; \ + _p; \ + }) + +static inline size_t +skip_digits(const char *src) +{ + size_t i; + + for (i = 0; isdigit(src[i]); i++) + ; + + return i; +} + +int parser_read_arg_bool(const char *p); + +int parser_read_uint64(uint64_t *value, const char *p); +int parser_read_uint32(uint32_t *value, const char *p); +int parser_read_uint16(uint16_t *value, const char *p); +int parser_read_uint8(uint8_t *value, const char *p); + +int parser_read_uint64_hex(uint64_t *value, const char *p); +int parser_read_uint32_hex(uint32_t *value, const char *p); +int parser_read_uint16_hex(uint16_t *value, const char *p); +int parser_read_uint8_hex(uint8_t *value, const char *p); + +int parser_read_int32(int32_t *value, const char *p); +int parser_read_int16(int16_t *value, const char *p); + +int parse_hex_string(char *src, uint8_t *dst, uint32_t *size); + +int parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens); + +int parse_lcores_list(bool lcores[], int lcores_num, const char *corelist); + +#endif /* __INCLUDE_PARSER_H__ */ diff --git a/doc/guides/rel_notes/release_23_03.rst b/doc/guides/rel_notes/release_23_03.rst index af6f37389c..072f2c9482 100644 --- a/doc/guides/rel_notes/release_23_03.rst +++ b/doc/guides/rel_notes/release_23_03.rst @@ -226,6 +226,14 @@ New Features * Added support to capture packets at each graph node with packet metadata and node name. +* **Added test application for machine learning inference device library.** + + * Added test application for mldev library with support for multiple test cases. + * Test case for device operations. + * Test case for model operations. + * Inference test case using multiple models in ordered mode. + * Inference test case using multiple models in interleave mode. + Removed Items ------------- diff --git a/doc/guides/tools/index.rst b/doc/guides/tools/index.rst index f1f5b94c8c..6f84fc31ff 100644 --- a/doc/guides/tools/index.rst +++ b/doc/guides/tools/index.rst @@ -21,4 +21,5 @@ DPDK Tools User Guides comp_perf testeventdev testregex + testmldev dts diff --git a/doc/guides/tools/testmldev.rst b/doc/guides/tools/testmldev.rst new file mode 100644 index 0000000000..9dd7606d0b --- /dev/null +++ b/doc/guides/tools/testmldev.rst @@ -0,0 +1,70 @@ +.. SPDX-License-Identifier: BSD-3-Clause + Copyright (c) 2022 Marvell. + +dpdk-test-mldev Application +=========================== + +The ``dpdk-test-mldev`` tool is a Data Plane Development Kit (DPDK) application that allows testing +various mldev use cases. This application has a generic framework to add new mldev based test cases +to verify functionality and measure the performance of inference execution on DPDK ML devices. + + +Application and Options +----------------------- + +The application has a number of command line options: + +.. code-block:: console + + dpdk-test-mldev [EAL Options] -- [application options] + +EAL Options +~~~~~~~~~~~ + +The following are the EAL command-line options that can be used with the ``dpdk-test-mldev`` +application. See the DPDK Getting Started Guides for more information on these options. + +* ``-c `` or ``-l `` + + Set the hexadecimal bitmask of the cores to run on. The corelist is a list of cores to use. + +* ``-a `` + + Attach a PCI based ML device. Specific to drivers using a PCI based ML devices. + +* ``--vdev `` + + Add a virtual mldev device. Specific to drivers using a ML virtual device. + + +Application Options +~~~~~~~~~~~~~~~~~~~ + +The following are the command-line options supported by the test application. + +* ``--test `` + + Name of the test to execute. + +* ``--dev_id `` + + Set the device id of the ML device to be used for the test. Default value is `0`. + +* ``--socket_id `` + + Set the socket id of the application resources. Default value is `SOCKET_ID_ANY`. + +* ``--debug`` + + Enable the tests to run in debug mode. + +* ``--help`` + + Print help message. + + +Debug mode +---------- + +ML tests can be executed in debug mode by enabling the option ``--debug``. Execution of tests in +debug mode would enable additional prints. From patchwork Thu Mar 16 21:14:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 125199 X-Patchwork-Delegate: thomas@monjalon.net 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 E97AF41EB5; Thu, 16 Mar 2023 22:14:50 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A1DD942DBF; Thu, 16 Mar 2023 22:14:45 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 1115A40DDC for ; Thu, 16 Mar 2023 22:14:42 +0100 (CET) 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 32GJMmig016125 for ; Thu, 16 Mar 2023 14:14:42 -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-type; s=pfpt0220; bh=MGUIjQju+m9TCXlv2Cx+EChB+fn87rlC4gNhJXz2fgs=; b=I5mbGFx3WBlLN4A0k8z7JPwpGdfp+wQkvqUcBDDJ1eWpRCrC5VDXX2M0Rrzn8xTWq0YV xOddyRNwYpQeOMOHu5bzyTUY8tsMylUCWDafa5cpTThC65DsDeSAIeL/PqzpQaPSBS7a zUygzC1lLc/3A0qCeI97BThB7mFbd57mNh5HJMFW7MfAdCaXOWzBn/sQ4WvUKzOPKnkw A/bYckBwkjCYN6YIo+uLVgzGrasKiXq0oS+1+KXXlqXVLnoX74RwX1FeB5UzlkElcim2 XqO31i+dAxpAed7rEhXHjzzZTqFjvsBLllpslt02e1ftJ8EkXPHZz66aFLLT7Eyn3OSC og== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3pbs2u3mk5-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 16 Mar 2023 14:14:42 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 16 Mar 2023 14:14:39 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 16 Mar 2023 14:14:39 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id B54D43F707C; Thu, 16 Mar 2023 14:14:39 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v7 02/11] app/mldev: add common test functions Date: Thu, 16 Mar 2023 14:14:25 -0700 Message-ID: <20230316211434.13409-3-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316211434.13409-1-syalavarthi@marvell.com> References: <20221129070746.20396-1-syalavarthi@marvell.com> <20230316211434.13409-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: 1H4EDxMqI7iuEvBjjnwGjssKHT20VB7S X-Proofpoint-ORIG-GUID: 1H4EDxMqI7iuEvBjjnwGjssKHT20VB7S X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 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 common functions used by all tests. Common code includes functions to check capabilities, options, and handle ML devices. Signed-off-by: Srikanth Yalavarthi Acked-by: Anup Prabhu --- app/test-mldev/meson.build | 1 + app/test-mldev/test_common.c | 136 +++++++++++++++++++++++++++++++++++ app/test-mldev/test_common.h | 27 +++++++ 3 files changed, 164 insertions(+) create mode 100644 app/test-mldev/test_common.c create mode 100644 app/test-mldev/test_common.h diff --git a/app/test-mldev/meson.build b/app/test-mldev/meson.build index 8ca2e1a1c1..964bb9ddc4 100644 --- a/app/test-mldev/meson.build +++ b/app/test-mldev/meson.build @@ -12,6 +12,7 @@ sources = files( 'ml_options.c', 'ml_test.c', 'parser.c', + 'test_common.c', ) deps += ['mldev'] diff --git a/app/test-mldev/test_common.c b/app/test-mldev/test_common.c new file mode 100644 index 0000000000..8c4da4609a --- /dev/null +++ b/app/test-mldev/test_common.c @@ -0,0 +1,136 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include + +#include +#include +#include + +#include "ml_common.h" +#include "test_common.h" + +bool +ml_test_cap_check(struct ml_options *opt) +{ + struct rte_ml_dev_info dev_info; + + rte_ml_dev_info_get(opt->dev_id, &dev_info); + if (dev_info.max_models == 0) { + ml_err("Not enough mldev models supported = %u", dev_info.max_models); + return false; + } + + return true; +} + +int +ml_test_opt_check(struct ml_options *opt) +{ + uint16_t dev_count; + int socket_id; + + RTE_SET_USED(opt); + + dev_count = rte_ml_dev_count(); + if (dev_count == 0) { + ml_err("No ML devices found"); + return -ENODEV; + } + + if (opt->dev_id >= dev_count) { + ml_err("Invalid option dev_id = %d", opt->dev_id); + return -EINVAL; + } + + socket_id = rte_ml_dev_socket_id(opt->dev_id); + if (!((opt->socket_id != SOCKET_ID_ANY) || (opt->socket_id != socket_id))) { + ml_err("Invalid option, socket_id = %d\n", opt->socket_id); + return -EINVAL; + } + + return 0; +} + +void +ml_test_opt_dump(struct ml_options *opt) +{ + ml_options_dump(opt); +} + +int +ml_test_device_configure(struct ml_test *test, struct ml_options *opt) +{ + struct test_common *t = ml_test_priv(test); + struct rte_ml_dev_config dev_config; + int ret; + + ret = rte_ml_dev_info_get(opt->dev_id, &t->dev_info); + if (ret != 0) { + ml_err("Failed to get mldev info, dev_id = %d\n", opt->dev_id); + return ret; + } + + /* configure device */ + dev_config.socket_id = opt->socket_id; + dev_config.nb_models = t->dev_info.max_models; + dev_config.nb_queue_pairs = t->dev_info.max_queue_pairs; + ret = rte_ml_dev_configure(opt->dev_id, &dev_config); + if (ret != 0) { + ml_err("Failed to configure ml device, dev_id = %d\n", opt->dev_id); + return ret; + } + + return 0; +} + +int +ml_test_device_close(struct ml_test *test, struct ml_options *opt) +{ + struct test_common *t = ml_test_priv(test); + int ret = 0; + + RTE_SET_USED(t); + + /* close device */ + ret = rte_ml_dev_close(opt->dev_id); + if (ret != 0) + ml_err("Failed to close ML device, dev_id = %d\n", opt->dev_id); + + return ret; +} + +int +ml_test_device_start(struct ml_test *test, struct ml_options *opt) +{ + struct test_common *t = ml_test_priv(test); + int ret; + + RTE_SET_USED(t); + + /* start device */ + ret = rte_ml_dev_start(opt->dev_id); + if (ret != 0) { + ml_err("Failed to start ml device, dev_id = %d\n", opt->dev_id); + return ret; + } + + return 0; +} + +int +ml_test_device_stop(struct ml_test *test, struct ml_options *opt) +{ + struct test_common *t = ml_test_priv(test); + int ret = 0; + + RTE_SET_USED(t); + + /* stop device */ + ret = rte_ml_dev_stop(opt->dev_id); + if (ret != 0) + ml_err("Failed to stop ML device, dev_id = %d\n", opt->dev_id); + + return ret; +} diff --git a/app/test-mldev/test_common.h b/app/test-mldev/test_common.h new file mode 100644 index 0000000000..cb286adcd6 --- /dev/null +++ b/app/test-mldev/test_common.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#ifndef _ML_TEST_COMMON_ +#define _ML_TEST_COMMON_ + +#include + +#include "ml_common.h" +#include "ml_test.h" + +struct test_common { + struct ml_options *opt; + enum ml_test_result result; + struct rte_ml_dev_info dev_info; +}; + +bool ml_test_cap_check(struct ml_options *opt); +int ml_test_opt_check(struct ml_options *opt); +void ml_test_opt_dump(struct ml_options *opt); +int ml_test_device_configure(struct ml_test *test, struct ml_options *opt); +int ml_test_device_close(struct ml_test *test, struct ml_options *opt); +int ml_test_device_start(struct ml_test *test, struct ml_options *opt); +int ml_test_device_stop(struct ml_test *test, struct ml_options *opt); + +#endif /* _ML_TEST_COMMON_ */ From patchwork Thu Mar 16 21:14:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 125201 X-Patchwork-Delegate: thomas@monjalon.net 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 5826441EB5; Thu, 16 Mar 2023 22:15:06 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 04D3742F86; Thu, 16 Mar 2023 22:14:48 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 8F73340DDC for ; Thu, 16 Mar 2023 22:14:43 +0100 (CET) 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 32GJMmih016125 for ; Thu, 16 Mar 2023 14:14:43 -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-type; s=pfpt0220; bh=GItS5lLvmKyezheQ9jRBLPR3pB37shjob88ThCLnkyA=; b=Mp5qrEKfCyCN3CELkJVFCImCnh+CHMctX4wgjcH3y75Sf6KWhqMxYX3EW888WnE0bhzf 8u0YgQyw3QmLztFWunq2vPKZa8hFwuXHzqCZN91kWjm1bOzbasR6UJGgXbnTiBcpjDl9 zXPy7cP6YzASBiqf/CVLffhfdnYw4zF01wkv5sc1X0OXQImNw2SXsrwTX56v00NKM/x4 O5UhRTyZITwV3pGPwfqcUZR7UZLsx7yLbp0uTToU866kCJz3Bpp73C+HWbUdPJKxAG8/ 5wmbBxphu2e1PB5uIYsn1XSqyVle17RbXHwO+jkrvzKM0iCA0oEB4S+U7j+I2QiIMq5f VQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3pbs2u3mk5-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 16 Mar 2023 14:14:42 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 16 Mar 2023 14:14:40 -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.42 via Frontend Transport; Thu, 16 Mar 2023 14:14:39 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id E18E93F707D; Thu, 16 Mar 2023 14:14:39 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v7 03/11] app/mldev: add test case to validate device ops Date: Thu, 16 Mar 2023 14:14:26 -0700 Message-ID: <20230316211434.13409-4-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316211434.13409-1-syalavarthi@marvell.com> References: <20221129070746.20396-1-syalavarthi@marvell.com> <20230316211434.13409-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: 9QTXDmYnk59MYSjTZVjiH2hY_DJTrxC- X-Proofpoint-ORIG-GUID: 9QTXDmYnk59MYSjTZVjiH2hY_DJTrxC- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 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 test case to validate device handling operations. Device ops test is a collection of multiple sub-tests. Enabled sub-test to validate device reconfiguration. Set device_ops as the default test. Signed-off-by: Srikanth Yalavarthi Acked-by: Anup Prabhu --- app/test-mldev/meson.build | 1 + app/test-mldev/ml_options.c | 5 +- app/test-mldev/ml_options.h | 2 + app/test-mldev/test_device_ops.c | 228 +++++++++++++++++++++++++++++++ app/test-mldev/test_device_ops.h | 17 +++ doc/guides/tools/testmldev.rst | 42 +++++- 6 files changed, 292 insertions(+), 3 deletions(-) create mode 100644 app/test-mldev/test_device_ops.c create mode 100644 app/test-mldev/test_device_ops.h diff --git a/app/test-mldev/meson.build b/app/test-mldev/meson.build index 964bb9ddc4..60ea23d142 100644 --- a/app/test-mldev/meson.build +++ b/app/test-mldev/meson.build @@ -13,6 +13,7 @@ sources = files( 'ml_test.c', 'parser.c', 'test_common.c', + 'test_device_ops.c', ) deps += ['mldev'] diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index 37559614b1..854d316521 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -19,7 +19,7 @@ void ml_options_default(struct ml_options *opt) { memset(opt, 0, sizeof(*opt)); - strlcpy(opt->test_name, "ml_test", ML_TEST_NAME_MAX_LEN); + strlcpy(opt->test_name, "device_ops", ML_TEST_NAME_MAX_LEN); opt->dev_id = 0; opt->socket_id = SOCKET_ID_ANY; opt->debug = false; @@ -61,7 +61,8 @@ ml_parse_socket_id(struct ml_options *opt, const char *arg) static void ml_dump_test_options(const char *testname) { - RTE_SET_USED(testname); + if (strcmp(testname, "device_ops") == 0) + printf("\n"); } static void diff --git a/app/test-mldev/ml_options.h b/app/test-mldev/ml_options.h index 05311a9a47..6899cc2f88 100644 --- a/app/test-mldev/ml_options.h +++ b/app/test-mldev/ml_options.h @@ -9,6 +9,7 @@ #include #define ML_TEST_NAME_MAX_LEN 32 +#define ML_TEST_MAX_MODELS 8 /* Options names */ #define ML_TEST ("test") @@ -21,6 +22,7 @@ struct ml_options { char test_name[ML_TEST_NAME_MAX_LEN]; int16_t dev_id; int socket_id; + uint8_t nb_filelist; bool debug; }; diff --git a/app/test-mldev/test_device_ops.c b/app/test-mldev/test_device_ops.c new file mode 100644 index 0000000000..be0c5f0780 --- /dev/null +++ b/app/test-mldev/test_device_ops.c @@ -0,0 +1,228 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include + +#include +#include +#include + +#include "test_device_ops.h" + +static bool +test_device_cap_check(struct ml_options *opt) +{ + if (!ml_test_cap_check(opt)) + return false; + + return true; +} + +static int +test_device_opt_check(struct ml_options *opt) +{ + int ret; + + /* check common opts */ + ret = ml_test_opt_check(opt); + if (ret != 0) + return ret; + + return 0; +} + +static void +test_device_opt_dump(struct ml_options *opt) +{ + /* dump common opts */ + ml_test_opt_dump(opt); +} + +static int +test_device_setup(struct ml_test *test, struct ml_options *opt) +{ + struct test_device *t; + void *test_device; + int ret = 0; + + /* allocate for test structure */ + test_device = rte_zmalloc_socket(test->name, sizeof(struct test_device), + RTE_CACHE_LINE_SIZE, opt->socket_id); + if (test_device == NULL) { + ml_err("failed to allocate memory for test_model"); + ret = -ENOMEM; + goto error; + } + test->test_priv = test_device; + t = ml_test_priv(test); + + t->cmn.result = ML_TEST_FAILED; + t->cmn.opt = opt; + + /* get device info */ + ret = rte_ml_dev_info_get(opt->dev_id, &t->cmn.dev_info); + if (ret < 0) { + ml_err("failed to get device info"); + goto error; + } + + return 0; + +error: + if (test_device != NULL) + rte_free(test_device); + + return ret; +} + +static void +test_device_destroy(struct ml_test *test, struct ml_options *opt) +{ + struct test_device *t; + + RTE_SET_USED(opt); + + t = ml_test_priv(test); + if (t != NULL) + rte_free(t); +} + +static int +test_device_reconfigure(struct ml_test *test, struct ml_options *opt) +{ + struct rte_ml_dev_config dev_config; + struct rte_ml_dev_qp_conf qp_conf; + struct test_device *t; + uint16_t qp_id = 0; + int ret = 0; + + t = ml_test_priv(test); + + /* configure with default options */ + ret = ml_test_device_configure(test, opt); + if (ret != 0) + return ret; + + /* setup one queue pair with nb_desc = 1 */ + qp_conf.nb_desc = 1; + qp_conf.cb = NULL; + + ret = rte_ml_dev_queue_pair_setup(opt->dev_id, qp_id, &qp_conf, opt->socket_id); + if (ret != 0) { + ml_err("Failed to setup ML device queue-pair, dev_id = %d, qp_id = %u\n", + opt->dev_id, qp_id); + goto error; + } + + /* start device */ + ret = ml_test_device_start(test, opt); + if (ret != 0) + goto error; + + /* stop device */ + ret = ml_test_device_stop(test, opt); + if (ret != 0) { + ml_err("Failed to stop device"); + goto error; + } + + /* reconfigure device based on dev_info */ + dev_config.socket_id = opt->socket_id; + dev_config.nb_models = t->cmn.dev_info.max_models; + dev_config.nb_queue_pairs = t->cmn.dev_info.max_queue_pairs; + ret = rte_ml_dev_configure(opt->dev_id, &dev_config); + if (ret != 0) { + ml_err("Failed to reconfigure ML device, dev_id = %d\n", opt->dev_id); + return ret; + } + + /* setup queue pairs */ + for (qp_id = 0; qp_id < t->cmn.dev_info.max_queue_pairs; qp_id++) { + qp_conf.nb_desc = t->cmn.dev_info.max_desc; + qp_conf.cb = NULL; + + ret = rte_ml_dev_queue_pair_setup(opt->dev_id, qp_id, &qp_conf, opt->socket_id); + if (ret != 0) { + ml_err("Failed to setup ML device queue-pair, dev_id = %d, qp_id = %u\n", + opt->dev_id, qp_id); + goto error; + } + } + + /* start device */ + ret = ml_test_device_start(test, opt); + if (ret != 0) + goto error; + + /* stop device */ + ret = ml_test_device_stop(test, opt); + if (ret != 0) + goto error; + + /* close device */ + ret = ml_test_device_close(test, opt); + if (ret != 0) + return ret; + + return 0; + +error: + ml_test_device_close(test, opt); + + return ret; +} + +static int +test_device_driver(struct ml_test *test, struct ml_options *opt) +{ + struct test_device *t; + int ret = 0; + + t = ml_test_priv(test); + + /* sub-test: device reconfigure */ + ret = test_device_reconfigure(test, opt); + if (ret != 0) { + printf("\n"); + printf("Model Device Reconfigure Test: " CLRED "%s" CLNRM "\n", "Failed"); + goto error; + } else { + printf("\n"); + printf("Model Device Reconfigure Test: " CLYEL "%s" CLNRM "\n", "Passed"); + } + + printf("\n"); + + t->cmn.result = ML_TEST_SUCCESS; + + return 0; + +error: + t->cmn.result = ML_TEST_FAILED; + return -1; +} + +static int +test_device_result(struct ml_test *test, struct ml_options *opt) +{ + struct test_device *t; + + RTE_SET_USED(opt); + + t = ml_test_priv(test); + + return t->cmn.result; +} + +static const struct ml_test_ops device_ops = { + .cap_check = test_device_cap_check, + .opt_check = test_device_opt_check, + .opt_dump = test_device_opt_dump, + .test_setup = test_device_setup, + .test_destroy = test_device_destroy, + .test_driver = test_device_driver, + .test_result = test_device_result, +}; + +ML_TEST_REGISTER(device_ops); diff --git a/app/test-mldev/test_device_ops.h b/app/test-mldev/test_device_ops.h new file mode 100644 index 0000000000..115b1072a2 --- /dev/null +++ b/app/test-mldev/test_device_ops.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#ifndef _ML_TEST_DEVICE_OPS_ +#define _ML_TEST_DEVICE_OPS_ + +#include + +#include "test_common.h" + +struct test_device { + /* common data */ + struct test_common cmn; +} __rte_cache_aligned; + +#endif /* _ML_TEST_DEVICE_OPS_ */ diff --git a/doc/guides/tools/testmldev.rst b/doc/guides/tools/testmldev.rst index 9dd7606d0b..1771c49fb4 100644 --- a/doc/guides/tools/testmldev.rst +++ b/doc/guides/tools/testmldev.rst @@ -44,7 +44,12 @@ The following are the command-line options supported by the test application. * ``--test `` - Name of the test to execute. + Name of the test to execute. ML tests supported include device tests. Test name should be + one of the following supported tests. + + **ML Device Tests** :: + + device_ops * ``--dev_id `` @@ -63,6 +68,41 @@ The following are the command-line options supported by the test application. Print help message. +ML Device Tests +------------------------- + +ML device tests are functional tests to validate ML device APIs. Device tests validate the ML device +handling APIs configure, close, start and stop APIs. + + +Application Options +~~~~~~~~~~~~~~~~~~~ + +Supported command line options for the `device_ops` test are following:: + + --debug + --test + --dev_id + --socket_id + + +DEVICE_OPS Test +~~~~~~~~~~~~~~~ + +Device ops test validates the device configuration and reconfiguration. + + +Example +^^^^^^^ + +Command to run device_ops test: + +.. code-block:: console + + sudo /app/dpdk-test-mldev -c 0xf -a -- \ + --test=device_ops + + Debug mode ---------- From patchwork Thu Mar 16 21:14: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: 125203 X-Patchwork-Delegate: thomas@monjalon.net 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 E0DFA41EB5; Thu, 16 Mar 2023 22:15:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8DDB042FA2; Thu, 16 Mar 2023 22:14:50 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id BB58B40DF6 for ; Thu, 16 Mar 2023 22:14:43 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32GKcQtb004129 for ; Thu, 16 Mar 2023 14:14:43 -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-type; s=pfpt0220; bh=Ncym7/ylaNb6HPNHhufsRMQH1wpL8nJHtncntrlREnU=; b=Hgeif2L5ByBKxY3MHGFUCkl/dpn7KCgq3wcA0fqpG/JwiUtSO3yjRIQhTGEDsHkkD3gB 9ZTJaqYwTkKEFvVywT25oMf1L0XcMI2IrleuyQBigSpPKZY3Xp7Z0UVQTk2J21VT7tGJ FJ8GR75VMjR3J9knkfK4ZXyqx9qr+Gjjl3rk3BU3jRtqbVkLOorUCE0w3QcBxyGzPzKH kckfUFVBhPZWcr6Xe9SkNrDsTyzc6zpWtIlHnMzqSkohEOrGbyX9Fh/nKWCQt6rZYoZ4 iALUZNIRfCMEw//Tb2rCn/YHePX+7IJ60CXsAJjN80G7fnARdL5AMc0C+/rPToNhMbrq 8g== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3pbxq2ub11-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 16 Mar 2023 14:14:42 -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.42; Thu, 16 Mar 2023 14:14:40 -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.42 via Frontend Transport; Thu, 16 Mar 2023 14:14:40 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 21F313F7081; Thu, 16 Mar 2023 14:14:40 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v7 04/11] app/mldev: add test case to validate model ops Date: Thu, 16 Mar 2023 14:14:27 -0700 Message-ID: <20230316211434.13409-5-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316211434.13409-1-syalavarthi@marvell.com> References: <20221129070746.20396-1-syalavarthi@marvell.com> <20230316211434.13409-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: qUY-7EUybbYRJWsdKNYkuXCPKJ3s8amz X-Proofpoint-ORIG-GUID: qUY-7EUybbYRJWsdKNYkuXCPKJ3s8amz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 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 test case to validate model operations. Model ops test is a collection of sub-tests. Each sub-test invokes the model operations in a specific order. Sub-test A: (load -> start -> stop -> unload) x n Sub-test B: load x n -> start x n -> stop x n -> unload x n Sub-test C: load x n + (start + stop) x n + unload x n Sub-test D: (load + start) x n -> (stop + unload) x n Added internal functions to handle model load, start, stop and unload. List of models to be used for testing can be specified through application argument "--models" Signed-off-by: Srikanth Yalavarthi Acked-by: Anup Prabhu --- app/test-mldev/meson.build | 2 + app/test-mldev/ml_options.c | 39 ++ app/test-mldev/ml_options.h | 6 + app/test-mldev/test_model_common.c | 158 +++++++ app/test-mldev/test_model_common.h | 34 ++ app/test-mldev/test_model_ops.c | 428 ++++++++++++++++++ app/test-mldev/test_model_ops.h | 20 + .../tools/img/mldev_model_ops_subtest_a.svg | 420 +++++++++++++++++ .../tools/img/mldev_model_ops_subtest_b.svg | 423 +++++++++++++++++ .../tools/img/mldev_model_ops_subtest_c.svg | 366 +++++++++++++++ .../tools/img/mldev_model_ops_subtest_d.svg | 424 +++++++++++++++++ doc/guides/tools/testmldev.rst | 97 +++- 12 files changed, 2415 insertions(+), 2 deletions(-) create mode 100644 app/test-mldev/test_model_common.c create mode 100644 app/test-mldev/test_model_common.h create mode 100644 app/test-mldev/test_model_ops.c create mode 100644 app/test-mldev/test_model_ops.h create mode 100644 doc/guides/tools/img/mldev_model_ops_subtest_a.svg create mode 100644 doc/guides/tools/img/mldev_model_ops_subtest_b.svg create mode 100644 doc/guides/tools/img/mldev_model_ops_subtest_c.svg create mode 100644 doc/guides/tools/img/mldev_model_ops_subtest_d.svg diff --git a/app/test-mldev/meson.build b/app/test-mldev/meson.build index 60ea23d142..b09e1ccc8a 100644 --- a/app/test-mldev/meson.build +++ b/app/test-mldev/meson.build @@ -14,6 +14,8 @@ sources = files( 'parser.c', 'test_common.c', 'test_device_ops.c', + 'test_model_common.c', + 'test_model_ops.c', ) deps += ['mldev'] diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index 854d316521..8ffbab7f75 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -22,6 +22,7 @@ ml_options_default(struct ml_options *opt) strlcpy(opt->test_name, "device_ops", ML_TEST_NAME_MAX_LEN); opt->dev_id = 0; opt->socket_id = SOCKET_ID_ANY; + opt->nb_filelist = 0; opt->debug = false; } @@ -58,11 +59,47 @@ ml_parse_socket_id(struct ml_options *opt, const char *arg) return 0; } +static int +ml_parse_models(struct ml_options *opt, const char *arg) +{ + const char *delim = ","; + char models[PATH_MAX]; + char *token; + int ret = 0; + + strlcpy(models, arg, PATH_MAX); + + token = strtok(models, delim); + while (token != NULL) { + strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX); + opt->nb_filelist++; + + if (opt->nb_filelist >= ML_TEST_MAX_MODELS) { + ml_err("Exceeded model count, max = %d\n", ML_TEST_MAX_MODELS); + ret = -EINVAL; + break; + } + token = strtok(NULL, delim); + } + + if (opt->nb_filelist == 0) { + ml_err("Models list is empty. Need at least one model for the test"); + ret = -EINVAL; + } + + return ret; +} + static void ml_dump_test_options(const char *testname) { if (strcmp(testname, "device_ops") == 0) printf("\n"); + + if (strcmp(testname, "model_ops") == 0) { + printf("\t\t--models : comma separated list of models\n"); + printf("\n"); + } } static void @@ -84,6 +121,7 @@ static struct option lgopts[] = { {ML_TEST, 1, 0, 0}, {ML_DEVICE_ID, 1, 0, 0}, {ML_SOCKET_ID, 1, 0, 0}, + {ML_MODELS, 1, 0, 0}, {ML_DEBUG, 0, 0, 0}, {ML_HELP, 0, 0, 0}, {NULL, 0, 0, 0}}; @@ -97,6 +135,7 @@ ml_opts_parse_long(int opt_idx, struct ml_options *opt) {ML_TEST, ml_parse_test_name}, {ML_DEVICE_ID, ml_parse_dev_id}, {ML_SOCKET_ID, ml_parse_socket_id}, + {ML_MODELS, ml_parse_models}, }; for (i = 0; i < RTE_DIM(parsermap); i++) { diff --git a/app/test-mldev/ml_options.h b/app/test-mldev/ml_options.h index 6899cc2f88..61e938d2e2 100644 --- a/app/test-mldev/ml_options.h +++ b/app/test-mldev/ml_options.h @@ -15,13 +15,19 @@ #define ML_TEST ("test") #define ML_DEVICE_ID ("dev_id") #define ML_SOCKET_ID ("socket_id") +#define ML_MODELS ("models") #define ML_DEBUG ("debug") #define ML_HELP ("help") +struct ml_filelist { + char model[PATH_MAX]; +}; + struct ml_options { char test_name[ML_TEST_NAME_MAX_LEN]; int16_t dev_id; int socket_id; + struct ml_filelist filelist[ML_TEST_MAX_MODELS]; uint8_t nb_filelist; bool debug; }; diff --git a/app/test-mldev/test_model_common.c b/app/test-mldev/test_model_common.c new file mode 100644 index 0000000000..b94d46154d --- /dev/null +++ b/app/test-mldev/test_model_common.c @@ -0,0 +1,158 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include + +#include +#include +#include + +#include "ml_common.h" +#include "test_model_common.h" + +int +ml_model_load(struct ml_test *test, struct ml_options *opt, struct ml_model *model, uint16_t fid) +{ + struct test_common *t = ml_test_priv(test); + struct rte_ml_model_params model_params; + FILE *fp; + int ret; + + if (model->state == MODEL_LOADED) + return 0; + + if (model->state != MODEL_INITIAL) + return -EINVAL; + + /* read model binary */ + fp = fopen(opt->filelist[fid].model, "r"); + if (fp == NULL) { + ml_err("Failed to open model file : %s\n", opt->filelist[fid].model); + return -1; + } + + fseek(fp, 0, SEEK_END); + model_params.size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + model_params.addr = rte_malloc_socket("ml_model", model_params.size, + t->dev_info.min_align_size, opt->socket_id); + if (model_params.addr == NULL) { + ml_err("Failed to allocate memory for model: %s\n", opt->filelist[fid].model); + fclose(fp); + return -ENOMEM; + } + + if (fread(model_params.addr, 1, model_params.size, fp) != model_params.size) { + ml_err("Failed to read model file : %s\n", opt->filelist[fid].model); + rte_free(model_params.addr); + fclose(fp); + return -1; + } + fclose(fp); + + /* load model to device */ + ret = rte_ml_model_load(opt->dev_id, &model_params, &model->id); + if (ret != 0) { + ml_err("Failed to load model : %s\n", opt->filelist[fid].model); + model->state = MODEL_ERROR; + rte_free(model_params.addr); + return ret; + } + + /* release mz */ + rte_free(model_params.addr); + + /* get model info */ + ret = rte_ml_model_info_get(opt->dev_id, model->id, &model->info); + if (ret != 0) { + ml_err("Failed to get model info : %s\n", opt->filelist[fid].model); + return ret; + } + + model->state = MODEL_LOADED; + + return 0; +} + +int +ml_model_unload(struct ml_test *test, struct ml_options *opt, struct ml_model *model, uint16_t fid) +{ + struct test_common *t = ml_test_priv(test); + int ret; + + RTE_SET_USED(t); + + if (model->state == MODEL_INITIAL) + return 0; + + if (model->state != MODEL_LOADED) + return -EINVAL; + + /* unload model */ + ret = rte_ml_model_unload(opt->dev_id, model->id); + if (ret != 0) { + ml_err("Failed to unload model: %s\n", opt->filelist[fid].model); + model->state = MODEL_ERROR; + return ret; + } + + model->state = MODEL_INITIAL; + + return 0; +} + +int +ml_model_start(struct ml_test *test, struct ml_options *opt, struct ml_model *model, uint16_t fid) +{ + struct test_common *t = ml_test_priv(test); + int ret; + + RTE_SET_USED(t); + + if (model->state == MODEL_STARTED) + return 0; + + if (model->state != MODEL_LOADED) + return -EINVAL; + + /* start model */ + ret = rte_ml_model_start(opt->dev_id, model->id); + if (ret != 0) { + ml_err("Failed to start model : %s\n", opt->filelist[fid].model); + model->state = MODEL_ERROR; + return ret; + } + + model->state = MODEL_STARTED; + + return 0; +} + +int +ml_model_stop(struct ml_test *test, struct ml_options *opt, struct ml_model *model, uint16_t fid) +{ + struct test_common *t = ml_test_priv(test); + int ret; + + RTE_SET_USED(t); + + if (model->state == MODEL_LOADED) + return 0; + + if (model->state != MODEL_STARTED) + return -EINVAL; + + /* stop model */ + ret = rte_ml_model_stop(opt->dev_id, model->id); + if (ret != 0) { + ml_err("Failed to stop model: %s\n", opt->filelist[fid].model); + model->state = MODEL_ERROR; + return ret; + } + + model->state = MODEL_LOADED; + + return 0; +} diff --git a/app/test-mldev/test_model_common.h b/app/test-mldev/test_model_common.h new file mode 100644 index 0000000000..74aec0a797 --- /dev/null +++ b/app/test-mldev/test_model_common.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#ifndef _ML_TEST_MODEL_COMMON_ +#define _ML_TEST_MODEL_COMMON_ + +#include + +#include "test_common.h" + +enum model_state { + MODEL_INITIAL, + MODEL_LOADED, + MODEL_STARTED, + MODEL_ERROR, +}; + +struct ml_model { + uint16_t id; + struct rte_ml_model_info info; + enum model_state state; +}; + +int ml_model_load(struct ml_test *test, struct ml_options *opt, struct ml_model *model, + uint16_t fid); +int ml_model_unload(struct ml_test *test, struct ml_options *opt, struct ml_model *model, + uint16_t fid); +int ml_model_start(struct ml_test *test, struct ml_options *opt, struct ml_model *model, + uint16_t fid); +int ml_model_stop(struct ml_test *test, struct ml_options *opt, struct ml_model *model, + uint16_t fid); + +#endif /* _ML_TEST_MODEL_COMMON_ */ diff --git a/app/test-mldev/test_model_ops.c b/app/test-mldev/test_model_ops.c new file mode 100644 index 0000000000..0202b31190 --- /dev/null +++ b/app/test-mldev/test_model_ops.c @@ -0,0 +1,428 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include + +#include +#include +#include + +#include "test_model_ops.h" + +static bool +test_model_ops_cap_check(struct ml_options *opt) +{ + if (!ml_test_cap_check(opt)) + return false; + + return true; +} + +static int +test_model_ops_opt_check(struct ml_options *opt) +{ + uint32_t i; + int ret; + + /* check common opts */ + ret = ml_test_opt_check(opt); + if (ret != 0) + return ret; + + /* check model file availability */ + for (i = 0; i < opt->nb_filelist; i++) { + if (access(opt->filelist[i].model, F_OK) == -1) { + ml_err("Model file not available: id = %u, file = %s", i, + opt->filelist[i].model); + return -ENOENT; + } + } + + return 0; +} + +static void +test_model_ops_opt_dump(struct ml_options *opt) +{ + uint32_t i; + + /* dump common opts */ + ml_test_opt_dump(opt); + + /* dump test specific opts */ + ml_dump_begin("models"); + for (i = 0; i < opt->nb_filelist; i++) + ml_dump_list("model", i, opt->filelist[i].model); + ml_dump_end; +} + +static int +test_model_ops_setup(struct ml_test *test, struct ml_options *opt) +{ + struct test_model_ops *t; + void *test_model_ops; + int ret = 0; + uint32_t i; + + /* allocate model ops test structure */ + test_model_ops = rte_zmalloc_socket(test->name, sizeof(struct test_model_ops), + RTE_CACHE_LINE_SIZE, opt->socket_id); + if (test_model_ops == NULL) { + ml_err("Failed to allocate memory for test_model"); + ret = -ENOMEM; + goto error; + } + test->test_priv = test_model_ops; + t = ml_test_priv(test); + + t->cmn.result = ML_TEST_FAILED; + t->cmn.opt = opt; + + /* get device info */ + ret = rte_ml_dev_info_get(opt->dev_id, &t->cmn.dev_info); + if (ret < 0) { + ml_err("Failed to get device info"); + goto error; + } + + /* set model initial state */ + for (i = 0; i < opt->nb_filelist; i++) + t->model[i].state = MODEL_INITIAL; + + return 0; + +error: + if (test_model_ops != NULL) + rte_free(test_model_ops); + + return ret; +} + +static void +test_model_ops_destroy(struct ml_test *test, struct ml_options *opt) +{ + struct test_model_ops *t; + + RTE_SET_USED(opt); + + t = ml_test_priv(test); + if (t != NULL) + rte_free(t); +} + +static int +test_model_ops_mldev_setup(struct ml_test *test, struct ml_options *opt) +{ + int ret; + + ret = ml_test_device_configure(test, opt); + if (ret != 0) + return ret; + + ret = ml_test_device_start(test, opt); + if (ret != 0) + goto error; + + return 0; + +error: + ml_test_device_close(test, opt); + + return ret; +} + +static int +test_model_ops_mldev_destroy(struct ml_test *test, struct ml_options *opt) +{ + int ret; + + ret = ml_test_device_stop(test, opt); + if (ret != 0) + goto error; + + ret = ml_test_device_close(test, opt); + if (ret != 0) + return ret; + + return 0; + +error: + ml_test_device_close(test, opt); + + return ret; +} + +/* Sub-test A: (load -> start -> stop -> unload) x n */ +static int +test_model_ops_subtest_a(struct ml_test *test, struct ml_options *opt) +{ + struct test_model_ops *t; + int ret = 0; + uint32_t i; + + t = ml_test_priv(test); + + /* load + start + stop + unload */ + for (i = 0; i < opt->nb_filelist; i++) { + ret = ml_model_load(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + + ret = ml_model_start(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + + ret = ml_model_stop(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + + ret = ml_model_unload(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + } + +error: + for (i = 0; i < opt->nb_filelist; i++) + ml_model_stop(test, opt, &t->model[i], i); + + for (i = 0; i < opt->nb_filelist; i++) + ml_model_unload(test, opt, &t->model[i], i); + + return ret; +} + +/* Sub-test B: load x n -> start x n -> stop x n -> unload x n */ +static int +test_model_ops_subtest_b(struct ml_test *test, struct ml_options *opt) +{ + struct test_model_ops *t; + int ret = 0; + uint32_t i; + + t = ml_test_priv(test); + + /* load */ + for (i = 0; i < opt->nb_filelist; i++) { + ret = ml_model_load(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + } + + /* start */ + for (i = 0; i < opt->nb_filelist; i++) { + ret = ml_model_start(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + } + + /* stop */ + for (i = 0; i < opt->nb_filelist; i++) { + ret = ml_model_stop(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + } + + /* unload */ + for (i = 0; i < opt->nb_filelist; i++) { + ret = ml_model_unload(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + } + + return 0; + +error: + for (i = 0; i < opt->nb_filelist; i++) + ml_model_stop(test, opt, &t->model[i], i); + + for (i = 0; i < opt->nb_filelist; i++) + ml_model_unload(test, opt, &t->model[i], i); + + return ret; +} + +/* Sub-test C: load x n + (start + stop) x n + unload x n */ +static int +test_model_ops_subtest_c(struct ml_test *test, struct ml_options *opt) +{ + struct test_model_ops *t; + int ret = 0; + uint32_t i; + + t = ml_test_priv(test); + + /* load */ + for (i = 0; i < opt->nb_filelist; i++) { + ret = ml_model_load(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + } + + /* start + stop */ + for (i = 0; i < opt->nb_filelist; i++) { + ret = ml_model_start(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + + ret = ml_model_stop(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + } + + /* unload */ + for (i = 0; i < opt->nb_filelist; i++) { + ret = ml_model_unload(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + } + + return 0; + +error: + for (i = 0; i < opt->nb_filelist; i++) + ml_model_stop(test, opt, &t->model[i], i); + + for (i = 0; i < opt->nb_filelist; i++) + ml_model_unload(test, opt, &t->model[i], i); + + return ret; +} + +/* Sub-test D: (load + start) x n -> (stop + unload) x n */ +static int +test_model_ops_subtest_d(struct ml_test *test, struct ml_options *opt) +{ + struct test_model_ops *t; + int ret = 0; + uint32_t i; + + t = ml_test_priv(test); + + /* load + start */ + for (i = 0; i < opt->nb_filelist; i++) { + ret = ml_model_load(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + + ret = ml_model_start(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + } + + /* stop + unload */ + for (i = 0; i < opt->nb_filelist; i++) { + ret = ml_model_stop(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + + ret = ml_model_unload(test, opt, &t->model[i], i); + if (ret != 0) + goto error; + } + + return 0; + +error: + for (i = 0; i < opt->nb_filelist; i++) + ml_model_stop(test, opt, &t->model[i], i); + + for (i = 0; i < opt->nb_filelist; i++) + ml_model_unload(test, opt, &t->model[i], i); + + return ret; +} + +static int +test_model_ops_driver(struct ml_test *test, struct ml_options *opt) +{ + struct test_model_ops *t; + int ret = 0; + + t = ml_test_priv(test); + + /* device setup */ + ret = test_model_ops_mldev_setup(test, opt); + if (ret != 0) + return ret; + + printf("\n"); + + /* sub-test A */ + ret = test_model_ops_subtest_a(test, opt); + if (ret != 0) { + printf("Model Ops Sub-test A: " CLRED "%s" CLNRM "\n", "Failed"); + goto error; + } else { + printf("Model Ops Sub-test A: " CLYEL "%s" CLNRM "\n", "Passed"); + } + + /* sub-test B */ + ret = test_model_ops_subtest_b(test, opt); + if (ret != 0) { + printf("Model Ops Sub-test B: " CLRED "%s" CLNRM "\n", "Failed"); + goto error; + } else { + printf("Model Ops Sub-test B: " CLYEL "%s" CLNRM "\n", "Passed"); + } + + /* sub-test C */ + ret = test_model_ops_subtest_c(test, opt); + if (ret != 0) { + printf("Model Ops Sub-test C: " CLRED "%s" CLNRM "\n", "Failed"); + goto error; + } else { + printf("Model Ops Sub-test C: " CLYEL "%s" CLNRM "\n", "Passed"); + } + + /* sub-test D */ + ret = test_model_ops_subtest_d(test, opt); + if (ret != 0) { + printf("Model Ops Sub-test D: " CLRED "%s" CLNRM "\n", "Failed"); + goto error; + } else { + printf("Model Ops Sub-test D: " CLYEL "%s" CLNRM "\n", "Passed"); + } + + printf("\n"); + + /* device destroy */ + ret = test_model_ops_mldev_destroy(test, opt); + if (ret != 0) + return ret; + + t->cmn.result = ML_TEST_SUCCESS; + + return 0; + +error: + test_model_ops_mldev_destroy(test, opt); + + t->cmn.result = ML_TEST_FAILED; + + return ret; +} + +static int +test_model_ops_result(struct ml_test *test, struct ml_options *opt) +{ + struct test_model_ops *t; + + RTE_SET_USED(opt); + + t = ml_test_priv(test); + + return t->cmn.result; +} + +static const struct ml_test_ops model_ops = { + .cap_check = test_model_ops_cap_check, + .opt_check = test_model_ops_opt_check, + .opt_dump = test_model_ops_opt_dump, + .test_setup = test_model_ops_setup, + .test_destroy = test_model_ops_destroy, + .test_driver = test_model_ops_driver, + .test_result = test_model_ops_result, +}; + +ML_TEST_REGISTER(model_ops); diff --git a/app/test-mldev/test_model_ops.h b/app/test-mldev/test_model_ops.h new file mode 100644 index 0000000000..c21f12b788 --- /dev/null +++ b/app/test-mldev/test_model_ops.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#ifndef _ML_TEST_MODEL_OPS_ +#define _ML_TEST_MODEL_OPS_ + +#include + +#include "test_model_common.h" + +struct test_model_ops { + /* common data */ + struct test_common cmn; + + /* test specific data */ + struct ml_model model[ML_TEST_MAX_MODELS]; +} __rte_cache_aligned; + +#endif /* _ML_TEST_MODEL_OPS_ */ diff --git a/doc/guides/tools/img/mldev_model_ops_subtest_a.svg b/doc/guides/tools/img/mldev_model_ops_subtest_a.svg new file mode 100644 index 0000000000..ed12cc5a05 --- /dev/null +++ b/doc/guides/tools/img/mldev_model_ops_subtest_a.svg @@ -0,0 +1,420 @@ + + + + + + + + + + + + + + + + + + Model 0 / Load + + Model 0 / Start + + Model 0 / Stop + + Model 0 / Unload + + + + + Model 1 / Load + + Model 1 / Start + + Model 1 / Unload + + Model 1 / Stop + + + + + Model N / Load + + Model N / Start + + Model N / Stop + + Model N / Unload + + + mldev: model_ops / subtest D + + + diff --git a/doc/guides/tools/img/mldev_model_ops_subtest_b.svg b/doc/guides/tools/img/mldev_model_ops_subtest_b.svg new file mode 100644 index 0000000000..173a2c6c05 --- /dev/null +++ b/doc/guides/tools/img/mldev_model_ops_subtest_b.svg @@ -0,0 +1,423 @@ + + + + + + + + + + + + + + + Model 0 / Load + + Model 1 / Load + + Model N / Load + + + + + Model 0 / Start + + Model 1 / Start + + Model N / Start + + + + + Model 1 / Stop + + Model 0 / Stop + + Model N / Stop + + + + + Model 0 / Unload + + Model 1 / Unload + + Model N / Unload + + + mldev: model_ops / subtest A + + + diff --git a/doc/guides/tools/img/mldev_model_ops_subtest_c.svg b/doc/guides/tools/img/mldev_model_ops_subtest_c.svg new file mode 100644 index 0000000000..f66f146d05 --- /dev/null +++ b/doc/guides/tools/img/mldev_model_ops_subtest_c.svg @@ -0,0 +1,366 @@ + + + + + + + + + + + + + + + Model 0 / Load + + Model 1 / Load + + Model N / Load + + + + + Model 0 / Start + + Model 0 / Stop + + + + Model 0 / Unload + + Model 1 / Unload + + Model N / Unload + + + + Model N / Stop + + Model N / Start + + + mldev: model_ops / subtest C + + + diff --git a/doc/guides/tools/img/mldev_model_ops_subtest_d.svg b/doc/guides/tools/img/mldev_model_ops_subtest_d.svg new file mode 100644 index 0000000000..3e2b89ad25 --- /dev/null +++ b/doc/guides/tools/img/mldev_model_ops_subtest_d.svg @@ -0,0 +1,424 @@ + + + + + + + + + + + + + + + Model 0 / Load + + Model 0 / Start + + Model 1 / Load + + + + + Model 1 / Start + + + Model N / Load + + Model N / Start + + + + Model N / Unload + + Model N / Stop + + + + Model 1 / Stop + + + Model 1 / Unload + + Model 0 / Stop + + Model 0 / Unload + + + mldev: model_ops / subest B + + + diff --git a/doc/guides/tools/testmldev.rst b/doc/guides/tools/testmldev.rst index 1771c49fb4..b8a2a16ca2 100644 --- a/doc/guides/tools/testmldev.rst +++ b/doc/guides/tools/testmldev.rst @@ -44,13 +44,17 @@ The following are the command-line options supported by the test application. * ``--test `` - Name of the test to execute. ML tests supported include device tests. Test name should be - one of the following supported tests. + Name of the test to execute. ML tests are divided into two groups, Device and Model + tests. Test name should be one of the following supported tests. **ML Device Tests** :: device_ops + **ML Model Tests** :: + + model_ops + * ``--dev_id `` Set the device id of the ML device to be used for the test. Default value is `0`. @@ -59,6 +63,12 @@ The following are the command-line options supported by the test application. Set the socket id of the application resources. Default value is `SOCKET_ID_ANY`. +* ``--models `` + + Set the list of model files to be used for the tests. Application expects the + ``model_list`` in comma separated form (i.e. ``--models model_A.bin,model_B.bin``). + Maximum number of models supported by the test is ``8``. + * ``--debug`` Enable the tests to run in debug mode. @@ -103,6 +113,89 @@ Command to run device_ops test: --test=device_ops +ML Model Tests +------------------------- + +Model tests are functional tests to validate ML model APIs. Model tests validate the functioning +of APIs to load, start, stop and unload ML models. + + +Application Options +~~~~~~~~~~~~~~~~~~~ + +Supported command line options for the `model_ops` test are following:: + + --debug + --test + --dev_id + --socket_id + --models + + +List of model files to be used for the `model_ops` test can be specified through the option +``--models `` as a comma separated list. Maximum number of models supported in +the test is `8`. + +.. Note:: + + * The ``--models `` is a mandatory option for running this test. + * Options not supported by the test are ignored if specified. + + +MODEL_OPS Test +~~~~~~~~~~~~~~ + +The test is a collection of multiple sub-tests, each with a different order of slow-path +operations when handling with `N` number of models. + + +**Sub-test A:** executes the sequence of load / start / stop / unload for a model in order, +followed by next model. +.. _figure_mldev_model_ops_subtest_a: + +.. figure:: img/mldev_model_ops_subtest_a.* + + Execution sequence of model_ops subtest A. + + +**Sub-test B:** executes load for all models, followed by a start for all models. Upon successful +start of all models, stop is invoked for all models followed by unload. +.. _figure_mldev_model_ops_subtest_b: + +.. figure:: img/mldev_model_ops_subtest_b.* + + Execution sequence of model_ops subtest B. + + +**Sub-test C:** loads all models, followed by a start and stop of all models in order. Upon +completion of stop, unload is invoked for all models. +.. _figure_mldev_model_ops_subtest_c: + +.. figure:: img/mldev_model_ops_subtest_c.* + + Execution sequence of model_ops subtest C. + + +**Sub-test D:** executes load and start for all models available. Upon successful start of all +models, stop and stop is executed for the models. +.. _figure_mldev_model_ops_subtest_d: + +.. figure:: img/mldev_model_ops_subtest_d.* + + Execution sequence of model_ops subtest D. + + +Example +^^^^^^^ + +Command to run model_ops test: + +.. code-block:: console + + sudo /app/dpdk-test-mldev -c 0xf -a -- \ + --test=model_ops --models model_1.bin,model_2.bin,model_3.bin, model_4.bin + + Debug mode ---------- From patchwork Thu Mar 16 21:14:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 125204 X-Patchwork-Delegate: thomas@monjalon.net 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 8D4C441EB5; Thu, 16 Mar 2023 22:15:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B832542F8A; Thu, 16 Mar 2023 22:14:51 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 6952042DB3 for ; Thu, 16 Mar 2023 22:14:44 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32GKcQtc004129 for ; Thu, 16 Mar 2023 14:14:43 -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-type; s=pfpt0220; bh=GMfi9qTVpYCNU97aF56wqw965+1hTsoylaos8z8XdDY=; b=bl2d1OkC5dMXNyktKfwSmxf1u6AGZ9MBATkfpvXIxGg3PU84opEShwkzG2xMAuKkLcA4 e9Q+ozaEyuo5obHwtgp5oB2L76W9p+WYac+RVHv6+Bk0JrW+R1qYjAnWl+CWIA52EnMr KwZ0qoec/+UN/JZDJ65rHTD9f0X7iuqefvt5aNXY4FVmuM7m8u0ot1jx2D7nZ5nFk/Hy wLgjPPZQZn1PYH2u635bG4+yWjN1bDqW1pA9PWBqm9V/uHnuaGKzZetxSbxmOv1AHshC 94RPnR7HFbuLp29Gj1Rqq6BzE1TaGxqY+QiSDqgLJmHKq51kGUQMX6zy7w3I8D1ug7vu OA== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3pbxq2ub11-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 16 Mar 2023 14:14:43 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 16 Mar 2023 14:14:40 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 16 Mar 2023 14:14:40 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 592B15B6939; Thu, 16 Mar 2023 14:14:40 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v7 05/11] app/mldev: add ordered inference test case Date: Thu, 16 Mar 2023 14:14:28 -0700 Message-ID: <20230316211434.13409-6-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316211434.13409-1-syalavarthi@marvell.com> References: <20221129070746.20396-1-syalavarthi@marvell.com> <20230316211434.13409-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: iEj_kOL1UDtaSB9Fjxhs7RpChWPl2C6D X-Proofpoint-ORIG-GUID: iEj_kOL1UDtaSB9Fjxhs7RpChWPl2C6D X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 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 an ordered test case to execute inferences with single or multiple models. In this test case inference requests for a model are enqueued after completion of all requests for the previous model. Test supports inference repetitions. Operations sequence when testing with N models and R reps, (load -> start -> (enqueue + dequeue) x R -> stop -> unload) x N Test case can be executed by selecting "inference_ordered" test and repetitions can be specified through "--repetitions" argument. Signed-off-by: Srikanth Yalavarthi Acked-by: Anup Prabhu --- app/test-mldev/meson.build | 2 + app/test-mldev/ml_options.c | 65 ++ app/test-mldev/ml_options.h | 17 +- app/test-mldev/test_inference_common.c | 567 ++++++++++++++++++ app/test-mldev/test_inference_common.h | 61 ++ app/test-mldev/test_inference_ordered.c | 115 ++++ app/test-mldev/test_model_common.h | 10 + .../tools/img/mldev_inference_ordered.svg | 528 ++++++++++++++++ doc/guides/tools/testmldev.rst | 88 ++- 9 files changed, 1445 insertions(+), 8 deletions(-) create mode 100644 app/test-mldev/test_inference_common.c create mode 100644 app/test-mldev/test_inference_common.h create mode 100644 app/test-mldev/test_inference_ordered.c create mode 100644 doc/guides/tools/img/mldev_inference_ordered.svg diff --git a/app/test-mldev/meson.build b/app/test-mldev/meson.build index b09e1ccc8a..475d76d126 100644 --- a/app/test-mldev/meson.build +++ b/app/test-mldev/meson.build @@ -16,6 +16,8 @@ sources = files( 'test_device_ops.c', 'test_model_common.c', 'test_model_ops.c', + 'test_inference_common.c', + 'test_inference_ordered.c', ) deps += ['mldev'] diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index 8ffbab7f75..7b56bca90e 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -23,6 +23,7 @@ ml_options_default(struct ml_options *opt) opt->dev_id = 0; opt->socket_id = SOCKET_ID_ANY; opt->nb_filelist = 0; + opt->repetitions = 1; opt->debug = false; } @@ -90,6 +91,60 @@ ml_parse_models(struct ml_options *opt, const char *arg) return ret; } +static int +ml_parse_filelist(struct ml_options *opt, const char *arg) +{ + const char *delim = ","; + char filelist[PATH_MAX]; + char *token; + + if (opt->nb_filelist >= ML_TEST_MAX_MODELS) { + ml_err("Exceeded filelist count, max = %d\n", ML_TEST_MAX_MODELS); + return -1; + } + + strlcpy(filelist, arg, PATH_MAX); + + /* model */ + token = strtok(filelist, delim); + if (token == NULL) { + ml_err("Invalid filelist, model not specified = %s\n", arg); + return -EINVAL; + } + strlcpy(opt->filelist[opt->nb_filelist].model, token, PATH_MAX); + + /* input */ + token = strtok(NULL, delim); + if (token == NULL) { + ml_err("Invalid filelist, input not specified = %s\n", arg); + return -EINVAL; + } + strlcpy(opt->filelist[opt->nb_filelist].input, token, PATH_MAX); + + /* output */ + token = strtok(NULL, delim); + if (token == NULL) { + ml_err("Invalid filelist, output not specified = %s\n", arg); + return -EINVAL; + } + strlcpy(opt->filelist[opt->nb_filelist].output, token, PATH_MAX); + + opt->nb_filelist++; + + if (opt->nb_filelist == 0) { + ml_err("Empty filelist. Need at least one filelist entry for the test."); + return -EINVAL; + } + + return 0; +} + +static int +ml_parse_repetitions(struct ml_options *opt, const char *arg) +{ + return parser_read_uint64(&opt->repetitions, arg); +} + static void ml_dump_test_options(const char *testname) { @@ -100,6 +155,12 @@ ml_dump_test_options(const char *testname) printf("\t\t--models : comma separated list of models\n"); printf("\n"); } + + if (strcmp(testname, "inference_ordered") == 0) { + printf("\t\t--filelist : comma separated list of model, input and output\n" + "\t\t--repetitions : number of inference repetitions\n"); + printf("\n"); + } } static void @@ -122,6 +183,8 @@ static struct option lgopts[] = { {ML_DEVICE_ID, 1, 0, 0}, {ML_SOCKET_ID, 1, 0, 0}, {ML_MODELS, 1, 0, 0}, + {ML_FILELIST, 1, 0, 0}, + {ML_REPETITIONS, 1, 0, 0}, {ML_DEBUG, 0, 0, 0}, {ML_HELP, 0, 0, 0}, {NULL, 0, 0, 0}}; @@ -136,6 +199,8 @@ ml_opts_parse_long(int opt_idx, struct ml_options *opt) {ML_DEVICE_ID, ml_parse_dev_id}, {ML_SOCKET_ID, ml_parse_socket_id}, {ML_MODELS, ml_parse_models}, + {ML_FILELIST, ml_parse_filelist}, + {ML_REPETITIONS, ml_parse_repetitions}, }; for (i = 0; i < RTE_DIM(parsermap); i++) { diff --git a/app/test-mldev/ml_options.h b/app/test-mldev/ml_options.h index 61e938d2e2..6a13f97a30 100644 --- a/app/test-mldev/ml_options.h +++ b/app/test-mldev/ml_options.h @@ -12,15 +12,19 @@ #define ML_TEST_MAX_MODELS 8 /* Options names */ -#define ML_TEST ("test") -#define ML_DEVICE_ID ("dev_id") -#define ML_SOCKET_ID ("socket_id") -#define ML_MODELS ("models") -#define ML_DEBUG ("debug") -#define ML_HELP ("help") +#define ML_TEST ("test") +#define ML_DEVICE_ID ("dev_id") +#define ML_SOCKET_ID ("socket_id") +#define ML_MODELS ("models") +#define ML_FILELIST ("filelist") +#define ML_REPETITIONS ("repetitions") +#define ML_DEBUG ("debug") +#define ML_HELP ("help") struct ml_filelist { char model[PATH_MAX]; + char input[PATH_MAX]; + char output[PATH_MAX]; }; struct ml_options { @@ -29,6 +33,7 @@ struct ml_options { int socket_id; struct ml_filelist filelist[ML_TEST_MAX_MODELS]; uint8_t nb_filelist; + uint64_t repetitions; bool debug; }; diff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c new file mode 100644 index 0000000000..6a6999d524 --- /dev/null +++ b/app/test-mldev/test_inference_common.c @@ -0,0 +1,567 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "ml_common.h" +#include "test_inference_common.h" + +/* Enqueue inference requests with burst size equal to 1 */ +static int +ml_enqueue_single(void *arg) +{ + struct test_inference *t = ml_test_priv((struct ml_test *)arg); + struct ml_request *req = NULL; + struct rte_ml_op *op = NULL; + struct ml_core_args *args; + uint64_t model_enq = 0; + uint32_t burst_enq; + uint32_t lcore_id; + uint16_t fid; + int ret; + + lcore_id = rte_lcore_id(); + args = &t->args[lcore_id]; + model_enq = 0; + + if (args->nb_reqs == 0) + return 0; + +next_rep: + fid = args->start_fid; + +next_model: + ret = rte_mempool_get(t->op_pool, (void **)&op); + if (ret != 0) + goto next_model; + +retry: + ret = rte_mempool_get(t->model[fid].io_pool, (void **)&req); + if (ret != 0) + goto retry; + + op->model_id = t->model[fid].id; + op->nb_batches = t->model[fid].info.batch_size; + op->mempool = t->op_pool; + + op->input.addr = req->input; + op->input.length = t->model[fid].inp_qsize; + op->input.next = NULL; + + op->output.addr = req->output; + op->output.length = t->model[fid].out_qsize; + op->output.next = NULL; + + op->user_ptr = req; + req->niters++; + req->fid = fid; + +enqueue_req: + burst_enq = rte_ml_enqueue_burst(t->cmn.opt->dev_id, 0, &op, 1); + if (burst_enq == 0) + goto enqueue_req; + + fid++; + if (likely(fid <= args->end_fid)) + goto next_model; + + model_enq++; + if (likely(model_enq < args->nb_reqs)) + goto next_rep; + + return 0; +} + +/* Dequeue inference requests with burst size equal to 1 */ +static int +ml_dequeue_single(void *arg) +{ + struct test_inference *t = ml_test_priv((struct ml_test *)arg); + struct rte_ml_op_error error; + struct rte_ml_op *op = NULL; + struct ml_core_args *args; + struct ml_request *req; + uint64_t total_deq = 0; + uint8_t nb_filelist; + uint32_t burst_deq; + uint32_t lcore_id; + + lcore_id = rte_lcore_id(); + args = &t->args[lcore_id]; + nb_filelist = args->end_fid - args->start_fid + 1; + + if (args->nb_reqs == 0) + return 0; + +dequeue_req: + burst_deq = rte_ml_dequeue_burst(t->cmn.opt->dev_id, 0, &op, 1); + + if (likely(burst_deq == 1)) { + total_deq += burst_deq; + if (unlikely(op->status == RTE_ML_OP_STATUS_ERROR)) { + rte_ml_op_error_get(t->cmn.opt->dev_id, op, &error); + ml_err("error_code = 0x%" PRIx64 ", error_message = %s\n", error.errcode, + error.message); + t->error_count[lcore_id]++; + } + req = (struct ml_request *)op->user_ptr; + rte_mempool_put(t->model[req->fid].io_pool, req); + rte_mempool_put(t->op_pool, op); + } + + if (likely(total_deq < args->nb_reqs * nb_filelist)) + goto dequeue_req; + + return 0; +} + +bool +test_inference_cap_check(struct ml_options *opt) +{ + struct rte_ml_dev_info dev_info; + + if (!ml_test_cap_check(opt)) + return false; + + rte_ml_dev_info_get(opt->dev_id, &dev_info); + if (opt->nb_filelist > dev_info.max_models) { + ml_err("Insufficient capabilities: Filelist count exceeded device limit, count = %u (max limit = %u)", + opt->nb_filelist, dev_info.max_models); + return false; + } + + return true; +} + +int +test_inference_opt_check(struct ml_options *opt) +{ + uint32_t i; + int ret; + + /* check common opts */ + ret = ml_test_opt_check(opt); + if (ret != 0) + return ret; + + /* check file availability */ + for (i = 0; i < opt->nb_filelist; i++) { + if (access(opt->filelist[i].model, F_OK) == -1) { + ml_err("Model file not accessible: id = %u, file = %s", i, + opt->filelist[i].model); + return -ENOENT; + } + + if (access(opt->filelist[i].input, F_OK) == -1) { + ml_err("Input file not accessible: id = %u, file = %s", i, + opt->filelist[i].input); + return -ENOENT; + } + } + + if (opt->repetitions == 0) { + ml_err("Invalid option, repetitions = %" PRIu64 "\n", opt->repetitions); + return -EINVAL; + } + + /* check number of available lcores. */ + if (rte_lcore_count() < 3) { + ml_err("Insufficient lcores = %u\n", rte_lcore_count()); + ml_err("Minimum lcores required to create %u queue-pairs = %u\n", 1, 3); + return -EINVAL; + } + + return 0; +} + +void +test_inference_opt_dump(struct ml_options *opt) +{ + uint32_t i; + + /* dump common opts */ + ml_test_opt_dump(opt); + + /* dump test opts */ + ml_dump("repetitions", "%" PRIu64, opt->repetitions); + + ml_dump_begin("filelist"); + for (i = 0; i < opt->nb_filelist; i++) { + ml_dump_list("model", i, opt->filelist[i].model); + ml_dump_list("input", i, opt->filelist[i].input); + ml_dump_list("output", i, opt->filelist[i].output); + } + ml_dump_end; +} + +int +test_inference_setup(struct ml_test *test, struct ml_options *opt) +{ + struct test_inference *t; + void *test_inference; + int ret = 0; + uint32_t i; + + test_inference = rte_zmalloc_socket(test->name, sizeof(struct test_inference), + RTE_CACHE_LINE_SIZE, opt->socket_id); + if (test_inference == NULL) { + ml_err("failed to allocate memory for test_model"); + ret = -ENOMEM; + goto error; + } + test->test_priv = test_inference; + t = ml_test_priv(test); + + t->nb_used = 0; + t->cmn.result = ML_TEST_FAILED; + t->cmn.opt = opt; + memset(t->error_count, 0, RTE_MAX_LCORE * sizeof(uint64_t)); + + /* get device info */ + ret = rte_ml_dev_info_get(opt->dev_id, &t->cmn.dev_info); + if (ret < 0) { + ml_err("failed to get device info"); + goto error; + } + + t->enqueue = ml_enqueue_single; + t->dequeue = ml_dequeue_single; + + /* set model initial state */ + for (i = 0; i < opt->nb_filelist; i++) + t->model[i].state = MODEL_INITIAL; + + return 0; + +error: + if (test_inference != NULL) + rte_free(test_inference); + + return ret; +} + +void +test_inference_destroy(struct ml_test *test, struct ml_options *opt) +{ + struct test_inference *t; + + RTE_SET_USED(opt); + + t = ml_test_priv(test); + if (t != NULL) + rte_free(t); +} + +int +ml_inference_mldev_setup(struct ml_test *test, struct ml_options *opt) +{ + struct rte_ml_dev_qp_conf qp_conf; + struct test_inference *t; + int ret; + + t = ml_test_priv(test); + + ret = ml_test_device_configure(test, opt); + if (ret != 0) + return ret; + + /* setup queue pairs */ + qp_conf.nb_desc = t->cmn.dev_info.max_desc; + qp_conf.cb = NULL; + + ret = rte_ml_dev_queue_pair_setup(opt->dev_id, 0, &qp_conf, opt->socket_id); + if (ret != 0) { + ml_err("Failed to setup ml device queue-pair, dev_id = %d, qp_id = %u\n", + opt->dev_id, 0); + goto error; + } + + ret = ml_test_device_start(test, opt); + if (ret != 0) + goto error; + + return 0; + +error: + ml_test_device_close(test, opt); + + return ret; +} + +int +ml_inference_mldev_destroy(struct ml_test *test, struct ml_options *opt) +{ + int ret; + + ret = ml_test_device_stop(test, opt); + if (ret != 0) + goto error; + + ret = ml_test_device_close(test, opt); + if (ret != 0) + return ret; + + return 0; + +error: + ml_test_device_close(test, opt); + + return ret; +} + +/* Callback for IO pool create. This function would compute the fields of ml_request + * structure and prepare the quantized input data. + */ +static void +ml_request_initialize(struct rte_mempool *mp, void *opaque, void *obj, unsigned int obj_idx) +{ + struct test_inference *t = ml_test_priv((struct ml_test *)opaque); + struct ml_request *req = (struct ml_request *)obj; + + RTE_SET_USED(mp); + RTE_SET_USED(obj_idx); + + req->input = (uint8_t *)obj + + RTE_ALIGN_CEIL(sizeof(struct ml_request), t->cmn.dev_info.min_align_size); + req->output = req->input + + RTE_ALIGN_CEIL(t->model[t->fid].inp_qsize, t->cmn.dev_info.min_align_size); + req->niters = 0; + + /* quantize data */ + rte_ml_io_quantize(t->cmn.opt->dev_id, t->model[t->fid].id, + t->model[t->fid].info.batch_size, t->model[t->fid].input, req->input); +} + +int +ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t fid) +{ + struct test_inference *t = ml_test_priv(test); + char mz_name[RTE_MEMZONE_NAMESIZE]; + char mp_name[RTE_MEMPOOL_NAMESIZE]; + const struct rte_memzone *mz; + uint64_t nb_buffers; + uint32_t buff_size; + uint32_t mz_size; + uint32_t fsize; + FILE *fp; + int ret; + + /* get input buffer size */ + ret = rte_ml_io_input_size_get(opt->dev_id, t->model[fid].id, t->model[fid].info.batch_size, + &t->model[fid].inp_qsize, &t->model[fid].inp_dsize); + if (ret != 0) { + ml_err("Failed to get input size, model : %s\n", opt->filelist[fid].model); + return ret; + } + + /* get output buffer size */ + ret = rte_ml_io_output_size_get(opt->dev_id, t->model[fid].id, + t->model[fid].info.batch_size, &t->model[fid].out_qsize, + &t->model[fid].out_dsize); + if (ret != 0) { + ml_err("Failed to get input size, model : %s\n", opt->filelist[fid].model); + return ret; + } + + /* allocate buffer for user data */ + mz_size = t->model[fid].inp_dsize + t->model[fid].out_dsize; + sprintf(mz_name, "ml_user_data_%d", fid); + mz = rte_memzone_reserve(mz_name, mz_size, opt->socket_id, 0); + if (mz == NULL) { + ml_err("Memzone allocation failed for ml_user_data\n"); + ret = -ENOMEM; + goto error; + } + + t->model[fid].input = mz->addr; + t->model[fid].output = t->model[fid].input + t->model[fid].inp_dsize; + + /* load input file */ + fp = fopen(opt->filelist[fid].input, "r"); + if (fp == NULL) { + ml_err("Failed to open input file : %s\n", opt->filelist[fid].input); + ret = -errno; + goto error; + } + + fseek(fp, 0, SEEK_END); + fsize = ftell(fp); + fseek(fp, 0, SEEK_SET); + if (fsize != t->model[fid].inp_dsize) { + ml_err("Invalid input file, size = %u (expected size = %" PRIu64 ")\n", fsize, + t->model[fid].inp_dsize); + ret = -EINVAL; + fclose(fp); + goto error; + } + + if (fread(t->model[fid].input, 1, t->model[fid].inp_dsize, fp) != t->model[fid].inp_dsize) { + ml_err("Failed to read input file : %s\n", opt->filelist[fid].input); + ret = -errno; + fclose(fp); + goto error; + } + fclose(fp); + + /* create mempool for quantized input and output buffers. ml_request_initialize is + * used as a callback for object creation. + */ + buff_size = RTE_ALIGN_CEIL(sizeof(struct ml_request), t->cmn.dev_info.min_align_size) + + RTE_ALIGN_CEIL(t->model[fid].inp_qsize, t->cmn.dev_info.min_align_size) + + RTE_ALIGN_CEIL(t->model[fid].out_qsize, t->cmn.dev_info.min_align_size); + nb_buffers = RTE_MIN((uint64_t)ML_TEST_MAX_POOL_SIZE, opt->repetitions); + + t->fid = fid; + sprintf(mp_name, "ml_io_pool_%d", fid); + t->model[fid].io_pool = rte_mempool_create(mp_name, nb_buffers, buff_size, 0, 0, NULL, NULL, + ml_request_initialize, test, opt->socket_id, 0); + if (t->model[fid].io_pool == NULL) { + ml_err("Failed to create io pool : %s\n", "ml_io_pool"); + ret = -ENOMEM; + goto error; + } + + return 0; + +error: + if (mz != NULL) + rte_memzone_free(mz); + + if (t->model[fid].io_pool != NULL) { + rte_mempool_free(t->model[fid].io_pool); + t->model[fid].io_pool = NULL; + } + + return ret; +} + +void +ml_inference_iomem_destroy(struct ml_test *test, struct ml_options *opt, uint16_t fid) +{ + char mz_name[RTE_MEMZONE_NAMESIZE]; + char mp_name[RTE_MEMPOOL_NAMESIZE]; + const struct rte_memzone *mz; + struct rte_mempool *mp; + + RTE_SET_USED(test); + RTE_SET_USED(opt); + + /* release user data memzone */ + sprintf(mz_name, "ml_user_data_%d", fid); + mz = rte_memzone_lookup(mz_name); + if (mz != NULL) + rte_memzone_free(mz); + + /* destroy io pool */ + sprintf(mp_name, "ml_io_pool_%d", fid); + mp = rte_mempool_lookup(mp_name); + if (mp != NULL) + rte_mempool_free(mp); +} + +int +ml_inference_mem_setup(struct ml_test *test, struct ml_options *opt) +{ + struct test_inference *t = ml_test_priv(test); + + /* create op pool */ + t->op_pool = rte_ml_op_pool_create("ml_test_op_pool", ML_TEST_MAX_POOL_SIZE, 0, 0, + opt->socket_id); + if (t->op_pool == NULL) { + ml_err("Failed to create op pool : %s\n", "ml_op_pool"); + return -ENOMEM; + } + + return 0; +} + +void +ml_inference_mem_destroy(struct ml_test *test, struct ml_options *opt) +{ + struct test_inference *t = ml_test_priv(test); + + RTE_SET_USED(opt); + + /* release op pool */ + if (t->op_pool != NULL) + rte_mempool_free(t->op_pool); +} + +/* Callback for mempool object iteration. This call would dequantize output data. */ +static void +ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int obj_idx) +{ + struct test_inference *t = ml_test_priv((struct ml_test *)opaque); + struct ml_request *req = (struct ml_request *)obj; + struct ml_model *model = &t->model[req->fid]; + + RTE_SET_USED(mp); + RTE_SET_USED(obj_idx); + + if (req->niters == 0) + return; + + t->nb_used++; + rte_ml_io_dequantize(t->cmn.opt->dev_id, model->id, t->model[req->fid].info.batch_size, + req->output, model->output); +} + +int +ml_inference_result(struct ml_test *test, struct ml_options *opt, uint16_t fid) +{ + struct test_inference *t = ml_test_priv(test); + uint64_t error_count = 0; + uint32_t i; + + RTE_SET_USED(opt); + + /* check for errors */ + for (i = 0; i < RTE_MAX_LCORE; i++) + error_count += t->error_count[i]; + + rte_mempool_obj_iter(t->model[fid].io_pool, ml_request_finish, test); + + if ((t->nb_used > 0) && (error_count == 0)) + t->cmn.result = ML_TEST_SUCCESS; + else + t->cmn.result = ML_TEST_FAILED; + + return t->cmn.result; +} + +int +ml_inference_launch_cores(struct ml_test *test, struct ml_options *opt, uint16_t start_fid, + uint16_t end_fid) +{ + struct test_inference *t = ml_test_priv(test); + uint32_t lcore_id; + uint32_t id = 0; + + RTE_LCORE_FOREACH_WORKER(lcore_id) + { + if (id == 2) + break; + + t->args[lcore_id].nb_reqs = opt->repetitions; + t->args[lcore_id].start_fid = start_fid; + t->args[lcore_id].end_fid = end_fid; + + if (id % 2 == 0) + rte_eal_remote_launch(t->enqueue, test, lcore_id); + else + rte_eal_remote_launch(t->dequeue, test, lcore_id); + + id++; + } + + return 0; +} diff --git a/app/test-mldev/test_inference_common.h b/app/test-mldev/test_inference_common.h new file mode 100644 index 0000000000..abb20fc9fb --- /dev/null +++ b/app/test-mldev/test_inference_common.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#ifndef _ML_TEST_INFERENCE_COMMON_ +#define _ML_TEST_INFERENCE_COMMON_ + +#include +#include +#include + +#include "test_model_common.h" + +struct ml_request { + uint8_t *input; + uint8_t *output; + uint16_t fid; + uint64_t niters; +}; + +struct ml_core_args { + uint64_t nb_reqs; + uint16_t start_fid; + uint16_t end_fid; +}; + +struct test_inference { + /* common data */ + struct test_common cmn; + + /* test specific data */ + struct ml_model model[ML_TEST_MAX_MODELS]; + struct rte_mempool *op_pool; + + uint64_t nb_used; + uint16_t fid; + + int (*enqueue)(void *arg); + int (*dequeue)(void *arg); + + struct ml_core_args args[RTE_MAX_LCORE]; + uint64_t error_count[RTE_MAX_LCORE]; +} __rte_cache_aligned; + +bool test_inference_cap_check(struct ml_options *opt); +int test_inference_opt_check(struct ml_options *opt); +void test_inference_opt_dump(struct ml_options *opt); +int test_inference_setup(struct ml_test *test, struct ml_options *opt); +void test_inference_destroy(struct ml_test *test, struct ml_options *opt); + +int ml_inference_mldev_setup(struct ml_test *test, struct ml_options *opt); +int ml_inference_mldev_destroy(struct ml_test *test, struct ml_options *opt); +int ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t fid); +void ml_inference_iomem_destroy(struct ml_test *test, struct ml_options *opt, uint16_t fid); +int ml_inference_mem_setup(struct ml_test *test, struct ml_options *opt); +void ml_inference_mem_destroy(struct ml_test *test, struct ml_options *opt); +int ml_inference_result(struct ml_test *test, struct ml_options *opt, uint16_t fid); +int ml_inference_launch_cores(struct ml_test *test, struct ml_options *opt, uint16_t start_fid, + uint16_t end_fid); + +#endif /* _ML_TEST_INFERENCE_COMMON_ */ diff --git a/app/test-mldev/test_inference_ordered.c b/app/test-mldev/test_inference_ordered.c new file mode 100644 index 0000000000..1cd91dc3d3 --- /dev/null +++ b/app/test-mldev/test_inference_ordered.c @@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include +#include + +#include "ml_common.h" +#include "test_inference_common.h" + +static int +test_inference_ordered_driver(struct ml_test *test, struct ml_options *opt) +{ + struct test_inference *t; + uint16_t fid = 0; + int ret = 0; + + t = ml_test_priv(test); + + ret = ml_inference_mldev_setup(test, opt); + if (ret != 0) + return ret; + + ret = ml_inference_mem_setup(test, opt); + if (ret != 0) + return ret; + +next_model: + /* load model */ + ret = ml_model_load(test, opt, &t->model[fid], fid); + if (ret != 0) + goto error; + + /* start model */ + ret = ml_model_start(test, opt, &t->model[fid], fid); + if (ret != 0) + goto error; + + ret = ml_inference_iomem_setup(test, opt, fid); + if (ret != 0) + goto error; + + /* launch inferences for one model using available queue pairs */ + ret = ml_inference_launch_cores(test, opt, fid, fid); + if (ret != 0) { + ml_err("failed to launch cores"); + goto error; + } + + rte_eal_mp_wait_lcore(); + + ret = ml_inference_result(test, opt, fid); + if (ret != ML_TEST_SUCCESS) + goto error; + + ml_inference_iomem_destroy(test, opt, fid); + + /* stop model */ + ret = ml_model_stop(test, opt, &t->model[fid], fid); + if (ret != 0) + goto error; + + /* unload model */ + ret = ml_model_unload(test, opt, &t->model[fid], fid); + if (ret != 0) + goto error; + + fid++; + if (fid < opt->nb_filelist) + goto next_model; + + ml_inference_mem_destroy(test, opt); + + ret = ml_inference_mldev_destroy(test, opt); + if (ret != 0) + return ret; + + t->cmn.result = ML_TEST_SUCCESS; + + return 0; + +error: + ml_inference_iomem_destroy(test, opt, fid); + ml_inference_mem_destroy(test, opt); + ml_model_stop(test, opt, &t->model[fid], fid); + ml_model_unload(test, opt, &t->model[fid], fid); + + t->cmn.result = ML_TEST_FAILED; + + return ret; +} + +static int +test_inference_ordered_result(struct ml_test *test, struct ml_options *opt) +{ + struct test_inference *t; + + RTE_SET_USED(opt); + + t = ml_test_priv(test); + + return t->cmn.result; +} + +static const struct ml_test_ops inference_ordered = { + .cap_check = test_inference_cap_check, + .opt_check = test_inference_opt_check, + .opt_dump = test_inference_opt_dump, + .test_setup = test_inference_setup, + .test_destroy = test_inference_destroy, + .test_driver = test_inference_ordered_driver, + .test_result = test_inference_ordered_result, +}; + +ML_TEST_REGISTER(inference_ordered); diff --git a/app/test-mldev/test_model_common.h b/app/test-mldev/test_model_common.h index 74aec0a797..5ee975109d 100644 --- a/app/test-mldev/test_model_common.h +++ b/app/test-mldev/test_model_common.h @@ -20,6 +20,16 @@ struct ml_model { uint16_t id; struct rte_ml_model_info info; enum model_state state; + + uint64_t inp_dsize; + uint64_t inp_qsize; + uint64_t out_dsize; + uint64_t out_qsize; + + uint8_t *input; + uint8_t *output; + + struct rte_mempool *io_pool; }; int ml_model_load(struct ml_test *test, struct ml_options *opt, struct ml_model *model, diff --git a/doc/guides/tools/img/mldev_inference_ordered.svg b/doc/guides/tools/img/mldev_inference_ordered.svg new file mode 100644 index 0000000000..12fa6acaec --- /dev/null +++ b/doc/guides/tools/img/mldev_inference_ordered.svg @@ -0,0 +1,528 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Model X + QueuePair 1 + QueuePair 2 + + + + + + + QueuePair 0 + + Machine LearningHardware Engine + lcore 1 + lcore 5 + lcore 3 + Enqueue Workers + lcore 2 + lcore 4 + lcore 6 + Dequeue Workers + test: inference_ordered + nb_worker_threads = 2 * MIN(nb_queue_pairs, (lcore_count - 1) / 2) + inferences_per_queue_pair = repetitions / nb_queue_pairs + + + + + + + + + + + + diff --git a/doc/guides/tools/testmldev.rst b/doc/guides/tools/testmldev.rst index b8a2a16ca2..164fbca64f 100644 --- a/doc/guides/tools/testmldev.rst +++ b/doc/guides/tools/testmldev.rst @@ -44,8 +44,8 @@ The following are the command-line options supported by the test application. * ``--test `` - Name of the test to execute. ML tests are divided into two groups, Device and Model - tests. Test name should be one of the following supported tests. + Name of the test to execute. ML tests are divided into three groups, Device, Model + and Inference tests. Test name should be one of the following supported tests. **ML Device Tests** :: @@ -55,6 +55,10 @@ The following are the command-line options supported by the test application. model_ops + **ML Inference Tests** :: + + inference_ordered + * ``--dev_id `` Set the device id of the ML device to be used for the test. Default value is `0`. @@ -69,6 +73,23 @@ The following are the command-line options supported by the test application. ``model_list`` in comma separated form (i.e. ``--models model_A.bin,model_B.bin``). Maximum number of models supported by the test is ``8``. +* ``--filelist `` + + Set the list of model, input, output and reference files to be used for the tests. + Application expects the ``file_list`` to be in comma separated form + (i.e. ``--filelist [,reference]``). + + Multiple filelist entries can be specified when running the tests with multiple models. + Both quantized and dequantized outputs are written to the disk. Dequantized output file + would have the name specified by the user through ``--filelist`` option. A suffix ``.q`` + is appended to quantized output filename. Maximum number of filelist entries supported + by the test is ``8``. + +* ``--repetitions `` + + Set the number of inference repetitions to be executed in the test per each model. Default + value is `1`. + * ``--debug`` Enable the tests to run in debug mode. @@ -196,6 +217,69 @@ Command to run model_ops test: --test=model_ops --models model_1.bin,model_2.bin,model_3.bin, model_4.bin +ML Inference Tests +------------------ + +Inference tests are a set of tests to validate end-to-end inference execution on ML device. +These tests executes the full sequence of operations required to run inferences with one or +multiple models. + +Application Options +~~~~~~~~~~~~~~~~~~~ + +Supported command line options for inference tests are following:: + + --debug + --test + --dev_id + --socket_id + --filelist + --repetitions + + +List of files to be used for the inference tests can be specified through the option +``--filelist `` as a comma separated list. A filelist entry would be of the format +``--filelist [,reference_file]`` and is used to specify the +list of files required to test with a single model. Multiple filelist entries are supported by +the test, one entry per model. Maximum number of file entries supported by the test is `8`. + +.. Note:: + + * The ``--filelist `` is a mandatory option for running inference tests. + * Options not supported by the tests are ignored if specified. + + +INFERENCE_ORDERED Test +~~~~~~~~~~~~~~~~~~~~~~ + +This is a functional test for validating the end-to-end inference execution on ML device. This +test configures ML device and queue pairs as per the queue-pair related options (queue_pairs and +queue_size) specified by the user. Upon successful configuration of the device and queue pairs, +the first model specified through the filelist is loaded to the device and inferences are enqueued +by a pool of worker threads to the ML device. Total number of inferences enqueued for the model +are equal to the repetitions specified. A dedicated pool of worker threads would dequeue the +inferences from the device. The model is unloaded upon completion of all inferences for the model. +The test would continue loading and executing inference requests for all models specified +through ``filelist`` option in an ordered manner. + +.. _figure_mldev_inference_ordered: + +.. figure:: img/mldev_inference_ordered.* + + Execution of inference_ordered on single model. + + +Example +^^^^^^^ + +Example command to run inference_ordered test: + +.. code-block:: console + + sudo /app/dpdk-test-mldev -c 0xf -a -- \ + --test=inference_ordered --filelist model.bin,input.bin,output.bin + + Debug mode ---------- From patchwork Thu Mar 16 21:14:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 125205 X-Patchwork-Delegate: thomas@monjalon.net 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 1DA7541EB5; Thu, 16 Mar 2023 22:15:39 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DA0EF42FB4; Thu, 16 Mar 2023 22:14:52 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 0767440DF6 for ; Thu, 16 Mar 2023 22:14:44 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32GKcQtd004129 for ; Thu, 16 Mar 2023 14:14:44 -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-type; s=pfpt0220; bh=7aLULWfGAUkzVpvoZsrpuxzrZpQC5E9re/HSR+85qjM=; b=DI4aoqSJjMIAAofrc+ATgQLErR+JCuvZ0IhUTEyNYKZ7HcNAd1njIjV7c7McfNlj3uLb 3wMddPRG4pJQ/P5uOENCTwH+myPP/I/EAtT4Yl5kk8GNsnelHoNb/6/6qSC9Odv8XxUH BwA5VmY8nsWKw98nt3xToS43Fr+k+7vQnHFhg7cdWeElC/Qu1vobM5L07gIOKSBLjXqj wHSMazKZCAPDi0+FwWJUFnvP3DMyU8DfbjnZqnPkSD6aIXjYCm4Hcme+kvz1+/W+iNme z6EgYwp43gJYA9EUraoXc1tEVnwED5DFbMgLm+uemzTUo/IBwWh1juXA51GBSJUUG3Jf Qg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3pbxq2ub11-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 16 Mar 2023 14:14:43 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 16 Mar 2023 14:14:40 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 16 Mar 2023 14:14:40 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 8C4155C68E2; Thu, 16 Mar 2023 14:14:40 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v7 06/11] app/mldev: add test case to interleave inferences Date: Thu, 16 Mar 2023 14:14:29 -0700 Message-ID: <20230316211434.13409-7-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316211434.13409-1-syalavarthi@marvell.com> References: <20221129070746.20396-1-syalavarthi@marvell.com> <20230316211434.13409-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: BjLUjlGqIikgf5eMHyrKCA4j_mbt9TZi X-Proofpoint-ORIG-GUID: BjLUjlGqIikgf5eMHyrKCA4j_mbt9TZi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 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 test case to interleave inference requests from multiple models. Interleaving would load and start all models and launch inference requests for the models using available queue-pairs Operations sequence when testing with N models and R reps, (load + start) x N -> (enqueue + dequeue) x N x R ... -> (stop + unload) x N Test can be executed by selecting "inference_interleave" test. Signed-off-by: Srikanth Yalavarthi Acked-by: Anup Prabhu --- app/test-mldev/meson.build | 1 + app/test-mldev/ml_options.c | 3 +- app/test-mldev/test_inference_interleave.c | 114 +++ .../tools/img/mldev_inference_interleave.svg | 669 ++++++++++++++++++ doc/guides/tools/testmldev.rst | 41 ++ 5 files changed, 827 insertions(+), 1 deletion(-) create mode 100644 app/test-mldev/test_inference_interleave.c create mode 100644 doc/guides/tools/img/mldev_inference_interleave.svg diff --git a/app/test-mldev/meson.build b/app/test-mldev/meson.build index 475d76d126..41d22fb22c 100644 --- a/app/test-mldev/meson.build +++ b/app/test-mldev/meson.build @@ -18,6 +18,7 @@ sources = files( 'test_model_ops.c', 'test_inference_common.c', 'test_inference_ordered.c', + 'test_inference_interleave.c', ) deps += ['mldev'] diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index 7b56bca90e..649cb9d8d1 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -156,7 +156,8 @@ ml_dump_test_options(const char *testname) printf("\n"); } - if (strcmp(testname, "inference_ordered") == 0) { + if ((strcmp(testname, "inference_ordered") == 0) || + (strcmp(testname, "inference_interleave") == 0)) { printf("\t\t--filelist : comma separated list of model, input and output\n" "\t\t--repetitions : number of inference repetitions\n"); printf("\n"); diff --git a/app/test-mldev/test_inference_interleave.c b/app/test-mldev/test_inference_interleave.c new file mode 100644 index 0000000000..9cf4cfa197 --- /dev/null +++ b/app/test-mldev/test_inference_interleave.c @@ -0,0 +1,114 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Marvell. + */ + +#include +#include + +#include "ml_common.h" +#include "test_inference_common.h" + +static int +test_inference_interleave_driver(struct ml_test *test, struct ml_options *opt) +{ + struct test_inference *t; + uint16_t fid = 0; + int ret = 0; + + t = ml_test_priv(test); + + ret = ml_inference_mldev_setup(test, opt); + if (ret != 0) + return ret; + + ret = ml_inference_mem_setup(test, opt); + if (ret != 0) + return ret; + + /* load and start all models */ + for (fid = 0; fid < opt->nb_filelist; fid++) { + ret = ml_model_load(test, opt, &t->model[fid], fid); + if (ret != 0) + goto error; + + ret = ml_model_start(test, opt, &t->model[fid], fid); + if (ret != 0) + goto error; + + ret = ml_inference_iomem_setup(test, opt, fid); + if (ret != 0) + goto error; + } + + /* launch inference requests */ + ret = ml_inference_launch_cores(test, opt, 0, opt->nb_filelist - 1); + if (ret != 0) { + ml_err("failed to launch cores"); + goto error; + } + + rte_eal_mp_wait_lcore(); + + /* stop and unload all models */ + for (fid = 0; fid < opt->nb_filelist; fid++) { + ret = ml_inference_result(test, opt, fid); + if (ret != ML_TEST_SUCCESS) + goto error; + + ml_inference_iomem_destroy(test, opt, fid); + + ret = ml_model_stop(test, opt, &t->model[fid], fid); + if (ret != 0) + goto error; + + ret = ml_model_unload(test, opt, &t->model[fid], fid); + if (ret != 0) + goto error; + } + + ml_inference_mem_destroy(test, opt); + + ret = ml_inference_mldev_destroy(test, opt); + if (ret != 0) + return ret; + + t->cmn.result = ML_TEST_SUCCESS; + + return 0; + +error: + ml_inference_mem_destroy(test, opt); + for (fid = 0; fid < opt->nb_filelist; fid++) { + ml_inference_iomem_destroy(test, opt, fid); + ml_model_stop(test, opt, &t->model[fid], fid); + ml_model_unload(test, opt, &t->model[fid], fid); + } + + t->cmn.result = ML_TEST_FAILED; + + return ret; +} + +static int +test_inference_interleave_result(struct ml_test *test, struct ml_options *opt) +{ + struct test_inference *t; + + RTE_SET_USED(opt); + + t = ml_test_priv(test); + + return t->cmn.result; +} + +static const struct ml_test_ops inference_interleave = { + .cap_check = test_inference_cap_check, + .opt_check = test_inference_opt_check, + .opt_dump = test_inference_opt_dump, + .test_setup = test_inference_setup, + .test_destroy = test_inference_destroy, + .test_driver = test_inference_interleave_driver, + .test_result = test_inference_interleave_result, +}; + +ML_TEST_REGISTER(inference_interleave); diff --git a/doc/guides/tools/img/mldev_inference_interleave.svg b/doc/guides/tools/img/mldev_inference_interleave.svg new file mode 100644 index 0000000000..3a741ea627 --- /dev/null +++ b/doc/guides/tools/img/mldev_inference_interleave.svg @@ -0,0 +1,669 @@ + + + + + + + + + + + + + + + + + + + + + + + + test: inference_interleave + + + + + + + + + QueuePair 0 + QueuePair 2 + + + + QueuePair 1 + + Machine LearningHardware Engine + + lcore 1 + lcore 5 + + + + lcore 3 + Enqueue Workers + + lcore 2 + lcore 4 + + + + lcore 6 + Dequeue Workers + + + + + + + + + + + + + Model 0 + Model 1 + Model 2 + Model 3 + + + + + + + nb_worker_threads = 2 * MIN(nb_queue_pairs, (lcore_count - 1) / 2) + inferences_per_queue_pair = nb_models * (repetitions / nb_queue_pairs) + + + + diff --git a/doc/guides/tools/testmldev.rst b/doc/guides/tools/testmldev.rst index 164fbca64f..1a1ab7d2bf 100644 --- a/doc/guides/tools/testmldev.rst +++ b/doc/guides/tools/testmldev.rst @@ -58,6 +58,7 @@ The following are the command-line options supported by the test application. **ML Inference Tests** :: inference_ordered + inference_interleave * ``--dev_id `` @@ -280,6 +281,46 @@ Example command to run inference_ordered test: --test=inference_ordered --filelist model.bin,input.bin,output.bin +INFERENCE_INTERLEAVE Test +~~~~~~~~~~~~~~~~~~~~~~~~~ + +This is a stress test for validating the end-to-end inference execution on ML device. The test +configures the ML device and queue pairs as per the queue-pair related options (queue_pairs +and queue_size) specified by the user. Upon successful configuration of the device and queue +pairs, all models specified through the filelist are loaded to the device. Inferences for multiple +models are enqueued by a pool of worker threads in parallel. Inference execution by the device is +interleaved between multiple models. Total number of inferences enqueued for a model are equal to +the repetitions specified. An additional pool of threads would dequeue the inferences from the +device. Models would be unloaded upon completion of inferences for all models loaded. + + +.. _figure_mldev_inference_interleave: + +.. figure:: img/mldev_inference_interleave.* + + Execution of inference_interleave on single model. + + +Example +^^^^^^^ + +Example command to run inference_interleave test: + +.. code-block:: console + + sudo /app/dpdk-test-mldev -c 0xf -a -- \ + --test=inference_interleave --filelist model.bin,input.bin,output.bin + + +Example command to run inference_interleave test with multiple models: + +.. code-block:: console + + sudo /app/dpdk-test-mldev -c 0xf -a -- \ + --test=inference_interleave --filelist model_A.bin,input_A.bin,output_A.bin \ + --filelist model_B.bin,input_B.bin,output_B.bin + + Debug mode ---------- From patchwork Thu Mar 16 21:14:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 125202 X-Patchwork-Delegate: thomas@monjalon.net 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 D142A41EB6; Thu, 16 Mar 2023 22:15:16 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6075742F98; Thu, 16 Mar 2023 22:14:49 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 46D0C40DDC for ; Thu, 16 Mar 2023 22:14:44 +0100 (CET) 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 32GJMmii016125 for ; Thu, 16 Mar 2023 14:14:43 -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-type; s=pfpt0220; bh=GkutLY+aaRCGuXhkYFBkrDQYWRFJTy712C3XdxImHBU=; b=LY+qb2K7YGqbHIzrD1J+0Row46+oDfeL43Px7U4g3EXS6CRS9DXRT/2uiWnzex0GCB5m rlrUsILtgZjA9QwptmoEEXVwSkGtCt+ZCPf+8oiTsW0CIfmDwL6soD9D6IGgEYY3fydS e7JDZgwj9jHrLEBYh+jkqzbQlSDcxjrvem41jpL4iqkPsdyYX59JuTTM6vSJCozjyHHG kDOghQQYm/vsQhr10COm0iRQL/HF1HOnRvymCOsDlLaS+Se/LZ+iZoq1Er8kEsLozQOt gK7P+3RUbGloxuzo9t0yqCghzx+biqfWq/O4AkhF6E0mIc3tB5I4dOvLx0SnJ6UtLKwE Nw== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3pbs2u3mk5-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 16 Mar 2023 14:14:43 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 16 Mar 2023 14:14:40 -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.42 via Frontend Transport; Thu, 16 Mar 2023 14:14:40 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id B9B983F7063; Thu, 16 Mar 2023 14:14:40 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v7 07/11] app/mldev: enable support for burst inferences Date: Thu, 16 Mar 2023 14:14:30 -0700 Message-ID: <20230316211434.13409-8-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316211434.13409-1-syalavarthi@marvell.com> References: <20221129070746.20396-1-syalavarthi@marvell.com> <20230316211434.13409-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: xHSY3JtMPdd6xMld9C1SdU-T-7_UB-z9 X-Proofpoint-ORIG-GUID: xHSY3JtMPdd6xMld9C1SdU-T-7_UB-z9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 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 'burst_size' support for inference tests. Burst size controls the number of inference requests handled during the burst enqueue and dequeue operations of the test case. Signed-off-by: Srikanth Yalavarthi Acked-by: Anup Prabhu --- app/test-mldev/ml_options.c | 12 +- app/test-mldev/ml_options.h | 2 + app/test-mldev/test_inference_common.c | 160 ++++++++++++++++++++++++- app/test-mldev/test_inference_common.h | 4 + doc/guides/tools/testmldev.rst | 24 ++++ 5 files changed, 199 insertions(+), 3 deletions(-) diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index 649cb9d8d1..19f2e1279e 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -24,6 +24,7 @@ ml_options_default(struct ml_options *opt) opt->socket_id = SOCKET_ID_ANY; opt->nb_filelist = 0; opt->repetitions = 1; + opt->burst_size = 1; opt->debug = false; } @@ -145,6 +146,12 @@ ml_parse_repetitions(struct ml_options *opt, const char *arg) return parser_read_uint64(&opt->repetitions, arg); } +static int +ml_parse_burst_size(struct ml_options *opt, const char *arg) +{ + return parser_read_uint16(&opt->burst_size, arg); +} + static void ml_dump_test_options(const char *testname) { @@ -159,7 +166,8 @@ ml_dump_test_options(const char *testname) if ((strcmp(testname, "inference_ordered") == 0) || (strcmp(testname, "inference_interleave") == 0)) { printf("\t\t--filelist : comma separated list of model, input and output\n" - "\t\t--repetitions : number of inference repetitions\n"); + "\t\t--repetitions : number of inference repetitions\n" + "\t\t--burst_size : inference burst size\n"); printf("\n"); } } @@ -186,6 +194,7 @@ static struct option lgopts[] = { {ML_MODELS, 1, 0, 0}, {ML_FILELIST, 1, 0, 0}, {ML_REPETITIONS, 1, 0, 0}, + {ML_BURST_SIZE, 1, 0, 0}, {ML_DEBUG, 0, 0, 0}, {ML_HELP, 0, 0, 0}, {NULL, 0, 0, 0}}; @@ -202,6 +211,7 @@ ml_opts_parse_long(int opt_idx, struct ml_options *opt) {ML_MODELS, ml_parse_models}, {ML_FILELIST, ml_parse_filelist}, {ML_REPETITIONS, ml_parse_repetitions}, + {ML_BURST_SIZE, ml_parse_burst_size}, }; for (i = 0; i < RTE_DIM(parsermap); i++) { diff --git a/app/test-mldev/ml_options.h b/app/test-mldev/ml_options.h index 6a13f97a30..00342d8a0c 100644 --- a/app/test-mldev/ml_options.h +++ b/app/test-mldev/ml_options.h @@ -18,6 +18,7 @@ #define ML_MODELS ("models") #define ML_FILELIST ("filelist") #define ML_REPETITIONS ("repetitions") +#define ML_BURST_SIZE ("burst_size") #define ML_DEBUG ("debug") #define ML_HELP ("help") @@ -34,6 +35,7 @@ struct ml_options { struct ml_filelist filelist[ML_TEST_MAX_MODELS]; uint8_t nb_filelist; uint64_t repetitions; + uint16_t burst_size; bool debug; }; diff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c index 6a6999d524..35323306de 100644 --- a/app/test-mldev/test_inference_common.c +++ b/app/test-mldev/test_inference_common.c @@ -124,6 +124,132 @@ ml_dequeue_single(void *arg) return 0; } +/* Enqueue inference requests with burst size greater than 1 */ +static int +ml_enqueue_burst(void *arg) +{ + struct test_inference *t = ml_test_priv((struct ml_test *)arg); + struct ml_core_args *args; + uint16_t ops_count; + uint64_t model_enq; + uint16_t burst_enq; + uint32_t lcore_id; + uint16_t pending; + uint16_t idx; + uint16_t fid; + uint16_t i; + int ret; + + lcore_id = rte_lcore_id(); + args = &t->args[lcore_id]; + model_enq = 0; + + if (args->nb_reqs == 0) + return 0; + +next_rep: + fid = args->start_fid; + +next_model: + ops_count = RTE_MIN(t->cmn.opt->burst_size, args->nb_reqs - model_enq); + ret = rte_mempool_get_bulk(t->op_pool, (void **)args->enq_ops, ops_count); + if (ret != 0) + goto next_model; + +retry: + ret = rte_mempool_get_bulk(t->model[fid].io_pool, (void **)args->reqs, ops_count); + if (ret != 0) + goto retry; + + for (i = 0; i < ops_count; i++) { + args->enq_ops[i]->model_id = t->model[fid].id; + args->enq_ops[i]->nb_batches = t->model[fid].info.batch_size; + args->enq_ops[i]->mempool = t->op_pool; + + args->enq_ops[i]->input.addr = args->reqs[i]->input; + args->enq_ops[i]->input.length = t->model[fid].inp_qsize; + args->enq_ops[i]->input.next = NULL; + + args->enq_ops[i]->output.addr = args->reqs[i]->output; + args->enq_ops[i]->output.length = t->model[fid].out_qsize; + args->enq_ops[i]->output.next = NULL; + + args->enq_ops[i]->user_ptr = args->reqs[i]; + args->reqs[i]->niters++; + args->reqs[i]->fid = fid; + } + + idx = 0; + pending = ops_count; + +enqueue_reqs: + burst_enq = rte_ml_enqueue_burst(t->cmn.opt->dev_id, 0, &args->enq_ops[idx], pending); + pending = pending - burst_enq; + + if (pending > 0) { + idx = idx + burst_enq; + goto enqueue_reqs; + } + + fid++; + if (fid <= args->end_fid) + goto next_model; + + model_enq = model_enq + ops_count; + if (model_enq < args->nb_reqs) + goto next_rep; + + return 0; +} + +/* Dequeue inference requests with burst size greater than 1 */ +static int +ml_dequeue_burst(void *arg) +{ + struct test_inference *t = ml_test_priv((struct ml_test *)arg); + struct rte_ml_op_error error; + struct ml_core_args *args; + struct ml_request *req; + uint64_t total_deq = 0; + uint16_t burst_deq = 0; + uint8_t nb_filelist; + uint32_t lcore_id; + uint32_t i; + + lcore_id = rte_lcore_id(); + args = &t->args[lcore_id]; + nb_filelist = args->end_fid - args->start_fid + 1; + + if (args->nb_reqs == 0) + return 0; + +dequeue_burst: + burst_deq = + rte_ml_dequeue_burst(t->cmn.opt->dev_id, 0, args->deq_ops, t->cmn.opt->burst_size); + + if (likely(burst_deq > 0)) { + total_deq += burst_deq; + + for (i = 0; i < burst_deq; i++) { + if (unlikely(args->deq_ops[i]->status == RTE_ML_OP_STATUS_ERROR)) { + rte_ml_op_error_get(t->cmn.opt->dev_id, args->deq_ops[i], &error); + ml_err("error_code = 0x%" PRIx64 ", error_message = %s\n", + error.errcode, error.message); + t->error_count[lcore_id]++; + } + req = (struct ml_request *)args->deq_ops[i]->user_ptr; + if (req != NULL) + rte_mempool_put(t->model[req->fid].io_pool, req); + } + rte_mempool_put_bulk(t->op_pool, (void *)args->deq_ops, burst_deq); + } + + if (total_deq < args->nb_reqs * nb_filelist) + goto dequeue_burst; + + return 0; +} + bool test_inference_cap_check(struct ml_options *opt) { @@ -173,6 +299,17 @@ test_inference_opt_check(struct ml_options *opt) return -EINVAL; } + if (opt->burst_size == 0) { + ml_err("Invalid option, burst_size = %u\n", opt->burst_size); + return -EINVAL; + } + + if (opt->burst_size > ML_TEST_MAX_POOL_SIZE) { + ml_err("Invalid option, burst_size = %u (> max supported = %d)\n", opt->burst_size, + ML_TEST_MAX_POOL_SIZE); + return -EINVAL; + } + /* check number of available lcores. */ if (rte_lcore_count() < 3) { ml_err("Insufficient lcores = %u\n", rte_lcore_count()); @@ -193,6 +330,7 @@ test_inference_opt_dump(struct ml_options *opt) /* dump test opts */ ml_dump("repetitions", "%" PRIu64, opt->repetitions); + ml_dump("burst_size", "%u", opt->burst_size); ml_dump_begin("filelist"); for (i = 0; i < opt->nb_filelist; i++) { @@ -208,6 +346,7 @@ test_inference_setup(struct ml_test *test, struct ml_options *opt) { struct test_inference *t; void *test_inference; + uint32_t lcore_id; int ret = 0; uint32_t i; @@ -233,13 +372,30 @@ test_inference_setup(struct ml_test *test, struct ml_options *opt) goto error; } - t->enqueue = ml_enqueue_single; - t->dequeue = ml_dequeue_single; + if (opt->burst_size == 1) { + t->enqueue = ml_enqueue_single; + t->dequeue = ml_dequeue_single; + } else { + t->enqueue = ml_enqueue_burst; + t->dequeue = ml_dequeue_burst; + } /* set model initial state */ for (i = 0; i < opt->nb_filelist; i++) t->model[i].state = MODEL_INITIAL; + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + t->args[lcore_id].enq_ops = rte_zmalloc_socket( + "ml_test_enq_ops", opt->burst_size * sizeof(struct rte_ml_op *), + RTE_CACHE_LINE_SIZE, opt->socket_id); + t->args[lcore_id].deq_ops = rte_zmalloc_socket( + "ml_test_deq_ops", opt->burst_size * sizeof(struct rte_ml_op *), + RTE_CACHE_LINE_SIZE, opt->socket_id); + t->args[lcore_id].reqs = rte_zmalloc_socket( + "ml_test_requests", opt->burst_size * sizeof(struct ml_request *), + RTE_CACHE_LINE_SIZE, opt->socket_id); + } + return 0; error: diff --git a/app/test-mldev/test_inference_common.h b/app/test-mldev/test_inference_common.h index abb20fc9fb..da800f2bd4 100644 --- a/app/test-mldev/test_inference_common.h +++ b/app/test-mldev/test_inference_common.h @@ -22,6 +22,10 @@ struct ml_core_args { uint64_t nb_reqs; uint16_t start_fid; uint16_t end_fid; + + struct rte_ml_op **enq_ops; + struct rte_ml_op **deq_ops; + struct ml_request **reqs; }; struct test_inference { diff --git a/doc/guides/tools/testmldev.rst b/doc/guides/tools/testmldev.rst index 1a1ab7d2bf..eb9081723b 100644 --- a/doc/guides/tools/testmldev.rst +++ b/doc/guides/tools/testmldev.rst @@ -91,6 +91,10 @@ The following are the command-line options supported by the test application. Set the number of inference repetitions to be executed in the test per each model. Default value is `1`. +* ``--burst_size `` + + Set the burst size to be used when enqueuing / dequeuing inferences. Default value is `1`. + * ``--debug`` Enable the tests to run in debug mode. @@ -236,6 +240,7 @@ Supported command line options for inference tests are following:: --socket_id --filelist --repetitions + --burst_size List of files to be used for the inference tests can be specified through the option @@ -244,6 +249,9 @@ List of files to be used for the inference tests can be specified through the op list of files required to test with a single model. Multiple filelist entries are supported by the test, one entry per model. Maximum number of file entries supported by the test is `8`. +When ``--burst_size `` option is specified for the test, enqueue and dequeue burst would +try to enqueue or dequeue ``num`` number of inferences per each call respectively. + .. Note:: * The ``--filelist `` is a mandatory option for running inference tests. @@ -280,6 +288,14 @@ Example command to run inference_ordered test: sudo /app/dpdk-test-mldev -c 0xf -a -- \ --test=inference_ordered --filelist model.bin,input.bin,output.bin +Example command to run inference_ordered test with a specific burst size: + +.. code-block:: console + + sudo /app/dpdk-test-mldev -c 0xf -a -- \ + --test=inference_ordered --filelist model.bin,input.bin,output.bin \ + --burst_size 12 + INFERENCE_INTERLEAVE Test ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -320,6 +336,14 @@ Example command to run inference_interleave test with multiple models: --test=inference_interleave --filelist model_A.bin,input_A.bin,output_A.bin \ --filelist model_B.bin,input_B.bin,output_B.bin +Example command to run inference_interleave test with a specific burst size: + +.. code-block:: console + + sudo /app/dpdk-test-mldev -c 0xf -a -- \ + --test=inference_interleave --filelist model.bin,input.bin,output.bin \ + --burst_size 16 + Debug mode ---------- From patchwork Thu Mar 16 21:14:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 125207 X-Patchwork-Delegate: thomas@monjalon.net 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 55E3441EB5; Thu, 16 Mar 2023 22:15:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 27DF342FC2; Thu, 16 Mar 2023 22:14:55 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 7FF1C42DB9 for ; Thu, 16 Mar 2023 22:14:45 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32GKcQte004129 for ; Thu, 16 Mar 2023 14:14:44 -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-type; s=pfpt0220; bh=OKZBqFRQtaQMtbXjcww0pm1Y1f1poxrz93nuObMwdgk=; b=NB1Dx3mE0q33xeQQto5aeAh6Z3x2Zo1Gv7kjUsWQHGCb7/z1tdVn8fOpP8Ylen8Gbttu Cye1cqS6QgvTMz5xMHnKKEg+Enmytr2oc4e8DJGCYFH82JENJGE9qC8WUhDNKjPnCxrx gYG6CSkPrTM+0BE0anEzaLvBe4fR9W4e90o7zyXKMm50rIByYHH5NLKElBy3d5IhfwzW q7z4rlDo1pXZyo3vi3ORY5icyXpSt2or3xVPs0S4k9pJGya1wkozgX0+QkufCIKlMNew 4caNQxN1UwOKfCnj4IrzlZjnbPj/Jh4U2OUGV2oxH3b9roc0GneYsKmONJEkXkzvXHsJ oQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3pbxq2ub11-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 16 Mar 2023 14:14:44 -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.42; Thu, 16 Mar 2023 14:14:40 -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.42 via Frontend Transport; Thu, 16 Mar 2023 14:14:40 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id E934E3F707A; Thu, 16 Mar 2023 14:14:40 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v7 08/11] app/mldev: enable support for queue pairs and size Date: Thu, 16 Mar 2023 14:14:31 -0700 Message-ID: <20230316211434.13409-9-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316211434.13409-1-syalavarthi@marvell.com> References: <20221129070746.20396-1-syalavarthi@marvell.com> <20230316211434.13409-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: YB3tSSPivINZOzRvTZL9MReXSJkGq1eB X-Proofpoint-ORIG-GUID: YB3tSSPivINZOzRvTZL9MReXSJkGq1eB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 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 create multiple queue-pairs per device to enqueue and dequeue inference requests. Number of queue pairs to be created can be specified through "--queue_pairs" option. Support is also enabled to control the number of descriptors per each queue pair through "--queue_size" option. Inference requests for a model are distributed across all available queue-pairs. Signed-off-by: Srikanth Yalavarthi Acked-by: Anup Prabhu --- app/test-mldev/ml_options.c | 31 +++++++++- app/test-mldev/ml_options.h | 4 ++ app/test-mldev/test_common.c | 2 +- app/test-mldev/test_inference_common.c | 79 +++++++++++++++++++++----- app/test-mldev/test_inference_common.h | 1 + doc/guides/tools/testmldev.rst | 44 +++++++++++++- 6 files changed, 140 insertions(+), 21 deletions(-) diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index 19f2e1279e..901adaed33 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -25,6 +25,8 @@ ml_options_default(struct ml_options *opt) opt->nb_filelist = 0; opt->repetitions = 1; opt->burst_size = 1; + opt->queue_pairs = 1; + opt->queue_size = 1; opt->debug = false; } @@ -152,11 +154,30 @@ ml_parse_burst_size(struct ml_options *opt, const char *arg) return parser_read_uint16(&opt->burst_size, arg); } +static int +ml_parse_queue_pairs(struct ml_options *opt, const char *arg) +{ + int ret; + + ret = parser_read_uint16(&opt->queue_pairs, arg); + + return ret; +} + +static int +ml_parse_queue_size(struct ml_options *opt, const char *arg) +{ + return parser_read_uint16(&opt->queue_size, arg); +} + static void ml_dump_test_options(const char *testname) { - if (strcmp(testname, "device_ops") == 0) + if (strcmp(testname, "device_ops") == 0) { + printf("\t\t--queue_pairs : number of queue pairs to create\n" + "\t\t--queue_size : size fo queue-pair\n"); printf("\n"); + } if (strcmp(testname, "model_ops") == 0) { printf("\t\t--models : comma separated list of models\n"); @@ -167,7 +188,9 @@ ml_dump_test_options(const char *testname) (strcmp(testname, "inference_interleave") == 0)) { printf("\t\t--filelist : comma separated list of model, input and output\n" "\t\t--repetitions : number of inference repetitions\n" - "\t\t--burst_size : inference burst size\n"); + "\t\t--burst_size : inference burst size\n" + "\t\t--queue_pairs : number of queue pairs to create\n" + "\t\t--queue_size : size fo queue-pair\n"); printf("\n"); } } @@ -195,6 +218,8 @@ static struct option lgopts[] = { {ML_FILELIST, 1, 0, 0}, {ML_REPETITIONS, 1, 0, 0}, {ML_BURST_SIZE, 1, 0, 0}, + {ML_QUEUE_PAIRS, 1, 0, 0}, + {ML_QUEUE_SIZE, 1, 0, 0}, {ML_DEBUG, 0, 0, 0}, {ML_HELP, 0, 0, 0}, {NULL, 0, 0, 0}}; @@ -212,6 +237,8 @@ ml_opts_parse_long(int opt_idx, struct ml_options *opt) {ML_FILELIST, ml_parse_filelist}, {ML_REPETITIONS, ml_parse_repetitions}, {ML_BURST_SIZE, ml_parse_burst_size}, + {ML_QUEUE_PAIRS, ml_parse_queue_pairs}, + {ML_QUEUE_SIZE, ml_parse_queue_size}, }; for (i = 0; i < RTE_DIM(parsermap); i++) { diff --git a/app/test-mldev/ml_options.h b/app/test-mldev/ml_options.h index 00342d8a0c..c4018ee9d1 100644 --- a/app/test-mldev/ml_options.h +++ b/app/test-mldev/ml_options.h @@ -19,6 +19,8 @@ #define ML_FILELIST ("filelist") #define ML_REPETITIONS ("repetitions") #define ML_BURST_SIZE ("burst_size") +#define ML_QUEUE_PAIRS ("queue_pairs") +#define ML_QUEUE_SIZE ("queue_size") #define ML_DEBUG ("debug") #define ML_HELP ("help") @@ -36,6 +38,8 @@ struct ml_options { uint8_t nb_filelist; uint64_t repetitions; uint16_t burst_size; + uint16_t queue_pairs; + uint16_t queue_size; bool debug; }; diff --git a/app/test-mldev/test_common.c b/app/test-mldev/test_common.c index 8c4da4609a..016b31c6ba 100644 --- a/app/test-mldev/test_common.c +++ b/app/test-mldev/test_common.c @@ -75,7 +75,7 @@ ml_test_device_configure(struct ml_test *test, struct ml_options *opt) /* configure device */ dev_config.socket_id = opt->socket_id; dev_config.nb_models = t->dev_info.max_models; - dev_config.nb_queue_pairs = t->dev_info.max_queue_pairs; + dev_config.nb_queue_pairs = opt->queue_pairs; ret = rte_ml_dev_configure(opt->dev_id, &dev_config); if (ret != 0) { ml_err("Failed to configure ml device, dev_id = %d\n", opt->dev_id); diff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c index 35323306de..b4ad3c4b72 100644 --- a/app/test-mldev/test_inference_common.c +++ b/app/test-mldev/test_inference_common.c @@ -66,7 +66,7 @@ ml_enqueue_single(void *arg) req->fid = fid; enqueue_req: - burst_enq = rte_ml_enqueue_burst(t->cmn.opt->dev_id, 0, &op, 1); + burst_enq = rte_ml_enqueue_burst(t->cmn.opt->dev_id, args->qp_id, &op, 1); if (burst_enq == 0) goto enqueue_req; @@ -103,7 +103,7 @@ ml_dequeue_single(void *arg) return 0; dequeue_req: - burst_deq = rte_ml_dequeue_burst(t->cmn.opt->dev_id, 0, &op, 1); + burst_deq = rte_ml_dequeue_burst(t->cmn.opt->dev_id, args->qp_id, &op, 1); if (likely(burst_deq == 1)) { total_deq += burst_deq; @@ -183,7 +183,8 @@ ml_enqueue_burst(void *arg) pending = ops_count; enqueue_reqs: - burst_enq = rte_ml_enqueue_burst(t->cmn.opt->dev_id, 0, &args->enq_ops[idx], pending); + burst_enq = + rte_ml_enqueue_burst(t->cmn.opt->dev_id, args->qp_id, &args->enq_ops[idx], pending); pending = pending - burst_enq; if (pending > 0) { @@ -224,8 +225,8 @@ ml_dequeue_burst(void *arg) return 0; dequeue_burst: - burst_deq = - rte_ml_dequeue_burst(t->cmn.opt->dev_id, 0, args->deq_ops, t->cmn.opt->burst_size); + burst_deq = rte_ml_dequeue_burst(t->cmn.opt->dev_id, args->qp_id, args->deq_ops, + t->cmn.opt->burst_size); if (likely(burst_deq > 0)) { total_deq += burst_deq; @@ -259,6 +260,19 @@ test_inference_cap_check(struct ml_options *opt) return false; rte_ml_dev_info_get(opt->dev_id, &dev_info); + + if (opt->queue_pairs > dev_info.max_queue_pairs) { + ml_err("Insufficient capabilities: queue_pairs = %u, max_queue_pairs = %u", + opt->queue_pairs, dev_info.max_queue_pairs); + return false; + } + + if (opt->queue_size > dev_info.max_desc) { + ml_err("Insufficient capabilities: queue_size = %u, max_desc = %u", opt->queue_size, + dev_info.max_desc); + return false; + } + if (opt->nb_filelist > dev_info.max_models) { ml_err("Insufficient capabilities: Filelist count exceeded device limit, count = %u (max limit = %u)", opt->nb_filelist, dev_info.max_models); @@ -310,10 +324,21 @@ test_inference_opt_check(struct ml_options *opt) return -EINVAL; } + if (opt->queue_pairs == 0) { + ml_err("Invalid option, queue_pairs = %u\n", opt->queue_pairs); + return -EINVAL; + } + + if (opt->queue_size == 0) { + ml_err("Invalid option, queue_size = %u\n", opt->queue_size); + return -EINVAL; + } + /* check number of available lcores. */ - if (rte_lcore_count() < 3) { + if (rte_lcore_count() < (uint32_t)(opt->queue_pairs * 2 + 1)) { ml_err("Insufficient lcores = %u\n", rte_lcore_count()); - ml_err("Minimum lcores required to create %u queue-pairs = %u\n", 1, 3); + ml_err("Minimum lcores required to create %u queue-pairs = %u\n", opt->queue_pairs, + (opt->queue_pairs * 2 + 1)); return -EINVAL; } @@ -331,6 +356,8 @@ test_inference_opt_dump(struct ml_options *opt) /* dump test opts */ ml_dump("repetitions", "%" PRIu64, opt->repetitions); ml_dump("burst_size", "%u", opt->burst_size); + ml_dump("queue_pairs", "%u", opt->queue_pairs); + ml_dump("queue_size", "%u", opt->queue_size); ml_dump_begin("filelist"); for (i = 0; i < opt->nb_filelist; i++) { @@ -422,23 +449,31 @@ ml_inference_mldev_setup(struct ml_test *test, struct ml_options *opt) { struct rte_ml_dev_qp_conf qp_conf; struct test_inference *t; + uint16_t qp_id; int ret; t = ml_test_priv(test); + RTE_SET_USED(t); + ret = ml_test_device_configure(test, opt); if (ret != 0) return ret; /* setup queue pairs */ - qp_conf.nb_desc = t->cmn.dev_info.max_desc; + qp_conf.nb_desc = opt->queue_size; qp_conf.cb = NULL; - ret = rte_ml_dev_queue_pair_setup(opt->dev_id, 0, &qp_conf, opt->socket_id); - if (ret != 0) { - ml_err("Failed to setup ml device queue-pair, dev_id = %d, qp_id = %u\n", - opt->dev_id, 0); - goto error; + for (qp_id = 0; qp_id < opt->queue_pairs; qp_id++) { + qp_conf.nb_desc = opt->queue_size; + qp_conf.cb = NULL; + + ret = rte_ml_dev_queue_pair_setup(opt->dev_id, qp_id, &qp_conf, opt->socket_id); + if (ret != 0) { + ml_err("Failed to setup ml device queue-pair, dev_id = %d, qp_id = %u\n", + opt->dev_id, qp_id); + return ret; + } } ret = ml_test_device_start(test, opt); @@ -700,14 +735,28 @@ ml_inference_launch_cores(struct ml_test *test, struct ml_options *opt, uint16_t { struct test_inference *t = ml_test_priv(test); uint32_t lcore_id; + uint32_t nb_reqs; uint32_t id = 0; + uint32_t qp_id; + + nb_reqs = opt->repetitions / opt->queue_pairs; RTE_LCORE_FOREACH_WORKER(lcore_id) { - if (id == 2) + if (id >= opt->queue_pairs * 2) break; - t->args[lcore_id].nb_reqs = opt->repetitions; + qp_id = id / 2; + t->args[lcore_id].qp_id = qp_id; + t->args[lcore_id].nb_reqs = nb_reqs; + if (qp_id == 0) + t->args[lcore_id].nb_reqs += opt->repetitions - nb_reqs * opt->queue_pairs; + + if (t->args[lcore_id].nb_reqs == 0) { + id++; + break; + } + t->args[lcore_id].start_fid = start_fid; t->args[lcore_id].end_fid = end_fid; diff --git a/app/test-mldev/test_inference_common.h b/app/test-mldev/test_inference_common.h index da800f2bd4..81d9b07d41 100644 --- a/app/test-mldev/test_inference_common.h +++ b/app/test-mldev/test_inference_common.h @@ -22,6 +22,7 @@ struct ml_core_args { uint64_t nb_reqs; uint16_t start_fid; uint16_t end_fid; + uint32_t qp_id; struct rte_ml_op **enq_ops; struct rte_ml_op **deq_ops; diff --git a/doc/guides/tools/testmldev.rst b/doc/guides/tools/testmldev.rst index eb9081723b..17ee2cf7fb 100644 --- a/doc/guides/tools/testmldev.rst +++ b/doc/guides/tools/testmldev.rst @@ -95,6 +95,17 @@ The following are the command-line options supported by the test application. Set the burst size to be used when enqueuing / dequeuing inferences. Default value is `1`. +* ``--queue_pairs `` + + Set the number of queue-pairs to be used for inference enqueue and dequeue operations. + Default value is `1`. + +* ``--queue_size `` + + Set the size of queue-pair to be created for inference enqueue / dequeue operations. + Queue size would translate into `rte_ml_dev_qp_conf::nb_desc` field during queue-pair + creation. Default value is `1`. + * ``--debug`` Enable the tests to run in debug mode. @@ -120,12 +131,17 @@ Supported command line options for the `device_ops` test are following:: --test --dev_id --socket_id + --queue_pairs + --queue_size DEVICE_OPS Test ~~~~~~~~~~~~~~~ -Device ops test validates the device configuration and reconfiguration. +Device ops test validates the device configuration and reconfiguration support. The test configures +ML device based on the option ``--queue_pairs`` and ``--queue_size`` specified by the user, and +later reconfigures the ML device with the number of queue pairs and queue size based the maximum +specified through the device info. Example @@ -139,6 +155,14 @@ Command to run device_ops test: --test=device_ops +Command to run device_ops test with user options: + +.. code-block:: console + + sudo /app/dpdk-test-mldev -c 0xf -a -- \ + --test=device_ops --queue_pairs --queue_size + + ML Model Tests ------------------------- @@ -241,6 +265,8 @@ Supported command line options for inference tests are following:: --filelist --repetitions --burst_size + --queue_pairs + --queue_size List of files to be used for the inference tests can be specified through the option @@ -252,6 +278,9 @@ the test, one entry per model. Maximum number of file entries supported by the t When ``--burst_size `` option is specified for the test, enqueue and dequeue burst would try to enqueue or dequeue ``num`` number of inferences per each call respectively. +In the inference test, a pair of lcores are mapped to each queue pair. Minimum number of lcores +required for the tests is equal to ``(queue_pairs * 2 + 1)``. + .. Note:: * The ``--filelist `` is a mandatory option for running inference tests. @@ -296,6 +325,14 @@ Example command to run inference_ordered test with a specific burst size: --test=inference_ordered --filelist model.bin,input.bin,output.bin \ --burst_size 12 +Example command to run inference_ordered test with multiple queue-pairs and queue size: + +.. code-block:: console + + sudo /app/dpdk-test-mldev -c 0xf -a -- \ + --test=inference_ordered --filelist model.bin,input.bin,output.bin \ + --queue_pairs 4 --queue_size 16 + INFERENCE_INTERLEAVE Test ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -336,13 +373,14 @@ Example command to run inference_interleave test with multiple models: --test=inference_interleave --filelist model_A.bin,input_A.bin,output_A.bin \ --filelist model_B.bin,input_B.bin,output_B.bin -Example command to run inference_interleave test with a specific burst size: +Example command to run inference_interleave test with a specific burst size, multiple queue-pairs +and queue size: .. code-block:: console sudo /app/dpdk-test-mldev -c 0xf -a -- \ --test=inference_interleave --filelist model.bin,input.bin,output.bin \ - --burst_size 16 + --queue_pairs 8 --queue_size 12 --burst_size 16 Debug mode From patchwork Thu Mar 16 21:14:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 125206 X-Patchwork-Delegate: thomas@monjalon.net 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 6BBF041EB5; Thu, 16 Mar 2023 22:15:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0021F42FBA; Thu, 16 Mar 2023 22:14:53 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 6598142DB3 for ; Thu, 16 Mar 2023 22:14:45 +0100 (CET) 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 32GJMmij016125 for ; Thu, 16 Mar 2023 14:14:44 -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-type; s=pfpt0220; bh=dksc2eMAKKufECaymGGvWGesgmpqiis4rGJpiD/vNZs=; b=PWSTJyaMC4hgc7F6evsY9G/xT/lSnDQN8QOOYvIoZgfwCj91nQ8Ik68E2w4aSdSUplFF MC4vWZpA/yP400rde6S9p//rPbH/26i1MVHHymeqCnrAf2Nztrbkvna/T+tQQwb9JKvw MxFVEW91XNbrgm3xOGBEYYYZmpKpAkvLMLDlOwYCrCHVXVAwISqgT+Oo5z1nXJYbk9KT 5HII4SkzyamMN+GFMRPP0ZCEMhTR64XisHKrg8dDLRd/0ZT6qE2CGbGF/q8Z5jSChmun S230dofuwsEEUsdjgV5/aEu3Uhw7lUoBkkpa2hCLAkfO8wUjh1tCIJSEOCYnr0dTQS2u /Q== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3pbs2u3mk5-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 16 Mar 2023 14:14:44 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 16 Mar 2023 14:14:41 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 16 Mar 2023 14:14:41 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 22E1E3F707C; Thu, 16 Mar 2023 14:14:41 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v7 09/11] app/mldev: enable support for inference batches Date: Thu, 16 Mar 2023 14:14:32 -0700 Message-ID: <20230316211434.13409-10-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316211434.13409-1-syalavarthi@marvell.com> References: <20221129070746.20396-1-syalavarthi@marvell.com> <20230316211434.13409-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: jDstgyW15OH01BLhTnjn6e8Oc9aebD9H X-Proofpoint-ORIG-GUID: jDstgyW15OH01BLhTnjn6e8Oc9aebD9H X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 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 Enabled support to execute multiple batches of inferences per each enqueue request. Input and reference for the test should be appropriately provided for multi-batch run. Number of batches can be specified through "--batches" option. Signed-off-by: Srikanth Yalavarthi Acked-by: Anup Prabhu --- app/test-mldev/ml_options.c | 12 +++++++++++- app/test-mldev/ml_options.h | 2 ++ app/test-mldev/test_inference_common.c | 22 +++++++++++++--------- app/test-mldev/test_model_common.c | 6 ++++++ app/test-mldev/test_model_common.h | 1 + doc/guides/tools/testmldev.rst | 6 ++++++ 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index 901adaed33..44df44991b 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -27,6 +27,7 @@ ml_options_default(struct ml_options *opt) opt->burst_size = 1; opt->queue_pairs = 1; opt->queue_size = 1; + opt->batches = 0; opt->debug = false; } @@ -170,6 +171,12 @@ ml_parse_queue_size(struct ml_options *opt, const char *arg) return parser_read_uint16(&opt->queue_size, arg); } +static int +ml_parse_batches(struct ml_options *opt, const char *arg) +{ + return parser_read_uint16(&opt->batches, arg); +} + static void ml_dump_test_options(const char *testname) { @@ -190,7 +197,8 @@ ml_dump_test_options(const char *testname) "\t\t--repetitions : number of inference repetitions\n" "\t\t--burst_size : inference burst size\n" "\t\t--queue_pairs : number of queue pairs to create\n" - "\t\t--queue_size : size fo queue-pair\n"); + "\t\t--queue_size : size fo queue-pair\n" + "\t\t--batches : number of batches of input\n"); printf("\n"); } } @@ -220,6 +228,7 @@ static struct option lgopts[] = { {ML_BURST_SIZE, 1, 0, 0}, {ML_QUEUE_PAIRS, 1, 0, 0}, {ML_QUEUE_SIZE, 1, 0, 0}, + {ML_BATCHES, 1, 0, 0}, {ML_DEBUG, 0, 0, 0}, {ML_HELP, 0, 0, 0}, {NULL, 0, 0, 0}}; @@ -239,6 +248,7 @@ ml_opts_parse_long(int opt_idx, struct ml_options *opt) {ML_BURST_SIZE, ml_parse_burst_size}, {ML_QUEUE_PAIRS, ml_parse_queue_pairs}, {ML_QUEUE_SIZE, ml_parse_queue_size}, + {ML_BATCHES, ml_parse_batches}, }; for (i = 0; i < RTE_DIM(parsermap); i++) { diff --git a/app/test-mldev/ml_options.h b/app/test-mldev/ml_options.h index c4018ee9d1..48fe064150 100644 --- a/app/test-mldev/ml_options.h +++ b/app/test-mldev/ml_options.h @@ -21,6 +21,7 @@ #define ML_BURST_SIZE ("burst_size") #define ML_QUEUE_PAIRS ("queue_pairs") #define ML_QUEUE_SIZE ("queue_size") +#define ML_BATCHES ("batches") #define ML_DEBUG ("debug") #define ML_HELP ("help") @@ -40,6 +41,7 @@ struct ml_options { uint16_t burst_size; uint16_t queue_pairs; uint16_t queue_size; + uint16_t batches; bool debug; }; diff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c index b4ad3c4b72..0f281aed6c 100644 --- a/app/test-mldev/test_inference_common.c +++ b/app/test-mldev/test_inference_common.c @@ -50,7 +50,7 @@ ml_enqueue_single(void *arg) goto retry; op->model_id = t->model[fid].id; - op->nb_batches = t->model[fid].info.batch_size; + op->nb_batches = t->model[fid].nb_batches; op->mempool = t->op_pool; op->input.addr = req->input; @@ -163,7 +163,7 @@ ml_enqueue_burst(void *arg) for (i = 0; i < ops_count; i++) { args->enq_ops[i]->model_id = t->model[fid].id; - args->enq_ops[i]->nb_batches = t->model[fid].info.batch_size; + args->enq_ops[i]->nb_batches = t->model[fid].nb_batches; args->enq_ops[i]->mempool = t->op_pool; args->enq_ops[i]->input.addr = args->reqs[i]->input; @@ -359,6 +359,11 @@ test_inference_opt_dump(struct ml_options *opt) ml_dump("queue_pairs", "%u", opt->queue_pairs); ml_dump("queue_size", "%u", opt->queue_size); + if (opt->batches == 0) + ml_dump("batches", "%u (default)", opt->batches); + else + ml_dump("batches", "%u", opt->batches); + ml_dump_begin("filelist"); for (i = 0; i < opt->nb_filelist; i++) { ml_dump_list("model", i, opt->filelist[i].model); @@ -528,8 +533,8 @@ ml_request_initialize(struct rte_mempool *mp, void *opaque, void *obj, unsigned req->niters = 0; /* quantize data */ - rte_ml_io_quantize(t->cmn.opt->dev_id, t->model[t->fid].id, - t->model[t->fid].info.batch_size, t->model[t->fid].input, req->input); + rte_ml_io_quantize(t->cmn.opt->dev_id, t->model[t->fid].id, t->model[t->fid].nb_batches, + t->model[t->fid].input, req->input); } int @@ -547,7 +552,7 @@ ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t int ret; /* get input buffer size */ - ret = rte_ml_io_input_size_get(opt->dev_id, t->model[fid].id, t->model[fid].info.batch_size, + ret = rte_ml_io_input_size_get(opt->dev_id, t->model[fid].id, t->model[fid].nb_batches, &t->model[fid].inp_qsize, &t->model[fid].inp_dsize); if (ret != 0) { ml_err("Failed to get input size, model : %s\n", opt->filelist[fid].model); @@ -555,9 +560,8 @@ ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t } /* get output buffer size */ - ret = rte_ml_io_output_size_get(opt->dev_id, t->model[fid].id, - t->model[fid].info.batch_size, &t->model[fid].out_qsize, - &t->model[fid].out_dsize); + ret = rte_ml_io_output_size_get(opt->dev_id, t->model[fid].id, t->model[fid].nb_batches, + &t->model[fid].out_qsize, &t->model[fid].out_dsize); if (ret != 0) { ml_err("Failed to get input size, model : %s\n", opt->filelist[fid].model); return ret; @@ -702,7 +706,7 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int return; t->nb_used++; - rte_ml_io_dequantize(t->cmn.opt->dev_id, model->id, t->model[req->fid].info.batch_size, + rte_ml_io_dequantize(t->cmn.opt->dev_id, model->id, t->model[req->fid].nb_batches, req->output, model->output); } diff --git a/app/test-mldev/test_model_common.c b/app/test-mldev/test_model_common.c index b94d46154d..c28e452f29 100644 --- a/app/test-mldev/test_model_common.c +++ b/app/test-mldev/test_model_common.c @@ -71,6 +71,12 @@ ml_model_load(struct ml_test *test, struct ml_options *opt, struct ml_model *mod return ret; } + /* Update number of batches */ + if (opt->batches == 0) + model->nb_batches = model->info.batch_size; + else + model->nb_batches = opt->batches; + model->state = MODEL_LOADED; return 0; diff --git a/app/test-mldev/test_model_common.h b/app/test-mldev/test_model_common.h index 5ee975109d..19429ce142 100644 --- a/app/test-mldev/test_model_common.h +++ b/app/test-mldev/test_model_common.h @@ -30,6 +30,7 @@ struct ml_model { uint8_t *output; struct rte_mempool *io_pool; + uint32_t nb_batches; }; int ml_model_load(struct ml_test *test, struct ml_options *opt, struct ml_model *model, diff --git a/doc/guides/tools/testmldev.rst b/doc/guides/tools/testmldev.rst index 17ee2cf7fb..6632025fdf 100644 --- a/doc/guides/tools/testmldev.rst +++ b/doc/guides/tools/testmldev.rst @@ -106,6 +106,11 @@ The following are the command-line options supported by the test application. Queue size would translate into `rte_ml_dev_qp_conf::nb_desc` field during queue-pair creation. Default value is `1`. +* ``--batches `` + + Set the number batches in the input file provided for inference run. When not specified + the test would assume the number of batches is equal to the batch size of the model. + * ``--debug`` Enable the tests to run in debug mode. @@ -267,6 +272,7 @@ Supported command line options for inference tests are following:: --burst_size --queue_pairs --queue_size + --batches List of files to be used for the inference tests can be specified through the option From patchwork Thu Mar 16 21:14:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 125208 X-Patchwork-Delegate: thomas@monjalon.net 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 B4E1341EB5; Thu, 16 Mar 2023 22:15:56 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 25D0942FCC; Thu, 16 Mar 2023 22:14:56 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id EE8D740DF6 for ; Thu, 16 Mar 2023 22:14:45 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32GKcQtf004129 for ; Thu, 16 Mar 2023 14:14:45 -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-type; s=pfpt0220; bh=or7ouVvdu4MbrDvN84EyOtw9S2Z/Gnb2oyumFeVB2Nw=; b=gRwvqY1FVAi6cFwIMdWCjATw8011m1+e6iYkpKcEhzD1yk1dkQ+cMxvbFKV7B4ykw85f Jn6ftQ8VEp9dbgREUpPL8lJ9UCZcy5kPJKUp8NYrctQ1QJw7vWLjoPVWl8vQ4veZqsee ao+gyD2mRYRhKrEZiMHzg1bH8GC8A6QMotr1jM9Ujx6Aap+InVPrWrN9tNMuTvJAgYCP b3I1eQuByAvF/fSSbinmR7E2hLGoDAHjUBxxWjEc7QAP5HcakErV6056cagB64qzdAfI YWZ8RsJ3Dplxt3mhMU+aHwvogdYqQd1BYog9FaaUCCj3jgZ7AuxGA6uk1hpwM0jrC6uH Qw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3pbxq2ub11-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 16 Mar 2023 14:14:44 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 16 Mar 2023 14:14:41 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 16 Mar 2023 14:14:41 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 4F7833F707D; Thu, 16 Mar 2023 14:14:41 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v7 10/11] app/mldev: enable support for inference validation Date: Thu, 16 Mar 2023 14:14:33 -0700 Message-ID: <20230316211434.13409-11-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316211434.13409-1-syalavarthi@marvell.com> References: <20221129070746.20396-1-syalavarthi@marvell.com> <20230316211434.13409-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: MhGRQ_JsqEUtFYAF6jZaiy_5bxUSkoAk X-Proofpoint-ORIG-GUID: MhGRQ_JsqEUtFYAF6jZaiy_5bxUSkoAk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 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 Enabled support to validate inference output with reference output provided by the user. Validation would be successful only when the inference outputs are within the 'tolerance' specified through command line option "--tolerance". Signed-off-by: Srikanth Yalavarthi Acked-by: Anup Prabhu --- app/test-mldev/meson.build | 2 +- app/test-mldev/ml_options.c | 24 ++- app/test-mldev/ml_options.h | 3 + app/test-mldev/test_inference_common.c | 216 ++++++++++++++++++++++++- app/test-mldev/test_inference_common.h | 1 + app/test-mldev/test_model_common.h | 1 + doc/guides/tools/testmldev.rst | 39 +++++ 7 files changed, 281 insertions(+), 5 deletions(-) diff --git a/app/test-mldev/meson.build b/app/test-mldev/meson.build index 41d22fb22c..15db534dc2 100644 --- a/app/test-mldev/meson.build +++ b/app/test-mldev/meson.build @@ -21,4 +21,4 @@ sources = files( 'test_inference_interleave.c', ) -deps += ['mldev'] +deps += ['mldev', 'hash'] diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index 44df44991b..da30796a6b 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -28,6 +29,7 @@ ml_options_default(struct ml_options *opt) opt->queue_pairs = 1; opt->queue_size = 1; opt->batches = 0; + opt->tolerance = 0.0; opt->debug = false; } @@ -133,6 +135,13 @@ ml_parse_filelist(struct ml_options *opt, const char *arg) } strlcpy(opt->filelist[opt->nb_filelist].output, token, PATH_MAX); + /* reference - optional */ + token = strtok(NULL, delim); + if (token != NULL) + strlcpy(opt->filelist[opt->nb_filelist].reference, token, PATH_MAX); + else + memset(opt->filelist[opt->nb_filelist].reference, 0, PATH_MAX); + opt->nb_filelist++; if (opt->nb_filelist == 0) { @@ -177,6 +186,14 @@ ml_parse_batches(struct ml_options *opt, const char *arg) return parser_read_uint16(&opt->batches, arg); } +static int +ml_parse_tolerance(struct ml_options *opt, const char *arg) +{ + opt->tolerance = fabs(atof(arg)); + + return 0; +} + static void ml_dump_test_options(const char *testname) { @@ -193,12 +210,13 @@ ml_dump_test_options(const char *testname) if ((strcmp(testname, "inference_ordered") == 0) || (strcmp(testname, "inference_interleave") == 0)) { - printf("\t\t--filelist : comma separated list of model, input and output\n" + printf("\t\t--filelist : comma separated list of model, input, output and reference\n" "\t\t--repetitions : number of inference repetitions\n" "\t\t--burst_size : inference burst size\n" "\t\t--queue_pairs : number of queue pairs to create\n" "\t\t--queue_size : size fo queue-pair\n" - "\t\t--batches : number of batches of input\n"); + "\t\t--batches : number of batches of input\n" + "\t\t--tolerance : maximum tolerance (%%) for output validation\n"); printf("\n"); } } @@ -229,6 +247,7 @@ static struct option lgopts[] = { {ML_QUEUE_PAIRS, 1, 0, 0}, {ML_QUEUE_SIZE, 1, 0, 0}, {ML_BATCHES, 1, 0, 0}, + {ML_TOLERANCE, 1, 0, 0}, {ML_DEBUG, 0, 0, 0}, {ML_HELP, 0, 0, 0}, {NULL, 0, 0, 0}}; @@ -249,6 +268,7 @@ ml_opts_parse_long(int opt_idx, struct ml_options *opt) {ML_QUEUE_PAIRS, ml_parse_queue_pairs}, {ML_QUEUE_SIZE, ml_parse_queue_size}, {ML_BATCHES, ml_parse_batches}, + {ML_TOLERANCE, ml_parse_tolerance}, }; for (i = 0; i < RTE_DIM(parsermap); i++) { diff --git a/app/test-mldev/ml_options.h b/app/test-mldev/ml_options.h index 48fe064150..7f3db29656 100644 --- a/app/test-mldev/ml_options.h +++ b/app/test-mldev/ml_options.h @@ -22,6 +22,7 @@ #define ML_QUEUE_PAIRS ("queue_pairs") #define ML_QUEUE_SIZE ("queue_size") #define ML_BATCHES ("batches") +#define ML_TOLERANCE ("tolerance") #define ML_DEBUG ("debug") #define ML_HELP ("help") @@ -29,6 +30,7 @@ struct ml_filelist { char model[PATH_MAX]; char input[PATH_MAX]; char output[PATH_MAX]; + char reference[PATH_MAX]; }; struct ml_options { @@ -42,6 +44,7 @@ struct ml_options { uint16_t queue_pairs; uint16_t queue_size; uint16_t batches; + float tolerance; bool debug; }; diff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c index 0f281aed6c..b605c1f5d3 100644 --- a/app/test-mldev/test_inference_common.c +++ b/app/test-mldev/test_inference_common.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -15,6 +16,27 @@ #include "ml_common.h" #include "test_inference_common.h" +#define ML_TEST_READ_TYPE(buffer, type) (*((type *)buffer)) + +#define ML_TEST_CHECK_OUTPUT(output, reference, tolerance) \ + (((float)output - (float)reference) <= (((float)reference * tolerance) / 100.0)) + +#define ML_OPEN_WRITE_GET_ERR(name, buffer, size, err) \ + do { \ + FILE *fp = fopen(name, "w+"); \ + if (fp == NULL) { \ + ml_err("Unable to create file: %s, error: %s", name, strerror(errno)); \ + err = true; \ + } else { \ + if (fwrite(buffer, 1, size, fp) != size) { \ + ml_err("Error writing output, file: %s, error: %s", name, \ + strerror(errno)); \ + err = true; \ + } \ + fclose(fp); \ + } \ + } while (0) + /* Enqueue inference requests with burst size equal to 1 */ static int ml_enqueue_single(void *arg) @@ -358,6 +380,7 @@ test_inference_opt_dump(struct ml_options *opt) ml_dump("burst_size", "%u", opt->burst_size); ml_dump("queue_pairs", "%u", opt->queue_pairs); ml_dump("queue_size", "%u", opt->queue_size); + ml_dump("tolerance", "%-7.3f", opt->tolerance); if (opt->batches == 0) ml_dump("batches", "%u (default)", opt->batches); @@ -369,6 +392,8 @@ test_inference_opt_dump(struct ml_options *opt) ml_dump_list("model", i, opt->filelist[i].model); ml_dump_list("input", i, opt->filelist[i].input); ml_dump_list("output", i, opt->filelist[i].output); + if (strcmp(opt->filelist[i].reference, "\0") != 0) + ml_dump_list("reference", i, opt->filelist[i].reference); } ml_dump_end; } @@ -393,6 +418,7 @@ test_inference_setup(struct ml_test *test, struct ml_options *opt) t = ml_test_priv(test); t->nb_used = 0; + t->nb_valid = 0; t->cmn.result = ML_TEST_FAILED; t->cmn.opt = opt; memset(t->error_count, 0, RTE_MAX_LCORE * sizeof(uint64_t)); @@ -569,6 +595,9 @@ ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t /* allocate buffer for user data */ mz_size = t->model[fid].inp_dsize + t->model[fid].out_dsize; + if (strcmp(opt->filelist[fid].reference, "\0") != 0) + mz_size += t->model[fid].out_dsize; + sprintf(mz_name, "ml_user_data_%d", fid); mz = rte_memzone_reserve(mz_name, mz_size, opt->socket_id, 0); if (mz == NULL) { @@ -579,6 +608,10 @@ ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t t->model[fid].input = mz->addr; t->model[fid].output = t->model[fid].input + t->model[fid].inp_dsize; + if (strcmp(opt->filelist[fid].reference, "\0") != 0) + t->model[fid].reference = t->model[fid].output + t->model[fid].out_dsize; + else + t->model[fid].reference = NULL; /* load input file */ fp = fopen(opt->filelist[fid].input, "r"); @@ -607,6 +640,27 @@ ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t } fclose(fp); + /* load reference file */ + if (t->model[fid].reference != NULL) { + fp = fopen(opt->filelist[fid].reference, "r"); + if (fp == NULL) { + ml_err("Failed to open reference file : %s\n", + opt->filelist[fid].reference); + ret = -errno; + goto error; + } + + if (fread(t->model[fid].reference, 1, t->model[fid].out_dsize, fp) != + t->model[fid].out_dsize) { + ml_err("Failed to read reference file : %s\n", + opt->filelist[fid].reference); + ret = -errno; + fclose(fp); + goto error; + } + fclose(fp); + } + /* create mempool for quantized input and output buffers. ml_request_initialize is * used as a callback for object creation. */ @@ -691,6 +745,121 @@ ml_inference_mem_destroy(struct ml_test *test, struct ml_options *opt) rte_mempool_free(t->op_pool); } +static bool +ml_inference_validation(struct ml_test *test, struct ml_request *req) +{ + struct test_inference *t = ml_test_priv((struct ml_test *)test); + struct ml_model *model; + uint32_t nb_elements; + uint8_t *reference; + uint8_t *output; + bool match; + uint32_t i; + uint32_t j; + + model = &t->model[req->fid]; + + /* compare crc when tolerance is 0 */ + if (t->cmn.opt->tolerance == 0.0) { + match = (rte_hash_crc(model->output, model->out_dsize, 0) == + rte_hash_crc(model->reference, model->out_dsize, 0)); + } else { + output = model->output; + reference = model->reference; + + i = 0; +next_output: + nb_elements = + model->info.output_info[i].shape.w * model->info.output_info[i].shape.x * + model->info.output_info[i].shape.y * model->info.output_info[i].shape.z; + j = 0; +next_element: + match = false; + switch (model->info.output_info[i].dtype) { + case RTE_ML_IO_TYPE_INT8: + if (ML_TEST_CHECK_OUTPUT(ML_TEST_READ_TYPE(output, int8_t), + ML_TEST_READ_TYPE(reference, int8_t), + t->cmn.opt->tolerance)) + match = true; + + output += sizeof(int8_t); + reference += sizeof(int8_t); + break; + case RTE_ML_IO_TYPE_UINT8: + if (ML_TEST_CHECK_OUTPUT(ML_TEST_READ_TYPE(output, uint8_t), + ML_TEST_READ_TYPE(reference, uint8_t), + t->cmn.opt->tolerance)) + match = true; + + output += sizeof(float); + reference += sizeof(float); + break; + case RTE_ML_IO_TYPE_INT16: + if (ML_TEST_CHECK_OUTPUT(ML_TEST_READ_TYPE(output, int16_t), + ML_TEST_READ_TYPE(reference, int16_t), + t->cmn.opt->tolerance)) + match = true; + + output += sizeof(int16_t); + reference += sizeof(int16_t); + break; + case RTE_ML_IO_TYPE_UINT16: + if (ML_TEST_CHECK_OUTPUT(ML_TEST_READ_TYPE(output, uint16_t), + ML_TEST_READ_TYPE(reference, uint16_t), + t->cmn.opt->tolerance)) + match = true; + + output += sizeof(uint16_t); + reference += sizeof(uint16_t); + break; + case RTE_ML_IO_TYPE_INT32: + if (ML_TEST_CHECK_OUTPUT(ML_TEST_READ_TYPE(output, int32_t), + ML_TEST_READ_TYPE(reference, int32_t), + t->cmn.opt->tolerance)) + match = true; + + output += sizeof(int32_t); + reference += sizeof(int32_t); + break; + case RTE_ML_IO_TYPE_UINT32: + if (ML_TEST_CHECK_OUTPUT(ML_TEST_READ_TYPE(output, uint32_t), + ML_TEST_READ_TYPE(reference, uint32_t), + t->cmn.opt->tolerance)) + match = true; + + output += sizeof(uint32_t); + reference += sizeof(uint32_t); + break; + case RTE_ML_IO_TYPE_FP32: + if (ML_TEST_CHECK_OUTPUT(ML_TEST_READ_TYPE(output, float), + ML_TEST_READ_TYPE(reference, float), + t->cmn.opt->tolerance)) + match = true; + + output += sizeof(float); + reference += sizeof(float); + break; + default: /* other types, fp8, fp16, bfloat16 */ + match = true; + } + + if (!match) + goto done; + j++; + if (j < nb_elements) + goto next_element; + + i++; + if (i < model->info.nb_outputs) + goto next_output; + } +done: + if (match) + t->nb_valid++; + + return match; +} + /* Callback for mempool object iteration. This call would dequantize output data. */ static void ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int obj_idx) @@ -698,9 +867,10 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int struct test_inference *t = ml_test_priv((struct ml_test *)opaque); struct ml_request *req = (struct ml_request *)obj; struct ml_model *model = &t->model[req->fid]; + char str[PATH_MAX]; + bool error = false; RTE_SET_USED(mp); - RTE_SET_USED(obj_idx); if (req->niters == 0) return; @@ -708,6 +878,48 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int t->nb_used++; rte_ml_io_dequantize(t->cmn.opt->dev_id, model->id, t->model[req->fid].nb_batches, req->output, model->output); + + if (model->reference == NULL) { + t->nb_valid++; + goto dump_output_pass; + } + + if (!ml_inference_validation(opaque, req)) + goto dump_output_fail; + else + goto dump_output_pass; + +dump_output_pass: + if (obj_idx == 0) { + /* write quantized output */ + snprintf(str, PATH_MAX, "%s.q", t->cmn.opt->filelist[req->fid].output); + ML_OPEN_WRITE_GET_ERR(str, req->output, model->out_qsize, error); + if (error) + return; + + /* write dequantized output */ + snprintf(str, PATH_MAX, "%s", t->cmn.opt->filelist[req->fid].output); + ML_OPEN_WRITE_GET_ERR(str, model->output, model->out_dsize, error); + if (error) + return; + } + + return; + +dump_output_fail: + if (t->cmn.opt->debug) { + /* dump quantized output buffer */ + snprintf(str, PATH_MAX, "%s.q.%d", t->cmn.opt->filelist[req->fid].output, obj_idx); + ML_OPEN_WRITE_GET_ERR(str, req->output, model->out_qsize, error); + if (error) + return; + + /* dump dequantized output buffer */ + snprintf(str, PATH_MAX, "%s.%d", t->cmn.opt->filelist[req->fid].output, obj_idx); + ML_OPEN_WRITE_GET_ERR(str, model->output, model->out_dsize, error); + if (error) + return; + } } int @@ -725,7 +937,7 @@ ml_inference_result(struct ml_test *test, struct ml_options *opt, uint16_t fid) rte_mempool_obj_iter(t->model[fid].io_pool, ml_request_finish, test); - if ((t->nb_used > 0) && (error_count == 0)) + if ((t->nb_used == t->nb_valid) && (error_count == 0)) t->cmn.result = ML_TEST_SUCCESS; else t->cmn.result = ML_TEST_FAILED; diff --git a/app/test-mldev/test_inference_common.h b/app/test-mldev/test_inference_common.h index 81d9b07d41..2e4889e1f7 100644 --- a/app/test-mldev/test_inference_common.h +++ b/app/test-mldev/test_inference_common.h @@ -38,6 +38,7 @@ struct test_inference { struct rte_mempool *op_pool; uint64_t nb_used; + uint64_t nb_valid; uint16_t fid; int (*enqueue)(void *arg); diff --git a/app/test-mldev/test_model_common.h b/app/test-mldev/test_model_common.h index 19429ce142..b2a75a3261 100644 --- a/app/test-mldev/test_model_common.h +++ b/app/test-mldev/test_model_common.h @@ -28,6 +28,7 @@ struct ml_model { uint8_t *input; uint8_t *output; + uint8_t *reference; struct rte_mempool *io_pool; uint32_t nb_batches; diff --git a/doc/guides/tools/testmldev.rst b/doc/guides/tools/testmldev.rst index 6632025fdf..25dc878f25 100644 --- a/doc/guides/tools/testmldev.rst +++ b/doc/guides/tools/testmldev.rst @@ -111,6 +111,11 @@ The following are the command-line options supported by the test application. Set the number batches in the input file provided for inference run. When not specified the test would assume the number of batches is equal to the batch size of the model. +* ``--tolerance `` + + Set the tolerance value in percentage to be used for output validation. Default value + is `0`. + * ``--debug`` Enable the tests to run in debug mode. @@ -273,6 +278,7 @@ Supported command line options for inference tests are following:: --queue_pairs --queue_size --batches + --tolerance List of files to be used for the inference tests can be specified through the option @@ -287,10 +293,20 @@ try to enqueue or dequeue ``num`` number of inferences per each call respectivel In the inference test, a pair of lcores are mapped to each queue pair. Minimum number of lcores required for the tests is equal to ``(queue_pairs * 2 + 1)``. +Output validation of inference would be enabled only when a reference file is specified through +the ``--filelist`` option. Application would additionally consider the tolerance value provided +through ``--tolerance`` option during validation. When the tolerance values is 0, CRC32 hash of +inference output and reference output are compared. When the tolerance is non-zero, element wise +comparison of output is performed. Validation is considered as successful only when all the +elements of the output tensor are with in the tolerance range specified. + .. Note:: * The ``--filelist `` is a mandatory option for running inference tests. * Options not supported by the tests are ignored if specified. + * Element wise comparison is not supported when the output dtype is either fp8, fp16 + or bfloat16. This is applicable only when the tolerance is greater than zero and for + pre-quantized models only. INFERENCE_ORDERED Test @@ -339,6 +355,14 @@ Example command to run inference_ordered test with multiple queue-pairs and queu --test=inference_ordered --filelist model.bin,input.bin,output.bin \ --queue_pairs 4 --queue_size 16 +Example command to run inference_ordered with output validation using tolerance of `1%``: + +.. code-block:: console + + sudo /app/dpdk-test-mldev -c 0xf -a -- \ + --test=inference_ordered --filelist model.bin,input.bin,output.bin,reference.bin \ + --tolerance 1.0 + INFERENCE_INTERLEAVE Test ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -388,9 +412,24 @@ and queue size: --test=inference_interleave --filelist model.bin,input.bin,output.bin \ --queue_pairs 8 --queue_size 12 --burst_size 16 +Example command to run inference_interleave test with multiple models ad output validation +using tolerance of `2.0%``: + +.. code-block:: console + + sudo /app/dpdk-test-mldev -c 0xf -a -- \ + --test=inference_interleave \ + --filelist model_A.bin,input_A.bin,output_A.bin,reference_A.bin \ + --filelist model_B.bin,input_B.bin,output_B.bin,reference_B.bin \ + --tolerance 2.0 + Debug mode ---------- ML tests can be executed in debug mode by enabling the option ``--debug``. Execution of tests in debug mode would enable additional prints. + +When a validation failure is observed, output from that buffer is written to the disk, with the +filenames having similar convention when the test has passed. Additionally index of the buffer +would be appended to the filenames. From patchwork Thu Mar 16 21:14:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Yalavarthi X-Patchwork-Id: 125209 X-Patchwork-Delegate: thomas@monjalon.net 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 4536341EB5; Thu, 16 Mar 2023 22:16:03 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4E03642FD8; Thu, 16 Mar 2023 22:14:57 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 5C00942DB9 for ; Thu, 16 Mar 2023 22:14:46 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32GKcQtg004129 for ; Thu, 16 Mar 2023 14:14:45 -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-type; s=pfpt0220; bh=HJorTXgT1ONIEspsID74cgCCPTDTBY7nlCpuT/co7v0=; b=a3FPrfraXp7yZNAJizqK9v6R6iLiB6KzuqkR0chZEECAsUYo6qO/dxxh9lHCHXubBAIw +Mm3TFx/3c2fXA+Rw7NNyjL0qs0LAuxy1spRrqUQ1YFyUD/N9bPf6G+gKlUFNJohSy78 DWeKpeqp9lpTw3kd8HaNeJPpzWb0Nu7W+KqEB0/q7vP+NEW6HVvRE4r3ujGeDjV9br0B SZf2l6cD2BDYMslcArIU7ySIfrsjskWh/euzi7taQnR8LcRcpHF00zITXylL+hf8ZmCn swVenn5z8lIaZRscms/iiJzIVrgvGas47V9Mcli7zR1ZOrG55SVXZClGz83v8kRI+yGb GA== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3pbxq2ub11-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 16 Mar 2023 14:14:45 -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.42; Thu, 16 Mar 2023 14:14:41 -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.42 via Frontend Transport; Thu, 16 Mar 2023 14:14:41 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 7F2743F7081; Thu, 16 Mar 2023 14:14:41 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi CC: , , , , , Subject: [PATCH v7 11/11] app/mldev: enable reporting stats in mldev app Date: Thu, 16 Mar 2023 14:14:34 -0700 Message-ID: <20230316211434.13409-12-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316211434.13409-1-syalavarthi@marvell.com> References: <20221129070746.20396-1-syalavarthi@marvell.com> <20230316211434.13409-1-syalavarthi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: CjNN24pO-OuEWVDegphXI6WCJRNLG5SC X-Proofpoint-ORIG-GUID: CjNN24pO-OuEWVDegphXI6WCJRNLG5SC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 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 Enable reporting driver xstats and inference end-to-end latency and throughput in mldev inference tests. Reporting of stats can be enabled using "--stats" option. Signed-off-by: Srikanth Yalavarthi Acked-by: Anup Prabhu --- app/test-mldev/ml_options.c | 10 +- app/test-mldev/ml_options.h | 2 + app/test-mldev/test_inference_common.c | 140 +++++++++++++++++++++ app/test-mldev/test_inference_common.h | 8 ++ app/test-mldev/test_inference_interleave.c | 4 + app/test-mldev/test_inference_ordered.c | 1 + doc/guides/tools/testmldev.rst | 7 ++ 7 files changed, 171 insertions(+), 1 deletion(-) diff --git a/app/test-mldev/ml_options.c b/app/test-mldev/ml_options.c index da30796a6b..2efcc3532c 100644 --- a/app/test-mldev/ml_options.c +++ b/app/test-mldev/ml_options.c @@ -30,6 +30,7 @@ ml_options_default(struct ml_options *opt) opt->queue_size = 1; opt->batches = 0; opt->tolerance = 0.0; + opt->stats = false; opt->debug = false; } @@ -216,7 +217,8 @@ ml_dump_test_options(const char *testname) "\t\t--queue_pairs : number of queue pairs to create\n" "\t\t--queue_size : size fo queue-pair\n" "\t\t--batches : number of batches of input\n" - "\t\t--tolerance : maximum tolerance (%%) for output validation\n"); + "\t\t--tolerance : maximum tolerance (%%) for output validation\n" + "\t\t--stats : enable reporting performance statistics\n"); printf("\n"); } } @@ -248,6 +250,7 @@ static struct option lgopts[] = { {ML_QUEUE_SIZE, 1, 0, 0}, {ML_BATCHES, 1, 0, 0}, {ML_TOLERANCE, 1, 0, 0}, + {ML_STATS, 0, 0, 0}, {ML_DEBUG, 0, 0, 0}, {ML_HELP, 0, 0, 0}, {NULL, 0, 0, 0}}; @@ -290,6 +293,11 @@ ml_options_parse(struct ml_options *opt, int argc, char **argv) while ((opts = getopt_long(argc, argv, "", lgopts, &opt_idx)) != EOF) { switch (opts) { case 0: /* parse long options */ + if (!strcmp(lgopts[opt_idx].name, "stats")) { + opt->stats = true; + break; + } + if (!strcmp(lgopts[opt_idx].name, "debug")) { opt->debug = true; break; diff --git a/app/test-mldev/ml_options.h b/app/test-mldev/ml_options.h index 7f3db29656..beb0fe69c6 100644 --- a/app/test-mldev/ml_options.h +++ b/app/test-mldev/ml_options.h @@ -23,6 +23,7 @@ #define ML_QUEUE_SIZE ("queue_size") #define ML_BATCHES ("batches") #define ML_TOLERANCE ("tolerance") +#define ML_STATS ("stats") #define ML_DEBUG ("debug") #define ML_HELP ("help") @@ -45,6 +46,7 @@ struct ml_options { uint16_t queue_size; uint16_t batches; float tolerance; + bool stats; bool debug; }; diff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c index b605c1f5d3..e85f32be60 100644 --- a/app/test-mldev/test_inference_common.c +++ b/app/test-mldev/test_inference_common.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,17 @@ } \ } while (0) +static void +print_line(uint16_t len) +{ + uint16_t i; + + for (i = 0; i < len; i++) + printf("-"); + + printf("\n"); +} + /* Enqueue inference requests with burst size equal to 1 */ static int ml_enqueue_single(void *arg) @@ -46,6 +58,7 @@ ml_enqueue_single(void *arg) struct rte_ml_op *op = NULL; struct ml_core_args *args; uint64_t model_enq = 0; + uint64_t start_cycle; uint32_t burst_enq; uint32_t lcore_id; uint16_t fid; @@ -53,6 +66,7 @@ ml_enqueue_single(void *arg) lcore_id = rte_lcore_id(); args = &t->args[lcore_id]; + args->start_cycles = 0; model_enq = 0; if (args->nb_reqs == 0) @@ -88,10 +102,12 @@ ml_enqueue_single(void *arg) req->fid = fid; enqueue_req: + start_cycle = rte_get_tsc_cycles(); burst_enq = rte_ml_enqueue_burst(t->cmn.opt->dev_id, args->qp_id, &op, 1); if (burst_enq == 0) goto enqueue_req; + args->start_cycles += start_cycle; fid++; if (likely(fid <= args->end_fid)) goto next_model; @@ -115,10 +131,12 @@ ml_dequeue_single(void *arg) uint64_t total_deq = 0; uint8_t nb_filelist; uint32_t burst_deq; + uint64_t end_cycle; uint32_t lcore_id; lcore_id = rte_lcore_id(); args = &t->args[lcore_id]; + args->end_cycles = 0; nb_filelist = args->end_fid - args->start_fid + 1; if (args->nb_reqs == 0) @@ -126,9 +144,11 @@ ml_dequeue_single(void *arg) dequeue_req: burst_deq = rte_ml_dequeue_burst(t->cmn.opt->dev_id, args->qp_id, &op, 1); + end_cycle = rte_get_tsc_cycles(); if (likely(burst_deq == 1)) { total_deq += burst_deq; + args->end_cycles += end_cycle; if (unlikely(op->status == RTE_ML_OP_STATUS_ERROR)) { rte_ml_op_error_get(t->cmn.opt->dev_id, op, &error); ml_err("error_code = 0x%" PRIx64 ", error_message = %s\n", error.errcode, @@ -152,6 +172,7 @@ ml_enqueue_burst(void *arg) { struct test_inference *t = ml_test_priv((struct ml_test *)arg); struct ml_core_args *args; + uint64_t start_cycle; uint16_t ops_count; uint64_t model_enq; uint16_t burst_enq; @@ -164,6 +185,7 @@ ml_enqueue_burst(void *arg) lcore_id = rte_lcore_id(); args = &t->args[lcore_id]; + args->start_cycles = 0; model_enq = 0; if (args->nb_reqs == 0) @@ -205,8 +227,10 @@ ml_enqueue_burst(void *arg) pending = ops_count; enqueue_reqs: + start_cycle = rte_get_tsc_cycles(); burst_enq = rte_ml_enqueue_burst(t->cmn.opt->dev_id, args->qp_id, &args->enq_ops[idx], pending); + args->start_cycles += burst_enq * start_cycle; pending = pending - burst_enq; if (pending > 0) { @@ -236,11 +260,13 @@ ml_dequeue_burst(void *arg) uint64_t total_deq = 0; uint16_t burst_deq = 0; uint8_t nb_filelist; + uint64_t end_cycle; uint32_t lcore_id; uint32_t i; lcore_id = rte_lcore_id(); args = &t->args[lcore_id]; + args->end_cycles = 0; nb_filelist = args->end_fid - args->start_fid + 1; if (args->nb_reqs == 0) @@ -249,9 +275,11 @@ ml_dequeue_burst(void *arg) dequeue_burst: burst_deq = rte_ml_dequeue_burst(t->cmn.opt->dev_id, args->qp_id, args->deq_ops, t->cmn.opt->burst_size); + end_cycle = rte_get_tsc_cycles(); if (likely(burst_deq > 0)) { total_deq += burst_deq; + args->end_cycles += burst_deq * end_cycle; for (i = 0; i < burst_deq; i++) { if (unlikely(args->deq_ops[i]->status == RTE_ML_OP_STATUS_ERROR)) { @@ -381,6 +409,7 @@ test_inference_opt_dump(struct ml_options *opt) ml_dump("queue_pairs", "%u", opt->queue_pairs); ml_dump("queue_size", "%u", opt->queue_size); ml_dump("tolerance", "%-7.3f", opt->tolerance); + ml_dump("stats", "%s", (opt->stats ? "true" : "false")); if (opt->batches == 0) ml_dump("batches", "%u (default)", opt->batches); @@ -454,6 +483,11 @@ test_inference_setup(struct ml_test *test, struct ml_options *opt) RTE_CACHE_LINE_SIZE, opt->socket_id); } + for (i = 0; i < RTE_MAX_LCORE; i++) { + t->args[i].start_cycles = 0; + t->args[i].end_cycles = 0; + } + return 0; error: @@ -986,3 +1020,109 @@ ml_inference_launch_cores(struct ml_test *test, struct ml_options *opt, uint16_t return 0; } + +int +ml_inference_stats_get(struct ml_test *test, struct ml_options *opt) +{ + struct test_inference *t = ml_test_priv(test); + uint64_t total_cycles = 0; + uint32_t nb_filelist; + uint64_t throughput; + uint64_t avg_e2e; + uint32_t qp_id; + uint64_t freq; + int ret; + int i; + + if (!opt->stats) + return 0; + + /* get xstats size */ + t->xstats_size = rte_ml_dev_xstats_names_get(opt->dev_id, NULL, 0); + if (t->xstats_size >= 0) { + /* allocate for xstats_map and values */ + t->xstats_map = rte_malloc( + "ml_xstats_map", t->xstats_size * sizeof(struct rte_ml_dev_xstats_map), 0); + if (t->xstats_map == NULL) { + ret = -ENOMEM; + goto error; + } + + t->xstats_values = + rte_malloc("ml_xstats_values", t->xstats_size * sizeof(uint64_t), 0); + if (t->xstats_values == NULL) { + ret = -ENOMEM; + goto error; + } + + ret = rte_ml_dev_xstats_names_get(opt->dev_id, t->xstats_map, t->xstats_size); + if (ret != t->xstats_size) { + printf("Unable to get xstats names, ret = %d\n", ret); + ret = -1; + goto error; + } + + for (i = 0; i < t->xstats_size; i++) + rte_ml_dev_xstats_get(opt->dev_id, &t->xstats_map[i].id, + &t->xstats_values[i], 1); + } + + /* print xstats*/ + printf("\n"); + print_line(80); + printf(" ML Device Extended Statistics\n"); + print_line(80); + for (i = 0; i < t->xstats_size; i++) + printf(" %-64s = %" PRIu64 "\n", t->xstats_map[i].name, t->xstats_values[i]); + print_line(80); + + /* release buffers */ + if (t->xstats_map) + rte_free(t->xstats_map); + + if (t->xstats_values) + rte_free(t->xstats_values); + + /* print end-to-end stats */ + freq = rte_get_tsc_hz(); + for (qp_id = 0; qp_id < RTE_MAX_LCORE; qp_id++) + total_cycles += t->args[qp_id].end_cycles - t->args[qp_id].start_cycles; + avg_e2e = total_cycles / opt->repetitions; + + if (freq == 0) { + avg_e2e = total_cycles / opt->repetitions; + printf(" %-64s = %" PRIu64 "\n", "Average End-to-End Latency (cycles)", avg_e2e); + } else { + avg_e2e = (total_cycles * NS_PER_S) / (opt->repetitions * freq); + printf(" %-64s = %" PRIu64 "\n", "Average End-to-End Latency (ns)", avg_e2e); + } + + /* print inference throughput */ + if (strcmp(opt->test_name, "inference_ordered") == 0) + nb_filelist = 1; + else + nb_filelist = opt->nb_filelist; + + if (freq == 0) { + throughput = (nb_filelist * t->cmn.opt->repetitions * 1000000) / total_cycles; + printf(" %-64s = %" PRIu64 "\n", "Average Throughput (inferences / million cycles)", + throughput); + } else { + throughput = (nb_filelist * t->cmn.opt->repetitions * freq) / total_cycles; + printf(" %-64s = %" PRIu64 "\n", "Average Throughput (inferences / second)", + throughput); + } + + print_line(80); + + return 0; + +error: + if (t->xstats_map) + rte_free(t->xstats_map); + + if (t->xstats_values) + rte_free(t->xstats_values); + + return ret; +} diff --git a/app/test-mldev/test_inference_common.h b/app/test-mldev/test_inference_common.h index 2e4889e1f7..0b4fba78e0 100644 --- a/app/test-mldev/test_inference_common.h +++ b/app/test-mldev/test_inference_common.h @@ -27,6 +27,9 @@ struct ml_core_args { struct rte_ml_op **enq_ops; struct rte_ml_op **deq_ops; struct ml_request **reqs; + + uint64_t start_cycles; + uint64_t end_cycles; }; struct test_inference { @@ -46,6 +49,10 @@ struct test_inference { struct ml_core_args args[RTE_MAX_LCORE]; uint64_t error_count[RTE_MAX_LCORE]; + + struct rte_ml_dev_xstats_map *xstats_map; + uint64_t *xstats_values; + int xstats_size; } __rte_cache_aligned; bool test_inference_cap_check(struct ml_options *opt); @@ -63,5 +70,6 @@ void ml_inference_mem_destroy(struct ml_test *test, struct ml_options *opt); int ml_inference_result(struct ml_test *test, struct ml_options *opt, uint16_t fid); int ml_inference_launch_cores(struct ml_test *test, struct ml_options *opt, uint16_t start_fid, uint16_t end_fid); +int ml_inference_stats_get(struct ml_test *test, struct ml_options *opt); #endif /* _ML_TEST_INFERENCE_COMMON_ */ diff --git a/app/test-mldev/test_inference_interleave.c b/app/test-mldev/test_inference_interleave.c index 9cf4cfa197..bd2c286737 100644 --- a/app/test-mldev/test_inference_interleave.c +++ b/app/test-mldev/test_inference_interleave.c @@ -56,7 +56,11 @@ test_inference_interleave_driver(struct ml_test *test, struct ml_options *opt) goto error; ml_inference_iomem_destroy(test, opt, fid); + } + + ml_inference_stats_get(test, opt); + for (fid = 0; fid < opt->nb_filelist; fid++) { ret = ml_model_stop(test, opt, &t->model[fid], fid); if (ret != 0) goto error; diff --git a/app/test-mldev/test_inference_ordered.c b/app/test-mldev/test_inference_ordered.c index 1cd91dc3d3..8992358936 100644 --- a/app/test-mldev/test_inference_ordered.c +++ b/app/test-mldev/test_inference_ordered.c @@ -54,6 +54,7 @@ test_inference_ordered_driver(struct ml_test *test, struct ml_options *opt) goto error; ml_inference_iomem_destroy(test, opt, fid); + ml_inference_stats_get(test, opt); /* stop model */ ret = ml_model_stop(test, opt, &t->model[fid], fid); diff --git a/doc/guides/tools/testmldev.rst b/doc/guides/tools/testmldev.rst index 25dc878f25..e51d780cd5 100644 --- a/doc/guides/tools/testmldev.rst +++ b/doc/guides/tools/testmldev.rst @@ -116,6 +116,10 @@ The following are the command-line options supported by the test application. Set the tolerance value in percentage to be used for output validation. Default value is `0`. +* ``--stats`` + + Enable reporting device extended stats. + * ``--debug`` Enable the tests to run in debug mode. @@ -279,6 +283,7 @@ Supported command line options for inference tests are following:: --queue_size --batches --tolerance + --stats List of files to be used for the inference tests can be specified through the option @@ -300,6 +305,8 @@ inference output and reference output are compared. When the tolerance is non-ze comparison of output is performed. Validation is considered as successful only when all the elements of the output tensor are with in the tolerance range specified. +Enabling ``--stats`` would print the extended stats supported by the driver. + .. Note:: * The ``--filelist `` is a mandatory option for running inference tests.