diff --git a/.buildkite/pipeline.yaml b/.buildkite/pipeline.yaml index 966174445..4fb677d1b 100644 --- a/.buildkite/pipeline.yaml +++ b/.buildkite/pipeline.yaml @@ -173,9 +173,8 @@ steps: <<: *source_test label: "GPU tests" commands: - - uname -r - - gcc --version - make sudo TARGETS=//tools/gpu:main ARGS="install --latest" || cat /var/log/nvidia-installer.log + - make gpu-tests agents: queue: gpu # Release workflow. diff --git a/Makefile b/Makefile index e00f781c1..367be4219 100644 --- a/Makefile +++ b/Makefile @@ -262,6 +262,12 @@ arm-qemu-smoke-test: $(RUNTIME_BIN) load-arm-qemu simple-tests: unit-tests # Compatibility target. .PHONY: simple-tests +gpu-tests: load-basic $(RUNTIME_BIN) + @$(call test,--test_env=RUNTIME=runc //test/gpu:gpu_test) + @$(call install_runtime,$(RUNTIME),--platform=systrap --nvproxy=true --nvproxy-docker=true) + @$(call test_runtime,$(RUNTIME),//test/gpu:gpu_test) +.PHONE: gpu-tests + portforward-tests: load-basic_redis load-basic_nginx $(RUNTIME_BIN) @$(call install_runtime,$(RUNTIME),--network=sandbox) @$(call sudo,test/root:portforward_test,--runtime=$(RUNTIME) -test.v $(ARGS)) diff --git a/images/basic/cuda-vector-add/Dockerfile b/images/basic/cuda-vector-add/Dockerfile new file mode 100644 index 000000000..112d045e1 --- /dev/null +++ b/images/basic/cuda-vector-add/Dockerfile @@ -0,0 +1 @@ +FROM gcr.io/google_containers/cuda-vector-add:v0.1 \ No newline at end of file diff --git a/pkg/test/dockerutil/container.go b/pkg/test/dockerutil/container.go index 71aa87ea6..6e3a711ab 100644 --- a/pkg/test/dockerutil/container.go +++ b/pkg/test/dockerutil/container.go @@ -42,7 +42,7 @@ import ( // Container represents a Docker Container allowing // user to configure and control as one would with the 'docker' -// client. Container is backed by the offical golang docker API. +// client. Container is backed by the official golang docker API. // See: https://pkg.go.dev/github.com/docker/docker. type Container struct { Name string @@ -105,6 +105,9 @@ type RunOpts struct { // Links is the list of containers to be connected to the container. Links []string + + // Devices are device requests on the container itself. + Devices []container.DeviceRequest } func makeContainer(ctx context.Context, logger testutil.Logger, runtime string) *Container { @@ -276,8 +279,9 @@ func (c *Container) hostConfig(r RunOpts) *container.HostConfig { ReadonlyRootfs: r.ReadOnly, NetworkMode: container.NetworkMode(r.NetworkMode), Resources: container.Resources{ - Memory: int64(r.Memory), // In bytes. - CpusetCpus: r.CpusetCpus, + Memory: int64(r.Memory), // In bytes. + CpusetCpus: r.CpusetCpus, + DeviceRequests: r.Devices, }, } } @@ -302,7 +306,7 @@ func (c *Container) Stop(ctx context.Context) error { return c.client.ContainerStop(ctx, c.id, container.StopOptions{}) } -// Pause is analogous to'docker pause'. +// Pause is analogous to 'docker pause'. func (c *Container) Pause(ctx context.Context) error { return c.client.ContainerPause(ctx, c.id) } diff --git a/test/gpu/BUILD b/test/gpu/BUILD new file mode 100644 index 000000000..b95ce0b08 --- /dev/null +++ b/test/gpu/BUILD @@ -0,0 +1,21 @@ +load("//tools:defs.bzl", "go_test") + +package( + default_applicable_licenses = ["//:license"], + licenses = ["notice"], +) + +go_test( + name = "gpu_test", + srcs = ["gpu_test.go"], + tags = [ + "local", + "noguitar", + "notap", + ], + visibility = ["//:sandbox"], + deps = [ + "//pkg/test/dockerutil", + "@com_github_docker_docker//api/types/container:go_default_library", + ], +) diff --git a/test/gpu/gpu_test.go b/test/gpu/gpu_test.go new file mode 100644 index 000000000..63b03581f --- /dev/null +++ b/test/gpu/gpu_test.go @@ -0,0 +1,48 @@ +// Copyright 2023 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 cos_gpu_test tests that GPUs work on Container Optimized OS (COS) images in GCP. This +// will probably only work on COS images. +package cos_gpu_test + +import ( + "context" + "testing" + + "github.com/docker/docker/api/types/container" + "gvisor.dev/gvisor/pkg/test/dockerutil" +) + +func TestGPUHello(t *testing.T) { + ctx := context.Background() + c := dockerutil.MakeContainer(ctx, t) + defer c.CleanUp(ctx) + + out, err := c.Run(ctx, dockerutil.RunOpts{ + Image: "basic/cuda-vector-add", + Devices: []container.DeviceRequest{ + { + Count: -1, + Capabilities: [][]string{[]string{"gpu"}}, + Options: map[string]string{}, + }, + }, + }) + + if err != nil { + t.Fatalf("could not run nvidia: %v", err) + } + + t.Logf("nvidia output: %s", string(out)) +}