Skip to content

Commit

Permalink
Auto (#5645)
Browse files Browse the repository at this point in the history
* Added LoadNetwork(filename) to AUTO

* Added more files

* So pointer can be used without loading

* Changed InferencePlugin, ICore to return internal interfaces

* Added SoPointers for InferRequest, ExecutableNetwork

* Fixed Windows

* Fixed KMB

* Fixes for KMB

* Removed dereference operator

* Play with include files

* Fixed compilation with older compilers

* Fixed comments

* Fixed win build

* Try  to fix Windows

* Try  to fix Windows 2

* Fixed windows

* Fixed windows

* Removed SOPointer as a base class

* Reverted back SOPointer split

* Code review

Co-authored-by: apankratovantonp <[email protected]>
  • Loading branch information
ilya-lavrenov and apankratovantonp authored May 19, 2021
1 parent 9568f81 commit 181ad06
Show file tree
Hide file tree
Showing 61 changed files with 576 additions and 870 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bool ngraph::pass::AddPreprocessing::run_on_function(std::shared_ptr<ngraph::Fun
NGRAPH_CHECK(meanImage->getTensorDesc().getPrecision() == InferenceEngine::Precision::FP32,
"Only InferenceEngine::Precision::FP32 precision is supported for PreProcessChannel::meanData");
} else {
NGRAPH_CHECK(pInfo[c]->meanData != nullptr, "pInfo[c]->meanData is nullptr");
NGRAPH_CHECK(meanImage->getTensorDesc() == pInfo[c]->meanData->getTensorDesc(),
"TensorDesc for PreProcessChannel::meanData must be equal");
}
Expand Down
31 changes: 14 additions & 17 deletions inference-engine/include/cpp/ie_executable_network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,37 @@
#include <string>
#include <vector>

#include "ie_parameter.hpp"
#include "ie_remote_context.hpp"
#include "cpp/ie_cnn_network.h"
#include "cpp/ie_infer_request.hpp"
#include "details/ie_so_loader.h"

namespace InferenceEngine {

namespace details {
class SharedObjectLoader;
}

class IExecutableNetworkInternal;
class IExecutableNetwork;

/**
* @brief This is an interface of an executable network
*/
class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) {
std::shared_ptr<IExecutableNetworkInternal> _impl;
std::shared_ptr<details::SharedObjectLoader> _so;

ExecutableNetwork(const std::shared_ptr<IExecutableNetworkInternal>& impl,
const std::shared_ptr<details::SharedObjectLoader>& so);

friend class InferencePlugin;
details::SharedObjectLoader _so;
std::shared_ptr<IExecutableNetworkInternal> _impl;

public:
/**
* @brief Default constructor
* @brief Constructs ExecutableNetwork from the initialized std::shared_ptr
* @param so Plugin to use. This is required to ensure that ExecutableNetwork can work properly even if plugin object is destroyed.
* @param impl Initialized shared pointer
*/
ExecutableNetwork() = default;
ExecutableNetwork(const details::SharedObjectLoader& so,
const std::shared_ptr<IExecutableNetworkInternal>& impl);
friend class Core;

public:
/**
* @brief Default destructor
* @brief A default constructor.
*/
~ExecutableNetwork();
ExecutableNetwork() = default;

/**
* @brief Gets the Executable network output Data node information.
Expand Down
25 changes: 10 additions & 15 deletions inference-engine/include/cpp/ie_infer_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@
#include <memory>
#include <string>

#include "ie_blob.h"
#include "cpp/ie_memory_state.hpp"
#include "ie_remote_context.hpp"
#include "ie_iinfer_request.hpp"
#include "details/ie_so_loader.h"
#include "ie_blob.h"

namespace InferenceEngine {

namespace details {
class SharedObjectLoader;
}
class IInferRequestInternal;

/**
Expand All @@ -33,12 +29,16 @@ class IInferRequestInternal;
* It can throw exceptions safely for the application, where it is properly handled.
*/
class INFERENCE_ENGINE_API_CLASS(InferRequest) {
std::shared_ptr<IInferRequestInternal> _impl;
std::shared_ptr<details::SharedObjectLoader> _so;

InferRequest(const std::shared_ptr<IInferRequestInternal>& impl,
const std::shared_ptr<details::SharedObjectLoader>& so);
details::SharedObjectLoader _so;
std::shared_ptr<IInferRequestInternal> _impl;

/**
* @brief Constructs InferRequest from the initialized std::shared_ptr
* @param so Plugin to use. This is required to ensure that InferRequest can work properly even if plugin object is destroyed.
* @param impl Initialized shared pointer
*/
InferRequest(const details::SharedObjectLoader& so,
const std::shared_ptr<IInferRequestInternal>& impl);
friend class ExecutableNetwork;

public:
Expand All @@ -63,11 +63,6 @@ class INFERENCE_ENGINE_API_CLASS(InferRequest) {
*/
InferRequest() = default;

/**
* @brief Destructor
*/
~InferRequest();

/**
* @brief Sets input/output data to infer
*
Expand Down
21 changes: 11 additions & 10 deletions inference-engine/include/cpp/ie_memory_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,35 @@

#include "ie_api.h"
#include "ie_blob.h"
#include "details/ie_so_loader.h"

namespace InferenceEngine {

namespace details {
class SharedObjectLoader;
}

class IVariableStateInternal;

/**
* @brief C++ exception based error reporting wrapper of API class IVariableState
*/
class INFERENCE_ENGINE_API_CLASS(VariableState) {
std::shared_ptr<IVariableStateInternal> _impl = nullptr;
std::shared_ptr<details::SharedObjectLoader> _so = nullptr;
details::SharedObjectLoader _so;
std::shared_ptr<IVariableStateInternal> _impl;

/**
* @brief Constructs VariableState from the initialized std::shared_ptr
* @param impl Initialized shared pointer
* @param so Optional: Plugin to use. This is required to ensure that VariableState can work properly even if plugin object is destroyed.
*/
VariableState(const std::shared_ptr<IVariableStateInternal>& impl,
const std::shared_ptr<details::SharedObjectLoader>& so);

VariableState(const details::SharedObjectLoader& so,
const std::shared_ptr<IVariableStateInternal>& impl);
friend class InferRequest;
friend class ExecutableNetwork;

public:
/**
* @brief Default constructor
*/
VariableState() = default;

/**
* @copybrief IVariableState::Reset
*
Expand All @@ -62,7 +63,7 @@ class INFERENCE_ENGINE_API_CLASS(VariableState) {
* @copybrief IVariableState::GetState
*
* Wraps IVariableState::GetState
* @return A blob representing a state
* @return A blob representing a state
*/
Blob::CPtr GetState() const;

Expand Down
6 changes: 3 additions & 3 deletions inference-engine/include/details/ie_so_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* @brief A header file for definition of abstraction over platform specific shared objects
*
*
* @file ie_so_loader.h
*/
#pragma once
Expand All @@ -25,9 +25,9 @@ class INFERENCE_ENGINE_API_CLASS(SharedObjectLoader) {

public:
/**
* @brief A shared pointer to SharedObjectLoader
* @brief Default constructor
*/
using Ptr = std::shared_ptr<SharedObjectLoader>;
SharedObjectLoader() = default;

#ifdef ENABLE_UNICODE_PATH_SUPPORT
/**
Expand Down
94 changes: 36 additions & 58 deletions inference-engine/include/details/ie_so_pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ using enableIfSupportedChar = typename std::enable_if<(std::is_same<C, char>::va
/**
* @brief This class instantiate object using shared library
* @tparam T An type of object SOPointer can hold
* @tparam Loader A loader used to load a library
*/
template <class T, class Loader = SharedObjectLoader>
template <class T>
class SOPointer {
template <class U, class W>
template <class U>
friend class SOPointer;
IE_SUPPRESS_DEPRECATED_START

IE_SUPPRESS_DEPRECATED_START
struct HasRelease {
template <typename C> static char test(decltype(&C::Release));
template <typename C> static long test(...);
constexpr static const bool value = sizeof(test<T>(nullptr)) == sizeof(char);
};
IE_SUPPRESS_DEPRECATED_END
IE_SUPPRESS_DEPRECATED_END

public:
/**
Expand All @@ -62,68 +62,48 @@ IE_SUPPRESS_DEPRECATED_END
*/
template <typename C,
typename = enableIfSupportedChar<C>>
explicit SOPointer(const std::basic_string<C> & name)
: _so_loader(new Loader(name.c_str())) {
Load(std::integral_constant<bool, HasRelease::value>{});
}

/**
* @brief The main constructor
* @param name Name of a shared library file
*/
explicit SOPointer(const char * name)
: _so_loader(new Loader(name)) {
Load(std::integral_constant<bool, HasRelease::value>{});
}
SOPointer(const std::basic_string<C> & name)
: _so(name.c_str()) {
Load(std::integral_constant<bool, HasRelease::value>{});
}

/**
* @brief Constructs an object with existing reference
* @param pointedObj Existing reference to wrap
* @brief Constructs an object with existing loader
* @param soLoader Existing pointer to a library loader
*/
explicit SOPointer(T* pointedObj): _so_loader(), _pointedObj(pointedObj) {
if (_pointedObj == nullptr) {
IE_THROW() << "Cannot create SOPointer<T, Loader> from nullptr";
}
}
SOPointer(const SharedObjectLoader& so, const std::shared_ptr<T>& ptr) : _so{so}, _ptr{ptr} {}

/**
* @brief Constructs an object with existing loader
* @param so_loader Existing pointer to a library loader
* @param so Existing pointer to a library loader
*/
explicit SOPointer(const std::shared_ptr<Loader>& so_loader)
: _so_loader(so_loader) {
Load(std::integral_constant<bool, HasRelease::value>{});
}
explicit SOPointer(const SharedObjectLoader& so)
: _so(so) {
Load(std::integral_constant<bool, HasRelease::value>{});
}

/**
* @brief The copy-like constructor, can create So Pointer that dereferenced into child type if T is derived of U
* @param that copied SOPointer object
*/
template <class U, class W>
SOPointer(const SOPointer<U, W>& that)
: _so_loader(std::dynamic_pointer_cast<Loader>(that._so_loader)),
_pointedObj(std::dynamic_pointer_cast<T>(that._pointedObj)) {
IE_ASSERT(_pointedObj != nullptr);
template <typename U>
SOPointer(const SOPointer<U>& that)
: _so(that._so),
_ptr(std::dynamic_pointer_cast<T>(that._ptr)) {
IE_ASSERT(_ptr != nullptr);
}

/**
* @brief Standard pointer operator
* @return underlined interface with disabled Release method
*/
T* operator->() const noexcept {
return _pointedObj.get();
}

/**
* @brief Standard dereference operator
* @return underlined interface with disabled Release method
*/
const T* operator*() const noexcept {
return this->operator->();
return _ptr.get();
}

explicit operator bool() const noexcept {
return (nullptr != _pointedObj);
return _ptr != nullptr;
}

friend bool operator==(std::nullptr_t, const SOPointer& ptr) noexcept {
Expand All @@ -139,14 +119,12 @@ IE_SUPPRESS_DEPRECATED_END
return static_cast<bool>(ptr);
}

SOPointer& operator=(const SOPointer& pointer) noexcept {
_pointedObj = pointer._pointedObj;
_so_loader = pointer._so_loader;
return *this;
operator const SharedObjectLoader&() const noexcept {
return _so;
}

operator const std::shared_ptr<Loader>&() const noexcept {
return _so_loader;
operator std::shared_ptr<T>& () noexcept {
return _ptr;
}

protected:
Expand All @@ -173,10 +151,10 @@ IE_SUPPRESS_DEPRECATED_END
try {
void* create = nullptr;
try {
create = _so_loader->get_symbol((SOCreatorTrait<T>::name + std::string("Shared")).c_str());
create = _so.get_symbol((SOCreatorTrait<T>::name + std::string("Shared")).c_str());
} catch (const NotFound&) {}
if (create == nullptr) {
create = _so_loader->get_symbol(SOCreatorTrait<T>::name);
create = _so.get_symbol(SOCreatorTrait<T>::name);
using CreateF = StatusCode(T*&, ResponseDesc*);
T* object = nullptr;
ResponseDesc desc;
Expand All @@ -186,11 +164,11 @@ IE_SUPPRESS_DEPRECATED_END
InferenceEngine::details::ThrowNow<ExceptionType>{} <<= std::stringstream{} << IE_LOCATION << desc.msg)
}
IE_SUPPRESS_DEPRECATED_START
_pointedObj = std::shared_ptr<T>(object, [] (T* ptr){ptr->Release();});
_ptr = std::shared_ptr<T>(object, [] (T* ptr){ptr->Release();});
IE_SUPPRESS_DEPRECATED_END
} else {
using CreateF = void(std::shared_ptr<T>&);
reinterpret_cast<CreateF*>(create)(_pointedObj);
reinterpret_cast<CreateF*>(create)(_ptr);
}
} CATCH_IE_EXCEPTIONS catch (const std::exception& ex) {
IE_THROW() << ex.what();
Expand All @@ -205,7 +183,7 @@ IE_SUPPRESS_DEPRECATED_END
void Load(std::false_type) {
try {
using CreateF = void(std::shared_ptr<T>&);
reinterpret_cast<CreateF*>(_so_loader->get_symbol(SOCreatorTrait<T>::name))(_pointedObj);
reinterpret_cast<CreateF*>(_so.get_symbol(SOCreatorTrait<T>::name))(_ptr);
} CATCH_IE_EXCEPTIONS catch (const std::exception& ex) {
IE_THROW() << ex.what();
} catch(...) {
Expand All @@ -216,14 +194,14 @@ IE_SUPPRESS_DEPRECATED_END
#undef CATCH_IE_EXCEPTIONS

/**
* @brief Gets a smart pointer to the DLL
* @brief The DLL
*/
std::shared_ptr<Loader> _so_loader;
SharedObjectLoader _so;

/**
* @brief Gets a smart pointer to the custom object
*/
std::shared_ptr<T> _pointedObj;
std::shared_ptr<T> _ptr;
};
} // namespace details
} // namespace InferenceEngine
Loading

0 comments on commit 181ad06

Please sign in to comment.