Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cuda_bindings/cuda/bindings/cufile.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ cpdef intptr_t handle_register(intptr_t descr) except? 0
cpdef void handle_deregister(intptr_t fh) except*
cpdef buf_register(intptr_t buf_ptr_base, size_t length, int flags)
cpdef buf_deregister(intptr_t buf_ptr_base)
cpdef read(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset)
cpdef write(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset)
cpdef driver_open()
cpdef use_count()
cpdef driver_get_properties(intptr_t props)
Expand Down
75 changes: 41 additions & 34 deletions cuda_bindings/cuda/bindings/cufile.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2281,40 +2281,6 @@ cpdef buf_deregister(intptr_t buf_ptr_base):
check_status(__status__)


cpdef read(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset):
"""read data from a registered file handle to a specified device or host memory.

Args:
fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
buf_ptr_base (intptr_t): base address of buffer in device or host memory.
size (size_t): size bytes to read.
file_offset (off_t): file-offset from begining of the file.
buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to read into.

.. seealso:: `cuFileRead`
"""
with nogil:
__status__ = cuFileRead(<Handle>fh, <void*>buf_ptr_base, size, file_offset, buf_ptr_offset)
check_status(__status__)


cpdef write(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset):
"""write data from a specified device or host memory to a registered file handle.

Args:
fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
buf_ptr_base (intptr_t): base address of buffer in device or host memory.
size (size_t): size bytes to write.
file_offset (off_t): file-offset from begining of the file.
buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to write from.

.. seealso:: `cuFileWrite`
"""
with nogil:
__status__ = cuFileWrite(<Handle>fh, <const void*>buf_ptr_base, size, file_offset, buf_ptr_offset)
check_status(__status__)


cpdef driver_open():
"""Initialize the cuFile library and open the nvidia-fs driver.

Expand Down Expand Up @@ -2689,3 +2655,44 @@ cpdef driver_close():
with nogil:
status = cuFileDriverClose_v2()
check_status(status)

cpdef read(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read should also have similar documentation as Write.
Can you also updates the tests to check for bytes returned?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed that this docstring was different when I approved the related cybind MR. We will also need to file another MR to update this over there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes whoops added to this repo and corresponding cybind MR :)

"""read data from a registered file handle to a specified device or host memory.

Args:
fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
buf_ptr_base (intptr_t): base address of buffer in device or host memory.
size (size_t): size bytes to read.
file_offset (off_t): file-offset from begining of the file.
buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to read into.

Returns:
ssize_t: number of bytes read on success.

.. seealso:: `cuFileRead`
"""
with nogil:
status = cuFileRead(<Handle>fh, <void*>buf_ptr_base, size, file_offset, buf_ptr_offset)
check_status(status)
return status


cpdef write(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset):
"""write data from a specified device or host memory to a registered file handle.

Args:
fh (intptr_t): ``CUfileHandle_t`` opaque file handle.
buf_ptr_base (intptr_t): base address of buffer in device or host memory.
size (size_t): size bytes to write.
file_offset (off_t): file-offset from begining of the file.
buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to write from.

Returns:
ssize_t: number of bytes written on success.

.. seealso:: `cuFileWrite`
"""
with nogil:
status = cuFileWrite(<Handle>fh, <const void*>buf_ptr_base, size, file_offset, buf_ptr_offset)
check_status(status)
return status
15 changes: 15 additions & 0 deletions cuda_bindings/tests/test_cufile.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ def test_cufile_read_write():
# Read data back using cuFile
bytes_read = cufile.read(handle, read_buf_int, write_size, 0, 0)

# Verify bytes written equals bytes read
assert bytes_written == write_size, f"Expected to write {write_size} bytes, but wrote {bytes_written}"
assert bytes_read == write_size, f"Expected to read {write_size} bytes, but read {bytes_read}"
assert bytes_written == bytes_read, f"Bytes written ({bytes_written}) doesn't match bytes read ({bytes_read})"

# Copy read data back to host
cuda.cuMemcpyDtoHAsync(host_buf, read_buf, write_size, 0)
cuda.cuStreamSynchronize(0)
Expand Down Expand Up @@ -636,6 +641,11 @@ def test_cufile_read_write_host_memory():
# Read data back using cuFile
bytes_read = cufile.read(handle, read_buf_int, write_size, 0, 0)

# Verify bytes written equals bytes read
assert bytes_written == write_size, f"Expected to write {write_size} bytes, but wrote {bytes_written}"
assert bytes_read == write_size, f"Expected to read {write_size} bytes, but read {bytes_read}"
assert bytes_written == bytes_read, f"Bytes written ({bytes_written}) doesn't match bytes read ({bytes_read})"

# Verify the data
read_data = ctypes.string_at(read_buf, write_size)
expected_data = write_buf_content
Expand Down Expand Up @@ -738,6 +748,11 @@ def test_cufile_read_write_large():
# Read data back using cuFile
bytes_read = cufile.read(handle, read_buf_int, write_size, 0, 0)

# Verify bytes written equals bytes read
assert bytes_written == write_size, f"Expected to write {write_size} bytes, but wrote {bytes_written}"
assert bytes_read == write_size, f"Expected to read {write_size} bytes, but read {bytes_read}"
assert bytes_written == bytes_read, f"Bytes written ({bytes_written}) doesn't match bytes read ({bytes_read})"

# Copy read data back to host
cuda.cuMemcpyDtoHAsync(host_buf, read_buf, write_size, 0)
cuda.cuStreamSynchronize(0)
Expand Down
Loading