Skip to content

Commit

Permalink
pyverbs/efa: Add EFA direct verbs query MR
Browse files Browse the repository at this point in the history
Expose efadv_query_mr verb and the related types in pyverbs.

Signed-off-by: Michael Margolin <[email protected]>
  • Loading branch information
mrgolin committed Jan 11, 2024
1 parent 63e2a42 commit 620ae50
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
7 changes: 6 additions & 1 deletion pyverbs/providers/efa/efa_enums.pyx
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
# Copyright 2020-2023 Amazon.com, Inc. or its affiliates. All rights reserved.
# Copyright 2020-2024 Amazon.com, Inc. or its affiliates. All rights reserved.

#cython: language_level=3

Expand All @@ -15,3 +15,8 @@ cdef extern from 'infiniband/efadv.h':

cpdef enum:
EFADV_WC_EX_WITH_SGID

cpdef enum:
EFADV_MR_ATTR_VALIDITY_RECV_IC_ID
EFADV_MR_ATTR_VALIDITY_RDMA_READ_IC_ID
EFADV_MR_ATTR_VALIDITY_RDMA_RECV_IC_ID
6 changes: 5 additions & 1 deletion pyverbs/providers/efa/efadv.pxd
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
# Copyright 2020-2022 Amazon.com, Inc. or its affiliates. All rights reserved.
# Copyright 2020-2024 Amazon.com, Inc. or its affiliates. All rights reserved.

#cython: language_level=3

Expand Down Expand Up @@ -46,3 +46,7 @@ cdef class EfaCQ(CQEX):

cdef class EfaDVCQInitAttr(PyverbsObject):
cdef dv.efadv_cq_init_attr cq_init_attr


cdef class EfaDVMRAttr(PyverbsObject):
cdef dv.efadv_mr_attr mr_attr
54 changes: 53 additions & 1 deletion pyverbs/providers/efa/efadv.pyx
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
# Copyright 2020-2023 Amazon.com, Inc. or its affiliates. All rights reserved.
# Copyright 2020-2024 Amazon.com, Inc. or its affiliates. All rights reserved.

cimport pyverbs.providers.efa.efadv_enums as dve
cimport pyverbs.providers.efa.libefa as dv
Expand All @@ -11,6 +11,7 @@ import pyverbs.enums as e
cimport pyverbs.libibverbs as v
from pyverbs.pd cimport PD
from pyverbs.qp cimport QP, QPEx, QPInitAttr, QPInitAttrEx
from pyverbs.mr cimport MR


def dev_cap_to_str(flags):
Expand Down Expand Up @@ -250,3 +251,54 @@ cdef class EfaCQ(CQEX):
if err:
return None
return sgid


cdef class EfaDVMRAttr(PyverbsObject):
"""
Represents efadv_mr_attr struct, which exposes efa-specific MR attributes,
reported by efadv_query_mr.
"""
@property
def comp_mask(self):
return self.mr_attr.comp_mask

@property
def ic_id_validity(self):
return self.mr_attr.ic_id_validity

@property
def recv_ic_id(self):
return self.mr_attr.recv_ic_id

@property
def rdma_read_ic_id(self):
return self.mr_attr.rdma_read_ic_id

@property
def rdma_recv_ic_id(self):
return self.mr_attr.rdma_recv_ic_id

def __str__(self):
print_format = '{:28}: {:<20}\n'
return print_format.format('comp_mask', self.mr_attr.comp_mask) + \
print_format.format('Interconnect id validity', self.mr_attr.ic_id_validity) + \
print_format.format('Receive interconnect id', self.mr_attr.recv_ic_id) + \
print_format.format('RDMA read interconnect id', self.mr_attr.rdma_read_ic_id) + \
print_format.format('RDMA receive interconnect id', self.mr_attr.rdma_recv_ic_id)


cdef class EfaMR(MR):
"""
Represents an MR with EFA specific properties
"""
def query(self):
"""
Queries the MR for device-specific attributes.
:return: An EfaDVMRAttr containing the attributes.
"""
mr_attr = EfaDVMRAttr()
rc = dv.efadv_query_mr(self.mr, &mr_attr.mr_attr, sizeof(mr_attr.mr_attr))
if rc:
raise PyverbsRDMAError(f'Failed to query EFA MR', rc)

return mr_attr
5 changes: 5 additions & 0 deletions pyverbs/providers/efa/efadv_enums.pxd
Expand Up @@ -16,3 +16,8 @@ cdef extern from 'infiniband/efadv.h':

cpdef enum:
EFADV_WC_EX_WITH_SGID

cpdef enum:
EFADV_MR_ATTR_VALIDITY_RECV_IC_ID
EFADV_MR_ATTR_VALIDITY_RDMA_READ_IC_ID
EFADV_MR_ATTR_VALIDITY_RDMA_RECV_IC_ID
10 changes: 9 additions & 1 deletion pyverbs/providers/efa/libefa.pxd
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
# Copyright 2020-2022 Amazon.com, Inc. or its affiliates. All rights reserved.
# Copyright 2020-2024 Amazon.com, Inc. or its affiliates. All rights reserved.

from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t
cimport pyverbs.libibverbs as v
Expand Down Expand Up @@ -35,6 +35,13 @@ cdef extern from 'infiniband/efadv.h':
cdef struct efadv_cq:
uint64_t comp_mask;

cdef struct efadv_mr_attr:
uint64_t comp_mask;
uint16_t ic_id_validity;
uint16_t recv_ic_id;
uint16_t rdma_read_ic_id;
uint16_t rdma_recv_ic_id;

int efadv_query_device(v.ibv_context *ibvctx, efadv_device_attr *attrs,
uint32_t inlen)
int efadv_query_ah(v.ibv_ah *ibvah, efadv_ah_attr *attr,
Expand All @@ -51,3 +58,4 @@ cdef extern from 'infiniband/efadv.h':
uint32_t inlen)
efadv_cq *efadv_cq_from_ibv_cq_ex(v.ibv_cq_ex *ibvcqx)
int efadv_wc_read_sgid(efadv_cq *efadv_cq, v.ibv_gid *sgid)
int efadv_query_mr(v.ibv_mr *ibvmr, efadv_mr_attr *attr, uint32_t inlen)

0 comments on commit 620ae50

Please sign in to comment.