Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IE][VPU]: Configuration options in VPU plugins refactoring #3211

Merged
merged 16 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion inference-engine/include/ie_parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class INFERENCE_ENGINE_API_CLASS(Parameter) {
* @param parameter object
*/
template <class T,
typename = typename std::enable_if<!std::is_same<typename std::decay<T>::type, Parameter>::value>::type>
typename = typename std::enable_if<!std::is_same<typename std::decay<T>::type, Parameter>::value &&
!std::is_abstract<typename std::decay<T>::type>::value>::type>
Parameter(T&& parameter) { // NOLINT
static_assert(!std::is_same<typename std::decay<T>::type, Parameter>::value, "To prevent recursion");
ptr = new RealData<typename std::decay<T>::type>(std::forward<T>(parameter));
Expand Down Expand Up @@ -254,6 +255,21 @@ class INFERENCE_ENGINE_API_CLASS(Parameter) {
return !(*this == rhs);
}

/**
* @brief Prints underlying object to the given output stream.
* Uses operator<< if it is defined, leaves stream unchanged otherwise.
* In case of empty parameter or nullptr stream immediately returns.
*
* @param object Object to be printed to the given output stream.
* @param stream Output stream object will be printed to.
*/
friend void PrintTo(const Parameter& object, std::ostream* stream) {
if (object.empty() || !stream) {
return;
}
object.ptr->print(*stream);
}

private:
template <class T, class EqualTo>
struct CheckOperatorEqual {
Expand All @@ -273,6 +289,24 @@ class INFERENCE_ENGINE_API_CLASS(Parameter) {
template <class T, class EqualTo = T>
struct HasOperatorEqual : CheckOperatorEqual<T, EqualTo>::type {};

template <class T, class U>
struct CheckOutputStreamOperator {
template <class V, class W>
static auto test(W*) -> decltype(std::declval<V&>() << std::declval<W>(), std::true_type()) {
return {};
}

template <typename, typename>
static auto test(...) -> std::false_type {
return {};
}

using type = typename std::is_same<std::true_type, decltype(test<T, U>(nullptr))>::type;
};

template <class T>
struct HasOutputStreamOperator : CheckOutputStreamOperator<std::ostream, T>::type {};

struct Any {
#ifdef __ANDROID__
virtual ~Any();
Expand All @@ -282,6 +316,7 @@ class INFERENCE_ENGINE_API_CLASS(Parameter) {
virtual bool is(const std::type_info&) const = 0;
virtual Any* copy() const = 0;
virtual bool operator==(const Any& rhs) const = 0;
virtual void print(std::ostream&) const = 0;
};

template <class T>
Expand Down Expand Up @@ -318,6 +353,20 @@ class INFERENCE_ENGINE_API_CLASS(Parameter) {
bool operator==(const Any& rhs) const override {
return rhs.is(typeid(T)) && equal<T>(*this, rhs);
}

template <class U>
typename std::enable_if<!HasOutputStreamOperator<U>::value, void>::type
print(std::ostream& stream, const U& object) const {}

template <class U>
typename std::enable_if<HasOutputStreamOperator<U>::value, void>::type
print(std::ostream& stream, const U& object) const {
stream << object;
}

void print(std::ostream& stream) const override {
print<T>(stream, get());
}
};

template <typename T>
Expand Down
7 changes: 3 additions & 4 deletions inference-engine/src/plugin_api/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@

#include "ie_algorithm.hpp"

namespace InferenceEngine {
namespace details {

Comment on lines +28 to +30
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ilya-lavrenov @apankratovantonp

Please take a look at changes at this file. For explanation see commit message. Thanks

/**
* @brief Serializes a `std::vector` to a `std::ostream`
* @ingroup ie_dev_api_error_debug
* @param out An output stream
* @param vec A vector to serialize
* @return A reference to a `std::stream`
*/
namespace std {
template <typename T>
inline std::ostream& operator<<(std::ostream& out, const std::vector<T>& vec) {
if (vec.empty()) return std::operator<<(out, "[]");
Expand All @@ -42,10 +44,7 @@ inline std::ostream& operator<<(std::ostream& out, const std::vector<T>& vec) {
}
return out << "]";
}
} // namespace std

namespace InferenceEngine {
namespace details {
/**
* @brief trim from start (in place)
* @ingroup ie_dev_api_error_debug
Expand Down
99 changes: 99 additions & 0 deletions inference-engine/src/vpu/common/include/vpu/configuration.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <string>
#include <vector>
#include <map>

#include "caseless.hpp"

#include "vpu/utils/optional.hpp"

namespace vpu {

struct CompilationConfig {
int numSHAVEs = -1;
int numCMXSlices = -1;
int numExecutors = -1;
int tilingCMXLimitKB = -1;

bool hwOptimization = true;
bool hwExtraSplit = false;

std::string irWithVpuScalesDir;

std::string customLayers;

bool detectBatch = true;

Optional<bool> injectSwOps;
Optional<bool> packDataInCmx;
bool mergeHwPoolToConv = true;
bool hwDilation = false;
bool forceDeprecatedCnnConversion = false;
bool enableEarlyEltwiseReLUFusion = true;

std::map<std::string, std::vector<int>> ioStrides;

//
// Debug options
//

InferenceEngine::details::caseless_set<std::string> hwWhiteList;
InferenceEngine::details::caseless_set<std::string> hwBlackList;

bool hwDisabled(const std::string& layerName) const {
if (!hwWhiteList.empty()) {
return hwWhiteList.count(layerName) == 0;
}

if (!hwBlackList.empty()) {
return hwBlackList.count(layerName) != 0;
}

return false;
}

InferenceEngine::details::caseless_set<std::string> noneLayers;

bool skipAllLayers() const {
if (noneLayers.size() == 1) {
const auto& val = *noneLayers.begin();
return val == "*";
}
return false;
}

bool skipLayerType(const std::string& layerType) const {
return noneLayers.count(layerType) != 0;
}
bool ignoreUnknownLayers = false;

std::string dumpInternalGraphFileName;
std::string dumpInternalGraphDirectory;
bool dumpAllPasses;

bool disableReorder = false; // TODO: rename to enableReorder and switch logic.
bool disableConvertStages = false;
bool enablePermuteMerging = true;
bool enableReplWithSCRelu = false;
bool enableReplaceWithReduceMean = true;
bool enableTensorIteratorUnrolling = false;
bool forcePureTensorIterator = false;
bool enableMemoryTypesAnnotation = false;
bool enableWeightsAnalysis = true;
bool checkPreprocessingInsideModel = true;
bool enableCustomReshapeParam = false;

//
// Deprecated options
//

float inputScale = 1.0f;
float inputBias = 0.0f;
};

} // namespace vpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <string>

#include "ie_parameter.hpp"

template<class OptionConcept>
struct AsParsedParameterEnabler {
static InferenceEngine::Parameter asParameter(const std::string& value) { return {OptionConcept::parse(value)}; }
};

struct AsParameterEnabler {
static InferenceEngine::Parameter asParameter(const std::string& value);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <string>

#include "vpu/configuration/as_parameter_enabler.hpp"

namespace vpu {

namespace details {

enum class Access;
enum class Category;

} // namespace details

class PluginConfiguration;

struct CopyOptimizationOption : public AsParsedParameterEnabler<CopyOptimizationOption> {
using value_type = bool;

static std::string key();
static void validate(const std::string&);
static void validate(const PluginConfiguration&);
static std::string defaultValue();
static value_type parse(const std::string&);
static details::Access access();
static details::Category category();
};

} // namespace vpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <string>

#include "vpu/configuration/as_parameter_enabler.hpp"

namespace vpu {

enum class LogLevel;

namespace details {

enum class Access;
enum class Category;

} // namespace details

class PluginConfiguration;

struct LogLevelOption : public AsParameterEnabler {
using value_type = LogLevel;

static std::string key();
static void validate(const std::string&);
static void validate(const PluginConfiguration&);
static std::string defaultValue();
static value_type parse(const std::string&);
static details::Access access();
static details::Category category();
};

} // namespace vpu
Loading