Skip to content

Commit 44bef81

Browse files
authored
Rename CudaDevice to CudaDeviceInterface (#626)
Signed-off-by: Dmitry Rogozhkin <[email protected]>
1 parent b6dd961 commit 44bef81

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/torchcodec/_core/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function(make_torchcodec_libraries
6868
)
6969

7070
if(ENABLE_CUDA)
71-
list(APPEND decoder_sources CudaDevice.cpp)
71+
list(APPEND decoder_sources CudaDeviceInterface.cpp)
7272
endif()
7373

7474
set(decoder_library_dependencies

src/torchcodec/_core/CudaDevice.cpp renamed to src/torchcodec/_core/CudaDeviceInterface.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <torch/types.h>
55
#include <mutex>
66

7-
#include "src/torchcodec/_core/CudaDevice.h"
7+
#include "src/torchcodec/_core/CudaDeviceInterface.h"
88
#include "src/torchcodec/_core/FFMPEGCommon.h"
99
#include "src/torchcodec/_core/SingleStreamDecoder.h"
1010

@@ -16,9 +16,10 @@ extern "C" {
1616
namespace facebook::torchcodec {
1717
namespace {
1818

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+
});
2223

2324
// We reuse cuda contexts across VideoDeoder instances. This is because
2425
// creating a cuda context is expensive. The cache mechanism is as follows:
@@ -163,20 +164,21 @@ AVBufferRef* getCudaContext(const torch::Device& device) {
163164
}
164165
} // namespace
165166

166-
CudaDevice::CudaDevice(const torch::Device& device) : DeviceInterface(device) {
167+
CudaDeviceInterface::CudaDeviceInterface(const torch::Device& device)
168+
: DeviceInterface(device) {
167169
if (device_.type() != torch::kCUDA) {
168170
throw std::runtime_error("Unsupported device: " + device_.str());
169171
}
170172
}
171173

172-
CudaDevice::~CudaDevice() {
174+
CudaDeviceInterface::~CudaDeviceInterface() {
173175
if (ctx_) {
174176
addToCacheIfCacheHasCapacity(device_, ctx_);
175177
av_buffer_unref(&ctx_);
176178
}
177179
}
178180

179-
void CudaDevice::initializeContext(AVCodecContext* codecContext) {
181+
void CudaDeviceInterface::initializeContext(AVCodecContext* codecContext) {
180182
TORCH_CHECK(!ctx_, "FFmpeg HW device context already initialized");
181183

182184
// It is important for pytorch itself to create the cuda context. If ffmpeg
@@ -189,7 +191,7 @@ void CudaDevice::initializeContext(AVCodecContext* codecContext) {
189191
return;
190192
}
191193

192-
void CudaDevice::convertAVFrameToFrameOutput(
194+
void CudaDeviceInterface::convertAVFrameToFrameOutput(
193195
const VideoStreamOptions& videoStreamOptions,
194196
UniqueAVFrame& avFrame,
195197
FrameOutput& frameOutput,
@@ -263,7 +265,8 @@ void CudaDevice::convertAVFrameToFrameOutput(
263265
// we have to do this because of an FFmpeg bug where hardware decoding is not
264266
// appropriately set, so we just go off and find the matching codec for the CUDA
265267
// device
266-
std::optional<const AVCodec*> CudaDevice::findCodec(const AVCodecID& codecId) {
268+
std::optional<const AVCodec*> CudaDeviceInterface::findCodec(
269+
const AVCodecID& codecId) {
267270
void* i = nullptr;
268271
const AVCodec* codec = nullptr;
269272
while ((codec = av_codec_iterate(&i)) != nullptr) {

src/torchcodec/_core/CudaDevice.h renamed to src/torchcodec/_core/CudaDeviceInterface.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
namespace facebook::torchcodec {
1212

13-
class CudaDevice : public DeviceInterface {
13+
class CudaDeviceInterface : public DeviceInterface {
1414
public:
15-
CudaDevice(const torch::Device& device);
15+
CudaDeviceInterface(const torch::Device& device);
1616

17-
virtual ~CudaDevice();
17+
virtual ~CudaDeviceInterface();
1818

1919
std::optional<const AVCodec*> findCodec(const AVCodecID& codecId) override;
2020

0 commit comments

Comments
 (0)