Skip to content

Add CUDA error checks after every kernel launch - #22755

Merged
rapids-bot[bot] merged 10 commits into
mainfrom
PointKernel-patch-1
Jun 11, 2026
Merged

Add CUDA error checks after every kernel launch#22755
rapids-bot[bot] merged 10 commits into
mainfrom
PointKernel-patch-1

Conversation

@PointKernel

@PointKernel PointKernel commented Jun 2, 2026

Copy link
Copy Markdown
Member

Description

This PR updates the cuDF codebase to follow CUDA best practices by consistently checking for errors after kernel launches. It also fixes a place where raw __global__ was used instead of the dedicated CUDF_KERNEL macro.

Checklist

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

…rement

Based on offline discussions, this PR updates the C++ review guideline to remove the kernel error checking requirement after each kernel launch.
@PointKernel
PointKernel requested a review from a team as a code owner June 2, 2026 19:37
@PointKernel
PointKernel requested review from mhaseeb123 and vyasr June 2, 2026 19:37
@PointKernel PointKernel added doc Documentation non-breaking Non-breaking change ai-agents AI agents instructions related issue labels Jun 2, 2026
@github-actions github-actions Bot added the libcudf Affects libcudf (C++/CUDA) code. label Jun 2, 2026
@PointKernel

PointKernel commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

related Slack discussions: https://nvidia.slack.com/archives/C01CW5L51QC/p1780351009811349

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6c2fa3d0-9df0-41dc-9c40-a2097c5804fd

📥 Commits

Reviewing files that changed from the base of the PR and between 2395bca and 7bc112e.

📒 Files selected for processing (2)
  • cpp/src/join/mark_join.cu
  • cpp/src/strings/like.cu
💤 Files with no reviewable changes (1)
  • cpp/src/strings/like.cu
🚧 Files skipped from review as they are similar to previous changes (1)
  • cpp/src/join/mark_join.cu

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved GPU reliability and diagnostics: added immediate CUDA error checks after numerous GPU kernel launches across many components so launch/runtime failures are detected and reported earlier, reducing silent failures and making error sources easier to diagnose.

Walkthrough

This PR inserts immediate post-kernel CUDA error checks (CUDF_CUDA_TRY(cudaGetLastError())) after many GPU kernel launches across bitmask, copying, I/O (CSV/Parquet/ORC/Avro), join, string, text, transform, and utility modules. No public APIs or kernel logic were modified.

Changes

Systematic CUDA Kernel Launch Error Checking

Layer / File(s) Summary
Post-launch checks across modules
cpp/src/* (many files across bitmask, copying, groupby, io, join, strings, text, transform, etc.)
Inserted CUDF_CUDA_TRY(cudaGetLastError()) immediately after numerous CUDA kernel launches across modules; a few SPDX header year updates and two small early-return guards were also added. No public API signatures were changed.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels:
3 - Ready for Review

Suggested reviewers:

  • vuule
  • vyasr
  • bdice
  • shrshi
  • KyleFromNVIDIA
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.70% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding CUDA error checks after every kernel launch across the codebase.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of the changes (following CUDA best practices, adding error checks after kernel launches, fixing a macro usage).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch PointKernel-patch-1

Comment @coderabbitai help to get the list of available commands and usage tips.

@PointKernel
PointKernel marked this pull request as draft June 2, 2026 20:46
@copy-pr-bot

copy-pr-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@PointKernel

Copy link
Copy Markdown
Member Author

/ok to test 4da31c2

@PointKernel PointKernel changed the title Update the review guideline to remove the kernel error checking Add CUDA error checks after every kernel launch Jun 2, 2026
@PointKernel
PointKernel marked this pull request as ready for review June 3, 2026 16:12
@PointKernel
PointKernel requested review from bdice and vuule June 3, 2026 16:12
@PointKernel

Copy link
Copy Markdown
Member Author

@vuule @bdice re-requested your review, as the PR scope has changed to update the implementation and align it with the review guidelines.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
cpp/src/io/text/multibyte_split.cu (1)

405-412: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Missing CUDA error check after kernel launch.

The multibyte_split_init_kernel launch at lines 405–412 is missing the post-launch error check. For consistency with the PR objective and to match the error checks added after the other kernel launches in this file, add CUDF_CUDA_TRY(cudaGetLastError()); immediately after line 412.

🔧 Proposed fix
       tile_multistates,
       tile_offsets);
+    CUDF_CUDA_TRY(cudaGetLastError());

     CUDF_CUDA_TRY(cudaStreamWaitEvent(scan_stream.value(), last_launch_event));

As per coding guidelines: Check for unchecked CUDA errors in kernel launches, memory operations, and synchronization calls.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/src/io/text/multibyte_split.cu` around lines 405 - 412, The kernel launch
of multibyte_split_init_kernel using tiles_in_launch, THREADS_PER_TILE and
scan_stream is missing a post-launch CUDA error check; add a
CUDF_CUDA_TRY(cudaGetLastError()); immediately after the
multibyte_split_init_kernel<<<...>>>(...) call (the same pattern used after
other kernel launches in this file) to catch launch errors and follow the
project's error-checking convention.
cpp/src/text/wordpiece_tokenize.cu (1)

827-831: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard the limited-tokenization launch when no words were found.

total_words can be 0 for valid inputs such as non-null empty strings. In that case this constructs a zero-block launch, and the new CUDF_CUDA_TRY(cudaGetLastError()) will now fail with cudaErrorInvalidConfiguration.

💡 Suggested fix
-  cudf::detail::grid_1d grid{total_words, 512};
-  tokenize_kernel<decltype(map_ref), decltype(sub_map_ref)>
-    <<<grid.num_blocks, grid.num_threads_per_block, 0, stream.value()>>>(
-      start_words, word_sizes, d_input_chars, map_ref, sub_map_ref, unk_id, d_tokens.data());
-  CUDF_CUDA_TRY(cudaGetLastError());
+  if (total_words > 0) {
+    cudf::detail::grid_1d grid{total_words, 512};
+    tokenize_kernel<decltype(map_ref), decltype(sub_map_ref)>
+      <<<grid.num_blocks, grid.num_threads_per_block, 0, stream.value()>>>(
+        start_words, word_sizes, d_input_chars, map_ref, sub_map_ref, unk_id, d_tokens.data());
+    CUDF_CUDA_TRY(cudaGetLastError());
+  }

Based on learnings: Verify kernel launches have valid grid/block dimensions (non-zero blocks/threads).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/src/text/wordpiece_tokenize.cu` around lines 827 - 831, total_words can
be zero which creates a zero-block kernel launch causing
cudaErrorInvalidConfiguration when CUDF_CUDA_TRY(cudaGetLastError()) is called;
guard the tokenize_kernel launch by checking total_words > 0 (or grid.num_blocks
> 0) before invoking tokenize_kernel<<<...>>>(start_words, word_sizes,
d_input_chars, map_ref, sub_map_ref, unk_id, d_tokens.data()) and only call
CUDF_CUDA_TRY(cudaGetLastError()) when the kernel was actually launched so no
zero-block launch occurs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cpp/src/io/comp/unsnap.cu`:
- Around line 719-721: The post-launch cudaGetLastError() checks can throw when
kernels were launched with zero blocks for valid empty inputs; update the launch
sites (e.g., unsnap_kernel_no_racecheck<<<dim_grid, dim_block,...>>>(...) and
the other kernel at lines ~758-760) to first guard the launch and the subsequent
cudaGetLastError() by checking that the grid and block dimensions are non-zero
(or that inputs.size() > 0) and only launch + call cudaGetLastError() when those
conditions hold; mirror the pattern used by gpuinflate/gpu_snap to skip launches
for empty inputs.

In `@cpp/src/io/parquet/decode_preprocess.cu`:
- Around line 485-492: The kernel launch in compute_page_sizes() can be invoked
with dim_grid.x == 0 when pages.size() == 0, causing an invalid configuration
error due to the new cudaGetLastError() check; add an early no-op guard in
compute_page_sizes() (the caller is preprocess_levels()) to return immediately
when there are no pages/chunks to process (e.g., pages.size()==0 or chunks==0 or
page_mask indicates empty) before computing dim_grid/dim_block and before
launching compute_page_sizes_kernel<uint8_t> /
compute_page_sizes_kernel<uint16_t>, so no kernel is launched with zero grid
dimensions.

---

Outside diff comments:
In `@cpp/src/io/text/multibyte_split.cu`:
- Around line 405-412: The kernel launch of multibyte_split_init_kernel using
tiles_in_launch, THREADS_PER_TILE and scan_stream is missing a post-launch CUDA
error check; add a CUDF_CUDA_TRY(cudaGetLastError()); immediately after the
multibyte_split_init_kernel<<<...>>>(...) call (the same pattern used after
other kernel launches in this file) to catch launch errors and follow the
project's error-checking convention.

In `@cpp/src/text/wordpiece_tokenize.cu`:
- Around line 827-831: total_words can be zero which creates a zero-block kernel
launch causing cudaErrorInvalidConfiguration when
CUDF_CUDA_TRY(cudaGetLastError()) is called; guard the tokenize_kernel launch by
checking total_words > 0 (or grid.num_blocks > 0) before invoking
tokenize_kernel<<<...>>>(start_words, word_sizes, d_input_chars, map_ref,
sub_map_ref, unk_id, d_tokens.data()) and only call
CUDF_CUDA_TRY(cudaGetLastError()) when the kernel was actually launched so no
zero-block launch occurs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: a1955893-e695-4bb4-8e95-3f821e6455ec

📥 Commits

Reviewing files that changed from the base of the PR and between f87a833 and 4da31c2.

📒 Files selected for processing (75)
  • cpp/src/bitmask/null_mask.cu
  • cpp/src/copying/concatenate.cu
  • cpp/src/copying/contiguous_split.cu
  • cpp/src/copying/scatter.cu
  • cpp/src/groupby/hash/compute_mapping_indices.cuh
  • cpp/src/groupby/hash/compute_shared_memory_aggs.cu
  • cpp/src/io/avro/avro_gpu.cu
  • cpp/src/io/comp/debrotli.cu
  • cpp/src/io/comp/gpuinflate.cu
  • cpp/src/io/comp/snap.cu
  • cpp/src/io/comp/unsnap.cu
  • cpp/src/io/csv/csv_gpu.cu
  • cpp/src/io/fst/dispatch_dfa.cuh
  • cpp/src/io/orc/dict_enc.cu
  • cpp/src/io/orc/stats_enc.cu
  • cpp/src/io/orc/stripe_data.cu
  • cpp/src/io/orc/stripe_enc.cu
  • cpp/src/io/orc/stripe_init.cu
  • cpp/src/io/orc/writer_impl.cu
  • cpp/src/io/parquet/chunk_dict.cu
  • cpp/src/io/parquet/decode_fixed.cu
  • cpp/src/io/parquet/decode_preprocess.cu
  • cpp/src/io/parquet/experimental/dictionary_page_filter.cu
  • cpp/src/io/parquet/page_data.cu
  • cpp/src/io/parquet/page_delta_decode.cu
  • cpp/src/io/parquet/page_enc.cu
  • cpp/src/io/parquet/page_hdr.cu
  • cpp/src/io/parquet/page_string_decode.cu
  • cpp/src/io/statistics/column_statistics.cuh
  • cpp/src/io/text/multibyte_split.cu
  • cpp/src/io/utilities/data_casting.cu
  • cpp/src/io/utilities/type_inference.cu
  • cpp/src/join/conditional_join.cu
  • cpp/src/join/filter_join_indices_kernel.cuh
  • cpp/src/join/filtered_join.cu
  • cpp/src/join/hash_join/partitioned_count_kernels.cuh
  • cpp/src/join/hash_join/partitioned_retrieve_kernels.cuh
  • cpp/src/join/key_remapping.cu
  • cpp/src/join/mark_join.cu
  • cpp/src/join/mixed_join_kernel.cuh
  • cpp/src/join/mixed_join_kernels_semi.cu
  • cpp/src/join/mixed_join_size_kernel.cuh
  • cpp/src/json/json_path.cu
  • cpp/src/merge/merge.cu
  • cpp/src/partitioning/partitioning.cu
  • cpp/src/quantiles/tdigest/tdigest.cu
  • cpp/src/quantiles/tdigest/tdigest_aggregation.cu
  • cpp/src/replace/nulls.cu
  • cpp/src/replace/replace.cu
  • cpp/src/rolling/detail/rolling.cuh
  • cpp/src/sort/segmented_top_k.cu
  • cpp/src/strings/attributes.cu
  • cpp/src/strings/case.cu
  • cpp/src/strings/convert/convert_urls.cu
  • cpp/src/strings/copying/concatenate.cu
  • cpp/src/strings/like.cu
  • cpp/src/strings/regex/utilities.cuh
  • cpp/src/strings/replace/multi.cu
  • cpp/src/strings/replace/replace.cu
  • cpp/src/strings/search/contains_multiple.cu
  • cpp/src/strings/search/find.cu
  • cpp/src/strings/search/find_instance.cu
  • cpp/src/strings/slice.cu
  • cpp/src/strings/split/split.cuh
  • cpp/src/strings/strings_column_factories.cu
  • cpp/src/text/bpe/byte_pair_encoding.cu
  • cpp/src/text/edit_distance.cu
  • cpp/src/text/generate_ngrams.cu
  • cpp/src/text/jaccard.cu
  • cpp/src/text/minhash.cu
  • cpp/src/text/normalize.cu
  • cpp/src/text/vocabulary_tokenize.cu
  • cpp/src/text/wordpiece_tokenize.cu
  • cpp/src/transform/compute_column_kernel.cuh
  • cpp/src/transform/row_bit_count.cu
✅ Files skipped from review due to trivial changes (6)
  • cpp/src/io/statistics/column_statistics.cuh
  • cpp/src/bitmask/null_mask.cu
  • cpp/src/strings/split/split.cuh
  • cpp/src/join/mark_join.cu
  • cpp/src/io/parquet/decode_fixed.cu
  • cpp/src/io/parquet/page_enc.cu

Comment thread cpp/src/io/comp/unsnap.cu
Comment thread cpp/src/io/parquet/decode_preprocess.cu
Comment thread cpp/src/io/comp/unsnap.cu
Comment thread cpp/src/io/parquet/decode_preprocess.cu
@PointKernel PointKernel added improvement Improvement / enhancement to an existing function and removed doc Documentation ai-agents AI agents instructions related issue labels Jun 4, 2026
@PointKernel

Copy link
Copy Markdown
Member Author

/merge

@rapids-bot
rapids-bot Bot merged commit 605d813 into main Jun 11, 2026
134 checks passed
@PointKernel
PointKernel deleted the PointKernel-patch-1 branch June 11, 2026 16:08
abigalekim pushed a commit to abigalekim/cudf that referenced this pull request Jun 12, 2026
This PR updates the cuDF codebase to follow CUDA best practices by consistently checking for errors after kernel launches. It also fixes a place where raw `__global__` was used instead of the dedicated `CUDF_KERNEL` macro.

Authors:
  - Yunsong Wang (https://github.com/PointKernel)

Approvers:
  - Vukasin Milovanovic (https://github.com/vuule)
  - Bradley Dice (https://github.com/bdice)
  - Muhammad Haseeb (https://github.com/mhaseeb123)

URL: NVIDIA#22755
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvement / enhancement to an existing function libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants