Compile bug: [CUDA 11.4 / Jetson] Build failures in ggml-cuda: missing nvml.h, missing nvmlBrandType_t/nvmlDeviceGetBrand, and constexpr evaluation in mmq-few.cu
Git commit
8d60873dfb8619f2b5ed31adfbab07cccb40db5c
Operating systems
Linux
GGML backends
CUDA
Problem description & steps to reproduce
Environment
- Project path:
/opt/update/llama-1121/llama.cpp - Hardware: NVIDIA Jetson (
aarch64) - CUDA Version: CUDA 11.4 (
nvcc) - Build Target:
-DGGML_CUDA=ON
Extracted Error Logs from Screenshots
- Missing
nvml.hinggml-cuda.cu
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu:102:10: fatal error: nvml.h: No such file or directory
102 | #include <nvml.h>
| ^~~~~~~~
compilation terminated.
make[3]: *** [ggml/src/ggml-cuda/CMakeFiles/ggml-cuda.dir/build.make:542: ggml/src/ggml-cuda/CMakeFiles/ggml-cuda.dir/ggml-cuda.cu.o] Error 1
```[cite: 1]
2. **Missing NVML brand symbols in `ggml-cuda.cu` after adding a minimal `nvml.h` stub**
```text
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(349): error: identifier "nvmlDeviceGetBrand" is undefined
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(365): error: identifier "nvmlBrandType_t" is undefined
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(365): error: identifier "NVML_BRAND_UNKNOWN" is undefined
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(368): error: identifier "NVML_BRAND_QUADRO" is undefined
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(369): error: identifier "NVML_BRAND_QUADRO_RTX" is undefined
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(370): error: identifier "NVML_BRAND_NVIDIA_RTX" is undefined
6 errors detected in the compilation of "/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu".
make[3]: *** [ggml/src/ggml-cuda/CMakeFiles/ggml-cuda.dir/build.make:542: ggml/src/ggml-cuda/CMakeFiles/ggml-cuda.dir/ggml-cuda.cu.o] Error 1
```[cite: 2]
3. **Constant expression evaluation failure (`*this`) in `mmq-few.cu`**
```text
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/mmq-few.cu(560): error: expression must have a constant value
Note: the value of *this cannot be used as a constant
detected during:
instantiation of "void mul_mat_q_few<type,ncg,nmt,has_ids>(const char *, const int4 *, float *, int, int, int, int64_t, int, int, int64_t, int, int, int64_t, int, __nv_bool, const int *)" ...
```[cite: 3, 4]
#### Local Workarounds Applied
* Created a local stub `nvml.h` passed via `-DCMAKE_CUDA_FLAGS="-I..."` defining `nvmlReturn_t`, `nvmlBrandType_enum` (`NVML_BRAND_*`), `nvmlBrandType_t`, and `nvmlDeviceGetBrand` returning `NVML_ERROR_NOT_SUPPORTED`
* Replaced `if constexpr (unaligned)` with `if (unaligned)` in `ggml/src/ggml-cuda/mmq-few.cu` around line 560[cite: 1, 2, 3, 4]
#### Expected / Suggested Improvement
* Guard NVML headers and brand queries cleanly for platforms/CUDA versions without NVML support, and avoid `if constexpr` over captured/lambda expressions where older `nvcc` frontends (such as CUDA 11.4) fail constant evaluation on `*this`[cite: 1, 2, 3, 4]
### First Bad Commit
_No response_
### Compile command
```shell
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DGGML_CUDA=ON \
-DCMAKE_CUDA_COMPILER=$CUDA_HOME/bin/nvcc \
-DCMAKE_CUDA_ARCHITECTURES="87" \
-DCUDAToolkit_ROOT=$CUDA_HOME \
-DBUILD_SHARED_LIBS=ON \
-DGGML_CCACHE=OFF \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_CXX_COMPILER=g++
Relevant log output
2. **Missing NVML brand symbols in `ggml-cuda.cu` after adding a minimal `nvml.h` stub**
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(349): error: identifier "nvmlDeviceGetBrand" is undefined
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(365): error: identifier "nvmlBrandType_t" is undefined
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(365): error: identifier "NVML_BRAND_UNKNOWN" is undefined
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(368): error: identifier "NVML_BRAND_QUADRO" is undefined
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(369): error: identifier "NVML_BRAND_QUADRO_RTX" is undefined
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu(370): error: identifier "NVML_BRAND_NVIDIA_RTX" is undefined
6 errors detected in the compilation of "/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu".
make[3]: *** [ggml/src/ggml-cuda/CMakeFiles/ggml-cuda.dir/build.make:542: ggml/src/ggml-cuda/CMakeFiles/ggml-cuda.dir/ggml-cuda.cu.o] Error 1
[cite: 2]
3. **Constant expression evaluation failure (`*this`) in `mmq-few.cu`**
/opt/update/llama-1121/llama.cpp/ggml/src/ggml-cuda/mmq-few.cu(560): error: expression must have a constant value
Note: the value of *this cannot be used as a constant
detected during:
instantiation of "void mul_mat_q_few<type,ncg,nmt,has_ids>(const char *, const int4 *, float *, int, int, int, int64_t, int, int, int64_t, int, int, int64_t, int, __nv_bool, const int *)" ...
[cite: 3, 4]
These are two separate regressions from last week:
1. nvml.h, from 2cbfc3cf3 (#30672, Nov 18). ggml-cuda.cu now includes <nvml.h> whenever the build isn't HIP or MUSA. NVML itself is only loaded at runtime (dlopen("libnvidia-ml.so.1"), around line 340), and every function pointer is checked before use. On Jetson that library doesn't exist, so nvml_initialized is false and should_use_fp32_acc returns false. The header is only needed for the types and the decltype(&nvml...) declarations.
That means your stub is safe at runtime. It only has to declare nvmlInit_v2, nvmlShutdown, nvmlDeviceGetHandleByPciBusId_v2 and nvmlDeviceGetBrand with the real signatures, plus nvmlDevice_t, nvmlReturn_t/NVML_SUCCESS and the NVML_BRAND_* values. No definitions are needed, because they're never linked.
2. if constexpr (unaligned) in mmq-few.cu, from the few-row MMQ kernel in 0fb8f1577 (#31533, Nov 12). Line 560 is inside the load_stage = [&](...) lambda. There, unaligned is a constexpr local captured by reference, and CUDA 11.4's front end doesn't treat it as a constant expression. Newer nvcc does. Swapping it to a plain if works. To keep it compile-time, build the condition only from template parameters, since nunits_stage is also a captured constexpr local:
if constexpr (mmq_few_unaligned(type, mmq_few_nunits_stage(type, ncg, nmt))) {
The one at line 574 is outside the lambda and should be fine as is.
If you just need a working build on CUDA 11.4 now, check out the commit before #31533 (827466b9e). Both changes come after it.
For an first issue, I personally solved it by installing cuda-nvml-dev-12-9 package.