Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cuda_core/cuda/core/_cpp/resource_handles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,10 @@ inline CUlibrary as_cu(const LibraryHandle& h) noexcept {
return h ? *h : nullptr;
}

inline CUmodule as_cu(const CUmodule& h) noexcept {
return h;
}

inline CUkernel as_cu(const KernelHandle& h) noexcept {
return h ? *h : nullptr;
}
Expand Down Expand Up @@ -838,6 +842,10 @@ inline std::intptr_t as_intptr(const LibraryHandle& h) noexcept {
return reinterpret_cast<std::intptr_t>(as_cu(h));
}

inline std::intptr_t as_intptr(const CUmodule& h) noexcept {
return reinterpret_cast<std::intptr_t>(as_cu(h));
}

inline std::intptr_t as_intptr(const KernelHandle& h) noexcept {
return reinterpret_cast<std::intptr_t>(as_cu(h));
}
Expand Down Expand Up @@ -968,6 +976,10 @@ inline PyObject* as_py(const LibraryHandle& h) noexcept {
return detail::make_py("cuda.bindings.driver", "CUlibrary", as_intptr(h));
}

inline PyObject* as_py(const CUmodule& h) noexcept {
return detail::make_py("cuda.bindings.driver", "CUmodule", as_intptr(h));
}

inline PyObject* as_py(const KernelHandle& h) noexcept {
return detail::make_py("cuda.bindings.driver", "CUkernel", as_intptr(h));
}
Expand Down
2 changes: 1 addition & 1 deletion cuda_core/cuda/core/_module.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ class ObjectCode:
"""

def get_module(self) -> object:
def get_module(self) -> driver.CUmodule:
"""Return a context-dependent :obj:`~driver.CUmodule` for legacy interop.
Bridges the native :obj:`~driver.CUlibrary` (see :attr:`handle`) to a
Expand Down
5 changes: 2 additions & 3 deletions cuda_core/cuda/core/_module.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ from __future__ import annotations

cimport cython
from libc.stddef cimport size_t
from libc.stdint cimport intptr_t
from libcpp.mutex cimport py_safe_call_once

from collections import namedtuple
Expand Down Expand Up @@ -811,7 +810,7 @@ cdef class ObjectCode:
HANDLE_RETURN(get_last_error())
return Kernel._from_handle(h_kernel)

def get_module(self) -> object:
def get_module(self) -> driver.CUmodule:
"""Return a context-dependent :obj:`~driver.CUmodule` for legacy interop.

Bridges the native :obj:`~driver.CUlibrary` (see :attr:`handle`) to a
Expand All @@ -828,7 +827,7 @@ cdef class ObjectCode:
cdef cydriver.CUmodule mod
with nogil:
HANDLE_RETURN(cydriver.cuLibraryGetModule(&mod, as_cu(self._h_library)))
return driver.CUmodule(<intptr_t>mod)
return as_py(mod)

@property
def code(self) -> CodeTypeT:
Expand Down
3 changes: 3 additions & 0 deletions cuda_core/cuda/core/_resource_handles.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ cdef extern from "_cpp/resource_handles.hpp" namespace "cuda_core":
cydriver.CUmemoryPool as_cu(MemoryPoolHandle h) noexcept nogil
cydriver.CUdeviceptr as_cu(DevicePtrHandle h) noexcept nogil
cydriver.CUlibrary as_cu(LibraryHandle h) noexcept nogil
cydriver.CUmodule as_cu(cydriver.CUmodule h) noexcept nogil
cydriver.CUkernel as_cu(KernelHandle h) noexcept nogil
cydriver.CUgraph as_cu(GraphHandle h) noexcept nogil
cydriver.CUgraphExec as_cu(GraphExecHandle h) noexcept nogil
Expand All @@ -107,6 +108,7 @@ cdef extern from "_cpp/resource_handles.hpp" namespace "cuda_core":
intptr_t as_intptr(MemoryPoolHandle h) noexcept nogil
intptr_t as_intptr(DevicePtrHandle h) noexcept nogil
intptr_t as_intptr(LibraryHandle h) noexcept nogil
intptr_t as_intptr(const cydriver.CUmodule& h) noexcept nogil
intptr_t as_intptr(KernelHandle h) noexcept nogil
intptr_t as_intptr(GraphHandle h) noexcept nogil
intptr_t as_intptr(GraphExecHandle h) noexcept nogil
Expand All @@ -130,6 +132,7 @@ cdef extern from "_cpp/resource_handles.hpp" namespace "cuda_core":
object as_py(MemoryPoolHandle h)
object as_py(DevicePtrHandle h)
object as_py(LibraryHandle h)
object as_py(const cydriver.CUmodule& h)
object as_py(KernelHandle h)
object as_py(GraphHandle h)
object as_py(GraphExecHandle h)
Expand Down
Loading