[GNA] Add support for future devices with relaxed capabilities (#12000)
This commit is contained in:
parent
a185299ba4
commit
9d0e623af6
@ -13,6 +13,7 @@
|
||||
#include "gna/gna_config.hpp"
|
||||
|
||||
#include "gna_plugin_log.hpp"
|
||||
#include "common/gna_target.hpp"
|
||||
#include "memory/gna_memory.hpp"
|
||||
#include <gna2-model-api.h>
|
||||
|
||||
@ -296,7 +297,7 @@ public:
|
||||
|
||||
void WriteDnnText(const char *filename, intel_dnn_number_type_t logging_precision);
|
||||
|
||||
void InitGNAStruct(Gna2Model *gnaModel, const std::string& gnaCompileTarget = InferenceEngine::GNAConfigParams::GNA_TARGET_2_0);
|
||||
void InitGNAStruct(Gna2Model *gnaModel, const std::string& gnaCompileTarget = common::kGnaTarget2_0);
|
||||
|
||||
void DestroyGNAStruct(Gna2Model *gnaModel);
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <layers/gna_layer_info.hpp>
|
||||
#include "gna_graph_tools.hpp"
|
||||
#include "gna_lib_ver_selector.hpp"
|
||||
#include "common/gna_target.hpp"
|
||||
|
||||
namespace GNAPluginNS {
|
||||
namespace GNALimitations {
|
||||
@ -118,55 +119,113 @@ std::string RectLimitByChannelsAndPrecision::GetErrorOrEmpty(const uint32_t h, c
|
||||
return GetByPrecision(precision).GetErrorOrEmpty(h, w, channels, what);
|
||||
}
|
||||
|
||||
const RangeLimit2D Validator_30::kInputHWLimit{{16, 384, "input height"}, {16, 240, "input width"}};
|
||||
const RangeMultipleLimit Validator_30::kInputChannelsNumberLimit{{8, 384, "number of input channels"}, 8};
|
||||
|
||||
const RangeMultipleLimit Validator_30::kKernelNumberLimit{{8, 1024, "number of kernels"}, 8};
|
||||
const RectLimitByChannelsAndPrecision Validator_30::kKernelLimit{
|
||||
{{{96, {7, 7}}, {136, {7, 5}}, {168, {7, 4}}, {240, {7, 3}}, {384, {7, 2}}}},
|
||||
{{{48, {7, 7}}, {64, {7, 5}}, {80, {7, 4}}, {120, {7, 3}}, {384, {7, 1}}}},
|
||||
};
|
||||
|
||||
const RangeLimit2D Validator_30::kDilationLimit{{convDilationHeight, convDilationHeight, "dilation height"},
|
||||
{convDilationWidth, convDilationWidth, "dilation width"}};
|
||||
|
||||
bool Validator_30::ValidateCnn2D(const std::string &name, const uint32_t inHeight, const uint32_t inWidth,
|
||||
const uint32_t inChannels, const uint32_t kernelH, const uint32_t kernelW, const uint32_t kernelN,
|
||||
const uint32_t strideH, const uint32_t strideW, const uint32_t dilationH, const uint32_t dilationW,
|
||||
OvGnaType inPrecision, bool exception) const {
|
||||
const OvGnaType inPrecision, const bool throwOnError) const {
|
||||
const auto& kStrideLimit = kKernelLimit;
|
||||
auto error = kInputHWLimit.GetErrorOrEmpty(inHeight, inWidth);
|
||||
|
||||
const std::string prefix = "Layer Convolution2D: " + name + ":";
|
||||
auto error = inputHWLimit.GetErrorOrEmpty(inHeight, inWidth);
|
||||
error += kKernelNumberLimit.GetErrorOrEmpty(kernelN);
|
||||
error += kInputChannelsNumberLimit.GetErrorOrEmpty(inChannels);
|
||||
error += kKernelLimit.GetErrorOrEmpty(kernelH, kernelW, inPrecision, inChannels, "kernel");
|
||||
error += kStrideLimit.GetErrorOrEmpty(strideH, strideW, inPrecision, inChannels, "convolution stride");
|
||||
|
||||
error += kernelNumberLimit.GetErrorOrEmpty(kernelN);
|
||||
error += inputChannelsNumberLimit.GetErrorOrEmpty(inChannels);
|
||||
error += kernelLimit.GetErrorOrEmpty(kernelH, kernelW, inPrecision, inChannels, "kernel");
|
||||
error += strideLimit.GetErrorOrEmpty(strideH, strideW, inPrecision, inChannels, "convolution stride");
|
||||
const RangeLimit kKernelStrideHLimit{1, kernelH, "kernel stride height (must be up to kernel height)"};
|
||||
const RangeLimit kKernelStrideWLimit{1, kernelW, "kernel stride width (must be up to kernel width)"};
|
||||
|
||||
const RangeLimit kernelStrideHLimit{1, kernelH, "kernel stride height (must be up to kernel height)"};
|
||||
const RangeLimit kernelStrideWLimit{1, kernelW, "kernel stride width (must be up to kernel width)"};
|
||||
error += kKernelStrideHLimit.GetErrorOrEmpty(strideH);
|
||||
error += kKernelStrideWLimit.GetErrorOrEmpty(strideW);
|
||||
|
||||
error += kernelStrideHLimit.GetErrorOrEmpty(strideH);
|
||||
error += kernelStrideWLimit.GetErrorOrEmpty(strideW);
|
||||
error += kDilationLimit.GetErrorOrEmpty(dilationH, dilationW);
|
||||
|
||||
error += dilationLimit.GetErrorOrEmpty(dilationH, dilationW);
|
||||
|
||||
if (exception)
|
||||
ThrowIfNotEmpty(prefix, error);
|
||||
|
||||
return error.empty() ? true : false;
|
||||
return ValidationSuccesful(throwOnError, error, name, "Convolution2D");
|
||||
}
|
||||
|
||||
const VectorOrSquareLimit Validator_30::kPoolingWindowLimit{3, 1, 1};
|
||||
|
||||
bool Validator_30::ValidatePooling2D(const std::string& name,
|
||||
const uint32_t windowH, const uint32_t windowW,
|
||||
const uint32_t strideH, const uint32_t strideW,
|
||||
bool exception) const {
|
||||
const std::string prefix = "Layer Pooling2D: " + name + ":";
|
||||
|
||||
auto error = poolingWindowLimit.GetErrorOrEmpty(windowH, windowW, "pooling window");
|
||||
const bool throwOnError) const {
|
||||
auto error = kPoolingWindowLimit.GetErrorOrEmpty(windowH, windowW, "pooling window");
|
||||
const RangeLimit poolingStrideHLimit{ 1, windowH, "pooling stride height (must be up to pooling window height)" };
|
||||
const RangeLimit poolingStrideWLimit{ 1, windowW, "pooling stride width (must be up to pooling window width)" };
|
||||
|
||||
error += poolingStrideHLimit.GetErrorOrEmpty(strideH);
|
||||
error += poolingStrideWLimit.GetErrorOrEmpty(strideW);
|
||||
|
||||
if (exception)
|
||||
ThrowIfNotEmpty(prefix, error);
|
||||
return ValidationSuccesful(throwOnError, error, name, "Pooling2D");
|
||||
}
|
||||
|
||||
return error.empty() ? true : false;
|
||||
bool Validator_30::IsPaddingSupported() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
const RangeLimit2D Validator_35::kInputHWLimit{{1, 65535, "input height"}, {1, 65535, "input width"}};
|
||||
const RangeLimit Validator_35::kInputChannelsNumberLimit1B{1, 2048, "number of input channels"};
|
||||
const RangeLimit Validator_35::kInputChannelsNumberLimit2B{1, 1024, "number of input channels"};
|
||||
|
||||
const RangeLimit Validator_35::kKernelNumberLimit{1, 8192, "number of kernels"};
|
||||
const RangeLimit2D Validator_35::kKerneHWlLimit{{1, 255, "kernel height"}, {1, 256, "kernel width"}};
|
||||
const RangeLimit2D Validator_35::kStrideHWLimit{{1, 255, "convolution stride height"},
|
||||
{1, 256, "convolution stride width"}};
|
||||
const RangeLimit2D Validator_35::kDilationLimit{{convDilationHeight, convDilationHeight, "dilation height"},
|
||||
{convDilationWidth, convDilationWidth, "dilation width"}};
|
||||
|
||||
bool Validator_35::ValidateCnn2D(const std::string& name, const uint32_t inHeight, const uint32_t inWidth,
|
||||
const uint32_t inChannels, const uint32_t kernelH, const uint32_t kernelW, const uint32_t kernelN,
|
||||
const uint32_t strideH, const uint32_t strideW, const uint32_t dilationH, const uint32_t dilationW,
|
||||
const OvGnaType inPrecision, const bool throwOnError) const {
|
||||
auto error = kInputHWLimit.GetErrorOrEmpty(inHeight, inWidth);
|
||||
|
||||
error += kKernelNumberLimit.GetErrorOrEmpty(kernelN);
|
||||
auto& inputChannelsNumberLimit = inPrecision == OvGnaTypeInt8 ? kInputChannelsNumberLimit1B : kInputChannelsNumberLimit2B;
|
||||
error += inputChannelsNumberLimit.GetErrorOrEmpty(inChannels);
|
||||
error += kKerneHWlLimit.GetErrorOrEmpty(kernelH, kernelW);
|
||||
error += kStrideHWLimit.GetErrorOrEmpty(strideH, strideW);
|
||||
|
||||
error += kDilationLimit.GetErrorOrEmpty(dilationH, dilationW);
|
||||
|
||||
return ValidationSuccesful(throwOnError, error, name, "Convolution2D");
|
||||
}
|
||||
|
||||
const RangeLimit2D Validator_35::kPoolingWindowHWLimit{{1, 255, "pooling window height"},
|
||||
{1, 255, "pooling window width"}};
|
||||
const RangeLimit2D Validator_35::kPoolingStrideHWLimit{{1, 255, "pooling stride height"},
|
||||
{1, 255, "pooling stride width"}};
|
||||
|
||||
bool Validator_35::ValidatePooling2D(const std::string& name,
|
||||
const uint32_t windowH, const uint32_t windowW,
|
||||
const uint32_t strideH, const uint32_t strideW,
|
||||
const bool throwOnError) const {
|
||||
auto error = kPoolingWindowHWLimit.GetErrorOrEmpty(windowH, windowW);
|
||||
error += kPoolingStrideHWLimit.GetErrorOrEmpty(strideH, strideW);
|
||||
|
||||
return ValidationSuccesful(throwOnError, error, name, "Pooling2D");
|
||||
}
|
||||
|
||||
bool Validator_35::IsPaddingSupported() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractValidator> AbstractValidator::Create(const std::string& target) {
|
||||
if (target == InferenceEngine::GNAConfigParams::GNA_TARGET_3_0) {
|
||||
if (target == common::kGnaTarget3_0) {
|
||||
return tools::make_unique<Validator_30>();
|
||||
} else if (target == common::kGnaTarget3_5) {
|
||||
return tools::make_unique<Validator_35>();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -177,6 +236,18 @@ void AbstractValidator::ThrowIfNotEmpty(const std::string& prefix, const std::st
|
||||
}
|
||||
}
|
||||
|
||||
bool AbstractValidator::ValidationSuccesful(const bool throwOnError,
|
||||
const std::string& error,
|
||||
const std::string& operationName,
|
||||
const std::string& type) {
|
||||
if (throwOnError) {
|
||||
const std::string prefix = "Layer " + type + ": " + operationName + ":";
|
||||
ThrowIfNotEmpty(prefix, error);
|
||||
}
|
||||
|
||||
return error.empty();
|
||||
}
|
||||
|
||||
} // namespace Cnn2D
|
||||
|
||||
IE_SUPPRESS_DEPRECATED_START
|
||||
|
@ -109,6 +109,11 @@ struct RectLimitByChannelsAndPrecision {
|
||||
class AbstractValidator {
|
||||
protected:
|
||||
static void ThrowIfNotEmpty(const std::string& prefix, const std::string& error);
|
||||
static bool ValidationSuccesful(const bool throwOnError,
|
||||
const std::string& error,
|
||||
const std::string& operation,
|
||||
const std::string& type);
|
||||
|
||||
public:
|
||||
virtual ~AbstractValidator() = default;
|
||||
virtual bool ValidateCnn2D(const std::string& name, const uint32_t inHeight, const uint32_t inWidth,
|
||||
@ -120,30 +125,21 @@ public:
|
||||
const uint32_t windowH, const uint32_t windowW,
|
||||
const uint32_t strideH, const uint32_t strideW,
|
||||
bool exception = true) const = 0;
|
||||
|
||||
virtual bool IsPaddingSupported() const = 0;
|
||||
|
||||
static std::unique_ptr<AbstractValidator> Create(const std::string&);
|
||||
};
|
||||
|
||||
class Validator_30 : public AbstractValidator {
|
||||
RangeLimit2D inputHWLimit{ { 16, 384, "input height"} , { 16, 240, "input width"} };
|
||||
RangeMultipleLimit inputChannelsNumberLimit{ {8, 384, "number of input channels"}, 8 };
|
||||
static const RangeLimit2D kInputHWLimit;
|
||||
static const RangeMultipleLimit kInputChannelsNumberLimit;
|
||||
|
||||
RangeMultipleLimit kernelNumberLimit{ {8, 1024, "number of kernels"}, 8 };
|
||||
RectLimitByChannelsAndPrecision kernelLimit {
|
||||
{ { {96, {7, 7}},
|
||||
{136, {7, 5}},
|
||||
{168, {7, 4}},
|
||||
{240, {7, 3}},
|
||||
{384, {7, 2}} } },
|
||||
{ { {48, {7, 7}},
|
||||
{64, {7, 5}},
|
||||
{80, {7, 4}},
|
||||
{120, {7, 3}},
|
||||
{384, {7, 1}} } },
|
||||
};
|
||||
RectLimitByChannelsAndPrecision& strideLimit = kernelLimit;
|
||||
RangeLimit2D dilationLimit{ {convDilationHeight, convDilationHeight, "dilation height" },
|
||||
{ convDilationWidth, convDilationWidth, "dilation width" } };
|
||||
const VectorOrSquareLimit poolingWindowLimit{ 3, 1, 1 };
|
||||
static const RangeMultipleLimit kKernelNumberLimit;
|
||||
static const RectLimitByChannelsAndPrecision kKernelLimit;
|
||||
static const RangeLimit2D kDilationLimit;
|
||||
|
||||
static const VectorOrSquareLimit kPoolingWindowLimit;
|
||||
|
||||
public:
|
||||
Validator_30() = default;
|
||||
@ -157,6 +153,37 @@ public:
|
||||
const uint32_t windowH, const uint32_t windowW,
|
||||
const uint32_t strideH, const uint32_t strideW,
|
||||
bool exception = true) const override;
|
||||
|
||||
bool IsPaddingSupported() const override;
|
||||
};
|
||||
|
||||
class Validator_35 : public AbstractValidator {
|
||||
static const RangeLimit2D kInputHWLimit;
|
||||
static const RangeLimit kInputChannelsNumberLimit1B;
|
||||
static const RangeLimit kInputChannelsNumberLimit2B;
|
||||
|
||||
static const RangeLimit kKernelNumberLimit;
|
||||
static const RangeLimit2D kKerneHWlLimit;
|
||||
static const RangeLimit2D kStrideHWLimit;
|
||||
static const RangeLimit2D kDilationLimit;
|
||||
|
||||
static const RangeLimit2D kPoolingWindowHWLimit;
|
||||
static const RangeLimit2D kPoolingStrideHWLimit;
|
||||
|
||||
public:
|
||||
Validator_35() = default;
|
||||
|
||||
bool ValidateCnn2D(const std::string& name, const uint32_t inHeight, const uint32_t inWidth,
|
||||
const uint32_t inChannels, const uint32_t kH, const uint32_t kW, const uint32_t kN,
|
||||
const uint32_t strideH, const uint32_t strideW, const uint32_t dilationH, const uint32_t dilationW,
|
||||
OvGnaType inPrecision, bool exception = true) const override;
|
||||
|
||||
bool ValidatePooling2D(const std::string& name,
|
||||
const uint32_t windowH, const uint32_t windowW,
|
||||
const uint32_t strideH, const uint32_t strideW,
|
||||
bool exception = true) const override;
|
||||
|
||||
bool IsPaddingSupported() const override;
|
||||
};
|
||||
} // namespace Cnn2D
|
||||
|
||||
|
5
src/plugins/intel_gna/common/gna_target.cpp
Normal file
5
src/plugins/intel_gna/common/gna_target.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "gna_target.hpp"
|
15
src/plugins/intel_gna/common/gna_target.hpp
Normal file
15
src/plugins/intel_gna/common/gna_target.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace GNAPluginNS {
|
||||
namespace common {
|
||||
static constexpr const char* kGnaTargetUnspecified = "";
|
||||
static constexpr const char* kGnaTarget2_0 = "GNA_TARGET_2_0";
|
||||
static constexpr const char* kGnaTarget3_0 = "GNA_TARGET_3_0";
|
||||
static constexpr const char* kGnaTarget3_1 = "GNA_TARGET_3_1";
|
||||
static constexpr const char* kGnaTarget3_5 = "GNA_TARGET_3_5";
|
||||
} // namespace common
|
||||
} // namespace GNAPluginNS
|
@ -8,11 +8,14 @@
|
||||
#include "gna2-model-export-api.h"
|
||||
#include "gna2-model-suecreek-header.h"
|
||||
#include "gna2-device-api.h"
|
||||
#include "gna/gna_config.hpp"
|
||||
#include "common/gna_target.hpp"
|
||||
|
||||
#include "gna2-tlv-writer.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <numeric>
|
||||
|
||||
void * ExportSueLegacyUsingGnaApi2(
|
||||
uint32_t modelId,
|
||||
@ -55,6 +58,7 @@ void * ExportSueLegacyUsingGnaApi2(
|
||||
|
||||
#define Gna2TlvTypeOVInputScaleFactor GNA2_TLV_IMPL_CHAR_TO_TYPE("OVIS")
|
||||
#define Gna2TlvTypeOVOutputScaleFactor GNA2_TLV_IMPL_CHAR_TO_TYPE("OVOS")
|
||||
#define Gna2TlvTypeOVString GNA2_TLV_IMPL_CHAR_TO_TYPE("OVSS")
|
||||
#define Gna2ExportTlv(...) 1
|
||||
|
||||
static_assert(std::numeric_limits<float>::is_iec559, "Float is not IEC 559 compatible");
|
||||
@ -67,17 +71,94 @@ TlvFloatRecord GetFloatInTLV(Gna2TlvType type, float value) {
|
||||
reinterpret_cast<Gna2TlvRecord*>(r.data())->length = sizeof(float);
|
||||
*reinterpret_cast<float*>(r.data() + sizeof(Gna2TlvRecord)) = value;
|
||||
return r;
|
||||
} // namespace
|
||||
|
||||
std::vector<char> GetStringAsTlv(Gna2TlvType type, const std::string& s) {
|
||||
std::vector<char> record(sizeof(Gna2TlvRecord));
|
||||
reinterpret_cast<Gna2TlvRecord*>(record.data())->type = type;
|
||||
|
||||
std::vector<char> vs(s.begin(), s.end());
|
||||
vs.resize(vs.size() + (4 - vs.size() % 4) % 4, 0);
|
||||
reinterpret_cast<Gna2TlvRecord*>(record.data())->length = vs.size();
|
||||
record.insert(record.end(), vs.begin(), vs.end());
|
||||
return record;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Gna2DeviceVersion getEmbeddedTargetFromCompileTarget(const std::string compileTarget) {
|
||||
static const std::map<std::string, Gna2DeviceVersion> targetMap = {
|
||||
{GNAPluginNS::common::kGnaTarget3_1, Gna2DeviceVersionEmbedded3_1},
|
||||
{GNAPluginNS::common::kGnaTarget3_5, Gna2DeviceVersionEmbedded3_5},
|
||||
};
|
||||
auto found = targetMap.find(compileTarget);
|
||||
if (found == targetMap.end()) {
|
||||
return Gna2DeviceVersionEmbedded1_0;
|
||||
}
|
||||
return found->second;
|
||||
}
|
||||
|
||||
namespace {
|
||||
Gna2DeviceVersion getTlvTargetFromCompileTarget(const std::string compileTarget) {
|
||||
const auto target = getEmbeddedTargetFromCompileTarget(compileTarget);
|
||||
static const std::set<Gna2DeviceVersion> supportedTargets = {
|
||||
Gna2DeviceVersionEmbedded3_1,
|
||||
Gna2DeviceVersionEmbedded3_5,
|
||||
};
|
||||
const auto found = supportedTargets.count(target) > 0;
|
||||
if (!found) {
|
||||
THROW_GNA_EXCEPTION << "Unsupported compile target for TLV export: " << compileTarget << "\n";
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
std::string WriteAllEndpoints(std::ostream& outStream,
|
||||
const std::vector<GnaEndpoint>& allEndpoints,
|
||||
const Gna2TlvType sfTlvType,
|
||||
const GnaAllocation* allocation) {
|
||||
const std::string endPointType = sfTlvType == Gna2TlvTypeOVInputScaleFactor ? "Input" : "Output";
|
||||
|
||||
if (allEndpoints.size() >= 1) {
|
||||
const auto scaleFactorTlv = GetFloatInTLV(sfTlvType, allEndpoints[0].scaleFactor);
|
||||
outStream.write(scaleFactorTlv.data(), scaleFactorTlv.size());
|
||||
}
|
||||
if (allEndpoints.size() != 1) {
|
||||
gnawarn() << "Number of endpoints: " << allEndpoints.size() << " for " << endPointType << "\n";
|
||||
}
|
||||
|
||||
std::stringstream stream;
|
||||
stream << "Endpoints for " << endPointType << ":\n";
|
||||
for (const auto& endpoint : allEndpoints) {
|
||||
stream << "name=[" << endpoint.name << "]\n";
|
||||
stream << "scaleFactor=[" << endpoint.scaleFactor << "]\n";
|
||||
stream << "byteSize=[" << endpoint.byteSize << "]\n";
|
||||
stream << "numberOfBytesPerElement=[" << endpoint.numberOfBytesPerElement << "]\n";
|
||||
if (allocation == nullptr) {
|
||||
stream << "allocation=[nullptr]\n";
|
||||
}
|
||||
if (endpoint.gnaPointer == nullptr) {
|
||||
stream << "gnaPointer=[nullptr]\n";
|
||||
}
|
||||
if (allocation != nullptr && endpoint.gnaPointer != nullptr) {
|
||||
const auto gnaOffset = allocation->getOffset(endpoint.gnaPointer);
|
||||
if (!gnaOffset.first) {
|
||||
stream << "offset=[invalid]\n";
|
||||
}
|
||||
stream << "offset=[" << gnaOffset.second << "]\n";
|
||||
}
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void ExportTlvModel(uint32_t modelId,
|
||||
uint32_t deviceIndex,
|
||||
std::ostream& outStream,
|
||||
Gna2DeviceVersion deviceVersionToExport,
|
||||
uint32_t input_size,
|
||||
uint32_t output_size,
|
||||
float inputSF,
|
||||
float outputSF) {
|
||||
std::string compileTarget,
|
||||
const std::vector<GnaEndpoint>& allInputs,
|
||||
const std::vector<GnaEndpoint>& allOutputs,
|
||||
const GnaAllocations& allAllocations) {
|
||||
const auto deviceVersionToExport = getTlvTargetFromCompileTarget(compileTarget);
|
||||
|
||||
uint32_t exportConfig;
|
||||
auto status = Gna2ModelExportConfigCreate(gnaUserAllocatorAlignedPage, &exportConfig);
|
||||
@ -150,6 +231,7 @@ void ExportTlvModel(uint32_t modelId,
|
||||
const auto gnaLibraryVersion = GNADeviceHelper::GetGnaLibraryVersion();
|
||||
|
||||
uint32_t outTlvSize = 0;
|
||||
|
||||
auto tlv_status = Gna2ExportTlv(
|
||||
deviceVersionToExport,
|
||||
gnaUserAllocator,
|
||||
@ -162,19 +244,20 @@ void ExportTlvModel(uint32_t modelId,
|
||||
(const char*)bufferStateRWData,
|
||||
sizeOfStateRWData,
|
||||
sizeOfScratchRWData,
|
||||
input_size,
|
||||
output_size,
|
||||
GnaEndpoint::GetTotalByteSize(allInputs),
|
||||
GnaEndpoint::GetTotalByteSize(allOutputs),
|
||||
gnaLibraryVersion.c_str(),
|
||||
nullptr,
|
||||
0);
|
||||
|
||||
if (Gna2TlvStatusSuccess == tlv_status) {
|
||||
outStream.write(outTlv, outTlvSize);
|
||||
auto tlvInSF = GetFloatInTLV(Gna2TlvTypeOVInputScaleFactor, inputSF);
|
||||
auto tlvOutSF = GetFloatInTLV(Gna2TlvTypeOVOutputScaleFactor, outputSF);
|
||||
outStream.write(tlvInSF.data(), tlvInSF.size());
|
||||
outStream.write(tlvOutSF.data(), tlvOutSF.size());
|
||||
auto metadata = WriteAllEndpoints(outStream, allInputs, Gna2TlvTypeOVInputScaleFactor, allAllocations.Get(Gna2MemoryTagInput));
|
||||
metadata += WriteAllEndpoints(outStream, allOutputs, Gna2TlvTypeOVOutputScaleFactor, allAllocations.Get(Gna2MemoryTagOutput));
|
||||
auto metadataTlv = GetStringAsTlv(Gna2TlvTypeOVString, metadata);
|
||||
outStream.write(metadataTlv.data(), metadataTlv.size());
|
||||
}
|
||||
|
||||
gnaUserFree(outTlv);
|
||||
|
||||
gnaUserFree(bufferLayerDescriptors);
|
||||
@ -185,57 +268,9 @@ void ExportTlvModel(uint32_t modelId,
|
||||
gnaUserFree(bufferInputRWData);
|
||||
gnaUserFree(bufferOutputRWData);
|
||||
|
||||
GNADeviceHelper::checkGna2Status((Gna2Status)status, "ExportTlvModel");
|
||||
status = Gna2ModelExportConfigRelease(exportConfig);
|
||||
GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigRelease");
|
||||
}
|
||||
|
||||
void ExportLdForDeviceVersion(
|
||||
uint32_t modelId,
|
||||
std::ostream & outStream,
|
||||
const Gna2DeviceVersion deviceVersionToExport) {
|
||||
|
||||
uint32_t exportConfig;
|
||||
auto status = Gna2ModelExportConfigCreate(gnaUserAllocatorAlignedPage, &exportConfig);
|
||||
GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigCreate");
|
||||
|
||||
status = Gna2ModelExportConfigSetSource(exportConfig, 0, modelId);
|
||||
GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigSetSource");
|
||||
status = Gna2ModelExportConfigSetTarget(exportConfig, deviceVersionToExport);
|
||||
GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigSetTarget");
|
||||
|
||||
void * ldDump = nullptr;
|
||||
uint32_t ldDumpSize;
|
||||
|
||||
status = Gna2ModelExport(exportConfig,
|
||||
Gna2ModelExportComponentLayerDescriptors,
|
||||
&ldDump, &ldDumpSize);
|
||||
GNADeviceHelper::checkGna2Status(status, "Gna2ModelExport(LayerDescriptors)");
|
||||
|
||||
outStream.write(static_cast<char*>(ldDump), ldDumpSize);
|
||||
|
||||
status = Gna2ModelExportConfigRelease(exportConfig);
|
||||
GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigRelease");
|
||||
|
||||
gnaUserFree(ldDump);
|
||||
}
|
||||
|
||||
void ExportGnaDescriptorPartiallyFilled(uint32_t number_of_layers, std::ostream& outStream) {
|
||||
const uint32_t scratchPadSize = 0x2000;
|
||||
const auto constScratchFill = static_cast<char>(-1);
|
||||
const uint32_t gnaDescSize = 32;
|
||||
char gd[gnaDescSize] = {};
|
||||
char gd2[gnaDescSize] = {};
|
||||
gd[0] = 1;
|
||||
*reinterpret_cast<uint32_t *>(gd + 4) = number_of_layers;
|
||||
*reinterpret_cast<uint32_t *>(gd + 8) = 0xffffffff;
|
||||
*reinterpret_cast<uint32_t *>(gd + 0xC) = 2 * sizeof(gd) + scratchPadSize;
|
||||
outStream.write(gd, sizeof(gd));
|
||||
outStream.write(gd2, sizeof(gd2));
|
||||
// TODO: GNA2: Scratchpad
|
||||
auto previousCharacter = outStream.fill(constScratchFill);
|
||||
auto previousWidth = outStream.width(scratchPadSize);
|
||||
outStream << constScratchFill;
|
||||
outStream.width(previousWidth);
|
||||
outStream.fill(previousCharacter);
|
||||
if (Gna2TlvStatusSuccess != tlv_status) {
|
||||
THROW_GNA_EXCEPTION << "Not succesfull status returned: " << tlv_status << ", from Gna2ExportTlv() function\n";
|
||||
}
|
||||
}
|
||||
|
@ -4,29 +4,79 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gna2-model-export-api.h"
|
||||
#include "gna2-common-api.h"
|
||||
#include "gna2-model-suecreek-header.h"
|
||||
|
||||
#include "gna_device_allocation.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
struct GnaEndpoint {
|
||||
std::string name;
|
||||
uint32_t byteSize = 0;
|
||||
uint32_t offset = 0;
|
||||
uint32_t numberOfBytesPerElement = 0;
|
||||
float scaleFactor = 0;
|
||||
void* gnaPointer = nullptr;
|
||||
|
||||
template <class T>
|
||||
static uint32_t GetTotalByteSize(const T& container);
|
||||
|
||||
template <class T>
|
||||
static GnaEndpoint CreateFromDescriptor(const T& descriptor);
|
||||
|
||||
template <class T>
|
||||
static std::vector<GnaEndpoint> CreateFromDescriptorContainer(const T& container);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
uint32_t GnaEndpoint::GetTotalByteSize(const T& container) {
|
||||
return std::accumulate(container.begin(), container.end(), 0, [](uint32_t cur, const GnaEndpoint& next) {
|
||||
return cur + next.byteSize;
|
||||
});
|
||||
}
|
||||
|
||||
template <class T>
|
||||
GnaEndpoint GnaEndpoint::CreateFromDescriptor(const T& descriptor) {
|
||||
GnaEndpoint e;
|
||||
e.scaleFactor = descriptor.scale_factor;
|
||||
e.byteSize = descriptor.get_required_size();
|
||||
e.name = descriptor.name;
|
||||
e.numberOfBytesPerElement = static_cast<uint32_t>(descriptor.tensor_precision.size());
|
||||
if (!descriptor.ptrs.empty()) {
|
||||
e.gnaPointer = descriptor.ptrs.front();
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::vector<GnaEndpoint> GnaEndpoint::CreateFromDescriptorContainer(const T& container) {
|
||||
std::vector<GnaEndpoint> result;
|
||||
for (const auto& e : container) {
|
||||
result.push_back(CreateFromDescriptor(e));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void * ExportSueLegacyUsingGnaApi2(
|
||||
uint32_t modelId,
|
||||
uint32_t deviceIndex,
|
||||
Gna2ModelSueCreekHeader* modelHeader);
|
||||
|
||||
void ExportLdForDeviceVersion(
|
||||
uint32_t modelId,
|
||||
std::ostream & outStream,
|
||||
Gna2DeviceVersion deviceVersionToExport);
|
||||
Gna2DeviceVersion getEmbeddedTargetFromCompileTarget(const std::string compileTarget);
|
||||
|
||||
void ExportTlvModel(uint32_t modelId,
|
||||
uint32_t deviceIndex,
|
||||
std::ostream& outStream,
|
||||
Gna2DeviceVersion deviceVersionToExport,
|
||||
uint32_t input_size,
|
||||
uint32_t output_size,
|
||||
float inputSF,
|
||||
float outputSF);
|
||||
|
||||
void ExportGnaDescriptorPartiallyFilled(uint32_t numberOfLayers, std::ostream & outStream);
|
||||
std::string compileTarget,
|
||||
const std::vector<GnaEndpoint>& inputs,
|
||||
const std::vector<GnaEndpoint>& outputs,
|
||||
const GnaAllocations& allAllocation);
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "backend/am_intel_dnn.hpp"
|
||||
#include "backend/gna_limitations.hpp"
|
||||
#include "common/gna_target.hpp"
|
||||
#include "gna/gna_config.hpp"
|
||||
#include "gna_plugin_log.hpp"
|
||||
#include "layers/gna_convolution_layer.hpp"
|
||||
@ -31,25 +32,22 @@
|
||||
|
||||
std::mutex GNADeviceHelper::acrossPluginsSync{};
|
||||
|
||||
|
||||
GNADeviceHelper::GNADeviceHelper(std::string executionTargetIn,
|
||||
std::string compileTargetIn,
|
||||
bool swExactModeIn,
|
||||
bool isPerformanceMeasuring,
|
||||
bool deviceEmbedded,
|
||||
int deviceVersionParsed)
|
||||
bool deviceEmbedded)
|
||||
: swExactMode(swExactModeIn),
|
||||
executionTarget(executionTargetIn),
|
||||
compileTarget(compileTargetIn),
|
||||
isPerformanceMeasuring(isPerformanceMeasuring),
|
||||
nGnaDeviceIndex{selectGnaDevice()},
|
||||
useDeviceEmbeddedExport(deviceEmbedded),
|
||||
exportGeneration(static_cast<Gna2DeviceVersion>(deviceVersionParsed)) {
|
||||
useDeviceEmbeddedExport(deviceEmbedded) {
|
||||
open();
|
||||
initGnaPerfCounters();
|
||||
|
||||
// check GNA Library version
|
||||
const auto gnaLibVersion = GetGnaLibraryVersion();
|
||||
GetGnaLibraryVersion();
|
||||
|
||||
maxLayersCount_ = retrieveMaxLayersCount();
|
||||
}
|
||||
@ -241,30 +239,16 @@ bool GNADeviceHelper::enforceLegacyCnnNeeded() const {
|
||||
}
|
||||
|
||||
Gna2DeviceVersion GNADeviceHelper::parseTarget(const std::string& target) {
|
||||
const std::map<std::string, Gna2DeviceVersion> targetMap {
|
||||
{InferenceEngine::GNAConfigParams::GNA_TARGET_2_0, Gna2DeviceVersion2_0},
|
||||
{InferenceEngine::GNAConfigParams::GNA_TARGET_3_0, Gna2DeviceVersion3_0},
|
||||
{"", Gna2DeviceVersionSoftwareEmulation},
|
||||
static const std::map<std::string, Gna2DeviceVersion> targetMap {
|
||||
{GNAPluginNS::common::kGnaTarget2_0, Gna2DeviceVersion2_0},
|
||||
{GNAPluginNS::common::kGnaTarget3_0, Gna2DeviceVersion3_0},
|
||||
{GNAPluginNS::common::kGnaTargetUnspecified, Gna2DeviceVersionSoftwareEmulation},
|
||||
};
|
||||
const auto f = targetMap.find(target);
|
||||
if (f != targetMap.end()) {
|
||||
return f->second;
|
||||
}
|
||||
THROW_GNA_EXCEPTION << "Unsupported " << "GNAConfigParams::GNA_TARGET = \"" << target << "\"\n";
|
||||
}
|
||||
|
||||
Gna2DeviceVersion GNADeviceHelper::parseDeclaredTarget(std::string target, const bool execTarget) const {
|
||||
auto parsed = Gna2DeviceVersion2_0;
|
||||
auto throwUnsupportedGnaTarget = [&](std::string extraSuffix) {
|
||||
auto key = execTarget ? InferenceEngine::GNAConfigParams::KEY_GNA_EXEC_TARGET : InferenceEngine::GNAConfigParams::KEY_GNA_COMPILE_TARGET;
|
||||
THROW_GNA_EXCEPTION << "Unsupported " << key << " = \"" << target << "\"" << extraSuffix;
|
||||
};
|
||||
if (target == InferenceEngine::GNAConfigParams::GNA_TARGET_3_0) {
|
||||
parsed = Gna2DeviceVersion3_0;
|
||||
} else if (target != InferenceEngine::GNAConfigParams::GNA_TARGET_2_0) {
|
||||
throwUnsupportedGnaTarget("");
|
||||
}
|
||||
return parsed;
|
||||
THROW_GNA_EXCEPTION << "Unsupported " << "GNA target: \"" << target << "\"\n";
|
||||
}
|
||||
|
||||
Gna2DeviceVersion GNADeviceHelper::getDefaultTarget() const {
|
||||
@ -275,10 +259,10 @@ Gna2DeviceVersion GNADeviceHelper::getDefaultTarget() const {
|
||||
|
||||
Gna2DeviceVersion GNADeviceHelper::getTargetDevice(const bool execTarget) const {
|
||||
const auto declared = execTarget ? executionTarget : compileTarget;
|
||||
if (declared.empty()) {
|
||||
if (declared == GNAPluginNS::common::kGnaTargetUnspecified) {
|
||||
return execTarget ? getDefaultTarget() : getTargetDevice(true);
|
||||
}
|
||||
return parseDeclaredTarget(declared, execTarget);
|
||||
return parseTarget(declared);
|
||||
}
|
||||
|
||||
uint32_t GNADeviceHelper::createRequestConfig(const uint32_t modelID) const {
|
||||
@ -514,32 +498,18 @@ GNADeviceHelper::DumpResult GNADeviceHelper::dumpXnn(const uint32_t modelId) {
|
||||
return r;
|
||||
}
|
||||
|
||||
void GNADeviceHelper::dumpXnnForDeviceVersion(
|
||||
const uint32_t modelId,
|
||||
std::ostream & outStream,
|
||||
const Gna2DeviceVersion targetDeviceVersion) {
|
||||
|
||||
Gna2ModelSueCreekHeader sueHeader;
|
||||
auto ptr = ExportSueLegacyUsingGnaApi2(modelId, nGnaDeviceIndex, &sueHeader);
|
||||
gnaUserFree(ptr);
|
||||
|
||||
ExportGnaDescriptorPartiallyFilled(sueHeader.NumberOfLayers, outStream);
|
||||
|
||||
ExportLdForDeviceVersion(modelId, outStream, targetDeviceVersion);
|
||||
if (dumpXNNROPtr == nullptr) {
|
||||
THROW_GNA_EXCEPTION << "Bad RO pointer (nullptr)";
|
||||
}
|
||||
outStream.write(static_cast<const char*>(dumpXNNROPtr), dumpXNNROSize);
|
||||
|
||||
// TODO: GNA2: remove
|
||||
outStream.write("Gna2ModelSueCreekHeader", 24);
|
||||
outStream.write(reinterpret_cast<const char*>(&sueHeader), sizeof(sueHeader));
|
||||
}
|
||||
|
||||
void GNADeviceHelper::dumpTLVForDeviceVersion(const uint32_t modelId, std::ostream& outStream,
|
||||
uint32_t input_size, uint32_t output_size,
|
||||
float inSF, float outSF) {
|
||||
ExportTlvModel(modelId, nGnaDeviceIndex, outStream, exportGeneration, input_size, output_size, inSF, outSF);
|
||||
void GNADeviceHelper::dumpTLVForDeviceVersion(const uint32_t modelId,
|
||||
std::ostream& outStream,
|
||||
const std::vector<GnaEndpoint>& inputsContainer,
|
||||
const std::vector<GnaEndpoint>& outputsContainer) {
|
||||
const auto compileTarget = GetCompileTarget();
|
||||
ExportTlvModel(modelId,
|
||||
nGnaDeviceIndex,
|
||||
outStream,
|
||||
compileTarget,
|
||||
inputsContainer,
|
||||
outputsContainer,
|
||||
allAllocations);
|
||||
}
|
||||
|
||||
void GNADeviceHelper::createVirtualDevice(Gna2DeviceVersion devVersion) {
|
||||
@ -557,6 +527,9 @@ void GNADeviceHelper::open() {
|
||||
updateGnaDeviceVersion();
|
||||
const auto gnaExecTarget = parseTarget(executionTarget);
|
||||
if (useDeviceEmbeddedExport) {
|
||||
const auto gnaCompileTarget = GetCompileTarget();
|
||||
const auto exportGeneration = getEmbeddedTargetFromCompileTarget(gnaCompileTarget);
|
||||
|
||||
createVirtualDevice(exportGeneration);
|
||||
updateGnaDeviceVersion();
|
||||
} else if (!executionTarget.empty() && gnaExecTarget != detectedGnaDevVersion) {
|
||||
@ -612,17 +585,10 @@ void GNADeviceHelper::getGnaPerfCounters(std::map<std::string, InferenceEngine::
|
||||
retPerfCounters["1.2 Stall scoring time in HW"] = info;
|
||||
}
|
||||
|
||||
std::string GNADeviceHelper::getEffectiveGnaCompileTarget() const {
|
||||
if (getTargetDevice(false) == Gna2DeviceVersion3_0) {
|
||||
return InferenceEngine::GNAConfigParams::GNA_TARGET_3_0;
|
||||
}
|
||||
return InferenceEngine::GNAConfigParams::GNA_TARGET_2_0;
|
||||
}
|
||||
|
||||
std::string GNADeviceHelper::GetCompileTarget() const {
|
||||
static const std::map<Gna2DeviceVersion, std::string> targetMap = {
|
||||
{Gna2DeviceVersion2_0, InferenceEngine::GNAConfigParams::GNA_TARGET_2_0},
|
||||
{Gna2DeviceVersion3_0, InferenceEngine::GNAConfigParams::GNA_TARGET_3_0},
|
||||
{Gna2DeviceVersion2_0, GNAPluginNS::common::kGnaTarget2_0},
|
||||
{Gna2DeviceVersion3_0, GNAPluginNS::common::kGnaTarget3_0},
|
||||
};
|
||||
const auto target = getTargetDevice(false);
|
||||
auto found = targetMap.find(target);
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <ie_common.h>
|
||||
|
||||
#include "gna2_model_export_helper.hpp"
|
||||
#include "memory/gna_mem_requests.hpp"
|
||||
|
||||
#include "gna2-common-api.h"
|
||||
@ -47,7 +48,6 @@ class GNADeviceHelper : public GNAPluginNS::GNADevice {
|
||||
std::string executionTarget;
|
||||
std::string compileTarget;
|
||||
bool useDeviceEmbeddedExport = false;
|
||||
Gna2DeviceVersion exportGeneration = Gna2DeviceVersionEmbedded1_0;
|
||||
uint32_t maxLayersCount_ = 0;
|
||||
|
||||
static const uint32_t TotalGna2InstrumentationPoints = 2;
|
||||
@ -74,8 +74,7 @@ public:
|
||||
std::string compileTargetIn = "",
|
||||
bool swExactModeIn = false,
|
||||
bool isPerformanceMeasuring = false,
|
||||
bool deviceEmbedded = false,
|
||||
int deviceVersionParsed = 0);
|
||||
bool deviceEmbedded = false);
|
||||
|
||||
GNADeviceHelper(const GNADeviceHelper&) = delete;
|
||||
GNADeviceHelper& operator= (const GNADeviceHelper&) = delete;
|
||||
@ -121,12 +120,10 @@ public:
|
||||
|
||||
DumpResult dumpXnn(const uint32_t modelId);
|
||||
|
||||
void dumpXnnForDeviceVersion(const uint32_t modelId,
|
||||
std::ostream & outStream,
|
||||
Gna2DeviceVersion targetDeviceVersion);
|
||||
void dumpTLVForDeviceVersion(const uint32_t modelId, std::ostream& outStream,
|
||||
uint32_t input_size, uint32_t output_size,
|
||||
float inSF, float outSF);
|
||||
void dumpTLVForDeviceVersion(const uint32_t modelId,
|
||||
std::ostream& outStream,
|
||||
const std::vector<GnaEndpoint>& inputsContainer,
|
||||
const std::vector<GnaEndpoint>& outputsContainer);
|
||||
|
||||
void free(void * ptr);
|
||||
|
||||
@ -134,7 +131,6 @@ public:
|
||||
void getGnaPerfCounters(std::map<std::string,
|
||||
InferenceEngine::InferenceEngineProfileInfo>& retPerfCounters);
|
||||
static std::string GetGnaLibraryVersion();
|
||||
std::string getEffectiveGnaCompileTarget() const;
|
||||
std::string GetCompileTarget() const;
|
||||
|
||||
const GnaAllocations& getAllAllocations() const {
|
||||
@ -181,7 +177,6 @@ private:
|
||||
static void enforceLegacyCnns(Gna2Model& gnaModel);
|
||||
static void enforceLegacyCnnsWhenNeeded(Gna2Model& gnaModel);
|
||||
static Gna2DeviceVersion parseTarget(const std::string& target);
|
||||
Gna2DeviceVersion parseDeclaredTarget(std::string target, const bool execTarget) const;
|
||||
Gna2DeviceVersion getDefaultTarget() const;
|
||||
Gna2DeviceVersion getTargetDevice(bool execTarget) const;
|
||||
|
||||
|
@ -165,4 +165,13 @@ public:
|
||||
newAllocation.sizeGranted = sizeGranted;
|
||||
allocations.push_back(newAllocation);
|
||||
}
|
||||
|
||||
const GnaAllocation* Get(const Gna2MemoryTag tag) const {
|
||||
for (auto&& a : allocations) {
|
||||
if (a.isTag(tag)) {
|
||||
return &a;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
@ -193,24 +193,36 @@ void GNAGraphCompiler::fillSplitConnections(InferenceEngine::CNNLayerPtr layer)
|
||||
split_connection.emplace(id, layerInfoItem);
|
||||
}
|
||||
|
||||
void GNAPluginNS::GNAGraphCompiler::SetValidatorTarget(std::string target) {
|
||||
if (InferenceEngine::GNAConfigParams::GNA_TARGET_3_0 == target) {
|
||||
cnn2dValidator.reset(new GNALimitations::Cnn2D::Validator_30());
|
||||
}
|
||||
void GNAPluginNS::GNAGraphCompiler::SetValidatorTarget(const std::string& target) {
|
||||
auto temp = GNALimitations::Cnn2D::AbstractValidator::Create(target);
|
||||
cnn2dValidator.reset(temp.release());
|
||||
}
|
||||
|
||||
void GNAPluginNS::GNAGraphCompiler::ValidateCnn2D(std::string name, const uint32_t inHeight, const uint32_t inWidth, const uint32_t inChannels,
|
||||
const uint32_t kH, const uint32_t kW, const uint32_t kN, const uint32_t strideH, const uint32_t strideW, OvGnaType inPrecision,
|
||||
const uint32_t dilH, const uint32_t dilW) const {
|
||||
void GNAPluginNS::GNAGraphCompiler::ValidateCnn2D(const std::string& name,
|
||||
const uint32_t inHeight,
|
||||
const uint32_t inWidth,
|
||||
const uint32_t inChannels,
|
||||
const uint32_t kH,
|
||||
const uint32_t kW,
|
||||
const uint32_t kN,
|
||||
const uint32_t strideH,
|
||||
const uint32_t strideW,
|
||||
const uint32_t dilH,
|
||||
const uint32_t dilW,
|
||||
OvGnaType inPrecision) const {
|
||||
if (cnn2dValidator) {
|
||||
cnn2dValidator->ValidateCnn2D(name, inHeight, inWidth, inChannels, kH, kW, kN, strideH, strideW, dilH, dilW, inPrecision);
|
||||
cnn2dValidator
|
||||
->ValidateCnn2D(name, inHeight, inWidth, inChannels, kH, kW, kN, strideH, strideW, dilH, dilW, inPrecision);
|
||||
} else {
|
||||
THROW_GNA_EXCEPTION << "No Cnn2D validator found for layer " << name;
|
||||
}
|
||||
}
|
||||
|
||||
void GNAPluginNS::GNAGraphCompiler::ValidatePooling2D(std::string name, const uint32_t windowH, const uint32_t windowW,
|
||||
const uint32_t strideH, const uint32_t strideW) const {
|
||||
void GNAPluginNS::GNAGraphCompiler::ValidatePooling2D(const std::string& name,
|
||||
const uint32_t windowH,
|
||||
const uint32_t windowW,
|
||||
const uint32_t strideH,
|
||||
const uint32_t strideW) const {
|
||||
if (cnn2dValidator) {
|
||||
cnn2dValidator->ValidatePooling2D(name, windowH, windowW, strideH, strideW);
|
||||
} else {
|
||||
@ -218,6 +230,14 @@ void GNAPluginNS::GNAGraphCompiler::ValidatePooling2D(std::string name, const ui
|
||||
}
|
||||
}
|
||||
|
||||
bool GNAPluginNS::GNAGraphCompiler::IsCnn2DInputPaddingSupported(const std::string& name) const {
|
||||
if (cnn2dValidator) {
|
||||
return cnn2dValidator->IsPaddingSupported();
|
||||
} else {
|
||||
THROW_GNA_EXCEPTION << "No Cnn2D input padding validator found for layer " << name;
|
||||
}
|
||||
}
|
||||
|
||||
void GNAGraphCompiler::DiagonalPrimitive(InferenceEngine::CNNLayerPtr layer) {
|
||||
AffinePrimitive(layer, true);
|
||||
}
|
||||
@ -587,8 +607,9 @@ void GNAGraphCompiler::finalizeConvolution2DPrimitive(InferenceEngine::CNNLayerP
|
||||
auto effectiveInputWidth = in_width;
|
||||
auto effectiveInputHeight = in_height;
|
||||
|
||||
if (convolution._padding_x != 0 || convolution._padding_y != 0 ||
|
||||
convolution._pads_end.at(X_AXIS) != 0 || convolution._pads_end.at(Y_AXIS) != 0) {
|
||||
if (!IsCnn2DInputPaddingSupported(convolution.name) &&
|
||||
(convolution._padding_x != 0 || convolution._padding_y != 0 ||
|
||||
convolution._pads_end.at(X_AXIS) != 0 || convolution._pads_end.at(Y_AXIS) != 0)) {
|
||||
THROW_GNA_LAYER_EXCEPTION(layer) << "Convolution's input padding is not supported";
|
||||
}
|
||||
|
||||
@ -598,6 +619,8 @@ void GNAGraphCompiler::finalizeConvolution2DPrimitive(InferenceEngine::CNNLayerP
|
||||
if (convolution._padding_y != convolution._pads_end.at(Y_AXIS)) {
|
||||
THROW_GNA_LAYER_EXCEPTION(layer) << "Convolution's input padding is not symetric along Y axis";
|
||||
}
|
||||
convolution._padding_x = convolution._pads_end.at(X_AXIS);
|
||||
convolution._padding_y = convolution._pads_end.at(Y_AXIS);
|
||||
|
||||
if (convolution._kernel_x > effectiveInputWidth ||
|
||||
convolution._kernel_y > effectiveInputHeight) {
|
||||
@ -636,7 +659,7 @@ void GNAGraphCompiler::finalizeConvolution2DPrimitive(InferenceEngine::CNNLayerP
|
||||
ValidateCnn2D(layer->name,
|
||||
in_height, in_width, in_channels,
|
||||
convolution._kernel_y, convolution._kernel_x, filter_n, convolution._stride_y, convolution._stride_x,
|
||||
inputPrec, convolution._dilation_y, convolution._dilation_x);
|
||||
convolution._dilation_y, convolution._dilation_x, inputPrec);
|
||||
|
||||
float weight_scale_factor = getScaleFactor(layer, QuantizedDataType::weights);
|
||||
float output_scale_factor = getScaleFactor(layer, QuantizedDataType::output);
|
||||
|
@ -68,17 +68,19 @@ public:
|
||||
void fillConcatConnections(InferenceEngine::CNNLayerPtr layer);
|
||||
void fillSplitConnections(InferenceEngine::CNNLayerPtr layer);
|
||||
|
||||
|
||||
void ValidateCnn2D(std::string name, const uint32_t inHeight, const uint32_t inWidth,
|
||||
void ValidateCnn2D(const std::string& name, const uint32_t inHeight, const uint32_t inWidth,
|
||||
const uint32_t inChannels, const uint32_t kH, const uint32_t kW, const uint32_t kN,
|
||||
const uint32_t strideH, const uint32_t strideW, OvGnaType inPrecision,
|
||||
const uint32_t dilH, const uint32_t dilW) const;
|
||||
const uint32_t strideH, const uint32_t strideW,
|
||||
const uint32_t dilH, const uint32_t dilW,
|
||||
OvGnaType inPrecision) const;
|
||||
|
||||
void ValidatePooling2D(std::string name,
|
||||
void ValidatePooling2D(const std::string& name,
|
||||
const uint32_t windowH, const uint32_t windowW,
|
||||
const uint32_t strideH, const uint32_t strideW) const;
|
||||
|
||||
void SetValidatorTarget(std::string target);
|
||||
bool IsCnn2DInputPaddingSupported(const std::string& name) const;
|
||||
|
||||
void SetValidatorTarget(const std::string& target);
|
||||
|
||||
/**
|
||||
* Connects either memory output, or generic output to a layer
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <gna/gna_config.hpp>
|
||||
#include "gna_plugin_config.hpp"
|
||||
#include "gna_plugin.hpp"
|
||||
#include "common/gna_target.hpp"
|
||||
#include "optimizer/gna_pass_manager.hpp"
|
||||
#include "layers/gna_layer_type.hpp"
|
||||
#include "preprocessing.hpp"
|
||||
@ -38,6 +39,7 @@
|
||||
#include "gna_graph_patterns.hpp"
|
||||
#include "gna_tensor_tools.hpp"
|
||||
#include "gna_itt.hpp"
|
||||
#include "gna2_model_export_helper.hpp"
|
||||
#include "gna2_model_helper.hpp"
|
||||
#include "request/model_wrapper_factory.hpp"
|
||||
#include "request/worker_pool_impl.hpp"
|
||||
@ -339,7 +341,7 @@ std::string GNAPluginNS::GNAPlugin::GetCompileTarget() const {
|
||||
} else if (!config.gnaCompileTarget.empty()) {
|
||||
return config.gnaCompileTarget;
|
||||
}
|
||||
return InferenceEngine::GNAConfigParams::GNA_TARGET_3_0;
|
||||
return common::kGnaTarget3_0;
|
||||
}
|
||||
|
||||
GNAPlugin::GNAPlugin(const std::map<std::string, std::string>& configMap) {
|
||||
@ -371,8 +373,7 @@ void GNAPlugin::InitGNADevice() {
|
||||
config.gnaCompileTarget,
|
||||
config.swExactMode,
|
||||
gnaFlags->performance_counting,
|
||||
!config.dumpXNNPath.empty(),
|
||||
GetDeviceVersionFromString(config.gnaCompileTarget));
|
||||
!config.dumpXNNPath.empty());
|
||||
size_t page_size_bytes = 4096;
|
||||
gnamem = std::make_shared<gna_memory_device>(memory::GNAAllocator(gnadevice), page_size_bytes);
|
||||
if (gnaFlags->log_level == ov::log::Level::DEBUG) {
|
||||
@ -1206,13 +1207,6 @@ std::shared_ptr<request::ModelWrapper> GNAPluginNS::GNAPlugin::createModelWrappe
|
||||
return request::ModelWrapperFactory::createWithNumberOfEmptyOperations(numberOfOperations);
|
||||
}
|
||||
|
||||
int GNAPlugin::GetDeviceVersionFromString(const std::string deviceString) {
|
||||
if (deviceString.empty() || deviceString == InferenceEngine::GNAConfigParams::GNA_TARGET_2_0) {
|
||||
return static_cast<int>(Gna2DeviceVersionEmbedded1_0);
|
||||
}
|
||||
return static_cast<int>(Gna2DeviceVersionEmbedded3_5);
|
||||
}
|
||||
|
||||
void GNAPlugin::DumpXNNToFile() const {
|
||||
// TODO: output precision as well as pointer might be incorrect, LSTM for sure
|
||||
// gna looks automatically set layer 0 as output and adjust it's pointer / precision/ size respectively
|
||||
@ -1236,7 +1230,7 @@ void GNAPlugin::DumpXNNToFile() const {
|
||||
const auto& inputsDesc = inputs_ptr_->Get();
|
||||
const auto& outputsDesc = outputs_.Get();
|
||||
|
||||
if (InferenceEngine::GNAConfigParams::GNA_TARGET_2_0 == gnadevice->getEffectiveGnaCompileTarget()) {
|
||||
if (common::kGnaTarget2_0 == gnadevice->GetCompileTarget()) {
|
||||
auto dump = gnadevice->dumpXnn(modelId);
|
||||
dump.header.RwRegionSize = gnamem->getRegionBytes(REGION_SCRATCH);
|
||||
dump.header.InputScalingFactor = inputsDesc.begin()->scale_factor;
|
||||
@ -1244,16 +1238,9 @@ void GNAPlugin::DumpXNNToFile() const {
|
||||
dumpStream.write(reinterpret_cast<char*>(&dump.header), sizeof(Gna2ModelSueCreekHeader));
|
||||
dumpStream.write(reinterpret_cast<char*>(dump.model.get()), dump.header.ModelSize);
|
||||
} else {
|
||||
uint32_t input_size = 0;
|
||||
uint32_t output_size = 0;
|
||||
for (auto i : inputsDesc)
|
||||
input_size += i.get_allocated_size();
|
||||
for (auto o : outputsDesc)
|
||||
output_size += o.get_required_size();
|
||||
auto inSF = inputsDesc.begin()->scale_factor;
|
||||
auto outSF = outputsDesc.front().scale_factor;
|
||||
gnadevice->dumpTLVForDeviceVersion(modelId, dumpStream,
|
||||
input_size, output_size, inSF, outSF);
|
||||
const auto inputsForTlv = GnaEndpoint::CreateFromDescriptorContainer(inputsDesc);
|
||||
const auto outputsForTlv = GnaEndpoint::CreateFromDescriptorContainer(outputsDesc);
|
||||
gnadevice->dumpTLVForDeviceVersion(modelId, dumpStream, inputsForTlv, outputsForTlv);
|
||||
}
|
||||
gnadevice->releaseModel(modelId);
|
||||
}
|
||||
|
@ -52,8 +52,6 @@ protected:
|
||||
uint32_t dnn_dump_write_index = 0;
|
||||
intel_dnn_number_type_t output_type = kDnnInt;
|
||||
|
||||
static int GetDeviceVersionFromString(const std::string deviceString);
|
||||
|
||||
std::shared_ptr<GNADeviceHelper> gnadevice;
|
||||
|
||||
std::shared_ptr<request::WorkerPool> requestWorkerPool_;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <gna/gna_config.hpp>
|
||||
#include "gna_plugin.hpp"
|
||||
#include "gna_plugin_config.hpp"
|
||||
#include "common/gna_target.hpp"
|
||||
#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp"
|
||||
#include "ie_common.h"
|
||||
#include <caseless.hpp>
|
||||
@ -39,9 +40,9 @@ static const caseless_unordered_map<std::string, std::pair<Gna2AccelerationMode,
|
||||
OPENVINO_SUPPRESS_DEPRECATED_END
|
||||
|
||||
static const std::set<std::string> supportedTargets = {
|
||||
GNAConfigParams::GNA_TARGET_2_0,
|
||||
GNAConfigParams::GNA_TARGET_3_0,
|
||||
""
|
||||
common::kGnaTarget2_0,
|
||||
common::kGnaTarget3_0,
|
||||
common::kGnaTargetUnspecified
|
||||
};
|
||||
|
||||
void Config::UpdateFromMap(const std::map<std::string, std::string>& config) {
|
||||
@ -153,9 +154,9 @@ OPENVINO_SUPPRESS_DEPRECATED_END
|
||||
auto target = ov::util::from_string(value, ov::intel_gna::execution_target);
|
||||
std::string target_str = "";
|
||||
if (ov::intel_gna::HWGeneration::GNA_2_0 == target) {
|
||||
target_str = GNAConfigParams::GNA_TARGET_2_0;
|
||||
target_str = common::kGnaTarget2_0;
|
||||
} else if (ov::intel_gna::HWGeneration::GNA_3_0 == target) {
|
||||
target_str = GNAConfigParams::GNA_TARGET_3_0;
|
||||
target_str = common::kGnaTarget3_0;
|
||||
}
|
||||
set_target(target_str);
|
||||
} else if (key == GNA_CONFIG_KEY(EXEC_TARGET)) {
|
||||
@ -373,12 +374,12 @@ Parameter Config::GetParameter(const std::string& name) const {
|
||||
} else if (name == ov::intel_gna::pwl_design_algorithm) {
|
||||
return gnaFlags.pwl_design_algorithm;
|
||||
} else if (name == ov::intel_gna::execution_target) {
|
||||
return ((gnaExecTarget == GNAConfigParams::GNA_TARGET_2_0) ? ov::intel_gna::HWGeneration::GNA_2_0 :
|
||||
(gnaExecTarget == GNAConfigParams::GNA_TARGET_3_0) ? ov::intel_gna::HWGeneration::GNA_3_0 :
|
||||
return ((gnaExecTarget == common::kGnaTarget2_0) ? ov::intel_gna::HWGeneration::GNA_2_0 :
|
||||
(gnaExecTarget == common::kGnaTarget3_0) ? ov::intel_gna::HWGeneration::GNA_3_0 :
|
||||
ov::intel_gna::HWGeneration::UNDEFINED);
|
||||
} else if (name == ov::intel_gna::compile_target) {
|
||||
return ((gnaCompileTarget == GNAConfigParams::GNA_TARGET_2_0) ? ov::intel_gna::HWGeneration::GNA_2_0 :
|
||||
(gnaCompileTarget == GNAConfigParams::GNA_TARGET_3_0) ? ov::intel_gna::HWGeneration::GNA_3_0 :
|
||||
return ((gnaCompileTarget == common::kGnaTarget2_0) ? ov::intel_gna::HWGeneration::GNA_2_0 :
|
||||
(gnaCompileTarget == common::kGnaTarget3_0) ? ov::intel_gna::HWGeneration::GNA_3_0 :
|
||||
ov::intel_gna::HWGeneration::UNDEFINED);
|
||||
} else if (name == ov::hint::performance_mode) {
|
||||
return performance_mode;
|
||||
|
361
src/tests/unit/gna/backend/gna_limitations_test.cpp
Normal file
361
src/tests/unit/gna/backend/gna_limitations_test.cpp
Normal file
@ -0,0 +1,361 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "backend/gna_limitations.hpp"
|
||||
#include "common/gna_target.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
using namespace GNAPluginNS::GNALimitations;
|
||||
using GNAPluginNS::common::kGnaTarget3_0;
|
||||
using GNAPluginNS::common::kGnaTarget3_5;
|
||||
|
||||
struct GNACnn2DValidatorTestParam {
|
||||
std::string target;
|
||||
std::string whatInvalid;
|
||||
std::vector<uint32_t> invalid;
|
||||
};
|
||||
|
||||
const std::vector<uint32_t> kInvalidH_30 = {0, 400};
|
||||
const std::vector<uint32_t> kInvalidH_35 = {0, 65536};
|
||||
|
||||
const std::vector<uint32_t> kInvalidW_30 = {0, 400};
|
||||
const std::vector<uint32_t> kInvalidW_35 = {0, 65536};
|
||||
|
||||
const std::vector<uint32_t> kInvalidC_30 = {0, 1, 400};
|
||||
const std::vector<uint32_t> kInvalidC_35 = {0, 2049};
|
||||
|
||||
const std::vector<uint32_t> kInvalidkH_30 = {0, 8, 400};
|
||||
const std::vector<uint32_t> kInvalidkH_35 = {0, 257, 2049};
|
||||
|
||||
const std::vector<uint32_t> kInvalidkW_30 = {0, 8, 400};
|
||||
const std::vector<uint32_t> kInvalidkW_35 = {0, 257, 2049};
|
||||
|
||||
const std::vector<uint32_t> kInvalidkN_30 = {0, 1, 400};
|
||||
const std::vector<uint32_t> kInvalidkN_35 = {0, 2049};
|
||||
|
||||
const std::vector<uint32_t> kInvalidsH_30 = {0, 400};
|
||||
const std::vector<uint32_t> kInvalidsH_35 = {0, 2049};
|
||||
|
||||
const std::vector<uint32_t> kInvalidsW_30 = {0, 400};
|
||||
const std::vector<uint32_t> kInvalidsW_35 = {0, 2049};
|
||||
|
||||
const std::vector<uint32_t> kInvaliddH_30 = {0, 2, 400};
|
||||
const std::vector<uint32_t> kInvaliddH_35 = {0, 2, 2049};
|
||||
|
||||
const std::vector<uint32_t> kInvaliddW_30 = {0, 2, 400};
|
||||
const std::vector<uint32_t> kInvaliddW_35 = {0, 2, 2049};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_30 {
|
||||
kGnaTarget3_0,
|
||||
"inH",
|
||||
kInvalidH_30,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_35 {
|
||||
kGnaTarget3_5,
|
||||
"inH",
|
||||
kInvalidH_35,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_30_inW{
|
||||
kGnaTarget3_0,
|
||||
"inW",
|
||||
kInvalidW_30,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_35_inW{
|
||||
kGnaTarget3_5,
|
||||
"inW",
|
||||
kInvalidW_35,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_30_inC{
|
||||
kGnaTarget3_0,
|
||||
"inC",
|
||||
kInvalidC_30,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_35_inC{
|
||||
kGnaTarget3_5,
|
||||
"inC",
|
||||
kInvalidC_35,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_30_kH{
|
||||
kGnaTarget3_0,
|
||||
"kH",
|
||||
kInvalidkH_30,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_35_kH{
|
||||
kGnaTarget3_5,
|
||||
"kH",
|
||||
kInvalidkH_35,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_30_kW{
|
||||
kGnaTarget3_0,
|
||||
"kW",
|
||||
kInvalidkW_30,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_35_kW{
|
||||
kGnaTarget3_5,
|
||||
"kW",
|
||||
kInvalidkW_35,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_30_kN{
|
||||
kGnaTarget3_0,
|
||||
"inC",
|
||||
kInvalidkN_30,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_35_kN{
|
||||
kGnaTarget3_5,
|
||||
"inC",
|
||||
kInvalidkN_35,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_30_sH{
|
||||
kGnaTarget3_0,
|
||||
"sH",
|
||||
kInvalidsH_30,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_35_sH{
|
||||
kGnaTarget3_5,
|
||||
"sH",
|
||||
kInvalidsH_35,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_30_sW{
|
||||
kGnaTarget3_0,
|
||||
"sW",
|
||||
kInvalidsW_30,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_35_sW{
|
||||
kGnaTarget3_5,
|
||||
"sW",
|
||||
kInvalidsW_35,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_30_dH{
|
||||
kGnaTarget3_0,
|
||||
"dH",
|
||||
kInvaliddH_30,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_35_dH{
|
||||
kGnaTarget3_5,
|
||||
"dH",
|
||||
kInvaliddH_35,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_30_dW{
|
||||
kGnaTarget3_0,
|
||||
"dW",
|
||||
kInvaliddW_30,
|
||||
};
|
||||
|
||||
const GNACnn2DValidatorTestParam target_35_dW{
|
||||
kGnaTarget3_5,
|
||||
"dW",
|
||||
kInvaliddW_35,
|
||||
};
|
||||
|
||||
const std::vector<uint32_t> kInvalidpw_30 = {0, 2, 10};
|
||||
const GNACnn2DValidatorTestParam target_30_pwH{
|
||||
kGnaTarget3_0,
|
||||
"windowH",
|
||||
kInvalidpw_30,
|
||||
};
|
||||
const GNACnn2DValidatorTestParam target_30_pwW{
|
||||
kGnaTarget3_0,
|
||||
"windowW",
|
||||
kInvalidpw_30,
|
||||
};
|
||||
|
||||
const std::vector<uint32_t> kInvalidps_30 = {0, 4, 10};
|
||||
const GNACnn2DValidatorTestParam target_30_psH{
|
||||
kGnaTarget3_0,
|
||||
"strideH",
|
||||
kInvalidps_30,
|
||||
};
|
||||
const GNACnn2DValidatorTestParam target_30_psW{
|
||||
kGnaTarget3_0,
|
||||
"strideW",
|
||||
kInvalidps_30,
|
||||
};
|
||||
|
||||
const std::vector<uint32_t> kInvalidPoolingRange35 = {0, 256};
|
||||
const GNACnn2DValidatorTestParam target_35_pwH{
|
||||
kGnaTarget3_5,
|
||||
"windowH",
|
||||
kInvalidPoolingRange35,
|
||||
};
|
||||
const GNACnn2DValidatorTestParam target_35_pwW{
|
||||
kGnaTarget3_5,
|
||||
"windowW",
|
||||
kInvalidPoolingRange35,
|
||||
};
|
||||
const GNACnn2DValidatorTestParam target_35_psH{
|
||||
kGnaTarget3_5,
|
||||
"strideH",
|
||||
kInvalidPoolingRange35,
|
||||
};
|
||||
const GNACnn2DValidatorTestParam target_35_psW{
|
||||
kGnaTarget3_5,
|
||||
"strideW",
|
||||
kInvalidPoolingRange35,
|
||||
};
|
||||
|
||||
|
||||
struct ValidateCnn2DParams {
|
||||
std::map<std::string, uint32_t> parameters;
|
||||
OvGnaType precission;
|
||||
static const bool exceptionMode = false;
|
||||
|
||||
static ValidateCnn2DParams GetValid() {
|
||||
ValidateCnn2DParams v;
|
||||
v.parameters["inH"] = 16;
|
||||
v.parameters["inW"] = 16;
|
||||
v.parameters["inC"] = 16;
|
||||
v.parameters["kH"] = 2;
|
||||
v.parameters["kW"] = 2;
|
||||
v.parameters["kN"] = 8;
|
||||
v.parameters["sH"] = 1;
|
||||
v.parameters["sW"] = 1;
|
||||
v.parameters["dH"] = 1;
|
||||
v.parameters["dW"] = 1;
|
||||
v.precission = OvGnaTypeInt16;
|
||||
return v;
|
||||
}
|
||||
|
||||
static ValidateCnn2DParams GetValidPooling() {
|
||||
ValidateCnn2DParams v;
|
||||
v.parameters["windowH"] = 3;
|
||||
v.parameters["windowW"] = 3;
|
||||
v.parameters["strideH"] = 3;
|
||||
v.parameters["strideW"] = 3;
|
||||
return v;
|
||||
}
|
||||
|
||||
bool ValidateCnn2D(const Cnn2D::AbstractValidator& validator) {
|
||||
return validator.ValidateCnn2D({},
|
||||
parameters["inH"],
|
||||
parameters["inW"],
|
||||
parameters["inC"],
|
||||
parameters["kH"],
|
||||
parameters["kW"],
|
||||
parameters["kN"],
|
||||
parameters["sH"],
|
||||
parameters["sW"],
|
||||
parameters["dH"],
|
||||
parameters["dW"],
|
||||
precission, exceptionMode);
|
||||
}
|
||||
|
||||
bool ValidatePooling2D(const Cnn2D::AbstractValidator& validator) {
|
||||
return validator.ValidatePooling2D({},
|
||||
parameters["windowH"],
|
||||
parameters["windowW"],
|
||||
parameters["strideH"],
|
||||
parameters["strideW"],
|
||||
exceptionMode);
|
||||
}
|
||||
|
||||
void set(const std::string& what, const uint32_t value) {
|
||||
if (what == "precission") {
|
||||
precission = static_cast<OvGnaType>(value);
|
||||
} else {
|
||||
parameters[what] = value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class GNACnn2DValidatorTest : public ::testing::TestWithParam<GNACnn2DValidatorTestParam> {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
validator = Cnn2D::AbstractValidator::Create(GetParam().target);
|
||||
ASSERT_TRUE(validator != nullptr);
|
||||
}
|
||||
std::unique_ptr<Cnn2D::AbstractValidator> validator;
|
||||
};
|
||||
|
||||
class GNACnn2DValidatorTestPadding : public GNACnn2DValidatorTest {
|
||||
protected:
|
||||
bool isPaddingSupported() {
|
||||
static const std::set<std::string> supported{kGnaTarget3_5};
|
||||
return supported.count(GetParam().target);
|
||||
}
|
||||
};
|
||||
|
||||
class GNACnn2DValidatorTestPooling2D : public GNACnn2DValidatorTest {};
|
||||
|
||||
namespace {
|
||||
TEST_P(GNACnn2DValidatorTestPadding, testPaddingSupported) {
|
||||
ASSERT_TRUE(validator->IsPaddingSupported() == isPaddingSupported());
|
||||
}
|
||||
|
||||
TEST_P(GNACnn2DValidatorTest, testValidateCnn2DInvalid) {
|
||||
auto valid = ValidateCnn2DParams::GetValid();
|
||||
for (const auto invalid : GetParam().invalid) {
|
||||
valid.set(GetParam().whatInvalid, invalid);
|
||||
ASSERT_FALSE(valid.ValidateCnn2D(*validator));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(GNACnn2DValidatorTestPooling2D, testValidateCnn2DInvalid) {
|
||||
auto valid = ValidateCnn2DParams::GetValidPooling();
|
||||
for (const auto invalid : GetParam().invalid) {
|
||||
valid.set(GetParam().whatInvalid, invalid);
|
||||
ASSERT_FALSE(valid.ValidatePooling2D(*validator));
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_GNACnn2DValidatorTestPadding,
|
||||
GNACnn2DValidatorTestPadding,
|
||||
testing::Values(target_30, target_35));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_GNACnn2DValidatorTest,
|
||||
GNACnn2DValidatorTest,
|
||||
testing::Values(target_30,
|
||||
target_35,
|
||||
target_30_inW,
|
||||
target_35_inW,
|
||||
target_30_inC,
|
||||
target_35_inC,
|
||||
target_30_kH,
|
||||
target_35_kH,
|
||||
target_30_kW,
|
||||
target_35_kW,
|
||||
target_30_kN,
|
||||
target_35_kN,
|
||||
target_30_sH,
|
||||
target_30_sW,
|
||||
target_30_dH,
|
||||
target_30_dW,
|
||||
target_35_sH,
|
||||
target_35_sW,
|
||||
target_35_dH,
|
||||
target_35_dW)
|
||||
);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_GNACnn2DValidatorTestPooling2D,
|
||||
GNACnn2DValidatorTestPooling2D,
|
||||
testing::Values(target_30_pwH,
|
||||
target_30_pwW,
|
||||
target_30_psH,
|
||||
target_30_psW,
|
||||
target_35_pwH,
|
||||
target_35_pwW,
|
||||
target_35_psH,
|
||||
target_35_psW));
|
||||
|
||||
} // namespace
|
Loading…
Reference in New Issue
Block a user