Skip to content

Commit e00d454

Browse files
committed
Merge branch 'master' into coverity_scan
2 parents 4a453f3 + 39c2dd8 commit e00d454

28 files changed

+513
-233
lines changed

.travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ install:
5757
- python retrieve_data.py
5858
- python gen_test_data.py
5959
before_script:
60+
- |
61+
echo 'Checking tools and libraries version:'
62+
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
63+
apt list --installed
64+
ldconfig -p
65+
fi
66+
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
67+
brew list --versions
68+
fi
69+
cmake --version
70+
make --version
6071
- ls -R $HOME/mkl-dnn
6172
script:
6273
#- if [ -f cov-int/build-log.txt ]; then cat cov-int/build-log.txt; fi

.travis/install_mkldnn.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
if [ ! -d "$HOME/mkl-dnn/lib" ]; then
22
git clone https://github.com/intel/mkl-dnn.git
33
cd mkl-dnn
4-
git checkout v0.14
4+
git checkout v0.15
55
cd scripts && bash ./prepare_mkl.sh && cd ..
66
sed -i 's/add_subdirectory(examples)//g' CMakeLists.txt
77
sed -i 's/add_subdirectory(tests)//g' CMakeLists.txt

BUILDING.md

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Building Menoh
2+
3+
## Prerequisites
4+
To build Menoh, you require the following toolchains:
5+
6+
Unix:
7+
- CMake 3.1 or later
8+
- GCC 4.9 or later
9+
10+
macOS (OSX):
11+
- TODO
12+
13+
Windows:
14+
- git
15+
- Visual Studio 2015
16+
17+
You also need to install the dependent libraries on your system:
18+
19+
- [Protocol Buffers](https://developers.google.com/protocol-buffers/) 2.6.1 or later
20+
- Building instructions are [here](https://github.com/protocolbuffers/protobuf/blob/master/src/README.md)
21+
- [MKL-DNN](https://github.com/intel/mkl-dnn) 0.14 or later (for `mkldnn` backend)
22+
- Building instructions are [here](https://github.com/intel/mkl-dnn/blob/master/README.md#installation)
23+
24+
You can install `protobuf` through the package manager instead of building it yourself. `mkl-dnn` package, unfortunatelly, is not available in many environments at the moment (except for `brew` in macOS).
25+
26+
### Debian/Ubuntu
27+
```
28+
apt-get install gcc g++ cmake-data cmake libopencv-dev libprotobuf-dev protobuf-compiler
29+
30+
# See the MKL-DNN's instructions for details
31+
git clone https://github.com/intel/mkl-dnn.git
32+
cd mkl-dnn
33+
cd scripts && ./prepare_mkl.sh && cd ..
34+
mkdir -p build && cd build && cmake .. && make
35+
make install # as root
36+
```
37+
38+
### macOS
39+
```
40+
brew update
41+
brew install protobuf mkl-dnn
42+
```
43+
44+
### Windows
45+
46+
None
47+
48+
## Building
49+
50+
### Unix
51+
Run the following command to build the source code:
52+
53+
```
54+
git clone https://github.com/pfnet-research/menoh.git
55+
cd menoh
56+
mkdir -p build && cd build
57+
cmake ..
58+
make
59+
```
60+
61+
To install Menoh into your system:
62+
63+
```
64+
make install # as root
65+
```
66+
67+
To run the example, you also need to download model data:
68+
69+
```
70+
python retrieve_data.py
71+
```
72+
73+
#### Static linking
74+
Menoh depends on several other libraries like `protobuf`. In Unix like systems, there is a chance to fail if you take the binary you built to other system because sometimes the dependent libraries installed on the system are not compatible with it.
75+
76+
To improve the portability, you can statically link Menoh with its dependencies. There is the following options for `cmake` command:
77+
78+
- `LINK_STATIC_LIBGCC` for `libgcc`
79+
- `LINK_STATIC_LIBSTDCXX` for `libstdc++`
80+
- `LINK_STATIC_LIBPROTOBUF` for `libprotobuf`
81+
- `LINK_STATIC_MKLDNN` for `libmkldnn` (NOT supported in this version)
82+
83+
If you use `LINK_STATIC_LIBPROTOBUF` and `LINK_STATIC_MKLDNN`, you don't need to install the libraries on your system because they build static library from the source.
84+
85+
All options are disabled by default, and you can turn them on as below:
86+
87+
```
88+
cmake \
89+
-DLINK_STATIC_LIBGCC=OFF \
90+
-DLINK_STATIC_LIBSTDCXX=OFF \
91+
-DLINK_STATIC_LIBPROTOBUF=ON \
92+
..
93+
```
94+
95+
Note that static linking is great for binary portability, but it increases the binary size and potentially introduces further weird problems depending on the combination. We strongly recommend to avoid using `LINK_STATIC_*` options and consider building the binary against the specific system where you run your Menoh application.
96+
97+
#### Old `libstdc++` ABI support
98+
Menoh has `USE_OLD_GLIBCXX_ABI` option to build its C++ source codes against the old `libstdc++` ABI to improve [backward compatibility](https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html) for the systems that depend on older GCC (`< 5.2`).
99+
100+
Note that enabling this option may cause a problem if `protobuf` in your environment is compiled against the new ABI because its API includes `std::` data types. We recommend to use it along with `-DLINK_STATIC_LIBPROTOBUF=ON`:
101+
102+
```
103+
cmake -DUSE_OLD_GLIBCXX_ABI=ON -DLINK_STATIC_LIBPROTOBUF=ON ..
104+
```
105+
106+
### macOS (OS X)
107+
TODO
108+
109+
### Windows
110+
111+
Please specify your directory into (CMake_Install_Dir).
112+
113+
#### mkl-dnn
114+
115+
```
116+
git clone https://github.com/intel/mkl-dnn.git
117+
cd mkl-dnn/scripts
118+
.\prepare_mkl.bat
119+
cd ..
120+
mdir build
121+
cd build
122+
cmake .. -G "Visual Studio 14 Win64" -DCMAKE_INSTALL_PREFIX=(CMake_Install_Dir)
123+
cmake --build . --config Debug --target install
124+
cmake --build . --config Release --target install
125+
cd ../..
126+
```
127+
128+
#### protobuf
129+
130+
Download and unzip https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protobuf-cpp-3.6.1.zip
131+
132+
```
133+
cd protobuf-3.6.1/cmake
134+
mdir build
135+
cd build
136+
cmake .. -G "Visual Studio 14" -A x64 -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=(CMake_Install_Dir)
137+
cmake --build . --config Debug --target install
138+
cmake --build . --config Release --target install
139+
cd ../../..
140+
```
141+
142+
#### menoh
143+
144+
```
145+
git clone https://github.com/pfnet-research/menoh.git
146+
cd menoh
147+
mdir build
148+
cd build
149+
cmake .. -G "Visual Studio 14 Win64" -DCMAKE_PREFIX_PATH=CMake_Install_Dir) -DCMAKE_INSTALL_PREFIX=CMake_Install_Dir) -DENABLE_TEST=OFF -DENABLE_BENCHMARK=OFF -DENABLE_EXAMPLE=OFF -DENABLE_TOOL=OFF
150+
cmake --build . --config Debug --target install
151+
cmake --build . --config Release --target install
152+
```

CMakeLists.txt

+42-15
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
44

55
set(MENOH_MAJOR_VERSION 1)
66
set(MENOH_MINOR_VERSION 0)
7-
set(MENOH_PATCH_VERSION 2)
7+
set(MENOH_PATCH_VERSION 3)
88

99
# Options
1010
option(BUILD_SHARED_LIBS "Build shared libs" ON)
11+
12+
option(USE_OLD_GLIBCXX_ABI "Generate binaries for the old libstdc++ ABI" OFF)
13+
option(LINK_STATIC_LIBPROTOBUF "Link static libprotobuf to libmenoh" OFF)
14+
1115
option(ENABLE_TEST "Build test" OFF)
1216
option(ENABLE_BENCHMARK "Build benchmark" ON)
1317
option(ENABLE_EXAMPLE "Build example" ON)
14-
option(ENABLE_TOOL "Build tool" ON)
18+
19+
option(SHOW_ALL_VARIABLES "Debug: show all variables" OFF)
1520

1621
# C++ setup
1722
set(CMAKE_CXX_STANDARD 14)
@@ -31,25 +36,36 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
3136
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -s -DNDEBUG -march=native")
3237
endif()
3338

39+
# Configure to use the new `libstdc++` ABI
40+
if(USE_OLD_GLIBCXX_ABI)
41+
message(STATUS "Set _GLIBCXX_USE_CXX11_ABI macro to 0")
42+
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
43+
endif()
44+
3445
include_directories("${PROJECT_SOURCE_DIR}")
3546
include_directories("${PROJECT_SOURCE_DIR}/include")
3647

3748
set(EXTERNAL_DIR ${CMAKE_SOURCE_DIR}/external)
49+
set(DOWNLOAD_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/downloads CACHE PATH "A directory to save the downloaded files.")
50+
mark_as_advanced(DOWNLOAD_LOCATION)
51+
52+
# Enable ExternalProject_Add
53+
include(ExternalProject)
54+
55+
# Setup protobuf
56+
include(SetupProtobuf)
3857

39-
# ONNX setup
58+
# Generate source codes from ONNX protobuf schema
4059
set(ONNX_DIR ${EXTERNAL_DIR}/onnx)
41-
set(Protobuf_PROTOC_EXECUTABLE protoc CACHE STRING "protoc path")
42-
include(FindProtobuf)
43-
find_package(Protobuf 2.6.1 REQUIRED)
44-
include_directories(${PROTOBUF_INCLUDE_DIR})
4560
execute_process(COMMAND git submodule update --init -- ${ONNX_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
46-
execute_process(COMMAND ${Protobuf_PROTOC_EXECUTABLE} -I=${ONNX_DIR} --cpp_out=${ONNX_DIR} ${ONNX_DIR}/onnx/onnx.proto WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
61+
execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} -I=${ONNX_DIR} --cpp_out=${ONNX_DIR} ${ONNX_DIR}/onnx/onnx.proto WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
62+
4763
set(ONNX_PROTO_HEADER ${ONNX_DIR}/onnx/onnx.pb.h)
4864
set(ONNX_PROTO_SRC ${ONNX_DIR}/onnx/onnx.pb.cc)
49-
include_directories(${EXTERNAL_DIR})
50-
include_directories(${ONNX_DIR})
5165

52-
# MKLDNN setup
66+
include_directories(${ONNX_DIR}) # for ONNX_PROTO_HEADER
67+
68+
# Setup MKLDNN
5369
find_package(MKLDNN "0.14")
5470
if (NOT MKLDNN_FOUND)
5571
message(FATAL_ERROR "MKLDNN is not found")
@@ -62,21 +78,32 @@ if(${ENABLE_TEST})
6278
# GTest setup
6379
set(GTEST_DIR test/lib/googletest)
6480
execute_process(COMMAND git submodule update --init -- ${GTEST_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
81+
message(STATUS "# add_subdirectory\(${GTEST_DIR}\)")
6582
add_subdirectory(${GTEST_DIR})
83+
message(STATUS "# add_subdirectory\(test\)")
6684
add_subdirectory(test)
6785
endif()
6886

6987
if(${ENABLE_BENCHMARK})
88+
message(STATUS "# add_subdirectory\(benchmark\)")
7089
add_subdirectory(benchmark)
7190
endif()
7291

7392
if(${ENABLE_EXAMPLE})
93+
message(STATUS "# add_subdirectory\(example\)")
7494
add_subdirectory(example)
7595
endif()
7696

77-
if(${ENABLE_TOOL})
78-
add_subdirectory(tool)
79-
endif()
80-
97+
message(STATUS "# add_subdirectory\(menoh\)")
8198
add_subdirectory(menoh)
99+
100+
message(STATUS "# add_subdirectory\(include\)")
82101
add_subdirectory(include)
102+
103+
if(SHOW_ALL_VARIABLES)
104+
get_cmake_property(_variableNames VARIABLES)
105+
list(SORT _variableNames)
106+
foreach(_variableName ${_variableNames})
107+
message(STATUS "${_variableName}=${${_variableName}}")
108+
endforeach()
109+
endif()

README.md

+15-11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This codebase contains C API and C++ API.
2727
- Go wrapper : [go-menoh](https://github.com/pfnet-research/go-menoh)
2828
- (unofficial wrapper [gomenoh](https://github.com/kou-m/gomenoh) by kou-m san has been merged)
2929
- Haskell wrapper : [menoh-haskell](https://github.com/pfnet-research/menoh-haskell)
30+
- Node.js wrapper : [node-menoh](https://github.com/pfnet-research/node-menoh)
3031
- Ruby wrapper : [menoh-ruby](https://github.com/pfnet-research/menoh-ruby)
3132
- Rust wrapper : [menoh-rs](https://github.com/pfnet-research/menoh-rs)
3233
- There is also [unofficial Rust wrapper by Y-Nak san](https://github.com/Y-Nak/menoh-rs)
@@ -47,7 +48,7 @@ This codebase contains C API and C++ API.
4748

4849
## Build
4950

50-
Execute below commands in root directory.
51+
Execute following commands in root directory.
5152

5253
```
5354
python retrieve_data.py
@@ -56,33 +57,36 @@ cmake ..
5657
make
5758
```
5859

60+
See [BUILDING.md](BUILDING.md) for details.
61+
5962
## Installation
6063

61-
Execute below command in build directory created at Build section.
64+
Execute following command in build directory created at Build section.
6265

6366
```
6467
make install
6568
```
6669

6770
# Run VGG16 example
6871

69-
Execute below command in root directory.
72+
Execute following command in root directory.
7073

7174
```
7275
./example/vgg16_example_in_cpp
7376
```
7477

75-
Result is below
78+
Result is here
7679

7780
```
7881
vgg16 example
79-
-22.3708 -34.4082 -10.218 24.2962 -0.252342 -8.004 -27.0804 -23.0728 -7.05607 16.1343
82+
-23.149 -26.9167 -12.9911 10.3262 -0.845882 0.454192 -24.1435 -21.891 -3.98805 15.6863
8083
top 5 categories are
81-
8 0.96132 n01514859 hen
82-
7 0.0369939 n01514668 cock
83-
86 0.00122795 n01807496 partridge
84-
82 0.000225824 n01797886 ruffed grouse, partridge, Bonasa umbellus
85-
97 3.83677e-05 n01847000 drake
84+
8 0.946072 n01514859 hen
85+
7 0.0485334 n01514668 cock
86+
86 0.00296125 n01807496 partridge
87+
82 0.000877083 n01797886 ruffed grouse, partridge, Bonasa umbellus
88+
97 0.000424042 n01847000 drake
89+
8690
```
8791

8892
Please give `--help` option for details
@@ -96,7 +100,7 @@ Please give `--help` option for details
96100

97101
Setup chainer
98102

99-
Then, execute below commands in root directory.
103+
Then, execute following commands in root directory.
100104

101105
```
102106
python gen_test_data.py

appveyor.yml

+13-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ install:
2424

2525
- if [%TARGET%]==[mingw] (
2626
pacman -S --needed --noconfirm mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-opencv mingw-w64-x86_64-protobuf mingw-w64-x86_64-python3 mingw-w64-x86_64-python3-pip mingw-w64-x86_64-python3-numpy mingw-w64-x86_64-hdf5 mingw-w64-x86_64-ca-certificates &&
27-
curl -omingw-w64-x86_64-mkl-dnn-0.14-3-x86_64.pkg.tar.xz -L https://preferredjp.box.com/shared/static/eb90vngoz8zngp6yy69x91q0swp11ha1.xz &&
28-
pacman -U --noconfirm mingw-w64-x86_64-mkl-dnn-0.14-3-x86_64.pkg.tar.xz
27+
curl -omingw-w64-x86_64-mkl-dnn-0.15-1-x86_64.pkg.tar.xz -L https://github.com/pfnet-research/menoh/releases/download/v1.0.3/mingw-w64-x86_64-mkl-dnn-0.15-1-x86_64.pkg.tar.xz &&
28+
pacman -U --noconfirm mingw-w64-x86_64-mkl-dnn-0.15-1-x86_64.pkg.tar.xz
2929
) else (
30-
curl -omkl-dnn-0.14-win64.7z -L --insecure https://preferredjp.box.com/shared/static/njn6vrjt8zaslk82yjw7j1pczkcp3c0f.7z &&
31-
mkdir mkl-dnn-0.14-win64 &&
32-
7z x -omkl-dnn-0.14-win64 mkl-dnn-0.14-win64.7z &&
30+
curl -omkl-dnn-0.15-win64.zip -L --insecure https://github.com/pfnet-research/menoh/releases/download/v1.0.3/mkl-dnn-0.15-win64.zip &&
31+
7z x mkl-dnn-0.15-win64.zip &&
3332
call appveyor\install_protoc_msvc.bat
3433
)
3534

@@ -45,10 +44,18 @@ install:
4544
python gen_test_data.py
4645
)
4746

47+
before_build:
48+
- if [%TARGET%]==[mingw] (
49+
echo 'Checking tools and libraries version:' &&
50+
pacman -Q &&
51+
cmake --version &&
52+
make --version
53+
)
54+
4855
build_script:
4956
- mkdir build
5057
- cd build
51-
- if [%TARGET%]==[msvc] set PATH=%PATH%;c:\protobuf-3.6.0-msvc\bin;c:\protobuf-3.6.0-msvc\include;c:\protobuf-3.6.0-msvc\lib;c:\projects\menoh\mkl-dnn-0.14-win64\bin;c:\projects\menoh\mkl-dnn-0.14-win64\include;c:\projects\menoh\mkl-dnn-0.14-win64\lib
58+
- if [%TARGET%]==[msvc] set PATH=%PATH%;c:\protobuf-3.6.0-msvc\bin;c:\protobuf-3.6.0-msvc\include;c:\protobuf-3.6.0-msvc\lib;c:\projects\menoh\mkl-dnn-0.15-win64\bin;c:\projects\menoh\mkl-dnn-0.15-win64\include;c:\projects\menoh\mkl-dnn-0.15-win64\lib
5259
- if [%TARGET%]==[mingw] (
5360
cmake -G "MSYS Makefiles" -DENABLE_TEST=ON -DCMAKE_INSTALL_PREFIX=/mingw64 .. &&
5461
make

0 commit comments

Comments
 (0)