File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -458,6 +458,16 @@ class ObjectCode:
458458
459459 """
460460
461+ def get_module (self ) -> object :
462+ """Return the :obj:`~driver.CUmodule` associated with this object code.
463+
464+ Returns
465+ -------
466+ :obj:`~driver.CUmodule`
467+ Module handle for the current CUDA context, suitable for legacy
468+ driver APIs that accept ``CUmodule``.
469+ """
470+
461471 @property
462472 def code (self ) -> CodeTypeT :
463473 """Return the underlying code object."""
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ from __future__ import annotations
66
77cimport cython
88from libc.stddef cimport size_t
9+ from libc.stdint cimport intptr_t
910
1011from collections import namedtuple
1112from os import fsencode, fspath, PathLike
@@ -796,6 +797,21 @@ cdef class ObjectCode:
796797 HANDLE_RETURN(get_last_error())
797798 return Kernel._from_handle(h_kernel)
798799
800+ def get_module (self ) -> object:
801+ """Return the :obj:`~driver.CUmodule` associated with this object code.
802+
803+ Returns
804+ -------
805+ :obj:`~driver.CUmodule`
806+ Module handle for the current CUDA context , suitable for legacy
807+ driver APIs that accept ``CUmodule``.
808+ """
809+ self._lazy_load_module()
810+ cdef cydriver.CUmodule mod
811+ with nogil:
812+ HANDLE_RETURN(cydriver.cuLibraryGetModule(&mod , as_cu(self._h_library )))
813+ return driver.CUmodule(<intptr_t>mod )
814+
799815 @property
800816 def code(self ) -> CodeTypeT:
801817 """Return the underlying code object."""
Original file line number Diff line number Diff line change @@ -226,6 +226,21 @@ def test_get_kernel(init_cuda):
226226 assert object_code .get_kernel (b"ABC" ).handle is not None
227227
228228
229+ def test_object_code_get_module_for_legacy_integration (init_cuda ):
230+ src = """
231+ extern "C" __global__ void ABC() { }
232+ extern "C" __global__ void DEF() { }
233+ """
234+ object_code = Program (src , "c++" ).compile ("cubin" )
235+
236+ # Bridge: CUlibrary (new) → CUmodule (legacy)
237+ module = object_code .get_module ()
238+
239+ # Legacy module-only API consumes it directly
240+ count = handle_return (driver .cuModuleGetFunctionCount (module ))
241+ assert count == 2
242+
243+
229244@pytest .mark .parametrize (
230245 "attr, expected_type" ,
231246 [
You can’t perform that action at this time.
0 commit comments