Skip to content

Commit

Permalink
simplify mac mkldnn build (apache#12724)
Browse files Browse the repository at this point in the history
* remove guard that prevent omp flag in mac

* udpate doc for mac make build

* update docs

* update readme

* set opencv to 1 in instructions

* remove disable opencv line

* update mac docs

* fix indent
  • Loading branch information
azai91 authored and piyushghai committed Nov 8, 2018
1 parent 955194a commit 71c133d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
23 changes: 3 additions & 20 deletions MKLDNN_README.md
Expand Up @@ -45,7 +45,7 @@ If you don't have full [MKL](https://software.intel.com/en-us/intel-mkl) library
Install the dependencies, required for MXNet, with the following commands:

- [Homebrew](https://brew.sh/)
- gcc (clang in macOS does not support OpenMP)
- llvm (clang in macOS does not support OpenMP)
- OpenCV (for computer vision operations)

```
Expand All @@ -59,8 +59,7 @@ brew install graphviz
brew tap homebrew/core
brew install opencv
brew tap homebrew/versions
brew install gcc49
brew link gcc49 #gcc-5 and gcc-7 also work
brew install llvm
```

### Clone MXNet sources
Expand All @@ -70,28 +69,12 @@ git clone --recursive https://github.com/apache/incubator-mxnet.git
cd incubator-mxnet
```

### Enable OpenMP for MacOS

If you want to enable OpenMP for better performance, you should modify the Makefile in MXNet root dictionary:

Add CFLAGS '-fopenmp' for Darwin.

```
ifeq ($(USE_OPENMP), 1)
# ifneq ($(UNAME_S), Darwin)
CFLAGS += -fopenmp
# endif
endif
```

### Build MXNet with MKL-DNN

```
make -j $(sysctl -n hw.ncpu) CC=gcc-4.9 CXX=g++-4.9 USE_OPENCV=0 USE_OPENMP=1 USE_MKLDNN=1 USE_BLAS=apple USE_PROFILER=1
LIBRARY_PATH=$(brew --prefix llvm)/lib/ make -j $(sysctl -n hw.ncpu) CC=$(brew --prefix llvm)/bin/clang++ CXX=$(brew --prefix llvm)/bin/clang++ USE_OPENCV=1 USE_OPENMP=1 USE_MKLDNN=1 USE_BLAS=apple USE_PROFILER=1
```

*Note: Temporarily disable OPENCV.*

<h2 id="3">Windows</h2>

We recommend to build and install MXNet yourself using [Microsoft Visual Studio 2015](https://www.visualstudio.com/vs/older-downloads/), or you can also try experimentally the latest [Microsoft Visual Studio 2017](https://www.visualstudio.com/downloads/).
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Expand Up @@ -145,9 +145,7 @@ else
endif

ifeq ($(USE_OPENMP), 1)
ifneq ($(UNAME_S), Darwin)
CFLAGS += -fopenmp
endif
CFLAGS += -fopenmp
endif

ifeq ($(USE_NNPACK), 1)
Expand Down
12 changes: 11 additions & 1 deletion docs/install/osx_setup.md
Expand Up @@ -65,6 +65,10 @@ Install the dependencies, required for MXNet, with the following commands:
brew install openblas
brew tap homebrew/core
brew install opencv

# If building with MKLDNN
brew install llvm

# Get pip
easy_install pip
# For visualization of network graphs
Expand All @@ -89,12 +93,18 @@ The file called ```osx.mk``` has the configuration required for building MXNet o
make -j$(sysctl -n hw.ncpu)
```

To build with MKLDNN

```bash
LIBRARY_PATH=$(brew --prefix llvm)/lib/ make -j $(sysctl -n hw.ncpu) CC=$(brew --prefix llvm)/bin/clang++ CXX=$(brew --prefix llvm)/bin/clang++ USE_OPENCV=1 USE_OPENMP=1 USE_MKLDNN=1 USE_BLAS=apple USE_PROFILER=1
```

If building with ```GPU``` support, add the following configuration to config.mk and build:
```bash
echo "USE_CUDA = 1" >> ./config.mk
echo "USE_CUDA_PATH = /usr/local/cuda" >> ./config.mk
echo "USE_CUDNN = 1" >> ./config.mk
make
make -j$(sysctl -n hw.ncpu)
```
**Note:** To change build parameters, edit ```config.mk```.

Expand Down
1 change: 1 addition & 0 deletions make/osx.mk
Expand Up @@ -77,6 +77,7 @@ USE_CUDNN = 0
USE_OPENCV = 1

# use openmp for parallelization
# apple-clang by default does not have openmp built-in
USE_OPENMP = 0

# choose the version of blas you want to use
Expand Down

0 comments on commit 71c133d

Please sign in to comment.