31

I would like to know what the external GPU (eGPU) options are for macOS in 2017 with the late 2016 MacBook Pro.

I did my research, however on the internet I find a lot of confusing information. Some say it can work, but it requires Windows (dual-boot). Others say, it can only work for the older graphics cards as CUDA is not supported for the newer graphics cards (GTX 1080). Ideally, I would like to run the 1080 GTX of NVIDIA. My only purpose is to use Keras and TensorFlow with it. However, I do not know all the things that are important to get it to work. My question therefore is, is it possible to use TensorFlow with CUDA and eGPU on the late MacBook Pro 2016 (15")? I want to use the graphics card in macOS (with late MacBook Pro 15") as an eGPU (no dual-boot/Windows/Linux partition).

Side note: I have seen users making use of eGPU's on macbook's before (Razor Core, AKiTiO Node), but never in combination with CUDA and Machine Learning (or the 1080 GTX for that matter). People suggested renting server space instead, or using Windows (better graphics card support) or even building a new PC for the same price that allows you to use a eGPU on Mac. (I do not prefer that option.)

  • CUDA on the 1080 most definitely does work. I was training a network on a 1080 earlier this morning using Keras with TensorFlow backend (on Ubuntu, but still). – brendon-ai Aug 23 '17 at 13:35
19

I could finally install Nvidia Titan XP + MacBook Pro + Akitio Node + Tensorflow + Keras

I wrote a gist with the procedure, hope it helps

https://gist.github.com/jganzabal/8e59e3b0f59642dd0b5f2e4de03c7687

Here is what I did:

This configuration worked for me, hope it helps

It is based on: https://becominghuman.ai/deep-learning-gaming-build-with-nvidia-titan-xp-and-macbook-pro-with-thunderbolt2-5ceee7167f8b

and on: https://stackoverflow.com/questions/44744737/tensorflow-mac-os-gpu-support

Hardware

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

Procedure:

Install GPU driver

  1. ShutDown your system, power it up again with pressing (⌘ and R) keys until you see , this will let you in Recovery Mode.
  2. From the Menu Bar click Utilities > Terminal and write ‘csrutil disable; reboot’ press enter to execute this command.
  3. When your mac restarted, run this command in Terminal:

    cd ~/Desktop; git clone https://github.com/goalque/automate-eGPU.git
    chmod +x ~/Desktop/automate-eGPU/automate-eGPU.sh
    sudo ~/Desktop/automate-eGPU/./automate-eGPU.sh
    
  4. Unplug your eGPU from your Mac, and restart. This is important if you did not unplug your eGPU you may end up with black screen after restarting.

  5. When your Mac restarted, Open up Terminal and execute this command:

    sudo ~/Desktop/automate-eGPU/./automate-eGPU.sh -a
    
    1. Plug your eGPU to your mac via TH2.
    2. Restart your Mac.

Install CUDA, cuDNN, Tensorflow and Keras

At this moment, Keras 2.08 needs tensorflow 1.0.0. Tensorflow-gpu 1.0.0 needs CUDA 8.0 and cuDNN v5.1 is the one that worked for me. I tried other combinations but doesn't seem to work

  1. Download and installing CUDA 8.0 CUDA Toolkit 8.0 GA2 (Feb 2017)
  2. Install it and follow the instructions
  3. Set env variables

    vim ~/.bash_profile
    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
    

(If your bash_profile does not exist, create it. This is executed everytime you open a terminal window)

  1. Downloading and installing cuDNN (cudnn-8.0-osx-x64-v5.1) Need to register before downloading it
  2. Copy cuDNN files to CUDA

    cd ~/Downloads/cuda
    sudo cp include/* /usr/local/cuda/include/
    sudo cp lib/* /usr/local/cuda/lib/
    
  3. Create envirenment and install tensorflow

    conda create -n egpu python=3
    source activate egpu
    pip install tensorflow-gpu==1.0.0
    
  4. Verify it works

Run the following script:

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))
  1. Install Keras in the envirenment and set tensorflow as backend:

    pip install --upgrade --no-deps keras # Need no-deps flag to prevent from installing tensorflow dependency
    KERAS_BACKEND=tensorflow python -c "from keras import backend"
    

    Output:

    Using TensorFlow backend.
    I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.8.0.dylib locally
    I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.5.dylib locally
    I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.8.0.dylib locally
    I tensorflow/stream_executor/dso_loader.cc:126] Couldn't open CUDA library libcuda.1.dylib. LD_LIBRARY_PATH: /usr/local/cuda/lib:/usr/local/cuda:/usr/local/cuda/extras/CUPTI/lib
    I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.dylib locally
    I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.8.0.dylib locally
    
  • do you need an external monitor for this? Or you don't? – Abhimanyu Aryan Nov 19 '17 at 8:25
  • @AbhimanyuAryan, there is no need for external monitor. This is just to use the eGPU with tensorlfow and/or keras – Julian Nov 19 '17 at 20:15
  • Does this also work with Mac OS 10.13. I see they only have CUDA 9 updated for 10.13, and Cuda 8 is only for 10.12. I'm trying to see wether I could get this to run TuriCreate on GPU. – Niklas Dec 20 '17 at 22:28
  • Have you compare the performance against PC? – Angus Tay Aug 30 '18 at 1:31
  • Anyone tried this with BlackMagic eGPU? – Pratik Khadloya Sep 8 '18 at 21:04
9

I was able to get a NVIDIA GTX 1080 Ti working on the Akitio Node on my iMac (late 2013). I'm using a Thunderbolt 2 > 3 adapter, though on newer Macs you can use the faster TB3 directly.

There are various eGPU set-ups described at eGPU.io, and you might find one that describes your computer/enclosure/card precisely. These tutorials are mostly for accelerating a display with an eGPU, though for training NNs you don't obviously need to follow all the steps.

Here's roughly what I did:

  • Install CUDA according to official documentation.
  • Disable SIP (Google for a tutorial). It's needed by the eGPU.sh script and later also by TensorFlow.
  • Run the automate-eGPU.sh script (with sudo) that everybody at eGPU.io seems to rely on.
  • Install cuDNN. The files from NVIDIA's website should go under /usr/local/cuda with the rest of your CUDA libraries and includes.
  • Uninstall CPU-only TensorFlow and install one with GPU support. When installing with pip install tensorflow-gpu, I had no installation errors, but got a segfault when requiring TensorFlow in Python. Turns out there are some environment variables that have to be set (a bit differently than the CUDA installer suggests), which were described in a GitHub issue comment.
  • I also tried compiling TensorFlow from source, which didn't work before I set the env vars as described in the previous step.

From iStat Menus I can verify that my external GPU is indeed used during training. This TensorFlow installation didn't work with Jupyter, though, but hopefully there's a workaround for that.

I haven't used this set-up much so not sure about the performance increase (or bandwidth limitations), but eGPU + TensorFlow/CUDA certainly is possible now, since NVIDIA started releasing proper drivers for macOS.

  • A word of warning: from TensorFlow 1.2 onwards, they are not providing official tensorflow-gpu pip packages. This means we need to build it from sources, which in my experience never works right away. Hopefully there will be 3rd party tutorials on how to compile major releases, but for now I can't for example upgrade to 1.2 or 1.3 if I still want to use my GPU. – Mattias Arro Aug 3 '17 at 15:45
  • 3
    Managed to compile tensorfow 1.2 from source. Wrote a little tutorial on it: medium.com/@mattias.arro/… – Mattias Arro Aug 4 '17 at 14:20
3

eGPU support on macOS is a difficult topic, but I will do my best to answer your question.

Let's begin with graphics cards! For the sake of time, and because we're talking CUDA, we'll stick with Nvidia cards. Any graphics card will work with the proper drivers on Windows. Apple, however, only officially supports a few Nvidia graphics cards, mainly very old ones. However, the Nvidia graphics drivers actually work on almost all of Nvidia's GeForce and Quadro cards, with one big exception. GTX 10xx cards WILL NOT WORK. On any Mac operating system. Period. Nvidia's drivers don't support this card. If you're looking for power, you'll want to look at the GTX 980Ti or Titan X (many good Quadro cards would also work well).

Now that we've got that covered, let's move onto eGPU enclosures. I'm going to assume, because you mentioned specifically eGPUs, that you've budgeted for an actual eGPU enclosure (let's use the AKiTiO Node as an example), instead of a PCIe expansion chassis with an external power supply, as this is not a great idea.

So now we have a graphics card (GTX 980Ti) in an eGPU enclosure (AKiTiO Node) and we want to get it to work. Well, that's easier said than done. I did a bit of eGPU researching towards the end of 2016, and the information I got was relatively confusing, so if anyone has any comments or corrections, please let me know. From what I understand, to utilize the power of the eGPU, you need to plug an external monitor into the eGPU. I don't believe you can run the eGPU without an external monitor in macOS. You will also not see Apple's boot screen on the eGPU-connected monitor (unless you buy a flashed card from MacVidCards), but you should then be able to use the eGPU to drive your graphics.

Assuming you do all of this successfully, you should have a very high powered CUDA-enabled graphics powerhouse.

  • Thank you for the information. The combination of 980 Ti with an eGPU enclosure seems like a viable option. The only thing is, the Akitio Node (3) seems discontinued and the Razor Core does not ship. Which eGPU enclosure can actually be bought? Akitio Node 2? – Joop Mar 25 '17 at 7:38
  • 2
    Well Bizon Box is designed for it, but it's like $500. Let me do some looking... – NoahL Mar 25 '17 at 7:54
  • 1
    This link might make for some good reading too: appleinsider.com/articles/17/01/17/… – NoahL Mar 25 '17 at 8:00
  • Is "10XX" series really not working on mac? I have heard others (including another answer here) used 1080ti on mac... – Blaszard Jul 31 '18 at 15:12
  • As of this answer, absolutely. 10xx series Mac drivers weren’t released until a full year after the cards were (sometime in late 2017 or early 2018, if I remember correctly) – NoahL Jul 31 '18 at 15:17
2

I recently did it with OSX 10.13.6 for pytorch and fastai. See my gist here: https://gist.github.com/dandanwei/18708e7bd5fd2b227f86bca668343093

1

If you are using macOS 10.13.3, check this link. It covers everything from eGPU setup to TensorFlow compile.

  • macOS: 10.13.3
  • WebDriver: 387.10.10.10.25.156
  • CUDA Toolkit: 9.1.128
  • cuDNN: 7
  • NVDAEGPUSupport: 6
  • XCode: 8.2
  • Bazel: 0.9.0
  • OpenMP: latest
  • Python: 3.6
  • TensorFlow: 1.5.0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .