Conversation
c939ea9 to
40a1d74
Compare
cmake/templates/cvconfig.h.in
Outdated
| #cmakedefine HAVE_VULKAN | ||
|
|
||
| /* TimVx support */ | ||
| #cmakedefine HAVE_TIMVX |
There was a problem hiding this comment.
Don't change cvconfig.h content anymore with module-specific definitions.
Use add_definitions() in DNN module only.
modules/dnn/include/opencv2/dnn.hpp
Outdated
| */ | ||
| /** @example samples/dnn/text_detection.cpp | ||
| */ | ||
|
|
There was a problem hiding this comment.
remove unnecessary changes from the PR
| public: | ||
| int input_zp, output_zp; | ||
| float output_sc; | ||
| float output_sc, input_sc; |
There was a problem hiding this comment.
align order of input/output variables.
| CV_WRAP DictValue(double p) : type(Param::REAL), pd(new AutoBuffer<double,1>) { (*pd)[0] = p; } //!< Constructs floating point scalar | ||
| CV_WRAP DictValue(const String &s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< Constructs string scalar | ||
| DictValue(const char *s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< @overload | ||
| // DictValue(const uchar *s1) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s1; } //!< @overload |
| DNN_TARGET_CUDA_FP16, | ||
| DNN_TARGET_HDDL | ||
| DNN_TARGET_NPU, | ||
| DNN_TARGET_HDDL, |
There was a problem hiding this comment.
Enum additions should go to the end.
There was a problem hiding this comment.
Hi, @alalek. Thank you for code review. In my test, if I move DNN_BACKEND_TIMVX to the end of enum Backend, I will get an error.
If I do the following, the value of DNN_BACKEND_TIMVX in the OpenCV library is 1000001, while the value of DNN_BACKEND_TIMVX when calling the OpenCV library is 6.
This may be caused by #ifdef __OPENCV_BUILD flag. In this case, I can not use DNN_BACKEND_TIMVX to trigger TimVx Backend, I can only use 1000001 to do it.
It happens on Ubuntu of ARM, but not for the Ubuntu of X86.
enum Backend
{
//! DNN_BACKEND_DEFAULT equals to DNN_BACKEND_INFERENCE_ENGINE if
//! OpenCV is built with Intel's Inference Engine library or
//! DNN_BACKEND_OPENCV otherwise.
DNN_BACKEND_DEFAULT = 0,
DNN_BACKEND_HALIDE,
DNN_BACKEND_INFERENCE_ENGINE, //!< Intel's Inference Engine computational backend
//!< @sa setInferenceEngineBackendType
DNN_BACKEND_OPENCV,
DNN_BACKEND_VKCOM,
DNN_BACKEND_CUDA,
#ifdef __OPENCV_BUILD
DNN_BACKEND_INFERENCE_ENGINE_NGRAPH = 1000000, // internal - use DNN_BACKEND_INFERENCE_ENGINE + setInferenceEngineBackendType()
DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019, // internal - use DNN_BACKEND_INFERENCE_ENGINE + setInferenceEngineBackendType()
#endif
DNN_BACKEND_TIMVX
};There was a problem hiding this comment.
This comment is about TARGET, not BACKEND.
Requirement of addition to the end comes from preserving values of already existed enum items.
There was a problem hiding this comment.
In BACKEND put to the end before #ifdef __OPENCV_BUILD
There was a problem hiding this comment.
Thank your reply, got it.
modules/dnn/src/dnn.cpp
Outdated
| case DNN_TARGET_FPGA: out << "FPGA"; colorId = 4; break; | ||
| case DNN_TARGET_CUDA: out << "CUDA"; colorId = 5; break; | ||
| case DNN_TARGET_CUDA_FP16: out << "CUDA_FP16"; colorId = 6; break; | ||
| case DNN_TARGET_NPU: out << "NPU"; colorId = 9; break; |
There was a problem hiding this comment.
std::vector<string> colors must be updated too.
There was a problem hiding this comment.
Thanks, It was fixed in the latest update.
|
|
||
| #ifdef HAVE_TIMVX | ||
| // For TimVx | ||
| input_sc = params.get<float>("input_scale"); |
There was a problem hiding this comment.
Field is defined in public API, so it must be initialized regardless of build flags.
| _MM_SET_FLUSH_ZERO_MODE(ftzMode); | ||
| _MM_SET_DENORMALS_ZERO_MODE(dazMode); | ||
| #endif | ||
|
|
| hasVecInput = false; | ||
| op = SUM; | ||
|
|
||
|
|
modules/dnn/src/op_timvx.cpp
Outdated
| tim::vx::DataType tensorDataType; | ||
| switch(matDepth) | ||
| { | ||
| case 0: // CV_8U |
There was a problem hiding this comment.
0
we don't need magic numbers here. Use CV_8U directly.
There was a problem hiding this comment.
Thanks, it was fixed in the latest update.
fengyuentau
left a comment
There was a problem hiding this comment.
make install will failed when TIM-VX is building from source:
-- Up-to-date: /home/tau/Workspace/fengyuentau/opencv/build/install/lib/libtim-vx.a
-- Up-to-date: /home/tau/Workspace/fengyuentau/opencv/build/install/lib/libtim-vx.a
CMake Error at 3rdparty/libtim-vx/build/src/tim/cmake_install.cmake:78 (file):
file INSTALL cannot find
"/home/tau/Workspace/fengyuentau/opencv/include/tim/vx": No such file or
directory.
Call Stack (most recent call first):
3rdparty/libtim-vx/build/cmake_install.cmake:42 (include)
cmake_install.cmake:135 (include)
make: *** [Makefile:86: install] Error 1
We need to find a way to solve this.
fengyuentau
left a comment
There was a problem hiding this comment.
Current version of cmake code requires TIM-VX to be built as static library, which solves the previous make install error. We will wait for the fix of TIM-VX to solve the linking problem.
559245f to
7e38da5
Compare
|
@alalek May I know which version of glibc in linux64 in the default ci? We got the following error /build/precommit_linux64/build/3rdparty/libtim-vx/VIVANTE_SDK/x86_64.prebuilt.ci.sdk/drivers/libOpenVX.so.1: undefined reference to `logf@GLIBC_2.27'
/build/precommit_linux64/build/3rdparty/libtim-vx/VIVANTE_SDK/x86_64.prebuilt.ci.sdk/drivers/libOpenVX.so.1: undefined reference to `powf@GLIBC_2.27'
/build/precommit_linux64/build/3rdparty/libtim-vx/VIVANTE_SDK/x86_64.prebuilt.ci.sdk/drivers/libOpenVX.so.1: undefined reference to `expf@GLIBC_2.27'
collect2: error: ld returned 1 exit status
apps/model-diagnostics/CMakeFiles/opencv_model_diagnostics.dir/build.make:99: recipe for target 'bin/opencv_model_diagnostics' failed
make[2]: Leaving directory '/build/precommit_linux64/build'
make[2]: *** [bin/opencv_model_diagnostics] Error 1
make[1]: *** [apps/model-diagnostics/CMakeFiles/opencv_model_diagnostics.dir/all] Error 2
CMakeFiles/Makefile2:22736: recipe for target 'apps/model-diagnostics/CMakeFiles/opencv_model_diagnostics.dir/all' failed
make[1]: *** Waiting for unfinished jobs....implying the unmatched versions of glibc between the one used in ci (older) and the one used to compile libOpenVX (newer). |
|
Base image for this builder is |
@alalek So can I get the same image via |
Not the same. Image is based on ubuntu:16.04. Take a look on "Linux AVX2" based on Ubuntu 18.04 - there are set of other issues with pre-compiled binaries. Pre-compiled binaries are not universal in general. Using of pre-compiled binaries reduces set of supported platforms. |
5e0c5dd to
1ae0621
Compare
b923992 to
4e2a806
Compare
modules/dnn/src/dnn.cpp
Outdated
|
|
||
| #ifdef HAVE_TIMVX | ||
| // update all comsumer | ||
| void tvUpdateConfictMap(int graphIndex, LayerData& ld, std::vector<std::vector<int> >& graphConflictMap) |
There was a problem hiding this comment.
To resolve conflicts with merged #21662 please:
- move methods declaration into
modules/dnn/src/net_impl.hppfile + puttimVxInfodeclaration near it (after all common fields) - methods implementation should be moved into
op_timvx.cpp(see halide code as example)
There was a problem hiding this comment.
@alalek Thanks for your guidance. We have completed the code refactoring.
0d5330b to
e51bea2
Compare
alalek
left a comment
There was a problem hiding this comment.
Overall looks good to me!
Please take a look on "white space" check issues from "Docs" builder.
a00f4a4 to
82eac54
Compare
vpisarev
left a comment
There was a problem hiding this comment.
tested it on my machine, works well!
1e0cf9b to
2a7387a
Compare
3rdparty/libtim-vx/tim-vx.cmake
Outdated
| set(TIMVX_FOUND ON) | ||
| else() | ||
| set(OCV_TIMVX_FILENAME "${TIMVX_COMMIT_HASH}.zip") | ||
| set(OCV_TIMVX_URL "https://github.com/fengyuentau/TIM-VX/archive/") |
There was a problem hiding this comment.
We are going to have a discussion with TIM-VX devs to work out a branch in TIM-VX repo for us to use.
23fc2dc to
f45400d
Compare
dnn: TIM-VX NPU backend support * Add TimVX NPU backend for DNN module. * use official branch from tim-vx repo; fix detecting viv sdk Co-authored-by: fytao <yuantao.feng@outlook.com>
…or_timvx_backend CI for TIM-VX backend * github actions for TIM-VX backend opencv#21036 * add reference to yuentau/ocv_ubuntu:20.04; remove extra quotes; enable BUILD_TESTS * rename to timvx_backend_tests.yml * add image source prefix * remove if condition for x86_64 simulator
This PR adds TIM-VX NPU backend to DNN module.
Tutorial on how to use the TIM-VX backend.
https://gist.github.com/fengyuentau/5a7a5ba36328f2b763aea026c43fa45f
Cross compilation for aarch64 and build and run tests with x86_64 simulators using docker: https://gist.github.com/fengyuentau/bf9e54f80dbec4cc0ea13b8f8a985f0b
NPU chip is commonly used DNN acceleration chip. TIM-VX is good NPU backend, it can support 8-bit ops, and its API follows the OpenVX protocol.
OpenCV without TIM-VX works with NEON.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.