Skip to content

coverage: expand tests coverage for API validation and resource lifecycles - #3222

Open
rluo8 wants to merge 5 commits into
NVIDIA:mainfrom
rluo8:test/core-coverage-20261026
Open

rluo8 wants to merge 5 commits into
NVIDIA:mainfrom
rluo8:test/core-coverage-20261026

Conversation

@rluo8

@rluo8 rluo8 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add test functions covering cuda.core API validation, resource lifetimes, and recovery after rejected operations. This PR contains test changes only.

Changes

  • Devices, memory, and streams: cover invalid device ordinals, thread-local context initialization, memory-resource assignment, buffer subclasses as kernel arguments, and borrowed-stream ownership.
  • Graphs: cover cyclic graphs, unsupported host callbacks for device launch, mixed-context nodes, and unused conditional handles. Verify that repaired graphs can be instantiated and executed after a rejected operation.
  • Compilation and modules: cover invalid object-code payloads, cleanup after externally removing a debug source file, and compilation with automatic PCH enabled while checking creation status and kernel results.
  • Tensor maps and textures: cover pointer alignment, hardware/context restrictions, dtype encoding with padded-row strides and exporter lifetimes, 1D/3D mipmap round trips, surface/texture lifecycles, and border-color sampling on the GPU.

Validation

  • Ran the tests on Linux/H800 and Windows/A100 using CUDA 13.4 wheels. All applicable PR test cases passed; unsupported hardware and platform combinations were skipped.
  • Revalidated the two tensor-map API tests on Linux/H800 and B10 (RTX PRO 4500 Blackwell): 15 parameterized cases passed on each. They skip on Windows/A100, which lacks TMA.
  • Validated the PCH test locally on Windows/Ada with NVRTC 12.9.86 and 13.4 runtimes, reusing CUDA 13.4 cuda-python wheels; normal and changed-diagnostic runs passed, with skip and incorrect-output probes behaving as expected.
  • All applicable pre-commit checks passed.

@copy-pr-bot

copy-pr-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Oct 26, 2026
@rluo8
rluo8 marked this pull request as ready for review October 26, 2026 08:50
@rluo8 rluo8 self-assigned this Oct 26, 2026
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Summary

Summary by CodeRabbit

  • Tests
    • Expanded coverage for CUDA graph validation and recovery, device selection, context handling, and external stream interoperability.
    • Added checks for memory-resource assignment, kernel launches with managed and virtual memory, and allocation failures.
    • Added coverage for program cleanup and precompiled-header reuse, module errors, tensor-map alignment and ownership, and texture and surface operations.
    • Added checks for green-context resource validation and DLPack exports of extended-precision data types.

This PR adds CUDA core regression tests for graph validation, device and stream behavior, memory allocation, program and module lifecycle, tensor maps, texture and surface objects, and versioned DLPack export.

Changes: Graph Definition Validation

Layer / File(s) Summary
Graph instantiation checks
cuda_core/tests/graph/test_graph_definition_errors.py
Tests rejection of cyclic graphs, host callbacks in device-launch graphs, nodes from different contexts, and unassociated graph conditions. Cycle and mixed-context tests also verify that repaired graphs can launch.

Context and Stream Handling

Layer / File(s) Summary
Device initialization and memory resources
cuda_core/tests/test_device.py
Tests invalid device ordinals, per-thread initialization, and memory-resource assignment and use.
Green-context resource validation
cuda_core/tests/test_green_context.py
Tests rejection of empty or unsupported resources and checks that failures preserve the current context.
Borrowed driver-stream behavior
cuda_core/tests/test_stream.py
Tests a borrowed driver stream’s context and device lookup, asynchronous memory operations, and raw-stream validity after wrapper closure.

Memory and Code Lifecycles

Layer / File(s) Summary
Kernel memory arguments and virtual-memory allocation
cuda_core/tests/test_launcher.py, cuda_core/tests/test_memory.py
Tests managed and virtual buffers as kernel arguments, and checks that failed virtual-memory allocations do not prevent use of another resource.
Module and program lifecycle
cuda_core/tests/test_module.py, cuda_core/tests/test_program.py
Tests repeated kernel lookup failures for invalid cubin inputs, cleanup after debug-source removal, and PCH creation and reuse.

Tensor-Map Operations

Layer / File(s) Summary
Tensor-map descriptors and alignment
cuda_core/tests/test_tensor_map.py
Tests padded-row descriptors across data types and rejection of a misaligned device pointer.
Tensor-map ownership and capability checks
cuda_core/tests/test_tensor_map.py
Tests failed address replacement in missing or different contexts and tensor-map creation on unsupported hardware.

Texture and Surface Objects

Layer / File(s) Summary
Texture resources and descriptor flags
cuda_core/tests/test_texture_surface.py
Tests texture descriptor flags, linear and pitched resource metadata, mipmap-level round trips, and surface and texture object states.
Texture sampling and context validation
cuda_core/tests/test_texture_surface.py
Tests device-side border-color sampling and surface creation with foreign and owning contexts.

DLPack Export

Layer / File(s) Summary
Extended-precision DLPack export
cuda_core/tests/test_utils_dlpack.py
Tests versioned DLPack export errors for unsupported extended-precision item sizes and checks exported view metadata.

Possibly related issues

  • NVIDIA/cuda-python#2910: The PR tests rejection of invalid addr_align values and verifies that another resource remains usable. It does not change the validation logic described by the issue.

Priority: Low

Change: Other

Merge Risk: Low · previous review 21643

Some supported CUDA or NVRTC versions may fail these tests solely because diagnostic wording changes; replace exact message checks with contractual signals before merging.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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: 2

🧹 Nitpick comments: 3
cuda_core/tests/test_device.py: 1

70-70: Trivial · Maintainability & Code Quality · Quick win

suggestion: Assert exception types without matching message text.

These tests depend on error-message substrings. A wording change would fail the tests even if the API behavior remains correct. Remove match= unless the message is part of a documented contract. As per coding guidelines, “Avoid asserting on ... error message substrings that are not part of the contract.” (raw.githubusercontent.com)

Also applies to: 86-86, 88-88, 138-138

Source: Coding guidelines

cuda_core/tests/test_green_context.py: 1

215-215: Trivial · Maintainability & Code Quality · Quick win

suggestion: Remove the error-message matches.

A wording-only change to either exception will fail these tests. Keep the exception-type and context checks, but remove both match= arguments. The public create_context documentation does not specify error-message text. (nvidia.github.io)

As per coding guidelines: “Avoid asserting on ... error message substrings that are not part of the contract.”

Also applies to: 224-224

Source: Coding guidelines

cuda_core/tests/test_tensor_map.py: 1

136-137: Trivial · Maintainability & Code Quality · Quick win

suggestion: Replace pytest.importorskip("ml_dtypes") with a direct import. The test-cu12 and test-cu13 groups include ml-dtypes, so skipping here hides a broken test environment.

Source: Coding guidelines


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between a2fb804 and 74eee8c.

Files selected for processing: 11
  • cuda_core/tests/graph/test_graph_definition_errors.py
  • cuda_core/tests/test_device.py
  • cuda_core/tests/test_green_context.py
  • cuda_core/tests/test_launcher.py
  • cuda_core/tests/test_memory.py
  • cuda_core/tests/test_module.py
  • cuda_core/tests/test_program.py
  • cuda_core/tests/test_stream.py
  • cuda_core/tests/test_tensor_map.py
  • cuda_core/tests/test_texture_surface.py
  • cuda_core/tests/test_utils_dlpack.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Comment thread cuda_core/tests/test_launcher.py Resolved
Comment thread cuda_core/tests/test_program.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

@rluo8

rluo8 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@rluo8
rluo8 force-pushed the test/core-coverage-20261026 branch from 6b82e9e to b4b8cd7 Compare October 29, 2026 08:11
Exercise validation failures, resource ownership, and recovery paths using real CUDA resources. Verify tensor-map dtype encoding and exporter lifetime without requiring runtime kernel compilation.

Signed-off-by: Rui Luo <ruluo@nvidia.com>
@rluo8
rluo8 force-pushed the test/core-coverage-20261026 branch from b4b8cd7 to d47ef9f Compare October 29, 2026 09:01
@rluo8
rluo8 marked this pull request as ready for review October 29, 2026 09:04

@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.

Nitpick comments: 1
cuda_core/tests/test_tensor_map.py: 1

104-105: Trivial · Maintainability & Code Quality · Quick win

suggestion: Do not assert on repr(descriptor) substrings. The test checks ", rank=2," and f"dtype={data_type.name},". The repr format is not part of the TensorMapDescriptor contract. A formatting change in _repr_info or __repr__ breaks the test while the descriptor stays correct. Assert on a public property of the descriptor if one exposes rank and data type. Otherwise keep only the isinstance and device assertions.

As per coding guidelines: "Avoid asserting on internal call counts, private helper invocation order, or error message substrings that are not part of the contract."

Source: Coding guidelines


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between e939d61 and d47ef9f.

Files selected for processing: 3
  • cuda_core/tests/graph/test_graph_definition_errors.py
  • cuda_core/tests/test_stream.py
  • cuda_core/tests/test_tensor_map.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@rluo8
rluo8 requested review from Andy-Jost and mdboom October 29, 2026 12:20

@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

Nitpick comments: 1
cuda_core/tests/test_tensor_map.py: 1

870-875: Trivial · Maintainability & Code Quality · Quick win

suggestion: Drop the match= message substrings from both pytest.raises calls. Assert only the exception type.

Line 875 matches "requires an active CUDA context" and "was created in a different CUDA context". Line 911 matches "Compute capability 9\.0 or higher is required". The contract defines the exception types (RuntimeError, CUDAError) and the ownership state after the call. It does not define the message text. A reword of these messages would break the tests without any behavior change. The ownership assertions on lines 879-880 already show that the rejected call had no effect.

As per coding guidelines: "Avoid asserting on internal call counts, private helper invocation order, or error message substrings that are not part of the contract."

Also applies to: 911-911

Source: Coding guidelines


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d47ef9f and 2a570f2.

Files selected for processing: 4
  • cuda_core/tests/test_device.py
  • cuda_core/tests/test_launcher.py
  • cuda_core/tests/test_program.py
  • cuda_core/tests/test_tensor_map.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Comment thread cuda_core/tests/test_program.py Resolved
Signed-off-by: Rui Luo <ruluo@nvidia.com>

@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


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 2a570f2 and 216430a.

Files selected for processing: 1
  • cuda_core/tests/test_program.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Comment thread cuda_core/tests/test_program.py Resolved

@Andy-Jost Andy-Jost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, this is useful coverage: 26 tests, no library change, each with one marker, no memory pools, and the new tests pass or skip for a stated reason on the H100, V100, L4, T4 x2, RTX 4090 WDDM, and WSL rows. Most of them check real behavior on the device or in the driver (the borrowed stream that outlives close(), kernel-argument marshalling for buffer subclasses, a descriptor keeping its source alive across replace_address, border-color sampling, the foreign-context surface rejection), so they would catch a regression. Approving.

One small point you may want to take: test_nvrtc_automatic_pch_preserves_compiled_kernel skips when NVRTC reports NOT_ATTEMPTED, so if cuda.core ever stopped passing --pch the test would skip rather than fail. An assert "--pch" in flags for ProgramOptions(pch=True) in the as_bytes option test would catch that without a GPU.

The metadata check is red only for the missing milestone.

This branch has not been deployed

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

Labels

cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants