[IE TESTS] Fix Comparation issue in LayerTestCommon class (#5624)
* [IE TESTS] Fix comparation in LayerTestUtils * Fixes * Small fix * Int4 fixes * remove extra * Fix NMS * Some fixes for tests * Add small fix * [IE TESTS] Remove const folding as a result engine * Remove extra * Revert remove constant folding (DSR test) & fix some cases for cpu * Fix GNA
This commit is contained in:
1 parent
ce8e1dc214
commit
9568f8120e
34 files changed
+347
-189
No files matched your search
@@ -46,7 +46,6 @@ public:
|
||||
}
|
||||
protected:
|
||||
void SetUp() override {
|
||||
SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
|
||||
size_t axis, numSplits;
|
||||
std::vector<size_t> inputShape, outIndices;
|
||||
InferenceEngine::Precision netPrecision;
|
||||
|
||||
@@ -42,8 +42,6 @@ public:
|
||||
}
|
||||
protected:
|
||||
void SetUp() override {
|
||||
SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
|
||||
|
||||
Precision netPrecision;
|
||||
std::vector<size_t> inputShape, inputOrder;
|
||||
CPUSpecificParams cpuParams;
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ public:
|
||||
ngraph::ResultVector results{std::make_shared<ngraph::opset3::Result>(gather)};
|
||||
function = std::make_shared<ngraph::Function>(results, params, "gather");
|
||||
}
|
||||
std::vector<std::vector<std::uint8_t>> CalculateRefs() override {
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> CalculateRefs() override {
|
||||
// Convert the second input constant precision to i64 to run the reference function
|
||||
if (ngraph::element::Type_t::i8 == secondConstantType) {
|
||||
ngraph::pass::ConvertPrecision<ngraph::element::Type_t::i8, ngraph::element::Type_t::i64>().run_on_function(function);
|
||||
|
||||
+1
-1
@@ -325,7 +325,7 @@ TEST_P(TwoNets_Test, canInferTwoExecNets) {
|
||||
const auto blobSize = inBlob->byteSize();
|
||||
const auto inBlobBuf = inBlob->cbuffer().as<uint8_t *>();
|
||||
std::vector<uint8_t> inData(inBlobBuf, inBlobBuf + blobSize);
|
||||
std::vector<uint8_t> reOutData = ngraph::helpers::interpreterFunction(fn_ptrs[i], {inData}).front();
|
||||
auto reOutData = ngraph::helpers::interpreterFunction(fn_ptrs[i], {inData}).front().second;
|
||||
ref.push_back(reOutData);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -64,9 +64,10 @@ protected:
|
||||
return FuncTestUtils::createAndFillBlobFloat(info.getTensorDesc(), 4, -2, 2);
|
||||
}
|
||||
|
||||
void Compare(const std::vector<std::vector<std::uint8_t>>& expectedOutput, const std::vector<InferenceEngine::Blob::Ptr>& actualOutputs) override {
|
||||
const auto expectedIndicesPtr = reinterpret_cast<const int32_t*>(expectedOutput[0].data());
|
||||
const auto expectedDimsPtr = reinterpret_cast<const int32_t*>(expectedOutput[1].data());
|
||||
void Compare(const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>>& expectedOutput,
|
||||
const std::vector<InferenceEngine::Blob::Ptr>& actualOutputs) override {
|
||||
const auto expectedIndicesPtr = reinterpret_cast<const int32_t*>(expectedOutput[0].second.data());
|
||||
const auto expectedDimsPtr = reinterpret_cast<const int32_t*>(expectedOutput[1].second.data());
|
||||
|
||||
const auto actualIndices = actualOutputs[0];
|
||||
const auto actualDims = actualOutputs[1];
|
||||
|
||||
-1
@@ -24,7 +24,6 @@ using Parameters = std::tuple<
|
||||
class Concat_Split_Transpose : public testing::WithParamInterface<Parameters>, virtual public LayerTestsUtils::LayerTestsCommon {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
|
||||
configuration[InferenceEngine::MYRIAD_DISABLE_CONVERT_STAGES] = CONFIG_VALUE(YES);
|
||||
configuration[InferenceEngine::MYRIAD_DETECT_NETWORK_BATCH] = CONFIG_VALUE(NO);
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ protected:
|
||||
virtual std::shared_ptr<ngraph::Node> createTestedOp() = 0;
|
||||
|
||||
void SetUp() override {
|
||||
// TODO: Replace CONSTANT_FOLDING to INTERPRETER
|
||||
SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
|
||||
configuration[InferenceEngine::MYRIAD_DETECT_NETWORK_BATCH] = CONFIG_VALUE(NO);
|
||||
if (CommonTestUtils::vpu::CheckMyriad2()) {
|
||||
|
||||
@@ -20,8 +20,6 @@ using Parameters = std::tuple<
|
||||
class NonZero_Transpose : public testing::WithParamInterface<Parameters>, virtual public LayerTestsUtils::LayerTestsCommon {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
|
||||
|
||||
const auto& parameters = GetParam();
|
||||
const auto& dataType = std::get<0>(parameters);
|
||||
const auto& dataDims = std::get<1>(parameters);
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ private:
|
||||
std::vector<size_t> batch_sizes;
|
||||
std::vector<std::vector<InferenceEngine::Blob::Ptr>> reference_inputs;
|
||||
std::vector<std::vector<InferenceEngine::Blob::Ptr>> scaled_inputs;
|
||||
std::vector<std::vector<std::vector<uint8_t>>> reference_outputs;
|
||||
std::vector<std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>>> reference_outputs;
|
||||
std::vector<std::vector<InferenceEngine::Blob::Ptr>> actual_outputs;
|
||||
std::vector<InferenceEngine::InferRequest> infer_requests;
|
||||
protected:
|
||||
|
||||
+3
-3
@@ -141,10 +141,10 @@ namespace ConfigurationTestsDefinitions {
|
||||
outputs.push_back(infer_requests[i].GetBlob(name));
|
||||
}
|
||||
for (int j = 0; j < reference_outputs[i].size(); j++) {
|
||||
if (reference_outputs[i][j].size() < outputs[j]->byteSize()) {
|
||||
if (reference_outputs[i][j].second.size() < outputs[j]->byteSize()) {
|
||||
auto actual_ptr = outputs[j]->buffer().as<uint8_t*>();
|
||||
for (int k = reference_outputs[i][j].size(); k < outputs[j]->byteSize(); k++) actual_ptr[k] = 0;
|
||||
reference_outputs[i][j].resize(outputs[j]->byteSize());
|
||||
for (int k = reference_outputs[i][j].second.size(); k < outputs[j]->byteSize(); k++) actual_ptr[k] = 0;
|
||||
reference_outputs[i][j].second.resize(outputs[j]->byteSize());
|
||||
}
|
||||
}
|
||||
Compare(reference_outputs[i], outputs);
|
||||
|
||||
+17
-13
@@ -57,18 +57,18 @@ public:
|
||||
|
||||
virtual void Serialize();
|
||||
|
||||
static void Compare(const std::vector<std::vector<std::uint8_t>> &expected,
|
||||
static void Compare(const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> &expected,
|
||||
const std::vector<InferenceEngine::Blob::Ptr> &actual,
|
||||
float threshold);
|
||||
|
||||
static void Compare(const std::vector<std::uint8_t> &expected,
|
||||
static void Compare(const std::pair<ngraph::element::Type, std::vector<std::uint8_t>> &expected,
|
||||
const InferenceEngine::Blob::Ptr &actual,
|
||||
float threshold);
|
||||
|
||||
virtual void Compare(const std::vector<std::vector<std::uint8_t>> &expectedOutputs,
|
||||
virtual void Compare(const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> &expectedOutputs,
|
||||
const std::vector<InferenceEngine::Blob::Ptr> &actualOutputs);
|
||||
|
||||
virtual void Compare(const std::vector<std::uint8_t> &expected, const InferenceEngine::Blob::Ptr &actual);
|
||||
virtual void Compare(const std::pair<ngraph::element::Type, std::vector<std::uint8_t>> &expected, const InferenceEngine::Blob::Ptr &actual);
|
||||
|
||||
virtual void Compare(const InferenceEngine::Blob::Ptr &expected, const InferenceEngine::Blob::Ptr &actual);
|
||||
|
||||
@@ -81,23 +81,27 @@ public:
|
||||
std::string getRuntimePrecision(const std::string& layerName);
|
||||
std::string getRuntimePrecisionByType(const std::string& layerType);
|
||||
|
||||
template<class T>
|
||||
static void Compare(const T *expected, const T *actual, std::size_t size, T threshold) {
|
||||
template<class T_IE, class T_NGRAPH>
|
||||
static void Compare(const T_NGRAPH *expected, const T_IE *actual, std::size_t size, float threshold) {
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
const auto &ref = expected[i];
|
||||
const T_NGRAPH &ref = expected[i];
|
||||
const auto &res = actual[i];
|
||||
const auto absoluteDifference = CommonTestUtils::ie_abs(res - ref);
|
||||
if (absoluteDifference <= threshold) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto max = std::max(CommonTestUtils::ie_abs(res), CommonTestUtils::ie_abs(ref));
|
||||
float diff = static_cast<float>(absoluteDifference) / static_cast<float>(max);
|
||||
double max;
|
||||
if (sizeof(T_IE) < sizeof(T_NGRAPH)) {
|
||||
max = std::max(CommonTestUtils::ie_abs(T_NGRAPH(res)), CommonTestUtils::ie_abs(ref));
|
||||
} else {
|
||||
max = std::max(CommonTestUtils::ie_abs(res), CommonTestUtils::ie_abs(T_IE(ref)));
|
||||
}
|
||||
double diff = static_cast<float>(absoluteDifference) / max;
|
||||
if (max == 0 || (diff > static_cast<float>(threshold)) ||
|
||||
std::isnan(static_cast<float>(res)) || std::isnan(static_cast<float>(ref))) {
|
||||
IE_THROW() << "Relative comparison of values expected: " << ref << " and actual: " << res
|
||||
<< " at index " << i << " with threshold " << threshold
|
||||
<< " failed";
|
||||
<< " at index " << i << " with threshold " << threshold
|
||||
<< " failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,7 +141,7 @@ protected:
|
||||
|
||||
virtual void Validate();
|
||||
|
||||
virtual std::vector<std::vector<std::uint8_t>> CalculateRefs();
|
||||
virtual std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> CalculateRefs();
|
||||
|
||||
virtual std::vector<InferenceEngine::Blob::Ptr> GetOutputs();
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ namespace LayerTestsDefinitions {
|
||||
|
||||
using CompareMap = std::map<ngraph::NodeTypeInfo, std::function<void(
|
||||
const std::shared_ptr<ngraph::Node> node,
|
||||
const std::vector<std::vector<std::uint8_t>>& expected,
|
||||
const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>>& expected,
|
||||
const std::vector<InferenceEngine::Blob::Ptr>& actual,
|
||||
float threshold)>>;
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public:
|
||||
protected:
|
||||
void SetUp() override;
|
||||
void GenerateInputs() override;
|
||||
void Compare(const std::vector<std::vector<std::uint8_t>> &expected,
|
||||
void Compare(const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> &expected,
|
||||
const std::vector<InferenceEngine::Blob::Ptr> &actual) override;
|
||||
std::vector<InferenceEngine::Blob::Ptr> GetOutputs() override;
|
||||
|
||||
|
||||
+2
-1
@@ -63,7 +63,8 @@ class DetectionOutputLayerTest : public testing::WithParamInterface<DetectionOut
|
||||
ngraph::op::DetectionOutputAttrs attrs;
|
||||
std::vector<InferenceEngine::SizeVector> inShapes;
|
||||
void GenerateInputs() override;
|
||||
void Compare(const std::vector<std::uint8_t> &expected, const InferenceEngine::Blob::Ptr &actual) override;
|
||||
void Compare(const std::pair<ngraph::element::Type, std::vector<std::uint8_t>> &expected,
|
||||
const InferenceEngine::Blob::Ptr &actual) override;
|
||||
protected:
|
||||
void SetUp() override;
|
||||
};
|
||||
|
||||
+5
-5
@@ -62,7 +62,7 @@ class StaticShapeLoopTest : public testing::WithParamInterface<StaticShapeLoopPa
|
||||
public:
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<StaticShapeLoopParams> &obj);
|
||||
InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &info) const override;
|
||||
std::vector<std::vector<std::uint8_t>> PredefinedRefs();
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> PredefinedRefs();
|
||||
|
||||
private:
|
||||
bool unrolling; // unroll Loop
|
||||
@@ -106,7 +106,7 @@ protected:
|
||||
return LayerTestsCommon::GenerateInput(info);
|
||||
}
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> CalculateRefs() override {
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> CalculateRefs() override {
|
||||
if (outputGens.empty())
|
||||
return LayerTestsCommon::CalculateRefs();
|
||||
|
||||
@@ -114,7 +114,7 @@ protected:
|
||||
const auto outs_info = cnnNetwork.getOutputsInfo();
|
||||
const auto num_out_blob = results.size();
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> res_collection(num_out_blob);
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> res_collection(num_out_blob);
|
||||
|
||||
for (int i = 0; i < num_out_blob; i++) {
|
||||
// TODO: name of original NG result doesn't match with outs after conversion.
|
||||
@@ -140,8 +140,8 @@ protected:
|
||||
auto blob_ptr = blob->buffer().as<uint8_t*>();
|
||||
|
||||
auto &res = res_collection[i];
|
||||
res.resize(blob_size);
|
||||
std::copy(blob_ptr, blob_ptr + blob_size, res.begin());
|
||||
res.second.resize(blob_size);
|
||||
std::copy(blob_ptr, blob_ptr + blob_size, res.second.begin());
|
||||
}
|
||||
return res_collection;
|
||||
}
|
||||
|
||||
+3
-1
@@ -35,7 +35,9 @@ class NmsLayerTest : public testing::WithParamInterface<NmsParams>, virtual publ
|
||||
public:
|
||||
static std::string getTestCaseName(testing::TestParamInfo<NmsParams> obj);
|
||||
void GenerateInputs() override;
|
||||
void Compare(const std::vector<std::vector<std::uint8_t>> &expectedOutputs, const std::vector<InferenceEngine::Blob::Ptr> &actualOutputs) override;
|
||||
void Compare(const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> &expectedOutputs,
|
||||
const std::vector<InferenceEngine::Blob::Ptr> &actualOutputs)
|
||||
override;
|
||||
|
||||
protected:
|
||||
void SetUp() override;
|
||||
|
||||
+2
-1
@@ -58,7 +58,8 @@ public:
|
||||
static std::string getTestCaseName(testing::TestParamInfo<proposalLayerTestParamsSet> obj);
|
||||
static std::string SerializeProposalSpecificParams(proposalSpecificParams& params);
|
||||
InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &info) const override;
|
||||
void Compare(const std::vector<std::vector<std::uint8_t>> &expectedOutputs, const std::vector<InferenceEngine::Blob::Ptr> &actualOutputs) override;
|
||||
void Compare(const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> &expectedOutputs,
|
||||
const std::vector<InferenceEngine::Blob::Ptr> &actualOutputs) override;
|
||||
template <class T>
|
||||
void Compare(const T *expected, const T *actual, std::size_t size,
|
||||
T threshold, const std::size_t output_index) {
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ protected:
|
||||
std::vector<float> hidden_memory_init;
|
||||
std::vector<float> cell_memory_init;
|
||||
void SetUp() override;
|
||||
std::vector<std::vector<std::uint8_t>> CalculateRefs() override;
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> CalculateRefs() override;
|
||||
};
|
||||
|
||||
} // namespace SubgraphTestsDefinitions
|
||||
+113
-32
@@ -93,7 +93,8 @@ void LayerTestsCommon::Serialize() {
|
||||
InferenceEngine::Blob::Ptr LayerTestsCommon::GenerateInput(const InferenceEngine::InputInfo &info) const {
|
||||
return FuncTestUtils::createAndFillBlob(info.getTensorDesc());
|
||||
}
|
||||
void LayerTestsCommon::Compare(const std::vector<std::vector<std::uint8_t>> &expectedOutputs,
|
||||
|
||||
void LayerTestsCommon::Compare(const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> &expectedOutputs,
|
||||
const std::vector<InferenceEngine::Blob::Ptr> &actualOutputs,
|
||||
float threshold) {
|
||||
for (std::size_t outputIndex = 0; outputIndex < expectedOutputs.size(); ++outputIndex) {
|
||||
@@ -103,67 +104,147 @@ void LayerTestsCommon::Compare(const std::vector<std::vector<std::uint8_t>> &exp
|
||||
}
|
||||
}
|
||||
|
||||
void LayerTestsCommon::Compare(const std::vector<std::uint8_t> &expected,
|
||||
template <typename T_IE>
|
||||
inline void callCompare(const std::pair<ngraph::element::Type, std::vector<std::uint8_t>> &expected,
|
||||
const T_IE* actualBuffer, size_t size, float threshold) {
|
||||
auto expectedBuffer = expected.second.data();
|
||||
switch (expected.first) {
|
||||
case ngraph::element::Type_t::i64:
|
||||
LayerTestsCommon::Compare<T_IE, int64_t>(reinterpret_cast<const int64_t *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::i32:
|
||||
LayerTestsCommon::Compare<T_IE, int32_t>(reinterpret_cast<const int32_t *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::i16:
|
||||
LayerTestsCommon::Compare<T_IE, int16_t>(reinterpret_cast<const int16_t *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::i8:
|
||||
LayerTestsCommon::Compare<T_IE, int8_t>(reinterpret_cast<const int8_t *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::u64:
|
||||
LayerTestsCommon::Compare<T_IE, uint64_t>(reinterpret_cast<const uint64_t *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::u32:
|
||||
LayerTestsCommon::Compare<T_IE, uint32_t>(reinterpret_cast<const uint32_t *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::u16:
|
||||
LayerTestsCommon::Compare<T_IE, uint16_t>(reinterpret_cast<const uint16_t *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::boolean:
|
||||
case ngraph::element::Type_t::u8:
|
||||
LayerTestsCommon::Compare<T_IE, uint8_t>(reinterpret_cast<const uint8_t *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::f64:
|
||||
LayerTestsCommon::Compare<T_IE, double>(reinterpret_cast<const double *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::f32:
|
||||
LayerTestsCommon::Compare<T_IE, float>(reinterpret_cast<const float *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::f16:
|
||||
LayerTestsCommon::Compare<T_IE, ngraph::float16>(reinterpret_cast<const ngraph::float16 *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::bf16:
|
||||
LayerTestsCommon::Compare<T_IE, ngraph::bfloat16>(reinterpret_cast<const ngraph::bfloat16 *>(expectedBuffer),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
case ngraph::element::Type_t::i4: {
|
||||
auto expectedOut = ngraph::helpers::convertOutputPrecision(
|
||||
expected.second,
|
||||
expected.first,
|
||||
ngraph::element::Type_t::i8,
|
||||
size);
|
||||
LayerTestsCommon::Compare<T_IE, int8_t>(reinterpret_cast<const int8_t *>(expectedOut.data()),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
}
|
||||
case ngraph::element::Type_t::u4: {
|
||||
auto expectedOut = ngraph::helpers::convertOutputPrecision(
|
||||
expected.second,
|
||||
expected.first,
|
||||
ngraph::element::Type_t::u8,
|
||||
size);
|
||||
LayerTestsCommon::Compare<T_IE, uint8_t>(reinterpret_cast<const uint8_t *>(expectedOut.data()),
|
||||
actualBuffer, size, threshold);
|
||||
break;
|
||||
}
|
||||
case ngraph::element::Type_t::dynamic:
|
||||
case ngraph::element::Type_t::undefined:
|
||||
LayerTestsCommon::Compare<T_IE, T_IE>(reinterpret_cast<const T_IE *>(expectedBuffer), actualBuffer, size, threshold);
|
||||
break;
|
||||
default: FAIL() << "Comparator for " << expected.first << " precision isn't supported";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void LayerTestsCommon::Compare(const std::pair<ngraph::element::Type, std::vector<std::uint8_t>> &expected,
|
||||
const InferenceEngine::Blob::Ptr &actual,
|
||||
float threshold) {
|
||||
ASSERT_EQ(expected.size(), actual->byteSize());
|
||||
const auto &expectedBuffer = expected.data();
|
||||
const auto &precision = actual->getTensorDesc().getPrecision();
|
||||
auto k = static_cast<float>(expected.first.size()) / precision.size();
|
||||
// W/A for int4, uint4
|
||||
if (expected.first == ngraph::element::Type_t::u4 || expected.first == ngraph::element::Type_t::i4) {
|
||||
k /= 2;
|
||||
} else if (expected.first == ngraph::element::Type_t::undefined || expected.first == ngraph::element::Type_t::dynamic) {
|
||||
k = 1;
|
||||
}
|
||||
ASSERT_EQ(expected.second.size(), actual->byteSize() * k);
|
||||
|
||||
auto memory = InferenceEngine::as<InferenceEngine::MemoryBlob>(actual);
|
||||
IE_ASSERT(memory);
|
||||
const auto lockedMemory = memory->wmap();
|
||||
const auto actualBuffer = lockedMemory.as<const std::uint8_t *>();
|
||||
|
||||
const auto &precision = actual->getTensorDesc().getPrecision();
|
||||
const auto &size = actual->size();
|
||||
switch (precision) {
|
||||
case InferenceEngine::Precision::FP32:
|
||||
Compare<float>(reinterpret_cast<const float *>(expectedBuffer),
|
||||
reinterpret_cast<const float *>(actualBuffer), size, threshold);
|
||||
callCompare<float>(expected, reinterpret_cast<const float *>(actualBuffer), size, threshold);
|
||||
break;
|
||||
case InferenceEngine::Precision::I32:
|
||||
Compare<int32_t>(reinterpret_cast<const int32_t *>(expectedBuffer),
|
||||
reinterpret_cast<const int32_t *>(actualBuffer), size, 0);
|
||||
callCompare<int32_t>(expected, reinterpret_cast<const int32_t *>(actualBuffer), size, threshold);
|
||||
break;
|
||||
case InferenceEngine::Precision::I64:
|
||||
Compare<int64_t>(reinterpret_cast<const int64_t *>(expectedBuffer),
|
||||
reinterpret_cast<const int64_t *>(actualBuffer), size, 0);
|
||||
callCompare<int64_t>(expected, reinterpret_cast<const int64_t *>(actualBuffer), size, threshold);
|
||||
break;
|
||||
case InferenceEngine::Precision::I8:
|
||||
Compare<int8_t>(reinterpret_cast<const int8_t *>(expectedBuffer),
|
||||
reinterpret_cast<const int8_t *>(actualBuffer), size, 0);
|
||||
callCompare<int8_t>(expected, reinterpret_cast<const int8_t *>(actualBuffer), size, threshold);
|
||||
break;
|
||||
case InferenceEngine::Precision::U16:
|
||||
Compare<uint16_t>(reinterpret_cast<const uint16_t *>(expectedBuffer),
|
||||
reinterpret_cast<const uint16_t *>(actualBuffer), size, 0);
|
||||
callCompare<uint16_t>(expected, reinterpret_cast<const uint16_t *>(actualBuffer), size, threshold);
|
||||
break;
|
||||
case InferenceEngine::Precision::I16:
|
||||
Compare<int16_t>(reinterpret_cast<const int16_t *>(expectedBuffer),
|
||||
reinterpret_cast<const int16_t *>(actualBuffer), size, 0);
|
||||
callCompare<int16_t>(expected, reinterpret_cast<const int16_t *>(actualBuffer), size, threshold);
|
||||
break;
|
||||
case InferenceEngine::Precision::BOOL:
|
||||
case InferenceEngine::Precision::U8:
|
||||
Compare<uint8_t>(reinterpret_cast<const uint8_t *>(expectedBuffer),
|
||||
reinterpret_cast<const uint8_t *>(actualBuffer), size, 0);
|
||||
callCompare<uint8_t>(expected, reinterpret_cast<const uint8_t *>(actualBuffer), size, threshold);
|
||||
break;
|
||||
case InferenceEngine::Precision::U64:
|
||||
Compare<uint64_t>(reinterpret_cast<const uint64_t *>(expectedBuffer),
|
||||
reinterpret_cast<const uint64_t *>(actualBuffer), size, 0);
|
||||
callCompare<uint64_t>(expected, reinterpret_cast<const uint64_t *>(actualBuffer), size, threshold);
|
||||
break;
|
||||
case InferenceEngine::Precision::BF16:
|
||||
Compare(reinterpret_cast<const ngraph::bfloat16 *>(expectedBuffer),
|
||||
reinterpret_cast<const ngraph::bfloat16 *>(actualBuffer), size, ngraph::bfloat16(threshold));
|
||||
callCompare<ngraph::bfloat16>(expected, reinterpret_cast<const ngraph::bfloat16 *>(actualBuffer), size, threshold);
|
||||
break;
|
||||
case InferenceEngine::Precision::FP16:
|
||||
Compare(reinterpret_cast<const ngraph::float16 *>(expectedBuffer),
|
||||
reinterpret_cast<const ngraph::float16 *>(actualBuffer), size, ngraph::float16(threshold));
|
||||
callCompare<ngraph::float16>(expected, reinterpret_cast<const ngraph::float16 *>(actualBuffer), size, threshold);
|
||||
break;
|
||||
default:
|
||||
FAIL() << "Comparator for " << precision << " precision isn't supported";
|
||||
}
|
||||
}
|
||||
|
||||
void LayerTestsCommon::Compare(const std::vector<std::uint8_t> &expected, const InferenceEngine::Blob::Ptr &actual) {
|
||||
void LayerTestsCommon::Compare(const std::pair<ngraph::element::Type, std::vector<std::uint8_t>> &expected,
|
||||
const InferenceEngine::Blob::Ptr &actual) {
|
||||
Compare(expected, actual, threshold);
|
||||
}
|
||||
|
||||
@@ -256,14 +337,14 @@ void LayerTestsCommon::Infer() {
|
||||
inferRequest.Infer();
|
||||
}
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> LayerTestsCommon::CalculateRefs() {
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> LayerTestsCommon::CalculateRefs() {
|
||||
// nGraph interpreter does not support f16/bf16
|
||||
ngraph::pass::ConvertPrecision<ngraph::element::Type_t::f16, ngraph::element::Type_t::f32>().run_on_function(function);
|
||||
ngraph::pass::ConvertPrecision<ngraph::element::Type_t::bf16, ngraph::element::Type_t::f32>().run_on_function(function);
|
||||
|
||||
function->validate_nodes_and_infer_types();
|
||||
|
||||
auto referenceInputs = std::vector<std::vector<std::uint8_t>>(inputs.size());
|
||||
auto referenceInputs = std::vector<std::vector<uint8_t>>(inputs.size());
|
||||
auto refInputsTypes = std::vector<ngraph::element::Type>(inputs.size());
|
||||
for (std::size_t i = 0; i < inputs.size(); ++i) {
|
||||
const auto &input = inputs[i];
|
||||
@@ -290,15 +371,15 @@ std::vector<std::vector<std::uint8_t>> LayerTestsCommon::CalculateRefs() {
|
||||
output.second->getTensorDesc().getPrecision()));
|
||||
}
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> expectedOutputs;
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> expectedOutputs;
|
||||
switch (refMode) {
|
||||
case INTERPRETER: {
|
||||
expectedOutputs = ngraph::helpers::interpreterFunction(function, referenceInputs, refInputsTypes, convertType);
|
||||
expectedOutputs = ngraph::helpers::interpreterFunction(function, referenceInputs, refInputsTypes);
|
||||
break;
|
||||
}
|
||||
case CONSTANT_FOLDING: {
|
||||
const auto &foldedFunc = ngraph::helpers::foldFunction(function, referenceInputs, refInputsTypes);
|
||||
expectedOutputs = ngraph::helpers::getConstData(foldedFunc, convertType);
|
||||
expectedOutputs = ngraph::helpers::getConstData(foldedFunc);
|
||||
break;
|
||||
}
|
||||
case IE: {
|
||||
@@ -319,7 +400,7 @@ std::vector<InferenceEngine::Blob::Ptr> LayerTestsCommon::GetOutputs() {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
void LayerTestsCommon::Compare(const std::vector<std::vector<std::uint8_t>> &expectedOutputs,
|
||||
void LayerTestsCommon::Compare(const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> &expectedOutputs,
|
||||
const std::vector<InferenceEngine::Blob::Ptr> &actualOutputs) {
|
||||
Compare(expectedOutputs, actualOutputs, threshold);
|
||||
}
|
||||
|
||||
+110
-64
@@ -11,14 +11,16 @@ namespace LayerTestsDefinitions {
|
||||
|
||||
namespace {
|
||||
void compare(const std::shared_ptr<ngraph::Node> node,
|
||||
const std::vector<std::vector<std::uint8_t>>& expected,
|
||||
const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>>& expected,
|
||||
const std::vector<InferenceEngine::Blob::Ptr>& actual,
|
||||
float threshold) {
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> types(expected.size());
|
||||
auto outputs = node->outputs();
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(expected, actual, threshold);
|
||||
}
|
||||
|
||||
void compare(const std::shared_ptr<ngraph::op::v0::DetectionOutput> node,
|
||||
const std::vector<std::uint8_t>& expected,
|
||||
const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>>& expected,
|
||||
const std::vector<InferenceEngine::Blob::Ptr>& actual,
|
||||
float threshold) {
|
||||
ASSERT_EQ(expected.size(), actual.front()->byteSize());
|
||||
@@ -84,82 +86,48 @@ void Compare(const T *expected, const T *actual, std::size_t size,
|
||||
} // namespace Proposal
|
||||
|
||||
void compare(const std::shared_ptr<ngraph::op::v4::Proposal> node,
|
||||
const std::vector<std::vector<std::uint8_t>>& expectedOutputs,
|
||||
const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>>& expectedOutputs,
|
||||
const std::vector<InferenceEngine::Blob::Ptr>& actualOutputs,
|
||||
float threshold) {
|
||||
size_t num_selected_boxes = 0;
|
||||
for (std::size_t outputIndex = 0; outputIndex < expectedOutputs.size(); ++outputIndex) {
|
||||
const auto &expected = expectedOutputs[outputIndex];
|
||||
const auto &actual = actualOutputs[outputIndex];
|
||||
ASSERT_EQ(expected.size(), actual->byteSize());
|
||||
const auto &expectedBuffer = expected.data();
|
||||
|
||||
auto memory = InferenceEngine::as<InferenceEngine::MemoryBlob>(actual);
|
||||
IE_ASSERT(memory);
|
||||
const auto lockedMemory = memory->rmap();
|
||||
const auto actualBuffer = lockedMemory.as<const std::uint8_t *>();
|
||||
|
||||
const auto &precision = actual->getTensorDesc().getPrecision();
|
||||
auto size = actual->size();
|
||||
|
||||
// verifying the first output if there was less proposals than space
|
||||
// provided,
|
||||
// num_selected_boxes was set, take this into consideration while verifying the 2nd
|
||||
// output
|
||||
if (outputIndex == 1 && num_selected_boxes) {
|
||||
size = num_selected_boxes;
|
||||
}
|
||||
|
||||
switch (precision) {
|
||||
case InferenceEngine::Precision::BF16:
|
||||
Proposal::Compare(
|
||||
reinterpret_cast<const ngraph::bfloat16 *>(expectedBuffer),
|
||||
reinterpret_cast<const ngraph::bfloat16 *>(actualBuffer), size,
|
||||
ngraph::bfloat16(threshold), outputIndex, num_selected_boxes);
|
||||
break;
|
||||
case InferenceEngine::Precision::FP16:
|
||||
Proposal::Compare(
|
||||
reinterpret_cast<const ngraph::float16 *>(expectedBuffer),
|
||||
reinterpret_cast<const ngraph::float16 *>(actualBuffer), size,
|
||||
ngraph::float16(threshold), outputIndex, num_selected_boxes);
|
||||
break;
|
||||
case InferenceEngine::Precision::FP32:
|
||||
Proposal::Compare<float>(
|
||||
reinterpret_cast<const float *>(expectedBuffer),
|
||||
reinterpret_cast<const float *>(actualBuffer), size,
|
||||
threshold, outputIndex, num_selected_boxes);
|
||||
break;
|
||||
default:
|
||||
FAIL() << "Comparator for " << precision << " precision isn't supported";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void compare(const std::shared_ptr<ngraph::op::v5::NonMaxSuppression> node,
|
||||
const std::vector<std::vector<std::uint8_t>>& expectedOutputs,
|
||||
const std::vector<InferenceEngine::Blob::Ptr>& actualOutputs,
|
||||
float threshold) {
|
||||
for (int outputIndex = static_cast<int>(expectedOutputs.size()) - 1; outputIndex >=0 ; outputIndex--) {
|
||||
for (int outputIndex = static_cast<int>(expectedOutputs.size()) - 1; outputIndex >= 0 ; outputIndex--) {
|
||||
const auto& expected = expectedOutputs[outputIndex];
|
||||
const auto& actual = actualOutputs[outputIndex];
|
||||
|
||||
const auto &expectedBuffer = expected.data();
|
||||
const auto &expectedBuffer = expected.second.data();
|
||||
auto memory = InferenceEngine::as<InferenceEngine::MemoryBlob>(actual);
|
||||
IE_ASSERT(memory);
|
||||
const auto lockedMemory = memory->wmap();
|
||||
const auto actualBuffer = lockedMemory.as<const uint8_t *>();
|
||||
|
||||
auto k = static_cast<float>(expected.first.size()) / actual->getTensorDesc().getPrecision().size();
|
||||
// W/A for int4, uint4
|
||||
if (expected.first == ngraph::element::Type_t::u4 || expected.first == ngraph::element::Type_t::i4) {
|
||||
k /= 2;
|
||||
}
|
||||
if (outputIndex == 2) {
|
||||
if (expected.size() != actual->byteSize())
|
||||
if (expected.second.size() != k * actual->byteSize())
|
||||
throw std::runtime_error("Expected and actual size 3rd output have different size");
|
||||
}
|
||||
|
||||
const auto &precision = actual->getTensorDesc().getPrecision();
|
||||
size_t size = expected.size() / actual->getTensorDesc().getPrecision().size();
|
||||
size_t size = expected.second.size() / (k * actual->getTensorDesc().getPrecision().size());
|
||||
switch (precision) {
|
||||
case InferenceEngine::Precision::FP32: {
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const float *>(expectedBuffer), reinterpret_cast<const float *>(actualBuffer), size, threshold);
|
||||
switch (expected.first) {
|
||||
case ngraph::element::Type_t::f32:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const float *>(expectedBuffer),
|
||||
reinterpret_cast<const float *>(actualBuffer), size, 0);
|
||||
break;
|
||||
case ngraph::element::Type_t::f64:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const double *>(expectedBuffer),
|
||||
reinterpret_cast<const float *>(actualBuffer), size, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const auto fBuffer = lockedMemory.as<const float *>();
|
||||
for (int i = size; i < actual->size(); i++) {
|
||||
ASSERT_TRUE(fBuffer[i] == -1.f) << "Invalid default value: " << fBuffer[i] << " at index: " << i;
|
||||
@@ -167,8 +135,86 @@ void compare(const std::shared_ptr<ngraph::op::v5::NonMaxSuppression> node,
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::I32: {
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const int32_t *>(expectedBuffer), reinterpret_cast<const int32_t *>(actualBuffer), size, 0);
|
||||
switch (expected.first) {
|
||||
case ngraph::element::Type_t::i32:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const int32_t *>(expectedBuffer),
|
||||
reinterpret_cast<const int32_t *>(actualBuffer), size, 0);
|
||||
break;
|
||||
case ngraph::element::Type_t::i64:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const int64_t *>(expectedBuffer),
|
||||
reinterpret_cast<const int32_t *>(actualBuffer), size, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const auto iBuffer = lockedMemory.as<const int *>();
|
||||
for (int i = size; i < actual->size(); i++) {
|
||||
ASSERT_TRUE(iBuffer[i] == -1) << "Invalid default value: " << iBuffer[i] << " at index: " << i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
FAIL() << "Comparator for " << precision << " precision isn't supported";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void compare(const std::shared_ptr<ngraph::op::v5::NonMaxSuppression> node,
|
||||
const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>>& expectedOutputs,
|
||||
const std::vector<InferenceEngine::Blob::Ptr>& actualOutputs,
|
||||
float threshold) {
|
||||
for (int outputIndex = static_cast<int>(expectedOutputs.size()) - 1; outputIndex >= 0 ; outputIndex--) {
|
||||
const auto& expected = expectedOutputs[outputIndex];
|
||||
const auto& actual = actualOutputs[outputIndex];
|
||||
|
||||
const auto &expectedBuffer = expected.second.data();
|
||||
auto memory = InferenceEngine::as<InferenceEngine::MemoryBlob>(actual);
|
||||
IE_ASSERT(memory);
|
||||
const auto lockedMemory = memory->wmap();
|
||||
const auto actualBuffer = lockedMemory.as<const uint8_t *>();
|
||||
|
||||
const auto &precision = actual->getTensorDesc().getPrecision();
|
||||
size_t size = expected.second.size() / (actual->getTensorDesc().getPrecision().size());
|
||||
switch (precision) {
|
||||
case InferenceEngine::Precision::FP32: {
|
||||
switch (expected.first) {
|
||||
case ngraph::element::Type_t::f32:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const float *>(expectedBuffer),
|
||||
reinterpret_cast<const float *>(actualBuffer), size, 0);
|
||||
break;
|
||||
case ngraph::element::Type_t::f64:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const double *>(expectedBuffer),
|
||||
reinterpret_cast<const float *>(actualBuffer), size, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const auto fBuffer = lockedMemory.as<const float *>();
|
||||
for (int i = size; i < actual->size(); i++) {
|
||||
ASSERT_TRUE(fBuffer[i] == -1.f) << "Invalid default value: " << fBuffer[i] << " at index: " << i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::I32: {
|
||||
switch (expected.first) {
|
||||
case ngraph::element::Type_t::i32:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const int32_t *>(expectedBuffer),
|
||||
reinterpret_cast<const int32_t *>(actualBuffer), size, 0);
|
||||
break;
|
||||
case ngraph::element::Type_t::i64:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const int64_t *>(expectedBuffer),
|
||||
reinterpret_cast<const int32_t *>(actualBuffer), size, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const auto iBuffer = lockedMemory.as<const int *>();
|
||||
for (int i = size; i < actual->size(); i++) {
|
||||
ASSERT_TRUE(iBuffer[i] == -1) << "Invalid default value: " << iBuffer[i] << " at index: " << i;
|
||||
@@ -183,7 +229,7 @@ void compare(const std::shared_ptr<ngraph::op::v5::NonMaxSuppression> node,
|
||||
|
||||
template<typename T>
|
||||
void compareResults(const std::shared_ptr<ngraph::Node> node,
|
||||
const std::vector<std::vector<std::uint8_t>>& expected,
|
||||
const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>>& expected,
|
||||
const std::vector<InferenceEngine::Blob::Ptr>& actual,
|
||||
float threshold) {
|
||||
return compare(ngraph::as_type_ptr<T>(node), expected, actual, threshold);
|
||||
|
||||
@@ -99,7 +99,7 @@ void ReadIRTest::GenerateInputs() {
|
||||
}
|
||||
}
|
||||
|
||||
void ReadIRTest::Compare(const std::vector<std::vector<std::uint8_t>> &expected,
|
||||
void ReadIRTest::Compare(const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> &expected,
|
||||
const std::vector<InferenceEngine::Blob::Ptr> &actual) {
|
||||
auto compareMap = getCompareMap();
|
||||
for (const auto &result : function->get_results()) {
|
||||
|
||||
+5
-3
@@ -90,13 +90,15 @@ void DetectionOutputLayerTest::GenerateInputs() {
|
||||
}
|
||||
}
|
||||
|
||||
void DetectionOutputLayerTest::Compare(const std::vector<std::uint8_t> &expected, const InferenceEngine::Blob::Ptr &actual) {
|
||||
ASSERT_EQ(expected.size(), actual->byteSize());
|
||||
void DetectionOutputLayerTest::Compare(
|
||||
const std::pair<ngraph::element::Type, std::vector<std::uint8_t>> &expected,
|
||||
const InferenceEngine::Blob::Ptr &actual) {
|
||||
ASSERT_EQ(expected.second.size(), actual->byteSize());
|
||||
|
||||
size_t expSize = 0;
|
||||
size_t actSize = 0;
|
||||
|
||||
const auto &expectedBuffer = expected.data();
|
||||
const auto &expectedBuffer = expected.second.data();
|
||||
auto memory = InferenceEngine::as<InferenceEngine::MemoryBlob>(actual);
|
||||
IE_ASSERT(memory);
|
||||
const auto lockedMemory = memory->wmap();
|
||||
|
||||
@@ -246,7 +246,7 @@ namespace LayerTestsDefinitions {
|
||||
}
|
||||
|
||||
// Predefined ref output
|
||||
std::vector<std::vector<std::uint8_t>> StaticShapeLoopTest::PredefinedRefs() {
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> StaticShapeLoopTest::PredefinedRefs() {
|
||||
bool auto_concat_out = (axis != -1);
|
||||
const auto n_iter = actual_n_iter();
|
||||
|
||||
@@ -256,8 +256,10 @@ namespace LayerTestsDefinitions {
|
||||
|
||||
using namespace CommonTestUtils;
|
||||
InferenceEngine::TensorDesc tdesc {data_prc, ref_shape, InferenceEngine::TensorDesc::getLayoutByDims(ref_shape)};
|
||||
std::vector<uint8_t> res(byte_size(tdesc));
|
||||
auto out = make_blob_with_precision(tdesc, res.data());
|
||||
std::pair<ngraph::element::Type, std::vector<uint8_t>> res;
|
||||
res.first = function->get_result()->get_element_type();
|
||||
res.second = std::vector<uint8_t>(byte_size(tdesc));
|
||||
auto out = make_blob_with_precision(tdesc, res.second.data());
|
||||
|
||||
std::vector<float> vals(n_iter);
|
||||
float val = start_value;
|
||||
|
||||
+43
-10
@@ -55,35 +55,68 @@ void NmsLayerTest::GenerateInputs() {
|
||||
}
|
||||
}
|
||||
|
||||
void NmsLayerTest::Compare(const std::vector<std::vector<std::uint8_t>> &expectedOutputs, const std::vector<Blob::Ptr> &actualOutputs) {
|
||||
for (int outputIndex = static_cast<int>(expectedOutputs.size()) - 1; outputIndex >=0 ; outputIndex--) {
|
||||
void NmsLayerTest::Compare(const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> &expectedOutputs,
|
||||
const std::vector<Blob::Ptr> &actualOutputs) {
|
||||
for (int outputIndex = static_cast<int>(expectedOutputs.size()) - 1; outputIndex >= 0 ; outputIndex--) {
|
||||
const auto& expected = expectedOutputs[outputIndex];
|
||||
const auto& actual = actualOutputs[outputIndex];
|
||||
|
||||
const auto &expectedBuffer = expected.data();
|
||||
auto memory = as<MemoryBlob>(actual);
|
||||
const auto &expectedBuffer = expected.second.data();
|
||||
auto memory = InferenceEngine::as<InferenceEngine::MemoryBlob>(actual);
|
||||
IE_ASSERT(memory);
|
||||
const auto lockedMemory = memory->wmap();
|
||||
const auto actualBuffer = lockedMemory.as<const uint8_t *>();
|
||||
|
||||
auto k = static_cast<float>(expected.first.size()) / actual->getTensorDesc().getPrecision().size();
|
||||
// W/A for int4, uint4
|
||||
if (expected.first == ngraph::element::Type_t::u4 || expected.first == ngraph::element::Type_t::i4) {
|
||||
k /= 2;
|
||||
}
|
||||
if (outputIndex == 2) {
|
||||
if (expected.size() != actual->byteSize())
|
||||
if (expected.second.size() != k * actual->byteSize())
|
||||
throw std::runtime_error("Expected and actual size 3rd output have different size");
|
||||
}
|
||||
|
||||
const auto &precision = actual->getTensorDesc().getPrecision();
|
||||
size_t size = expected.size() / actual->getTensorDesc().getPrecision().size();
|
||||
size_t size = expected.second.size() / (k * actual->getTensorDesc().getPrecision().size());
|
||||
switch (precision) {
|
||||
case Precision::FP32: {
|
||||
LayerTestsCommon::Compare(reinterpret_cast<const float *>(expectedBuffer), reinterpret_cast<const float *>(actualBuffer), size, threshold);
|
||||
case InferenceEngine::Precision::FP32: {
|
||||
switch (expected.first) {
|
||||
case ngraph::element::Type_t::f32:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const float *>(expectedBuffer),
|
||||
reinterpret_cast<const float *>(actualBuffer), size, 0);
|
||||
break;
|
||||
case ngraph::element::Type_t::f64:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const double *>(expectedBuffer),
|
||||
reinterpret_cast<const float *>(actualBuffer), size, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const auto fBuffer = lockedMemory.as<const float *>();
|
||||
for (int i = size; i < actual->size(); i++) {
|
||||
ASSERT_TRUE(fBuffer[i] == -1.f) << "Invalid default value: " << fBuffer[i] << " at index: " << i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Precision::I32: {
|
||||
LayerTestsCommon::Compare(reinterpret_cast<const int32_t *>(expectedBuffer), reinterpret_cast<const int32_t *>(actualBuffer), size, 0);
|
||||
case InferenceEngine::Precision::I32: {
|
||||
switch (expected.first) {
|
||||
case ngraph::element::Type_t::i32:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const int32_t *>(expectedBuffer),
|
||||
reinterpret_cast<const int32_t *>(actualBuffer), size, 0);
|
||||
break;
|
||||
case ngraph::element::Type_t::i64:
|
||||
LayerTestsUtils::LayerTestsCommon::Compare(
|
||||
reinterpret_cast<const int64_t *>(expectedBuffer),
|
||||
reinterpret_cast<const int32_t *>(actualBuffer), size, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const auto iBuffer = lockedMemory.as<const int *>();
|
||||
for (int i = size; i < actual->size(); i++) {
|
||||
ASSERT_TRUE(iBuffer[i] == -1) << "Invalid default value: " << iBuffer[i] << " at index: " << i;
|
||||
|
||||
@@ -21,7 +21,6 @@ std::string NonZeroLayerTest::getTestCaseName(testing::TestParamInfo<NonZeroLaye
|
||||
}
|
||||
|
||||
void NonZeroLayerTest::SetUp() {
|
||||
SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
|
||||
auto inputShape = std::vector<std::size_t>{};
|
||||
auto inputPrecision = InferenceEngine::Precision::UNSPECIFIED;
|
||||
ConfigMap additionalConfig;
|
||||
|
||||
-1
@@ -56,7 +56,6 @@ std::string PriorBoxClusteredLayerTest::getTestCaseName(const testing::TestParam
|
||||
}
|
||||
|
||||
void PriorBoxClusteredLayerTest::SetUp() {
|
||||
SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
|
||||
priorBoxClusteredSpecificParams specParams;
|
||||
std::tie(specParams, netPrecision,
|
||||
inPrc, outPrc, inLayout, outLayout,
|
||||
|
||||
@@ -64,11 +64,11 @@ std::string ProposalLayerTest::getTestCaseName(testing::TestParamInfo<proposalLa
|
||||
}
|
||||
|
||||
void ProposalLayerTest::Compare(
|
||||
const std::vector<std::vector<std::uint8_t>> &expectedOutputs,
|
||||
const std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> &expectedOutputs,
|
||||
const std::vector<InferenceEngine::Blob::Ptr> &actualOutputs) {
|
||||
num_selected_boxes = 0;
|
||||
for (std::size_t outputIndex = 0; outputIndex < expectedOutputs.size(); ++outputIndex) {
|
||||
const auto &expected = expectedOutputs[outputIndex];
|
||||
const auto &expected = expectedOutputs[outputIndex].second;
|
||||
const auto &actual = actualOutputs[outputIndex];
|
||||
ASSERT_EQ(expected.size(), actual->byteSize());
|
||||
const auto &expectedBuffer = expected.data();
|
||||
|
||||
@@ -33,7 +33,6 @@ std::string SplitLayerTest::getTestCaseName(testing::TestParamInfo<splitParams>
|
||||
}
|
||||
|
||||
void SplitLayerTest::SetUp() {
|
||||
SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
|
||||
size_t axis, numSplits;
|
||||
std::vector<size_t> inputShape, outIndices;
|
||||
InferenceEngine::Precision netPrecision;
|
||||
|
||||
@@ -26,7 +26,6 @@ std::string TransposeLayerTest::getTestCaseName(testing::TestParamInfo<transpose
|
||||
}
|
||||
|
||||
void TransposeLayerTest::SetUp() {
|
||||
SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
|
||||
std::vector<size_t> inputShape, inputOrder;
|
||||
InferenceEngine::Precision netPrecision;
|
||||
std::tie(inputOrder, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShape, targetDevice) = this->GetParam();
|
||||
|
||||
-1
@@ -30,7 +30,6 @@ namespace LayerTestsDefinitions {
|
||||
}
|
||||
|
||||
void VariadicSplitLayerTest::SetUp() {
|
||||
SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
|
||||
size_t axis;
|
||||
std::vector<size_t> inputShape, numSplits;
|
||||
InferenceEngine::Precision netPrecision;
|
||||
|
||||
@@ -114,7 +114,7 @@ void Basic_LSTM_S::Run() {
|
||||
Compare(referenceOutputs, actualOutputs);
|
||||
}
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> Basic_LSTM_S::CalculateRefs() {
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> Basic_LSTM_S::CalculateRefs() {
|
||||
//For now TensorIterator is not implemented in ngraph interpreter so it is needed to validate with another reference
|
||||
auto reference_model = ngraph::clone_function(*function);
|
||||
ngraph::pass::Manager manager;
|
||||
@@ -146,12 +146,13 @@ std::vector<std::vector<std::uint8_t>> Basic_LSTM_S::CalculateRefs() {
|
||||
refOutputs.push_back(refInferRequest.GetBlob(name));
|
||||
}
|
||||
|
||||
auto referenceOutputs = std::vector<std::vector<std::uint8_t>>(refOutputs.size());
|
||||
auto referenceOutputs = std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>>(refOutputs.size());
|
||||
for (std::size_t i = 0; i < refOutputs.size(); ++i) {
|
||||
const auto& reference = refOutputs[i];
|
||||
const auto refSize = reference->byteSize();
|
||||
|
||||
auto& expectedOutput = referenceOutputs[i];
|
||||
referenceOutputs[i].first = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(reference->getTensorDesc().getPrecision());
|
||||
auto& expectedOutput = referenceOutputs[i].second;
|
||||
expectedOutput.resize(refSize);
|
||||
|
||||
auto refMemory = InferenceEngine::as<InferenceEngine::MemoryBlob>(reference);
|
||||
|
||||
+5
-6
@@ -247,10 +247,10 @@ inline ngraph::NodeVector castOps2Nodes(const std::vector<std::shared_ptr<opType
|
||||
return nodes;
|
||||
}
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> interpreterFunction(const std::shared_ptr<Function> &function,
|
||||
const std::vector<std::vector<std::uint8_t>> &inputs,
|
||||
const std::vector<ngraph::element::Type> &inputTypes = {},
|
||||
const std::vector<ngraph::element::Type_t> convertType = {});
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>>
|
||||
interpreterFunction(const std::shared_ptr<Function> &function,
|
||||
const std::vector<std::vector<std::uint8_t>> &inputs,
|
||||
const std::vector<ngraph::element::Type> &inputTypes = {});
|
||||
|
||||
//
|
||||
// This function compares two nGraph functions and requires them to have exactly one output
|
||||
@@ -265,8 +265,7 @@ std::shared_ptr<Function> foldFunction(const std::shared_ptr<Function> &function
|
||||
const std::vector<std::vector<std::uint8_t>> &inputs,
|
||||
const std::vector<ngraph::element::Type> &inputTypes = {});
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> getConstData(const std::shared_ptr<Function> &function,
|
||||
std::vector<ngraph::element::Type_t> convertType = {});
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> getConstData(const std::shared_ptr<Function> &function);
|
||||
|
||||
std::shared_ptr<ngraph::Node> getNodeSharedPtr(const ngraph::NodeTypeInfo &type_info,
|
||||
const ngraph::OutputVector &outputVector);
|
||||
|
||||
+16
-20
@@ -79,10 +79,10 @@ OutputVector convert2OutputVector(const std::vector<std::shared_ptr<Node>> &node
|
||||
return outs;
|
||||
}
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> interpreterFunction(const std::shared_ptr<Function> &function,
|
||||
const std::vector<std::vector<std::uint8_t>> &inputs,
|
||||
const std::vector<ngraph::element::Type> &inputTypes,
|
||||
const std::vector<ngraph::element::Type_t> convertType) {
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>>
|
||||
interpreterFunction(const std::shared_ptr<Function> &function,
|
||||
const std::vector<std::vector<std::uint8_t>> &inputs,
|
||||
const std::vector<ngraph::element::Type> &inputTypes) {
|
||||
runtime::Backend::set_backend_shared_library_search_directory("");
|
||||
auto backend = runtime::Backend::create("INTERPRETER");
|
||||
|
||||
@@ -132,19 +132,13 @@ std::vector<std::vector<std::uint8_t>> interpreterFunction(const std::shared_ptr
|
||||
|
||||
auto handle = backend->compile(function);
|
||||
handle->call_with_validate(outputTensors, inputTensors);
|
||||
auto outputs = std::vector<std::vector<std::uint8_t>>(results.size());
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> outputs(results.size());
|
||||
for (size_t resultIndex = 0; resultIndex < results.size(); resultIndex++) {
|
||||
auto& output = outputs[resultIndex];
|
||||
output.first = results[resultIndex]->get_element_type();
|
||||
const auto& outputTensor = outputTensors[resultIndex];
|
||||
output.resize(ceil(shape_size(outputTensor->get_shape()) * outputTensor->get_element_type().bitwidth() / 8.f));
|
||||
outputTensors[resultIndex]->read(output.data(), output.size());
|
||||
if (!convertType.empty() && convertType[resultIndex] != element::Type_t::undefined &&
|
||||
outputTensor->get_element_type() != element::Type(convertType[resultIndex]))
|
||||
output = convertOutputPrecision(
|
||||
output,
|
||||
outputTensor->get_element_type(),
|
||||
convertType[resultIndex],
|
||||
shape_size(outputTensors[resultIndex]->get_shape()));
|
||||
output.second.resize(ceil(shape_size(outputTensor->get_shape()) * outputTensor->get_element_type().bitwidth() / 8.f));
|
||||
outputTensors[resultIndex]->read(output.second.data(), output.second.size());
|
||||
}
|
||||
|
||||
return outputs;
|
||||
@@ -203,10 +197,12 @@ std::shared_ptr<Function> foldFunction(const std::shared_ptr<Function> &function
|
||||
return foldedFunc;
|
||||
}
|
||||
|
||||
std::vector<std::vector<std::uint8_t>> getConstData(const std::shared_ptr<Function> &function, std::vector<ngraph::element::Type_t> convertType) {
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> getConstData(const std::shared_ptr<Function> &function) {
|
||||
size_t numOutputs = function->get_output_size();
|
||||
auto outputs = std::vector<std::vector<std::uint8_t>>(numOutputs);
|
||||
std::vector<std::pair<ngraph::element::Type, std::vector<std::uint8_t>>> outputs(numOutputs);
|
||||
auto funcResults = function->get_results();
|
||||
for (size_t i = 0; i < numOutputs; i++) {
|
||||
outputs[i].first = funcResults[i]->get_element_type();
|
||||
const auto &output = function->output(i).get_node_shared_ptr();
|
||||
NGRAPH_CHECK(output->inputs().size() == 1);
|
||||
auto parrentNode = output->input_value(0).get_node_shared_ptr();
|
||||
@@ -215,10 +211,8 @@ std::vector<std::vector<std::uint8_t>> getConstData(const std::shared_ptr<Functi
|
||||
|
||||
const auto data = std::dynamic_pointer_cast<opset1::Constant>(parrentNode)->get_data_ptr<std::uint8_t>();
|
||||
const auto dataSize = shape_size(parrentNode->get_shape()) * parrentNode->get_element_type().size();
|
||||
outputs[i].resize(dataSize);
|
||||
std::copy(data, data + dataSize, outputs[i].data());
|
||||
if (!convertType.empty() && convertType[i] != element::Type_t::undefined && parrentNode->get_element_type() != element::Type(convertType[i]))
|
||||
outputs[i] = convertOutputPrecision(outputs[i], parrentNode->get_element_type(), convertType[i], shape_size(parrentNode->get_shape()));
|
||||
outputs[i].second.resize(dataSize);
|
||||
std::copy(data, data + dataSize, outputs[i].second.data());
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
@@ -233,6 +227,8 @@ void CompareShapes(const PartialShape& actual, const PartialShape& expected) {
|
||||
NGRAPH_CHECK(actual.relaxes(expected) && actual.refines(expected), "Functions compare: Different shape detected ", actual, " and ", expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CompareNodes(const Node& actual, const Node& expected) {
|
||||
const auto& actualType = actual.get_type_info();
|
||||
const auto& expectedType = expected.get_type_info();
|
||||
|
||||
@@ -1470,7 +1470,6 @@ namespace
|
||||
break;
|
||||
default: return false;
|
||||
}
|
||||
#undef REF_CALL
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user