Skip to content

Commit

Permalink
Publishing 2019 R1.1 content and Myriad plugin sources (openvinotoolk…
Browse files Browse the repository at this point in the history
…it#162)

* Publishing 2019 R1.1 content and Myriad plugin sources
  • Loading branch information
asuhov authored and dood-apo committed Aug 24, 2023
1 parent 9895a0c commit 704d4f8
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 71 deletions.
3 changes: 1 addition & 2 deletions inference-engine/src/gna_plugin/dnn.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright (C) 2018-2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// dnn.cpp : component based neural network class for ease of use
//

extern bool global_debug;

#include <cstdlib>
Expand Down
4 changes: 3 additions & 1 deletion inference-engine/src/gna_plugin/dnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ class AmIntelDnn {
ptr_sumgroup_sizes(NULL),
num_sumgroup_sizes(0),
ptr_priors(NULL),
ptr_dnn_memory_(NULL) {
ptr_dnn_memory_(NULL),
num_bytes_dnn_memory_(0),
number_type_(kDnnNumNumberType) {
}

~AmIntelDnn() {
Expand Down
2 changes: 0 additions & 2 deletions inference-engine/src/gna_plugin/dnn_memory.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (C) 2018-2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// dnn_memory.cpp : memory manipulation routines
//

#include <cstdio>
#include <cstdlib>
Expand Down
1 change: 0 additions & 1 deletion inference-engine/src/gna_plugin/dnn_memory.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (C) 2018-2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// dnn_memory.hpp : memory manipulation routines

#pragma once

Expand Down
2 changes: 0 additions & 2 deletions inference-engine/src/gna_plugin/dnn_traits.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (C) 2018-2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// dnn_traits.hpp : c++ trait approach to define dnn objects
//

#pragma once

Expand Down
2 changes: 0 additions & 2 deletions inference-engine/src/gna_plugin/floatmath.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (C) 2018-2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// floatmath.cpp : unoptimized floating point math routines (for reference)
//

#include "floatmath.h"
#include "pwl.h"
Expand Down
1 change: 1 addition & 0 deletions inference-engine/src/gna_plugin/gna_api_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CPPWrapper<intel_nnet_type_t> {
for (int i = 0; i < obj.nLayers; i++) {
obj.pLayers[i].pLayerStruct = nullptr;
}
obj.nGroup = 0;
}
~CPPWrapper() {
for (int i = 0; i < obj.nLayers; i++) {
Expand Down
2 changes: 2 additions & 0 deletions inference-engine/src/gna_plugin/gna_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ void GNADeviceHelper::updateGnaPerfCounters() {
void GNADeviceHelper::getGnaPerfCounters(std::map<std::string, InferenceEngine::InferenceEngineProfileInfo>& retPerfCounters) {
InferenceEngine::InferenceEngineProfileInfo info;
info.status = InferenceEngine::InferenceEngineProfileInfo::EXECUTED;
info.cpu_uSec = 0;
info.execution_index = 0;

// Hardware
info.realTime_uSec = nGNAPerfResultsTotal.hw.total;
Expand Down
2 changes: 0 additions & 2 deletions inference-engine/src/gna_plugin/gna_helper.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (C) 2018-2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// gna_helper.cpp : various GNA-related utility functions
//

#include "lstm.hpp"

Expand Down
17 changes: 13 additions & 4 deletions inference-engine/src/gna_plugin/gna_layer_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@ class LayerInfo {
bool isEltwiseSum() const noexcept {
IS_VALID();
if (!isEltwise()) return false;
return dynamic_cast<const InferenceEngine::EltwiseLayer*>(layer)->_operation ==
InferenceEngine::EltwiseLayer::Sum;
// dynamic_cast<const InferenceEngine::EltwiseLayer *>(layer) is validated in isEltwise function
// coverity[var_deref_op]
return dynamic_cast<const InferenceEngine::EltwiseLayer *>(layer)->_operation ==
InferenceEngine::EltwiseLayer::Sum;
}
bool isEltwiseMul() const noexcept {
IS_VALID();
if (!isEltwise()) return false;
// dynamic_cast<const InferenceEngine::EltwiseLayer *>(layer) is validated in isEltwise function
// coverity[var_deref_op]
return dynamic_cast<const InferenceEngine::EltwiseLayer*>(layer)->_operation ==
InferenceEngine::EltwiseLayer::Prod;
}
Expand Down Expand Up @@ -156,8 +160,13 @@ class LayerInfo {
}
bool isCropAffined() const noexcept {
auto cropLayer = dynamic_cast<InferenceEngine::CropLayer *> (layer);
size_t cropOffset = cropLayer->offset.back() * cropLayer->precision.size();
return (ALIGN64(cropOffset) != cropOffset);
if (cropLayer != nullptr && !cropLayer->offset.empty()) {
try {
size_t cropOffset = cropLayer->offset.back() * cropLayer->precision.size();
return (ALIGN64(cropOffset) != cropOffset);
} catch (InferenceEngine::details::InferenceEngineException& e) {}
}
return false;
}
bool isCopy() const noexcept {
IS_VALID();
Expand Down
2 changes: 1 addition & 1 deletion inference-engine/src/gna_plugin/gna_mem_requests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct MemRequest {
uint8_t _element_size;
size_t _num_elements;
size_t _alignment;
size_t _offset;
size_t _offset = 0;
// expansion in bytes due to large depended layers
size_t _padding = 0;
MemRequest(rRegion region,
Expand Down
8 changes: 4 additions & 4 deletions inference-engine/src/gna_plugin/gna_model_serial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ class GNAModelSerial {
/**
* if scale factor is different then pased into infer , network might need to be requantized
*/
float scaleFactor;
float scaleFactor = 0;
/**
* Pointer descriptor
*/
void* descriptor_ptr;
void* descriptor_ptr = nullptr;
/**
* Endpoint resolution in bytes.
*/
uint32_t element_size;
uint32_t element_size = 0;
/**
* Number of elements
*/
uint32_t elements_count;
uint32_t elements_count = 0;

RuntimeEndPoint() = default;
RuntimeEndPoint(double scaleFactor,
Expand Down
84 changes: 50 additions & 34 deletions inference-engine/src/gna_plugin/gna_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,12 @@ void GNAPlugin::PWLPrimitive(InferenceEngine::CNNLayerPtr layer) {
THROW_GNA_EXCEPTION << "Activation function type not yet supported: " << type;
}
auto activation_type = DnnActivation::fromType(it->second);
activation_type.negative_slope = (it->second == kActRelu) ? dynamic_cast<ReLULayer*>(layer.get())->negative_slope : 0.0f;
if (it->second == kActRelu) {
auto reluLayer = dynamic_cast<ReLULayer *>(layer.get());
activation_type.negative_slope = reluLayer != nullptr ? reluLayer->negative_slope : 0.0f;
} else {
activation_type.negative_slope = 0.0f;
}

// TODO: need to take graph dependency instead of linear
auto &prevComponent = dnnComponentsForLayer.back().second;
Expand Down Expand Up @@ -1649,20 +1654,23 @@ void GNAPlugin::LoadNetwork(ICNNNetwork &network) {
for (auto layer = sortedNoMem.begin(); layer != sortedNoMem.end(); ++layer) {
CreateLayerPrimitive(*layer);
}
if (dnnComponentsForLayer.empty()) {
THROW_GNA_EXCEPTION << "No outputs found in dnn components structure";
}

DnnComponentsForLayer::iterator output_component = std::find_if(dnnComponentsForLayer.begin(),
dnnComponentsForLayer.end(),
[&](const std::pair<std::string, intel_dnn_component_t>& v)
{ return outputsDataMap.begin()->first == v.first; });

if (output_component == dnnComponentsForLayer.end()) {
if (dnnComponentsForLayer.empty()) {
THROW_GNA_EXCEPTION << "No outputs found in internal structures";
}
// likely layer is fused. Take last one
output_component = std::prev(dnnComponentsForLayer.end());
auto it = dnnComponentsForLayer.begin();
std::advance(it, dnnComponentsForLayer.size() - 1);
output_component = it;
gnalog() << "Output layer "<< outputsDataMap.begin()->first
<< " has not been found in component list. Took "
<< output_component->first << " instead \n" << std::flush;
<< " has not been found in component list. Took "
<< output_component->first << " instead \n" << std::flush;
}
gnamem->bind_ptr(&ptr_outputs_global.front(), &output_component->second.ptr_outputs);

Expand Down Expand Up @@ -1775,14 +1783,20 @@ void GNAPlugin::LoadNetwork(ICNNNetwork &network) {
orientation_out = output_component->second.orientation_out;
num_bytes_per_output = output_component->second.num_bytes_per_output;

if (sortedNet.empty()) {
THROW_GNA_EXCEPTION << "Sorted network is empty";
}

// find output layer
auto output = std::find_if(sortedNet.begin(),
sortedNet.end(),
[&](const CNNLayerPtr& v)
{ return outputsDataMap.begin()->first == v.get()->name; });
if (output == sortedNet.end()) {
// likely layer is fused. Take last one
output = std::prev(sortedNet.end());
auto it = sortedNet.begin();
std::advance(it, sortedNet.size() - 1);
output = it;
}
auto quantized = InferenceEngine::getInjectedData<QuantizedLayerParams>(*output);
output_scale_factor = quantized != nullptr ? quantized->_dst_quant.scale : 1.0f;
Expand Down Expand Up @@ -2461,36 +2475,38 @@ void GNAPlugin::connectOutput(InferenceEngine::CNNLayerPtr layer, void *ptr, voi
[&name](GNAPlugin::GNAConcatLayer::ConcatConnectedLayerInfo &item) {
return item.name == name;
});
// reserve full size for concat
if (!concatLayerInfoItem.output_allocation_flag) {
// check if this concat is being included by other one
// by going thru each concat and checking inputs
auto included =
std::find_if(concat_connection.begin(),
concat_connection.end(),
[&concatLayerInfo]
(const std::pair<std::string, GNAPlugin::GNAConcatLayer> &concatItem) -> bool {
auto it = std::find_if(concatItem.second.concatInputLayers.begin(),
concatItem.second.concatInputLayers.end(),
[&concatLayerInfo]
(const GNAPlugin::GNAConcatLayer::ConcatConnectedLayerInfo &item) -> bool {
return item.name == concatLayerInfo->first;
});
return it != concatItem.second.concatInputLayers.end();
});
if (included == concat_connection.end()) {
gnamem->reserve_ptr(&concatLayerInfoItem.gna_ptr, ALIGN64(concatLayerInfoItem.reserved_size));

for (auto && inputLayer : concatLayerInfoItem.concatInputLayers) {
if ( InferenceEngine::details::CaselessEq<std::string>()
(inputLayer.name, "input") ) {
bytes_alllocated_for_input[inputLayer.name] = ALIGN64(concatLayerInfoItem.reserved_size) - inputLayer.offset;
if (it != concatLayerInfoItem.concatInputLayers.end()) {
// reserve full size for concat
if (!concatLayerInfoItem.output_allocation_flag) {
// check if this concat is being included by other one
// by going thru each concat and checking inputs
auto included =
std::find_if(concat_connection.begin(),
concat_connection.end(),
[&concatLayerInfo]
(const std::pair<std::string, GNAPlugin::GNAConcatLayer> &concatItem) -> bool {
auto it = std::find_if(concatItem.second.concatInputLayers.begin(),
concatItem.second.concatInputLayers.end(),
[&concatLayerInfo]
(const GNAPlugin::GNAConcatLayer::ConcatConnectedLayerInfo &item) -> bool {
return item.name == concatLayerInfo->first;
});
return it != concatItem.second.concatInputLayers.end();
});
if (included == concat_connection.end()) {
gnamem->reserve_ptr(&concatLayerInfoItem.gna_ptr, ALIGN64(concatLayerInfoItem.reserved_size));

for (auto &&inputLayer : concatLayerInfoItem.concatInputLayers) {
if (InferenceEngine::details::CaselessEq<std::string>()
(inputLayer.name, "input")) {
bytes_alllocated_for_input[inputLayer.name] = ALIGN64(concatLayerInfoItem.reserved_size) - inputLayer.offset;
}
}
}
concatLayerInfo->second.output_allocation_flag = true;
}
concatLayerInfo->second.output_allocation_flag = true;
gnamem->bind_ptr(ptr, &concatLayerInfoItem.gna_ptr, it->offset);
}
gnamem->bind_ptr(ptr, &concatLayerInfoItem.gna_ptr, it->offset);
} else {
// error
}
Expand Down
4 changes: 2 additions & 2 deletions inference-engine/src/gna_plugin/gna_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class GNAPlugin : public InferenceEngine::IInferencePluginInternal, public std::


uint32_t num_feature_maps = 1;
uint32_t num_memory_bytes;
uint32_t num_memory_bytes = 0;

std::unordered_map<std::string, std::list<std::vector<void *>>::iterator> ptr_inputs_global_id;
std::list<std::vector<void *>> ptr_inputs_global_storage;
Expand All @@ -79,7 +79,7 @@ class GNAPlugin : public InferenceEngine::IInferencePluginInternal, public std::
uint32_t *ptr_active_indices = NULL;
uint32_t num_active_indices = 0;
uint32_t num_group_in = 0;
uint32_t num_bytes_weight;
uint32_t num_bytes_weight = 0;
uint32_t num_bytes_per_output = 0;

bool use_dynamic_quantization = false;
Expand Down
2 changes: 1 addition & 1 deletion inference-engine/src/gna_plugin/gna_plugin_passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void GNAPlugin::insertCopyLayer(std::vector<InferenceEngine::CNNLayerPtr> & laye
if ((LayerInfo(l).isMemory() && LayerInfo(prevLayer).isConcat()) ||
(LayerInfo(l).isConcat() && LayerInfo(prevLayer).isCrop())) {
if (LayerInfo(prevLayer).isCrop()) {
auto cropLayer = dynamic_cast<InferenceEngine::CropLayer *> (prevLayer.get());
auto cropLayer = LayerInfo(prevLayer).as<CropLayer*>();
size_t cropOffset = cropLayer->offset.back() * cropLayer->precision.size();
if (ALIGN(cropOffset, 8) != cropOffset) {
// The crop will be replced by affine.
Expand Down
2 changes: 0 additions & 2 deletions inference-engine/src/gna_plugin/lstm.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (C) 2018-2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// lstm.cpp : GNA LSTM macro layer definition
//

#include "lstm.hpp"

Expand Down
2 changes: 0 additions & 2 deletions inference-engine/src/gna_plugin/pwl_design.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (C) 2018-2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// pwl_design.cpp : simple activation function designer
//

#include "pwl.h"
#include "gna_plugin_log.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ inline void quantizeWeightsBiasesConv(const QuantDesc & quantDesc,
auto inputData = conv->insData[0].lock();

uint32_t num_rows = getBiasSizeForLayer(conv);
if (num_rows == 0) {
THROW_GNA_EXCEPTION << "Invalid num rows";
}
uint32_t num_columns = conv->_weights->size() / num_rows;

uint32_t num_rows_padded = num_rows;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class ModelQuantizer {
// one of solution is to create not copyNet overloads, that accepts 2 functors, one for layer copy
// and another one for net copy
auto rawNet = dynamic_cast<InferenceEngine::details::CNNNetworkImpl *>(copiedNet.get());
rawNet->setPrecision(T::mandatory().getNetPrecision());
if (rawNet != nullptr) {
rawNet->setPrecision(T::mandatory().getNetPrecision());
}

// allow client code to access copied topology, to avoid copies if user would like to chain quantisation with
// another preprocessing
Expand Down
12 changes: 8 additions & 4 deletions inference-engine/src/gna_plugin/quantization/quantization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <cstring>
#include <iostream>
#include <details/ie_exception.hpp>
#include "quantization.h"

void QuantizeAffine16(float *ptr_float_weights,
Expand Down Expand Up @@ -496,6 +497,9 @@ void QuantizeAffine8(float *ptr_float_weights, float *ptr_float_biases,
float input_scale_factor, float *ptr_weight_scale_factor,
float *ptr_output_scale_factor, uint32_t num_rows, uint32_t num_columns,
uint32_t num_rows_padded, uint32_t num_columns_padded) {
if (ptr_int_biases == nullptr) {
THROW_IE_EXCEPTION << "Int biases are empty";
}
uint32_t num_saturate = 0;

if (*ptr_weight_scale_factor == 1.0) {
Expand Down Expand Up @@ -547,23 +551,23 @@ void QuantizeAffine8(float *ptr_float_weights, float *ptr_float_biases,
value = scaled_row_max / static_cast<float>(MAX_VAL_1B_WEIGHT);
ptr_int_biases[row].multiplier = (uint8_t) (value + 0.5);
for (uint32_t col = 0; col < num_columns; col++) {
int8_t *ptr_weight_8 = ptr_int_weights + (row*num_columns_padded + col);
int8_t *ptr_weight_8 = ptr_int_weights + (row * num_columns_padded + col);
rounding_value = (ptr_float_weights[row * num_columns + col] > 0) ? 0.5f : -0.5f;


value = ptr_float_weights[row*num_columns + col] * (*ptr_weight_scale_factor / ptr_int_biases[row].multiplier) + rounding_value;
value = ptr_float_weights[row * num_columns + col] * (*ptr_weight_scale_factor / ptr_int_biases[row].multiplier) + rounding_value;
if (value > 127.0) {
*ptr_weight_8 = 127;
num_saturate++;
} else if (value < -128.0) {
*ptr_weight_8 = -128;
num_saturate++;
} else {
*ptr_weight_8 = (int8_t)value;
*ptr_weight_8 = (int8_t) value;
}
}
for (uint32_t col = num_columns; col < num_columns_padded; col++) {
int8_t *ptr_weight_8 = ptr_int_weights + (row*num_columns_padded + col);
int8_t *ptr_weight_8 = ptr_int_weights + (row * num_columns_padded + col);
*ptr_weight_8 = 0;
}
}
Expand Down
Loading

0 comments on commit 704d4f8

Please sign in to comment.