3

I am working on a Python script (I use Python 3.7.3) that uses tensorflow-gpu (1.14.0) and used PyInstaller 3.5 to convert this script to an executable. I am using CUDA 10.0 and cuDNN 7.6.1 and my graphics card is a NVIDIA GeForce GTX 960M. I recently deinstalled CUDA to test if the executable of the Python script still runs and surprisingly it still runs via GPU, which does not work when I now run the Python script directly.

My question is, can this executable be run on systems without the CUDA toolkit but with a CUDA-capable graphics card?

disputator1991
  • 165
  • 5
  • 13
  • What does " without CUDA" mean? Without the CUDA toolkit? Without the CUDA driver? – talonmies Nov 28 '19 at 08:37
  • I was under the impression that the CUDA toolkit includes the CUDA driver? In any case I am talking about the toolkit. – disputator1991 Nov 28 '19 at 10:07
  • 1
    On some platforms it does, but uninstalling the toolkit doesn't remove the driver. In that case I would guess that PyInstaller produces statically linked executable code (which CUDA also supports on most platforms) – talonmies Nov 28 '19 at 10:09
  • I am running everything on Windows 10 and verified the correct deinstallation of the CUDA toolkit by the nvcc -V command. Since my Python scripts relying on tensorflow-gpu are not running any longer since the deinstallation, am I to assume that the driver was also uninstalled? – disputator1991 Nov 28 '19 at 10:18
  • 1
    No. Uninstalling the toolkit removes the dynamic libraries which the Python scripts rely on, breaking them. But your executable *probably* has the static version of all the CUDA libraries linked into it, so it is unaffected. I have never heard of PyInstaller and know nothing about how it works, but that is the only explanation I can think of. – talonmies Nov 28 '19 at 10:22

2 Answers2

1

According to this documentation PyInstaller will make and store a private copy of all of the dependent external libraries which Python code relies on when building a single file executable.

Therefore it is safe to assume that your executable runs irrespective of the installation status of the CUDA toolkit because it has a full private copy of the necessary CUDA libraries internally which it uses when the executable is run.

talonmies
  • 70,661
  • 34
  • 192
  • 269
  • The documentation linked simply explains how the generated exe file works after being created with the `--onefile` option. It doesn't describe how the exe is created and what (and how) is included in the process. – Aelius Dec 14 '22 at 16:01
0

According to the GitHub issues in the official repository (here and here for example) CUDA libraries are usually dynamically loaded at run-time and not at link-time, so they are typically not included in the final exe file (or folder) with the result that the exe file won't work on a machine without CUDA installed. The solution (please refer to the linked issues too) is to put the DLLs necessary to run the exe in its dist folder (if generated without the --onefile option) or install the CUDA runtime on the target machine.

The behaviour that you're experimenting maybe it's due to the specific version of TF, that loads the libraries in a different fashion with respect to what described above, but it's not the expected behaviour nowadays.

Aelius
  • 1,029
  • 11
  • 22