Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- implement NRI plugin reconnect mechanism
- ensure the toolkit exits if NRI Plugin init fails
- feat(nvcdi): Allow IPC sockets to not be discovered
- fix(cudacompat): Fix handling of CUDA compat on Orin

## v1.19.0
- Promote v1.19.0-rc.7 to v1.19.0
Expand Down
12 changes: 10 additions & 2 deletions cmd/nvidia-cdi-hook/cudacompat/cuda-elf-header.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (h elf32_Nhdr) sizeof() int {
return 12
}

// GetCUDACompatElfHeader returns the elf header for the specified library.
// This should be equivalent to:
// readelf -p .note.cuda.fwd_compatibility {{.libraryPath}}
func GetCUDACompatElfHeader(libraryPath string) (*compatElfHeader, error) {
lib, err := elf.Open(libraryPath)
if os.IsNotExist(err) {
Expand Down Expand Up @@ -99,8 +102,13 @@ func alignUp[T uint32 | uint64, S uint64](size T, to S) int {
return int((size + T(to) - 1) &^ (T(to) - 1))
}

func trim(data []byte, from int, len int) []byte {
return bytes.Trim(data[from:from+len], "\x00")
func trim(data []byte, from int, n int) []byte {
if len(data) == 0 {
return nil
}
from = min(len(data)-1, from)
to := min(len(data), from+n)
return bytes.Trim(data[from:to], "\x00")
}

func getCUDAFwdCompatibilitySection(lib *elf.File) *elf.Section {
Expand Down
29 changes: 24 additions & 5 deletions cmd/nvidia-cdi-hook/cudacompat/cuda-elf-header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ func TestGetCUDACompatElfHeader(t *testing.T) {
dataRoot := filepath.Join(moduleRoot, "testdata", "compat")

testCases := []struct {
description string
filename string
expected *compatElfHeader
description string
filename string
expected *compatElfHeader
expectedError string
}{
{
description: "wip",
description: "libcuda.so.575.57.08",
filename: "libcuda.so.575.57.08",
expected: &compatElfHeader{
Format: 1,
Expand All @@ -48,7 +49,7 @@ func TestGetCUDACompatElfHeader(t *testing.T) {
},
},
{
description: "wip",
description: "libcuda.so.590.44.01",
filename: "libcuda.so.590.44.01",
expected: &compatElfHeader{
Format: 1,
Expand All @@ -57,13 +58,31 @@ func TestGetCUDACompatElfHeader(t *testing.T) {
Device: []int{1, 2, 7, 8, 9, 10, 11, 12, 13, 14},
},
},
{
description: "invalid json",
filename: "libcuda.invalid.json.so.99.88",
expectedError: "could not unmarshal JSON data",
},
{
description: "orin-13.2.1",
filename: "libcuda.orin.13.2.1.so.1.1",
expected: &compatElfHeader{
Format: 1,
CUDAVersion: "13.2",
},
},
}

for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
libpath := filepath.Join(dataRoot, tc.filename)

h, err := GetCUDACompatElfHeader(libpath)
if tc.expectedError != "" {
require.ErrorContains(t, err, tc.expectedError)
require.Nil(t, h)
return
}
require.NoError(t, err)

require.EqualValues(t, tc.expected, h)
Expand Down
Binary file added testdata/compat/libcuda.invalid.json.so.99.88
Binary file not shown.
Binary file added testdata/compat/libcuda.orin.13.2.1.so.1.1
Binary file not shown.
Binary file modified testdata/compat/libcuda.so.575.57.08
Binary file not shown.
Binary file modified testdata/compat/libcuda.so.590.44.01
Binary file not shown.
Loading