Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cuda_core/cuda/core/_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

cimport cpython
from libc.stdint cimport uintptr_t

from cuda.bindings cimport cydriver
from cuda.core._utils.cuda_utils cimport HANDLE_RETURN

import threading
from typing import TYPE_CHECKING

from cuda.core._context cimport Context
from cuda.core._context import ContextOptions
Expand All @@ -34,9 +35,6 @@ from cuda.core._utils.cuda_utils import (
)
from cuda.core._stream cimport default_stream

if TYPE_CHECKING:
from cuda.core._memory import Buffer, MemoryResource

# TODO: I prefer to type these as "cdef object" and avoid accessing them from within Python,
# but it seems it is very convenient to expose them for testing purposes...
_tls = threading.local()
Expand Down
9 changes: 3 additions & 6 deletions cuda_core/cuda/core/_event.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ from cuda.core._utils.cuda_utils cimport (
import cython
from dataclasses import dataclass
import multiprocessing
from typing import TYPE_CHECKING, Optional

from cuda.core._utils.cuda_utils import (
CUDAError,
check_multiprocessing_start_method,
)
if TYPE_CHECKING:
import cuda.bindings


@dataclass
Expand All @@ -56,9 +53,9 @@ cdef class EventOptions:

"""

enable_timing: Optional[bool] = False
busy_waited_sync: Optional[bool] = False
ipc_enabled: Optional[bool] = False
enable_timing: bool | None = False
busy_waited_sync: bool | None = False
ipc_enabled: bool | None = False


cdef class Event:
Expand Down
1 change: 1 addition & 0 deletions cuda_core/cuda/core/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

if TYPE_CHECKING:
from cuda.core._stream import Stream

from cuda.core._utils.cuda_utils import (
driver,
get_binding_version,
Expand Down
8 changes: 4 additions & 4 deletions cuda_core/cuda/core/_linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ class LinkerOptions:
prec_div: bool | None = None
prec_sqrt: bool | None = None
fma: bool | None = None
kernels_used: Union[str, tuple[str], list[str]] | None = None
variables_used: Union[str, tuple[str], list[str]] | None = None
kernels_used: str | tuple[str] | list[str] | None = None
variables_used: str | tuple[str] | list[str] | None = None
optimize_unused_variables: bool | None = None
ptxas_options: Union[str, tuple[str], list[str]] | None = None
ptxas_options: str | tuple[str] | list[str] | None = None
split_compile: int | None = None
split_compile_extended: int | None = None
no_cache: bool | None = None
Expand All @@ -203,7 +203,7 @@ def __post_init__(self):
_lazy_init()
self._name = self.name.encode()

def _prepare_nvjitlink_options(self, as_bytes: bool = False) -> Union[list[bytes], list[str]]:
def _prepare_nvjitlink_options(self, as_bytes: bool = False) -> list[bytes] | list[str]:
options = []

if self.arch is not None:
Expand Down
4 changes: 2 additions & 2 deletions cuda_core/cuda/core/_memory/_buffer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ from cuda.core._stream cimport Stream_accept, Stream
from cuda.core._utils.cuda_utils cimport HANDLE_RETURN

import sys
from typing import TypeVar, Union
from typing import TypeVar

if sys.version_info >= (3, 12):
from collections.abc import Buffer as BufferProtocol
Expand All @@ -40,7 +40,7 @@ from cuda.core._device import Device
__all__ = ['Buffer', 'MemoryResource']


DevicePointerT = Union[driver.CUdeviceptr, int, None]
DevicePointerT = driver.CUdeviceptr | int | None
"""
A type union of :obj:`~driver.CUdeviceptr`, `int` and `None` for hinting
:attr:`Buffer.handle`.
Expand Down
4 changes: 0 additions & 4 deletions cuda_core/cuda/core/_memory/_device_memory_resource.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ from cuda.core._utils.cuda_utils cimport (

from dataclasses import dataclass
import multiprocessing
from typing import TYPE_CHECKING
import platform # no-cython-lint
import uuid

from cuda.core._utils.cuda_utils import check_multiprocessing_start_method
from cuda.core._resource_handles cimport as_cu

if TYPE_CHECKING:
from .._device import Device

__all__ = ['DeviceMemoryResource', 'DeviceMemoryResourceOptions']


Expand Down
4 changes: 0 additions & 4 deletions cuda_core/cuda/core/_memory/_graph_memory_resource.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ from cuda.core._stream cimport default_stream, Stream_accept, Stream
from cuda.core._utils.cuda_utils cimport HANDLE_RETURN

from functools import cache
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from cuda.core._memory.buffer import DevicePointerT

__all__ = ['GraphMemoryResource']

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 @@ -6,6 +6,9 @@

from typing import TYPE_CHECKING

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

from cuda.core._memory._buffer import Buffer, MemoryResource
from cuda.core._utils.cuda_utils import (
_check_driver_error as raise_if_driver_error,
Expand All @@ -14,9 +17,6 @@
driver,
)

if TYPE_CHECKING:
from cuda.core._memory.buffer import DevicePointerT

__all__ = ["LegacyPinnedMemoryResource", "_SynchronousMemoryResource"]


Expand Down
3 changes: 1 addition & 2 deletions cuda_core/cuda/core/_memory/_managed_memory_resource.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ from cuda.core._utils.cuda_utils cimport (
)

from dataclasses import dataclass
from typing import Optional

__all__ = ['ManagedMemoryResource', 'ManagedMemoryResourceOptions']

Expand All @@ -28,7 +27,7 @@ cdef class ManagedMemoryResourceOptions:
or None to let the driver decide.
(Default to None)
"""
preferred_location : Optional[int] = None
preferred_location: int | None = None


cdef class ManagedMemoryResource(_MemPool):
Expand Down
7 changes: 1 addition & 6 deletions cuda_core/cuda/core/_memory/_memory_pool.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@ from cuda.core._utils.cuda_utils cimport (
HANDLE_RETURN,
)

from typing import TYPE_CHECKING
import platform # no-cython-lint
import weakref

from cuda.core._utils.cuda_utils import driver

if TYPE_CHECKING:
from cuda.core._memory.buffer import DevicePointerT
from .._device import Device


cdef class _MemPoolOptions:

Expand Down Expand Up @@ -302,7 +297,7 @@ cdef class _MemPool(MemoryResource):
return self._ipc_data is not None and self._ipc_data._is_mapped

@property
def uuid(self) -> Optional[uuid.UUID]:
def uuid(self) -> uuid.UUID | None:
"""
A universally unique identifier for this memory resource. Meaningful
only for IPC-enabled memory resources.
Expand Down
12 changes: 6 additions & 6 deletions cuda_core/cuda/core/_memory/_virtual_memory_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from __future__ import annotations

from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Iterable, Literal, Union
from typing import TYPE_CHECKING, Iterable, Literal

if TYPE_CHECKING:
from cuda.core._stream import Stream

from cuda.core._device import Device
from cuda.core._memory._buffer import Buffer, MemoryResource
Expand All @@ -19,15 +22,12 @@
_check_driver_error as raise_if_driver_error,
)

if TYPE_CHECKING:
from cuda.core._stream import Stream

__all__ = ["VirtualMemoryResourceOptions", "VirtualMemoryResource"]

VirtualMemoryHandleTypeT = Union[Literal["posix_fd", "generic", "win32_kmt", "fabric"], None]
VirtualMemoryHandleTypeT = Literal["posix_fd", "generic", "win32_kmt", "fabric"] | None
VirtualMemoryLocationTypeT = Literal["device", "host", "host_numa", "host_numa_current"]
VirtualMemoryGranularityT = Literal["minimum", "recommended"]
VirtualMemoryAccessTypeT = Union[Literal["rw", "r"], None]
VirtualMemoryAccessTypeT = Literal["rw", "r"] | None
VirtualMemoryAllocationTypeT = Literal["pinned", "managed"]


Expand Down
7 changes: 4 additions & 3 deletions cuda_core/cuda/core/_memoryview.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

from ._dlpack cimport *
from libc.stdint cimport intptr_t
from cuda.core._layout cimport _StridedLayout
from cuda.core._stream import Stream

import functools
import warnings
from typing import Optional

import numpy

Expand Down Expand Up @@ -321,14 +322,14 @@ cdef class StridedMemoryView:
return self.get_layout().get_shape_tuple()

@property
def strides(self) -> Optional[tuple[int, ...]]:
def strides(self) -> tuple[int, ...] | None:
"""
Strides of the tensor (in **counts**, not bytes).
"""
return self.get_layout().get_strides_tuple()

@property
def dtype(self) -> Optional[numpy.dtype]:
def dtype(self) -> numpy.dtype | None:
"""
Data type of the tensor.
"""
Expand Down
21 changes: 11 additions & 10 deletions cuda_core/cuda/core/_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

import functools
import threading
import weakref
from collections import namedtuple
from typing import Union

from cuda.core._device import Device
from cuda.core._launch_config import LaunchConfig, _to_native_launch_config
Expand Down Expand Up @@ -292,7 +293,7 @@ def max_active_blocks_per_multiprocessor(self, block_size: int, dynamic_shared_m
)

def max_potential_block_size(
self, dynamic_shared_memory_needed: Union[int, driver.CUoccupancyB2DSize], block_size_limit: int
self, dynamic_shared_memory_needed: int | driver.CUoccupancyB2DSize, block_size_limit: int
) -> MaxPotentialBlockSizeOccupancyResult:
"""MaxPotentialBlockSizeOccupancyResult: Suggested launch configuration for reasonable occupancy.

Expand Down Expand Up @@ -487,7 +488,7 @@ def occupancy(self) -> KernelOccupancy:
return self._occupancy

@staticmethod
def from_handle(handle: int, mod: "ObjectCode" = None) -> "Kernel":
def from_handle(handle: int, mod: ObjectCode = None) -> Kernel:
"""Creates a new :obj:`Kernel` object from a foreign kernel handle.

Uses a CUkernel pointer address to create a new :obj:`Kernel` object.
Expand Down Expand Up @@ -528,7 +529,7 @@ def from_handle(handle: int, mod: "ObjectCode" = None) -> "Kernel":
return Kernel._from_obj(kernel_obj, mod)


CodeTypeT = Union[bytes, bytearray, str]
CodeTypeT = bytes | bytearray | str


class ObjectCode:
Expand Down Expand Up @@ -582,7 +583,7 @@ def __reduce__(self):
return ObjectCode._reduce_helper, (self._module, self._code_type, self._name, self._sym_map)

@staticmethod
def from_cubin(module: Union[bytes, str], *, name: str = "", symbol_mapping: dict | None = None) -> "ObjectCode":
def from_cubin(module: bytes | str, *, name: str = "", symbol_mapping: dict | None = None) -> ObjectCode:
"""Create an :class:`ObjectCode` instance from an existing cubin.

Parameters
Expand All @@ -600,7 +601,7 @@ def from_cubin(module: Union[bytes, str], *, name: str = "", symbol_mapping: dic
return ObjectCode._init(module, "cubin", name=name, symbol_mapping=symbol_mapping)

@staticmethod
def from_ptx(module: Union[bytes, str], *, name: str = "", symbol_mapping: dict | None = None) -> "ObjectCode":
def from_ptx(module: bytes | str, *, name: str = "", symbol_mapping: dict | None = None) -> ObjectCode:
"""Create an :class:`ObjectCode` instance from an existing PTX.

Parameters
Expand All @@ -618,7 +619,7 @@ def from_ptx(module: Union[bytes, str], *, name: str = "", symbol_mapping: dict
return ObjectCode._init(module, "ptx", name=name, symbol_mapping=symbol_mapping)

@staticmethod
def from_ltoir(module: Union[bytes, str], *, name: str = "", symbol_mapping: dict | None = None) -> "ObjectCode":
def from_ltoir(module: bytes | str, *, name: str = "", symbol_mapping: dict | None = None) -> ObjectCode:
"""Create an :class:`ObjectCode` instance from an existing LTOIR.

Parameters
Expand All @@ -636,7 +637,7 @@ def from_ltoir(module: Union[bytes, str], *, name: str = "", symbol_mapping: dic
return ObjectCode._init(module, "ltoir", name=name, symbol_mapping=symbol_mapping)

@staticmethod
def from_fatbin(module: Union[bytes, str], *, name: str = "", symbol_mapping: dict | None = None) -> "ObjectCode":
def from_fatbin(module: bytes | str, *, name: str = "", symbol_mapping: dict | None = None) -> ObjectCode:
"""Create an :class:`ObjectCode` instance from an existing fatbin.

Parameters
Expand All @@ -654,7 +655,7 @@ def from_fatbin(module: Union[bytes, str], *, name: str = "", symbol_mapping: di
return ObjectCode._init(module, "fatbin", name=name, symbol_mapping=symbol_mapping)

@staticmethod
def from_object(module: Union[bytes, str], *, name: str = "", symbol_mapping: dict | None = None) -> "ObjectCode":
def from_object(module: bytes | str, *, name: str = "", symbol_mapping: dict | None = None) -> ObjectCode:
"""Create an :class:`ObjectCode` instance from an existing object code.

Parameters
Expand All @@ -672,7 +673,7 @@ def from_object(module: Union[bytes, str], *, name: str = "", symbol_mapping: di
return ObjectCode._init(module, "object", name=name, symbol_mapping=symbol_mapping)

@staticmethod
def from_library(module: Union[bytes, str], *, name: str = "", symbol_mapping: dict | None = None) -> "ObjectCode":
def from_library(module: bytes | str, *, name: str = "", symbol_mapping: dict | None = None) -> ObjectCode:
"""Create an :class:`ObjectCode` instance from an existing library.

Parameters
Expand Down
Loading
Loading