Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2023 Marvell.
3 : : */
4 : :
5 : : #include "test_stats.h"
6 : : #include "test_inference_common.h"
7 : : #include "test_model_ops.h"
8 : :
9 : : int
10 : 0 : ml_stats_get(struct ml_test *test, struct ml_options *opt, enum rte_ml_dev_xstats_mode mode,
11 : : int32_t fid)
12 : : {
13 : : struct test_common *t = ml_test_priv(test);
14 : : int32_t model_id;
15 : : int ret;
16 : : int i;
17 : :
18 : 0 : if (!opt->stats)
19 : : return 0;
20 : :
21 : 0 : if (mode == RTE_ML_DEV_XSTATS_MODEL)
22 : 0 : model_id = ((struct test_inference *)t)->model[fid].id;
23 : : else
24 : : model_id = -1;
25 : :
26 : : /* get xstats size */
27 : 0 : t->xstats_size = rte_ml_dev_xstats_names_get(opt->dev_id, mode, model_id, NULL, 0);
28 : 0 : if (t->xstats_size > 0) {
29 : : /* allocate for xstats_map and values */
30 : 0 : t->xstats_map = rte_malloc(
31 : 0 : "ml_xstats_map", t->xstats_size * sizeof(struct rte_ml_dev_xstats_map), 0);
32 : 0 : if (t->xstats_map == NULL) {
33 : : ret = -ENOMEM;
34 : 0 : goto error;
35 : : }
36 : :
37 : 0 : t->xstats_values =
38 : 0 : rte_malloc("ml_xstats_values", t->xstats_size * sizeof(uint64_t), 0);
39 : 0 : if (t->xstats_values == NULL) {
40 : : ret = -ENOMEM;
41 : 0 : goto error;
42 : : }
43 : :
44 : 0 : ret = rte_ml_dev_xstats_names_get(opt->dev_id, mode, model_id, t->xstats_map,
45 : 0 : t->xstats_size);
46 : 0 : if (ret != t->xstats_size) {
47 : : printf("Unable to get xstats names, ret = %d\n", ret);
48 : : ret = -1;
49 : 0 : goto error;
50 : : }
51 : :
52 : 0 : for (i = 0; i < t->xstats_size; i++)
53 : 0 : rte_ml_dev_xstats_get(opt->dev_id, mode, model_id, &t->xstats_map[i].id,
54 : 0 : &t->xstats_values[i], 1);
55 : : }
56 : :
57 : : /* print xstats*/
58 : : printf("\n");
59 : 0 : ml_print_line(80);
60 : 0 : if (mode == RTE_ML_DEV_XSTATS_MODEL)
61 : : printf(" Model Statistics: %s\n",
62 : 0 : ((struct test_inference *)t)->model[fid].info.name);
63 : : else
64 : : printf(" Device Statistics\n");
65 : 0 : ml_print_line(80);
66 : 0 : for (i = 0; i < t->xstats_size; i++)
67 : 0 : printf(" %-64s = %" PRIu64 "\n", t->xstats_map[i].name, t->xstats_values[i]);
68 : 0 : ml_print_line(80);
69 : :
70 : 0 : rte_free(t->xstats_map);
71 : 0 : rte_free(t->xstats_values);
72 : :
73 : 0 : return 0;
74 : :
75 : 0 : error:
76 : 0 : rte_free(t->xstats_map);
77 : 0 : rte_free(t->xstats_values);
78 : :
79 : 0 : return ret;
80 : : }
81 : :
82 : : int
83 : 0 : ml_throughput_get(struct ml_test *test, struct ml_options *opt)
84 : : {
85 : : struct test_inference *t = ml_test_priv(test);
86 : : uint64_t total_cycles = 0;
87 : : uint32_t nb_filelist;
88 : : uint64_t throughput;
89 : : uint64_t avg_e2e;
90 : : uint32_t qp_id;
91 : : uint64_t freq;
92 : :
93 : 0 : if (!opt->stats)
94 : : return 0;
95 : :
96 : : /* print inference throughput */
97 : 0 : if (strcmp(opt->test_name, "inference_ordered") == 0)
98 : : nb_filelist = 1;
99 : : else
100 : 0 : nb_filelist = opt->nb_filelist;
101 : :
102 : : /* Print model end-to-end latency and throughput */
103 : 0 : freq = rte_get_tsc_hz();
104 : 0 : for (qp_id = 0; qp_id < RTE_MAX_LCORE; qp_id++)
105 : 0 : total_cycles += t->args[qp_id].end_cycles - t->args[qp_id].start_cycles;
106 : :
107 : 0 : avg_e2e = total_cycles / (opt->repetitions * nb_filelist);
108 : 0 : if (freq == 0) {
109 : : printf(" %-64s = %" PRIu64 "\n", "Average End-to-End Latency (cycles)", avg_e2e);
110 : : } else {
111 : 0 : avg_e2e = (avg_e2e * NS_PER_S) / freq;
112 : : printf(" %-64s = %" PRIu64 "\n", "Average End-to-End Latency (ns)", avg_e2e);
113 : : }
114 : :
115 : : /* Print model throughput */
116 : 0 : if (freq == 0) {
117 : 0 : throughput = 1000000 / avg_e2e;
118 : : printf(" %-64s = %" PRIu64 "\n", "Average Throughput (inferences / million cycles)",
119 : : throughput);
120 : : } else {
121 : 0 : throughput = freq / avg_e2e;
122 : : printf(" %-64s = %" PRIu64 "\n", "Average Throughput (inferences / second)",
123 : : throughput);
124 : : }
125 : :
126 : 0 : ml_print_line(80);
127 : :
128 : 0 : return 0;
129 : : }
|