-
Notifications
You must be signed in to change notification settings - Fork 31
Make device interface generic #606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Caught by macos ci:
Plus there is a conflict with recent commits in |
58b55e3
to
89df863
Compare
@@ -138,7 +140,7 @@ class VideoDecoder { | |||
std::optional<int> height; | |||
std::optional<ColorConversionLibrary> colorConversionLibrary; | |||
// By default we use CPU for decoding for both C++ and python users. | |||
torch::Device device = torch::kCPU; | |||
std::shared_ptr<DeviceInterface> device; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DeviceInterface
object should be a required member of VideoDecoder
. It should also be a unique_ptr
, as the VideoDecoder
should be the only owner. At VideoDecoder
construction, it will be empty, and it will only take on a value after we've added a stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some video clips might contain multiple video streams (multiple audio streams, subtitles, etc.). As of now DeviceInterface
is associated with a single stream and allows to potentially process different streams on different accelerators. Did you consider to support such scenario in the future? /We still can handle that even we will move DeviceInterface
to VideoDecoder
storing it in a vector or map indexed by streams. That is design decision to make./
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current C++ decoder was originally implemented to support decoding from multiple streams at once, hence why we have methods for adding a stream and tracking info per-stream. But, that functionality never actually worked correctly. Getting it to work correctly would have required a lot more changes and testing, and we only expose single-stream decoding in our public API. So we instead decided to just make it explicit: the C++ decoder only works on one stream at a time. That's more explicit now in the new name.
We actually have a TODO to move some of the current fields of StreamInfo
into SingleStreamDecoder
itself for this reason. The device interface is another field that belongs in SingleStreamDecoder
itself rather than in StreamInfo
. In general, we're trying to keep the code as simple as possible, which means not keeping things around that we "might need" in the future. If we need it in the future, we'll implement it then. And if we want to implement mulistream decoding, we may end up implementing an entirely new C++ class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dvrogozh, this is great progress! I'd also like to see all of the VideoDecoder::*OnCPU()
functions moved into a CpuDevice
class. A bunch of the initialize and release member functions will be no-ops, and that's fine. That way it's clear what is device-agnostic code and what is device-specific code. I think that will also clean-up the dispatch logic inside of VideoDecoder
.
@scotts : I thought to do that in a follow up PR. Do you want me to do that in a single shot now? |
5643d10
to
433d0da
Compare
Fixes: pytorch#605 Changes: * Device interface made device agnostic by intorducing `class DeviceInterface` from which specific backends should inherit their device specific implementations * Implemented `CudaDevice` derived from `DeviceInterface` * Created device interface registration mechanism (`registerDeviceInterface`) * Created device interface creation mechanism (`createDeviceInterface`) These changes allow to replace CUDA specific code in `VideoDecoder.cpp` and `VideoDecoderOps.cpp` by device agnostic code. Signed-off-by: Dmitry Rogozhkin <[email protected]>
433d0da
to
a0d3d59
Compare
@scotts : can you, please, review again? |
@dvrogozh, this is looking great! Let's make that one change to where the device lives, and also figure out why the C++ tests are failing. |
Signed-off-by: Dmitry Rogozhkin <[email protected]>
Also: making a proper CPU device is fine for a follow-up PR, there's a bunch of changes already in this one, and it's self-consistent. |
Signed-off-by: Dmitry Rogozhkin <[email protected]>
Signed-off-by: Dmitry Rogozhkin <[email protected]>
Signed-off-by: Dmitry Rogozhkin <[email protected]>
a0d3d59
to
79c84c6
Compare
@scotts : done
@scotts : C++ tests were failing with quite cryptic manner. See error above. I've fixed it by including I think we can consider to extract |
@@ -493,6 +492,7 @@ class SingleStreamDecoder { | |||
SeekMode seekMode_; | |||
ContainerMetadata containerMetadata_; | |||
UniqueDecodingAVFormatContext formatContext_; | |||
std::unique_ptr<DeviceInterface> deviceInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class variable members end with an underscore (foo_
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I overlooked moving it from the struct. Will fix in a follow up PR.
Agreed on moving This looks great, thanks for making TorchCodec more general for devices! |
@dvrogozh, I'm merging as-is, you can address the class member name in the follow-up PRs. |
Filed to track:
Filed to track: |
|
||
namespace facebook::torchcodec { | ||
|
||
class CudaDevice : public DeviceInterface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The term "device" should be reserved for the concept of pytorch device object. Here, the CudaDevice
class name is misleading because it doesn't refer to a device, it refers to a device interface. @dvrogozh , do you mind submitting a PR to rename CudaDevice into CudaDeviceInterface
(file names and file classes)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NicolasHug : no problem, will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NicolasHug : filed #626
Renaming as requested in: * pytorch#606 (comment) Signed-off-by: Dmitry Rogozhkin <[email protected]>
…ec][diff_train] Make device interface generic (pytorch#606)" for one test failure Summary: This diff reverts D72722867 D72475332: [torchcodec][diff_train] Make device interface generic (pytorch#606) by generatedunixname499836121 causes the following test failure: Tests affected: - [cogwheel:cogwheel_fblearner_inferno_hello_world#main](https://www.internalfb.com/intern/test/844425115815788/) Here's the Multisect link: https://www.internalfb.com/multisect/25810176 Here are the tasks that are relevant to this breakage: T191383700: 100+ tests, 10+ build rules, some CI signals unhealthy for offline_inference The backout may land if someone accepts it. If this diff has been generated in error, you can Commandeer and Abandon it. Reviewed By: scotts Differential Revision: D72775487
Fixes: #605
Changes:
class DeviceInterface
from which specific backends should inherit their device specific implementationsCudaDevice
derived fromDeviceInterface
registerDeviceInterface
)createDeviceInterface
)These changes allow to replace CUDA specific code in
VideoDecoder.cpp
andVideoDecoderOps.cpp
by device agnostic code.CC: @scotts, @NicolasHug