torchcodec 0.7.0__cp313-cp313-win_amd64.whl → 0.8.1__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of torchcodec might be problematic. Click here for more details.

Files changed (66) hide show
  1. torchcodec/_core/AVIOTensorContext.cpp +23 -16
  2. torchcodec/_core/AVIOTensorContext.h +2 -1
  3. torchcodec/_core/BetaCudaDeviceInterface.cpp +718 -0
  4. torchcodec/_core/BetaCudaDeviceInterface.h +193 -0
  5. torchcodec/_core/CMakeLists.txt +18 -3
  6. torchcodec/_core/CUDACommon.cpp +330 -0
  7. torchcodec/_core/CUDACommon.h +51 -0
  8. torchcodec/_core/Cache.h +6 -20
  9. torchcodec/_core/CpuDeviceInterface.cpp +195 -108
  10. torchcodec/_core/CpuDeviceInterface.h +84 -19
  11. torchcodec/_core/CudaDeviceInterface.cpp +227 -376
  12. torchcodec/_core/CudaDeviceInterface.h +38 -6
  13. torchcodec/_core/DeviceInterface.cpp +57 -19
  14. torchcodec/_core/DeviceInterface.h +97 -16
  15. torchcodec/_core/Encoder.cpp +346 -9
  16. torchcodec/_core/Encoder.h +62 -1
  17. torchcodec/_core/FFMPEGCommon.cpp +190 -3
  18. torchcodec/_core/FFMPEGCommon.h +27 -1
  19. torchcodec/_core/FilterGraph.cpp +30 -22
  20. torchcodec/_core/FilterGraph.h +15 -1
  21. torchcodec/_core/Frame.cpp +22 -7
  22. torchcodec/_core/Frame.h +15 -61
  23. torchcodec/_core/Metadata.h +2 -2
  24. torchcodec/_core/NVCUVIDRuntimeLoader.cpp +320 -0
  25. torchcodec/_core/NVCUVIDRuntimeLoader.h +14 -0
  26. torchcodec/_core/NVDECCache.cpp +60 -0
  27. torchcodec/_core/NVDECCache.h +102 -0
  28. torchcodec/_core/SingleStreamDecoder.cpp +196 -201
  29. torchcodec/_core/SingleStreamDecoder.h +42 -15
  30. torchcodec/_core/StreamOptions.h +16 -6
  31. torchcodec/_core/Transform.cpp +87 -0
  32. torchcodec/_core/Transform.h +84 -0
  33. torchcodec/_core/__init__.py +4 -0
  34. torchcodec/_core/custom_ops.cpp +257 -32
  35. torchcodec/_core/fetch_and_expose_non_gpl_ffmpeg_libs.cmake +61 -1
  36. torchcodec/_core/nvcuvid_include/cuviddec.h +1374 -0
  37. torchcodec/_core/nvcuvid_include/nvcuvid.h +610 -0
  38. torchcodec/_core/ops.py +147 -44
  39. torchcodec/_core/pybind_ops.cpp +22 -59
  40. torchcodec/_samplers/video_clip_sampler.py +7 -19
  41. torchcodec/decoders/__init__.py +1 -0
  42. torchcodec/decoders/_decoder_utils.py +61 -1
  43. torchcodec/decoders/_video_decoder.py +46 -20
  44. torchcodec/libtorchcodec_core4.dll +0 -0
  45. torchcodec/libtorchcodec_core5.dll +0 -0
  46. torchcodec/libtorchcodec_core6.dll +0 -0
  47. torchcodec/libtorchcodec_core7.dll +0 -0
  48. torchcodec/libtorchcodec_core8.dll +0 -0
  49. torchcodec/libtorchcodec_custom_ops4.dll +0 -0
  50. torchcodec/libtorchcodec_custom_ops5.dll +0 -0
  51. torchcodec/libtorchcodec_custom_ops6.dll +0 -0
  52. torchcodec/libtorchcodec_custom_ops7.dll +0 -0
  53. torchcodec/libtorchcodec_custom_ops8.dll +0 -0
  54. torchcodec/libtorchcodec_pybind_ops4.pyd +0 -0
  55. torchcodec/libtorchcodec_pybind_ops5.pyd +0 -0
  56. torchcodec/libtorchcodec_pybind_ops6.pyd +0 -0
  57. torchcodec/libtorchcodec_pybind_ops7.pyd +0 -0
  58. torchcodec/libtorchcodec_pybind_ops8.pyd +0 -0
  59. torchcodec/samplers/_time_based.py +8 -0
  60. torchcodec/version.py +1 -1
  61. {torchcodec-0.7.0.dist-info → torchcodec-0.8.1.dist-info}/METADATA +29 -16
  62. torchcodec-0.8.1.dist-info/RECORD +82 -0
  63. {torchcodec-0.7.0.dist-info → torchcodec-0.8.1.dist-info}/WHEEL +1 -1
  64. torchcodec-0.7.0.dist-info/RECORD +0 -67
  65. {torchcodec-0.7.0.dist-info → torchcodec-0.8.1.dist-info}/licenses/LICENSE +0 -0
  66. {torchcodec-0.7.0.dist-info → torchcodec-0.8.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,60 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // All rights reserved.
3
+ //
4
+ // This source code is licensed under the BSD-style license found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+
7
+ #include <torch/types.h>
8
+ #include <mutex>
9
+
10
+ #include "src/torchcodec/_core/CUDACommon.h"
11
+ #include "src/torchcodec/_core/FFMPEGCommon.h"
12
+ #include "src/torchcodec/_core/NVDECCache.h"
13
+
14
+ #include <cuda_runtime.h> // For cudaGetDevice
15
+
16
+ extern "C" {
17
+ #include <libavutil/hwcontext_cuda.h>
18
+ #include <libavutil/pixdesc.h>
19
+ }
20
+
21
+ namespace facebook::torchcodec {
22
+
23
+ NVDECCache& NVDECCache::getCache(const torch::Device& device) {
24
+ static NVDECCache cacheInstances[MAX_CUDA_GPUS];
25
+ return cacheInstances[getDeviceIndex(device)];
26
+ }
27
+
28
+ UniqueCUvideodecoder NVDECCache::getDecoder(CUVIDEOFORMAT* videoFormat) {
29
+ CacheKey key(videoFormat);
30
+ std::lock_guard<std::mutex> lock(cacheLock_);
31
+
32
+ auto it = cache_.find(key);
33
+ if (it != cache_.end()) {
34
+ auto decoder = std::move(it->second);
35
+ cache_.erase(it);
36
+ return decoder;
37
+ }
38
+
39
+ return nullptr;
40
+ }
41
+
42
+ bool NVDECCache::returnDecoder(
43
+ CUVIDEOFORMAT* videoFormat,
44
+ UniqueCUvideodecoder decoder) {
45
+ if (!decoder) {
46
+ return false;
47
+ }
48
+
49
+ CacheKey key(videoFormat);
50
+ std::lock_guard<std::mutex> lock(cacheLock_);
51
+
52
+ if (cache_.size() >= MAX_CACHE_SIZE) {
53
+ return false;
54
+ }
55
+
56
+ cache_[key] = std::move(decoder);
57
+ return true;
58
+ }
59
+
60
+ } // namespace facebook::torchcodec
@@ -0,0 +1,102 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // All rights reserved.
3
+ //
4
+ // This source code is licensed under the BSD-style license found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+
7
+ #pragma once
8
+
9
+ #include <map>
10
+ #include <memory>
11
+ #include <mutex>
12
+
13
+ #include <cuda.h>
14
+ #include <torch/types.h>
15
+
16
+ #include "src/torchcodec/_core/NVCUVIDRuntimeLoader.h"
17
+ #include "src/torchcodec/_core/nvcuvid_include/cuviddec.h"
18
+ #include "src/torchcodec/_core/nvcuvid_include/nvcuvid.h"
19
+
20
+ namespace facebook::torchcodec {
21
+
22
+ // This file implements a cache for NVDEC decoders.
23
+ // TODONVDEC P3: Consider merging this with Cache.h. The main difference is that
24
+ // this NVDEC Cache involves a cache key (the decoder parameters).
25
+
26
+ struct CUvideoDecoderDeleter {
27
+ void operator()(CUvideodecoder* decoderPtr) const {
28
+ if (decoderPtr && *decoderPtr) {
29
+ cuvidDestroyDecoder(*decoderPtr);
30
+ delete decoderPtr;
31
+ }
32
+ }
33
+ };
34
+
35
+ using UniqueCUvideodecoder =
36
+ std::unique_ptr<CUvideodecoder, CUvideoDecoderDeleter>;
37
+
38
+ // A per-device cache for NVDEC decoders. There is one instance of this class
39
+ // per GPU device, and it is accessed through the static getCache() method.
40
+ class NVDECCache {
41
+ public:
42
+ static NVDECCache& getCache(const torch::Device& device);
43
+
44
+ // Get decoder from cache - returns nullptr if none available
45
+ UniqueCUvideodecoder getDecoder(CUVIDEOFORMAT* videoFormat);
46
+
47
+ // Return decoder to cache - returns true if added to cache
48
+ bool returnDecoder(CUVIDEOFORMAT* videoFormat, UniqueCUvideodecoder decoder);
49
+
50
+ private:
51
+ // Cache key struct: a decoder can be reused and taken from the cache only if
52
+ // all these parameters match.
53
+ struct CacheKey {
54
+ cudaVideoCodec codecType;
55
+ uint32_t width;
56
+ uint32_t height;
57
+ cudaVideoChromaFormat chromaFormat;
58
+ uint32_t bitDepthLumaMinus8;
59
+ uint8_t numDecodeSurfaces;
60
+
61
+ CacheKey() = delete;
62
+
63
+ explicit CacheKey(CUVIDEOFORMAT* videoFormat)
64
+ : codecType(videoFormat->codec),
65
+ width(videoFormat->coded_width),
66
+ height(videoFormat->coded_height),
67
+ chromaFormat(videoFormat->chroma_format),
68
+ bitDepthLumaMinus8(videoFormat->bit_depth_luma_minus8),
69
+ numDecodeSurfaces(videoFormat->min_num_decode_surfaces) {}
70
+
71
+ CacheKey(const CacheKey&) = default;
72
+ CacheKey& operator=(const CacheKey&) = default;
73
+
74
+ bool operator<(const CacheKey& other) const {
75
+ return std::tie(
76
+ codecType,
77
+ width,
78
+ height,
79
+ chromaFormat,
80
+ bitDepthLumaMinus8,
81
+ numDecodeSurfaces) <
82
+ std::tie(
83
+ other.codecType,
84
+ other.width,
85
+ other.height,
86
+ other.chromaFormat,
87
+ other.bitDepthLumaMinus8,
88
+ other.numDecodeSurfaces);
89
+ }
90
+ };
91
+
92
+ NVDECCache() = default;
93
+ ~NVDECCache() = default;
94
+
95
+ std::map<CacheKey, UniqueCUvideodecoder> cache_;
96
+ std::mutex cacheLock_;
97
+
98
+ // Max number of cached decoders, per device
99
+ static constexpr int MAX_CACHE_SIZE = 20;
100
+ };
101
+
102
+ } // namespace facebook::torchcodec