Does PyInstaller include CUDA - tensorflow

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?

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.

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.

Related

What is the difference between Tensorflow installation via source vs using pip?

I'm want to run tensorflow on a very standard machine setup (windows 64 bit) and have read that tensorflow has greater performance if built from source as it is optimised for your system. When installing tensorflow via pip for why does pip not select the optimal build for your system?
Also if you did install via pip is there a way or being able to tell whether the optimal build has been installed, or is the only way of knowing that simply remembering how you installed it?
Google has taken the position, that it is not reasonable to build TF for every possible instruction set out there. They only release generic builds for Linux, Mac and Windows. You must build from source if you want all the optimizations for your particular machine's instruction set.

Tensorflow can find right cudnn in one python file but fail in another

I am trying to use tensorflow gpu version to train and test my deep learning model. But here comes the problem. When I train my model in one python file things go on well. Tensorflow-gpu can be used properly. Then I save my model as a pretrained on as grapg.pb format and try to reuse it in another python file.
Then I got the following error messages.
E tensorflow/stream_executor/cuda/cuda_dnn.cc:363] Loaded runtime CuDNN
library: 7.1.4 but source was compiled with: 7.2.1. CuDNN library major
and minor version needs to match or have higher minor version in case of
CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN
library. If building from sources, make sure the library loaded at runtime
is compatible with the version specified during compile configuration.
I checked my cudnn version, in fact it is version 7.4.2. I also checked my environment path settings /cuda/v9.0/bin, cuda/v9.0/lib/x64, /cuda/v9.0/include are in there.
So why this happens? And how can I solve this?
--
cuda:v9.0
cudnn:7.4.2 (I think, I copy those cudnn files manually)
windows 10
python: 3.5
If you have multiple CuDNN installed thorough various ways like anaconda module and windows installation, you need to remove the older version in order for your code to detect the latest version and reinstall tensorflow-gpu.
You can follow this guide for installation based on OS.

ImportError: Could not find 'cudart64_90.dll'. TensorFlow [duplicate]

I installed CUDA 9.0 because without it, Tensorflow gives the error:
ImportError: Could not find 'cudart64_90.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable.
I have the path variable set to the bin directory of CUDA 9.0 installation, where the required DLL file is present. I tried setting it to its parent directory too. But it still gives me the same error.
I found the solution. And it was the good old advice - "Have you tried turning it off and on again?"
I restarted the computer, Tensorflow found cudart64_90.dll, but now it could not find cudnn64_7.dll. I'm providing the steps ahead to get rid of the issues I encountered.
If you've installed Tensorflow GPU version, you're likely to run into the problem mentioned in the post. Especially if you've not installed NVDIA development toolkits before. Follow these steps:
1. Install CUDA
Get it from here. Install only the version mentioned in Tensorflow's ImportError.
ImportError: Could not find 'cudart64_90.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 9.0 from this URL: https://developer.nvidia.com/cuda-toolkit
It explicitly tells you the version number. Initially, I installed CUDA 9.1 instead of 9.0, it didn't work. The installation on Windows is straight forward. Run the .exe, uncheck NVIDIA Geforce and other packages if you already have them installed.
2. Include CUDA path in PATH variable
Point it to the bin directory of your tensorflow installation.
Check here if you don't know how to set the PATH variable. Now try importing Tensorflow, if it still doesn't work, try rebooting the system.
Now you will likely run into the error:
ImportError: Could not find 'cudnn64_7.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Note that installing cuDNN is a separate step from installing CUDA, and this DLL is often found in a different directory from the CUDA DLLs. You may install the necessary DLL by downloading cuDNN 7 from this URL: https://developer.nvidia.com/cudnn
3. Install cuDNN
Once again, only install the version mentioned in the error.To get the installer, you need to have an NVIDIA developer account. If you don't have it, sign up and it will direct you to the link to download cuDNN. Select the version compatible with your CUDA version (it's in the package name). Download the zip archive. Extract it somewhere on your disk.
4. Include cuDNN path in PATH variable
Similar to step two. This time, point it to the bin directory in your extracted archive of cuDNN. Now import Tensorflow. Restart system if required.
It should now work.
When I reached to step 3, I copied and pasted the files inside the archive
as in here
Copy <installpath>\cuda\bin\cudnn64_7.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin.
Copy <installpath>\cuda\ include\cudnn.h to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include.
Copy <installpath>\cuda\lib\x64\cudnn.lib to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64.
I had the same problem for a couple hours as well. Just restarted my computer and that fixed the issue you were having, so give that a try.
Always check the cuda version, in this case you have to install cuda version 9.0 this will create the cudart64_90.dll file in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin folder.
This will surely work.

cuda dll files not found

I am using zed camera for 3D mapping(https://www.stereolabs.com/). The camera comes with a software devolopment kit. The development kit makes use of Nvidia graphics card and CUDA7.5 toolkit. The SDK setup automatically checks for CUDA on pc and installs it if not present.
The problem I am facing is that when I run the software it gives an error messages that it cannot find nppi64_75.dll, cudart64_75.dll, nppc64_75.dll. However, CUDA 7.5 is already installed and I can see these dll files in "NVIDIA GPU Computing Toolkit" folder in the same drive. But why the software cannot find these files? And what should I do? I am using windows 10, 64 bit. I have tried reinstalling the software and CUDA toolkit but it doesn't work and it works easily on other computers.
Note: I would like to mention that earlier I had some problem with the camera drivers and camera wasn't working but the software was able to locate the CUDA dll files. I uninstalled everything including CUDA toolkit and reinstalled and now i am stuck with this problem.
However, cuda 7.5 is already installed and i can see these dll files in "NVIDIA GPU Computing Toolkit" folder in the same drive. But why the software cannot find these files?
The DLLs are not found, because the CUDA Computing Toolkit installation folder is not a standard search path. Either add it to the system's PATH environment variable, or copy the DLLs into the same folder in which your .exe resides. You can also implement a wrapper .bat file that sets path accordingly (just for that invocation) and then launches the program.

Is it safe to install Tensorflow in an existing Conda environment?

I am looking into using Tensorflow for my research soon, and looked at the online documentation for installing with Conda https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html#anaconda-installation.
It suggested creating a new environment, and installing Tensorflow in it, and the installing other python packages afterwards.
But I already have an existing environment with lots of packages I need, and I'm wondering if its safe to add Tensorflow into that environment?
Also, I have a question about how this installation with conda works. I know that Conda will create a distinct set of folders containing the libraries needed for each environment, but if I install Tensorflow, what happens to all the base low level C++ and CUDA libraries that get compiled? Do they reside in my Conda environment's folder, or are they in some system wide libraries closer to my root?
PS: I'm using Ubuntu 16.04, and have a GPU that I want to run Tensorflow on.
Thank you.
But I already have an existing environment with lots of packages I need, and I'm wondering if its safe to add Tensorflow into that environment?
conda has this awesome feature called "revisions". You can show your current environment with
conda list --revisions
which allows you to revert changes to your conda environment. This allows you to install new packages with confidence that if something breaks you can always revert it later. See this page for more info: https://www.continuum.io/blog/developer/advanced-features-conda-part-2. tl;dr: conda install --revisions <revision_number>
what happens to all the base low level C++ and CUDA libraries that get compiled
Are you talking about the libraries that get compiled when you are trying to run your code? Or the C++/CUDA libraries? If you're talking about the C++/CUDA libs then conda is not compiling them, but merely installing a pre-compiled binary into a specific location that gets picked up. If you're talking about your code, then where exactly those files live would seem to depend on where you put them.