Skip to content

Enable CUDA filter graph #3159

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

Closed
mthrok opened this issue Mar 9, 2023 · 0 comments
Closed

Enable CUDA filter graph #3159

mthrok opened this issue Mar 9, 2023 · 0 comments

Comments

@mthrok
Copy link
Collaborator

mthrok commented Mar 9, 2023

Currently, when performing GPU decoding/encoding, filter graph is disable.
We should enable filter graph so that it is more flexible for GPU processing.

implementation direction

  1. Explicitly pass HW device context and/or HW frame context to AVCodecContext here. Similar to encoder.
  2. Modify the FilterGraph implementation so that HW device context is attached to AVFilterContext and HW frame context is attached to AVFilterLink.
  3. Test with scale_cuda filter.

Test code

import torchaudio
from torchaudio.io import StreamReader

src = "NASAs_Most_Scientifically_Complex_Space_Observatory_Requires_Precision-MP4_small.mp4"
r = StreamReader(src)
torchaudio.utils.ffmpeg_utils.set_log_level(56)
r.add_video_stream(-1, decoder="h264_cuvid", filter_desc="scale_cuda=480:270", hw_accel="cuda")

Currently this causes segmentation fault at

void FilterGraph::create_filter() {
int ret = avfilter_graph_config(pFilterGraph, nullptr);
TORCH_CHECK(ret >= 0, "Failed to configure the graph: " + av_err2string(ret));
// char* desc = avfilter_graph_dump(pFilterGraph, NULL);
// std::cerr << "Filter created:\n" << desc << std::endl;
// av_free(static_cast<void*>(desc));
}

  • log
[h264_cuvid @ 0x6814340] Calling ctx->cudl->cuCtxPushCurrent(cuda_ctx)
[h264_cuvid @ 0x6814340] Calling ctx->cvdl->cuvidGetDecoderCaps(&ctx->caps8)
[h264_cuvid @ 0x6814340] Calling ctx->cvdl->cuvidGetDecoderCaps(&ctx->caps10)
[h264_cuvid @ 0x6814340] Calling ctx->cvdl->cuvidGetDecoderCaps(&ctx->caps12)
[h264_cuvid @ 0x6814340] CUVID capabilities for h264_cuvid:
[h264_cuvid @ 0x6814340] 8 bit: supported: 1, min_width: 48, max_width: 4096, min_height: 16, max_height: 4096
[h264_cuvid @ 0x6814340] 10 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0
[h264_cuvid @ 0x6814340] 12 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0
[h264_cuvid @ 0x6814340] Calling ctx->cvdl->cuvidCreateVideoParser(&ctx->cuparser, &ctx->cuparseinfo)
[h264_cuvid @ 0x6814340] Calling ctx->cvdl->cuvidParseVideoData(ctx->cuparser, &seq_pkt)
[h264_cuvid @ 0x6814340] Calling ctx->cudl->cuCtxPopCurrent(&dummy)
[h264_cuvid @ 0x6814340] Invalid pkt_timebase, passing timestamps as-is.
[in @ 0x71da9c0] Setting 'video_size' to value '960x540'
[in @ 0x71da9c0] Setting 'pix_fmt' to value 'cuda'
[in @ 0x71da9c0] Setting 'time_base' to value '1/30000'
[in @ 0x71da9c0] Setting 'frame_rate' to value '30000/1001'
[in @ 0x71da9c0] Setting 'pixel_aspect' to value '1/1'
[in @ 0x71da9c0] w:960 h:540 pixfmt:cuda tb:1/30000 fr:30000/1001 sar:1/1
[Parsed_scale_cuda_0 @ 0x71db980] Setting 'w' to value '480'
[Parsed_scale_cuda_0 @ 0x71db980] Setting 'h' to value '270'
[AVFilterGraph @ 0x71da840] query_formats: 3 queried, 2 merged, 0 already done, 0 delayed
/fsx/users/moto/torchaudio/./bu.sh: line 17: 11665 Segmentation fault      (core dumped) python repro/cuda_filter.py

The segfault happens in cudascale_config_props function of vf_scale_cuda.c, it seems that hw_device_context is required.

mthrok added a commit to mthrok/audio that referenced this issue Mar 19, 2023
Summary:
This commit adds CUDA frame support to FilterGraph

It initializes and attaches CUDA frames context to FilterGraph,
so that CUDA frames can be processed in FilterGraph.

As a result, it enables
1. CUDA filter support such as `scale_cuda`
2. Properly retrieve the pixel format coming out of FilterGraph when
   CUDA HW acceleration is enabled. (currently it is reported as "cuda")

Resolves pytorch#3159

Pull Request resolved: pytorch#3183

Differential Revision: D44183722

Pulled By: mthrok

fbshipit-source-id: 263999172522233401109b9a0d13514883d95660
mthrok added a commit to mthrok/audio that referenced this issue Mar 19, 2023
Summary:
This commit adds CUDA frame support to FilterGraph

It initializes and attaches CUDA frames context to FilterGraph,
so that CUDA frames can be processed in FilterGraph.

As a result, it enables
1. CUDA filter support such as `scale_cuda`
2. Properly retrieve the pixel format coming out of FilterGraph when
   CUDA HW acceleration is enabled. (currently it is reported as "cuda")

Resolves pytorch#3159

Pull Request resolved: pytorch#3183

Differential Revision: D44183722

Pulled By: mthrok

fbshipit-source-id: ae99c63c770234ec979008a31fcbe661d0265fb3
mthrok added a commit to mthrok/audio that referenced this issue Mar 19, 2023
Summary:
This commit adds CUDA frame support to FilterGraph

It initializes and attaches CUDA frames context to FilterGraph,
so that CUDA frames can be processed in FilterGraph.

As a result, it enables
1. CUDA filter support such as `scale_cuda`
2. Properly retrieve the pixel format coming out of FilterGraph when
   CUDA HW acceleration is enabled. (currently it is reported as "cuda")

Resolves pytorch#3159

Pull Request resolved: pytorch#3183

Differential Revision: D44183722

Pulled By: mthrok

fbshipit-source-id: 7a1ec4717348965d178045c76b0bbe506140f8c7
mthrok added a commit to mthrok/audio that referenced this issue Mar 20, 2023
Summary:
This commit adds CUDA frame support to FilterGraph

It initializes and attaches CUDA frames context to FilterGraph,
so that CUDA frames can be processed in FilterGraph.

As a result, it enables
1. CUDA filter support such as `scale_cuda`
2. Properly retrieve the pixel format coming out of FilterGraph when
   CUDA HW acceleration is enabled. (currently it is reported as "cuda")

Resolves pytorch#3159

Pull Request resolved: pytorch#3183

Differential Revision: D44183722

Pulled By: mthrok

fbshipit-source-id: 971f796c11a96d728065f84726bdb7acd6e656bc
mthrok added a commit to mthrok/audio that referenced this issue Mar 20, 2023
Summary:
This commit adds CUDA frame support to FilterGraph

It initializes and attaches CUDA frames context to FilterGraph,
so that CUDA frames can be processed in FilterGraph.

As a result, it enables
1. CUDA filter support such as `scale_cuda`
2. Properly retrieve the pixel format coming out of FilterGraph when
   CUDA HW acceleration is enabled. (currently it is reported as "cuda")

Resolves pytorch#3159

Pull Request resolved: pytorch#3183

Differential Revision: D44183722

Pulled By: mthrok

fbshipit-source-id: d319fee3a6c03e1dbc985879f0eead879925b4c8
mthrok added a commit to mthrok/audio that referenced this issue Mar 20, 2023
Summary:
This commit adds CUDA frame support to FilterGraph

It initializes and attaches CUDA frames context to FilterGraph,
so that CUDA frames can be processed in FilterGraph.

As a result, it enables
1. CUDA filter support such as `scale_cuda`
2. Properly retrieve the pixel format coming out of FilterGraph when
   CUDA HW acceleration is enabled. (currently it is reported as "cuda")

Resolves pytorch#3159

Pull Request resolved: pytorch#3183

Differential Revision: D44183722

Pulled By: mthrok

fbshipit-source-id: 7f3a223330cc5bc54f99c87c203494c948e9dfba
mthrok added a commit to mthrok/audio that referenced this issue Mar 20, 2023
Summary:
This commit adds CUDA frame support to FilterGraph

It initializes and attaches CUDA frames context to FilterGraph,
so that CUDA frames can be processed in FilterGraph.

As a result, it enables
1. CUDA filter support such as `scale_cuda`
2. Properly retrieve the pixel format coming out of FilterGraph when
   CUDA HW acceleration is enabled. (currently it is reported as "cuda")

Resolves pytorch#3159

Pull Request resolved: pytorch#3183

Differential Revision: D44183722

Pulled By: mthrok

fbshipit-source-id: 394c16b2d95d6a741addd17b1284c901ba6a8de6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant