# tensorplay.cuda API Source: https://www.tensorplay.cn/docs/api/tensorplay.cuda.html ## Functions 58 [#](#api-tensorplay.cuda.caching_allocator_alloc) ### caching_allocator_alloc function[Full reference ↗](/docs/generated/tensorplay.cuda.caching_allocator_alloc.html) ```python tensorplay.cuda.caching_allocator_alloc(size, device: Any = None, stream=None) ``` Perform a memory allocation using the CUDA memory allocator. Not exposed by this TensorPlay build. [#](#api-tensorplay.cuda.caching_allocator_delete) ### caching_allocator_delete function[Full reference ↗](/docs/generated/tensorplay.cuda.caching_allocator_delete.html) ```python tensorplay.cuda.caching_allocator_delete(mem_ptr) ``` Delete memory allocated using the CUDA memory allocator. [#](#api-tensorplay.cuda.can_device_access_peer) ### can_device_access_peer function[Full reference ↗](/docs/generated/tensorplay.cuda.can_device_access_peer.html) ```python tensorplay.cuda.can_device_access_peer(device: Any, peer_device: Any) → bool ``` Check if peer access between two devices is possible. [#](#api-tensorplay.cuda.change_current_allocator) ### change_current_allocator function[Full reference ↗](/docs/generated/tensorplay.cuda.change_current_allocator.html) ```python tensorplay.cuda.change_current_allocator(alloc) ``` Change the currently used memory allocator (not supported by this build). [#](#api-tensorplay.cuda.check_error) ### check_error function[Full reference ↗](/docs/generated/tensorplay.cuda.check_error.html) ```python tensorplay.cuda.check_error(res: int) → None ``` Raise an error if the result of a CUDA runtime API call is not success. [#](#api-tensorplay.cuda.classproperty) ### classproperty function[Full reference ↗](/docs/generated/tensorplay.cuda.classproperty.html) ```python tensorplay.cuda.classproperty(func: Callable) → _ClassPropertyDescriptor ``` [#](#api-tensorplay.cuda.clock_rate) ### clock_rate function[Full reference ↗](/docs/generated/tensorplay.cuda.clock_rate.html) ```python tensorplay.cuda.clock_rate(device: Any = None) → int ``` Return the clock speed of the GPU SM in MHz (megahertz) over the past sample period as given by nvidia-smi. [#](#api-tensorplay.cuda.cudart) ### cudart function[Full reference ↗](/docs/generated/tensorplay.cuda.cudart.html) ```python tensorplay.cuda.cudart() ``` 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 [#](#api-tensorplay.cuda.current_blas_handle) ### current_blas_handle function[Full reference ↗](/docs/generated/tensorplay.cuda.current_blas_handle.html) ```python tensorplay.cuda.current_blas_handle() ``` Return cublasHandle_t pointer to current cuBLAS handle [#](#api-tensorplay.cuda.current_device) ### current_device function[Full reference ↗](/docs/generated/tensorplay.cuda.current_device.html) ```python tensorplay.cuda.current_device() → int ``` Return the index of a currently selected device. [#](#api-tensorplay.cuda.current_solver_handle) ### current_solver_handle function[Full reference ↗](/docs/generated/tensorplay.cuda.current_solver_handle.html) ```python tensorplay.cuda.current_solver_handle() ``` Return cusolverDnHandle_t pointer to current cuSOLVER handle [#](#api-tensorplay.cuda.current_stream) ### current_stream function[Full reference ↗](/docs/generated/tensorplay.cuda.current_stream.html) ```python tensorplay.cuda.current_stream(device: Any = None) → Stream ``` Return the currently selected Stream for a given device. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – selected device. Returns the currently selected Stream for the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). [#](#api-tensorplay.cuda.default_stream) ### default_stream function[Full reference ↗](/docs/generated/tensorplay.cuda.default_stream.html) ```python tensorplay.cuda.default_stream(device: Any = None) → Stream ``` Return the default Stream for a given device. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – selected device. Returns the default Stream for the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). [#](#api-tensorplay.cuda.device_count) ### device_count function[Full reference ↗](/docs/generated/tensorplay.cuda.device_count.html) ```python tensorplay.cuda.device_count() → int ``` Return the number of GPUs available. > **Note** > > This API will NOT poison fork if NVML discovery succeeds. [#](#api-tensorplay.cuda.device_memory_used) ### device_memory_used function[Full reference ↗](/docs/generated/tensorplay.cuda.device_memory_used.html) ```python tensorplay.cuda.device_memory_used(device: Any = None) → int ``` Return used global (device) memory in bytes as given by nvidia-smi. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – selected device. Returns statistic for the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). [#](#api-tensorplay.cuda.empty_cache) ### empty_cache function[Full reference ↗](/docs/generated/tensorplay.cuda.empty_cache.html) ```python tensorplay.cuda.empty_cache() → None ``` 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. [#](#api-tensorplay.cuda.get_allocator_backend) ### get_allocator_backend function[Full reference ↗](/docs/generated/tensorplay.cuda.get_allocator_backend.html) ```python tensorplay.cuda.get_allocator_backend() → str ``` Returns the active allocator backend as a string. Always native here. [#](#api-tensorplay.cuda.get_arch_list) ### get_arch_list function[Full reference ↗](/docs/generated/tensorplay.cuda.get_arch_list.html) ```python tensorplay.cuda.get_arch_list() → list[str] ``` Return list CUDA architectures this library was compiled for. [#](#api-tensorplay.cuda.get_device_capability) ### get_device_capability function[Full reference ↗](/docs/generated/tensorplay.cuda.get_device_capability.html) ```python tensorplay.cuda.get_device_capability(device: Any = None) → tuple[int, int] ``` Get the cuda capability of a device. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int) or [str](https://docs.python.org/3/builtins/stdtypes.html#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()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). Returns: the major and minor cuda capability of the device Return type: [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)([int](https://docs.python.org/3/builtins/functions.html#int), [int](https://docs.python.org/3/builtins/functions.html#int)) [#](#api-tensorplay.cuda.get_device_name) ### get_device_name function[Full reference ↗](/docs/generated/tensorplay.cuda.get_device_name.html) ```python tensorplay.cuda.get_device_name(device: Any = None) → str ``` Get the name of a device. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int) or [str](https://docs.python.org/3/builtins/stdtypes.html#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()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). Returns: the name of the device Return type: [str](https://docs.python.org/3/builtins/stdtypes.html#str) [#](#api-tensorplay.cuda.get_device_properties) ### get_device_properties function[Full reference ↗](/docs/generated/tensorplay.cuda.get_device_properties.html) ```python tensorplay.cuda.get_device_properties(device: Any = None) → _CudaDeviceProperties ``` Get the properties of a device. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int) or [str](https://docs.python.org/3/builtins/stdtypes.html#str), optional) – device for which to return the properties of the device. It uses the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). Returns: the properties of the device Return type: _CudaDeviceProperties [#](#api-tensorplay.cuda.get_gencode_flags) ### get_gencode_flags function[Full reference ↗](/docs/generated/tensorplay.cuda.get_gencode_flags.html) ```python tensorplay.cuda.get_gencode_flags() → str ``` Return NVCC gencode flags this library was compiled with. [#](#api-tensorplay.cuda.get_per_process_memory_fraction) ### get_per_process_memory_fraction function[Full reference ↗](/docs/generated/tensorplay.cuda.get_per_process_memory_fraction.html) ```python tensorplay.cuda.get_per_process_memory_fraction(device: Any = None) → float ``` Get memory fraction for a process. Always returns 1.0 in this build. [#](#api-tensorplay.cuda.get_stream_from_external) ### get_stream_from_external function[Full reference ↗](/docs/generated/tensorplay.cuda.get_stream_from_external.html) ```python tensorplay.cuda.get_stream_from_external(data_ptr: int, device: Any = None) → Stream ``` Return a Stream from an externally allocated CUDA stream. [#](#api-tensorplay.cuda.get_sync_debug_mode) ### get_sync_debug_mode function[Full reference ↗](/docs/generated/tensorplay.cuda.get_sync_debug_mode.html) ```python tensorplay.cuda.get_sync_debug_mode() → int ``` Return current value of debug mode for cuda synchronizing operations. Always returns 0 in this build (mode is not enforced). [#](#api-tensorplay.cuda.host_memory_stats_as_nested_dict) ### host_memory_stats_as_nested_dict function[Full reference ↗](/docs/generated/tensorplay.cuda.host_memory_stats_as_nested_dict.html) ```python tensorplay.cuda.host_memory_stats_as_nested_dict() → dict[str, Any] ``` Return the result of [host_memory_stats()](/docs/generated/tensorplay.cuda.host_memory_stats.html#tensorplay.cuda.host_memory_stats) as a nested dictionary. [#](#api-tensorplay.cuda.host_memory_stats) ### host_memory_stats function[Full reference ↗](/docs/generated/tensorplay.cuda.host_memory_stats.html) ```python tensorplay.cuda.host_memory_stats() → dict[str, Any] ``` Return a dictionary of pinned (host) allocator statistics. [#](#api-tensorplay.cuda.init) ### init function[Full reference ↗](/docs/generated/tensorplay.cuda.init.html) ```python tensorplay.cuda.init() ``` 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. [#](#api-tensorplay.cuda.ipc_collect) ### ipc_collect function[Full reference ↗](/docs/generated/tensorplay.cuda.ipc_collect.html) ```python tensorplay.cuda.ipc_collect() ``` Force collects GPU memory after it has been released by CUDA IPC. [#](#api-tensorplay.cuda.is_available) ### is_available function[Full reference ↗](/docs/generated/tensorplay.cuda.is_available.html) ```python tensorplay.cuda.is_available() → bool ``` 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. [#](#api-tensorplay.cuda.is_bf16_supported) ### is_bf16_supported function[Full reference ↗](/docs/generated/tensorplay.cuda.is_bf16_supported.html) ```python tensorplay.cuda.is_bf16_supported(including_emulation: bool = True) ``` Return a bool indicating if the current CUDA device supports dtype bfloat16. [#](#api-tensorplay.cuda.is_gds_available) ### is_gds_available function[Full reference ↗](/docs/generated/tensorplay.cuda.is_gds_available.html) ```python tensorplay.cuda.is_gds_available() → bool ``` Return whether GDS is available. Always False in this build. [#](#api-tensorplay.cuda.is_initialized) ### is_initialized function[Full reference ↗](/docs/generated/tensorplay.cuda.is_initialized.html) ```python tensorplay.cuda.is_initialized() ``` Return whether TensorPlay’s CUDA state has been initialized. [#](#api-tensorplay.cuda.is_tf32_supported) ### is_tf32_supported function[Full reference ↗](/docs/generated/tensorplay.cuda.is_tf32_supported.html) ```python tensorplay.cuda.is_tf32_supported() → bool ``` Return a bool indicating if the current CUDA device supports dtype tf32. [#](#api-tensorplay.cuda.list_gpu_processes) ### list_gpu_processes function[Full reference ↗](/docs/generated/tensorplay.cuda.list_gpu_processes.html) ```python tensorplay.cuda.list_gpu_processes(device: Any = None) → str ``` Return a human-readable printout of the running processes and their GPU memory use for a given device. [#](#api-tensorplay.cuda.max_memory_allocated) ### max_memory_allocated function[Full reference ↗](/docs/generated/tensorplay.cuda.max_memory_allocated.html) ```python tensorplay.cuda.max_memory_allocated(device: Any = None) → int ``` 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()](/docs/generated/tensorplay.cuda.reset_peak_memory_stats.html#tensorplay.cuda.reset_peak_memory_stats) can be used to reset the starting point in tracking this metric. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – selected device. Returns statistic for the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). [#](#api-tensorplay.cuda.max_memory_reserved) ### max_memory_reserved function[Full reference ↗](/docs/generated/tensorplay.cuda.max_memory_reserved.html) ```python tensorplay.cuda.max_memory_reserved(device: Any = None) → int ``` Return the maximum GPU memory managed by the caching allocator in bytes for a given device. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – selected device. Returns statistic for the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). [#](#api-tensorplay.cuda.mem_get_info) ### mem_get_info function[Full reference ↗](/docs/generated/tensorplay.cuda.mem_get_info.html) ```python tensorplay.cuda.mem_get_info(device: Any = None) → tuple[int, int] ``` Return the global free and total GPU memory for a given device using cudaMemGetInfo. [#](#api-tensorplay.cuda.memory_allocated) ### memory_allocated function[Full reference ↗](/docs/generated/tensorplay.cuda.memory_allocated.html) ```python tensorplay.cuda.memory_allocated(device: Any = None) → int ``` Return the current GPU memory occupied by tensors in bytes for a given device. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – selected device. Returns statistic for the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). [#](#api-tensorplay.cuda.memory_reserved) ### memory_reserved function[Full reference ↗](/docs/generated/tensorplay.cuda.memory_reserved.html) ```python tensorplay.cuda.memory_reserved(device: Any = None) → int ``` Return the current GPU memory managed by the caching allocator in bytes for a given device. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – selected device. Returns statistic for the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). [#](#api-tensorplay.cuda.memory_snapshot) ### memory_snapshot function[Full reference ↗](/docs/generated/tensorplay.cuda.memory_snapshot.html) ```python tensorplay.cuda.memory_snapshot(mempool_id=None, include_traces=True) ``` 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. [#](#api-tensorplay.cuda.memory_stats_as_nested_dict) ### memory_stats_as_nested_dict function[Full reference ↗](/docs/generated/tensorplay.cuda.memory_stats_as_nested_dict.html) ```python tensorplay.cuda.memory_stats_as_nested_dict(device: Any = None) → dict[str, Any] ``` Return the result of [memory_stats()](/docs/generated/tensorplay.cuda.memory_stats.html#tensorplay.cuda.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 [#](#api-tensorplay.cuda.memory_stats) ### memory_stats function[Full reference ↗](/docs/generated/tensorplay.cuda.memory_stats.html) ```python tensorplay.cuda.memory_stats(device: Any = None) → dict[str, Any] ``` 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](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – selected device. Returns statistics for the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). [#](#api-tensorplay.cuda.memory_summary) ### memory_summary function[Full reference ↗](/docs/generated/tensorplay.cuda.memory_summary.html) ```python tensorplay.cuda.memory_summary(device: Any = None, abbreviated: bool = False) → str ``` 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](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – selected device. Returns printout for the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). - abbreviated ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – whether to return an abbreviated summary (default: False). [#](#api-tensorplay.cuda.memory_usage) ### memory_usage function[Full reference ↗](/docs/generated/tensorplay.cuda.memory_usage.html) ```python tensorplay.cuda.memory_usage(device: Any = None) → int ``` 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. [#](#api-tensorplay.cuda.power_draw) ### power_draw function[Full reference ↗](/docs/generated/tensorplay.cuda.power_draw.html) ```python tensorplay.cuda.power_draw(device: Any = None) → int ``` 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. [#](#api-tensorplay.cuda.reset_accumulated_host_memory_stats) ### reset_accumulated_host_memory_stats function[Full reference ↗](/docs/generated/tensorplay.cuda.reset_accumulated_host_memory_stats.html) ```python tensorplay.cuda.reset_accumulated_host_memory_stats() → None ``` Reset the “accumulated” (historical) stats tracked by the host memory allocator. [#](#api-tensorplay.cuda.reset_accumulated_memory_stats) ### reset_accumulated_memory_stats function[Full reference ↗](/docs/generated/tensorplay.cuda.reset_accumulated_memory_stats.html) ```python tensorplay.cuda.reset_accumulated_memory_stats(device: Any = None) → None ``` 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. [#](#api-tensorplay.cuda.reset_peak_host_memory_stats) ### reset_peak_host_memory_stats function[Full reference ↗](/docs/generated/tensorplay.cuda.reset_peak_host_memory_stats.html) ```python tensorplay.cuda.reset_peak_host_memory_stats() → None ``` Reset the “peak” stats tracked by the host memory allocator. [#](#api-tensorplay.cuda.reset_peak_memory_stats) ### reset_peak_memory_stats function[Full reference ↗](/docs/generated/tensorplay.cuda.reset_peak_memory_stats.html) ```python tensorplay.cuda.reset_peak_memory_stats(device: Any = None) → None ``` 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](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – selected device. Returns statistic for the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). [#](#api-tensorplay.cuda.set_device) ### set_device function[Full reference ↗](/docs/generated/tensorplay.cuda.set_device.html) ```python tensorplay.cuda.set_device(device: Any) → None ``` Set the current device. Usage of this function is discouraged in favor of [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device). In most cases it’s better to use CUDA_VISIBLE_DEVICES environmental variable. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int)) – selected device. This function is a no-op if this argument is negative. [#](#api-tensorplay.cuda.set_per_process_memory_fraction) ### set_per_process_memory_fraction function[Full reference ↗](/docs/generated/tensorplay.cuda.set_per_process_memory_fraction.html) ```python tensorplay.cuda.set_per_process_memory_fraction(fraction, device: Any = None) → None ``` Set memory fraction for a process. Not enforced by this TensorPlay build; the signature is retained for API compatibility. Parameters: - fraction ([float](https://docs.python.org/3/builtins/functions.html#float)) – Range: 0~1. Allowed memory equals total_memory * fraction. - device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – selected device. [#](#api-tensorplay.cuda.set_stream) ### set_stream function[Full reference ↗](/docs/generated/tensorplay.cuda.set_stream.html) ```python tensorplay.cuda.set_stream(stream: Stream) ``` 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](/docs/generated/tensorplay.cuda.streams.Stream.html#tensorplay.cuda.streams.Stream)) – selected stream. This function is a no-op if this argument is None. [#](#api-tensorplay.cuda.set_sync_debug_mode) ### set_sync_debug_mode function[Full reference ↗](/docs/generated/tensorplay.cuda.set_sync_debug_mode.html) ```python tensorplay.cuda.set_sync_debug_mode(debug_mode: int | str) → None ``` 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](https://docs.python.org/3/builtins/stdtypes.html#str) or [int](https://docs.python.org/3/builtins/functions.html#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. [#](#api-tensorplay.cuda.stream) ### stream function[Full reference ↗](/docs/generated/tensorplay.cuda.stream.html) ```python tensorplay.cuda.stream(stream_: Stream | None) → StreamContext ``` Wrap around the Context-manager StreamContext that selects a given stream. Parameters: stream ([Stream](/docs/generated/tensorplay.cuda.streams.Stream.html#tensorplay.cuda.streams.Stream)) – selected stream. This manager is a no-op if it’s None. > **Note** > > Streams are per-device. [#](#api-tensorplay.cuda.synchronize) ### synchronize function[Full reference ↗](/docs/generated/tensorplay.cuda.synchronize.html) ```python tensorplay.cuda.synchronize(device: Any = None) → None ``` Wait for all kernels in all streams on a CUDA device to complete. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – device for which to synchronize. It uses the current device, given by [current_device()](/docs/generated/tensorplay.cuda.current_device.html#tensorplay.cuda.current_device), if [device](/docs/generated/tensorplay.cuda.device.html#tensorplay.cuda.device) is None (default). [#](#api-tensorplay.cuda.temperature) ### temperature function[Full reference ↗](/docs/generated/tensorplay.cuda.temperature.html) ```python tensorplay.cuda.temperature(device: Any = None) → int ``` 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. [#](#api-tensorplay.cuda.utilization) ### utilization function[Full reference ↗](/docs/generated/tensorplay.cuda.utilization.html) ```python tensorplay.cuda.utilization(device: Any = None) → int ``` 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 5 [#](#api-tensorplay.cuda.CUDAPluggableAllocator) ### CUDAPluggableAllocator class[Full reference ↗](/docs/generated/tensorplay.cuda.CUDAPluggableAllocator.html) ```python class tensorplay.cuda.CUDAPluggableAllocator(so_file: str, alloc_fn_name: str = 'my_alloc', free_fn_name: str = 'my_free') ``` CUDA memory allocator plugin (not supported by this TensorPlay build). [#](#api-tensorplay.cuda.device_of) ### device_of class[Full reference ↗](/docs/generated/tensorplay.cuda.device_of.html) ```python class tensorplay.cuda.device_of(obj) ``` 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Storage) – object allocated on the selected device. [#](#api-tensorplay.cuda.device) ### device class[Full reference ↗](/docs/generated/tensorplay.cuda.device.html) ```python class tensorplay.cuda.device(device: Any) ``` Context-manager that changes the selected device. Parameters: device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int)) – device index to select. It’s a no-op if this argument is a negative integer or None. [#](#api-tensorplay.cuda.MemPool) ### MemPool class[Full reference ↗](/docs/generated/tensorplay.cuda.MemPool.html) ```python class tensorplay.cuda.MemPool(*args, **kwargs) ``` MemPool context (not supported by this TensorPlay build). [#](#api-tensorplay.cuda.StreamContext) ### StreamContext class[Full reference ↗](/docs/generated/tensorplay.cuda.StreamContext.html) ```python class tensorplay.cuda.StreamContext(stream: Stream | None) ``` Context-manager that selects a given stream. All CUDA kernels queued within its context will be enqueued on a selected stream. Parameters: Stream ([Stream](/docs/generated/tensorplay.cuda.streams.Stream.html#tensorplay.cuda.streams.Stream)) – selected stream. This manager is a no-op if it’s None. > **Note** > > Streams are per-device. ## Exceptions 4 [#](#api-tensorplay.cuda.AcceleratorError) ### AcceleratorError exception[Full reference ↗](/docs/generated/tensorplay.cuda.AcceleratorError.html) ```python exception tensorplay.cuda.AcceleratorError ``` [#](#api-tensorplay.cuda.CudaError) ### CudaError exception[Full reference ↗](/docs/generated/tensorplay.cuda.CudaError.html) ```python exception tensorplay.cuda.CudaError(code: int) ``` [#](#api-tensorplay.cuda.DeferredCudaCallError) ### DeferredCudaCallError exception[Full reference ↗](/docs/generated/tensorplay.cuda.DeferredCudaCallError.html) ```python exception tensorplay.cuda.DeferredCudaCallError ``` [#](#api-tensorplay.cuda.OutOfMemoryError) ### OutOfMemoryError exception[Full reference ↗](/docs/generated/tensorplay.cuda.OutOfMemoryError.html) ```python exception tensorplay.cuda.OutOfMemoryError ```