Skip to content

Commit 5d8fa24

Browse files
committed
fix(core): retain driver log buffers for CUlinkState lifetime
Linker_link was nulling self._drv_log_bufs right after cuLinkComplete, releasing the bytearrays whose addresses were handed to the driver via CU_JIT_INFO_LOG_BUFFER and CU_JIT_ERROR_LOG_BUFFER at cuLinkCreate time. The CUlinkState retains those pointers until cuLinkDestroy, which runs during Linker tp_dealloc. Freeing the bytearrays first left the driver with dangling pointers and corrupted the heap; subsequent CUDA calls (e.g. NVRTC compilation in the next test fixture) segfaulted. This path became reachable in CI with the new per-instance backend dispatch: CTK 12.9.1 + driver 13.0 runners now hit the driver linker for cross-major linking, which was never exercised before. Retain _drv_log_bufs until the cdef class is deallocated; pxd declaration order ensures _culink_handle (and therefore cuLinkDestroy) runs before the bytearrays are cleared.
1 parent 44b4380 commit 5d8fa24

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

cuda_core/cuda/core/_linker.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cdef class Linker:
1010
NvJitLinkHandle _nvjitlink_handle
1111
CuLinkHandle _culink_handle
1212
bint _use_nvjitlink
13-
object _drv_log_bufs # formatted_options list (driver); None for nvjitlink; cleared in link()
13+
object _drv_log_bufs # formatted_options list (driver); None for nvjitlink
1414
str _info_log # decoded log; None until link() or pre-link get_*_log()
1515
str _error_log # decoded log; None until link() or pre-link get_*_log()
1616
object _options # LinkerOptions

cuda_core/cuda/core/_linker.pyx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,12 @@ cdef inline object Linker_link(Linker self, str target_type):
627627
raise
628628
code = (<char*>c_cubin_out)[:c_output_size]
629629

630-
# Linking is complete; cache the decoded log strings and release
631-
# the driver's raw bytearray buffers (no longer written to).
630+
# Linking is complete; cache the decoded log strings. The driver's raw
631+
# bytearray buffers are retained for the lifetime of the CUlinkState
632+
# because cuLinkDestroy may still dereference the log-buffer pointers
633+
# registered via cuLinkCreate.
632634
self._info_log = self.get_info_log()
633635
self._error_log = self.get_error_log()
634-
self._drv_log_bufs = None
635636

636637
return ObjectCode._init(bytes(code), target_type, name=self._options.name)
637638

0 commit comments

Comments
 (0)