Skip to content

Commit 2ecea45

Browse files
Add limit memory for bazel
1 parent 27113a4 commit 2ecea45

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

compile_tensorflow_cpp.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,30 @@ Let's compile using bazel `build` rule:
7575
```bash
7676
export CC=gcc
7777
export CXX=g++
78-
bazel build --jobs=4 --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" -c opt \
78+
bazel build --jobs=4 --local_ram_resources="HOST_MEM*.50" \
79+
--cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" -c opt \
7980
//tensorflow:libtensorflow.so \
8081
//tensorflow:libtensorflow_cc.so \
8182
//tensorflow:libtensorflow_framework.so \
8283
//tensorflow:install_headers \
8384
//tensorflow/tools/pip_package:build_pip_package
8485
```
8586

86-
You can use the following command to check all available rules in each folder:
87+
You can use the following command to check all available rules in a specific top directory:
8788
```bash
8889
bazel query ...
8990
```
9091

9192
Note:
9293

9394
1. Building TensorFlow uses a lot of memory, I prefer a small number of CPUs (`--jobs`)
94-
2. The whole process can take several hours
95-
3. Add `-D_GLIBCXX_USE_CXX11_ABI=0` if you use GCC 5 or higher
96-
4. Flags for optimization: `--copt="-O3"`
97-
5. Flasg for both AMD and Intel chips: `--copt=-mfma --copt=-msse4.1 --copt=-msse4.2 --copt=-mfpmath=both`
98-
6. Flags for Intel: `--copt=-mavx --copt=-mavx2`
99-
7. Rebuild with `--config=monolithic` if you want compile all TensorFlow C++ code into a single shared object
95+
2. Limit RAM requested by bazel with `--local_ram_resources`. The value is either integer, .e.g., `4096` or % of total memory, e.g., 50% `"HOST_MEM*.50"`
96+
3. The whole process can take several hours
97+
4. Add `-D_GLIBCXX_USE_CXX11_ABI=0` if you use GCC 5 or higher
98+
5. Flags for optimization: `--copt="-O3"`
99+
6. Flasg for both AMD and Intel chips: `--copt=-mfma --copt=-msse4.1 --copt=-msse4.2 --copt=-mfpmath=both`
100+
7. Flags for Intel: `--copt=-mavx --copt=-mavx2`
101+
8. Rebuild with `--config=monolithic` if you want compile all TensorFlow C++ code into a single shared object
100102

101103
**optional**
102104
```bash

0 commit comments

Comments
 (0)