Commit 863f898
Cythonize _linker.py (#1604)
* Begin Cythonization of _program.py
- Rename _program.py to _program.pyx
- Convert Program to cdef class with _program.pxd declarations
- Extract _MembersNeededForFinalize to module-level _ProgramMNFF
(nested classes not allowed in cdef class)
- Add __repr__ method to Program
- Keep ProgramOptions as @DataClass (unchanged)
- Keep weakref.finalize pattern for handle cleanup
* Extract Program helpers to module-level cdef functions
- Move _translate_program_options to Program_translate_options (cdef)
- Move _can_load_generated_ptx to Program_can_load_generated_ptx (cdef)
- Remove unused TYPE_CHECKING import block
- Follow _memory/_buffer.pyx helper function patterns
* Complete Cythonization of _program.py
- Reorganize file structure per developer guide (principal class first)
- Add module docstring, __all__, type alias section
- Factor long methods into cdef inline helpers
- Add proper exception specs to cdef functions
- Fix docstrings (use :class: refs, public paths)
- Add type annotations to public methods
- Inline _nvvm_exception_manager (single use)
- Remove Union import, use | syntax
- Add public Program.driver_can_load_nvrtc_ptx_output() API
- Update tests to use new public API
Closes #1082
* Extend test_object_protocols.py with Program and ObjectCode variations
Add fixtures for different Program backends (NVRTC, PTX, NVVM) and
ObjectCode code types (cubin, PTX, LTOIR). Split API_TYPES into more
precise HASH_TYPES, EQ_TYPES, and WEAKREF_TYPES lists. Derive
DICT_KEY_TYPES and WEAK_KEY_TYPES for collection tests.
* Add NVRTC/NVVM resource handles and remove Program MNFF
- Add NvrtcProgramHandle and NvvmProgramHandle to resource handles module
- Add function pointer initialization for nvrtcDestroyProgram and nvvmDestroyProgram
- Forward-declare nvvmProgram to avoid nvvm.h dependency
- Refactor detail::make_py to accept module name parameter
- Remove _ProgramMNFF class from _program.pyx
- Program now uses typed handles directly with RAII cleanup
- Update handle property to return None when handle is null
* Add HANDLE_RETURN_NVRTC and HANDLE_RETURN_NVVM, simplify HANDLE_RETURN
- Add NVVMError exception class
- Add HANDLE_RETURN_NVRTC for nogil NVRTC error handling with program log
- Add HANDLE_RETURN_NVVM for nogil NVVM error handling with program log
- Remove vestigial supported_error_type fused type
- Simplify HANDLE_RETURN to directly take cydriver.CUresult
* Fix build errors, update tests, remove unused imports
- Change cdef function return types from ObjectCode to object (Cython limitation)
- Remove unused imports: intptr_t, NvrtcProgramHandle, NvvmProgramHandle, as_intptr
- Update as_py(NvvmProgramHandle) to return Python int via PyLong_FromSsize_t
- Update test assertions: remove handle checks after close(), test idempotency instead
- Update NVVM error message regex to match new unified format
* Address review feedback: keep _can_load_generated_ptx private, update SPDX dates
- Remove Program.driver_can_load_nvrtc_ptx_output() public static method
- Make _can_load_generated_ptx a cpdef (callable from Python tests)
- Update tests to import _can_load_generated_ptx from cuda.core._program
- Update SPDX copyright years to 2024-2026 for files with 2024-2025
- Update get_kernel docstring: name parameter is str | bytes
Co-authored-by: Cursor <cursoragent@cursor.com>
* Address review feedback: NVVMError inherits from nvvmError, clean up error helpers
- Make NVVMError inherit from cuda.bindings.nvvm.nvvmError for compatibility
with code catching nvvmError, while also inheriting from CUDAError
- Simplify HANDLE_RETURN_NVRTC and HANDLE_RETURN_NVVM to just check success
and delegate to helper functions
- Move all error handling logic into _raise_nvrtc_error and _raise_nvvm_error
Co-authored-by: Cursor <cursoragent@cursor.com>
* Add 0.6.x release notes with cuda-bindings build requirement change
Co-authored-by: Cursor <cursoragent@cursor.com>
* Begin Cythonization of _linker.py
Rename _linker.py to _linker.pyx with cdef class Linker. Create
_linker.pxd with typed attribute declarations. Move inner
_MembersNeededForFinalize class to module level.
No behavior change; all existing tests pass.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Add NvJitLinkHandle, CuLinkHandle RAII and HANDLE_RETURN_NVJITLINK
Add resource handle infrastructure for linker cythonization:
- NvJitLinkHandle and CuLinkHandle in resource_handles.hpp/.cpp with
shared_ptr RAII ownership and automatic destroy on release.
- TaggedHandle<T, int> template to make void*-based handle types
(NvvmProgramHandle, NvJitLinkHandle) distinct for C++ overloading.
- Factory functions, as_cu/as_intptr/as_py accessors, and function
pointer initialization for nvJitLinkDestroy and cuLinkDestroy.
- HANDLE_RETURN_NVJITLINK in cuda_utils for nvJitLink error handling
with automatic error log retrieval.
Pure infrastructure; no changes to _linker.pyx yet.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Replace MNFF/weakref.finalize with RAII handle ownership in _linker
The Linker class now holds NvJitLinkHandle and CuLinkHandle shared_ptrs
directly as cdef attributes, replacing the _LinkerMembersNeededForFinalize
helper class and weakref.finalize destructor pattern. close() simply
resets the shared_ptr. Also removes _const_char_keep_alive (unnecessary)
and TYPE_CHECKING block.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Migrate linker to C-level calls with nogil
Both nvJitLink and driver paths now use cynvjitlink/cydriver C-level
calls directly, releasing the GIL around expensive operations. Option
arrays built with std::vector (RAII, no manual malloc/free). Removed
_exception_manager context manager (was too broad, caught TypeError);
driver path errors annotated via targeted except CUDAError. Removed
ctypes dependency, _input_type_from_code_type (inlined), and
TYPE_CHECKING block.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Clean up module globals: remove _nvjitlink, use C-level enum ints
Replace _nvjitlink Python module global with _use_nvjitlink_backend flag.
Input type dicts now use C-level enum values (cynvjitlink/cydriver)
instead of Python enum objects. The cuda.bindings.nvjitlink module is
only imported locally for availability detection.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Reorganize _linker module per developer guide conventions
- Add module docstring and __all__ declaration
- Reorder file: Linker (principal) -> LinkerOptions (supporting) -> cdef inline helpers -> private state
- Extract cdef inline helpers: Linker_init, Linker_add_code_object, Linker_link, Linker_annotate_error_log
- Fix import ordering per developer guide (5 groups)
- Apply c_ prefix to cdef variables for clarity
- Replace _formatted_options/option_keys with typed log members
- Cache decoded log strings after link() for efficiency
- Type Linker _linker member in _program.pxd (object -> Linker)
Co-authored-by: Cursor <cursoragent@cursor.com>
* Fix cython-lint warnings in _linker.pyx
Remove unused cimports (CuLinkHandle, NvJitLinkHandle already declared
in .pxd) and use __import__ for the availability check to avoid an
unused-import lint error.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Minor fixes for review feedback.
---------
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 3e4af8f commit 863f898
File tree
10 files changed
+719
-306
lines changed- cuda_core
- cuda/core
- _cpp
- _utils
- docs/source/release
10 files changed
+719
-306
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
| |||
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
| 71 | + | |
| 72 | + | |
68 | 73 | | |
69 | 74 | | |
70 | 75 | | |
| |||
869 | 874 | | |
870 | 875 | | |
871 | 876 | | |
872 | | - | |
| 877 | + | |
873 | 878 | | |
874 | 879 | | |
875 | 880 | | |
876 | 881 | | |
877 | 882 | | |
878 | | - | |
| 883 | + | |
879 | 884 | | |
880 | 885 | | |
881 | 886 | | |
882 | 887 | | |
883 | 888 | | |
884 | | - | |
| 889 | + | |
885 | 890 | | |
886 | 891 | | |
887 | 892 | | |
| |||
890 | 895 | | |
891 | 896 | | |
892 | 897 | | |
893 | | - | |
| 898 | + | |
894 | 899 | | |
895 | 900 | | |
896 | 901 | | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
897 | 963 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
19 | 39 | | |
20 | 40 | | |
21 | 41 | | |
| |||
72 | 92 | | |
73 | 93 | | |
74 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
75 | 98 | | |
76 | 99 | | |
77 | 100 | | |
| |||
97 | 120 | | |
98 | 121 | | |
99 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
100 | 136 | | |
101 | 137 | | |
102 | 138 | | |
| |||
109 | 145 | | |
110 | 146 | | |
111 | 147 | | |
112 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
113 | 151 | | |
114 | 152 | | |
115 | 153 | | |
| |||
347 | 385 | | |
348 | 386 | | |
349 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
350 | 415 | | |
351 | 416 | | |
352 | 417 | | |
| |||
389 | 454 | | |
390 | 455 | | |
391 | 456 | | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
392 | 465 | | |
393 | 466 | | |
394 | 467 | | |
| |||
434 | 507 | | |
435 | 508 | | |
436 | 509 | | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
437 | 518 | | |
438 | 519 | | |
439 | 520 | | |
| |||
486 | 567 | | |
487 | 568 | | |
488 | 569 | | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
489 | 579 | | |
490 | 580 | | |
491 | 581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
0 commit comments