Skip to content

Commit 2daa05c

Browse files
committed
add build on MAC OSX docs
1 parent 75cbf5e commit 2daa05c

File tree

1 file changed

+136
-6
lines changed

1 file changed

+136
-6
lines changed

doc/build/build_from_source.md

Lines changed: 136 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
Build and Install
22
=================
33

4-
## Requirement
4+
* [1. Requirement](#Requirement)
5+
* [2. Build on Ubuntu](#ubuntu)
6+
* [3. Build on Mac OS X](#mac)
7+
8+
## <span id="Requirement">Requirement</span>
59

610
### Dependents
711

@@ -28,7 +32,7 @@ PaddlePaddle also support some build options, you have to install related librar
2832
- **WITH_STYLE_CHECK**: Style check for source code
2933

3034

31-
## Building on Ubuntu14.04
35+
## <span id="ubuntu">Building on Ubuntu14.04</span>
3236

3337
### Install Dependencies
3438

@@ -44,7 +48,7 @@ sudo apt-get install libgflags-dev
4448
sudo apt-get install libgtest-dev
4549
sudo pip install wheel
4650
pushd /usr/src/gtest
47-
cmake .
51+
cmake ..
4852
make
4953
sudo cp *.a /usr/lib
5054
popd
@@ -102,19 +106,19 @@ Here are some examples of cmake command with different options:
102106
**only cpu**
103107

104108
```bash
105-
cmake -DWITH_GPU=OFF -DWITH_DOC=OFF
109+
cmake -DWITH_GPU=OFF -DWITH_DOC=OFF ..
106110
```
107111

108112
**gpu**
109113

110114
```bash
111-
cmake -DWITH_GPU=ON -DWITH_DOC=OFF
115+
cmake -DWITH_GPU=ON -DWITH_DOC=OFF ..
112116
```
113117

114118
**gpu with doc and swig**
115119

116120
```bash
117-
cmake -DWITH_GPU=ON -DWITH_DOC=ON -DWITH_SWIG_PY=ON
121+
cmake -DWITH_GPU=ON -DWITH_DOC=ON -DWITH_SWIG_PY=ON ..
118122
```
119123

120124
Finally, you can download source code and build:
@@ -139,3 +143,129 @@ And if you set WITH_SWIG_PY=ON, you have to install related python predict api a
139143
```bash
140144
pip install <path to install>/opt/paddle/share/wheels/*.whl
141145
```
146+
## <span id="mac">Building on Mac OS X</span>
147+
148+
### Prerequisites
149+
This guide is based on Mac OS X 10.11 (El Capitan). Note that if you are running an up to date version of OS X,
150+
you will already have Python 2.7.10 and Numpy 1.8 installed.
151+
152+
The best option is to use the package manager homebrew to handle installations and upgrades for you.
153+
To install homebrew, first open a terminal window (you can find Terminal in the Utilities folder in Applications), and issue the command:
154+
155+
```bash
156+
# install brew
157+
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
158+
# install pip
159+
easy_install pip
160+
```
161+
162+
### Install Dependencies
163+
164+
- **CPU Dependencies**
165+
166+
```bash
167+
# Install fundamental dependents
168+
brew install glog gflags cmake protobuf openblas
169+
170+
# Install google test on Mac OS X
171+
# Download gtest 1.7.0
172+
wget https://github.com/google/googletest/archive/release-1.7.0.tar.gz
173+
tar -xvf googletest-release-1.7.0.tar.gz && cd googletest-release-1.7.0
174+
# Build gtest
175+
mkdir build && cmake ..
176+
make
177+
# Install gtest library
178+
sudo cp -r ../include/gtest /usr/local/include/
179+
sudo cp lib*.a /usr/local/lib
180+
```
181+
182+
183+
- **GPU Dependencies(optional)**
184+
185+
If you need to build GPU version, the first thing you need is a machine that has NVIDIA GPU and CUDA installed.
186+
And you also need to install cuDNN.
187+
188+
You can download CUDA toolkit and cuDNN from nvidia website:
189+
190+
```bash
191+
https://developer.nvidia.com/cuda-downloads
192+
https://developer.nvidia.com/cudnn
193+
```
194+
You can copy cuDNN files into the CUDA toolkit directory, for instance:
195+
196+
```bash
197+
sudo tar -xzf cudnn-7.5-osx-x64-v5.0-ga.tgz -C /usr/local
198+
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
199+
```
200+
Then you need to set DYLD\_LIBRARY\_PATH, CUDA\_HOME and PATH environment variables in ~/.bashrc.
201+
202+
```bash
203+
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH
204+
export PATH=/usr/local/cuda/bin:$PATH
205+
```
206+
- **Python Dependencies(optional)**
207+
208+
If you want to compile PaddlePaddle with python predict API, you need to add -DWITH_SWIG_PY=ON in cmake command and install these first:
209+
210+
```bash
211+
brew install swig
212+
```
213+
214+
- **Doc Dependencies(optional)**
215+
216+
If you want to compile PaddlePaddle with doc, you need to add -DWITH_DOC=ON in cmake command and install these first:
217+
218+
```bash
219+
pip install 'sphinx>=1.4.0'
220+
pip install sphinx_rtd_theme breathe recommonmark
221+
brew install doxygen
222+
```
223+
224+
### Build and Install
225+
226+
CMake can find dependent libraries in system default paths firstly.
227+
After installing some optional libraries, corresponding build option will be on automatically (for instance, glog, gtest and gflags).
228+
If not found, you have to set following variables manually via CMake command (CUDNN_ROOT, ATLAS_ROOT, MKL_ROOT, OPENBLAS_ROOT).
229+
230+
Here are some examples of CMake command with different options:
231+
232+
**only cpu**
233+
234+
```bash
235+
cmake -DWITH_GPU=OFF -DWITH_DOC=OFF ..
236+
```
237+
238+
**gpu**
239+
240+
```bash
241+
cmake -DWITH_GPU=ON -DWITH_DOC=OFF ..
242+
```
243+
244+
**gpu with doc and swig**
245+
246+
```bash
247+
cmake -DWITH_GPU=ON -DWITH_DOC=ON -DWITH_SWIG_PY=ON ..
248+
```
249+
250+
Finally, you can download source code and build:
251+
252+
```bash
253+
git clone https://github.com/baidu/Paddle paddle
254+
cd paddle
255+
mkdir build
256+
cd build
257+
# you can add build option here, such as:
258+
cmake -DWITH_GPU=ON -DWITH_DOC=OFF -DCMAKE_INSTALL_PREFIX=<path to install> ..
259+
# please use sudo make install, if you want
260+
# to install PaddlePaddle into the system
261+
make -j `nproc` && make install
262+
# PaddlePaddle installation path
263+
export PATH=<path to install>/bin:$PATH
264+
```
265+
**Note**
266+
267+
And if you set WITH_SWIG_PY=ON, you have to install related python predict api at the same time:
268+
269+
```bash
270+
sudo pip install <path to install>/opt/paddle/share/wheels/*.whl
271+
```

0 commit comments

Comments
 (0)