Skip to content

cuda.core: expose last prefetch location on ManagedBuffer - #2774

Open
isVoid wants to merge 5 commits into
NVIDIA:mainfrom
isVoid:fea-2109
Open

cuda.core: expose last prefetch location on ManagedBuffer#2774
isVoid wants to merge 5 commits into
NVIDIA:mainfrom
isVoid:fea-2109

Conversation

@isVoid

@isVoid isVoid commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Description

closes #2109

Expose the read-only ManagedBuffer.last_prefetch_location property.

  • Map the legacy CUDA 12 range attribute to Device, Host, or None.
  • Query the CUDA 13 LAST_PREFETCH_LOCATION_TYPE / _ID pair so NUMA host locations round-trip.
  • Replace test-only private range-attribute probes with the public property.
  • Update API documentation and generated Cython stubs.

Testing

  • cd cuda_core && pixi run -e cu13 pytest tests/memory/test_managed_ops.py -q — 37 passed, 1 skipped
  • cd cuda_core && pixi run -e cu12 pytest tests/memory/test_managed_ops.py -q — 16 passed, 22 skipped
  • Changed-file pre-commit hook suite — passed

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@copy-pr-bot

copy-pr-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Sep 5, 2026
@isVoid
isVoid marked this pull request as ready for review September 8, 2026 17:49
@isVoid

isVoid commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@copy-pr-bot

copy-pr-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

/ok to test

@isVoid, there was an error processing your request: E1

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/

@isVoid

isVoid commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 08b4cf4

@isVoid isVoid self-assigned this Sep 8, 2026
@isVoid isVoid added the feature New feature or request label Sep 8, 2026
@isVoid isVoid added this to the cuda.bindings 13.5.0 & 12.9.10 milestone Sep 8, 2026
from cuda.core._utils.version import binding_version, driver_version

if binding_version() < (13, 0, 0) or driver_version() < (13, 0, 0):
pytest.skip("Host NUMA last-prefetch location requires CUDA 13")

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.

I've been trained to lean towards skipping at collection time. Worth doing here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if there are any order requirement at test collecting time and initializing CUDA. Let me check with my agent to see if possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@brandon-b-miller brandon-b-miller 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.

Overall looks good. Based on what happened when this features sibling attrs were introduced, I infer that we may need a release notes entry documenting this new feature.

if loc_type == <int>cydriver.CUmemLocationType.CU_MEM_LOCATION_TYPE_HOST_NUMA_CURRENT:
return Host.numa_current()
return None # CU_MEM_LOCATION_TYPE_INVALID — no preferred location
return None # CU_MEM_LOCATION_TYPE_INVALID

@brandon-b-miller brandon-b-miller Sep 9, 2026

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.

the docs for LAST_PREFETCH_LOCATION_TYPE list only DEVICE, HOST, HOST_NUMA, and INVALID is the HOST_NUMA_CURRENT branch reachable in practice, or should a numa_current() prefetch be documented as reading back the resolved node?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

and INVALID is the HOST_NUMA_CURRENT branch reachable in practice

Not sure if this is accurate - I think this branch, according to the documentation, is unreachable at all times. IMO the branch should just be

 if loc_type == <int>cydriver.CUmemLocationType.CU_MEM_LOCATION_TYPE_INVALID:
    return None

# raise? Fall through?

Small self nit: the _HOST branch can also skip querying the id and return sooner to avoid an additional API query.

@isVoid isVoid Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correction: It seems like the doc is inconsistent - After runtime probing, the return type can be HOST_NUMA_CURRENT if the previously prefetched mem location is HOST_NUMA_CURRENT. So we should add INVALID branch and document numa_current.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@isVoid

isVoid commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test afb0334

@isVoid

isVoid commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test bcf63da

@github-actions

Copy link
Copy Markdown

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 feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cuda.core: expose mem-range attributes on ManagedBuffer (last_prefetch_location and read-side getters)

2 participants