These are the things I did to get NVIDIA GeForce GTX 1050 Ti working on Ubuntu 24. Given its an older GPU card, I had to use a lower CUDA version and a lower gcc version. Your system may be different. Don't try and figure it out yourself. Easier to use claude CLI and debug together:
IMPORTANT: Don't copy paste - find out your GPU specs, and then download the right nvidia driver/CUDA/CuDNN/
wget https://developer.download.nvidia.com/compute/nvidia-driver/590.48.01/local_installers/nvidia-driver-local-repo-ubuntu2404-590.48.01_1.0-1_amd64.deb
sudo dpkg -i nvidia-driver-local-repo-ubuntu2404-590.48.01_1.0-1_amd64.deb
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run --toolkit --silent --override
sudo apt install libcudnn8-dev=8.9.7.29-1+cuda11.8 libcudnn8=8.9.7.29-1+cuda11.8
Add to your ~/.bashrc:
export PATH=/usr/local/cuda-11.8/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:$LD_LIBRARY_PATH
Then:
source ~/.bashrc
nvcc --version
Should show release 11.8.
nvidia-smi - make sure it works
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.126.09 Driver Version: 580.126.09 CUDA Version: 13.0 |
+-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce GTX 1050 Ti Off | 00000000:01:00.0 Off | N/A |
| 34% 34C P0 N/A / 75W | 0MiB / 4096MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| No running processes found |
+-----------------------------------------------------------------------------------------+
Compile opencv
sudo apt install gcc-11 g++-11
git clone https://github.com/opencv/opencv
git clone https://github.com/opencv/opencv_contrib
cd opencv
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN=6.1 -D CUDA_ARCH_PTX="" \
-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D HAVE_opencv_python3=ON \
-D PYTHON_EXECUTABLE=/usr/bin/python3 \
-D CMAKE_C_COMPILER=/usr/bin/gcc-11 \
-D CMAKE_CXX_COMPILER=/usr/bin/g++-11 \
-D CUDA_HOST_COMPILER=/usr/bin/gcc-11 \
-D BUILD_EXAMPLES=ON ..
AT THIS STAGE LOOK CAREFULLY AT THE OUTPUT - IF ANY OF THESE FAILED OR SAID NO, YOU NEED TO FIX THEM (Your values will be different)
-- OpenCV modules:
-- To be built: <whole bunch of module>
...
-- NVIDIA CUDA: YES (ver 11.8, CUFFT CUBLAS FAST_MATH)
-- NVIDIA GPU arch: 61
-- NVIDIA PTX archs:
--
-- cuDNN: YES (ver 8.9.7)
...
-- Python 3:
-- Interpreter: /usr/bin/python3 (ver 3.12.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.12.so (ver 3.12.3)
-- Limited API: NO
-- numpy: /path/to/lib/python3.12/site-packages/numpy/_core/include (ver 2.4.2)
-- install path: lib/python3.12/dist-packages/cv2/python-3.12
--
-- Python (for build): /usr/bin/python3
Then build
For me using make -j$(nproc) got stuck. Seems to run out of memory. I have 18, 10 worked well.
Remember this takes a long time.
make -j10
sudo make install
Test everything works:
python
>>> import cv2
>>> cv2.__version__
'4.14.0-pre'