Skip to content

Commit bbbbe36

Browse files
committed
Merge branch 'master' of https://github.com/NVlabs/gbrl
2 parents 873db0e + 32a5545 commit bbbbe36

File tree

6 files changed

+73
-45
lines changed

6 files changed

+73
-45
lines changed

CMakeLists.txt

+16-10
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ if(APPLE)
112112
find_package(OpenMP)
113113
if(NOT OpenMP_FOUND)
114114
# Try again with extra path info; required for libomp 15+ from Homebrew
115-
execute_process(COMMAND brew --prefix libomp
116-
OUTPUT_VARIABLE HOMEBREW_LIBOMP_PREFIX
117-
OUTPUT_STRIP_TRAILING_WHITESPACE)
118-
set(OpenMP_C_FLAGS
115+
execute_process(COMMAND brew --prefix libomp
116+
OUTPUT_VARIABLE HOMEBREW_LIBOMP_PREFIX
117+
OUTPUT_STRIP_TRAILING_WHITESPACE)
118+
set(OpenMP_C_FLAGS
119119
"-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include")
120-
set(OpenMP_CXX_FLAGS
120+
set(OpenMP_CXX_FLAGS
121121
"-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include")
122-
set(OpenMP_C_LIB_NAMES omp)
123-
set(OpenMP_CXX_LIB_NAMES omp)
124-
set(OpenMP_omp_LIBRARY ${HOMEBREW_LIBOMP_PREFIX}/lib/libomp.dylib)
125-
find_package(OpenMP REQUIRED)
122+
set(OpenMP_C_LIB_NAMES omp)
123+
set(OpenMP_CXX_LIB_NAMES omp)
124+
set(OpenMP_omp_LIBRARY ${HOMEBREW_LIBOMP_PREFIX}/lib/libomp.dylib)
125+
find_package(OpenMP REQUIRED)
126126
endif()
127127
else()
128128
find_package(OpenMP REQUIRED)
@@ -131,6 +131,13 @@ else()
131131
set(OpenMP_omp_LIBRARY ${OpenMP_omp_LIBRARY})
132132
endif()
133133

134+
# Ensure OpenMP flags and directories are applied
135+
if (OpenMP_FOUND)
136+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
137+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
138+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
139+
endif()
140+
134141
# Include directories
135142
include_directories(${pybind11_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/gbrl/src/cpp)
136143

@@ -192,7 +199,6 @@ elseif (WIN32)
192199
target_link_libraries(gbrl_cpp PRIVATE OpenMP::OpenMP_CXX)
193200
if (USE_CUDA)
194201
set(cuda_lib_path "${CUDAToolkit_ROOT_DIR}/lib/x64")
195-
# target_link_libraries(gbrl_cpp PRIVATE ${cuda_lib_path}/cudart.lib)
196202
target_link_libraries(gbrl_cpp PRIVATE CUDA::cudart)
197203
endif()
198204
endif()

README.md

+2-28
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,12 @@ GBRL is a Python-based GBT library designed and optimized for reinforcement lear
99

1010

1111
## Getting started
12-
13-
### Dependencies
14-
#### MAC OS
15-
```
16-
llvm
17-
openmp
18-
```
19-
20-
Make sure to run:
21-
```
22-
brew install libomp
23-
brew install llvm
24-
```
25-
26-
xcode command line tools should be installed installed
27-
28-
### Installation
12+
GBRL is installed via
2913
```
3014
pip install gbrl
31-
```
32-
33-
Verify that GPU is visible by running
3415
```
35-
import gbrl
36-
37-
gbrl.cuda_available()
38-
```
39-
40-
GBRL can be compiled and installed with a CPU version only even on CUDA capable machines by setting `CPU_ONLY=1` as an environment variable.
4116

42-
*OPTIONAL*
43-
For tree visualization make sure graphviz is installed before compilation.
17+
For furthere installation details and dependencies see the documentation.
4418

4519
***Usage Example see `tutorial.ipynb`***
4620

docs/quickstart.rst

+47-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,50 @@ Install GBRL via pip:
77
88
pip install gbrl
99
10-
GBRL can be compiled and installed with a CPU version only even on CUDA capable machines by setting `CPU_ONLY=1` as an environment variable.
10+
CPU only version is installed with the following command:
11+
12+
.. code-block:: console
13+
14+
CPU_ONLY=1 pip install gbrl
15+
16+
Dependencies
17+
============
18+
19+
MAC OS
20+
~~~~~~
21+
22+
GBRL is dependent on LLVM and OpenMP.
23+
24+
These dependencies can be installed via Homebrew:
25+
26+
.. code-block:: console
27+
28+
brew install libomp llvm
29+
30+
31+
Once installed make sure that the appropriate environment variables are set:
32+
33+
.. code-block:: bash
34+
35+
export PATH="$(brew --prefix llvm)/bin:$PATH"
36+
export LDFLAGS="-L$(brew --prefix libomp)/lib -L$(brew --prefix llvm)/lib -L$(brew --prefix llvm)/lib/c++ -Wl,-rpath,$(brew --prefix llvm)/lib/c++"
37+
export CPPFLAGS="-I$(brew --prefix libomp)/include -I$(brew --prefix llvm)/include"
38+
export CC="$(brew --prefix llvm)/bin/clang"
39+
export CXX="$(brew --prefix llvm)/bin/clang++"
40+
export DYLD_LIBRARY_PATH="$(brew --prefix llvm)/lib:$(brew --prefix libomp)/lib"
41+
42+
CUDA
43+
~~~~
44+
45+
.. code-block:: python
46+
# Verify that GPU is visible by running
47+
import gbrl
48+
49+
print(gbrl.cuda_available())
50+
51+
52+
Graphviz
53+
~~~~~~~~
54+
55+
*OPTIONAL*
56+
For tree visualization make sure graphviz is installed before compilation.

gbrl/src/cpp/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ if (CUDAToolkit_FOUND AND NOT APPLE)
2929
endif()
3030

3131
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
32-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++14 ${OpenMP_CXX_FLAGS} -Wall -Wpedantic -Wextra -march=native")
32+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++14 -Wall -Wpedantic -Wextra -march=native")
3333
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
34-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++14 ${OpenMP_C_FLAGS} -Wall -Wpedantic -Wextra")
34+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++14 -Wall -Wpedantic -Wextra")
3535
elseif (WIN32)
36-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /std:c++14 ${OpenMP_CXX_FLAGS} /W3")
36+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /std:c++14 /W3")
3737
endif()
3838

3939
if (CMAKE_BUILD_TYPE STREQUAL "Debug")

gbrl/src/cpp/gbrl.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,9 @@ void GBRL::plot_tree(int tree_idx, const std::string &filename){
999999
}
10001000
#endif
10011001
#else
1002-
throw std::runtime_error("GBRL compiled without Graphviz! Cannot plot model");
1002+
(void)tree_idx;
1003+
(void)filename;
1004+
throw std::runtime_error("GBRL compiled without Graphviz! Cannot plot model");
10031005
#endif
10041006
}
10051007

gbrl/src/cpp/loss.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ float MultiRMSE::get_loss_and_gradients(const float *raw_preds, const float *raw
2525
int thread_id = omp_get_thread_num();
2626
int start_idx = thread_id * elements_per_thread;
2727
int end_idx = (thread_id == n_threads - 1) ? n_elements : start_idx + elements_per_thread;
28-
#ifndef _MSC_VER
28+
#if !defined(_MSC_VER) && !defined(__APPLE__)
2929
#pragma omp simd
3030
#endif
3131
for (int i = start_idx; i < end_idx; ++i){
@@ -57,7 +57,7 @@ float MultiRMSE::get_loss(const float *raw_preds, const float *raw_targets, cons
5757
int end_idx = (thread_id == n_threads - 1) ? n_samples : start_idx + samples_per_thread;
5858
for (int sample_idx = start_idx; sample_idx < end_idx; ++sample_idx){
5959
row = sample_idx * output_dim;
60-
#ifndef _MSC_VER
60+
#if !defined(_MSC_VER) && !defined(__APPLE__)
6161
#pragma omp simd
6262
#endif
6363
for (int d = 0; d < output_dim; ++d){

0 commit comments

Comments
 (0)