Add a protocol buffer decode kernel#4107
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a GPU-accelerated protocol buffer decoder with intentionally limited features, focusing on simple scalar field types. The implementation provides a JNI interface for decoding binary protobuf messages into cuDF STRUCT columns.
Key changes:
- Implements GPU kernels for decoding protobuf varint, fixed32/64, and length-delimited (string) fields
- Adds JNI bindings between Java and CUDA implementation
- Provides basic test coverage for INT64 and STRING field types
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/nvidia/spark/rapids/jni/ProtobufSimple.java | Java API providing decodeToStruct() method with parameter validation |
| src/test/java/com/nvidia/spark/rapids/jni/ProtobufSimpleTest.java | Basic test case covering varint (INT64) and string decoding with missing fields and null messages |
| src/main/cpp/src/protobuf_simple.hpp | C++ API declaration with documentation of supported types |
| src/main/cpp/src/protobuf_simple.cu | CUDA implementation with three specialized kernels for varint, fixed-width, and string extraction |
| src/main/cpp/src/ProtobufSimpleJni.cpp | JNI bridge translating Java arrays to C++ vectors and invoking decode logic |
| src/main/cpp/CMakeLists.txt | Build configuration adding new source files to compilation targets |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/test/java/com/nvidia/spark/rapids/jni/ProtobufSimpleTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/nvidia/spark/rapids/jni/ProtobufSimpleTest.java
Outdated
Show resolved
Hide resolved
|
@greptile full review |
Greptile SummaryThis PR adds a multi-pass GPU protobuf decode kernel to spark-rapids-jni, translating a column of raw protobuf bytes (LIST) into a cuDF STRUCT column following a flattened schema descriptor. The implementation spans a Java API layer ( The PR has addressed a large number of issues raised in prior review rounds (JNI local-ref leaks,
Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Java as Protobuf.java
participant JNI as ProtobufJni.cpp
participant Host as protobuf.cu (host)
participant Kern as GPU Kernels
participant Build as protobuf_builders.cu
Java->>JNI: decodeToStruct(binaryInput, schema...)
JNI->>JNI: Validate arrays & topology
JNI->>Host: decode_protobuf_to_struct()
Host->>Kern: scan_all_fields_kernel (Pass 1: locate scalar fields)
Host->>Kern: count_repeated_fields_kernel (Pass 1: count repeated)
Host->>Kern: scan_all_fields_kernel (Pass 1: locate nested messages)
Host->>Kern: thrust::inclusive_scan (Pass 2: prefix sums for offsets)
Host->>Kern: scan_all_repeated_occurrences_kernel (Pass 2: record occurrences)
Host->>Build: build scalar columns (batched extract kernels)
Host->>Build: build_repeated_scalar/string/struct_column (repeated fields)
Host->>Build: build_nested_struct_column (nested message fields)
Build->>Kern: extract_varint/fixed_batched_kernel
Build->>Kern: validate_enum_values_kernel
Build->>Kern: scan_repeated_message_children_kernel
Host->>Kern: valid_if (build struct null mask from d_row_has_invalid_enum)
Host->>Java: ColumnVector handle (STRUCT column)
|
There was a problem hiding this comment.
Additional Comments (6)
-
src/main/cpp/src/protobuf_simple.cu, line 89-91 (link)logic: potential overflow:
len64can be up to 2^64-1, but casting tointon line 90 can overflow iflen64 > INT_MAX -
src/main/cpp/src/protobuf_simple.cu, line 323-324 (link)logic: potential overflow:
len64can be larger thanINT_MAX, but casting tointon line 324 will overflow -
src/main/cpp/src/protobuf_simple.cu, line 375-376 (link)logic: race condition: multiple threads write to
*error_flagwithout atomics, causing undefined behavior when multiple threads encounter errors simultaneouslyThen in kernels, use
atomicOr(error_flag, 1)instead of*error_flag = 1 -
src/main/cpp/src/protobuf_simple.cu, line 398-407 (link)logic: protobuf uses zigzag encoding for signed integers (sint32/sint64), but varint decoding here treats them as unsigned - decoding negative values will produce incorrect results. Are you only supporting unsigned int32/int64, or should zigzag decoding be implemented for signed types?
-
src/main/cpp/src/protobuf_simple.cu, line 240 (link)syntax: type punning through
reinterpret_castof incompatible pointer types is undefined behavior in C++ -
src/main/cpp/src/protobuf_simple.cu, line 248 (link)syntax: type punning through
reinterpret_castof incompatible pointer types is undefined behavior in C++
6 files reviewed, 6 comments
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile full review |
There was a problem hiding this comment.
Additional Comments (2)
-
src/main/cpp/src/protobuf_simple.cu, line 186 (link)logic: zigzag decode uses signed right shift which is correct for signed types, but applied to unsigned
v -
src/main/cpp/src/ProtobufSimpleJni.cpp, line 55 (link)logic:
encodingsis constructed fromn_type_scalesbut thenout_typesis also constructed usingn_type_scales[i]as the scale parameter, which would be wrong for non-decimal types where this represents encoding
6 files reviewed, 2 comments
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 13 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/test/java/com/nvidia/spark/rapids/jni/ProtobufSimpleTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/test/java/com/nvidia/spark/rapids/jni/ProtobufSimpleTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/nvidia/spark/rapids/jni/ProtobufSimpleTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
…ven/spark-rapids-jni into protocol_buffer_jni_dev
|
@greptileai full review |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
NOTE: release/26.02 has been created from main. Please retarget your PR to release/26.02 if it should be included in the release. |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile please check again |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile list all remain issues |
|
All review comments appear to be resolved! Looking at the PR:
Since all the review feedback has been resolved, the main remaining task is likely to:
If you'd like me to check for any specific unresolved issues or review any particular aspect of the code, let me know! |
|
@greptile full review again |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile full review again |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile please check again |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile please check again |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile please check again |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile please check again |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile review |
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
|
@greptile full review again and give comments rather than just update summary. please. |
WIP
It's not ready for (human) review yet (but soon!). Marked as open just because to trigger greptile once I push new commit.
But human review is greatly appreciated also