Skip to content
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

Start migrating I/O to pylibcudf #15899

Merged
merged 13 commits into from
Jun 6, 2024

Conversation

lithomas1
Copy link
Contributor

@lithomas1 lithomas1 commented May 31, 2024

Description

xref #15162

Starts migrating cudf I/O cython to use pylibcudf APIs, starting with avro.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@lithomas1 lithomas1 added feature request New feature or request non-breaking Non-breaking change pylibcudf Issues specific to the pylibcudf package labels May 31, 2024
@github-actions github-actions bot added Python Affects Python cuDF API. CMake CMake build issue labels May 31, 2024
@lithomas1 lithomas1 marked this pull request as ready for review June 3, 2024 19:34
@lithomas1 lithomas1 requested a review from a team as a code owner June 3, 2024 19:34
@lithomas1 lithomas1 requested review from vyasr and bdice June 3, 2024 19:34
self.c_obj = move(source_info(c_files))
return

# TODO: host_buffer is deprecated API, use host_span instead
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The deprecated API usage was originally in make_source_info, which this code is based off of.

I tried to have a go at switching over to host_span, but my C++ isn't good enough for that yet 😭 .

IMO, it should be fine to keep it as is for now, and tackle the deprecated API usage in a followup (I'll open a followup issue).

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably (sketch):

Add the follow declaration to utilities/host_span.pxd:

host_span(T*, size_type)

and then

from ...libcudf.utilities.host_span cimport host_span

cdef vector[host_span[char]] c_host_buffers

# fill host buffers
...
c_host_buffers.push_back(host_span[char](<char *>&c_buffer[0], c_buffer.shape[0]))

cdef host_span[host_span[char]] c_spans = host_span[host_span[char]](c_host_buffers)
...

plc.io.SourceInfo([source])

# TODO: test contents of source_info buffer is correct
# once buffers are exposed on python side
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accessing the buffers of the SourceInfo is a bit annoying right now, due to the host_buffer deprecation, and because the host_span bindings are incomplete.

This is probably better done after the host_buffer -> host_span deprecation adjustment.

Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

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

Some small tidyings, looks good!

python/cudf/cudf/_lib/pylibcudf/io/avro.pyx Outdated Show resolved Hide resolved
python/cudf/cudf/_lib/pylibcudf/io/avro.pyx Outdated Show resolved Hide resolved
python/cudf/cudf/_lib/pylibcudf/io/avro.pyx Outdated Show resolved Hide resolved

cdef avro_reader_options avro_opts = move(
avro_reader_options.builder(source_info.c_obj)
.columns(c_columns)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

I would perhaps rather rely on the default-constructed avro_reader_options object, and not repeat default values in this interface.

We could take optional skip_rows and num_rows and do:

cdef avro_reader_options opts = move(avro_reader_options.builder(source_info.c_obj))
if skip_rows is not None:
    opts = move(opts.skip_rows(skip_rows))

etc...

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the old Avro (and I/O) Cython files do it my way (passing all arguments) in general.

Unless there's a C++ trap I'm missing, I think I'd prefer to keep it more compact like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't mind doing it "all at once", it's just that (the old code did this too), with this mechanism we encode the "default" values in two places: once canonically in libcudf C++ "skip_rows = -1 means all of them", and once non-canonically here.

python/cudf/cudf/_lib/pylibcudf/io/types.pyx Outdated Show resolved Hide resolved
python/cudf/cudf/_lib/utils.pyx Outdated Show resolved Hide resolved
python/cudf/cudf/pylibcudf_tests/test_avro.py Show resolved Hide resolved
python/cudf/cudf/pylibcudf_tests/test_avro.py Outdated Show resolved Hide resolved
python/cudf/cudf/pylibcudf_tests/test_avro.py Outdated Show resolved Hide resolved
python/cudf/cudf/pylibcudf_tests/test_avro.py Outdated Show resolved Hide resolved
Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

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

Thanks @lithomas1

@wence-
Copy link
Contributor

wence- commented Jun 6, 2024

/merge

@rapids-bot rapids-bot bot merged commit 3b734ec into rapidsai:branch-24.08 Jun 6, 2024
71 checks passed
@lithomas1 lithomas1 deleted the pylibcudf-io branch June 6, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CMake CMake build issue feature request New feature or request non-breaking Non-breaking change pylibcudf Issues specific to the pylibcudf package Python Affects Python cuDF API.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants