-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add pylibcudf bindings for fetch_byte_ranges_to_device
#23543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Matt711
wants to merge
22
commits into
NVIDIA:main
Choose a base branch
from
Matt711:fea/pylibcudf/fetch-byte-ranges
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4e6a046
Add pylibcudf bindings for fetch_byte_ranges_to_device
Matt711 1f3530f
use byte_slice
Matt711 10c03f1
Merge branch 'main' into fea/pylibcudf/fetch-byte-ranges
Matt711 eab58d0
add missing bindings
Matt711 0ed0a28
merge conflict
Matt711 09c4ad3
remove cdef
Matt711 007007b
add negative test cases
Matt711 b95b6b1
doc location
Matt711 0568a90
fix docstring
Matt711 fbdfdf2
use libcudf_exception_handler
Matt711 337fbad
raise for more than one device buffer
Matt711 9855657
raise if pointer is NULL
Matt711 ed680f2
add consts to decl
Matt711 3dd055e
use dize_t
Matt711 c6b52b4
Merge branch 'main' into fea/pylibcudf/fetch-byte-ranges
Matt711 53df649
remove const
Matt711 ef2129d
docs
Matt711 8f3cd40
Merge branch 'main' into fea/pylibcudf/fetch-byte-ranges
Matt711 4544758
add note about resolving future
Matt711 760509e
remove redundant check
Matt711 1996cf0
fix cython signature
Matt711 20df137
fix cython signature for device_span methods
Matt711 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ============ | ||
| Experimental | ||
| ============ | ||
|
|
||
| APIs in this namespace are experimental and may change without warning in the future. | ||
|
|
||
| .. automodule:: pylibcudf.io.experimental | ||
| :members: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,11 @@ I/O Functions | |
|
|
||
| avro | ||
| csv | ||
| experimental | ||
| json | ||
| orc | ||
| parquet | ||
| parquet_io_utils | ||
| parquet_metadata | ||
| text | ||
| timezone | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ================ | ||
| Parquet IO Utils | ||
| ================ | ||
|
|
||
| .. automodule:: pylibcudf.io.parquet_io_utils | ||
| :members: | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from pylibcudf.io.text cimport ByteRangeInfo | ||
| from pylibcudf.io.types cimport SourceInfo | ||
| from rmm.pylibrmm.memory_resource cimport DeviceMemoryResource | ||
|
|
||
| cpdef list fetch_byte_ranges_to_device( | ||
| SourceInfo source_info, | ||
| list byte_ranges, | ||
| object stream=*, | ||
| DeviceMemoryResource mr=*, | ||
| ) | ||
|
|
||
| cpdef bytes fetch_page_index_to_host( | ||
| SourceInfo source_info, | ||
| ByteRangeInfo page_index_range, | ||
| ) | ||
|
Matt711 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from rmm.pylibrmm.memory_resource import DeviceMemoryResource | ||
|
|
||
| from pylibcudf.gpumemoryview import gpumemoryview | ||
| from pylibcudf.io.text import ByteRangeInfo | ||
| from pylibcudf.io.types import SourceInfo | ||
| from pylibcudf.utils import CudaStreamLike | ||
|
|
||
| __all__ = ["fetch_byte_ranges_to_device", "fetch_page_index_to_host"] | ||
|
|
||
| def fetch_byte_ranges_to_device( | ||
| source_info: SourceInfo, | ||
| byte_ranges: list[ByteRangeInfo], | ||
| stream: CudaStreamLike | None = None, | ||
| mr: DeviceMemoryResource | None = None, | ||
| ) -> list[gpumemoryview]: ... | ||
| def fetch_page_index_to_host( | ||
| source_info: SourceInfo, | ||
| page_index_range: ByteRangeInfo, | ||
| ) -> bytes: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """IO utilities for Parquet.""" | ||
|
|
||
| from libc.stddef cimport size_t | ||
| from libc.stdint cimport uint8_t, uintptr_t | ||
| from libcpp.memory cimport make_unique, unique_ptr | ||
| from libcpp.pair cimport pair | ||
| from libcpp.utility cimport move | ||
| from libcpp.vector cimport vector | ||
| from cython.operator cimport dereference | ||
|
|
||
| from rmm.librmm.device_buffer cimport device_buffer | ||
| from rmm.pylibrmm.device_buffer cimport DeviceBuffer | ||
| from rmm.pylibrmm.memory_resource cimport DeviceMemoryResource | ||
| from rmm.pylibrmm.stream cimport Stream | ||
|
|
||
| from pylibcudf.gpumemoryview cimport gpumemoryview | ||
| from pylibcudf.io.text cimport ByteRangeInfo | ||
| from pylibcudf.io.types cimport SourceInfo | ||
| from pylibcudf.libcudf.io.datasource cimport datasource, make_datasources | ||
| from pylibcudf.libcudf.io.parquet_io_utils cimport ( | ||
| const_byte_range_info, | ||
| const_uint8_t, | ||
| cpp_fetch_byte_ranges_to_device, | ||
| fetch_page_index_to_host as cpp_fetch_page_index_to_host, | ||
| ) | ||
|
|
||
| from pylibcudf.libcudf.io.text cimport byte_range_info | ||
| from pylibcudf.libcudf.utilities.span cimport device_span, host_span | ||
| from pylibcudf.utils cimport _get_memory_resource, _get_stream | ||
|
|
||
| __all__ = ["fetch_byte_ranges_to_device", "fetch_page_index_to_host"] | ||
|
|
||
|
|
||
| cpdef list fetch_byte_ranges_to_device( | ||
| SourceInfo source_info, | ||
| list byte_ranges, | ||
| object stream=None, | ||
| DeviceMemoryResource mr=None, | ||
| ): | ||
| """Fetch byte ranges from a Parquet source into device memory. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| source_info : SourceInfo | ||
| Source describing a single Parquet file. | ||
| byte_ranges : list[ByteRangeInfo] | ||
| Byte ranges to fetch, as returned by | ||
| :meth:`~pylibcudf.io.experimental.HybridScanReader.filter_column_chunks_byte_ranges`, | ||
| :meth:`~pylibcudf.io.experimental.HybridScanReader.payload_column_chunks_byte_ranges`, | ||
| or | ||
| :meth:`~pylibcudf.io.experimental.HybridScanReader.all_column_chunks_byte_ranges`. | ||
| stream : Stream, optional | ||
| CUDA stream. | ||
| mr : DeviceMemoryResource, optional | ||
| Device memory resource. | ||
|
|
||
| Returns | ||
| ------- | ||
| list[gpumemoryview] | ||
| One view per byte range. Each view holds a reference to the | ||
| :class:`~rmm.DeviceBuffer` that owns its memory, keeping the | ||
| allocation alive for as long as the view is referenced. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
| If ``source_info`` does not describe exactly one source. | ||
| """ | ||
| cdef Stream _stream = _get_stream(stream) | ||
| cdef DeviceMemoryResource _mr = _get_memory_resource(mr) | ||
| cdef vector[unique_ptr[datasource]] sources = make_datasources(source_info.c_obj) | ||
| if sources.size() != 1: | ||
| raise ValueError( | ||
| f"fetch_byte_ranges_to_device requires exactly one source, " | ||
| f"got {sources.size()}" | ||
| ) | ||
|
|
||
| cdef vector[byte_range_info] ranges_vec | ||
| cdef ByteRangeInfo bri | ||
| for bri in byte_ranges: | ||
| ranges_vec.push_back(bri.c_obj) | ||
|
|
||
| cdef pair[vector[device_buffer], vector[device_span[const_uint8_t]]] fetched | ||
| with nogil: | ||
| fetched = cpp_fetch_byte_ranges_to_device( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a note here that this ensures the C++ future is complete?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added here 4544758 |
||
| dereference(sources[0]), | ||
| host_span[const_byte_range_info](ranges_vec.data(), ranges_vec.size()), | ||
| _stream.view(), | ||
| _mr.get_mr(), | ||
| ) | ||
|
|
||
| if fetched.first.size() != 1: | ||
| raise RuntimeError( | ||
| f"Expected exactly one device buffer, got {fetched.first.size()}" | ||
| ) | ||
| cdef DeviceBuffer owner = DeviceBuffer.c_from_unique_ptr( | ||
| make_unique[device_buffer](move(fetched.first[0])), | ||
| _stream, | ||
| _mr, | ||
| ) | ||
| cdef gpumemoryview owner_gv = gpumemoryview(owner) | ||
| cdef uintptr_t base = owner_gv.ptr | ||
| cdef uintptr_t ptr | ||
| cdef size_t n | ||
| result = [] | ||
| for i in range(fetched.second.size()): | ||
| ptr = <uintptr_t>fetched.second[i].data() | ||
| n = fetched.second[i].size() | ||
| result.append(owner_gv.byte_slice(slice(ptr - base, ptr - base + n))) | ||
| return result | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
|
|
||
| cpdef bytes fetch_page_index_to_host( | ||
| SourceInfo source_info, | ||
| ByteRangeInfo page_index_range, | ||
| ): | ||
| """Fetch parquet page index bytes to host memory. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| source_info : SourceInfo | ||
| Source describing a single Parquet file. | ||
| page_index_range : ByteRangeInfo | ||
| Byte range of the page index, as returned by | ||
| :meth:`~pylibcudf.io.experimental.HybridScanReader.page_index_byte_range`. | ||
|
|
||
| Returns | ||
| ------- | ||
| bytes | ||
| Raw page index bytes copied to Python host memory. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
| If ``source_info`` does not describe exactly one source. | ||
| """ | ||
| cdef vector[unique_ptr[datasource]] sources = make_datasources(source_info.c_obj) | ||
| if sources.size() != 1: | ||
| raise ValueError( | ||
| f"fetch_page_index_to_host requires exactly one source, " | ||
| f"got {sources.size()}" | ||
| ) | ||
|
|
||
| cdef unique_ptr[datasource.buffer] buf | ||
| with nogil: | ||
| buf = move(cpp_fetch_page_index_to_host( | ||
| dereference(sources[0]), | ||
| (<ByteRangeInfo>page_index_range).c_obj, | ||
| )) | ||
|
|
||
| if buf.get() is NULL: | ||
| raise RuntimeError("fetch_page_index_to_host returned no buffer") | ||
| cdef const uint8_t* ptr = buf.get().data() | ||
| cdef size_t n = buf.get().size() | ||
| return bytes(ptr[:n]) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.