meta-pytorch / meta-pytorch/torchcodec

Potential perf improvements to the BETA CUDA interface

Open
#944 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.2k
Forks
125
Avg merge
22h 47m
Merged PRs (30d)
54

Description

Opening this mostly for my own sake, for future reference

Cache improvements

I haven't put too much thoughts in our existing cache and mostly tried for it to be safe. Maybe we can make it smarter to increase cache hits. For example, right now we expect an exact match in stream resolution - maybe a decoder can still be re-used for a stream whose resolution is strictly smaller?

I think this is slightly related to decoder re-configuration:

Decoder re-configuration

The NVDEC docs mention we could re-configure an existing decoder in some cases, typically when a "sequence change" occurs (stream resolution change).

DALI has some code-path for that too.

We cache the decoders, while the docs assume a new decoder would be instantiated from scratch, so maybe that's not needed.

CUDA Streams

We currently hard-code both the NVDEC stream and the NPP stream (for color-conversion) to be the current stream (as, e.g., specified by a context manager). Maybe... those could be different?

Threaded implementation
  • NVDEC docs mention the synchronous “mapping” stage could be done in a separate thread.

  • In this section they mention there could actually be 3 threads: 1 for demuxing (FFmpeg), 1 for decoding, one for mapping.

This shouldn’t be too hard to implement, but out of scope for now, and we should factor-in the maintenance cost of having to manage thread pools. It's also unclear to me whether this would make any difference when the user is already spawning N threads, each with its own VideoDecoder() instead. It's possible we're already maxing out NVDEC there, and if that's the case the benefits of a threaded implementation would be minimal.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/torchcodec/_core/BetaCudaDeviceInterface.cpp around lines 490-491 and src/torchcodec/_core/CUDACommon.cpp around lines 170-171, then read the linked NVDEC documentation. Investigate decoder caching, reconfiguration, CUDA streams, and the proposed threaded implementation. The issue has no single defined scope or acceptance criteria, so a concrete improvement and measurable completion condition would need to be established first.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.