PixInsight GPU support in RC-Astro plugins (TensorFlow with CUDA) in Debian 12 Other · Jan Bielański · ... · 3 · 222 · 8

JanBielanski 0.90
...
· 
·  3 likes
·  Share link
I've successfully configured my PixInsight in Linux - Debian 12 with full GPU support. The problem was related to TensorFlow library used by PixInsight, current PixInsight version support TensorFlow 2.11.0 with CPU support only. Through experiments I discovered the library could be replaced by TensorFlow 2.14.1 with GPU support.
obraz.png
Newer version can't be used because introduce new CUDA version 12.2 and loose compatibility with used in PixInsight TensorFlow API.
What to do if we want enable this support in Debian 12? In short:
- remove all NVIDIA CUDA drivers delivered by distribution
- install a proper NVIDIA driver manually
- build TensorFlow 2.14.1 with CUDA support
- replace PixInsight libraries
Unfortunately this process is not sow easy:
1) Download correct NVIDIA drivers:
- CUDA 11.8.0 with driver 520.61.05 -> cuda_11.8.0_520.61.05_linux.run
- CuDNN 8.7.0.84 -> cudnn-linux-x86_64-8.7.0.84_cuda11-archive.tar.xz
- NCCL 2.21.5 -> nccl_2.21.5-1+cuda11.0_x86_64.txz
- TensorRT 8.6.1.6 -> TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-11.8.tar.gz

2)  Remove all NVIDIA and CUDA by `apt` or `aptitude`
3) Install CUDA 11.8.0 with driver 520.61.05:
3a) Install necessary packages for built kernel modules as root or with sudo:
apt -y install linux-headers-$(uname -r) build-essential libglvnd-dev pkg-config

3b) Switch `gcc` to version is `gcc version 11.3.0 (Debian 11.3.0-12)` if not follow this topic.
3c) Disable default drivers as root or with sudo:
- open and edit:
nano /etc/modprobe.d/blacklist-nouveau.conf

put there and save file:
blacklist nouveau
options nouveau modeset=0

update kernel initramfs:
update-initramfs -u

restart computer it should run in text mode and it's ok because graphics drivers is not installed
3d) Driver and CUDA installation:
- login to root account and go to directory with `cuda_11.8.0_520.61.05_linux.run`
- run installer, remember install al CUDA and NVIDIA drivers
sh cuda_11.8.0_520.61.05_linux.run

- create configuration file `/etc/X11/xorg.conf.d/nvidia_as_primary.conf` with:
Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "PrimaryGPU" "yes"
EndSection

- reset computer, now X server should start
3e) Install libraries CuDNN, NCCL, TensorRT
- Extract files from: `cudnn-linux-x86_64-8.7.0.84_cuda11-archive.tar.xz`:
--> cudnn-linux-x86_64-8.7.0.84_cuda11-archive/include/ --> /usr/local/include
--> cudnn-linux-x86_64-8.7.0.84_cuda11-archive/lib/ --> /usr/local/lib/

- Extract files from `nccl_2.21.5-1+cuda11.0_x86_64.txz`:
--> nccl_2.21.5-1+cuda11.0_x86_64/include/ --> /usr/local/include
--> nccl_2.21.5-1+cuda11.0_x86_64/lib/ --> /usr/local/lib

- TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-11.8.tar.gz -> extract into `/opt/nvidia/`:
mkdir -p /opt/nvidia/ && sudo tar -xz  TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-11.8.tar.gz -C  /opt/nvidia/

-- then follow directory `/opt/nvidia/TensorRT-8.6.1.6/`
-- run following commands:
ln -sf /opt/nvidia/TensorRT-8.6.1.6 /opt/nvidia/tensorrt
echo "/opt/nvidia/TensorRT-8.6.1.6/lib" > /etc/ld.so.conf.d/989_tensorrt-8-6.conf
ldconfig

- reset computer
4) Build TensorFlow
4a) Extract TensorFlow 2.14.1:
tar -xf tensorflow-2.14.1.tar.gz

4b) Edit `tensorflow-2.14.1/third_party/tensorrt/tensorrt_configure.bzl` and add this two lines:
obraz.png
"NvInferRuntimePlugin.h",
    "NvInferRuntimeBase.h",

4c) Set TMP directory:
export TMP=/tmp

4d) Run TensorFlow configuration in `tensorflow-2.14.1` and answer for questions:
- run configuration:
./configure

- answers for my GPU `NVIDIA RTX A4000 Laptop GPU` in many case will be the same:
Do you wish to build TensorFlow with ROCm support? [y/N]: N

Do you wish to build TensorFlow with CUDA support? [y/N]: y

Do you wish to build TensorFlow with TensorRT support? [y/N]: y
[Leave empty to default to CUDA 11]: 11

[Leave empty to default to cuDNN 2]: 8

[Leave empty to default to TensorRT 6]: 8

NCCL version you want to use. [Leave empty to use http://github.com/nvidia/nccl]: 2

Please specify the comma-separated list of base paths to look for CUDA libraries and headers. [Leave empty to use the default]:
/usr/include/,/usr/lib/x86_64-linux-gnu/,/usr/local/,/usr/local/include/,/usr/local/lib/,/usr/local/cuda/,/usr/local/cuda/include/,/opt/nvidia/tensorrt/,/opt/nvidia/tensorrt/include/

Please note that each additional compute capability significantly increases your build time and binary size, and that TensorFlow only supports compute capabilities >= 3.5 [Default is: 8.6]: 8.6

Do you want to use clang as CUDA compiler? [Y/n]: n

Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: N

4e) Start compilation and finger crossed (this stage take a lot of time...):
bazel build --config opt //tensorflow/tools/lib_package:libtensorflow --config=cuda --config=v2 --config=nonccl --verbose_failures

when it's done, you see:

tensorflow-2.14.1_successfully_built_on_debian12.jpg
the results of compilation will be in:
tensorflow-2.14.1/bazel-bin/tensorflow/
libtensorflow.so.2.14.1
libtensorflow_framework.so.2.14.1

5) Copy libraries to PixInsight
- make backup of original TensorFlow files in PixInsight:
sudo mv /opt/PixInsight/bin/lib/libtensorflow.so.2.11.0 /opt/PixInsight/bin/lib/libtensorflow.so.2.11.0_cpu
sudo mv /opt/PixInsight/bin/lib/libtensorflow_framework.so.2.11.0 /opt/PixInsight/bin/lib/libtensorflow_framework.so.2.11.0_cpu

- copy new TensorFlow files with GPU support:
sudo cp bazel-bin/tensorflow/libtensorflow.so.2.14.1 /opt/PixInsight/bin/lib/libtensorflow.so_gpu
sudo cp bazel-bin/tensorflow/libtensorflow_framework.so.2.14.1 /opt/PixInsight/bin/lib/libtensorflow_framework.so_gpu
ln -sf /opt/PixInsight/bin/lib/libtensorflow.so_gpu /opt/PixInsight/bin/lib/libtensorflow.so.2.11.0
ln -sf /opt/PixInsight/bin/lib/libtensorflow_framework.so_gpu /opt/PixInsight/bin/lib/libtensorflow_framework.so.2.11.0

- switch back TensorFlow with support CPU only:
ln -sf /opt/PixInsight/bin/lib/libtensorflow.so.2.11.0_cpu /opt/PixInsight/bin/lib/libtensorflow.so.2.11.0
ln -sf /opt/PixInsight/bin/lib/libtensorflow_framework.so.2.11.0_cpu /opt/PixInsight/bin/lib/libtensorflow_framework.so.2.11.0

6) If everything goes well then GPU will be supporting calculations in RC Astro: NoiseXTerminator, StarXTerminator and BlurXTerminator
- GPU working:
obraz.png
- Comparison execution time CPU vs GPU:
obraz.png
Time execution reduced 10 times, from 1 hour to 6 minutes for image 18812x12276 RGB Float32!!!
Edited ...
Like
jml79 4.17
...
· 
·  1 like
·  Share link
Great write-up but I have it running with driver 560 and Cuda 12.6 with tensorflow 2.15. This is on a GTX 1070 but you can see the usage stats while I run a BlurX process on a 47MP image. Yes I am running Debian 12 with Gnome.

BlurX.jpg

From the RCAstro site they link to this guide on the PI forum.

https://pixinsight.com/forum/index.php?threads/procedure-to-enable-gpu-acceleration-for-bxt-starnet-etc-within-linux-mint-with-a-supported-nvidia-graphics-card.23356/
Edited ...
Like
JanBielanski 0.90
Topic starter
...
· 
·  Share link
Great! I tried earlier with TensorFlow 2.18.0 and 2.17.0 and CUDA 12.x and for both case my PixInsight crashed, so I linked that with CUDA version and API after checking this support table. Based on that knowledge and following topic for Gentoo (this libraries from topic work in Debian 12 after installing CUDA 11.8), I selected TensorFlow 2.14.1.
 Earlier on Gentoo Linux I had TensorFlow 2.11.0 from portage and it's work nice until developers removed it from portage and then I moved to Debian 11 and now Debian 12. Thank you for link, I will try this procedure with newest drivers.
                    
                
Like
JanBielanski 0.90
Topic starter
...
· 
·  Share link
CUDA 12 / TensoRT 8.6.1.6 / CUDNN 8.9.7.29 / NVIDIA DRIVER 570.133.07 + TensorFlow 2.15.1

- Notes:
--> no needed modification files in TesorFlow
--> no needed installation GCC-11
--> a bit more work with NVIDIA drivers:
- CUDA 12.2.2 - TensorFlow compile with this without error
- CUDA 12.8.0 - newest drivers can be installed and not influence work of CUDA 12.2.2
- CUDA 12.8.0 - 570.124.06 driver can be updated to 570.133.07
- NVIDIA-Linux-x86_64-570.133.07 - no contain all cuda driver files and TensorFlow not work if CUDA 12.8.0 - 570.124.06 not installed before installation this driver

- List of packages:
--> nVidia NEWEST drivers (20-03-2025) NVIDIA-Linux-x86_64-570.133.07.run

--> CUDA:
- CUDA 12.8.0 NEWEST [https://developer.nvidia.com/cuda-downloads] -> cuda_12.8.1_570.124.06_linux.run
- CUDA 12.2.2 supported by tensorflow 2.15.1 [https://developer.nvidia.com/cuda-downloads] -> cuda_12.2.2_535.104.05_linux.run
- CuDNN 8.9.7.29 supported by tensorflow 2.15.1 [https://developer.nvidia.com/downloads/compute/cudnn/secure/8.9.7/local_installers/12.x/cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz/] -> cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz
- TensorRT 8.6.1.6 supported by tensorflow 2.15.1 [https://developer.nvidia.com/nvidia-tensorrt-8x-download] -> TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-12.0.tar.gz


1) Uninstall NVIDIA drivers
--> Set Debian Linux into text mode and reboot
sudo systemctl set-default multi-user.target
    reboot

--> Uninstall all nVidia drivers and cuda
apt remove *nvidia*.deb *cuda*.deb

or
sh /usr/local/cuda-x.y/bin/cuda-uninstaller
    nvidia-uninstall


2) Install CUDA and NVIDIA DRIVERS

2a) Install CUDA 11.2.2 without driver
sudo sh cuda_12.2.2_535.104.05_linux.run

2b) Install driver from CUDA 12.8.0
sudo sh cuda_12.8.1_570.124.06_linux.run

2c) Install newest NVIDIA driver (will overwrite some driver files)
sudo sh NVIDIA-Linux-x86_64-570.133.07.run

2d) nvidia_as_primary.conf - copy to /etc/X11/xorg.conf.d/nvidia_as_primary.conf
Section "OutputClass"
        Identifier "nvidia"
        MatchDriver "nvidia-drm"
        Driver "nvidia"
        Option "PrimaryGPU" "yes"
    EndSection


2e) Make symlinks:
sudo ln -sf /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib64/libGL.so
    sudo ln -sf /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib64/libGLU.so


3) Install CUDNN and TensorRT
3a) cudnn-linux-x86_64-8.7.0.84_cuda11-archive.tar.xz -> extract files into /usr/local/{include,lib}
3b) TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-11.8.tar.gz -> extract into /opt/nvidia

-> sudo ln -sf /opt/nvidia/TensorRT-8.6.1.6 /opt/nvidia/tensorrt
    -> Create: /etc/ld.so.conf.d/989_tensorrt.conf

/opt/nvidia/tensorrt/lib

4) Change profile and reboot
systemctl set-default graphical.target
    reboot


5) After reboot check DRIVER and CUDA
nvidia-smi

+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 570.133.07             Driver Version: 570.133.07     CUDA Version: 12.8     |
|-----------------------------------------+------------------------+----------------------+
| 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 RTX A4000 Laptop GPU    On  |   00000000:01:00.0 Off |                  N/A |
| N/A   60C    P8             15W /   80W |     659MiB /   8192MiB |     33%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+


5) Build TensorFlow with GPU and support CUDA,CUDNN,TensorRT

5.1) Download tensorflow from git and switch to version v2.15.1:
-> git clone https://github.com/tensorflow/tensorflow.git
-> git checkout v2.15.1

or package:
-> https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.15.1.tar.gz
mv v2.15.1.tar.gz tensorflow-2.15.1.tar.gz
tar -xf tensorflow-2.15.1.tar.gz


5.2) Open terminal and export TMP directory:
export TMP=/tmp


5.3) Go to tensorflow-2.14.1 and start configuration:
./configure

Options for NVIDIA A4000:
Do you wish to build TensorFlow with ROCm support? [y/N]: N
    Do you wish to build TensorFlow with CUDA support? [y/N]: y
    Do you wish to build TensorFlow with TensorRT support? [y/N]: y
    [Leave empty to default to CUDA 11]: 12
    [Leave empty to default to cuDNN 2]: 8
    [Leave empty to default to TensorRT 6]: 8
    NCCL version you want to use. [Leave empty to use http://github.com/nvidia/nccl]:
    Please specify the comma-separated list of base paths to look for CUDA libraries and headers. [Leave empty to use the default]:
    /usr/include/,/usr/lib/x86_64-linux-gnu/,/usr/local/,/usr/local/include/,/usr/local/lib/,/usr/local/cuda/,/usr/local/cuda/include/,/opt/nvidia/tensorrt/,/opt/nvidia/tensorrt/include/
    Please note that each additional compute capability significantly increases your build time and binary size, and that TensorFlow only supports compute capabilities >= 3.5 [Default is: 8.6]: 8.6
    Do you want to use clang as CUDA compiler? [Y/n]: n
    Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
    Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: N


5.4) Build TensorFlow:
bazel build --config opt //tensorflow/tools/lib_package:libtensorflow --config=cuda --config=v2 --config=nonccl --verbose_failures


5.5) Libraries will be in:
tensorflow-2.15.1/bazel-bin/tensorflow/


6) Copy libraries to PixInsight
- make backup of original TensorFlow files in PixInsight:
sudo mv /opt/PixInsight/bin/lib/libtensorflow.so.2.11.0 /opt/PixInsight/bin/lib/libtensorflow.so.2.11.0_cpu
    sudo mv /opt/PixInsight/bin/lib/libtensorflow_framework.so.2.11.0 /opt/PixInsight/bin/lib/libtensorflow_framework.so.2.11.0_cpu



- copy new TensorFlow files with GPU support:
sudo cp bazel-bin/tensorflow/libtensorflow.so.2.15.1 /opt/PixInsight/bin/lib/libtensorflow.so_gpu
    sudo cp bazel-bin/tensorflow/libtensorflow_framework.so.2.15.1 /opt/PixInsight/bin/lib/libtensorflow_framework.so_gpu
    ln -sf /opt/PixInsight/bin/lib/libtensorflow.so_gpu /opt/PixInsight/bin/lib/libtensorflow.so.2.11.0
    ln -sf /opt/PixInsight/bin/lib/libtensorflow_framework.so_gpu /opt/PixInsight/bin/lib/libtensorflow_framework.so.2.11.0



- switch back TensorFlow with support CPU only:
ln -sf /opt/PixInsight/bin/lib/libtensorflow.so.2.11.0_cpu /opt/PixInsight/bin/lib/libtensorflow.so.2.11.0
    ln -sf /opt/PixInsight/bin/lib/libtensorflow_framework.so.2.11.0_cpu /opt/PixInsight/bin/lib/libtensorflow_framework.so.2.11.0

GPUPix.jpeg

Articles:
https://pixinsight.com/forum/index.php?threads/how-to-enable-gpu-acceleration-for-tools-such-as-starxterminator-blurxterminator-etc-on-gentoo-linux.23989/
https://pixinsight.com/forum/index.php?threads/procedure-to-enable-gpu-acceleration-for-bxt-starnet-etc-within-linux-mint-with-a-supported-nvidia-graphics-card.23356/
Edited ...
Like
 
Register or login to create to post a reply.