Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Installing GPU support on Mac #9217

Closed
helloniklas opened this issue Dec 28, 2017 · 30 comments
Closed

Installing GPU support on Mac #9217

helloniklas opened this issue Dec 28, 2017 · 30 comments

Comments

@helloniklas
Copy link

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.

@szha
Copy link
Member

szha commented Dec 28, 2017

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.

@helloniklas
Copy link
Author

@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.

@helloniklas
Copy link
Author

helloniklas commented Dec 28, 2017

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

@szha
Copy link
Member

szha commented Dec 29, 2017

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.

@helloniklas
Copy link
Author

helloniklas commented Dec 31, 2017

@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.

@Cosmo
Copy link

Cosmo commented Jan 3, 2018

@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!

@helloniklas
Copy link
Author

helloniklas commented Jan 3, 2018

@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
  1. Copy the mxnet/make/osx.mk to mxnet/config.mk
  2. 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.
  3. Once finished you should have a file called libmxnet.so in mxnet/lib/
  4. Do cd python
  5. Run sudo python setup.py install
  6. Do cd .. then you should be able to run python example/image-classification/train_mnist.py --network lenet --gpus 0 to test GPU training.

@Cosmo
Copy link

Cosmo commented Jan 3, 2018

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

@aaronmarkham
Copy link
Contributor

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

@aaronmarkham
Copy link
Contributor

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

@Cosmo
Copy link

Cosmo commented Jan 17, 2018

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

@aaronmarkham
Copy link
Contributor

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.

@shankarrajus
Copy link

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

@rafaelsimonmaia
Copy link

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!

@bradcar
Copy link
Contributor

bradcar commented Apr 5, 2018

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 <cblas.h>
^~~~~~~~~
1 error generated.

ideas?

@szha
Copy link
Member

szha commented Apr 5, 2018

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

@bradcar
Copy link
Contributor

bradcar commented Apr 5, 2018

my config.mk has the following:

USE_BLAS = apple

@szha
Copy link
Member

szha commented Apr 5, 2018

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

@bradcar
Copy link
Contributor

bradcar commented Apr 5, 2018

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

@szha
Copy link
Member

szha commented Apr 5, 2018

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?

@szha
Copy link
Member

szha commented Apr 5, 2018

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

@bradcar
Copy link
Contributor

bradcar commented Apr 5, 2018

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

@szha
Copy link
Member

szha commented Apr 5, 2018

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

@bradcar
Copy link
Contributor

bradcar commented Apr 5, 2018

xcode Version 9.3 (9E145)

@bradcar
Copy link
Contributor

bradcar commented Apr 6, 2018

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 <cuda.h>
^~~~~~~~
error.

@szha
Copy link
Member

szha commented Apr 6, 2018

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

@bradcar
Copy link
Contributor

bradcar commented Apr 6, 2018

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

@szha
Copy link
Member

szha commented Apr 6, 2018

That would be https://developer.nvidia.com/cuda-downloads

@szha
Copy link
Member

szha commented Apr 6, 2018

@ThomasDelteil
Copy link
Contributor

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?

@szha szha closed this as completed Jul 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants