@@ -67,6 +67,10 @@ static void usage(const struct perftest_context *ctx, const char *program)
6767 api_names [test -> api ], test -> desc );
6868 }
6969 printf ("\n" );
70+ printf (" -a <send-device-type[:dev-id]>[,<recv-device-type[:dev-id]>]\n" );
71+ printf (" Accelerator device type and device id to use for running the test.\n" );
72+ printf (" device id is optional, it corresponds to the index of\n" );
73+ printf (" the device in the list of available devices\n" );
7074 printf (" -s <size> list of scatter-gather sizes for single message (%zu)\n" ,
7175 ctx -> params .super .msg_size_list [0 ]);
7276 printf (" for example: \"-s 16,48,8192,8192,14\"\n" );
@@ -165,6 +169,26 @@ static void usage(const struct perftest_context *ctx, const char *program)
165169 printf ("\n" );
166170}
167171
172+ static ucs_status_t parse_device_id (const char * opt_arg , int * device_id )
173+ {
174+ char * endptr ;
175+ int parsed_device_id ;
176+
177+ if (opt_arg == NULL ) {
178+ ucs_error ("device id string is NULL" );
179+ return UCS_ERR_INVALID_PARAM ;
180+ }
181+
182+ parsed_device_id = strtol (opt_arg , & endptr , 10 );
183+ if ((endptr == opt_arg ) || (* endptr != '\0' ) || (parsed_device_id < 0 )) {
184+ ucs_error ("Failed to parse device id: %s" , opt_arg );
185+ return UCS_ERR_INVALID_PARAM ;
186+ }
187+
188+ * device_id = parsed_device_id ;
189+ return UCS_OK ;
190+ }
191+
168192static ucs_status_t parse_mem_type (const char * opt_arg ,
169193 ucs_memory_type_t * mem_type )
170194{
@@ -186,6 +210,42 @@ static ucs_status_t parse_mem_type(const char *opt_arg,
186210 return UCS_ERR_INVALID_PARAM ;
187211}
188212
213+ static ucs_status_t
214+ parse_accel_device (char * opt_arg , ucx_perf_accel_dev_t * dev )
215+ {
216+ const char * delim = ":" ;
217+ char * saveptr = NULL ;
218+ char * token ;
219+ ucs_status_t status ;
220+ ucs_memory_type_t mem_type ;
221+ int device_id ;
222+
223+ if (opt_arg == NULL ) {
224+ ucs_error ("mem type param is NULL" );
225+ return UCS_ERR_INVALID_PARAM ;
226+ }
227+
228+ token = strtok_r (opt_arg , delim , & saveptr );
229+ status = parse_mem_type (token , & mem_type );
230+ if (status != UCS_OK ) {
231+ return status ;
232+ }
233+
234+ token = strtok_r (NULL , delim , & saveptr );
235+ if (NULL == token ) {
236+ device_id = UCX_PERF_MEM_DEV_DEFAULT ;
237+ } else {
238+ status = parse_device_id (token , & device_id );
239+ if (status != UCS_OK ) {
240+ return status ;
241+ }
242+ }
243+
244+ dev -> mem_type = mem_type ;
245+ dev -> device_id = device_id ;
246+ return UCS_OK ;
247+ }
248+
189249static ucs_status_t parse_mem_type_params (const char * opt_arg ,
190250 ucs_memory_type_t * send_mem_type ,
191251 ucs_memory_type_t * recv_mem_type )
@@ -208,6 +268,45 @@ static ucs_status_t parse_mem_type_params(const char *opt_arg,
208268 }
209269}
210270
271+ static ucs_status_t parse_accel_device_params (const char * opt_arg ,
272+ ucx_perf_accel_dev_t * send_device ,
273+ ucx_perf_accel_dev_t * recv_device )
274+ {
275+ const char * delim = "," ;
276+ char * saveptr = NULL ;
277+ char * token , * arg ;
278+ ucs_status_t status ;
279+
280+ arg = ucs_alloca (strlen (opt_arg ) + 1 );
281+ strcpy (arg , opt_arg );
282+ token = strtok_r (arg , delim , & saveptr );
283+ status = parse_accel_device (token , send_device );
284+ if (status != UCS_OK ) {
285+ return status ;
286+ }
287+
288+ token = strtok_r (NULL , delim , & saveptr );
289+ if (NULL == token ) {
290+ * recv_device = * send_device ;
291+ return UCS_OK ;
292+ }
293+
294+ status = parse_accel_device (token , recv_device );
295+ if (status != UCS_OK ) {
296+ return status ;
297+ }
298+
299+ if (send_device -> mem_type == recv_device -> mem_type ) {
300+ if (send_device -> device_id == UCX_PERF_MEM_DEV_DEFAULT ) {
301+ send_device -> device_id = recv_device -> device_id ;
302+ } else if (recv_device -> device_id == UCX_PERF_MEM_DEV_DEFAULT ) {
303+ recv_device -> device_id = send_device -> device_id ;
304+ }
305+ }
306+
307+ return UCS_OK ;
308+ }
309+
211310static ucs_status_t parse_message_sizes_params (const char * opt_arg ,
212311 ucx_perf_params_t * params )
213312{
@@ -504,6 +603,13 @@ ucs_status_t parse_test_params(perftest_params_t *params, char opt,
504603 return UCS_ERR_INVALID_PARAM ;
505604 }
506605 return UCS_OK ;
606+ case 'a' :
607+ if (UCS_OK != parse_accel_device_params (opt_arg ,
608+ & params -> super .send_device ,
609+ & params -> super .recv_device )) {
610+ return UCS_ERR_INVALID_PARAM ;
611+ }
612+ return UCS_OK ;
507613 case 'y' :
508614 params -> super .flags |= UCX_PERF_TEST_FLAG_AM_RECV_COPY ;
509615 return UCS_OK ;
0 commit comments