[GNA] Fixes in checks, asserts, etc. (#867)

This commit is contained in:
Denis Orlov
2020-06-11 20:04:46 +03:00
committed by GitHub
parent e53eb86334
commit 66c8df6a87
8 changed files with 14 additions and 2 deletions

View File

@@ -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<Gna2PoolingMode*>(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);

View File

@@ -9,6 +9,7 @@
#if GNA_LIB_VER == 2
#include "gna2_model_debug_log.hpp"
#include "gna2-model-api.h"
#include <details/ie_exception.hpp>
#include <cstdint>
#include <fstream>
@@ -52,6 +53,7 @@ template <class T>
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--;
}

View File

@@ -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<Gna2Tensor*>(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<Gna2Tensor*>(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<Gna2Tensor*>(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<Gna2Tensor*>(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<uint32_t*>(gnaUserAllocator(sizeof(uint32_t)));
IE_ASSERT(param != nullptr);
*param = value;
return param;
}
Gna2Shape* create_shape1D_parameter(uint32_t x) {
const auto shp = reinterpret_cast<Gna2Shape*>(gnaUserAllocator(sizeof(Gna2Shape)));
IE_ASSERT(shp != nullptr);
shp->NumberOfDimensions = 1;
shp->Dimensions[0] = x;
return shp;

View File

@@ -1417,6 +1417,7 @@ void GNAGraphCompiler::PermutePrimitive(InferenceEngine::CNNLayerPtr layer) {
}
auto layerOrder = layer->GetParamAsInts("order");
auto quantized = InferenceEngine::getInjectedData<QuantizedLayerParams>(layer);
IE_ASSERT(!layer->insData.empty());
auto inputs = layer->insData.begin()->lock();
auto inputsOrder = inputs->getTensorDesc().getDims();
auto outputs = layer->outData.front();

View File

@@ -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<Gna2Tensor const **>(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;
}

View File

@@ -71,7 +71,7 @@ void Config::UpdateFromMap(const std::map<std::string, std::string>& 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&) {

View File

@@ -204,6 +204,7 @@ class LayerInfo {
if (layerOrder == std::vector<int>({ 0, 3, 2, 1 })) {
return true; // supported case
}
IE_ASSERT(!layer->insData.empty());
auto inputs = layer->insData.begin()->lock();
auto inputsOrder = inputs->getTensorDesc().getDims();

View File

@@ -40,7 +40,6 @@ public:
// length of current cycle
std::list<cnt_type> permuteCycles;
int seqId = 0;
bool newSeq = false;
for (int i = 0; i != orderVec.size();) {