Skip to content

Add a mutex for shared Inference Engine plugins - #13738

Merged
opencv-pushbot merged 1 commit into
opencv:3.4from
dkurt:dnn_ie_lock_shared_plugins
Feb 6, 2019
Merged

opencv-pushbot merged 1 commit into
opencv:3.4from
dkurt:dnn_ie_lock_shared_plugins

Conversation

@dkurt

@dkurt dkurt commented Jan 31, 2019 •

Copy link
Copy Markdown
Member

resolves #13715
resolves #13569

force_builders=Custom

docker_image:Custom=ubuntu-openvino-2018r5:16.04
test_opencl:Custom=ON
buildworker:Custom=linux-2
#test_modules=dnn

Comment thread modules/dnn/src/op_inf_engine.cpp Outdated
#endif // IE < R5

static Mutex sharedPluginsMutex;
static std::map<InferenceEngine::TargetDevice, InferenceEngine::InferenceEnginePluginPtr> sharedPlugins;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to wrap global "static" variables into static functions (to ensure initialization of them at least).

Example:
https://github.com/opencv/opencv/blob/3.4.5/modules/dnn/src/dnn.cpp#L94-L98

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alalek, Is that Ok to use a mutex from getInitializationMutex()?

Mutex& getInitializationMutex()
{
if (__initialization_mutex == NULL)
__initialization_mutex = new Mutex();
return *__initialization_mutex;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can reuse it (declared in dnn's precomp.hpp).

@dkurt
dkurt force-pushed the dnn_ie_lock_shared_plugins branch from 21cc489 to 38346d3 Compare January 31, 2019 14:42
Comment thread modules/dnn/test/test_layers.cpp Outdated

#ifdef HAVE_INF_ENGINE
#include <thread>
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep "test_precomp.hpp" as the first "include" statement.

@dkurt
dkurt force-pushed the dnn_ie_lock_shared_plugins branch from 38346d3 to bc4e471 Compare February 5, 2019 16:27

try
{
AutoLock lock(getInitializationMutex());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps const if not modified.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shahzadlone, thanks for review! Could you please clarify it a bit?

@shahzadlone shahzadlone Feb 6, 2019 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if lock isn't being modified could it perhaps be made const AutoLock?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't fix (or change) anything in current code.

@shahzadlone Please report about real issues only.

Avoid reporting about "const" of local variables. They are usually not required and can be safely omitted (compilers are smart enough).
It make sense to report about "const" in parameters or about "const methods".

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! Thank you 👍

@opencv-pushbot
opencv-pushbot merged commit bc4e471 into opencv:3.4 Feb 6, 2019
@alalek alalek mentioned this pull request Feb 8, 2019
@dkurt
dkurt deleted the dnn_ie_lock_shared_plugins branch May 6, 2019 05:48
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants