Skip to content

Conversation

@Andy-Jost
Copy link
Contributor

Summary

Four tests in test_utils.py relied on CuPy implicitly creating a CUDA context but failed intermittently when pytest-randomly ordered them after tests using the init_cuda fixture, which pops the context on cleanup.

The affected tests are:

  • test_view_sliced_external
  • test_view_sliced_external_negative_offset
  • test_view_zero_size_array
  • test_struct_array

Root Cause

The init_cuda fixture calls Device().set_current() before a test and pops the context via cuCtxPopCurrent() after the test completes. When a CuPy-based test runs next without its own context setup, CUDA API calls (like cuCtxGetDevice() for zero-sized arrays) fail with CUDA_ERROR_INVALID_CONTEXT.

Fix

Add the init_cuda fixture to all four affected tests to ensure a CUDA context is always current.

Test Plan

  • Verified failure on main with seed 3529696628
  • Verified fix passes with multiple random seeds
  • All 128 tests in test_utils.py pass consistently

Four tests in test_utils.py relied on CuPy implicitly creating a CUDA
context but failed when pytest-randomly ordered them after tests using
the init_cuda fixture, which pops the context on cleanup.
@Andy-Jost Andy-Jost added bug Something isn't working cuda.core Everything related to the cuda.core module labels Jan 22, 2026
@Andy-Jost Andy-Jost self-assigned this Jan 22, 2026
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Jan 22, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@Andy-Jost
Copy link
Contributor Author

/ok to test ac53170

@Andy-Jost Andy-Jost requested a review from cpcloud January 22, 2026 16:27
@github-actions

This comment has been minimized.

Copy link
Contributor

@mdboom mdboom left a comment

Choose a reason for hiding this comment

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

LGTM. pytest-randomly does its job!

@Andy-Jost Andy-Jost merged commit 27e9066 into NVIDIA:main Jan 22, 2026
164 of 165 checks passed
@github-actions
Copy link

Doc Preview CI
Preview removed because the pull request was closed or merged.

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

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants