dnn: add plugin support for OpenVINO#21745
Conversation
|
@rogday It makes sense to start review from "backend API" in this file: modules/dnn/src/backend.hpp |
mshabunin
left a comment
There was a problem hiding this comment.
Overall looks good to me, though I haven't reviewed some parts in details.
Some notes:
- perhaps we need to extract common registry/factory/backend/cmake part from all plugin-compatible modules
- we don't have
worldbuilder in CI, will we support this configuration?
modules/dnn/CMakeLists.txt
Outdated
| endif() | ||
| list(APPEND dnn_runtime_libs ocv.3rdparty.openvino) | ||
| if("openvino" IN_LIST DNN_PLUGIN_LIST OR DNN_PLUGIN_LIST STREQUAL "all") | ||
| add_subdirectory(misc/plugin/openvino) # plugin doesn't support PCH, separate directory scope is necessary |
There was a problem hiding this comment.
It does not work with world build:
$ cmake -GNinja \
-DWITH_OPENVINO=ON \
-DBUILD_opencv_world=ON \
../opencvCMake Error at modules/dnn/CMakeLists.txt:207 (add_subdirectory):
add_subdirectory given source "misc/plugin/openvino" which is not an
existing directory.
Call Stack (most recent call first):
modules/world/CMakeLists.txt:13 (include)
modules/world/CMakeLists.txt:32 (include_one_module)
There was a problem hiding this comment.
Fixed.
To properly use OV plugin need to disable GAPI module or OV-in-GAPI:
-DBUILD_opencv_gapi=OFF- or
-DOPENCV_GAPI_WITH_OPENVINO=OFF
Otherwise gapi links OpenVINO to opencv_world directly, which affects DNN code compilation flags too.
| //} // Net::Impl | ||
|
|
||
| #if 0 | ||
| #define printf_(args) printf args |
There was a problem hiding this comment.
Maybe it would be better to use logging facilities? Are they available in the plugin?
There was a problem hiding this comment.
It makes sense in general.
Currently it is out of scope of this PR as mentioned code is a copy-paste.
rogday
left a comment
There was a problem hiding this comment.
Thank you for contribution! Design looks good.
A few minor comments.
| { | ||
| CV_Assert(instancePtr); | ||
| // TODO C++20 "aliasing constructor" | ||
| return std::shared_ptr<cv::dnn_backend::NetworkBackend>(instancePtr, [](cv::dnn_backend::NetworkBackend*){}); // empty deleter |
There was a problem hiding this comment.
Maybe we could capture shared_from_this() inside a deleter for now?
Seems to achieve the same goal.
There was a problem hiding this comment.
- This requires changes in class inheritance (use
std::enable_shared_from_this<T>). I prefer to keep interfaces clear as much as possible. - I don't want to transfer object lifetime control from the plugin (it could not prevent unloading of plugin code anyway).
There was a problem hiding this comment.
- Line 22:
class PluginDNNBackend CV_FINAL: public std::enable_shared_from_this<PluginDNNBackend> - Then why
shared_ptris used in the first place? - Does TODO makes sense then?
There was a problem hiding this comment.
PluginDNNBackend!=NetworkBackend.- To avoid uncontrolled usage of RAW pointers.
- AFAIK, to alias on plugins instance (the same is for highgui/parallel plugins - code borrowed from there)
There was a problem hiding this comment.
- We are in a class that is derived from enable_shared_from_this. The idea behind capturing shared_from_this()(PluginDNNBackend) inside a deleter of NetworkBackend was that the former wouldn't run its destructor before the latter.
- In its current state they are equivalent.
- The idea seems to be similar to p.1 above.
There was a problem hiding this comment.
I believe we need a separate proposal which covers similar cases from other plugins.
| // TODO: implemented accurate versions-based comparator | ||
| std::sort(candidates.begin(), candidates.end(), std::greater<std::string>()); | ||
| CV_LOG_DEBUG(NULL, " - " << path << ": " << candidates.size()); | ||
| copy(candidates.begin(), candidates.end(), back_inserter(results)); |
There was a problem hiding this comment.
Not needed, as ADL should work here well.
(also there are other places with the same code which works well)
There was a problem hiding this comment.
It's not immediately obvious why sort is used with std, but copy - without. Just consistency nitpick.
|
Rebased and removed test commit. |
|
👍 |
|
Great refactoring! I think I can have the same design as openvino (NetImplOpenVINO) for the CANN backend to have higher freedom to utilize CANN features. |
TODO: