@@ -1000,6 +1000,51 @@ static uint64_t ucp_str_array_search(const char **array, unsigned array_len,
10001000 return result ;
10011001}
10021002
1003+ /* Search str in the ranges that are specified in the array.
1004+ * Ranges are a prefix followed by a [range_start-range_end] suffix. (ex: mlx5_[0-2])
1005+ * @return bitmap of indexes in which the string appears in the array.
1006+ */
1007+ static uint64_t ucp_str_array_search_in_ranges (const char * * array ,
1008+ unsigned array_len ,
1009+ const char * str )
1010+ {
1011+ unsigned long range_start , range_end , str_id ;
1012+ size_t prefix_len ;
1013+ uint64_t result ;
1014+ const char * p ;
1015+ char * endptr ;
1016+ unsigned i ;
1017+
1018+ result = 0 ;
1019+ for (i = 0 ; i < array_len ; ++ i ) {
1020+ p = strchr (array [i ], '[' );
1021+ if (p == NULL ) {
1022+ continue ; /* Not a range */
1023+ }
1024+
1025+ prefix_len = (size_t )(p - array [i ]);
1026+ if (strncmp (array [i ], str , prefix_len )) {
1027+ continue ; /* Prefix does not match */
1028+ }
1029+
1030+ if (sscanf (p , "[%lu-%lu]" , & range_start , & range_end ) != 2 ||
1031+ range_start > range_end ) {
1032+ ucs_warn ("invalid device range: %s" , array [i ]);
1033+ continue ;
1034+ }
1035+
1036+ str_id = strtoul (str + prefix_len , & endptr , 10 );
1037+ if ((endptr == str + prefix_len ) || (* endptr != '\0' ) ||
1038+ (str_id < range_start ) || (str_id > range_end )) {
1039+ continue ; /* Mismatch */
1040+ }
1041+
1042+ result |= UCS_BIT (i );
1043+ }
1044+
1045+ return result ;
1046+ }
1047+
10031048static unsigned ucp_tl_alias_count (ucp_tl_alias_t * alias )
10041049{
10051050 unsigned count ;
@@ -1052,17 +1097,22 @@ static int ucp_is_resource_in_device_list(const uct_tl_resource_desc_t *resource
10521097 devices [dev_type ].count , resource -> dev_name ,
10531098 NULL );
10541099
1055- /* For mlx devices, if the current resource is the default port
1056- * (ex: mlx5_0:1), try matching the basename with the device list */
1057- if (!mask && (dev_type == UCT_DEVICE_TYPE_NET ) &&
1100+ /* mlx device with the default port */
1101+ if ((dev_type == UCT_DEVICE_TYPE_NET ) &&
10581102 UCP_IS_RESOURCE_MLX_DEFAULT_PORT (resource )) {
1059- mask = ucp_str_array_search ((const char * * )devices [dev_type ].names ,
1060- devices [dev_type ].count ,
1061- resource -> dev_name_base , NULL );
1103+ /* search for the base name (ex: mlx5_0) */
1104+ mask |= ucp_str_array_search ((const char * * )devices [dev_type ].names ,
1105+ devices [dev_type ].count ,
1106+ resource -> dev_name_base , NULL );
1107+
1108+ /* search for ranges (ex: mlx5_[0-2]) */
1109+ mask |= ucp_str_array_search_in_ranges (
1110+ (const char * * )devices [dev_type ].names , devices [dev_type ].count ,
1111+ resource -> dev_name_base );
10621112 }
10631113
1114+ /* if the user's list is 'all', use all the available resources */
10641115 if (!mask ) {
1065- /* if the user's list is 'all', use all the available resources */
10661116 mask = ucp_str_array_search ((const char * * )devices [dev_type ].names ,
10671117 devices [dev_type ].count , UCP_RSC_CONFIG_ALL ,
10681118 NULL );
@@ -1230,7 +1280,6 @@ static int ucp_is_resource_enabled(const uct_tl_resource_desc_t *resource,
12301280 resource , config -> devices , & dev_cfg_masks [resource -> dev_type ],
12311281 resource -> dev_type );
12321282
1233-
12341283 /* Find the enabled UCTs */
12351284 * rsc_flags = 0 ;
12361285 tl_enabled = ucp_is_resource_in_transports_list (resource -> tl_name ,
0 commit comments