Skip to content

Commit 6949bc9

Browse files
committed
Merge pull request opencv#12105 from mshabunin:fix-ie-R2
2 parents 9433784 + 7cf52de commit 6949bc9

File tree

5 files changed

+95
-85
lines changed

5 files changed

+95
-85
lines changed

CMakeLists.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,15 +1407,19 @@ if(WITH_HALIDE OR HAVE_HALIDE)
14071407
status(" Halide:" HAVE_HALIDE THEN "YES (${HALIDE_LIBRARIES} ${HALIDE_INCLUDE_DIRS})" ELSE NO)
14081408
endif()
14091409

1410-
if(WITH_INF_ENGINE OR HAVE_INF_ENGINE)
1411-
if(HAVE_INF_ENGINE)
1412-
set(__msg "YES")
1413-
if(DEFINED INF_ENGINE_VERSION)
1414-
set(__msg "YES (ver ${INF_ENGINE_VERSION})")
1410+
if(WITH_INF_ENGINE OR INF_ENGINE_TARGET)
1411+
if(INF_ENGINE_TARGET)
1412+
set(__msg "YES (${INF_ENGINE_RELEASE} / ${INF_ENGINE_VERSION})")
1413+
get_target_property(_lib ${INF_ENGINE_TARGET} IMPORTED_LOCATION)
1414+
if(NOT _lib)
1415+
get_target_property(_lib_rel ${INF_ENGINE_TARGET} IMPORTED_IMPLIB_RELEASE)
1416+
get_target_property(_lib_dbg ${INF_ENGINE_TARGET} IMPORTED_IMPLIB_DEBUG)
1417+
set(_lib "${_lib_rel} / ${_lib_dbg}")
14151418
endif()
1419+
get_target_property(_inc ${INF_ENGINE_TARGET} INTERFACE_INCLUDE_DIRECTORIES)
14161420
status(" Inference Engine:" "${__msg}")
1417-
status(" libs:" "${INF_ENGINE_LIBRARIES}")
1418-
status(" includes:" "${INF_ENGINE_INCLUDE_DIRS}")
1421+
status(" libs:" "${_lib}")
1422+
status(" includes:" "${_inc}")
14191423
else()
14201424
status(" Inference Engine:" "NO")
14211425
endif()
Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,87 @@
11
# The script detects Intel(R) Inference Engine installation
22
#
3-
# Parameters:
4-
# INTEL_CVSDK_DIR - Path to Inference Engine root folder
5-
# IE_PLUGINS_PATH - Path to folder with Inference Engine plugins
3+
# Cache variables:
4+
# INF_ENGINE_OMP_DIR - directory with OpenMP library to link with (needed by some versions of IE)
5+
# INF_ENGINE_RELEASE - a number reflecting IE source interface (linked with OpenVINO release)
66
#
7-
# On return this will define:
7+
# Detect parameters:
8+
# 1. Native cmake IE package:
9+
# - enironment variable InferenceEngine_DIR is set to location of cmake module
10+
# 2. Custom location:
11+
# - INF_ENGINE_INCLUDE_DIRS - headers search location
12+
# - INF_ENGINE_LIB_DIRS - library search location
13+
# 3. OpenVINO location:
14+
# - environment variable INTEL_CVSDK_DIR is set to location of OpenVINO installation dir
15+
# - INF_ENGINE_PLATFORM - part of name of library directory representing its platform (default ubuntu_16.04)
816
#
9-
# HAVE_INF_ENGINE - True if Intel Inference Engine was found
10-
# INF_ENGINE_INCLUDE_DIRS - Inference Engine include folder
11-
# INF_ENGINE_LIBRARIES - Inference Engine libraries and it's dependencies
17+
# Result:
18+
# INF_ENGINE_TARGET - set to name of imported library target representing InferenceEngine
1219
#
13-
macro(ie_fail)
14-
set(HAVE_INF_ENGINE FALSE)
15-
return()
16-
endmacro()
1720

1821
if(NOT HAVE_CXX11)
1922
message(WARNING "DL Inference engine requires C++11. You can turn it on via ENABLE_CXX11=ON CMake flag.")
20-
ie_fail()
21-
endif()
22-
23-
find_package(InferenceEngine QUIET)
24-
if(InferenceEngine_FOUND)
25-
set(INF_ENGINE_LIBRARIES "${InferenceEngine_LIBRARIES}")
26-
set(INF_ENGINE_INCLUDE_DIRS "${InferenceEngine_INCLUDE_DIRS}")
27-
set(INF_ENGINE_VERSION "${InferenceEngine_VERSION}")
28-
set(HAVE_INF_ENGINE TRUE)
29-
return()
23+
return()
3024
endif()
3125

32-
ocv_check_environment_variables(INTEL_CVSDK_DIR INF_ENGINE_ROOT_DIR IE_PLUGINS_PATH)
26+
# =======================
3327

34-
if(NOT INF_ENGINE_ROOT_DIR OR NOT EXISTS "${INF_ENGINE_ROOT_DIR}/include/inference_engine.hpp")
35-
set(ie_root_paths "${INF_ENGINE_ROOT_DIR}")
36-
if(DEFINED INTEL_CVSDK_DIR)
37-
list(APPEND ie_root_paths "${INTEL_CVSDK_DIR}/")
38-
list(APPEND ie_root_paths "${INTEL_CVSDK_DIR}/deployment_tools/inference_engine")
39-
endif()
28+
function(add_custom_ie_build _inc _lib _lib_rel _lib_dbg _msg)
29+
if(NOT _inc OR NOT (_lib OR _lib_rel OR _lib_dbg))
30+
return()
31+
endif()
32+
add_library(inference_engine UNKNOWN IMPORTED)
33+
set_target_properties(inference_engine PROPERTIES
34+
IMPORTED_LOCATION "${_lib}"
35+
IMPORTED_IMPLIB_RELEASE "${_lib_rel}"
36+
IMPORTED_IMPLIB_DEBUG "${_lib_dbg}"
37+
INTERFACE_INCLUDE_DIRECTORIES "${_inc}"
38+
)
39+
find_library(omp_lib iomp5 PATHS "${INF_ENGINE_OMP_DIR}" NO_DEFAULT_PATH)
40+
if(NOT omp_lib)
41+
message(WARNING "OpenMP for IE have not been found. Set INF_ENGINE_OMP_DIR variable if you experience build errors.")
42+
else()
43+
set_target_properties(inference_engine PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES "${omp_lib}")
44+
endif()
45+
set(INF_ENGINE_VERSION "Unknown" CACHE STRING "")
46+
set(INF_ENGINE_TARGET inference_engine PARENT_SCOPE)
47+
message(STATUS "Detected InferenceEngine: ${_msg}")
48+
endfunction()
4049

41-
if(NOT ie_root_paths)
42-
list(APPEND ie_root_paths "/opt/intel/computer_vision_sdk/deployment_tools/inference_engine/")
43-
endif()
50+
# ======================
4451

45-
find_path(INF_ENGINE_ROOT_DIR include/inference_engine.hpp PATHS ${ie_root_paths})
46-
if(INF_ENGINE_ROOT_DIR MATCHES "-NOTFOUND$")
47-
unset(INF_ENGINE_ROOT_DIR CACHE)
48-
endif()
52+
find_package(InferenceEngine QUIET)
53+
if(InferenceEngine_FOUND)
54+
set(INF_ENGINE_TARGET IE::inference_engine)
55+
set(INF_ENGINE_VERSION "${InferenceEngine_VERSION}" CACHE STRING "")
56+
message(STATUS "Detected InferenceEngine: cmake package")
4957
endif()
5058

51-
set(INF_ENGINE_INCLUDE_DIRS "${INF_ENGINE_ROOT_DIR}/include" CACHE PATH "Path to Inference Engine include directory")
52-
53-
if(NOT INF_ENGINE_ROOT_DIR
54-
OR NOT EXISTS "${INF_ENGINE_ROOT_DIR}"
55-
OR NOT EXISTS "${INF_ENGINE_ROOT_DIR}/include/inference_engine.hpp"
56-
)
57-
message(WARNING "DL IE: Can't detect INF_ENGINE_ROOT_DIR location.")
58-
ie_fail()
59+
if(NOT INF_ENGINE_TARGET AND INF_ENGINE_LIB_DIRS AND INF_ENGINE_INCLUDE_DIRS)
60+
find_path(ie_custom_inc "inference_engine.hpp" PATHS "${INF_ENGINE_INCLUDE_DIRS}" NO_DEFAULT_PATH)
61+
find_library(ie_custom_lib "inference_engine" PATHS "${INF_ENGINE_LIB_DIRS}" NO_DEFAULT_PATH)
62+
find_library(ie_custom_lib_rel "inference_engine" PATHS "${INF_ENGINE_LIB_DIRS}/Release" NO_DEFAULT_PATH)
63+
find_library(ie_custom_lib_dbg "inference_engine" PATHS "${INF_ENGINE_LIB_DIRS}/Debug" NO_DEFAULT_PATH)
64+
add_custom_ie_build("${ie_custom_inc}" "${ie_custom_lib}" "${ie_custom_lib_rel}" "${ie_custom_lib_dbg}" "INF_ENGINE_{INCLUDE,LIB}_DIRS")
5965
endif()
6066

61-
set(INF_ENGINE_LIBRARIES "")
62-
63-
set(ie_lib_list inference_engine)
64-
65-
if(NOT IS_ABSOLUTE "${IE_PLUGINS_PATH}")
66-
set(IE_PLUGINS_PATH "${INF_ENGINE_ROOT_DIR}/${IE_PLUGINS_PATH}")
67+
set(_loc "$ENV{INTEL_CVSDK_DIR}")
68+
if(NOT INF_ENGINE_TARGET AND _loc)
69+
set(INF_ENGINE_PLATFORM "ubuntu_16.04" CACHE STRING "InferenceEngine platform (library dir)")
70+
find_path(ie_custom_env_inc "inference_engine.hpp" PATHS "${_loc}/deployment_tools/inference_engine/include" NO_DEFAULT_PATH)
71+
find_library(ie_custom_env_lib "inference_engine" PATHS "${_loc}/deployment_tools/inference_engine/lib/${INF_ENGINE_PLATFORM}/intel64" NO_DEFAULT_PATH)
72+
find_library(ie_custom_env_lib_rel "inference_engine" PATHS "${_loc}/deployment_tools/inference_engine/lib/intel64/Release" NO_DEFAULT_PATH)
73+
find_library(ie_custom_env_lib_dbg "inference_engine" PATHS "${_loc}/deployment_tools/inference_engine/lib/intel64/Debug" NO_DEFAULT_PATH)
74+
add_custom_ie_build("${ie_custom_env_inc}" "${ie_custom_env_lib}" "${ie_custom_env_lib_rel}" "${ie_custom_env_lib_dbg}" "OpenVINO (${_loc})")
6775
endif()
6876

69-
link_directories(
70-
${INF_ENGINE_ROOT_DIR}/external/mkltiny_lnx/lib
71-
${INF_ENGINE_ROOT_DIR}/external/cldnn/lib
72-
)
73-
74-
foreach(lib ${ie_lib_list})
75-
find_library(${lib} NAMES ${lib} HINTS ${IE_PLUGINS_PATH})
76-
if(NOT ${lib})
77-
message(WARNING "DL IE: Can't find library: '${lib}'")
78-
ie_fail()
79-
endif()
80-
list(APPEND INF_ENGINE_LIBRARIES ${${lib}})
81-
endforeach()
77+
# Add more features to the target
8278

83-
set(HAVE_INF_ENGINE TRUE)
79+
if(INF_ENGINE_TARGET)
80+
if(NOT INF_ENGINE_RELEASE)
81+
message(WARNING "InferenceEngine version have not been set, 2018R2 will be used by default. Set INF_ENGINE_RELEASE variable if you experience build errors.")
82+
endif()
83+
set(INF_ENGINE_RELEASE "2018020000" CACHE STRING "Force IE version, should be in form YYYYAABBCC (e.g. 2018R2.0.2 -> 2018020002)")
84+
set_target_properties(${INF_ENGINE_TARGET} PROPERTIES
85+
INTERFACE_COMPILE_DEFINITIONS "HAVE_INF_ENGINE=1;INF_ENGINE_RELEASE=${INF_ENGINE_RELEASE}"
86+
)
87+
endif()

modules/dnn/CMakeLists.txt

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,16 @@ else()
8585
set(sources_options EXCLUDE_OPENCL)
8686
endif()
8787

88-
if(HAVE_INF_ENGINE)
89-
add_definitions(-DHAVE_INF_ENGINE=1)
90-
list(APPEND include_dirs ${INF_ENGINE_INCLUDE_DIRS})
91-
list(APPEND libs ${INF_ENGINE_LIBRARIES})
92-
endif()
93-
9488
ocv_module_include_directories(${include_dirs})
9589
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
9690
ocv_append_source_files_cxx_compiler_options(fw_srcs "-Wno-suggest-override") # GCC
9791
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
9892
ocv_append_source_files_cxx_compiler_options(fw_srcs "-Wno-inconsistent-missing-override") # Clang
9993
endif()
10094
ocv_glob_module_sources(${sources_options} SOURCES ${fw_srcs})
101-
ocv_create_module(${libs})
95+
ocv_create_module(${libs} ${INF_ENGINE_TARGET})
10296
ocv_add_samples()
103-
ocv_add_accuracy_tests()
97+
ocv_add_accuracy_tests(${INF_ENGINE_TARGET})
10498
ocv_add_perf_tests()
10599

106100
ocv_option(${the_module}_PERF_CAFFE "Add performance tests of Caffe framework" OFF)
@@ -120,9 +114,3 @@ if(BUILD_PERF_TESTS)
120114
endif()
121115
endif()
122116
endif()
123-
124-
# Test Intel's Inference Engine models
125-
if(HAVE_INF_ENGINE AND TARGET opencv_test_dnn)
126-
ocv_target_include_directories(opencv_test_dnn PRIVATE ${INF_ENGINE_INCLUDE_DIRS})
127-
ocv_target_link_libraries(opencv_test_dnn LINK_PRIVATE ${INF_ENGINE_LIBRARIES})
128-
endif()

modules/dnn/src/op_inf_engine.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ size_t InfEngineBackendNet::getBatchSize() const noexcept
334334
return 0;
335335
}
336336

337+
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R2)
337338
InferenceEngine::StatusCode InfEngineBackendNet::AddExtension(const InferenceEngine::IShapeInferExtensionPtr &extension, InferenceEngine::ResponseDesc *resp) noexcept
338339
{
339340
CV_Error(Error::StsNotImplemented, "");
@@ -345,6 +346,7 @@ InferenceEngine::StatusCode InfEngineBackendNet::reshape(const InferenceEngine::
345346
CV_Error(Error::StsNotImplemented, "");
346347
return InferenceEngine::StatusCode::OK;
347348
}
349+
#endif
348350

349351
void InfEngineBackendNet::init(int targetId)
350352
{

modules/dnn/src/op_inf_engine.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
#if defined(__GNUC__) && __GNUC__ >= 5
2222
//#pragma GCC diagnostic pop
2323
#endif
24+
25+
#define INF_ENGINE_RELEASE_2018R1 2018010000
26+
#define INF_ENGINE_RELEASE_2018R2 2018020000
27+
28+
#ifndef INF_ENGINE_RELEASE
29+
#warning("IE version have not been provided via command-line. Using 2018R2 by default")
30+
#define INF_ENGINE_RELEASE INF_ENGINE_RELEASE_2018R2
31+
#endif
32+
33+
#define INF_ENGINE_VER_MAJOR_GT(ver) (((INF_ENGINE_RELEASE) / 10000) > ((ver) / 10000))
34+
2435
#endif // HAVE_INF_ENGINE
2536

2637
namespace cv { namespace dnn {
@@ -92,9 +103,10 @@ class InfEngineBackendNet : public InferenceEngine::ICNNNetwork
92103

93104
virtual size_t getBatchSize() const noexcept CV_OVERRIDE;
94105

106+
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R2)
95107
virtual InferenceEngine::StatusCode AddExtension(const InferenceEngine::IShapeInferExtensionPtr& extension, InferenceEngine::ResponseDesc* resp) noexcept;
96-
97108
virtual InferenceEngine::StatusCode reshape(const InputShapes& inputShapes, InferenceEngine::ResponseDesc* resp) noexcept;
109+
#endif
98110

99111
void init(int targetId);
100112

0 commit comments

Comments
 (0)