Skip to content

Commit

Permalink
feat(api): add versions and compile flags to /info
Browse files Browse the repository at this point in the history
Close #897
  • Loading branch information
sileht committed Oct 21, 2020
1 parent 41a5de3 commit 67b1d99
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 44 deletions.
39 changes: 23 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 2.8.8)
project(deepdetect)

option(RELEASE "release mode" OFF)
option(USE_CAFFE2 "build caffe2 backend")
option(USE_TF "use TF backend")
option(USE_NCNN "use NCNN backend")
Expand Down Expand Up @@ -36,9 +37,6 @@ include(ProcessorCount)
ProcessorCount(N)
include(ExternalProject)

set (deepdetect_VERSION_MAJOR 0)
set (deepdetect_VERSION_MINOR 1)

# options
OPTION(BUILD_TESTS "Should the tests be built")
OPTION(BUILD_TOOLS "Should the tools be built")
Expand All @@ -54,6 +52,14 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Get the current version
execute_process(
COMMAND git describe --tags --dirty --broken
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%H
Expand Down Expand Up @@ -100,8 +106,14 @@ if (${PB_GENERATOR_SYSTEM})
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()

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

set(CMAKE_CXX_FLAGS "-g -Wall -Wextra -Werror -fopenmp -O2 -fPIC -std=c++14 -DUSE_OPENCV -DUSE_LMDB")
if(RELEASE)
set(BUILD_TYPE release)
else()
set(BUILD_TYPE dev)
string(APPEND CMAKE_CXX_FLAGS " -g")
endif()

if (USE_COMMAND_LINE)
if (NOT USE_CAFFE)
Expand All @@ -119,18 +131,6 @@ if (USE_JSON_API)
string(APPEND CMAKE_CXX_FLAGS " -DUSE_JSON_API")
endif()

# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/dd_config.h.in"
"${PROJECT_BINARY_DIR}/dd_config.h"
)

configure_file(
"${PROJECT_SOURCE_DIR}/src/githash.h.in"
"${PROJECT_BINARY_DIR}/githash.h"
)

# dependency on Eigen for confusion matrix fast computation
if (USE_TF)
set(TENSORFLOW_CC_DIR ${CMAKE_BINARY_DIR}/tensorflow_cc/src/tensorflow_cc/tensorflow_cc/build/)
Expand Down Expand Up @@ -1045,6 +1045,13 @@ if (INSTALL_GIT_HOOKS)
${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit @ONLY)
endif()

# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/src/dd_config.h.in"
"${PROJECT_BINARY_DIR}/dd_config.h"
)

# status
message(STATUS "Build Tests : ${BUILD_TESTS}")
message(STATUS "Caffe DEBUG : ${USE_CAFFE_DEBUG}")
9 changes: 5 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if [ ! "$DEEPDETECT_CUDA_ARCH" ]; then
DEEPDETECT_CUDA_ARCH="$(echo ${DEEPDETECT_CUDA_ARCH} | xargs)"
fi

DEEPDETECT_RELEASE=${DEEPDETECT_RELEASE:-OFF}

# Help menu with arguments descriptions
help_menu() {
Expand Down Expand Up @@ -124,17 +125,17 @@ cpu_build() {
case ${DEEPDETECT_BUILD} in

"tf")
cmake .. -DUSE_TF=ON -DUSE_TF_CPU_ONLY=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DUSE_NCNN=OFF -DUSE_CPU_ONLY=ON
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}
make
;;

"armv7")
cmake .. -DUSE_NCNN=ON -DRPI3=ON -DUSE_HDF5=OFF -DUSE_CAFFE=OFF
cmake .. -DUSE_NCNN=ON -DRPI3=ON -DUSE_HDF5=OFF -DUSE_CAFFE=OFF -DRELEASE=${DEEPDETECT_RELEASE}
make
;;

*)
cmake .. -DUSE_XGBOOST=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DUSE_NCNN=ON -DUSE_CPU_ONLY=ON
cmake .. -DUSE_XGBOOST=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DUSE_NCNN=ON -DUSE_CPU_ONLY=ON -DRELEASE=${DEEPDETECT_RELEASE}
make
;;
esac
Expand All @@ -149,7 +150,7 @@ gpu_build() {
"torch") extra_flags="-DUSE_TORCH=ON" ;;
"tensorrt") extra_flags="-DUSE_TENSORRT_OSS=ON" ;;
esac
cmake .. $extra_flags -DUSE_FAISS=ON -DUSE_CUDNN=ON -DUSE_XGBOOST=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DCUDA_ARCH="${DEEPDETECT_CUDA_ARCH}"
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}"
make
}

Expand Down
7 changes: 0 additions & 7 deletions dd_config.h.in

This file was deleted.

1 change: 1 addition & 0 deletions docker/cpu.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# syntax = docker/dockerfile:1.0-experimental
FROM ubuntu:18.04 AS build

ARG DEEPDETECT_RELEASE=OFF
ARG DEEPDETECT_ARCH=cpu
ARG DEEPDETECT_BUILD=default
ARG DEEPDETECT_DEFAULT_MODELS=true
Expand Down
22 changes: 22 additions & 0 deletions src/dd_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef DD_CONFIG_H
#define DD_CONFIG_H

#define BUILD_TYPE "@BUILD_TYPE@"
#define GIT_VERSION "@GIT_VERSION@"
#define GIT_BRANCH "@GIT_BRANCH@"
#define GIT_COMMIT_HASH "@GIT_COMMIT_HASH@"

#define COMPLIE_FLAGS \
"USE_CAFFE2=@USE_CAFFE2@ USE_TF=@USE_TF@ USE_NCNN=@USE_NCNN@ " \
"USE_TORCH=@USE_TORCH@ USE_HDF5=@USE_HDF5@ USE_CAFFE=@USE_CAFFE@ " \
"USE_TENSORRT=@USE_TENSORRT@ USE_TENSORRT_OSS=@USE_TENSORRT_OSS@ " \
"USE_DLIB=@USE_DLIB@ USE_CUDA_CV=@USE_CUDA_CV@ " \
"USE_SIMSEARCH=@USE_SIMSEARCH@ USE_ANNOY=@USE_ANNOY@ " \
"USE_FAISS=@USE_FAISS@ USE_COMMAND_LINE=@USE_COMMAND_LINE@ " \
"USE_JSON_API=@USE_JSON_API@ USE_HTTP_SERVER=@USE_HTTP_SERVER@"

#define DEPS_VERSION \
"OPENCV_VERSION=@OpenCV_VERSION@ " \
"CUDA_VERSION_STRING=@CUDA_VERSION_STRING@ CUDNN_VERSION=@CUDNN_VERSION@"

#endif
10 changes: 4 additions & 6 deletions src/deepdetect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@
#include "jsonapi.h"
#endif
#include "dd_config.h"
#include "githash.h"

namespace dd
{
template <class TAPIStrategy>
std::string DeepDetect<TAPIStrategy>::_commit_version = GIT_COMMIT_HASH;

template <class TAPIStrategy> DeepDetect<TAPIStrategy>::DeepDetect()
{
std::cout << "DeepDetect [ commit " << DeepDetect::_commit_version
<< " ]\n";
std::cout << "DeepDetect " << GIT_VERSION << " (" << BUILD_TYPE << ")\n";
std::cout << "GIT REF: " << GIT_BRANCH << ":" << GIT_COMMIT_HASH << "\n";
std::cout << "COMPILE_FLAGS: " << COMPLIE_FLAGS << "\n";
std::cout << "DEPS_VERSION: " << DEPS_VERSION << "\n ";
}

template <class TAPIStrategy> DeepDetect<TAPIStrategy>::~DeepDetect()
Expand Down
7 changes: 0 additions & 7 deletions src/githash.h.in

This file was deleted.

14 changes: 10 additions & 4 deletions src/jsonapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include "jsonapi.h"
#include "dd_config.h"
#include "githash.h"
#include <rapidjson/allocators.h>
#include <rapidjson/document.h>
#include <rapidjson/stringbuffer.h>
Expand Down Expand Up @@ -402,17 +401,24 @@ namespace dd
JDoc jinfo = dd_ok_200();
JVal jhead(rapidjson::kObjectType);
jhead.AddMember("method", "/info", jinfo.GetAllocator());
std::string sversion
= std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR);
jhead.AddMember("build-type",
JVal().SetString(BUILD_TYPE, jinfo.GetAllocator()),
jinfo.GetAllocator());
jhead.AddMember("version",
JVal().SetString(sversion.c_str(), jinfo.GetAllocator()),
JVal().SetString(GIT_VERSION, jinfo.GetAllocator()),
jinfo.GetAllocator());
jhead.AddMember("branch",
JVal().SetString(GIT_BRANCH, jinfo.GetAllocator()),
jinfo.GetAllocator());
jhead.AddMember("commit",
JVal().SetString(GIT_COMMIT_HASH, jinfo.GetAllocator()),
jinfo.GetAllocator());
jhead.AddMember("compile_flags",
JVal().SetString(COMPLIE_FLAGS, jinfo.GetAllocator()),
jinfo.GetAllocator());
jhead.AddMember("deps_version",
JVal().SetString(DEPS_VERSION, jinfo.GetAllocator()),
jinfo.GetAllocator());
JVal jservs(rapidjson::kArrayType);
auto hit = _mlservices.begin();
while (hit != _mlservices.end())
Expand Down
4 changes: 4 additions & 0 deletions tools/build-docker-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ for name in $NAMES; do
arch=${target%%/*}
build=${target##*/}
image_url="${image_url_prefix}_${name}"
release="OFF"
[ "$TAG_NAME" ] && release="ON"

docker build \
-t $image_url:$TMP_TAG \
--progress plain \
--build-arg DEEPDETECT_BUILD=$build \
--build-arg DEEPDETECT_RELEASE=$release \
-f docker/${arch}.Dockerfile \
.

Expand Down

0 comments on commit 67b1d99

Please sign in to comment.