Skip to content

Commit 864296b

Browse files
committed
feat(api): add versions and compile flags to /info
Close jolibrain#897
1 parent 22edd72 commit 864296b

9 files changed

+69
-44
lines changed

CMakeLists.txt

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required(VERSION 2.8.8)
22
project(deepdetect)
33

4+
option(RELEASE "release mode" OFF)
45
option(USE_CAFFE2 "build caffe2 backend")
56
option(USE_TF "use TF backend")
67
option(USE_NCNN "use NCNN backend")
@@ -36,9 +37,6 @@ include(ProcessorCount)
3637
ProcessorCount(N)
3738
include(ExternalProject)
3839

39-
set (deepdetect_VERSION_MAJOR 0)
40-
set (deepdetect_VERSION_MINOR 1)
41-
4240
# options
4341
OPTION(BUILD_TESTS "Should the tests be built")
4442
OPTION(BUILD_TOOLS "Should the tools be built")
@@ -54,6 +52,14 @@ execute_process(
5452
OUTPUT_STRIP_TRAILING_WHITESPACE
5553
)
5654

55+
# Get the current version
56+
execute_process(
57+
COMMAND git describe --tags --dirty --broken
58+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
59+
OUTPUT_VARIABLE GIT_VERSION
60+
OUTPUT_STRIP_TRAILING_WHITESPACE
61+
)
62+
5763
# Get the latest abbreviated commit hash of the working branch
5864
execute_process(
5965
COMMAND git log -1 --format=%H
@@ -100,8 +106,14 @@ if (${PB_GENERATOR_SYSTEM})
100106
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
101107
endif()
102108

109+
set(CMAKE_CXX_FLAGS "-g -O2 -Wall -Wextra -Werror -fopenmp -fPIC -std=c++14 -DUSE_OPENCV -DUSE_LMDB")
103110

104-
set(CMAKE_CXX_FLAGS "-g -Wall -Wextra -Werror -fopenmp -O2 -fPIC -std=c++14 -DUSE_OPENCV -DUSE_LMDB")
111+
if(RELEASE)
112+
set(BUILD_TYPE release)
113+
else()
114+
set(BUILD_TYPE dev)
115+
string(APPEND CMAKE_CXX_FLAGS " -g")
116+
endif()
105117

106118
if (USE_COMMAND_LINE)
107119
if (NOT USE_CAFFE)
@@ -119,18 +131,6 @@ if (USE_JSON_API)
119131
string(APPEND CMAKE_CXX_FLAGS " -DUSE_JSON_API")
120132
endif()
121133

122-
# configure a header file to pass some of the CMake settings
123-
# to the source code
124-
configure_file (
125-
"${PROJECT_SOURCE_DIR}/dd_config.h.in"
126-
"${PROJECT_BINARY_DIR}/dd_config.h"
127-
)
128-
129-
configure_file(
130-
"${PROJECT_SOURCE_DIR}/src/githash.h.in"
131-
"${PROJECT_BINARY_DIR}/githash.h"
132-
)
133-
134134
# dependency on Eigen for confusion matrix fast computation
135135
if (USE_TF)
136136
set(TENSORFLOW_CC_DIR ${CMAKE_BINARY_DIR}/tensorflow_cc/src/tensorflow_cc/tensorflow_cc/build/)
@@ -1045,6 +1045,13 @@ if (INSTALL_GIT_HOOKS)
10451045
${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit @ONLY)
10461046
endif()
10471047

1048+
# configure a header file to pass some of the CMake settings
1049+
# to the source code
1050+
configure_file (
1051+
"${PROJECT_SOURCE_DIR}/src/dd_config.h.in"
1052+
"${PROJECT_BINARY_DIR}/dd_config.h"
1053+
)
1054+
10481055
# status
10491056
message(STATUS "Build Tests : ${BUILD_TESTS}")
10501057
message(STATUS "Caffe DEBUG : ${USE_CAFFE_DEBUG}")

build.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if [ ! "$DEEPDETECT_CUDA_ARCH" ]; then
1717
DEEPDETECT_CUDA_ARCH="$(echo ${DEEPDETECT_CUDA_ARCH} | xargs)"
1818
fi
1919

20+
DEEPDETECT_RELEASE=${DEEPDETECT_RELEASE:-OFF}
2021

2122
# Help menu with arguments descriptions
2223
help_menu() {
@@ -124,17 +125,17 @@ cpu_build() {
124125
case ${DEEPDETECT_BUILD} in
125126

126127
"tf")
127-
cmake .. -DUSE_TF=ON -DUSE_TF_CPU_ONLY=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DUSE_NCNN=OFF -DUSE_CPU_ONLY=ON
128+
cmake .. -DUSE_TF=ON -DUSE_TF_CPU_ONLY=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DUSE_NCNN=OFF -DUSE_CPU_ONLY=ON -DRELEASE=${DEEPDETECT_RELEASE}
128129
make
129130
;;
130131

131132
"armv7")
132-
cmake .. -DUSE_NCNN=ON -DRPI3=ON -DUSE_HDF5=OFF -DUSE_CAFFE=OFF
133+
cmake .. -DUSE_NCNN=ON -DRPI3=ON -DUSE_HDF5=OFF -DUSE_CAFFE=OFF -DRELEASE=${DEEPDETECT_RELEASE}
133134
make
134135
;;
135136

136137
*)
137-
cmake .. -DUSE_XGBOOST=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DUSE_NCNN=ON -DUSE_CPU_ONLY=ON
138+
cmake .. -DUSE_XGBOOST=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DUSE_NCNN=ON -DUSE_CPU_ONLY=ON -DRELEASE=${DEEPDETECT_RELEASE}
138139
make
139140
;;
140141
esac
@@ -149,7 +150,7 @@ gpu_build() {
149150
"torch") extra_flags="-DUSE_TORCH=ON" ;;
150151
"tensorrt") extra_flags="-DUSE_TENSORRT_OSS=ON" ;;
151152
esac
152-
cmake .. $extra_flags -DUSE_FAISS=ON -DUSE_CUDNN=ON -DUSE_XGBOOST=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DCUDA_ARCH="${DEEPDETECT_CUDA_ARCH}"
153+
cmake .. $extra_flags -DUSE_FAISS=ON -DUSE_CUDNN=ON -DUSE_XGBOOST=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DCUDA_ARCH="${DEEPDETECT_CUDA_ARCH} -DRELEASE=${DEEPDETECT_RELEASE}"
153154
make
154155
}
155156

dd_config.h.in

-7
This file was deleted.

docker/cpu.Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# syntax = docker/dockerfile:1.0-experimental
22
FROM ubuntu:18.04 AS build
33

4+
ARG DEEPDETECT_RELEASE=OFF
45
ARG DEEPDETECT_ARCH=cpu
56
ARG DEEPDETECT_BUILD=default
67
ARG DEEPDETECT_DEFAULT_MODELS=true

src/dd_config.h.in

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef DD_CONFIG_H
2+
#define DD_CONFIG_H
3+
4+
#define BUILD_TYPE "@BUILD_TYPE@"
5+
#define GIT_VERSION "@GIT_VERSION@"
6+
#define GIT_BRANCH "@GIT_BRANCH@"
7+
#define GIT_COMMIT_HASH "@GIT_COMMIT_HASH@"
8+
9+
#define COMPLIE_FLAGS \
10+
"USE_CAFFE2=@USE_CAFFE2@ USE_TF=@USE_TF@ USE_NCNN=@USE_NCNN@ " \
11+
"USE_TORCH=@USE_TORCH@ USE_HDF5=@USE_HDF5@ USE_CAFFE=@USE_CAFFE@ " \
12+
"USE_TENSORRT=@USE_TENSORRT@ USE_TENSORRT_OSS=@USE_TENSORRT_OSS@ " \
13+
"USE_DLIB=@USE_DLIB@ USE_CUDA_CV=@USE_CUDA_CV@ " \
14+
"USE_SIMSEARCH=@USE_SIMSEARCH@ USE_ANNOY=@USE_ANNOY@ " \
15+
"USE_FAISS=@USE_FAISS@ USE_COMMAND_LINE=@USE_COMMAND_LINE@ " \
16+
"USE_JSON_API=@USE_JSON_API@ USE_HTTP_SERVER=@USE_HTTP_SERVER@"
17+
18+
#define DEPS_VERSION \
19+
"OPENCV_VERSION=@OpenCV_VERSION@ " \
20+
"CUDA_VERSION_STRING=@CUDA_VERSION_STRING@ CUDNN_VERSION=@CUDNN_VERSION@"
21+
22+
#endif

src/deepdetect.cc

+4-6
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,15 @@
3636
#include "jsonapi.h"
3737
#endif
3838
#include "dd_config.h"
39-
#include "githash.h"
4039

4140
namespace dd
4241
{
43-
template <class TAPIStrategy>
44-
std::string DeepDetect<TAPIStrategy>::_commit_version = GIT_COMMIT_HASH;
45-
4642
template <class TAPIStrategy> DeepDetect<TAPIStrategy>::DeepDetect()
4743
{
48-
std::cout << "DeepDetect [ commit " << DeepDetect::_commit_version
49-
<< " ]\n";
44+
std::cout << "DeepDetect " << GIT_VERSION << " (" << BUILD_TYPE << ")\n";
45+
std::cout << " GIT REF: " << GIT_BRANCH << ":" << GIT_COMMIT_HASH << "\n";
46+
std::cout << " COMPILE_FLAGS: " << COMPLIE_FLAGS << "\n ";
47+
std::cout << " DEPS_VERSION: " << DEPS_VERSION << "\n ";
5048
}
5149

5250
template <class TAPIStrategy> DeepDetect<TAPIStrategy>::~DeepDetect()

src/githash.h.in

-7
This file was deleted.

src/jsonapi.cc

+10-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include "jsonapi.h"
2323
#include "dd_config.h"
24-
#include "githash.h"
2524
#include <rapidjson/allocators.h>
2625
#include <rapidjson/document.h>
2726
#include <rapidjson/stringbuffer.h>
@@ -402,17 +401,24 @@ namespace dd
402401
JDoc jinfo = dd_ok_200();
403402
JVal jhead(rapidjson::kObjectType);
404403
jhead.AddMember("method", "/info", jinfo.GetAllocator());
405-
std::string sversion
406-
= std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR);
404+
jhead.AddMember("build-type",
405+
JVal().SetString(BUILD_TYPE, jinfo.GetAllocator()),
406+
jinfo.GetAllocator());
407407
jhead.AddMember("version",
408-
JVal().SetString(sversion.c_str(), jinfo.GetAllocator()),
408+
JVal().SetString(GIT_VERSION, jinfo.GetAllocator()),
409409
jinfo.GetAllocator());
410410
jhead.AddMember("branch",
411411
JVal().SetString(GIT_BRANCH, jinfo.GetAllocator()),
412412
jinfo.GetAllocator());
413413
jhead.AddMember("commit",
414414
JVal().SetString(GIT_COMMIT_HASH, jinfo.GetAllocator()),
415415
jinfo.GetAllocator());
416+
jhead.AddMember("compile_flags",
417+
JVal().SetString(COMPLIE_FLAGS, jinfo.GetAllocator()),
418+
jinfo.GetAllocator());
419+
jhead.AddMember("deps_version",
420+
JVal().SetString(DEPS_VERSION, jinfo.GetAllocator()),
421+
jinfo.GetAllocator());
416422
JVal jservs(rapidjson::kArrayType);
417423
auto hit = _mlservices.begin();
418424
while (hit != _mlservices.end())

tools/build-docker-images.sh

+4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ for name in $NAMES; do
4343
arch=${target%%/*}
4444
build=${target##*/}
4545
image_url="${image_url_prefix}_${name}"
46+
release="OFF"
47+
[ "$TAG_NAME" ] && release="ON"
4648

4749
docker build \
4850
-t $image_url:$TMP_TAG \
51+
--progress plain \
4952
--build-arg DEEPDETECT_BUILD=$build \
53+
--build-arg DEEPDETECT_RELEASE=$release \
5054
-f docker/${arch}.Dockerfile \
5155
.
5256

0 commit comments

Comments
 (0)