mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add cos_gpu_test that will run GPU container on COS.
Add GPU test that runs on COS. The container instructions can be found here: https://cloud.google.com/container-optimized-os/docs/how-to/run-gpus#configure_containers_to_consume_gpus PiperOrigin-RevId: 575042089
This commit is contained in:
committed by
gVisor bot
parent
d039776e16
commit
54ef8c70dd
@@ -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.
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
FROM gcr.io/google_containers/cuda-vector-add:v0.1
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
],
|
||||
)
|
||||
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user