Skip to content

Commit

Permalink
Add ffmpeg GPU test with h264_nvenc video codec (which uses NVENC).
Browse files Browse the repository at this point in the history
This test does NOT work yet in gVisor.

Updates #9452

PiperOrigin-RevId: 682127429
  • Loading branch information
EtiennePerot authored and gvisor-bot committed Oct 4, 2024
1 parent cb418b7 commit b89f53b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ cos-gpu-smoke-tests: gpu-smoke-images $(RUNTIME_BIN)
# This is a superset of those needed for smoke tests.
# It includes non-GPU images that are used as part of GPU tests,
# e.g. busybox and python.
gpu-images: gpu-smoke-images load-gpu_pytorch load-gpu_ollama load-gpu_ollama_client load-basic_busybox load-basic_python load-gpu_stable-diffusion-xl load-gpu_vllm load-gpu_nccl-tests
gpu-images: gpu-smoke-images load-gpu_pytorch load-gpu_ollama load-gpu_ollama_client load-basic_busybox load-basic_alpine load-basic_python load-gpu_stable-diffusion-xl load-gpu_vllm load-gpu_nccl-tests load-benchmarks_ffmpeg
.PHONY: gpu-images

gpu-all-tests: gpu-images gpu-smoke-tests $(RUNTIME_BIN)
Expand All @@ -314,6 +314,7 @@ gpu-all-tests: gpu-images gpu-smoke-tests $(RUNTIME_BIN)
@$(call sudo,test/gpu:imagegen_test,--runtime=$(RUNTIME) -test.v $(ARGS))
@$(call sudo,test/gpu:sr_test,--runtime=$(RUNTIME) -test.v $(ARGS))
@$(call sudo,test/gpu:nccl_test,--runtime=$(RUNTIME) -test.v $(ARGS))
@$(call sudo,test/gpu:ffmpeg_test,--runtime=$(RUNTIME) -test.v $(ARGS))
@$(call sudo,test/gpu:sniffer_test,--runtime=$(RUNTIME) -test.v $(ARGS))
.PHONY: gpu-all-tests

Expand All @@ -324,6 +325,7 @@ cos-gpu-all-tests: gpu-images cos-gpu-smoke-tests $(RUNTIME_BIN)
@$(call sudo,test/gpu:imagegen_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
@$(call sudo,test/gpu:sr_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
@$(call sudo,test/gpu:nccl_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
@$(call sudo,test/gpu:ffmpeg_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
@$(call sudo,test/gpu:sniffer_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
.PHONY: cos-gpu-all-tests

Expand Down
14 changes: 14 additions & 0 deletions test/gpu/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ go_test(
],
)

go_test(
name = "ffmpeg_test",
srcs = ["ffmpeg_test.go"],
# runsc is needed to invalidate the bazel cache in case of any code changes.
data = ["//runsc"],
tags = [
"manual",
"noguitar",
"notap",
],
visibility = ["//:sandbox"],
deps = ["//pkg/test/dockerutil"],
)

go_test(
name = "imagegen_test",
srcs = ["imagegen_test.go"],
Expand Down
48 changes: 48 additions & 0 deletions test/gpu/ffmpeg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2020 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ffmpeg_test

import (
"context"
"strings"
"testing"

"gvisor.dev/gvisor/pkg/test/dockerutil"
)

// TestFffmpegGPU runs ffmpeg in a GPU container using NVENC.
func TestFffmpegGPU(t *testing.T) {
ctx := context.Background()
isGVisor, err := dockerutil.IsGVisorRuntime(ctx, t)
if err != nil {
t.Fatalf("Failed to determine if runtime is gVisor: %v", err)
}
if isGVisor {
t.Skip("This test is currently broken in gVisor")
}
container := dockerutil.MakeContainer(ctx, t)
defer container.CleanUp(ctx)
opts, err := dockerutil.GPURunOpts(dockerutil.SniffGPUOpts{
Capabilities: "NVIDIA_DRIVER_CAPABILITIES=video",
AllowIncompatibleIoctl: true,
})
if err != nil {
t.Fatalf("Failed to get GPU run options: %v", err)
}
opts.Image = "benchmarks/ffmpeg"
cmd := strings.Split("ffmpeg -i video.mp4 -c:v h264_nvenc -preset fast output.mp4", " ")
if output, err := container.Run(ctx, opts, cmd...); err != nil {
t.Errorf("failed to run container: %v; output:\n%s", err, output)
}
}

0 comments on commit b89f53b

Please sign in to comment.