spdl.io.cuda_decoders¶
- cuda_decoders(device_config: CUDAConfig, *, frames_in_flight: int = 2, size_buckets: Sequence[tuple[int, int]] | None = None, max_memory_bytes: int | None = None, num_lanes: int | None = None) CudaDecoders[source]¶
Create a
CudaDecodersfor bulk decoding on one GPU.Construction is cheap: nothing is allocated until the object is entered as a context manager or the first clip is decoded.
Example
cfg = spdl.io.cuda_config( device_index=0, stream=torch.cuda.current_stream().cuda_stream, allocator=( torch.cuda.caching_allocator_alloc, torch.cuda.caching_allocator_delete, ), ) with spdl.io.cuda_decoders(cfg) as decoders: packets = spdl.io.demux_video(src, bsf="h264_mp4toannexb") buffer = decoders.decode(packets, pix_fmt="rgb") frames = torch.from_dlpack(buffer)
- Parameters:
device_config – The GPU, the consumer stream and the allocator. See
cuda_config(). Outputs are allocated on, and ordered on, the stream.frames_in_flight – How many decoded frames may wait to be copied out while the engine keeps decoding. Higher values hide the wait for each frame’s decoding; each costs one output surface per decoder (about 4 MB at 1080p).
size_buckets – Sizes
(width, height)new decoders are created at. A new decoder gets the smallest-area bucket covering the coded size of the stream (or the coded size, if no bucket does). Any decoder at least as large as a stream of the same codec, chroma format and bit depth decodes it after a reconfiguration that takes microseconds, so buckets only bound memory. Default: 1280x720, 1920x1088 and 3840x2160, in both orientations.max_memory_bytes – Cap on the estimated GPU memory held by idle decoders. The least recently used idle decoders beyond it are destroyed in the background.
Nonemeans no cap.num_lanes – Number of clips decoded concurrently, each on a worker thread. A clip never uses more than one engine, and a worker also spends time on the host per clip, so the default is twice the number of NVDEC engines of the device. Fewer lanes use less GPU memory; more help when clips are very short.
- Returns:
The decoders.
Added in version 0.10.0.