Incubator-mxnet: Installing GPU support on Mac

Created on 28 Dec 2017  路  30Comments  路  Source: apache/incubator-mxnet

Anyone managed to install GPU support on macOS? I've got an eGPU running with NVIDIA card. Installed CUDA 9 with cuDNN (version 8 does not seem to run on macOS 10.13.2).

I've read some posts saying that CUDA 9 was supported from MXNET v 0.12.

Running a command like pip install mxnet-cu90 does not work though.

Call for Contribution Doc

Most helpful comment

@cosmo

  1. Download Xcode8.3.3 from Apple. This is the version NVIDIA state for Cuda 9.1 Mac. Unzip and rename to Xcode8.3.3.app.
  2. Run sudo xcode-select -s /Applications/Xcode8.3.3.app or to wherever you have placed Xcode.
  3. Run xcode-select --install to install all command line tools compilers etc.
  4. Run git clone --recursive https://github.com/apache/incubator-mxnet.git mxnet to get the latest version currently 1.0.1 which worked for me.
  5. cd mxnet
  6. Edit the make/osx.mk file to set
    USE_CUDA = 1 USE_CUDA_PATH = /usr/local/cuda USE_CUDNN = 1 USE_OPENCV = 0
  7. Copy the mxnet/make/osx.mk to mxnet/config.mk
  8. Run make If you previously attempted to compile you might want to do make clean_all first. You can also run make -j to compile with multithreading. There'll be plenty of warnings but should be no errors.
  9. Once finished you should have a file called libmxnet.so in mxnet/lib/
  10. Do cd python
  11. Run sudo python setup.py install
  12. Do cd .. then you should be able to run python example/image-classification/train_mnist.py --network lenet --gpus 0 to test GPU training.

All 30 comments

GPU version of osx is currently not supported through pip.

You can try to build from source. A while back I was able to build mxnet with cuda 8 on OSX.

@szha right, got you, thanks. So do you know if MXNET 1.0.0 in theory will support cuda 9 if I attempt to build from source.

@szha Also, it seems Python can't be supported if building from source? https://mxnet.incubator.apache.org/get_started/build_from_source.html

Yes, mxnet 1.0.0 should support cuda 9 when building from source.

The build process is for building the shared object of mxnet, which is a dependency of the python language binding of mxnet. The python language binding doesn't require building so there is no doc listed.

@szha thanks, can confirm it all works, running macOS 10.13.2 with Cuda 9.1 and cuDNN 7 on a MacBook Pro with Sonnett ePGU and GeForce 1080 gpu.

Training the lenet example takes 36 seconds now vs. 14 minutes and 11 seconds on cpu.

@helloniklas I have a similar setup (macOS 10.13.2, GeForce 1080, cuda 9.1 and cuDNN 7).
would you mind to share the steps you took, to build and run mxnet on your machine?

thanks, any help appreciated!

@cosmo

  1. Download Xcode8.3.3 from Apple. This is the version NVIDIA state for Cuda 9.1 Mac. Unzip and rename to Xcode8.3.3.app.
  2. Run sudo xcode-select -s /Applications/Xcode8.3.3.app or to wherever you have placed Xcode.
  3. Run xcode-select --install to install all command line tools compilers etc.
  4. Run git clone --recursive https://github.com/apache/incubator-mxnet.git mxnet to get the latest version currently 1.0.1 which worked for me.
  5. cd mxnet
  6. Edit the make/osx.mk file to set
    USE_CUDA = 1 USE_CUDA_PATH = /usr/local/cuda USE_CUDNN = 1 USE_OPENCV = 0
  7. Copy the mxnet/make/osx.mk to mxnet/config.mk
  8. Run make If you previously attempted to compile you might want to do make clean_all first. You can also run make -j to compile with multithreading. There'll be plenty of warnings but should be no errors.
  9. Once finished you should have a file called libmxnet.so in mxnet/lib/
  10. Do cd python
  11. Run sudo python setup.py install
  12. Do cd .. then you should be able to run python example/image-classification/train_mnist.py --network lenet --gpus 0 to test GPU training.

Wohoo, it works! Thank you very much! :)
Let's hope that Turi Create will get support for 1.x

Thanks @helloniklas!
I'll be adding these instructions to the install area. Please ping me if you uncover any refinements that should be mentioned.

Was anyone able to confirm that the Mac GPU build will work with OpenCV support (USE_OPENCV=1) in the config?
@Cosmo
@helloniklas

@aaronmarkham Haven't tried unfortunately. I'm back on my machine by end of jan. I assume, it's a bit too late :|

Hi @cosmo - we're trying to wrap up the instructions for the next incremental release which is imminent. Either way, let me know if you can confirm, and I'll update the install info whenever you can try it out with OpenCV.

Hi @helloniklas,
Thank you so much for the detailed instruction. I think it worked. It took me around 4 minutes to complete 19 epochs, is it good? (I am new to this DL).

It said something about "MXNET_CUDNN_AUTOTUNE_DEFAULT = 0" do I need to worry about it?

[05:10:49] src/operator/nn/./cudnn/./cudnn_algoreg-inl.h:107: Running performance tests to find the best convolution algorithm, this can take a while... (setting env variable MXNET_CUDNN_AUTOTUNE_DEFAULT to 0 to disable)
INFO:root:Epoch[0] Batch [100] Speed: 4560.95 samples/sec accuracy=0.876702
...
INFO:root:Epoch[19] Batch [900] Speed: 5639.22 samples/sec accuracy=1.000000
INFO:root:Epoch[19] Train-accuracy=1.000000
INFO:root:Epoch[19] Time cost=10.585
INFO:root:Epoch[19] Validation-accuracy=0.992138

Hi @helloniklas, could you remove the space after USE_CUDA = 1. It is just a minor detail that may make it fail to compile if someone just copies that code without paying attention. Thanks!

Hi, @helloniklas I just tried to use your instructions with 10.13.4, Run git clone --recursive https://github.com/apache/incubator-mxnet.git mxnet which gets the latest version which is 1.1.0
and I get the following error:

In file included from src/operator/nn/cudnn/../../../common/cuda_utils.h:31:
/Users/bradcarlile/mxnet/3rdparty/mshadow/mshadow/base.h:147:14: fatal error: 'cblas.h' file not
found
#include
^~~~~
1 error generated.

ideas?

@bradcar Change the USE_BLAS in config.mk to 'apple'.

my config.mk has the following:

USE_BLAS = apple

@bradcar would you mind sharing some of the compilation outputs from the terminal?

sure, thanks in advance for your help...
cblas-notfound.txt

No problem. The error that you shared is the missing cblas.h. I checked the compilation line for the problem source, and it looks like this:

g++ -std=c++11 -c -DMSHADOW_FORCE_STREAM -Wall -Wsign-compare -O3 -DNDEBUG=1 -I/Users/bradcarlile/mxnet/3rdparty/mshadow/ -I/Users/bradcarlile/mxnet/3rdparty/dmlc-core/include -fPIC -I/Users/bradcarlile/mxnet/3rd
party/nnvm/include -I/Users/bradcarlile/mxnet/3rdparty/dlpack/include -I/Users/bradcarlile/mxnet/3rdparty/nnvm/tvm/include -Iinclude -funroll-loops -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-local-typ
edefs -msse3 -I/usr/local/cuda/include -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0 -I/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Versions/Current/Headers/ -DMSHADOW_
RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DMSHADOW_USE_PASCAL=0 -DMXNET_USE_OPENCV=0 -DMXNET_USE_LAPACK -DMSHADOW_USE_CUDNN=1  -I/Users/bradcarlile/mxnet/3rdparty/cub -DMXNET_ENABLE_CUDA_RTC=1 -DMXNET_USE_NCCL=0 -DMXNET_US
E_LIBJPEG_TURBO=0 -MMD -c src/operator/contrib/krprod.cc -o build/src/operator/contrib/krprod.o

Note that there is -I/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Versions/Current/Headers/. In that place, I was able to find cblas.h on my machine. Could you check whether it's the case for you?

According to this doc from OS X, you need OS X 10.0+ to get veclib.

I have two macs 10.12.6 and 10.13.4 . I could not find cblas.h in
/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Versions/Current/Headers/

There is no Headers directory in /System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Versions/Current/ All I see is:
Resources libBNNS.dylib libQuadrature.dylib libvDSP.dylib
_CodeSignature libLAPACK.dylib libSparse.dylib libvMisc.dylib
libBLAS.dylib libLinearAlgebra.dylib libSparseBLAS.dylib vecLib

I'm not sure what's happening there... Is xcode on your machine?

xcode Version 9.3 (9E145)

I re-installed my Xcode command line developer tools
xcode-select --install
Now the Header directory is there, and I no longer any cblas.h errors.

Where do I find the proper coda to install for mxnet 1.1.0 for mac?
/Users/bradcarlile/mxnet/3rdparty/mshadow/mshadow/base.h:157:12: fatal error: 'cuda.h' file not
found
#include
^~~~
error.

Usually it's in /usr/local/cuda once CUDA is installed.

THANKS!
what website do I go to download the proper CUDA for mac 10.13.4 and mxnet 1.1.0?

and https://pypi.python.org/pypi?:action=display&name=mxnet-cu91&version=1.1.0

Installation steps provided from this discussion have been made available on the mxnet website there:
http://mxnet.incubator.apache.org/install/index.html?platform=MacOS&language=Python&processor=GPU

@szha could you please close this issue?

Was this page helpful?
0 / 5 - 0 ratings