From 66c8df6a87648d7e964ab3c411bdc503a6a23c42 Mon Sep 17 00:00:00 2001 From: Denis Orlov Date: Thu, 11 Jun 2020 20:04:46 +0300 Subject: [PATCH] [GNA] Fixes in checks, asserts, etc. (#867) --- inference-engine/src/gna_plugin/backend/am_intel_dnn.cpp | 1 + inference-engine/src/gna_plugin/gna2_model_debug_log.cpp | 2 ++ inference-engine/src/gna_plugin/gna2_model_helper.cpp | 6 ++++++ inference-engine/src/gna_plugin/gna_graph_compiler.cpp | 1 + inference-engine/src/gna_plugin/gna_model_serial.cpp | 2 ++ inference-engine/src/gna_plugin/gna_plugin_config.cpp | 2 +- inference-engine/src/gna_plugin/layers/gna_layer_info.hpp | 1 + inference-engine/src/gna_plugin/layers/gna_permute.hpp | 1 - 8 files changed, 14 insertions(+), 2 deletions(-) diff --git a/inference-engine/src/gna_plugin/backend/am_intel_dnn.cpp b/inference-engine/src/gna_plugin/backend/am_intel_dnn.cpp index 49fcb03d330..a099f6bcdcf 100644 --- a/inference-engine/src/gna_plugin/backend/am_intel_dnn.cpp +++ b/inference-engine/src/gna_plugin/backend/am_intel_dnn.cpp @@ -1524,6 +1524,7 @@ void GNAPluginNS::backend::AMIntelDNN::InitGNAStruct(intel_nnet_type_t *ptr_nnet THROW_GNA_EXCEPTION << "Encountered activation component before pooling component at." << i; } else { const auto poolMode = reinterpret_cast(gnaUserAllocator(sizeof(Gna2PoolingMode))); + IE_ASSERT(poolMode != nullptr); *poolMode = (comp.op.maxpool.do_sum_not_max) ? Gna2PoolingModeSum : Gna2PoolingModeMax; const auto poolWindow = create_shape1D_parameter(comp.op.maxpool.num_inputs); const auto poolStride = create_shape1D_parameter(comp.op.maxpool.num_inputs_step); diff --git a/inference-engine/src/gna_plugin/gna2_model_debug_log.cpp b/inference-engine/src/gna_plugin/gna2_model_debug_log.cpp index 77fba011335..175ccc01f45 100644 --- a/inference-engine/src/gna_plugin/gna2_model_debug_log.cpp +++ b/inference-engine/src/gna_plugin/gna2_model_debug_log.cpp @@ -9,6 +9,7 @@ #if GNA_LIB_VER == 2 #include "gna2_model_debug_log.hpp" #include "gna2-model-api.h" +#include
#include #include @@ -52,6 +53,7 @@ template bool NextElement(T & elementIndex, const Gna2Shape& total) { if (total.NumberOfDimensions == 0) return false; auto idx = total.NumberOfDimensions - 1; + IE_ASSERT(idx < GNA2_SHAPE_MAXIMUM_NUMBER_OF_DIMENSIONS); while (elementIndex[idx] + 1 >= total.Dimensions[idx] && idx > 0) { idx--; } diff --git a/inference-engine/src/gna_plugin/gna2_model_helper.cpp b/inference-engine/src/gna_plugin/gna2_model_helper.cpp index 93979624735..b09a1e7700c 100644 --- a/inference-engine/src/gna_plugin/gna2_model_helper.cpp +++ b/inference-engine/src/gna_plugin/gna2_model_helper.cpp @@ -60,6 +60,7 @@ Gna2Tensor HelperGna2TensorInit3D(uint32_t x, uint32_t y, uint32_t z, Gna2DataTy Gna2Tensor * createGna2Tensor1D(uint32_t x, uint32_t byteSize, void* data) { const auto input = reinterpret_cast(gnaUserAllocator(sizeof(Gna2Tensor))); + IE_ASSERT(input != nullptr); *input = HelperGna2TensorInit1D(x, Gna2DataTypeFromBytes(byteSize), data); return input; } @@ -74,6 +75,7 @@ Gna2Tensor * createGna2TensorPwl(uint32_t x, void* data) { Gna2Tensor * createGna2BiasTensor1D(uint32_t x, uint32_t byteSize, void* data) { const auto input = reinterpret_cast(gnaUserAllocator(sizeof(Gna2Tensor))); + IE_ASSERT(input != nullptr); if (byteSize == 8) { *input = HelperGna2TensorInit1D(x, Gna2DataTypeCompoundBias, data); } else { @@ -84,24 +86,28 @@ Gna2Tensor * createGna2BiasTensor1D(uint32_t x, uint32_t byteSize, void* data) { Gna2Tensor * createGna2Tensor2D(uint32_t x, uint32_t y, uint32_t byteSize, void* data) { const auto input = reinterpret_cast(gnaUserAllocator(sizeof(Gna2Tensor))); + IE_ASSERT(input != nullptr); *input = HelperGna2TensorInit2D(x, y, Gna2DataTypeFromBytes(byteSize), data); return input; } Gna2Tensor * createGna2Tensor3D(uint32_t x, uint32_t y, uint32_t z, uint32_t byteSize, void* data) { const auto input = reinterpret_cast(gnaUserAllocator(sizeof(Gna2Tensor))); + IE_ASSERT(input != nullptr); *input = HelperGna2TensorInit3D(x, y, z, Gna2DataTypeFromBytes(byteSize), data); return input; } uint32_t* create_uint32_parameter(uint32_t value) { const auto param = reinterpret_cast(gnaUserAllocator(sizeof(uint32_t))); + IE_ASSERT(param != nullptr); *param = value; return param; } Gna2Shape* create_shape1D_parameter(uint32_t x) { const auto shp = reinterpret_cast(gnaUserAllocator(sizeof(Gna2Shape))); + IE_ASSERT(shp != nullptr); shp->NumberOfDimensions = 1; shp->Dimensions[0] = x; return shp; diff --git a/inference-engine/src/gna_plugin/gna_graph_compiler.cpp b/inference-engine/src/gna_plugin/gna_graph_compiler.cpp index ef0649d061d..0e352efca7e 100644 --- a/inference-engine/src/gna_plugin/gna_graph_compiler.cpp +++ b/inference-engine/src/gna_plugin/gna_graph_compiler.cpp @@ -1417,6 +1417,7 @@ void GNAGraphCompiler::PermutePrimitive(InferenceEngine::CNNLayerPtr layer) { } auto layerOrder = layer->GetParamAsInts("order"); auto quantized = InferenceEngine::getInjectedData(layer); + IE_ASSERT(!layer->insData.empty()); auto inputs = layer->insData.begin()->lock(); auto inputsOrder = inputs->getTensorDesc().getDims(); auto outputs = layer->outData.front(); diff --git a/inference-engine/src/gna_plugin/gna_model_serial.cpp b/inference-engine/src/gna_plugin/gna_model_serial.cpp index 74f3af1125e..cad6b955c4c 100644 --- a/inference-engine/src/gna_plugin/gna_model_serial.cpp +++ b/inference-engine/src/gna_plugin/gna_model_serial.cpp @@ -128,6 +128,7 @@ void GNAModelSerial::Import(void *basePointer, size_t gnaGraphSize, std::istream readNBits<32>(operation->Type, is); readBits(operation->NumberOfOperands, is); operation->Operands = static_cast(gnaUserAllocator(sizeof(Gna2Tensor*) * operation->NumberOfOperands)); + IE_ASSERT(operation->Operands != nullptr); for (uint32_t i = 0; i < operation->NumberOfOperands; i++) { Gna2Tensor t{}; readBits(t, is); @@ -161,6 +162,7 @@ void GNAModelSerial::Import(void *basePointer, size_t gnaGraphSize, std::istream uint32_t paramSize; readBits(paramSize, is); if (paramSize == 0) { + IE_ASSERT(operation->Parameters != nullptr); operation->Parameters[i] = nullptr; continue; } diff --git a/inference-engine/src/gna_plugin/gna_plugin_config.cpp b/inference-engine/src/gna_plugin/gna_plugin_config.cpp index 163b2f1e6e9..2d43588af52 100644 --- a/inference-engine/src/gna_plugin/gna_plugin_config.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin_config.cpp @@ -71,7 +71,7 @@ void Config::UpdateFromMap(const std::map& config) { key.erase(0, 1); try { input_index = std::stoi(key); - if (input_index < 0 | input_index > 99) { + if (input_index > 99) { throw std::out_of_range(""); } } catch (std::invalid_argument&) { diff --git a/inference-engine/src/gna_plugin/layers/gna_layer_info.hpp b/inference-engine/src/gna_plugin/layers/gna_layer_info.hpp index 4c665ebdb7f..9748a6e4f3b 100644 --- a/inference-engine/src/gna_plugin/layers/gna_layer_info.hpp +++ b/inference-engine/src/gna_plugin/layers/gna_layer_info.hpp @@ -204,6 +204,7 @@ class LayerInfo { if (layerOrder == std::vector({ 0, 3, 2, 1 })) { return true; // supported case } + IE_ASSERT(!layer->insData.empty()); auto inputs = layer->insData.begin()->lock(); auto inputsOrder = inputs->getTensorDesc().getDims(); diff --git a/inference-engine/src/gna_plugin/layers/gna_permute.hpp b/inference-engine/src/gna_plugin/layers/gna_permute.hpp index 609b7edef80..f70e12edb22 100644 --- a/inference-engine/src/gna_plugin/layers/gna_permute.hpp +++ b/inference-engine/src/gna_plugin/layers/gna_permute.hpp @@ -40,7 +40,6 @@ public: // length of current cycle std::list permuteCycles; - int seqId = 0; bool newSeq = false; for (int i = 0; i != orderVec.size();) {