diff --git a/src/plugins/intel_gna/src/gna_plugin.hpp b/src/plugins/intel_gna/src/gna_plugin.hpp index 724943bc804744..b2a50d8be25d4f 100644 --- a/src/plugins/intel_gna/src/gna_plugin.hpp +++ b/src/plugins/intel_gna/src/gna_plugin.hpp @@ -124,7 +124,7 @@ class GNAPlugin : public InferenceEngine::IInferencePlugin { } void Export(const std::string& fileName); - virtual void Export(std::ostream& networkModel); + void Export(std::ostream& networkModel); InferenceEngine::IExecutableNetworkInternal::Ptr ImportNetwork( const std::string& modelFileName, const std::map& config) override { diff --git a/src/plugins/intel_gna/src/scale_factor_helper.cpp b/src/plugins/intel_gna/src/scale_factor_helper.cpp index 7c673efb17583b..2214adc841e9c6 100644 --- a/src/plugins/intel_gna/src/scale_factor_helper.cpp +++ b/src/plugins/intel_gna/src/scale_factor_helper.cpp @@ -37,7 +37,7 @@ static void ApplyScaleFactorsLegacy(const std::vector& input_scale_factor for (size_t id = 0; id < inputs.size(); ++id) { log::warning() << "Using input scale factor: " << input_scale_factors[id] << ", defined in configuration for input id: " << id << std::endl; - if (input_scale_factors.size() > id && !AreFpEq(input_scale_factors[id], kScaleFactorDefault)) { + if (input_scale_factors.size() > id) { inputs.Get().at(id).scale_factor = input_scale_factors[id]; } else { log::warning() << "Using default input scale factor: " << kScaleFactorDefault << " for input id: " << id diff --git a/src/plugins/intel_gna/tests/functional/CMakeLists.txt b/src/plugins/intel_gna/tests/functional/CMakeLists.txt index 3ab445ee31560c..05636bdca84cf1 100644 --- a/src/plugins/intel_gna/tests/functional/CMakeLists.txt +++ b/src/plugins/intel_gna/tests/functional/CMakeLists.txt @@ -7,20 +7,11 @@ set(TARGET_NAME ov_gna_func_tests) addIeTargetTest( NAME ${TARGET_NAME} ROOT ${CMAKE_CURRENT_SOURCE_DIR} - INCLUDES - ${CMAKE_CURRENT_SOURCE_DIR} - $ - $ - $ DEPENDENCIES openvino_intel_gna_plugin LINK_LIBRARIES funcSharedTests - openvino_intel_gna_plugin_test_static - inference_engine_legacy_s - libGNA ADD_CLANG_FORMAT - ADD_CPPLINT LABELS GNA ) diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot7/gna_model_serial.cpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot7/gna_model_serial.cpp deleted file mode 100644 index 7b0bfcfab3d92a..00000000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot7/gna_model_serial.cpp +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined __INTEL_COMPILER || defined _MSC_VER -#include -#else -#include -#endif - -#include "gna_model_serial.hpp" -#include "common/versioning.hpp" -#include "gna2_model_helper.hpp" -#include "serial/headers/2dot7/gna_model_header.hpp" - -#ifdef GNA_DEBUG -#include -#include "transformations/serialize.hpp" -#endif - -using namespace ov::intel_gna::header_2_dot_7; - -inline void writeNBytes(const void *ptr, uint32_t size, std::ostream & os) { - os.write(static_cast(ptr), size); -} - -template -inline void writeBits(const T & obj, std::ostream & os) { - os.write(reinterpret_cast(&obj), sizeof(T)); -} - -template -inline void readBits(T & obj, std::istream & is) { - is.read(reinterpret_cast(&obj), sizeof(T)); -} - -inline void readNBytes(void * ptr, uint32_t size, std::istream & is) { - is.read(reinterpret_cast(ptr), size); -} - -template -inline void readNBits(T & obj, std::istream & is) { - std::array tmp; - is.read(reinterpret_cast(&tmp), nBits / 8); - - obj = * reinterpret_cast(&tmp.front()); -} - -inline void * offsetToPointer(void * const base, uint64_t offset) { - return reinterpret_cast(base) + offset; -} - -template -inline void readOffset(T & ptr, void *base, std::istream & is) { - uint64_t offset = 0ull; - readBits(offset, is); - ptr = reinterpret_cast(offsetToPointer(base, offset)); -} - -#define offsetFromBase(field)\ -getOffsetFromBase(field, #field) - -bool IsEmptyTensor(const Gna2Tensor& t) { - return t.Type == Gna2DataTypeNone && - t.Data == nullptr && - t.Layout[0] == '\0' && - t.Mode == Gna2TensorModeDefault && - t.Shape.NumberOfDimensions == 0; -} - -const std::map> GnaParamSize{ - {Gna2OperationTypeFullyConnectedAffine, {sizeof(Gna2BiasMode), sizeof(uint32_t)}}, - {Gna2OperationTypeConvolution, { - sizeof(Gna2Shape), - sizeof(Gna2BiasMode), - sizeof(Gna2PoolingMode), - sizeof(Gna2Shape), - sizeof(Gna2Shape), - sizeof(Gna2Shape)}}, - {Gna2OperationTypeCopy, {sizeof(Gna2Shape)}}, - {Gna2OperationTypeTransposition, {sizeof(Gna2Shape)}}, -}; - -void GNAModelSerial::Export(const GnaAllocations& allocations, std::ostream& os) const { - os.exceptions(std::ostream::failbit); - - const std::vector - layers(gna2Model->Operations, gna2Model->Operations + gna2Model->NumberOfOperations); - - const auto gnaGraphSize = allocations.GetSizeForExport(); - const auto& allocationsOrdered = allocations.GetAllocationsInExportOrder(); - - // all offsets will be from this pointer - auto getTensorWithProperOffset = [&allocationsOrdered](const Gna2Tensor& tensor) { - Gna2Tensor out = tensor; - const auto found = GnaAllocations::GetOffsetForExport(allocationsOrdered, tensor.Data); - if (!found.first) { - THROW_GNA_EXCEPTION << "Tensor data pointer not found in allocations\n"; - } - out.Data = reinterpret_cast(found.second); - return out; - }; - - auto convert_to_serial = [&allocationsOrdered](const RuntimeEndPoint& ep) { - RuntimeEndPoint out; - out.elements_count = ep.elements_count; - const auto found = GnaAllocations::GetOffsetForExport(allocationsOrdered, ep.descriptor_ptr); - if (!found.first) { - THROW_GNA_EXCEPTION << "Endpoint data pointer not found in allocations\n"; - } - out.descriptor_offset = found.second; - out.scaleFactor = ep.scaleFactor; - out.element_size = ep.element_size; - out.shape = ep.shape; - out.layout = ep.layout; - out.precision = ep.precision; - out.orientation = ep.orientation; - return out; - }; - - /** - * writing header - */ - ModelHeader header; - header.gnam[0] = 'G'; - header.gnam[1] = 'N'; - header.gnam[2] = 'A'; - header.gnam[3] = 'M'; - header.headerSize = sizeof(ModelHeader); - header.gnaMemSize = gnaGraphSize; - header.layersCount = layers.size(); - header.nGroup = 1; // just to support the old models - header.nInputs = inputs.size(); - header.nOutputs = outputs.size(); - header.nTransposeInputs = transposeInputsInfo.size(); - header.nTransposeOutputs = transposeOutputsInfo.size(); - - writeBits(header, os); - - for (auto &name : inputNames) { - const auto nameSize = strlen(name.c_str()) + 1; - writeBits(static_cast(nameSize), os); - writeNBytes(name.c_str(), nameSize , os); - } - ExportTranspositionInfo(os, transposeInputsInfo); - ExportTranspositionInfo(os, transposeOutputsInfo); - for (const auto &input : inputs) { - writeBits(convert_to_serial(input), os); - } - for (auto &name : outputNames) { - const auto nameSize = strlen(name.c_str()) + 1; - writeBits(static_cast(nameSize), os); - writeNBytes(name.c_str(), nameSize, os); - } - for (const auto &output : outputs) { - writeBits(convert_to_serial(output), os); - } - - for (const auto & layer : layers) { - writeBits(static_cast(layer.Type), os); - writeBits(layer.NumberOfOperands, os); - - for (uint32_t i = 0; i < layer.NumberOfOperands; i++) { - if (layer.Operands[i] == nullptr) { - writeBits(Gna2Tensor{}, os); - } else { - Gna2Tensor tensor = getTensorWithProperOffset(*layer.Operands[i]); - // we need to remove legacy (up to & including GNA HW 2.0) CNN enforement during export - // to avoid issues when importing and running the model on newer GNA HW with libGNA 2.1.x.y - if (i == OutOpIdx && layer.Type == Gna2OperationTypeConvolution) { - memset(tensor.Layout, 0, sizeof(tensor.Layout)); - } - writeBits(tensor, os); - } - } - - writeBits(layer.NumberOfParameters, os); - - // writing parameters - switch (layer.Type) { - case Gna2OperationTypeElementWiseAffine: - case Gna2OperationTypeFullyConnectedAffine: - case Gna2OperationTypeConvolution: - case Gna2OperationTypeCopy: - case Gna2OperationTypeTransposition: - break; - case Gna2OperationTypeRecurrent: - THROW_GNA_EXCEPTION << "Exporting of recurrent operation not supported"; - default: - THROW_GNA_EXCEPTION << "Exporting of unknown GNA operation type(" << layer.Type << ") not supported"; - } - for (uint32_t i = 0; i < layer.NumberOfParameters; i++) { - if (layer.Parameters[i] == nullptr) { - writeBits(static_cast(0), os); - continue; - } - const auto paramSize = GnaParamSize.at(layer.Type).at(i); - writeBits(paramSize, os); - writeNBytes(layer.Parameters[i], paramSize, os); - } - } - // writing memory information - writeBits(static_cast(states.size()), os); - for (auto && state : states) { - void* gna_ptr = nullptr; - uint32_t reserved_size = 0; - std::string name; - float scale_factor = 1.0f; - std::tie(gna_ptr, reserved_size, name, scale_factor) = state; - const auto found = GnaAllocations::GetOffsetForExport(allocationsOrdered, gna_ptr); - if (!found.first) { - THROW_GNA_EXCEPTION << "State data pointer not found in allocations\n"; - } - writeBits(found.second, os); - writeBits(reserved_size, os); - const auto nameSize = strlen(name.c_str()) + 1; - writeBits(static_cast(nameSize), os); - writeNBytes(name.c_str(), nameSize, os); - writeBits(scale_factor, os); - } - - // once structure has been written lets push gna graph - for (const auto& a : allocationsOrdered) { - os.write(reinterpret_cast(a.ptr), a.sizeForExport()); - } -} - -std::vector GNAModelSerial::serializeOutputs(const InferenceEngine::OutputsDataMap& outputsDataMap, - const std::vector& outputsDesc) { - std::vector endPoints; - std::size_t outputIndex = 0; - for (auto const &output : outputsDataMap) { - auto outputName = output.first; - auto outputDims = output.second->getTensorDesc().getDims(); - RuntimeEndPoint::Shape outputShape; - outputShape.NumberOfDimensions = outputDims.size(); - for (size_t i=0; i < outputShape.NumberOfDimensions; ++i) { - outputShape.Dimensions[i] = static_cast(outputDims[i]); - } - uint32_t elementsCount = static_cast(InferenceEngine::details::product(outputDims.begin(), outputDims.end())); - InferenceEngine::Layout outputLayout = output.second->getLayout(); - InferenceEngine::Precision::ePrecision outputPrecision = InferenceEngine::Precision::FP32; - RuntimeEndPoint endPoint(outputsDesc[outputIndex].scale_factor, - outputsDesc[outputIndex].ptrs[0], - outputsDesc[outputIndex].tensor_precision.size(), - elementsCount, - outputShape, - outputLayout, - outputPrecision, - outputsDesc[outputIndex].orientation); - endPoints.push_back(endPoint); - outputIndex++; - } - return endPoints; -} - -std::vector GNAModelSerial::serializeInputs(const InferenceEngine::InputsDataMap& inputsDataMap, - const std::vector& inputDesc) { - std::vector endPoints; - - std::size_t inputIndex = 0; - for (auto const& input : inputsDataMap) { - auto inputName = input.first; - auto inputDims = input.second->getTensorDesc().getDims(); - RuntimeEndPoint::Shape inputShape; - inputShape.NumberOfDimensions = inputDims.size(); - for (size_t i=0; i < inputShape.NumberOfDimensions; ++i) { - inputShape.Dimensions[i] = static_cast(inputDims[i]); - } - double scaleFactor = inputDesc[inputIndex].scale_factor; - std::vector descriptor_ptr = inputDesc[inputIndex].ptrs; - IE_ASSERT(descriptor_ptr.size() > 0); - uint32_t element_size = 2u; - uint32_t elementsCount = static_cast(InferenceEngine::details::product(inputDims.begin(), inputDims.end())); - intel_dnn_orientation_t orientation = inputDesc[inputIndex].orientation; - InferenceEngine::Layout inputLayout = input.second->getLayout(); - InferenceEngine::Precision::ePrecision inputPrecision = InferenceEngine::Precision::FP32; - RuntimeEndPoint endPoint(scaleFactor, - descriptor_ptr[0], - element_size, - elementsCount, - inputShape, - inputLayout, - inputPrecision, - orientation); - endPoints.push_back(endPoint); - inputIndex++; - } - return endPoints; -} - -void GNAModelSerial::ExportTranspositionInfo(std::ostream &os, - const TranspositionInfoMap &transpositionInfoMap) const { - for (const auto &transpositionInfo : transpositionInfoMap) { - auto nameSize = strlen(transpositionInfo.first.c_str()); - writeBits(static_cast(nameSize), os); - writeNBytes(transpositionInfo.first.c_str(), nameSize, os); - auto fragmentsNum = transpositionInfo.second.size(); - writeBits(static_cast(fragmentsNum), os); - for (const auto &transposeFragmentInfo : transpositionInfo.second) { - writeNBytes(&transposeFragmentInfo, sizeof(TranspositionInfo), os); - } - } -} \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot7/gna_model_serial.hpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot7/gna_model_serial.hpp deleted file mode 100644 index 67cef77ac63f7c..00000000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot7/gna_model_serial.hpp +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "gna_plugin.hpp" -#include "descriptions/gna_desc.hpp" -#include "request/worker_pool_impl.hpp" -#include "memory/gna_memory_state.hpp" -#include "serial/headers/2dot7/gna_model_header.hpp" -#include "gna2-model-api.h" - -#include "gna_device_allocation.hpp" - -namespace ov { -namespace intel_gna { -namespace header_2_dot_7 { - -/** - * @brief implements serialisation tasks for GNAGraph - */ -class GNAModelSerial { - public: - using MemoryType = std::vector>; - -private: - Gna2Model * gna2Model; - std::vector inputs; - std::vector outputs; - std::vector inputNames; - std::vector outputNames; - TranspositionInfoMap transposeInputsInfo; - TranspositionInfoMap transposeOutputsInfo; - - MemoryType states, *pstates = nullptr; - ModelHeader modelHeader; - - void ExportTranspositionInfo(std::ostream &os, - const TranspositionInfoMap &transpositionInfoMap) const; - - public: - GNAModelSerial(Gna2Model * model, MemoryType & states_holder) - : gna2Model(model), pstates(&states_holder) { - } - - GNAModelSerial( - Gna2Model * model, - const std::vector& inputDesc, - const std::vector& outputsDesc, - const InferenceEngine::InputsDataMap& inputsDataMap, - const InferenceEngine::OutputsDataMap& outputsDataMap) : gna2Model(model), - inputs(serializeInputs(inputsDataMap, inputDesc)), - outputs(serializeOutputs(outputsDataMap, outputsDesc)) { - for (auto const& input : inputsDataMap) { - inputNames.push_back(input.first); - } - - for (auto const& input : outputsDataMap) { - outputNames.push_back(input.first); - } - } - - GNAModelSerial & SetInputRotation(const TranspositionInfoMap &transposeInputsInfo) { - this->transposeInputsInfo = transposeInputsInfo; - return *this; - } - - GNAModelSerial& SetOutputRotation(const TranspositionInfoMap &transposeOutputsInfo) { - this->transposeOutputsInfo = transposeOutputsInfo; - return *this; - } - - /** - * mark certain part of gna_blob as state (in future naming is possible) - * @param descriptor_ptr - * @param size - * @param layerName - * @return - */ - GNAModelSerial & AddState(void* descriptor_ptr, size_t size, std::string layerName = "noname", float scale_factor = 1.0f) { - states.emplace_back(descriptor_ptr, size, layerName, scale_factor); - return *this; - } - - /** - * save gna graph to an outpus stream - * @param basePtr - * @param gnaGraphSize - * @param os - */ - void Export(const GnaAllocations& allocations, std::ostream &os) const; - - static std::vector serializeOutputs(const InferenceEngine::OutputsDataMap& outputsDataMap, - const std::vector& outputsDesc); - - - static std::vector serializeInputs(const InferenceEngine::InputsDataMap& inputsDataMap, - const std::vector& inputsDesc); -}; - -class GNAPluginLegacy : public GNAPlugin { -public: - void Export(const std::string& fileName) { - GNAPlugin::Export(fileName); - } - - void Export(std::ostream &outStream) override { - if (inputs_ptr_->empty() || outputs_.empty()) { - THROW_GNA_EXCEPTION << " network not loaded"; - } - - IE_ASSERT(!inputs_data_map_.empty()); - - Gna2Model* model_to_serial = requestWorkerPool_->firstWorker().model(); - auto serial = ov::intel_gna::header_2_dot_7::GNAModelSerial(model_to_serial, - inputs_ptr_->Get(), - outputs_.Get(), - inputs_data_map_, - outputs_data_map_) - .SetInputRotation(transpose_inputs_info) - .SetOutputRotation(transpose_outputs_info); - - for (auto && memoryConnection : graphCompiler.memory_connection) { - auto state = std::make_shared(memoryConnection.first, std::make_shared (memoryConnection.second)); - log::debug() << "Scale factor Memory layer " << state->GetScaleFactor() << std::endl; - serial.AddState(memoryConnection.second.gna_ptr, memoryConnection.second.reserved_size, memoryConnection.first, state->GetScaleFactor()); - } - - serial.Export(gnadevice->getAllAllocations(), outStream); -} -}; - -} // namespace header_2_dot_8 -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot8/gna_model_serial.cpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot8/gna_model_serial.cpp deleted file mode 100644 index 7621c92e77a7e1..00000000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot8/gna_model_serial.cpp +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined __INTEL_COMPILER || defined _MSC_VER -#include -#else -#include -#endif - -#include "gna_model_serial.hpp" -#include "common/versioning.hpp" -#include "gna2_model_helper.hpp" -#include "serial/headers/2dot8/gna_model_header.hpp" - -#ifdef GNA_DEBUG -#include -#include "transformations/serialize.hpp" -#endif - -using namespace ov::intel_gna::header_2_dot_8; - -inline void writeNBytes(const void *ptr, uint32_t size, std::ostream & os) { - os.write(static_cast(ptr), size); -} - -template -inline void writeBits(const T & obj, std::ostream & os) { - size_t size = sizeof(T); - os.write(reinterpret_cast(&obj), size); -} - -inline void writeString(const std::string &str, std::ostream &os) { - const char *c_str = str.c_str(); - const size_t str_len = strlen(c_str) + 1; - writeBits(static_cast(str_len), os); - writeNBytes(c_str, str_len, os); -} - -void GNAVersionSerializer::Export(std::ostream& os) const { - writeString(ov::intel_gna::common::get_openvino_version_string(), os); - writeString(GNADeviceHelper::GetGnaLibraryVersion(), os); -} - -static const std::map> GnaParamSize{ - {Gna2OperationTypeFullyConnectedAffine, {sizeof(Gna2BiasMode), sizeof(uint32_t)}}, - {Gna2OperationTypeConvolution, { - sizeof(Gna2Shape), - sizeof(Gna2BiasMode), - sizeof(Gna2PoolingMode), - sizeof(Gna2Shape), - sizeof(Gna2Shape), - sizeof(Gna2Shape)}}, - {Gna2OperationTypeCopy, {sizeof(Gna2Shape)}}, - {Gna2OperationTypeTransposition, {sizeof(Gna2Shape)}}, -}; - -void GNAModelSerial::Export(const GnaAllocations& allocations, std::ostream& os) const { - os.exceptions(std::ostream::failbit); - - const std::vector - layers(gna2model_->Operations, gna2model_->Operations + gna2model_->NumberOfOperations); - - const auto gnaGraphSize = allocations.GetSizeForExport(); - const auto& allocationsOrdered = allocations.GetAllocationsInExportOrder(); - - auto getTensorWithProperOffset = [&allocationsOrdered](const Gna2Tensor& tensor) { - Gna2Tensor out = tensor; - const auto found = GnaAllocations::GetOffsetForExport(allocationsOrdered, tensor.Data); - if (!found.first) { - THROW_GNA_EXCEPTION << "Tensor data pointer not found in allocations\n"; - } - out.Data = reinterpret_cast(found.second); - return out; - }; - - auto convert_to_serial = [&allocationsOrdered](const GnaDesc& desc) { - ov::intel_gna::header_2_dot_8::RuntimeEndPoint ep; - ep.elements_count = desc.num_elements; - ep.scaleFactor = desc.scale_factor; - ep.element_size = desc.tensor_precision.size(); - ep.layout = desc.model_layout; - ep.precision = desc.model_precision; - ep.orientation = desc.orientation; - ep.tensor_names_count = static_cast(desc.tensor_names.size()); - const auto found = GnaAllocations::GetOffsetForExport(allocationsOrdered, *desc.ptrs.begin()); - if (!found.first) { - THROW_GNA_EXCEPTION << "Endpoint data pointer not found in allocations\n"; - } - ep.descriptor_offset = found.second; - // shape - ep.shape.NumberOfDimensions = desc.dims.size(); - for (size_t i=0; i < ep.shape.NumberOfDimensions; ++i) { - ep.shape.Dimensions[i] = desc.dims[i]; - } - return ep; - }; - - /** - * writing header - */ - ov::intel_gna::header_2_dot_8::ModelHeader header; - header.gnam[0] = 'G'; - header.gnam[1] = 'N'; - header.gnam[2] = 'A'; - header.gnam[3] = 'M'; - header.headerSize = sizeof(ov::intel_gna::header_2_dot_8::ModelHeader); - header.gnaMemSize = gnaGraphSize; - header.layersCount = layers.size(); - header.nGroup = 1; // just to support the old models - header.nInputs = inputs_.size(); - header.nOutputs = outputs_.size(); - header.nTransposeInputs = inputs_transpose_info_.size(); - header.nTransposeOutputs = outputs_transpose_info_.size(); - // 1. Write header - writeBits(header, os); - // 2. Write input names - for (const auto &input : inputs_.Get()) { - // Write the input name - writeString(input.name, os); - } - // 3. Write transposition input info - ExportTranspositionInfo(os, inputs_transpose_info_); - // 4. Write transposition output info - ExportTranspositionInfo(os, outputs_transpose_info_); - // 5. Write input endpoints and tensor names - for (const auto &input : inputs_.Get()) { - // write RuntimeEndPoint - writeBits(convert_to_serial(input), os); - // write the input tensor names - for (const auto &tname : input.tensor_names) { - writeString(tname, os); - } - } - // 6. Write outputs names - for (auto &output : outputs_.Get()) { - // write the output name - writeString(output.name, os); - } - // 7. Write outputs endpoints and tensor names - for (auto &output : outputs_.Get()) { - // write RuntimeEndPoint - writeBits(convert_to_serial(output), os); - // write the output tensor names - for (auto &tname : output.tensor_names) { - writeString(tname, os); - } - } - // 8. Write layers - for (const auto & layer : layers) { - writeBits(static_cast(layer.Type), os); - writeBits(layer.NumberOfOperands, os); - - for (uint32_t i = 0; i < layer.NumberOfOperands; i++) { - if (layer.Operands[i] == nullptr) { - writeBits(Gna2Tensor{}, os); - } else { - Gna2Tensor tensor = getTensorWithProperOffset(*layer.Operands[i]); - // we need to remove legacy (up to & including GNA HW 2.0) CNN enforement during export - // to avoid issues when importing and running the model on newer GNA HW with libGNA 2.1.x.y - if (i == OutOpIdx && layer.Type == Gna2OperationTypeConvolution) { - memset(tensor.Layout, 0, sizeof(tensor.Layout)); - } - writeBits(tensor, os); - } - } - - writeBits(layer.NumberOfParameters, os); - - // writing parameters - switch (layer.Type) { - case Gna2OperationTypeElementWiseAffine: - case Gna2OperationTypeFullyConnectedAffine: - case Gna2OperationTypeConvolution: - case Gna2OperationTypeCopy: - case Gna2OperationTypeTransposition: - break; - case Gna2OperationTypeRecurrent: - THROW_GNA_EXCEPTION << "Exporting of recurrent operation not supported"; - default: - THROW_GNA_EXCEPTION << "Exporting of unknown GNA operation type(" << layer.Type << ") not supported"; - } - for (uint32_t i = 0; i < layer.NumberOfParameters; i++) { - if (layer.Parameters[i] == nullptr) { - writeBits(static_cast(0), os); - continue; - } - const auto paramSize = GnaParamSize.at(layer.Type).at(i); - writeBits(paramSize, os); - writeNBytes(layer.Parameters[i], paramSize, os); - } - } - // writing memory information - writeBits(static_cast(states.size()), os); - for (auto && state : states) { - void* gna_ptr = nullptr; - uint32_t reserved_size = 0; - std::string name; - float scale_factor = 1.0f; - std::tie(gna_ptr, reserved_size, name, scale_factor) = state; - const auto found = GnaAllocations::GetOffsetForExport(allocationsOrdered, gna_ptr); - if (!found.first) { - THROW_GNA_EXCEPTION << "State data pointer not found in allocations\n"; - } - writeBits(found.second, os); - writeBits(reserved_size, os); - const auto nameSize = strlen(name.c_str()) + 1; - writeBits(static_cast(nameSize), os); - writeNBytes(name.c_str(), nameSize, os); - writeBits(scale_factor, os); - } - - // once structure has been written let's push gna graph memory - for (const auto& a : allocationsOrdered) { - os.write(reinterpret_cast(a.ptr), a.sizeForExport()); - } - - // write OV & GNA versions - version_.Export(os); -} - -void GNAModelSerial::ExportTranspositionInfo(std::ostream &os, -const TranspositionInfoMap &transpositionInfoMap) const { - for (const auto &transpositionInfo : transpositionInfoMap) { - auto nameSize = strlen(transpositionInfo.first.c_str()); - writeBits(static_cast(nameSize), os); - writeNBytes(transpositionInfo.first.c_str(), nameSize, os); - auto fragmentsNum = transpositionInfo.second.size(); - writeBits(static_cast(fragmentsNum), os); - for (const auto &transposeFragmentInfo : transpositionInfo.second) { - writeNBytes(&transposeFragmentInfo, sizeof(TranspositionInfo), os); - } - } -} \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot8/gna_model_serial.hpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot8/gna_model_serial.hpp deleted file mode 100644 index d95827c3ad7f3d..00000000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/2dot8/gna_model_serial.hpp +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "gna_plugin.hpp" -#include "descriptions/gna_desc.hpp" -#include "request/worker_pool_impl.hpp" -#include "memory/gna_memory_state.hpp" -#include "serial/headers/2dot8/gna_model_header.hpp" -#include "gna2-model-api.h" - -#include "gna_device_allocation.hpp" - -namespace ov { -namespace intel_gna { -namespace header_2_dot_8 { - -/** - * @brief helper class for GNAGraph serialization tasks - */ -class GNAVersionSerializer { -public: - void Export(std::ostream& os) const; - std::string Import(std::istream& is) const; -}; - -/** - * @brief implements serialization tasks for GNAGraph - */ -class GNAModelSerial { -public: - using MemoryType = std::vector>; - -private: - Gna2Model * gna2model_; - MemoryType states, *pstates_ = nullptr; - ov::intel_gna::GnaInputs inputs_; - ov::intel_gna::GnaOutputs outputs_; - TranspositionInfoMap inputs_transpose_info_; - TranspositionInfoMap outputs_transpose_info_; - ov::intel_gna::header_2_dot_8::ModelHeader model_header_; - GNAVersionSerializer version_; - - void AppendTensorNameIfNeeded(ov::intel_gna::GnaDesc& nodeDesc) const; - - public: - GNAModelSerial(Gna2Model* model, MemoryType& states_holder) - : gna2model_(model), - pstates_(&states_holder) { - } - - GNAModelSerial(Gna2Model* model, - ov::intel_gna::GnaInputs& inputs, - ov::intel_gna::GnaOutputs& outputs) - : gna2model_(model), - inputs_(inputs), - outputs_(outputs) { - } - - void setHeader(ov::intel_gna::header_2_dot_8::ModelHeader header) { - model_header_ = header; - } - - GNAModelSerial & SetInputRotation(const TranspositionInfoMap &transpose_inputs_info) { - inputs_transpose_info_ = transpose_inputs_info; - return *this; - } - - GNAModelSerial & SetOutputRotation(const TranspositionInfoMap &transpose_outputs_info) { - outputs_transpose_info_ = transpose_outputs_info; - return *this; - } - - /** - * mark certain part of gna_blob as state (in future naming is possible) - * @param descriptor_ptr - * @param size - * @param layerName - * @return - */ - GNAModelSerial & AddState(void* descriptor_ptr, size_t size, std::string layerName = "noname", float scale_factor = 1.0f) { - states.emplace_back(descriptor_ptr, static_cast(size), layerName, scale_factor); - return *this; - } - - /** - * save gna graph to an outpus stream - * @param allocations - * @param os - */ - void Export(const GnaAllocations& allocations, - std::ostream &os) const; - - void ExportTranspositionInfo(std::ostream &os, const TranspositionInfoMap &transpositionInfoMap) const; - -}; - -class GNAPluginLegacy : public GNAPlugin { -public: - void Export(const std::string& fileName) { - GNAPlugin::Export(fileName); - } - - void Export(std::ostream &outStream) override { - if (inputs_ptr_->empty() || outputs_.empty()) { - THROW_GNA_EXCEPTION << " network not loaded"; - } - - IE_ASSERT(!inputs_data_map_.empty()); - - Gna2Model* model_to_serial = requestWorkerPool_->firstWorker().model(); - auto serial = ov::intel_gna::header_2_dot_8::GNAModelSerial(model_to_serial, - *(inputs_ptr_), - outputs_) - .SetInputRotation(transpose_inputs_info) - .SetOutputRotation(transpose_outputs_info); - - for (auto && memoryConnection : graphCompiler.memory_connection) { - auto state = std::make_shared(memoryConnection.first, std::make_shared (memoryConnection.second)); - log::debug() << "Scale factor Memory layer " << state->GetScaleFactor() << std::endl; - serial.AddState(memoryConnection.second.gna_ptr, memoryConnection.second.reserved_size, memoryConnection.first, state->GetScaleFactor()); - } - - serial.Export(gnadevice->getAllAllocations(), outStream); -} -}; - -} // namespace header_2_dot_8 -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/gna_plugin_factory.hpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/gna_plugin_factory.hpp deleted file mode 100644 index 07c1bcf6fe68fb..00000000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/gna_plugin_factory.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include "2dot7/gna_model_serial.hpp" -#include "2dot8/gna_model_serial.hpp" -#include "gna_plugin.hpp" - -namespace ov { -namespace intel_gna { -namespace test { - -enum kExportModelVersion { - V2_7, - V2_8, - UNKNOWN -}; - -inline const char* ExportModelVersionToStr(kExportModelVersion ver) { - const char* ver_str = "UNKNOWN"; - switch (ver) { - case kExportModelVersion::V2_7: - ver_str = "2.7"; - break; - case kExportModelVersion::V2_8: - ver_str = "2.8"; - break; - case kExportModelVersion::UNKNOWN: - ver_str = "UNKNOWN"; - break; - } - return ver_str; -} - -class GNAPluginLegacyFactory { -public: - static std::shared_ptr CreatePluginLegacy(kExportModelVersion model_ver) { - switch (model_ver) - { - case kExportModelVersion::V2_7: - return std::shared_ptr(new ov::intel_gna::header_2_dot_7::GNAPluginLegacy()); - break; - case kExportModelVersion::V2_8: - return std::shared_ptr(new ov::intel_gna::header_2_dot_8::GNAPluginLegacy()); - break; - default: - break; - } - } -}; - -} // test -} // intel_gna -} // ov \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/base/import_export_base.cpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/base/import_export_base.cpp index daa7d282fdcb64..59265f6c02c635 100644 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/base/import_export_base.cpp +++ b/src/plugins/intel_gna/tests/functional/Import_export_tests/base/import_export_base.cpp @@ -3,12 +3,9 @@ // #include "import_export_base.hpp" -#include "../backward_compatibility/gna_plugin_factory.hpp" #include -using namespace ov::intel_gna::test; - namespace FuncTestUtils { std::string ImportNetworkTestBase::getTestCaseName(testing::TestParamInfo obj) { @@ -18,11 +15,7 @@ std::string ImportNetworkTestBase::getTestCaseName(testing::TestParamInfo exportConfiguration; std::map importConfiguration; std::string appHeader; - kExportModelVersion model_ver; - - std::tie(inputShape, netPrecision, targetDevice, - exportConfiguration, importConfiguration, - model_ver, appHeader) = obj.param; + std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, appHeader) = obj.param; std::ostringstream result; result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_"; @@ -35,22 +28,13 @@ std::string ImportNetworkTestBase::getTestCaseName(testing::TestParamInfo, // Input Shape InferenceEngine::Precision, // Network Precision std::string, // Target Device std::map, // Export Configuration std::map, // Import Configuration - kExportModelVersion, // Exported model version std::string // Application Header > exportImportNetworkParams; @@ -35,7 +30,6 @@ class ImportNetworkTestBase : public testing::WithParamInterface exportConfiguration; std::map importConfiguration; std::string applicationHeader; - kExportModelVersion m_model_version; private: virtual void exportImportNetwork(); diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_batch_size.cpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_batch_size.cpp index c00a0779e2f262..bf5c9144d124ea 100644 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_batch_size.cpp +++ b/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_batch_size.cpp @@ -26,7 +26,7 @@ class ImportBatchTest : public FuncTestUtils::ImportNetworkTestBase { InferenceEngine::Precision netPrecision; std::vector inputShape; std::string _; - std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, m_model_version, _) = + std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, _) = this->GetParam(); auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); @@ -69,10 +69,6 @@ const std::vector> importConfigs = {{{"GNA_DE const std::vector appHeader = {""}; -const std::vector model_versions = {kExportModelVersion::UNKNOWN, - kExportModelVersion::V2_8, - kExportModelVersion::V2_7}; - INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkBatchCase, ImportBatchTest, ::testing::Combine(::testing::ValuesIn(inputShapes), @@ -80,7 +76,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkBatchCase, ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), ::testing::ValuesIn(importConfigs), - ::testing::ValuesIn(model_versions), ::testing::ValuesIn(appHeader)), ImportBatchTest::getTestCaseName); } // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_multi_inputs.cpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_multi_inputs.cpp index ee65666cbe3eb1..a0f872439c779d 100644 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_multi_inputs.cpp +++ b/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_multi_inputs.cpp @@ -18,7 +18,7 @@ class ImportMultiInput : public FuncTestUtils::ImportNetworkTestBase { void SetUp() override { std::vector inputShape; InferenceEngine::Precision netPrecision; - std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, m_model_version, applicationHeader) = + std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam(); auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); @@ -62,10 +62,6 @@ const std::vector> importConfigsUnchanged = { {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_1", "327.67"}}, }; -const std::vector model_versions = {kExportModelVersion::UNKNOWN, - kExportModelVersion::V2_8, - kExportModelVersion::V2_7}; - INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportMultiInputUnchanged, ::testing::Combine(::testing::ValuesIn(inputShape), @@ -73,7 +69,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), ::testing::ValuesIn(importConfigsUnchanged), - ::testing::ValuesIn(model_versions), ::testing::Values("")), ImportMultiInputUnchanged::getTestCaseName); @@ -84,7 +79,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), ::testing::ValuesIn(importConfigsChanged), - ::testing::Values(kExportModelVersion::UNKNOWN), ::testing::Values("")), ImportMultiInputChanged::getTestCaseName); diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_reshape_permute_conv.cpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/import_reshape_permute_conv.cpp index ce8f0bd5748111..bd68f89f517295 100644 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_reshape_permute_conv.cpp +++ b/src/plugins/intel_gna/tests/functional/Import_export_tests/import_reshape_permute_conv.cpp @@ -12,7 +12,7 @@ class ImportReshapePermuteConv : public FuncTestUtils::ImportNetworkTestBase { void SetUp() override { std::vector inputShape; InferenceEngine::Precision netPrecision; - std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, m_model_version, applicationHeader) = + std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam(); auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); @@ -118,10 +118,6 @@ const std::vector> importConfigsUnchanged = { {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}}, {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; -const std::vector model_versions = {kExportModelVersion::UNKNOWN, - kExportModelVersion::V2_8, - kExportModelVersion::V2_7}; - const std::vector appHeaders = {"", "APPLICATION_HEADER"}; INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, @@ -131,7 +127,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), ::testing::ValuesIn(importConfigsUnchanged), - ::testing::ValuesIn(model_versions), ::testing::ValuesIn(appHeaders)), ImportExportGNAModelUnchanged::getTestCaseName); @@ -142,7 +137,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), ::testing::ValuesIn(importConfigsChanged), - ::testing::Values(kExportModelVersion::UNKNOWN), ::testing::ValuesIn(appHeaders)), ImportExportGNAModelChanged::getTestCaseName);