Skip to content

Require cudaMemcpyDefault policy - #23605

Open
bdice wants to merge 3 commits into
NVIDIA:mainfrom
bdice:replace-cudamemcpy-policies
Open

Require cudaMemcpyDefault policy#23605
bdice wants to merge 3 commits into
NVIDIA:mainfrom
bdice:replace-cudamemcpy-policies

Conversation

@bdice

@bdice bdice commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Description

This PR requires the use of cudaMemcpyDefault instead of explicit host/device policies. This ensures that copies do not fail: we only care about memory accessibility, not memory residency. We must support cases where the source is device-accessible but resident on the host, such as host pinned memory.

Checklist

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

@bdice
bdice requested review from a team as code owners August 10, 2026 14:16
@github-actions github-actions Bot added libcudf Affects libcudf (C++/CUDA) code. Python Affects Python cuDF API. Java Affects Java cuDF API. pylibcudf Issues specific to the pylibcudf package labels Aug 10, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python Aug 10, 2026
@bdice bdice added bug Something isn't working non-breaking Non-breaking change labels Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 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: 138c61bc-4e90-451a-aaaf-ea8d43fbd945

📥 Commits

Reviewing files that changed from the base of the PR and between 0ab2f73 and 4c989bc.

📒 Files selected for processing (2)
  • cpp/doxygen/developer_guide/DEVELOPER_GUIDE.md
  • cpp/tests/io/io_test_utils.hpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • cpp/tests/io/io_test_utils.hpp

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved CUDA memory-copy handling across data transfers, including asynchronous reads and writes.
    • Standardized copy-direction detection to reduce transfer configuration errors across C++, CUDA, Cython, Java, Python, and tests.
  • Documentation

    • Added guidance for consistent CUDA memory-copy usage.
  • Chores

    • Added automated checks to help prevent incorrect CUDA memory-copy configurations.
    • Updated applicable copyright notices through 2026.

Walkthrough

The change replaces explicit CUDA memcpy direction kinds with cudaMemcpyDefault across runtime code, Java and Python bindings, tests, and evaluation code. A pre-commit hook and developer guide enforce the updated usage.

Changes

CUDA memcpy direction normalization

Layer / File(s) Summary
Memcpy direction enforcement
.pre-commit-config.yaml, cpp/doxygen/developer_guide/DEVELOPER_GUIDE.md
Adds a pre-commit hook and documentation for detecting and avoiding explicit CUDA memcpy direction kinds.
Runtime memcpy updates
cpp/include/cudf_test/tdigest_utilities.hpp, cpp/src/io/utilities/data_sink.cpp, cpp/src/strings/utilities.cu, java/src/main/native/src/*, python/pylibcudf/pylibcudf/contiguous_split.pyx
Uses cudaMemcpyDefault for tdigest validation, IO transfers, string table initialization, Java native buffer operations, and staged Python transfers. Updates affected copyright notices.
Validation and test updates
cpp/tests/io/cudftable_test.cpp, cpp/tests/io/io_test_utils.hpp, cpp/tests/io/json/json_quote_normalization_test.cpp, skills/accelerated-computing-cudf/evals/files/cudf-native-stream-handoff-boundary/code/threaded_handoff.cu
Updates CUDA copies in tests and evaluation code. Adds CUDA error handling and stream-view synchronization in IO test utilities. Updates affected copyright notices.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: jameslamb, brandon-b-miller, qbacpey

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 summarizes the main change: enforcing cudaMemcpyDefault usage.
Description check ✅ Passed The description explains the cudaMemcpyDefault policy, its purpose, and related test and documentation updates.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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: 1

🤖 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/tests/io/io_test_utils.hpp`:
- Around line 62-64: Update device_read to replace the raw cudaMemcpyAsync call
with cudf::detail::memcpy_async and wrap the result in CUDF_CUDA_TRY; also wrap
cudaStreamSynchronize(stream.value()) with CUDF_CUDA_TRY so both CUDA operations
propagate errors.
🪄 Autofix

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: afd14363-619d-4ca3-9d6d-1262d1bcc40b

📥 Commits

Reviewing files that changed from the base of the PR and between 6a22d1d and 0ab2f73.

📒 Files selected for processing (11)
  • .pre-commit-config.yaml
  • cpp/include/cudf_test/tdigest_utilities.hpp
  • cpp/src/io/utilities/data_sink.cpp
  • cpp/src/strings/utilities.cu
  • cpp/tests/io/cudftable_test.cpp
  • cpp/tests/io/io_test_utils.hpp
  • cpp/tests/io/json/json_quote_normalization_test.cpp
  • java/src/main/native/src/jni_writer_data_sink.hpp
  • java/src/main/native/src/multi_host_buffer_source.cpp
  • python/pylibcudf/pylibcudf/contiguous_split.pyx
  • skills/accelerated-computing-cudf/evals/files/cudf-native-stream-handoff-boundary/code/threaded_handoff.cu

Comment thread cpp/tests/io/io_test_utils.hpp Outdated
Comment on lines 62 to 64
cudaMemcpyAsync(
out_data.data(), data_.data() + offset, size, cudaMemcpyHostToDevice, stream.value());
out_data.data(), data_.data() + offset, size, cudaMemcpyDefault, stream.value());
cudaStreamSynchronize(stream.value());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- target file context ---'
sed -n '1,110p' cpp/tests/io/io_test_utils.hpp

printf '%s\n' '--- CUDA error macros and related usage ---'
rg -n --glob '*.{h,hpp,cpp,cu,cuh}' 'CUDF_CUDA_TRY_NO_THROW|CUDF_CUDA_TRY|cudaMemcpyAsync|cudaStreamSynchronize' cpp | head -200

Repository: rapidsai/cudf

Length of output: 21884


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- CUDA error macro definition ---'
sed -n '260,315p' cpp/include/cudf/utilities/error.hpp

printf '%s\n' '--- memcpy helper declaration and implementation ---'
sed -n '1,90p' cpp/include/cudf/detail/utilities/cuda_memcpy.hpp
sed -n '1,75p' cpp/src/utilities/cuda_memcpy.cu

printf '%s\n' '--- includes used by comparable test helpers ---'
sed -n '35,70p' cpp/tests/copying/concatenate_tests.cpp
sed -n '75,105p' cpp/tests/io/comp/comp_test.cpp
sed -n '95,125p' cpp/benchmarks/io/cuio_common.cpp

printf '%s\n' '--- direct includes in target or nearby test utilities ---'
rg -n '^`#include` .*error.hpp|^`#include` .*cuda_memcpy.hpp|^`#include` .*cuda_runtime' cpp/tests/io cpp/tests/copying/concatenate_tests.cpp

Repository: rapidsai/cudf

Length of output: 13712


🏁 Script executed:

#!/bin/bash
set -eu

python3 - <<'PY'
from pathlib import Path
import re

target = Path("cpp/tests/io/io_test_utils.hpp").read_text()
error_h = Path("cpp/include/cudf/utilities/error.hpp").read_text()
memcpy_h = Path("cpp/include/cudf/detail/utilities/cuda_memcpy.hpp").read_text()

device_read = re.search(
    r'std::unique_ptr<cudf::io::datasource::buffer> device_read\(.*?\n  \}',
    target,
    re.S,
)
assert device_read, "device_read definition not found"
body = device_read.group(0)

calls = {
    "cudaMemcpyAsync": len(re.findall(r'\bcudaMemcpyAsync\s*\(', body)),
    "cudaStreamSynchronize": len(re.findall(r'\bcudaStreamSynchronize\s*\(', body)),
}
wrapped = {
    name: bool(re.search(rf'CUDF_CUDA_TRY\s*\(\s*{name}\s*\(', body))
    for name in calls
}

macro = re.search(
    r'`#define` CUDF_CUDA_TRY\(call\).*?cudaSuccess != status',
    error_h,
    re.S,
)
helper = re.search(
    r'\[\[nodiscard\]\]\s+cudaError_t\s+memcpy_async\(.*?\);',
    memcpy_h,
    re.S,
)

print("device_read calls:", calls)
print("device_read calls wrapped:", wrapped)
print("CUDF_CUDA_TRY checks cudaSuccess:", bool(macro))
print("detail::memcpy_async returns cudaError_t:", bool(helper))
PY

Repository: rapidsai/cudf

Length of output: 393


Handle CUDA errors in device_read.

Use cudf::detail::memcpy_async for the copy and wrap its result with CUDF_CUDA_TRY. Wrap cudaStreamSynchronize with CUDF_CUDA_TRY as well.

🤖 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/tests/io/io_test_utils.hpp` around lines 62 - 64, Update device_read to
replace the raw cudaMemcpyAsync call with cudf::detail::memcpy_async and wrap
the result in CUDF_CUDA_TRY; also wrap cudaStreamSynchronize(stream.value())
with CUDF_CUDA_TRY so both CUDA operations propagate errors.

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Java Affects Java cuDF API. libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change pylibcudf Issues specific to the pylibcudf package Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants