Skip to content

[FEA]: Autodetect __cuda_array_interface__ for launching kernels #1435

Closed as duplicate

Description

@desplenterkarel

Is this a duplicate?

Area

cuda.pathfinder

Is your feature request related to a problem? Please describe.

When researching how to launch kernels in python i came to the problem that unlike cupy, CUDA python needs .data.ptr or .data_ptr depending if its a cupy array or a pytorch tensor.

This came up in de discussion of a cupy kernel launch problem.
cupy#9576

Describe the solution you'd like

The __cuda_array_interface__ already has the specification that data key returns the pointer.

So the question is if we can leverage this and make the passing of array/tensors more pythonic (like for ints and so on).
By getting the pointer automatically if the interface is part of the object?

Describe alternatives you've considered

Alternatively we could just standardize either .data.ptr or .data_ptr. But as its already part or a standard interface this seams to be redundant.
But if here are other ideas or ways to achieve the same goal my very happy to hear them.

Additional context

No response

Activity

  1. cpcloud commented on Jan 7, 2026

    @cpcloud
    Contributor

    You might be able to use StridedMemoryView to get the abstraction you're after:

    from cuda.core.utils import StridedMemoryView
    
    smv = StridedMemoryView.from_cuda_array_interface(
        obj, # cupy array or torch tensor
    )
    # ...
    launch(..., smv.ptr)
  2. leofang commented on Jan 7, 2026

    @leofang
    Member

    Yes. Using SMV is our recommendation and in the future we'll make it work nicer (ex: #1280 would be the ideal end goal, and #1387 is the first step).

    As I noted in cupy/cupy#9576 (comment), though, we care a lot about kernel launch overhead, so it is unclear when/if #1280 will ever be supported. This problem is a lot worse for Array Interface and CUDA Array Interface, because checks like hasattr have side effects that prompted us to design the DLPack and CUDA Stream Protocols differently. Using CAI during kernel launch is known to kill perf for small kernels (the addition overhead is O(100) us instead of O(1) us).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNeeds the team's attention

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions