-
Notifications
You must be signed in to change notification settings - Fork 14
fix(xunix): improve handling of gpu library mounts #129
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4ea87fc
feat(xunix): add SameDirSymlinks, add symlinks pointing to mounted libs
johnstcn ad7c946
chore(integration): update GPU integration tests
johnstcn 4878301
fix(xunix): tighten up gpuExtraRegex to avoid extraneous matches
johnstcn 669f1e5
chore(integration): test with nvidia sample CUDA image
johnstcn c3ad5b4
keep sharedObjectRegex around
johnstcn f3da271
redhat integration test: ensure libglib is not mounted in from host
johnstcn 7dee998
improve efficiency of SameDirSymlinks
johnstcn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/envbox/integration/integrationtest" | ||
|
@@ -41,8 +42,7 @@ func TestDocker_Nvidia(t *testing.T) { | |
) | ||
|
||
// Assert that we can run nvidia-smi in the inner container. | ||
_, err := execContainerCmd(ctx, t, ctID, "docker", "exec", "workspace_cvm", "nvidia-smi") | ||
require.NoError(t, err, "failed to run nvidia-smi in the inner container") | ||
assertInnerNvidiaSMI(ctx, t, ctID) | ||
}) | ||
|
||
t.Run("Redhat", func(t *testing.T) { | ||
|
@@ -52,16 +52,23 @@ func TestDocker_Nvidia(t *testing.T) { | |
|
||
// Start the envbox container. | ||
ctID := startEnvboxCmd(ctx, t, integrationtest.RedhatImage, "root", | ||
"-v", "/usr/lib/x86_64-linux-gnu:/var/coder/usr/lib64", | ||
"-v", "/usr/lib/x86_64-linux-gnu:/var/coder/usr/lib", | ||
"--env", "CODER_ADD_GPU=true", | ||
"--env", "CODER_USR_LIB_DIR=/var/coder/usr/lib64", | ||
"--env", "CODER_USR_LIB_DIR=/var/coder/usr/lib", | ||
"--runtime=nvidia", | ||
"--gpus=all", | ||
) | ||
|
||
// Assert that we can run nvidia-smi in the inner container. | ||
_, err := execContainerCmd(ctx, t, ctID, "docker", "exec", "workspace_cvm", "nvidia-smi") | ||
require.NoError(t, err, "failed to run nvidia-smi in the inner container") | ||
assertInnerNvidiaSMI(ctx, t, ctID) | ||
|
||
// Make sure dnf still works. This checks for a regression due to | ||
// gpuExtraRegex matching `libglib.so` in the outer container. | ||
// This had a dependency on `libpcre.so.3` which would cause dnf to fail. | ||
out, err := execContainerCmd(ctx, t, ctID, "docker", "exec", "workspace_cvm", "dnf") | ||
if !assert.NoError(t, err, "failed to run dnf in the inner container") { | ||
t.Logf("dnf output:\n%s", strings.TrimSpace(out)) | ||
} | ||
}) | ||
|
||
t.Run("InnerUsrLibDirOverride", func(t *testing.T) { | ||
|
@@ -79,11 +86,58 @@ func TestDocker_Nvidia(t *testing.T) { | |
"--gpus=all", | ||
) | ||
|
||
// Assert that the libraries end up in the expected location in the inner container. | ||
out, err := execContainerCmd(ctx, t, ctID, "docker", "exec", "workspace_cvm", "ls", "-l", "/usr/lib/coder") | ||
// Assert that the libraries end up in the expected location in the inner | ||
// container. | ||
out, err := execContainerCmd(ctx, t, ctID, "docker", "exec", "workspace_cvm", "ls", "-1", "/usr/lib/coder") | ||
require.NoError(t, err, "inner usr lib dir override failed") | ||
require.Regexp(t, `(?i)(libgl|nvidia|vulkan|cuda)`, out) | ||
}) | ||
|
||
t.Run("EmptyHostUsrLibDir", func(t *testing.T) { | ||
t.Parallel() | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
t.Cleanup(cancel) | ||
emptyUsrLibDir := t.TempDir() | ||
|
||
// Start the envbox container. | ||
ctID := startEnvboxCmd(ctx, t, integrationtest.UbuntuImage, "root", | ||
"-v", emptyUsrLibDir+":/var/coder/usr/lib", | ||
"--env", "CODER_ADD_GPU=true", | ||
"--env", "CODER_USR_LIB_DIR=/var/coder/usr/lib", | ||
"--runtime=nvidia", | ||
"--gpus=all", | ||
) | ||
|
||
ofs := outerFiles(ctx, t, ctID, "/usr/lib/x86_64-linux-gnu/libnv*") | ||
// Assert invariant: the outer container has the files we expect. | ||
require.NotEmpty(t, ofs, "failed to list outer container files") | ||
// Assert that expected files are available in the inner container. | ||
assertInnerFiles(ctx, t, ctID, "/usr/lib/x86_64-linux-gnu/libnv*", ofs...) | ||
assertInnerNvidiaSMI(ctx, t, ctID) | ||
}) | ||
Comment on lines
+102
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review: this tests that we can get by with no extra files in |
||
|
||
t.Run("CUDASample", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
t.Cleanup(cancel) | ||
|
||
// Start the envbox container. | ||
ctID := startEnvboxCmd(ctx, t, integrationtest.CUDASampleImage, "root", | ||
"-v", "/usr/lib/x86_64-linux-gnu:/var/coder/usr/lib", | ||
"--env", "CODER_ADD_GPU=true", | ||
"--env", "CODER_USR_LIB_DIR=/var/coder/usr/lib", | ||
"--runtime=nvidia", | ||
"--gpus=all", | ||
) | ||
|
||
// Assert that we can run nvidia-smi in the inner container. | ||
assertInnerNvidiaSMI(ctx, t, ctID) | ||
|
||
// Assert that /tmp/vectorAdd runs successfully in the inner container. | ||
_, err := execContainerCmd(ctx, t, ctID, "docker", "exec", "workspace_cvm", "/tmp/vectorAdd") | ||
require.NoError(t, err, "failed to run /tmp/vectorAdd in the inner container") | ||
}) | ||
} | ||
|
||
// dockerRuntimes returns the list of container runtimes available on the host. | ||
|
@@ -101,6 +155,49 @@ func dockerRuntimes(t *testing.T) []string { | |
return strings.Split(raw, "\n") | ||
} | ||
|
||
// outerFiles returns the list of files in the outer container matching the | ||
// given pattern. It does this by running `ls -1` in the outer container. | ||
func outerFiles(ctx context.Context, t *testing.T, containerID, pattern string) []string { | ||
t.Helper() | ||
// We need to use /bin/sh -c to avoid the shell interpreting the glob. | ||
out, err := execContainerCmd(ctx, t, containerID, "/bin/sh", "-c", "ls -1 "+pattern) | ||
require.NoError(t, err, "failed to list outer container files") | ||
files := strings.Split(strings.TrimSpace(out), "\n") | ||
slices.Sort(files) | ||
return files | ||
} | ||
|
||
// assertInnerFiles checks that all the files matching the given pattern exist in the | ||
// inner container. | ||
func assertInnerFiles(ctx context.Context, t *testing.T, containerID, pattern string, expected ...string) { | ||
t.Helper() | ||
|
||
// Get the list of files in the inner container. | ||
// We need to use /bin/sh -c to avoid the shell interpreting the glob. | ||
out, err := execContainerCmd(ctx, t, containerID, "docker", "exec", "workspace_cvm", "/bin/sh", "-c", "ls -1 "+pattern) | ||
require.NoError(t, err, "failed to list inner container files") | ||
innerFiles := strings.Split(strings.TrimSpace(out), "\n") | ||
|
||
// Check that the expected files exist in the inner container. | ||
missingFiles := make([]string, 0) | ||
for _, expectedFile := range expected { | ||
if !slices.Contains(innerFiles, expectedFile) { | ||
missingFiles = append(missingFiles, expectedFile) | ||
} | ||
} | ||
require.Empty(t, missingFiles, "missing files in inner container: %s", strings.Join(missingFiles, ", ")) | ||
} | ||
|
||
// assertInnerNvidiaSMI checks that nvidia-smi runs successfully in the inner | ||
// container. | ||
func assertInnerNvidiaSMI(ctx context.Context, t *testing.T, containerID string) { | ||
t.Helper() | ||
// Assert that we can run nvidia-smi in the inner container. | ||
out, err := execContainerCmd(ctx, t, containerID, "docker", "exec", "workspace_cvm", "nvidia-smi") | ||
require.NoError(t, err, "failed to run nvidia-smi in the inner container") | ||
require.Contains(t, out, "NVIDIA-SMI", "nvidia-smi output does not contain NVIDIA-SMI") | ||
} | ||
|
||
// startEnvboxCmd starts the envbox container with the given arguments. | ||
// Ideally we would use ory/dockertest for this, but it doesn't support | ||
// specifying the runtime. We have alternatively used the docker client library, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.