Skip to content

Commit

Permalink
[GNA] Fixes in checks, asserts, etc. (openvinotoolkit#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
dorloff authored Aug 11, 2020
1 parent 3c9fc72 commit 8c122f4
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions inference-engine/src/gna_plugin/backend/am_intel_dnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,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);
Expand Down
2 changes: 2 additions & 0 deletions inference-engine/src/gna_plugin/gna2_model_debug_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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--;
}
Expand Down
6 changes: 6 additions & 0 deletions inference-engine/src/gna_plugin/gna2_model_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions inference-engine/src/gna_plugin/gna_graph_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,9 @@ void GNAGraphCompiler::PermutePrimitive(InferenceEngine::CNNLayerPtr layer) {
}
auto layerOrder = layer->GetParamAsInts("order");
auto quantized = InferenceEngine::getInjectedData<QuantizedLayerParams>(layer);
if (layer->insData.empty()) {
THROW_GNA_LAYER_EXCEPTION(layer) << "Input layer pointer is unexpectedly absent";
}
auto inputs = layer->insData.begin()->lock();
auto inputsOrder = inputs->getTensorDesc().getDims();
auto outputs = layer->outData.front();
Expand Down
2 changes: 2 additions & 0 deletions inference-engine/src/gna_plugin/gna_model_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void GNAModelSerial::Import(void *basePointer,
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);
Expand Down Expand Up @@ -173,6 +174,7 @@ void GNAModelSerial::Import(void *basePointer,
uint32_t paramSize = 0;
readBits(paramSize, is);
if (paramSize == 0) {
IE_ASSERT(operation->Parameters != nullptr);
operation->Parameters[i] = nullptr;
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion inference-engine/src/gna_plugin/gna_plugin_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&) {
Expand Down
1 change: 1 addition & 0 deletions inference-engine/src/gna_plugin/layers/gna_layer_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,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();

Expand Down
1 change: 0 additions & 1 deletion inference-engine/src/gna_plugin/layers/gna_permute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class PermuteSequence {

// length of current cycle
std::list<cnt_type> permuteCycles;
int seqId = 0;
bool newSeq = false;

for (int i = 0; i != orderVec.size();) {
Expand Down

0 comments on commit 8c122f4

Please sign in to comment.