Common issues and solutions for Mock NVML.
Error:
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH
Solution:
# Ubuntu/Debian
sudo apt-get install build-essential
# RHEL/CentOS
sudo yum groupinstall "Development Tools"
# macOS
xcode-select --installError:
go: go.mod file indicates go 1.25
Solution:
# Install Go 1.25+
wget https://go.dev/dl/go1.25.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.25.0.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/binProblem: Cannot build shared library on macOS for Linux.
Solution: Use Docker build:
make docker-buildError:
nvidia-smi: error while loading shared libraries: libnvidia-ml.so.1: cannot open shared object file
Solution:
# Verify library exists
ls -la pkg/gpu/mocknvml/libnvidia-ml.so*
# Set library path correctly
export LD_LIBRARY_PATH=$(pwd)/pkg/gpu/mocknvml:$LD_LIBRARY_PATH
# Or use absolute path
LD_LIBRARY_PATH=/full/path/to/pkg/gpu/mocknvml nvidia-smiError:
nvidia-smi: symbol lookup error: nvidia-smi: undefined symbol: nvmlSomeFunction
Solution:
- Check if symbol is exported:
nm -D pkg/gpu/mocknvml/libnvidia-ml.so | grep nvmlSomeFunction- If missing, check if it's a stub or needs implementation:
# Check if it's in stubs
grep "nvmlSomeFunction" pkg/gpu/mocknvml/bridge/stubs_generated.go
# If stub, implement it in appropriate bridge file, then:
go generate ./pkg/gpu/mocknvml/bridge/
make -C pkg/gpu/mocknvml clean
make -C pkg/gpu/mocknvmlError:
Segmentation fault (core dumped)
Causes and Solutions:
-
Handle dereferencing issue:
- Enable debug mode:
MOCK_NVML_DEBUG=1 - Check which function crashes
- Verify handle table is working
- Enable debug mode:
-
CGo memory issue:
- Run with address sanitizer:
CGO_CFLAGS="-fsanitize=address" go build -buildmode=c-shared ... -
nvidia-smi version mismatch:
- Ensure driver version in config matches nvidia-smi expectation
- Try different nvidia-smi versions
Error:
[CONFIG] Failed to load YAML config from /path/to/config.yaml: ...
Solution:
- Verify file exists and is readable:
cat $MOCK_NVML_CONFIG- Validate YAML syntax:
python3 -c "import yaml; yaml.safe_load(open('$MOCK_NVML_CONFIG'))"- Check required fields:
version: "1.0" # Required
system:
driver_version: "550.163.01" # Required- Enable debug to see specific error:
MOCK_NVML_DEBUG=1 LD_LIBRARY_PATH=. nvidia-smiProblem: Values don't match YAML config.
Solution:
- Verify config is loaded:
MOCK_NVML_DEBUG=1 LD_LIBRARY_PATH=. nvidia-smi 2>&1 | head -5
# Should show: [CONFIG] Loaded YAML config: N devices, driver X.Y.Z-
Check device override vs defaults:
- Per-device settings override defaults
- Check
devices:section in YAML
-
Verify field mapping:
- Some nvidia-smi fields map to different config fields
- Check Configuration Reference
Problem: nvidia-smi shows "N/A" or errors for some queries.
Explanation: Functions return NOT_SUPPORTED when:
- YAML config doesn't provide the value
- Function is not implemented (stub)
Solution:
- Add missing config values:
device_defaults:
thermal:
temperature_gpu_c: 33 # Add this for temperature- Check if function is implemented:
# Check engine implementation
grep "GetXxx" pkg/gpu/mocknvml/engine/device.go
# Check bridge implementation
grep "nvmlDeviceGetXxx" pkg/gpu/mocknvml/bridge/*.go
# Check if it's just a stub
grep "nvmlDeviceGetXxx" pkg/gpu/mocknvml/bridge/stubs_generated.goError:
Error: No GPU found
Solution:
- Ensure mock library is built:
make -C pkg/gpu/mocknvml- Check library is accessible in Docker:
docker run -v $(pwd)/pkg/gpu/mocknvml:/mock -e LD_LIBRARY_PATH=/mock ...Error:
WARNING: DATA RACE
Solution:
- All Engine methods should use mutex
- Check that new code acquires locks properly
- Run tests with race detector:
go test -race ./...
Problem: nvidia-smi takes long to start.
Causes:
- Large YAML config parsing
- Debug logging enabled
Solution:
# Disable debug
unset MOCK_NVML_DEBUG
# Use simpler config for testingProblem: High memory usage.
Explanation:
- Each handle allocates ~40 bytes of C memory
- Error string cache grows with unique errors
This is typically not a problem for normal usage.
Problem: System uses real NVML despite setting LD_LIBRARY_PATH.
Solutions:
- Check library search order:
LD_DEBUG=libs nvidia-smi 2>&1 | grep nvml- Verify no cached libraries:
sudo ldconfig # Refresh cache- Use absolute path:
LD_LIBRARY_PATH=/absolute/path/to/mocknvml nvidia-smi- Check for ld.so.conf entries:
grep nvml /etc/ld.so.conf.d/*Problem: Library doesn't work in Docker container.
Solutions:
- Mount library correctly:
docker run -v $(pwd)/pkg/gpu/mocknvml:/mock:ro \
-e LD_LIBRARY_PATH=/mock \
ubuntu nvidia-smi- Ensure nvidia-smi is available:
docker run ... which nvidia-smi- Use correct architecture:
# Build for container architecture
GOARCH=amd64 make -C pkg/gpu/mocknvmlProblem: The GPU Operator validator pod repeatedly crashes.
Explanation: The GPU Operator validator (/usr/bin/nvidia-validator) is a
statically-linked Go binary with no shell. It probes the driver root for
expected files.
Solution: Ensure the mock driver root has all required files:
# Use the specific Kind cluster and node name (adjust cluster name as needed)
NODE_CONTAINER="nvml-mock-operator-control-plane"
docker exec "$NODE_CONTAINER" ls -la /run/nvidia/driver/usr/lib64/libnvidia-ml.so*
docker exec "$NODE_CONTAINER" cat /var/lib/nvml-mock/driver/config/config.yamlProblem: CDI specs are not appearing in /var/run/cdi/.
Solution: Check nvml-mock DaemonSet logs for CDI generation errors:
kubectl logs -l app.kubernetes.io/name=nvml-mock | grep -i cdiProblem: The GPU Operator-managed device plugin reports 0 GPUs.
Solution: Verify the device plugin is using the mock driver root:
kubectl -n gpu-operator logs -l app=nvidia-device-plugin-daemonset | head -20The GPU Operator must be installed with --set driver.enabled=false and
--set toolkit.enabled=false when using mock GPUs, since there is no real
NVIDIA driver to manage.
When reporting issues, include:
- Environment:
uname -a
go version
gcc --version- Debug output:
MOCK_NVML_DEBUG=1 LD_LIBRARY_PATH=. nvidia-smi 2>&1- Library info:
file pkg/gpu/mocknvml/libnvidia-ml.so
ldd pkg/gpu/mocknvml/libnvidia-ml.so-
Config file (if using YAML)
-
Expected vs actual output
Include:
- Steps to reproduce
- Expected behavior
- Actual behavior
- Debug output
- Environment info