Fix compilation on Pop!_OS 22.04 LTS CUDA
Downgrade the C++ version from 17 to 14, and also update the code to remove compilation warnings.
Without that fix the build fails with the following error.
/usr/include/c++/11/bits/std_function.h:435:145: error: parameter packs not expanded with ‘...’:
435 | function(_Functor&& __f)
| ^
/usr/include/c++/11/bits/std_function.h:435:145: note: ‘_ArgTypes’
/usr/include/c++/11/bits/std_function.h:530:146: error: parameter packs not expanded with ‘...’:
530 | operator=(_Functor&& __f)
| ^
/usr/include/c++/11/bits/std_function.h:530:146: note: ‘_ArgTypes’
gmake[2]: *** [ggml/src/ggml-cuda/CMakeFiles/ggml-cuda.dir/build.make:107: ggml/src/ggml-cuda/CMakeFiles/ggml-cuda.dir/argmax.cu.o] Error 1
Make sure to read the contributing guidelines before submitting a PR
Making C++ standard conditional on some backend is not a good idea. We recently decided to go C++17 by default.
PopOS is based on Ubuntu. Why don't you just get new llvm-18 or -19 stack installed and build with llvm/clang.
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
Then build llama.cpp with
CC=clang-18 CXX=clang++-18 cmake ...
I did not know I can build it with clang. Clang should work with C++17 no problem. I'll try to rebuild it with clang.
Before I try, one question. I suspect the problem might be with CUDA because it is failing to build .cu file?
I played around with nvcc a bit and reprod the issue.
#include <iostream>
#include <functional>
__global__ void hello() {
if constexpr (true) {
printf("C++17 is supported!\n");
}
}
int main() {
hello<<<1, 1>>>();
cudaDeviceSynchronize();
return 0;
}
$ nvcc -std=c++17 -o main main.cu /usr/include/c++/11/bits/std_function.h:435:145: error: parameter packs not expanded with ‘...’: 435 | function(_Functor&& __f) | ^ /usr/include/c++/11/bits/std_function.h:435:145: note: ‘_ArgTypes’ /usr/include/c++/11/bits/std_function.h:530:146: error: parameter packs not expanded with ‘...’: 530 | operator=(_Functor&& __f) | ^ /usr/include/c++/11/bits/std_function.h:530:146: note: ‘_ArgTypes’
I suspect using clang would not help. I need to upgrade nvcc.
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:45:30_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0
Maybe there is a way build nvcc on C++14 and rest on C++17. I am not expert in cmake.
Ah. Yeah, sorry, my bad. You need newer CUDA toolkit. CUDA 12 should work (it does on Ubuntu 24.04). https://toranbillups.com/blog/archive/2023/08/19/install-cuda-12-on-popos/
Technically you can explicitly specify the host compiler to use (NVCC_PREPEND_FLAGS) but it seems to be picky about the specific compiler versions it supports.
Thanks for the suggestion. I'll try to update to CUDA 12.