Skip to content

Commit 8f7f7a1

Browse files
committed
fabric: Add fi_hmem_attr to fi_info structure
FI_HMEM is only an on/off capability bit but there are more specific capabilities. Add fi_hmem_attr to fi_info to provide better control over: - whether device API calls are permitted in libfabric, except for FI_HMEM initialization. - whether peer to peer transfers should be used. - whether optimized memcpy for device mempry should be used. This change results in the ABI needing to be updated. A new compatibility set of interfaces is the result. Signed-off-by: Jessie Yang <[email protected]>
1 parent ffeb3a8 commit 8f7f7a1

12 files changed

+211
-29
lines changed

include/ofi_abi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ extern "C" {
111111
* name appended with the ABI version that it is compatible with.
112112
*/
113113

114-
#define CURRENT_ABI "FABRIC_1.7"
114+
#define CURRENT_ABI "FABRIC_1.8"
115115

116116
#if HAVE_ALIAS_ATTRIBUTE == 1
117117
#define DEFAULT_SYMVER_PRE(a) a##_

include/ofi_util.h

+1
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,7 @@ int ofi_check_rx_attr(const struct fi_provider *prov,
11131113
int ofi_check_tx_attr(const struct fi_provider *prov,
11141114
const struct fi_tx_attr *prov_attr,
11151115
const struct fi_tx_attr *user_attr, uint64_t info_mode);
1116+
int ofi_check_hmem_attr(const struct fi_provider *prov, const struct fi_info *user_info);
11161117
int ofi_check_attr_subset(const struct fi_provider *prov,
11171118
uint64_t base_caps, uint64_t requested_caps);
11181119
int ofi_prov_check_info(const struct util_prov *util_prov,

include/rdma/fabric.h

+26
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,22 @@ enum {
360360
FI_TC_NETWORK_CTRL,
361361
};
362362

363+
enum fi_hmem_iface {
364+
FI_HMEM_SYSTEM = 0,
365+
FI_HMEM_CUDA,
366+
FI_HMEM_ROCR,
367+
FI_HMEM_ZE,
368+
FI_HMEM_NEURON,
369+
FI_HMEM_SYNAPSEAI,
370+
};
371+
372+
enum fi_hmem_attr_opt {
373+
FI_HMEM_ATTR_ENABLED,
374+
FI_HMEM_ATTR_REQUIRED,
375+
FI_HMEM_ATTR_PREFERRED,
376+
FI_HMEM_ATTR_DISABLED
377+
};
378+
363379
static inline uint32_t fi_tc_dscp_set(uint8_t dscp)
364380
{
365381
return ((uint32_t) dscp) | FI_TC_DSCP;
@@ -465,6 +481,14 @@ struct fi_fabric_attr {
465481
uint32_t api_version;
466482
};
467483

484+
struct fi_hmem_attr {
485+
enum fi_hmem_iface iface;
486+
enum fi_hmem_attr_opt api_permitted;
487+
enum fi_hmem_attr_opt use_p2p;
488+
enum fi_hmem_attr_opt use_dev_reg_copy;
489+
struct fi_hmem_attr *next;
490+
};
491+
468492
struct fi_info {
469493
struct fi_info *next;
470494
uint64_t caps;
@@ -480,6 +504,7 @@ struct fi_info {
480504
struct fi_ep_attr *ep_attr;
481505
struct fi_domain_attr *domain_attr;
482506
struct fi_fabric_attr *fabric_attr;
507+
struct fi_hmem_attr *hmem_attr;
483508
struct fid_nic *nic;
484509
};
485510

@@ -771,6 +796,7 @@ enum fi_type {
771796
FI_TYPE_MR_ATTR,
772797
FI_TYPE_CNTR_ATTR,
773798
FI_TYPE_CQ_ERR_ENTRY,
799+
FI_TYPE_HMEM_ATTR,
774800
};
775801

776802
char *fi_tostr(const void *data, enum fi_type datatype);

include/rdma/fi_domain.h

-9
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,6 @@ struct fid_mr {
128128
uint64_t key;
129129
};
130130

131-
enum fi_hmem_iface {
132-
FI_HMEM_SYSTEM = 0,
133-
FI_HMEM_CUDA,
134-
FI_HMEM_ROCR,
135-
FI_HMEM_ZE,
136-
FI_HMEM_NEURON,
137-
FI_HMEM_SYNAPSEAI,
138-
};
139-
140131
static inline int fi_hmem_ze_device(int driver_index, int device_index)
141132
{
142133
return driver_index << 16 | device_index;

man/fabric.7.md

+8
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,14 @@ attributes:
447447
*fi_domain_attr*
448448
: Added max_ep_auth_key
449449

450+
## ABI 1.8
451+
ABI version starting with libfabric 2.0. Expanded the following structure.
452+
453+
*fi_info*
454+
: The fi_info structure was expanded to reference a new fabric object,
455+
fi_hmem_attr. When available, the fi_hmem_attr references a new set of
456+
attributes related to heterogeneous memory.
457+
450458
# SEE ALSO
451459

452460
[`fi_info`(1)](fi_info.1.html),

man/fi_fabric.3.md

+3
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ datatype or field value.
177177
*FI_TYPE_LOG_SUBSYS*
178178
: enum fi_log_subsys
179179
180+
*FI_TYPE_HMEM_ATTR*
181+
: struct fi_hmem_attr
182+
180183
fi_tostr() will return a pointer to an internal libfabric buffer that
181184
should not be modified, and will be overwritten the next time
182185
fi_tostr() is invoked. fi_tostr() is not thread safe.

man/fi_getinfo.3.md

+8
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ struct fi_info {
142142
struct fi_ep_attr *ep_attr;
143143
struct fi_domain_attr *domain_attr;
144144
struct fi_fabric_attr *fabric_attr;
145+
struct fi_hmem_attr *hmem_attr;
145146
struct fid_nic *nic;
146147
};
147148
```
@@ -242,6 +243,13 @@ struct fi_info {
242243
output, the actual fabric attributes that can be provided will be
243244
returned. See [`fi_fabric`(3)](fi_fabric.3.html) for details.
244245

246+
*hmem_attr - heterogeneous memory attributes*
247+
: Optionally supplied HMEM attributes. HMEM attributes may be
248+
specified and returned as part of fi_getinfo. When provided as
249+
hints, requested values of struct fi_hmem_attr should be set. On
250+
output, the actual HMEM attributes that can be provided will be
251+
returned.
252+
245253
*nic - network interface details*
246254
: Optional attributes related to the hardware NIC associated with
247255
the specified fabric, domain, and endpoint data. This field is

man/fi_info.1.md

+5
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ fi_info:
200200
prov_name: verbs;ofi_rxd
201201
prov_version: 116.0
202202
api_version: 1.16
203+
fi_hmem_attr:
204+
iface:
205+
api_permitted:
206+
use_p2p:
207+
use_dev_reg_copy:
203208
nic:
204209
fi_device_attr:
205210
name: mlx5_0

prov/util/src/util_attr.c

+37
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,17 @@ int ofi_check_tx_attr(const struct fi_provider *prov,
10021002
return 0;
10031003
}
10041004

1005+
int ofi_check_hmem_attr(const struct fi_provider *prov,
1006+
const struct fi_info *user_info)
1007+
{
1008+
if (!(user_info->caps & FI_HMEM)) {
1009+
FI_INFO(prov, FI_LOG_CORE, "FI_HMEM not set\n");
1010+
return -FI_ENODATA;
1011+
}
1012+
1013+
return 0;
1014+
}
1015+
10051016
/* Use if there are multiple fi_info in the provider:
10061017
* check provider's info */
10071018
int ofi_prov_check_info(const struct util_prov *util_prov,
@@ -1152,6 +1163,13 @@ int ofi_check_info(const struct util_prov *util_prov,
11521163
if (ret)
11531164
return ret;
11541165
}
1166+
1167+
if (user_info->hmem_attr) {
1168+
ret = ofi_check_hmem_attr(prov, user_info);
1169+
if (ret)
1170+
return ret;
1171+
}
1172+
11551173
return 0;
11561174
}
11571175

@@ -1271,6 +1289,24 @@ static void fi_alter_tx_attr(struct fi_tx_attr *attr,
12711289
attr->rma_iov_limit = hints->rma_iov_limit;
12721290
}
12731291

1292+
static void fi_alter_hmem_attr(struct fi_hmem_attr *attr,
1293+
const struct fi_hmem_attr *hints)
1294+
{
1295+
if (!hints)
1296+
return;
1297+
1298+
if (hints->iface)
1299+
attr->iface = hints->iface;
1300+
if (hints->api_permitted)
1301+
attr->api_permitted = hints->api_permitted;
1302+
if (hints->use_p2p)
1303+
attr->use_p2p = hints->use_p2p;
1304+
if (hints->use_dev_reg_copy)
1305+
attr->use_dev_reg_copy = hints->use_dev_reg_copy;
1306+
if (hints->next)
1307+
attr->next = hints->next;
1308+
}
1309+
12741310
static uint64_t ofi_get_info_caps(const struct fi_info *prov_info,
12751311
const struct fi_info *user_info,
12761312
uint32_t api_version)
@@ -1336,5 +1372,6 @@ void ofi_alter_info(struct fi_info *info, const struct fi_info *hints,
13361372
info->caps);
13371373
fi_alter_tx_attr(info->tx_attr, hints ? hints->tx_attr : NULL,
13381374
info->caps);
1375+
fi_alter_hmem_attr(info->hmem_attr, hints ? hints->hmem_attr : NULL);
13391376
}
13401377
}

src/abi_1_0.c

+34
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,40 @@ struct fi_info_1_7 {
305305
struct fid_nic_1_7 *nic;
306306
};
307307

308+
struct fi_hmem_attr_1_8 {
309+
enum fi_hmem_iface iface;
310+
enum fi_hmem_attr_opt api_permitted;
311+
enum fi_hmem_attr_opt use_p2p;
312+
enum fi_hmem_attr_opt use_dev_reg_copy;
313+
struct fi_hmem_attr *next;
314+
};
315+
316+
#define fi_tx_attr_1_8 fi_tx_attr_1_7
317+
#define fi_rx_attr_1_8 fi_rx_attr_1_7
318+
#define fi_ep_attr_1_8 fi_ep_attr_1_7
319+
#define fi_domain_attr_1_8 fi_domain_attr_1_7
320+
#define fi_fabric_attr_1_8 fi_fabric_attr_1_7
321+
#define fid_nic_1_8 fid_nic_1_7
322+
323+
struct fi_info_1_8 {
324+
struct fi_info *next;
325+
uint64_t caps;
326+
uint64_t mode;
327+
uint32_t addr_format;
328+
size_t src_addrlen;
329+
size_t dest_addrlen;
330+
void *src_addr;
331+
void *dest_addr;
332+
fid_t handle;
333+
struct fi_tx_attr_1_8 *tx_attr;
334+
struct fi_rx_attr_1_8 *rx_attr;
335+
struct fi_ep_attr_1_8 *ep_attr;
336+
struct fi_domain_attr_1_8 *domain_attr;
337+
struct fi_fabric_attr_1_8 *fabric_attr;
338+
struct fi_hmem_attr_1_8 *hmem_attr;
339+
struct fid_nic_1_8 *nic;
340+
};
341+
308342
#define ofi_dup_attr(dst, src) \
309343
do { \
310344
dst = calloc(1, sizeof(*dst)); \

src/fabric.c

+31-3
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ __attribute__((visibility ("default"),EXTERNALLY_VISIBLE))
10411041
void DEFAULT_SYMVER_PRE(fi_freeinfo)(struct fi_info *info)
10421042
{
10431043
struct fi_info *next;
1044+
struct fi_hmem_attr *next_hmem_attr;
10441045

10451046
for (; info; info = next) {
10461047
next = info->next;
@@ -1063,6 +1064,12 @@ void DEFAULT_SYMVER_PRE(fi_freeinfo)(struct fi_info *info)
10631064
free(info->fabric_attr->prov_name);
10641065
free(info->fabric_attr);
10651066
}
1067+
if (info->hmem_attr) {
1068+
for (; info->hmem_attr; info->hmem_attr = next_hmem_attr) {
1069+
next_hmem_attr = info->hmem_attr->next;
1070+
free(info->hmem_attr);
1071+
}
1072+
}
10661073
if (info->nic &&
10671074
FI_CHECK_OP(info->nic->fid.ops, struct fi_ops, close)) {
10681075
fi_close(&info->nic->fid);
@@ -1303,6 +1310,21 @@ static int ofi_layering_ok(const struct fi_provider *provider,
13031310
return !strcasecmp(provider->name, prov_name);
13041311
}
13051312

1313+
static struct fi_hmem_attr *dup_hmem_attr(const struct fi_hmem_attr *hmem_attr)
1314+
{
1315+
if (!hmem_attr)
1316+
return NULL;
1317+
1318+
struct fi_hmem_attr *dup =
1319+
(struct fi_hmem_attr *) mem_dup(hmem_attr, sizeof(*hmem_attr));
1320+
if (!dup)
1321+
return NULL;
1322+
1323+
dup->next = dup_hmem_attr(hmem_attr->next);
1324+
1325+
return dup;
1326+
}
1327+
13061328
__attribute__((visibility ("default"),EXTERNALLY_VISIBLE))
13071329
int DEFAULT_SYMVER_PRE(fi_getinfo)(uint32_t version, const char *node,
13081330
const char *service, uint64_t flags,
@@ -1423,8 +1445,9 @@ struct fi_info *ofi_allocinfo_internal(void)
14231445
info->ep_attr = calloc(1, sizeof(*info->ep_attr));
14241446
info->domain_attr = calloc(1, sizeof(*info->domain_attr));
14251447
info->fabric_attr = calloc(1, sizeof(*info->fabric_attr));
1426-
if (!info->tx_attr|| !info->rx_attr || !info->ep_attr ||
1427-
!info->domain_attr || !info->fabric_attr)
1448+
info->hmem_attr = calloc(1, sizeof(*info->hmem_attr));
1449+
if (!info->tx_attr || !info->rx_attr || !info->ep_attr ||
1450+
!info->domain_attr || !info->fabric_attr || !info->hmem_attr)
14281451
goto err;
14291452

14301453
return info;
@@ -1454,6 +1477,7 @@ struct fi_info *DEFAULT_SYMVER_PRE(fi_dupinfo)(const struct fi_info *info)
14541477
dup->ep_attr = NULL;
14551478
dup->domain_attr = NULL;
14561479
dup->fabric_attr = NULL;
1480+
dup->hmem_attr = NULL;
14571481
dup->next = NULL;
14581482

14591483
if (info->src_addr != NULL) {
@@ -1526,7 +1550,11 @@ struct fi_info *DEFAULT_SYMVER_PRE(fi_dupinfo)(const struct fi_info *info)
15261550
goto fail;
15271551
}
15281552
}
1529-
1553+
if (info->hmem_attr) {
1554+
dup->hmem_attr = dup_hmem_attr(info->hmem_attr);
1555+
if (dup->hmem_attr == NULL)
1556+
goto fail;
1557+
}
15301558
if (info->nic) {
15311559
ret = fi_control(&info->nic->fid, FI_DUP, &dup->nic);
15321560
if (ret && ret != -FI_ENOSYS)

0 commit comments

Comments
 (0)