Skip to content

Commit

Permalink
pyverbs: Extend MR's write method
Browse files Browse the repository at this point in the history
The current implementation of write() doesn't take an offset parameter.
In UD this means that extra 40 bytes need to be written, so that the
GRH won't override the beginning of the message.
Add offset parameter to write().

Signed-off-by: Maxim Chicherin <maximc@mellanox.com>
Signed-off-by: Edward Srouji <edwards@mellanox.com>
  • Loading branch information
maxim-chi authored and EdwardSro committed Jul 19, 2020
1 parent 3bc496f commit 0423e44
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pyverbs/mr.pyx
Expand Up @@ -129,21 +129,23 @@ cdef class MR(PyverbsCM):
self.pd = None
self.buf = NULL

def write(self, data, length):
def write(self, data, length, offset=0):
"""
Write user data to the MR's buffer using memcpy
:param data: User data to write
:param length: Length of the data to write
:param offset: Writing offset
:return: None
"""
if not self.buf or length < 0:
raise PyverbsUserError('The MR buffer isn\'t allocated or length'
f' {length} is invalid')
# If data is a string, cast it to bytes as Python3 doesn't
# automatically convert it.
cdef int off = offset
if isinstance(data, str):
data = data.encode()
memcpy(self.buf, <char *>data, length)
memcpy(<char*>(self.buf + off), <char *>data, length)

cpdef read(self, length, offset):
"""
Expand Down

0 comments on commit 0423e44

Please sign in to comment.