Skip to content
6 changes: 3 additions & 3 deletions cuda_core/cuda/core/_context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ from cuda.core._utils.cuda_utils cimport HANDLE_RETURN
__all__ = ['Context', 'ContextOptions']


DeviceResourcesT = Sequence[SMResource | WorkqueueResource]
DeviceResourcesType = Sequence[SMResource | WorkqueueResource]


cdef class Context:
Expand Down Expand Up @@ -149,7 +149,7 @@ cdef class ContextOptions:
Attributes
----------
resources : :obj:`~cuda.core.typing.DeviceResourcesT`
resources : :obj:`~cuda.core.typing.DeviceResourcesType`
Device resources used to create a green context.
"""
resources: DeviceResourcesT
resources: DeviceResourcesType
6 changes: 3 additions & 3 deletions cuda_core/cuda/core/_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ from cuda.core._resource_handles cimport (
as_cu,
)

from cuda.core._stream import IsStreamT, Stream, StreamOptions
from cuda.core._stream import IsStreamType, Stream, StreamOptions
from cuda.core._utils.clear_error_support import assert_type
from cuda.core._utils.cuda_utils import (
ComputeCapability,
Expand Down Expand Up @@ -1341,7 +1341,7 @@ class Device:

return Context._from_green_ctx(Context, h_green, self._device_id)

def create_stream(self, obj: IsStreamT | None = None, options: StreamOptions | None = None) -> Stream:
def create_stream(self, obj: IsStreamType | None = None, options: StreamOptions | None = None) -> Stream:
"""Create a :obj:`~_stream.Stream` object.

New stream objects can be created in two different ways:
Expand All @@ -1358,7 +1358,7 @@ class Device:

Parameters
----------
obj : :obj:`~_stream.IsStreamT`, optional
obj : :obj:`~_stream.IsStreamType`, optional
Any object supporting the ``__cuda_stream__`` protocol.
options : :obj:`~_stream.StreamOptions`, optional
Customizable dataclass for stream creation options.
Expand Down
2 changes: 1 addition & 1 deletion cuda_core/cuda/core/_launcher.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ from cuda.core._stream import Stream
from math import prod


def launch(stream: Stream | GraphBuilder | IsStreamT, config: LaunchConfig, kernel: Kernel, *kernel_args):
def launch(stream: Stream | GraphBuilder | IsStreamType, config: LaunchConfig, kernel: Kernel, *kernel_args):
"""Launches a :obj:`~_module.Kernel`
object with launch-time configuration.
Expand Down
13 changes: 7 additions & 6 deletions cuda_core/cuda/core/_linker.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ from cuda.core._utils.cuda_utils import (
driver,
is_sequence,
)
from cuda.core.typing import CompilerBackendType

ctypedef const char* const_char_ptr
ctypedef void* void_ptr
Expand Down Expand Up @@ -70,12 +71,12 @@ cdef class Linker:
def __init__(self, *object_codes: ObjectCode, options: "LinkerOptions" = None):
Linker_init(self, object_codes, options)

def link(self, target_type) -> ObjectCode:
def link(self, target_type: ObjectCodeFormatType | str) -> ObjectCode:
"""Link the provided object codes into a single output of the specified target type.

Parameters
----------
target_type : str
target_type : ObjectCodeFormatType | str
The type of the target output. Must be either "cubin" or "ptx".

Returns
Expand All @@ -88,7 +89,7 @@ cdef class Linker:
Ensure that input object codes were compiled with appropriate
flags for linking (e.g., relocatable device code enabled).
"""
return Linker_link(self, target_type)
return Linker_link(self, str(target_type))

def get_error_log(self) -> str:
"""Get the error log generated by the linker.
Expand Down Expand Up @@ -168,9 +169,9 @@ cdef class Linker:
return as_py(self._culink_handle)

@property
def backend(self) -> str:
"""Return this Linker instance's underlying backend."""
return "nvJitLink" if self._use_nvjitlink else "driver"
def backend(self) -> CompilerBackendType:
"""Return this Linker instance's underlying :class:`CompilerBackendType`."""
return CompilerBackendType.NVJITLINK if self._use_nvjitlink else CompilerBackendType.DRIVER


# =============================================================================
Expand Down
19 changes: 7 additions & 12 deletions cuda_core/cuda/core/_memory/_buffer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ from cuda.core._resource_handles cimport (
as_cu,
set_deallocation_stream,
)
from cuda.core.typing import DevicePointerType

from cuda.core._stream cimport Stream, Stream_accept
from cuda.core._utils.cuda_utils cimport HANDLE_RETURN, _parse_fill_value
Expand All @@ -35,7 +36,6 @@ else:
BufferProtocol = object

from cuda.core._dlpack import classify_dl_device, make_py_capsule
from cuda.core._utils.cuda_utils import driver
from cuda.core._device import Device


Expand Down Expand Up @@ -65,11 +65,6 @@ register_mr_dealloc_callback(_mr_dealloc_callback)
__all__ = ['Buffer', 'MemoryResource']


DevicePointerT = driver.CUdeviceptr | int | None
"""
A type union of :obj:`~driver.CUdeviceptr`, `int` and `None` for hinting
:attr:`Buffer.handle`.
"""

cdef class Buffer:
"""Represent a handle to allocated memory.
Expand Down Expand Up @@ -97,7 +92,7 @@ cdef class Buffer:

@classmethod
def _init(
cls, ptr: DevicePointerT, size_t size, mr: MemoryResource | None = None,
cls, ptr: DevicePointerType, size_t size, mr: MemoryResource | None = None,
ipc_descriptor: IPCBufferDescriptor | None = None,
owner : object | None = None
):
Expand Down Expand Up @@ -132,14 +127,14 @@ cdef class Buffer:

@staticmethod
def from_handle(
ptr: DevicePointerT, size_t size, mr: MemoryResource | None = None,
ptr: DevicePointerType, size_t size, mr: MemoryResource | None = None,
owner: object | None = None,
) -> Buffer:
"""Create a new :class:`Buffer` object from a pointer.

Parameters
----------
ptr : :obj:`~_memory.DevicePointerT`
ptr : :obj:`~_memory.DevicePointerType`
Allocated buffer handle object
size : int
Memory size of the buffer
Expand Down Expand Up @@ -347,7 +342,7 @@ cdef class Buffer:
return self._mem_attrs.device_id

@property
def handle(self) -> DevicePointerT:
def handle(self) -> DevicePointerType:
"""Return the buffer handle object.

.. caution::
Expand Down Expand Up @@ -515,12 +510,12 @@ cdef class MemoryResource:
"""
raise TypeError("MemoryResource.allocate must be implemented by subclasses.")

def deallocate(self, ptr: DevicePointerT, size_t size, stream: Stream | GraphBuilder | None = None):
def deallocate(self, ptr: DevicePointerType, size_t size, stream: Stream | GraphBuilder | None = None):
"""Deallocate a buffer previously allocated by this resource.

Parameters
----------
ptr : :obj:`~_memory.DevicePointerT`
ptr : :obj:`~_memory.DevicePointerType`
The pointer or handle to the buffer to deallocate.
size : int
The size of the buffer to deallocate, in bytes.
Expand Down
4 changes: 2 additions & 2 deletions cuda_core/cuda/core/_memory/_graph_memory_resource.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -111,7 +111,7 @@ cdef class cyGraphMemoryResource(MemoryResource):
stream = Stream_accept(stream) if stream is not None else default_stream()
return GMR_allocate(self, size, <Stream> stream)

def deallocate(self, ptr: "DevicePointerT", size_t size, stream: Stream | GraphBuilder | None = None):
def deallocate(self, ptr: "DevicePointerType", size_t size, stream: Stream | GraphBuilder | None = None):
"""
Deallocate a buffer of the requested size. See documentation for :obj:`~_memory.MemoryResource`.
"""
Expand Down
6 changes: 3 additions & 3 deletions cuda_core/cuda/core/_memory/_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from cuda.core._memory._buffer import DevicePointerT
from cuda.core._memory._buffer import DevicePointerType

from cuda.core._memory._buffer import Buffer, MemoryResource
from cuda.core._utils.cuda_utils import (
Expand Down Expand Up @@ -53,12 +53,12 @@ def allocate(self, size, stream=None) -> Buffer:
ptr = 0
return Buffer._init(ptr, size, self)

def deallocate(self, ptr: DevicePointerT, size, stream):
def deallocate(self, ptr: DevicePointerType, size, stream):
"""Deallocate a buffer previously allocated by this resource.

Parameters
----------
ptr : :obj:`~_memory.DevicePointerT`
ptr : :obj:`~_memory.DevicePointerType`
The pointer or handle to the buffer to deallocate.
size : int
The size of the buffer to deallocate, in bytes.
Expand Down
12 changes: 7 additions & 5 deletions cuda_core/cuda/core/_memory/_managed_memory_resource.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ from dataclasses import dataclass
import threading
import warnings

from cuda.core.typing import ManagedMemoryLocationType

__all__ = ['ManagedMemoryResource', 'ManagedMemoryResourceOptions']


Expand All @@ -30,7 +32,7 @@ cdef class ManagedMemoryResourceOptions:
meaning depends on ``preferred_location_type``.
(Default to ``None``)

preferred_location_type : ``"device"`` | ``"host"`` | ``"host_numa"`` | None, optional
preferred_location_type : ManagedMemoryLocationType | str | None, optional
Controls how ``preferred_location`` is interpreted.

When set to ``None`` (the default), legacy behavior is used:
Expand All @@ -54,7 +56,7 @@ cdef class ManagedMemoryResourceOptions:
(Default to ``None``)
"""
preferred_location: int | None = None
preferred_location_type: str | None = None
preferred_location_type: ManagedMemoryLocationType | str | None = None


cdef class ManagedMemoryResource(_MemPool):
Expand Down Expand Up @@ -97,7 +99,7 @@ cdef class ManagedMemoryResource(_MemPool):
return -1

@property
def preferred_location(self) -> tuple | None:
def preferred_location(self) -> tuple[ManagedMemoryLocationType, int | None] | None:
"""The preferred location for managed memory allocations.

Returns ``None`` if no preferred location is set (driver decides),
Expand All @@ -108,8 +110,8 @@ cdef class ManagedMemoryResource(_MemPool):
if self._pref_loc_type is None:
return None
if self._pref_loc_type == "host":
return ("host", None)
return (self._pref_loc_type, self._pref_loc_id)
return (ManagedMemoryLocationType.HOST, None)
return (ManagedMemoryLocationType(self._pref_loc_type), self._pref_loc_id)

@property
def is_device_accessible(self) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions cuda_core/cuda/core/_memory/_memory_pool.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ cdef class _MemPool(MemoryResource):
stream = Stream_accept(stream) if stream is not None else default_stream()
return _MP_allocate(self, size, <Stream> stream)

def deallocate(self, ptr: "DevicePointerT", size_t size, stream: Stream | GraphBuilder | None = None):
def deallocate(self, ptr: "DevicePointerType", size_t size, stream: Stream | GraphBuilder | None = None):
"""Deallocate a buffer previously allocated by this resource.

Parameters
----------
ptr : :obj:`~_memory.DevicePointerT`
ptr : :obj:`~_memory.DevicePointerType`
The pointer or handle to the buffer to deallocate.
size : int
The size of the buffer to deallocate, in bytes.
Expand Down
Loading
Loading