Skip to content

[cuda.core] Promote library loading to a public first-class Library API #2059

@rparolin

Description

@rparolin

Feature Request

Promote the internal cuLibrary*-backed loading path into a public
first-class Library class in cuda.core, symmetric to ObjectCode and
Kernel.

Current State

The low-level cuda.bindings layer already exposes cudaLibrary_t and
CUlibraryOption_enum. Internal cuda.core code references library
handles (e.g. LibraryHandle _h_library in _module.pxd, LIBRARY in
cuda.core.typing.CodeType, and ObjectCode.from_library(...)). However,
there is no public cuda.core.Library class — users who want to load a
CUDA library (a collection of kernels, constants, and global variables,
loaded via cuLibraryLoadData / cuLibraryLoadFromFile) have to go
through ObjectCode.from_library which returns an ObjectCode, not a
richer library-aware object.

Motivation

CUDA 12.0+ introduced cuLibrary* as the modern replacement for
cuModule*, supporting:

  • Per-library global variables with cuLibraryGetGlobal /
    cuLibraryGetManaged / cuLibraryGetUnifiedFunction.
  • Per-kernel and per-library options (CU_LIBRARY_BINARY_IS_PRESERVED,
    host universal function fallback, etc.).
  • Cleaner separation between "compiled artifact" (ObjectCode) and
    "loaded runtime handle" (Library) than the legacy module path.

A public Library class would let users access globals, query kernel
tables, and manage library lifetime explicitly — parity with what
cuModule* users get today via ObjectCode + Kernel, but for the
modern driver API.

Proposed Scope

  • A cuda.core.Library class wrapping CUlibrary with:
    • Library.load(data_or_path, options=...) factory
    • .get_kernel(name) -> Kernel
    • .get_global(name) -> (device_ptr, size)
    • .get_managed(name), .get_unified_function(name)
    • Context-manager lifecycle
  • A LibraryOptions dataclass mirroring CU_LIBRARY_* enum values.
  • Integration with the existing ObjectCode.from_library path — likely
    ObjectCode can expose a .to_library(options=...) shortcut.
  • API reference entries and at least one example.

Related

  • Driver APIs: cuLibraryLoadData, cuLibraryLoadFromFile, cuLibraryUnload,
    cuLibraryGetKernel, cuLibraryGetGlobal, cuLibraryGetManaged,
    cuLibraryGetUnifiedFunction, cuLibraryGetModule.
  • Existing internal references: cuda_core/cuda/core/_module.pxd
    (LibraryHandle), cuda_core/cuda/core/typing.py (CodeType.LIBRARY),
    ObjectCode.from_library in _module.pyx.
  • Part of cuda.core feature audit gap list (Nov 2025).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0High priority - Must do!cuda.coreEverything related to the cuda.core module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions