TensorPlay

Latest development documentation · Updated 2026-09-08. A documentation snapshot for package 1.0.0.dev20260909 is not available.

On this page

Functions 58

#

caching_allocator_alloc

functionFull reference ↗
tensorplay.cuda.caching_allocator_alloc(size, device: Any = None, stream=None)[source]

Perform a memory allocation using the CUDA memory allocator.

Not exposed by this TensorPlay build.

#

caching_allocator_delete

functionFull reference ↗
tensorplay.cuda.caching_allocator_delete(mem_ptr)[source]

Delete memory allocated using the CUDA memory allocator.

#

can_device_access_peer

functionFull reference ↗
tensorplay.cuda.can_device_access_peer(device: Any, peer_device: Any) bool[source]

Check if peer access between two devices is possible.

#

change_current_allocator

functionFull reference ↗
tensorplay.cuda.change_current_allocator(alloc)[source]

Change the currently used memory allocator (not supported by this build).

#

clock_rate

functionFull reference ↗
tensorplay.cuda.clock_rate(device: Any = None) int[source]

Return the clock speed of the GPU SM in MHz (megahertz) over the past sample period as given by nvidia-smi.

#

cudart

functionFull reference ↗
tensorplay.cuda.cudart()[source]

Retrieves the CUDA runtime API module.

This function initializes the CUDA runtime environment if it is not already initialized and returns the CUDA runtime API module (_cudart).

Returns:

The CUDA runtime API module, or None when no ctypes runtime binding is exposed by this build.

Return type:

module or None

#

current_blas_handle

functionFull reference ↗
tensorplay.cuda.current_blas_handle()[source]

Return cublasHandle_t pointer to current cuBLAS handle

#

current_solver_handle

functionFull reference ↗
tensorplay.cuda.current_solver_handle()[source]

Return cusolverDnHandle_t pointer to current cuSOLVER handle

#

device_count

functionFull reference ↗
tensorplay.cuda.device_count() int[source]

Return the number of GPUs available.

Note

This API will NOT poison fork if NVML discovery succeeds.

#

empty_cache

functionFull reference ↗
tensorplay.cuda.empty_cache() None[source]

Release all unoccupied cached memory currently held by the caching allocator so that those can be used in other GPU application and visible in nvidia-smi.

Note

empty_cache() doesn’t increase the amount of GPU memory available for TensorPlay. However, it may help reduce fragmentation of GPU memory in certain cases.

#

get_allocator_backend

functionFull reference ↗
tensorplay.cuda.get_allocator_backend() str[source]

Returns the active allocator backend as a string. Always native here.

#

get_device_capability

functionFull reference ↗
tensorplay.cuda.get_device_capability(device: Any = None) tuple[int, int][source]

Get the cuda capability of a device.

Parameters:

device (tensorplay.Device or int or str, optional) – device for which to return the device capability. This function is a no-op if this argument is a negative integer. It uses the current device, given by current_device(), if device is None (default).

Returns:

the major and minor cuda capability of the device

Return type:

tuple(int, int)

#

get_device_name

functionFull reference ↗
tensorplay.cuda.get_device_name(device: Any = None) str[source]

Get the name of a device.

Parameters:

device (tensorplay.Device or int or str, optional) – device for which to return the name. This function is a no-op if this argument is a negative integer. It uses the current device, given by current_device(), if device is None (default).

Returns:

the name of the device

Return type:

str

#

get_device_properties

functionFull reference ↗
tensorplay.cuda.get_device_properties(device: Any = None) _CudaDeviceProperties[source]

Get the properties of a device.

Parameters:

device (tensorplay.Device or int or str, optional) – device for which to return the properties of the device. It uses the current device, given by current_device(), if device is None (default).

Returns:

the properties of the device

Return type:

_CudaDeviceProperties

#

get_gencode_flags

functionFull reference ↗
tensorplay.cuda.get_gencode_flags() str[source]

Return NVCC gencode flags this library was compiled with.

#

get_per_process_memory_fraction

functionFull reference ↗
tensorplay.cuda.get_per_process_memory_fraction(device: Any = None) float[source]

Get memory fraction for a process. Always returns 1.0 in this build.

#

get_stream_from_external

functionFull reference ↗
tensorplay.cuda.get_stream_from_external(data_ptr: int, device: Any = None) Stream[source]

Return a Stream from an externally allocated CUDA stream.

#

get_sync_debug_mode

functionFull reference ↗
tensorplay.cuda.get_sync_debug_mode() int[source]

Return current value of debug mode for cuda synchronizing operations.

Always returns 0 in this build (mode is not enforced).

#

init

functionFull reference ↗
tensorplay.cuda.init()[source]

Initialize TensorPlay’s CUDA state.

You may need to call this explicitly if you are interacting with TensorPlay via its C API, as Python bindings for CUDA functionality will not be available until this initialization takes place. Ordinary users should not need this, as all of TensorPlay’s CUDA methods automatically initialize CUDA state on-demand.

Does nothing if the CUDA state is already initialized.

#

ipc_collect

functionFull reference ↗
tensorplay.cuda.ipc_collect()[source]

Force collects GPU memory after it has been released by CUDA IPC.

#

is_available

functionFull reference ↗
tensorplay.cuda.is_available() bool[source]

Return a bool indicating if CUDA is currently available.

Note

This function will NOT poison fork if the environment variable TENSORPLAY_NVML_BASED_CUDA_CHECK=1 is set.

#

is_bf16_supported

functionFull reference ↗
tensorplay.cuda.is_bf16_supported(including_emulation: bool = True)[source]

Return a bool indicating if the current CUDA device supports dtype bfloat16.

#

is_gds_available

functionFull reference ↗
tensorplay.cuda.is_gds_available() bool[source]

Return whether GDS is available. Always False in this build.

#

is_initialized

functionFull reference ↗
tensorplay.cuda.is_initialized()[source]

Return whether TensorPlay’s CUDA state has been initialized.

#

is_tf32_supported

functionFull reference ↗
tensorplay.cuda.is_tf32_supported() bool[source]

Return a bool indicating if the current CUDA device supports dtype tf32.

#

list_gpu_processes

functionFull reference ↗
tensorplay.cuda.list_gpu_processes(device: Any = None) str[source]

Return a human-readable printout of the running processes and their GPU memory use for a given device.

#

max_memory_allocated

functionFull reference ↗
tensorplay.cuda.max_memory_allocated(device: Any = None) int[source]

Return the maximum GPU memory occupied by tensors in bytes for a given device.

By default, this returns the peak allocated memory since the beginning of this program. reset_peak_memory_stats() can be used to reset the starting point in tracking this metric.

Parameters:

device (tensorplay.Device or int, optional) – selected device. Returns statistic for the current device, given by current_device(), if device is None (default).

#

max_memory_reserved

functionFull reference ↗
tensorplay.cuda.max_memory_reserved(device: Any = None) int[source]

Return the maximum GPU memory managed by the caching allocator in bytes for a given device.

Parameters:

device (tensorplay.Device or int, optional) – selected device. Returns statistic for the current device, given by current_device(), if device is None (default).

#

memory_reserved

functionFull reference ↗
tensorplay.cuda.memory_reserved(device: Any = None) int[source]

Return the current GPU memory managed by the caching allocator in bytes for a given device.

Parameters:

device (tensorplay.Device or int, optional) – selected device. Returns statistic for the current device, given by current_device(), if device is None (default).

#

memory_snapshot

functionFull reference ↗
tensorplay.cuda.memory_snapshot(mempool_id=None, include_traces=True)[source]

Return a snapshot of the CUDA memory allocator state across all devices.

Interpreting the output of this function requires familiarity with the memory allocator internals. Not exposed by this TensorPlay build.

#

memory_stats_as_nested_dict

functionFull reference ↗
tensorplay.cuda.memory_stats_as_nested_dict(device: Any = None) dict[str, Any][source]

Return the result of memory_stats() as a nested dictionary.

The native allocator reports the fragmentation-aware matrix directly (segments, free-block histogram, pending cross-stream blocks, graph pools, capture state); it is exposed under "allocator" alongside the

#

memory_stats

functionFull reference ↗
tensorplay.cuda.memory_stats(device: Any = None) dict[str, Any][source]

Return a dictionary of CUDA memory allocator statistics for a given device.

The return value of this function is a dictionary of statistics, each of the full key layout; keys that are not tracked by this TensorPlay build are always reported as zero.

Parameters:

device (tensorplay.Device or int, optional) – selected device. Returns statistics for the current device, given by current_device(), if device is None (default).

#

memory_summary

functionFull reference ↗
tensorplay.cuda.memory_summary(device: Any = None, abbreviated: bool = False) str[source]

Return a human-readable printout of the current memory allocator statistics for a given device.

This can be useful to display periodically during training, or when handling out-of-memory exceptions.

Parameters:
  • device (tensorplay.Device or int, optional) – selected device. Returns printout for the current device, given by current_device(), if device is None (default).

  • abbreviated (bool, optional) – whether to return an abbreviated summary (default: False).

#

memory_usage

functionFull reference ↗
tensorplay.cuda.memory_usage(device: Any = None) int[source]

Return the percent of time over the past sample period during which global (device) memory was being read or written as given by nvidia-smi.

Warning: Each sample period may be between 1 second and 1/6 second, depending on the product being queried.

#

power_draw

functionFull reference ↗
tensorplay.cuda.power_draw(device: Any = None) int[source]

Return the average power draw of the GPU sensor in mW (MilliWatts) over the past sample period as given by nvidia-smi for Fermi or newer fully supported devices.

#

reset_accumulated_host_memory_stats

functionFull reference ↗
tensorplay.cuda.reset_accumulated_host_memory_stats() None[source]

Reset the “accumulated” (historical) stats tracked by the host memory allocator.

#

reset_accumulated_memory_stats

functionFull reference ↗
tensorplay.cuda.reset_accumulated_memory_stats(device: Any = None) None[source]

Reset the “accumulated” (historical) stats tracked by the CUDA memory allocator.

This TensorPlay build does not track historical totals; the call is a no-op.

#

reset_peak_host_memory_stats

functionFull reference ↗
tensorplay.cuda.reset_peak_host_memory_stats() None[source]

Reset the “peak” stats tracked by the host memory allocator.

#

reset_peak_memory_stats

functionFull reference ↗
tensorplay.cuda.reset_peak_memory_stats(device: Any = None) None[source]

Reset the “peak” stats tracked by the CUDA memory allocator.

Peak stats correspond to the “peak” key in each individual stat dict.

Parameters:

device (tensorplay.Device or int, optional) – selected device. Returns statistic for the current device, given by current_device(), if device is None (default).

#

set_device

functionFull reference ↗
tensorplay.cuda.set_device(device: Any) None[source]

Set the current device.

Usage of this function is discouraged in favor of device. In most cases it’s better to use CUDA_VISIBLE_DEVICES environmental variable.

Parameters:

device (tensorplay.Device or int) – selected device. This function is a no-op if this argument is negative.

#

set_per_process_memory_fraction

functionFull reference ↗
tensorplay.cuda.set_per_process_memory_fraction(fraction, device: Any = None) None[source]

Set memory fraction for a process.

Not enforced by this TensorPlay build; the signature is retained for API compatibility.

Parameters:
  • fraction (float) – Range: 0~1. Allowed memory equals total_memory * fraction.

  • device (tensorplay.Device or int, optional) – selected device.

#

set_stream

functionFull reference ↗
tensorplay.cuda.set_stream(stream: Stream)[source]
Set the current stream. This is a wrapper API to set the stream.

Usage of this function is discouraged in favor of the stream context manager.

Parameters:

stream (Stream) – selected stream. This function is a no-op if this argument is None.

#

set_sync_debug_mode

functionFull reference ↗
tensorplay.cuda.set_sync_debug_mode(debug_mode: int | str) None[source]

Set the debug mode for cuda synchronizing operations.

Not enforced by this TensorPlay build; the signature is retained for API compatibility.

Parameters:

debug_mode (str or int) – if “default” or 0, don’t error or warn on synchronizing operations, if “warn” or 1, warn on synchronizing operations, if “error” or 2, error out synchronizing operations.

#

stream

functionFull reference ↗
tensorplay.cuda.stream(stream_: Stream | None) StreamContext[source]

Wrap around the Context-manager StreamContext that selects a given stream.

Parameters:

stream (Stream) – selected stream. This manager is a no-op if it’s None.

Note

Streams are per-device.

#

temperature

functionFull reference ↗
tensorplay.cuda.temperature(device: Any = None) int[source]

Return the average temperature of the GPU sensor in Degrees C (Centigrades).

The average temperature is computed based on past sample period as given by nvidia-smi.

#

utilization

functionFull reference ↗
tensorplay.cuda.utilization(device: Any = None) int[source]

Return the percent of time over the past sample period during which one or more kernels was executing on the GPU as given by nvidia-smi.

Warning: Each sample period may be between 1 second and 1/6 second, depending on the product being queried.

Classes 6

#

CUDAPluggableAllocator

classFull reference ↗
class tensorplay.cuda.CUDAPluggableAllocator(so_file: str, alloc_fn_name: str = 'my_alloc', free_fn_name: str = 'my_free')[source]

CUDA memory allocator plugin (not supported by this TensorPlay build).

#

device_of

classFull reference ↗
class tensorplay.cuda.device_of(obj)[source]

Context-manager that changes the current device to that of given object.

You can use both tensors and storages as arguments. If a given object is not allocated on a GPU, this is a no-op.

Parameters:

obj (Tensor or Storage) – object allocated on the selected device.

#

device

classFull reference ↗
class tensorplay.cuda.device(device: Any)[source]

Context-manager that changes the selected device.

Parameters:

device (tensorplay.Device or int) – device index to select. It’s a no-op if this argument is a negative integer or None.

#

Device

classFull reference ↗
class tensorplay.cuda.Device
is_cpu(self: tensorplay._C.Device) bool
is_cuda(self: tensorplay._C.Device) bool
is_vulkan(self: tensorplay._C.Device) bool
#

MemPool

classFull reference ↗
class tensorplay.cuda.MemPool(*args, **kwargs)[source]

MemPool context (not supported by this TensorPlay build).

#

StreamContext

classFull reference ↗
class tensorplay.cuda.StreamContext(stream: Stream | None)[source]

Context-manager that selects a given stream.

All CUDA kernels queued within its context will be enqueued on a selected stream.

Parameters:

Stream (Stream) – selected stream. This manager is a no-op if it’s None.

Note

Streams are per-device.

Exceptions 4

Search documentation

Search all 1,743 documentation pages.

Keyboard shortcuts

Global

  • /Focus search
  • ?This dialog
  • ,Open settings
  • jAI assistant

Search

  • Navigate results
  • Open result
  • escClose

Package

  • mMain information
  • dDocs
  • .Code
  • -Changelog
  • tTimeline
  • sStats
  • vVersions