1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2022 Marvell. 3 */ 4 5 #include <errno.h> 6 7 #include <rte_common.h> 8 #include <rte_memory.h> 9 #include <rte_mldev.h> 10 11 #include "ml_common.h" 12 #include "test_common.h" 13 14 bool 15 ml_test_cap_check(struct ml_options *opt) 16 { 17 struct rte_ml_dev_info dev_info; 18 19 rte_ml_dev_info_get(opt->dev_id, &dev_info); 20 if (dev_info.max_models == 0) { 21 ml_err("Not enough mldev models supported = %u", dev_info.max_models); 22 return false; 23 } 24 25 return true; 26 } 27 28 int 29 ml_test_opt_check(struct ml_options *opt) 30 { 31 uint16_t dev_count; 32 int socket_id; 33 34 RTE_SET_USED(opt); 35 36 dev_count = rte_ml_dev_count(); 37 if (dev_count == 0) { 38 ml_err("No ML devices found"); 39 return -ENODEV; 40 } 41 42 if (opt->dev_id >= dev_count) { 43 ml_err("Invalid option dev_id = %d", opt->dev_id); 44 return -EINVAL; 45 } 46 47 socket_id = rte_ml_dev_socket_id(opt->dev_id); 48 if (!((opt->socket_id != SOCKET_ID_ANY) || (opt->socket_id != socket_id))) { 49 ml_err("Invalid option, socket_id = %d\n", opt->socket_id); 50 return -EINVAL; 51 } 52 53 return 0; 54 } 55 56 void 57 ml_test_opt_dump(struct ml_options *opt) 58 { 59 ml_options_dump(opt); 60 } 61 62 int 63 ml_test_device_configure(struct ml_test *test, struct ml_options *opt) 64 { 65 struct test_common *t = ml_test_priv(test); 66 struct rte_ml_dev_config dev_config; 67 int ret; 68 69 ret = rte_ml_dev_info_get(opt->dev_id, &t->dev_info); 70 if (ret != 0) { 71 ml_err("Failed to get mldev info, dev_id = %d\n", opt->dev_id); 72 return ret; 73 } 74 75 /* configure device */ 76 dev_config.socket_id = opt->socket_id; 77 dev_config.nb_models = t->dev_info.max_models; 78 dev_config.nb_queue_pairs = opt->queue_pairs; 79 ret = rte_ml_dev_configure(opt->dev_id, &dev_config); 80 if (ret != 0) { 81 ml_err("Failed to configure ml device, dev_id = %d\n", opt->dev_id); 82 return ret; 83 } 84 85 return 0; 86 } 87 88 int 89 ml_test_device_close(struct ml_test *test, struct ml_options *opt) 90 { 91 struct test_common *t = ml_test_priv(test); 92 int ret = 0; 93 94 RTE_SET_USED(t); 95 96 /* close device */ 97 ret = rte_ml_dev_close(opt->dev_id); 98 if (ret != 0) 99 ml_err("Failed to close ML device, dev_id = %d\n", opt->dev_id); 100 101 return ret; 102 } 103 104 int 105 ml_test_device_start(struct ml_test *test, struct ml_options *opt) 106 { 107 struct test_common *t = ml_test_priv(test); 108 int ret; 109 110 RTE_SET_USED(t); 111 112 /* start device */ 113 ret = rte_ml_dev_start(opt->dev_id); 114 if (ret != 0) { 115 ml_err("Failed to start ml device, dev_id = %d\n", opt->dev_id); 116 return ret; 117 } 118 119 return 0; 120 } 121 122 int 123 ml_test_device_stop(struct ml_test *test, struct ml_options *opt) 124 { 125 struct test_common *t = ml_test_priv(test); 126 int ret = 0; 127 128 RTE_SET_USED(t); 129 130 /* stop device */ 131 ret = rte_ml_dev_stop(opt->dev_id); 132 if (ret != 0) 133 ml_err("Failed to stop ML device, dev_id = %d\n", opt->dev_id); 134 135 return ret; 136 } 137