tensorflow Mac OS gpu support - macos

According to
https://www.tensorflow.org/install/install_mac Note: As of version 1.2, TensorFlow no longer provides GPU support on Mac OS X.
GPU support for OS X is no longer provided.
However, I would want to run an e-gpu setup like akitio node with a 1080 ti via thunderbolt 3.
What steps are required to get this setup to work?
So far I know that
disable SIP
run automate e-gpu script https://github.com/goalque/automate-eGPU
are required. What else is needed to get CUDA / tensorflow to work?

I wrote a little tutorial on compiling TensorFlow 1.2 with GPU support on macOS. I think it's customary to copy relevant parts to SO, so here it goes:
If you haven’t used a TensorFlow-GPU set-up before, I suggest first setting everything up with TensorFlow 1.0 or 1.1, where you can still do pip install tensorflow-gpu. Once you get that working, the CUDA set-up would also work if you’re compiling TensorFlow. If you have an external GPU, YellowPillow's answer (or mine) might help you get things set up.
Follow the official tutorial “Installing TensorFlow from Sources”, but obviously substitute git checkout r1.0 with git checkout r1.2.
When doing ./configure, pay attention to the Python library path: it sometimes suggests an incorrect one. I chose the default options in most cases, except for: Python library path, CUDA support and compute capacity. Don’t use Clang as the CUDA compiler: this will lead you to an error “Inconsistent crosstool configuration; no toolchain corresponding to 'local_darwin' found for cpu 'darwin'.”. Using /usr/bin/gcc as your compiler will actually use Clang that comes with macOS / XCode. Below is my full configuration.
TensorFlow 1.2 expects a C library called OpenMP, which is not available in the current Apple Clang. It should speed up multithreaded TensorFlow on multi-CPU machines, but it will also compile without it. We could try to build TensorFlow with gcc 4 (which I didn’t manage), or simply remove the line that includes OpenMP from the build file. In my case I commented out line 98 of tensorflow/third_party/gpus/cuda/BUILD.tpl, which contained linkopts = [“-lgomp”] (but the location of the line might obviously change). Some people had issues with zmuldefs, but I assume that was with earlier versions; thanks to udnaan for pointing out that it’s OK to comment out these lines.
I had some problems building with the latest bazel 0.5.3, so I reverted to using 0.4.5 that I already had installed. But some discussion in a github issue mentioned bazel 0.5.2 also didn’t have the problem.
Now build with bazel and finish the installation as instructed by the official install guide. On my 3.2 GHz iMac this took about 37 minutes.
Using python library path: /Users/m/code/3rd/conda/envs/p3gpu/lib/python3.6/site-packages
Do you wish to build TensorFlow with MKL support? [y/N] N
No MKL support will be enabled for TensorFlow
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]:
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N]
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/N]
No Hadoop File System support will be enabled for TensorFlow
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]
No XLA support will be enabled for TensorFlow
Do you wish to build TensorFlow with VERBS support? [y/N]
No VERBS support will be enabled for TensorFlow
Do you wish to build TensorFlow with OpenCL support? [y/N]
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] y
CUDA support will be enabled for TensorFlow
Do you want to use clang as CUDA compiler? [y/N]
nvcc will be used as CUDA compiler
Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to use system default]:
Please specify the location where CUDA toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Please specify the cuDNN version you want to use. [Leave empty to use system default]:
Please specify the location where cuDNN library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: "3.5,5.2"]: 6.1
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.
Configuration finished

Assuming that you have already setup your eGPU box and attached the TB3 cable from the eGPU to your TB3 port:
1. Download the automate-eGPU script and run it
curl -o ~/Desktop/automate-eGPU.sh
https://raw.githubusercontent.com/goalque/automate-eGPU/master/automate-eGPU.sh
&& chmod +x ~/Desktop/automate-eGPU.sh && cd ~/Desktop && sudo
./automate-eGPU.sh
You might get an error saying:
"Boot into recovery partition and type: csrutil disable"
All you need to do now is to restart your computer and when it's restarting hold down cmd + R to enable the recovery mode. Then locate the Terminal while in recovery mode and type in:
csrutil disable
Then restart your computer and re-run the automate-eGPU.sh script
2: Download and installing CUDA
CUDA: https://developer.nvidia.com/cuda-downloads
Run the cuda_8.0.61_mac.dmg file and follow through the installation phase. Then afterwards you will need to set the paths.
Go to your Terminal and type:
vim ~/.bash_profile
Or whether you have stored your environmental variables and then add these three lines:
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH="$CUDA_HOME/lib:$CUDA_HOME:$CUDA_HOME/extras/CUPTI/lib"
export LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
3. Downloading and installing cuDNN
cuDNN: https://developer.nvidia.com/cudnn
To download cuDNN is a bit more troublesome you have to sign up to be a developer for Nvidia and then afterwards you can download it. Make sure to download cuDNN v5.1 Library for OSX as it's the one that Tensorflow v1.1 expects Note that we can't use Tensorflow v1.2 as there is no GPU support for Macs :((
[![enter image description here][1]][1]
Now you will download a zip file called cudnn-8.0-osx-x64-v5.1.tgz, unzip and, which will create a file called cuda and cd to it using terminal. Assuming that the folder is in Downloads
Open terminal and type:
cd ~/Downloads/cuda
Now we need to copy cuDNN files to where CUDA is stored so:
sudo cp include/* /usr/local/cuda/include/
sudo cp lib/* /usr/local/cuda/lib/
4. Now install Tensorflow-GPU v1.1 in your conda/virtualenv
For me since I use conda I created a new environment using Terminal:
conda create -n egpu python=3
source activate egpu
pip install tensorflow-gpu # should install version 1.1
5. Verify that it works
First you have to restart your computer then:
In terminal type python and enter:
import tensorflow as tf
with tf.device('/gpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
with tf.Session() as sess:
print (sess.run(c))
If you have a GPU this should run with no problem, if it does then you should get a stack trace (just a bunch of error messages) and it should include
Cannot assign a device to node 'MatMul': Could not satisfy explicit device specification '/device:GPU:0' because no devices matching that specification are registered in this process
If not then you're done congratz! I just got mine set up today and it's working perfectly :)

I could finally make it work with the following setup
Hardware
Nvidia Video Card: Titan Xp
EGPU: Akitio Node
MacBook Pro (Retina, 13-inch, Early 2015)
Apple Thunderbolt3 to Thunderbolt2 Adapter
Apple Thunderbolt2 Cable
Software versions
macOS Sierra Version 10.12.6
GPU Driver Version: 10.18.5 (378.05.05.25f01)
CUDA Driver Version: 8.0.61
cuDNN v5.1 (Jan 20, 2017), for CUDA 8.0: Need to register and download
tensorflow-gpu 1.0.0
Keras 2.0.8
I wrote a gist with the procedure:
https://gist.github.com/jganzabal/8e59e3b0f59642dd0b5f2e4de03c7687

Here is my solution to install an e-gpu on a mac. Tensorflow doesn't support tensorflow-gpu anymore, so there are definitely better approaches to get it working:
My configuration:
IMac 27' late 2012
Aktio Node
GTX 1080 ti
3 Screens: One of them connected to the GTX 1080 and the others directly plugged on the mac.
Advantages of windows bootcamp installation:
You can use pip to install tensorflow-gpu.
Good GPU 1080 ti support (Downloadable display driver)
Howto:
Install windows 10 with bootcamp. Do not connect the Akito node for the moment.
Download and install the display driver for your gpu from NVIDIA download page
Install Visual Studio
If you want to use CUDA 9.x you can install Visual Studio 2017
Otherwise install Visual Studio 2015
Install CUDA and CuDNN
Note that the tensorflow-gpu version must match with your Cuda and your CudNN version. See available tensorflow releases here.
After the CUDA installation you can move the unpacked CuDNN files to the CUDA folder at: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0. Move the lib files to the lib folder, the bin files to the bin folder and the include files to the include folder.
Install Python 3.5+
You need a 64-bit version to install tensorflow-gpu with pip
Python 2.7 won't work.
Install tensorflow with pip:
Command:
pip install tensorflow-gpu==1.5.0rc0
Check your installation
The display driver has been installed correctly when you can plug a screen to the GTX 1080 ti card.
Call C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe to check if your video card is available for CUDA.
Execute the following tensorflow command to see available devices:
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
Troubleshooting and hints:
Windows wants to update your GTX 1080 driver. Never allow that because you
won't be able to startup your computer again! A black screen with moving dots will appear before you can login to windows. Game over! Only use the display driver from NVIDIA download page.
If you cannot start windows on OSX anymore, press the alt key at startup to reinstall windows.
Ubuntu solution:
I couldn't find a working solution but here are some approaches:
It seems that my GTX 680 (iMac) and my GTX 1080 ti won't work together. Ubuntu could not be started anymore after installing the display driver via apt-get: Ubuntu not starting anmore. Try to download the official display driver from NVIDIA download page.
OSX Solution:
Tensorflow GPU is only supported up to tensorflow 1.1. I tried to install a newer version but couldn't build tensorflow-gpu with cuda support. Here are some approaches:
Install OSX Sierra to use the e-gpu script. High Sierra won't work (Jan, 13 2018). Downgrade to sierra by deleting all your partitions. Then press Command + R at startup to load the internet recovery. Don't forget to backup your data first.
Install e-gpu script.
If tensorflow-gpu 1.1 is enough for you, you can just install via pip, otherwise you need to build your pip with bazel.
Conclusion:
The windows installation is easier than OSX or Ubuntu installation because display drivers work properly and tensorflow and must not be build on your own. Always check the software version you use. The must match exactly.
I hope this will help you!

Related

Is it possible to build and install the TensorFlow 2.0 gpu on macOS?

I'm trying to use TensorFlow on High Sierra 10.13.6, but TensorFlow 1.8 didn't build through at all. So I wanted to build a newer version of TensorFlow, but there are no published instructions on the net for building a newer version of TensorFlow than TensorFlow 1.8.
Does this mean that versions newer than 1.8 can't be used on Mac?
According to TensorFlow 2 Install guide, It is tested and supported on the macOS 10.12.6 (Sierra) or later (no GPU support).
Tested build configurations for macOs GPU are
Accoring to GPU support, it is available for Ubuntu and Windows with CUDA®-enabled cards.
If you are looking to build a TensorFlow pip package from source and install it on macOS. Please refer office guide.

Build Tensorflow on one system, deploy on another

How can I deploy TensorFlow on a different computer from the one I build it on? Which files need to be copied across? Building from source on each and every target PC is impractical. In my case I need to build from source since the standard install of TensorFlow is not optimized for my target (non-GPU build but with AVX/AVX2 available), not that that should make any difference. I am building & deploying on Windows PCs, which almost certainly will make a difference.
Think: python. Tensorflow is essentially a python package, and python packages are installed with pip.
In this specific case, the standard installation of TensorFlow (version 1.5) was easily installed on my target system using pip3 install --upgrade tensorflow as per standard TensorFlow instructions. But when I tested examples I had already developed I was warned that the install was not optimal, since AVX and AVX2 instructions were available, but not being used.
To rebuild Tensorflow from source to make use of AVX2, follow instructions here, in particular:
Obtain the source from github: git clone https://github.com/tensorflow/tensorflow
Choose either the Bazel or CMake build option (I chose CMake, which required SWIG)
Customise the build to specify use of AVX or AVX2 (for me, I added -Dtensorflow_WIN_CPU_SIMD_OPTIONS=/arch:AVX2 to the options during the CMake step)
build the tensorflow python pip package (very last instruction in the CMake step-by-step instructions)
Once you have the package (a wheel or .whl) file, move it to the target PC, and install it using pip3 install tensorflow-<version-specific-details>.whl.
This process has been tested on:
Development PC: Windows 7-64 bit, Python 3.6.4 (64-bit), SWIG 3.0.12
Target PC: Windows 8.1 Pro (64-bit), Python 3.6.4 (64-bit)
For the record, the use of AVX2 instructions gave me approximately a 20% speed increase on my network training. Also, despite one of the known limitations being the need to use Python 3.5 for the CMake build, I have found no issue (so far) using Python 3.6.4.

Installation of gstreamer bad plugins and opencv3.3 on Ubuntu 16.04 arm64

I have been working on some video playing/streaming pipelines for Computer Vision work on Nvidia Jetson TX2. It had Ubuntu 16.04 with latest Jetpack.
I have already installed opencv 3.3 and to test some of the pipelines, with .MP$ video files, I need h264parse plugin which is a part of gst-bad-plugins. However, when I try to install it using apt-get, it shows that following packages will be installed:
freepats gstreamer1.0-plugins-bad-faad gstreamer1.0-plugins-bad-videoparsers
libbs2b0 libde265-0 libflite1 libfluidsynth1 libgstreamer-plugins-bad1.0-0
libmimic0 libmjpegutils-2.1-0 libmms0 libmpeg2encpp-2.1-0 libmplex2-2.1-0
libofa0 libopenal-data libopenal1 libopencv-calib3d2.4v5
libopencv-contrib2.4v5 libopencv-core2.4v5 libopencv-features2d2.4v5
libopencv-flann2.4v5 libopencv-highgui2.4v5 libopencv-imgproc2.4v5
libopencv-legacy2.4v5 libopencv-ml2.4v5 libopencv-objdetect2.4v5
libopencv-video2.4v5 libsoundtouch1 libspandsp2 libsrtp0 libvo-aacenc0
libvo-amrwbenc0 libwildmidi-config libwildmidi1 libzbar0
Here it tries to install an older version of opencv and this really messes up with my current opencv (v3.3) install.
Does anyone have any idea on how should I overcome this problem. I would not want the option to just ignore all the dependencies. But somehow, if it detects the installed opencv version, that would be awesome.
Any help is appreciated.
Thanks!
I am working on Jetson Tx1 , and have problem installing opencv 3.3 in virtual environment onto it due to space issues. I tried to compile the build file from external sd card and make from there. Then Sym-link (cv2.so) file to appropriate path. Can you tell me how you were able to install opencv3.3 ??

is it possible to code CUDA at virtual box Win8?

I know that by using virtual box, graphics card cannot be utilized by all the measures so I think it is not possible but I also think that coding cuda at least setting the CUDA developing environment is easier at Windows (unfortunately) thus if it is possible I plan to setup win8 to virtual box on my Ubuntu.
I do want to use win since I am at optimus Nvidia machine thus there is a driver problem at Ubuntu. In addition compilation of the code at Eclipse does not work due to that driver flaw. In case I use Win there might be the remedy of the problem.
Even if you get success in setting up environment in your virtual box to compile cuda code and you compiled cuda code there it will be of no use because you wont be able to run the code in virtual box.
Yes, your are absolutely right that installing drivers on optimus nvidia card is difficult task. I was also stuck with the same problem. but with release of cuda 5, installing cuda on Ubuntu is very simple.
follow these simple steps.
Driver installation ##
Download cuda 5 from here.(32bit or 64bit depending on OS)
Cuda 5 download
Install required tools by following command
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
Next, blacklist the unnecessary modules
sudo gedit /etc/modprobe.d/blacklist.conf
add following lines at last
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv
and reboot your system.
After reboot press Ctrl+Alt+F1. Login there and enter following command.
service lightdm stop
Go to location where you have downloaded cuda 5. In my case its on desktop.
cd Desktop
make it run from shell
chmod +x cuda_5.3.35_linux*****
Run from terminal
./cuda_5.3.35_linux*****
accept it, when asked to install drivers press y and n for cudatoolkit and gpucomputingsdk
now reboot and you are done with driver installation.
To install cudatoolkit and gpucomputingsdk follow this link
Cuda 4.2 installation on Ubuntu

Installing openCV on Lion OS 10.7.4 Xcode 4.3.2

I'm trying to install openCV on university's iMac,
but the problem is our university's network is so strict.
and I couldn't install openCV using MacPorts.
I tried google to look for a way to install but it all failed
i guess because it is kind of old ways and because my network is so strict.
So if anybody knows a way that I can download a ready framework with how to use it inside
Xcode. or at least a framework with how to install it to work with Xcode.
or a way to download from the source and compile it then install it in Xcode
please.
Because I tried the cmake way and I still have no luck to get it work.
thanks in advance.
sources I used:
http://salemsayed.me/?p=240
http://opencv.willowgarage.com/wiki/InstallGuide
http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port
http://www.ient.rwth-aachen.de/cms/software/opencv/
I'm using Lion + Xcode 4.x branch, with OpenCV svn trunk. Everything works fine. You have to install cmake first, then get the code from the svn following the instructions at http://code.opencv.org . The compilation process worked fine for me for all the core modules + the Qt module + the GPU module + TBB acceleration.
The instructions are the same as the Linux platform.
After setting up cmake configuration in a terminal (using ccmake for a more interactive tool),
I set the architecture to x86_64 (on my MBP Core 2 Duo), the target directory to /usr/local/(the default), and I have Intel TBB installed in /usr/local/.
Cmake generates the makefiles for you, so you just have to type make -j2 to compile, then sudo make install. If you're working on a workstation, then you have more CPU power, and you can replace the value 2 by more, e.g. 8.

Resources