Skip to content

Turn all cdef class objects in the Python layer to cdef public class #464

Open

Description

@leofang

This allows us to share the class declarations with C/C++:
https://cython.readthedocs.io/en/latest/src/userguide/external_C_code.html#using-cython-declarations-from-c
which is needed after PR #463 set up a path for Python-C/C++/Cython interoperability, but without adding the public qualifier the interoperability was limited to Cython only.

Activity

  1. added
    cuda.bindingsEverything related to the cuda.bindings module
    enhancementAny code-related improvements
    P1Medium priority - Should do
    on Feb 24, 2025
  2. leofang commented on Feb 24, 2025

    @leofang
    MemberAuthor

    @vzhurba01 I hope this is a simple one-liner change to the codegen and the remaining task is on verifying the generated headers. Could you take a look?

  3. leofang commented on Apr 23, 2025

    @leofang
    MemberAuthor

    It is unclear to me if we still need this done if we want to go by the route of #564. @oleksandr-pavlyk @shwina WDYT?

  4. shwina commented on Apr 23, 2025

    @shwina
    Contributor

    Hmm, if my understanding is correct, the two seem a bit orthogonal:

    1. cdef public would allow e.g., third-party C/C++ code to use types defined in Cython (not sure if we know of use cases for this)
    2. get_native_hande() would allow us to grab a pointer to the underlying native CUDA object wrapped by a Cython type

    Am I missing something or can (1) be used in place of (2) somehow?

  5. oleksandr-pavlyk commented on Apr 23, 2025

    @oleksandr-pavlyk
    Contributor

    @leofang, I think it should be cdef api instead of cdef public.

  6. leofang commented on May 23, 2025

    @leofang
    MemberAuthor

    Sorry I somehow dropped the ball and Sasha reminded me about this with a use case in mind (accessing cuda.bindings types in pybind11).

    @shwina You're absolutely right. And it turns out we need both:

    // pseudo code
    #include <cuda_bindings_runtime.h>
    
    cudaStream_t c_stream = <cudaStream_t>get_native_cuda_handle<cuda_bindings_runtime_cudaStream_t>(py_stream);

    We need to expose the C definitions for all Python classes (via cdef public) and then use it with get_native_cuda_handle to unbox. @oleksandr-pavlyk pointed out that test code we had with get_native_cuda_handle got around with the first requirement because we tested it in Cython and we got the definition for free.

    I think it should be cdef api instead of cdef public.

    Yes if we need more than the type information from cuda.bindings.

    Assigning to Sasha for now as he'd have a use case study. @oleksandr-pavlyk all the needed changes to cuda.bindings will need to be done in the cython-gen, so just report back what's needed to happen and we can find someone else to work on the next step.

  7. removed this from the cuda.bindings backlog milestone on Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1Medium priority - Should docuda.bindingsEverything related to the cuda.bindings moduleenhancementAny code-related improvements

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions