4
4
#include < torch/types.h>
5
5
#include < mutex>
6
6
7
- #include " src/torchcodec/_core/CudaDevice .h"
7
+ #include " src/torchcodec/_core/CudaDeviceInterface .h"
8
8
#include " src/torchcodec/_core/FFMPEGCommon.h"
9
9
#include " src/torchcodec/_core/SingleStreamDecoder.h"
10
10
@@ -16,9 +16,10 @@ extern "C" {
16
16
namespace facebook ::torchcodec {
17
17
namespace {
18
18
19
- bool g_cuda = registerDeviceInterface(
20
- torch::kCUDA ,
21
- [](const torch::Device& device) { return new CudaDevice (device); });
19
+ bool g_cuda =
20
+ registerDeviceInterface (torch::kCUDA , [](const torch::Device& device) {
21
+ return new CudaDeviceInterface (device);
22
+ });
22
23
23
24
// We reuse cuda contexts across VideoDeoder instances. This is because
24
25
// creating a cuda context is expensive. The cache mechanism is as follows:
@@ -163,20 +164,21 @@ AVBufferRef* getCudaContext(const torch::Device& device) {
163
164
}
164
165
} // namespace
165
166
166
- CudaDevice::CudaDevice (const torch::Device& device) : DeviceInterface(device) {
167
+ CudaDeviceInterface::CudaDeviceInterface (const torch::Device& device)
168
+ : DeviceInterface(device) {
167
169
if (device_.type () != torch::kCUDA ) {
168
170
throw std::runtime_error (" Unsupported device: " + device_.str ());
169
171
}
170
172
}
171
173
172
- CudaDevice ::~CudaDevice () {
174
+ CudaDeviceInterface ::~CudaDeviceInterface () {
173
175
if (ctx_) {
174
176
addToCacheIfCacheHasCapacity (device_, ctx_);
175
177
av_buffer_unref (&ctx_);
176
178
}
177
179
}
178
180
179
- void CudaDevice ::initializeContext (AVCodecContext* codecContext) {
181
+ void CudaDeviceInterface ::initializeContext (AVCodecContext* codecContext) {
180
182
TORCH_CHECK (!ctx_, " FFmpeg HW device context already initialized" );
181
183
182
184
// It is important for pytorch itself to create the cuda context. If ffmpeg
@@ -189,7 +191,7 @@ void CudaDevice::initializeContext(AVCodecContext* codecContext) {
189
191
return ;
190
192
}
191
193
192
- void CudaDevice ::convertAVFrameToFrameOutput (
194
+ void CudaDeviceInterface ::convertAVFrameToFrameOutput (
193
195
const VideoStreamOptions& videoStreamOptions,
194
196
UniqueAVFrame& avFrame,
195
197
FrameOutput& frameOutput,
@@ -263,7 +265,8 @@ void CudaDevice::convertAVFrameToFrameOutput(
263
265
// we have to do this because of an FFmpeg bug where hardware decoding is not
264
266
// appropriately set, so we just go off and find the matching codec for the CUDA
265
267
// device
266
- std::optional<const AVCodec*> CudaDevice::findCodec (const AVCodecID& codecId) {
268
+ std::optional<const AVCodec*> CudaDeviceInterface::findCodec (
269
+ const AVCodecID& codecId) {
267
270
void * i = nullptr ;
268
271
const AVCodec* codec = nullptr ;
269
272
while ((codec = av_codec_iterate (&i)) != nullptr ) {
0 commit comments