Skip to content
Draft
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
12 changes: 9 additions & 3 deletions src/gt4py/_core/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ class DeviceType(enum.IntEnum):
https://github.com/dmlc/dlpack/blob/main/include/dlpack/dlpack.h
"""

INVALID_DEVICE = -1
CPU = 1
CUDA = 2
# CPU_PINNED = 3 # noqa: ERA001
Expand All @@ -388,11 +389,18 @@ class DeviceType(enum.IntEnum):
ROCM = 10
# CUDA_MANAGED = 13 # noqa: ERA001
# ONE_API = 14 # noqa: ERA001
GPU = ( # TODO whatever makes sense
CUDA
if cp is not None
and not (cp.cuda.runtime.is_hip if hasattr(cp.cuda.runtime, "is_hip") else False)
else ROCM
)


CPUDeviceTyping: TypeAlias = Literal[DeviceType.CPU]
CUDADeviceTyping: TypeAlias = Literal[DeviceType.CUDA]
ROCMDeviceTyping: TypeAlias = Literal[DeviceType.ROCM]
GPUDeviceTyping: TypeAlias = Literal[DeviceType.GPU]


DeviceTypeT = TypeVar(
Expand All @@ -403,9 +411,7 @@ class DeviceType(enum.IntEnum):
)


CUPY_DEVICE_TYPE = (
None if not cp else (DeviceType.ROCM if cp.cuda.runtime.is_hip else DeviceType.CUDA)
)
CUPY_DEVICE_TYPE = DeviceType.GPU


@dataclasses.dataclass(frozen=True)
Expand Down
2 changes: 1 addition & 1 deletion src/gt4py/next/allocators.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def is_field_allocation_tool(obj: Any) -> TypeGuard[FieldBufferAllocationUtil]:

def is_field_allocation_tool_for(
obj: Any, device: core_defs.DeviceTypeT
) -> TypeGuard[FieldBufferAllocationUtil]:
) -> TypeGuard[FieldBufferAllocationUtil[core_defs.DeviceTypeT]]:
return is_field_allocator_for(obj, device) or is_field_allocator_factory_for(obj, device)


Expand Down
Loading