warp.Device#

class warp.Device(runtime, alias, ordinal=-1, is_primary=False, context=None)[source]#

A device to allocate Warp arrays and to launch kernels on.

ordinal#

A Warp-specific label for the device. -1 for CPU devices.

Type:

int

name#

A label for the device. By default, CPU devices will be named according to the processor name, or "CPU" if the processor name cannot be determined.

Type:

str

arch#

The compute capability version number calculated as 10 * major + minor. 0 for CPU devices.

Type:

int

sm_count#

The number of streaming multiprocessors on the CUDA device. 0 for CPU devices.

Type:

int

is_uva#

Indicates whether the device supports unified addressing. False for CPU devices.

Type:

bool

is_cubin_supported#

Indicates whether Warp’s version of NVRTC can directly generate CUDA binary files (cubin) for this device’s architecture. False for CPU devices.

Type:

bool

is_mempool_supported#

Indicates whether the device supports using the cuMemAllocAsync and cuMemPool family of APIs for stream-ordered memory allocations. False for CPU devices.

Type:

bool

is_ipc_supported#

Indicates whether the device supports IPC.

  • True if supported.

  • False if not supported.

  • None if IPC support could not be determined.

Type:

Optional[bool]

is_primary#

Indicates whether this device’s CUDA context is also the device’s primary context.

Type:

bool

uuid#

The UUID of the CUDA device. The UUID is in the same format used by nvidia-smi -L. None for CPU devices.

Type:

str

pci_bus_id#

An identifier for the CUDA device in the format [domain]:[bus]:[device], in which domain, bus, and device are all hexadecimal values. None for CPU devices.

Type:

str

__init__(
runtime,
alias,
ordinal=-1,
is_primary=False,
context=None,
)[source]#

Methods

__init__(runtime, alias[, ordinal, ...])

can_access(other)

get_allocator([pinned])

Get the memory allocator for this device.

get_cuda_compile_arch()

Get the CUDA architecture to use when compiling code for this device.

get_cuda_output_format([preferred_cuda_output])

Determine the CUDA output format to use for this device.

make_current()

set_stream(stream[, sync])

Set the current stream for this CUDA device.

Attributes

context

The context associated with the device.

free_memory

The amount of memory on the device that is free according to the OS in bytes.

has_context

A boolean indicating whether the device has a CUDA context associated with it.

has_stream

A boolean indicating whether the device has a stream associated with it.

is_capturing

A boolean indicating whether this device's default stream is currently capturing a graph.

is_cpu

A boolean indicating whether the device is a CPU device.

is_cuda

A boolean indicating whether the device is a CUDA device.

stream

The stream associated with a CUDA device.

total_memory

The total amount of device memory available in bytes.

get_allocator(pinned=False)[source]#

Get the memory allocator for this device.

Parameters:

pinned (bool) – If True, an allocator for pinned memory will be returned. Only applicable when this device is a CPU device.

property is_cpu: bool[source]#

A boolean indicating whether the device is a CPU device.

property is_cuda: bool[source]#

A boolean indicating whether the device is a CUDA device.

property is_capturing: bool[source]#

A boolean indicating whether this device’s default stream is currently capturing a graph.

property context[source]#

The context associated with the device.

property has_context: bool[source]#

A boolean indicating whether the device has a CUDA context associated with it.

property stream: Stream[source]#

The stream associated with a CUDA device.

Raises:

RuntimeError – The device is not a CUDA device.

set_stream(stream, sync=True)[source]#

Set the current stream for this CUDA device.

The current stream will be used by default for all kernel launches and memory operations on this device.

If this is an external stream, the caller is responsible for guaranteeing the lifetime of the stream.

Consider using warp.ScopedStream instead.

Parameters:
  • stream (Stream) – The stream to set as this device’s current stream.

  • sync (bool) – If True, then stream will perform a device-side synchronization with the device’s previous current stream.

Return type:

None

property has_stream: bool[source]#

A boolean indicating whether the device has a stream associated with it.

property total_memory: int[source]#

The total amount of device memory available in bytes.

Querying memory information for the CPU device requires the psutil package to be installed and will return 0 otherwise.

property free_memory: int[source]#

The amount of memory on the device that is free according to the OS in bytes.

Querying memory information for the CPU device requires the psutil package to be installed and will return 0 otherwise.

make_current()[source]#
can_access(other)[source]#
get_cuda_output_format(preferred_cuda_output=None)[source]#

Determine the CUDA output format to use for this device.

This method is intended for internal use by Warp’s compilation system. External users should not need to call this method directly.

It determines whether to use PTX or CUBIN output based on device capabilities, caller preferences, and runtime constraints.

Parameters:

preferred_cuda_output (str | None) – Caller’s preferred format ("ptx", "cubin", or None). If None, falls back to global config or automatic determination.

Returns:

"ptx", "cubin", or None for CPU devices.

Return type:

The output format to use

get_cuda_compile_arch()[source]#

Get the CUDA architecture to use when compiling code for this device.

This method is intended for internal use by Warp’s compilation system. External users should not need to call this method directly.

Determines the appropriate compute capability version to use when compiling CUDA kernels for this device. The architecture depends on the device’s CUDA output format preference and available target architectures.

For PTX output format, uses the minimum of the device’s architecture and the configured PTX target architecture to ensure compatibility. For CUBIN output format, uses the device’s exact architecture.

Returns:

The compute capability version (e.g., 75 for sm_75) to use for compilation, or None for CPU devices which don’t use CUDA compilation.

Return type:

int | None