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.
- 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:
- arch#
The compute capability version number calculated as
10 * major + minor.0for CPU devices.- Type:
- is_cubin_supported#
Indicates whether Warp’s version of NVRTC can directly generate CUDA binary files (cubin) for this device’s architecture.
Falsefor CPU devices.- Type:
- is_mempool_supported#
Indicates whether the device supports using the
cuMemAllocAsyncandcuMemPoolfamily of APIs for stream-ordered memory allocations.Falsefor CPU devices.- Type:
- is_ipc_supported#
Indicates whether the device supports IPC.
Trueif supported.Falseif not supported.Noneif 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:
- uuid#
The UUID of the CUDA device. The UUID is in the same format used by
nvidia-smi -L.Nonefor CPU devices.- Type:
- pci_bus_id#
An identifier for the CUDA device in the format
[domain]:[bus]:[device], in whichdomain,bus, anddeviceare all hexadecimal values.Nonefor CPU devices.- Type:
Methods
__init__(runtime, alias[, ordinal, ...])can_access(other)get_allocator([pinned])Get the memory allocator for this device.
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.
set_stream(stream[, sync])Set the current stream for this CUDA device.
Attributes
The context associated with the device.
The amount of memory on the device that is free according to the OS in bytes.
A boolean indicating whether the device has a CUDA context associated with it.
A boolean indicating whether the device has a stream associated with it.
A boolean indicating whether this device's default stream is currently capturing a graph.
A boolean indicating whether the device is a CPU device.
A boolean indicating whether the device is a CUDA device.
The stream associated with a CUDA device.
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_capturing: bool[source]#
A boolean indicating whether this device’s default stream is currently capturing a graph.
- 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.ScopedStreaminstead.
- 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.
- 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", orNone). IfNone, falls back to global config or automatic determination.- Returns:
"ptx","cubin", orNonefor 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, orNonefor CPU devices which don’t use CUDA compilation.- Return type:
int | None