Skip to content

Commit 2f20414

Browse files
authored
Merge pull request #1030 from elezar/add-driver-lib-root-envvar
Add envvar for libcuda.so parent dir to CDI spec
2 parents 5bc2f50 + 4bab94b commit 2f20414

File tree

16 files changed

+226
-9
lines changed

16 files changed

+226
-9
lines changed

cmd/nvidia-ctk-installer/toolkit/toolkit_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ devices:
8686
hostPath: /host/driver/root/dev/nvidia-caps-imex-channels/channel2047
8787
containerEdits:
8888
env:
89+
- NVIDIA_CTK_LIBCUDA_DIR=/lib/x86_64-linux-gnu
8990
- NVIDIA_VISIBLE_DEVICES=void
9091
hooks:
9192
- hookName: createContainer

cmd/nvidia-ctk/cdi/generate/generate_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ devices:
8080
hostPath: {{ .driverRoot }}/dev/nvidia0
8181
containerEdits:
8282
env:
83+
- NVIDIA_CTK_LIBCUDA_DIR=/lib/x86_64-linux-gnu
8384
- NVIDIA_VISIBLE_DEVICES=void
8485
deviceNodes:
8586
- path: /dev/nvidiactl
@@ -164,6 +165,7 @@ devices:
164165
hostPath: {{ .driverRoot }}/dev/nvidia0
165166
containerEdits:
166167
env:
168+
- NVIDIA_CTK_LIBCUDA_DIR=/lib/x86_64-linux-gnu
167169
- NVIDIA_VISIBLE_DEVICES=void
168170
deviceNodes:
169171
- path: /dev/nvidiactl
@@ -240,6 +242,7 @@ devices:
240242
hostPath: {{ .driverRoot }}/dev/nvidia0
241243
containerEdits:
242244
env:
245+
- NVIDIA_CTK_LIBCUDA_DIR=/lib/x86_64-linux-gnu
243246
- NVIDIA_VISIBLE_DEVICES=void
244247
deviceNodes:
245248
- path: /dev/nvidiactl
@@ -307,6 +310,7 @@ devices:
307310
hostPath: {{ .driverRoot }}/dev/nvidia0
308311
containerEdits:
309312
env:
313+
- NVIDIA_CTK_LIBCUDA_DIR=/lib/x86_64-linux-gnu
310314
- NVIDIA_VISIBLE_DEVICES=void
311315
deviceNodes:
312316
- path: /dev/nvidiactl

internal/discover/cache.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type cache struct {
2323

2424
sync.Mutex
2525
devices []Device
26+
envVars []EnvVar
2627
hooks []Hook
2728
mounts []Mount
2829
}
@@ -51,6 +52,20 @@ func (c *cache) Devices() ([]Device, error) {
5152
return c.devices, nil
5253
}
5354

55+
func (c *cache) EnvVars() ([]EnvVar, error) {
56+
c.Lock()
57+
defer c.Unlock()
58+
59+
if c.envVars == nil {
60+
envVars, err := c.d.EnvVars()
61+
if err != nil {
62+
return nil, err
63+
}
64+
c.envVars = envVars
65+
}
66+
return c.envVars, nil
67+
}
68+
5469
func (c *cache) Hooks() ([]Hook, error) {
5570
c.Lock()
5671
defer c.Unlock()

internal/discover/discover.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ type Device struct {
2222
Path string
2323
}
2424

25+
// EnvVar represents a discovered environment variable.
26+
type EnvVar struct {
27+
Name string
28+
Value string
29+
}
30+
2531
// Mount represents a discovered mount.
2632
type Mount struct {
2733
HostPath string
@@ -42,6 +48,7 @@ type Hook struct {
4248
//go:generate moq -rm -fmt=goimports -stub -out discover_mock.go . Discover
4349
type Discover interface {
4450
Devices() ([]Device, error)
51+
EnvVars() ([]EnvVar, error)
4552
Mounts() ([]Mount, error)
4653
Hooks() ([]Hook, error)
4754
}

internal/discover/discover_mock.go

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/discover/envvar.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
**/
17+
18+
package discover
19+
20+
var _ Discover = (*EnvVar)(nil)
21+
22+
// Devices returns an empty list of devices for a EnvVar discoverer.
23+
func (e EnvVar) Devices() ([]Device, error) {
24+
return nil, nil
25+
}
26+
27+
// EnvVars returns an empty list of envs for a EnvVar discoverer.
28+
func (e EnvVar) EnvVars() ([]EnvVar, error) {
29+
return []EnvVar{e}, nil
30+
}
31+
32+
// Mounts returns an empty list of mounts for a EnvVar discoverer.
33+
func (e EnvVar) Mounts() ([]Mount, error) {
34+
return nil, nil
35+
}
36+
37+
// Hooks allows the Hook type to also implement the Discoverer interface.
38+
// It returns a single hook
39+
func (e EnvVar) Hooks() ([]Hook, error) {
40+
return nil, nil
41+
}

internal/discover/first-valid.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ func (f firstOf) Devices() ([]Device, error) {
4545
return nil, errs
4646
}
4747

48+
func (f firstOf) EnvVars() ([]EnvVar, error) {
49+
var errs error
50+
for _, d := range f {
51+
envs, err := d.EnvVars()
52+
if err != nil {
53+
errs = errors.Join(errs, err)
54+
continue
55+
}
56+
return envs, nil
57+
}
58+
return nil, errs
59+
}
60+
4861
func (f firstOf) Hooks() ([]Hook, error) {
4962
var errs error
5063
for _, d := range f {

internal/discover/hooks.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func (h *Hook) Devices() ([]Device, error) {
5757
return nil, nil
5858
}
5959

60+
// EnvVars returns an empty list of envs for a Hook discoverer.
61+
func (h *Hook) EnvVars() ([]EnvVar, error) {
62+
return nil, nil
63+
}
64+
6065
// Mounts returns an empty list of mounts for a Hook discoverer.
6166
func (h *Hook) Mounts() ([]Mount, error) {
6267
return nil, nil

internal/discover/list.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ func (d list) Devices() ([]Device, error) {
5353
return allDevices, nil
5454
}
5555

56+
// EnvVars returns all environment variables from the included discoverers.
57+
func (d list) EnvVars() ([]EnvVar, error) {
58+
var allEnvs []EnvVar
59+
60+
for i, di := range d {
61+
envs, err := di.EnvVars()
62+
if err != nil {
63+
return nil, fmt.Errorf("error discovering envs for discoverer %v: %w", i, err)
64+
}
65+
allEnvs = append(allEnvs, envs...)
66+
}
67+
68+
return allEnvs, nil
69+
}
70+
5671
// Mounts returns all mounts from the included discoverers
5772
func (d list) Mounts() ([]Mount, error) {
5873
var allMounts []Mount

internal/discover/none.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ func (e None) Devices() ([]Device, error) {
2727
return nil, nil
2828
}
2929

30+
// EnvVars returns an empty list of devices
31+
func (e None) EnvVars() ([]EnvVar, error) {
32+
return nil, nil
33+
}
34+
3035
// Mounts returns an empty list of mounts
3136
func (e None) Mounts() ([]Mount, error) {
3237
return nil, nil

0 commit comments

Comments
 (0)