diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3727c4d88f6..69912be7abe 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -58,9 +58,6 @@ /src/tests/**/gpu/ @openvinotoolkit/openvino-ie-gpu-maintainers /thirdparty/ocl/ @openvinotoolkit/openvino-ie-gpu-maintainers @openvinotoolkit/openvino-ie-gpu-developers -# OpenVINO GNA: -/src/plugins/intel_gna/ @openvinotoolkit/openvino-ie-gna-maintainers - # OpenVINO Auto (MULTI) plugin: /src/plugins/auto/ @openvinotoolkit/openvino-ie-auto-multi-maintainers @@ -118,7 +115,6 @@ /docs/snippets/ @openvinotoolkit/openvino-docs-maintainers @openvinotoolkit/openvino-ie-maintainers /docs/OV_Runtime_UG/supported_plugins/ARM_CPU.md @openvinotoolkit/openvino-docs-maintainers @openvinotoolkit/openvino_contrib-arm_plugin-maintainers /docs/OV_Runtime_UG/supported_plugins/CPU.md @openvinotoolkit/openvino-docs-maintainers @openvinotoolkit/openvino-ie-cpu-maintainers -/docs/OV_Runtime_UG/supported_plugins/GNA.md @openvinotoolkit/openvino-docs-maintainers @openvinotoolkit/openvino-ie-gna-maintainers /docs/OV_Runtime_UG/supported_plugins/GPU*.md @openvinotoolkit/openvino-docs-maintainers @openvinotoolkit/openvino-ie-gpu-maintainers # Configuration management diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index d8f447ef327..a3782490f81 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -41,9 +41,7 @@ body: options: - CPU - GPU - - GNA - - NCS2 (Intel Movidius) - - HDDL + - NPU - AUTO - HETERO - BATCH diff --git a/.github/components.yml b/.github/components.yml index 26bc6ece11f..083dd2b769b 100644 --- a/.github/components.yml +++ b/.github/components.yml @@ -18,7 +18,6 @@ LP_transformations: preprocessing: revalidate: - inference - - GNA - C_API - Python_API @@ -48,18 +47,10 @@ GPU: - IR_FE - PROXY -GNA: - build: - - HETERO - - AUTO_BATCH - - TEMPLATE - - IR_FE - HETERO: revalidate: - CPU - GPU - - GNA - HETERO - AUTO_BATCH - TEMPLATE @@ -72,7 +63,6 @@ AUTO_BATCH: revalidate: - CPU - GPU - - GNA - HETERO - AUTO_BATCH - TEMPLATE @@ -85,7 +75,6 @@ TEMPLATE: revalidate: - CPU - GPU - - GNA - HETERO - AUTO_BATCH - TEMPLATE @@ -194,7 +183,6 @@ IE_Tests: revalidate: - CPU - GPU - - GNA - HETERO - AUTO_BATCH - TEMPLATE diff --git a/.github/github_org_control/config.json b/.github/github_org_control/config.json index 1d87ff26bee..1eaab07c42b 100644 --- a/.github/github_org_control/config.json +++ b/.github/github_org_control/config.json @@ -24,7 +24,6 @@ "openvino-docs-maintainers": "category: docs", "openvino-ie-maintainers": "category: inference", "openvino-ie-cpu-maintainers": "category: CPU", - "openvino-ie-gna-maintainers": "category: GNA", "openvino-ie-gpu-maintainers": "category: GPU", "openvino-ie-lpt-maintainers": "category: LP transformations", "openvino-ie-transformations-maintainers": "category: transformations", diff --git a/.github/labeler.yml b/.github/labeler.yml index 95ba3b9a666..5c90a516be8 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -67,9 +67,6 @@ - 'src/frontends/common/include/openvino/frontend/extension.hpp' - 'src/frontends/common/include/openvino/frontend/extension/**/*' -'category: GNA': -- 'src/plugins/intel_gna/**/*' - 'category: GPU': - 'src/plugins/intel_gpu/**/*' - 'thirdparty/ocl/**/*' diff --git a/.github/workflows/job_cxx_unit_tests.yml b/.github/workflows/job_cxx_unit_tests.yml index e2c1cfc0fa7..e484dc59696 100644 --- a/.github/workflows/job_cxx_unit_tests.yml +++ b/.github/workflows/job_cxx_unit_tests.yml @@ -157,22 +157,6 @@ jobs: ${INSTALL_TEST_DIR}/ov_transformations_tests --gtest_print_time=1 \ --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-Transformations.xml - - name: Legacy Transformations func tests - if: fromJSON(inputs.affected-components).GNA.test && - (runner.os != 'macOS' && runner.arch != 'ARM64') - run: | - source ${INSTALL_DIR}/setupvars.sh - ${INSTALL_TEST_DIR}/ov_legacy_transformations_tests --gtest_print_time=1 \ - --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-LegacyTransformations.xml - - - name: Inference Engine 1.0 unit tests - if: fromJSON(inputs.affected-components).GNA.test && - (runner.os != 'macOS' && runner.arch != 'ARM64') - run: | - source ${INSTALL_DIR}/setupvars.sh - ${INSTALL_TEST_DIR}/InferenceEngineUnitTests --gtest_print_time=1 \ - --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-InferenceEngineUnitTests.xml - - name: Common test utils tests run: | source ${INSTALL_DIR}/setupvars.sh diff --git a/.github/workflows/linux_conditional_compilation.yml b/.github/workflows/linux_conditional_compilation.yml index 82b2f24b6b7..79ac560f84b 100644 --- a/.github/workflows/linux_conditional_compilation.yml +++ b/.github/workflows/linux_conditional_compilation.yml @@ -147,7 +147,6 @@ jobs: -DENABLE_TESTS=ON \ -DENABLE_CPPLINT=OFF \ -DENABLE_NCC_STYLE=OFF \ - -DENABLE_INTEL_GNA=OFF \ -DCMAKE_COMPILE_WARNING_AS_ERROR=ON \ -DENABLE_PROFILING_ITT=ON \ -DSELECTIVE_BUILD=COLLECT \ @@ -303,7 +302,6 @@ jobs: -DSELECTIVE_BUILD=ON \ -DENABLE_TEMPLATE=OFF \ -DENABLE_INTEL_GPU=OFF \ - -DENABLE_INTEL_GNA=OFF \ -DENABLE_OV_TF_FRONTEND=OFF \ -DENABLE_OV_TF_LITE_FRONTEND=OFF \ -DENABLE_OV_PADDLE_FRONTEND=OFF \ diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 3c1df21a9cf..45a25797e37 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -617,18 +617,6 @@ jobs: run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_transformations_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-Transformations.xml - - name: Legacy Transformations func tests - if: fromJSON(needs.smart_ci.outputs.affected_components).GNA.test - shell: cmd - run: | - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_legacy_transformations_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-LegacyTransformations.xml - - - name: Inference Engine 1.0 unit tests - if: fromJSON(needs.smart_ci.outputs.affected_components).GNA.test - shell: cmd - run: | - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/InferenceEngineUnitTests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-InferenceEngineUnitTests.xml - - name: Common test utils tests shell: cmd run: | @@ -656,13 +644,7 @@ jobs: run: | call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_op_conformance_tests --gtest_print_time=1 --gtest_filter="*OpImpl*" --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TemplateOpImplTests.xml - - name: GNA plugin unit tests - if: fromJSON(needs.smart_ci.outputs.affected_components).GNA.test - shell: cmd - run: | - call "${{ env.INSTALL_DIR }}\\setupvars.bat" && ${{ env.INSTALL_TEST_DIR }}/ov_gna_unit_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-GNAUnitTests.xml - - - name: AUTO unit tests + - name: AUTO unit tests if: fromJSON(needs.smart_ci.outputs.affected_components).AUTO.test shell: cmd run: | diff --git a/.github/workflows/windows_conditional_compilation.yml b/.github/workflows/windows_conditional_compilation.yml index 57d8e327782..b21fa60686d 100644 --- a/.github/workflows/windows_conditional_compilation.yml +++ b/.github/workflows/windows_conditional_compilation.yml @@ -140,7 +140,6 @@ jobs: -DENABLE_TESTS=ON ` -DENABLE_CPPLINT=OFF ` -DENABLE_NCC_STYLE=OFF ` - -DENABLE_INTEL_GNA=OFF ` -DCMAKE_COMPILE_WARNING_AS_ERROR=ON ` -DENABLE_PROFILING_ITT=ON ` -DSELECTIVE_BUILD=COLLECT ` @@ -306,7 +305,6 @@ jobs: -DSELECTIVE_BUILD=ON ` -DENABLE_TEMPLATE=OFF ` -DENABLE_INTEL_GPU=OFF ` - -DENABLE_INTEL_GNA=OFF ` -DENABLE_OV_TF_FRONTEND=OFF ` -DENABLE_OV_TF_LITE_FRONTEND=OFF ` -DENABLE_OV_PADDLE_FRONTEND=OFF ` diff --git a/README.md b/README.md index af0d31bb5b8..80af816b80f 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ OpenVINO™ is an open-source toolkit for optimizing and deploying AI inference. - Reduce resource demands and efficiently deploy on a range of Intel® platforms from edge to cloud -This open-source version includes several components: namely [OpenVINO Model Converter (OVC)], [OpenVINO™ Runtime], as well as CPU, GPU, GNA, multi device and heterogeneous plugins to accelerate deep learning inference on Intel® CPUs and Intel® Processor Graphics. +This open-source version includes several components: namely [OpenVINO Model Converter (OVC)], [OpenVINO™ Runtime], as well as CPU, GPU, multi device and heterogeneous plugins to accelerate deep learning inference on Intel® CPUs and Intel® Processor Graphics. It supports pre-trained models from [Open Model Zoo], along with 100+ open source and public models in popular formats such as TensorFlow, ONNX, PaddlePaddle, MXNet, Caffe, Kaldi. @@ -82,12 +82,6 @@ The OpenVINO™ Runtime can infer models on different hardware devices. This sec openvino_intel_gpu_plugin Intel Processor Graphics, including Intel HD Graphics and Intel Iris Graphics - - GNA - Intel GNA - openvino_intel_gna_plugin - Intel Speech Enabling Developer Kit, Amazon Alexa* Premium Far-Field Developer Kit, Intel Pentium Silver J5005 Processor, Intel Pentium Silver N5000 Processor, Intel Celeron J4005 Processor, Intel Celeron J4105 Processor, Intel Celeron Processor N4100, Intel Celeron Processor N4000, Intel Core i3-8121U Processor, Intel Core i7-1065G7 Processor, Intel Core i7-1060G7 Processor, Intel Core i5-1035G4 Processor, Intel Core i5-1035G7 Processor, Intel Core i5-1035G1 Processor, Intel Core i5-1030G7 Processor, Intel Core i5-1030G4 Processor, Intel Core i3-1005G1 Processor, Intel Core i3-1000G1 Processor, Intel Core i3-1000G4 Processor - diff --git a/cmake/coverage.cmake b/cmake/coverage.cmake index 2f39ba2d93b..1f1c4c45548 100644 --- a/cmake/coverage.cmake +++ b/cmake/coverage.cmake @@ -89,13 +89,6 @@ if(ENABLE_INTEL_CPU) PREFIX "${OV_COVERAGE_BASE_DIRECTORY}") endif() -if(ENABLE_INTEL_GNA) - ov_coverage_extract(INPUT "openvino" OUTPUT "intel_gna_plugin" - PATTERNS "${OV_COVERAGE_BASE_DIRECTORY}/src/plugins/intel_gna/*") - ov_coverage_genhtml(INFO_FILE "intel_gna_plugin" - PREFIX "${OV_COVERAGE_BASE_DIRECTORY}") -endif() - if (ENABLE_INTEL_GPU) ov_coverage_extract(INPUT "openvino" OUTPUT "intel_gpu_plugin" PATTERNS "${OV_COVERAGE_BASE_DIRECTORY}/src/plugins/intel_gpu/*") diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index c90309ab294..169fa4fc889 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -221,47 +221,3 @@ Build oneTBB from sources and set TBBROOT environment var before OpenVINO cmake update_deps_cache(TBBBIND_2_5_ROOT "${TBBBIND_2_5}" "Path to TBBBIND_2_5 root folder") update_deps_cache(TBBBIND_2_5_DIR "${TBBBIND_2_5}/cmake" "Path to TBBBIND_2_5 cmake folder") endfunction() - -if(ENABLE_INTEL_GNA) - reset_deps_cache( - GNA_EXT_DIR - GNA_PLATFORM_DIR - GNA_KERNEL_LIB_NAME - GNA_LIBS_LIST - GNA_LIB_DIR - libGNA_INCLUDE_DIRS - libGNA_LIBRARIES_BASE_PATH) - set(GNA_VERSION "03.05.00.2116") - set(GNA_HASH "960350567702bda17276ac4c060d7524fb7ce7ced785004bd861c81ff2bfe2c5") - - set(FILES_TO_EXTRACT_LIST gna_${GNA_VERSION}/include) - if(WIN32) - LIST(APPEND FILES_TO_EXTRACT_LIST gna_${GNA_VERSION}/win64) - else() - LIST(APPEND FILES_TO_EXTRACT_LIST gna_${GNA_VERSION}/linux) - endif() - - RESOLVE_DEPENDENCY(GNA_EXT_DIR - ARCHIVE_UNIFIED "gna/gna_${GNA_VERSION}.zip" - TARGET_PATH "${TEMP}/gna_${GNA_VERSION}" - VERSION_REGEX ".*_([0-9]+.[0-9]+.[0-9]+.[0-9]+).*" - FILES_TO_EXTRACT FILES_TO_EXTRACT_LIST - SHA256 ${GNA_HASH} - USE_NEW_LOCATION TRUE) - update_deps_cache(GNA_EXT_DIR "${GNA_EXT_DIR}" "Path to GNA root folder") - debug_message(STATUS "gna=" ${GNA_EXT_DIR}) - - if (WIN32) - set(GNA_PLATFORM_DIR win64 CACHE STRING "" FORCE) - elseif (UNIX) - set(GNA_PLATFORM_DIR linux CACHE STRING "" FORCE) - else () - message(FATAL_ERROR "GNA not supported on this platform, only linux, and windows") - endif () - set(GNA_LIB_DIR x64 CACHE STRING "" FORCE) - set(GNA_PATH ${GNA_EXT_DIR}/${GNA_PLATFORM_DIR}/${GNA_LIB_DIR} CACHE STRING "" FORCE) - - if(NOT BUILD_SHARED_LIBS) - list(APPEND PATH_VARS "GNA_PATH") - endif() -endif() diff --git a/cmake/features.cmake b/cmake/features.cmake index 2a970e5720c..a4d19f116cb 100644 --- a/cmake/features.cmake +++ b/cmake/features.cmake @@ -103,13 +103,6 @@ endif() ov_dependent_option (ENABLE_TBBBIND_2_5 "Enable TBBBind_2_5 static usage in OpenVINO runtime" ${ENABLE_TBBBIND_2_5_DEFAULT} "THREADING MATCHES TBB; NOT APPLE" OFF) ov_dependent_option (ENABLE_TBB_RELEASE_ONLY "Only Release TBB libraries are linked to the OpenVINO Runtime binaries" ON "THREADING MATCHES TBB;LINUX" OFF) -ov_dependent_option (ENABLE_INTEL_GNA "GNA support for OpenVINO Runtime" ON - "NOT APPLE;NOT ANDROID;X86_64;CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5.4" OFF) - -ov_dependent_option (ENABLE_INTEL_GNA_DEBUG "GNA debug build" OFF "ENABLE_INTEL_GNA" OFF) -ov_dependent_option (ENABLE_V7_SERIALIZE "enables serialization to IR v7" OFF "ENABLE_INTEL_GNA" OFF) -ov_dependent_option (ENABLE_IR_V7_READER "Enables IR v7 reader" ${BUILD_SHARED_LIBS} "ENABLE_TESTS;ENABLE_INTEL_GNA" OFF) - ov_dependent_option (ENABLE_GAPI_PREPROCESSING "Enables G-API preprocessing" ON "NOT MINGW64" OFF) ov_option (ENABLE_MULTI "Enables MULTI Device Plugin" ON) diff --git a/cmake/packaging/debian.cmake b/cmake/packaging/debian.cmake index b4d2a8ac462..9db940fae07 100644 --- a/cmake/packaging/debian.cmake +++ b/cmake/packaging/debian.cmake @@ -51,8 +51,6 @@ macro(ov_cpack_settings) NOT item MATCHES "^${OV_CPACK_COMP_PYTHON_OPENVINO}_python.*" AND # because in case of .deb package, pyopenvino_package_python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR} is installed (NOT item MATCHES "^${OV_CPACK_COMP_PYTHON_OPENVINO_PACKAGE}_python.*" OR ENABLE_PYTHON_PACKAGING) AND - # see ticket # 82605 - NOT item STREQUAL "gna" AND # temporary block nvidia NOT item STREQUAL "nvidia" AND # don't install Intel OpenMP @@ -183,23 +181,6 @@ macro(ov_cpack_settings) set(gpu_copyright "generic") endif() - # intel-gna - if(ENABLE_INTEL_GNA AND "gna" IN_LIST CPACK_COMPONENTS_ALL) - set(CPACK_COMPONENT_GNA_DESCRIPTION "Intel® Gaussian Neural Accelerator inference plugin") - set(CPACK_COMPONENT_GNA_DEPENDS "${OV_CPACK_COMP_CORE}") - set(CPACK_DEBIAN_GNA_PACKAGE_NAME "libopenvino-intel-gna-plugin-${cpack_name_ver}") - # since we have libgna.so we need to call ldconfig and have `def_triggers` here - set(CPACK_DEBIAN_GNA_PACKAGE_CONTROL_EXTRA "${def_postinst};${def_postrm};${def_triggers}") - - ov_debian_add_lintian_suppression(gna - # package name matches libopenvino_intel_gna_plugin.so - # but lintian looks at libgna.so.2 since it's a versioned library - "package-name-doesnt-match-sonames") - set(gna_copyright "generic") - - _ov_add_plugin(gna OFF) - endif() - # # add pseudo plugins are recommended to core component # if(pseudo_plugins_recommends) # # see https://superuser.com/questions/70031/what-is-the-difference-between-recommended-and-suggested-packages-ubuntu. diff --git a/cmake/packaging/rpm.cmake b/cmake/packaging/rpm.cmake index c083fc2afb2..e6bb1aca1c5 100644 --- a/cmake/packaging/rpm.cmake +++ b/cmake/packaging/rpm.cmake @@ -37,8 +37,6 @@ macro(ov_cpack_settings) NOT item MATCHES "^${OV_CPACK_COMP_PYTHON_OPENVINO}_python.*" AND # because in case of .rpm package, pyopenvino_package_python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR} is installed (NOT item MATCHES "^${OV_CPACK_COMP_PYTHON_OPENVINO_PACKAGE}_python.*" OR ENABLE_PYTHON_PACKAGING) AND - # see ticket # 82605 - NOT item STREQUAL "gna" AND # temporary block nvidia NOT item STREQUAL "nvidia" AND # don't install Intel OpenMP @@ -179,15 +177,6 @@ macro(ov_cpack_settings) set(gpu_copyright "generic") endif() - # intel-gna - if(ENABLE_INTEL_GNA AND "gna" IN_LIST CPACK_COMPONENTS_ALL) - set(CPACK_COMPONENT_GNA_DESCRIPTION "Intel® Gaussian Neural Accelerator inference plugin") - set(CPACK_RPM_GNA_PACKAGE_REQUIRES "${core_package}") - set(CPACK_RPM_GNA_PACKAGE_NAME "libopenvino-intel-gna-plugin-${cpack_name_ver}") - _ov_add_package(plugin_packages gna) - set(gna_copyright "generic") - endif() - # # Frontends # diff --git a/cmake/templates/OpenVINOConfig.cmake.in b/cmake/templates/OpenVINOConfig.cmake.in index 470be5d17b1..6cf044d3927 100644 --- a/cmake/templates/OpenVINOConfig.cmake.in +++ b/cmake/templates/OpenVINOConfig.cmake.in @@ -417,20 +417,6 @@ macro(_ov_find_intel_gpu_dependencies) unset(_OV_ENABLE_ONEDNN_FOR_GPU) endmacro() -macro(_ov_find_intel_gna_dependencies) - set(_OV_ENABLE_INTEL_GNA "@ENABLE_INTEL_GNA@") - if(_OV_ENABLE_INTEL_GNA) - set_and_check(GNA_PATH "@PACKAGE_GNA_PATH@") - _ov_find_dependency(libGNA - COMPONENTS KERNEL - CONFIG - PATHS "${CMAKE_CURRENT_LIST_DIR}" - NO_DEFAULT_PATH) - unset(GNA_PATH) - endif() - unset(_OV_ENABLE_INTEL_GNA) -endmacro() - macro(_ov_find_protobuf_frontend_dependency) set(_OV_ENABLE_SYSTEM_PROTOBUF "@ENABLE_SYSTEM_PROTOBUF@") set(_OV_PROTOBUF_PACKAGE_CONFIG "@protobuf_config@") @@ -518,7 +504,6 @@ if(NOT _OV_ENABLE_OPENVINO_BUILD_SHARED) # plugin dependencies _ov_find_intel_cpu_dependencies() _ov_find_intel_gpu_dependencies() - _ov_find_intel_gna_dependencies() endif() _ov_find_dependency(Threads) diff --git a/docs/articles_en/about_openvino/system_requirements.rst b/docs/articles_en/about_openvino/system_requirements.rst index 7923e51be90..f6e32c4a0a3 100644 --- a/docs/articles_en/about_openvino/system_requirements.rst +++ b/docs/articles_en/about_openvino/system_requirements.rst @@ -81,7 +81,7 @@ GPU were used during OpenVINO internal validation: 22.43 for Ubuntu 22.04, 21.48 for Ubuntu 20.04 and 21.49 for Red Hat Enterprise Linux 8. -NPU and GNA +NPU ############################# .. tab-set:: @@ -91,13 +91,6 @@ NPU and GNA * Ubuntu 22.04 long-term support (LTS), 64-bit * Windows 11, 64-bit - .. tab-item:: Operating Systems for GNA - - * Ubuntu 22.04 long-term support (LTS), 64-bit - * Ubuntu 20.04 long-term support (LTS), 64-bit - * Windows 10, 64-bit - * Windows 11, 64-bit - .. tab-item:: Additional considerations * These Accelerators require drivers that are not included in the @@ -130,7 +123,7 @@ Operating systems and developer environment Higher versions of kernel might be required for 10th Gen Intel® Core™ Processors, 11th Gen Intel® Core™ Processors, 11th Gen Intel® Core™ Processors S-Series Processors, 12th Gen Intel® Core™ Processors, 13th Gen Intel® Core™ Processors, Intel® Core™ Ultra - Processors, or 4th Gen Intel® Xeon® Scalable Processors to support CPU, GPU, GNA or + Processors, or 4th Gen Intel® Xeon® Scalable Processors to support CPU, GPU or hybrid-cores CPU capabilities. .. tab-item:: Windows diff --git a/docs/articles_en/glossary.rst b/docs/articles_en/glossary.rst index 81224891f4b..24bbbd8b382 100644 --- a/docs/articles_en/glossary.rst +++ b/docs/articles_en/glossary.rst @@ -75,7 +75,7 @@ Glossary of terms used in OpenVINO™ | Number of images to analyze during one call of infer. Maximum batch size is a property of the model set before its compilation. In NHWC, NCHW, and NCDHW image data layout representations, the 'N' refers to the number of images in the batch. | *Device Affinity* -| A preferred hardware device to run inference (CPU, GPU, GNA, etc.). +| A preferred hardware device to run inference (CPU, GPU, NPU, etc.). | *Extensibility mechanism, Custom layers* | The mechanism that provides you with capabilities to extend the OpenVINO™ Runtime and model conversion API so that they can work with models containing operations that are not yet supported. @@ -87,7 +87,7 @@ Glossary of terms used in OpenVINO™ | The Conversion API is used to import and convert models trained in popular frameworks to a format usable by other OpenVINO components. Model conversion API is represented by a Python ``openvino.convert_model()`` method and ``ovc`` command-line tool. | *OpenVINO™ Core* -| OpenVINO™ Core is a software component that manages inference on certain Intel(R) hardware devices: CPU, GPU, GNA, etc. +| OpenVINO™ Core is a software component that manages inference on certain Intel(R) hardware devices: CPU, GPU, NPU, etc. | *OpenVINO™ API* | The basic default API for all supported devices, which allows you to load a model from Intermediate Representation or convert from ONNX, PaddlePaddle, TensorFlow, TensorFlow Lite file formats, set input and output formats and execute the model on various devices. diff --git a/docs/articles_en/openvino_workflow/deployment_intro/conditional_compilation_deployment.rst b/docs/articles_en/openvino_workflow/deployment_intro/conditional_compilation_deployment.rst index eff28154130..0f0e88070b9 100644 --- a/docs/articles_en/openvino_workflow/deployment_intro/conditional_compilation_deployment.rst +++ b/docs/articles_en/openvino_workflow/deployment_intro/conditional_compilation_deployment.rst @@ -245,7 +245,7 @@ Build OpenVINO with conditional compilation enabled: cd %OPENVINO_HOME% md build_cc cd build_cc - cmake -G Ninja -Wno-dev -DCMAKE_BUILD_TYPE=Debug -DENABLE_CPPLINT=OFF -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF -DENABLE_FASTER_BUILD=ON -DENABLE_SANITIZER=OFF -DTHREADING=TBB -DBUILD_SHARED_LIBS=OFF -DENABLE_PROFILING_ITT=ON -DSELECTIVE_BUILD=COLLECT -DENABLE_INTEL_GPU=OFF -DENABLE_INTEL_GNA=OFF -DENABLE_MULTI=OFF -DENABLE_AUTO=OFF -DENABLE_AUTO_BATCH=OFF -DENABLE_HETERO=OFF -DENABLE_TEMPLATE=OFF -DENABLE_OV_ONNX_FRONTEND=OFF -DENABLE_OV_PADDLE_FRONTEND=OFF -DENABLE_OV_PYTORCH_FRONTEND=OFF -DENABLE_OV_TF_FRONTEND=OFF -DCMAKE_INSTALL_PREFIX=install .. + cmake -G Ninja -Wno-dev -DCMAKE_BUILD_TYPE=Debug -DENABLE_CPPLINT=OFF -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF -DENABLE_FASTER_BUILD=ON -DENABLE_SANITIZER=OFF -DTHREADING=TBB -DBUILD_SHARED_LIBS=OFF -DENABLE_PROFILING_ITT=ON -DSELECTIVE_BUILD=COLLECT -DENABLE_INTEL_GPU=OFF -DENABLE_MULTI=OFF -DENABLE_AUTO=OFF -DENABLE_AUTO_BATCH=OFF -DENABLE_HETERO=OFF -DENABLE_TEMPLATE=OFF -DENABLE_OV_ONNX_FRONTEND=OFF -DENABLE_OV_PADDLE_FRONTEND=OFF -DENABLE_OV_PYTORCH_FRONTEND=OFF -DENABLE_OV_TF_FRONTEND=OFF -DCMAKE_INSTALL_PREFIX=install .. cmake --build . --config Debug @@ -278,7 +278,7 @@ Generate final optimal binaries size of OpenVINO package md build cd build - cmake -G "Visual Studio 16 2019" -A x64 -DENABLE_CPPLINT=OFF -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF -DCMAKE_BUILD_TYPE=Release -DENABLE_FASTER_BUILD=ON -DENABLE_PROFILING_ITT=OFF -DSELECTIVE_BUILD=ON -DENABLE_INTEL_GPU=OFF -DENABLE_INTEL_GNA=OFF -DENABLE_MULTI=OFF -DENABLE_AUTO=OFF -DENABLE_AUTO_BATCH=OFF -DENABLE_HETERO=OFF -DENABLE_TEMPLATE=OFF -DENABLE_OV_ONNX_FRONTEND=OFF -DENABLE_OV_PADDLE_FRONTEND=OFF -DENABLE_OV_PYTORCH_FRONTEND=OFF -DENABLE_OV_TF_FRONTEND=OFF -DSELECTIVE_BUILD_STAT=%OPENVINO_HOME%\cc_data\*.csv -DBUILD_SHARED_LIBS=OFF -DENABLE_LTO=ON -DENABLE_ONEDNN_FOR_GPU=OFF -DENABLE_GAPI_PREPROCESSING=OFF -DENABLE_OV_TF_LITE_FRONTEND=OFF -DENABLE_PROFILING_FIRST_INFERENCE=OFF .. + cmake -G "Visual Studio 16 2019" -A x64 -DENABLE_CPPLINT=OFF -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF -DCMAKE_BUILD_TYPE=Release -DENABLE_FASTER_BUILD=ON -DENABLE_PROFILING_ITT=OFF -DSELECTIVE_BUILD=ON -DENABLE_INTEL_GPU=OFF -DENABLE_MULTI=OFF -DENABLE_AUTO=OFF -DENABLE_AUTO_BATCH=OFF -DENABLE_HETERO=OFF -DENABLE_TEMPLATE=OFF -DENABLE_OV_ONNX_FRONTEND=OFF -DENABLE_OV_PADDLE_FRONTEND=OFF -DENABLE_OV_PYTORCH_FRONTEND=OFF -DENABLE_OV_TF_FRONTEND=OFF -DSELECTIVE_BUILD_STAT=%OPENVINO_HOME%\cc_data\*.csv -DBUILD_SHARED_LIBS=OFF -DENABLE_LTO=ON -DENABLE_ONEDNN_FOR_GPU=OFF -DENABLE_GAPI_PREPROCESSING=OFF -DENABLE_OV_TF_LITE_FRONTEND=OFF -DENABLE_PROFILING_FIRST_INFERENCE=OFF .. cmake --build . --config Release diff --git a/docs/dev/cmake_options_for_custom_compilation.md b/docs/dev/cmake_options_for_custom_compilation.md index c6eb28d536d..36ba866b32f 100644 --- a/docs/dev/cmake_options_for_custom_compilation.md +++ b/docs/dev/cmake_options_for_custom_compilation.md @@ -19,8 +19,6 @@ This document provides description and default values for CMake options that can * `ON` is default for x86 platforms; `OFF`, otherwise. * `ENABLE_INTEL_GPU` enables Intel GPU plugin compilation: * `ON` is default for x86 platforms; not available, otherwise. - * `ENABLE_INTEL_GNA` enables GNA plugin compilation: - * `ON` is default for x86 platforms; not available, otherwise. * `ENABLE_HETERO` enables HETERO plugin build: * `ON` is default. * `ENABLE_MULTI` enables MULTI plugin build: @@ -58,9 +56,6 @@ This document provides description and default values for CMake options that can * `ON` if requirements are satisfied (auto-discovered by CMake). * `ENABLE_TESTS` enables tests compilation: * `OFF` is default. -* `ENABLE_IR_V7_READER` enables IR v7 reader: - * `ON` is default. - **Note:** must be turned `OFF` when building OpenVINO runtime as static * `ENABLE_DOCS` enables building the OpenVINO documentation: * `OFF` is on Debian (Ubuntu) OSes * `OFF` is in other cases. diff --git a/docs/dev/static_libaries.md b/docs/dev/static_libaries.md index e538a37555f..7b00f9e5499 100644 --- a/docs/dev/static_libaries.md +++ b/docs/dev/static_libaries.md @@ -31,14 +31,12 @@ The default architecture of OpenVINO Runtime assumes that the following componen * (Device) Inference backends (CPU, GPU, MULTI, HETERO, etc.) * (Model) Frontends (IR, ONNX, PDPD, etc.) * Preprocessing library (to perform preprocessing, e.g. resize and color space conversions) -* IR v7 reader (used in legacy tests only, if you are not to going to run OpenVINO tests, set `-DENABLE_TESTS=OFF` which disables IR v7 reader) With the static OpenVINO Runtime, all these modules should be linked into a final user application and **the list of modules/configuration must be known for the CMake configuration stage**. To minimize the total binary size, you can explicitly turn `OFF` unnecessary components. Use [[CMake Options for Custom Compilation|CMakeOptionsForCustomCompilation ]] as a reference for OpenVINO CMake configuration. For example, to enable only IR v11 reading and CPU inference capabilities, use: ```sh cmake -DENABLE_INTEL_GPU=OFF \ - -DENABLE_INTEL_GNA=OFF \ -DENABLE_TEMPLATE=OFF \ -DENABLE_HETERO=OFF \ -DENABLE_MULTI=OFF \ @@ -49,7 +47,6 @@ cmake -DENABLE_INTEL_GPU=OFF \ -DENABLE_OV_TF_FRONTEND=OFF \ -DENABLE_OV_TF_LITE_FRONTEND=OFF \ -DENABLE_OV_PYTORCH_FRONTEND=OFF \ - -DENABLE_IR_V7_READER=OFF \ -DENABLE_GAPI_PREPROCESSING=OFF \ -DENABLE_INTEL_CPU=ON \ -DENABLE_OV_IR_FRONTEND=ON @@ -135,7 +132,6 @@ cmake -DCMAKE_TOOLCHAIN_FILE=/cmake/toolchains/mt.runtime.w * The enabled and tested capabilities of OpenVINO Runtime in a static build: * OpenVINO common runtime - work with `ov::Model`, perform model loading on particular device - * CPU and GNA inference plugins (**GPU is not enabled**) * MULTI, HETERO, AUTO, and BATCH inference modes * IR, ONNX, PDPD, and TF frontends to read `ov::Model` * Static build support for building static libraries only for OpenVINO Runtime libraries. All other third-party prebuilt dependencies remain in the same format: diff --git a/src/cmake/openvino.cmake b/src/cmake/openvino.cmake index 72fecabd929..355d7ed13f1 100644 --- a/src/cmake/openvino.cmake +++ b/src/cmake/openvino.cmake @@ -54,12 +54,6 @@ endif() if(NOT BUILD_SHARED_LIBS) target_compile_definitions(${TARGET_NAME} PUBLIC OPENVINO_STATIC_LIBRARY) - - # TODO: remove together we GNA plugin - # for static linkage the dependencies are in opposite order - if(TARGET inference_engine_ir_v7_reader) - target_link_libraries(${TARGET_NAME} PRIVATE inference_engine_ir_v7_reader) - endif() endif() if(WIN32) diff --git a/src/inference/CMakeLists.txt b/src/inference/CMakeLists.txt index 768e7cf1185..6525d181c02 100644 --- a/src/inference/CMakeLists.txt +++ b/src/inference/CMakeLists.txt @@ -23,14 +23,6 @@ file (GLOB LIBRARY_SRC set(OV_STATIC_DEPENDENT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/file_utils.cpp) list(REMOVE_ITEM LIBRARY_SRC ${OV_STATIC_DEPENDENT_FILES}) -if(BUILD_SHARED_LIBS OR ENABLE_IR_V7_READER) - # TODO: remove together with GNA plugin - # we have unconditional adding of the ENABLE_IR_V7_READER compile definition for shared libs case - # to avoid rebuild, relink during work with build tree - set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/ie_network_reader.cpp PROPERTIES - COMPILE_DEFINITIONS "ENABLE_IR_V7_READER") -endif() - file (GLOB LIBRARY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h ${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp diff --git a/src/inference/include/openvino/runtime/core.hpp b/src/inference/include/openvino/runtime/core.hpp index 153559c17e0..ea31992ce1e 100644 --- a/src/inference/include/openvino/runtime/core.hpp +++ b/src/inference/include/openvino/runtime/core.hpp @@ -667,7 +667,7 @@ public: * @brief Returns devices available for inference. * Core objects go over all registered plugins and ask about available devices. * - * @return A vector of devices. The devices are returned as { CPU, GPU.0, GPU.1, GNA }. + * @return A vector of devices. The devices are returned as { CPU, GPU.0, GPU.1, NPU }. * If there is more than one device of a specific type, they are enumerated with the .# suffix. * Such enumerated device can later be used as a device name in all Core methods like Core::compile_model, * Core::query_model, Core::set_property and so on. diff --git a/src/inference/src/dev/core_impl.hpp b/src/inference/src/dev/core_impl.hpp index f7cd4a781ab..86365f891fc 100644 --- a/src/inference/src/dev/core_impl.hpp +++ b/src/inference/src/dev/core_impl.hpp @@ -286,7 +286,7 @@ public: /** * @brief Returns devices available for neural networks inference * - * @return A vector of devices. The devices are returned as { CPU, GPU.0, GPU.1, GNA } + * @return A vector of devices. The devices are returned as { CPU, GPU.0, GPU.1, NPU } * If there more than one device of specific type, they are enumerated with .# suffix. */ std::vector GetAvailableDevices() const override; diff --git a/src/inference/src/ie_network_reader.cpp b/src/inference/src/ie_network_reader.cpp index f5aca3586e8..b9543193a58 100644 --- a/src/inference/src/ie_network_reader.cpp +++ b/src/inference/src/ie_network_reader.cpp @@ -19,13 +19,7 @@ #include "ie_common.h" #include "ie_icnn_network.hpp" #include "ie_input_info.hpp" -#include "openvino/frontend/manager.hpp" -#include "openvino/runtime/shared_buffer.hpp" -#ifdef ENABLE_IR_V7_READER -# include "legacy/ie_ir_version.hpp" -#endif #include "itt.hpp" -#include "legacy/ie_reader.hpp" #include "legacy_op_extension.hpp" #include "ngraph/function.hpp" #include "ngraph/type/element_type.hpp" @@ -33,6 +27,8 @@ #include "openvino/core/except.hpp" #include "openvino/core/preprocess/pre_post_process.hpp" #include "openvino/core/type/element_type.hpp" +#include "openvino/frontend/manager.hpp" +#include "openvino/runtime/shared_buffer.hpp" #include "openvino/util/shared_object.hpp" #include "so_ptr.hpp" #include "transformations/rt_info/old_api_map_order_attribute.hpp" @@ -40,179 +36,6 @@ namespace InferenceEngine { -#ifdef ENABLE_IR_V7_READER - -/** - * @brief This class is a wrapper for reader interfaces - */ -class Reader : public IReader { -# ifdef OPENVINO_STATIC_LIBRARY - using ReaderPtr = std::shared_ptr; -# else - using ReaderPtr = ov::SoPtr; -# endif - ReaderPtr ptr; - -public: - using Ptr = std::shared_ptr; - - explicit Reader(const std::string& location) { -# ifdef OPENVINO_STATIC_LIBRARY - // call library creator directly, since we are in the same application - InferenceEngine::CreateReader(ptr); - OPENVINO_ASSERT(ptr != nullptr, "Failed to create static version of IR v7 reader"); -# else - ov::util::FilePath libraryPath = ov::util::to_file_path(FileUtils::makePluginLibraryName({}, location)); - ov::util::FilePath readersLibraryPath = FileUtils::makePath(getInferenceEngineLibraryPath(), libraryPath); - - if (FileUtils::fileExist(readersLibraryPath)) { - libraryPath = readersLibraryPath; - } - - auto so = ov::util::load_shared_object(libraryPath.c_str()); - std::shared_ptr plugin_impl; - using createFunc = void(std::shared_ptr&); - reinterpret_cast(ov::util::get_symbol(so, "CreateReader"))(plugin_impl); - ptr = {plugin_impl, so}; -# endif // OPENVINO_STATIC_LIBRARY - } - - bool supportModel(std::istream& model) const override { - OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Reader::supportModel"); - return ptr->supportModel(model); - } - - CNNNetwork read(std::istream& model, const std::vector& exts) const override { - return ptr->read(model, exts); - } - - CNNNetwork read(std::istream& model, - const Blob::CPtr& weights, - const std::vector& exts) const override { - return ptr->read(model, weights, exts); - } - - std::vector getDataFileExtensions() const override { - return ptr->getDataFileExtensions(); - } -}; - -namespace { - -Reader::Ptr reader_irv7 = nullptr; - -void registerReaders() { - OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "registerReaders"); - static bool initialized = false; - static std::mutex readerMutex; - std::lock_guard lock(readerMutex); - if (initialized) - return; - - initialized = true; - - // try to load IR reader v7 if library exists - try { - reader_irv7 = - std::make_shared(std::string("inference_engine_ir_v7_reader") + std::string(OV_BUILD_POSTFIX)); - } catch (const std::runtime_error&) { - // runtime error is thrown in case of library cannot be loaded - } -} - -void assertIfIRv7LikeModel(std::istream& modelStream) { - auto irVersion = details::get_ir_version(modelStream); - bool isIRv7 = irVersion > 1 && irVersion <= 7; - - if (!isIRv7 || reader_irv7) - return; - - IE_THROW() << "The support of IR v" << irVersion - << " has been removed from the product. " - "Please, convert the original model using the Model Optimizer which comes with this " - "version of the OpenVINO to generate supported IR version."; -} - -CNNNetwork load_ir_v7_network(const std::string& modelPath, - const std::string& binPath, - const std::vector& exts) { - // Fix unicode name -# if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - std::wstring model_path = ov::util::string_to_wstring(modelPath.c_str()); -# else - std::string model_path = modelPath; -# endif - - if (ov::util::directory_exists(modelPath)) { - return {}; - } - - // Try to open model file - std::ifstream modelStream(model_path.c_str(), std::ios::binary); - if (!modelStream.is_open()) - IE_THROW() << "Model file " << modelPath << " cannot be opened!"; - - assertIfIRv7LikeModel(modelStream); - - // Check that reader supports the model - if (reader_irv7 && reader_irv7->supportModel(modelStream)) { - // Find weights - std::string bPath = binPath; - if (bPath.empty()) { - auto pathWoExt = modelPath; - auto pos = modelPath.rfind('.'); - if (pos != std::string::npos) - pathWoExt = modelPath.substr(0, pos); - for (const auto& ext : reader_irv7->getDataFileExtensions()) { - bPath = pathWoExt + "." + ext; - if (!FileUtils::fileExist(bPath)) { - bPath.clear(); - } else { - break; - } - } - } - if (!bPath.empty()) { - // Open weights file -# if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - std::wstring weights_path = ov::util::string_to_wstring(bPath.c_str()); -# else - std::string weights_path = bPath; -# endif - std::ifstream binStream; - binStream.open(weights_path.c_str(), std::ios::binary); - if (!binStream.is_open()) - IE_THROW() << "Weights file " << bPath << " cannot be opened!"; - - binStream.seekg(0, std::ios::end); - size_t fileSize = binStream.tellg(); - binStream.seekg(0, std::ios::beg); - - Blob::Ptr weights = make_shared_blob({Precision::U8, {fileSize}, C}); - - { - OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::ReadTime, "ReadNetworkWeights"); - weights->allocate(); - binStream.read(weights->buffer(), fileSize); - binStream.close(); - } - - // read model with weights - auto network = reader_irv7->read(modelStream, weights, exts); - modelStream.close(); - return network; - } - // read model without weights - return reader_irv7->read(modelStream, exts); - } - - return {}; -} - -} // namespace - -#endif // ENABLE_IR_V7_READER - namespace { CNNNetwork convert_to_cnnnetwork(std::shared_ptr& function, @@ -297,20 +120,6 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath, bool is_new_api, bool enable_mmap) { auto exts = ov::legacy_convert::convert_extension(ov_exts); -#ifdef ENABLE_IR_V7_READER - // IR v7 obsolete code - { - // Register readers if it is needed - registerReaders(); - auto cnnnetwork = load_ir_v7_network(modelPath, binPath, exts); - - OPENVINO_SUPPRESS_DEPRECATED_START - if (static_cast(cnnnetwork) != nullptr) { - return cnnnetwork; - } - OPENVINO_SUPPRESS_DEPRECATED_END - } -#endif // ENABLE_IR_V7_READER // Fix unicode name #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) @@ -366,21 +175,6 @@ CNNNetwork details::ReadNetwork(const std::string& model, std::istream& modelStream = modelStringStream; auto exts = ov::legacy_convert::convert_extension(ov_exts); -#ifdef ENABLE_IR_V7_READER - // IR v7 obsolete code - { - // Register readers if it is needed - registerReaders(); - assertIfIRv7LikeModel(modelStream); - - if (reader_irv7 && reader_irv7->supportModel(modelStream)) { - if (weights) - return reader_irv7->read(modelStream, weights, exts); - return reader_irv7->read(modelStream, exts); - } - } -#endif // ENABLE_IR_V7_READER - // Try to load with FrontEndManager ov::frontend::FrontEndManager manager; ov::frontend::FrontEnd::Ptr FE; diff --git a/src/plugins/auto/src/plugin_config.cpp b/src/plugins/auto/src/plugin_config.cpp index c8e32fc68c2..bfc09210a68 100644 --- a/src/plugins/auto/src/plugin_config.cpp +++ b/src/plugins/auto/src/plugin_config.cpp @@ -8,7 +8,7 @@ namespace auto_plugin { // AUTO will enable the blocklist if // 1.No device priority passed to AUTO/MULTI.(eg. core.compile_model(model, "AUTO", configs);) // 2.No valid device parsed out from device priority (eg. core.compile_model(model, "AUTO:-CPU,-GPU", configs);). -const std::set PluginConfig::device_block_list = {"NPU", "GNA", "notIntelGPU"}; +const std::set PluginConfig::device_block_list = {"NPU", "notIntelGPU"}; PluginConfig::PluginConfig() { set_default(); diff --git a/src/plugins/intel_gna/CMakeLists.txt b/src/plugins/intel_gna/CMakeLists.txt deleted file mode 100644 index ce51c8fc88a..00000000000 --- a/src/plugins/intel_gna/CMakeLists.txt +++ /dev/null @@ -1,141 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -if (NOT ENABLE_INTEL_GNA) - return() -endif() - -# GNA plugin will be removed before 2024.0 together with API 1.0 -ov_disable_deprecated_warnings() - -add_subdirectory(legacy) - -set(TARGET_NAME "openvino_intel_gna_plugin") - -if (ENABLE_INTEL_GNA_DEBUG) - add_compile_definitions(GNA_DEBUG) -endif() - -file(GLOB_RECURSE SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) - -file(GLOB_RECURSE HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp) - -# build avx2.cpp with AVX2 support, only for Windows -if(ENABLE_AVX2 AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - ov_avx2_optimization_flags(avx2_flags) - set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/pre_post_process/hw_accelerated_converter_avx2.cpp PROPERTIES COMPILE_OPTIONS "${avx2_flags}") - add_compile_definitions(HAVE_AVX2=1) -endif() - - -find_package(libGNA REQUIRED - CONFIG - PATHS "${CMAKE_CURRENT_SOURCE_DIR}/cmake" - NO_DEFAULT_PATH - NO_CMAKE_FIND_ROOT_PATH) - -# -# Shared plugin library -# - -ov_add_plugin(NAME ${TARGET_NAME} - DEVICE_NAME "GNA" - SOURCES ${SOURCES} ${HEADERS} - VERSION_DEFINES_FOR src/gna_plugin_entry_points.cpp - ADD_CLANG_FORMAT) - -# Enable support of CC for the plugin -ov_mark_target_as_cc(${TARGET_NAME}) - -target_link_libraries(${TARGET_NAME} PRIVATE inference_engine_legacy - Threads::Threads libGNA) -target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) - -target_compile_definitions(${TARGET_NAME} - PRIVATE - _NO_MKL_ - ) - -# must be called after all target_link_libraries -ov_add_api_validator_post_build_step(TARGET ${TARGET_NAME}) - -# -# Static version for tests -# - -add_library(${TARGET_NAME}_test_static STATIC EXCLUDE_FROM_ALL ${SOURCES} ${HEADERS}) - -ov_add_version_defines(src/gna_plugin_entry_points.cpp ${TARGET_NAME}_test_static) - -target_compile_definitions(${TARGET_NAME}_test_static - PRIVATE - _NO_MKL_ - IMPLEMENT_INFERENCE_ENGINE_PLUGIN - PUBLIC - INTEGER_LOW_P - USE_STATIC_IE) - -target_link_libraries(${TARGET_NAME}_test_static PUBLIC inference_engine_s inference_engine_transformations libGNA::API) -target_include_directories(${TARGET_NAME}_test_static - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - $ - PRIVATE - $) - -set_target_properties(${TARGET_NAME} ${TARGET_NAME}_test_static - PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) - -# install - -if(BUILD_SHARED_LIBS) - set(gna_component gna) -else() - # during static build all plugins are part of the core, thus the dependencies as well - set(gna_component ${OV_CPACK_COMP_CORE}) -endif() - -file(GLOB_RECURSE gna_libraries "${libGNA_LIBRARIES_BASE_PATH}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*") -set(gna_library_installed OFF) - -foreach(gna_lib IN LISTS gna_libraries) - # install only versioned files like libgna.so.N or libgna.so.N.M - # and don't install global symlink libgna.so. Exceptions: - # 1. On Windows we don't have libraries versioning and need to install all .dlls - # 2. For case of static libraries we also need to install .so since it's required for linkage with final application - if(gna_lib MATCHES "^.*\.${CMAKE_SHARED_LIBRARY_SUFFIX}(\.[0-9]+)+$" OR WIN32 OR NOT BUILD_SHARED_LIBS) - install(FILES ${gna_lib} - DESTINATION ${OV_CPACK_RUNTIMEDIR} - COMPONENT ${gna_component}) - set(gna_library_installed ON) - endif() -endforeach() - -if(NOT gna_library_installed) - message(FATAL_ERROR "Failed to install GNA library (available libraries: ${gna_libraries})") -endif() - -# additional install rules for case of static libraries - -if(NOT BUILD_SHARED_LIBS) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/libGNAConfig.cmake ${CMAKE_BINARY_DIR} COPYONLY) - install(FILES "${CMAKE_BINARY_DIR}/libGNAConfig.cmake" - DESTINATION ${OV_CPACK_IE_CMAKEDIR} - COMPONENT ${gna_component} - ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL}) - - # install .lib file on Windows - if(WIN32) - file(GLOB_RECURSE gna_libraries "${libGNA_LIBRARIES_BASE_PATH}/*${CMAKE_STATIC_LIBRARY_SUFFIX}") - install(FILES ${gna_libraries} - DESTINATION ${OV_CPACK_LIBRARYDIR} - COMPONENT ${gna_component} - ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL}) - endif() -endif() - -add_subdirectory(tests) diff --git a/src/plugins/intel_gna/cmake/libGNAConfig.cmake b/src/plugins/intel_gna/cmake/libGNAConfig.cmake deleted file mode 100644 index 299f4d2d7c4..00000000000 --- a/src/plugins/intel_gna/cmake/libGNAConfig.cmake +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -# -# The module defines several imported targets: -# -# - (Optional) libGNA::API -# - (Optional) libGNA::KERNEL -# -# And high-level imported interface target: -# -# - libGNA -# -# And the following variables: -# -# - libGNA_API_FOUND -# - libGNA_KERNEL_FOUND -# -# The example usage: -# -# find_package(libGNA NO_MODULE COMPONENTS API KERNEL) -# - -set(libGNA_FOUND ON) - -set(GNA_KERNEL_LIB_NAME gna CACHE STRING "" FORCE) - -if(NOT libGNA_FIND_COMPONENTS) - set(libGNA_FIND_COMPONENTS "API;KERNEL") -endif() - -foreach (_gna_component ${libGNA_FIND_COMPONENTS}) - set(libGNA_${_gna_component}_FOUND OFF) - set(libGNA_FIND_REQUIRED_${_gna_component} ON) -endforeach() - -set(libGNA_LIBRARIES_BASE_PATH ${GNA_PATH} CACHE STRING "" FORCE) - -if(libGNA_FIND_REQUIRED_KERNEL AND NOT TARGET libGNA::KERNEL) - find_library(GNA_KERNEL_LIBRARY ${GNA_KERNEL_LIB_NAME} - HINTS ${libGNA_LIBRARIES_BASE_PATH} - NO_CMAKE_FIND_ROOT_PATH) - - if(GNA_KERNEL_LIBRARY) - add_library(libGNA::KERNEL SHARED IMPORTED) - set_property(TARGET libGNA::KERNEL APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) - if(WIN32) - set(gna_dll "${CMAKE_SHARED_LIBRARY_PREFIX}${GNA_KERNEL_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}") - set_target_properties(libGNA::KERNEL PROPERTIES - IMPORTED_LOCATION_RELEASE "${libGNA_LIBRARIES_BASE_PATH}/${gna_dll}" - IMPORTED_IMPLIB_RELEASE "${GNA_KERNEL_LIBRARY}") - else() - set_target_properties(libGNA::KERNEL PROPERTIES - IMPORTED_LOCATION_RELEASE "${GNA_KERNEL_LIBRARY}" - INTERFACE_LINK_OPTIONS "-Wl,-rpath-link,${libGNA_LIBRARIES_BASE_PATH}") - endif() - else() - message(SEND_ERROR "GNA KERNEL library (${GNA_KERNEL_LIB_NAME}) was not found in ${libGNA_LIBRARIES_BASE_PATH}") - endif() -endif() - -if(libGNA_FIND_REQUIRED_API AND NOT TARGET libGNA::API) - find_path(libGNA_INCLUDE_DIRS gna2-api.h - PATHS "${GNA_EXT_DIR}/include" - NO_CMAKE_FIND_ROOT_PATH) - if(libGNA_INCLUDE_DIRS) - add_library(libGNA::API INTERFACE IMPORTED) - set_target_properties(libGNA::API PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${libGNA_INCLUDE_DIRS}") - else() - message(SEND_ERROR "GNA API headers (gna2-api.h) was not found in ${GNA_EXT_DIR}/include") - endif() -endif() - -if(TARGET libGNA::KERNEL) - set(libGNA_KERNEL_FOUND ON) -endif() - -if(TARGET libGNA::API) - set(libGNA_API_FOUND ON) -endif() - -if(NOT TARGET libGNA) - add_library(libGNA INTERFACE IMPORTED) - foreach(_lib_name IN LISTS libGNA_FIND_COMPONENTS) - set_property(TARGET libGNA APPEND PROPERTY INTERFACE_LINK_LIBRARIES libGNA::${_lib_name}) - endforeach() -endif() diff --git a/src/plugins/intel_gna/docs/transformations.md b/src/plugins/intel_gna/docs/transformations.md deleted file mode 100644 index 66510780a31..00000000000 --- a/src/plugins/intel_gna/docs/transformations.md +++ /dev/null @@ -1,97 +0,0 @@ -# GNA transformations documentation - -GNA Plugin provides implementation of multiple methods required by OpenVINO plugin API. Original model usually consists of variety of operations, i.e. Convolution, Add, Gather, LSTMSequence and so on. GNA Hardware is its own limitation and not all operations can be executed on GNA Hardware. -One of the main functionalities for GNA Plugin is conversion of source network to equivalent network which could be executed on the GNA hardware. This conversion is done in LoadNetwok method. - -## LoadNetwork - -GNAPlugin::LoadNetwork in the future should execute following stages: -- Converting input graph to fully GNA-supported graph (all in ngraph) -- Creating and connecting GNA primitives within libGNA from ngraph-based network - -These stages include: -- Obtain ngraph-based network from the CNNNetwork argument (if input is not ngraph-based, proceed to CNNNetwork passes stage) -- Pass ngraph-based network through ngraph-based transformations. -- Convert ngraph-based network to CNNNetwork-based -- Pass network through CNNNetwork-based transformations. -- Creating and connecting GNA primitives withing libGNA from CNNNetwork-bases graph -Transformations are the way of modifying input graph. Ngraph-based transformations usually are of the following types: -- inherited from ov::pass::ModelPass. They implement run_on_model method. It allows them to be a container of other transformations. For example, ngraph::pass::CommonOptimizations executes multiple transformations in it. Each of them do some basic transformations. -- inherited from ov::pass::MatcherPass. Such transformations usually have a constructor. That constructor defines a pattern with the several connected together layers and a function that modifies found group of layers. The pattern can also handle additional predicates that do any checks on the traversed nodes. It is preferable to use that predicates explicitly rather than check and return from the transform function. -GNA-specific ngraph-based transformations are placed in src/plugins/intel_gna/src/transformations. All transformations should have brief comments in their headers. That brief should describe what pattern transformation handles and what modifications do. -There is also a directory src/plugins/intel_gna/src/transformations/rt_info with auxiliary runtime attributes. That attributes could be added into node rt_info map. That attributes can be read/write in transformations which is useful in some cases. For example, transformation can proceed some node in a special way if the node has special attribute. -All new transformations should have unit tests, that are placed in src/plugins/intel_gna/tests/unit/transformations. All that unit tests are compiled in ov_gna_unit_tests binary. -CNNNetwork transformations are so-called passes. They are placed in src/plugins/intel_gna/src/optimizer/gna_pass_manager.cpp. Passes proceed network as a -``` -std::vector * pLayers -``` -It is preferrable to write new transformations as nGraph passes and avoid implementing CNNNetwork passes. All CNNNetwork related code is considered as a legacy. Existed CNNNetwork passes are ported to ngraph. - -## GNA ngraph-based layers - -OpenVino allows to work with graph nodes as ov::Node class instances. Most of them are stored in src/core/include/openvino/op directory and could be used by all plugins. GNA plugin stores own (GNA-specific) layer types. -1. src/plugins/intel_gna/legacy/include/legacy/ngraph_ops -Here there are legacy layer types. Their names ends with “IE”. These types cannot be in graph, that pass to GNA plugin. All of these types are created within GNA transformations and used in GNA graph compiler for creating libGNA primitives. There are plans to rewrite all legacy code. These legacy types should be removed after that. -2. src/plugins/intel_gna/src/ops -GNA-specific operations. For example, GNAConvolution type describes convolution layers. It differs from common OpenVino Convolution type as it handles NHWC data layout instead of NCHW. -Ngraph-based transformations -1. Transformations that are common for all OpenVino plugins (are placed outside GNA plugin directory). These transformations perform different optimizations. For example, ov::pass::ConvertDivide transforms Divide operation into the sequence of nodes with Power layer. LSTMCellDecomposition extracts LSTMCell into subgraph of mathematical operations. -2. Transformations that are specific for the GNA plugin (are placed inside GNA plugin directory) -They also include src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy directory with ngraph-based legacy transformations. These transformations produce “IE” layers. After rewriting GNA legacy code these transformations should be removed. - -### "Layout transformations" -There are group of transformations that work with data layout. GNA-hardware supports MaxPool and Convolution operations in a different way in comparison to OpenVino common types. GNA supports NHWC layout, OpenVino supports NCHW layout. -There are group of transformations ReplaceGnaNHWCLayers that substitutes common types with NCHW layout to GNA-specific types with NHWC layout. It is done with wrapping GNA-types with transpose operations, that converts layout on input and output of GNA-types. Unfortunately, in most situations GNA hardware cannot execute these transpose operations. To solve this issue, there are transformations that allows to push transposes through layers from GNA-specific NHWC layers to the start and end of the graph, exchanging Transpose/Gather layer with neighbor layer. Some of them (for example, TransposeSinking group of transformations) allows to push transpose layers through multiple layer types. These transformations are common for all OpenVino and stores outside GNA plugin code. They are not able to push Transpose layer through Reshape type nodes due to mathematical reasons. -To push Transpose operation through Reshape nodes there are transformations that substitute Transpose + Reshape pattern with Reshape + Gather. Gather operation is not supported by the GNA hardware and it should also be pushed through the graph to the start and end. There are group of transformations that does it. -Transpose/Gather sinking consists of multiple transformations. Each of these transformations works with a small pattern consisting of Transpose/Gather and a node with a specific kind of layers (for example, with binary elementwise operations). Sinking transformation interchanges layers. After each sinking transformation execution Transpose/Gather layer moves through one layer in the graph. There are multiple nodes between start/end of the graph and initial Transpose/Gather layer position. Node types can repeat multiple times while sinking and are going in a arbitrary order. The same Transpose/Sinking transformation should be executed multiple times. They use register_new_node functionality. This method adds new created Transpose/Gather node at the end of the matcher pass queue to allow the same transformation be executed once again without necessity to call it implicitly once again. -TransposeSinking changes Concat and Split axis while pushing Transpose nodes through them. GNA doesn't support all possible Concat and Split axis. Some TransposeSinking transformations support callbacks. These callbacks are executed inside transformations and allow to add plugin specific checks. In these checks, GNA plugin prevents sinking transposes that would make some Split/Concats unsupported. -As Transpose and Gather layers are moved to start and end of the graph they are cut from the graph and moved to ov::intel_gna::PrePostProcessModels structure as separate models. On each network inference plugin searches in this structure model for input/output, executes this model on CPU and copy resulted data as input/output of the entire model. - TransposeSinking group of transformations doesn’t support currently StridedSlice layer. It leads to the next problem. -GNA plugin has the following Slice layer flow: -- SliceToStridedSlice transformation in CommonOptimizations converts Slice to StridedSlice -- ConvertStridedSliceToCropMatcher transformation convers StridedSlice to CropIE -- convertFunctionToICNNNetwork converts CropIE to CNNNetwork CropLayer -- GNA graph compiler converts CropLayer into affine layer -Since TransposeSInking is called after common optimizations it cannot push Transpose through the StridedSlice. If we have Slice operation in the original model we should prevent converting Slice to StridedSlice in common optimization. It is done by next steps: -- Disable execution of SliceToStridedSlice transformation -- Execute entire set of ngraph-based transformations -- Execute a set of transformations to convert Slice -> StridedSlice -> CropIE nodes -When StridedSlice layer will be supported by TransposeSInking these steps could be removed from GNA plugin pipeline. - -## CNNNetwork based passes - -After running ngraph-based transformations model is converted with function convertFunctionToICNNNetwork into CNNNetwork-based function. The next step is the model transformation with the CNNNetwork-based passes. -All the legacy CNNNetwork-based passes are stored in src/plugins/intel_gna/src/optimizer/gna_pass_manager.cpp. One of the main difference between legacy passes and ngraph transformations is that legacy passes doesn’t have pattern matching functionality. Each of the passes iterating through the graph nodes (previously sorting toplogical) searching for sought sequence of layers and modify them. -It should be mentioned that ngraph API stores constant data as input nodes with type Constant, but CNNNetwork API stores data as a BLOB in layer info. - -## Debugging - -There is an ability to dump model between transformations/passes. -To dump CNNNetwork passes use -DENABLE_INTEL_GNA_DEBUG=ON option to cmake build configuration. After plugin execution, *.dot files representing the final graph will be saved in the current working directory; *.dot files can be converted to an image with the graphviz dot executable, for example: -``` -dot -Tpng -o -``` -To dump CNNNetwork-based model in xml add -``` -#define ENABLE_V7_SERIALIZE -``` -to src/plugins/intel_gna/src/log/debug.hpp - -To dump model between ngraph-based transformations use VisualizeTree and Serialize transformations. - -### VisualizeTree - -VisualizeTree transformation allows to dump model as image. -``` -#include "openvino/pass/visualize_tree.hpp" -manager.register_pass("./dump.png"); -``` - -### Serialize - -Serialize transformation allows to dump model as xml and binary files that could be loaded in neutron web application -``` -#include "openvino/pass/serialize.hpp" -manager.register_pass("./dump.xml", "./dump.bin"); -``` -Where, manager is the ov::pass::Manager instance. diff --git a/src/plugins/intel_gna/legacy/CMakeLists.txt b/src/plugins/intel_gna/legacy/CMakeLists.txt deleted file mode 100644 index 33915b9ccd4..00000000000 --- a/src/plugins/intel_gna/legacy/CMakeLists.txt +++ /dev/null @@ -1,92 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -set(TARGET_NAME "inference_engine_legacy") - -set(PUBLIC_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") - -file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp) -file(GLOB_RECURSE PUBLIC_HEADERS ${PUBLIC_HEADERS_DIR}/*.hpp - ${PUBLIC_HEADERS_DIR}/*.h) - -# Create named folders for the sources within the .vcproj -# Empty name lists them directly under the .vcproj - -source_group("src" FILES ${LIBRARY_SRC}) -source_group("include" FILES ${PUBLIC_HEADERS}) - -if(ENABLE_V7_SERIALIZE) - set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/src/cnn_network_impl.cpp" - PROPERTIES COMPILE_DEFINITIONS ENABLE_V7_SERIALIZE) -endif() - -# Create object library - -add_library(${TARGET_NAME}_obj OBJECT EXCLUDE_FROM_ALL - ${LIBRARY_SRC} - ${PUBLIC_HEADERS}) - -ov_build_target_faster(${TARGET_NAME}_obj - PCH PRIVATE "src/precomp.hpp") - -target_include_directories(${TARGET_NAME}_obj PRIVATE - ${PUBLIC_HEADERS_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/src - $/src # For CNNNetworkNGraphImpl - $ - $ - $/src/ops) - -target_compile_definitions(${TARGET_NAME}_obj PRIVATE $) - -target_link_libraries(${TARGET_NAME}_obj PRIVATE openvino::itt) - -ov_add_clang_format_target(${TARGET_NAME}_obj_clang FOR_TARGETS ${TARGET_NAME}_obj) - -# Create static library - -add_library(${TARGET_NAME} STATIC EXCLUDE_FROM_ALL - $) - -target_link_libraries(${TARGET_NAME} PUBLIC openvino::runtime - PRIVATE openvino::pugixml openvino::itt openvino::runtime::dev) - -target_include_directories(${TARGET_NAME} INTERFACE - $) - -# Compile with USE_STATIC_IE - -add_library(${TARGET_NAME}_s STATIC EXCLUDE_FROM_ALL - ${LIBRARY_SRC} - ${PUBLIC_HEADERS}) - -target_compile_definitions(${TARGET_NAME}_s PUBLIC USE_STATIC_IE) - -target_include_directories(${TARGET_NAME}_s - PUBLIC - $ - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/src - $/src # For CNNNetworkNGraphImpl - $ - $ - $/src/ops) - -set_target_properties(${TARGET_NAME}_s PROPERTIES - EXCLUDE_FROM_ALL ON - INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) - -# LTO - -set_target_properties(${TARGET_NAME} ${TARGET_NAME}_obj - PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) - -# install - -ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE} OPTIONAL) - -if(ENABLE_TESTS) - add_subdirectory(tests) -endif() diff --git a/src/plugins/intel_gna/legacy/include/legacy/cnn_network_impl.hpp b/src/plugins/intel_gna/legacy/include/legacy/cnn_network_impl.hpp deleted file mode 100644 index fbb2a32ba71..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/cnn_network_impl.hpp +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include -#include -#include -#include -#include - -#include "ie_api.h" -#include "ie_blob.h" -#include "ie_common.h" -#include "ie_data.h" -#include "ie_input_info.hpp" - -namespace InferenceEngine { - -namespace details { - -IE_SUPPRESS_DEPRECATED_START - -class CNNNetworkImpl final : public ICNNNetwork { -public: - CNNNetworkImpl(); - explicit CNNNetworkImpl(const CNNNetwork& ngraphImpl); - ~CNNNetworkImpl(); - - std::shared_ptr<::ngraph::Function> getFunction() noexcept override { - return nullptr; - } - - std::shared_ptr getFunction() const noexcept override { - return nullptr; - } - - void getOutputsInfo(std::map& out) const noexcept override; - - void getInputsInfo(InputsDataMap& inputs) const noexcept override; - - InputInfo::Ptr getInput(const std::string& inputName) const noexcept override { - auto it = _inputData.find(inputName); - if (it == _inputData.end()) { - return nullptr; - } - return it->second; - } - - void setInputInfo(InputInfo::Ptr data) { - _inputData[data->name()] = data; - } - - void removeInputInfo(const std::string& name) { - _inputData.erase(name); - } - - const std::string& getName() const noexcept override { - return _name; - } - - void setName(const std::string& name) { - _name = name; - } - - const std::map& allLayers() const { - return _layers; - } - - size_t layerCount() const override { - return _layers.size(); - } - - DataPtr& getData(const char* name) noexcept { - return _data[name]; - } - - void addData(const char* name, DataPtr data) noexcept { - _data.emplace(name, data); - } - - DataPtr& getData(const std::string& name) { - return getData(name.c_str()); - } - - void addLayer(const CNNLayerPtr& layer) noexcept; - - void removeLayer(const std::string& layerName); - - // renames layer, statistics is not supported - void renameLayer(const std::string& currentName, const std::string& newName); - - void removeData(const std::string& dataName); - - StatusCode getLayerByName(const char* layerName, CNNLayerPtr& out, ResponseDesc* resp) const noexcept; - - // public version - StatusCode setBatchSize(size_t size, ResponseDesc* responseDesc) noexcept override; - - // for internal usage (e.g. setBatch via reshape in tests) - StatusCode setBatchSizeReshape(size_t size, ResponseDesc* responseDesc) noexcept; - - size_t getBatchSize() const override; - - StatusCode addOutput(const std::string& layerName, size_t outputIndex, ResponseDesc* resp) noexcept override; - - void resolveOutput(); - - void addOutput(const std::string& dataName); - - void removeOutput(const std::string& dataName); - - virtual void validate(int = 2); - - StatusCode reshape(const std::map>& inputShapes, - ResponseDesc* resp) noexcept override; - - StatusCode serialize(const std::string& xmlPath, const std::string& binPath, ResponseDesc* resp) const - noexcept override; - - StatusCode serialize(std::ostream& xmlBuf, std::ostream& binBuf, ResponseDesc* resp) const noexcept override; - - StatusCode serialize(std::ostream& xmlBuf, Blob::Ptr& binBlob, ResponseDesc* resp) const noexcept override; - -protected: - std::map _data; - std::map _layers; - InferenceEngine::InputsDataMap _inputData; - std::map _outputData; - std::string _name; - DataPtr _emptyData; -}; - -IE_SUPPRESS_DEPRECATED_END - -typedef std::shared_ptr CNNNetworkImplPtr; - -} // namespace details -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/convert_function_to_cnn_network.hpp b/src/plugins/intel_gna/legacy/include/legacy/convert_function_to_cnn_network.hpp deleted file mode 100644 index 0a1ff04a150..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/convert_function_to_cnn_network.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include "blob_factory.hpp" - -namespace InferenceEngine { -namespace details { - -std::shared_ptr convertFunctionToICNNNetwork(const std::shared_ptr& graph, - const CNNNetwork& network, - bool keep_constant_inputs = false); - -void convertFunctionToICNNNetwork(const std::shared_ptr& graph, - const CNNNetwork& ngraphNetwork, - CNNNetworkImpl* cnnNetworkImpl, - bool keep_constant_inputs = false); - -// TODO: move ConstAllocatorWrapper class, shareWeights add addBlob into CNNLayerCreator when NodeConverter class is -// removed -class ConstAllocatorWrapper : public IAllocator { -public: - explicit ConstAllocatorWrapper(std::shared_ptr constOp) : _constOp(std::move(constOp)) {} - - void* lock(void* handle, LockOp) noexcept override { - return handle; - } - - void unlock(void*) noexcept override {} // NOLINT - - void* alloc(size_t) noexcept override { - return const_cast(_constOp->get_data_ptr()); - } - - bool free(void*) noexcept override { // NOLINT - return true; - } - -private: - std::shared_ptr _constOp; -}; - -enum BlobType { weights, biases }; - -inline Blob::Ptr shareWeights(const std::shared_ptr& constLayer) { - if (!constLayer) - IE_THROW() << "Cannot share weights! Constant operation is empty!"; - auto dataPrecision = convertPrecision(constLayer->get_element_type()); - - size_t shapeSize = ngraph::shape_size(constLayer->get_shape()); - constexpr size_t byte_size{8}; - if (dataPrecision == Precision::BIN) { - shapeSize = (shapeSize + (byte_size - 1)) / byte_size; - } - - TensorDesc td(dataPrecision, {shapeSize}, Layout::C); - - auto blob = make_blob_with_precision(td, std::make_shared(constLayer)); - blob->allocate(); - - return blob; -} - -template -bool addBlob(const std::shared_ptr& weightsNode, std::shared_ptr& res, BlobType type) { - auto constWeights = ngraph::as_type_ptr(weightsNode); - if (constWeights) { - Blob::Ptr dataBlob = shareWeights(constWeights); - if (type == weights) { - res->blobs["weights"] = dataBlob; - res->_weights = dataBlob; - } else if (type == biases) { - res->blobs["biases"] = dataBlob; - res->_biases = dataBlob; - } else { - return false; - } - return true; - } else { - return false; - } -} - -} // namespace details -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/details/ie_cnn_network_iterator.hpp b/src/plugins/intel_gna/legacy/include/legacy/details/ie_cnn_network_iterator.hpp deleted file mode 100644 index 4dc15581d24..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/details/ie_cnn_network_iterator.hpp +++ /dev/null @@ -1,234 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief A header file for the CNNNetworkIterator class - * - * @file ie_cnn_network_iterator.hpp - */ -#pragma once -#include - -#include -#include -#include -#include -#include -#include - -#include "cpp/ie_cnn_network.h" -#include "ie_api.h" -#include "ie_locked_memory.hpp" - -namespace InferenceEngine { -namespace details { - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class enables range loops for CNNNetwork objects - */ -class CNNNetworkIterator { - IE_SUPPRESS_DEPRECATED_START - - std::list nextLayersToVisit{}; - InferenceEngine::CNNLayerPtr currentLayer = nullptr; - const ICNNNetwork* network = nullptr; - - void init(const ICNNNetwork* net) { - network = net; - if (network == nullptr) - IE_THROW() << "ICNNNetwork object is nullptr"; - - OutputsDataMap outputs; - network->getOutputsInfo(outputs); - - InputsDataMap inputs; - network->getInputsInfo(inputs); - - auto get_consumers = [](const CNNLayerPtr& node) -> std::vector { - std::vector consumers; - for (const auto& output : node->outData) { - for (const auto& consumer : getInputTo(output)) { - consumers.push_back(consumer.second); - } - } - return consumers; - }; - std::unordered_set visited; - auto bfs = [&](const CNNLayerPtr& start_node, bool traverse_via_outputs = false) { - if (!start_node || visited.count(start_node.get())) - return; - std::deque q; - q.push_front(start_node); - while (!q.empty()) { - auto node = q.front(); - q.pop_front(); - if (visited.insert(node.get()).second) { - nextLayersToVisit.push_front(node); - } - - // Traverse via inputs - for (const auto& input : node->insData) { - auto locked_input = input.lock(); - if (!locked_input) { - IE_THROW() << "insData for " << node->name << " is not valid."; - } - if (auto next_node = getCreatorLayer(locked_input).lock()) { - if (!visited.count(next_node.get())) { - // Check that all consumers were visited - bool all_consumers_used(true); - for (const auto& consumer : get_consumers(next_node)) { - if (!visited.count(consumer.get())) - all_consumers_used = false; - } - if (all_consumers_used) { - q.push_front(next_node); - } - } - } - } - - // Traverse via outputs - if (traverse_via_outputs) { - for (const auto& consumer : get_consumers(node)) { - if (!visited.count(consumer.get())) { - q.push_front(consumer); - } - } - } - } - }; - - // Find all outputLayers - std::vector outputLayers; - const auto* networkImpl = dynamic_cast(network); - if (networkImpl) { - for (const auto& node : networkImpl->allLayers()) { - if (get_consumers(node.second).empty()) - outputLayers.emplace_back(node.second); - } - } else { - // For backward compatibility - for (const auto& out : outputs) { - outputLayers.emplace_back(getCreatorLayer(out.second).lock()); - } - } - // First we run bfs starting from outputs that provides deterministic graph traverse - for (const auto& output : outputLayers) { - bfs(output); - } - if (!networkImpl) { - // For cases when graph has no outputs we start bfs from inputs to ensure topological sort - for (const auto& input : inputs) { - const auto data_ptr = input.second->getInputData(); - for (const auto& consumer : getInputTo(data_ptr)) - bfs(consumer.second, true); - } - } - currentLayer = nextLayersToVisit.front(); - } - -public: - /** - * iterator trait definitions - */ - typedef std::forward_iterator_tag iterator_category; - typedef CNNLayerPtr value_type; - typedef int difference_type; - typedef CNNLayerPtr pointer; - typedef CNNLayerPtr reference; - - /** - * @brief Default constructor - */ - CNNNetworkIterator() = default; - - /** - * @brief Constructor. Creates an iterator for specified CNNNetwork instance. - * @param network Network to iterate. Make sure the network object is not destroyed before iterator goes out of - * scope. - */ - explicit CNNNetworkIterator(const ICNNNetwork* network) { - init(network); - } - - explicit CNNNetworkIterator(const CNNNetwork& network) { - const auto& inetwork = static_cast(network); - init(&inetwork); - } - - /** - * @brief Performs pre-increment - * @return This CNNNetworkIterator instance - */ - CNNNetworkIterator& operator++() { - currentLayer = next(); - return *this; - } - - /** - * @brief Performs post-increment. - * Implementation does not follow the std interface since only move semantics is used - */ - void operator++(int) { - currentLayer = next(); - } - - /** - * @brief Checks if the given iterator is not equal to this one - * @param that Iterator to compare with - * @return true if the given iterator is not equal to this one, false - otherwise - */ - bool operator!=(const CNNNetworkIterator& that) const { - return !operator==(that); - } - - /** - * @brief Gets const layer pointer referenced by this iterator - */ - const CNNLayerPtr& operator*() const { - if (nullptr == currentLayer) { - IE_THROW() << "iterator out of bound"; - } - return currentLayer; - } - - /** - * @brief Gets a layer pointer referenced by this iterator - */ - CNNLayerPtr& operator*() { - if (nullptr == currentLayer) { - IE_THROW() << "iterator out of bound"; - } - return currentLayer; - } - /** - * @brief Compares the given iterator with this one - * @param that Iterator to compare with - * @return true if the given iterator is equal to this one, false - otherwise - */ - bool operator==(const CNNNetworkIterator& that) const { - return currentLayer == that.currentLayer && - (network == that.network || - ((network == nullptr || that.network == nullptr) && currentLayer == nullptr)); - } - -private: - /** - * @brief implementation based on BFS - */ - CNNLayerPtr next() { - if (nextLayersToVisit.empty()) { - return nullptr; - } - - nextLayersToVisit.pop_front(); - - return nextLayersToVisit.empty() ? nullptr : nextLayersToVisit.front(); - } - - IE_SUPPRESS_DEPRECATED_END -}; -} // namespace details -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/details/ie_cnn_network_tools.h b/src/plugins/intel_gna/legacy/include/legacy/details/ie_cnn_network_tools.h deleted file mode 100644 index 15aa326276a..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/details/ie_cnn_network_tools.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief A header file for CNNNetwork tools - * - * @file ie_cnn_network_tools.h - */ -#pragma once -#include - -#include - -#include "cpp/ie_cnn_network.h" - -namespace InferenceEngine { -namespace details { - -std::vector CNNNetSortTopologically(const CNNNetwork& network); - -} // namespace details -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/graph_tools.hpp b/src/plugins/intel_gna/legacy/include/legacy/graph_tools.hpp deleted file mode 100644 index 448ec3ca8b6..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/graph_tools.hpp +++ /dev/null @@ -1,735 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cpp/ie_cnn_network.h" -#include "ie_algorithm.hpp" - -IE_SUPPRESS_DEPRECATED_START - -namespace InferenceEngine { -namespace details { - -/** - * @brief Iterate over all layers followed by certain CNNLayer layer, and suitable to use ranged loops for output layers - */ -class OutLayersIterator { - std::vector::iterator dataCntIteratorCurrent; - std::vector::iterator dataCntIteratorEnd; - - using OutdataIterator = std::map::iterator; - bool pointingToEnd = true; - OutdataIterator currentIterator; - -public: - OutLayersIterator() = default; - - static OutLayersIterator make_begin(std::vector& origin) { - if (origin.empty()) { - return {}; - } - OutLayersIterator it; - - it.dataCntIteratorCurrent = origin.begin(); - it.dataCntIteratorEnd = origin.end(); - it.moveToNextNonEmptyData(); - - return it; - } - - bool operator==(const OutLayersIterator& it) const { - if (pointingToEnd || it.pointingToEnd) { - return pointingToEnd && it.pointingToEnd; - } - return it.dataCntIteratorCurrent == dataCntIteratorCurrent && it.currentIterator == currentIterator; - } - - bool operator!=(const OutLayersIterator& it) const { - return !this->operator==(it); - } - - void operator++() { - if (dataCntIteratorCurrent == dataCntIteratorEnd) { - return; - } - - if (pointingToEnd) { - return; - } - currentIterator++; - if (currentIterator != getInputTo(dataCntIteratorCurrent->get()).end()) { - return; - } - - dataCntIteratorCurrent++; - moveToNextNonEmptyData(); - } - - CNNLayerPtr operator*() const { - return currentIterator->second; - } - -protected: - void moveToNextNonEmptyData() { - pointingToEnd = true; - for (; dataCntIteratorCurrent != dataCntIteratorEnd; dataCntIteratorCurrent++) { - if (!getInputTo(dataCntIteratorCurrent->get()).empty()) { - currentIterator = getInputTo(dataCntIteratorCurrent->get()).begin(); - pointingToEnd = false; - break; - } - } - } -}; - -class OutInfoWrapper { - CNNLayer* origin = nullptr; - -public: - explicit OutInfoWrapper(CNNLayer* origin) : origin(origin) {} - OutLayersIterator begin() const { - return OutLayersIterator::make_begin(origin->outData); - } - - OutLayersIterator end() const { - return {}; - } -}; - -inline OutInfoWrapper default_order(CNNLayer* layer) { - return OutInfoWrapper(layer); -} - -/** - * @brief implementation of DFS with visiting checking to avoid multientry - * @param visited - set to store visited layers - * @param layer - current layer to start DFS from - * @param visit - user callback on visited node - * @param visitBefore - indicates when callback is happened before all child nodes or after - * @return false if cycle detected - */ -template > -inline bool DFS(std::unordered_map& visited, - const InferenceEngine::CNNLayerPtr& layer, - const T& visit, - bool visitBefore, - const Ordering& order = &default_order) { - if (layer == nullptr) { - return true; - } - - if (visitBefore) - visit(layer); - visited[layer.get()] = false; - for (auto outLayerPtr : order(layer.get())) { - auto i = visited.find(outLayerPtr.get()); - if (i != visited.end()) { - /** - * cycle detected we entered still not completed node - */ - if (!i->second) { - return false; - } - continue; - } - if (!DFS(visited, outLayerPtr, visit, visitBefore, order)) { - return false; - } - } - - if (!visitBefore) - visit(layer); - visited[layer.get()] = true; - return true; -} - -/** - * @brief implementation of DFS in unordered graph, mean next layers not just child but also parents - * @param visited - set to store visited layers - * @param layer - current layer to start UnorderedDFS from - * @param visit - user callback on visited node - * @param visitBefore - indicates when callback is happened before all child nodes or after - */ -template -inline void UnorderedDFS(std::unordered_set& visited, - const InferenceEngine::CNNLayerPtr& layer, - const T& visit, - bool visitBefore) { - std::queue layers; - auto cycleDFS = [&]() { - if (layers.empty()) - return; - auto cnnLayer = layers.front(); - layers.pop(); - - if (cnnLayer == nullptr) { - return; - } - if (visited.end() != visited.find(cnnLayer.get())) { - return; - } - - if (visitBefore) - visit(cnnLayer); - visited.insert(cnnLayer.get()); - - // visit children - for (const auto& od : cnnLayer->outData) { - for (const auto& nl : getInputTo(od)) { - layers.push(nl.second); - } - } - - // visit parents - for (size_t i = 0; i < cnnLayer->insData.size(); i++) { - auto& input = cnnLayer->insData[i]; - if (!input.lock()) { - IE_THROW() << "Data " << i << " inserted into layer " << cnnLayer->name << " is nullptr"; - } else { - auto creatorLayer = getCreatorLayer(input.lock()).lock(); - if (creatorLayer) { - layers.push(creatorLayer); - } - } - } - - if (!visitBefore) - visit(cnnLayer); - }; - layers.push(layer); - while (!layers.empty()) { - cycleDFS(); - } -} - -/** - * @brief implementation of DFS with visiting checking to avoid multyentry - * @param visited - set to store visited layers - * @param layer - current layer to start DFS from - * @param visit - user callback on visited node - */ -template -inline void BFS(InferenceEngine::CNNLayerPtr layer, const T& visit, int maxDepth) { - std::set visited; - std::list nextLayers; - nextLayers.push_back(layer); - - int layersOnLevel = 1; - for (; !nextLayers.empty() && maxDepth != 0;) { - visit(*nextLayers.begin()); - for (auto& od : (*nextLayers.begin())->outData) { - for (auto nl : getInputTo(od)) { - if (visited.find(nl.second.get()) == visited.end()) { - nextLayers.push_back(nl.second); - visited.insert(nl.second.get()); - } - } - } - nextLayers.pop_front(); - // move to nextLayer - if (!--layersOnLevel) { - layersOnLevel = nextLayers.size(); - maxDepth--; - } - } -} - -} // namespace details - -/** - * Generic DFS algorithm traverser - * @param layer - starting layer - * @param visit - callback to be called upon visiting - * @param visitBefore - indicates when callback is happened before all child nodes or after - */ -template > -inline bool CNNNetDFS(const InferenceEngine::CNNLayerPtr& layer, - const T& visit, - bool visitBefore = true, - const Ordering& order = &details::default_order) { - if (layer == nullptr) { - return true; - } - - std::unordered_map visited; - return details::DFS(visited, layer, visit, visitBefore, order); -} -/** - * DFS algorithm with multiple starting data - * @param layer - starting data - * @param visit - callback to be called upon visiting - * @param visitBefore - indicates when callback is happened before all child nodes or after - */ -template -inline bool CNNNetForestDFS(const std::vector& heads, const T& visit, bool bVisitBefore) { - std::unordered_map visited; - for (const auto& in : heads) { - for (const auto& to : getInputTo(in)) { - if (visited.find(to.second.get()) != visited.end()) - continue; - if (!details::DFS(visited, to.second, visit, bVisitBefore)) { - return false; - } - } - } - return true; -} - -/** - * DFS algorithm with multiple starting nodes - * @param layer - starting layer - * @param visit - callback to be called upon visiting - * @param visitBefore - indicates when callback is happened before all child nodes or after - */ -template -inline bool CNNNetForestDFS(const Forest& heads, const T& visit, bool bVisitBefore) { - if (heads.empty()) { - return true; - } - - std::unordered_map visited; - for (auto& layer : heads) { - if (!details::DFS(visited, layer, visit, bVisitBefore)) { - return false; - } - } - return true; -} - -/** - * DFS algorithm with multiple starting nodes - * @param layer - starting layer - * @param visit - callback to be called upon visiting - * @param visitBefore - indicates when callback is happened before all child nodes or after - */ -template -inline bool CNNNetForestDFS(const Forest& heads, const T& visit, bool bVisitBefore, const Ordering& order) { - if (heads.empty()) { - return true; - } - - std::unordered_map visited; - for (auto& layer : heads) { - if (!details::DFS(visited, layer, visit, bVisitBefore, order)) { - return false; - } - } - return true; -} - -/** - * Generic BFS algorithm traverser - * @param layer - starting layer - * @param visit - callback to be called upon visiting - */ -template -inline void CNNNetBFS(const InferenceEngine::CNNLayerPtr& layer, const T& visit) { - if (!layer) { - return; - } - details::BFS(layer, visit, -1); -} - -/** - * @brief pointer of previous layers - * @param idx - index in previous layer collection - * @param layer - */ -inline bool CNNNetHasPrevLayer(const InferenceEngine::CNNLayer* layer, int idx = 0) { - IE_ASSERT(layer != nullptr); - if (layer->insData.empty() || static_cast(layer->insData.size()) <= idx) { - return false; - } - auto prevData = layer->insData[idx].lock(); - return !!getCreatorLayer(prevData).lock(); -} - -/** - * @brief to allow storing of LayersSP in collections ordered by names - */ - -class LayerNameLess { -public: - bool operator()(const CNNLayerPtr& lhs, const CNNLayerPtr& rhs) const { - return std::less()(lhs->name, rhs->name); - } -}; - -using CNNLayerSet = std::set; - -/** - * @brief returns all layers that are input or memory - * @param network - * @return set of input layers - */ -inline CNNLayerSet CNNNetGetAllInputLayers(const CNNNetwork& network) { - InputsDataMap inputs = network.getInputsInfo(); - OutputsDataMap outputs = network.getOutputsInfo(); - - std::vector entryDataSet; - entryDataSet.reserve(inputs.size() + outputs.size()); - for (const auto& kvp : inputs) - entryDataSet.push_back(kvp.second->getInputData()); - for (const auto& kvp : outputs) - entryDataSet.push_back(kvp.second); - - CNNLayerSet inputLayers; - std::unordered_set allLayers; - - if (entryDataSet.empty()) - return inputLayers; - - // define any layer connected to provided Data object (consumer or creator) - auto findConnectedLayer = [](const DataPtr& data) -> CNNLayerPtr { - auto consumerLayers = getInputTo(data); - if (!consumerLayers.empty()) - return consumerLayers.begin()->second; - - auto creator = getCreatorLayer(data).lock(); - if (creator != nullptr) - return creator; - - return nullptr; - }; - - for (const auto& data : entryDataSet) { - auto entryLayer = findConnectedLayer(data); - - if (entryLayer == nullptr) - continue; - - details::UnorderedDFS( - allLayers, - entryLayer, - [&inputLayers](const CNNLayerPtr& layer) { - if (layer->insData.empty()) { - inputLayers.insert(layer); - } - }, - false); - } - return inputLayers; -} - -inline CNNLayerSet CNNNetGetAllInputLayers(ICNNNetwork* network) { - std::shared_ptr pointer(network, [](ICNNNetwork* p) {}); - return CNNNetGetAllInputLayers(CNNNetwork(pointer)); -} - -/** - * @brief returns all layers that are input or memory , search started from arbitrary location in network - * @param start layer - * @return set of input layers - */ -inline CNNLayerSet CNNNetGetAllInputLayers(CNNLayer* layer) { - CNNLayerSet inputLayers; - std::unordered_set allLayers; - - CNNLayerPtr layerPtr(layer, [](CNNLayer*) {}); - - details::UnorderedDFS( - allLayers, - layerPtr, - [&](CNNLayerPtr layer) { - if (layer->insData.empty()) { - inputLayers.insert(layer); - } - }, - false); - return inputLayers; -} - -/** - * @brief Sorts CNNNetork graph in topological order, while uses custom ordering when walking among child nodes - * @param network - input CNNNetwork - * @param ordering - callback that returns output layers for given CNNLayer pointer, see default_order function - * @return sorted CNNNetwork layers - */ -template -std::vector CNNNetSortTopologicallyEx(const CNNNetwork& network, LayerOrdering ordering) { - std::vector stackOfVisited; - bool res = CNNNetForestDFS( - CNNNetGetAllInputLayers(network), - [&](CNNLayerPtr current) { - stackOfVisited.push_back(current); - }, - false, - ordering); - - if (!res) { - IE_THROW() << "Sorting not possible, due to existed loop."; - } - - std::reverse(std::begin(stackOfVisited), std::end(stackOfVisited)); - - return stackOfVisited; -} - -using CNNNetPtr = std::shared_ptr; -using CNNNetCPtr = std::shared_ptr; - -/** - * @brief deep copy of the entire network, structure using custom copier for layers - * @param input - source network - * @param cp - custom copier object, ex: [](CNNLayerPtr lp) { return injectData(lp); } - * @return copied network - */ -template -inline CNNNetwork CNNNetCopy(const CNNNetwork& input, const Copier& cp) { - auto net = std::make_shared(); - - net->setName(input.getName()); - - // rest info is layer dependent so have to create graph clone - std::unordered_map oldToNewLayers; - - auto starters = CNNNetGetAllInputLayers(input); - - // 1st pass node creation - bool res = CNNNetForestDFS( - starters, - [&](CNNLayerPtr current) { - auto newLayer = cp(current); - oldToNewLayers[current.get()] = newLayer; - net->addLayer(newLayer); - }, - true); - - if (!res) { - IE_THROW() << "Copying of network not possible, due to existed loop."; - } - - // internal utility to locate out data idx in layer - auto findOutDataIdx = [&](DataPtr sourceData) { - int dataIdx = -1; - auto sourceLayer = getCreatorLayer(sourceData).lock(); - if (!sourceLayer) { - IE_THROW() << "Data " << sourceData->getName() << " has no creator layer"; - } - for (size_t j = 0; j < sourceLayer->outData.size(); j++) { - if (sourceData.get() == sourceLayer->outData[j].get()) { - dataIdx = static_cast(j); - break; - } - } - IE_ASSERT(dataIdx != -1); - return dataIdx; - }; - - // compares data, for copied network and in old network - auto areEqualDatas = [&](DataPtr source, DataPtr target) { - if (source.get() == target.get()) { - return true; - } - - // dims comparison - - // actual dims value might be incorrect dueto syntetic case - // , when getbatch() size returns value not reflect in actual data - - if (source->getTensorDesc().getDims().size() != target->getTensorDesc().getDims().size()) { - return false; - } - - // name comparison - if (source->getName() != target->getName()) { - return false; - } - - // inputTO layers are identical by design - return true; - }; - // internal utility to locate input data idx in layer - auto findInsDataIdx = [&](DataPtr sourceData, CNNLayerPtr layer) { - int dataIdx = -1; - auto sourceLayerMap = getInputTo(sourceData); - for (auto& layersMapping : sourceLayerMap) { - if (layersMapping.second.get() != layer.get()) { - continue; - } - for (size_t j = 0; j < layer->insData.size(); j++) { - if (areEqualDatas(layer->insData[j].lock(), sourceData)) { - dataIdx = static_cast(j); - } - } - if (dataIdx != -1) { - break; - } - } - IE_ASSERT(dataIdx != -1); - return dataIdx; - }; - - // 2nd pass edges creation - CNNNetForestDFS( - starters, - [&](CNNLayerPtr current) { - auto newLayer = oldToNewLayers[current.get()]; - // remap output data - for (size_t i = 0; i != current->outData.size(); i++) { - getCreatorLayer(newLayer->outData[i]) = CNNLayerWeakPtr(newLayer); - - // transfer data info for getData routine - net->getData(newLayer->outData[i]->getName()) = newLayer->outData[i]; - - for (auto inputTo = std::begin(getInputTo(newLayer->outData[i])); - inputTo != std::end(getInputTo(newLayer->outData[i])); - inputTo++) { - inputTo->second = oldToNewLayers[inputTo->second.get()]; - } - } - // remap input data - for (size_t i = 0; i != current->insData.size(); i++) { - // found that data IDX - auto sourceData = current->insData[i].lock(); - auto sourceLayer = getCreatorLayer(sourceData).lock(); - if (!sourceLayer) { - IE_THROW() << "Data " << sourceData->getName() << " has no creator layer"; - } - // find insData Entry in outData of sourceLayer - newLayer->insData[i] = oldToNewLayers[sourceLayer.get()]->outData[findOutDataIdx(sourceData)]; - } - }, - true); - - // transfer input info - InputsDataMap inputsInfo = input.getInputsInfo(); - std::set insDatas; - for (auto&& info : inputsInfo) { - for (const auto& secondLayer : getInputTo(info.second->getInputData())) { - auto secondLayerNew = oldToNewLayers[secondLayer.second.get()]; - InputInfo::Ptr infoNew = std::make_shared(); - infoNew->setInputData( - secondLayerNew->insData[findInsDataIdx(info.second->getInputData(), secondLayer.second)].lock()); - infoNew->getPreProcess() = info.second->getPreProcess(); - net->setInputInfo(infoNew); - } - } - - // transfer output info - OutputsDataMap outmap = input.getOutputsInfo(); - for (auto&& data : outmap) { - ResponseDesc dsc; - if (OK != net->addOutput(getCreatorLayer(data.second).lock()->name, findOutDataIdx(data.second), &dsc)) { - IE_THROW() << dsc.msg; - } - } - - ResponseDesc dsc; - // transfer batch size - if (OK != net->setBatchSize(input.getBatchSize(), &dsc)) { - IE_THROW() << dsc.msg; - } - - return CNNNetwork(net); -} - -/** - * @brief deep copy of the entire network - * @param input - * @return - */ -inline CNNNetwork CNNNetCopy(const CNNNetwork& input) { - struct EmptyStruct {}; - auto copier = [](CNNLayerPtr lp) { - return injectData(lp); - }; - return InferenceEngine::CNNNetCopy(input, copier); -} - -namespace details { - -/** - * The structure to wrap network as lists of input and output data objects - * Each layer of network is achievable by DFS started from inputs. - * - * NB! The input collection may contain a "fake" data object which is not a - * real input to network, but just a holder to keep "const" and "memory" - * layers alive. Fake data object points layers with empty creator field. - * The fake data object always has "UNSPECIFIED" precision attribute. - */ -struct CNNSubnet { - std::vector inputs; - std::vector outputs; -}; - -/** - * @brief Detect all input data object, not only provided as entry point. - * @param heads collection of some input into graph - * @return all input data objects including "fake" data (layers holder). - */ -inline std::vector CNNSubnetGetAllInputs(const std::vector& heads) { - CNNLayerSet inputLayers; - std::unordered_set allLayers; - - // Define all start layers - for (const auto& data : heads) { - auto& secondLayers = getInputTo(data); - - if (secondLayers.empty()) - continue; - - details::UnorderedDFS( - allLayers, - secondLayers.begin()->second, - [&](CNNLayerPtr layer) { - if (layer->insData.empty()) { - inputLayers.insert(layer); - } - }, - false); - } - - std::vector res = heads; - // Add fake input data to point on not achievable - // layers from head (like const placeholders) - for (auto& starter : inputLayers) { - DataPtr holder(new Data(starter->name + ":input_holder", starter->precision)); - getInputTo(holder)[starter->name] = starter; - res.push_back(holder); - } - - return res; -} - -/** - * @brief Sorts SNNSubnet graph representation in topological order - * @param subnet input object - * @return layer collection sorted in topological order - */ -inline std::vector CNNSubnetSortTopologically(const CNNSubnet& subnet) { - std::vector stackOfVisited; - bool res = CNNNetForestDFS( - CNNSubnetGetAllInputs(subnet.inputs), - [&](CNNLayerPtr current) { - stackOfVisited.push_back(current); - }, - false); - if (!res) { - IE_THROW() << "Sorting not possible, due to existed loop."; - } - - std::reverse(stackOfVisited.begin(), stackOfVisited.end()); - return stackOfVisited; -} - -} // namespace details -} // namespace InferenceEngine - -IE_SUPPRESS_DEPRECATED_END diff --git a/src/plugins/intel_gna/legacy/include/legacy/graph_transformer.h b/src/plugins/intel_gna/legacy/include/legacy/graph_transformer.h deleted file mode 100644 index f98a03f689b..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/graph_transformer.h +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief a header file with common functions for graph transformation - * @file graph_transformer.h - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace InferenceEngine { - -/** - * @brief TBD - */ -class ConstTransformer { -public: - explicit ConstTransformer(details::CNNNetworkImpl* _network); - - /** - * @brief calculates const layers, combines const subgraph into a single const layers - */ - void foldConstSubgraphs(); - - /** - * @brief folds Const Subgraphs and removes second input of Reshape-like layers (Interp, Gather, Resample, ...) - */ - void fullTrim(); - -protected: - ConstTransformer(std::vector& _inputs, std::vector& _outputs); - - /** - * @brief collect all const layers with marking if it defines shape (1 - for shape, 0 - otherwise) - */ - virtual const std::map getConstLayers(const std::vector& sortedLayers); - - /** - * @brief TBD - */ - virtual const BlobMap getConstData(const std::map& constLayers, - const std::vector& sortedLayers); - - /** - * @brief TBD - */ - virtual std::vector foldConstSubgraphsInternal(const std::map& constLayers, - const BlobMap& constData, - const std::vector& sortedLayers); - - /** - * @brief TBD - */ - virtual void trimShapeInputs(const std::vector& constLayers, std::vector& allLayers); - - /** - * @brief TBD - */ - void cleanup(); - -private: - const details::caseless_set shapeTaking = {"Reshape", "Resample", "Interp", "Squeeze", "Unsqueeze"}; - details::CNNNetworkImpl* network; - std::vector inputs; - std::vector outputs; - - /** data/layer collection to restore valida state of network if it was specified */ - std::vector data_to_remove; - std::vector data_to_add; - - std::vector layer_to_remove; - std::vector layer_to_add; -}; - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/ie_ir_version.hpp b/src/plugins/intel_gna/legacy/include/legacy/ie_ir_version.hpp deleted file mode 100644 index eb532d448cc..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ie_ir_version.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include - -namespace InferenceEngine { -namespace details { - -inline size_t get_ir_version(pugi::xml_node& root) { - return pugixml::utils::GetUIntAttr(root, "version", 0); -} - -/** - * @brief Extracts IR version from model stream - * @param model Models stream - * @return IR version, 0 if model does represent IR - */ -inline size_t get_ir_version(std::istream& model) { - std::array header = {}; - - model.seekg(0, model.beg); - model.read(header.data(), header.size()); - model.clear(); - model.seekg(0, model.beg); - - pugi::xml_document doc; - auto res = - doc.load_buffer(header.data(), header.size(), pugi::parse_default | pugi::parse_fragment, pugi::encoding_utf8); - - if (res == pugi::status_ok) { - pugi::xml_node root = doc.document_element(); - - std::string node_name = root.name(); - std::transform(node_name.begin(), node_name.end(), node_name.begin(), ::tolower); - - if (node_name == "net") { - return get_ir_version(root); - } - } - - return 0; -} - -} // namespace details -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/ie_layers.h b/src/plugins/intel_gna/legacy/include/legacy/ie_layers.h deleted file mode 100644 index 40434bce5e3..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ie_layers.h +++ /dev/null @@ -1,2332 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief a header file for internal Layers structure to describe layers information - * - * @file ie_layers.h - */ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ie_blob.h" -#include "ie_common.h" -#include "ie_data.h" - -#ifdef _MSC_VER -# define _IE_SUPPRESS_DEPRECATED_START_MSVC IE_SUPPRESS_DEPRECATED_START -# define _IE_SUPPRESS_DEPRECATED_END_MSVC IE_SUPPRESS_DEPRECATED_END -#else -# define _IE_SUPPRESS_DEPRECATED_START_MSVC -# define _IE_SUPPRESS_DEPRECATED_END_MSVC -#endif - -namespace InferenceEngine { - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - */ -struct LayerParams { - /** - * @brief Layer name - */ - std::string name; - - /** - * @brief Layer type - */ - std::string type; - - /** - * @brief Layer precision - */ - Precision precision; - - /** - * @brief A default constructor. - */ - LayerParams(); - - IE_SUPPRESS_DEPRECATED_START - - /** - * @brief A copy constructor. - * @param other An object to copy. - */ - LayerParams(const LayerParams& other); - - /** - * @brief A copy assignment operator - * @param other An object to copy - * @return A value - */ - LayerParams& operator=(const LayerParams& other); - - IE_SUPPRESS_DEPRECATED_END - - /** - * @brief A constructor with parameters. - * @param name A layer name. - * @param type A layer type. - * @param precision A layer precision. - */ - LayerParams(const std::string& name, const std::string& type, Precision precision); -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This is a base abstraction Layer - all DNN Layers inherit from this class - */ -class CNNLayer { -protected: - std::shared_ptr node; - -public: - /** - * @brief A shared pointer to CNNLayer - */ - IE_SUPPRESS_DEPRECATED_START - using Ptr = std::shared_ptr; - IE_SUPPRESS_DEPRECATED_END - - /** - * @brief Layer name - */ - std::string name; - - /** - * @brief Layer type - */ - std::string type; - - /** - * @brief Layer base operating precision - */ - Precision precision; - - /** - * @brief A vector of pointers to the output data elements of this layer in the di-graph (order matters) - */ - std::vector outData; - - /** - * @brief A vector of weak pointers to the input data elements of this layer in the di-graph (order matters) - */ - std::vector insData; - - /** - * @brief If suggested to fuse - a pointer to the layer which needs to be fused with this layer - */ - _IE_SUPPRESS_DEPRECATED_START_MSVC - Ptr _fusedWith; - _IE_SUPPRESS_DEPRECATED_END_MSVC - - /** - * @brief Convenience user values to store in this object as extra data - */ - UserValue userValue; - - /** - * @brief Layer affinity set by user. - */ - std::string affinity; - - IE_SUPPRESS_DEPRECATED_START - - /** - * @brief A constructor. Creates a new CNNLayer instance and initializes layer parameters with the given values. - * - * @param prms Basic common parsing parameters - */ - explicit CNNLayer(const LayerParams& prms); - - /** - * @brief Returns the original nGraph op - * @return A smart pointer to nGraph op - */ - std::shared_ptr getNode() const { - return node; - } - - /** - * @brief A copy constructor - * @param other An object to copy - */ - CNNLayer(const CNNLayer& other); - - IE_SUPPRESS_DEPRECATED_END - - /** - * @brief A virtual destructor - */ - virtual ~CNNLayer(); - - /** - * @brief Sets a layer to be fused with - * - * @param layer Reference to the layer to be fused with - */ - _IE_SUPPRESS_DEPRECATED_START_MSVC - void fuse(Ptr& layer) { - _fusedWith = layer; - } - _IE_SUPPRESS_DEPRECATED_END_MSVC - - /** - * @brief Returns the first element of the input data for this layer - * - * @return A smart pointer to the input data element - */ - virtual const DataPtr input() const; - - /** - * @brief Checks if the input data and layer data are legitimate - */ - void parseParams(); - - /** - * @brief Parse string with float in accordance with IE rules - * - * @param str input string with float value - * @return float value if parsing was successful - * @throws Exception in case of parsing error - */ - static float ie_parse_float(const std::string& str); - - /** - * @brief serialize float with c_locale formating - * used for default values serializing - */ - static std::string ie_serialize_float(float value); - - /** - * @brief Gets float value for the given parameter - * - * @param param name of the parameter to find - * @param def default value of the parameter if not found - * @return float value - */ - float GetParamAsFloat(const char* param, float def) const; - - /** - * @brief Returns a float value for the given layer parameter - * - * @param param Name of the layer parameter - * @return A float value for the specified parameter - */ - float GetParamAsFloat(const char* param) const; - - /** - * @brief Returns a vector of float values for the given parameter or returns the default value - * - * @param param Name of the layer parameter - * @param def Default value of the parameter if not found - * @return vector of float values - */ - std::vector GetParamAsFloats(const char* param, std::vector def) const; - - /** - * @brief Returns a vector of float values for the given parameter - * - * @param param Name of the layer parameter - * @return vector of float values - */ - std::vector GetParamAsFloats(const char* param) const; - - /** - * @brief Returns an integer value for the given parameter or returns the default value - * - * @param param Name of the layer parameter - * @param def Default value of the parameter if not found - * @return An int value for the specified parameter - */ - int GetParamAsInt(const char* param, int def) const; - - /** - * @brief Returns an integer value for the given parameter - * - * @param param Name of the layer parameter - * @return An int value for the specified parameter - */ - int GetParamAsInt(const char* param) const; - - /** - * @brief Returns a vector of int values for the given parameter or returns the default value - * - * @param param Name of the layer parameter - * @param def Default value of the parameter if not found - * @return vector of int values - */ - std::vector GetParamAsInts(const char* param, std::vector def) const; - - /** - * @brief Returns a vector of int values for the given parameter - * - * @param param Name of the layer parameter - * @return vector of int values - */ - std::vector GetParamAsInts(const char* param) const; - - /** - * @brief Returns an unsigned integer value for the given parameter or returns the default value - * - * @param param Name of the layer parameter - * @param def Default value of the parameter if not found - * @return An unsigned integer value for the specified parameter - */ - unsigned int GetParamAsUInt(const char* param, unsigned int def) const; - - /** - * @brief Returns an unsigned integer value for the given parameter - * - * @param param Name of the layer parameter - * @return An unsigned integer value for the specified parameter - */ - unsigned int GetParamAsUInt(const char* param) const; - - /** - * @brief Returns an size_t value for the given parameter or returns the default value - * - * @param param Name of the layer parameter - * @param def Default value of the parameter if not found - * @return An size_t value for the specified parameter - */ - size_t GetParamAsSizeT(const char* param, size_t def) const; - - /** - * @brief Returns an size_t value for the given parameter - * - * @param param Name of the layer parameter - * @return An size_t value for the specified parameter - */ - size_t GetParamAsSizeT(const char* param) const; - - /** - * @brief Returns a vector of unsigned int values for the given parameter or returns the default value - * - * @param param Name of the layer parameter - * @param def Default value of the parameter if not found - * @return vector of unsigned int values - */ - std::vector GetParamAsUInts(const char* param, std::vector def) const; - - /** - * @brief Returns a vector of unsigned int values for the given parameter - * - * @param param Name of the layer parameter - * @return vector of unsigned int values - */ - std::vector GetParamAsUInts(const char* param) const; - - /** - * @brief Returns a boolean value for the given parameter. - * - * The valid values are (true, false, 1, 0). - * @param param Name of the layer parameter - * @param def Default value of the parameter if not found - * @return A bool value for the specified parameter - */ - bool GetParamAsBool(const char* param, bool def) const; - - /** - * @brief Returns a boolean value for the given parameter - * - * @param param Name of the layer parameter - * @return A bool value for the specified parameter - */ - bool GetParamAsBool(const char* param) const; - - /** - * @brief Returns a string value for the given parameter or returns the default one - * - * @param param Name of the layer parameter - * @param def Default value of the parameter if not found - * @return A string value - */ - std::string GetParamAsString(const char* param, const char* def) const; - - /** - * @brief Checks the param presence in the layer - * - * @param param Name of the layer parameter - * @return a bool depending param presence - */ - bool CheckParamPresence(const char* param) const; - - /** - * @brief Returns a string value for the given parameter. - * - * Throws exception if parameter was not found. - * @param param Name of the layer parameter - * @return A string value - */ - std::string GetParamAsString(const char* param) const; - - /** - * @brief Returns a string containing an integer if parameters value was - * "true" or "false" - * - * @param param Name of the layer parameter - * @return A string containing an integer or the parameter as string - */ - std::string getBoolStrParamAsIntStr(const char* param) const; - - /** - * @brief Gets the parameter as a std::vector - * @param param The parameter name - * @param def The default values if case of parameter is not found - * @return The parameter as strings. - */ - std::vector GetParamAsStrings(const char* param, std::vector def) const; - - /** - * @brief Map of pairs: (parameter name, parameter value) - */ - std::map params; - - /** - * @brief Map of pairs: (name, weights/biases blob) - */ - std::map blobs; -}; - -IE_SUPPRESS_DEPRECATED_START - -/** - * @brief Alias for CNNLayer object - */ -using GenericLayer = class CNNLayer; - -/** - * @brief A smart pointer to the CNNLayer - */ -using CNNLayerPtr = std::shared_ptr; -/** - * @brief A smart weak pointer to the CNNLayer - */ -using CNNLayerWeakPtr = std::weak_ptr; - -CNNLayerWeakPtr& getCreatorLayer(const DataPtr& data); - -std::map& getInputTo(const DataPtr& data); -std::map& getInputTo(Data* data); -IE_SUPPRESS_DEPRECATED_END - -_IE_SUPPRESS_DEPRECATED_START_MSVC - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a layer with Weights and/or Biases (e.g. Convolution/Fully Connected, etc.) - */ -class WeightableLayer : public CNNLayer { -public: - IE_SUPPRESS_DEPRECATED_START - - /** - * @brief A default constructor. Constructs a WeightableLayer instance and initiates layer parameters with the given - * values - * - * @param prms Initial layer parameters - */ - explicit WeightableLayer(const LayerParams& prms); - - /** - * @brief Constructs a WeightableLayer instance and initiates layer parameters with the given values - */ - using CNNLayer::CNNLayer; - - IE_SUPPRESS_DEPRECATED_END - - /** - * @brief A pointer to a weights blob - */ - Blob::Ptr _weights; - /** - * @brief A pointer to a biases blob - */ - Blob::Ptr _biases; - - ~WeightableLayer() override; -}; - -/** - * @brief convinenent way to declare property with backward compatibility to 2D members - */ -#define DEFINE_PROP(prop_name) \ - PropertyVector prop_name; \ - unsigned int& prop_name##_x = prop_name.at(X_AXIS); \ - unsigned int& prop_name##_y = prop_name.at(Y_AXIS) - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard 3D Convolution Layer - */ -class ConvolutionLayer : public WeightableLayer { -public: - /** - * @brief A convolution kernel array [X, Y, Z, ...] - */ - DEFINE_PROP(_kernel); - /** - * @brief A convolution paddings begin array [X, Y, Z, ...] - */ - DEFINE_PROP(_padding); - /** - * @brief A convolution paddings end array [X, Y, Z, ...] - */ - DEFINE_PROP(_pads_end); - /** - * @brief A convolution strides array [X, Y, Z, ...] - */ - DEFINE_PROP(_stride); - /** - * @brief A convolution dilations array [X, Y, Z, ...] - */ - DEFINE_PROP(_dilation); - /** - * @brief A number of output feature maps (size) generating the 3'rd output dimension - */ - unsigned int _out_depth = 0u; - /** - * @brief Number of groups - */ - unsigned int _group = 1u; - /** - * @brief Auto padding type - */ - std::string _auto_pad; - - IE_SUPPRESS_DEPRECATED_START - - /** - * @brief Creates a new ConvolutionLayer instance. - */ - explicit ConvolutionLayer(const LayerParams& p) - : WeightableLayer(p), - _kernel(2, 0u), - _padding(2, 0u), - _stride(2, 1u), - _dilation(2, 1u) {} - - /** - * @brief assignment operator - */ - ConvolutionLayer& operator=(const ConvolutionLayer& that) { - if (&that != this) { - WeightableLayer::operator=(that); - _kernel = that._kernel; - _padding = that._padding; - _pads_end = that._pads_end; - _stride = that._stride; - _dilation = that._dilation; - _out_depth = that._out_depth; - _group = that._group; - } - return *this; - } - - /** - * @brief copy constructor - */ - ConvolutionLayer(const ConvolutionLayer& that) : WeightableLayer(that) { - operator=(that); - } - /** - * @brief move constructor - */ - ConvolutionLayer(ConvolutionLayer&&) = default; - - IE_SUPPRESS_DEPRECATED_END - - ~ConvolutionLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard deconvolution layer - */ -class DeconvolutionLayer : public ConvolutionLayer { -public: - IE_SUPPRESS_DEPRECATED_START - using ConvolutionLayer::ConvolutionLayer; - using ConvolutionLayer::operator=; - IE_SUPPRESS_DEPRECATED_END - - ~DeconvolutionLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard deformable convolution layer - */ -class DeformableConvolutionLayer : public ConvolutionLayer { -public: - IE_SUPPRESS_DEPRECATED_START - using ConvolutionLayer::ConvolutionLayer; - using ConvolutionLayer::operator=; - IE_SUPPRESS_DEPRECATED_END - - /** - * @brief Number of deformable groups - */ - unsigned int _deformable_group = 1u; - - ~DeformableConvolutionLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard pooling layer - */ -class PoolingLayer : public CNNLayer { -public: - /** - * @brief Pooling kernel array [X, Y, Z, ...] - */ - DEFINE_PROP(_kernel); - /** - * @brief Pooling paddings begin array [X, Y, Z, ...] - */ - DEFINE_PROP(_padding); - /** - * @brief Pooling paddings end array [X, Y, Z, ...] - */ - PropertyVector _pads_end; - /** - * @brief Pooling strides array [X, Y, Z, ...] - */ - DEFINE_PROP(_stride); - - /** - * @enum PoolType - * @brief Defines available pooling types - */ - enum PoolType { MAX = 1, AVG = 2, STOCH = 3, ROI = 4, SPACIAL_PYRAMID = 5 }; - - /** - * @brief A pooling type - */ - PoolType _type = MAX; - - /** - * @brief A flag that indicates if padding is excluded or not - */ - bool _exclude_pad = false; - /** - * @brief Auto padding type - */ - std::string _auto_pad; - - IE_SUPPRESS_DEPRECATED_START - - /** - * @brief Creates a new PoolingLayer instance. - */ - explicit PoolingLayer(const LayerParams& p) : CNNLayer(p), _kernel(2, 0u), _padding(2, 0u), _stride(2, 0u) {} - - /** - * @brief assignment operator - */ - PoolingLayer& operator=(const PoolingLayer& that) { - if (&that != this) { - CNNLayer::operator=(that); - _kernel = that._kernel; - _padding = that._padding; - _pads_end = that._pads_end; - _stride = that._stride; - _type = that._type; - _exclude_pad = that._exclude_pad; - } - return *this; - } - /** - * @brief copy constructor - */ - PoolingLayer(const PoolingLayer& that) : CNNLayer(that) { - operator=(that); - } - - /** - * @brief move constructor - */ - PoolingLayer(PoolingLayer&&) = default; - - IE_SUPPRESS_DEPRECATED_END - - ~PoolingLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard binary convolution layer - */ -class BinaryConvolutionLayer : public WeightableLayer { -public: - /** - * @enum eBinaryConvolutionMode - * @brief Defines possible modes of binary convolution operation - */ - enum eBinaryConvolutionMode { xnor_popcount = 0 }; - - /** - * @brief Mode of binary convolution operation - */ - eBinaryConvolutionMode _mode = xnor_popcount; - - /** - * @brief A number of input feature maps (size) generating the 3'rd input dimension - */ - unsigned int _in_depth = 0u; - - /** - * @brief A pad value which is used to fill pad area - */ - float _pad_value = 0.0f; - - /** - * @brief A convolution kernel array [X, Y, Z, ...] - */ - DEFINE_PROP(_kernel); - /** - * @brief A convolution paddings begin array [X, Y, Z, ...] - */ - DEFINE_PROP(_padding); - /** - * @brief A convolution paddings end array [X, Y, Z, ...] - */ - PropertyVector _pads_end; - /** - * @brief A convolution strides array [X, Y, Z, ...] - */ - DEFINE_PROP(_stride); - /** - * @brief A convolution dilations array [X, Y, Z, ...] - */ - DEFINE_PROP(_dilation); - /** - * @brief A number of output feature maps (size) generating the 3'rd output dimension - */ - unsigned int _out_depth = 0u; - /** - * @brief Number of groups - */ - unsigned int _group = 1u; - /** - * @brief Auto padding type - */ - std::string _auto_pad; - - IE_SUPPRESS_DEPRECATED_START - - /** - * @brief Creates a new BinaryConvolutionLayer instance. - */ - explicit BinaryConvolutionLayer(const LayerParams& p) - : WeightableLayer(p), - _kernel(2, 0u), - _padding(2, 0u), - _stride(2, 1u), - _dilation(2, 1u) {} - - /** - * @brief assignment operator - */ - BinaryConvolutionLayer& operator=(const BinaryConvolutionLayer& that) { - if (&that != this) { - WeightableLayer::operator=(that); - _kernel = that._kernel; - _padding = that._padding; - _pads_end = that._pads_end; - _stride = that._stride; - _dilation = that._dilation; - _out_depth = that._out_depth; - _group = that._group; - _mode = that._mode; - _in_depth = that._in_depth; - _pad_value = that._pad_value; - } - return *this; - } - /** - * @brief copy constructor - */ - BinaryConvolutionLayer(const BinaryConvolutionLayer& that) : WeightableLayer(that) { - operator=(that); - } - /** - * @brief move constructor - */ - BinaryConvolutionLayer(BinaryConvolutionLayer&&) = default; - - IE_SUPPRESS_DEPRECATED_END - - ~BinaryConvolutionLayer() override; -}; - -#undef DEFINE_PROP - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a fully connected layer - */ -class FullyConnectedLayer : public WeightableLayer { -public: - /** - * @brief A size of output - */ - unsigned int _out_num = 0; - - /** - * @brief Creates a new FullyConnectedLayer instance and initializes layer parameters with the given values. - */ - IE_SUPPRESS_DEPRECATED_START - using WeightableLayer::WeightableLayer; - IE_SUPPRESS_DEPRECATED_END - - ~FullyConnectedLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents concatenation layer - * - * Takes as input several data elements and merges them to one using the supplied axis - */ -class ConcatLayer : public CNNLayer { -public: - /** - * @brief An axis on which concatenation operation is performed - */ - unsigned int _axis = 1; - - /** - * @brief Creates a new ConcatLayer instance and initializes layer parameters with the given values. - * - * If batch is used, then batch needs to be specified as an input dimension also - * In current implementation 1 means channels, 0 - batch - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~ConcatLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a layer that evenly splits the input into the supplied outputs - */ -class SplitLayer : public CNNLayer { -public: - /** - * @brief An axis on which split operation is performed - */ - unsigned int _axis = 1; - - /** - * @brief Creates a new SplitLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~SplitLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a Linear Response Normalization (LRN) Layer - */ -class NormLayer : public CNNLayer { -public: - /** - * @brief Response size - */ - unsigned int _size = 0; - /** - * @brief K - */ - unsigned int _k = 1; - /** - * @brief Alpha coefficient - */ - float _alpha = 0; - /** - * @brief Beta coefficient - */ - float _beta = 0; - /** - * @brief Flag to specify normalization across feature maps (true) or across channels - */ - bool _isAcrossMaps = false; - - /** - * @brief Creates a new NormLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~NormLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents standard softmax Layer - */ -class SoftMaxLayer : public CNNLayer { -public: - /** - * @brief Axis number for a softmax operation - */ - int axis = 1; - /** - * @brief Creates a new SoftMaxLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~SoftMaxLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents standard GRN Layer - */ -class GRNLayer : public CNNLayer { -public: - /** - * @brief A default constructor. Creates a new GRNLayer instance and initializes layer parameters with the given - * values. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - /** - * @brief Bias for squares sum - */ - float bias = 0.f; - - ~GRNLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents standard MVN Layer - */ -class MVNLayer : public CNNLayer { -public: - /** - * @brief A default constructor. Creates a new MVNLayer instance and initializes layer parameters with the given - * values. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - /** - * @brief Indicate that mean value is calculated across channels - */ - int across_channels = 0; - - /** - * @brief Indicate that the result needs to be normalized - */ - int normalize = 1; - - ~MVNLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a Rectified Linear activation layer - */ -class ReLULayer : public CNNLayer { -public: - /** - * @brief Negative slope is used to takle negative inputs instead of setting them to 0 - */ - float negative_slope = 0.0f; - - /** - * @brief Creates a new ReLULayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~ReLULayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a Clamp activation layer - * - * Clamps all tensor elements into the range [min_value, max_value] - */ -class ClampLayer : public CNNLayer { -public: - /** - * @brief A minimum value - */ - float min_value = 0.0f; - - /** - * @brief A maximum value - */ - float max_value = 1.0f; - /** - * @brief Creates a new ClampLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~ClampLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a ReLU6 activation layer - * - * Clamps all tensor elements into the range [0, 6.0] - */ -class ReLU6Layer : public ClampLayer { -public: - IE_SUPPRESS_DEPRECATED_START - /** - * @brief A constructor with common layer parameters - * @param prms The common layer parameters - */ - explicit ReLU6Layer(const LayerParams& prms) : ClampLayer(prms) { - max_value = 6.0f; - } - IE_SUPPRESS_DEPRECATED_END - - ~ReLU6Layer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents an element wise operation layer - */ -class EltwiseLayer : public CNNLayer { -public: - /** - * @enum eOperation - * @brief Defines possible operations that can be used - */ - enum eOperation { - Sum = 0, - Prod, - Max, - Sub, - Min, - Div, - Squared_diff, - Floor_mod, - Pow, - Equal, - Not_equal, - Less, - Less_equal, - Greater, - Greater_equal, - Logical_AND, - Logical_OR, - Logical_XOR, - Logical_NOT, - Mean, - Abs, - }; - - /** - * @brief A type of the operation to use - */ - eOperation _operation = Sum; - - /** - * @brief A vector of coefficients to scale the operands - */ - std::vector coeff; - - /** - * @brief Creates a new EltwiseLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~EltwiseLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard crop layer - */ -class CropLayer : public CNNLayer { -public: - /** - * @brief A vector of dimensions for cropping - */ - std::vector axis; - /** - * @brief A vector of dimensions to be preserved - */ - std::vector dim; - /** - * @brief A vector of offsets for each dimension - */ - std::vector offset; - - /** - * @brief Creates a new CropLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~CropLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard reshape layer - */ -class ReshapeLayer : public CNNLayer { -public: - /** - * @brief A vector of sizes of the shape - */ - std::vector shape; - /** - * @brief A number of axis to be taken for a reshape - */ - int axis = 0; - /** - * @brief A number of first axises to be taken for a reshape - */ - int num_axes = -1; - - /** - * @brief Creates a new ReshapeLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~ReshapeLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Tile Layer - */ -class TileLayer : public CNNLayer { -public: - /** - * @brief An index of the axis to tile - */ - int axis = -1; - /** - * @brief A number of copies to be made - */ - int tiles = -1; - - /** - * @brief Creates a new TileLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~TileLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a Layer which performs Scale and Shift - */ -class ScaleShiftLayer : public WeightableLayer { -public: - /** - * @brief A flag that indicates if the same value is used for all the features. If false, the value is used pixel - * wise - */ - unsigned int _broadcast = 0; - - /** - * @brief Creates a new ScaleShiftLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using WeightableLayer::WeightableLayer; - IE_SUPPRESS_DEPRECATED_END - - ~ScaleShiftLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents TensorIterator layer - */ -class TensorIterator : public CNNLayer { -public: - struct PortMap { - // Data map rule - int from; /**< Index of exteral data from ins/outs fields of CNNLayer */ - int to; /**< Index of internal data in iterator body */ - - // Iteration rule - int axis; /**< Axis to iterate throught */ - int stride; /**< Stride to iterate throught */ - int start; /**< Start index of iteration range */ - int end; /**< Last index of iteration range */ - int part_size; /**< Part size which will be transfered to body subnetwork */ - }; - - /** - * @brief Describes a tensor iterator body - */ - struct Body { - std::vector inputs; //!< Inputs data - std::vector outputs; //!< Outputs data - }; - - std::vector input_port_map; //!< Input ports map - std::vector output_port_map; //!< Output ports map - std::vector back_edges; //!< Back edges map - - Body body; //!< A Tensor Iterator body - - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~TensorIterator() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief Base class for recurrent cell layers - */ -class RNNCellBase : public WeightableLayer { -public: - IE_SUPPRESS_DEPRECATED_START - using WeightableLayer::WeightableLayer; - IE_SUPPRESS_DEPRECATED_END - - /** - * @brief Direct type of recurrent cell (including subtypes) - * Description of particular cell semantics is in LSTMCell, GRUCell, RNNCell. - */ - enum CellType { - LSTM, /**< Original LSTM cell */ - GRU, /**< Original GRU cell */ - RNN, /**< Original RNN cell */ - GRU_LBR, /**< GRU cell modification. "Linear before reset" */ - }; - - /** @copybrief CellType */ - CellType cellType = LSTM; - - /** - * @brief Size of hidden state data - * - * In case of batch output state tensor will have shape [N, hidden_size] - */ - int hidden_size = 0; - - /** - * @brief Clip data into range [-clip, clip] on input of activations - * - * clip==0.0f means no clipping - */ - float clip = 0.0f; - /** - * @brief Activations used inside recurrent cell - * - * Valid values: sigmoid, tanh, relu - */ - std::vector activations; - - /** - * @brief Alpha parameters of activations - * - * Respective to activation list. - */ - std::vector activation_alpha; - - /** - * @brief Beta parameters of activations - * - * Respective to activation list. - */ - std::vector activation_beta; - - ~RNNCellBase() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief LSTM Cell layer - * - * G - number of gates (=4) - * N - batch size - * S - state size (=hidden_size) - * - * Inputs: - * [N,D] Xt - input data - * [N,S] Ht-1 - initial hidden state - * [N,S] Ct-1 - initial cell state - * - * Outputs: - * [N,S] Ht - out hidden state - * [N,S] Ct - out cell state - * - * Weights: - * - weights [G,S,D+S] - * - biases [G,S] - * NB! gates order is FICO {forget, input, candidate, output} - * - * activations is {_f, _g, _h} - * default: {_f=sigm, _g=tanh, _h=tanh} - * - * Equations: - * - * * - matrix mult - * (.) - eltwise mult - * [,] - concatenation - * - * - ft = _f(Wf*[Ht-1, Xt] + Bf) - * - it = _f(Wi*[Ht-1, Xt] + Bi) - * - ct = _g(Wc*[Ht-1, Xt] + Bc) - * - ot = _f(Wo*[Ht-1, Xt] + Bo) - * - Ct = ft (.) Ct-1 + it (.) ct - * - Ht = ot (.) _h(Ct) - */ -class LSTMCell : public RNNCellBase { -public: - IE_SUPPRESS_DEPRECATED_START - using RNNCellBase::RNNCellBase; - using RNNCellBase::operator=; - IE_SUPPRESS_DEPRECATED_END - - ~LSTMCell() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief GRU Cell layer - * - * G - number of gates (=3) - * N - batch size - * S - state size (=hidden_size) - * - * Inputs: - * [N,D] Xt - input data - * [N,S] Ht-1 - initial hidden state - * - * Outputs: - * [N,S] Ht - out hidden state - * - * Weights: - * - weights [G,S,D+S] - * - biases [G,S] - * NB! gates order is ZRH {update, reset, output} - * - * activations is {_f, _g} - * default: {_f=sigm, _g=tanh} - * - * Equations: - * - * * - matrix mult - * (.) - eltwise mult - * [,] - concatenation - * - * - zt = _f(Wz*[Ht-1, Xt] + Bz) - * - rt = _f(Wr*[Ht-1, Xt] + Br) - * - ht = _g(Wh*[rt (.) Ht-1, Xt] + Bh) - * - Ht = (1 - zt) (.) ht + zt (.) Ht-1 - */ -class GRUCell : public RNNCellBase { -public: - IE_SUPPRESS_DEPRECATED_START - using RNNCellBase::RNNCellBase; - using RNNCellBase::operator=; - IE_SUPPRESS_DEPRECATED_END - - ~GRUCell() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief RNN Cell layer - * - * G - number of gates (=1) - * N - batch size - * S - state size (=hidden_size) - * - * Inputs: - * [N,D] Xt - input data - * [N,S] Ht-1 - initial hidden state - * - * Outputs: - * [N,S] Ht - out hidden state - * - * Weights: - * - weights [G,S,D+S] - * - biases [G,S] - * - * activations is {_f} - * default: {_f=tanh} - * - * Equations: - * - * * - matrix mult - * [,] - concatenation - * - * - Ht = _f(Wi*[Ht-1, Xt] + Bi) - */ -class RNNCell : public RNNCellBase { -public: - IE_SUPPRESS_DEPRECATED_START - using RNNCellBase::RNNCellBase; - using RNNCellBase::operator=; - IE_SUPPRESS_DEPRECATED_END - - ~RNNCell() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief Sequence of recurrent cells - * - * N - batch size - * T - sequence size - * S - state size (=hidden_size) - * NS - num of state tensors (LSTM=2, GRU/RNN=1) - * ND - num of direction (BDR=2, WFD/BWD=1) - * - * Inputs: - * [N,T,D] Xt - input data - * [ND,N,S] Ht-1 - initial hidden state - * [ND,N,S] Ct-1 - initial cell state // if NS==2 - * [N] SL - sequence length (optional input) - * - * Outputs: - * [ND,N,T,S] Xt - input data - * [ND,N,S] Ht-1 - initial hidden state - * [ND,N,S] Ct-1 - initial cell state // if NS==2 - * - * NB! if axis==0 batch and sequense dimensions are swapped (N <-> T) for input and output tensors - * - * Weights: - * - weights [ND,G,S,D+S] - * - biases [ND,G,S] - * NB! if ND==2 weights are concatenated cell weights [forward_cell_weights, backward_cell_weights] - * - */ -class RNNSequenceLayer : public RNNCellBase { -public: - IE_SUPPRESS_DEPRECATED_START - using RNNCellBase::RNNCellBase; - IE_SUPPRESS_DEPRECATED_END - - /** - * @brief An axis by which iteration is performed - * - * axis=0 means first input/output data blob dimension is sequence - * axis=1 means first input/output data blob dimension is batch - */ - unsigned int axis = 1; - - /** - * @brief Direction of iteration through sequence dimension - */ - enum Direction { - FWD, /**< Forward mode. Iterate starts from index 0 with step 1. */ - BWD, /**< Backward mode. Iterate starts from last index with step -1. */ - BDR /**< Bidirectional mode. First is forward pass, second is backward. */ - }; - - /** @copybrief Direction */ - Direction direction = FWD; - - ~RNNSequenceLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a Layer which performs Scale and Shift - */ -class PReLULayer : public WeightableLayer { -public: - /** - * @brief A flag that indicates if the same negative_slope value is used for all the features. If false, the value - * is used pixel wise - */ - bool _channel_shared = false; - - /** - * @brief A default constructor. Creates a new PReLULayer instance and initializes layer parameters with the given - * values. - * - * @param prms Initial layer parameters - */ - IE_SUPPRESS_DEPRECATED_START - using WeightableLayer::WeightableLayer; - IE_SUPPRESS_DEPRECATED_END - - ~PReLULayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Power Layer - * - * Formula is: output = (offset + scale * input) ^ power - */ -class PowerLayer : public CNNLayer { -public: - /** - * @brief An exponent value - */ - float power = 1.f; - /** - * @brief A scale factor - */ - float scale = 1.f; - /** - * @brief An offset value - */ - float offset = 0.f; - - /** - * @brief Creates a new PowerLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~PowerLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a Batch Normalization Layer - */ -class BatchNormalizationLayer : public WeightableLayer { -public: - /** - * @brief A small value to add to the variance estimate to avoid division by zero - */ - float epsilon = 1e-3f; - - /** - * @brief Creates a new BatchNormalizationLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using WeightableLayer::WeightableLayer; - IE_SUPPRESS_DEPRECATED_END - - ~BatchNormalizationLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a general matrix multiplication operation layer - * - * Formula is: dst := alpha*src1*src2 + beta*src3 - */ -class GemmLayer : public CNNLayer { -public: - /** - * @brief A scale factor of src1 matrix - */ - float alpha = 1.f; - /** - * @brief A scale factor of src3 matrix - */ - float beta = 1.f; - /** - * @brief A flag that indicates if the src1 matrix is to be transposed - */ - bool transpose_a = false; - /** - * @brief A flag that indicates if the src2 matrix is to be transposed - */ - bool transpose_b = false; - /** - * @brief Creates a new GemmLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~GemmLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Pad layer - * - * Adds paddings to input tensor - */ -class PadLayer : public CNNLayer { -public: - /** - * @enum ePadMode - * @brief Defines possible modes of pad operation - */ - enum ePadMode { Constant = 0, Edge, Reflect, Symmetric }; - - /** - * @brief Size of padding in the beginning of each axis - */ - PropertyVector pads_begin; - /** - * @brief Size of padding in the end of each axis - */ - PropertyVector pads_end; - /** - * @brief Mode of pad operation - */ - ePadMode pad_mode = Constant; - /** - * @brief A pad value which is used for filling in Constant mode - */ - float pad_value = 0.0f; - /** - * @brief Creates a new PadLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~PadLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Gather layer - * - * Gather slices from Dictionary according to Indexes - */ -class GatherLayer : public CNNLayer { -public: - /** - * @brief The axis in Dictionary to gather Indexes from - */ - int axis = 0; - /** - * @brief Creates a new GatherLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~GatherLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Strided Slice layer - * - * Strided Slice picks from input tensor according parameters - */ -class StridedSliceLayer : public CNNLayer { -public: - /** - * @brief The begin_mask is a bitmask where bit i being 0 means - * to ignore the begin value and instead use the default value - */ - std::string begin_mask; - /** - * @brief Analogous to begin_mask - */ - std::string end_mask; - /** - * @brief The ellipsis_mask is a bitmask where bit i being 1 means - * the i-th is actually an ellipsis - */ - std::string ellipsis_mask; - /** - * @brief The new_axis_mask_ is a bitmask where bit i being 1 means - * the i-th position creates a new 1 dimension shape - */ - std::string new_axis_mask; - /** - * @brief The shrink_axis_mask is a bitmask where bit i being 1 means - * the i-th position shrinks the dimensionality - */ - std::string shrink_axis_mask; - - /** - * @brief Creates a new StridedSliceLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~StridedSliceLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Shuffle Channels layer - * Shuffle Channels picks from input tensor according parameters - */ -class ShuffleChannelsLayer : public CNNLayer { -public: - /** - * @brief The axis in tensor to shuffle channels - */ - int axis = 1; - - /** - * @brief The group of output shuffled channels - */ - unsigned int group = 1; - - /** - * @brief Creates a new ShuffleChannelsLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~ShuffleChannelsLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Depth To Space layer - * Depth To Space picks from input tensor according parameters - */ -class DepthToSpaceLayer : public CNNLayer { -public: - /** - * @brief The group of output shuffled channels - */ - unsigned int block_size = 1; - - /** - * @brief Creates a new DepthToSpaceLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~DepthToSpaceLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Space To Depth layer - * Space To Depth picks from input tensor according parameters - */ -class SpaceToDepthLayer : public CNNLayer { -public: - /** - * @brief The group of output Space To Depth - */ - unsigned int block_size = 1; - - /** - * @brief Creates a new SpaceToDepthLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~SpaceToDepthLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Space To Batch layer - * - * Space To Batch picks from input tensor according parameters - */ -class SpaceToBatchLayer : public CNNLayer { -public: - /** - * @brief Spatial dimensions blocks sizes - */ - std::vector _block_shape; - - /** - * @brief Size of padding in the beginning of each axis - */ - std::vector _pads_begin; - /** - * @brief Size of padding in the end of each axis - */ - std::vector _pads_end; - - /** - * @brief Creates a new SpaceToBatchLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~SpaceToBatchLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Batch To Space layer - * - * Batch To Space picks from input tensor according parameters - */ -class BatchToSpaceLayer : public CNNLayer { -public: - /** - * @brief Spatial dimensions blocks sizes - */ - std::vector _block_shape; - - /** - * @brief It specifies how many elements to crop from the intermediate result - * across the spatial dimensions - */ - std::vector _crops_begin; - - /** - * @brief It specifies how many elements to crop from the intermediate result - * across the spatial dimensions - */ - std::vector _crops_end; - - /** - * @brief Creates a new BatchToSpaceLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~BatchToSpaceLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents SparseFillEmptyRows layer - * - * SparseFillEmptyRows fills empty rows in a sparse tensor - */ -class SparseFillEmptyRowsLayer : public CNNLayer { -public: - /** - * @brief Creates a new SparseFillEmptyRowsLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~SparseFillEmptyRowsLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents SparseSegmentMean(SqrtN, Sum) layers - * SparseSegmentMean(SqrtN, Sum) layer reduces data along sparse segments of a tensor. - */ -class SparseSegmentReduceLayer : public CNNLayer { -public: - /** - * @brief Creates a new SparseSegmentReduceLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~SparseSegmentReduceLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents ExperimentalSparseWeightedReduce layer - * ExperimentalSparseWeightedReduce layer reduces data along sparse segments of a tensor. - */ -class ExperimentalSparseWeightedReduceLayer : public CNNLayer { -public: - /** - * @brief Creates a new ExperimentalSparseWeightedReduceLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~ExperimentalSparseWeightedReduceLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents SparseToDense layer - * SparseToDense layer converts a sparse tensor to a dense tensor. - */ -class SparseToDenseLayer : public CNNLayer { -public: - /** - * @brief Creates a new SparseToDenseLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~SparseToDenseLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents Bucketize layer - * Bucketize layer bucketizes the input based on the boundaries. - */ -class BucketizeLayer : public CNNLayer { -public: - /** - * @brief Indicates whether the intervals include the right or the left bucket edge. - */ - bool with_right_bound = true; - - /** - * @brief Creates a new BucketizeLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~BucketizeLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Reverse Sequence layer - * - * Reverse Sequence modifies input tensor according parameters - */ -class ReverseSequenceLayer : public CNNLayer { -public: - /** - * @brief The seq_axis dimension in tensor which is partially reversed - */ - int seq_axis = 1; - - /** - * @brief The batch_axis dimension in tensor along which reversal is performed - */ - int batch_axis = 0; - - /** - * @brief Creates a new ReverseSequence instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~ReverseSequenceLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a OneHot layer - * Converts input into OneHot representation. - */ -class OneHotLayer : public CNNLayer { -public: - /** - * @brief A depth of representation - */ - unsigned int depth = 0; - - /** - * @brief The locations represented by indices in input take value on_value - */ - float on_value = 1.f; - - /** - * @brief The locations not represented by indices in input take value off_value - */ - float off_value = 0.f; - - /** - * @brief Define the shape of output tensor - */ - int axis = -1; - - /** - * @brief Creates a new OneHot instance - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~OneHotLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard RangeLayer layer - * - * RangeLayer modifies input tensor dimensions according parameters - */ -class RangeLayer : public CNNLayer { -public: - /** - * @brief Creates a new RangeLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~RangeLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Fill layer - * - * RFill modifies input tensor according parameters - */ -class FillLayer : public CNNLayer { -public: - /** - * @brief Creates a new Fill instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~FillLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a SelectLayer layer - * - * SelectLayer layer takes elements from the second (“then”) or the third (“else”) input based on condition mask - * (“cond”) provided in the first input. The “cond” tensor is broadcasted to “then” and “else” tensors. The output - * tensor shape is equal to broadcasted shape of “cond”, “then” and “else”. - */ -class SelectLayer : public CNNLayer { -public: - /** - * @brief Creates a new SelectLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~SelectLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Broadcast layer - * - * Broadcast modifies input tensor dimensions according parameters - */ -class BroadcastLayer : public CNNLayer { -public: - /** - * @brief Creates a new Broadcast instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~BroadcastLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a quantization operation layer - * - * Element-wise linear quantization of floating point input values into a descrete set of floating point values - */ -class QuantizeLayer : public CNNLayer { -public: - /** - * @brief The number of quantization levels - */ - size_t levels = 1; - - /** - * @brief Creates a new QuantizeLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~QuantizeLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Math layers - * - * Math modifies input tensor dimensions according parameters - */ -class MathLayer : public CNNLayer { -public: - /** - * @brief Creates a new Math instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~MathLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard Reduce layers - * - * Reduce modifies input tensor according parameters - */ -class ReduceLayer : public CNNLayer { -public: - /** - * @brief The keep_dims dimension in tensor which is partially reversed - */ - bool keep_dims = true; - - /** - * @brief Creates a new Reduce instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~ReduceLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard TopK layer - * - * TopK picks top K values from input tensor according parameters - */ -class TopKLayer : public CNNLayer { -public: - /** - * @brief The mode could be 'max' or 'min' - */ - std::string mode; - /** - * @brief top K values sort mode could be 'value' or 'index' - */ - std::string sort; - /** - * @brief The axis dimension in tensor which is top K values are picked - */ - int axis = -1; - - /** - * @brief Creates a new TopKLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~TopKLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents Unique layer. - * - * The Unique operation searches for unique elements in 1-D input - */ -class UniqueLayer : public CNNLayer { -public: - /** - * @brief A flag indicating whether to sort unique elements - */ - bool sorted; - /** - * @brief A flag indicating whether to return indices of input data elements in the output of uniques - */ - bool return_inverse; - /** - * @brief A flag indicating whether to return a number of occurrences for each unique element - */ - bool return_counts; - - /** - * @brief Creates a new UniqueLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~UniqueLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard NonMaxSuppression layer - */ -class NonMaxSuppressionLayer : public CNNLayer { -public: - /** - * @brief The 'center_point_box' indicates the format of the box data - */ - bool center_point_box = false; - /** - * @brief The 'sort_result_descending' indicates that result will sort descending by score through all batches and - * classes - */ - bool sort_result_descending = true; - /** - * @brief Output type for first and third inputs - */ - std::string output_type = "I64"; - /** - * @brief Creates a new NonMaxSuppressionLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~NonMaxSuppressionLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard ScatterUpdate layer - */ -class ScatterUpdateLayer : public CNNLayer { -public: - /** - * @brief Creates a new ScatterUpdateLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~ScatterUpdateLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents a standard ScatterElementsUpdate layer - */ -class ScatterElementsUpdateLayer : public CNNLayer { -public: - /** - * @brief Creates a new ScatterElementsUpdateLayer instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - ~ScatterElementsUpdateLayer() override; -}; - -/** - * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2021.1 - * @brief This class represents an onnx ExperimentalDetectronPriorGridGenerator Layer - */ -class ExperimentalDetectronPriorGridGeneratorLayer : public CNNLayer { -public: - /** - * @brief flatten value - */ - int flatten = 1; - /** - * @brief Value of grid width - */ - int grid_w = 0; - /** - * @brief Value of grid height - */ - int grid_h = 0; - /** - * @brief Value of width step between grid cells - */ - float stride_w = 0.f; - /** - * @brief Value of height step between grid cells - */ - float stride_h = 0.f; - - /** - * @brief Creates a new ExperimentalDetectronPriorGridGenerator instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - virtual ~ExperimentalDetectronPriorGridGeneratorLayer(); -}; - -/** - * @brief This class represents a standard ExperimentalDetectronTopKROIs layer - */ -class ExperimentalDetectronTopKROIs : public CNNLayer { -public: - /** - * @brief The maximum number of output rois - */ - int max_rois = 0; - /** - * @brief Creates a new ExperimentalDetectronTopKROIs instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - virtual ~ExperimentalDetectronTopKROIs(); -}; - -/** - * @brief This class represents an onnx ExperimentalDetectronGenerateProposalsSingleImage Layer - */ -class ExperimentalDetectronGenerateProposalsSingleImageLayer : public CNNLayer { -public: - /** - * @brief Minimium width and height for boxes - */ - float min_size = 0.f; - /** - * @brief Non max suppression threshold - */ - float nms_threshold = 0.7f; - /** - * @brief Maximum number of anchors selected before nms - */ - int pre_nms_topn = 1000; - /** - * @brief Maximum number of anchors selected after nms - */ - int post_nms_topn = 1000; - - /** - * @brief Creates a new ExperimentalDetectronGenerateProposalsSingleImage instance. - */ - IE_SUPPRESS_DEPRECATED_START - using CNNLayer::CNNLayer; - IE_SUPPRESS_DEPRECATED_END - - virtual ~ExperimentalDetectronGenerateProposalsSingleImageLayer(); -}; - -_IE_SUPPRESS_DEPRECATED_END_MSVC - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/ie_layers_internal.hpp b/src/plugins/intel_gna/legacy/include/legacy/ie_layers_internal.hpp deleted file mode 100644 index afb6989c70a..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ie_layers_internal.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include - -#include - -#include "legacy/ie_util_internal.hpp" - -namespace InferenceEngine { - -class Paddings { -public: - PropertyVector begin; - PropertyVector end; -}; - -/** - * @brief gets padding with runtime type check - */ -Paddings getPaddingsImpl(const CNNLayer& layer); - -/** - * @brief checks that given type is one of specified in variadic template list - * @tparam ... - */ -template -struct is_one_of { - static constexpr bool value = false; -}; - -/** - * @brief checks that given type is one of specified in variadic template list - * @tparam ... - */ -template -struct is_one_of { - static constexpr bool value = std::is_same::value || is_one_of::value; -}; - -IE_SUPPRESS_DEPRECATED_START - -/** - * @brief gets padding without compile-time type check - */ -template -inline typename std::enable_if::value, - Paddings>::type -getPaddings(const T& layer) { - return getPaddingsImpl(layer); -} - -/********************************************* - * TensorIterator Helpers section - *********************************************/ - -/** - * @brief Calculate number of iteration required for provided TI layer - * - * @param ti TensorIterator layer to parse - * @return positive value in case of correct TI layer, -1 in case of inconsistency - */ -int getNumIteration(const TensorIterator& ti); - -IE_SUPPRESS_DEPRECATED_END - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/ie_layers_property.hpp b/src/plugins/intel_gna/legacy/include/legacy/ie_layers_property.hpp deleted file mode 100644 index 610dbe6807f..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ie_layers_property.hpp +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief a header file for describing property style structure used by CNNLayers - * - * @file ie_layers_property.hpp - */ -#pragma once - -#include - -#include - -namespace InferenceEngine { - -constexpr const int MAX_DIMS_NUMBER = 12; - -enum eDIMS_AXIS : uint8_t { X_AXIS = 0, Y_AXIS, Z_AXIS }; - -template -class PropertyVector { - T _axises[N] = {}; - bool _allocated[N] = {}; - size_t _length = 0; - -public: - PropertyVector() = default; - - PropertyVector(size_t len, T val) { - if (len > N) { - IE_THROW() << "Property size exceeed limit of: " << N; - } - for (size_t i = 0; i < len; i++) { - _axises[i] = val; - _allocated[i] = true; - } - _length = len; - } - - explicit PropertyVector(const std::vector& values) { - size_t i = 0; - for (const auto val : values) { - insert(i++, val); - } - } - - PropertyVector(std::initializer_list init_list) { - size_t i = 0; - for (const auto val : init_list) { - insert(i++, val); - } - } - - /** - * @brief allows access up-to capacity size - * - * @param index - * @return - */ - T& at(int index) { - if (index >= N) { - IE_THROW() << "Property index is out of bounds (" << index << "/" << N; - } - return _axises[index]; - } - - const T& operator[](size_t index) const { - if (index >= N || !_allocated[index]) { - IE_THROW() << "Property index (" << index << ") is out of bounds"; - } - return _axises[index]; - } - - T& operator[](size_t index) { - if (index >= N || !_allocated[index]) { - IE_THROW() << "Property index (" << index << ") is out of bounds"; - } - return _axises[index]; - } - - PropertyVector& operator=(const PropertyVector& src) { - if (this != &src) { - _length = src.size(); - for (size_t i = 0; i < N; i++) { - _allocated[i] = src._allocated[i]; - if (_allocated[i]) { - _axises[i] = src[i]; - } - } - } - return *this; - } - - bool operator==(const PropertyVector& src) const { - if (this == &src) - return true; - if (_length != src.size()) - return false; - for (size_t i = 0; i < N; i++) - if ((_allocated[i] != src._allocated[i]) || (_allocated[i] && _axises[i] != src._axises[i])) - return false; - return true; - } - - size_t size() const { - return _length; - } - - void insert(size_t axis, const T& val) { - if (axis < N) { - if (!_allocated[axis]) { - _allocated[axis] = true; - _length++; - } - _axises[axis] = val; - } else { - IE_THROW() << "Layer Property insertion at(axis) should be in [0," << N << ")"; - } - } - - void remove(size_t axis) { - if (axis < N && _allocated[axis]) { - _allocated[axis] = false; - _length--; - } - } - - void clear() { - for (int i = 0; i != N; i++) { - _allocated[i] = 0; - } - _length = 0u; - } - - bool exist(size_t axis) const { - return (axis < N && _allocated[axis]); - } -}; - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/ie_reader.hpp b/src/plugins/intel_gna/legacy/include/legacy/ie_reader.hpp deleted file mode 100644 index 586d01a0130..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ie_reader.hpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include -#include -#include - -namespace InferenceEngine { - -/** - * @brief IReader an abstract interface for Inference Engine readers - */ -class IReader : public std::enable_shared_from_this { -public: - /** - * @brief Checks that reader supports format of the model - * @param model stream with model - * @return true if format is supported - */ - virtual bool supportModel(std::istream& model) const = 0; - /** - * @brief Reads the model to CNNNetwork - * @param model stream with model - * @param exts vector with extensions - * - * @return CNNNetwork - */ - virtual CNNNetwork read(std::istream& model, const std::vector& exts) const = 0; - /** - * @brief Reads the model to CNNNetwork - * @param model stream with model - * @param weights stream with binary data - * @param exts vector with extensions - * - * @return CNNNetwork - */ - virtual CNNNetwork read(std::istream& model, - const Blob::CPtr& weights, - const std::vector& exts) const = 0; - - /** - * @brief Returns all supported extensions for data files - * - * @return vector of file extensions, for example the reader for OpenVINO IR returns {"bin"} - */ - virtual std::vector getDataFileExtensions() const = 0; - -protected: - virtual ~IReader() = default; -}; - -/** - * @brief Creates the default instance of the reader - * @return Reader interface - */ -INFERENCE_PLUGIN_API(void) CreateReader(std::shared_ptr& reader); - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/ie_util_internal.hpp b/src/plugins/intel_gna/legacy/include/legacy/ie_util_internal.hpp deleted file mode 100644 index b3e1f22de4e..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ie_util_internal.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace InferenceEngine { - -/** - * @brief Creates data object copy unconnected to any graph - * @param source - source data object - * @return Shared pointer to new data object - */ -DataPtr cloneData(const Data& source); - -IE_SUPPRESS_DEPRECATED_START - -/** - * @brief Creates layer object copy, unconnected to any grapoh - * @param source - source layer object - * @return Shared pointer to new layer object - */ -CNNLayerPtr clonelayer(const CNNLayer& source); - -/** - * @brief Clones selected set of nodes into separate network - * only connections between passed nodes will be duplicated - * - * @param layers Layers to clone, must all be in same network - * @param networkStats A network statistic to clone - * - * @return Cloned network - */ -InferenceEngine::details::CNNNetworkImplPtr cloneNet(const std::vector& layers); - -IE_SUPPRESS_DEPRECATED_END - -/** - * @brief Clones the whole network without conversion to CNNNetworkImpl. All layers and data objects will be cloned - * @note Blobs inside layers are reused - * @param network A network to clone - * @return A cloned object - */ -InferenceEngine::CNNNetwork cloneNetwork(const InferenceEngine::CNNNetwork& network); - -/** - * @brief Clones the whole network. All layers and data objects will be cloned - * @note Blobs inside layers are reused - * @param network A network to clone - * @return A cloned object - */ -InferenceEngine::details::CNNNetworkImplPtr cloneNet(const InferenceEngine::CNNNetwork& network); - -using ordered_properties = std::vector>; -using printer_callback = - std::function; - -/** - * @brief Visualize network in GraphViz (.dot) format and write to output stream - * - * @param network - graph to visualize - * @param out - output stream for saving graph - * @param layer_cb - callback function, that called on every printed layer node - */ -void saveGraphToDot(const InferenceEngine::CNNNetwork& network, std::ostream& out, printer_callback layer_cb = nullptr); - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/layer_transform.hpp b/src/plugins/intel_gna/legacy/include/legacy/layer_transform.hpp deleted file mode 100644 index 69c82871449..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/layer_transform.hpp +++ /dev/null @@ -1,227 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -namespace InferenceEngine { - -IE_SUPPRESS_DEPRECATED_START - -namespace details { - -template -class LayerInjector : public T { -public: - InjectType injected; - explicit LayerInjector(const T& base) : T(base) {} -}; - -using AllLayers = std::tuple; - -template -inline typename std::enable_if::type visitActualLayer(std::tuple&& t, - const CNNLayer& sourceLayer, - const Visitor& v) {} - -template - inline typename std::enable_if < I::type visitActualLayer(std::tuple&& t, - const CNNLayer& sourceLayer, - const Visitor& visitor) { - using EType = typename std::tuple_element>::type; - auto casted = dynamic_cast(const_cast(&sourceLayer)); - - if (casted != nullptr) { - // means no need to handle further layers - if (visitor(casted)) { - return; - } - } - - visitActualLayer(std::move(t), sourceLayer, visitor); -} - -template -inline typename std::enable_if::type injectHelper(std::tuple& t, - const CNNLayer& sourceLayer, - CNNLayerPtr& targetLayer, - const InjectedType& value) {} - -template - inline typename std::enable_if < I::type injectHelper(std::tuple& t, - const CNNLayer& sourceLayer, - CNNLayerPtr& target, - const InjectedType& value) { - if (target) { - return; - } - using EType = typename std::tuple_element>::type; - auto casted = dynamic_cast(const_cast(&sourceLayer)); - - if (casted != nullptr) { - auto layerWithInjectedData = - std::make_shared::type, InjectedType>>(*casted); - - // copy outdata - for (auto&& data : layerWithInjectedData->outData) { - data = std::make_shared(*data.get()); - } - - layerWithInjectedData->injected = value; - - target = layerWithInjectedData; - } - - injectHelper(t, sourceLayer, target, value); -} - -template -inline typename std::enable_if::type locateInjected(std::tuple& t, - const CNNLayer& sourceLayer, - InjectedType*& value) {} - -template - inline typename std::enable_if < I::type locateInjected(std::tuple& t, - const CNNLayer& sourceLayer, - InjectedType*& value) { - if (value != nullptr) { - return; - } - using EType = typename std::tuple_element>::type; - auto injectedLayer = dynamic_cast::type, InjectedType>*>( - const_cast(&sourceLayer)); - - if (injectedLayer != nullptr) { - value = &injectedLayer->injected; - } - - locateInjected(t, sourceLayer, value); -} - -} // namespace details - -/** - * @brief creates copy of source layer, with injected arbitrary data - * @tparam InjectType data type to be injected - * @param sourceLayer - * @param value injected value - * @return newly created layer with injected data - */ -template -inline CNNLayerPtr injectData(const CNNLayer& sourceLayer, const InjectType& value = InjectType()) { - details::AllLayers layers; - CNNLayerPtr targetLayer; - details::injectHelper(layers, sourceLayer, targetLayer, value); - - return targetLayer; -} - -template -inline CNNLayerPtr injectData(CNNLayerPtr sourceLayer, const InjectType& value = InjectType()) { - return injectData(*sourceLayer.get(), value); -} - -/** - * @brief transforms of source layer - * @tparam InjectType data type to be injected - * @param sourceLayer - * @param value injected value - * @return newly created layer with injected data - */ -template -inline void transformLayer(const CNNLayer& sourceLayer, const Transformer& transformer) { - details::visitActualLayer(std::move(details::AllLayers()), sourceLayer, transformer); -} - -template -inline void transformLayer(CNNLayerPtr sourceLayer, const Transformer& transformer) { - transformLayer(*sourceLayer.get(), transformer); -} - -/** - * @brief getPointer to injected data - * @tparam InjectType - * @param sourceLayer - * @return if previously data of type InjectType was injected, will return pointer to it, nullptr otherwise - */ -template -inline InjectType* getInjectedData(const CNNLayer& sourceLayer) { - details::AllLayers layers; - InjectType* injected = nullptr; - - details::locateInjected(layers, sourceLayer, injected); - - return injected; -} - -template -inline InjectType* getInjectedData(CNNLayerPtr sourceLayer) { - return getInjectedData(*sourceLayer.get()); -} - -IE_SUPPRESS_DEPRECATED_END - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/net_pass.h b/src/plugins/intel_gna/legacy/include/legacy/net_pass.h deleted file mode 100644 index e52bce305a2..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/net_pass.h +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "cpp/ie_cnn_network.h" -#include "legacy/graph_tools.hpp" - -namespace InferenceEngine { -namespace NetPass { - -IE_SUPPRESS_DEPRECATED_START - -/** - * Try to detect LSTM Sequence pattern inside TI and convert it - * - * @param net network to modify - * @return true if all Tensor iterator was converted - */ -bool CombineRNNSeq(CNNNetwork& net); -bool CombineRNNSeq(TensorIterator::Body& net); - -/** - * Returns a vector of the topologically sorted layers from - * the passed TI layer body. - * - * @param body TI body - * @return vector of layer objects - */ -std::vector TIBodySortTopologically(const TensorIterator::Body& body); - -/** - * Check if provided layer contains internal attribute like subnet/subgraph - * - * @param layer to check - * @return true if layer has subnet - */ -bool HasInternalSubnet(const CNNLayerPtr& layer); - -/** - * Extract internal subnet from layer - * - * All internal layers are returned by reference. Any modification further subnet modification will - * has affect on original layer state. - * - * @param layer to proceed - * @return internal subnet - */ -details::CNNSubnet GetInternalSubnet(const CNNLayerPtr& layer); - -/** - * Unroll all present Tensor Iterators - * - * @param net network to modify - * @return true if all Tensor iterator was unrolled successfully - */ -bool UnrollTI(CNNNetwork& net); - -/** - * Unroll all RNN specific layers by predicate - * - * Will be applied to all RNNSeq and RNNCell layers - * - * @param net network to modify - * @param pred predicate to mark layer to unroll - * @return true if all RNN layers was unrolled successfully - */ -bool UnrollRNN_if(CNNNetwork& net, std::function pred); - -/** - * Construct a copy of provided subnet. Will change names by adding suffix if it was provided. - * - * @param subnet to copy from - * @param suffix is optional attribute. Will be added into name of each layer/data object if provided - * @return subnet copy. Each layer/data object is newly created. Const blob objects is inherited from - * original subnet. - */ -TensorIterator::Body CopyTIBody(const TensorIterator::Body& body, std::string suffix = std::string()); - -bool UnrollRNN_if(TensorIterator::Body& net, std::function pred); - -IE_SUPPRESS_DEPRECATED_END - -/** - * Precision conversion pass - * - * Will perform conversion of all presented tensors with specified precision including - * const blobs and intermediate tensors. It doesn't check layer semantic. It may break - * correctness of topology. - * - * It also remove redundant convert layers if they will appear. - * - * @param net is network to apply conversion - * @param from precision of tensors required conversion - * @param to resulting precision of tensors - */ -void ConvertPrecision(CNNNetwork& net, Precision from, Precision to); - -void ConvertIOPrecision(CNNNetwork& net, Precision from, Precision to); - -} // namespace NetPass -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/convolution_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/convolution_ie.hpp deleted file mode 100644 index 40f461cd960..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/convolution_ie.hpp +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "ngraph/coordinate_diff.hpp" -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class ConvolutionIE : public Op { -public: - OPENVINO_OP("ConvolutionIE", "util"); - /// \brief Constructs a batched convolution operation. - ConvolutionIE() = default; - /// \brief Constructs a batched convolution operation. - /// - /// \param data_batch The node producing the input data batch tensor.
- /// `[N, C_IN, D1, ... Df]` - /// \param filters The node producing the filters tensor.
- /// `[C_OUT, C_IN, F1, ... Ff]` - /// \param strides The strides.
- /// `[f]` - /// \param dilations The dilations.
- /// `[f]` - /// \param pads_begin The beginning of padding shape.
- /// `[f]` - /// \param pads_end The end of padding shape.
- /// `[f]` - /// \param auto_pad The pad type for automatically computing padding sizes.
- /// `[f]` - /// - /// Output `[N, C_OUT, R1, ... Rf]` - /// - ConvolutionIE(const Output& data_batch, - const Output& filters, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const element::Type output_type, - const size_t& group = 1, - const PadType& auto_pad = PadType::EXPLICIT); - - ConvolutionIE(const Output& data_batch, - const Output& filters, - const Output& bias, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const element::Type output_type, - const size_t& group = 1, - const PadType& auto_pad = PadType::EXPLICIT); - - // KMB compilation support - ConvolutionIE(const Output& data_batch, - const Output& filters, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const size_t& group = 1, - const PadType& auto_pad = PadType::EXPLICIT); - - // KMB compilation support - ConvolutionIE(const Output& data_batch, - const Output& filters, - const Output& bias, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const size_t& group = 1, - const PadType& auto_pad = PadType::EXPLICIT); - - void validate_and_infer_types() override; - - bool visit_attributes(AttributeVisitor& visitor) override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - /// \return The strides. - const Strides& get_strides() const { - return m_strides; - } - void set_strides(const Strides& strides) { - m_strides = strides; - } - /// \return The dilations. - const Strides& get_dilations() const { - return m_dilations; - } - void set_dilations(const Strides& dilations) { - m_dilations = dilations; - } - /// \return The padding-below sizes (possibly negative). - const CoordinateDiff& get_pads_begin() const { - return m_pads_begin; - } - void set_pads_begin(const CoordinateDiff& pads_begin) { - m_pads_begin = pads_begin; - } - /// \return The padding-above sizes (possibly negative). - const CoordinateDiff& get_pads_end() const { - return m_pads_end; - } - void set_adding_above(const CoordinateDiff& pads_end) { - m_pads_end = pads_end; - } - /// \return The pad type for convolution. - const PadType& get_auto_pad() const { - return m_auto_pad; - } - void set_auto_pad(const PadType& auto_pad) { - m_auto_pad = auto_pad; - } - /// \return The groups for convolution. - const size_t& get_group() const { - return m_group; - } - void set_group(const size_t& group) { - m_group = group; - } - -protected: - Strides m_strides; - Strides m_dilations; - CoordinateDiff m_pads_begin; - CoordinateDiff m_pads_end; - PadType m_auto_pad; - size_t m_group; - element::Type m_output_type; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/crop_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/crop_ie.hpp deleted file mode 100644 index 970f254ea73..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/crop_ie.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class CropIE : public Op { -public: - OPENVINO_OP("CropIE", "legacy"); - - CropIE(const Output& data1, std::vector axes, std::vector dim, std::vector offset); - - bool visit_attributes(AttributeVisitor& visitor) override; - - void validate_and_infer_types() override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - std::vector axes, dim, offset; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/deconvolution_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/deconvolution_ie.hpp deleted file mode 100644 index ceb9db90271..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/deconvolution_ie.hpp +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "ngraph/coordinate_diff.hpp" -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class DeconvolutionIE : public Op { -public: - OPENVINO_OP("DeconvolutionIE", "util"); - - DeconvolutionIE() = default; - - DeconvolutionIE(const Output& data, - const Output& filters, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const element::Type output_type, - const size_t& group = 1, - const PadType& auto_pad = PadType::EXPLICIT, - const CoordinateDiff& output_padding = {}, - const std::shared_ptr& output_shape = nullptr); - - DeconvolutionIE(const Output& data, - const Output& filters, - const Output& bias, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const element::Type output_type, - const size_t& group = 1, - const PadType& auto_pad = PadType::EXPLICIT, - const CoordinateDiff& output_padding = {}, - const std::shared_ptr& output_shape = nullptr); - - void validate_and_infer_types() override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - /// \return The strides from the forward prop. - const Strides& get_strides() const { - return m_strides; - } - void set_strides(const Strides& strides) { - m_strides = strides; - } - /// \return The dilations from the forward prop. - const Strides& get_dilations() const { - return m_dilations; - } - void set_dilations(const Strides& dilations) { - m_dilations = dilations; - } - /// \return The padding-below sizes (possibly negative) from the forward prop. - const CoordinateDiff& get_pads_begin() const { - return m_pads_begin; - } - void set_pads_begin(const CoordinateDiff& pads_begin) { - m_pads_begin = pads_begin; - } - /// \return The padding-above sizes (possibly negative) from the forward prop. - const CoordinateDiff& get_pads_end() const { - return m_pads_end; - } - void set_pads_end(const CoordinateDiff& pads_end) { - m_pads_end = pads_end; - } - /// \return The auto pad. - const PadType& get_auto_pad() const { - return m_auto_pad; - } - void set_auto_pad(const PadType& auto_pad) { - m_auto_pad = auto_pad; - } - /// \return The group - const size_t& get_group() const { - return m_group; - } - void set_group(const size_t& group) { - m_group = group; - } - bool visit_attributes(AttributeVisitor& visitor) override; - -protected: - Strides m_strides; - Strides m_dilations; - CoordinateDiff m_pads_begin; - CoordinateDiff m_pads_end; - PadType m_auto_pad; - size_t m_group; - CoordinateDiff m_output_padding; - std::shared_ptr m_output_shape; - element::Type m_output_type; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/eltwise.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/eltwise.hpp deleted file mode 100644 index bbdd455c58c..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/eltwise.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "ngraph/op/op.hpp" - -enum class ELTWISE_TYPE { Sum, Prod, Max, Sub, Min, Div }; -namespace ngraph { -namespace op { - -class Eltwise : public Op { -public: - OPENVINO_OP("Eltwise", "legacy"); - - Eltwise(const Output& data1, - const Output& data2, - const ELTWISE_TYPE eltwise_type, - const element::Type output_type = element::undefined); - - bool visit_attributes(AttributeVisitor& visitor) override; - - void validate_and_infer_types() override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - ELTWISE_TYPE eltwise_type; - -private: - ELTWISE_TYPE type_from_string(const std::string& eltwise_type) const { - return as_enum(eltwise_type); - } - element::Type m_output_type; -}; - -} // namespace op - -std::ostream& operator<<(std::ostream& s, const ELTWISE_TYPE& type); -} // namespace ngraph - -namespace ov { - -template <> -class AttributeAdapter : public EnumAttributeAdapterBase { -public: - AttributeAdapter(ELTWISE_TYPE& value) : EnumAttributeAdapterBase(value) {} - - OPENVINO_RTTI("AttributeAdapter"); -}; - -} // namespace ov diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/fully_connected.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/fully_connected.hpp deleted file mode 100644 index ac40e385925..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/fully_connected.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "ngraph/node.hpp" -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -/// \brief Operator performing Matrix Multiplication. -class FullyConnected : public Op { -public: - OPENVINO_OP("FullyConnected", "legacy"); - FullyConnected() = default; - /// \brief Constructs an FullyConnected operation. - /// - /// \param A Matrix A - /// \param B Matrix B - /// \param C Matrix C - FullyConnected(const Output& A, - const Output& B, - const Output& C, - const Shape& output_shape, - const element::Type output_type = element::undefined); - - bool visit_attributes(AttributeVisitor& visitor) override; - - void validate_and_infer_types() override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - size_t get_out_size() const { - return m_output_size; - } - - element::Type get_output_type() const { - return m_output_type; - } - -private: - size_t m_output_size = 0; - Shape m_output_shape = {}; - element::Type m_output_type; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gather_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gather_ie.hpp deleted file mode 100644 index c7e49e98b93..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gather_ie.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class GatherIE : public Op { -public: - OPENVINO_OP("GatherIE", "legacy"); - GatherIE() = default; - - GatherIE(const Output& params, const Output& indices, int64_t axis); - - void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; - int64_t get_axis() const { - return m_axis; - } - void set_axis(int64_t axis) { - m_axis = axis; - } - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - -protected: - int64_t m_axis; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gather_tree_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gather_tree_ie.hpp deleted file mode 100644 index ba0767871c1..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gather_tree_ie.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class GatherTreeIE : public Op { -public: - OPENVINO_OP("GatherTreeIE", "legacy"); - GatherTreeIE() = default; - /// \param step_ids Tensor of shape [MAX_TIME, BATCH_SIZE, BEAM_WIDTH] with - /// indices from per each step - /// \param parent_idx Tensor of shape [MAX_TIME, BATCH_SIZE, BEAM_WIDTH] with - /// parent beam indices - /// \param max_seq_len Tensor of shape [BATCH_SIZE] with maximum lengths for each - /// sequence in the batch - /// \param end_token Tensor of shape [MAX_TIME, BATCH_SIZE, BEAM_WIDTH] - GatherTreeIE(const Output& step_ids, - const Output& parent_idx, - const Output& max_seq_len, - const Output& end_token); - - void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gru_cell_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gru_cell_ie.hpp deleted file mode 100644 index 4ed540b87eb..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gru_cell_ie.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class GRUCellIE : public Op { -public: - OPENVINO_OP("GRUCellIE", "legacy"); - - GRUCellIE(const Output& X, - const Output& H_t, - const Output& WR, - const Output& B, - size_t hidden_size, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip, - bool linear_before_reset); - - GRUCellIE() = delete; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - void validate_and_infer_types() override; - - std::size_t get_hidden_size() { - return m_hidden_size; - } - const std::vector& get_activations() { - return m_activations; - } - const std::vector& get_activations_alpha() { - return m_activations_alpha; - } - const std::vector& get_activations_beta() { - return m_activations_beta; - } - float get_clip() { - return m_clip; - } - bool get_linear_before_reset() const { - return m_linear_before_reset; - } - bool visit_attributes(AttributeVisitor& visitor) override; - -protected: - int64_t m_hidden_size{}; - - std::vector m_activations; - std::vector m_activations_alpha; - std::vector m_activations_beta; - float m_clip; - bool m_linear_before_reset; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gru_sequence_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gru_sequence_ie.hpp deleted file mode 100644 index 182c55f1710..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/gru_sequence_ie.hpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include "ngraph/op/op.hpp" -#include "ngraph/opsets/opset4.hpp" - -namespace ngraph { -namespace op { -class GRUSequenceIE : public ngraph::op::util::RNNCellBase { -public: - OPENVINO_OP("GRUSequenceIE", "legacy"); - - GRUSequenceIE(const Output& X, - const Output& H_t, - const Output& seg_lengths, - const Output& WR, - const Output& B, - size_t hidden_size, - op::RecurrentSequenceDirection direction, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip, - bool linear_before_reset, - int64_t seq_axis = 1); - - GRUSequenceIE() = delete; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - void validate_and_infer_types() override; - - std::size_t get_hidden_size() { - return m_hidden_size; - } - - const std::vector& get_activations() { - return m_activations; - } - - const std::vector& get_activations_alpha() { - return m_activations_alpha; - } - - const std::vector& get_activations_beta() { - return m_activations_beta; - } - - float get_clip() { - return m_clip; - } - - bool visit_attributes(AttributeVisitor& visitor) override; - -protected: - op::RecurrentSequenceDirection m_direction; - bool m_linear_before_reset; - int64_t m_seq_axis; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/hard_sigmoid_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/hard_sigmoid_ie.hpp deleted file mode 100644 index d642a13de65..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/hard_sigmoid_ie.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class HardSigmoid_IE : public Op { -public: - OPENVINO_OP("HardSigmoid_IE", "legacy"); - - HardSigmoid_IE() = default; - - HardSigmoid_IE(const Output& arg, float alpha, float beta); - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; - - float get_alpha() const { - return m_alpha; - } - void set_alpha(float alpha) { - m_alpha = alpha; - } - float get_beta() const { - return m_beta; - } - void set_beta(float beta) { - m_beta = beta; - } - -protected: - float m_alpha; - float m_beta; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/interp.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/interp.hpp deleted file mode 100644 index 34bc4b71153..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/interp.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -struct InterpolateIEAttrs { - int height = -1; - int width = -1; - float zoom_factor = 0; - float shrink_factor = 0; - float scale_factor = 1.0; - bool align_corners = true; - bool antialias = true; - std::string mode = ""; - int pad_beg = 0; - int pad_end = 0; -}; - -class Interp : public Op { -public: - OPENVINO_OP("Interp", "legacy"); - - Interp(const Output& image, const InterpolateIEAttrs& attrs); - - void validate_and_infer_types() override; - - bool visit_attributes(AttributeVisitor& visitor) override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - InterpolateIEAttrs get_attrs() { - return m_attrs; - } - -private: - InterpolateIEAttrs m_attrs; -}; - -struct ResampleIEAttrs { - bool antialias = true; - int64_t factor = 0; - std::string mode = ""; -}; - -class ResampleV2 : public Op { -public: - OPENVINO_OP("ResampleV2", "legacy"); - - ResampleV2(const Output& image, const Output& output_shape, const ResampleIEAttrs& attrs); - - ResampleV2(const Output& image, const ResampleIEAttrs& attrs); - - void validate_and_infer_types() override; - - bool visit_attributes(AttributeVisitor& visitor) override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - ResampleIEAttrs get_attrs() { - return m_attrs; - } - -private: - ResampleIEAttrs m_attrs; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/lrn_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/lrn_ie.hpp deleted file mode 100644 index 1d79e26be5a..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/lrn_ie.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class LRN_IE : public Op { -public: - OPENVINO_OP("LRN_IE", "legacy"); - - LRN_IE() = default; - - LRN_IE(const Output& arg, double alpha, double beta, double bias, size_t size, std::string region); - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; - - double get_alpha() const { - return m_alpha; - } - void set_alpha(double alpha) { - m_alpha = alpha; - } - double get_beta() const { - return m_beta; - } - void set_beta(double beta) { - m_beta = beta; - } - double get_bias() const { - return m_bias; - } - void set_bias(double bias) { - m_bias = bias; - } - size_t get_nsize() const { - return m_size; - } - void set_nsize(size_t size) { - m_size = size; - } - std::string get_region() const { - return m_region; - } - void set_region(std::string region) { - m_region = region; - } - -protected: - double m_alpha; - double m_beta; - double m_bias; - size_t m_size; - std::string m_region; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/lstm_cell_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/lstm_cell_ie.hpp deleted file mode 100644 index c6ad64e2641..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/lstm_cell_ie.hpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class LSTMCellIE : public Op { -public: - OPENVINO_OP("LSTMCellIE", "legacy"); - - LSTMCellIE(const Output& X, - const Output& H_t, - const Output& C_t, - const Output& WR, - const Output& B, - size_t hidden_size, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip); - - LSTMCellIE() = delete; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - void validate_and_infer_types() override; - - std::size_t get_hidden_size() { - return m_hidden_size; - } - const std::vector& get_activations() { - return m_activations; - } - const std::vector& get_activations_alpha() { - return m_activations_alpha; - } - const std::vector& get_activations_beta() { - return m_activations_beta; - } - float get_clip() { - return m_clip; - } - bool visit_attributes(AttributeVisitor& visitor) override; - -protected: - int64_t m_hidden_size{}; - - std::vector m_activations; - std::vector m_activations_alpha; - std::vector m_activations_beta; - float m_clip; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/lstm_sequence_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/lstm_sequence_ie.hpp deleted file mode 100644 index 2fb38ec3fe0..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/lstm_sequence_ie.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include "ngraph/op/op.hpp" -#include "ngraph/opsets/opset4.hpp" - -namespace ngraph { -namespace op { -class LSTMSequenceIE : public ngraph::op::util::RNNCellBase { -public: - OPENVINO_OP("LSTMSequenceIE", "legacy"); - - LSTMSequenceIE() = delete; - - LSTMSequenceIE(const Output& X, - const Output& H_t, - const Output& C_t, - const Output& seq_lengths, - const Output& WR, - const Output& B, - size_t hidden_size, - ngraph::op::RecurrentSequenceDirection lstm_direction, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip, - int64_t seq_len = 1); - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - void validate_and_infer_types() override; - - ngraph::op::RecurrentSequenceDirection get_direction() { - return m_direction; - } - - bool visit_attributes(AttributeVisitor& visitor) override; - -protected: - ngraph::op::RecurrentSequenceDirection m_direction; - int64_t m_seq_axis; -}; -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/nms_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/nms_ie.hpp deleted file mode 100644 index 5f52ae91da7..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/nms_ie.hpp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class NonMaxSuppressionIE; -class NonMaxSuppressionIE2; -class NonMaxSuppressionIE3; - -} // namespace op -} // namespace ngraph - -class ngraph::op::NonMaxSuppressionIE : public Op { -public: - OPENVINO_OP("NonMaxSuppressionIE", "legacy"); - - NonMaxSuppressionIE(const Output& boxes, - const Output& scores, - const Output& max_output_boxes_per_class, - const Output& iou_threshold, - const Output& score_threshold, - int center_point_box, - bool sort_result_descending, - const ngraph::element::Type& output_type = ngraph::element::i64); - - void validate_and_infer_types() override; - - bool visit_attributes(AttributeVisitor& visitor) override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - int m_center_point_box; - bool m_sort_result_descending = true; - element::Type m_output_type; -}; - -class ngraph::op::NonMaxSuppressionIE2 : public NonMaxSuppressionIE { -public: - OPENVINO_OP("NonMaxSuppressionIE2", "legacy"); - - NonMaxSuppressionIE2(const Output& boxes, - const Output& scores, - const Output& max_output_boxes_per_class, - const Output& iou_threshold, - const Output& score_threshold, - int center_point_box, - bool sort_result_descending, - const ngraph::element::Type& output_type = ngraph::element::i64); - - void validate_and_infer_types() override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; -}; - -class ngraph::op::NonMaxSuppressionIE3 : public Op { -public: - OPENVINO_OP("NonMaxSuppressionIE3", "legacy"); - - NonMaxSuppressionIE3(const Output& boxes, - const Output& scores, - const Output& max_output_boxes_per_class, - const Output& iou_threshold, - const Output& score_threshold, - int center_point_box, - bool sort_result_descending, - const ngraph::element::Type& output_type = ngraph::element::i64); - - NonMaxSuppressionIE3(const Output& boxes, - const Output& scores, - const Output& max_output_boxes_per_class, - const Output& iou_threshold, - const Output& score_threshold, - const Output& soft_nms_sigma, - int center_point_box, - bool sort_result_descending, - const ngraph::element::Type& output_type = ngraph::element::i64); - - void validate_and_infer_types() override; - - bool visit_attributes(AttributeVisitor& visitor) override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - int m_center_point_box; - bool m_sort_result_descending = true; - element::Type m_output_type; - -private: - int64_t max_boxes_output_from_input() const; -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/normalize_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/normalize_ie.hpp deleted file mode 100644 index 297081fdc28..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/normalize_ie.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "ngraph/node.hpp" -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class NormalizeIE : public Op { -public: - OPENVINO_OP("NormalizeIE", "legacy"); - - NormalizeIE() = default; - - NormalizeIE(const Output& data, - const Output& weights, - float eps, - bool across_spatial, - bool channel_shared, - const ngraph::element::Type output_type); - - float get_eps() const { - return m_eps; - } - bool get_channel_shared() const { - return m_channel_shared; - } - bool get_across_spatial() const { - return m_across_spatial; - } - - void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - -protected: - float m_eps; - bool m_across_spatial; - bool m_channel_shared; - ngraph::element::Type m_output_type; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/onehot_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/onehot_ie.hpp deleted file mode 100644 index e06f8c5a528..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/onehot_ie.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "ngraph/node.hpp" -#include "ngraph/op/one_hot.hpp" -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class OneHotIE; - -} // namespace op -} // namespace ngraph - -class ngraph::op::OneHotIE : public Op { -public: - OPENVINO_OP("OneHotIE", "legacy"); - - explicit OneHotIE(const Output& input, - int axis, - int depth, - float on_value, - float off_value, - element::Type type); - - void validate_and_infer_types() override; - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - bool visit_attributes(AttributeVisitor& visitor) override; - - int get_axis() { - return m_axis; - } - int get_depth() { - return m_depth; - } - float get_on_value() { - return m_on_value; - } - float get_off_value() { - return m_off_value; - } - -private: - element::Type m_type; - int m_axis; - int m_depth; - float m_off_value = 0.0; - float m_on_value = 0.0; -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/pad_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/pad_ie.hpp deleted file mode 100644 index 076280819e3..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/pad_ie.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "ngraph/node.hpp" -#include "ngraph/op/op.hpp" -#include "ngraph/op/pad.hpp" - -namespace ngraph { -namespace op { - -class PadIE : public Op { -public: - OPENVINO_OP("PadIE", "legacy"); - - explicit PadIE(const std::shared_ptr& pad); - - PadIE(const Output& input, - PadMode pad_mode, - CoordinateDiff pads_begin, - CoordinateDiff pads_end, - Shape output_shape, - float pad_value); - - void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - PadMode get_pad_mode() { - return m_pad_mode; - } - CoordinateDiff get_pads_begin() { - return m_pads_begin; - } - CoordinateDiff get_pads_end() { - return m_pads_end; - } - float get_pad_value() { - return m_pad_value; - } - -private: - PadMode m_pad_mode; - CoordinateDiff m_pads_begin, m_pads_end; - Shape m_output_shape; - float m_pad_value = 0; -}; -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/power.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/power.hpp deleted file mode 100644 index e67adc0f0a5..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/power.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class PowerIE : public Op { -public: - OPENVINO_OP("PowerIE", "legacy"); - PowerIE() = default; - PowerIE(const Output& data_batch, - const float power, - const float scale, - const float shift, - const element::Type output_type = element::undefined); - - void validate_and_infer_types() override; - - bool visit_attributes(AttributeVisitor& visitor) override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - float scale, power, shift; - -private: - element::Type m_output_type; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/proposal_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/proposal_ie.hpp deleted file mode 100644 index 11ec79f0ceb..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/proposal_ie.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class ProposalIE : public Op { -public: - OPENVINO_OP("ProposalIE", "legacy"); - - // \brief Constructs a Proposal operation - // - // \param class_probs Class probability scores - // \param class_bbox_deltas Class prediction bbox_deltas - // \param image_shape Shape of image - // \param attrs Proposal op attributes - ProposalIE(const Output& class_probs, - const Output& class_bbox_deltas, - const Output& image_shape, - const ProposalAttrs& attrs); - - void validate_and_infer_types() override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - bool visit_attributes(AttributeVisitor& visitor) override; - const ProposalAttrs& get_attrs() const { - return m_attrs; - } - -private: - ProposalAttrs m_attrs; -}; -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/relu_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/relu_ie.hpp deleted file mode 100644 index de5f83c407a..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/relu_ie.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class ReLUIE : public Op { -public: - OPENVINO_OP("ReLUIE", "legacy"); - - ReLUIE(const Output& data, const float& negative_slope, const element::Type output_type); - - void validate_and_infer_types() override; - - bool visit_attributes(AttributeVisitor& visitor) override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - float get_slope() { - return m_negative_slope; - } - - element::Type get_output_type() const { - return m_output_type; - } - -private: - float m_negative_slope; - element::Type m_output_type; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/rnn_cell_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/rnn_cell_ie.hpp deleted file mode 100644 index 6715c45f23b..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/rnn_cell_ie.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class RNNCellIE : public Op { -public: - OPENVINO_OP("RNNCellIE", "legacy"); - - RNNCellIE(const Output& X, - const Output& H_t, - const Output& WR, - const Output& B, - size_t hidden_size, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip); - - RNNCellIE() = delete; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - void validate_and_infer_types() override; - - std::size_t get_hidden_size() { - return m_hidden_size; - } - const std::vector& get_activations() { - return m_activations; - } - const std::vector& get_activations_alpha() { - return m_activations_alpha; - } - const std::vector& get_activations_beta() { - return m_activations_beta; - } - float get_clip() { - return m_clip; - } - bool visit_attributes(AttributeVisitor& visitor) override; - -protected: - int64_t m_hidden_size{}; - - std::vector m_activations; - std::vector m_activations_alpha; - std::vector m_activations_beta; - float m_clip; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/rnn_sequence_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/rnn_sequence_ie.hpp deleted file mode 100644 index b81a78432a2..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/rnn_sequence_ie.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include "ngraph/op/op.hpp" -#include "ngraph/opsets/opset4.hpp" - -namespace ngraph { -namespace op { -class RNNSequenceIE : public ngraph::op::util::RNNCellBase { -public: - OPENVINO_OP("RNNSequenceIE", "legacy"); - - RNNSequenceIE(const Output& X, - const Output& H_t, - const Output& seq_lengths, - const Output& WR, - const Output& B, - size_t hidden_size, - op::RecurrentSequenceDirection direction, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip, - int64_t seq_axis = 1); - - RNNSequenceIE() = delete; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - void validate_and_infer_types() override; - - std::size_t get_hidden_size() { - return m_hidden_size; - } - - const std::vector& get_activations() { - return m_activations; - } - - const std::vector& get_activations_alpha() { - return m_activations_alpha; - } - - const std::vector& get_activations_beta() { - return m_activations_beta; - } - - float get_clip() { - return m_clip; - } - - bool visit_attributes(AttributeVisitor& visitor) override; - -protected: - op::RecurrentSequenceDirection m_direction; - int64_t m_seq_axis; -}; -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/scaleshift.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/scaleshift.hpp deleted file mode 100644 index 9e55c721287..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/scaleshift.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class ScaleShiftIE : public Op { -public: - OPENVINO_OP("ScaleShiftIE", "legacy"); - - ScaleShiftIE(const Output& data_batch, - const Output& weights, - const Output& bias, - const element::Type output_type = element::undefined); - bool visit_attributes(AttributeVisitor& visitor) override; - - void validate_and_infer_types() override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - -private: - element::Type output_type; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/selu_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/selu_ie.hpp deleted file mode 100644 index 4951c4b243c..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/selu_ie.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class SeluIE : public Op { -public: - OPENVINO_OP("SeluIE", "legacy"); - - SeluIE(const Output& input, const float alpha, const float gamma); - - void validate_and_infer_types() override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - bool visit_attributes(AttributeVisitor& visitor) override; - float gamma, alpha; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/swish_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/swish_ie.hpp deleted file mode 100644 index ff350f1a269..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/swish_ie.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { -class SwishIE : public Op { -public: - OPENVINO_OP("SwishIE", "legacy"); - - explicit SwishIE(const Output& input, float alpha = 1.0); - - void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - void set_alpha(float alpha); - float get_alpha() const; - -protected: - float m_alpha; -}; -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/tile_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/tile_ie.hpp deleted file mode 100644 index 59815ef2db4..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/tile_ie.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "ngraph/op/op.hpp" - -namespace ngraph { -namespace op { - -class TileIE : public Op { -public: - OPENVINO_OP("TileIE", "legacy"); - - TileIE(const Output& data1, const int64_t axis, const int64_t tiles); - - void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - int64_t axis, tiles; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/topk_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/topk_ie.hpp deleted file mode 100644 index c9a17959ce1..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/ngraph_ops/topk_ie.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "ngraph/op/op.hpp" -#include "ngraph/op/topk.hpp" - -namespace ngraph { -namespace op { - -class TopKIE : public Op { -public: - OPENVINO_OP("TopKIE", "legacy"); - - TopKIE(const Output& data, - const Output& k, - const int64_t axis, - const ngraph::op::TopKMode mode, - const ngraph::op::TopKSortType sort, - const element::Type& index_element_type = element::i32); - - void validate_and_infer_types() override; - - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - - int64_t get_axis() { - return m_axis; - } - - ngraph::op::TopKMode get_mode() { - return m_mode; - } - - ngraph::op::TopKSortType get_sort_type() { - return m_sort_type; - } - bool visit_attributes(AttributeVisitor& visitor) override; - -private: - int64_t m_axis; - ngraph::op::TopKMode m_mode; - ngraph::op::TopKSortType m_sort_type; - ngraph::element::Type m_index_element_type; -}; - -} // namespace op -} // namespace ngraph diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/conv_bias_fusion.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/conv_bias_fusion.hpp deleted file mode 100644 index da2c69f27bf..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/conv_bias_fusion.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -#include "legacy/ngraph_ops/convolution_ie.hpp" -#include "legacy/ngraph_ops/deconvolution_ie.hpp" -#include "ngraph/op/add.hpp" -#include "ngraph/op/broadcast.hpp" -#include "ngraph/op/group_conv.hpp" -#include "ngraph/op/reshape.hpp" -#include "ngraph/pattern/matcher.hpp" -#include "ngraph/rt_info.hpp" - -namespace ngraph { -namespace pass { - -class ConvFusion; -class ConvAddFusion; -class ConvMultiplyFusion; -class DeconvAddFusion; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvAddFusion : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvAddFusion", "0"); - ConvAddFusion(); -}; - -class ngraph::pass::ConvMultiplyFusion : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvMultiplyFusion", "0"); - ConvMultiplyFusion(); -}; - -class ngraph::pass::DeconvAddFusion : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("DeconvAddFusion", "0"); - DeconvAddFusion(); -}; - -class ngraph::pass::ConvFusion : public ov::pass::GraphRewrite { -public: - OPENVINO_RTTI("ConvFusion", "0"); - ConvFusion() { - add_matcher(); - add_matcher(); - add_matcher(); - } -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_cells_to_cells_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_cells_to_cells_ie.hpp deleted file mode 100644 index b258aecfe92..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_cells_to_cells_ie.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertLSTMCellMatcher; -class ConvertGRUCellMatcher; -class ConvertRNNCellMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertLSTMCellMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertLSTMCellMatcher", "0"); - ConvertLSTMCellMatcher(); -}; - -class ngraph::pass::ConvertGRUCellMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertGRUCellMatcher", "0"); - ConvertGRUCellMatcher(); -}; - -class ngraph::pass::ConvertRNNCellMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertRNNCellMatcher", "0"); - ConvertRNNCellMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_convolutions.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_convolutions.hpp deleted file mode 100644 index f70425ca24b..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_convolutions.hpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertConvolutions; - -class ConvertConvolution; -class ConvertGroupConvolution; -class ConvertDeconvolution; -class ConvertGroupDeconvolution; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertConvolution : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertConvolution", "0"); - ConvertConvolution(); -}; - -class ngraph::pass::ConvertGroupConvolution : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertGroupConvolution", "0"); - ConvertGroupConvolution(); -}; - -class ngraph::pass::ConvertDeconvolution : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertDeconvolution", "0"); - ConvertDeconvolution(); -}; - -class ngraph::pass::ConvertGroupDeconvolution : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertGroupDeconvolution", "0"); - ConvertGroupDeconvolution(); -}; - -class ngraph::pass::ConvertConvolutions : public ov::pass::GraphRewrite { -public: - OPENVINO_RTTI("ConvertConvolutions", "0"); - ConvertConvolutions() { - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - } -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_gather_to_gather_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_gather_to_gather_ie.hpp deleted file mode 100644 index 7902fc28111..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_gather_to_gather_ie.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include - -#include "ngraph/op/constant.hpp" -#include "ngraph/op/gather.hpp" -#include "ngraph/op/squeeze.hpp" -#include "ngraph/op/unsqueeze.hpp" - -namespace ngraph { -namespace pass { - -class ConvertGatherToGatherIEMatcher; - -} // namespace pass -} // namespace ngraph - -/* - * Description: - * This transformation converts opset1::Gather to legacy GatherIE - * GatherIE takes axes as value and if indices input has empty shape (scalar) - * we unsqueeze indices input and squeeze GatherIE output. - */ - -class ngraph::pass::ConvertGatherToGatherIEMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertGatherToGatherIEMatcher", "0"); - ConvertGatherToGatherIEMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_gathertree_to_gathertree_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_gathertree_to_gathertree_ie.hpp deleted file mode 100644 index dbadc67fa0d..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_gathertree_to_gathertree_ie.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertGatherTreeToGatherTreeIEMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertGatherTreeToGatherTreeIEMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertGatherTreeToGatherTreeIEMatcher", "0"); - ConvertGatherTreeToGatherTreeIEMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_hard_sigmoid_to_hard_sigmoid_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_hard_sigmoid_to_hard_sigmoid_ie.hpp deleted file mode 100644 index 680e4b243de..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_hard_sigmoid_to_hard_sigmoid_ie.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertHardSigmoidToLegacyMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertHardSigmoidToLegacyMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertHardSigmoidToLegacyMatcher", "0"); - ConvertHardSigmoidToLegacyMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_interpolate_to_interp_or_resample.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_interpolate_to_interp_or_resample.hpp deleted file mode 100644 index e4eef4a835e..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_interpolate_to_interp_or_resample.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertInterpolateToInterpOrResampleMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertInterpolateToInterpOrResampleMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertInterpolateToInterpOrResampleMatcher", "0"); - ConvertInterpolateToInterpOrResampleMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_lrn_to_lrn_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_lrn_to_lrn_ie.hpp deleted file mode 100644 index 16834374345..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_lrn_to_lrn_ie.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertLRNToLegacyMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertLRNToLegacyMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertLRNToLegacyMatcher", "0"); - ConvertLRNToLegacyMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.hpp deleted file mode 100644 index d05fbaac2a1..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertMatMulToFCorGemm; -class ConvertMatMulToFC; -class ConvertMatMulToGemm; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertMatMulToFC : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertMatMulToFC", "0"); - ConvertMatMulToFC(); -}; - -class ngraph::pass::ConvertMatMulToGemm : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertMatMulToGemm", "0"); - ConvertMatMulToGemm(); -}; - -class ngraph::pass::ConvertMatMulToFCorGemm : public ov::pass::GraphRewrite { -public: - OPENVINO_RTTI("ConvertMatMulToFCorGemm", "0"); - ConvertMatMulToFCorGemm() { - add_matcher(); - add_matcher(); - } -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.hpp deleted file mode 100644 index c78342c492d..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertMulAddToScaleShiftOrPower; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertMulAddToScaleShiftOrPower : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertMulAddToScaleShiftOrPower", "0"); - ConvertMulAddToScaleShiftOrPower(); -}; - -enum class CONVERSION_RESULT { SCALE_SHIFT, POWER, NONE }; - -/* - * check_constant function checks how given constant performs elementwise operation with given input - * CONVERSION_RESULT has several types: - * SCALE_SHIFT - constant applies only per-channel - * POWER - constant applies as single value - * NONE - default return value - */ - -CONVERSION_RESULT -check_constant(const std::shared_ptr& constant, const ngraph::PartialShape& shape); diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp deleted file mode 100644 index 4d258b369bf..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertMulOrAddFinally; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertMulOrAddFinally : public ov::pass::GraphRewrite { -public: - OPENVINO_RTTI("ConvertMulOrAddFinally", "0"); - ConvertMulOrAddFinally(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_nms_5_to_legacy.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_nms_5_to_legacy.hpp deleted file mode 100644 index 4ba32c1834b..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_nms_5_to_legacy.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertNMS5ToLegacyMatcher; - -} // namespace pass -} // namespace ngraph - -/* - * Description: - * Convert NMS-5 directly to inner NMS. - */ - -class ngraph::pass::ConvertNMS5ToLegacyMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertNMS5ToLegacyMatcher", "0"); - ConvertNMS5ToLegacyMatcher(bool force_i32_output_type = true); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_nms_to_nms_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_nms_to_nms_ie.hpp deleted file mode 100644 index 76733f6a60c..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_nms_to_nms_ie.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertNMSToNMSIEMatcher; - -} // namespace pass -} // namespace ngraph - -/* - * Description: - * This transformation converts opset1::NonMaxSuppression to legacy NonMaxSuppressionIE - * NonMaxSuppressionIE takes max_output_boxes_per_class, iou_threshold and score_threshold - * inputs as 1D tensors when original operation requires scalars. And for this inputs - * we insert Unsqueeze operations. - */ - -class ngraph::pass::ConvertNMSToNMSIEMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertNMSToNMSIEMatcher", "0"); - ConvertNMSToNMSIEMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.hpp deleted file mode 100644 index 47adbbfa870..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertNormalizeL2WithMulToNormalizeIE; -class ConvertNormalizeL2ToLegacyMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertNormalizeL2WithMulToNormalizeIE : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertNormalizeL2WithMulToNormalizeIE", "0"); - ConvertNormalizeL2WithMulToNormalizeIE(); -}; - -class ngraph::pass::ConvertNormalizeL2ToLegacyMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertNormalizeL2ToLegacyMatcher", "0"); - ConvertNormalizeL2ToLegacyMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_one_hot_to_one_hot_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_one_hot_to_one_hot_ie.hpp deleted file mode 100644 index c37f71d2878..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_one_hot_to_one_hot_ie.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertOneHotToOneHotIEMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertOneHotToOneHotIEMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertOneHotToOneHotIEMatcher", "0"); - ConvertOneHotToOneHotIEMatcher(); - - void detect_output_type(const std::shared_ptr& f); - -private: - element::Type m_output_type = element::Type_t::f32; -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.hpp deleted file mode 100644 index 69d511d1204..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertOpSet1ToLegacy; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertOpSet1ToLegacy : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("ConvertOpSet1ToLegacy", "0"); - bool run_on_model(const std::shared_ptr& m) override; -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_pad_to_pad_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_pad_to_pad_ie.hpp deleted file mode 100644 index 7b017df37e1..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_pad_to_pad_ie.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include - -#include "ngraph/op/constant.hpp" -#include "ngraph/op/lrn.hpp" - -namespace ngraph { -namespace pass { - -class ConvertPadToLegacyMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertPadToLegacyMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertPadToLegacyMatcher", "0"); - ConvertPadToLegacyMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.hpp deleted file mode 100644 index dee94dd5e54..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertPowerToPowerIEMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertPowerToPowerIEMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertPowerToPowerIEMatcher", "0"); - ConvertPowerToPowerIEMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_prelu_to_relu_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_prelu_to_relu_ie.hpp deleted file mode 100644 index 82fcb02e729..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_prelu_to_relu_ie.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertPReLUToReLUIE; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertPReLUToReLUIE : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertPReLUToReLUIE", "0"); - ConvertPReLUToReLUIE(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.hpp deleted file mode 100644 index fe6702f8c0d..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertProposalToLegacyMatcher; -class ConvertProposal4ToLegacyMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertProposal4ToLegacyMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertProposal4ToLegacyMatcher", "0"); - ConvertProposal4ToLegacyMatcher(); -}; - -class ngraph::pass::ConvertProposalToLegacyMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertProposalToLegacyMatcher", "0"); - ConvertProposalToLegacyMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_selu_to_selu_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_selu_to_selu_ie.hpp deleted file mode 100644 index 3d5ae3aa874..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_selu_to_selu_ie.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertSeluToSeluIEMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertSeluToSeluIEMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertSeluToSeluIEMatcher", "0"); - ConvertSeluToSeluIEMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.hpp deleted file mode 100644 index 2021f83c55b..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertLSTMSequenceMatcher; -class ConvertGRUSequenceMatcher; -class ConvertRNNSequenceMatcher; - -} // namespace pass -} // namespace ngraph - -/** - * @ingroup ie_transformation_common_api - * @brief Converts LSTMSequence to legacy LSTMSequenceIE. - * SequenceIE op doesn't use seq_length input and num_direction (direction) attribute. - * We squeeze num_direction dimension for all corresponding inputs and unsqueeze them after the SequenceIE op. - */ - -class ngraph::pass::ConvertLSTMSequenceMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertLSTMSequenceMatcher", "0"); - ConvertLSTMSequenceMatcher(); -}; - -/** - * @ingroup ie_transformation_common_api - * @brief Converts GRUSequence to legacy GRUSequenceIE. - * SequenceIE op doesn't use seq_length input and num_direction (direction) attribute. - * We squeeze num_direction dimension for all corresponding inputs and unsqueeze them after the SequenceIE op. - */ - -class ngraph::pass::ConvertGRUSequenceMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertGRUSequenceMatcher", "0"); - ConvertGRUSequenceMatcher(); -}; - -/** - * @ingroup ie_transformation_common_api - * @brief Converts RNNSequence to legacy RNNSequenceIE. - * SequenceIE op doesn't use seq_length input and num_direction (direction) attribute. - * We squeeze num_direction dimension for all corresponding inputs and unsqueeze them after the SequenceIE op. - */ - -class ngraph::pass::ConvertRNNSequenceMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertRNNSequenceMatcher", "0"); - ConvertRNNSequenceMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.hpp deleted file mode 100644 index 63b863aa872..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertSqrtToPowerIEMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertSqrtToPowerIEMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertSqrtToPowerIEMatcher", "0"); - ConvertSqrtToPowerIEMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_strided_slice_to_crop.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_strided_slice_to_crop.hpp deleted file mode 100644 index 0ef21312641..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_strided_slice_to_crop.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertStridedSliceToCropMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertStridedSliceToCropMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertStridedSliceToCropMatcher", "0"); - ConvertStridedSliceToCropMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_swish_to_swish_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_swish_to_swish_ie.hpp deleted file mode 100644 index 1d5c9ae1d54..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_swish_to_swish_ie.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { -class ConvertSwishToSwishIEMatcher; -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertSwishToSwishIEMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertSwishToSwishIEMatcher", "0"); - ConvertSwishToSwishIEMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_tile_to_ie_tile.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_tile_to_ie_tile.hpp deleted file mode 100644 index 5049a755a36..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_tile_to_ie_tile.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertTileToLegacyMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertTileToLegacyMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertTileToLegacyMatcher", "0"); - ConvertTileToLegacyMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_topk_to_topk_ie.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_topk_to_topk_ie.hpp deleted file mode 100644 index e4c3034c189..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/convert_topk_to_topk_ie.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ConvertTopKToTopKIEMatcher; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ConvertTopKToTopKIEMatcher : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertTopKToTopKIEMatcher", "0"); - ConvertTopKToTopKIEMatcher(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/fc_bias_fusion.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/fc_bias_fusion.hpp deleted file mode 100644 index fe960f2a041..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/fc_bias_fusion.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class FullyConnectedBiasFusion; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::FullyConnectedBiasFusion : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("FullyConnectedBiasFusion", "0"); - FullyConnectedBiasFusion(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/reshape_1d_ops.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/reshape_1d_ops.hpp deleted file mode 100644 index be46603f8fd..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/reshape_1d_ops.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -namespace ngraph { -namespace pass { - -class Reshape1DOps; -class Reshape1DConvolution; -class Reshape1DAvgPool; -class Reshape1DMaxPool; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::Reshape1DConvolution : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("Reshape1DConvolution", "0"); - Reshape1DConvolution(); -}; - -class ngraph::pass::Reshape1DAvgPool : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("Reshape1DAvgPool", "0"); - Reshape1DAvgPool(); -}; - -class ngraph::pass::Reshape1DMaxPool : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("Reshape1DMaxPool", "0"); - Reshape1DMaxPool(); -}; - -class ngraph::pass::Reshape1DOps : public ov::pass::GraphRewrite { -public: - OPENVINO_RTTI("Reshape1DOps", "0"); - Reshape1DOps() { - add_matcher(); - add_matcher(); - add_matcher(); - } -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp deleted file mode 100644 index 1aae7fe07de..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ReshapeFullyConnectedFusion; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::ReshapeFullyConnectedFusion : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ReshapeFullyConnectedFusion", "0"); - ReshapeFullyConnectedFusion(); -}; diff --git a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/reshape_fully_connected.hpp b/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/reshape_fully_connected.hpp deleted file mode 100644 index d0c615369c3..00000000000 --- a/src/plugins/intel_gna/legacy/include/legacy/transformations/convert_opset1_to_legacy/reshape_fully_connected.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -namespace ngraph { -namespace pass { - -class ReshapeFullyConnected; - -} // namespace pass -} // namespace ngraph - -/* - * Description: - * ReshapeFullyConnected transformation detects FullyConnected operations - * and for each operation where input shape is greater than 2 inserts Reshape - * operations before and after FullyConnected operation. This transformation is - * required because of IE restrictions. - * - * Parametrization: - * This transformation can be parametrize with callback. If you dont want to apply - * this transformation for some particular FullyConnected operations you can use - * setCallback method. See example below. - * - * Callback example: - * - * // This callback disables ReshapeFullyConnected for FC with 3D input shapes - * auto callback = [](const std::shared_ptr & node) -> bool { - * if (auto fc_op = std::dynamic_pointer_cast(node)) { - * return fc_op->input_value(0).get_shape().size() == 3; - * } - * }; - * - */ - -class ngraph::pass::ReshapeFullyConnected : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ReshapeFullyConnected", "0"); - ReshapeFullyConnected(); -}; diff --git a/src/plugins/intel_gna/legacy/src/cnn_network_impl.cpp b/src/plugins/intel_gna/legacy/src/cnn_network_impl.cpp deleted file mode 100644 index bd32e97b707..00000000000 --- a/src/plugins/intel_gna/legacy/src/cnn_network_impl.cpp +++ /dev/null @@ -1,500 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cnn_network_ngraph_impl.hpp" -#include "debug.h" -#include "exec_graph_info.hpp" -#include "legacy/convert_function_to_cnn_network.hpp" -#include "legacy/details/ie_cnn_network_tools.h" -#include "legacy/graph_tools.hpp" - -#ifdef ENABLE_V7_SERIALIZE -# include "network_serializer_v7.hpp" -#endif - -using namespace std; -using namespace InferenceEngine; -using namespace InferenceEngine::details; - -namespace { - -std::map getConstLayersMap(const CNNNetwork& network) { - std::map result; - - const std::vector layers = CNNNetSortTopologically(network); - for (const CNNLayerPtr& layer : layers) { - if (equal(layer->type, "Input") || equal(layer->type, "Memory")) { - result.emplace(layer.get(), false); - continue; - } - - if ((equal(layer->type, "Const")) || (equal(layer->type, "Shape")) || (equal(layer->type, "PriorBox"))) { - result.emplace(layer.get(), true); - continue; - } - - bool allParentsAreConst = true; - for (const DataWeakPtr& insWeakData : layer->insData) { - const DataPtr insData = insWeakData.lock(); - if (insData == nullptr) { - IE_THROW() << "input data is absent"; - } - - const CNNLayerWeakPtr parentWeak = getCreatorLayer(insData); - const CNNLayerPtr parent = parentWeak.lock(); - if (parent == nullptr) { - IE_THROW() << "parentLayer is absent"; - } - - const auto parentIt = result.find(parent.get()); - if (parentIt == result.end()) { - IE_THROW() << "parent layer '" << parent->name << "' was not found"; - } - - if (!parentIt->second) { - result.emplace(layer.get(), false); - allParentsAreConst = false; - break; - } - } - - if (allParentsAreConst) { - result.emplace(layer.get(), true); - } - } - - return result; -} - -} // namespace - -CNNNetworkImpl::CNNNetworkImpl() {} - -CNNNetworkImpl::CNNNetworkImpl(const CNNNetwork& cnnnetwork) { - IE_SUPPRESS_DEPRECATED_START - auto& icnnnetwork = static_cast(cnnnetwork); - IE_SUPPRESS_DEPRECATED_END - auto ngraphImplPtr = dynamic_cast(&icnnnetwork); - IE_ASSERT(ngraphImplPtr != nullptr); - IE_ASSERT(ngraphImplPtr->getFunction() != nullptr); - auto graph = ngraph::clone_function(*ngraphImplPtr->getFunction()); - - ::ngraph::pass::Manager manager; - manager.register_pass<::ov::pass::InitNodeInfo>(); - manager.register_pass<::ov::pass::CommonOptimizations>(); - manager.register_pass<::ov::pass::ConvertOpSet3ToOpSet2>(); - manager.register_pass<::ov::pass::ConvertOpSet2ToOpSet1>(); - manager.register_pass<::ngraph::pass::ConvertOpSet1ToLegacy>(); - manager.run_passes(graph); - - InferenceEngine::details::convertFunctionToICNNNetwork(graph, cnnnetwork, this, false); -} - -CNNNetworkImpl::~CNNNetworkImpl() { - // In case of cycles, memory leaks occur: Layer holds shared_ptr, and vice versa. - // Added additional check on cycles. - bool res = false; - try { - res = CNNNetForestDFS( - CNNNetGetAllInputLayers(this), - [&](CNNLayerPtr layer) {}, - false); - } catch (const std::exception& ex) { - std::cout << ex.what() << std::endl; - // Exception means that network was invalid. Reset all data. - } - - // workaround due to memory leaks - if (!res) { - for (const auto& data : _data) { - if (!data.second) - continue; - for (auto& input : getInputTo(data.second)) { - if (!input.second) - continue; - input.second.reset(); - } - } - } -} - -void CNNNetworkImpl::getOutputsInfo(std::map& out) const noexcept { - out = _outputData; -} - -void CNNNetworkImpl::getInputsInfo(InputsDataMap& inputs) const noexcept { - inputs = _inputData; -} - -void CNNNetworkImpl::addLayer(const CNNLayerPtr& layer) noexcept { - if (!layer) - return; - _layers[layer->name] = layer; -} - -void CNNNetworkImpl::removeLayer(const std::string& layerName) { - auto it = _layers.find(layerName); - if (it != _layers.end()) { - _layers.erase(it); - } -} - -void CNNNetworkImpl::renameLayer(const std::string& currentName, const std::string& newName) { - const auto currentIt = _layers.find(currentName); - if (currentIt == _layers.end()) { - IE_THROW() << "Layer '" << currentName << "' was not found in layers"; - } - - if (_layers.find(newName) != _layers.end()) { - IE_THROW() << "Layer with name '" << currentName << "' already exists in layers"; - } - - if (_inputData.find(newName) != _inputData.end()) { - IE_THROW() << "Layer with name '" << currentName << "' already exists in input data"; - } - - if (_outputData.find(newName) != _outputData.end()) { - IE_THROW() << "Layer with name '" << currentName << "' already exists in output data"; - } - - const auto currentDataIt = _data.find(currentName); - if (currentDataIt == _data.end()) { - IE_THROW() << "Layer '" << currentName << "' was not found in data"; - } - - if (_data.find(newName) != _data.end()) { - IE_THROW() << "Layer with name '" << currentName << "' already exists in data"; - } - - bool wasUpdatedInput = false; - for (auto inputDataIt = _inputData.begin(); inputDataIt != _inputData.end(); ++inputDataIt) { - const CNNLayerPtr inputLayer = getCreatorLayer(inputDataIt->second->getInputData()).lock(); - if (inputLayer->name == currentName) { - _inputData.emplace(newName, inputDataIt->second); - _inputData.erase(inputDataIt); - wasUpdatedInput = true; - break; - } - } - - if (!wasUpdatedInput) { - for (auto outputDataIt = _outputData.begin(); outputDataIt != _outputData.end(); ++outputDataIt) { - const CNNLayerPtr outputLayer = getCreatorLayer(outputDataIt->second).lock(); - if (outputLayer->name == currentName) { - _outputData.emplace(newName, outputDataIt->second); - _outputData.erase(outputDataIt); - break; - } - } - } - - _layers.emplace(newName, currentIt->second); - currentIt->second->name = newName; - _layers.erase(currentIt); - - _data.emplace(newName, currentDataIt->second); - currentDataIt->second->setName(newName); - _data.erase(currentDataIt); -} - -void CNNNetworkImpl::removeData(const std::string& dataName) { - auto it = _data.find(dataName); - if (it != _data.end()) { - _data.erase(it); - } -} - -void CNNNetworkImpl::validate(int version) { - std::set layerNames; - std::set dataNames; - - InputsDataMap inputs; - this->getInputsInfo(inputs); - if (inputs.empty()) { - IE_THROW() << "No input layers"; - } - - bool res = CNNNetForestDFS( - CNNNetGetAllInputLayers(this), - [&](CNNLayerPtr layer) { - std::string layerName = layer->name; - - for (auto i : layer->insData) { - auto data = i.lock(); - if (data) { - auto inputTo = getInputTo(data); - auto iter = inputTo.find(layerName); - auto dataName = data->getName(); - if (iter == inputTo.end()) { - IE_THROW() << "Data " << data->getName() << " which inserted into the layer " << layerName - << " does not point at this layer"; - } - if (!getCreatorLayer(data).lock()) { - IE_THROW() << "Data " << dataName << " has no creator layer"; - } - } else { - IE_THROW() << "Data which inserted into the layer " << layerName << " is nullptr"; - } - } - for (auto data : layer->outData) { - auto inputTo = getInputTo(data); - std::string dataName = data->getName(); - for (auto layerIter : inputTo) { - CNNLayerPtr layerInData = layerIter.second; - if (!layerInData) { - IE_THROW() << "Layer which takes data " << dataName << " is nullptr"; - } - auto insertedDatas = layerInData->insData; - - auto it = - std::find_if(insertedDatas.begin(), insertedDatas.end(), [&](InferenceEngine::DataWeakPtr& d) { - return d.lock() == data; - }); - if (it == insertedDatas.end()) { - IE_THROW() << "Layer " << layerInData->name << " which takes data " << dataName - << " does not point at this data"; - } - } - auto dataNameSetPair = dataNames.insert(dataName); - if (!dataNameSetPair.second) { - IE_THROW() << "Data name " << dataName << " is not unique"; - } - } - auto layerSetPair = layerNames.insert(layerName); - if (!layerSetPair.second) { - IE_THROW() << "Layer name " << layerName << " is not unique"; - } - }, - false); - - std::string inputType = "Input"; - for (auto i : inputs) { - CNNLayerPtr layer = getCreatorLayer(i.second->getInputData()).lock(); - if (layer && !equal(layer->type, inputType)) { - IE_THROW() << "Input layer " << layer->name << " should have Input type but actually its type is " - << layer->type; - } - } - - if (!res) { - IE_THROW() << "Sorting not possible, due to existed loop."; - } -} - -StatusCode CNNNetworkImpl::getLayerByName(const char* layerName, CNNLayerPtr& out, ResponseDesc* resp) const noexcept { - auto it = _layers.find(layerName); - if (it == _layers.end()) - return DescriptionBuffer(NOT_FOUND, resp) << "Layer " << layerName << " not found in network"; - out = it->second; - return OK; -} - -StatusCode CNNNetworkImpl::addOutput(const std::string& layerName, size_t outputIndex, ResponseDesc* resp) noexcept { - CNNLayerPtr outLayer; - auto rc = getLayerByName(layerName.c_str(), outLayer, resp); - if (rc != OK) - return rc; - - if (outputIndex >= outLayer->outData.size()) - return DescriptionBuffer(OUT_OF_BOUNDS, resp) - << "port index " << outputIndex << " exceeds layer's outputs which is " << outLayer->outData.size(); - shared_ptr outData = outLayer->outData[outputIndex]; - _outputData[outData->getName()] = outData; - return OK; -} - -void CNNNetworkImpl::resolveOutput() { - // check orphan nodes... - for (auto kvp : _data) { - if (!kvp.second->isInitialized()) - IE_THROW() << "data name [" << kvp.first << "] dimensions is not known"; - - // data nodes not going to any layer are basically graph output... - if (getInputTo(kvp.second).empty()) { - _outputData[kvp.first] = kvp.second; - } - } -} - -void CNNNetworkImpl::addOutput(const string& dataName) { - auto it = _data.find(dataName); - if (it == _data.end()) { - IE_THROW() << "data [" << dataName << "] doesn't exist"; - } - auto data = it->second; - assert(data->getName() == dataName); - _outputData[dataName] = data; -} - -void CNNNetworkImpl::removeOutput(const string& dataName) { - removeData(dataName); - - auto it = _outputData.find(dataName); - if (it != _outputData.end()) { - _outputData.erase(it); - } -} - -size_t CNNNetworkImpl::getBatchSize() const { - if (!_inputData.size()) - return 0; - // currently CNNNetworkImpl::setBatchSize set the same values - // for the latest dim as a batch, we can take the first input - // and return batch size for it - SizeVector dims = _inputData.cbegin()->second->getTensorDesc().getDims(); - // 3D input layout doesn't have batch notation for input so batch is 1 - if (dims.size() == 3 || dims.size() == 1) { - return 1; - } - if (dims.size() == 0) { - return 0; - } - return dims.at(0); -} - -StatusCode CNNNetworkImpl::reshape(const std::map>& inputShapes, - ResponseDesc* responseDesc) noexcept { - for (const auto& pair : _inputData) { - auto info = pair.second; - if (info) { - auto data = info->getInputData(); - auto it = inputShapes.find(pair.first); - if (data && it != inputShapes.end()) { - auto newDims = it->second; - auto currentDims = data->getTensorDesc().getDims(); - if (newDims != currentDims) { - return DescriptionBuffer(NOT_IMPLEMENTED, responseDesc) - << "You have called setBatchSize + reshape for CNNNetwork object. Please, either: \n" - "- [SUGGESTED] Regenerate IR with current version of Model Optimizer\n" - "- [WORKAROUND] Call only reshape method where proper batch is already set\n"; - } - } - } - } - - return OK; -} - -StatusCode CNNNetworkImpl::serialize(const std::string& xmlPath, const std::string& binPath, ResponseDesc* resp) const - noexcept { - try { -#ifdef ENABLE_V7_SERIALIZE - IE_SUPPRESS_DEPRECATED_START - Serialization::Serialize(xmlPath, - binPath, - CNNNetwork(std::const_pointer_cast(shared_from_this()))); - IE_SUPPRESS_DEPRECATED_END - return OK; -#endif - } catch (const Exception& e) { - return DescriptionBuffer(GENERAL_ERROR, resp) << e.what(); - } catch (const std::exception& e) { - return DescriptionBuffer(UNEXPECTED, resp) << e.what(); - } catch (...) { - return DescriptionBuffer(UNEXPECTED, resp); - } - - return DescriptionBuffer(NOT_IMPLEMENTED, resp) << "The CNNNetworkImpl::serialize is not implemented"; -} - -StatusCode CNNNetworkImpl::serialize(std::ostream& xmlBuf, std::ostream& binBuf, ResponseDesc* resp) const noexcept { - return DescriptionBuffer(NOT_IMPLEMENTED, resp) << "The CNNNetworkImpl::serialize is not implemented"; -} - -StatusCode CNNNetworkImpl::serialize(std::ostream& xmlBuf, Blob::Ptr& binBlob, ResponseDesc* resp) const noexcept { - return DescriptionBuffer(NOT_IMPLEMENTED, resp) << "The CNNNetworkImpl::serialize is not implemented"; -} - -StatusCode CNNNetworkImpl::setBatchSize(size_t size, ResponseDesc* responseDesc) noexcept { - try { - auto originalBatchSize = getBatchSize(); - if (originalBatchSize == size) - return OK; - if (_inputData.empty()) - return DescriptionBuffer(GENERAL_ERROR, responseDesc) - << "Cannot set batch! Topology doesn't contain inputs!"; - - SizeVector dims = _inputData.cbegin()->second->getTensorDesc().getDims(); - - // 3D/1D/0D input layouts don't have batch notation - if (dims.size() == 3 || dims.size() == 1 || dims.empty()) { - return DescriptionBuffer(PARAMETER_MISMATCH, responseDesc) << "Cannot set batch for 0D/1D/3D input"; - } - - IE_SUPPRESS_DEPRECATED_START - const std::map layersMap = getConstLayersMap(CNNNetwork(shared_from_this())); - IE_SUPPRESS_DEPRECATED_END - for (auto& layer : _data) { - SizeVector dims = layer.second->getDims(); - CNNLayerPtr layerT = getCreatorLayer(layer.second).lock(); - - bool constOrAbsent; - if (layerT) { - const auto it = layersMap.find(layerT.get()); - if (it == layersMap.end()) { - IE_THROW() << "layer '" << layerT->name << "' was not found in layers map"; - } - constOrAbsent = it->second; - } else { - constOrAbsent = true; - } - - if (!layerT || !constOrAbsent) { - float diff = static_cast(dims.at(0)) / static_cast(originalBatchSize); - dims.at(0) = static_cast(std::ceil(size * diff)); - layer.second->setDims(dims); - } - } - return OK; - } catch (const Exception& e) { - return DescriptionBuffer(GENERAL_ERROR, responseDesc) << e.what(); - } catch (const std::exception& e) { - return DescriptionBuffer(UNEXPECTED, responseDesc) << e.what(); - } catch (...) { - return DescriptionBuffer(UNEXPECTED, responseDesc); - } -} - -StatusCode CNNNetworkImpl::setBatchSizeReshape(size_t size, ResponseDesc* responseDesc) noexcept { - InputShapes inputShapes; - try { - for (const auto& pair : _inputData) { - auto info = pair.second; - if (info) { - auto data = info->getInputData(); - if (data) { - auto dims = data->getTensorDesc().getDims(); - dims[0] = size; - inputShapes[data->getName()] = dims; - } - } - } - return reshape(inputShapes, responseDesc); - } catch (const Exception& e) { - return DescriptionBuffer(GENERAL_ERROR, responseDesc) << e.what(); - } catch (const std::exception& e) { - return DescriptionBuffer(UNEXPECTED, responseDesc) << e.what(); - } catch (...) { - return DescriptionBuffer(UNEXPECTED, responseDesc); - } -} diff --git a/src/plugins/intel_gna/legacy/src/convert_function_to_cnn_network.cpp b/src/plugins/intel_gna/legacy/src/convert_function_to_cnn_network.cpp deleted file mode 100644 index b1eb1e0539e..00000000000 --- a/src/plugins/intel_gna/legacy/src/convert_function_to_cnn_network.cpp +++ /dev/null @@ -1,2402 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/convert_function_to_cnn_network.hpp" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "caseless.hpp" -#include "cpp/ie_cnn_network.h" -#include "exec_graph_info.hpp" -#include "gna_convolution.hpp" -#include "gna_max_pool.hpp" -#include "ie_legacy_itt.hpp" -#include "legacy/graph_tools.hpp" -#include "legacy/net_pass.h" -#include "legacy/ngraph_ops/convolution_ie.hpp" -#include "legacy/ngraph_ops/crop_ie.hpp" -#include "legacy/ngraph_ops/deconvolution_ie.hpp" -#include "legacy/ngraph_ops/eltwise.hpp" -#include "legacy/ngraph_ops/fully_connected.hpp" -#include "legacy/ngraph_ops/gather_ie.hpp" -#include "legacy/ngraph_ops/gather_tree_ie.hpp" -#include "legacy/ngraph_ops/gru_cell_ie.hpp" -#include "legacy/ngraph_ops/gru_sequence_ie.hpp" -#include "legacy/ngraph_ops/hard_sigmoid_ie.hpp" -#include "legacy/ngraph_ops/interp.hpp" -#include "legacy/ngraph_ops/lrn_ie.hpp" -#include "legacy/ngraph_ops/lstm_cell_ie.hpp" -#include "legacy/ngraph_ops/lstm_sequence_ie.hpp" -#include "legacy/ngraph_ops/nms_ie.hpp" -#include "legacy/ngraph_ops/normalize_ie.hpp" -#include "legacy/ngraph_ops/onehot_ie.hpp" -#include "legacy/ngraph_ops/pad_ie.hpp" -#include "legacy/ngraph_ops/power.hpp" -#include "legacy/ngraph_ops/proposal_ie.hpp" -#include "legacy/ngraph_ops/relu_ie.hpp" -#include "legacy/ngraph_ops/rnn_cell_ie.hpp" -#include "legacy/ngraph_ops/rnn_sequence_ie.hpp" -#include "legacy/ngraph_ops/scaleshift.hpp" -#include "legacy/ngraph_ops/selu_ie.hpp" -#include "legacy/ngraph_ops/tile_ie.hpp" -#include "legacy/ngraph_ops/topk_ie.hpp" -#include "openvino/runtime/aligned_buffer.hpp" -#include "transformations/rt_info/fused_names_attribute.hpp" -#include "transformations/rt_info/primitives_priority_attribute.hpp" -#include "transformations/utils/utils.hpp" - -namespace Builder { - -template -std::string asString(const T& value) { - return std::to_string(value); -} - -template -std::string asString(const std::vector& value) { - std::string result; - for (const auto& item : value) { - if (!result.empty()) - result += ","; - result += asString(item); - } - return result; -} - -template <> -std::string asString(const double& value) { - std::ostringstream sStrm; - sStrm.precision(std::numeric_limits::digits10); - sStrm << std::fixed << value; - std::string result = sStrm.str(); - - auto pos = result.find_last_not_of("0"); - if (pos != std::string::npos) - result.erase(pos + 1); - - pos = result.find_last_not_of("."); - if (pos != std::string::npos) - result.erase(pos + 1); - - return result; -} - -template <> -std::string asString(const float& value) { - return asString(static_cast(value)); -} - -} // namespace Builder - -namespace InferenceEngine { -namespace { - -// helper for adding creators with a specific exception -#define REQUIRED_IE_CONVERSION_CREATOR(type_name, ie_type_name) \ - addSpecificCreator({type_name}, \ - [](const std::shared_ptr<::ngraph::Node>& node, \ - const std::map& params) -> CNNLayerPtr { \ - IE_THROW() << type_name << " operation has a form that is not supported. " \ - << node->get_friendly_name() << " should be converted to " << ie_type_name \ - << " operation."; \ - return nullptr; \ - }); - -/// \brief Creates legacy representation of CNNLayer for SubGraphOp. -/// \param layer node type -/// \return pointer to CNNLayer with legacy representation of SubGraphOp. -CNNLayer::Ptr createSubGraphLayer(const std::shared_ptr& layer) { - auto sub_graph = std::dynamic_pointer_cast(layer); - if (!sub_graph) { - IE_THROW() << "Cannot cast layer to SubGraphOp."; - } - - // inputs/outputs of TensorIterator (ngraph representation) - auto parameters = sub_graph->get_function()->get_parameters(); - auto results = sub_graph->get_function()->get_results(); - - // Convert body (ngraph representation) to CNNNetwork. - // This network will contain nodes of type = "Input" and data nodes with wrong names. - // IE TensorIterator doesn't include such nodes so we create CNNNetwork in a separate scope - // to call the destructor and delete these "Input"/data nodes. - - TensorIterator::Body body; - { - InferenceEngine::CNNNetwork body_net(sub_graph->get_function()); - IE_SUPPRESS_DEPRECATED_START - // TODO: fix convertFunctionToICNNNetwork - InferenceEngine::CNNNetwork net( - InferenceEngine::details::convertFunctionToICNNNetwork(body_net.getFunction(), body_net)); - IE_SUPPRESS_DEPRECATED_END - // Paranoid check for cycles - bool res = CNNNetForestDFS( - CNNNetGetAllInputLayers(net), - [](const CNNLayerPtr& layer) {}, - false); - if (!res) { - IE_THROW() << "Loop detected. SubGraphOp body should not contain loops."; - } - - // Get inputs/outputs of cnn network - auto in_info_map_with_parameters = net.getInputsInfo(); - auto out_info_map = net.getOutputsInfo(); - - IE_ASSERT(in_info_map_with_parameters.size() == parameters.size()); - IE_ASSERT(out_info_map.size() == results.size()); - - InferenceEngine::TensorIterator::Body temp_body; - temp_body.inputs.resize(in_info_map_with_parameters.size()); - temp_body.outputs.resize(out_info_map.size()); - - // Fill inputs/outs in order aligned with ng representation - uint64_t counter = 0; - for (const auto& param : parameters) { - auto info = in_info_map_with_parameters.at(param->get_friendly_name()); - temp_body.inputs[counter++] = info->getInputData(); - } - - counter = 0; - for (const auto& result : results) { - auto data = out_info_map.at(ov::op::util::get_ie_output_name(result->input_value(0))); - temp_body.outputs[counter++] = data; - } - - // This deep copy will hold all unreachable constants. See the comment in CopyTIBody function. - body = InferenceEngine::NetPass::CopyTIBody(temp_body); - - // Check if data is really const layer holder - auto is_constant_holder = [](const DataPtr data) { - return data->getPrecision() == Precision::UNSPECIFIED; - }; - - // Strip unreached node holder from Inputs node. - auto holder = body.inputs.back(); - if (is_constant_holder(holder)) { - auto& holder_map = getInputTo(holder); - - for (auto it = holder_map.begin(); it != holder_map.end();) { - if (it->second->type == "Input") - it = holder_map.erase(it); - else - ++it; - } - } - - // TODO: Disable this WA after total switch onto Ngraph - // WA: Some plugins (like GPU) require matching of Data object name and producer Layer name. - // Data name is expected in format "[layer_name]" or "[layer_name].[port_idx]" in case - // of multiple inputs. We have to restore it if possible and ignore original names of - // Ngraph parameter and result ops. - // Will not change data name if: - // - data has several consumer layers - // - data has no consumer (example if data is straight used as output) - // - for (auto& in : body.inputs) { - if (is_constant_holder(in)) - continue; - - const auto input_to = getInputTo(in); - if (input_to.size() != 1) - continue; - - const auto consumer_layer = input_to.begin()->second; - const auto consumer_in_port_set = consumer_layer->insData; - const auto found = - std::find_if(consumer_in_port_set.begin(), consumer_in_port_set.end(), [&in](const DataWeakPtr& wptr) { - return wptr.lock() == in; - }); - IE_ASSERT(found != consumer_in_port_set.end()); - const auto consumer_port_idx = std::distance(consumer_in_port_set.begin(), found); - - auto new_name = consumer_layer->name; - if (consumer_in_port_set.size() > 1) { - new_name += '.' + std::to_string(consumer_port_idx); - } - in->setName(new_name); - } - - // TODO: this WA restore original precisions of outputs. - // convertFunctionToICNNNetwork has internal fallback policy for unsupported - // precisions for inputs/outputs ports. Particular for U8 will be translated - // to FP32. However Loop body has strong requirements for continue_condition - // port, it should be BOOL(U8). - // - for (size_t i = 0; i < results.size(); i++) { - auto result = results[i]; - auto output = body.outputs[i]; - if (result->get_element_type() == ngraph::element::u8) { - output->setPrecision(InferenceEngine::Precision::U8); - } - } - } - - // Create Inference Engine representation of TensorIterator - LayerParams params = {layer->get_friendly_name(), - "TensorIterator", - details::convertPrecision(layer->get_output_element_type(0))}; - auto res = std::make_shared(params); - if (res == nullptr) { - IE_THROW() << "Can't create TensorIterator"; - } - res->body = body; - - // Port map: outputs - for (const auto& desc : sub_graph->get_output_descriptions()) { - auto body_output_idx = desc->m_body_value_index; - - std::string type_name = desc->get_type_info().name; - if (type_name == "ConcatOutputDescription") { - auto output_desc = ::ngraph::as_type_ptr(desc); - IE_ASSERT(output_desc != nullptr); - - res->output_port_map.emplace_back( - InferenceEngine::TensorIterator::PortMap{static_cast(output_desc->m_output_index), - static_cast(body_output_idx), - static_cast(output_desc->m_axis), - static_cast(output_desc->m_stride), - static_cast(output_desc->m_start), - static_cast(output_desc->m_end), - static_cast(output_desc->m_part_size)}); - } else if (type_name == "BodyOutputDescription") { - auto output_desc = ::ngraph::as_type_ptr(desc); - IE_ASSERT(output_desc != nullptr); - - res->output_port_map.emplace_back( - InferenceEngine::TensorIterator::PortMap{static_cast(output_desc->m_output_index), - static_cast(body_output_idx), - -1, - 1, - 0, - -1, - 1}); - } else { - IE_THROW() << "Incorrect type of the output description."; - } - } - - // Port map : inputs and back edges - for (const auto& desc : sub_graph->get_input_descriptions()) { - auto body_input_index = desc->m_body_parameter_index; - - if (const auto slice_desc = - std::dynamic_pointer_cast(desc)) { - res->input_port_map.emplace_back( - InferenceEngine::TensorIterator::PortMap{static_cast(slice_desc->m_input_index), - static_cast(body_input_index), - static_cast(slice_desc->m_axis), - static_cast(slice_desc->m_stride), - static_cast(slice_desc->m_start), - static_cast(slice_desc->m_end), - static_cast(slice_desc->m_part_size)}); - } else if (const auto merge_desc = - std::dynamic_pointer_cast(desc)) { - res->input_port_map.emplace_back( - InferenceEngine::TensorIterator::PortMap{static_cast(merge_desc->m_input_index), - static_cast(body_input_index), - -1, - 1, - 0, - -1, - 1}); - - auto body_output_idx = merge_desc->m_body_value_index; - - res->back_edges.emplace_back(InferenceEngine::TensorIterator::PortMap{static_cast(body_output_idx), - static_cast(body_input_index), - -1, - 1, - 0, - -1, - 1}); - } else if (const auto inv_desc = - std::dynamic_pointer_cast(desc)) { - res->input_port_map.emplace_back( - InferenceEngine::TensorIterator::PortMap{static_cast(inv_desc->m_input_index), - static_cast(body_input_index), - -1, - 1, - 0, - -1, - 1}); - } else { - IE_THROW() << "Incorrect type of the input description."; - } - } - - if (const auto loop_op = std::dynamic_pointer_cast(layer)) { - auto spec_port = loop_op->get_special_body_ports(); - if (spec_port.current_iteration_input_idx != -1) { - auto ie_port_idx = spec_port.current_iteration_input_idx; - res->params["loop_body_current_iteration_idx"] = std::to_string(ie_port_idx); - } - if (spec_port.body_condition_output_idx != -1) { - auto body_output_idx = spec_port.body_condition_output_idx; - res->params["loop_body_condition_output_idx"] = std::to_string(body_output_idx); - } - res->params["loop_trip_count_idx"] = "0"; - res->params["loop_execution_condition_idx"] = "1"; - } - - return res; -} - -/** - * @brief Creator for CNNLayer from nGraph op - */ -class CNNLayerCreator : public ::ngraph::AttributeVisitor { -public: - explicit CNNLayerCreator(); - - CNNLayerPtr create(const std::shared_ptr<::ngraph::Node>& origin); - -protected: - using CreatorFor = std::function& node, - const std::map& param)>; - - void on_adapter(const std::string& name, ::ngraph::ValueAccessor& value) override { - params[name] = value.get() ? "true" : "false"; - } - - void addSpecificCreator(const std::vector& forTypes, const CreatorFor& creator) { - for (const auto& type : forTypes) { - creators[type] = creator; - } - } - - void on_adapter(const std::string& name, ::ngraph::ValueAccessor& adapter) override { - std::string data = adapter.get(); - std::transform(data.begin(), data.end(), data.begin(), [](unsigned char c) { - return std::tolower(c); - }); - params[name] = data; - } - - void on_adapter(const std::string& name, ::ngraph::ValueAccessor>& adapter) override { - auto shape = adapter.get(); - params[name] = details::joinVec(shape); - } - - void on_adapter(const std::string& name, ::ngraph::ValueAccessor>& adapter) override { - auto shape = adapter.get(); - params[name] = details::joinVec(shape); - } - - void on_adapter(const std::string& name, ::ngraph::ValueAccessor& adapter) override { - std::ostringstream stream; - stream.precision(8); - stream << std::fixed << adapter.get(); - params[name] = stream.str(); - } - - void on_adapter(const std::string& name, ::ngraph::ValueAccessor& adapter) override { - params[name] = std::to_string(adapter.get()); - } - - void on_adapter(const std::string& name, ngraph::ValueAccessor>& adapter) override { - std::vector data = adapter.get(); - for (auto& str : data) { - std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { - return std::tolower(c); - }); - } - - std::stringstream ss; - std::copy(data.begin(), data.end(), std::ostream_iterator(ss, ",")); - params[name] = ss.str(); - } - - void on_adapter(const std::string& name, ngraph::ValueAccessor>& adapter) override { - auto data = adapter.get(); - params[name] = details::joinVec(data); - } - - void on_adapter(const std::string& name, - ::ngraph::ValueAccessor>& adapter) override {} - - void on_adapter(const std::string& name, ::ngraph::ValueAccessor& adapter) override; - -private: - std::shared_ptr<::ngraph::Node> node; - std::map params; - std::map creators; -}; - -void CNNLayerCreator::on_adapter(const std::string& name, ::ngraph::ValueAccessor& adapter) { - if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter<::ngraph::element::Type>>(&adapter)) { - auto type = static_cast<::ngraph::element::Type&>(*a); - params[name] = details::convertPrecision(type).name(); - } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter<::ngraph::PartialShape>>(&adapter)) { - std::string dims; - auto shape = a->get(); - if (shape.rank().is_dynamic()) { - IE_THROW() << "Error converting ngraph to CNN network. Dynamic rank is not supported."; - } - for (int64_t i = 0; i < shape.rank().get_length(); i++) { - if (shape[i].is_dynamic()) - IE_THROW() << "Error converting ngraph to CNN network. Dynamic dimension is not supported."; - if (!dims.empty()) - dims += ","; - dims += std::to_string(shape[i].get_length()); - } - params[name] = dims; - } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter<::ngraph::Shape>>(&adapter)) { - auto shape = static_cast<::ngraph::Shape&>(*a); - params[name] = details::joinVec(shape); - } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter<::ngraph::Strides>>(&adapter)) { - auto shape = static_cast<::ngraph::Strides&>(*a); - params[name] = details::joinVec(shape); - } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter>>(&adapter)) { - auto data = a->get(); - params[name] = details::joinVec(data); - } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter>>(&adapter)) { - params[name] = a->get()->get_info().variable_id; - } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter< - std::vector>>>(&adapter)) { - (void)a; - } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter< - std::vector>>>(&adapter)) { - (void)a; - } else if (auto a = - ::ngraph::as_type<::ngraph::AttributeAdapter>(&adapter)) { - (void)a; - } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter>>( - &adapter)) { - if (std::string(node->get_type_name()) != "Constant") { - const auto data_beg = static_cast(a->get()->get_ptr()); - params[name] = std::string(data_beg, a->get()->size()); - } - } else if (auto a = ::ngraph::as_type<::ngraph::AttributeAdapter>>(&adapter)) { - if (std::string(node->get_type_name()) != "Constant") { - const auto data_beg = static_cast(a->get()->get_ptr()); - params[name] = std::string(data_beg, a->get()->size()); - } - } else if (const auto& a = ngraph::as_type>(&adapter)) { - const auto& attrs = a->get(); - params[name] = details::joinVec(attrs); - } else { - IE_THROW() << "Error converting ngraph to CNN network. " - "Attribute adapter can not be found for " - << name << " parameter"; - } -} - -CNNLayerCreator::CNNLayerCreator() { - addSpecificCreator({"Parameter"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Input", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - return res; - }); - // TODO - Remove "GreaterEq" once ngraph transitions to GreaterEqual - addSpecificCreator({"Eltwise", - "Subtract", - "Power", - "Maximum", - "Minimum", - "Divide", - "Greater", - "GreaterEqual", - "FloorMod", - "LogicalOr", - "LogicalAnd", - "LogicalXor", - "GreaterEq", - "Less", - "LessEqual", - "Equal", - "NotEqual", - "Multiply", - "Add"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Eltwise", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - if (node->description() == "Maximum") { - res->params["operation"] = "max"; - } else if (node->description() == "Minimum") { - res->params["operation"] = "min"; - } else if (node->description() == "Power") { - res->params["operation"] = "pow"; - } else if (node->description() == "Subtract") { - res->params["operation"] = "sub"; - } else if (node->description() == "Divide") { - res->params["operation"] = "div"; - } else if (node->description() == "LessEqual") { - res->params["operation"] = "less_equal"; - } else if (node->description() == "Less") { - res->params["operation"] = "less"; - } else if (node->description() == "Equal") { - res->params["operation"] = "equal"; - } else if (node->description() == "NotEqual") { - res->params["operation"] = "not_equal"; - } else if (node->description() == "FloorMod") { - res->params["operation"] = "floor_mod"; - } else if (node->description() == "Multiply") { - res->params["operation"] = "prod"; - } else if (node->description() == "Add") { - res->params["operation"] = "sum"; - } else if (node->description() == "Greater") { - res->params["operation"] = "greater"; - } else if (node->description() == "GreaterEq") { - res->params["operation"] = "greater_equal"; - } else if (node->description() == "GreaterEqual") { - res->params["operation"] = "greater_equal"; - } else if (node->description() == "LogicalOr") { - res->params["operation"] = "logical_or"; - } else if (node->description() == "LogicalAnd") { - res->params["operation"] = "logical_and"; - } else if (node->description() == "LogicalXor") { - res->params["operation"] = "logical_xor"; - } else if (node->description() == "Eltwise") { - auto castedLayer = std::dynamic_pointer_cast<::ngraph::op::Eltwise>(node); - if (castedLayer == nullptr) - IE_THROW() << "Cannot get " << attrs.type << " layer " << attrs.name; - std::string type; - switch (castedLayer->eltwise_type) { - case ELTWISE_TYPE::Sum: - type = "sum"; - break; - case ELTWISE_TYPE::Sub: - type = "sub"; - break; - case ELTWISE_TYPE::Prod: - type = "prod"; - break; - default: - IE_THROW() << "Not supported eltwise type!"; - } - - res->params["operation"] = type; - } - return res; - }); - addSpecificCreator({"Concat"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - node->description(), - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - auto axis = std::stoi(res->params["axis"]); - res->params["axis"] = - Builder::asString(axis < 0 ? axis + node->get_input_shape(0).size() : axis); - return res; - }); - addSpecificCreator({"AvgPool", "MaxPool", "GNAMaxPool"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Pooling", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - if (res->params.find("auto_pad") != res->params.end() && - details::CaselessEq()(res->params["auto_pad"], "EXPLICIT")) - res->params.erase("auto_pad"); - - if (res->params.find("exclude_pad") != res->params.end()) { - res->params["exclude-pad"] = res->params["exclude_pad"]; - res->params.erase("exclude_pad"); - } - - if (node->description() == "MaxPool" || node->description() == "GNAMaxPool") { - res->params["pool-method"] = "max"; - } else if (node->description() == "AvgPool") { - res->params["pool-method"] = "avg"; - } - return res; - }); - addSpecificCreator({"Select"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - node->description(), - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - addSpecificCreator({"BinaryConvolution"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - node->description(), - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - - // todo: investigate difference between ngraph parameters for BinConvolution and the - // implementation above this leads to accuracy issue for - // Precollected_ONNX_ResNet50_88percentinto1bit e2e test res->params = params; - - auto castedLayer = ::ngraph::as_type_ptr<::ngraph::op::v1::BinaryConvolution>(node); - IE_ASSERT(castedLayer) - << " Operation " << node->description() << " with name " << node->get_friendly_name() - << " cannot be casted to ngraph::op::v1::BinaryConvolution"; - - std::string value; - for (const auto& val : castedLayer->get_pads_begin()) { - if (!value.empty()) - value += ","; - value += Builder::asString(val); - } - res->params["pads_begin"] = value; - - value.clear(); - for (const auto& val : castedLayer->get_pads_end()) { - if (!value.empty()) - value += ","; - value += Builder::asString(val); - } - res->params["pads_end"] = value; - - switch (castedLayer->get_auto_pad()) { - case ::ngraph::op::PadType::SAME_UPPER: - res->params["auto_pad"] = "same_upper"; - break; - case ::ngraph::op::PadType::SAME_LOWER: - res->params["auto_pad"] = "same_lower"; - break; - case ::ngraph::op::PadType::VALID: - res->params["auto_pad"] = "valid"; - break; - default: - break; - } - - value.clear(); - for (const auto& val : castedLayer->get_strides()) { - if (!value.empty()) - value += ","; - value += Builder::asString(val); - } - res->params["strides"] = value; - - value.clear(); - for (const auto& val : castedLayer->get_dilations()) { - if (!value.empty()) - value += ","; - value += Builder::asString(val); - } - res->params["dilations"] = value; - - // Restore kernel size and output - const auto& shape = castedLayer->get_input_shape(1); - res->params["output"] = Builder::asString(shape[0]); - - value.clear(); - for (size_t i = 2; i < shape.size(); i++) { - if (!value.empty()) - value += ","; - value += Builder::asString(shape[i]); - } - res->params["kernel"] = value; - - switch (castedLayer->get_mode()) { - case ::ngraph::op::v1::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT: - res->params["mode"] = "xnor-popcount"; - } - - IE_ASSERT(castedLayer->input(1).get_partial_shape().is_static()) - << " Weights for binary convolution " << castedLayer->get_friendly_name() - << " should have static shapes!"; - auto weights_shape = castedLayer->input(1).get_source_output().get_shape(); - res->params["input"] = Builder::asString(weights_shape[1]); - res->params["pad_value"] = Builder::asString(castedLayer->get_pad_value()); - - const auto weightsNode = castedLayer->input(1).get_source_output().get_node_shared_ptr(); - addBlob(weightsNode, res, InferenceEngine::details::weights); - - return res; - }); - - addSpecificCreator({"SpaceToBatch"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - node->description(), - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"BatchToSpace"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - node->description(), - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"Assign"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Memory", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params["id"] = params.at("variable_id"); - res->params["index"] = "0"; - res->params["size"] = "2"; - return res; - }); - - addSpecificCreator({"ReadValue"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Memory", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params["id"] = params.at("variable_id"); - res->params["index"] = "1"; - res->params["size"] = "2"; - return res; - }); - - addSpecificCreator({"DepthToSpace"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - node->description(), - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"SpaceToDepth"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - node->description(), - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"DeconvolutionIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Deconvolution", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - - res->params = params; - const auto& shape = node->get_input_shape(1); - res->params["output"] = Builder::asString(shape[1]); - std::string kernel_value; - for (size_t i = 2; i < shape.size(); i++) { - if (!kernel_value.empty()) - kernel_value += ","; - kernel_value += Builder::asString(shape[i]); - } - res->params["kernel"] = kernel_value; - - const auto weightsNode = node->input_value(1).get_node_shared_ptr(); - if (InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights)) { - if (node->inputs().size() == 3) { - const auto biasNode = node->input_value(2).get_node_shared_ptr(); - InferenceEngine::details::addBlob(biasNode, res, InferenceEngine::details::biases); - } - } - return res; - }); - - addSpecificCreator({"DetectionOutput"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "DetectionOutput", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - - if (res->params["code_type"] == "caffe.priorboxparameter.center_size") { - res->params["code_type"] = "caffe.PriorBoxParameter.CENTER_SIZE"; - } else { - res->params["code_type"] = "caffe.PriorBoxParameter.CORNER"; - } - res->params["variance_encoded_in_target"] = - res->getBoolStrParamAsIntStr("variance_encoded_in_target"); - res->params["share_location"] = res->getBoolStrParamAsIntStr("share_location"); - res->params["clip_after_nms"] = res->getBoolStrParamAsIntStr("clip_after_nms"); - res->params["clip_before_nms"] = res->getBoolStrParamAsIntStr("clip_before_nms"); - res->params["decrease_label_id"] = res->getBoolStrParamAsIntStr("decrease_label_id"); - res->params["normalized"] = res->getBoolStrParamAsIntStr("normalized"); - return res; - }); - - addSpecificCreator({"LogicalNot"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Activation", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params["type"] = "not"; - return res; - }); - - addSpecificCreator({"LSTMCellIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "LSTMCell", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - const auto weightsNode = node->input_value(3).get_node_shared_ptr(); - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights); - - const auto biasNode = node->input_value(4).get_node_shared_ptr(); - InferenceEngine::details::addBlob(biasNode, res, InferenceEngine::details::biases); - - return res; - }); - - addSpecificCreator({"RNNCellIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "RNNCell", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - - const auto weightsNode = node->input_value(2).get_node_shared_ptr(); - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights); - - const auto biasNode = node->input_value(3).get_node_shared_ptr(); - InferenceEngine::details::addBlob(biasNode, res, InferenceEngine::details::biases); - - return res; - }); - - addSpecificCreator({"GRUCellIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "GRUCell", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - - const auto weightsNode = node->input_value(2).get_node_shared_ptr(); - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights); - - const auto biasNode = node->input_value(3).get_node_shared_ptr(); - InferenceEngine::details::addBlob(biasNode, res, InferenceEngine::details::biases); - - return res; - }); - - addSpecificCreator({"PRelu"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "PReLU", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - - const auto weightsNode = node->input_value(1).get_node_shared_ptr(); - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights); - - return res; - }); - - addSpecificCreator({"TileIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Tile", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"ProposalIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Proposal", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - res->params["clip_before_nms"] = res->getBoolStrParamAsIntStr("clip_before_nms"); - res->params["clip_after_nms"] = res->getBoolStrParamAsIntStr("clip_after_nms"); - res->params["normalize"] = res->getBoolStrParamAsIntStr("normalize"); - return res; - }); - - addSpecificCreator({"Relu", "ReLUIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "ReLU", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"Reshape"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Reshape", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - return res; - }); - - addSpecificCreator({"ReverseSequence"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "ReverseSequence", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"SeluIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Selu", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"Softmax"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "SoftMax", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"Split"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Split", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - - auto axis_node = node->input_value(1).get_node_shared_ptr(); - const auto axis_node_const = std::dynamic_pointer_cast(axis_node); - if (!axis_node_const) { - IE_THROW() << "Split " << node->get_friendly_name() << " has no axes as Constant"; - } - auto axis = axis_node_const->cast_vector()[0]; - if (axis < 0) { - axis += node->get_input_shape(0).size(); - } - res->params["axis"] = Builder::asString(axis); - - return res; - }); - - addSpecificCreator({"Tanh"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "TanH", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"ScatterElementsUpdate"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - node->description(), - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"ScatterUpdate"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - node->description(), - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"StaticShapeTopK"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "TopK", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"StridedSlice"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "StridedSlice", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - auto stridedSliceInvertMaskStr = [](const std::string& str) -> std::string { - std::string value; - auto found_numbers = details::split(str, ","); - for (const auto& val : found_numbers) { - if (!value.empty()) - value += ","; - value += Builder::asString((1 - std::stoi(val))); - } - return value; - }; - - res->params = params; - // plugins require reversed value of begin_mask and end_mask - res->params["begin_mask"] = stridedSliceInvertMaskStr(res->params["begin_mask"]); - res->params["end_mask"] = stridedSliceInvertMaskStr(res->params["end_mask"]); - - return res; - }); - - addSpecificCreator({"TopK", "TopKIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "TopK", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"Transpose"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Permute", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - if (auto transpose_const = std::dynamic_pointer_cast( - node->input_value(1).get_node_shared_ptr())) { - res->params["order"] = Builder::asString(transpose_const->cast_vector()); - } - return res; - }); - - addSpecificCreator({"SwishIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Swish", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator( - {"NonMaxSuppressionIE3"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "NonMaxSuppression", - details::convertPrecision(node->get_output_element_type(0))}; - - auto castedLayer = ::ngraph::as_type_ptr<::ngraph::op::NonMaxSuppressionIE3>(node); - IE_ASSERT(castedLayer) << " Operation " << node->description() << " with name " << node->get_friendly_name() - << " cannot be casted to ngraph::op::NonMaxSuppressionIE3"; - - auto res = std::make_shared(attrs); - res->params = params; - - res->params["center_point_box"] = castedLayer->m_center_point_box ? "true" : "false"; - res->params["sort_result_descending"] = castedLayer->m_sort_result_descending ? "true" : "false"; - - auto output_type = details::convertPrecision(castedLayer->m_output_type); - std::string output_type_str; - switch (output_type) { - case Precision::I32: - output_type_str = "I32"; - break; - case Precision::I64: - output_type_str = "I64"; - break; - default: - IE_THROW() << "Unsupported output type"; - } - res->params["output_type"] = output_type_str; - - return res; - }); - - addSpecificCreator({"NonMaxSuppression"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "NonMaxSuppression", - details::convertPrecision(node->get_output_element_type(0))}; - - auto castedLayer = ::ngraph::as_type_ptr<::ngraph::op::v5::NonMaxSuppression>(node); - IE_ASSERT(castedLayer) - << " Operation " << node->description() << " with name " << node->get_friendly_name() - << " cannot be casted to ngraph::op::v5::NonMaxSuppression"; - - auto res = std::make_shared(attrs); - res->params = params; - - auto box_encoding = castedLayer->get_box_encoding(); - switch (box_encoding) { - case ngraph::op::v5::NonMaxSuppression::BoxEncodingType::CORNER: - res->params["center_point_box"] = "false"; - break; - case ngraph::op::v5::NonMaxSuppression::BoxEncodingType::CENTER: - res->params["center_point_box"] = "true"; - break; - default: - IE_THROW() << "Unsupported box encoding for NonMaxSuppression op"; - break; - } - - auto output_type = details::convertPrecision(castedLayer->get_output_type()); - std::string output_type_str; - switch (output_type) { - case Precision::I32: - output_type_str = "I32"; - break; - case Precision::I64: - output_type_str = "I64"; - break; - default: - IE_THROW() << "Unsupported output type"; - } - res->params["output_type"] = output_type_str; - - bool sort_result_descending = castedLayer->get_sort_result_descending(); - res->params["sort_result_descending"] = sort_result_descending ? "true" : "false"; - - return res; - }); - - addSpecificCreator({"NonMaxSuppressionIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "NonMaxSuppression", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"GRUSequenceIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "GRUSequence", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - res->axis = std::stoi(res->params["axis"]); - if (res->params["direction"] == "reverse") - res->params["direction"] = "Backward"; - else if (res->params["direction"] == "forward") - res->params["direction"] = "Forward"; - else - res->params["direction"] = "Bidirectional"; - - res->cellType = RNNSequenceLayer::CellType::GRU; - if (res->params["linear_before_reset"] == "true") { - res->cellType = RNNSequenceLayer::CellType::GRU_LBR; - } - - const auto weightsNode = node->input_value(3).get_node_shared_ptr(); - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights); - - const auto biasNode = node->input_value(4).get_node_shared_ptr(); - InferenceEngine::details::addBlob(biasNode, res, InferenceEngine::details::biases); - - return res; - }); - - addSpecificCreator({"RNNSequenceIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "RNNSequence", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - - res->cellType = RNNSequenceLayer::CellType::RNN; - res->axis = std::stoi(res->params["axis"]); - if (res->params["direction"] == "reverse") - res->params["direction"] = "Backward"; - else if (res->params["direction"] == "forward") - res->params["direction"] = "Forward"; - else - res->params["direction"] = "Bidirectional"; - - const auto weightsNode = node->input_value(3).get_node_shared_ptr(); - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights); - - const auto biasNode = node->input_value(4).get_node_shared_ptr(); - InferenceEngine::details::addBlob(biasNode, res, InferenceEngine::details::biases); - - return res; - }); - - addSpecificCreator({"LSTMSequenceIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "LSTMSequence", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - - res->cellType = RNNSequenceLayer::CellType::LSTM; - res->axis = std::stoi(res->params["axis"]); - if (res->params["direction"] == "reverse") - res->params["direction"] = "Backward"; - else if (res->params["direction"] == "forward") - res->params["direction"] = "Forward"; - else - res->params["direction"] = "Bidirectional"; - - const auto weightsNode = node->input_value(4).get_node_shared_ptr(); - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights); - - const auto biasNode = node->input_value(5).get_node_shared_ptr(); - InferenceEngine::details::addBlob(biasNode, res, InferenceEngine::details::biases); - - return res; - }); - - REQUIRED_IE_CONVERSION_CREATOR("Broadcast", "Tile"); - REQUIRED_IE_CONVERSION_CREATOR("Interpolate", "Interp"); - REQUIRED_IE_CONVERSION_CREATOR("NormalizeL2", "NormalizeIE"); - REQUIRED_IE_CONVERSION_CREATOR("GroupConvolution", "ConvolutionIE"); - REQUIRED_IE_CONVERSION_CREATOR("GroupConvolutionBackpropData", "DeconvolutionIE"); - - addSpecificCreator({"Convolution", - "GatherTree", - "GRUCell", - "GRUSequence", - "HardSigmoid", - "LRN", - "LSTMCell", - "LSTMSequence", - "NonMaxSuppression", - "RNNCell", - "RNNSequence", - "OneHot", - "Pad", - "PriorBoxClustered", - "PriorBox", - "Proposal", - "Selu", - "Swish", - "Tile"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - const std::string& type_name = node->get_type_name(); - IE_THROW() << type_name << " operation has a form that is not supported. " - << node->get_friendly_name() << " should be converted to " - << type_name + "IE operation."; - return nullptr; - }); - - addSpecificCreator( - {"ReduceMin", "ReduceMax", "ReduceMean", "ReduceProd", "ReduceSum", "ReduceL1", "ReduceL2"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - node->description(), - details::convertPrecision(node->get_output_element_type(0))}; - auto reduce_node = std::dynamic_pointer_cast(node); - if (reduce_node == nullptr) - IE_THROW() << "Node '" << node->get_name() << "' is not an instance of ArithmeticReductionKeepDims."; - auto res = std::make_shared(attrs); - res->params = params; - res->params["keep_dims"] = reduce_node->get_keep_dims() ? "True" : "False"; - return res; - }); - - addSpecificCreator( - {"ReduceLogicalAnd"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "ReduceAnd", - details::convertPrecision(node->get_output_element_type(0))}; - auto reduce_node = std::dynamic_pointer_cast(node); - if (reduce_node == nullptr) - IE_THROW() << "Node '" << node->get_name() << "' is not an instance of LogicalReductionKeepDims."; - auto res = std::make_shared(attrs); - res->params = params; - res->params["keep_dims"] = reduce_node->get_keep_dims() ? "True" : "False"; - return res; - }); - - addSpecificCreator( - {"ReduceLogicalOr"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "ReduceOr", - details::convertPrecision(node->get_output_element_type(0))}; - auto reduce_node = std::dynamic_pointer_cast(node); - if (reduce_node == nullptr) - IE_THROW() << "Node '" << node->get_name() << "' is not an instance of LogicalReductionKeepDims."; - auto res = std::make_shared(attrs); - res->params = params; - res->params["keep_dims"] = reduce_node->get_keep_dims() ? "True" : "False"; - return res; - }); - - addSpecificCreator({"Constant"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Const", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - auto castedLayer = ngraph::as_type_ptr(node); - if (!res) - IE_THROW() << "Cannot get " << attrs.type << " layer " << attrs.name; - - res->blobs["custom"] = InferenceEngine::details::shareWeights(castedLayer); - - return res; - }); - - addSpecificCreator({"Convert"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Convert", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - - auto p = details::convertPrecision(node->get_output_element_type(0)); - std::string precision_str; - switch (p) { - case Precision::FP16: - precision_str = "FP16"; - break; - case Precision::BF16: - precision_str = "BF16"; - break; - case Precision::FP32: - precision_str = "FP32"; - break; - case Precision::FP64: - precision_str = "FP64"; - break; - case Precision::I8: - precision_str = "I8"; - break; - case Precision::I16: - precision_str = "I16"; - break; - case Precision::I32: - precision_str = "I32"; - break; - case Precision::I64: - precision_str = "I64"; - break; - case Precision::U8: - precision_str = "U8"; - break; - case Precision::U16: - precision_str = "U16"; - break; - case Precision::U32: - precision_str = "U32"; - break; - case Precision::U64: - precision_str = "U64"; - break; - case Precision::BOOL: - precision_str = "BOOL"; - break; - default: - IE_THROW() << "Unsupported type"; - } - - res->params["precision"] = precision_str; - return res; - }); - - addSpecificCreator({"MVN"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "MVN", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - - res->params["normalize_variance"] = params.at("normalize_variance"); - res->params["normalize_variance"] = res->getBoolStrParamAsIntStr("normalize_variance"); - res->params["eps"] = params.at("eps"); - const auto& acrossChannelsIt = params.find("across_channels"); - if (acrossChannelsIt != params.end()) { - res->params["across_channels"] = params.at("across_channels"); - res->params["across_channels"] = res->getBoolStrParamAsIntStr("across_channels"); - } - return res; - }); - - addSpecificCreator({"NormalizeIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Normalize", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - - res->params = params; - res->params["channel_shared"] = res->getBoolStrParamAsIntStr("channel_shared"); - res->params["across_spatial"] = res->getBoolStrParamAsIntStr("across_spatial"); - - const auto weightsNode = node->input_value(1).get_node_shared_ptr(); - if (auto castedLayer = ngraph::as_type_ptr(weightsNode)) { - res->blobs["weights"] = InferenceEngine::details::shareWeights(castedLayer); - } - return res; - }); - - addSpecificCreator({"Clamp"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Clamp", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"LRN_IE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Norm", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"Elu"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "elu", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"MatMul"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Gemm", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"GatherIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Gather", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - - auto castedLayer = std::dynamic_pointer_cast(node); - if (castedLayer == nullptr) - IE_THROW() << "Cannot get " << attrs.type << " layer " << attrs.name; - - res->params["axis"] = Builder::asString(castedLayer->get_axis()); - - return res; - }); - - addSpecificCreator({"GatherTreeIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "GatherTree", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - return res; - }); - - addSpecificCreator({"GRN"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "GRN", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"OneHotIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "OneHot", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"HardSigmoid_IE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "HardSigmoid", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - - auto castedLayer = std::dynamic_pointer_cast(node); - if (!castedLayer) - IE_THROW() << "Cannot get " << attrs.type << " layer " << attrs.name; - - res->params["alpha"] = Builder::asString(castedLayer->get_alpha()); - res->params["beta"] = Builder::asString(castedLayer->get_beta()); - return res; - }); - - addSpecificCreator({"Interp"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Interp", - details::convertPrecision(node->get_output_element_type(0))}; - auto castedLayer = std::dynamic_pointer_cast(node); - if (!castedLayer) - IE_THROW() << "Cannot get " << attrs.type << " layer " << attrs.name; - - auto interp_attrs = castedLayer->get_attrs(); - - if (interp_attrs.antialias) { - IE_THROW() << "Interp do not support antialias"; - } - if (interp_attrs.mode != "linear") { - IE_THROW() << "Interp do not support mode '" << interp_attrs.mode << "'"; - } - - auto res = std::make_shared(attrs); - res->params = params; - res->params["align_corners"] = interp_attrs.align_corners ? "1" : "0"; - return res; - }); - - addSpecificCreator({"PadIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Pad", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - - res->params["pad_mode"] = params.at("pad_mode"); - res->params["pads_begin"] = params.at("pads_begin"); - res->params["pads_end"] = params.at("pads_end"); - - if (params.at("pad_mode") == "constant") { - res->params["pad_value"] = params.at("pad_value"); - } - - return res; - }); - - addSpecificCreator({"Subtract"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Eltwise", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params["operation"] = "sub"; - return res; - }); - - addSpecificCreator({"FakeQuantize"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "FakeQuantize", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"ConvolutionIE", "GNAConvolution"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Convolution", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - - auto&& rt_info = node->get_rt_info(); - bool keep_constants = rt_info["keep_constants"].as(); - - // Restore output and kernel size - auto shape = node->get_input_shape(1); - // extract HW - if (node->description() == "GNAConvolution") { - // NHWC - shape.erase(shape.begin()); - shape.erase(shape.end() - 1); - res->params["output"] = Builder::asString(*(node->get_shape().rbegin())); - } else { - // NCHW - shape.erase(shape.begin(), shape.begin() + 2); - res->params["output"] = Builder::asString(node->get_shape()[1]); - } - - res->params["kernel"] = Builder::asString(static_cast&>(shape)); - - // forward auto_pad only when its value is different than explicit - if (params.at("auto_pad") == "explicit") { - res->params.erase("auto_pad"); - } - - const auto weightsNode = node->input_value(1).get_node_shared_ptr(); - if (!keep_constants && - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights)) { - if (node->inputs().size() == 3) { - const auto biasNode = node->input_value(2).get_node_shared_ptr(); - InferenceEngine::details::addBlob(biasNode, res, InferenceEngine::details::biases); - } - } - return res; - }); - - addSpecificCreator({"DeformableConvolution"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "DeformableConvolution", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - - res->params = params; - - auto shape = node->get_input_shape(2); - std::string value; - - res->params["output"] = Builder::asString(shape[0]); - - for (size_t i = 2; i < shape.size(); i++) { - if (!value.empty()) - value += ","; - value += Builder::asString(shape[i]); - } - res->params["kernel"] = value; - - if (res->params["auto_pad"] == "explicit") { - res->params.erase("auto_pad"); - } - - const auto weightsNode = node->input_value(2).get_node_shared_ptr(); - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights); - - return res; - }); - - addSpecificCreator({"DeformablePSROIPooling"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "PSROIPooling", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - res->params["no_trans"] = node->get_input_size() == 2 ? "1" : "0"; - // v1::DeformablePRSOIPooling treats group_size attribute as pooled sizes - res->params["pooled_height"] = params.at("group_size"); - res->params["pooled_width"] = params.at("group_size"); - return res; - }); - - addSpecificCreator({"CTCGreedyDecoder"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "CTCGreedyDecoder", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - res->params["ctc_merge_repeated"] = res->getBoolStrParamAsIntStr("ctc_merge_repeated"); - return res; - }); - - addSpecificCreator({"TensorIterator", "StaticShapeLoop"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - auto res = createSubGraphLayer(node); - res->type = "TensorIterator"; - return res; - }); - - addSpecificCreator({"Loop"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - auto res = createSubGraphLayer(node); - res->type = "Loop"; - return res; - }); - - addSpecificCreator({"SquaredDifference"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Eltwise", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params["operation"] = "squared_diff"; - return res; - }); - - addSpecificCreator({"RegionYolo"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "RegionYolo", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - res->params["do_softmax"] = res->getBoolStrParamAsIntStr("do_softmax"); - return res; - }); - - addSpecificCreator({"VariadicSplit"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Split", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - auto castedLayer = std::dynamic_pointer_cast(node); - if (!castedLayer) - IE_THROW() << "Cannot get " << attrs.type << " layer " << attrs.name; - - auto axis_node = castedLayer->input_value(1).get_node_shared_ptr(); - const auto axis_node_const = ngraph::as_type_ptr(axis_node); - if (!axis_node_const) { - IE_THROW() << "Split " << castedLayer->get_friendly_name() << " has no axes as Constant"; - } - - auto axis = axis_node_const->cast_vector()[0]; - if (axis < 0) { - axis += castedLayer->get_input_shape(0).size(); - } - - res->params["axis"] = Builder::asString(axis); - return res; - }); - - addSpecificCreator({"Interpolate"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Interpolate", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"CropIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Crop", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"ScaleShiftIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "ScaleShift", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - const auto weightsNode = node->input_value(1).get_node_shared_ptr(); - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights); - const auto biasNode = node->input_value(2).get_node_shared_ptr(); - InferenceEngine::details::addBlob(biasNode, res, InferenceEngine::details::biases); - return res; - }); - - addSpecificCreator({"ExecutionNode"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - auto& rtInfo = node->get_rt_info(); - - if (rtInfo.count(ExecGraphInfoSerialization::LAYER_TYPE) == 0) { - IE_THROW() << "No " << ExecGraphInfoSerialization::LAYER_TYPE << " attribute is set in " - << node->get_friendly_name() << " node"; - } - - LayerParams attrs = {node->get_friendly_name(), - rtInfo[ExecGraphInfoSerialization::LAYER_TYPE].as(), - details::convertPrecision(node->get_output_element_type(0))}; - rtInfo.erase(ExecGraphInfoSerialization::LAYER_TYPE); - - auto res = std::make_shared(attrs); - res->params = params; - - for (const auto& kvp : rtInfo) { - if (kvp.second.is()) - res->params[kvp.first] = kvp.second.as(); - } - - return res; - }); - - addSpecificCreator({"ResampleV2"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Resample", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - - res->params["antialias"] = res->getBoolStrParamAsIntStr("antialias"); - if (res->params["type"] == "nearest") { - res->params["type"] = "caffe.ResampleParameter.NEAREST"; - } else if (res->params["type"] == "cubic") { - res->params["type"] = "caffe.ResampleParameter.CUBIC"; - } else if (res->params["type"] == "area") { - res->params["type"] = "caffe.ResampleParameter.AREA"; - } else if (res->params["type"] == "linear") { - res->params["type"] = "caffe.ResampleParameter.LINEAR"; - } - return res; - }); - - addSpecificCreator({"FullyConnected"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "FullyConnected", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - - auto& rt_info = node->get_rt_info(); - bool keep_constants = rt_info["keep_constants"].as(); - const auto weightsNode = node->input_value(1).get_node_shared_ptr(); - if (!keep_constants && - InferenceEngine::details::addBlob(weightsNode, res, InferenceEngine::details::weights)) { - const auto biasNode = node->input_value(2).get_node_shared_ptr(); - InferenceEngine::details::addBlob(biasNode, res, InferenceEngine::details::biases); - } - return res; - }); - - addSpecificCreator({"ShuffleChannels"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "ShuffleChannels", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - res->params = params; - return res; - }); - - addSpecificCreator({"PowerIE"}, - [](const std::shared_ptr<::ngraph::Node>& node, - const std::map& params) -> CNNLayerPtr { - LayerParams attrs = {node->get_friendly_name(), - "Power", - details::convertPrecision(node->get_output_element_type(0))}; - auto res = std::make_shared(attrs); - - auto castedLayer = ngraph::as_type_ptr(node); - if (castedLayer == nullptr) - IE_THROW() << "Cannot get " << attrs.type << " layer " << attrs.name; - res->params = params; - // This is needed as scale parameter requires high precision - res->params["scale"] = Builder::asString(castedLayer->scale); - return res; - }); -} - -CNNLayerPtr CNNLayerCreator::create(const std::shared_ptr<::ngraph::Node>& origin) { - node = origin; // node used by node->visit_attributes(..) > AttributeVisitor::on_attribute(..) - - if (!node->visit_attributes(*this)) - return nullptr; - - LayerParams attrs = {node->get_friendly_name(), - node->description(), - details::convertPrecision(node->get_output_element_type(0))}; - - CNNLayerPtr res; - - auto creator = creators.find(node->description()); - - if (creator != creators.end()) - res = creator->second(node, params); - else { - res = std::make_shared(attrs); - res->params = params; - } - node = nullptr; - - return res; -} - -} // namespace - -namespace details { -void convertFunctionToICNNNetwork(const std::shared_ptr& graph, - const CNNNetwork& network, - CNNNetworkImpl* cnnNetworkImpl, - bool keep_constant_inputs) { - OV_ITT_SCOPED_TASK(itt::domains::IELegacy, "details::convertFunctionToICNNNetwork"); - - CNNLayerCreator visitor; - - const auto createCNNLayer = [&visitor](const std::shared_ptr<::ngraph::Node>& node) -> CNNLayerPtr { - class NGraphCNNLayer : public CNNLayer { - public: - void setNode(const std::shared_ptr<::ngraph::Node>& node) { - this->node = node; - } - }; - - CNNLayerPtr result = visitor.create(node); - - if (!result) - IE_THROW() << "Cannot cast ngraph node " << node->get_friendly_name() << " to CNNLayer!"; - NGraphCNNLayer* layer = reinterpret_cast(result.get()); - layer->setNode(node); - return result; - }; - - const auto isInternalConstLayer = [](const std::shared_ptr<::ngraph::op::Constant>& constLayer, - const std::shared_ptr<::ngraph::Node>& consumerLayer, - bool keep_constants) -> bool { - if (((::ngraph::as_type_ptr<::ngraph::op::ConvolutionIE>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::FullyConnected>(consumerLayer) || - ::ngraph::as_type_ptr(consumerLayer) || - ::ngraph::as_type_ptr(consumerLayer)) && - !keep_constants) || - ::ngraph::as_type_ptr<::ngraph::op::v1::BinaryConvolution>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::DeconvolutionIE>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::v1::DeformableConvolution>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::Elu>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::NormalizeIE>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::PRelu>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::v1::Split>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::VariadicSplit>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::ScaleShiftIE>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::Transpose>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::LSTMSequenceIE>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::RNNSequenceIE>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::GRUSequenceIE>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::RNNCellIE>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::GRUCellIE>(consumerLayer)) { - // Check that all input nodes except zero input are Constants for all ops except DeformableConvolutions - // for which the input with index 1 is also dynamic - size_t inputID = 1; - if (::ngraph::as_type_ptr<::ngraph::op::v1::DeformableConvolution>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::GRUCellIE>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::RNNCellIE>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::GRUSequenceIE>(consumerLayer) || - ::ngraph::as_type_ptr<::ngraph::op::RNNSequenceIE>(consumerLayer)) { - inputID = 2; - } else if (::ngraph::as_type_ptr<::ngraph::op::LSTMSequenceIE>(consumerLayer)) { - inputID = 3; - } - - for (; inputID < consumerLayer->inputs().size(); ++inputID) { - auto inputLayer = consumerLayer->input(inputID).get_source_output().get_node_shared_ptr(); - if (inputLayer == constLayer) { - return true; - } - } - } else if (::ngraph::as_type_ptr<::ngraph::op::LSTMCellIE>(consumerLayer)) { - for (size_t inputID = 3; inputID < consumerLayer->inputs().size(); ++inputID) { - auto inputLayer = consumerLayer->input(inputID).get_source_output().get_node_shared_ptr(); - if (inputLayer == constLayer) { - return true; - } - } - } - return false; - }; - - // Checks that node is internal layer for all layers from specific function - const auto isInternalLayer = [=](const std::shared_ptr<::ngraph::Node>& node, bool keep_constant) -> bool { - if (auto constantNode = ::ngraph::as_type_ptr<::ngraph::op::Constant>(node)) { - for (const auto& consumerInputPort : constantNode->output(0).get_target_inputs()) { - const auto& consumerLayer = consumerInputPort.get_node()->shared_from_this(); - if (!isInternalConstLayer(constantNode, consumerLayer, keep_constant)) - return false; - } - return true; - } - - return ::ngraph::as_type_ptr<::ngraph::op::Result>(node) != nullptr; - }; - - const auto keep_input_info = [](CNNNetworkImpl* network, const DataPtr& inData) { - InputInfo::Ptr info(new InputInfo()); - info->setInputData(inData); - network->setInputInfo(info); - }; - - // Check if some of function nodes has dynamic input or output shape - // we collect this nodes and then throw an exception with the list - // of dynamic nodes. - std::stringstream err_log; - for (const auto& node : graph->get_ordered_ops()) { - bool is_dynamic = false; - for (const auto& input : node->inputs()) { - if (input.get_partial_shape().is_dynamic()) { - is_dynamic = true; - break; - } - } - for (const auto& output : node->outputs()) { - if (output.get_partial_shape().is_dynamic()) { - is_dynamic = true; - break; - } - } - if (is_dynamic) - err_log << node << std::endl; - } - if (!err_log.str().empty()) { - IE_THROW() << "\nUnsupported dynamic ops: \n" << err_log.str(); - } - - IE_SUPPRESS_DEPRECATED_START - const auto& icnnnetwork = static_cast(network); - IE_SUPPRESS_DEPRECATED_END - const CNNNetworkNGraphImpl* nGraphImpl = dynamic_cast(&icnnnetwork); - - InputsDataMap thisInputDataMap = network.getInputsInfo(); - - // Construct network - cnnNetworkImpl->setName(graph->get_friendly_name()); - - const ngraph::NodeVector& nodes = graph->get_ops(); - bool keep_constants = keep_constant_inputs || ::ov::op::util::has_op_with_type<::ngraph::op::FakeQuantize>(graph); - - std::unordered_map> unique_names; - auto can_change_name = [](const std::shared_ptr& node) -> bool { - if (ngraph::as_type_ptr(node) || ngraph::as_type_ptr(node)) { - return false; - } - for (const auto& output : node->outputs()) { - for (const auto& consumer : output.get_target_inputs()) { - if (ngraph::is_type(consumer.get_node())) { - return false; - } - } - } - return true; - }; - - auto generate_unique_name = [&unique_names](std::string name) -> std::string { - size_t suffix = 1; - while (unique_names.count(name + "/" + std::to_string(suffix))) { - ++suffix; - } - return name + "/" + std::to_string(suffix); - }; - - // normalize nodes names to be unique - for (auto& node : nodes) { - // skip Result operations as they have the same friendly name as their parent - if (ngraph::is_type(node.get())) { - continue; - } - - auto& duplicate = unique_names[node->get_friendly_name()]; - if (!duplicate) { - duplicate = node; - continue; - } - - if (!can_change_name(duplicate) && !can_change_name(node)) { - IE_THROW() << "Detected two output operations with the same name: " << duplicate << " and " << node; - } - - auto& renamed = can_change_name(duplicate) ? duplicate : node; - renamed->set_friendly_name(generate_unique_name(renamed->get_friendly_name())); - - unique_names[duplicate->get_friendly_name()] = duplicate; - unique_names[node->get_friendly_name()] = node; - } - - // Create layers and output data - for (const auto& layer : nodes) { - if (isInternalLayer(layer, keep_constants)) - continue; - - // TODO: remove this rt info when all blobs will be inputs - auto& rt_info = layer->get_rt_info(); - rt_info["keep_constants"] = keep_constants; - - CNNLayerPtr cnnLayer = createCNNLayer(layer); - - // Set originalLayersNames from FusedNames - std::string originalNames = ov::getFusedNames(layer); - if (!originalNames.empty()) { - cnnLayer->params[ExecGraphInfoSerialization::ORIGINAL_NAMES] = originalNames; - } - - std::string primitivesPriority = ov::getPrimitivesPriority(layer); - if (!primitivesPriority.empty()) { - cnnLayer->params["PrimitivesPriority"] = primitivesPriority; - } - - // Copy runtime info attributes from Nodes to CNNLayers if they have std::string type - for (const auto& rt : rt_info) { - if (rt.second.is()) { - auto str_attr = rt.second.as(); - if (details::CaselessEq()(rt.first, "affinity")) { - cnnLayer->affinity = str_attr; - } else { - cnnLayer->params[rt.first] = str_attr; - } - } - } - - size_t inputCount(0); - for (size_t i = 0; i < layer->get_input_size(); i++) { - const auto& constant = - ngraph::as_type_ptr(layer->input(i).get_source_output().get_node_shared_ptr()); - if (constant && isInternalConstLayer(constant, layer, keep_constants)) { - continue; - } - inputCount++; - } - - if (cnnLayer->type == "Memory" && cnnLayer->params["index"] == "1") { - inputCount = 0; - } - - cnnLayer->insData.resize(inputCount); - - for (size_t i = 0; i < layer->get_output_size(); i++) { - // Memory node with index = 1 has no inputs according to the specification. - // For proper conversion, we must cut off all the layers and data nodes above ReadValue, - // if they are connected only with this layer. - // Now MO generates only constants or constant sub-graphs as input to ReadValue op. - if (std::dynamic_pointer_cast<::ngraph::op::Constant>(layer)) { - bool all_to_read_value = !layer->output(i).get_target_inputs().empty(); - for (const auto& output_input : layer->output(i).get_target_inputs()) { - all_to_read_value &= dynamic_cast(output_input.get_node()) != nullptr; - } - if (all_to_read_value) - continue; - } - - if (cnnLayer->type == "Memory" && cnnLayer->params["index"] == "0") { - cnnLayer->outData.clear(); - continue; - } - - auto outName = ov::op::util::get_ie_output_name(layer->output(i)); - - DataPtr& ptr = cnnNetworkImpl->getData(outName.c_str()); - IE_ASSERT(layer->get_output_partial_shape(i).is_static()) - << " nGraph " << layer->description() << " operation with name: " << layer->get_friendly_name() - << " cannot be converted to " << cnnLayer->type << " layer with name: " << cnnLayer->name - << " because output with index " << i - << " contains dynamic shapes: " << layer->get_output_partial_shape(i) - << ". Try to use CNNNetwork::reshape() method in order to specialize shapes " - << "before the conversion."; - SizeVector dims = layer->get_output_shape(i); - for (const auto& dim : dims) { - if (!dim) - IE_THROW() << cnnLayer->type << " layer " << cnnLayer->name - << " has incorrect dimensions in the output data " << i; - } - if (!ptr && nGraphImpl && nGraphImpl->_data.find(outName) != nGraphImpl->_data.end()) { - ptr = nGraphImpl->_data.at(outName); - { - const auto layout = dims.size() == ptr->getTensorDesc().getDims().size() - ? ptr->getTensorDesc().getLayout() - : TensorDesc::getLayoutByDims(dims); - - ptr->reshape(dims, layout); - } - cnnNetworkImpl->addData(outName.c_str(), ptr); - } - - if (!ptr) { - ptr.reset(new Data(outName, - {details::convertPrecision(layer->get_output_element_type(i)), - dims, - TensorDesc::getLayoutByDims(dims)})); - } - - getCreatorLayer(ptr) = cnnLayer; - cnnLayer->outData.push_back(ptr); - if (std::dynamic_pointer_cast<::ngraph::op::Parameter>(layer)) { - keep_input_info(cnnNetworkImpl, ptr); - } - } - cnnNetworkImpl->addLayer(cnnLayer); - } - - // Set input data - for (const auto& layer : graph->get_ordered_ops()) { - if (std::dynamic_pointer_cast<::ngraph::op::ReadValueBase>(layer)) - continue; - if (std::dynamic_pointer_cast<::ngraph::op::Result>(layer)) { - IE_ASSERT(layer->get_input_size() == 1); - const auto& input = layer->input_value(0); - cnnNetworkImpl->addOutput(ov::op::util::get_ie_output_name(input)); - continue; - } - - uint64_t count_of_skipped = 0; - for (size_t i = 0; i < layer->get_input_size(); i++) { - const auto& output_port = layer->input_value(i); - const auto& input = output_port.get_node_shared_ptr(); - - if (auto const_node = std::dynamic_pointer_cast<::ngraph::op::Constant>(input)) { - if (isInternalConstLayer(const_node, layer, keep_constants)) { - count_of_skipped++; - continue; - } - } - - CNNLayerPtr prevCnnLayer; - StatusCode ret = cnnNetworkImpl->getLayerByName(input->get_friendly_name().c_str(), prevCnnLayer, nullptr); - if (ret != OK) - IE_THROW() << "Cannot find layer with name: " << input->get_friendly_name(); - - CNNLayerPtr cnnLayer; - ret = cnnNetworkImpl->getLayerByName(layer->get_friendly_name().c_str(), cnnLayer, nullptr); - if (ret != OK) - IE_THROW() << "Cannot find layer with name: " << layer->get_friendly_name(); - - auto inIndex = layer->input(i).get_index(); - if (cnnLayer->insData.size() <= (inIndex - count_of_skipped) || - prevCnnLayer->outData.size() <= output_port.get_index() || count_of_skipped > inIndex) - IE_THROW() << "Cannot create CNNNetwork. Network structure is incorrect! " - << "Input port " << inIndex << " (max " << cnnLayer->insData.size() << ") of " - << cnnLayer->type << " layer " << cnnLayer->name << " cannot be connected with output port " - << output_port.get_index() << " (max " << prevCnnLayer->outData.size() << ") of " - << prevCnnLayer->type << " layer " << prevCnnLayer->name; - cnnLayer->insData[inIndex - count_of_skipped] = prevCnnLayer->outData[output_port.get_index()]; - getInputTo(prevCnnLayer->outData[output_port.get_index()])[cnnLayer->name] = cnnLayer; - } - } - - // check all input ports are occupied - for (const auto& kvp : cnnNetworkImpl->allLayers()) { - const CNNLayer::Ptr& layer = kvp.second; - size_t inSize = layer->insData.size(); - - for (unsigned i = 0; i < inSize; i++) { - if (!layer->insData[i].lock()) { - IE_THROW() << "Layer " << layer->name.c_str() << " input port " << i << " is not connected to any data"; - } - } - - // execution ngraph is fake graph and should not be validated - if (layer->params.count(ExecGraphInfoSerialization::PERF_COUNTER) == 0) { - layer->parseParams(); - } - } - - // update input preprocessing info - InputsDataMap resultInputDataMap; - cnnNetworkImpl->getInputsInfo(resultInputDataMap); - IE_ASSERT(resultInputDataMap.size() == thisInputDataMap.size()); - auto params = graph->get_parameters(); - for (const auto& param : params) { - const std::string input_name = param->get_friendly_name(); - auto thisInputDataItr = thisInputDataMap.find(input_name); - IE_ASSERT(thisInputDataItr != thisInputDataMap.end()) - << "Internal issue with model handling. Improper input name: " << input_name; - resultInputDataMap[input_name]->setPrecision(thisInputDataItr->second->getPrecision()); - resultInputDataMap[input_name]->setLayout(thisInputDataItr->second->getLayout()); - resultInputDataMap[input_name]->getPreProcess() = thisInputDataItr->second->getPreProcess(); - } -} - -std::shared_ptr convertFunctionToICNNNetwork(const std::shared_ptr& graph, - const CNNNetwork& network, - bool keep_constant_inputs) { - auto cnnNetworkImpl = std::make_shared(); - convertFunctionToICNNNetwork(graph, network, cnnNetworkImpl.get(), keep_constant_inputs); - return cnnNetworkImpl; -} - -} // namespace details -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/graph_tools.cpp b/src/plugins/intel_gna/legacy/src/graph_tools.cpp deleted file mode 100644 index 3b27fb3d043..00000000000 --- a/src/plugins/intel_gna/legacy/src/graph_tools.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/graph_tools.hpp" - -#include -#include -#include - -#include "legacy/details/ie_cnn_network_tools.h" - -using namespace std; - -namespace InferenceEngine { -namespace details { - -std::vector CNNNetSortTopologically(const CNNNetwork& network) { - std::vector stackOfVisited; - bool res = CNNNetForestDFS( - CNNNetGetAllInputLayers(network), - [&](CNNLayerPtr current) { - stackOfVisited.push_back(current); - }, - false); - - if (!res) { - IE_THROW() << "Sorting not possible, due to existed loop."; - } - - std::reverse(std::begin(stackOfVisited), std::end(stackOfVisited)); - - return stackOfVisited; -} - -} // namespace details - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/graph_transformer.cpp b/src/plugins/intel_gna/legacy/src/graph_transformer.cpp deleted file mode 100644 index c3047bd3ac7..00000000000 --- a/src/plugins/intel_gna/legacy/src/graph_transformer.cpp +++ /dev/null @@ -1,529 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/graph_transformer.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "blob_factory.hpp" -#include "legacy/graph_tools.hpp" -#include "legacy/net_pass.h" - -using namespace InferenceEngine; -using namespace InferenceEngine::details; - -namespace InferenceEngine { - -inline bool isForLayers(const CNNLayer& layer, const std::vector& types) { - for (const DataPtr& data : layer.outData) { - for (const auto& it : getInputTo(data)) { - const CNNLayerPtr childLayer = it.second; - for (const auto& type : types) { - if (childLayer->type.compare(type) == 0) { - return true; - } - } - } - } - - return false; -} - -static std::vector get_inputs(details::CNNNetworkImpl* _network) { - if (!_network) - return {}; - - InputsDataMap ins_info; - _network->getInputsInfo(ins_info); - - std::vector inputs; - for (const auto& kvp : ins_info) - inputs.push_back(kvp.second->getInputData()); - return inputs; -} - -static std::vector get_outputs(details::CNNNetworkImpl* _network) { - if (!_network) - return {}; - - std::map outs_info; - _network->getOutputsInfo(outs_info); - - std::vector outputs; - for (const auto& kvp : outs_info) - outputs.push_back(kvp.second); - return outputs; -} - -ConstTransformer::ConstTransformer(details::CNNNetworkImpl* _network) - : network(_network), - inputs(get_inputs(_network)), - outputs(get_outputs(_network)) { - if (!_network) - IE_THROW() << "[ERROR]: Failed to init ConstTransformer with null pointer of network"; -} - -ConstTransformer::ConstTransformer(std::vector& _inputs, std::vector& _outputs) - : network(nullptr), - inputs(_inputs), - outputs(_outputs) { - if (inputs.empty() || outputs.empty()) - IE_THROW() << "[ERROR]: Failed to init ConstTransformer with empty list of inputs or outputs"; -} - -std::vector ConstTransformer::foldConstSubgraphsInternal(const std::map& constLayers, - const BlobMap& constData, - const std::vector& sortedLayers) { - std::vector remainingConstLayers; - for (const auto& layer : sortedLayers) { - if (constLayers.find(layer->name) != constLayers.end()) { - // const layer doesn't need parent connections -> erase them - for (const auto& insData : layer->insData) { - auto& inputTo = getInputTo(insData.lock()); - inputTo.erase(layer->name); - // Note: to resolve corner case above layers can be marked as const with const data, just to be removed - // properly.. and maybe this logic wouldn't be needed - if (inputTo.empty()) { - auto creator = getCreatorLayer(insData.lock()).lock(); - auto it = std::find(creator->outData.begin(), creator->outData.end(), insData.lock()); - if (it != creator->outData.end()) { - data_to_remove.push_back(*it); - creator->outData.erase(it); - } - } - } - layer->insData.clear(); - - if (constLayers.at(layer->name) || isForLayers(*layer, {"Pwl"})) { - for (const auto& outData : layer->outData) { - for (const auto& inputTo : getInputTo(outData)) { - CNNLayerPtr inputToLayer; - std::string inputToName; - std::tie(inputToName, inputToLayer) = inputTo; - auto& insData = inputToLayer->insData; - auto insDataIt = - std::find_if(insData.begin(), insData.end(), [&outData](const DataWeakPtr& current) { - return current.lock()->getName() == outData->getName(); - }); - // remove connection with const data, because for const child it's not needed, for dynamic - new - // one will be created - if (insDataIt != insData.end()) { - insDataIt = inputToLayer->insData.erase(insDataIt); - } - } - data_to_remove.push_back(outData); - } - layer_to_remove.push_back(layer); - } else { - // if only one output data is not const - do nothing, otherwise - run procedure below - // note: multiple const output data requires multiple layers with blob["custom"] to keep const data - bool keepConstData = layer->outData.size() == 1; - if (keepConstData) { - auto outData = layer->outData[0]; - for (const auto& inputTo : getInputTo(outData)) { - if (constLayers.find(inputTo.first) != constLayers.end()) { - keepConstData = false; - } - } - } - if (keepConstData) { - if (!constLayers.at(layer->name)) { - auto outData = layer->outData[0]; - if (layer->blobs.find("custom") == layer->blobs.end()) { - // if there's no const data - set it - const auto it = constData.find(outData->getName()); - if (it != constData.end()) { - layer->blobs["custom"] = it->second; - } - } - if (layer->type != "Const") { - // layer was calculated during the Const Propagation, need to hide its semantic (type, - // params) - LayerParams layerParams{layer->name + "__" + outData->getName() + "__Const", - "Const", - layer->precision}; - auto newLayer = std::make_shared(layerParams); - for (const auto& data : layer->outData) { - getCreatorLayer(data) = newLayer; - } - newLayer->outData = layer->outData; - newLayer->blobs["custom"] = layer->blobs["custom"]; - layer_to_remove.push_back(layer); - layer_to_add.push_back(newLayer); - remainingConstLayers.push_back(newLayer); - } else { - // Layer with `Const` type should be also considered on trimming shape inputs - remainingConstLayers.push_back(layer); - } - } - } else { - for (const auto& outData : layer->outData) { - for (const auto& inputTo : getInputTo(outData)) { - CNNLayerPtr inputToLayer; - std::string inputToName; - std::tie(inputToName, inputToLayer) = inputTo; - auto& insData = inputToLayer->insData; - auto insDataIt = - std::find_if(insData.begin(), insData.end(), [&outData](const DataWeakPtr& current) { - return current.lock()->getName() == outData->getName(); - }); - // remove connection with const data, because for const child it's not needed, for dynamic - - // new one will be created - if (insDataIt != insData.end()) { - insDataIt = inputToLayer->insData.erase(insDataIt); - } - if (constLayers.find(inputToName) == constLayers.end()) { - // next layer is not const, need to attach const data to it via blobs["custom"] of new - // Const layer - LayerParams layerParams{layer->name + "__" + outData->getName() + "__Const", - "Const", - layer->precision}; - auto newLayer = std::make_shared(layerParams); - remainingConstLayers.push_back(newLayer); - const auto it = constData.find(outData->getName()); - if (it != constData.end()) { - newLayer->blobs["custom"] = it->second; - } - auto newData = std::make_shared(outData->getName() + "__" + inputToName, - outData->getTensorDesc()); - getCreatorLayer(newData) = newLayer; - getInputTo(newData)[inputToName] = inputToLayer; - newLayer->outData = {newData}; - layer_to_add.push_back(newLayer); - data_to_add.push_back(newData); - inputToLayer->insData.insert(insDataIt, newData); - } - } - } - for (const auto& data : layer->outData) { - data_to_remove.push_back(data); - } - layer_to_remove.push_back(layer); - } - } - } - if (NetPass::HasInternalSubnet(layer)) { - auto subgraph = NetPass::GetInternalSubnet(layer); - ConstTransformer transformer(subgraph.inputs, subgraph.outputs); - transformer.foldConstSubgraphs(); - } - } - return remainingConstLayers; -} - -static std::vector skipConstInfer = { - "FakeQuantize", - "Quantize", - "CumSum", // Const inference function for CumSum is not implemented - "Convolution", // Const inference function for Convolution is not implemented - "Eltwise", // Const inference function for Eltwise is not implemented - "Copy", - "FullyConnected", - "Squeeze", - "Split", - "TensorIterator", - "LSTMSequence", - "Range", - "MVN"}; - -const std::map ConstTransformer::getConstLayers(const std::vector& sortedLayers) { - std::map mapConstLayers; - // collect all const layers, which inputs are const layers. - for (const auto& layer : sortedLayers) { - // Layers with "Shape" and "Const" type are Const by definition - if (layer->type == "Shape" || layer->type == "Const") { - mapConstLayers[layer->name] = false; - } else if (std::find(skipConstInfer.begin(), skipConstInfer.end(), layer->type) == skipConstInfer.end() && - !isForLayers(*layer, {"FakeQuantize", "Quantize"})) { - bool isAllInputsConst = true; - for (auto const& data : layer->insData) { - auto creator = getCreatorLayer(data.lock()).lock(); - if (creator != nullptr) { - if (mapConstLayers.find(creator->name) == mapConstLayers.end()) { - isAllInputsConst = false; - } - } else { - // Empty creator means that it's a network representation via inputs/outs data collection - // And it's a first layer in network. - isAllInputsConst = false; - } - } - if (isAllInputsConst && !layer->insData.empty()) - mapConstLayers[layer->name] = false; - } - } - // Add mark for const layers, if it's used for shape taking layers as second input - // true - is used and can be deleted from graph, as no influence on data, false - opposite - std::map mapVisitedLayers = mapConstLayers; - for (auto rit = sortedLayers.rbegin(); rit != sortedLayers.rend(); rit++) { - auto currentLayer = (*rit); - std::string currentLayerName = currentLayer->name; - bool isCurrentConst = mapConstLayers.find(currentLayerName) != mapConstLayers.end(); - for (size_t i = 0; i < currentLayer->insData.size(); i++) { - std::string creatorName; - if (currentLayer->insData[i].lock() != nullptr) { - auto creator = getCreatorLayer(currentLayer->insData[i].lock()).lock(); - if (creator) { - creatorName = creator->name; - } - } - bool isCreatorConst = mapConstLayers.find(creatorName) != mapConstLayers.end(); - if (isCreatorConst) { - // mark second const input of shape taking layers (Reshape, Interp..), if they wasn't visited before - if ((i == 1) && (shapeTaking.find(currentLayer->type)) != shapeTaking.end()) { - if (!mapConstLayers[creatorName]) { - if (!mapVisitedLayers.at(creatorName)) { - mapConstLayers[creatorName] = true; - } - } - } else { - if (isCurrentConst) { - if (mapConstLayers.at(currentLayerName)) { - if (!mapConstLayers[creatorName]) { - if (!mapVisitedLayers.at(creatorName)) { - mapConstLayers[creatorName] = true; - } - } - } else { - mapConstLayers[creatorName] = false; - } - } else { - mapConstLayers[creatorName] = false; - } - } - } - mapVisitedLayers[creatorName] = true; - } - mapVisitedLayers[currentLayerName] = true; - } - return mapConstLayers; -} - -const BlobMap ConstTransformer::getConstData(const std::map& constLayers, - const std::vector& sortedLayers) { - BlobMap constData; - - for (const auto& layer : sortedLayers) { - if (constLayers.find(layer->name) != constLayers.end()) { - std::string layerName = layer->name; - bool isForShape = constLayers.at(layerName); - - if (!isForShape && layer->type != "Const") - IE_THROW() << "Failed to find reference implementation for `" + layer->name + "` Layer with `" + - layer->type + "` Type on constant propagation"; - if (!isForShape) { - auto& blobs = layer->blobs; - auto it = blobs.find("custom"); - if (it == blobs.end()) - IE_THROW() << "Missed `custom` blob in Const layer"; - - auto dataName = layer->outData[0]->getName(); - constData[dataName] = (*it).second; - } - } - } - return constData; -} - -/** - * Will replace provided layer with reshape with corresponding shape from output data - * - * @param layer is operation to replace with static reshape - * @return newly created reshape static layer - */ -static CNNLayerPtr replace_with_static_reshape(CNNLayerPtr& layer) { - IE_ASSERT(layer->insData.size() == 1); - IE_ASSERT(layer->outData.size() == 1); - - auto in_data = layer->insData[0].lock(); - if (in_data == nullptr) - IE_THROW() << "Layer '" << layer->name << "' has invalid input data"; - auto out_data = layer->outData[0]; - - auto precision = out_data->getPrecision(); - auto shape = out_data->getDims(); - - // TODO: Have to use old name instead a new one because tensor statistic is mapped - // to layers by name. The old int8 pipeline may be broken because of lose - // tensor statistic for particular reshape. - auto reshape = std::make_shared(LayerParams{layer->name, "Reshape", precision}); - - reshape->shape.resize(shape.size()); - for (size_t p = 0; p < shape.size(); ++p) - reshape->shape[p] = static_cast(shape[p]); - - // replacement - auto& input_to_map = getInputTo(in_data); - - // try to find by name - auto found_by_name = input_to_map.find(layer->name); - if (found_by_name != input_to_map.end()) { - input_to_map.erase(found_by_name); - } else { - // try to find by ptr - auto found_by_ptr = std::find_if(input_to_map.begin(), - input_to_map.end(), - [&layer](const std::pair& p) { - return p.second == layer; - }); - if (found_by_ptr != input_to_map.end()) - input_to_map.erase(found_by_ptr); - } - input_to_map[reshape->name] = reshape; - - reshape->insData = {in_data}; - reshape->outData = {out_data}; - getCreatorLayer(out_data) = reshape; - - return reshape; -} - -void ConstTransformer::trimShapeInputs(const std::vector& constLayers, - std::vector& allLayers) { - for (const auto& layer : constLayers) { - if (layer->outData.size() == 1 && layer->type == "Const" && layer->insData.empty()) { - auto constData = layer->outData[0]; - std::map inputToMap = getInputTo(constData); - for (const auto& inputTo : inputToMap) { - CNNLayerPtr inputToLayer = inputTo.second; - if (shapeTaking.find(inputToLayer->type) != shapeTaking.end()) { - auto& insData = inputToLayer->insData; - auto it = std::find_if(insData.begin(), insData.end(), [&constData](const DataWeakPtr& current) { - return current.lock()->getName() == constData->getName(); - }); - if (it != insData.end() && std::distance(insData.begin(), it) == 1) { - inputToLayer->insData.erase(it); - getInputTo(constData).erase(inputTo.first); - } - } - } - if (getInputTo(constData).empty()) { - layer_to_remove.push_back(layer); - data_to_remove.push_back(constData); - } - } - } - // TODO: Some WA. Previous step foldConstSubgraphsInternal remove all const data - // from graph. Although that is responsibility of trimShapeInputs pass. - // That's why we need make additional pass through allLayers and replace - // all shape taken layers like Squeeze/Flatten with Reshape with single input. - for (auto& layer : allLayers) { - // Layer is from list of reshape-like layers - if (layer->type != "Reshape" && layer->type != "Unsqueeze" && layer->type != "Squeeze" && - layer->type != "Flatten") - continue; - - // already removed - if (std::find(layer_to_remove.begin(), layer_to_remove.end(), layer) != layer_to_remove.end()) - continue; - - // The second input was not removed. So shape is not constant. - if (layer->insData.size() != 1) - continue; - - auto new_one = replace_with_static_reshape(layer); - layer_to_remove.push_back(layer); - layer_to_add.push_back(new_one); - } -} - -void ConstTransformer::cleanup() { - if (network) { - for (const auto& layer : layer_to_remove) - network->removeLayer(layer->name); - for (const auto& data : data_to_remove) - network->removeData(data->getName()); - - for (const auto& layer : layer_to_add) - network->addLayer(layer); - for (const auto& data : data_to_add) - network->addData(data->getName().c_str(), data); - } else { - // Subgraph case - auto& const_holder = inputs.back(); - if (const_holder->getPrecision() == Precision::UNSPECIFIED) { - auto& holder_map = getInputTo(const_holder); - // Remove from const holder data object - for (const auto& layer : layer_to_remove) { - auto self_found = std::find_if(holder_map.begin(), - holder_map.end(), - [&layer](const std::pair kvp) { - return kvp.second == layer; - }); - - if (self_found != holder_map.end()) { - holder_map.erase(self_found); - } - } - // Add to const holder - for (const auto& layer : layer_to_add) { - holder_map[layer->name] = layer; - } - } - } -} - -void ConstTransformer::foldConstSubgraphs() { - auto sortedLayers = details::CNNSubnetSortTopologically({inputs, outputs}); - auto constLayers = getConstLayers(sortedLayers); - auto constData = getConstData(constLayers, sortedLayers); - foldConstSubgraphsInternal(constLayers, constData, sortedLayers); - - cleanup(); -} - -void ConstTransformer::fullTrim() { - // Avoid data races on one network instance - static std::mutex lockFullTrim; - std::lock_guard lock(lockFullTrim); - auto sortedLayers = details::CNNSubnetSortTopologically({inputs, outputs}); - auto constMapLayers = getConstLayers(sortedLayers); - - for (const auto& layer : sortedLayers) { - [&] { - if (layer->type == "Const") { - for (const auto& out : outputs) { - for (const auto& out_const : layer->outData) { - if (out_const == out) { - constMapLayers.erase(layer->name); - return; - } - } - } - } - }(); - } - - auto constData = getConstData(constMapLayers, sortedLayers); - auto constLayers = foldConstSubgraphsInternal(constMapLayers, constData, sortedLayers); - trimShapeInputs(constLayers, sortedLayers); - - for (auto& layer : sortedLayers) { - if (NetPass::HasInternalSubnet(layer)) { - auto subgraph = NetPass::GetInternalSubnet(layer); - - ConstTransformer transformer(subgraph.inputs, subgraph.outputs); - auto ti_sortedLayers = details::CNNSubnetSortTopologically({subgraph.inputs, subgraph.outputs}); - auto ti_constMapLayers = transformer.getConstLayers(ti_sortedLayers); - auto ti_constData = transformer.getConstData(ti_constMapLayers, ti_sortedLayers); - auto ti_constLayers = - transformer.foldConstSubgraphsInternal(ti_constMapLayers, ti_constData, ti_sortedLayers); - transformer.trimShapeInputs(ti_constLayers, ti_sortedLayers); - transformer.cleanup(); - } - } - - cleanup(); -} -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/ie_layer_validators.cpp b/src/plugins/intel_gna/legacy/src/ie_layer_validators.cpp deleted file mode 100644 index bf13bd2824a..00000000000 --- a/src/plugins/intel_gna/legacy/src/ie_layer_validators.cpp +++ /dev/null @@ -1,1267 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ie_layer_validators.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "debug.h" - -namespace InferenceEngine { - -using namespace details_legacy; -using std::map; -using std::string; -using std::vector; - -template -inline bool one_of(T val, P item) { - return val == item; -} -template -inline bool one_of(T val, P item, Args... item_others) { - return val == item || one_of(val, item_others...); -} - -void CNNLayer::parseParams() { - try { - LayerValidator::Ptr validator = LayerValidators::getInstance()->getValidator(type); - validator->parseParams(this); - } catch (const Exception& ie_e) { - IE_THROW() << "Error of validate layer: " << this->name << " with type: " << this->type << ". " << ie_e.what(); - } -} - -LayerValidators* LayerValidators::getInstance() { - static LayerValidators instance; - return &instance; -} - -LayerValidator::Ptr LayerValidators::getValidator(const std::string& type) { - if (_validators.find(type) == _validators.end()) { - return std::make_shared(type); - } - return _validators[type]; -} - -GeneralValidator::GeneralValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void FullyConnectedValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of FullyConnectedLayer class"; - } - casted->_out_num = casted->GetParamAsUInt("out-size"); -} - -FullyConnectedValidator::FullyConnectedValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void CropValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of CropLayer class"; - } - if (casted->axis.empty()) { - auto getArray = [](std::string param, vector& array) { - std::istringstream stream(param); - std::string str; - while (getline(stream, str, ',')) { - int val = std::stoi(str); - array.push_back(val); - } - }; - getArray(layer->GetParamAsString("axis"), casted->axis); - if (casted->params.find("offset") != casted->params.end()) { - getArray(layer->GetParamAsString("offset"), casted->offset); - } - if (casted->params.find("dim") != casted->params.end()) { - getArray(layer->GetParamAsString("dim"), casted->dim); - } - if (casted->params.find("crop_begin") != casted->params.end()) { - getArray(layer->GetParamAsString("crop_begin"), casted->offset); - } - } -} - -CropValidator::CropValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -ConvolutionValidator::ConvolutionValidator(const std::string& _type) : LayerValidator(_type) {} - -void ConvolutionValidator::parseParams(CNNLayer* layer) { - auto convLayer = dynamic_cast(layer); - if (!convLayer) { - IE_THROW() << "Layer is not instance of ConvolutionLayer class"; - } - convLayer->_out_depth = convLayer->GetParamAsUInt("output"); - - convLayer->_kernel.clear(); - convLayer->_stride.clear(); - convLayer->_padding.clear(); - convLayer->_pads_end.clear(); - convLayer->_dilation.clear(); - - vector kernels = convLayer->GetParamAsUInts("kernel", {}); - if (kernels.empty()) { - // IR_v == 2 - convLayer->_kernel.insert(X_AXIS, convLayer->GetParamAsUInt("kernel-x")); - convLayer->_kernel.insert(Y_AXIS, convLayer->GetParamAsUInt("kernel-y")); - - convLayer->_stride.insert(X_AXIS, convLayer->GetParamAsUInt("stride-x", 1u)); - convLayer->_stride.insert(Y_AXIS, convLayer->GetParamAsUInt("stride-y", 1u)); - // TODO: maybe just throw exception, why do we change IR? - if (0 == convLayer->_stride[X_AXIS]) { - convLayer->_stride[X_AXIS] = 1u; - } - if (0 == convLayer->_stride[Y_AXIS]) { - convLayer->_stride[Y_AXIS] = 1u; - } - - convLayer->_padding.insert(X_AXIS, convLayer->GetParamAsUInt("pad-x", 0u)); - convLayer->_padding.insert(Y_AXIS, convLayer->GetParamAsUInt("pad-y", 0u)); - - convLayer->_pads_end.insert(X_AXIS, convLayer->GetParamAsUInt("pad-r", convLayer->_padding[X_AXIS])); - convLayer->_pads_end.insert(Y_AXIS, convLayer->GetParamAsUInt("pad-b", convLayer->_padding[Y_AXIS])); - - convLayer->_dilation.insert(X_AXIS, convLayer->GetParamAsUInt("dilation-x", 1u)); - convLayer->_dilation.insert(Y_AXIS, convLayer->GetParamAsUInt("dilation-y", 1u)); - } else { - // IR_v > 2 - for (size_t i = 1; i <= kernels.size(); i++) { - convLayer->_kernel.insert(i - 1, kernels[kernels.size() - i]); - } - - vector default_0 = vector(convLayer->_kernel.size(), 0u); - vector default_1 = vector(convLayer->_kernel.size(), 1u); - - vector strides = convLayer->GetParamAsUInts("strides", default_1); - for (size_t i = 1; i <= strides.size(); i++) { - if (strides[strides.size() - i] == 0) { - IE_THROW() << "Stride could not be 0.\nIn layer " << convLayer->name; - } - convLayer->_stride.insert(i - 1, strides[strides.size() - i]); - } - - vector pads_begin = convLayer->GetParamAsUInts("pads_begin", default_0); - for (size_t i = 1; i <= pads_begin.size(); i++) { - convLayer->_padding.insert(i - 1, pads_begin[pads_begin.size() - i]); - } - - vector pads_end = convLayer->GetParamAsUInts("pads_end", pads_begin); - for (size_t i = 1; i <= pads_end.size(); i++) { - convLayer->_pads_end.insert(i - 1, pads_end[pads_end.size() - i]); - } - - vector dilations = convLayer->GetParamAsUInts("dilations", default_1); - for (size_t i = 1; i <= dilations.size(); i++) { - convLayer->_dilation.insert(i - 1, dilations[dilations.size() - i]); - } - } - - convLayer->_auto_pad = convLayer->GetParamAsString("auto_pad", ""); - convLayer->_group = convLayer->GetParamAsUInt("group", 1u); -} - -// - -void DeconvolutionValidator::parseParams(CNNLayer* layer) { - auto deconvLayer = dynamic_cast(layer); - if (!deconvLayer) { - IE_THROW() << "Layer is not instance of DeconvolutionLayer class"; - } - ConvolutionValidator::parseParams(layer); -} - -DeconvolutionValidator::DeconvolutionValidator(const std::string& _type) : ConvolutionValidator(_type) {} - -// - -DeformableConvolutionValidator::DeformableConvolutionValidator(const std::string& _type) - : ConvolutionValidator(_type) {} - -void DeformableConvolutionValidator::parseParams(CNNLayer* layer) { - auto deformable_conv_layer = dynamic_cast(layer); - if (!deformable_conv_layer) { - IE_THROW() << "Layer is not instance of DeformableConvolutionLayer class"; - } - deformable_conv_layer->_deformable_group = deformable_conv_layer->GetParamAsUInt("deformable_group", 1u); - ConvolutionValidator::parseParams(layer); -} - -// - -PoolingValidator::PoolingValidator(const std::string& _type) : LayerValidator(_type) {} - -void PoolingValidator::parseParams(CNNLayer* layer) { - auto poolLayer = dynamic_cast(layer); - if (!poolLayer) { - IE_THROW() << "Layer is not instance of PoolingLayer class"; - } - - poolLayer->_kernel.clear(); - poolLayer->_stride.clear(); - poolLayer->_padding.clear(); - poolLayer->_pads_end.clear(); - - poolLayer->_auto_pad = poolLayer->GetParamAsString("auto_pad", ""); - - vector kernels = poolLayer->GetParamAsUInts("kernel", {}); - if (kernels.empty()) { - int kernel_x = poolLayer->GetParamAsInt("kernel-x", -1); - /** Pooling as custom layer */ - if (kernel_x == -1) { - try { - unsigned int kernel_size = poolLayer->GetParamAsUInt("kernel_size"); - unsigned int kernel_w = poolLayer->GetParamAsUInt("kernel_w", 0u); - unsigned int kernel_h = poolLayer->GetParamAsUInt("kernel_h", 0u); - poolLayer->_kernel.insert(X_AXIS, kernel_w == 0u ? kernel_size : kernel_w); - poolLayer->_kernel.insert(Y_AXIS, kernel_h == 0u ? kernel_size : kernel_h); - - unsigned int stride = poolLayer->GetParamAsUInt("stride", 1u); - unsigned int stride_w = poolLayer->GetParamAsUInt("stride_w", 0u); - unsigned int stride_h = poolLayer->GetParamAsUInt("stride_h", 0u); - poolLayer->_stride.insert(X_AXIS, stride_w == 0u ? stride : stride_w); - poolLayer->_stride.insert(Y_AXIS, stride_h == 0u ? stride : stride_h); - - unsigned int pad = poolLayer->GetParamAsUInt("pad", 0u); - unsigned int pad_w = poolLayer->GetParamAsUInt("pad_w", 0u); - unsigned int pad_h = poolLayer->GetParamAsUInt("pad_h", 0u); - - poolLayer->_padding.insert(X_AXIS, pad_w == 0u ? pad : pad_w); - poolLayer->_padding.insert(Y_AXIS, pad_h == 0u ? pad : pad_h); - - poolLayer->_pads_end.insert(X_AXIS, 0u); - poolLayer->_pads_end.insert(Y_AXIS, 0u); - } catch (...) { - } - - std::string alg = poolLayer->GetParamAsString("pool", "caffe.PoolingParameter.MAX"); - poolLayer->_type = alg == "caffe.PoolingParameter.MAX" ? PoolingLayer::MAX : PoolingLayer::AVG; - } else /** Default behavior */ { - poolLayer->_kernel.insert(X_AXIS, poolLayer->GetParamAsUInt("kernel-x")); - poolLayer->_kernel.insert(Y_AXIS, poolLayer->GetParamAsUInt("kernel-y")); - - poolLayer->_stride.insert(X_AXIS, poolLayer->GetParamAsUInt("stride-x", 1u)); - poolLayer->_stride.insert(Y_AXIS, poolLayer->GetParamAsUInt("stride-y", 1u)); - // TODO: maybe just throw exception, why do we change IR? - if (0 == poolLayer->_stride[X_AXIS]) { - poolLayer->_stride[X_AXIS] = 1u; - } - if (0 == poolLayer->_stride[Y_AXIS]) { - poolLayer->_stride[Y_AXIS] = 1u; - } - - poolLayer->_padding.insert(X_AXIS, poolLayer->GetParamAsUInt("pad-x", 0u)); - poolLayer->_padding.insert(Y_AXIS, poolLayer->GetParamAsUInt("pad-y", 0u)); - - poolLayer->_pads_end.insert(X_AXIS, poolLayer->GetParamAsUInt("pad-r", poolLayer->_padding[X_AXIS])); - poolLayer->_pads_end.insert(Y_AXIS, poolLayer->GetParamAsUInt("pad-b", poolLayer->_padding[Y_AXIS])); - - // TODO: All kind of pool methods - poolLayer->_exclude_pad = poolLayer->GetParamAsBool("exclude-pad", false); - std::string alg = poolLayer->GetParamAsString("pool-method", "max"); - poolLayer->_type = alg == "avg" ? PoolingLayer::AVG : PoolingLayer::MAX; - if (alg != "max" && alg != "avg") { - IE_THROW() << "Layer with type `" << _type << "` has incorrect pool-type!"; - } - } - } else { - for (size_t i = 1; i <= kernels.size(); i++) { - poolLayer->_kernel.insert(i - 1, kernels[kernels.size() - i]); - } - - vector default_0 = vector(poolLayer->_kernel.size(), 0u); - vector default_1 = vector(poolLayer->_kernel.size(), 1u); - - vector strides = poolLayer->GetParamAsUInts("strides", default_1); - for (size_t i = 1; i <= strides.size(); i++) { - if (strides[strides.size() - i] == 0) { - IE_THROW() << "Stride could not be 0.\nIn layer " << poolLayer->name; - } - poolLayer->_stride.insert(i - 1, strides[strides.size() - i]); - } - - vector pads_begin = poolLayer->GetParamAsUInts("pads_begin", default_0); - for (size_t i = 1; i <= pads_begin.size(); i++) { - poolLayer->_padding.insert(i - 1, pads_begin[pads_begin.size() - i]); - } - - vector pads_end = poolLayer->GetParamAsUInts("pads_end", pads_begin); - for (size_t i = 1; i <= pads_end.size(); i++) { - poolLayer->_pads_end.insert(i - 1, pads_end[pads_end.size() - i]); - } - - poolLayer->_exclude_pad = poolLayer->GetParamAsBool("exclude-pad", false); - std::string alg = poolLayer->GetParamAsString("pool-method", "max"); - poolLayer->_type = alg == "avg" ? PoolingLayer::AVG : PoolingLayer::MAX; - if (alg != "max" && alg != "avg") { - IE_THROW() << "Layer with type `" << _type << "` has incorrect pad-type!"; - } - } - // TODO: checks for presence of all required attributes, and that there's no extraneous parameters only. -} - -// - -void BatchNormalizationValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of BatchNormalizationLayer class"; - } - casted->epsilon = casted->GetParamAsFloat("epsilon"); -} - -BatchNormalizationValidator::BatchNormalizationValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void PowerValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of PowerLayer class"; - } - casted->offset = casted->GetParamAsFloat("shift"); - casted->power = casted->GetParamAsFloat("power"); - casted->scale = casted->GetParamAsFloat("scale"); -} - -PowerValidator::PowerValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void PReLUValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of PReLULayer class"; - } - casted->_channel_shared = casted->GetParamAsBool("channel_shared", false); -} - -PReLUValidator::PReLUValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void ScaleShiftValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of ScaleShiftLayer class"; - } - if (casted->params.count("broadcast")) { - casted->_broadcast = casted->GetParamAsUInt("broadcast", 2); - } -} - -ScaleShiftValidator::ScaleShiftValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void TileValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of TileLayer class"; - } - casted->axis = casted->GetParamAsInt("axis", -1); - casted->tiles = casted->GetParamAsInt("tiles", -1); -} - -TileValidator::TileValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -ReshapeValidator::ReshapeValidator(const std::string& _type) : LayerValidator(_type) {} - -void ReshapeValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of ReshapeLayer class"; - } - casted->shape.clear(); - if (casted->type == "Flatten" && casted->params.count("end_axis") && casted->params.count("axis")) { - casted->num_axes = casted->GetParamAsInt("end_axis", -1); - casted->axis = casted->GetParamAsInt("axis", 0); - } else if (casted->params.count("dim")) { - casted->shape = casted->GetParamAsInts("dim", {}); - } -} - -// - -void EltwiseValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of EltwiseLayer class"; - } - // TODO: fix this onece we switched to IR v2.x also enable dedicated unit tests - // @details: need to remove sum - std::string op = casted->GetParamAsString("operation", "sum"); - // TODO: remove empty value case in IRv2.x - if (op == "sum" || op == "") { - casted->_operation = EltwiseLayer::Sum; - } else if (op == "mul" || op == "prod") { - casted->_operation = EltwiseLayer::Prod; - } else if (op == "max") { - casted->_operation = EltwiseLayer::Max; - } else if (op == "sub") { - casted->_operation = EltwiseLayer::Sub; - } else if (op == "div") { - casted->_operation = EltwiseLayer::Div; - } else if (op == "min") { - casted->_operation = EltwiseLayer::Min; - } else if (op == "squared_diff") { - casted->_operation = EltwiseLayer::Squared_diff; - } else if (op == "equal") { - casted->_operation = EltwiseLayer::Equal; - } else if (op == "not_equal") { - casted->_operation = EltwiseLayer::Not_equal; - } else if (op == "less") { - casted->_operation = EltwiseLayer::Less; - } else if (op == "less_equal") { - casted->_operation = EltwiseLayer::Less_equal; - } else if (op == "greater") { - casted->_operation = EltwiseLayer::Greater; - } else if (op == "greater_equal") { - casted->_operation = EltwiseLayer::Greater_equal; - } else if (op == "logical_not") { - casted->_operation = EltwiseLayer::Logical_NOT; - } else if (op == "logical_and") { - casted->_operation = EltwiseLayer::Logical_AND; - } else if (op == "logical_or") { - casted->_operation = EltwiseLayer::Logical_OR; - } else if (op == "logical_xor") { - casted->_operation = EltwiseLayer::Logical_XOR; - } else if (op == "floor_mod") { - casted->_operation = EltwiseLayer::Floor_mod; - } else if (op == "pow") { - casted->_operation = EltwiseLayer::Pow; - } else if (op == "mean") { - casted->_operation = EltwiseLayer::Mean; - } else { - IE_THROW() << "Unsupported element wise operation: " << op; - } - - casted->coeff = casted->GetParamAsFloats("coeff", {}); -} - -EltwiseValidator::EltwiseValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void ClampValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of ClampLayer class"; - } - casted->min_value = casted->GetParamAsFloat("min"); - casted->max_value = casted->GetParamAsFloat("max"); -} - -ClampValidator::ClampValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void ReLUValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of ReLULayer class"; - } - if (casted->params.count("negative_slope")) { - casted->negative_slope = casted->GetParamAsFloat("negative_slope"); - } -} - -ReLUValidator::ReLUValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void MVNValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of MVNLayer class"; - } - casted->across_channels = casted->GetParamAsInt("across_channels", 0); - casted->normalize = casted->GetParamAsInt("normalize_variance", 1); -} - -MVNValidator::MVNValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void GRNValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of GRNLayer class"; - } - casted->bias = casted->GetParamAsFloat("bias", 0.f); -} - -GRNValidator::GRNValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void SoftMaxValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of SoftMaxLayer class"; - } - casted->axis = casted->GetParamAsInt("axis", 1); -} - -SoftMaxValidator::SoftMaxValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void NormValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of NormLayer class"; - } - casted->_size = casted->GetParamAsUInt("local_size", 0); - casted->_size += casted->GetParamAsUInt("local-size", 0); - casted->_k = casted->GetParamAsUInt("k", 1); - casted->_alpha = casted->GetParamAsFloat("alpha"); - casted->_beta = casted->GetParamAsFloat("beta"); - casted->_isAcrossMaps = details::CaselessEq()(casted->GetParamAsString("region"), "across"); -} - -NormValidator::NormValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -SplitValidator::SplitValidator(const std::string& _type) : LayerValidator(_type) {} - -void SplitValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of SplitLayer class"; - } - casted->_axis = casted->GetParamAsUInt("axis", 1); - - std::string out_sizes; - for (auto& i : layer->outData) { - if (!out_sizes.empty()) - out_sizes += ","; - if (static_cast(i->getTensorDesc().getDims().size()) <= casted->_axis) { - IE_THROW() << "Internal error - dimensions are empty"; - } - out_sizes += std::to_string(i->getTensorDesc().getDims()[casted->_axis]); - } - if (!out_sizes.empty()) - casted->params["out_sizes"] = out_sizes; -} - -// - -ConcatValidator::ConcatValidator(const std::string& _type) : LayerValidator(_type) {} - -void ConcatValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of ConcatLayer class"; - } - casted->_axis = casted->GetParamAsUInt("axis", 1); -} - -// - -GemmValidator::GemmValidator(const std::string& _type) : LayerValidator(_type) {} - -void GemmValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of GemmLayer class"; - } - casted->alpha = casted->GetParamAsFloat("alpha", 1); - casted->beta = casted->GetParamAsFloat("beta", 1); - casted->transpose_a = casted->GetParamAsBool("transpose_a", false); - casted->transpose_b = casted->GetParamAsBool("transpose_b", false); -} - -// - -PadValidator::PadValidator(const std::string& _type) : LayerValidator(_type) {} - -void PadValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of PadLayer class"; - } - std::vector pads_begin = casted->GetParamAsUInts("pads_begin"); - std::vector pads_end = casted->GetParamAsUInts("pads_end"); - - casted->pads_begin.clear(); - for (size_t i = 0; i < pads_begin.size(); i++) { - casted->pads_begin.insert(i, pads_begin[i]); - } - - casted->pads_end.clear(); - for (size_t i = 0; i < pads_end.size(); i++) { - casted->pads_end.insert(i, pads_end[i]); - } - - casted->pad_value = casted->GetParamAsFloat("pad_value", 0.0f); - - std::string mode = casted->GetParamAsString("pad_mode", "constant"); - if (mode == "constant") { - casted->pad_mode = PadLayer::Constant; - } else if (mode == "edge") { - casted->pad_mode = PadLayer::Edge; - } else if (mode == "reflect") { - casted->pad_mode = PadLayer::Reflect; - } else if (mode == "symmetric") { - casted->pad_mode = PadLayer::Symmetric; - } else { - IE_THROW() << layer->name << " Unsupported pad mode operation: " << mode; - } -} - -// - -GatherValidator::GatherValidator(const std::string& _type) : LayerValidator(_type) {} - -void GatherValidator::parseParams(CNNLayer* layer) { - if (auto casted = dynamic_cast(layer)) { - casted->axis = casted->GetParamAsInt("axis", 0); - } else if (layer->insData.size() != 3) { - IE_THROW() << layer->name << " Gather layer is expected to have 3 inputs"; - } -} - -// - -StridedSliceValidator::StridedSliceValidator(const std::string& _type) : LayerValidator(_type) {} - -void StridedSliceValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of StridedSlice class"; - } - - casted->begin_mask = layer->GetParamAsString("begin_mask", ""); - casted->end_mask = layer->GetParamAsString("end_mask", ""); - casted->ellipsis_mask = layer->GetParamAsString("ellipsis_mask", ""); - casted->new_axis_mask = layer->GetParamAsString("new_axis_mask", ""); - casted->shrink_axis_mask = layer->GetParamAsString("shrink_axis_mask", ""); -} - -// - -ShuffleChannelsValidator::ShuffleChannelsValidator(const std::string& _type) : LayerValidator(_type) {} - -void ShuffleChannelsValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of ShuffleChannels class"; - } - - casted->axis = casted->GetParamAsInt("axis", 1); - casted->group = casted->GetParamAsUInt("group", 1); -} - -// - -DepthToSpaceValidator::DepthToSpaceValidator(const std::string& _type) : LayerValidator(_type) {} - -void DepthToSpaceValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of DepthToSpace class"; - } - - casted->block_size = casted->GetParamAsUInt("block_size", 1); -} - -// - -SpaceToDepthValidator::SpaceToDepthValidator(const std::string& _type) : LayerValidator(_type) {} - -void SpaceToDepthValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of SpaceToDepth class"; - } - - casted->block_size = casted->GetParamAsUInt("block_size", 1); -} - -/*--- SpaceToBatchValidator ---*/ - -SpaceToBatchValidator::SpaceToBatchValidator(const std::string& _type) : LayerValidator(_type) {} - -void SpaceToBatchValidator::parseParams(CNNLayer* layer) { - auto spaceToBatchLayer = dynamic_cast(layer); - if (!spaceToBatchLayer) - IE_THROW() << "'" << layer->name << "' layer is not instance of SpaceToBatchLayer class"; - - if (spaceToBatchLayer->insData.size() != 4 || spaceToBatchLayer->outData.size() != 1) - IE_THROW() << "'" << spaceToBatchLayer->name << "' layer has incorrect number of inputs or outputs edges!"; - - auto getParams = [](const DataPtr& dataPtr, std::vector& dst, std::string& layerName) { - if (dataPtr == nullptr) - IE_THROW() << "'" << layerName << "' layer has nullable input data"; - if (dataPtr->getTensorDesc().getPrecision() != Precision::I32 && - dataPtr->getTensorDesc().getPrecision() != Precision::I64) - IE_THROW() << "'" << layerName << "' layer has invalid input precision"; - auto creator = getCreatorLayer(dataPtr).lock(); - if (creator == nullptr) - IE_THROW() << "'" << layerName << "' layer has nullable input layer"; - - const auto& blob = creator->blobs.begin()->second; - dst.resize(blob->size()); - if (dataPtr->getTensorDesc().getPrecision() == Precision::I32) { - int* data = blob->buffer().as(); - for (size_t i = 0; i < blob->size(); i++) - dst[i] = data[i]; - } else if (dataPtr->getTensorDesc().getPrecision() == Precision::I64) { - int64_t* data = blob->buffer().as(); - for (size_t i = 0; i < blob->size(); i++) - dst[i] = data[i]; - } - }; - - if (spaceToBatchLayer->insData[0].lock() == nullptr) - IE_THROW() << "'" << layer->name << "' layer has nullable input data"; - getParams(spaceToBatchLayer->insData[1].lock(), spaceToBatchLayer->_block_shape, layer->name); - getParams(spaceToBatchLayer->insData[2].lock(), spaceToBatchLayer->_pads_begin, layer->name); - getParams(spaceToBatchLayer->insData[3].lock(), spaceToBatchLayer->_pads_end, layer->name); -} - -/*--- BatchToSpaceValidator ---*/ - -BatchToSpaceValidator::BatchToSpaceValidator(const std::string& _type) : LayerValidator(_type) {} - -void BatchToSpaceValidator::parseParams(CNNLayer* layer) { - auto batchToSpaceLayer = dynamic_cast(layer); - if (!batchToSpaceLayer) { - IE_THROW() << "'" << layer->name << "' layer is not instance of BatchToSpaceLayer class"; - } - - if (batchToSpaceLayer->insData.empty()) - IE_THROW() << "'" << layer->name << "' layer does not have any input data"; - - auto inData = batchToSpaceLayer->insData[0].lock(); - if (inData == nullptr) - IE_THROW() << "'" << layer->name << "' layer has nullable input data"; - - auto getParams = [](const DataPtr& dataPtr, std::vector& dst, std::string& layerName) { - if (dataPtr == nullptr) - IE_THROW() << "'" << layerName << "' layer has nullable input data"; - if (dataPtr->getTensorDesc().getPrecision() != Precision::I32 && - dataPtr->getTensorDesc().getPrecision() != Precision::I64) - IE_THROW() << "'" << layerName << "' layer has invalid input precision"; - auto creator = getCreatorLayer(dataPtr).lock(); - if (creator == nullptr) - IE_THROW() << "'" << layerName << "' layer has nullable input layer"; - - const auto& blob = creator->blobs.begin()->second; - dst.resize(blob->size()); - if (dataPtr->getTensorDesc().getPrecision() == Precision::I32) { - int* data = blob->buffer().as(); - for (size_t i = 0; i < blob->size(); i++) - dst[i] = data[i]; - } else if (dataPtr->getTensorDesc().getPrecision() == Precision::I64) { - int64_t* data = blob->buffer().as(); - for (size_t i = 0; i < blob->size(); i++) - dst[i] = data[i]; - } - }; - - if (batchToSpaceLayer->insData[0].lock() == nullptr) - IE_THROW() << "'" << layer->name << "' layer has nullable input data"; - getParams(batchToSpaceLayer->insData[1].lock(), batchToSpaceLayer->_block_shape, layer->name); - getParams(batchToSpaceLayer->insData[2].lock(), batchToSpaceLayer->_crops_begin, layer->name); - getParams(batchToSpaceLayer->insData[3].lock(), batchToSpaceLayer->_crops_end, layer->name); -} - -// - -BucketizeValidator::BucketizeValidator(const std::string& _type) : LayerValidator(_type) {} - -void BucketizeValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of Bucketize class"; - } - - casted->with_right_bound = casted->GetParamAsBool("with_right_bound", true); -} - -// - -ReverseSequenceValidator::ReverseSequenceValidator(const std::string& _type) : LayerValidator(_type) {} - -void ReverseSequenceValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of ReverseSequence class"; - } - - casted->seq_axis = casted->GetParamAsInt("seq_axis", 1); - casted->batch_axis = casted->GetParamAsInt("batch_axis", 0); -} - -/****************************************/ -/*** RNN specific validators ************/ -/****************************************/ - -static RNNCellBase::CellType cell_type_from(string type_name) { - const vector to_remove{"Cell", "Sequence"}; - for (auto& sub : to_remove) { - auto idx = type_name.find(sub); - if (idx != string::npos) - type_name.erase(idx); - } - - if (!one_of(type_name, "LSTM", "RNN", "GRU")) - IE_THROW() << "Unknown RNN cell type " << type_name << ". " - << "Expected one of [ LSTM | RNN | GRU ]."; - - return type_name == "LSTM" - ? RNNSequenceLayer::LSTM - : type_name == "GRU" ? RNNSequenceLayer::GRU - : type_name == "RNN" ? RNNSequenceLayer::RNN : RNNSequenceLayer::LSTM; -} - -static RNNSequenceLayer::Direction direction_from(string direction_name) { - if (!one_of(direction_name, "Forward", "Backward", "Bidirectional")) - IE_THROW() << "Unknown RNN direction type " << direction_name << ". " - << "Expected one of [ Forward | Backward | Bidirectional ]."; - - return direction_name == "Forward" - ? RNNSequenceLayer::FWD - : direction_name == "Backward" - ? RNNSequenceLayer::BWD - : direction_name == "Bidirecttional" ? RNNSequenceLayer::BDR : RNNSequenceLayer::FWD; -} - -RNNBaseValidator::RNNBaseValidator(const std::string& _type, RNNSequenceLayer::CellType CELL) : LayerValidator(_type) { - if (RNNSequenceLayer::LSTM == CELL) { - def_acts = {"sigmoid", "tanh", "tanh"}; - def_alpha = {0, 0, 0}; - def_beta = {0, 0, 0}; - G = 4; - NS = 2; - } else if (RNNSequenceLayer::GRU == CELL) { - def_acts = {"sigmoid", "tanh"}; - def_alpha = {0, 0}; - def_beta = {0, 0}; - G = 3; - NS = 1; - } else if (RNNSequenceLayer::RNN == CELL) { - def_acts = {"tanh"}; - def_alpha = {0}; - def_beta = {0}; - G = 1; - NS = 1; - } else { - IE_ASSERT(false); - } -} - -void RNNBaseValidator::parseParams(CNNLayer* layer) { - auto rnn = dynamic_cast(layer); - if (!rnn) - IE_THROW() << "Layer is not instance of RNNLayer class"; - - rnn->cellType = cell_type_from(layer->type); - rnn->hidden_size = rnn->GetParamAsInt("hidden_size"); - rnn->clip = rnn->GetParamAsFloat("clip", 0.0f); - rnn->activations = rnn->GetParamAsStrings("activations", def_acts); - rnn->activation_alpha = rnn->GetParamAsFloats("activation_alpha", def_alpha); - rnn->activation_beta = rnn->GetParamAsFloats("activation_beta", def_beta); - - if (rnn->cellType == RNNCellBase::GRU) { - auto lbr = rnn->GetParamAsBool("linear_before_reset", false); - if (lbr) - rnn->cellType = RNNCellBase::GRU_LBR; - } -} - -// - -template -RNNSequenceValidator::RNNSequenceValidator(const std::string& _type) : RNNBaseValidator(_type, CELL) {} - -template -void RNNSequenceValidator::parseParams(CNNLayer* layer) { - RNNBaseValidator::parseParams(layer); - - auto casted = dynamic_cast(layer); - if (!casted) - IE_THROW() << "Layer is not instance of RNNLayer class"; - - std::string direction = layer->GetParamAsString("direction"); - - casted->axis = layer->GetParamAsUInt("axis", 1); - casted->direction = direction_from(direction); -} - -template class details_legacy::RNNSequenceValidator; -template class details_legacy::RNNSequenceValidator; -template class details_legacy::RNNSequenceValidator; - -// - -template -RNNCellValidator::RNNCellValidator(const std::string& _type) : RNNBaseValidator(_type, CELL) {} - -template class details_legacy::RNNCellValidator; -template class details_legacy::RNNCellValidator; -template class details_legacy::RNNCellValidator; - -// - -void DetectionOutputValidator::parseParams(CNNLayer* layer) { - unsigned int num_classes = layer->GetParamAsUInt("num_classes"); - if (num_classes == 0) { - IE_THROW() << "num_classes parameter of DetectionOutput layer can't be equal to zero"; - } - float _nms_threshold = layer->GetParamAsFloat("nms_threshold"); - if (_nms_threshold < 0) { - IE_THROW() << "nms_threshold parameter of DetectionOutput layer can't be less then zero"; - } - int _keep_top_k = layer->GetParamAsInt("keep_top_k", -1); - (void)_keep_top_k; - - if (layer->CheckParamPresence("background_label_id")) { - int _background_label_id = layer->GetParamAsInt("background_label_id", -1); - (void)_background_label_id; - } - if (layer->CheckParamPresence("top_k")) { - int _top_k = layer->GetParamAsInt("top_k", -1); - (void)_top_k; - } - if (layer->CheckParamPresence("variance_encoded_in_target")) { - bool _variance_encoded_in_target = static_cast(layer->GetParamAsUInt("variance_encoded_in_target", 0)); - (void)_variance_encoded_in_target; - } - if (layer->CheckParamPresence("num_orient_classes")) { - int _num_orient_classes = layer->GetParamAsUInt("num_orient_classes"); - (void)_num_orient_classes; - } - if (layer->CheckParamPresence("share_location")) { - bool _share_location = static_cast(layer->GetParamAsUInt("share_location", 1)); - (void)_share_location; - } - if (layer->CheckParamPresence("interpolate_orientation")) { - int _interpolate_orientation = layer->GetParamAsInt("interpolate_orientation"); - (void)_interpolate_orientation; - } - if (layer->CheckParamPresence("confidence_threshold")) { - float _confidence_threshold = layer->GetParamAsFloat("confidence_threshold"); - if (_confidence_threshold < 0) { - IE_THROW() << "_confidence_threshold parameter of DetectionOutput layer can't be less then zero"; - } - } - - if (layer->CheckParamPresence("code_type")) { - std::string _code_type = layer->GetParamAsString("code_type"); - for (auto& c : _code_type) { - c = std::tolower(c); - } - std::vector code_types = {"caffe.priorboxparameter.center_size", "caffe.priorboxparameter.corner"}; - auto it = std::find(code_types.begin(), code_types.end(), _code_type); - if (it == code_types.end()) { - IE_THROW() << "Parameter code_type of DetectionOutput layer "; - } - } -} - -DetectionOutputValidator::DetectionOutputValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -void ProposalValidator::parseParams(CNNLayer* layer) { - if (layer->params.find("num_outputs") == layer->params.end()) { - layer->params["num_outputs"] = std::to_string(layer->outData.size()); - } -} - -ProposalValidator::ProposalValidator(const std::string& _type) : LayerValidator(_type) {} - -// - -OneHotValidator::OneHotValidator(const std::string& _type) : LayerValidator(_type) {} - -void OneHotValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not an instance of the OneHot class"; - } - - if (layer->CheckParamPresence("depth")) { - casted->depth = layer->GetParamAsUInt("depth"); - } else { - IE_THROW() << "The required depth parameter of OneHot layer is missing"; - } - - auto on_value_str = layer->GetParamAsString("on_value", "1.0"); - auto off_value_str = layer->GetParamAsString("off_value", "0.0"); - - // there are some key words to represent reserved values - auto universal_read = [](std::string str) { - float res; - if (str == "True") - res = 1.0f; - else if (str == "False") - res = 0.0f; - else - res = CNNLayer::ie_parse_float(str); - return res; - }; - - casted->on_value = universal_read(on_value_str); - casted->off_value = universal_read(off_value_str); - - casted->axis = layer->GetParamAsInt("axis", -1); -} - -// - -QuantizeValidator::QuantizeValidator(const std::string& _type) : LayerValidator(_type) {} - -void QuantizeValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of QuantizeLayer class"; - } - - casted->levels = casted->GetParamAsSizeT("levels", 1); - - if (casted->levels <= 1) { - IE_THROW() << layer->name << ": Incorrect value for parameter levels = " << casted->levels - << ". Expected to be > 1."; - } -} - -// - -BinaryConvolutionValidator::BinaryConvolutionValidator(const std::string& _type) : LayerValidator(_type) {} - -void BinaryConvolutionValidator::parseParams(CNNLayer* layer) { - auto binConvLayer = dynamic_cast(layer); - if (!binConvLayer) { - IE_THROW() << "Layer is not instance of BinaryConvolutionLayer class"; - } - - binConvLayer->_pad_value = binConvLayer->GetParamAsFloat("pad_value", 0.f); - binConvLayer->_in_depth = binConvLayer->GetParamAsUInt("input"); - binConvLayer->_mode = BinaryConvolutionLayer::xnor_popcount; - std::string mode = binConvLayer->GetParamAsString("mode", "xnor-popcount"); - if (mode != "xnor-popcount") - IE_THROW() << "Layer with type `" << _type << "` has incorrect mode!"; - - binConvLayer->_out_depth = binConvLayer->GetParamAsUInt("output"); - - binConvLayer->_kernel.clear(); - binConvLayer->_stride.clear(); - binConvLayer->_padding.clear(); - binConvLayer->_pads_end.clear(); - binConvLayer->_dilation.clear(); - - vector kernels = binConvLayer->GetParamAsUInts("kernel", {}); - if (kernels.empty()) { - // IR_v == 2 - binConvLayer->_kernel.insert(X_AXIS, binConvLayer->GetParamAsUInt("kernel-x")); - binConvLayer->_kernel.insert(Y_AXIS, binConvLayer->GetParamAsUInt("kernel-y")); - - binConvLayer->_stride.insert(X_AXIS, binConvLayer->GetParamAsUInt("stride-x", 1u)); - binConvLayer->_stride.insert(Y_AXIS, binConvLayer->GetParamAsUInt("stride-y", 1u)); - // TODO: maybe just throw exception, why do we change IR? - if (0 == binConvLayer->_stride[X_AXIS]) { - binConvLayer->_stride[X_AXIS] = 1u; - } - if (0 == binConvLayer->_stride[Y_AXIS]) { - binConvLayer->_stride[Y_AXIS] = 1u; - } - - binConvLayer->_padding.insert(X_AXIS, binConvLayer->GetParamAsUInt("pad-x", 0u)); - binConvLayer->_padding.insert(Y_AXIS, binConvLayer->GetParamAsUInt("pad-y", 0u)); - - binConvLayer->_pads_end.insert(X_AXIS, binConvLayer->GetParamAsUInt("pad-r", binConvLayer->_padding[X_AXIS])); - binConvLayer->_pads_end.insert(Y_AXIS, binConvLayer->GetParamAsUInt("pad-b", binConvLayer->_padding[Y_AXIS])); - - binConvLayer->_dilation.insert(X_AXIS, binConvLayer->GetParamAsUInt("dilation-x", 1u)); - binConvLayer->_dilation.insert(Y_AXIS, binConvLayer->GetParamAsUInt("dilation-y", 1u)); - } else { - // IR_v > 2 - for (size_t i = 1; i <= kernels.size(); i++) { - binConvLayer->_kernel.insert(i - 1, kernels[kernels.size() - i]); - } - - vector default_0 = vector(binConvLayer->_kernel.size(), 0u); - vector default_1 = vector(binConvLayer->_kernel.size(), 1u); - - vector strides = binConvLayer->GetParamAsUInts("strides", default_1); - for (size_t i = 1; i <= strides.size(); i++) { - if (strides[strides.size() - i] == 0) { - IE_THROW() << "Stride could not be 0.\nIn layer " << binConvLayer->name; - } - binConvLayer->_stride.insert(i - 1, strides[strides.size() - i]); - } - - vector pads_begin = binConvLayer->GetParamAsUInts("pads_begin", default_0); - for (size_t i = 1; i <= pads_begin.size(); i++) { - binConvLayer->_padding.insert(i - 1, pads_begin[pads_begin.size() - i]); - } - - vector pads_end = binConvLayer->GetParamAsUInts("pads_end", pads_begin); - for (size_t i = 1; i <= pads_end.size(); i++) { - binConvLayer->_pads_end.insert(i - 1, pads_end[pads_end.size() - i]); - } - - vector dilations = binConvLayer->GetParamAsUInts("dilations", default_1); - for (size_t i = 1; i <= dilations.size(); i++) { - binConvLayer->_dilation.insert(i - 1, dilations[dilations.size() - i]); - } - } - - binConvLayer->_auto_pad = binConvLayer->GetParamAsString("auto_pad", ""); - binConvLayer->_group = binConvLayer->GetParamAsUInt("group", 1u); -} - -// - -ReduceValidator::ReduceValidator(const std::string& _type) : LayerValidator(_type) {} - -void ReduceValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of Reduce class"; - } - - casted->keep_dims = layer->GetParamAsBool("keep_dims", true); -} - -// - -TopKValidator::TopKValidator(const std::string& _type) : LayerValidator(_type) {} - -void TopKValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of TopK class"; - } - - casted->mode = layer->GetParamAsString("mode", "max"); - if (casted->mode != "max" && casted->mode != "min") - IE_THROW() << layer->name - << " TopK can take only 'max' or 'min' for mode, but actually it has: " << casted->mode; - casted->sort = layer->GetParamAsString("sort", "index"); - if (casted->sort != "value" && casted->sort != "index" && casted->sort != "none") - IE_THROW() << layer->name - << " TopK can take only 'value', 'index' or 'none' for sort, but actually it has: " << casted->sort; - casted->axis = layer->GetParamAsInt("axis", -1); -} - -// - -UniqueValidator::UniqueValidator(const std::string& _type) : LayerValidator(_type) {} - -void UniqueValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of Unique class"; - } - - casted->sorted = layer->GetParamAsBool("sorted"); - casted->return_inverse = layer->GetParamAsBool("return_inverse"); - casted->return_counts = layer->GetParamAsBool("return_counts"); -} - -// - -NMSValidator::NMSValidator(const std::string& _type) : LayerValidator(_type) {} - -void NMSValidator::parseParams(CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of NonMaxSuppression class"; - } - - casted->center_point_box = layer->GetParamAsBool("center_point_box", false); - casted->sort_result_descending = layer->GetParamAsBool("sort_result_descending", true); - casted->output_type = layer->GetParamAsString("output_type", "I64"); -} - -#define REG_LAYER_VALIDATOR_FOR_TYPE(__validator, __type) _validators[#__type] = std::make_shared<__validator>(#__type) - -LayerValidators::LayerValidators() : _validators() { - REG_LAYER_VALIDATOR_FOR_TYPE(BatchNormalizationValidator, BatchNormalization); - REG_LAYER_VALIDATOR_FOR_TYPE(ClampValidator, Clamp); - REG_LAYER_VALIDATOR_FOR_TYPE(ConcatValidator, Concat); - REG_LAYER_VALIDATOR_FOR_TYPE(ConvolutionValidator, Convolution); - REG_LAYER_VALIDATOR_FOR_TYPE(CropValidator, Crop); - REG_LAYER_VALIDATOR_FOR_TYPE(DeconvolutionValidator, Deconvolution); - REG_LAYER_VALIDATOR_FOR_TYPE(DeformableConvolutionValidator, DeformableConvolution); - REG_LAYER_VALIDATOR_FOR_TYPE(DetectionOutputValidator, DetectionOutput); - REG_LAYER_VALIDATOR_FOR_TYPE(EltwiseValidator, Eltwise); - REG_LAYER_VALIDATOR_FOR_TYPE(FullyConnectedValidator, InnerProduct); - REG_LAYER_VALIDATOR_FOR_TYPE(FullyConnectedValidator, FullyConnected); - REG_LAYER_VALIDATOR_FOR_TYPE(GRNValidator, GRN); - REG_LAYER_VALIDATOR_FOR_TYPE(MVNValidator, MVN); - REG_LAYER_VALIDATOR_FOR_TYPE(NormValidator, Norm); - REG_LAYER_VALIDATOR_FOR_TYPE(NormValidator, LRN); - REG_LAYER_VALIDATOR_FOR_TYPE(PReLUValidator, PReLU); - REG_LAYER_VALIDATOR_FOR_TYPE(PoolingValidator, Pooling); - REG_LAYER_VALIDATOR_FOR_TYPE(PowerValidator, Power); - REG_LAYER_VALIDATOR_FOR_TYPE(ProposalValidator, Proposal); - REG_LAYER_VALIDATOR_FOR_TYPE(ReLUValidator, ReLU); - REG_LAYER_VALIDATOR_FOR_TYPE(ReshapeValidator, Reshape); - REG_LAYER_VALIDATOR_FOR_TYPE(ReshapeValidator, Flatten); - REG_LAYER_VALIDATOR_FOR_TYPE(ScaleShiftValidator, ScaleShift); - REG_LAYER_VALIDATOR_FOR_TYPE(SoftMaxValidator, SoftMax); - REG_LAYER_VALIDATOR_FOR_TYPE(SplitValidator, Split); - REG_LAYER_VALIDATOR_FOR_TYPE(SplitValidator, Slice); - REG_LAYER_VALIDATOR_FOR_TYPE(GemmValidator, Gemm); - REG_LAYER_VALIDATOR_FOR_TYPE(PadValidator, Pad); - REG_LAYER_VALIDATOR_FOR_TYPE(GatherValidator, Gather); - REG_LAYER_VALIDATOR_FOR_TYPE(StridedSliceValidator, StridedSlice); - REG_LAYER_VALIDATOR_FOR_TYPE(ShuffleChannelsValidator, ShuffleChannels); - REG_LAYER_VALIDATOR_FOR_TYPE(DepthToSpaceValidator, DepthToSpace); - REG_LAYER_VALIDATOR_FOR_TYPE(SpaceToDepthValidator, SpaceToDepth); - REG_LAYER_VALIDATOR_FOR_TYPE(SpaceToBatchValidator, SpaceToBatch); - REG_LAYER_VALIDATOR_FOR_TYPE(BatchToSpaceValidator, BatchToSpace); - REG_LAYER_VALIDATOR_FOR_TYPE(ReverseSequenceValidator, ReverseSequence); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNCellValidator, RNNCell); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNCellValidator, GRUCell); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNCellValidator, LSTMCell); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNSequenceValidator, RNNSequence); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNSequenceValidator, GRUSequence); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNSequenceValidator, LSTMSequence); - REG_LAYER_VALIDATOR_FOR_TYPE(TileValidator, Tile); - REG_LAYER_VALIDATOR_FOR_TYPE(OneHotValidator, OneHot); - REG_LAYER_VALIDATOR_FOR_TYPE(QuantizeValidator, FakeQuantize); - REG_LAYER_VALIDATOR_FOR_TYPE(BinaryConvolutionValidator, BinaryConvolution); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceAnd); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceL1); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceL2); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceLogSum); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceLogSumExp); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceMax); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceMean); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceMin); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceOr); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceProd); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceSum); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceSumSquare); - REG_LAYER_VALIDATOR_FOR_TYPE(TopKValidator, TopK); - REG_LAYER_VALIDATOR_FOR_TYPE(UniqueValidator, Unique); - REG_LAYER_VALIDATOR_FOR_TYPE(NMSValidator, NonMaxSuppression); -} - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/ie_layer_validators.hpp b/src/plugins/intel_gna/legacy/src/ie_layer_validators.hpp deleted file mode 100644 index 206ec906509..00000000000 --- a/src/plugins/intel_gna/legacy/src/ie_layer_validators.hpp +++ /dev/null @@ -1,410 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -#include "caseless.hpp" - -namespace InferenceEngine { -namespace details_legacy { - -/** - * @brief Contains methods to validate layer of specific type - */ -class LayerValidator { -public: - using Ptr = std::shared_ptr; - - explicit LayerValidator(const std::string& _type) : _type(_type) {} - virtual ~LayerValidator() = default; - - /** - * @brief It parses map of params and applies to the layer's fields. - * This checks for presence of all required attributes, and that there's no extraneous parameters only. - * Throws exception in case of parsing error - */ - virtual void parseParams(CNNLayer* layer) {} - -protected: - std::string _type; -}; - -/** - * @brief Contains all validators, registered for specific layer type - */ -class LayerValidators { -public: - static LayerValidators* getInstance(); - - LayerValidators(LayerValidators const&) = delete; - - void operator=(LayerValidators const&) = delete; - - LayerValidator::Ptr getValidator(const std::string& type); - -private: - LayerValidators(); - -private: - InferenceEngine::details::caseless_unordered_map _validators; -}; - -class GeneralValidator : public LayerValidator { -public: - explicit GeneralValidator(const std::string& _type); -}; - -class ConvolutionValidator : public LayerValidator { -public: - void parseParams(CNNLayer* layer) override; - - explicit ConvolutionValidator(const std::string& _type); -}; - -class DeconvolutionValidator : public ConvolutionValidator { -public: - void parseParams(CNNLayer* layer) override; - - explicit DeconvolutionValidator(const std::string& _type); -}; - -class DeformableConvolutionValidator : public ConvolutionValidator { -public: - void parseParams(CNNLayer* layer) override; - - explicit DeformableConvolutionValidator(const std::string& _type); -}; - -class PoolingValidator : public LayerValidator { -public: - void parseParams(CNNLayer* layer) override; - - explicit PoolingValidator(const std::string& _type); -}; - -class FullyConnectedValidator : public LayerValidator { -public: - explicit FullyConnectedValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class CropValidator : public LayerValidator { -public: - explicit CropValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class TileValidator : public LayerValidator { -public: - explicit TileValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class BatchNormalizationValidator : public LayerValidator { -public: - explicit BatchNormalizationValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class PowerValidator : public LayerValidator { -public: - explicit PowerValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class PReLUValidator : public LayerValidator { -public: - explicit PReLUValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class ScaleShiftValidator : public LayerValidator { -public: - explicit ScaleShiftValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class ReshapeValidator : public LayerValidator { -public: - explicit ReshapeValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class EltwiseValidator : public LayerValidator { -public: - explicit EltwiseValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class ClampValidator : public LayerValidator { -public: - explicit ClampValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class ReLUValidator : public LayerValidator { -public: - explicit ReLUValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class MVNValidator : public LayerValidator { -public: - explicit MVNValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class GRNValidator : public LayerValidator { -public: - explicit GRNValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class SoftMaxValidator : public LayerValidator { -public: - explicit SoftMaxValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class NormValidator : public LayerValidator { -public: - explicit NormValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class SplitValidator : public LayerValidator { -public: - explicit SplitValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class ConcatValidator : public LayerValidator { -public: - explicit ConcatValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class GemmValidator : public LayerValidator { -public: - explicit GemmValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class PadValidator : public LayerValidator { -public: - explicit PadValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class GatherValidator : public LayerValidator { -public: - explicit GatherValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class StridedSliceValidator : public LayerValidator { -public: - explicit StridedSliceValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class ShuffleChannelsValidator : public LayerValidator { -public: - explicit ShuffleChannelsValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class DepthToSpaceValidator : public LayerValidator { -public: - explicit DepthToSpaceValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class SpaceToDepthValidator : public LayerValidator { -public: - explicit SpaceToDepthValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class SpaceToBatchValidator : public LayerValidator { -public: - explicit SpaceToBatchValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class BatchToSpaceValidator : public LayerValidator { -public: - explicit BatchToSpaceValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class SparseFillEmptyRowsValidator : public LayerValidator { -public: - explicit SparseFillEmptyRowsValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class BucketizeValidator : public LayerValidator { -public: - explicit BucketizeValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class ReverseSequenceValidator : public LayerValidator { -public: - explicit ReverseSequenceValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class RNNBaseValidator : public LayerValidator { -public: - RNNBaseValidator(const std::string& _type, RNNSequenceLayer::CellType CELL); - - void parseParams(CNNLayer* layer) override; - -protected: - std::vector def_acts; // Default values for cell gate activations - std::vector def_alpha; // Default activation alpha parameter - std::vector def_beta; // Default activation beta parameter - size_t G; // gate number - size_t NS; // state number -}; - -template -class RNNCellValidator : public RNNBaseValidator { -public: - explicit RNNCellValidator(const std::string& _type); -}; - -extern template class RNNCellValidator; -extern template class RNNCellValidator; -extern template class RNNCellValidator; - -template -class RNNSequenceValidator : public RNNBaseValidator { -public: - explicit RNNSequenceValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -extern template class RNNSequenceValidator; -extern template class RNNSequenceValidator; -extern template class RNNSequenceValidator; - -class DetectionOutputValidator : public LayerValidator { -public: - explicit DetectionOutputValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class ProposalValidator : public LayerValidator { -public: - explicit ProposalValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class OneHotValidator : public LayerValidator { -public: - explicit OneHotValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class QuantizeValidator : public LayerValidator { -public: - explicit QuantizeValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class BinaryConvolutionValidator : public LayerValidator { -public: - void parseParams(CNNLayer* layer) override; - - explicit BinaryConvolutionValidator(const std::string& _type); -}; - -class ReduceValidator : public LayerValidator { -public: - explicit ReduceValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class TopKValidator : public LayerValidator { -public: - explicit TopKValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class UniqueValidator : public LayerValidator { -public: - explicit UniqueValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class NMSValidator : public LayerValidator { -public: - explicit NMSValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class ScatterUpdateValidator : public LayerValidator { -public: - explicit ScatterUpdateValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -class ScatterElementsUpdateValidator : public LayerValidator { -public: - explicit ScatterElementsUpdateValidator(const std::string& _type); - - void parseParams(CNNLayer* layer) override; -}; - -} // namespace details_legacy -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/ie_layers.cpp b/src/plugins/intel_gna/legacy/src/ie_layers.cpp deleted file mode 100644 index a8a4ef6727b..00000000000 --- a/src/plugins/intel_gna/legacy/src/ie_layers.cpp +++ /dev/null @@ -1,443 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -using namespace InferenceEngine; - -CNNLayer::CNNLayer(const LayerParams& prms) - : node(nullptr), - name(prms.name), - type(prms.type), - precision(prms.precision), - userValue({0}) {} - -CNNLayer::CNNLayer(const CNNLayer& other) - : node(other.node), - name(other.name), - type(other.type), - precision(other.precision), - outData(other.outData), - insData(other.insData), - _fusedWith(other._fusedWith), - userValue(other.userValue), - affinity(other.affinity), - params(other.params), - blobs(other.blobs) {} - -LayerParams::LayerParams() {} - -LayerParams::LayerParams(const std::string& name, const std::string& type, Precision precision) - : name(name), - type(type), - precision(precision) {} - -LayerParams::LayerParams(const LayerParams& other) : name(other.name), type(other.type), precision(other.precision) {} - -LayerParams& LayerParams::operator=(const LayerParams& other) { - if (&other != this) { - name = other.name; - type = other.type; - precision = other.precision; - } - return *this; -} - -WeightableLayer::WeightableLayer(const LayerParams& prms) : CNNLayer(prms) {} - -const DataPtr CNNLayer::input() const { - if (insData.empty()) { - IE_THROW() << "Internal error: input data is empty"; - } - auto lockedFirstInsData = insData[0].lock(); - if (!lockedFirstInsData) { - IE_THROW() << "Internal error: unable to lock weak_ptr\n"; - } - return lockedFirstInsData; -} - -float CNNLayer::ie_parse_float(const std::string& str) { - if (str == "-inf") { - return -std::numeric_limits::infinity(); - } else if (str == "inf") { - return std::numeric_limits::infinity(); - } else { - float res; - std::stringstream val_stream(str); - val_stream.imbue(std::locale("C")); - val_stream >> res; - if (!val_stream.eof()) - IE_THROW(); - return res; - } -} - -std::string CNNLayer::ie_serialize_float(float value) { - std::stringstream val_stream; - val_stream.imbue(std::locale("C")); - val_stream << value; - return val_stream.str(); -} - -float CNNLayer::GetParamAsFloat(const char* param, float def) const { - std::string val = GetParamAsString(param, ie_serialize_float(def).c_str()); - try { - return ie_parse_float(val); - } catch (...) { - IE_THROW() << "Cannot parse parameter " << param << " from IR for layer " << name << ". Value " << val - << " cannot be casted to float."; - } -} - -float CNNLayer::GetParamAsFloat(const char* param) const { - std::string val = GetParamAsString(param); - try { - return ie_parse_float(val); - } catch (...) { - IE_THROW() << "Cannot parse parameter " << param << " from IR for layer " << name << ". Value " << val - << " cannot be casted to float."; - } -} - -std::vector CNNLayer::GetParamAsFloats(const char* param, std::vector def) const { - std::string vals = GetParamAsString(param, ""); - std::vector result; - std::istringstream stream(vals); - std::string str; - if (vals.empty()) - return def; - while (getline(stream, str, ',')) { - try { - float val = ie_parse_float(str); - result.push_back(val); - } catch (...) { - IE_THROW() << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name - << ". Value " << vals << " cannot be casted to floats."; - } - } - return result; -} - -std::vector CNNLayer::GetParamAsFloats(const char* param) const { - std::string vals = GetParamAsString(param); - std::vector result; - std::istringstream stream(vals); - std::string str; - while (getline(stream, str, ',')) { - try { - float val = ie_parse_float(str); - result.push_back(val); - } catch (...) { - IE_THROW() << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name - << ". Value " << vals << " cannot be casted to floats."; - } - } - return result; -} - -int CNNLayer::GetParamAsInt(const char* param, int def) const { - std::string val = GetParamAsString(param, std::to_string(def).c_str()); - try { - return std::stoi(val); - } catch (...) { - IE_THROW() << "Cannot parse parameter " << param << " from IR for layer " << name << ". Value " << val - << " cannot be casted to int."; - } -} - -int CNNLayer::GetParamAsInt(const char* param) const { - std::string val = GetParamAsString(param); - try { - return std::stoi(val); - } catch (...) { - IE_THROW() << "Cannot parse parameter " << param << " from IR for layer " << name << ". Value " << val - << " cannot be casted to int."; - } -} - -std::vector CNNLayer::GetParamAsInts(const char* param, std::vector def) const { - std::string vals = GetParamAsString(param, ""); - std::vector result; - std::istringstream stream(vals); - std::string str; - if (vals.empty()) - return def; - while (getline(stream, str, ',')) { - try { - result.push_back(std::stoi(str)); - } catch (...) { - IE_THROW() << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name - << ". Value " << vals << " cannot be casted to int."; - } - } - return result; -} - -std::vector CNNLayer::GetParamAsInts(const char* param) const { - std::string vals = GetParamAsString(param); - std::vector result; - std::istringstream stream(vals); - std::string str; - while (getline(stream, str, ',')) { - try { - result.push_back(std::stoi(str)); - } catch (...) { - IE_THROW() << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name - << ". Value " << vals << " cannot be casted to int."; - } - } - return result; -} - -unsigned int CNNLayer::GetParamAsUInt(const char* param, unsigned int def) const { - std::string val = GetParamAsString(param, std::to_string(def).c_str()); - std::string message = "Cannot parse parameter " + std::string(param) + " from IR for layer " + name + ". Value " + - val + " cannot be casted to unsigned int."; - try { - long long value = std::stoll(val); - if ((value < 0) || (value > std::numeric_limits::max())) { - IE_THROW() << message; - } - return static_cast(value); - } catch (...) { - IE_THROW() << message; - } -} - -unsigned int CNNLayer::GetParamAsUInt(const char* param) const { - std::string val = GetParamAsString(param); - std::string message = "Cannot parse parameter " + std::string(param) + " from IR for layer " + name + ". Value " + - val + " cannot be casted to unsigned int."; - try { - long long value = std::stoll(val); - if ((value < 0) || (value > std::numeric_limits::max())) { - IE_THROW() << message; - } - return static_cast(value); - } catch (...) { - IE_THROW() << message; - } -} - -std::vector CNNLayer::GetParamAsUInts(const char* param, std::vector def) const { - std::string vals = GetParamAsString(param, ""); - std::vector result; - std::istringstream stream(vals); - std::string str; - std::string message = "Cannot parse parameter " + std::string(param) + " " + str + " from IR for layer " + name + - ". Value " + vals + " cannot be casted to unsigned int."; - if (vals.empty()) - return def; - while (getline(stream, str, ',')) { - try { - long long value = std::stoll(str); - if ((value < 0) || (value > std::numeric_limits::max())) { - IE_THROW() << message; - } - result.push_back(static_cast(value)); - } catch (...) { - IE_THROW() << message; - } - } - return result; -} - -std::vector CNNLayer::GetParamAsUInts(const char* param) const { - std::string vals = GetParamAsString(param); - std::vector result; - std::istringstream stream(vals); - std::string str; - std::string message = "Cannot parse parameter " + std::string(param) + " " + str + " from IR for layer " + name + - ". Value " + vals + " cannot be casted to unsigned int."; - while (getline(stream, str, ',')) { - try { - long long value = std::stoll(str); - if ((value < 0) || (value > std::numeric_limits::max())) { - IE_THROW() << message; - } - result.push_back(static_cast(value)); - } catch (...) { - IE_THROW() << message; - } - } - return result; -} - -size_t CNNLayer::GetParamAsSizeT(const char* param, size_t def) const { - std::string val = GetParamAsString(param, std::to_string(def).c_str()); - std::string message = "Cannot parse parameter " + std::string(param) + " from IR for layer " + name + ". Value " + - val + " cannot be casted to size_t."; - try { - long long value = std::stoll(val); - if ((value < 0) || (static_cast(value) > std::numeric_limits::max())) { - IE_THROW() << message; - } - return static_cast(value); - } catch (...) { - IE_THROW() << message; - } -} - -size_t CNNLayer::GetParamAsSizeT(const char* param) const { - std::string val = GetParamAsString(param); - std::string message = "Cannot parse parameter " + std::string(param) + " from IR for layer " + name + ". Value " + - val + " cannot be casted to size_t."; - try { - long long value = std::stoll(val); - if ((value < 0) || (static_cast(value) > std::numeric_limits::max())) { - IE_THROW() << message; - } - return static_cast(value); - } catch (...) { - IE_THROW() << message; - } -} - -bool CNNLayer::GetParamAsBool(const char* param, bool def) const { - std::string val = GetParamAsString(param, std::to_string(def).c_str()); - std::string loweredCaseValue; - std::transform(val.begin(), val.end(), std::back_inserter(loweredCaseValue), [](char value) { - return static_cast(std::tolower(value)); - }); - - bool result = false; - - if (!(std::istringstream(loweredCaseValue) >> std::boolalpha >> result)) { - // attempting parse using non alpha bool - return (GetParamAsInt(param, def) != 0); - } - - return result; -} - -bool CNNLayer::GetParamAsBool(const char* param) const { - std::string val = GetParamAsString(param); - std::string loweredCaseValue; - std::transform(val.begin(), val.end(), std::back_inserter(loweredCaseValue), [](char value) { - return static_cast(std::tolower(value)); - }); - - bool result = false; - - if (!(std::istringstream(loweredCaseValue) >> std::boolalpha >> result)) { - // attempting parse using non alpha bool - return (GetParamAsInt(param) != 0); - } - - return result; -} - -std::string CNNLayer::GetParamAsString(const char* param, const char* def) const { - auto it = params.find(param); - if (it == params.end() || it->second.empty()) { - return def; - } - return (*it).second; -} - -bool CNNLayer::CheckParamPresence(const char* param) const { - auto it = params.find(param); - if (it == params.end()) { - return false; - } - return true; -} - -std::string CNNLayer::GetParamAsString(const char* param) const { - auto it = params.find(param); - if (it == params.end()) { - IE_THROW() << "No such parameter name '" << param << "' for layer " << name; - } - return (*it).second; -} - -std::string CNNLayer::getBoolStrParamAsIntStr(const char* param) const { - std::string val = GetParamAsString(param); - if (val == "true" || val == "True") { - return "1"; - } else if (val == "false" || val == "False") { - return "0"; - } - return val; -} - -std::vector CNNLayer::GetParamAsStrings(const char* param, std::vector def) const { - std::string vals = GetParamAsString(param, ""); - std::vector result; - std::istringstream stream(vals); - std::string str; - if (vals.empty()) - return def; - while (getline(stream, str, ',')) { - try { - result.push_back(str); - } catch (...) { - IE_THROW() << "Cannot parse parameter " << param << " from IR for layer " << name << "."; - } - } - return result; -} - -CNNLayer::~CNNLayer() {} -WeightableLayer::~WeightableLayer() {} -ConvolutionLayer::~ConvolutionLayer() {} -DeconvolutionLayer::~DeconvolutionLayer() {} -DeformableConvolutionLayer::~DeformableConvolutionLayer() {} -PoolingLayer::~PoolingLayer() {} -BinaryConvolutionLayer::~BinaryConvolutionLayer() {} -FullyConnectedLayer::~FullyConnectedLayer() {} -ConcatLayer::~ConcatLayer() {} -SplitLayer::~SplitLayer() {} -NormLayer::~NormLayer() {} -SoftMaxLayer::~SoftMaxLayer() {} -GRNLayer::~GRNLayer() {} -MVNLayer::~MVNLayer() {} -ReLULayer::~ReLULayer() {} -ClampLayer::~ClampLayer() {} -ReLU6Layer::~ReLU6Layer() {} -EltwiseLayer::~EltwiseLayer() {} -CropLayer::~CropLayer() {} -ReshapeLayer::~ReshapeLayer() {} -TileLayer::~TileLayer() {} -ScaleShiftLayer::~ScaleShiftLayer() {} -TensorIterator::~TensorIterator() {} -RNNCellBase::~RNNCellBase() {} -LSTMCell::~LSTMCell() {} -GRUCell::~GRUCell() {} -RNNCell::~RNNCell() {} -RNNSequenceLayer::~RNNSequenceLayer() {} -PReLULayer::~PReLULayer() {} -PowerLayer::~PowerLayer() {} -BatchNormalizationLayer::~BatchNormalizationLayer() {} -GemmLayer::~GemmLayer() {} -PadLayer::~PadLayer() {} -GatherLayer::~GatherLayer() {} -StridedSliceLayer::~StridedSliceLayer() {} -ShuffleChannelsLayer::~ShuffleChannelsLayer() {} -DepthToSpaceLayer::~DepthToSpaceLayer() {} -SpaceToDepthLayer::~SpaceToDepthLayer() {} -SpaceToBatchLayer::~SpaceToBatchLayer() {} -BatchToSpaceLayer::~BatchToSpaceLayer() {} -SparseFillEmptyRowsLayer::~SparseFillEmptyRowsLayer() {} -SparseSegmentReduceLayer::~SparseSegmentReduceLayer() {} -ExperimentalSparseWeightedReduceLayer::~ExperimentalSparseWeightedReduceLayer() {} -SparseToDenseLayer::~SparseToDenseLayer() {} -BucketizeLayer::~BucketizeLayer() {} -ReverseSequenceLayer::~ReverseSequenceLayer() {} -OneHotLayer::~OneHotLayer() {} -RangeLayer::~RangeLayer() {} -FillLayer::~FillLayer() {} -SelectLayer::~SelectLayer() {} -BroadcastLayer::~BroadcastLayer() {} -QuantizeLayer::~QuantizeLayer() {} -MathLayer::~MathLayer() {} -ReduceLayer::~ReduceLayer() {} -TopKLayer::~TopKLayer() {} -UniqueLayer::~UniqueLayer() {} -NonMaxSuppressionLayer::~NonMaxSuppressionLayer() {} -ScatterUpdateLayer::~ScatterUpdateLayer() {} -ScatterElementsUpdateLayer::~ScatterElementsUpdateLayer() {} -ExperimentalDetectronPriorGridGeneratorLayer::~ExperimentalDetectronPriorGridGeneratorLayer() {} -ExperimentalDetectronGenerateProposalsSingleImageLayer::~ExperimentalDetectronGenerateProposalsSingleImageLayer() {} -ExperimentalDetectronTopKROIs::~ExperimentalDetectronTopKROIs() {} diff --git a/src/plugins/intel_gna/legacy/src/ie_layers_internal.cpp b/src/plugins/intel_gna/legacy/src/ie_layers_internal.cpp deleted file mode 100644 index 250c7f9222e..00000000000 --- a/src/plugins/intel_gna/legacy/src/ie_layers_internal.cpp +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ie_layers_internal.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace InferenceEngine { - -template -int getKernel(const Layer& layer, size_t i) { - if (layer._dilation.size() > i && layer._dilation[i]) - return (layer._kernel[i] - 1) * layer._dilation[i] + 1; - return layer._kernel[i]; -} - -template <> -int getKernel(const PoolingLayer& layer, size_t i) { - return layer._kernel[i]; -} - -template -Paddings getPaddingsInternal(const Layer& layer) { - std::string errorPrefix = "Failed to calculate padding for " + layer.type + ": "; - try { - const std::map& params = layer.params; - const std::vector& insData = layer.insData; - auto it = params.find("auto_pad"); - if (it != params.end()) { - if (it->second == "valid") { - return {PropertyVector(layer._kernel.size(), 0u), - PropertyVector(layer._kernel.size(), 0u)}; - } else { - if ((insData.size() > 3 || insData.empty()) && layer.type != "DeformableConvolution") - IE_THROW() << "number of inputs should be in range [1, 3]"; - if ((insData.size() > 4 || insData.empty()) && layer.type == "DeformableConvolution") - IE_THROW() << "number of inputs should be in range [2, 4]"; - auto firstInput = insData[0].lock(); - if (!firstInput) - IE_THROW() << "input is empty"; - auto shape = firstInput->getTensorDesc().getDims(); - auto shape_size = shape.size(); - if (shape_size < 4 || shape_size > 5) - IE_THROW() << "input shape must be 4D or 5D"; - - std::vector shapes; - shapes.push_back(static_cast(shape[shape_size - 1])); - shapes.push_back(static_cast(shape[shape_size - 2])); - if (shape_size > 4) - shapes.push_back(static_cast(shape[shape_size - 3])); - - PropertyVector pad_begin, pad_end; - - bool same_upper = it->second == "same_upper"; - bool same_lower = it->second == "same_lower"; - bool is_deconv = (layer.type == "Deconvolution"); - - for (size_t i = 0; i < layer._kernel.size(); i++) { - int PA = 0; - int kernel = getKernel(layer, i); - - int stride = layer._stride.size() > i ? layer._stride[i] : 1; - int sh = shapes[i]; - if (is_deconv) - sh *= stride; - - int rm = sh % stride; - if (rm == 0) { - PA = std::max(kernel - stride, 0); - } else { - PA = std::max(kernel - rm, 0); - } - float p_begin = PA * 0.5f, p_end = PA - p_begin; - - if (same_upper) { - p_begin = std::floor(p_begin); - p_end = std::ceil(p_end); - } else if (same_lower) { - p_begin = std::ceil(p_begin); - p_end = std::floor(p_end); - } - pad_begin.insert(i, static_cast(p_begin)); - pad_end.insert(i, static_cast(p_end)); - } - - return {pad_begin, pad_end}; - } - } - return {layer._padding, layer._pads_end}; - } catch (const InferenceEngine::Exception& iee) { - IE_THROW() << errorPrefix << iee.what(); - } -} - -class PaddingsUpdater { - std::reference_wrapper pad; - -public: - explicit PaddingsUpdater(Paddings& pad) : pad(pad) {} - template - typename std::enable_if::value, bool>::type operator()(T& layer) const { - pad.get() = getPaddingsInternal(*layer); - return true; - } - bool operator()(CNNLayer* layer) const { - IE_THROW() << "padding calculation for layer: " << layer->name << "(" << layer->type << ") unsupported"; - } -}; - -Paddings getPaddingsImpl(const CNNLayer& layer) { - Paddings actual; - details::visitActualLayer(std::tuple(), - layer, - PaddingsUpdater(actual)); - return actual; -} - -int getNumIteration(const TensorIterator& tensorIterator) { - using PortMap = TensorIterator::PortMap; - const auto isIterable = [](const PortMap& rule) { - return rule.axis != -1; - }; - const auto getNumIterations = [](const PortMap& rule, const DataPtr& iterableData) -> int { - if (iterableData == nullptr) { - IE_THROW() << ": Iteration over an invalid data object (null pointer dereference)"; - } - const auto& dimensions = iterableData->getDims(); - - const auto axis = rule.axis; - if (axis < 0 || static_cast(axis) >= dimensions.size()) { - IE_THROW() << R"(: Invalid "axis" value in an iteration component: )" << rule.axis - << ", dimensions number = " << dimensions.size() << " (out of range)"; - } - const auto space = dimensions[axis]; - const int start = static_cast((rule.start < 0 ? (space + 1) : 0) + rule.start); - const int end = static_cast((rule.end < 0 ? (space + 1) : 0) + rule.end); - - const auto stride = rule.stride; - if (stride == 0) { - IE_THROW() << R"(: Invalid "stride" value in an iteration component: )" << rule.stride - << " (infinite loop)"; - } - const auto step = std::abs(stride); - - const auto src = stride < 0 ? end : start; - const auto dst = stride < 0 ? start : end; - const auto length = dst - src; - if (src < 0 || src >= dst || dst > static_cast(space) || length < step) { - IE_THROW() << R"(: Invalid "start"/"stride"/"end" values in an iteration component)" - << ": \"start\" = " << rule.start << ", \"stride\" = " << rule.stride - << ", \"end\" = " << rule.end; - } - - if (length % step != 0) { - IE_THROW() << ": Each iteration must be the same size: length (" << length << ") is not divisible by step (" - << step << ")"; - } - - return static_cast(length / step); - }; - - int numIterations = 1; - bool isDefault = true; - for (const auto& rule : tensorIterator.input_port_map) { - if (!isIterable(rule)) { - continue; - } - - if (rule.from < 0 || rule.from >= static_cast(tensorIterator.insData.size())) { - IE_THROW() << R"(: Invalid "from" value: "from" = )" << rule.from - << " inputs number = " << tensorIterator.insData.size() << " (out of range)"; - } - - const auto currentNumIterations = getNumIterations(rule, tensorIterator.insData[rule.from].lock()); - if (isDefault) { - isDefault = false; - numIterations = currentNumIterations; - } else if (numIterations != currentNumIterations) { - IE_THROW() << ": There are at least two different iterations numbers: " << numIterations << " and " - << currentNumIterations; - } - } - - for (const auto& rule : tensorIterator.output_port_map) { - if (!isIterable(rule)) { - continue; - } - - if (rule.from < 0 || rule.from >= static_cast(tensorIterator.outData.size())) { - IE_THROW() << R"(: Invalid "from" value: "from" = )" << rule.from - << " inputs number = " << tensorIterator.outData.size() << " (out of range)"; - } - - const auto currentNumIterations = getNumIterations(rule, tensorIterator.outData[rule.from]); - if (isDefault) { - isDefault = false; - numIterations = currentNumIterations; - } else if (numIterations != currentNumIterations) { - IE_THROW() << ": There are at least two different iterations numbers: " << numIterations << " and " - << currentNumIterations; - } - } - - return numIterations; -} - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/ie_legacy_itt.hpp b/src/plugins/intel_gna/legacy/src/ie_legacy_itt.hpp deleted file mode 100644 index 4c96cba1b5d..00000000000 --- a/src/plugins/intel_gna/legacy/src/ie_legacy_itt.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief Defines openvino domains for tracing - * @file ie_legacy_itt.hpp - */ - -#pragma once - -#include - -namespace InferenceEngine { -namespace itt { -namespace domains { -OV_ITT_DOMAIN(IELegacy); -OV_ITT_DOMAIN(IELegacy_LT); -} // namespace domains -} // namespace itt -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/ie_util_internal.cpp b/src/plugins/intel_gna/legacy/src/ie_util_internal.cpp deleted file mode 100644 index 67eb2cb9e10..00000000000 --- a/src/plugins/intel_gna/legacy/src/ie_util_internal.cpp +++ /dev/null @@ -1,581 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ie_util_internal.hpp" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "caseless.hpp" -#include "cnn_network_ngraph_impl.hpp" -#include "ie_legacy_itt.hpp" -#include "ie_ngraph_utils.hpp" -#include "legacy/cnn_network_impl.hpp" -#include "legacy/details/ie_cnn_network_tools.h" -#include "legacy/graph_tools.hpp" -#include "legacy/net_pass.h" -#include "precision_utils.h" - -using std::string; - -namespace InferenceEngine { - -using namespace details; - -DataPtr cloneData(const InferenceEngine::Data& source) { - auto cloned = std::make_shared(source); - if (cloned != nullptr) { - getCreatorLayer(cloned).reset(); - getInputTo(cloned).clear(); - } - return cloned; -} - -namespace { -template -CNNLayerPtr layerCloneImpl(const CNNLayer* source) { - auto layer = dynamic_cast(source); - if (nullptr != layer) { - auto newLayer = std::make_shared(*layer); - newLayer->_fusedWith = nullptr; - newLayer->outData.clear(); - newLayer->insData.clear(); - return std::static_pointer_cast(newLayer); - } - return nullptr; -} - -/* Make this function explicit for TensorIterator layer - * because of specific handling of the body field */ -template <> -CNNLayerPtr layerCloneImpl(const CNNLayer* source) { - auto layer = dynamic_cast(source); - if (nullptr != layer) { - auto newLayer = std::make_shared(*layer); - newLayer->_fusedWith = nullptr; - newLayer->outData.clear(); - newLayer->insData.clear(); - - newLayer->body = NetPass::CopyTIBody(newLayer->body); - - return std::static_pointer_cast(newLayer); - } - return nullptr; -} - -} // namespace - -CNNLayerPtr clonelayer(const CNNLayer& source) { - using fptr = CNNLayerPtr (*)(const CNNLayer*); - // Most derived layers must go first in this list - static const fptr cloners[] = {&layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl, - &layerCloneImpl}; - for (auto cloner : cloners) { - auto cloned = cloner(&source); - if (nullptr != cloned) { - return cloned; - } - } - assert(!"All layers derived from CNNLayer so we must never get here"); - return nullptr; // Silence "control may reach end of non-void function" warning -} - -CNNNetwork cloneNetwork(const CNNNetwork& network) { - OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::IELegacy_LT, "cloneNetwork"); - - if (network.getFunction()) { - return InferenceEngine::details::cloneNetwork(network); - } - - IE_SUPPRESS_DEPRECATED_START - return CNNNetwork(InferenceEngine::cloneNet(network)); - IE_SUPPRESS_DEPRECATED_END -} - -details::CNNNetworkImplPtr cloneNet(const CNNNetwork& network) { - OV_ITT_SCOPED_TASK(itt::domains::IELegacy, "cloneNet(CNNNetwork)"); - IE_ASSERT(network.getFunction() == nullptr); - - std::vector layers; - details::CNNNetworkIterator i(network); - while (i != details::CNNNetworkIterator()) { - layers.push_back(*i); - i++; - } - - // copy of the network - details::CNNNetworkImplPtr net = cloneNet(layers); - // going over output layers and aligning output ports and outputs - OutputsDataMap outputs = network.getOutputsInfo(); - OutputsDataMap outputInfo; - net->getOutputsInfo(outputInfo); - for (auto o : outputs) { - auto it = outputInfo.find(o.first); - if (it != outputInfo.end()) { - outputInfo.erase(it); - } else { - net->addOutput(o.first); - } - } - // remove output ports which unconnected with outputs - for (auto o : outputInfo) { - net->removeOutput(o.first); - } - net->setName(network.getName()); - - InputsDataMap externalInputsData = network.getInputsInfo(); - InputsDataMap clonedInputs; - net->getInputsInfo(clonedInputs); - for (auto&& it : externalInputsData) { - auto inp = clonedInputs.find(it.first); - if (inp != clonedInputs.end() && nullptr != inp->second) { - inp->second->setPrecision(it.second->getPrecision()); - inp->second->getPreProcess() = it.second->getPreProcess(); - } - } - - return net; -} - -details::CNNNetworkImplPtr cloneNet(const std::vector& layers) { - OV_ITT_SCOPED_TASK(itt::domains::IELegacy, "cloneNet(std::vector)"); - auto net = std::make_shared(); - - // Src to cloned data map - std::unordered_map dataMap; - // Cloned to src data map - std::unordered_map clonedDataMap; - std::vector clonedDatas; - - auto createDataImpl = [&](const InferenceEngine::DataPtr& data) { - assert(nullptr != data); - if (!contains(dataMap, data)) { - auto clonedData = cloneData(*data); - dataMap[data] = clonedData; - clonedDataMap[clonedData] = data; - clonedDatas.push_back(clonedData); - net->getData(clonedData->getName()) = clonedData; - return clonedData; - } - return dataMap[data]; - }; - - auto cloneLayerImpl = [&](const CNNLayer& srcLayer) { - CNNLayerPtr clonedLayer = clonelayer(srcLayer); - clonedLayer->_fusedWith = nullptr; - // We will need to reconstruct all connections in new graph - clonedLayer->outData.clear(); - clonedLayer->insData.clear(); - net->addLayer(clonedLayer); - return clonedLayer; - }; - - for (auto&& srcLayer : layers) { - CNNLayerPtr clonedLayer = cloneLayerImpl(*srcLayer); - for (auto&& src : srcLayer->insData) { - auto data = src.lock(); - auto clonedData = createDataImpl(data); - - string inputName; - // Find input name - for (auto&& inp : getInputTo(data)) { - if (srcLayer == inp.second) { - inputName = inp.first; - break; - } - } - assert(!inputName.empty()); - getInputTo(clonedData).insert({inputName, clonedLayer}); - clonedLayer->insData.push_back(clonedData); - } - - for (auto&& data : srcLayer->outData) { - auto clonedData = createDataImpl(data); - getCreatorLayer(clonedData) = clonedLayer; - clonedLayer->outData.push_back(clonedData); - for (auto&& inp : getInputTo(data)) { - auto layer = inp.second; - // TODO(amalyshe) is it the best place to check priorbox and remove - // such edge from outputs? - if (std::find(layers.begin(), layers.end(), layer) == layers.end() && - !(CaselessEq()(layer->type, "priorbox") || - CaselessEq()(layer->type, "PriorBoxClustered"))) { - net->addOutput(data->getName()); - break; - } - } - } - } - - for (auto&& data : clonedDatas) { - auto layer = getCreatorLayer(data).lock(); - // create an artificial input layer because logic in some algorithms rely - // on existence of these layers in the network - if (nullptr == layer) { - assert(contains(clonedDataMap, data)); - auto originalData = clonedDataMap[data]; - assert(nullptr != originalData); - - if (auto originalLayer = getCreatorLayer(originalData).lock()) { - if (CaselessEq()(originalLayer->type, "input") || - CaselessEq()(originalLayer->type, "const") || - CaselessEq()(originalLayer->type, "memory")) { - layer = cloneLayerImpl(*originalLayer); - layer->outData.push_back(data); - getCreatorLayer(data) = layer; - } - } - - if (nullptr == layer) { - LayerParams params = {data->getName(), std::string("Input"), data->getPrecision()}; - layer = std::make_shared(params); - // this place should be transactional - layer->outData.push_back(data); - getCreatorLayer(data) = layer; - net->addLayer(layer); - } - } - if (CaselessEq()(layer->type, "input")) { - auto input = std::make_shared(); - input->setInputData(data); - net->setInputInfo(input); - } - } - - net->resolveOutput(); - - return net; -} - -struct NodePrinter { - enum FILL_COLOR { DATA, SUPPORTED_LAYER, UNSOPPORTED_LAYER }; - - std::unordered_set printed_data; - std::unordered_set printed_layers; - std::ostream& out; - - printer_callback layer_cb; - - explicit NodePrinter(std::ostream& os, printer_callback cb) : out(os), layer_cb(std::move(cb)) {} - - bool isPrinted(const CNNLayerPtr& layer) { - return static_cast(printed_layers.count(layer.get())); - } - - bool isPrinted(const DataPtr& datum) { - return static_cast(printed_data.count(datum.get())); - } - - string colorToStr(FILL_COLOR color) { - switch (color) { - case DATA: - return "#FCF6E3"; - case SUPPORTED_LAYER: - return "#D9EAD3"; - case UNSOPPORTED_LAYER: - return "#F4CCCC"; - default: - return "#FFFFFF"; - } - } - - string formatSize_(const std::vector& spatialDims) { - string result; - if (spatialDims.empty()) - return result; - result = std::to_string(spatialDims[0]); - for (auto dim : spatialDims) { - result += "x" + std::to_string(dim); - } - return result; - } - - string cleanNodeName_(string node_name) const { - // remove dot and dash symbols from node name. It is incorrectly displayed in xdot - node_name.erase(remove(node_name.begin(), node_name.end(), '.'), node_name.end()); - std::replace(node_name.begin(), node_name.end(), '-', '_'); - std::replace(node_name.begin(), node_name.end(), ':', '_'); - return node_name; - } - - void printLayerNode(const CNNLayerPtr& layer) { - auto node_name = "layer_" + cleanNodeName_(layer->name); - printed_layers.insert(layer.get()); - - ordered_properties printed_properties; - - ordered_properties node_properties = {{"shape", "box"}, - {"style", "filled"}, - {"fillcolor", colorToStr(SUPPORTED_LAYER)}}; - - auto type = layer->type; - printed_properties.emplace_back("type", type); - - if (type == "Convolution") { - auto* conv = dynamic_cast(layer.get()); - - if (conv != nullptr) { - unsigned int depth = conv->_out_depth, group = conv->_group; - - printed_properties.emplace_back( - "kernel size", - formatSize_({&(conv->_kernel[0]), &(conv->_kernel[conv->_kernel.size() - 1])})); - printed_properties.emplace_back("output depth", std::to_string(depth)); - printed_properties.emplace_back("group", std::to_string(group)); - printed_properties.emplace_back( - "padding begin", - formatSize_({&(conv->_padding[0]), &(conv->_padding[conv->_padding.size() - 1])})); - printed_properties.emplace_back( - "padding end", - formatSize_({&(conv->_pads_end[0]), &(conv->_pads_end[conv->_pads_end.size() - 1])})); - printed_properties.emplace_back( - "strides", - formatSize_({&(conv->_stride[0]), &(conv->_stride[conv->_stride.size() - 1])})); - printed_properties.emplace_back( - "dilations", - formatSize_({&(conv->_dilation[0]), &(conv->_dilation[conv->_dilation.size() - 1])})); - } - } else if (type == "Pooling") { - auto* pool = dynamic_cast(layer.get()); - - if (pool != nullptr) { - printed_properties.emplace_back( - "window size", - formatSize_({&(pool->_kernel[0]), &(pool->_kernel[pool->_kernel.size() - 1])})); - printed_properties.emplace_back( - "padding begin", - formatSize_({&(pool->_padding[0]), &(pool->_padding[pool->_padding.size() - 1])})); - printed_properties.emplace_back( - "padding end", - formatSize_({&(pool->_pads_end[0]), &(pool->_pads_end[pool->_pads_end.size() - 1])})); - printed_properties.emplace_back( - "strides", - formatSize_({&(pool->_stride[0]), &(pool->_stride[pool->_stride.size() - 1])})); - } - } else if (type == "ReLU") { - auto* relu = dynamic_cast(layer.get()); - - if (relu != nullptr) { - float negative_slope = relu->negative_slope; - - if (negative_slope != 0.0f) - printed_properties.emplace_back("negative_slope", CNNLayer::ie_serialize_float(negative_slope)); - } - } else if (type == "Eltwise") { - auto* eltwise = dynamic_cast(layer.get()); - - if (eltwise != nullptr) { - std::string operation; - - if (eltwise->_operation == EltwiseLayer::Sum) - operation = "Sum"; - else if (eltwise->_operation == EltwiseLayer::Prod) - operation = "Prod"; - else if (eltwise->_operation == EltwiseLayer::Max) - operation = "Max"; - else if (eltwise->_operation == EltwiseLayer::Sub) - operation = "Sub"; - else if (eltwise->_operation == EltwiseLayer::Min) - operation = "Min"; - else if (eltwise->_operation == EltwiseLayer::Div) - operation = "Div"; - else if (eltwise->_operation == EltwiseLayer::Squared_diff) - operation = "Squared_diff"; - else if (eltwise->_operation == EltwiseLayer::Equal) - operation = "Equal"; - else if (eltwise->_operation == EltwiseLayer::Not_equal) - operation = "Not_equal"; - else if (eltwise->_operation == EltwiseLayer::Less) - operation = "Less"; - else if (eltwise->_operation == EltwiseLayer::Less_equal) - operation = "Less_equal"; - else if (eltwise->_operation == EltwiseLayer::Greater) - operation = "Greater"; - else if (eltwise->_operation == EltwiseLayer::Greater_equal) - operation = "Greater_equal"; - else if (eltwise->_operation == EltwiseLayer::Logical_NOT) - operation = "Logical_NOT"; - else if (eltwise->_operation == EltwiseLayer::Logical_AND) - operation = "Logical_AND"; - else if (eltwise->_operation == EltwiseLayer::Logical_OR) - operation = "Logical_OR"; - else if (eltwise->_operation == EltwiseLayer::Logical_XOR) - operation = "Logical_XOR"; - else if (eltwise->_operation == EltwiseLayer::Floor_mod) - operation = "Floor_mod"; - else if (eltwise->_operation == EltwiseLayer::Pow) - operation = "Pow"; - else if (eltwise->_operation == EltwiseLayer::Mean) - operation = "Mean"; - - printed_properties.emplace_back("operation", operation); - } - } - - if (layer_cb != nullptr) { - layer_cb(layer, printed_properties, node_properties); - } - - printNode(node_name, layer->name, node_properties, printed_properties); - } - - void printDataNode(const std::shared_ptr& data) { - auto node_name = "data_" + cleanNodeName_(data->getName()); - printed_data.insert(data.get()); - - ordered_properties printed_properties; - ordered_properties node_properties = {{"shape", "ellipse"}, - {"style", "filled"}, - {"fillcolor", colorToStr(DATA)}}; - - std::stringstream dims_ss; - size_t idx = data->getTensorDesc().getDims().size(); - dims_ss << '['; - for (auto& dim : data->getTensorDesc().getDims()) { - dims_ss << dim << ((--idx) != 0u ? ", " : ""); - } - dims_ss << ']'; - - printed_properties.emplace_back("dims", dims_ss.str()); - printed_properties.emplace_back("precision", data->getPrecision().name()); - - std::stringstream ss; - ss << data->getTensorDesc().getLayout(); - printed_properties.emplace_back("layout", ss.str()); - printed_properties.emplace_back("name", data->getName()); - if (getCreatorLayer(data).lock() != nullptr) - printed_properties.emplace_back("creator layer", getCreatorLayer(data).lock()->name); - printNode(node_name, data->getName(), node_properties, printed_properties); - } - - void printNode(string const& node_name, - const string& node_title, - ordered_properties const& node_properties, - ordered_properties const& printed_properties) { - // normalization of names, removing all prohibited symbols like "/" - string nodeNameN = node_name; - std::replace(nodeNameN.begin(), nodeNameN.end(), '/', '_'); - string dataNameN = node_title; - std::replace(dataNameN.begin(), dataNameN.end(), '/', '_'); - - out << '\t' << nodeNameN << " ["; - for (auto& node_property : node_properties) { - out << node_property.first << "=\"" << node_property.second << "\", "; - } - - out << "label=\"" << node_title; - for (auto& printed_property : printed_properties) { - out << "\\n" << printed_property.first << ": " << printed_property.second; - } - out << "\"];\n"; - } - - void printEdge(const CNNLayerPtr& from_, const DataPtr& to_, bool reverse) { - auto from_name = "layer_" + cleanNodeName_(from_->name); - auto to_name = "data_" + cleanNodeName_(to_->getName()); - std::replace(from_name.begin(), from_name.end(), '/', '_'); - std::replace(to_name.begin(), to_name.end(), '/', '_'); - if (reverse) - std::swap(from_name, to_name); - out << '\t' << from_name << " -> " << to_name << ";\n"; - } -}; - -void saveGraphToDot(const InferenceEngine::CNNNetwork& network, std::ostream& out, printer_callback layer_cb) { - NodePrinter printer(out, std::move(layer_cb)); - - out << "digraph Network {\n"; - // Traverse graph and print nodes - for (const auto& layer : details::CNNNetSortTopologically(network)) { - printer.printLayerNode(layer); - - // Print output Data Object - for (auto& dataptr : layer->outData) { - if (!printer.isPrinted(dataptr)) { - printer.printDataNode(dataptr); - } - printer.printEdge(layer, dataptr, false); - } - - // Print input Data objects - for (auto& datum : layer->insData) { - auto dataptr = datum.lock(); - if (!printer.isPrinted(dataptr)) { - printer.printDataNode(dataptr); - } - printer.printEdge(layer, dataptr, true); - } - } - out << "}" << std::endl; -} - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/layer_transform.cpp b/src/plugins/intel_gna/legacy/src/layer_transform.cpp deleted file mode 100644 index 692fb49e209..00000000000 --- a/src/plugins/intel_gna/legacy/src/layer_transform.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include - -namespace InferenceEngine { - -namespace details { - -/** - * @brief checks whether type index as P has a parent among element in range I..N - * can be used only for P < I - * */ -template -struct is_base_of_any; - -// clang-format off -template -struct is_base_of_any< IBase, IDerived, Tuple, - typename std::enable_if::value, void>::type > : public std::true_type { - using base = typename std::remove_pointer::type>::type; - using derived = typename std::remove_pointer::type>::type; - - static_assert(IDerived < IBase, "cannot match parent using incorrect indices"); - static_assert(!std::is_base_of::value, "probing type is a parent of followed type"); - - // check that incoming type have parents in range I..N, and any of I..N not a child of derived type - static_assert((std::is_base_of::value || is_base_of_any::value), "parent matching failed"); -}; -// clang-format on - -// for matches any->after last -template -struct is_base_of_any= std::tuple_size::value, void>::type> - : public std::false_type {}; - -/** - * @brief check whether type ordered from child to base within given list - */ -template -struct is_types_ordered_from_child_to_base {}; - -template -struct is_types_ordered_from_child_to_base< - P, - Tuple, - typename std::enable_if

::value - 2, void>::type> { - static constexpr bool value = - is_base_of_any

::value && is_types_ordered_from_child_to_base

::value; -}; - -template -struct is_types_ordered_from_child_to_base< - P, - Tuple, - typename std::enable_if

::value - 2, void>::type> { - static constexpr bool value = is_base_of_any

::value; -}; - -static_assert( - is_types_ordered_from_child_to_base<0, AllLayers>::value, - "All layers must be topologically sorted as so for any layer, it's father appeared later in a types list"); - -} // namespace details - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/net_pass.cpp b/src/plugins/intel_gna/legacy/src/net_pass.cpp deleted file mode 100644 index ed5ae0c4ba2..00000000000 --- a/src/plugins/intel_gna/legacy/src/net_pass.cpp +++ /dev/null @@ -1,1625 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/net_pass.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "blob_factory.hpp" -#include "cnn_network_ngraph_impl.hpp" -#include "ie_legacy_itt.hpp" -#include "ie_memcpy.h" -#include "legacy/details/ie_cnn_network_tools.h" -#include "legacy/graph_tools.hpp" -#include "legacy/ie_layers_internal.hpp" -#include "precision_utils.h" - -namespace InferenceEngine { -namespace NetPass { - -template -inline bool one_of(T val, P item) { - return val == item; -} - -template -inline bool one_of(T val, P item, Args... item_others) { - return val == item || one_of(val, item_others...); -} - -/************************************************************/ -/**** TI Utils ********************************************/ -/************************************************************/ - -static std::vector getAllInputs(const std::vector& heads) { - CNNLayerSet inputLayers; - std::unordered_set allLayers; - - // define any layer connected to provided Data object (consumer or creator) - auto findConnectedLayer = [](const DataPtr& data) -> CNNLayerPtr { - auto consumerLayers = getInputTo(data); - if (!consumerLayers.empty()) - return consumerLayers.begin()->second; - - auto creator = getCreatorLayer(data).lock(); - if (creator != nullptr) - return creator; - - return nullptr; - }; - - // Define all start layers - for (const auto& data : heads) { - auto entryLayer = findConnectedLayer(data); - - if (entryLayer == nullptr) - continue; - - details::UnorderedDFS( - allLayers, - entryLayer, - [&inputLayers](const CNNLayerPtr& layer) { - if (layer->insData.empty()) { - inputLayers.insert(layer); - } - }, - false); - } - - std::vector res = heads; - // Add fake input data to point on not achievable - // layers from head (like const placeholders) - for (auto& starter : inputLayers) { - DataPtr holder(new Data(starter->name + ":input_holder", starter->precision)); - getInputTo(holder)[starter->name] = starter; - res.push_back(holder); - } - - return res; -} - -std::vector TIBodySortTopologically(const TensorIterator::Body& body) { - std::vector all_layers; - - // In case of graph with several connected component - // total entry point is a union of [inputs]U[outputs] - // All internal nodes are achievable starting from this. - auto total_entry_point = body.inputs; - total_entry_point.insert(total_entry_point.end(), body.outputs.begin(), body.outputs.end()); - - auto all_input_layers = getAllInputs(total_entry_point); - CNNNetForestDFS( - all_input_layers, - [&all_layers](const CNNLayerPtr& current) { - all_layers.push_back(current); - }, - false); - std::reverse(all_layers.begin(), all_layers.end()); - return all_layers; -} - -TensorIterator::Body CopyTIBody(const TensorIterator::Body& body, std::string suffix) { - struct NoneStruct {}; - auto cp = [&](CNNLayerPtr lp) { - return injectData(lp); - }; - - const auto all_orig = TIBodySortTopologically(body); - - std::unordered_map old2new_l; - for (const auto& orig : all_orig) { - old2new_l[orig.get()] = cp(orig); - } - - std::unordered_map old2new_d; - for (auto& in : body.inputs) { - auto new_data = std::make_shared(*in.get()); - for (auto& to : getInputTo(new_data)) - to.second = old2new_l[to.second.get()]; - - old2new_d[in.get()] = new_data; - } - - for (const auto& old : all_orig) { - auto& new_one = old2new_l[old.get()]; - // remap output data - for (size_t i = 0; i < old->outData.size(); i++) { - auto old_data = old->outData[i]; - auto new_data = new_one->outData[i]; - getCreatorLayer(new_data) = CNNLayerWeakPtr(new_one); - old2new_d[old_data.get()] = new_data; - - for (auto& to : getInputTo(new_data)) - to.second = old2new_l[to.second.get()]; - } - // remap input data - for (size_t i = 0; i < old->insData.size(); i++) { - auto old_data = old->insData[i].lock(); - auto new_data = old2new_d.at(old_data.get()); - new_one->insData[i] = new_data; - } - } - - // Add suffix - if (!suffix.empty()) { - for (auto& kvp : old2new_l) { - auto layer = kvp.second; - auto old_name = layer->name; - layer->name += suffix; - for (auto& ins : layer->insData) { - getInputTo(ins.lock()).erase(old_name); - getInputTo(ins.lock())[layer->name] = layer; - } - } - for (auto& kvp : old2new_d) - kvp.second->setName(kvp.second->getName() + suffix); - } - - TensorIterator::Body res; - for (auto& in : body.inputs) { - auto found = old2new_d.find(in.get()); - IE_ASSERT(found != old2new_d.end()); - res.inputs.emplace_back(found->second); - } - - for (auto& out : body.outputs) { - auto found = old2new_d.find(out.get()); - IE_ASSERT(found != old2new_d.end()); - res.outputs.emplace_back(found->second); - } - - // Fake holder. - // The graph itself is a shared_ptr set where parent holds child. - // Res.inputs vector hold head of graph and all nodes should be - // achievable for oriented search started from that. But place - // const holder has no input and cannot be achieved. So we need - // to hold then in other way. - // - // Let's add one more Data object which has no representation in - // original network. It will hold all unreachable const placeholder - // nodes. - // - std::unordered_set already_on_hold; - for (auto& in : res.inputs) { - // fake holder Data should have UNSPECIFIED precision - if (in->getPrecision() == Precision::UNSPECIFIED) { - for (const auto& kvp : getInputTo(in)) { - already_on_hold.emplace(kvp.second); - } - } - } - std::vector to_hold; - for (auto& kvp : old2new_l) { - auto layer = kvp.second; - // layer has no parent Data object and is not on hold - if (layer->insData.empty() && !already_on_hold.count(layer)) - to_hold.emplace_back(layer); - } - if (!to_hold.empty()) { - // detect existing holder or create new one - if (res.inputs.back()->getPrecision() != Precision::UNSPECIFIED || res.inputs.back()->getDims().size() != 0) { - res.inputs.emplace_back(new Data("const_holder", Precision::UNSPECIFIED)); - } - - auto holder = res.inputs.back(); - for (auto layer : to_hold) { - getInputTo(holder)[layer->name] = layer; - } - } - return res; -} - -/************************************************************/ -/**** TI rule helpers *************************************/ -/************************************************************/ - -inline bool is_full_ranged(const TensorIterator::PortMap& rule, const DataPtr& data) { - if (!data) - IE_THROW() << "Internal error. data == nullptr"; - - if (rule.axis == -1 || !one_of(rule.stride, 1, -1)) - return false; - - auto& shape = data->getDims(); - int size = static_cast(shape[rule.axis]); - - int begin = rule.start >= 0 ? rule.start : size + rule.start + 1; - int end = rule.end >= 0 ? rule.end : size + rule.end + 1; - - return (rule.stride == 1) ? begin == 0 && end == size : begin == size && end == 0; -} - -using RuleSet = std::vector; -using RuleClassSet = std::tuple; - -/** - * @brief Helper to split port mapping rules to three group - * - * first_class - which has iteration component - * second_class - which has no iteration and there are no backedge connection to the same port - * third_class - which has no iteration and has corresponding backedge - * - * @param ti TensorIterator layer to analyze - * @return tuple with three classes of port map rule - */ -static RuleClassSet classifyInputRules(const TensorIterator& ti) { - RuleSet first_class_rules, second_class_rules, third_class_rules; - - std::set ports_with_backedge; - for (const auto& back_edge : ti.back_edges) - ports_with_backedge.insert(back_edge.to); - - for (const auto& rule : ti.input_port_map) { - if (rule.axis != -1) - first_class_rules.push_back(rule); - - else if (!ports_with_backedge.count(rule.to)) - second_class_rules.push_back(rule); - - else - third_class_rules.push_back(rule); - } - return RuleClassSet{first_class_rules, second_class_rules, third_class_rules}; -} - -static RuleClassSet classifyOutputRules(const TensorIterator& ti) { - RuleSet first_class_rules, second_class_rules, third_class_rules; - - std::set ports_with_backedge; - for (const auto& back_edge : ti.back_edges) - ports_with_backedge.insert(back_edge.from); - - for (const auto& rule : ti.output_port_map) { - if (rule.axis != -1) - first_class_rules.push_back(rule); - - else if (!ports_with_backedge.count(rule.to)) - second_class_rules.push_back(rule); - - else - third_class_rules.push_back(rule); - } - return RuleClassSet{first_class_rules, second_class_rules, third_class_rules}; -} - -/** - * Merge slave connections into master data - * - * @param master - * @param slave - */ -static void CombineData(DataPtr& master, DataPtr& slave) { - for (auto& kvp : getInputTo(slave)) { - auto& slave_layer = kvp.second; - for (auto& slv_ins_wptr : slave_layer->insData) { - auto slv_ins = slv_ins_wptr.lock(); - // Replace slave ptr with master - if (slv_ins == slave) - slv_ins_wptr = master; - } - getInputTo(master)[slave_layer->name] = slave_layer; - } -} - -/** - * Preserve output data name and update output data map of the network - * - * @param in_data name to update - * @param out_data name to preserve - * @param net output data map to update with in_data - */ -template -void SaveOutputDataName(InferenceEngine::DataPtr in_data, InferenceEngine::DataPtr out_data, NET& net) { - // TODO: update outputs of the network if out_data was output - if (getInputTo(out_data).empty()) { - auto data_name = out_data->getName(); - in_data->setName(data_name); - } -} - -/** - * void SaveOutputDataName(InferenceEngine::DataPtr in_data, InferenceEngine::DataPtr out_data, NET &net), where - * NET = CNNNetwork - */ -static void SaveOutputDataName(InferenceEngine::DataPtr in_data, InferenceEngine::DataPtr out_data, CNNNetwork& net) { - if (getInputTo(out_data).empty()) { - InferenceEngine::OutputsDataMap outputs_data_map = net.getOutputsInfo(); - auto out_data_name = out_data->getName(); - in_data->setName(out_data_name); - if (outputs_data_map.count(out_data_name)) { - auto parent_layer_ptr = getCreatorLayer(in_data).lock(); - IE_ASSERT(parent_layer_ptr != nullptr); - auto parent_layer_name = parent_layer_ptr->name; - size_t in_data_out_index = 0; - for (size_t ind = 0; ind < parent_layer_ptr->outData.size(); ++ind) { - if (parent_layer_ptr->outData[ind] == in_data) { - in_data_out_index = ind; - } - } - net.addOutput(parent_layer_name, in_data_out_index); - } - } -} - -/** - * Remove layer form graph - * May be applied only for inplace layer. One input, one output, - * with same tensor descriptors. - * - * @param layer to remove from graph - */ -template -void RemoveLayer(CNNLayerPtr& layer, NET& net) { - IE_ASSERT(layer->insData.size() == 1); - IE_ASSERT(layer->outData.size() == 1); - - auto in_data = layer->input(); - auto out_data = layer->outData[0]; - - IE_ASSERT(in_data->getTensorDesc() == out_data->getTensorDesc()); - auto& input_to_map = getInputTo(in_data); - auto self_found = std::find_if(input_to_map.begin(), - input_to_map.end(), - [&layer](const std::pair& kvp) { - return kvp.second == layer; - }); - IE_ASSERT(self_found != input_to_map.end()); - // detach layer from input data - input_to_map.erase(self_found); - - // transfer output connections into parent data - CombineData(in_data, out_data); - - // save name for output data and update network output - SaveOutputDataName(in_data, out_data, net); -} - -/************************************************************/ -/**** Converter Passes ************************************/ -/************************************************************/ - -static std::string cell_name(RNNSequenceLayer::CellType type) { - std::string res; - switch (type) { - case RNNSequenceLayer::LSTM: - res = "LSTM"; - break; - case RNNSequenceLayer::GRU: - case RNNSequenceLayer::GRU_LBR: - res = "GRU"; - break; - case RNNSequenceLayer::RNN: - res = "RNN"; - break; - } - return res; -} - -template -bool convertToRNNSeq(CNNLayerPtr cur, const N& net) { - if (cur->type != "TensorIterator") - return true; - - auto ti = std::dynamic_pointer_cast(cur); - IE_ASSERT(ti) << "Cannot cast object with type TensorIterator to TensorIterator object"; - - auto all_body_layers = TIBodySortTopologically(ti->body); - - // Check if body is: squeeze -> lstm_cell -> unsqueeze - if (all_body_layers.size() != 3 || all_body_layers[0]->type != "Reshape" || - !one_of(all_body_layers[1]->type, "GRUCell", "RNNCell", "LSTMCell") || all_body_layers[2]->type != "Reshape") - return false; - - auto rsp1 = std::dynamic_pointer_cast(all_body_layers[0]); - auto cell = std::dynamic_pointer_cast(all_body_layers[1]); - auto rsp2 = std::dynamic_pointer_cast(all_body_layers[2]); - - IE_ASSERT(rsp1); - IE_ASSERT(cell); - IE_ASSERT(rsp2); - - size_t NS = (cell->cellType == RNNSequenceLayer::LSTM) ? 2 : 1; // number of states - - IE_ASSERT(cell->insData.size() == NS + 1); // {data, state1, [state2]} - IE_ASSERT(cell->outData.size() == NS); // {state1, [state2]} - - auto outData0InputsTo = getInputTo(cell->outData[0]); - if (getCreatorLayer(cell->insData[0].lock()).lock() != rsp1 || outData0InputsTo.empty() || - outData0InputsTo.begin()->second != rsp2) - return false; - - // Check port mapping - auto _indx_in = [&](const std::vector& scope, const DataPtr& data) { - size_t indx = static_cast(std::find(scope.begin(), scope.end(), data) - scope.begin()); - return indx == scope.size() ? -1 : indx; - }; - - int in_dt_idx = static_cast(_indx_in(ti->body.inputs, rsp1->insData[0].lock())); - int in_hs_idx = static_cast(_indx_in(ti->body.inputs, cell->insData[1].lock())); - int in_cs_idx = NS == 2 ? static_cast(_indx_in(ti->body.inputs, cell->insData[2].lock())) : -1; - - int out_dt_idx = static_cast(_indx_in(ti->body.outputs, rsp2->outData[0])); - int out_hs_idx = static_cast(_indx_in(ti->body.outputs, cell->outData[0])); - int out_cs_idx = NS == 2 ? static_cast(_indx_in(ti->body.outputs, cell->outData[1])) : -1; - - // indexes should be [0,1,2] : sum == 3 or [0,1,-1] : sum == 0 - int sum = (static_cast(NS) - 1) * 3; - if (in_hs_idx + in_cs_idx + in_dt_idx != sum || out_hs_idx + out_cs_idx + out_dt_idx != sum) - return false; - - std::map i2map, o2map, be2map; - for (auto& m : ti->input_port_map) - i2map[m.to] = m; - for (auto& m : ti->output_port_map) - o2map[m.to] = m; - for (auto& m : ti->back_edges) - be2map[m.to] = m; - - if (!one_of(i2map.size(), NS + 1, 1u) || !one_of(o2map.size(), NS + 1, 1u) || !one_of(be2map.size(), NS)) - return false; - - auto in_iter_rule = i2map[in_dt_idx]; - auto in_iter_data = ti->insData[in_iter_rule.from].lock(); - - auto out_iter_rule = o2map[out_dt_idx]; - auto out_iter_data = ti->outData[out_iter_rule.from]; - - // TI iterates only for full range of tensor - if (!is_full_ranged(in_iter_rule, in_iter_data) || !is_full_ranged(out_iter_rule, out_iter_data)) - return false; - - // supported only same axis and strides for in/out data tensors - if (in_iter_rule.axis != out_iter_rule.axis || in_iter_rule.stride != out_iter_rule.stride) - return false; - - // supported only firs and second dim for LSTM-Sequence - if (!one_of(in_iter_rule.axis, 0, 1)) - return false; - - bool no_init_state = i2map.size() == 1; - bool no_last_state = o2map.size() == 1; - - if (!no_init_state && (i2map[in_hs_idx].axis != -1 || (NS == 2 && i2map[in_cs_idx].axis != -1))) - return false; - if (!no_last_state && (o2map[out_hs_idx].axis != -1 || (NS == 2 && o2map[out_cs_idx].axis != -1))) - return false; - - std::vector i_order{i2map[in_dt_idx].from}; - if (!no_init_state) - i_order.push_back(i2map[in_hs_idx].from); - if (!no_init_state && NS == 2) - i_order.push_back(i2map[in_cs_idx].from); - - std::vector o_order{o2map[out_dt_idx].from}; - if (!no_last_state) - o_order.push_back(o2map[out_hs_idx].from); - if (!no_last_state && NS == 2) - o_order.push_back(o2map[out_cs_idx].from); - - // need swap an i/o ports if it is not in natural order - std::string name = cell->name + "_sequence"; - std::string type = cell_name(cell->cellType) + "Sequence"; - - auto rnn = std::make_shared(LayerParams{name, type, cell->precision}); - rnn->axis = in_iter_rule.axis; - rnn->direction = in_iter_rule.stride == 1 ? RNNSequenceLayer::FWD : RNNSequenceLayer::BWD; - - // copy base RNN cell fields - rnn->cellType = cell->cellType; - rnn->_weights = cell->_weights; - rnn->_biases = cell->_biases; - rnn->blobs["weights"] = rnn->_weights; - rnn->blobs["biases"] = rnn->_biases; - rnn->blobs = cell->blobs; - rnn->activations = cell->activations; - rnn->activation_alpha = cell->activation_alpha; - rnn->activation_beta = cell->activation_beta; - rnn->hidden_size = cell->hidden_size; - rnn->clip = cell->clip; - - for (int i : i_order) { - auto in_data = ti->insData[i].lock(); - getInputTo(in_data).erase(ti->name); - getInputTo(in_data)[rnn->name] = rnn; - rnn->insData.push_back(in_data); - } - for (int i : o_order) { - rnn->outData.push_back(ti->outData[i]); - getCreatorLayer(rnn->outData.back()) = rnn; - } - - return true; -} - -static bool unrollTI(CNNLayerPtr cur, CNNNetwork& net) { - IE_SUPPRESS_DEPRECATED_START - auto& icnnnet = static_cast(net); - IE_SUPPRESS_DEPRECATED_END - auto inet = dynamic_cast(&icnnnet); - IE_ASSERT(inet != nullptr); - - if (cur->type != "TensorIterator") - return true; - - auto ti = std::dynamic_pointer_cast(cur); - IE_ASSERT(ti) << "Cannot cast object with type TensorIterator to TensorIterator object"; - - int num = getNumIteration(*ti); // -1 means inconsistent TI - if (num == -1) - return false; // TODO: better to throw exception - - const auto& body = ti->body; - - std::vector body_list(num); - for (int i = 0; i < num; i++) { - // copy with additional suffix to each object name - body_list[i] = CopyTIBody(body, ":" + std::to_string(i)); - - auto holder = body_list[i].inputs.back(); - if (holder->getPrecision() == Precision::UNSPECIFIED) { - for (auto kvp : getInputTo(holder)) { - inet->addLayer(kvp.second); - } - } - } - - RuleSet first_class, second_class, third_class; - std::tie(first_class, second_class, third_class) = classifyInputRules(*ti); - - /** Clean links on TI */ - for (auto& ins : ti->insData) - getInputTo(ins.lock()).erase(ti->name); - for (auto& outs : ti->outData) - getCreatorLayer(outs).reset(); - - /** FIRST class comes */ - for (size_t i = 0; i < first_class.size(); i++) { - auto& rule = first_class[i]; - auto in_data = ti->insData[rule.from].lock(); - - std::string name = ti->name + ":in_split_" + std::to_string(i); - auto split = std::make_shared(LayerParams{name, "Split", cur->precision}); - split->_axis = rule.axis; - split->outData.resize(num); - split->insData.emplace_back(in_data); - getInputTo(in_data)[split->name] = split; - - for (int j = 0; j < num; j++) { - auto body_idx = rule.stride == 1 ? j : num - 1 - j; - auto& chunk = body_list[body_idx].inputs[rule.to]; - getCreatorLayer(chunk) = split; - split->outData[j] = chunk; - } - } - - /** SECOND class come on */ - for (const auto& rule : second_class) { - auto in_data = ti->insData[rule.from].lock(); - - for (int j = 0; j < num; j++) { - auto& chunk = body_list[j].inputs[rule.to]; - CombineData(in_data, chunk); - } - } - - /** BACK EDGES that's your time */ - for (const auto& rule : ti->back_edges) { - for (int i = 1; i < num; i++) { - auto& from_data = body_list[i - 1].outputs[rule.from]; - auto& to_data = body_list[i].inputs[rule.to]; - CombineData(from_data, to_data); - } - } - - /** THIRD class end up */ - for (const auto& rule : third_class) { - // first iteration - auto from_data = ti->insData[rule.from].lock(); - auto& to_data = body_list[0].inputs[rule.to]; - CombineData(from_data, to_data); - } - - /** And the same actions for outputs connections */ - std::tie(first_class, second_class, third_class) = classifyOutputRules(*ti); - - /** FIRST class comes */ - for (size_t i = 0; i < first_class.size(); i++) { - auto& rule = first_class[i]; - auto out_data = ti->outData[rule.from]; - - if (num == 1) { - auto to_data = body_list[0].outputs[rule.to]; - auto parent = getCreatorLayer(to_data).lock(); - std::replace(parent->outData.begin(), parent->outData.end(), to_data, out_data); - getCreatorLayer(out_data) = parent; - CombineData(out_data, to_data); - continue; - } - - std::string name = ti->name + ":out_concat_" + std::to_string(i); - auto concat = std::make_shared(LayerParams{name, "Concat", cur->precision}); - concat->_axis = rule.axis; - concat->insData.resize(num); - concat->outData.emplace_back(out_data); - getCreatorLayer(out_data) = concat; - - for (int j = 0; j < num; j++) { - auto body_idx = rule.stride == 1 ? j : num - 1 - j; - auto& chunk = body_list[body_idx].outputs[rule.to]; - getInputTo(chunk)[concat->name] = concat; - concat->insData[j] = chunk; - } - } - - /** SECOND class come on */ - for (const auto& rule : second_class) { - auto out_data = ti->outData[rule.from]; - - for (int j = 0; j < num; j++) { - auto& chunk = body_list[j].outputs[rule.to]; - CombineData(chunk, out_data); - } - } - - /** THIRD class end up */ - for (const auto& rule : third_class) { - // first iteration - auto& from_data = ti->outData[rule.from]; - auto& to_data = body_list[num - 1].outputs[rule.to]; - - auto parent = getCreatorLayer(to_data).lock(); - std::replace(parent->outData.begin(), parent->outData.end(), to_data, from_data); - getCreatorLayer(from_data) = parent; - - CombineData(from_data, to_data); - } - return true; -} - -/************************************************************/ -/**** Builder helpers ************************************/ -/************************************************************/ - -static CNNLayerPtr _concat(std::string name, Precision prc, SizeVector dims, int num) { - auto res = std::make_shared(LayerParams{name, "Concat", prc}); - res->_axis = 1; - - res->insData.resize(num); - res->outData.resize(1); - - auto out_data = DataPtr(new Data(name, TensorDesc{prc, dims, TensorDesc::getLayoutByDims(dims)})); - getCreatorLayer(out_data) = res; - - res->outData[0] = out_data; - return res; -} - -static CNNLayerPtr _split(std::string name, Precision prc, SizeVector dims, int num) { - auto res = std::make_shared(LayerParams{name, "Split", prc}); - res->_axis = 1; - res->params["axis"] = std::to_string(res->_axis); - - res->insData.resize(1); - res->outData.resize(num); - - for (int i = 0; i < num; i++) { - auto out_data = DataPtr( - new Data(name + "_part_" + std::to_string(i), TensorDesc{prc, dims, TensorDesc::getLayoutByDims(dims)})); - getCreatorLayer(out_data) = res; - - res->outData[i] = out_data; - } - return res; -} - -static CNNLayerPtr _fc(std::string name, Precision prc, SizeVector dims, Blob::Ptr& W, Blob::Ptr& B) { - auto res = std::make_shared(LayerParams{name, "FullyConnected", prc}); - - res->_weights = W; - res->_biases = B; - res->_out_num = static_cast(dims[1]); - res->blobs["weights"] = W; - res->blobs["biases"] = B; - res->params["out-size"] = std::to_string(dims[1]); - - res->insData.resize(1); - res->outData.resize(1); - - auto out_data = DataPtr(new Data(name, TensorDesc{prc, dims, TensorDesc::getLayoutByDims(dims)})); - getCreatorLayer(out_data) = res; - - res->outData[0] = out_data; - return res; -} - -static std::shared_ptr _act(std::string name, Precision prc, SizeVector dims, std::string type) { - auto res = std::make_shared(LayerParams{name, type, prc}); - - res->params["type"] = type; - - res->insData.resize(1); - res->outData.resize(1); - - auto out_data = DataPtr(new Data(name, TensorDesc{prc, dims, TensorDesc::getLayoutByDims(dims)})); - getCreatorLayer(out_data) = res; - - res->outData[0] = out_data; - return res; -} - -static CNNLayerPtr _pwr(std::string name, Precision prc, SizeVector dims, float scale, float shift) { - auto res = std::make_shared(LayerParams{name, "Power", prc}); - - res->power = 1.0; - res->scale = scale; - res->offset = shift; - res->params["power"] = CNNLayer::ie_serialize_float(res->power); - res->params["scale"] = CNNLayer::ie_serialize_float(res->scale); - res->params["shift"] = CNNLayer::ie_serialize_float(res->offset); - - res->insData.resize(1); - res->outData.resize(1); - - auto out_data = DataPtr(new Data(name, TensorDesc{prc, dims, TensorDesc::getLayoutByDims(dims)})); - getCreatorLayer(out_data) = res; - - res->outData[0] = out_data; - return res; -} - -static CNNLayerPtr _eltw(std::string name, Precision prc, SizeVector dims, std::string type) { - auto res = std::make_shared(LayerParams{name, "Eltwise", prc}); - - res->params["operation"] = type; - res->_operation = type == "sum" ? EltwiseLayer::Sum : EltwiseLayer::Prod; - - res->insData.resize(2); - res->outData.resize(1); - - auto out_data = DataPtr(new Data(name, TensorDesc{prc, dims, TensorDesc::getLayoutByDims(dims)})); - getCreatorLayer(out_data) = res; - - res->outData[0] = out_data; - return res; -} - -static std::shared_ptr _resh(std::string name, Precision prc, SizeVector dims) { - auto res = std::make_shared(LayerParams{name, "Reshape", prc}); - - res->insData.resize(1); - res->outData.resize(1); - - auto out_data = DataPtr(new Data(name, TensorDesc{prc, dims, TensorDesc::getLayoutByDims(dims)})); - getCreatorLayer(out_data) = res; - - res->outData[0] = out_data; - return res; -} - -static std::shared_ptr _cell(std::string name, - Precision prc, - SizeVector data_dims, - SizeVector state_dims, - RNNSequenceLayer::CellType type) { - std::shared_ptr res; - size_t NS = 1; - switch (type) { - case RNNSequenceLayer::LSTM: - res = std::make_shared(LayerParams{name, "LSTMCell", prc}); - NS = 2; - break; - case RNNSequenceLayer::GRU: - case RNNSequenceLayer::GRU_LBR: - res = std::make_shared(LayerParams{name, "GRUCell", prc}); - break; - case RNNSequenceLayer::RNN: - res = std::make_shared(LayerParams{name, "RNNCell", prc}); - break; - } - - res->cellType = type; - res->insData.resize(1 + NS); - res->outData.resize(NS); - - auto out_data = - DataPtr(new Data(name + ":out_data", TensorDesc{prc, data_dims, TensorDesc::getLayoutByDims(data_dims)})); - getCreatorLayer(out_data) = res; - res->outData[0] = out_data; - - for (size_t i = 0; i < NS; i++) { - auto out_state = DataPtr(new Data(name + ":out_state_" + std::to_string(i), - TensorDesc{prc, state_dims, TensorDesc::getLayoutByDims(state_dims)})); - getCreatorLayer(out_state) = res; - res->outData[i] = out_state; - } - - return res; -} - -static std::shared_ptr _ti(std::string name, Precision prc, size_t NS) { - auto res = std::make_shared(LayerParams{name, "TensorIterator", prc}); - - res->insData.resize(1 + NS); - res->outData.resize(1 + NS); - - return res; -} - -static void _link(CNNLayerPtr src, CNNLayerPtr dst, size_t src_port = 0, size_t dst_port = 0) { - auto data = src->outData[src_port]; - getInputTo(data)[dst->name] = dst; - dst->insData[dst_port] = data; -} - -static void _link(DataPtr& data, CNNLayerPtr dst, size_t dst_port = 0) { - getInputTo(data)[dst->name] = dst; - dst->insData[dst_port] = data; -} - -/** Link nodes with clipping data if required (clip_val != 0.0) */ -static void _link_with_clip(CNNLayerPtr src, - CNNLayerPtr dst, - const float clip_val, - size_t src_port = 0, - size_t dst_port = 0) { - if (clip_val == 0.0f) { - _link(src, dst, src_port, dst_port); - } else { - auto clip_name = dst->name + "_clip"; - auto clip_prc = dst->precision; - auto clip_shape = src->outData[src_port]->getTensorDesc().getDims(); - auto clip = _act(clip_name, clip_prc, clip_shape, "clamp"); - clip->params["min"] = CNNLayer::ie_serialize_float(-clip_val); - clip->params["max"] = CNNLayer::ie_serialize_float(clip_val); - clip->min_value = -clip_val; - clip->max_value = clip_val; - - _link(src, clip, src_port, 0); - _link(clip, dst, 0, dst_port); - } -} -static Blob::Ptr wrap_as_tensor(Blob::Ptr src, SizeVector dims) { - auto res = make_blob_with_precision( - TensorDesc{src->getTensorDesc().getPrecision(), dims, TensorDesc::getLayoutByDims(dims)}, - src->buffer()); - IE_ASSERT(src->size() == res->size()); - return res; -} - -static Blob::Ptr make_region_copy(Blob::Ptr src, SizeVector region, SizeVector offset) { - IE_ASSERT(region.size() == offset.size()); - IE_ASSERT(region.size() == src->getTensorDesc().getDims().size()); - - auto res = make_plain_blob(src->getTensorDesc().getPrecision(), region); - res->allocate(); - - size_t elem_size = src->getTensorDesc().getPrecision().size(); - auto src_ptr = src->buffer().as(); - auto dst_ptr = res->buffer().as(); - - auto& dd = src->getTensorDesc().getDims(); - SizeVector src_dims{1, 1, 1}; - std::copy(dd.begin(), dd.end(), src_dims.end() - dd.size()); - - SizeVector dims{1, 1, 1}; - std::copy(region.begin(), region.end(), dims.end() - region.size()); - - SizeVector off{0, 0, 0}; - std::copy(offset.begin(), offset.end(), off.end() - offset.size()); - - const auto D1 = dims[0]; - const auto D2 = dims[1]; - const auto D3 = dims[2]; - const auto off1 = off[0]; - const auto off2 = off[1]; - const auto off3 = off[2]; - const auto str1 = src_dims[1] * src_dims[2]; - const auto str2 = src_dims[2]; - - for (size_t d1 = 0; d1 < D1; d1++) - for (size_t d2 = 0; d2 < D2; d2++) { - auto off_src = (off1 + d1) * str1 + (off2 + d2) * str2 + off3; - auto off_dst = d1 * D2 * D3 + d2 * D3; - ie_memcpy(dst_ptr + off_dst * elem_size, res->byteSize(), src_ptr + off_src * elem_size, D3 * elem_size); - } - - return res; -} - -static bool unrollRNNCellBody(CNNLayerPtr cur) { - if (cur->type != "RNNCell") - return true; - - auto cell = std::dynamic_pointer_cast(cur); - IE_ASSERT(cell) << "Cannot cast object with type ***Cell to WeightableLayer object"; - - auto name = cell->name; - - auto in_data = cell->insData[0].lock(); - auto in_h_state = cell->insData[1].lock(); - auto out_h_state = cell->outData[0]; - - auto d_dims = in_data->getTensorDesc().getDims(); - auto s_dims = in_h_state->getTensorDesc().getDims(); - - size_t N = d_dims[0]; - size_t D = d_dims[1]; - size_t S = s_dims[1]; - - auto prc = cell->precision; - - /** Release links on TI */ - for (auto& ins : cell->insData) - getInputTo(ins.lock()).erase(cell->name); - for (auto& outs : cell->outData) - getCreatorLayer(outs).reset(); - - // operations - auto concat = _concat(name + ":concat", prc, {N, D + S}, 2); - auto fc = _fc(name + ":fc", prc, {N, S}, cell->_weights, cell->_biases); - auto act = _act(name + ":act", prc, {N, S}, cell->activations[0]); - - // Connection - _link(in_data, concat, 0); - _link(in_h_state, concat, 1); - _link(concat, fc); - _link_with_clip(fc, act, cell->clip); - - // Output - act->outData[0] = out_h_state; - getCreatorLayer(out_h_state) = act; - - return true; -} - -static bool unrollLSTMCellBody(CNNLayerPtr cur) { - if (cur->type != "LSTMCell") - return true; - - auto cell = std::dynamic_pointer_cast(cur); - IE_ASSERT(cell) << "Cannot cast object with type ***Cell to WeightableLayer object"; - - auto name = cell->name; - - auto in_data = cell->insData[0].lock(); - auto in_h_state = cell->insData[1].lock(); - auto in_c_state = cell->insData[2].lock(); - auto out_h_state = cell->outData[0]; - auto out_c_state = cell->outData[1]; - - auto d_dims = in_data->getTensorDesc().getDims(); - auto s_dims = in_h_state->getTensorDesc().getDims(); - - size_t N = d_dims[0]; - size_t D = d_dims[1]; - size_t S = s_dims[1]; - size_t G = 4; - - auto prc = cell->precision; - - /** Release links on TI */ - for (auto& ins : cell->insData) - getInputTo(ins.lock()).erase(cell->name); - for (auto& outs : cell->outData) - getCreatorLayer(outs).reset(); - - // operations - auto concat = _concat(name + ":concat", prc, {N, D + S}, 2); - auto split = _split(name + ":split", prc, {N, S}, static_cast(G)); - auto fc = _fc(name + ":fc", prc, {N, S * G}, cell->_weights, cell->_biases); - - const std::string _f = cell->activations[0], _g = cell->activations[1], _h = cell->activations[2]; - - auto act_f = _act(name + ":act_f", prc, {N, S}, _f); - auto act_i = _act(name + ":act_i", prc, {N, S}, _f); - auto act_c = _act(name + ":act_c", prc, {N, S}, _g); - auto act_o = _act(name + ":act_o", prc, {N, S}, _f); - auto act_x = _act(name + ":act_x", prc, {N, S}, _h); - - auto mul_ic = _eltw(name + ":mul_ic", prc, {N, S}, "mul"); - auto mul_f = _eltw(name + ":mul_f", prc, {N, S}, "mul"); - auto sum = _eltw(name + ":sum", prc, {N, S}, "sum"); - auto mul = _eltw(name + ":mul", prc, {N, S}, "mul"); - - // Connection - _link(in_data, concat, 0); - _link(in_h_state, concat, 1); - _link(concat, fc); - - _link_with_clip(fc, split, cell->clip); - - _link(split, act_f, 0, 0); - _link(split, act_i, 1, 0); - _link(split, act_c, 2, 0); - _link(split, act_o, 3, 0); - - _link(act_i, mul_ic, 0, 0); - _link(act_c, mul_ic, 0, 1); - - _link(act_f, mul_f, 0, 0); - _link(in_c_state, mul_f, 1); - - _link(mul_f, sum, 0, 0); - _link(mul_ic, sum, 0, 1); - - _link(sum, act_x); - - _link(act_x, mul, 0, 0); - _link(act_o, mul, 0, 1); - - // Output - mul->outData[0] = out_h_state; - getCreatorLayer(out_h_state) = mul; - - CombineData(out_c_state, sum->outData[0]); - sum->outData[0] = out_c_state; - getCreatorLayer(out_c_state) = sum; - - return true; -} - -static bool unrollGRUCellBody(CNNLayerPtr cur, bool linear_before_reset = false) { - if (cur->type != "GRUCell") - return true; - - auto cell = std::dynamic_pointer_cast(cur); - IE_ASSERT(cell) << "Cannot cast object with type ***Cell to WeightableLayer object"; - - auto name = cell->name; - - auto in_data = cell->insData[0].lock(); - auto in_h_state = cell->insData[1].lock(); - auto out_h_state = cell->outData[0]; - - auto d_dims = in_data->getTensorDesc().getDims(); - auto s_dims = in_h_state->getTensorDesc().getDims(); - - size_t N = d_dims[0]; - size_t D = d_dims[1]; - size_t S = s_dims[1]; - - // Split weights UR and O gates. Original gates are URO - size_t bG = linear_before_reset ? 4 : 3; - auto orig_W = wrap_as_tensor(cell->_weights, {3, S, D + S}); - auto orig_B = wrap_as_tensor(cell->_biases, {bG, S}); - - auto ur_W = make_region_copy(orig_W, {2, S, D + S}, {0, 0, 0}); - auto o_W = make_region_copy(orig_W, {1, S, D + S}, {2, 0, 0}); - auto ur_B = make_region_copy(orig_B, {2, S}, {0, 0}); - auto o_B = make_region_copy(orig_B, {1, S}, {2, 0}); - - auto prc = cell->precision; - - /** Release links on TI */ - for (auto& ins : cell->insData) - getInputTo(ins.lock()).erase(cell->name); - for (auto& outs : cell->outData) - getCreatorLayer(outs).reset(); - - // operations - auto concat = _concat(name + ":concat", prc, {N, D + S}, 2); - auto split = _split(name + ":split", prc, {N, S}, 2); - auto fc_ur = _fc(name + ":fc_ur", prc, {N, S * 2}, ur_W, ur_B); - - const std::string _f = cell->activations[0], _g = cell->activations[1]; - - auto act_ur = _act(name + ":act_ur", prc, {N, 2 * S}, _f); - auto act_o = _act(name + ":act_o", prc, {N, S}, _g); - - auto mul_u = _eltw(name + ":mul_u", prc, {N, S}, "mul"); - auto mul_r = _eltw(name + ":mul_r", prc, {N, S}, "mul"); - - auto pwr_m1 = _pwr(name + ":pwr", prc, {N, S}, -1.0, 1.0); - - auto mul = _eltw(name + ":mul", prc, {N, S}, "mul"); - auto sum = _eltw(name + ":sum", prc, {N, S}, "sum"); - - /** - * - zt = _f(Wz*[Xt + Ht-1] + Bz) - * - rt = _f(Wr*[Xt + Ht-1] + Br) - * - ht = _g(Wh*[Xt + (rt (.) Ht-1)] + Bh) # default, when linear_before_reset = 0 - * - ht = _g(Whw*Xt + Bhw + (rt (.) (Whr*Ht-1 + Bhr))) # when linear_before_reset != 0 - * - Ht = (1 - zt) (.) ht + zt (.) Ht-1 - */ - _link(in_data, concat, 0); - _link(in_h_state, concat, 1); - _link(concat, fc_ur); - _link_with_clip(fc_ur, act_ur, cell->clip); - _link(act_ur, split); // split[0] - zt, split[1] - rt - - if (linear_before_reset) { - auto lbr_B = wrap_as_tensor(orig_B, {4, S}); - - auto whw_W = make_region_copy(o_W, {1, S, D}, {0, 0, 0}); - auto whr_W = make_region_copy(o_W, {1, S, S}, {0, 0, D}); - auto whw_B = make_region_copy(lbr_B, {1, S}, {2, 0}); - auto whr_B = make_region_copy(lbr_B, {1, S}, {3, 0}); - - auto fc_whr = _fc(name + ":fc_whr", prc, {N, S}, whr_W, whr_B); - auto fc_whw = _fc(name + ":fc_whw", prc, {N, S}, whw_W, whw_B); - auto sum_h = _eltw(name + ":sum_h", prc, {N, S}, "sum"); - - _link(in_h_state, fc_whr); // Whr*Ht-1 + Bhr - _link(fc_whr, mul_r, 0); // - _link(split, mul_r, 1, 1); // rt (.) (Whr*Ht-1 + Bhr) - _link(in_data, fc_whw); // Whw*Xt + Bhw - _link(fc_whw, sum_h, 0, 0); // - _link(mul_r, sum_h, 0, 1); // Whw*Xt + Bhw + (rt (.) (Whr*Ht-1 + Bhr)) - _link_with_clip(sum_h, act_o, cell->clip); // _g(Whw*Xt + Bhw + (rt (.) (Whr*Ht-1 + Bhr))) - } else { - auto fc_wh = _fc(name + ":fc_o", prc, {N, S}, o_W, o_B); - auto concat_h = _concat(name + ":concat_h", prc, {N, D + S}, 2); - - _link(split, mul_r, 1, 0); // - _link(in_h_state, mul_r, 1); // rt (.) Ht-1 - _link(in_data, concat_h, 0); // - _link(mul_r, concat_h, 0, 1); // [Xt + (rt (.) Ht-1)] - _link(concat_h, fc_wh); // Wh*[Xt + (rt (.) Ht-1)] + Bh - _link_with_clip(fc_wh, act_o, cell->clip); // _g(Wh*[Xt + (rt (.) Ht-1)] + Bh) - } - - _link(split, pwr_m1, 0, 0); // 1 - zt - _link(act_o, mul, 0, 0); // - _link(pwr_m1, mul, 0, 1); // (1 - zt) (.) ht - _link(split, mul_u, 0, 0); // - _link(in_h_state, mul_u, 1); // zt (.) Ht-1 - _link(mul, sum, 0, 0); // - _link(mul_u, sum, 0, 1); // (1 - zt) (.) ht + zt (.) Ht-1 - - // Output - sum->outData[0] = out_h_state; - getCreatorLayer(out_h_state) = sum; - - return true; -} - -static bool unrollCell(CNNLayerPtr cur) { - auto cell = std::dynamic_pointer_cast(cur); - switch (cell->cellType) { - case RNNCellBase::LSTM: - return unrollLSTMCellBody(cur); - case RNNCellBase::GRU: - return unrollGRUCellBody(cur); - case RNNCellBase::GRU_LBR: - return unrollGRUCellBody(cur, true); - case RNNCellBase::RNN: - return unrollRNNCellBody(cur); - } - return false; -} - -static bool unrollSeq(CNNLayerPtr cur) { - if (!one_of(cur->type, "LSTMSequence", "GRUSequence", "RNNSequence")) - return true; - - auto seq = std::dynamic_pointer_cast(cur); - IE_ASSERT(seq) << "Cannot cast object with type ***Sequence to RNNSequenceLayer object"; - - auto name = seq->name; - - auto in_data = seq->insData[0].lock(); - auto in_h_state = seq->insData[1].lock(); - auto out_data = seq->outData[0]; - - auto in_d_dims = in_data->getTensorDesc().getDims(); - auto state_dims = in_h_state->getTensorDesc().getDims(); - auto out_d_dims = out_data->getTensorDesc().getDims(); - - const int axis = seq->axis; - const auto direct = seq->direction; - const auto prc = seq->precision; - - /** Release links on Seq */ - for (auto& ins : seq->insData) - getInputTo(ins.lock()).erase(seq->name); - for (auto& outs : seq->outData) - getCreatorLayer(outs).reset(); - - /** Body subgraph*/ - auto in_d_body_dims = in_d_dims; - in_d_body_dims[axis] = 1; - - auto in_d_body_squeeze_dims = in_d_dims; - in_d_body_squeeze_dims.erase(in_d_body_squeeze_dims.begin() + axis); - - auto out_d_body_dims = out_d_dims; - out_d_body_dims[axis] = 1; - - auto out_d_body_squeeze_dims = out_d_dims; - out_d_body_squeeze_dims.erase(out_d_body_squeeze_dims.begin() + axis); - - auto body_in_data = DataPtr( - new Data(name + ":data_in", TensorDesc{prc, in_d_body_dims, TensorDesc::getLayoutByDims(in_d_body_dims)})); - - auto resh1 = _resh(name + ":resh1", prc, in_d_body_squeeze_dims); - auto cell = _cell(name + ":cell", prc, out_d_body_squeeze_dims, state_dims, seq->cellType); - auto resh2 = _resh(name + ":resh2", prc, out_d_body_dims); - - _link(body_in_data, resh1); - _link(resh1, cell); - _link(cell, resh2); - - cell->_weights = seq->_weights; - cell->_biases = seq->_biases; - cell->blobs["weights"] = cell->_weights; - cell->blobs["biases"] = cell->_biases; - cell->hidden_size = seq->hidden_size; - cell->clip = seq->clip; - cell->activations = seq->activations; - cell->activation_alpha = seq->activation_alpha; - cell->activation_beta = seq->activation_beta; - - const size_t NS = cell->outData.size(); // num of state - - /** TI layer */ - auto ti = _ti(name + ":ti", prc, NS); - _link(in_data, ti, 0); - - ti->outData[0] = out_data; - getCreatorLayer(out_data) = ti; - - ti->body.inputs.push_back(body_in_data); - ti->body.outputs.push_back(resh2->outData[0]); - - int start = direct == RNNSequenceLayer::FWD ? 0 : -1; - int end = direct == RNNSequenceLayer::FWD ? -1 : 0; - int step = direct == RNNSequenceLayer::FWD ? 1 : -1; - ti->input_port_map.push_back({0, 0, axis, step, start, end, 1}); - ti->output_port_map.push_back({0, 0, axis, step, start, end, 1}); - - for (size_t i = 0; i < NS; i++) { - auto in_state = seq->insData[1 + i].lock(); - _link(in_state, ti, 1 + i); - - auto out_state = seq->outData[1 + i]; - ti->outData[1 + i] = out_state; - getCreatorLayer(out_state) = ti; - - auto body_in_state = DataPtr(new Data(name + ":state_in_" + std::to_string(i), - TensorDesc{prc, state_dims, TensorDesc::getLayoutByDims(state_dims)})); - - _link(body_in_state, cell, 1 + i); - - ti->body.inputs.push_back(body_in_state); - ti->body.outputs.push_back(cell->outData[i]); - - const int ii = 1 + static_cast(i); - ti->input_port_map.push_back({ii, ii, -1, 0, 0, 0, 0}); - ti->output_port_map.push_back({ii, ii, -1, 0, 0, 0, 0}); - ti->back_edges.push_back({ii, ii, -1, 0, 0, 0, 0}); - } - - return true; -} - -/************************************************************/ -/**** Converter API ***************************************/ -/************************************************************/ - -template -std::vector TopolSort(const N& net); - -template <> -std::vector TopolSort(const CNNNetwork& net) { - return details::CNNNetSortTopologically(net); -} - -template <> -std::vector TopolSort(const TensorIterator::Body& net) { - return details::CNNSubnetSortTopologically({net.inputs, net.outputs}); -} - -template <> -std::vector TopolSort(const details::CNNSubnet& net) { - return details::CNNSubnetSortTopologically(net); -} - -static void restore_net_consistency(CNNNetwork& net) { - IE_SUPPRESS_DEPRECATED_START - auto& icnnnet = static_cast(net); - // ilavreno: - // issues with RTTI on OSX once we compiled inference_engine_legacy as STATIC library - // So, we use static_cast instead of dynamic_cast since we are sure that - // icnnnet is always a details::CNNNetworkImpl - auto inet = static_cast(&icnnnet); - IE_ASSERT(inet != nullptr); - // At first all layers should be available via findByName() api. - // In other words all layers should be present in internal map - for (auto& l : TopolSort(net)) { - inet->addLayer(l); - } - IE_SUPPRESS_DEPRECATED_END -} - -template -bool ApplyForAll(N& net, T action) { - auto all_layers = TopolSort(net); - bool sts = true; - - for (auto& layer : all_layers) - sts &= action(layer, net); - - return sts; -} - -template -bool ApplyForAll_if(N& net, T action, P pred) { - auto all_layers = TopolSort(net); - bool sts = true; - - for (auto& layer : all_layers) - if (pred(layer)) - sts &= action(layer); - - return sts; -} - -bool CombineRNNSeq(CNNNetwork& net) { - auto res = ApplyForAll(net, convertToRNNSeq); - restore_net_consistency(net); - return res; -} - -bool CombineRNNSeq(TensorIterator::Body& net) { - return ApplyForAll(net, convertToRNNSeq); -} - -bool UnrollTI(CNNNetwork& net) { - auto res = ApplyForAll(net, unrollTI); - restore_net_consistency(net); - return res; -} - -template -bool UnrollRNN_if_impl(NET& net, const std::function pred) { - // Filter layers by RNN specific type - auto _seq_pred = [&](CNNLayerPtr layer) { - auto rnn = std::dynamic_pointer_cast(layer); - if (!rnn) - return false; - return pred(*rnn.get()); - }; - auto _cell_pred = [&](CNNLayerPtr layer) { - auto rnn = std::dynamic_pointer_cast(layer); - if (!rnn || !one_of(rnn->type, "LSTMCell", "GRUCell", "RNNCell")) - return false; - return pred(*rnn.get()); - }; - - bool res = true; - res &= ApplyForAll_if(net, unrollSeq, _seq_pred); - res &= ApplyForAll_if(net, unrollCell, _cell_pred); - return res; -} - -bool UnrollRNN_if(CNNNetwork& net, const std::function pred) { - auto res = UnrollRNN_if_impl(net, pred); - restore_net_consistency(net); - return res; -} - -bool UnrollRNN_if(TensorIterator::Body& net, const std::function pred) { - return UnrollRNN_if_impl(net, pred); -} - -/** - * =========================== - * Precision conversion passes - * =========================== - */ - -namespace { - -template -void convertArrayPrecision(typename PrecisionTrait::value_type* dst, - const typename PrecisionTrait::value_type* src, - size_t nelem) { - using dst_type = typename PrecisionTrait::value_type; - - for (size_t i = 0; i < nelem; i++) { - dst[i] = PrecisionUtils::saturate_cast(static_cast(src[i])); - } -} - -template <> -void convertArrayPrecision(float* dst, const short* src, size_t nelem) { - PrecisionUtils::f16tof32Arrays(dst, src, nelem, 1.0f, 0.0f); -} - -template -Blob::Ptr convertBlobPrecision(const Blob::Ptr& blob) { - using from_d_type = typename PrecisionTrait::value_type; - using to_d_type = typename PrecisionTrait::value_type; - - auto tensor_desc = blob->getTensorDesc(); - Blob::Ptr new_blob = - make_shared_blob(TensorDesc{PREC_TO, tensor_desc.getDims(), tensor_desc.getLayout()}); - new_blob->allocate(); - auto target = new_blob->buffer().as(); - auto source = blob->buffer().as(); - convertArrayPrecision(target, source, blob->size()); - return new_blob; -} - -// forward declaration to use in convertLayerPrecision<>() -template -void convertPrecisionForAll(NET& net); - -template -void convertLayerPrecision(const CNNLayerPtr& layer) { - for (auto& out_data : layer->outData) { - if (PREC_FROM == out_data->getPrecision()) - out_data->setPrecision(PREC_TO); - } - for (auto& in_data : layer->insData) { - if (PREC_FROM == in_data.lock()->getPrecision()) - in_data.lock()->setPrecision(PREC_TO); - } - - if (layer->precision == PREC_FROM) - layer->precision = PREC_TO; - - if (HasInternalSubnet(layer)) { - // apply the same conversion pass for internal graph - auto layer_subnet = GetInternalSubnet(layer); - convertPrecisionForAll(layer_subnet); - } - - auto wLayer = dynamic_cast(layer.get()); - if (wLayer) { - if (wLayer->_weights && wLayer->_weights->getTensorDesc().getPrecision() == PREC_FROM) { - wLayer->_weights = convertBlobPrecision(wLayer->_weights); - } - if (wLayer->_biases && wLayer->_biases->getTensorDesc().getPrecision() == PREC_FROM) { - wLayer->_biases = convertBlobPrecision(wLayer->_biases); - } - } - - for (auto& blob : layer->blobs) { - auto& data = blob.second; - if (nullptr != data) { - if (data->getTensorDesc().getPrecision() == PREC_FROM) { - data = convertBlobPrecision(data); - } - } - } -} - -template -void RemoveConverts(NET& net, std::vector& to_remove) { - for (auto& layer : to_remove) { - RemoveLayer(layer, net); - } -} - -template <> -void RemoveConverts(CNNNetwork& net, std::vector& to_remove) { - OutputsDataMap outputs = net.getOutputsInfo(); - for (auto& layer : to_remove) { - if (!std::any_of(outputs.begin(), outputs.end(), [layer](std::pair p) { - return p.second->getName() == layer->name; - })) { - RemoveLayer(layer, net); - } - } -} - -template -void fixConvertLayers(NET& net) { - std::vector to_remove; - auto all_layers = TopolSort(net); - for (auto& layer : all_layers) { - if (layer->type == "Convert") { - auto out_precision = layer->outData[0]->getPrecision(); - auto in_precision = layer->input()->getPrecision(); - - // Restore destination_type attribute after conversion - auto found = layer->params.find("precision"); - IE_ASSERT(found != layer->params.end()); - found->second = out_precision.name(); - - // Remove convert layer if it do nothing. After type conversion pass - // some convert layers may lose actuality. - if (in_precision == out_precision) { - to_remove.push_back(layer); - } - } - } - RemoveConverts(net, to_remove); -} - -template -void convertPrecisionForAll(NET& net) { - auto all_layers = TopolSort(net); - for (auto& layer : all_layers) { - convertLayerPrecision(layer); - } - fixConvertLayers(net); -} - -} // namespace - -bool HasInternalSubnet(const CNNLayerPtr& layer) { - return layer->type == "TensorIterator" && dynamic_cast(layer.get()) != nullptr; -} - -details::CNNSubnet GetInternalSubnet(const CNNLayerPtr& layer) { - if (layer->type == "TensorIterator") { - auto ti = static_cast(layer.get()); - IE_ASSERT(ti); - return {ti->body.inputs, ti->body.outputs}; - } - return {}; -} - -void ConvertPrecision(CNNNetwork& net, Precision from, Precision to) { - OV_ITT_SCOPED_TASK(itt::domains::IELegacy, "NetPass::ConvertPrecision"); - - auto compare = getPrecisionMask(from, to); - switch (compare) { - case getPrecisionMask(Precision::U32, Precision::I32): - convertPrecisionForAll(net); - break; - case getPrecisionMask(Precision::U64, Precision::I32): - convertPrecisionForAll(net); - break; - case getPrecisionMask(Precision::I64, Precision::I32): - convertPrecisionForAll(net); - break; - case getPrecisionMask(Precision::BOOL, Precision::U8): - convertPrecisionForAll(net); - break; - case getPrecisionMask(Precision::BOOL, Precision::I32): - convertPrecisionForAll(net); - break; - case getPrecisionMask(Precision::FP16, Precision::FP32): - convertPrecisionForAll(net); - break; - case getPrecisionMask(Precision::FP64, Precision::FP32): - convertPrecisionForAll(net); - break; - case getPrecisionMask(Precision::U8, Precision::I32): - convertPrecisionForAll(net); - break; - case getPrecisionMask(Precision::U16, Precision::I32): - convertPrecisionForAll(net); - break; - case getPrecisionMask(Precision::I16, Precision::I32): - convertPrecisionForAll(net); - break; - default: - IE_THROW() << "Precision conversion from " << from << " to " << to - << " currently is not supported. You may expand precision" - " conversion pass."; - } -} - -void ConvertIOPrecision(CNNNetwork& net, Precision from, Precision to) { - InputsDataMap inputDataMap = net.getInputsInfo(); - for (auto& i : inputDataMap) { - if (i.second->getPrecision() == from) { - i.second->setPrecision(to); - } - } - - OutputsDataMap outputDataMap = net.getOutputsInfo(); - for (auto& i : outputDataMap) { - if (i.second->getPrecision() == from) { - i.second->setPrecision(to); - } - } -} - -} // namespace NetPass -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/network_serializer_v7.cpp b/src/plugins/intel_gna/legacy/src/network_serializer_v7.cpp deleted file mode 100644 index 9dca8a3cac9..00000000000 --- a/src/plugins/intel_gna/legacy/src/network_serializer_v7.cpp +++ /dev/null @@ -1,471 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "network_serializer_v7.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "caseless.hpp" -#include "cpp/ie_cnn_network.h" -#include "exec_graph_info.hpp" -#include "legacy/details/ie_cnn_network_tools.h" -#include "legacy/ie_layers.h" -#include "xml_parse_utils.h" - -namespace InferenceEngine { -namespace Serialization { - -namespace { -template -std::string arrayToIRProperty(const T& property) { - std::string sProperty; - for (size_t i = 0; i < property.size(); i++) { - sProperty = sProperty + std::to_string(property[i]) + std::string((i != property.size() - 1) ? "," : ""); - } - return sProperty; -} - -template -std::string arrayRevertToIRProperty(const T& property) { - std::string sProperty; - for (size_t i = 0; i < property.size(); i++) { - sProperty = sProperty + std::to_string(property[property.size() - i - 1]) + - std::string((i != property.size() - 1) ? "," : ""); - } - return sProperty; -} - -void UpdateStdLayerParams(const CNNLayer::Ptr& layer) { - auto layerPtr = layer.get(); - auto& params = layer->params; - using ::InferenceEngine::details::CaselessEq; - if (CaselessEq()(layer->type, "power")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of PowerLayer class"; - } - params["scale"] = CNNLayer::ie_serialize_float(lr->scale); - params["shift"] = CNNLayer::ie_serialize_float(lr->offset); - params["power"] = CNNLayer::ie_serialize_float(lr->power); - } else if (CaselessEq()(layer->type, "convolution") || - CaselessEq()(layer->type, "deconvolution")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of ConvolutionLayer class"; - } - params["kernel"] = arrayRevertToIRProperty(lr->_kernel); - params["pads_begin"] = arrayRevertToIRProperty(lr->_padding); - params["pads_end"] = arrayRevertToIRProperty(lr->_pads_end); - params["strides"] = arrayRevertToIRProperty(lr->_stride); - params["dilations"] = arrayRevertToIRProperty(lr->_dilation); - params["output"] = std::to_string(lr->_out_depth); - params["group"] = std::to_string(lr->_group); - } else if (CaselessEq()(layer->type, "deformable_convolution")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of DeformableConvolutionLayer class"; - } - params["kernel"] = arrayRevertToIRProperty(lr->_kernel); - params["pads_begin"] = arrayRevertToIRProperty(lr->_padding); - params["pads_end"] = arrayRevertToIRProperty(lr->_pads_end); - params["strides"] = arrayRevertToIRProperty(lr->_stride); - params["dilations"] = arrayRevertToIRProperty(lr->_dilation); - params["output"] = std::to_string(lr->_out_depth); - params["group"] = std::to_string(lr->_group); - params["deformable_group"] = std::to_string(lr->_deformable_group); - } else if (CaselessEq()(layer->type, "relu")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of ReLULayer class"; - } - if (lr->negative_slope != 0.0f) { - params["negative_slope"] = CNNLayer::ie_serialize_float(lr->negative_slope); - } - } else if (CaselessEq()(layer->type, "norm") || CaselessEq()(layer->type, "lrn")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of NormLayer class"; - } - params["alpha"] = CNNLayer::ie_serialize_float(lr->_alpha); - params["beta"] = CNNLayer::ie_serialize_float(lr->_beta); - params["local-size"] = std::to_string(lr->_size); - params["region"] = lr->_isAcrossMaps ? "across" : "same"; - } else if (CaselessEq()(layer->type, "pooling")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of PoolingLayer class"; - } - params["kernel"] = arrayRevertToIRProperty(lr->_kernel); - params["pads_begin"] = arrayRevertToIRProperty(lr->_padding); - params["pads_end"] = arrayRevertToIRProperty(lr->_pads_end); - params["strides"] = arrayRevertToIRProperty(lr->_stride); - - switch (lr->_type) { - case PoolingLayer::MAX: - params["pool-method"] = "max"; - break; - case PoolingLayer::AVG: - params["pool-method"] = "avg"; - break; - - default: - IE_THROW() << "Found unsupported pooling method: " << lr->_type; - } - } else if (CaselessEq()(layer->type, "split")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of SplitLayer class"; - } - params["axis"] = std::to_string(lr->_axis); - } else if (CaselessEq()(layer->type, "concat")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of ConcatLayer class"; - } - params["axis"] = std::to_string(lr->_axis); - } else if (CaselessEq()(layer->type, "FullyConnected") || - CaselessEq()(layer->type, "InnerProduct")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of FullyConnectedLayer class"; - } - params["out-size"] = std::to_string(lr->_out_num); - } else if (CaselessEq()(layer->type, "softmax")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of SoftMaxLayer class"; - } - params["axis"] = std::to_string(lr->axis); - } else if (CaselessEq()(layer->type, "reshape")) { - // need to add here support of flatten layer if it is created from API - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of ReshapeLayer class"; - } - params["dim"] = arrayToIRProperty(lr->shape); - } else if (CaselessEq()(layer->type, "Eltwise")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of EltwiseLayer class"; - } - - std::string op; - - switch (lr->_operation) { - case EltwiseLayer::Sum: - op = "sum"; - break; - case EltwiseLayer::Prod: - op = "prod"; - break; - case EltwiseLayer::Max: - op = "max"; - break; - case EltwiseLayer::Sub: - op = "sub"; - break; - default: - break; - } - - params["operation"] = op; - } else if (CaselessEq()(layer->type, "scaleshift")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of ScaleShiftLayer class"; - } - params["broadcast"] = std::to_string(lr->_broadcast); - } else if (CaselessEq()(layer->type, "crop")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of CropLayer class"; - } - params["axis"] = arrayToIRProperty(lr->axis); - params["offset"] = arrayToIRProperty(lr->offset); - params["dim"] = arrayToIRProperty(lr->dim); - } else if (CaselessEq()(layer->type, "tile")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of TileLayer class"; - } - params["axis"] = std::to_string(lr->axis); - params["tiles"] = std::to_string(lr->tiles); - } else if (CaselessEq()(layer->type, "prelu")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of PReLULayer class"; - } - params["channel_shared"] = std::to_string(lr->_channel_shared); - } else if (CaselessEq()(layer->type, "clamp")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of ClampLayer class"; - } - params["min"] = CNNLayer::ie_serialize_float(lr->min_value); - params["max"] = CNNLayer::ie_serialize_float(lr->max_value); - } else if (CaselessEq()(layer->type, "BatchNormalization")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of BatchNormalizationLayer class"; - } - params["epsilon"] = CNNLayer::ie_serialize_float(lr->epsilon); - } else if (CaselessEq()(layer->type, "grn")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of GRNLayer class"; - } - params["bias"] = CNNLayer::ie_serialize_float(lr->bias); - } else if (CaselessEq()(layer->type, "mvn")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of MVNLayer class"; - } - params["across_channels"] = std::to_string(lr->across_channels); - params["normalize_variance"] = std::to_string(lr->normalize); - } else if (CaselessEq()(layer->type, "LSTMCell")) { - auto* lr = dynamic_cast(layerPtr); - if (lr == nullptr) { - IE_THROW() << "Layer " << layerPtr->name << " is not instance of LSTMCell class"; - } - params["hidden_size"] = std::to_string(lr->hidden_size); - } else if (CaselessEq()(layer->type, "rnn") || - CaselessEq()(layer->type, "TensorIterator")) { - IE_THROW() << "Not covered layers for writing to IR"; - } - - if (layer->params.find("quantization_level") != layer->params.end()) { - params["quantization_level"] = layer->params["quantization_level"]; - } - - // update of weightable layers - auto* pwlayer = dynamic_cast(layerPtr); - if (pwlayer) { - if (pwlayer->_weights) { - pwlayer->blobs["weights"] = pwlayer->_weights; - } - if (pwlayer->_biases) { - pwlayer->blobs["biases"] = pwlayer->_biases; - } - } -} - -std::size_t FillXmlDoc(const InferenceEngine::CNNNetwork& network, - pugi::xml_document& doc, - const bool execGraphInfoSerialization, - const bool dumpWeights) { - const std::vector ordered = InferenceEngine::details::CNNNetSortTopologically(network); - pugi::xml_node netXml = doc.append_child("net"); - netXml.append_attribute("name").set_value(network.getName().c_str()); - - // no need to print this information for executable graph information serialization because it is not IR. - if (!execGraphInfoSerialization) { - netXml.append_attribute("version").set_value("6"); - netXml.append_attribute("batch").set_value(static_cast(network.getBatchSize())); - } - - pugi::xml_node layers = netXml.append_child("layers"); - - std::map matching; - for (size_t i = 0; i < ordered.size(); i++) { - matching[ordered[i]] = i; - } - - const std::string dataName = "data"; - size_t dataOffset = 0; - for (size_t i = 0; i < ordered.size(); ++i) { - const CNNLayerPtr node = ordered[i]; - - pugi::xml_node layer = layers.append_child("layer"); - const Precision precision = node->precision; - layer.append_attribute("name").set_value(node->name.c_str()); - layer.append_attribute("type").set_value(node->type.c_str()); - layer.append_attribute("precision").set_value(precision.name()); - layer.append_attribute("id").set_value(static_cast(i)); - - if (!execGraphInfoSerialization) { - UpdateStdLayerParams(node); - } - - const auto& params = node->params; - if (!params.empty()) { - pugi::xml_node data = layer.append_child(dataName.c_str()); - - for (const auto& it : params) { - data.append_attribute(it.first.c_str()).set_value(it.second.c_str()); - } - } - - if (!node->insData.empty()) { - pugi::xml_node input = layer.append_child("input"); - - for (size_t iport = 0; iport < node->insData.size(); iport++) { - const DataPtr d = node->insData[iport].lock(); - pugi::xml_node port = input.append_child("port"); - - port.append_attribute("id").set_value(static_cast(iport)); - - for (auto dim : d->getDims()) { - port.append_child("dim").text().set(static_cast(dim)); - } - } - } - if (!node->outData.empty()) { - pugi::xml_node output = layer.append_child("output"); - for (size_t oport = 0; oport < node->outData.size(); oport++) { - pugi::xml_node port = output.append_child("port"); - - port.append_attribute("id").set_value(static_cast(node->insData.size() + oport)); - port.append_attribute("precision").set_value(node->outData[oport]->getPrecision().name()); - - for (const auto dim : node->outData[oport]->getDims()) { - port.append_child("dim").text().set(static_cast(dim)); - } - } - } - if (dumpWeights && !node->blobs.empty()) { - auto blobsNode = layer.append_child("blobs"); - for (const auto& dataIt : node->blobs) { - if (!dataIt.second) - continue; - size_t dataSize = dataIt.second->byteSize(); - pugi::xml_node data = blobsNode.append_child(dataIt.first.c_str()); - data.append_attribute("offset").set_value(static_cast(dataOffset)); - data.append_attribute("size").set_value(static_cast(dataSize)); - data.append_attribute("precision").set_value(dataIt.second->getTensorDesc().getPrecision().name()); - - dataOffset += dataSize; - } - } - } - - pugi::xml_node edges = netXml.append_child("edges"); - - for (const auto& ord : ordered) { - const CNNLayer::Ptr node = ord; - - if (!node->outData.empty()) { - auto itFrom = matching.find(node); - if (itFrom == matching.end()) { - IE_THROW() << "Internal error, cannot find " << node->name - << " in matching container during serialization of IR"; - } - for (size_t oport = 0; oport < node->outData.size(); oport++) { - const DataPtr outData = node->outData[oport]; - for (const auto& inputTo : getInputTo(outData)) { - for (size_t iport = 0; iport < inputTo.second->insData.size(); iport++) { - if (inputTo.second->insData[iport].lock() == outData) { - auto itTo = matching.find(inputTo.second); - if (itTo == matching.end()) { - IE_THROW() << "Broken edge form layer " << node->name << " to layer " << inputTo.first - << "during serialization of IR"; - } - pugi::xml_node edge = edges.append_child("edge"); - edge.append_attribute("from-layer") - .set_value(static_cast(itFrom->second)); - edge.append_attribute("from-port") - .set_value(static_cast(oport + node->insData.size())); - - edge.append_attribute("to-layer").set_value(static_cast(itTo->second)); - edge.append_attribute("to-port").set_value(static_cast(iport)); - } - } - } - } - } - } - - return dataOffset; -} - -void SerializeBlobs(std::ostream& stream, const InferenceEngine::CNNNetwork& network) { - const std::vector ordered = InferenceEngine::details::CNNNetSortTopologically(network); - for (auto&& node : ordered) { - if (!node->blobs.empty()) { - for (const auto& dataIt : node->blobs) { - if (!dataIt.second) - continue; - const char* dataPtr = dataIt.second->buffer().as(); - size_t dataSize = dataIt.second->byteSize(); - stream.write(dataPtr, dataSize); - if (!stream.good()) { - IE_THROW() << "Error during writing blob weights"; - } - } - } - } - - InputsDataMap inputInfo = network.getInputsInfo(); - for (auto ii : inputInfo) { - const PreProcessInfo& pp = ii.second->getPreProcess(); - size_t nInChannels = pp.getNumberOfChannels(); - if (nInChannels) { - for (size_t ch = 0; ch < nInChannels; ch++) { - const PreProcessChannel::Ptr& preProcessChannel = pp[ch]; - if (preProcessChannel->meanData) { - const char* dataPtr = preProcessChannel->meanData->buffer().as(); - size_t dataSize = preProcessChannel->meanData->byteSize(); - stream.write(dataPtr, dataSize); - if (!stream.good()) { - IE_THROW() << "Error during writing mean data"; - } - } - } - } - } -} - -} // namespace - -void Serialize(const std::string& xmlPath, const std::string& binPath, const InferenceEngine::CNNNetwork& network) { - // A flag for serializing executable graph information (not complete IR) - bool execGraphInfoSerialization = false; - pugi::xml_document doc; - - const std::vector ordered = InferenceEngine::details::CNNNetSortTopologically(network); - // If first layer has perfCounter parameter set then it's executable graph info serialization. - // All other layers must also have this parameter set. - if (ordered[0]->params.find(ExecGraphInfoSerialization::PERF_COUNTER) != ordered[0]->params.end()) { - execGraphInfoSerialization = true; - for (const auto& layer : ordered) { - if (layer->params.find(ExecGraphInfoSerialization::PERF_COUNTER) == layer->params.end()) { - IE_THROW() << "Each node must have " << ExecGraphInfoSerialization::PERF_COUNTER - << " parameter set in case of executable graph info serialization"; - } - } - } - - bool dumpWeights = !execGraphInfoSerialization & !binPath.empty(); - FillXmlDoc(network, doc, execGraphInfoSerialization, dumpWeights); - - if (!doc.save_file(xmlPath.c_str())) { - IE_THROW() << "file '" << xmlPath << "' was not serialized"; - } - - if (dumpWeights) { - std::ofstream ofsBin; - ofsBin.open(binPath, std::ofstream::out | std::ofstream::binary); - if (!ofsBin.is_open()) { - IE_THROW() << "File '" << binPath << "' is not opened as out file stream"; - } - try { - SerializeBlobs(ofsBin, network); - } catch (std::exception& e) { - ofsBin.close(); - throw e; - } - ofsBin.close(); - if (!ofsBin.good()) { - IE_THROW() << "Error during '" << binPath << "' closing"; - } - } -} -} // namespace Serialization -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/network_serializer_v7.hpp b/src/plugins/intel_gna/legacy/src/network_serializer_v7.hpp deleted file mode 100644 index d88119be99b..00000000000 --- a/src/plugins/intel_gna/legacy/src/network_serializer_v7.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "compilation_context.hpp" -#include "cpp/ie_cnn_network.h" - -namespace InferenceEngine { -namespace Serialization { - -/** - * @brief Serialize network into IE IR XML file and binary weights file - * @param xmlPath Path to XML file - * @param binPath Path to BIN file - * @param network network to be serialized - */ -void Serialize(const std::string& xmlPath, const std::string& binPath, const InferenceEngine::CNNNetwork& network); - -} // namespace Serialization -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/convolution_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/convolution_ie.cpp deleted file mode 100644 index 4495c060b89..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/convolution_ie.cpp +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/convolution_ie.hpp" - -#include -#include -#include - -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; - -op::ConvolutionIE::ConvolutionIE(const Output& data_batch, - const Output& filters, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const element::Type output_type, - const size_t& group, - const PadType& auto_pad) - : Op({data_batch, filters}), - m_strides(strides), - m_dilations(dilations), - m_pads_begin(pads_begin), - m_pads_end(pads_end), - m_auto_pad(auto_pad), - m_group(group), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -op::ConvolutionIE::ConvolutionIE(const Output& data_batch, - const Output& filters, - const Output& bias, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const element::Type output_type, - const size_t& group, - const PadType& auto_pad) - : Op({data_batch, filters, bias}), - m_strides(strides), - m_dilations(dilations), - m_pads_begin(pads_begin), - m_pads_end(pads_end), - m_auto_pad(auto_pad), - m_group(group), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -// KMB compilation support -op::ConvolutionIE::ConvolutionIE(const Output& data_batch, - const Output& filters, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const size_t& group, - const PadType& auto_pad) - : Op({data_batch, filters}), - m_strides(strides), - m_dilations(dilations), - m_pads_begin(pads_begin), - m_pads_end(pads_end), - m_auto_pad(auto_pad), - m_group(group), - m_output_type(element::undefined) { - constructor_validate_and_infer_types(); -} - -// KMB compilation support -op::ConvolutionIE::ConvolutionIE(const Output& data_batch, - const Output& filters, - const Output& bias, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const size_t& group, - const PadType& auto_pad) - : Op({data_batch, filters, bias}), - m_strides(strides), - m_dilations(dilations), - m_pads_begin(pads_begin), - m_pads_end(pads_end), - m_auto_pad(auto_pad), - m_group(group), - m_output_type(element::undefined) { - constructor_validate_and_infer_types(); -} - -void op::ConvolutionIE::validate_and_infer_types() { - PartialShape data_batch_shape = get_input_partial_shape(0); - PartialShape filters_shape = get_input_partial_shape(1); - - PartialShape result_shape{PartialShape::dynamic()}; - - // In case if number of groups greater than 1 and channel dimension is dynamic we can't calculate output shape - if (m_group > 1) { - if (data_batch_shape.rank().is_dynamic() || data_batch_shape[1].is_dynamic()) { - set_output_type(0, m_output_type, result_shape); - return; - } else { - // Update channel dimension according to groups count - data_batch_shape[1] = data_batch_shape[1].get_length() / m_group; - } - } - - // we need to adjust filters_shape to reuse helpers for normal convolution - if (filters_shape.is_static() && data_batch_shape.is_static()) { - if (m_auto_pad == PadType::SAME_UPPER || m_auto_pad == PadType::SAME_LOWER) { - m_pads_begin.clear(); - m_pads_end.clear(); - auto filter_shape = filters_shape.to_shape(); - filter_shape.erase(filter_shape.begin(), filter_shape.begin() + 2); // Remove {O,I} - OPENVINO_SUPPRESS_DEPRECATED_START - infer_auto_padding(data_batch_shape.to_shape(), - filter_shape, - m_strides, - m_dilations, - m_auto_pad, - m_pads_end, - m_pads_begin); - OPENVINO_SUPPRESS_DEPRECATED_END - } - } - - OPENVINO_SUPPRESS_DEPRECATED_START - result_shape = infer_convolution_forward(this, - data_batch_shape, - Strides(m_strides.size(), 1), // dummy data dilations - m_pads_begin, - m_pads_end, - filters_shape, - m_strides, - m_dilations); - OPENVINO_SUPPRESS_DEPRECATED_END - - set_output_type(0, m_output_type, result_shape); -} - -shared_ptr op::ConvolutionIE::clone_with_new_inputs(const ngraph::OutputVector& new_args) const { - if (new_args.size() == 2) { - return make_shared(new_args.at(0), - new_args.at(1), - m_strides, - m_dilations, - m_pads_begin, - m_pads_end, - m_output_type, - m_group, - m_auto_pad); - } else if (new_args.size() == 3) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - m_strides, - m_dilations, - m_pads_begin, - m_pads_end, - m_output_type, - m_group, - m_auto_pad); - } - - OPENVINO_THROW("Unsupported number of arguments for ConvolutionIE operation"); -} - -bool op::ConvolutionIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("strides", m_strides); - visitor.on_attribute("dilations", m_dilations); - visitor.on_attribute("pads_begin", m_pads_begin); - visitor.on_attribute("pads_end", m_pads_end); - visitor.on_attribute("auto_pad", m_auto_pad); - visitor.on_attribute("group", m_group); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/crop_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/crop_ie.cpp deleted file mode 100644 index fa5736b25ed..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/crop_ie.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/crop_ie.hpp" - -#include -#include -#include - -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; - -op::CropIE::CropIE(const Output& data, - std::vector axes, - std::vector dim, - std::vector offset) - : Op({data}), - axes(axes), - dim(dim), - offset(offset) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::CropIE::clone_with_new_inputs(const OutputVector& new_args) const { - if (new_args.size() != 1) { - OPENVINO_THROW("Incorrect number of new arguments"); - } - - return make_shared(new_args.at(0), axes, dim, offset); -} - -void op::CropIE::validate_and_infer_types() { - auto input_shape = get_input_partial_shape(0).to_shape(); - NODE_VALIDATION_CHECK(this, axes.size() == dim.size(), "axes and dim needs to have same number of values"); - - NODE_VALIDATION_CHECK(this, axes.size() == offset.size(), "axes and offset needs to have same number of values"); - - ngraph::Shape output_shape(input_shape); - for (size_t i = 0; i < axes.size(); ++i) { - NODE_VALIDATION_CHECK(this, - axes[i] >= 0 && axes[i] < static_cast(output_shape.size()), - "axes should be positive and less than number of input dims"); - output_shape[axes[i]] = dim[i]; - } - - set_output_type(0, get_input_element_type(0), PartialShape(output_shape)); -} - -bool op::CropIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("axis", axes); - visitor.on_attribute("dim", dim); - visitor.on_attribute("offset", offset); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/deconvolution_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/deconvolution_ie.cpp deleted file mode 100644 index 0c1bef5d736..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/deconvolution_ie.cpp +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/deconvolution_ie.hpp" - -#include -#include -#include -#include - -#include "ngraph/opsets/opset1.hpp" -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" -#include "ov_ops/type_relaxed.hpp" - -using namespace std; -using namespace ngraph; - -op::DeconvolutionIE::DeconvolutionIE(const Output& data, - const Output& filters, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const element::Type output_type, - const size_t& group, - const PadType& auto_pad, - const CoordinateDiff& output_padding, - const std::shared_ptr& output_shape) - : Op({data, filters}), - m_strides(strides), - m_dilations(dilations), - m_pads_begin(pads_begin), - m_pads_end(pads_end), - m_auto_pad(auto_pad), - m_group(group), - m_output_padding(output_padding), - m_output_shape(output_shape), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -op::DeconvolutionIE::DeconvolutionIE(const Output& data, - const Output& filters, - const Output& bias, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const element::Type output_type, - const size_t& group, - const PadType& auto_pad, - const CoordinateDiff& output_padding, - const std::shared_ptr& output_shape) - : Op({data, filters, bias}), - m_strides(strides), - m_dilations(dilations), - m_pads_begin(pads_begin), - m_pads_end(pads_end), - m_auto_pad(auto_pad), - m_group(group), - m_output_padding(output_padding), - m_output_shape(output_shape), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -void op::DeconvolutionIE::validate_and_infer_types() { - // To calculate output shape we use opset1::GroupConvolutionBackPropData - // but before we need to reshape weights from I(G*O)YX to GIOYX - auto weights = input_value(1); - const auto weights_pshape = weights.get_partial_shape(); - if (weights_pshape.is_static()) { - auto weights_shape = weights_pshape.to_shape(); - std::vector reshape_dims(3); - reshape_dims[0] = m_group; // G - reshape_dims[1] = weights_shape[0]; // I - reshape_dims[2] = weights_shape[1] / m_group; // O - reshape_dims.insert(reshape_dims.end(), weights_shape.begin() + 2, weights_shape.end()); - weights = std::make_shared( - weights, - opset1::Constant::create(element::i64, Shape{reshape_dims.size()}, reshape_dims), - true); - } - Output conv; - if (m_output_shape) { - conv = std::make_shared>( - std::vector{element::f32, element::f32}, - std::vector{element::f32}, - ov::op::TemporaryReplaceOutputType(input_value(0), element::f32).get(), - ov::op::TemporaryReplaceOutputType(weights, element::f32).get(), - m_output_shape, - m_strides, - m_pads_begin, - m_pads_end, - m_dilations, - m_auto_pad, - m_output_padding); - } else { - conv = std::make_shared>( - std::vector{element::f32, element::f32}, - std::vector{element::f32}, - ov::op::TemporaryReplaceOutputType(input_value(0), element::f32).get(), - ov::op::TemporaryReplaceOutputType(weights, element::f32).get(), - m_strides, - m_pads_begin, - m_pads_end, - m_dilations, - m_auto_pad, - m_output_padding); - } - set_output_type(0, m_output_type, conv.get_partial_shape()); -} - -shared_ptr op::DeconvolutionIE::clone_with_new_inputs(const ngraph::OutputVector& new_args) const { - if (new_args.size() == 2) { - return make_shared(new_args.at(0), - new_args.at(1), - m_strides, - m_dilations, - m_pads_begin, - m_pads_end, - m_output_type, - m_group, - m_auto_pad, - m_output_padding, - m_output_shape); - } else if (new_args.size() == 3) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - m_strides, - m_dilations, - m_pads_begin, - m_pads_end, - m_output_type, - m_group, - m_auto_pad, - m_output_padding, - m_output_shape); - } - OPENVINO_THROW("Unexpected number of arguments"); -} - -bool op::DeconvolutionIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("strides", m_strides); - visitor.on_attribute("dilations", m_dilations); - visitor.on_attribute("pads_begin", m_pads_begin); - visitor.on_attribute("pads_end", m_pads_end); - visitor.on_attribute("group", m_group); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/eltwise.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/eltwise.cpp deleted file mode 100644 index 1d80c3f7aa6..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/eltwise.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/eltwise.hpp" - -#include -#include - -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; - -op::Eltwise::Eltwise(const Output& data1, - const Output& data2, - const ELTWISE_TYPE eltwise_type, - const element::Type output_type) - : Op({data1, data2}), - eltwise_type(eltwise_type), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::Eltwise::clone_with_new_inputs(const OutputVector& new_args) const { - if (new_args.size() != 2) { - OPENVINO_THROW("Incorrect number of new arguments"); - } - - return make_shared(new_args.at(0), new_args.at(1), eltwise_type, m_output_type); -} - -void op::Eltwise::validate_and_infer_types() { - // Check that weights and biases has the same type - element::Type data1_et = get_input_element_type(0); - element::Type data2_et = get_input_element_type(1); - - element::Type et_result; - if (m_output_type == element::undefined) { - NODE_VALIDATION_CHECK(this, - element::Type::merge(et_result, data1_et, data2_et), - "Element types for first and second do not match :", - data1_et, - " and ", - data2_et); - } else { - et_result = m_output_type; - } - - if (get_input_partial_shape(0).rank().is_dynamic() || get_input_partial_shape(1).rank().is_dynamic()) { - set_output_type(0, et_result, PartialShape::dynamic()); - return; - } - - std::vector shape1(get_input_partial_shape(0)); - std::vector shape2(get_input_partial_shape(1)); - - std::vector output_shape(PartialShape::dynamic(std::max(shape1.size(), shape2.size()))); - auto output_shape_it = output_shape.rbegin(); - - auto shape1_it = shape1.rbegin(), shape2_it = shape2.rbegin(); - while (shape1_it != shape1.rend() || shape2_it != shape2.rend()) { - if (shape1_it != shape1.rend() && shape2_it != shape2.rend()) { - if (shape1_it->is_static() && shape2_it->is_static()) { - *output_shape_it = (shape1_it->get_length() > shape2_it->get_length() ? *shape1_it : *shape2_it); - } - } else if (shape1_it != shape1.rend()) { - *output_shape_it = *shape1_it; - } else if (shape2_it != shape2.rend()) { - *output_shape_it = *shape2_it; - } - - if (shape1_it != shape1.rend()) - ++shape1_it; - if (shape2_it != shape2.rend()) - ++shape2_it; - ++output_shape_it; - if (output_shape_it == output_shape.rend()) { - break; - } - } - - set_output_type(0, et_result, output_shape); -} - -bool op::Eltwise::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("operation", eltwise_type); - return true; -} -std::ostream& ngraph::operator<<(std::ostream& s, const ELTWISE_TYPE& type) { - return s << as_string(type); -} - -namespace ov { -template <> -EnumNames& EnumNames::get() { - static auto enum_names = EnumNames("ELTWISE_TYPE", - {{"sum", ELTWISE_TYPE::Sum}, - {"prod", ELTWISE_TYPE::Prod}, - {"max", ELTWISE_TYPE::Max}, - {"sub", ELTWISE_TYPE::Sub}, - {"min", ELTWISE_TYPE::Min}, - {"div", ELTWISE_TYPE::Div}}); - return enum_names; -} -} // namespace ov diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/fully_connected.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/fully_connected.cpp deleted file mode 100644 index 70f64245f95..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/fully_connected.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/fully_connected.hpp" - -#include -#include - -using namespace std; -using namespace ngraph; - -op::FullyConnected::FullyConnected(const Output& A, - const Output& B, - const Output& C, - const Shape& output_shape, - const element::Type output_type) - : Op({A, B, C}), - m_output_shape(output_shape), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -shared_ptr op::FullyConnected::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_output_shape); -} - -void op::FullyConnected::validate_and_infer_types() { - m_output_size = m_output_shape.back(); - set_output_type(0, - m_output_type == element::undefined ? input_value(0).get_element_type() : m_output_type, - m_output_shape); -} - -bool op::FullyConnected::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("out-size", m_output_size); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/gather_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/gather_ie.cpp deleted file mode 100644 index df60e910501..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/gather_ie.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/gather_ie.hpp" - -#include -#include -#include -#include -#include - -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; - -op::GatherIE::GatherIE(const Output& params, const Output& indices, int64_t axis) - : Op({params, indices}), - m_axis(axis) { - constructor_validate_and_infer_types(); -} - -shared_ptr op::GatherIE::clone_with_new_inputs(const ngraph::OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_axis); -} - -void op::GatherIE::validate_and_infer_types() { - // Use opset1::Gather to calculate output shape - auto gather = std::make_shared(input_value(0), - input_value(1), - opset1::Constant::create(element::i64, Shape{1}, {m_axis})); - set_output_type(0, gather->output(0).get_element_type(), gather->output(0).get_partial_shape()); -} - -bool op::GatherIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("axis", m_axis); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/gather_tree_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/gather_tree_ie.cpp deleted file mode 100644 index b0c397e2fdd..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/gather_tree_ie.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/gather_tree_ie.hpp" - -#include -#include - -using namespace std; -using namespace ngraph; - -op::GatherTreeIE::GatherTreeIE(const Output& step_ids, - const Output& parent_idx, - const Output& max_seq_len, - const Output& end_token) - : Op({step_ids, parent_idx, max_seq_len, end_token}) { - constructor_validate_and_infer_types(); -} - -shared_ptr op::GatherTreeIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), new_args.at(3)); -} - -void op::GatherTreeIE::validate_and_infer_types() { - const auto& step_ids_rank = get_input_partial_shape(0); - const auto& parent_idx_rank = get_input_partial_shape(1); - const auto& max_seq_len_rank = get_input_partial_shape(2); - const auto& end_token_rank = get_input_partial_shape(3); - - NODE_VALIDATION_CHECK(this, - step_ids_rank.rank().is_dynamic() || step_ids_rank.rank().get_length() == 3, - "step_ids input rank must equal to 3 (step_ids rank: ", - step_ids_rank.rank().get_length(), - ")"); - - NODE_VALIDATION_CHECK(this, - parent_idx_rank.rank().is_dynamic() || parent_idx_rank.rank().get_length() == 3, - "parent_idx input rank must equal to 3 (parent_idx rank: ", - parent_idx_rank.rank().get_length(), - ")"); - - NODE_VALIDATION_CHECK(this, - max_seq_len_rank.rank().is_dynamic() || max_seq_len_rank.rank().get_length() == 1, - "max_seq_len input rank must equal to 1 (max_seq_len rank: ", - max_seq_len_rank.rank().get_length(), - ")"); - - NODE_VALIDATION_CHECK(this, - end_token_rank.rank().is_dynamic() || end_token_rank.rank().get_length() == 1, - "end_token input rank must be scalar (end_token rank: ", - end_token_rank.rank().get_length(), - ")"); - - const auto& step_ids_et = get_input_element_type(0); - set_output_type(0, step_ids_et, step_ids_rank); -} - -bool ngraph::op::GatherTreeIE::visit_attributes(AttributeVisitor& visitor) { - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/gru_cell_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/gru_cell_ie.cpp deleted file mode 100644 index a672d498ae1..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/gru_cell_ie.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/gru_cell_ie.hpp" - -#include -#include -#include - -using namespace std; -using namespace ngraph; - -op::GRUCellIE::GRUCellIE(const Output& X, - const Output& H_t, - const Output& WR, - const Output& B, - std::size_t hidden_size, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip, - bool linear_before_reset) - : Op({X, H_t, WR, B}), - m_hidden_size(hidden_size), - m_activations(activations), - m_activations_alpha(activations_alpha), - m_activations_beta(activations_beta), - m_clip(clip), - m_linear_before_reset(linear_before_reset) { - constructor_validate_and_infer_types(); -} - -void op::GRUCellIE::validate_and_infer_types() { - element::Type arg_type = get_input_element_type(0); - - PartialShape output_shape{PartialShape::dynamic(2)}; - - if (get_input_partial_shape(0).is_static()) { - int64_t batch_size = get_input_partial_shape(0).get_shape()[0]; - output_shape = {batch_size, m_hidden_size}; - } - - set_output_type(0, arg_type, output_shape); -} - -shared_ptr op::GRUCellIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - m_hidden_size, - m_activations, - m_activations_alpha, - m_activations_beta, - m_clip, - m_linear_before_reset); -} - -bool op::GRUCellIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("hidden_size", m_hidden_size); - visitor.on_attribute("activations", m_activations); - visitor.on_attribute("activations_alpha", m_activations_alpha); - visitor.on_attribute("activations_beta", m_activations_beta); - visitor.on_attribute("clip", m_clip); - visitor.on_attribute("linear_before_reset", m_linear_before_reset); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/gru_sequence_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/gru_sequence_ie.cpp deleted file mode 100644 index e6635ac6275..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/gru_sequence_ie.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/gru_sequence_ie.hpp" - -#include -#include -#include - -#include "ngraph/op/util/recurrent_sequence.hpp" - -using namespace std; -using namespace ngraph; - -op::GRUSequenceIE::GRUSequenceIE(const Output& X, - const Output& H_t, - const Output& seq_lengths, - const Output& WR, - const Output& B, - std::size_t hidden_size, - op::RecurrentSequenceDirection direction, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip, - bool linear_before_reset, - int64_t seq_axis) - : RNNCellBase({X, H_t, seq_lengths, WR, B}, hidden_size, clip, activations, activations_alpha, activations_beta), - m_direction(direction), - m_linear_before_reset(linear_before_reset), - m_seq_axis(seq_axis) { - constructor_validate_and_infer_types(); -} - -void op::GRUSequenceIE::validate_and_infer_types() { - for (const auto& input : inputs()) { - if (input.get_partial_shape().rank().is_dynamic()) { - set_output_type(0, get_input_element_type(0), PartialShape::dynamic()); - set_output_type(1, get_input_element_type(0), PartialShape::dynamic()); - return; - } - } - // rank validation - auto x_pshape = get_input_partial_shape(0); - auto h_state_pshape = get_input_partial_shape(1); - auto seq_lengths_pshape = get_input_partial_shape(2); - auto wr_pshape = get_input_partial_shape(3); - auto b_pshape = get_input_partial_shape(4); - std::vector pshapes = {x_pshape, h_state_pshape, seq_lengths_pshape, wr_pshape, b_pshape}; - - std::vector in_names = {"X", "H", "seq_lengths", "WR", "B"}; - // num_direction dimension should be squeezed, we don't support bidirectional case - std::vector ranks = {3, 2, 1, 2, 1}; - for (size_t i = 0; i < pshapes.size(); ++i) { - NGRAPH_CHECK((pshapes[i].rank().get_length() == static_cast(ranks[i])), - "GRUSequenceIE ", - in_names[i], - " input rank is not correct."); - } - - element::Type arg_type = get_input_element_type(0); - PartialShape output_shape_0{PartialShape::dynamic(3)}; - PartialShape output_shape_1{PartialShape::dynamic(2)}; - if (get_input_partial_shape(0).is_static()) { - size_t batch_size = get_input_partial_shape(0).get_shape()[1 - m_seq_axis]; - size_t seq_length = get_input_partial_shape(0).get_shape()[m_seq_axis]; - if (m_seq_axis == 1) - output_shape_0 = Shape{batch_size, seq_length, m_hidden_size}; - else - output_shape_0 = Shape{seq_length, batch_size, m_hidden_size}; - output_shape_1 = Shape{batch_size, m_hidden_size}; - } - set_output_type(0, arg_type, output_shape_0); - set_output_type(1, arg_type, output_shape_1); -} - -bool op::GRUSequenceIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("direction", m_direction); - visitor.on_attribute("linear_before_reset", m_linear_before_reset); - visitor.on_attribute("axis", m_seq_axis); - return op::util::RNNCellBase::visit_attributes(visitor); -} - -shared_ptr op::GRUSequenceIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return std::make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - m_hidden_size, - m_direction, - m_activations, - m_activations_alpha, - m_activations_beta, - m_clip, - m_linear_before_reset, - m_seq_axis); -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/hard_sigmoid_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/hard_sigmoid_ie.cpp deleted file mode 100644 index 908aa0f70db..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/hard_sigmoid_ie.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/hard_sigmoid_ie.hpp" - -#include -#include - -#include "ngraph/op/constant.hpp" -#include "ngraph/op/hard_sigmoid.hpp" -#include "ngraph/op/multiply.hpp" - -using namespace std; -using namespace ngraph; - -op::HardSigmoid_IE::HardSigmoid_IE(const ngraph::Output& arg, float alpha, float beta) - : Op({arg}), - m_alpha(alpha), - m_beta(beta) { - constructor_validate_and_infer_types(); -} - -void op::HardSigmoid_IE::validate_and_infer_types() { - element::Type arg_type = get_input_element_type(0); - PartialShape arg_shape = get_input_partial_shape(0); - set_output_type(0, arg_type, arg_shape); -} - -shared_ptr op::HardSigmoid_IE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), m_alpha, m_beta); -} - -bool op::HardSigmoid_IE::visit_attributes(AttributeVisitor& visitor) { - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/interp.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/interp.cpp deleted file mode 100644 index 8909ba9ac8f..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/interp.cpp +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/interp.hpp" - -#include -#include - -#include "ngraph/op/constant.hpp" - -using namespace std; -using namespace ngraph; - -op::Interp::Interp(const Output& image, const InterpolateIEAttrs& attrs) : Op({image}), m_attrs(attrs) { - constructor_validate_and_infer_types(); -} - -void op::Interp::validate_and_infer_types() { - if (get_input_partial_shape(0).is_static()) { - Shape input_shape = get_input_partial_shape(0).to_shape(); - Shape output_shape(4); - // Assumes {N, C, H, W} - output_shape[0] = input_shape[0]; - output_shape[1] = input_shape[1]; - - auto is_zero = [](float value) { - return std::fabs(value) < std::numeric_limits::epsilon(); - }; - - bool should_scale = - !(is_zero(m_attrs.zoom_factor) && is_zero(m_attrs.shrink_factor) && is_zero(m_attrs.scale_factor)); - - if (should_scale) { - float scale = m_attrs.scale_factor; - if (!is_zero(m_attrs.shrink_factor) || !is_zero(m_attrs.zoom_factor)) { - if (!is_zero(m_attrs.zoom_factor)) { - scale = m_attrs.zoom_factor; - } - if (!is_zero(m_attrs.shrink_factor)) { - scale /= m_attrs.shrink_factor; - } - } - - output_shape[2] = static_cast(input_shape[2] * scale); - output_shape[3] = static_cast(input_shape[3] * scale); - } - - if (m_attrs.height > 0) { - output_shape[2] = m_attrs.height; - } - if (m_attrs.width > 0) { - output_shape[3] = m_attrs.width; - } - - set_output_type(0, get_input_element_type(0), output_shape); - } else { - set_output_type(0, get_input_element_type(0), PartialShape::dynamic()); - } -} - -shared_ptr op::Interp::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), m_attrs); -} - -bool op::Interp::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("align_corners", m_attrs.align_corners); - visitor.on_attribute("width", m_attrs.width); - visitor.on_attribute("height", m_attrs.height); - visitor.on_attribute("pad_beg", m_attrs.pad_beg); - visitor.on_attribute("pad_end", m_attrs.pad_end); - return true; -} - -op::ResampleV2::ResampleV2(const Output& image, const Output& output_shape, const ResampleIEAttrs& attrs) - : Op({image, output_shape}), - m_attrs(attrs) { - constructor_validate_and_infer_types(); -} - -op::ResampleV2::ResampleV2(const Output& image, const ResampleIEAttrs& attrs) : Op({image}), m_attrs(attrs) { - constructor_validate_and_infer_types(); -} - -void op::ResampleV2::validate_and_infer_types() { - if (m_attrs.factor != 0) { - Shape output_shape(get_input_shape(0)); - for (size_t i = 2; i < output_shape.size(); ++i) { - output_shape[i] *= m_attrs.factor; - } - set_output_type(0, get_input_element_type(0), output_shape); - } else if (auto const_shape = dynamic_pointer_cast(input_value(1).get_node_shared_ptr())) { - NODE_VALIDATION_CHECK(this, - shape_size(const_shape->get_shape()) == 4 || shape_size(const_shape->get_shape()) == 5, - "Layer shape must have rank 4 or 5", - const_shape->get_shape()); - - auto out_shape = const_shape->cast_vector(); - Shape output_shape; - for (size_t i = 0; i < const_shape->get_shape()[0]; i++) { - output_shape.push_back((out_shape[i] > 0) ? out_shape[i] : 0); - } - set_output_type(0, get_input_element_type(0), output_shape); - } else { - set_output_type(0, get_input_element_type(0), PartialShape::dynamic()); - } -} - -shared_ptr op::ResampleV2::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_attrs); -} - -bool op::ResampleV2::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("antialias", m_attrs.antialias); - visitor.on_attribute("factor", m_attrs.factor); - visitor.on_attribute("mode", m_attrs.mode); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/lrn_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/lrn_ie.cpp deleted file mode 100644 index 85bdcbb9956..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/lrn_ie.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/lrn_ie.hpp" - -#include -#include - -#include "ngraph/op/constant.hpp" -#include "ngraph/op/lrn.hpp" -#include "ngraph/op/multiply.hpp" - -using namespace std; -using namespace ngraph; - -op::LRN_IE::LRN_IE(const ngraph::Output& arg, - double alpha, - double beta, - double bias, - size_t size, - std::string region) - : Op({arg}), - m_alpha(alpha), - m_beta(beta), - m_bias(bias), - m_size(size), - m_region(region) { - constructor_validate_and_infer_types(); -} - -void op::LRN_IE::validate_and_infer_types() { - element::Type arg_type = get_input_element_type(0); - PartialShape arg_shape = get_input_partial_shape(0); - set_output_type(0, arg_type, arg_shape); -} - -shared_ptr op::LRN_IE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), m_alpha, m_beta, m_bias, m_size, m_region); -} - -bool op::LRN_IE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("alpha", m_alpha); - visitor.on_attribute("beta", m_beta); - visitor.on_attribute("k", m_bias); - visitor.on_attribute("local-size", m_size); - visitor.on_attribute("region", m_region); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/lstm_cell_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/lstm_cell_ie.cpp deleted file mode 100644 index 840fc6f78eb..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/lstm_cell_ie.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/lstm_cell_ie.hpp" - -#include -#include -#include - -using namespace std; -using namespace ngraph; - -op::LSTMCellIE::LSTMCellIE(const Output& X, - const Output& H_t, - const Output& C_t, - const Output& WR, - const Output& B, - std::size_t hidden_size, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip) - : Op({X, H_t, C_t, WR, B}), - m_hidden_size(hidden_size), - m_activations(activations), - m_activations_alpha(activations_alpha), - m_activations_beta(activations_beta), - m_clip(clip) { - constructor_validate_and_infer_types(); -} - -void op::LSTMCellIE::validate_and_infer_types() { - element::Type arg_type = get_input_element_type(0); - PartialShape output_shape{PartialShape::dynamic(2)}; - if (get_input_partial_shape(0).is_static()) { - int64_t batch_size = get_input_partial_shape(0).get_shape()[0]; - output_shape = {batch_size, m_hidden_size}; - } - set_output_type(0, arg_type, output_shape); - set_output_type(1, arg_type, output_shape); -} - -bool ngraph::op::LSTMCellIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("hidden_size", m_hidden_size); - visitor.on_attribute("activations", m_activations); - visitor.on_attribute("activations_alpha", m_activations_alpha); - visitor.on_attribute("activations_beta", m_activations_beta); - visitor.on_attribute("clip", m_clip); - return true; -} - -shared_ptr op::LSTMCellIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - m_hidden_size, - m_activations, - m_activations_alpha, - m_activations_beta, - m_clip); -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/lstm_sequence_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/lstm_sequence_ie.cpp deleted file mode 100644 index f6347627f37..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/lstm_sequence_ie.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/lstm_sequence_ie.hpp" - -#include -#include -#include - -#include "ngraph/op/util/recurrent_sequence.hpp" - -using namespace std; -using namespace ngraph; - -op::LSTMSequenceIE::LSTMSequenceIE(const Output& X, - const Output& H_t, - const Output& C_t, - const Output& seq_lengths, - const Output& WR, - const Output& B, - std::size_t hidden_size, - ngraph::op::RecurrentSequenceDirection direction, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip, - int64_t seq_axis) - : RNNCellBase({X, H_t, C_t, seq_lengths, WR, B}, - hidden_size, - clip, - activations, - activations_alpha, - activations_beta), - m_direction(direction), - m_seq_axis(seq_axis) { - constructor_validate_and_infer_types(); -} - -void op::LSTMSequenceIE::validate_and_infer_types() { - for (const auto& input : inputs()) { - if (input.get_partial_shape().rank().is_dynamic()) { - set_output_type(0, get_input_element_type(0), PartialShape::dynamic()); - set_output_type(1, get_input_element_type(0), PartialShape::dynamic()); - set_output_type(2, get_input_element_type(0), PartialShape::dynamic()); - return; - } - } - // rank validation - auto x_pshape = get_input_partial_shape(0); - auto h_state_pshape = get_input_partial_shape(1); - auto c_state_pshape = get_input_partial_shape(2); - auto seq_lengths_pshape = get_input_partial_shape(3); - auto wr_pshape = get_input_partial_shape(4); - auto b_pshape = get_input_partial_shape(5); - - std::vector pshapes = - {x_pshape, h_state_pshape, c_state_pshape, seq_lengths_pshape, wr_pshape, b_pshape}; - std::vector in_names = {"X", "H", "C", "seq_lengths", "WR", "B"}; - // num_direction dimension should be squeezed, we don't support bidirectional case - std::vector ranks = {3, 2, 2, 1, 2, 1}; - for (size_t i = 0; i < pshapes.size(); ++i) { - NGRAPH_CHECK((pshapes[i].rank().get_length() == static_cast(ranks[i])), - "LSTMSequenceIE ", - in_names[i], - " input rank is not correct."); - } - - element::Type arg_type = get_input_element_type(0); - PartialShape output_shape_0{PartialShape::dynamic(3)}; - PartialShape output_shape_1{PartialShape::dynamic(2)}; - if (get_input_partial_shape(0).is_static()) { - size_t batch_size = get_input_partial_shape(0).get_shape()[1 - m_seq_axis]; - size_t seq_length = get_input_partial_shape(0).get_shape()[m_seq_axis]; - if (m_seq_axis == 1) - output_shape_0 = Shape{batch_size, seq_length, m_hidden_size}; - else - output_shape_0 = Shape{seq_length, batch_size, m_hidden_size}; - output_shape_1 = Shape{batch_size, m_hidden_size}; - } - set_output_type(0, arg_type, output_shape_0); - set_output_type(1, arg_type, output_shape_1); - set_output_type(2, arg_type, output_shape_1); -} - -bool ngraph::op::LSTMSequenceIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("direction", m_direction); - visitor.on_attribute("axis", m_seq_axis); - return op::util::RNNCellBase::visit_attributes(visitor); -} - -shared_ptr op::LSTMSequenceIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - new_args.at(5), - m_hidden_size, - m_direction, - m_activations, - m_activations_alpha, - m_activations_beta, - m_clip, - m_seq_axis); -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/nms_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/nms_ie.cpp deleted file mode 100644 index d9a0950aa8b..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/nms_ie.cpp +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/nms_ie.hpp" - -#include -#include -#include - -using namespace std; -using namespace ngraph; - -op::NonMaxSuppressionIE::NonMaxSuppressionIE(const Output& boxes, - const Output& scores, - const Output& max_output_boxes_per_class, - const Output& iou_threshold, - const Output& score_threshold, - int center_point_box, - bool sort_result_descending, - const ngraph::element::Type& output_type) - : Op({boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold}), - m_center_point_box(center_point_box), - m_sort_result_descending(sort_result_descending), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::NonMaxSuppressionIE::clone_with_new_inputs(const ngraph::OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - m_center_point_box, - m_sort_result_descending, - m_output_type); -} - -void op::NonMaxSuppressionIE::validate_and_infer_types() { - auto squeeze_input = [](const Output& input) -> std::shared_ptr { - return std::make_shared(input, opset3::Constant::create(element::i64, Shape{1}, {0})); - }; - - // Calculate output shape using opset3::NonMaxSuppression - auto max_output_boxes_per_class = std::dynamic_pointer_cast(input_value(2).get_node_shared_ptr()); - auto nms = std::make_shared( - input_value(0), - input_value(1), - /* second input is used for output calculation and only if it's Constant output shape won't be dynamic */ - max_output_boxes_per_class - ? opset3::Constant::create(element::i64, Shape{}, max_output_boxes_per_class->cast_vector()) - : squeeze_input(input_value(2)), - squeeze_input(input_value(3)), - squeeze_input(input_value(4)), - opset3::NonMaxSuppression::BoxEncodingType::CENTER, - m_sort_result_descending, - m_output_type); - set_output_type(0, nms->output(0).get_element_type(), nms->output(0).get_partial_shape()); -} - -bool op::NonMaxSuppressionIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("center_point_box", m_center_point_box); - visitor.on_attribute("sort_result_descending", m_sort_result_descending); - visitor.on_attribute("output_type", m_output_type); - return true; -} - -// The second version of the operation is different just in the shape infer function (uses v4::NMS) -op::NonMaxSuppressionIE2::NonMaxSuppressionIE2(const Output& boxes, - const Output& scores, - const Output& max_output_boxes_per_class, - const Output& iou_threshold, - const Output& score_threshold, - int center_point_box, - bool sort_result_descending, - const ngraph::element::Type& output_type) - : op::NonMaxSuppressionIE(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - center_point_box, - sort_result_descending, - output_type) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::NonMaxSuppressionIE2::clone_with_new_inputs(const ngraph::OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - m_center_point_box, - m_sort_result_descending, - m_output_type); -} - -void op::NonMaxSuppressionIE2::validate_and_infer_types() { - auto squeeze_input = [](const Output& input) -> std::shared_ptr { - return std::make_shared(input, opset4::Constant::create(element::i64, Shape{1}, {0})); - }; - - // Calculate output shape using opset4::NonMaxSuppression - auto max_output_boxes_per_class = std::dynamic_pointer_cast(input_value(2).get_node_shared_ptr()); - auto nms = std::make_shared( - input_value(0), - input_value(1), - /* second input is used for output calculation and only if it's Constant output shape won't be dynamic */ - max_output_boxes_per_class - ? opset4::Constant::create(element::i64, Shape{}, max_output_boxes_per_class->cast_vector()) - : squeeze_input(input_value(2)), - squeeze_input(input_value(3)), - squeeze_input(input_value(4)), - opset4::NonMaxSuppression::BoxEncodingType::CENTER, - m_sort_result_descending, - m_output_type); - set_output_type(0, nms->output(0).get_element_type(), nms->output(0).get_partial_shape()); -} - -op::NonMaxSuppressionIE3::NonMaxSuppressionIE3(const Output& boxes, - const Output& scores, - const Output& max_output_boxes_per_class, - const Output& iou_threshold, - const Output& score_threshold, - int center_point_box, - bool sort_result_descending, - const ngraph::element::Type& output_type) - : Op({boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold}), - m_center_point_box(center_point_box), - m_sort_result_descending(sort_result_descending), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -op::NonMaxSuppressionIE3::NonMaxSuppressionIE3(const Output& boxes, - const Output& scores, - const Output& max_output_boxes_per_class, - const Output& iou_threshold, - const Output& score_threshold, - const Output& soft_nms_sigma, - int center_point_box, - bool sort_result_descending, - const ngraph::element::Type& output_type) - : Op({boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold, soft_nms_sigma}), - m_center_point_box(center_point_box), - m_sort_result_descending(sort_result_descending), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::NonMaxSuppressionIE3::clone_with_new_inputs(const ngraph::OutputVector& new_args) const { - if (new_args.size() == 6) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - new_args.at(5), - m_center_point_box, - m_sort_result_descending, - m_output_type); - } else if (new_args.size() == 5) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - m_center_point_box, - m_sort_result_descending, - m_output_type); - } - OPENVINO_THROW("Unsupported number of inputs: " + std::to_string(new_args.size())); -} - -bool op::NonMaxSuppressionIE3::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("center_point_box", m_center_point_box); - visitor.on_attribute("sort_result_descending", m_sort_result_descending); - visitor.on_attribute("output_type", m_output_type); - return true; -} - -static constexpr size_t boxes_port = 0; -static constexpr size_t scores_port = 1; -static constexpr size_t max_output_boxes_per_class_port = 2; - -int64_t op::NonMaxSuppressionIE3::max_boxes_output_from_input() const { - int64_t max_output_boxes{0}; - - size_t num_of_inputs = inputs().size(); - if (num_of_inputs < 3) { - return 0; - } - - const auto max_output_boxes_input = - ov::as_type_ptr(input_value(max_output_boxes_per_class_port).get_node_shared_ptr()); - max_output_boxes = max_output_boxes_input->cast_vector().at(0); - - return max_output_boxes; -} - -void op::NonMaxSuppressionIE3::validate_and_infer_types() { - const auto boxes_ps = get_input_partial_shape(boxes_port); - const auto scores_ps = get_input_partial_shape(scores_port); - - // NonMaxSuppression produces triplets - // that have the following format: [batch_index, class_index, box_index] - PartialShape out_shape = {Dimension::dynamic(), 3}; - - if (boxes_ps.rank().is_static() && scores_ps.rank().is_static()) { - const auto num_boxes_boxes = boxes_ps[1]; - const auto max_output_boxes_per_class_node = input_value(max_output_boxes_per_class_port).get_node_shared_ptr(); - if (num_boxes_boxes.is_static() && scores_ps[0].is_static() && scores_ps[1].is_static() && - op::is_constant(max_output_boxes_per_class_node)) { - const auto num_boxes = num_boxes_boxes.get_length(); - const auto num_classes = scores_ps[1].get_length(); - const auto max_output_boxes_per_class = max_boxes_output_from_input(); - - out_shape[0] = std::min(num_boxes, max_output_boxes_per_class) * num_classes * scores_ps[0].get_length(); - } - } - - set_output_type(0, m_output_type, out_shape); - set_output_type(1, element::f32, out_shape); - set_output_type(2, m_output_type, Shape{1}); -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/normalize_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/normalize_ie.cpp deleted file mode 100644 index 0c224d1f15e..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/normalize_ie.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/normalize_ie.hpp" - -#include -#include - -#include "ngraph/op/constant.hpp" - -using namespace std; -using namespace ngraph; - -op::NormalizeIE::NormalizeIE(const Output& data, - const Output& weights, - float eps, - bool across_spatial, - bool channel_shared, - const ngraph::element::Type output_type) - : Op({data, weights}), - m_eps(eps), - m_across_spatial(across_spatial), - m_channel_shared(channel_shared), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -void op::NormalizeIE::validate_and_infer_types() { - PartialShape arg_shape = get_input_partial_shape(0); - set_output_type(0, m_output_type, arg_shape); - - const PartialShape& input_shape = get_input_partial_shape(0); - - NODE_VALIDATION_CHECK(this, - input_shape.rank().is_dynamic() || - (input_shape.rank().get_length() >= 2 && input_shape.rank().get_length() <= 4), - "Argument must have rank >= 2 and <= 4 (argument shape: ", - input_shape, - ")."); -} - -shared_ptr op::NormalizeIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - m_eps, - m_across_spatial, - m_channel_shared, - m_output_type); -} - -bool op::NormalizeIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("eps", m_eps); - visitor.on_attribute("channel_shared", m_channel_shared); - visitor.on_attribute("across_spatial", m_across_spatial); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/onehot_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/onehot_ie.cpp deleted file mode 100644 index 6c0b567baee..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/onehot_ie.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/onehot_ie.hpp" - -#include - -using namespace std; -using namespace ngraph; - -op::OneHotIE::OneHotIE(const Output& input, - int axis, - int depth, - float on_value, - float off_value, - element::Type type) - : Op({input}), - m_type(type), - m_axis(axis), - m_depth(depth), - m_off_value(off_value), - m_on_value(on_value) { - constructor_validate_and_infer_types(); -} - -void op::OneHotIE::validate_and_infer_types() { - const PartialShape& arg_shape = get_input_partial_shape(0); - - if (arg_shape.rank().is_dynamic()) { - set_output_type(0, m_type, PartialShape::dynamic()); - } else { - vector output_shape{arg_shape}; - int normalized_axis = m_axis; - if (m_axis < 0) - normalized_axis = m_axis + static_cast(arg_shape.to_shape().size()); - output_shape.insert(output_shape.begin() + normalized_axis, m_depth); - set_output_type(0, m_type, output_shape); - } -} - -shared_ptr op::OneHotIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), m_axis, m_depth, m_on_value, m_off_value, m_type); -} - -bool op::OneHotIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("axis", m_axis); - visitor.on_attribute("depth", m_depth); - visitor.on_attribute("off_value", m_off_value); - visitor.on_attribute("on_value", m_on_value); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/pad_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/pad_ie.cpp deleted file mode 100644 index dc354b36ed5..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/pad_ie.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/pad_ie.hpp" - -#include - -#include -#include -#include - -#include "ngraph/op/constant.hpp" -#include "ngraph/op/pad.hpp" - -using namespace std; -using namespace ngraph; - -op::PadIE::PadIE(const std::shared_ptr& pad) - : Op({pad->input(0).get_source_output()}), - m_pad_mode(pad->get_pad_mode()), - m_pads_begin(pad->get_pads_begin()), - m_pads_end(pad->get_pads_end()), - m_output_shape(pad->output(0).get_shape()) { - if (pad->inputs().size() == 4) { - auto const_node = - std::dynamic_pointer_cast(pad->input(3).get_source_output().get_node_shared_ptr()); - if (!const_node) { - OPENVINO_THROW("Pad " + pad->get_friendly_name() + " with not constant pad_value is not allowed"); - } - if (!ov::op::util::get_single_value(const_node, m_pad_value)) { - OPENVINO_THROW("Unsupported pad value"); - } - } - constructor_validate_and_infer_types(); -} - -op::PadIE::PadIE(const Output& input, - PadMode pad_mode, - CoordinateDiff pads_begin, - CoordinateDiff pads_end, - Shape output_shape, - float pad_value) - : Op({input}), - m_pad_mode(pad_mode), - m_pads_begin(pads_begin), - m_pads_end(pads_end), - m_output_shape(output_shape), - m_pad_value(pad_value) { - constructor_validate_and_infer_types(); -} - -void op::PadIE::validate_and_infer_types() { - set_output_type(0, get_input_element_type(0), m_output_shape); -} - -shared_ptr op::PadIE::clone_with_new_inputs(const OutputVector& new_args) const { - return std::make_shared(new_args.at(0), m_pad_mode, m_pads_begin, m_pads_end, m_output_shape, m_pad_value); -} - -bool op::PadIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("pads_begin", m_pads_begin); - visitor.on_attribute("pads_end", m_pads_end); - visitor.on_attribute("pad_mode", m_pad_mode); - visitor.on_attribute("pad_value", m_pad_value); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/power.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/power.cpp deleted file mode 100644 index e62301f0df2..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/power.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/power.hpp" - -#include - -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; - -op::PowerIE::PowerIE(const Output& data_batch, - const float power, - const float scale, - const float shift, - const element::Type output_type) - : Op({data_batch}), - scale(scale), - power(power), - shift(shift), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::PowerIE::clone_with_new_inputs(const OutputVector& new_args) const { - if (new_args.size() != 1) { - OPENVINO_THROW("Incorrect number of new arguments"); - } - - return make_shared(new_args.at(0), this->power, this->scale, this->shift, this->m_output_type); -} - -void op::PowerIE::validate_and_infer_types() { - set_output_type(0, - m_output_type == element::undefined ? get_input_element_type(0) : m_output_type, - get_input_partial_shape(0)); -} - -bool op::PowerIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("scale", scale); - visitor.on_attribute("power", power); - visitor.on_attribute("shift", shift); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/proposal_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/proposal_ie.cpp deleted file mode 100644 index bd3f1059594..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/proposal_ie.cpp +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/proposal_ie.hpp" - -#include - -#include "ngraph/op/constant.hpp" - -using namespace std; -using namespace ngraph; - -op::ProposalIE::ProposalIE(const Output& class_probs, - const Output& class_bbox_deltas, - const Output& image_shape, - const ProposalAttrs& attrs) - : Op({class_probs, class_bbox_deltas, image_shape}), - m_attrs(attrs) { - constructor_validate_and_infer_types(); -} - -void op::ProposalIE::validate_and_infer_types() { - const auto& class_probs_pshape = get_input_partial_shape(0); - const auto& class_bbox_deltas_pshape = get_input_partial_shape(1); - const auto& image_shape_pshape = get_input_partial_shape(2); - - if (class_probs_pshape.is_static() && class_bbox_deltas_pshape.is_static() && image_shape_pshape.is_static()) { - const Shape class_probs_shape{class_probs_pshape.to_shape()}; - const Shape class_bbox_deltas_shape{class_bbox_deltas_pshape.to_shape()}; - const Shape image_shape_shape{image_shape_pshape.to_shape()}; - - NODE_VALIDATION_CHECK(this, - class_probs_shape.size() == 4, - "Proposal layer shape class_probs input must have rank 4 (class_probs_shape: ", - class_probs_shape, - ")."); - - NODE_VALIDATION_CHECK( - this, - class_bbox_deltas_shape.size() == 4, - "Proposal layer shape class_bbox_deltas_shape input must have rank 4 (class_bbox_deltas_shape: ", - class_bbox_deltas_shape, - ")."); - - NODE_VALIDATION_CHECK(this, - image_shape_shape.size() == 2, - "Proposal layer image_shape input must have rank 2 (image_shape_shape: ", - image_shape_shape, - ")."); - - NODE_VALIDATION_CHECK(this, - image_shape_shape[1] >= 3 && image_shape_shape[1] <= 4, - "Image_shape 1D tensor must have => 3 and <= 4 elements (image_shape_shape[1]", - image_shape_shape[1], - ")."); - - auto batch_size = class_probs_shape[0]; - set_output_type(0, get_input_element_type(0), Shape{batch_size * m_attrs.post_nms_topn, 5}); - if (m_attrs.infer_probs) - set_output_type(1, get_input_element_type(0), Shape{batch_size * m_attrs.post_nms_topn}); - } else { - set_output_type(0, get_input_element_type(0), PartialShape::dynamic()); - if (m_attrs.infer_probs) - set_output_type(1, get_input_element_type(0), PartialShape::dynamic()); - } -} - -shared_ptr op::ProposalIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_attrs); -} - -bool op::ProposalIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("ratio", m_attrs.ratio); - visitor.on_attribute("scale", m_attrs.scale); - visitor.on_attribute("base_size", m_attrs.base_size); - visitor.on_attribute("pre_nms_topn", m_attrs.pre_nms_topn); - visitor.on_attribute("post_nms_topn", m_attrs.post_nms_topn); - visitor.on_attribute("nms_thresh", m_attrs.nms_thresh); - visitor.on_attribute("feat_stride", m_attrs.feat_stride); - visitor.on_attribute("min_size", m_attrs.min_size); - visitor.on_attribute("box_size_scale", m_attrs.box_size_scale); - visitor.on_attribute("box_coordinate_scale", m_attrs.box_coordinate_scale); - visitor.on_attribute("clip_before_nms", m_attrs.clip_before_nms); - visitor.on_attribute("clip_after_nms", m_attrs.clip_after_nms); - visitor.on_attribute("normalize", m_attrs.normalize); - visitor.on_attribute("framework", m_attrs.framework); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/relu_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/relu_ie.cpp deleted file mode 100644 index 2853dc40ad1..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/relu_ie.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/relu_ie.hpp" - -#include -#include - -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; - -op::ReLUIE::ReLUIE(const Output& data, const float& negative_slope, const element::Type output_type) - : Op(OutputVector{data}), - m_negative_slope(negative_slope), - m_output_type(output_type) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::ReLUIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), m_negative_slope, m_output_type); -} - -void op::ReLUIE::validate_and_infer_types() { - set_output_type(0, - m_output_type == element::undefined ? get_input_element_type(0) : m_output_type, - get_input_partial_shape(0)); -} - -bool op::ReLUIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("negative_slope", m_negative_slope); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/rnn_cell_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/rnn_cell_ie.cpp deleted file mode 100644 index de423e27210..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/rnn_cell_ie.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/rnn_cell_ie.hpp" - -#include -#include -#include - -using namespace std; -using namespace ngraph; - -op::RNNCellIE::RNNCellIE(const Output& X, - const Output& H_t, - const Output& WR, - const Output& B, - std::size_t hidden_size, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip) - : Op({X, H_t, WR, B}), - m_hidden_size(hidden_size), - m_activations(activations), - m_activations_alpha(activations_alpha), - m_activations_beta(activations_beta), - m_clip(clip) { - constructor_validate_and_infer_types(); -} - -void op::RNNCellIE::validate_and_infer_types() { - element::Type arg_type = get_input_element_type(0); - - PartialShape output_shape{PartialShape::dynamic(2)}; - if (get_input_partial_shape(0).is_static()) { - int64_t batch_size = get_input_partial_shape(0).get_shape()[0]; - output_shape = {batch_size, m_hidden_size}; - } - set_output_type(0, arg_type, output_shape); -} - -shared_ptr op::RNNCellIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - m_hidden_size, - m_activations, - m_activations_alpha, - m_activations_beta, - m_clip); -} - -bool op::RNNCellIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("hidden_size", m_hidden_size); - visitor.on_attribute("activations", m_activations); - visitor.on_attribute("activations_alpha", m_activations_alpha); - visitor.on_attribute("activations_beta", m_activations_beta); - visitor.on_attribute("clip", m_clip); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/rnn_sequence_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/rnn_sequence_ie.cpp deleted file mode 100644 index ea554171ce8..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/rnn_sequence_ie.cpp +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/rnn_sequence_ie.hpp" - -#include -#include -#include - -#include "ngraph/op/util/recurrent_sequence.hpp" - -using namespace std; -using namespace ngraph; - -op::RNNSequenceIE::RNNSequenceIE(const Output& X, - const Output& H_t, - const Output& seq_lengths, // actually not supported - const Output& WR, - const Output& B, - std::size_t hidden_size, - op::RecurrentSequenceDirection direction, - const std::vector& activations, - const std::vector& activations_alpha, - const std::vector& activations_beta, - float clip, - int64_t seq_axis) - : RNNCellBase({X, H_t, seq_lengths, WR, B}, hidden_size, clip, activations, activations_alpha, activations_beta), - m_direction(direction), - m_seq_axis(seq_axis) { - constructor_validate_and_infer_types(); -} - -void op::RNNSequenceIE::validate_and_infer_types() { - for (const auto& input : inputs()) { - if (input.get_partial_shape().rank().is_dynamic()) { - set_output_type(0, get_input_element_type(0), PartialShape::dynamic()); - set_output_type(1, get_input_element_type(0), PartialShape::dynamic()); - return; - } - } - // rank validation - auto x_pshape = get_input_partial_shape(0); - auto h_state_pshape = get_input_partial_shape(1); - auto seq_lengths_pshape = get_input_partial_shape(2); - auto wr_pshape = get_input_partial_shape(3); - auto b_pshape = get_input_partial_shape(4); - - std::vector pshapes = {x_pshape, h_state_pshape, seq_lengths_pshape, wr_pshape, b_pshape}; - std::vector in_names = {"X", "H", "seq_lengths", "WR", "B"}; - // num_direction dimension should be squeezed, we don't support bidirectional case - std::vector ranks = {3, 2, 1, 2, 1}; - for (size_t i = 0; i < pshapes.size(); ++i) { - NGRAPH_CHECK((pshapes[i].rank().get_length() == static_cast(ranks[i])), - "RNNSequenceIE ", - in_names[i], - " input rank is not correct."); - } - - element::Type arg_type = get_input_element_type(0); - PartialShape output_shape_0{PartialShape::dynamic(3)}; - PartialShape output_shape_1{PartialShape::dynamic(2)}; - if (get_input_partial_shape(0).is_static()) { - size_t batch_size = get_input_partial_shape(0).get_shape()[1 - m_seq_axis]; - size_t seq_length = get_input_partial_shape(0).get_shape()[m_seq_axis]; - if (m_seq_axis == 1) - output_shape_0 = Shape{batch_size, seq_length, m_hidden_size}; - else - output_shape_0 = Shape{seq_length, batch_size, m_hidden_size}; - output_shape_1 = Shape{batch_size, m_hidden_size}; - } - set_output_type(0, arg_type, output_shape_0); - set_output_type(1, arg_type, output_shape_1); -} - -bool op::RNNSequenceIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("direction", m_direction); - visitor.on_attribute("axis", m_seq_axis); - return op::util::RNNCellBase::visit_attributes(visitor); -} - -shared_ptr op::RNNSequenceIE::clone_with_new_inputs(const ngraph::OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - m_hidden_size, - m_direction, - m_activations, - m_activations_alpha, - m_activations_beta, - m_clip, - m_seq_axis); -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/scaleshift.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/scaleshift.cpp deleted file mode 100644 index ee098a67fcf..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/scaleshift.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/scaleshift.hpp" - -#include - -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; - -inline element::Type getMaxBitwidth(const std::vector& types) { - if (types.empty()) { - return element::undefined; - } - - element::Type maxType = types[0]; - for (size_t i = 1; i < types.size(); ++i) { - if (types[i].bitwidth() > maxType.bitwidth()) { - maxType = types[i]; - } - } - return maxType; -} - -op::ScaleShiftIE::ScaleShiftIE(const Output& data_batch, - const Output& weights, - const Output& bias, - const element::Type output_type) - : Op({data_batch, weights, bias}), - output_type(output_type) { - if (this->output_type == element::undefined) { - this->output_type = - getMaxBitwidth({data_batch.get_element_type(), weights.get_element_type(), bias.get_element_type()}); - } - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::ScaleShiftIE::clone_with_new_inputs(const OutputVector& new_args) const { - if (new_args.size() != 3) { - OPENVINO_THROW("Incorrect number of new arguments"); - } - - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), output_type); -} - -void op::ScaleShiftIE::validate_and_infer_types() { - // Check that weights and biases has the same type - element::Type data_et = output_type == element::undefined ? get_input_element_type(0) : output_type; - element::Type weights_et = get_input_element_type(1); - element::Type biases_et = get_input_element_type(2); - - element::Type et_result; - NODE_VALIDATION_CHECK(this, - element::Type::merge(et_result, weights_et, biases_et), - "Element types for bias and weights do not match (biases element type: ", - biases_et, - ", weights element type: ", - weights_et, - ")."); - - set_output_type(0, data_et, get_input_partial_shape(0)); -} - -bool ngraph::op::ScaleShiftIE::visit_attributes(AttributeVisitor& visitor) { - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/selu_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/selu_ie.cpp deleted file mode 100644 index 0069674a4f4..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/selu_ie.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/selu_ie.hpp" - -#include -#include - -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; - -op::SeluIE::SeluIE(const Output& input, const float alpha, const float gamma) - : Op({input}), - gamma(gamma), - alpha(alpha) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::SeluIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), alpha, gamma); -} - -void op::SeluIE::validate_and_infer_types() { - set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); -} - -bool op::SeluIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("alpha", alpha); - visitor.on_attribute("gamma", gamma); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/swish_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/swish_ie.cpp deleted file mode 100644 index f8b4d3e840c..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/swish_ie.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/swish_ie.hpp" - -#include -#include - -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; - -op::SwishIE::SwishIE(const Output& input, const float alpha) : Op({input}), m_alpha(alpha) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::SwishIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), m_alpha); -} - -bool op::SwishIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("alpha", m_alpha); - return true; -} - -void op::SwishIE::validate_and_infer_types() { - set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); -} - -void op::SwishIE::set_alpha(float alpha) { - m_alpha = alpha; -} - -float op::SwishIE::get_alpha() const { - return m_alpha; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/tile_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/tile_ie.cpp deleted file mode 100644 index 4ca5c237d9a..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/tile_ie.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/tile_ie.hpp" - -#include -#include - -#include "ngraph/util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; - -op::TileIE::TileIE(const Output& data1, const int64_t axis, const int64_t tiles) - : Op({data1}), - axis(axis), - tiles(tiles) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::TileIE::clone_with_new_inputs(const OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), axis, tiles); -} - -void op::TileIE::validate_and_infer_types() { - const auto& input_pshape = get_input_partial_shape(0); - auto output_pshape = PartialShape::dynamic(); - if (input_pshape.rank().is_static()) { - const auto& rank = input_pshape.rank().get_length(); - NODE_VALIDATION_CHECK(this, - axis >= 0 && axis < rank, - "Axis: ", - axis, - " must be >= 0 and less than ", - rank, - "(input rank)"); - output_pshape = input_pshape; - if (output_pshape[axis].is_static()) { - output_pshape[axis] *= tiles; - } - } - - set_output_type(0, get_input_element_type(0), output_pshape); -} - -bool op::TileIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("axis", axis); - visitor.on_attribute("tiles", tiles); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/ngraph_ops/topk_ie.cpp b/src/plugins/intel_gna/legacy/src/ngraph_ops/topk_ie.cpp deleted file mode 100644 index ecb81e605d4..00000000000 --- a/src/plugins/intel_gna/legacy/src/ngraph_ops/topk_ie.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/ngraph_ops/topk_ie.hpp" - -#include -#include -#include - -using namespace std; -using namespace ngraph; - -op::TopKIE::TopKIE(const ngraph::Output& data, - const ngraph::Output& k, - const int64_t axis, - const ngraph::op::TopKMode mode, - const ngraph::op::TopKSortType sort, - const element::Type& index_element_type) - : Op({data, k}), - m_axis(axis), - m_mode(mode), - m_sort_type(sort), - m_index_element_type(index_element_type) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr op::TopKIE::clone_with_new_inputs(const ngraph::OutputVector& new_args) const { - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_axis, m_mode, m_sort_type, m_index_element_type); -} - -void op::TopKIE::validate_and_infer_types() { - const auto& input_partial_shape = get_input_partial_shape(0); - const auto input_rank = input_partial_shape.rank(); - - NODE_VALIDATION_CHECK(this, - input_rank.is_dynamic() || input_rank.get_length() > 0, - "Input rank must be greater than 0."); - - const auto& k_partial_shape = get_input_partial_shape(1); - NODE_VALIDATION_CHECK(this, k_partial_shape.rank().compatible(1), "The 'K' input must be a 1D tensor."); - - // Construct v1::TopK operation to calculate output shapes - std::shared_ptr topk; - if (auto k_const = std::dynamic_pointer_cast(input_value(1).get_node_shared_ptr())) { - const auto k = k_const->cast_vector(); - topk = std::make_shared(input_value(0), - opset1::Constant::create(element::i64, Shape{}, k), - m_axis, - m_mode, - m_sort_type, - m_index_element_type); - } else { - topk = std::make_shared( - input_value(0), - std::make_shared(input_value(1), opset1::Constant::create(element::i64, Shape{1}, {0})), - m_axis, - m_mode, - m_sort_type, - m_index_element_type); - } - - set_output_size(2); - set_output_type(0, topk->get_output_element_type(0), topk->get_output_partial_shape(0)); - set_output_type(1, topk->get_output_element_type(1), topk->get_output_partial_shape(1)); -} - -bool op::TopKIE::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("axis", m_axis); - visitor.on_attribute("mode", m_mode); - visitor.on_attribute("sort", m_sort_type); - return true; -} diff --git a/src/plugins/intel_gna/legacy/src/precomp.hpp b/src/plugins/intel_gna/legacy/src/precomp.hpp deleted file mode 100644 index 0105651c75f..00000000000 --- a/src/plugins/intel_gna/legacy/src/precomp.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/conv_bias_fusion.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/conv_bias_fusion.cpp deleted file mode 100644 index 52c19343585..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/conv_bias_fusion.cpp +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/conv_bias_fusion.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace ngraph; - -template -std::pair, std::shared_ptr> parse_eltwise_inputs(std::shared_ptr node) { - auto eltwise = std::dynamic_pointer_cast(node->input(0).get_source_output().get_node_shared_ptr()); - auto constant = std::dynamic_pointer_cast(node->input(1).get_source_output().get_node_shared_ptr()); - - if (!eltwise) { - eltwise = std::dynamic_pointer_cast(node->input(1).get_source_output().get_node_shared_ptr()); - constant = std::dynamic_pointer_cast(node->input(0).get_source_output().get_node_shared_ptr()); - } - - if (!eltwise || !constant) { - return {nullptr, nullptr}; - } - - return {eltwise, constant}; -} - -template -bool IsConvInLowPrecision(const std::shared_ptr& conv) { - if (!ngraph::is_type(conv)) { - return false; - } - - auto isLowPrecision = [](const std::shared_ptr& node, const size_t index) { - const ngraph::element::Type inputType = node->get_input_element_type(index); - return (inputType == ngraph::element::i8) || (inputType == ngraph::element::u8); - }; - - // Convolution operation has to be executed in INT8 if ... - if (isLowPrecision(conv, 0) && isLowPrecision(conv, 1)) { - // ... INT8 on activations && INT8 on weights - return true; - } - - const std::shared_ptr subtract = - ngraph::as_type_ptr(conv->get_input_node_shared_ptr(0)); - if (subtract == nullptr) { - return false; - } - - // ... INT8 on activations with asymmetric quantization && INT8 on weights - return isLowPrecision(subtract, 0) && isLowPrecision(subtract, 1) && isLowPrecision(conv, 1); -} - -template -bool conv_callback(ngraph::pattern::Matcher& m) { - auto eltwise = m.get_match_root(); - - std::shared_ptr m_const; - std::shared_ptr m_conv; - // FIXME: use auto [m_conv, m_const] when C++17 is available - std::tie(m_conv, m_const) = parse_eltwise_inputs(eltwise); - if (!m_conv || !m_const) { - return false; - } - - const auto& const_shape = m_const->get_shape(); - const auto& output_pshape = m_conv->get_output_partial_shape(0); - - if (output_pshape.rank().is_dynamic() || output_pshape[1].is_dynamic()) { - return false; - } - - const auto& output_rank = output_pshape.rank().get_length(); - - const int64_t channel_dim = output_pshape[1].get_length(); - - bool is_scalar_multiplier(shape_size(const_shape) == 1); - - // Check that constant has shape [1, C, 1, 1] where the number of 1 is equal to - // the number of spatial dimensions or it's a scalar. That means that Constant - // applied per channel and can be fused into Convolution weights. - // Also Constant shape rank must be less or equal Convolution output shape - // otherwise fusion will break output broadcasting - auto expected_shape = Shape(output_rank, 1); - expected_shape[1] = channel_dim; - - if (ov::op::util::check_for_broadcast(expected_shape, const_shape)) { - return false; - } - - // Broadcast constant to [1, C, 1, 1] where the number of 1 is equal to - // the number of weights dimensions. - Output final_const = m_const; - if (is_scalar_multiplier) { - final_const = ov::op::util::broadcastTo(m_const, expected_shape); - } - - if (final_const.get_shape().size() > 1) { - final_const = std::make_shared( - final_const, - ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {channel_dim}), - true); - } - - ngraph::Output new_conv, new_weights, new_bias; - if (std::dynamic_pointer_cast(eltwise)) { - // Fuse: ConvolutionIE/DeconvolutionIE->Add - if (m_conv->inputs().size() == 2) { - new_bias = final_const; - } else { - new_bias = std::make_shared(final_const, m_conv->input_value(2)); - } - new_conv = m_conv->clone_with_new_inputs({m_conv->input_value(0), m_conv->input_value(1), new_bias}); - } else if (std::is_same() && - std::dynamic_pointer_cast(eltwise) && !IsConvInLowPrecision(m_conv)) { - // Fuse: ConvolutionIE->Mul - auto weights_shape = m_conv->input(1).get_shape(); - - ngraph::Shape weights_const_shape(weights_shape.size(), 1); - weights_const_shape[0] = weights_shape[0]; - - auto const_reshape = std::make_shared( - final_const, - ngraph::opset1::Constant::create(ngraph::element::i64, - ngraph::Shape{weights_const_shape.size()}, - weights_const_shape), - true); - new_weights = std::make_shared(m_conv->input_value(1), const_reshape); - if (m_conv->inputs().size() == 2) { - new_conv = m_conv->clone_with_new_inputs({m_conv->input_value(0), new_weights}); - } else { - auto bias_reshape = std::make_shared( - final_const, - ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {weights_shape[0]}), - true); - new_bias = std::make_shared(bias_reshape, final_const); - new_conv = m_conv->clone_with_new_inputs({m_conv->input_value(0), new_weights, new_bias}); - } - } else { - return false; - } - - ngraph::copy_runtime_info({m_conv, eltwise}, new_conv.get_node_shared_ptr()); - new_conv.get_node_shared_ptr()->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::replace_node(m.get_match_root(), new_conv.get_node_shared_ptr()); - return true; -} - -ngraph::pass::ConvAddFusion::ConvAddFusion() { - auto conv = ngraph::pattern::wrap_type(pattern::consumers_count(1)); - auto add = ngraph::pattern::wrap_type({conv, pattern::any_input()}); - - matcher_pass_callback callback = [](ngraph::pattern::Matcher& m) { - return conv_callback(m); - }; - - auto m = std::make_shared(add, "ConvAddFusion"); - register_matcher(m, callback); -} - -ngraph::pass::ConvMultiplyFusion::ConvMultiplyFusion() { - auto conv = ngraph::pattern::wrap_type(pattern::consumers_count(1)); - auto add = ngraph::pattern::wrap_type({conv, pattern::any_input()}); - - matcher_pass_callback callback = [](ngraph::pattern::Matcher& m) { - return conv_callback(m); - }; - - auto m = std::make_shared(add, "ConvMultiplyFusion"); - register_matcher(m, callback); -} - -ngraph::pass::DeconvAddFusion::DeconvAddFusion() { - auto conv = ngraph::pattern::wrap_type(pattern::consumers_count(1)); - auto add = ngraph::pattern::wrap_type({conv, pattern::any_input()}); - - matcher_pass_callback callback = [](ngraph::pattern::Matcher& m) { - return conv_callback(m); - }; - - auto m = std::make_shared(add, "DeconvAddFusion"); - register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_cells_to_cells_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_cells_to_cells_ie.cpp deleted file mode 100644 index 4f37503e87a..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_cells_to_cells_ie.cpp +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_cells_to_cells_ie.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "legacy/ngraph_ops/gru_cell_ie.hpp" -#include "legacy/ngraph_ops/lstm_cell_ie.hpp" -#include "legacy/ngraph_ops/rnn_cell_ie.hpp" - -ngraph::pass::ConvertLSTMCellMatcher::ConvertLSTMCellMatcher() { - auto is_supported_lstm_cell = [](const std::shared_ptr& n) { - return pattern::has_class()(n) || pattern::has_class()(n); - }; - auto any_lstm = std::make_shared(element::f32, Shape{}, is_supported_lstm_cell); - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto lstm_cell = std::dynamic_pointer_cast(m.get_match_root()); - if (!lstm_cell) { - return false; - } - auto W = std::dynamic_pointer_cast(lstm_cell->input_value(3).get_node_shared_ptr()); - if (!W) { - return false; - } - - auto R = std::dynamic_pointer_cast(lstm_cell->input_value(4).get_node_shared_ptr()); - if (!R) { - return false; - } - - auto concat = std::make_shared(ngraph::NodeVector({W, R}), 1); - auto lstm_cell_ie = - std::make_shared(lstm_cell->input(0).get_source_output(), // X - lstm_cell->input(1).get_source_output(), // initial_hidden_state - lstm_cell->input(2).get_source_output(), // initial_cell_state - concat->output(0), // WR - lstm_cell->input(5).get_source_output(), // B - lstm_cell->get_hidden_size(), - lstm_cell->get_activations(), - lstm_cell->get_activations_alpha(), - lstm_cell->get_activations_beta(), - lstm_cell->get_clip()); - - lstm_cell_ie->set_friendly_name(lstm_cell->get_friendly_name()); - ngraph::copy_runtime_info(lstm_cell, {concat, lstm_cell_ie}); - ngraph::replace_node(m.get_match_root(), lstm_cell_ie); - return true; - }; - - auto m = std::make_shared(any_lstm, "ConvertLSTMCellToLSTMCellIE"); - this->register_matcher(m, callback); -} - -ngraph::pass::ConvertGRUCellMatcher::ConvertGRUCellMatcher() { - auto gru_cell_ngraph = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto gru_cell = std::dynamic_pointer_cast(m.get_match_root()); - if (!gru_cell) { - return false; - } - - auto W = std::dynamic_pointer_cast(gru_cell->input_value(2).get_node_shared_ptr()); - if (!W) { - return false; - } - - auto R = std::dynamic_pointer_cast(gru_cell->input_value(3).get_node_shared_ptr()); - if (!R) { - return false; - } - - auto concat = std::make_shared(ngraph::NodeVector({W, R}), 1); - auto gru_cell_ie = - std::make_shared(gru_cell->input(0).get_source_output(), // X - gru_cell->input(1).get_source_output(), // initial_hidden_state - concat->output(0), // WR - gru_cell->input(4).get_source_output(), // B - gru_cell->get_hidden_size(), - gru_cell->get_activations(), - gru_cell->get_activations_alpha(), - gru_cell->get_activations_beta(), - gru_cell->get_clip(), - gru_cell->get_linear_before_reset()); - - gru_cell_ie->set_friendly_name(gru_cell->get_friendly_name()); - ngraph::copy_runtime_info(gru_cell, {concat, gru_cell_ie}); - ngraph::replace_node(m.get_match_root(), gru_cell_ie); - return true; - }; - - auto m = std::make_shared(gru_cell_ngraph, "ConvertGRUCellToGRUCellIE"); - this->register_matcher(m, callback); -} - -ngraph::pass::ConvertRNNCellMatcher::ConvertRNNCellMatcher() { - auto rnn_cell_ngraph = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto rnn_cell = std::dynamic_pointer_cast(m.get_match_root()); - if (!rnn_cell) { - return false; - } - - auto W = std::dynamic_pointer_cast(rnn_cell->input_value(2).get_node_shared_ptr()); - if (!W) { - return false; - } - - auto R = std::dynamic_pointer_cast(rnn_cell->input_value(3).get_node_shared_ptr()); - if (!R) { - return false; - } - - auto concat = std::make_shared(ngraph::NodeVector({W, R}), 1); - auto rnn_cell_ie = - std::make_shared(rnn_cell->input(0).get_source_output(), // X - rnn_cell->input(1).get_source_output(), // initial_hidden_state - concat->output(0), // WR - rnn_cell->input(4).get_source_output(), // B - rnn_cell->get_hidden_size(), - rnn_cell->get_activations(), - rnn_cell->get_activations_alpha(), - rnn_cell->get_activations_beta(), - rnn_cell->get_clip()); - - rnn_cell_ie->set_friendly_name(rnn_cell->get_friendly_name()); - ngraph::copy_runtime_info(rnn_cell, {concat, rnn_cell_ie}); - ngraph::replace_node(m.get_match_root(), rnn_cell_ie); - return true; - }; - - auto m = std::make_shared(rnn_cell_ngraph, "ConvertRNNCellToRNNCellIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_convolutions.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_convolutions.cpp deleted file mode 100644 index 0e0d71e4263..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_convolutions.cpp +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_convolutions.hpp" - -#include -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertConvolution::ConvertConvolution() { - auto conv = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto conv = std::dynamic_pointer_cast(m.get_match_root()); - if (!conv) { - return false; - } - - auto conv_ie = std::make_shared(conv->input_value(0), - conv->input_value(1), - conv->get_strides(), - conv->get_dilations(), - conv->get_pads_begin(), - conv->get_pads_end(), - conv->get_output_element_type(0), - 1 /* groups */, - conv->get_auto_pad()); - ngraph::copy_runtime_info(conv, conv_ie); - conv_ie->set_friendly_name(conv->get_friendly_name()); - ngraph::replace_node(conv, conv_ie); - return true; - }; - - auto m = std::make_shared(conv, "ConvertConvolution"); - this->register_matcher(m, callback); -} - -ngraph::pass::ConvertGroupConvolution::ConvertGroupConvolution() { - auto gconv = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto gconv = std::dynamic_pointer_cast(m.get_match_root()); - if (!gconv) { - return false; - } - size_t group = gconv->input_value(1).get_shape()[0]; - - // Merge weights layout GOIYX to (G*O)IYX - auto shape = gconv->input_value(1).get_shape(); - Shape reshape_shape{static_cast(shape[0] * shape[1])}; - for (size_t i = 2; i < shape.size(); ++i) { - reshape_shape.push_back(shape[i]); - } - Output weights; - auto w_input = gconv->input_value(1).get_node_shared_ptr(); - if (std::dynamic_pointer_cast(w_input) && - w_input->input_value(0).get_shape() == reshape_shape) { - weights = w_input->input_value(0); - } else { - weights = std::make_shared( - gconv->input_value(1), - op::Constant::create(element::i64, Shape{reshape_shape.size()}, reshape_shape), - true); - ngraph::copy_runtime_info(gconv, weights.get_node_shared_ptr()); - } - auto conv_ie = std::make_shared(gconv->input_value(0), - weights, - gconv->get_strides(), - gconv->get_dilations(), - gconv->get_pads_begin(), - gconv->get_pads_end(), - gconv->get_output_element_type(0), - group, - gconv->get_auto_pad()); - conv_ie->set_friendly_name(gconv->get_friendly_name()); - ngraph::copy_runtime_info(gconv, conv_ie); - ngraph::replace_node(gconv, conv_ie); - return true; - }; - - auto m = std::make_shared(gconv, "ConvertGroupConvolution"); - this->register_matcher(m, callback); -} - -ngraph::pass::ConvertDeconvolution::ConvertDeconvolution() { - auto conv = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto deconv = std::dynamic_pointer_cast(m.get_match_root()); - if (!deconv) { - return false; - } - - auto deconv_ie = std::make_shared( - deconv->input_value(0), - deconv->input_value(1), - deconv->get_strides(), - deconv->get_dilations(), - deconv->get_pads_begin(), - deconv->get_pads_end(), - deconv->get_output_element_type(0), - 1 /* groups */, - deconv->get_auto_pad(), - deconv->get_output_padding(), - (deconv->inputs().size() == 3 ? deconv->input_value(2).get_node_shared_ptr() : nullptr)); - deconv_ie->set_friendly_name(deconv->get_friendly_name()); - ngraph::copy_runtime_info(deconv, deconv_ie); - ngraph::replace_node(deconv, deconv_ie); - return true; - }; - - auto m = std::make_shared(conv, "ConvertDeconvolution"); - this->register_matcher(m, callback); -} - -ngraph::pass::ConvertGroupDeconvolution::ConvertGroupDeconvolution() { - auto gconv = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto gconv = std::dynamic_pointer_cast(m.get_match_root()); - if (!gconv) { - return false; - } - size_t group = gconv->input_value(1).get_shape()[0]; - - // Merge weights layout GIOYX to I(G*O)YX - auto input_shape = gconv->input_value(0).get_shape(); - auto weights_shape = gconv->input_value(1).get_shape(); - std::vector reshape_shape{static_cast(weights_shape[1]), - static_cast(weights_shape[2] * group)}; - for (size_t i = 3; i < weights_shape.size(); ++i) { - reshape_shape.push_back(weights_shape[i]); - } - - auto reshape = std::make_shared( - gconv->input_value(1), - op::Constant::create(element::i64, Shape{reshape_shape.size()}, reshape_shape), - true); - auto conv_ie = std::make_shared( - gconv->input_value(0), - reshape, - gconv->get_strides(), - gconv->get_dilations(), - gconv->get_pads_begin(), - gconv->get_pads_end(), - gconv->get_output_element_type(0), - group, - gconv->get_auto_pad(), - gconv->get_output_padding(), - (gconv->inputs().size() == 3 ? gconv->input_value(2).get_node_shared_ptr() : nullptr)); - conv_ie->set_friendly_name(gconv->get_friendly_name()); - ngraph::copy_runtime_info(gconv, conv_ie); - ngraph::replace_node(gconv, conv_ie); - return true; - }; - - auto m = std::make_shared(gconv, "ConvertGroupDeconvolution"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_gather_to_gather_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_gather_to_gather_ie.cpp deleted file mode 100644 index 757ff1dacec..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_gather_to_gather_ie.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_gather_to_gather_ie.hpp" - -#include -#include -#include -#include -#include - -ngraph::pass::ConvertGatherToGatherIEMatcher::ConvertGatherToGatherIEMatcher() { - auto gather = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto gather = std::dynamic_pointer_cast(m.get_match_root()); - if (!gather) { - return false; - } - - auto axes_constant = - std::dynamic_pointer_cast(gather->input_value(2).get_node_shared_ptr()); - if (!axes_constant) { - return false; - } - auto axis = axes_constant->cast_vector()[0]; - - // vector of new created nGraph operations - NodeVector new_ops; - - // if the input with indices is scalar we need to unsqueeze it to 1D so plugins which do not support 0D can - // execute this layer. Then we need to squeeze the axis dimension to restore original shape of gather output - auto indices = gather->input_value(1); - const auto indices_rank = indices.get_partial_shape().rank(); - if (indices_rank.is_dynamic()) { - return false; - } - - bool squeeze_gather_output = false; - if (indices_rank.get_length() == 0) { - squeeze_gather_output = true; - indices = - std::make_shared(indices, - opset1::Constant::create(element::i64, Shape{1}, {0})); - new_ops.push_back(indices.get_node_shared_ptr()); - } - - auto gather_ie = std::make_shared(gather->input_value(0), indices, axis); - new_ops.push_back(gather_ie); - - if (squeeze_gather_output) { - auto sq = - std::make_shared(gather_ie, - opset1::Constant::create(element::i64, Shape{1}, {axis})); - sq->set_friendly_name(gather->get_friendly_name()); - new_ops.push_back(sq); - - ngraph::copy_runtime_info(gather, new_ops); - ngraph::replace_node(gather, sq); - } else { - gather_ie->set_friendly_name(gather->get_friendly_name()); - ngraph::copy_runtime_info(gather, new_ops); - ngraph::replace_node(gather, gather_ie); - } - return true; - }; - - auto m1 = std::make_shared(gather, "ConvertGatherToGatherIE"); - this->register_matcher(m1, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_gathertree_to_gathertree_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_gathertree_to_gathertree_ie.cpp deleted file mode 100644 index 0b981204e92..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_gathertree_to_gathertree_ie.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_gathertree_to_gathertree_ie.hpp" - -#include -#include -#include -#include - -ngraph::pass::ConvertGatherTreeToGatherTreeIEMatcher::ConvertGatherTreeToGatherTreeIEMatcher() { - auto input0 = std::make_shared(element::i64, Shape{1, 1, 1}); - auto input1 = std::make_shared(element::i64, Shape{1, 1, 1}); - auto input2 = std::make_shared(element::i64, Shape{1}); - auto input3 = std::make_shared(element::i64, Shape{}); - auto gt = std::make_shared(input0, input1, input2, input3); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto gt = std::dynamic_pointer_cast(m.get_match_root()); - if (!gt) { - return false; - } - auto reshape = std::make_shared(gt->input_value(3), - opset1::Constant::create(element::i64, Shape{1}, {1}), - true); - auto gt_ie = std::make_shared(gt->input_value(0), - gt->input_value(1), - gt->input_value(2), - reshape); - - gt_ie->set_friendly_name(gt->get_friendly_name()); - ngraph::copy_runtime_info(gt, {reshape, gt_ie}); - ngraph::replace_node(gt, gt_ie); - return true; - }; - - auto m = std::make_shared(gt, "ConvertGatherTreeToGatherTreeIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_hard_sigmoid_to_hard_sigmoid_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_hard_sigmoid_to_hard_sigmoid_ie.cpp deleted file mode 100644 index 5a96c1c4781..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_hard_sigmoid_to_hard_sigmoid_ie.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_hard_sigmoid_to_hard_sigmoid_ie.hpp" - -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertHardSigmoidToLegacyMatcher::ConvertHardSigmoidToLegacyMatcher() { - auto input_0 = std::make_shared(element::f32, Shape{1, 1, 1, 1}); - auto input_1 = std::make_shared(element::f32, Shape{}); - auto input_2 = std::make_shared(element::f32, Shape{}); - auto node = std::make_shared(input_0, input_1, input_2); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto hard_sigmoid = std::dynamic_pointer_cast(m.get_match_root()); - if (!hard_sigmoid) { - return false; - } - - auto alpha = std::dynamic_pointer_cast( - hard_sigmoid->input(1).get_source_output().get_node_shared_ptr()); - if (!alpha) { - return false; - } - - auto beta = std::dynamic_pointer_cast( - hard_sigmoid->input(2).get_source_output().get_node_shared_ptr()); - if (!beta) { - return false; - } - - float alpha_value; - float beta_value; - if (!ov::op::util::get_single_value(alpha, alpha_value) || !ov::op::util::get_single_value(beta, beta_value)) - return false; - - auto hard_sigmoid_ie = std::make_shared(hard_sigmoid->input(0).get_source_output(), - alpha_value, - beta_value); - - hard_sigmoid_ie->set_friendly_name(hard_sigmoid->get_friendly_name()); - ngraph::copy_runtime_info(hard_sigmoid, hard_sigmoid_ie); - ngraph::replace_node(hard_sigmoid, hard_sigmoid_ie); - return true; - }; - - auto m = std::make_shared(node, "ConvertHardSigmoidToLegacy"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_interpolate_to_interp_or_resample.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_interpolate_to_interp_or_resample.cpp deleted file mode 100644 index 7fd5a3f7e2e..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_interpolate_to_interp_or_resample.cpp +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_interpolate_to_interp_or_resample.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertInterpolateToInterpOrResampleMatcher::ConvertInterpolateToInterpOrResampleMatcher() { - auto interpolate = pattern::wrap_type( - {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type()}); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto interpolate = std::dynamic_pointer_cast(m.get_match_root()); - if (!interpolate) - return false; - - auto data_node = interpolate->input_value(0); - auto out_shape_node = - std::dynamic_pointer_cast(interpolate->input_value(1).get_node_shared_ptr()); - auto interpolate_attrs = interpolate->get_attrs(); - auto input_shape = data_node.get_shape(); - - if (!out_shape_node) { - return false; - } - - auto out_spatial_shape = out_shape_node->cast_vector(); - - std::size_t num_of_spatial_vars = input_shape.size() - 2; - auto interpolate_axes = interpolate_attrs.axes; - auto interpolate_mode = interpolate_attrs.mode; - if (num_of_spatial_vars != 2 && num_of_spatial_vars != 3) { - return false; - } - - if (interpolate_attrs.pads_begin.empty()) - interpolate_attrs.pads_begin = std::vector{0}; - if (interpolate_attrs.pads_end.empty()) - interpolate_attrs.pads_end = std::vector{0}; - - std::vector useless_axes; - size_t axis_idx = 0; - for (size_t axis = 0; axis < input_shape.size(); ++axis) { - if (interpolate_axes.count(axis)) { - if (static_cast(input_shape[axis]) == out_spatial_shape[axis_idx] && axis < 2) - // keeping only those not spatial dimensions that are going to be changed - useless_axes.push_back(axis); - ++axis_idx; - } - } - - std::reverse(useless_axes.begin(), useless_axes.end()); - for (const auto& axis : useless_axes) { - interpolate_axes.erase(axis); - out_spatial_shape.erase(out_spatial_shape.begin() + axis); - } - - // Interpolate can be converted when interpolation is performed over spatial dimensions only - if (num_of_spatial_vars == 2 && interpolate_axes != AxisSet{2, 3}) { - return false; - } - - if (num_of_spatial_vars == 2 && interpolate_axes.size() == 2 && - std::set{"nearest", "cubic", "area"}.count(interpolate_mode) == 0) { - auto attrs = ngraph::op::InterpolateIEAttrs(); - attrs.pad_beg = static_cast(interpolate_attrs.pads_begin[0]); - attrs.pad_end = static_cast(interpolate_attrs.pads_end[0]); - attrs.height = static_cast(out_spatial_shape[0]); - attrs.width = static_cast(out_spatial_shape[1]); - attrs.align_corners = interpolate_attrs.align_corners; - attrs.mode = interpolate_mode; - attrs.antialias = interpolate_attrs.antialias; - - auto interp = std::make_shared(data_node, attrs); - interp->set_friendly_name(interpolate->get_friendly_name()); - - ngraph::copy_runtime_info(interpolate, interp); - ngraph::replace_node(interpolate, interp); - } else if (interpolate_attrs.pads_begin[0] == 0 && interpolate_attrs.pads_end[0] == 0 && - !interpolate_attrs.align_corners) { - auto attrs = ngraph::op::ResampleIEAttrs(); - attrs.mode = interpolate_mode; - attrs.antialias = interpolate_attrs.antialias; - - std::shared_ptr resample; - - if (num_of_spatial_vars == 3 && interpolate_axes != AxisSet{2, 3, 4}) { - auto corrected_output_spatial_shape = std::vector(num_of_spatial_vars); - - std::map axis_to_index; - /* - * Because interpolate_axes != AxisSet{2, 3, 4} and num_of_spatial_vars == 3, then - * interpolate_axes can have one of the following values: - * {2}, {3}, {4}, {2, 3}, {2, 4} - * Sizes of out_spatial_shape are correspondigly 1, 1, 1, 2, 2. - * Hence, we need to add missing axes, and shape component for missing axes will be taken from - * input_shape. - */ - int64_t counter = 0; - for (int64_t axis : interpolate_axes) { - axis_to_index[axis] = counter++; - } - - for (int64_t axis = 2; axis <= 4; ++axis) { - auto it = interpolate_axes.find(axis); - if (it != interpolate_axes.end()) { - corrected_output_spatial_shape[axis - 2] = out_spatial_shape[axis_to_index[axis]]; - } else { - corrected_output_spatial_shape[axis - 2] = input_shape[axis]; - } - } - - out_spatial_shape = corrected_output_spatial_shape; - } - - // In case if output shape differ only in spatial dims and can be produced by using factor we set factor - // attr - bool has_same_factor(true); - int64_t factor(0); - for (size_t i = 0; i < out_spatial_shape.size(); ++i) { - if (out_spatial_shape[i] % input_shape[i + 2] == 0) { - int64_t f = out_spatial_shape[i] / input_shape[i + 2]; - if (factor == 0) { - factor = f; - } else if (factor != f) { - has_same_factor = false; - } - } else { - has_same_factor = false; - } - } - - if (has_same_factor && factor != 0) { - attrs.factor = factor; - resample = std::make_shared(data_node, attrs); - } else { - // first concatenates [N,C] shapes from the input tensor with the Interpolate second input value to - // create the desired output shape for the Resample - auto output_shape = out_spatial_shape; - output_shape.insert(output_shape.begin(), input_shape[0]); - output_shape.insert(output_shape.begin() + 1, input_shape[1]); - auto constant = std::make_shared(out_shape_node->get_element_type(), - Shape{output_shape.size()}, - output_shape); - resample = std::make_shared(data_node, constant, attrs); - } - - resample->set_friendly_name(interpolate->get_friendly_name()); - ngraph::copy_runtime_info(interpolate, resample); - ngraph::replace_node(interpolate, resample); - } else { - return false; - } - return true; - }; - - auto m = std::make_shared(interpolate, "ConvertInterpolateToInterpOrResample"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_lrn_to_lrn_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_lrn_to_lrn_ie.cpp deleted file mode 100644 index 0b13a80175e..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_lrn_to_lrn_ie.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_lrn_to_lrn_ie.hpp" - -#include -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertLRNToLegacyMatcher::ConvertLRNToLegacyMatcher() { - auto lrn = pattern::wrap_type({pattern::any_input(), pattern::wrap_type()}, - pattern::has_static_rank()); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto lrn = std::dynamic_pointer_cast(m.get_match_root()); - if (!lrn) { - return false; - } - - auto axis_const = std::dynamic_pointer_cast( - lrn->input(1).get_source_output().get_node_shared_ptr()); - if (!axis_const) { - return false; - } - - auto axis_value = axis_const->cast_vector(); - std::string region; - if (axis_value.size() == 1 && axis_value[0] == 1) { - region = "across"; - } else { - std::vector norm(lrn->get_output_partial_shape(0).rank().get_length(), false); - for (auto& axis : axis_value) { - if (axis < 0 || static_cast(axis) >= norm.size()) { - return false; - } - norm[axis] = true; - } - - // Check that axes belongs to spatial dims - for (size_t i = 2; i < norm.size(); ++i) { - if (!norm[i]) - return false; - } - region = "same"; - } - - auto lrn_ie = std::make_shared(lrn->input(0).get_source_output(), - lrn->get_alpha(), - lrn->get_beta(), - lrn->get_bias(), - lrn->get_nsize(), - region); - - lrn_ie->set_friendly_name(lrn->get_friendly_name()); - ngraph::copy_runtime_info(lrn, lrn_ie); - ngraph::replace_node(lrn, lrn_ie); - return true; - }; - - auto m = std::make_shared(lrn, "ConvertLRNToLegacy"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.cpp deleted file mode 100644 index 03705229b24..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.cpp +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertMatMulToFC::ConvertMatMulToFC() { - auto matmul = pattern::wrap_type( - {pattern::any_input(pattern::has_static_shape()), pattern::any_input(pattern::has_static_shape())}, - pattern::has_static_shape()); - - ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { - auto matmul = std::dynamic_pointer_cast(m.get_match_root()); - if (!matmul || transformation_callback(matmul)) { - return false; - } - - auto input_a = matmul->input(0).get_source_output(); - auto input_b = matmul->input(1).get_source_output(); - - auto shape_a = input_a.get_shape(); - auto shape_b = input_b.get_shape(); - auto output_shape = matmul->get_shape(); - - // Transformation to FC is not supported for 1D second input - if (shape_b.size() == 1) { - return false; - } - - /* - * get_aligned_shapes function align two input shapes to have the same size and - * the same batch dimensions (last two dimensions are not comparable). - * It also checks that dimensions are compatible so in case with two shapes - * for example: [2, 32, 64] [3, 64, 64] it will raise an exception. - */ - - auto get_aligned_shapes = [shape_a, shape_b, &matmul]() -> std::pair { - Shape shape_a_aligned(shape_a), shape_b_aligned(shape_b); - size_t max_size = std::max(shape_a_aligned.size(), shape_b_aligned.size()); - for (size_t i = 0, cnt = max_size - shape_a_aligned.size(); i < cnt; ++i) - shape_a_aligned.insert(shape_a_aligned.begin(), 1); - for (size_t i = 0, cnt = max_size - shape_b_aligned.size(); i < cnt; ++i) - shape_b_aligned.insert(shape_b_aligned.begin(), 1); - - if (matmul->get_transpose_a() && shape_a.size() != 1) { - std::swap(*(shape_a_aligned.end() - 1), *(shape_a_aligned.end() - 2)); - } - if (matmul->get_transpose_b()) { - std::swap(*(shape_b_aligned.end() - 1), *(shape_b_aligned.end() - 2)); - } - - for (size_t i = 0; i < max_size - 2; ++i) { - if (shape_a_aligned[i] != shape_b_aligned[i] && shape_a_aligned[i] > 1 && shape_b_aligned[i] > 1) { - std::ostringstream stream; - stream << "Shapes can't be aligned: " << shape_a_aligned << " " << shape_b_aligned; - OPENVINO_THROW(stream.str()); - } - size_t max_value = std::max(shape_a_aligned[i], shape_b_aligned[i]); - shape_a_aligned[i] = shape_b_aligned[i] = max_value; - } - - return {shape_a_aligned, shape_b_aligned}; - }; - - /* - * create_transpose function return Transpose operation to replace transpose_a or transpose_b - * arguments with an operation. In other words in this function we create Transpose operation - * with order length equal to output_shape length of given node and fill order with increasing - * sequence starting from 0 and replace last two dimension. For example for length = 4 the - * order will be [0, 1, 3, 2] that emulates transpose_a or transpose_b attribute. - */ - - auto create_transpose = [this](Output node, const std::string& transpose_name) -> std::shared_ptr { - Shape output_shape = node.get_node_shared_ptr()->get_shape(); - - std::vector transpose_order(output_shape.size()); - std::iota(transpose_order.begin(), transpose_order.end(), 0); - std::swap(*(transpose_order.end() - 1), *(transpose_order.end() - 2)); - - auto transpose = register_new_node( - node, - opset1::Constant::create(element::i64, Shape{transpose_order.size()}, transpose_order)); - transpose->set_friendly_name(transpose_name); - return transpose; - }; - - // fc_input_a and fc_input_b - are the final inputs that will be set to FullyConnected of GemmIE operations. - // So in case of adding new operations that takes matmul inputs we need keep update fc_input_a and - // fc_input_b updated. - auto fc_input_a = input_a, fc_input_b = input_b; - - // vector of new nGraph operations - NodeVector new_ops; - - // Check that if second inputs is Constant operation and it's shape without ones dimensions has length <= 2 - // we replace MatMul with FullyConnected operation. - // Otherwise we replace MatMul with Gemm. - auto fq_after_const = std::dynamic_pointer_cast(fc_input_b.get_node_shared_ptr()); - bool is_fq_after_const = - fq_after_const && std::dynamic_pointer_cast( - fc_input_b.get_node_shared_ptr()->input_value(0).get_node_shared_ptr()); - if ((std::dynamic_pointer_cast(fc_input_b.get_node_shared_ptr()) || is_fq_after_const) && - std::count_if(shape_b.begin(), shape_b.end(), [](size_t x) { - return x != 1; - }) <= 2) { - Shape shape_a_aligned, shape_b_aligned; - std::tie(shape_a_aligned, shape_b_aligned) = get_aligned_shapes(); - - if (shape_a_aligned.size() < 2 || shape_b_aligned.size() < 2) { - OPENVINO_THROW("MatMul " + matmul->get_friendly_name() + " shapes are inconsistent."); - } - - // Transferring from MatMul representation: [B, I, K] * [B, K, O] = [B, I, O] - // to FullyConnected representation: [I, K] * [O, K] = [I, O] - size_t K = *(shape_a_aligned.end() - 1); - size_t O = *(shape_b_aligned.end() - 1); - Shape B(shape_a_aligned.begin(), shape_a_aligned.end() - 2); - - // Weights normalization - if (!matmul->get_transpose_b()) { - Output constant = fc_input_b; - // transpose the constant itself, not FQ output, to allow constant folding to apply this transpose - if (fq_after_const) { - constant = fc_input_b.get_node_shared_ptr()->input_value(0); - } - fc_input_b = create_transpose(constant, matmul->get_friendly_name() + "/transpose_b"); - new_ops.push_back(fc_input_b.get_node_shared_ptr()); - if (fq_after_const) { - fc_input_b = fq_after_const->clone_with_new_inputs(OutputVector{fc_input_b, - fq_after_const->input_value(1), - fq_after_const->input_value(2), - fq_after_const->input_value(3), - fq_after_const->input_value(4)}); - new_ops.push_back(fc_input_b.get_node_shared_ptr()); - } - } - - if (shape_b.size() != 2) { - auto reshape_shape = - opset1::Constant::create(element::i64, Shape{2}, {-1ll, static_cast(K)}); - fc_input_b = std::make_shared(fc_input_b, reshape_shape, true); - new_ops.push_back(fc_input_b.get_node_shared_ptr()); - } - - // Input normalization - if (matmul->get_transpose_a() && shape_a.size() != 1) { - fc_input_a = create_transpose(fc_input_a, matmul->get_friendly_name() + "/transpose_a"); - new_ops.push_back(fc_input_a.get_node_shared_ptr()); - } - - // Create FullyConnected - std::vector bias_value(O, 0); - auto fc_bias = opset1::Constant::create(matmul->get_output_element_type(0), Shape{O}, bias_value); - - auto fc = std::make_shared(fc_input_a, - fc_input_b, - fc_bias, - output_shape, - matmul->output(0).get_element_type()); - fc->set_friendly_name(matmul->get_friendly_name()); - new_ops.push_back(fc); - - ngraph::copy_runtime_info(matmul, new_ops); - ngraph::replace_node(matmul, fc); - return true; - } - return false; - }; - - auto m = std::make_shared(matmul, "ConvertMatMulToFC"); - this->register_matcher(m, callback); -} - -ngraph::pass::ConvertMatMulToGemm::ConvertMatMulToGemm() { - auto matmul = pattern::wrap_type( - {pattern::any_input(pattern::has_static_shape()), pattern::any_input(pattern::has_static_shape())}, - pattern::has_static_shape()); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto matmul = std::dynamic_pointer_cast(m.get_match_root()); - if (!matmul) { - return false; - } - - auto input_a = matmul->input(0).get_source_output(); - auto input_b = matmul->input(1).get_source_output(); - - auto shape_a = input_a.get_shape(); - auto shape_b = input_b.get_shape(); - auto output_shape = matmul->get_shape(); - - auto fc_input_a = input_a, fc_input_b = input_b; - NodeVector new_ops; - - if (shape_a.size() == 1) { - // If the first input is 1D tensor, it is unsqueezed to 2D tensor (row vector) - // by adding axes with size 1 at ROW_INDEX_DIM, to the left of the shape. - // For example {S} will be reshaped to {1, S}. - fc_input_a = std::make_shared( - fc_input_a, - ngraph::opset1::Constant::create(element::i64, Shape{1}, {0})); - shape_a = fc_input_a.get_shape(); - new_ops.push_back(fc_input_a.get_node_shared_ptr()); - // For 1D inputs transpose flag is expected to always act like `false` - matmul->set_transpose_a(false); - } - if (shape_b.size() == 1) { - // If the second input is 1D tensor, it is unsqueezed to 2D tensor (column vector) - // by adding axes with size 1 at COL_INDEX_DIM, to the right of the shape. - // For example {S} will be reshaped to {S, 1}. - fc_input_b = std::make_shared( - fc_input_b, - ngraph::opset1::Constant::create(element::i64, Shape{1}, {1})); - shape_b = fc_input_b.get_shape(); - new_ops.push_back(fc_input_b.get_node_shared_ptr()); - // For 1D inputs transpose flag is expected to always act like `false` - matmul->set_transpose_b(false); - } - - // WA for IE that Gemm must have inputs with the same length. - // If ranks of input arguments are still different, - // the smaller tensor is unsqueezed from the left side of the shape - // by necessary number of axes to make both shapes of the same rank. - if (shape_a.size() < shape_b.size()) { - // Reshape first input (fc_input_a) - Shape reshape_shape(shape_b.size() - shape_a.size(), 1); - reshape_shape.insert(reshape_shape.end(), shape_a.begin(), shape_a.end()); - fc_input_a = ov::op::util::reshapeTo(fc_input_a, reshape_shape); - new_ops.push_back(fc_input_a.get_node_shared_ptr()); - } else if (shape_b.size() < shape_a.size()) { - // Reshape second input (fc_input_b) - Shape reshape_shape(shape_a.size() - shape_b.size(), 1); - reshape_shape.insert(reshape_shape.end(), shape_b.begin(), shape_b.end()); - fc_input_b = ov::op::util::reshapeTo(fc_input_b, reshape_shape); - new_ops.push_back(fc_input_b.get_node_shared_ptr()); - } - - auto gemm = matmul->clone_with_new_inputs({fc_input_a, fc_input_b}); - new_ops.push_back(gemm); - - if (gemm->get_shape() != output_shape) { - // This case is possible when one of the inputs has exactly 1 dimension (that is not supported by GEMM - // operation) So to preserve output shape we insert additional reshape operation - std::shared_ptr reshape_output; - if (output_shape.size() == 0) { - std::vector dim_indices(gemm->get_shape().size()); - std::iota(dim_indices.begin(), dim_indices.end(), 0); - reshape_output = std::make_shared( - gemm, - ngraph::opset1::Constant::create(element::i64, Shape{dim_indices.size()}, dim_indices)); - } else { - reshape_output = ov::op::util::reshapeTo(gemm, output_shape); - } - - new_ops.push_back(reshape_output); - gemm->set_friendly_name(matmul->get_friendly_name() + "/gemm"); - reshape_output->set_friendly_name(matmul->get_friendly_name()); - ngraph::copy_runtime_info(matmul, new_ops); - ngraph::replace_node(matmul, reshape_output); - } else { - gemm->set_friendly_name(matmul->get_friendly_name()); - ngraph::copy_runtime_info(matmul, new_ops); - ngraph::replace_node(matmul, gemm); - } - - return true; - }; - - auto m = std::make_shared(matmul, "ConvertMatMulToGemm"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.cpp deleted file mode 100644 index 0c3f95ef47d..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.cpp +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.hpp" - -#include -#include -#include -#include -#include - -#include "legacy/ngraph_ops/power.hpp" -#include "legacy/ngraph_ops/scaleshift.hpp" -#include "transformations/utils/utils.hpp" - -CONVERSION_RESULT check_constant(const std::shared_ptr& constant, - const ngraph::PartialShape& shape) { - if (!constant || shape.rank().is_dynamic()) - return CONVERSION_RESULT::NONE; - - auto const_shape = constant->get_shape(); - std::vector input_shape(shape); - - // In case of scalar we will convert it to Power - if (const_shape.empty() || (const_shape.size() == 1 && const_shape[0] == 1)) { - return CONVERSION_RESULT::POWER; - } - - // Align shapes - size_t max_shape_len = std::max(input_shape.size(), const_shape.size()); - while (const_shape.size() < max_shape_len) - const_shape.insert(const_shape.begin(), 1); - while (input_shape.size() < max_shape_len) - input_shape.insert(input_shape.begin(), 1); - - // This is feature dimension index from right side (ex. for NCDHW it's equal to 3). - const size_t feature_index = input_shape.size() - 2; - if (const_shape.size() < feature_index) - return CONVERSION_RESULT::NONE; - - bool is_power = false; - auto in_it = const_shape.rbegin(); - auto out_it = input_shape.rbegin(); - for (size_t idx = 0; in_it != const_shape.rend() && out_it != input_shape.rend(); ++in_it, ++out_it, ++idx) { - if (idx != feature_index && *in_it != 1) { - return CONVERSION_RESULT::NONE; - } - - if (idx == feature_index && *in_it == 1) { - is_power = true; - } else if (idx == feature_index && - (out_it->is_dynamic() || static_cast(*in_it) != out_it->get_length())) { - return CONVERSION_RESULT::NONE; - } - } - - return is_power ? CONVERSION_RESULT::POWER : CONVERSION_RESULT::SCALE_SHIFT; -} - -ngraph::pass::ConvertMulAddToScaleShiftOrPower::ConvertMulAddToScaleShiftOrPower() { - auto data_batch = std::make_shared(element::f32, Shape{1}); - - auto weights = std::make_shared(element::f32, Shape{1}, std::vector{0}); - auto bias = std::make_shared(element::f32, Shape{1}, std::vector{0}); - - auto mul = std::make_shared(data_batch, weights); - auto add = std::make_shared(mul, bias); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto add_node = ngraph::as_type_ptr(m.get_match_root()); - - if (!add_node) { - return false; - } - - if (!add_node->get_element_type().is_real()) { - return false; - } - - auto add_input_0 = add_node->input(0).get_source_output().get_node_shared_ptr(); - auto add_input_1 = add_node->input(1).get_source_output().get_node_shared_ptr(); - - auto mul_node = ngraph::as_type_ptr(add_input_0); - auto const_bias_node = ngraph::as_type_ptr(add_input_1); - if (!mul_node) { - mul_node = ngraph::as_type_ptr(add_input_1); - const_bias_node = ngraph::as_type_ptr(add_input_0); - } - - if (const_bias_node->output(0).get_element_type() != add_node->output(0).get_element_type()) { - return false; - } - - auto mul_input_0 = mul_node->input(0).get_source_output().get_node_shared_ptr(); - auto mul_input_1 = mul_node->input(1).get_source_output().get_node_shared_ptr(); - - auto data_node = mul_node->input(0).get_source_output(); - auto const_weights_node = ngraph::as_type_ptr(mul_input_1); - if (!const_weights_node) { - data_node = mul_node->input(1).get_source_output(); - const_weights_node = ngraph::as_type_ptr(mul_input_0); - } - - if (const_weights_node->output(0).get_element_type() != mul_node->output(0).get_element_type()) { - return false; - } - - if (add_node->get_output_partial_shape(0).rank().is_dynamic() || - mul_node->get_output_partial_shape(0).rank().is_dynamic()) { - return false; - } - - // Check that eltwise is not useless otherwise we remove it - if (ov::op::util::constantIsEqualTo(const_weights_node, 1) && - ov::op::util::constantIsEqualTo(const_bias_node, 0)) { - bool has_result_output = false; - for (const auto& output : add_node->output(0).get_target_inputs()) { - if (dynamic_cast(output.get_node())) { - has_result_output = true; - } - } - - auto parent = data_node.get_node_shared_ptr(); - size_t consumers_count = 0; - for (const auto& output : parent->outputs()) { - consumers_count += output.get_target_inputs().size(); - } - - if (!has_result_output || consumers_count == 1) { - if (!std::dynamic_pointer_cast(parent)) { - parent->set_friendly_name(add_node->get_friendly_name()); - } - // TODO: due to ngraph::replace_node function limitations we have to reconnect output port consumers to - // the new input using replace_source_output method - for (auto& input : add_node->output(0).get_target_inputs()) { - input.replace_source_output(data_node); - } - return true; - } - } - - auto res1 = check_constant(const_weights_node, data_node.get_partial_shape()); - auto res2 = check_constant(const_bias_node, mul_node->get_output_partial_shape(0)); - - const auto output_shape = add_node->get_output_partial_shape(0); - const auto output_shape_rank = output_shape.rank().get_length(); - - if (res1 == CONVERSION_RESULT::NONE || res2 == CONVERSION_RESULT::NONE || - ((res1 == CONVERSION_RESULT::SCALE_SHIFT || res2 == CONVERSION_RESULT::SCALE_SHIFT) && - output_shape_rank < 4)) { - return false; - } - - // TODO: in case if scale and shift constants has equal values the best way is to convert them to Power - if (res1 == CONVERSION_RESULT::SCALE_SHIFT || res2 == CONVERSION_RESULT::SCALE_SHIFT) { - NodeVector new_ops; - - auto weights_in = ov::op::util::normalize_constant(const_weights_node, output_shape); - auto biases_in = ov::op::util::normalize_constant(const_bias_node, output_shape); - new_ops.push_back(weights_in); - new_ops.push_back(biases_in); - - if (res1 == CONVERSION_RESULT::POWER) { - weights_in = ov::op::util::broadcastTo(weights_in, biases_in->get_shape()); - new_ops.push_back(weights_in); - } - if (res2 == CONVERSION_RESULT::POWER) { - biases_in = ov::op::util::broadcastTo(biases_in, weights_in->get_shape()); - new_ops.push_back(biases_in); - } - - auto output_type = m.get_match_root()->get_output_element_type(0); - auto scaleshift = std::make_shared(data_node, weights_in, biases_in, output_type); - new_ops.push_back(scaleshift); - - scaleshift->set_friendly_name(add_node->get_friendly_name()); - ngraph::copy_runtime_info({mul_node, add_node}, new_ops); - ngraph::replace_node(m.get_match_root(), scaleshift); - } else { - float scale = 0.f, shift = 0.f; - if (!ov::op::util::get_single_value(const_weights_node, scale)) { - return false; - } - if (!ov::op::util::get_single_value(const_bias_node, shift)) { - return false; - } - - auto output_type = m.get_match_root()->get_output_element_type(0); - auto power = std::make_shared(data_node, 1.0f, scale, shift, output_type); - power->set_friendly_name(add_node->get_friendly_name()); - ngraph::copy_runtime_info({mul_node, add_node}, power); - ngraph::replace_node(m.get_match_root(), power); - } - - return true; - }; - - auto m = std::make_shared(add, "MulAddToScaleShiftOrPower"); - register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.cpp deleted file mode 100644 index b20f56605d7..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.cpp +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp" - -#include -#include -#include - -#include "legacy/ngraph_ops/eltwise.hpp" -#include "legacy/ngraph_ops/power.hpp" -#include "legacy/ngraph_ops/scaleshift.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.hpp" -#include "transformations/utils/utils.hpp" - -template -bool convert_to_eltwise(std::shared_ptr& node, - ngraph::Output data1, - ngraph::Output data2) { - ELTWISE_TYPE et; - if (std::is_same()) { - et = ELTWISE_TYPE::Prod; - } else if (std::is_same()) { - et = ELTWISE_TYPE::Sum; - } else if (std::is_same()) { - et = ELTWISE_TYPE::Sub; - } else { - return false; - } - - auto eltwise = std::make_shared(data1, data2, et, node->output(0).get_element_type()); - eltwise->set_friendly_name(node->get_friendly_name()); - ngraph::copy_runtime_info(node, eltwise); - ngraph::replace_node(node, eltwise); - return true; -} - -template -ngraph::matcher_pass_callback get_callback() { - ngraph::matcher_pass_callback callback = [](ngraph::pattern::Matcher& m) { - static_assert(std::is_same() || std::is_same() || - std::is_same(), - "Unsupported template parameter. Only Add or Multiply allowed!"); - - auto lin_op = std::dynamic_pointer_cast(m.get_match_root()); - if (!lin_op || lin_op->output(0).get_partial_shape().rank().is_dynamic()) { - return false; - } - - const auto output_shape = lin_op->output(0).get_partial_shape(); - const auto output_shape_rank = output_shape.rank().get_length(); - - const auto intInputs = - !lin_op->get_input_element_type(0).is_real() && !lin_op->get_input_element_type(1).is_real(); - - if (!lin_op->get_element_type().is_real() || intInputs) { - return convert_to_eltwise(lin_op, - lin_op->input(0).get_source_output(), - lin_op->input(1).get_source_output()); - } - - std::shared_ptr const_node = std::dynamic_pointer_cast( - lin_op->input(0).get_source_output().get_node_shared_ptr()); - auto data_node = lin_op->input(1).get_source_output(); - if (!const_node) { - const_node = std::dynamic_pointer_cast( - lin_op->input(1).get_source_output().get_node_shared_ptr()); - data_node = lin_op->input(0).get_source_output(); - if (!const_node) { - return convert_to_eltwise(lin_op, - lin_op->input(0).get_source_output(), - lin_op->input(1).get_source_output()); - } - } - - /* This lambda checks data and constant shapes for broadcasting - For example: - 1. data_shape{1, 64, 64} and const_shape{64, 1, 1} - constant broadcasts data_shape zero dimension - 2. data_shape{DYN, 64, 64} and const_shape{1, 1, 64} - constant do not broadcasts data_shape - 3. data_shape{64, 64} and const_shape{1, 1, 1} - constant broadcasts data_shape with additional - dimension - */ - auto constant_broadcast_output = [](const ngraph::PartialShape& data_pshape, - const ngraph::Shape& const_shape) -> bool { - if (data_pshape.rank().is_dynamic() || - const_shape.size() > static_cast(data_pshape.rank().get_length())) { - return true; - } - - std::vector data_shape(data_pshape); - - auto const_shape_it = const_shape.rbegin(); - auto data_shape_it = data_shape.rbegin(); - - while (const_shape_it != const_shape.rend()) { - auto data_dim = *data_shape_it; - auto const_dim = *const_shape_it; - - /* DATA DIM - CONST DIM - CONSTANT BROADCAST OUTPUT - DYN - 64 - TRUE - DYN - 1 - FALSE - 64 - 1 - FALSE - 1 - 64 - TRUE - 64 - 64 - FALSE - */ - if ((data_dim.is_dynamic() && const_dim != 1) || - (data_dim.is_static() && data_dim.get_length() == 1 && const_dim != 1)) { - return true; - } - - ++const_shape_it; - ++data_shape_it; - } - - return false; - }; - - // Check that eltwise is not useless and do not broadcast output otherwise we remove it - if (((std::is_same() && ov::op::util::constantIsEqualTo(const_node, 0)) || - (std::is_same() && ov::op::util::constantIsEqualTo(const_node, 1))) && - !constant_broadcast_output(data_node.get_partial_shape(), const_node->get_shape())) { - bool ret_status = ngraph::replace_output_update_name(lin_op->output(0), data_node); - if (ret_status) { - return true; - } - } - - auto res = check_constant(const_node, data_node.get_partial_shape()); - - if (res == CONVERSION_RESULT::NONE || (res == CONVERSION_RESULT::SCALE_SHIFT && output_shape_rank < 4)) { - return convert_to_eltwise(lin_op, - lin_op->input(0).get_source_output(), - lin_op->input(1).get_source_output()); - } - - // TODO: if all values in Constant are equal the best way is to convert this Eltwise to Power - if (res == CONVERSION_RESULT::SCALE_SHIFT) { - auto weights_et = const_node->get_element_type(); - auto weights_shape = const_node->get_shape(); - - // In case of Add we create fake weights with 1, in case of Multiply we create fake bias with 0 - std::shared_ptr scaleshift; - if (std::is_same()) { - auto weights = ngraph::opset1::Constant::create(weights_et, weights_shape, {1}); - auto weights_in = ov::op::util::normalize_constant(weights, output_shape); - auto biases_in = ov::op::util::normalize_constant(const_node, output_shape); - scaleshift = std::make_shared(data_node, weights_in, biases_in); - } else if (std::is_same()) { - std::shared_ptr new_const_node = std::make_shared( - ov::op::util::normalize_constant(const_node, output_shape), - ngraph::opset1::Constant::create(weights_et, ngraph::Shape{1}, {-1})); - - auto weights = ngraph::opset1::Constant::create(weights_et, weights_shape, {1}); - auto weights_in = ov::op::util::normalize_constant(weights, output_shape); - auto biases_in = new_const_node; - scaleshift = std::make_shared(data_node, weights_in, biases_in); - } else if (std::is_same()) { - auto bias = ngraph::opset1::Constant::create(weights_et, weights_shape, {0}); - auto weights_in = ov::op::util::normalize_constant(const_node, output_shape); - auto biases_in = ov::op::util::normalize_constant(bias, output_shape); - scaleshift = std::make_shared(data_node, weights_in, biases_in); - } else { - return false; - } - - scaleshift->set_friendly_name(lin_op->get_friendly_name()); - ngraph::copy_runtime_info(m.get_match_root(), scaleshift); - ngraph::replace_node(m.get_match_root(), scaleshift); - } else { - float value; - if (!ov::op::util::get_single_value(const_node, value)) { - return false; - } - - // In case Add we create fake scale equal to 1, in case of Multiply we create fake shift equal to 0 - std::shared_ptr power; - if (std::is_same()) { - power = std::make_shared(data_node, - 1.0f, - 1.0f, - value, - lin_op->get_output_element_type(0)); - } else if (std::is_same()) { - power = std::make_shared(data_node, - 1.0f, - value, - 0.0f, - lin_op->get_output_element_type(0)); - } else if (std::is_same()) { - power = std::make_shared(data_node, - 1.0f, - 1.0f, - -value, - lin_op->get_output_element_type(0)); - } else { - return false; - } - power->set_friendly_name(lin_op->get_friendly_name()); - ngraph::copy_runtime_info(m.get_match_root(), power); - ngraph::replace_node(m.get_match_root(), power); - } - - return true; - }; - return callback; -} - -class ConvertAdd : public ov::pass::MatcherPass { -public: - ConvertAdd() { - auto m = std::make_shared(ngraph::pattern::wrap_type()); - register_matcher(m, get_callback()); - } -}; - -class ConvertSub : public ov::pass::MatcherPass { -public: - ConvertSub() { - auto m = std::make_shared(ngraph::pattern::wrap_type()); - register_matcher(m, get_callback()); - } -}; - -class ConvertMul : public ov::pass::MatcherPass { -public: - ConvertMul() { - auto m = std::make_shared(ngraph::pattern::wrap_type()); - register_matcher(m, get_callback()); - } -}; - -ngraph::pass::ConvertMulOrAddFinally::ConvertMulOrAddFinally() { - add_matcher(); - add_matcher(); - add_matcher(); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_nms_5_to_legacy.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_nms_5_to_legacy.cpp deleted file mode 100644 index ef3954955ef..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_nms_5_to_legacy.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_nms_5_to_legacy.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertNMS5ToLegacyMatcher::ConvertNMS5ToLegacyMatcher(bool force_i32_output_type) { - auto nms = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [force_i32_output_type](pattern::Matcher& m) { - auto nms_5 = std::dynamic_pointer_cast(m.get_match_root()); - if (!nms_5) { - return false; - } - - const auto new_args = nms_5->input_values(); - const std::size_t num_of_inputs = new_args.size(); - - const auto& arg2 = - num_of_inputs > 2 ? new_args.at(2) : ngraph::opset5::Constant::create(element::i32, Shape{}, {0}); - const auto& arg3 = - num_of_inputs > 3 ? new_args.at(3) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); - const auto& arg4 = - num_of_inputs > 4 ? new_args.at(4) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); - - // vector of new nGraph operations - NodeVector new_ops; - - auto one_dim_shape = Shape{1}; - - Output new_max_per_class; - Output new_iou_threshold; - Output new_score_threshold; - Output new_soft_nms_sigma; - - Output new_shape_for_max_per_class = opset1::Constant::create(ngraph::element::i64, Shape{1}, {1}); - Output new_shape_for_iou_threshold = opset1::Constant::create(ngraph::element::i64, Shape{1}, {1}); - Output new_shape_for_score_threshold = opset1::Constant::create(ngraph::element::i64, Shape{1}, {1}); - Output new_shape_for_soft_nms_sigma = opset1::Constant::create(ngraph::element::i64, Shape{1}, {1}); - - new_max_per_class = std::make_shared(arg2, new_shape_for_max_per_class, true); - new_ops.emplace_back(new_max_per_class.get_node_shared_ptr()); - - new_iou_threshold = std::make_shared(arg3, new_shape_for_iou_threshold, true); - new_ops.emplace_back(new_iou_threshold.get_node_shared_ptr()); - - new_score_threshold = std::make_shared(arg4, new_shape_for_score_threshold, true); - new_ops.emplace_back(new_score_threshold.get_node_shared_ptr()); - - int center_point_box = 0; - switch (nms_5->get_box_encoding()) { - case ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CENTER: - center_point_box = 1; - break; - case ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER: - center_point_box = 0; - break; - default: - OPENVINO_THROW("NonMaxSuppression layer " + nms_5->get_friendly_name() + " has unsupported box encoding"); - } - - std::shared_ptr nms_legacy{nullptr}; - - auto output_type = force_i32_output_type ? element::i32 : nms_5->get_output_type(); - if (num_of_inputs > 5 && !nms_5->is_soft_nms_sigma_constant_and_default()) { - new_soft_nms_sigma = std::make_shared(new_args.at(5), new_shape_for_soft_nms_sigma, true); - new_ops.emplace_back(new_soft_nms_sigma.get_node_shared_ptr()); - nms_legacy = std::make_shared(new_args.at(0), - new_args.at(1), - new_max_per_class, - new_iou_threshold, - new_score_threshold, - new_soft_nms_sigma, - center_point_box, - nms_5->get_sort_result_descending(), - output_type); - new_ops.push_back(nms_legacy); - } else { - nms_legacy = std::make_shared(new_args.at(0), - new_args.at(1), - new_max_per_class, - new_iou_threshold, - new_score_threshold, - center_point_box, - nms_5->get_sort_result_descending(), - output_type); - new_ops.push_back(nms_legacy); - } - - Output output_0 = nms_legacy->output(0); - if (nms_5->output(0).get_element_type() != output_0.get_element_type()) { - output_0 = std::make_shared(output_0, nms_5->output(0).get_element_type()); - output_0.get_node_shared_ptr()->set_friendly_name(nms_5->get_friendly_name() + "/convert.0"); - new_ops.emplace_back(output_0.get_node_shared_ptr()); - } - - Output output_2 = nms_legacy->output(2); - if (nms_5->output(2).get_element_type() != output_2.get_element_type()) { - output_2 = std::make_shared(output_2, nms_5->output(2).get_element_type()); - output_2.get_node_shared_ptr()->set_friendly_name(nms_5->get_friendly_name() + "/convert.2"); - new_ops.emplace_back(output_2.get_node_shared_ptr()); - } - - nms_legacy->set_friendly_name(nms_5->get_friendly_name()); - ngraph::copy_runtime_info(nms_5, new_ops); - ngraph::replace_node(nms_5, {output_0, nms_legacy->output(1), output_2}); - return true; - }; - - auto m = std::make_shared(nms, "ConvertNMS5ToNMSLegacy"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_nms_to_nms_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_nms_to_nms_ie.cpp deleted file mode 100644 index c9a51136a91..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_nms_to_nms_ie.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_nms_to_nms_ie.hpp" - -#include -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertNMSToNMSIEMatcher::ConvertNMSToNMSIEMatcher() { - auto nms = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto nms = std::dynamic_pointer_cast(m.get_match_root()); - if (!nms) { - return false; - } - - const auto max_output_boxes_per_class_rank = nms->input(2).get_partial_shape().rank(); - const auto iou_threshold_rank = nms->input(3).get_partial_shape().rank(); - const auto score_threshold_rank = nms->input(4).get_partial_shape().rank(); - // Check that required ranks are not dynamic - if (max_output_boxes_per_class_rank.is_dynamic() || iou_threshold_rank.is_dynamic() || - score_threshold_rank.is_dynamic()) { - return false; - } - - if (max_output_boxes_per_class_rank.get_length() == 1 && iou_threshold_rank.get_length() == 1 && - score_threshold_rank.get_length() == 1) { - return false; - } - - // vector of new nGraph operations - NodeVector new_ops; - - auto new_max_per_class = nms->input_value(2); - if (max_output_boxes_per_class_rank.get_length() == 0) { - // WA: we need to create Constant manually because it requires by NMS shape inference - // otherwise we will get dynamic shape until first CF is executed. It can be resolved - // if CF will be executed right after transformation and before Validate pass. - if (auto new_max_per_class_const = - std::dynamic_pointer_cast(new_max_per_class.get_node_shared_ptr())) { - new_max_per_class = - opset1::Constant::create(element::i64, Shape{1}, new_max_per_class_const->cast_vector()); - } else { - new_max_per_class = - std::make_shared(nms->input_value(2), - opset1::Constant::create(element::i64, Shape{1}, {0})); - new_ops.push_back(new_max_per_class.get_node_shared_ptr()); - } - } - auto new_iou_threshold = nms->input_value(3); - if (iou_threshold_rank.get_length() == 0) { - new_iou_threshold = - std::make_shared(nms->input_value(3), - opset1::Constant::create(element::i64, Shape{1}, {0})); - new_ops.push_back(new_iou_threshold.get_node_shared_ptr()); - } - auto new_score_threshold = nms->input_value(4); - if (score_threshold_rank.get_length() == 0) { - new_score_threshold = - std::make_shared(nms->input_value(4), - opset1::Constant::create(element::i64, Shape{1}, {0})); - new_ops.push_back(new_score_threshold.get_node_shared_ptr()); - } - int center_point_box = 0; - switch (nms->get_box_encoding()) { - case ::ngraph::opset3::NonMaxSuppression::BoxEncodingType::CENTER: - center_point_box = 1; - break; - case ::ngraph::opset3::NonMaxSuppression::BoxEncodingType::CORNER: - center_point_box = 0; - break; - default: - OPENVINO_THROW("NonMaxSuppression layer " + nms->get_friendly_name() + " has unsupported box encoding"); - } - auto new_nms = std::make_shared(nms->input_value(0), - nms->input_value(1), - new_max_per_class, - new_iou_threshold, - new_score_threshold, - center_point_box, - nms->get_sort_result_descending(), - nms->get_output_type()); - new_ops.push_back(new_nms); - new_nms->set_friendly_name(nms->get_friendly_name()); - ngraph::copy_runtime_info(nms, new_ops); - ngraph::replace_node(nms, new_nms); - return true; - }; - - auto m = std::make_shared(nms, "ConvertNMSToNMSIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.cpp deleted file mode 100644 index 15d210b44d2..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.hpp" - -#include -#include -#include -#include - -#include "legacy/ngraph_ops/normalize_ie.hpp" - -ngraph::pass::ConvertNormalizeL2WithMulToNormalizeIE::ConvertNormalizeL2WithMulToNormalizeIE() { - auto input_0 = std::make_shared(element::f32, Shape{1, 1, 1, 1}); - auto input_1 = std::make_shared(element::f32, Shape{1, 1, 1, 1}); - auto axis = std::make_shared(element::i64, Shape{1}, std::vector{0}); - - auto normalize = std::make_shared(input_0, axis, 0.0f, ngraph::op::EpsMode::ADD); - auto mul = std::make_shared(normalize, input_1); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto mul = std::dynamic_pointer_cast(m.get_match_root()); - if (!mul) - return false; - - auto normalize = std::dynamic_pointer_cast( - mul->input(0).get_source_output().get_node_shared_ptr()); - auto weights_output = mul->input(1).get_source_output(); - if (!normalize) { - normalize = std::dynamic_pointer_cast( - mul->input(1).get_source_output().get_node_shared_ptr()); - weights_output = mul->input(1).get_source_output(); - if (!normalize) - return false; - } - - auto const_axis = std::dynamic_pointer_cast( - normalize->input(1).get_source_output().get_node_shared_ptr()); - if (!const_axis) - return false; - - // Handle two cases: - // 1. When Mul has weights input as Broadcast - // 2. When Mul has weights as Constant - - auto broadcast = std::dynamic_pointer_cast(weights_output.get_node_shared_ptr()); - auto constant = std::dynamic_pointer_cast(weights_output.get_node_shared_ptr()); - - if (broadcast) { - constant = std::dynamic_pointer_cast( - broadcast->input(0).get_source_output().get_node_shared_ptr()); - } - - if (!constant) { - return false; - } - - // Replace NormalizeL2 with NormalizeIE operation - - auto axis = const_axis->cast_vector(); - bool across_spatial = !(axis.size() == 1 && axis[0] == 1); - bool channel_shared = (constant->get_shape().size() == 1); - - auto normalize_ie = std::make_shared(normalize->input(0).get_source_output(), - constant->output(0), - normalize->get_eps(), - across_spatial, - channel_shared, - normalize->get_element_type()); - - normalize_ie->set_friendly_name(mul->get_friendly_name()); - ngraph::copy_runtime_info({normalize, mul}, normalize_ie); - ngraph::replace_node(mul, normalize_ie); - return true; - }; - - auto m = std::make_shared(mul, "CPUFusion.ConvertNormalizeL2WithMulToNormalizeIE"); - this->register_matcher(m, callback); -} - -ngraph::pass::ConvertNormalizeL2ToLegacyMatcher::ConvertNormalizeL2ToLegacyMatcher() { - auto input_0 = std::make_shared(element::f32, Shape{1, 1, 1, 1}); - auto axis = std::make_shared(element::i64, Shape{1}, std::vector{0}); - auto normalize = std::make_shared(input_0, axis, 0.0f, ngraph::op::EpsMode::ADD); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto normalize = std::dynamic_pointer_cast(m.get_match_root()); - if (!normalize) - return false; - - auto const_axis = std::dynamic_pointer_cast( - normalize->input(1).get_source_output().get_node_shared_ptr()); - if (!const_axis) - return false; - - // Replace NormalizeL2 with NormalizeIE operation - auto axis = const_axis->cast_vector(); - bool across_channels = !(axis.size() == 1 && axis[0] == 1); - bool channel_shared = true; - - auto scale = std::make_shared(normalize->output(0).get_element_type(), - Shape{1}, - std::vector{1.0}); - - auto normalize_ie = std::make_shared(normalize->input(0).get_source_output(), - scale->output(0), - normalize->get_eps(), - across_channels, - channel_shared, - normalize->get_element_type()); - - normalize_ie->set_friendly_name(normalize->get_friendly_name()); - ngraph::copy_runtime_info(normalize, normalize_ie); - ngraph::replace_node(normalize, normalize_ie); - return true; - }; - - auto m = std::make_shared(normalize, "ConvertNormalizeL2ToNormalizeIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_one_hot_to_one_hot_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_one_hot_to_one_hot_ie.cpp deleted file mode 100644 index cc68ba78c0e..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_one_hot_to_one_hot_ie.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_one_hot_to_one_hot_ie.hpp" - -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertOneHotToOneHotIEMatcher::ConvertOneHotToOneHotIEMatcher() { - auto input = std::make_shared(element::i32, Shape{1, 1, 1, 1}); - auto depth = std::make_shared(element::i64, Shape{}); - auto on_value = std::make_shared(element::f32, Shape{}); - auto off_value = std::make_shared(element::f32, Shape{}); - auto one_hot = std::make_shared(input, depth, on_value, off_value, 1); - - ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { - auto one_hot = std::dynamic_pointer_cast(m.get_match_root()); - if (!one_hot) { - return false; - } - - const auto depth_node = - std::dynamic_pointer_cast(one_hot->input_value(1).get_node_shared_ptr()); - const auto on_value_node = - std::dynamic_pointer_cast(one_hot->input_value(2).get_node_shared_ptr()); - const auto off_value_node = - std::dynamic_pointer_cast(one_hot->input_value(3).get_node_shared_ptr()); - - // can be converted iff inputs with depth, on/off values are constants - if (depth_node == nullptr || on_value_node == nullptr || off_value_node == nullptr) - return false; - - auto depth_value = std::stoi(depth_node->convert_value_to_string(0)); - auto on_value = std::stof(on_value_node->convert_value_to_string(0)); - auto off_value = std::stof(off_value_node->convert_value_to_string(0)); - - auto one_hot_ie = std::make_shared(one_hot->input_value(0), - static_cast(one_hot->get_axis()), - depth_value, - on_value, - off_value, - m_output_type); - one_hot_ie->set_friendly_name(one_hot->get_friendly_name()); - - // insert Convert layer to cast output to a correct data type defined by the on/off values - if (on_value_node->get_element_type() != m_output_type) { - auto convert = std::make_shared(one_hot_ie, on_value_node->get_element_type()); - convert->set_friendly_name(one_hot->get_friendly_name()); - ngraph::copy_runtime_info(one_hot, {one_hot_ie, convert}); - ngraph::replace_node(m.get_match_root(), convert); - } else { - ngraph::copy_runtime_info(one_hot, one_hot_ie); - ngraph::replace_node(m.get_match_root(), one_hot_ie); - } - - return true; - }; - - auto m = std::make_shared(one_hot, "ConvertOneHotToOneHotIE"); - this->register_matcher(m, callback); -} - -void ngraph::pass::ConvertOneHotToOneHotIEMatcher::detect_output_type(const std::shared_ptr& f) { - m_output_type = ov::op::util::has_f16_constants(f) ? element::Type_t::f16 : element::Type_t::f32; -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.cpp deleted file mode 100644 index b527127b03f..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.cpp +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "legacy/transformations/convert_opset1_to_legacy/conv_bias_fusion.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_cells_to_cells_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_convolutions.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_gather_to_gather_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_gathertree_to_gathertree_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_hard_sigmoid_to_hard_sigmoid_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_interpolate_to_interp_or_resample.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_lrn_to_lrn_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_nms_5_to_legacy.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_one_hot_to_one_hot_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_pad_to_pad_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_prelu_to_relu_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_selu_to_selu_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_strided_slice_to_crop.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_swish_to_swish_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_tile_to_ie_tile.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_topk_to_topk_ie.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/fc_bias_fusion.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/reshape_1d_ops.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/reshape_fully_connected.hpp" - -bool ngraph::pass::ConvertOpSet1ToLegacy::run_on_model(const std::shared_ptr& f) { - ngraph::pass::Manager manager(get_pass_config()); - - manager.register_pass(); - - // Some passes before ConvertOpSet1ToLegacy can produce some of this - // operations. So for convenience we decompose this operations here and - // in CommonOptimizations. - auto decomp = manager.register_pass(); - decomp->add_matcher(); - decomp->add_matcher(); - decomp->add_matcher(); - decomp->add_matcher(); - decomp->add_matcher(); - decomp->set_name("ngraph::pass::LegacyDecompositions"); - - auto convert_matmul = manager.register_pass(); - convert_matmul->add_matcher(); - convert_matmul->add_matcher(); - convert_matmul->add_matcher(); - convert_matmul->set_name("ngraph::pass::ConvertMatMul"); - - manager.register_pass(); - - // Convolution/Deconvolution/FullyConnected fusions - manager.register_pass(); - - // Convolution/Deconvolution/FullyConnected fusions - auto fusion = manager.register_pass(); - fusion->add_matcher(); - fusion->add_matcher(); - fusion->add_matcher(); - fusion->set_name("ngraph::pass::BiasFusions"); - - // CF is required after fusions - manager.register_pass(); - - // List of passes that convert opset1 operations to legacy - // plus transformations that are required by InferenceEngine - // All this transformations can be executed simultaneously - auto anchor = manager.register_pass(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher()->detect_output_type(f); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->add_matcher(); - anchor->set_name("ngraph::pass::LegacyConversions"); - - // List of final conversion transformations that must to be executed - // after previous group of transformations - - if (!ov::op::util::has_op_with_type(f)) { - manager.register_pass(); - } - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - - manager.register_pass(); - - manager.run_passes(f); - - // Returning value is false because pass::Manager always apply Validation pass - // if function was changed. This helps to avoid excess Validations after applying - // this pass. In future when we will return more meaningful status code it will be - // replaced with real status reported by manager.run_passes() method call. - return false; -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_pad_to_pad_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_pad_to_pad_ie.cpp deleted file mode 100644 index 211450914c1..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_pad_to_pad_ie.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_pad_to_pad_ie.hpp" - -#include -#include -#include -#include -#include - -ngraph::pass::ConvertPadToLegacyMatcher::ConvertPadToLegacyMatcher() { - auto m_pad = ngraph::pattern::wrap_type(pattern::has_static_shape()); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto pad = std::dynamic_pointer_cast(m.get_match_root()); - if (!pad) { - return false; - } - - auto pad_ie = std::make_shared(pad); - pad_ie->set_friendly_name(pad->get_friendly_name()); - ngraph::copy_runtime_info(pad, pad_ie); - ngraph::replace_node(pad, pad_ie); - return true; - }; - - auto m = std::make_shared(m_pad, "ConvertPadToLegacy"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.cpp deleted file mode 100644 index b4e9d56fdf6..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.hpp" - -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertPowerToPowerIEMatcher::ConvertPowerToPowerIEMatcher() { - auto input_0 = std::make_shared(element::f32, Shape{1}); - auto input_1 = std::make_shared(element::f32, Shape{1}); - auto power = std::make_shared(input_0, input_1); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto power = std::dynamic_pointer_cast(m.get_match_root()); - if (!power) { - return false; - } - auto node = power->input(1).get_source_output().get_node_shared_ptr(); - if (auto const_node = std::dynamic_pointer_cast(node)) { - float value(0); - if (!ov::op::util::get_single_value(const_node, value)) { - return false; - } - - // check broadcast influence - if (ov::op::util::check_for_broadcast(power->input(0).get_shape(), node->get_shape())) { - return false; - } - - auto power_ie = std::make_shared(power->input(0).get_source_output(), - value, - 1.0f, - 0.0f, - power->output(0).get_element_type()); - power_ie->set_friendly_name(power->get_friendly_name()); - ngraph::copy_runtime_info(power, power_ie); - ngraph::replace_node(power, power_ie); - return true; - } - return false; - }; - - auto m = std::make_shared(power, "ConvertPowerToPowerIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_prelu_to_relu_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_prelu_to_relu_ie.cpp deleted file mode 100644 index c30198d0e12..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_prelu_to_relu_ie.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_prelu_to_relu_ie.hpp" - -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertPReLUToReLUIE::ConvertPReLUToReLUIE() { - auto input_0 = std::make_shared(element::f32, Shape{1}); - auto input_1 = std::make_shared(element::f32, Shape{1}); - auto prelu = std::make_shared(input_0, input_1); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto prelu = std::dynamic_pointer_cast(m.get_match_root()); - if (!prelu) { - return false; - } - auto node = prelu->input(1).get_source_output().get_node_shared_ptr(); - if (auto const_node = std::dynamic_pointer_cast(node)) { - float value(0); - if (!ov::op::util::get_single_value(const_node, value)) { - return false; - } - - auto relu_ie = std::make_shared(prelu->input(0).get_source_output(), - value, - prelu->output(0).get_element_type()); - relu_ie->set_friendly_name(prelu->get_friendly_name()); - ngraph::copy_runtime_info(prelu, relu_ie); - ngraph::replace_node(prelu, relu_ie); - return true; - } - return false; - }; - - auto m = std::make_shared(prelu, "ConvertPReLUToReLUIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.cpp deleted file mode 100644 index f6d0053333b..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_proposal_to_proposal_ie.hpp" - -#include -#include -#include -#include -#include -#include -#include - -namespace { - -bool convert_to_proposal_ie(std::shared_ptr proposal, bool infer_probs = false) { - ngraph::Output last; // 2D tensor of size [1, 3-4] with im_info will be retrieved from this node - ngraph::NodeVector ops_to_replace, new_ops; - ops_to_replace.push_back(proposal); - - if (auto reshape = - std::dynamic_pointer_cast(proposal->input_value(2).get_node_shared_ptr())) { - const ngraph::PartialShape& im_info_shape = reshape->get_input_partial_shape(0); - if (im_info_shape != ngraph::Shape({1, 3}) && im_info_shape != ngraph::Shape({1, 4})) { - return false; - } - last = reshape->input_value(0); - ops_to_replace.push_back(reshape); - } else { - auto const_shape = ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, -1}); - last = std::make_shared(proposal->input_value(2), const_shape, true); - new_ops.push_back(last.get_node_shared_ptr()); - } - - auto ie_attrs = proposal->get_attrs(); - ie_attrs.infer_probs = infer_probs; - auto proposal_ie = - std::make_shared(proposal->input_value(0), proposal->input_value(1), last, ie_attrs); - new_ops.push_back(proposal_ie); - - proposal_ie->set_friendly_name(proposal->get_friendly_name()); - ngraph::copy_runtime_info(ops_to_replace, new_ops); - ngraph::replace_node(proposal, proposal_ie); - - return true; -} - -} // namespace - -ngraph::pass::ConvertProposalToLegacyMatcher::ConvertProposalToLegacyMatcher() { - auto proposal = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto proposal = std::dynamic_pointer_cast(m.get_match_root()); - - if (!proposal) { - return false; - } - convert_to_proposal_ie(proposal); - return true; - }; - auto m = std::make_shared(proposal, "ConvertProposalToProposalIE"); - this->register_matcher(m, callback); -} - -ngraph::pass::ConvertProposal4ToLegacyMatcher::ConvertProposal4ToLegacyMatcher() { - auto proposal = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto proposal = std::dynamic_pointer_cast(m.get_match_root()); - - if (!proposal) { - return false; - } - convert_to_proposal_ie(proposal, true); - return true; - }; - auto m = std::make_shared(proposal, "ConvertProposal4ToProposalIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_selu_to_selu_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_selu_to_selu_ie.cpp deleted file mode 100644 index 8232563315a..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_selu_to_selu_ie.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_selu_to_selu_ie.hpp" - -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertSeluToSeluIEMatcher::ConvertSeluToSeluIEMatcher() { - auto input_0 = std::make_shared(element::f32, Shape{1}); - auto input_1 = std::make_shared(element::f32, Shape{1}); - auto input_2 = std::make_shared(element::f32, Shape{1}); - auto selu = std::make_shared(input_0, input_1, input_2); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto selu = std::dynamic_pointer_cast(m.get_match_root()); - if (!selu) { - return false; - } - auto alpha_node = selu->input(1).get_source_output().get_node_shared_ptr(); - auto gamma_node = selu->input(2).get_source_output().get_node_shared_ptr(); - - auto alpha_const = std::dynamic_pointer_cast(alpha_node); - auto gamma_const = std::dynamic_pointer_cast(gamma_node); - - if (!alpha_const || !gamma_const) { - return false; - } - - float alpha, gamma; - if (!ov::op::util::get_single_value(alpha_const, alpha) || - !ov::op::util::get_single_value(gamma_const, gamma)) { - return false; - } - - auto selu_ie = std::make_shared(selu->input(0).get_source_output(), alpha, gamma); - selu_ie->set_friendly_name(selu->get_friendly_name()); - ngraph::copy_runtime_info(selu, selu_ie); - ngraph::replace_node(selu, selu_ie); - return true; - }; - - auto m = std::make_shared(selu, "ConvertSeluToSeluIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.cpp deleted file mode 100644 index f499f0563d0..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.cpp +++ /dev/null @@ -1,266 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.hpp" - -#include -#include -#include -#include -#include -#include -#include - -namespace { -int64_t get_seq_axis(const std::shared_ptr& sequence_node) { - // Optimization. - // Plug-ins support seq_axis attribute (value 1 or 0) for Seq ops, but according to the spec we don't - // support this attribute and should insert Transpose layer before and after Seq op in TI to Sequences - // transformation. Additional Transpose layers affect the performance, so we try to detect pattern - // Transpose(axis_order={1,0,2}) -> Seq -> Transpose(axis_order={2,1,0,3} - // and replace unnecessary Transpose ops with SeqIE (seq_axis = 0) to transfer value - // of the attribute to plug-ins. - // todo: specify seq_axis attribute for Sequence ops. - int64_t seq_axis = 1; // default - const auto& target_inputs = sequence_node->output(0).get_target_inputs(); - if (target_inputs.size() == 1) { - const auto& transpose_before = - std::dynamic_pointer_cast(sequence_node->input_value(0).get_node_shared_ptr()); - const auto& transpose_after = - std::dynamic_pointer_cast(target_inputs.begin()->get_node()->shared_from_this()); - if (transpose_after != nullptr && transpose_before != nullptr) { - auto order_before = std::dynamic_pointer_cast( - transpose_before->input_value(1).get_node_shared_ptr()); - auto order_after = std::dynamic_pointer_cast( - transpose_after->input_value(1).get_node_shared_ptr()); - if (order_before != nullptr && order_after != nullptr) { - auto order_before_values = order_before->cast_vector(); - auto order_after_values = order_after->cast_vector(); - std::vector order_ref_before = {1, 0, 2}; - std::vector order_ref_after = {2, 1, 0, 3}; - if (order_before_values == order_ref_before && order_after_values == order_ref_after) { - seq_axis = 0; - } - } - } - } - return seq_axis; -} -} // namespace - -ngraph::pass::ConvertLSTMSequenceMatcher::ConvertLSTMSequenceMatcher() { - auto lstm_sequence_ngraph = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto lstm_sequence = std::dynamic_pointer_cast(m.get_match_root()); - if (!lstm_sequence) { - return false; - } - - const auto& W = lstm_sequence->input_value(4); - const auto& R = lstm_sequence->input_value(5); - - // Bidirectional cases are not supported - if (lstm_sequence->get_direction() == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) - return false; - - // Detect pattern: Transpose_before -> Seq -> Transpose_after - auto seq_axis = get_seq_axis(lstm_sequence); - ngraph::Output in_0 = lstm_sequence->input(0).get_source_output(); - if (seq_axis == 0) { - // input(0) to Transpose_before - in_0 = lstm_sequence->get_input_source_output(0).get_node_shared_ptr()->get_input_source_output(0); - } - // for forward/reverse cases we can squeeze num_direction dimension - auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(lstm_sequence->input_value(1), axis_1); - auto in_2 = std::make_shared(lstm_sequence->input_value(2), axis_1); - auto concat = std::make_shared(ngraph::OutputVector{W, R}, 2); - auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(lstm_sequence->input_value(6), axis_2); - auto lstm_sequence_ie = std::make_shared(in_0, // X - in_1, // initial_hidden_state - in_2, // initial_cell_state - lstm_sequence->input_value(3), - in_3, // WR - in_4, // B - lstm_sequence->get_hidden_size(), - lstm_sequence->get_direction(), - lstm_sequence->get_activations(), - lstm_sequence->get_activations_alpha(), - lstm_sequence->get_activations_beta(), - lstm_sequence->get_clip(), - seq_axis); - - auto unsqueeze_axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(lstm_sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(lstm_sequence_ie->output(1), unsqueeze_axis); - auto unsqueeze_3 = std::make_shared(lstm_sequence_ie->output(2), unsqueeze_axis); - - ngraph::copy_runtime_info( - lstm_sequence, - {concat, lstm_sequence_ie, in_1, in_2, in_3, in_4, unsqueeze_1, unsqueeze_2, unsqueeze_3}); - unsqueeze_1->set_friendly_name(lstm_sequence->get_friendly_name() + ".0"); - unsqueeze_2->set_friendly_name(lstm_sequence->get_friendly_name() + ".1"); - unsqueeze_3->set_friendly_name(lstm_sequence->get_friendly_name() + ".2"); - if (seq_axis == 1) { - ngraph::replace_node(lstm_sequence, - {unsqueeze_1->output(0), unsqueeze_2->output(0), unsqueeze_3->output(0)}); - } else { - const auto& lstm_target_inputs = lstm_sequence->output(0).get_target_inputs(); - if (lstm_target_inputs.empty()) - return false; - auto transpose_after = lstm_target_inputs.begin()->get_node()->shared_from_this(); - unsqueeze_1->set_friendly_name(transpose_after->get_friendly_name()); - ngraph::replace_node(transpose_after, unsqueeze_1); - ngraph::replace_node(lstm_sequence, - {lstm_sequence_ie->output(0), unsqueeze_2->output(0), unsqueeze_3->output(0)}); - } - return true; - }; - - auto m = std::make_shared(lstm_sequence_ngraph, "ConvertLSTMSequenceToLSTMSequenceIE"); - this->register_matcher(m, callback); -} - -ngraph::pass::ConvertGRUSequenceMatcher::ConvertGRUSequenceMatcher() { - auto gru_sequence_ngraph = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto gru_sequence = std::dynamic_pointer_cast(m.get_match_root()); - if (!gru_sequence) { - return false; - } - - auto W = gru_sequence->input_value(3); - auto R = gru_sequence->input_value(4); - - // Bidirectional cases are not supported - if (gru_sequence->get_direction() == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) - return false; - - // Detect pattern: Transpose_before -> Seq -> Transpose_after - auto seq_axis = get_seq_axis(gru_sequence); - ngraph::Output in_0 = gru_sequence->input(0).get_source_output(); - if (seq_axis == 0) { - // input(0) to Transpose_before - in_0 = gru_sequence->get_input_source_output(0).get_node_shared_ptr()->get_input_source_output(0); - } - // for forward/reverse cases we can squeeze num_direction dimension - auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(gru_sequence->input_value(1), axis_1); - auto concat = std::make_shared(ngraph::OutputVector{W, R}, 2); - auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(gru_sequence->input_value(5), axis_2); - - auto gru_sequence_ie = std::make_shared(in_0, // X - in_1, // initial_hidden_state - gru_sequence->input_value(2), - in_3, // WR - in_4, // B - gru_sequence->get_hidden_size(), - gru_sequence->get_direction(), - gru_sequence->get_activations(), - gru_sequence->get_activations_alpha(), - gru_sequence->get_activations_beta(), - gru_sequence->get_clip(), - gru_sequence->get_linear_before_reset(), - seq_axis); - - auto unsqueeze_axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(gru_sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(gru_sequence_ie->output(1), unsqueeze_axis); - - ngraph::copy_runtime_info(gru_sequence, {concat, gru_sequence_ie, unsqueeze_1, unsqueeze_2, in_1, in_3, in_4}); - unsqueeze_1->set_friendly_name(gru_sequence->get_friendly_name() + ".0"); - unsqueeze_2->set_friendly_name(gru_sequence->get_friendly_name() + ".1"); - if (seq_axis == 1) { - ngraph::replace_node(gru_sequence, {unsqueeze_1->output(0), unsqueeze_2->output(0)}); - } else { - const auto& gru_target_inputs = gru_sequence->output(0).get_target_inputs(); - if (gru_target_inputs.empty()) - return false; - auto transpose_after = gru_target_inputs.begin()->get_node()->shared_from_this(); - unsqueeze_1->set_friendly_name(transpose_after->get_friendly_name()); - ngraph::replace_node(transpose_after, unsqueeze_1); - ngraph::replace_node(gru_sequence, {gru_sequence_ie->output(0), unsqueeze_2->output(0)}); - } - return true; - }; - - auto m = std::make_shared(gru_sequence_ngraph, "ConvertGRUSequenceToGRUSequenceIE"); - this->register_matcher(m, callback); -} - -ngraph::pass::ConvertRNNSequenceMatcher::ConvertRNNSequenceMatcher() { - auto rnn_sequence_ngraph = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto rnn_sequence = std::dynamic_pointer_cast(m.get_match_root()); - if (!rnn_sequence) { - return false; - } - - // Bidirectional cases are not supported - if (rnn_sequence->get_direction() == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) - return false; - - // Detect pattern: Transpose_before -> Seq -> Transpose_after - auto seq_axis = get_seq_axis(rnn_sequence); - ngraph::Output in_0 = rnn_sequence->input(0).get_source_output(); - if (seq_axis == 0) { - // input(0) to Transpose_before - in_0 = rnn_sequence->get_input_source_output(0).get_node_shared_ptr()->get_input_source_output(0); - } - - auto W = rnn_sequence->input_value(3); - auto R = rnn_sequence->input_value(4); - - // for forward/reverse cases we can squeeze num_direction dimension - auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(rnn_sequence->input_value(1), axis_1); - auto concat = std::make_shared(ngraph::OutputVector{W, R}, 2); - auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(rnn_sequence->input_value(5), axis_2); - auto rnn_sequence_ie = std::make_shared(in_0, // X - in_1, // initial_hidden_state - rnn_sequence->input_value(2), - in_3, // WR - in_4, // B - rnn_sequence->get_hidden_size(), - rnn_sequence->get_direction(), - rnn_sequence->get_activations(), - rnn_sequence->get_activations_alpha(), - rnn_sequence->get_activations_beta(), - rnn_sequence->get_clip(), - seq_axis); - - auto unsqueeze_axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(rnn_sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(rnn_sequence_ie->output(1), unsqueeze_axis); - - ngraph::copy_runtime_info(rnn_sequence, {concat, rnn_sequence_ie, in_1, in_3, in_4, unsqueeze_1, unsqueeze_2}); - unsqueeze_1->set_friendly_name(rnn_sequence->get_friendly_name() + ".0"); - unsqueeze_2->set_friendly_name(rnn_sequence->get_friendly_name() + ".1"); - - if (seq_axis == 1) { - ngraph::replace_node(rnn_sequence, {unsqueeze_1->output(0), unsqueeze_2->output(0)}); - } else { - const auto& rnn_target_inputs = rnn_sequence->output(0).get_target_inputs(); - if (rnn_target_inputs.empty()) - return false; - auto transpose_after = rnn_target_inputs.begin()->get_node()->shared_from_this(); - unsqueeze_1->set_friendly_name(transpose_after->get_friendly_name()); - ngraph::replace_node(transpose_after, unsqueeze_1); - ngraph::replace_node(rnn_sequence, {rnn_sequence_ie->output(0), unsqueeze_2->output(0)}); - } - return true; - }; - - auto m = std::make_shared(rnn_sequence_ngraph, "ConvertRNNSequenceToRNNSequenceIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.cpp deleted file mode 100644 index 480b6ab9539..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.hpp" - -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertSqrtToPowerIEMatcher::ConvertSqrtToPowerIEMatcher() { - auto input_0 = std::make_shared(element::f32, Shape{1}); - auto sqrt = std::make_shared(input_0); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto sqrt = std::dynamic_pointer_cast(m.get_match_root()); - if (!sqrt) { - return false; - } - auto power_ie = std::make_shared(sqrt->input(0).get_source_output(), - 0.5f, - 1.0f, - 0.0f, - sqrt->output(0).get_element_type()); - power_ie->set_friendly_name(sqrt->get_friendly_name()); - ngraph::copy_runtime_info(sqrt, power_ie); - ngraph::replace_node(sqrt, power_ie); - return true; - }; - - auto m = std::make_shared(sqrt, "ConvertPowerToPowerIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_strided_slice_to_crop.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_strided_slice_to_crop.cpp deleted file mode 100644 index c0f6215427f..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_strided_slice_to_crop.cpp +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_strided_slice_to_crop.hpp" - -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertStridedSliceToCropMatcher::ConvertStridedSliceToCropMatcher() { - auto data = std::make_shared(element::f32, Shape{1, 1, 1, 1}); - auto m_begin = std::make_shared(element::i64, Shape{2}); - auto m_end = std::make_shared(element::i64, Shape{2}); - auto m_stride = std::make_shared(element::i64, Shape{2}); - std::vector begin_mask = {0, 0, 0, 0}; - std::vector end_mask = {0, 0, 0, 0}; - auto m_slice = std::make_shared(data, m_begin, m_end, m_stride, begin_mask, end_mask); - - ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { - auto slice = std::dynamic_pointer_cast(m.get_match_root()); - if (!slice || transformation_callback(slice)) { - return false; - } - - auto data_output = slice->input_value(0); - auto begin_node = - std::dynamic_pointer_cast(slice->input_value(1).get_node_shared_ptr()); - auto end_node = - std::dynamic_pointer_cast(slice->input_value(2).get_node_shared_ptr()); - auto stride_node = - std::dynamic_pointer_cast(slice->input_value(3).get_node_shared_ptr()); - - auto partial_input_shape = slice->get_input_partial_shape(0); - - if (!begin_node || !end_node || !stride_node || partial_input_shape.is_dynamic()) { - return false; - } - - auto input_shape = slice->get_input_shape(0); - auto output_shape = slice->get_output_shape(0); - - auto begin = begin_node->cast_vector(); - auto end = end_node->cast_vector(); - auto strides = stride_node->cast_vector(); - - bool ones_stride = true; - for (auto& s : strides) { - if (s != 1) - ones_stride = false; - } - - if (!ones_stride) - return false; - - auto convert_to_set = [](const std::vector mask) { - AxisSet axis_set{}; - for (size_t i = 0; i < static_cast(mask.size()); ++i) { - if (mask[i] == 1) { - axis_set.emplace(i); - } - } - return axis_set; - }; - - auto shrink_axis_mask = convert_to_set(slice->get_shrink_axis_mask()); - auto new_axis_mask = convert_to_set(slice->get_new_axis_mask()); - auto ellipsis_mask = convert_to_set(slice->get_ellipsis_mask()); - auto begin_mask = convert_to_set(slice->get_begin_mask()); - auto end_mask = convert_to_set(slice->get_end_mask()); - - std::vector reshape_pattern, axes, offset, dim; - - size_t input_shape_idx = 0; - uint64_t uniq_id = 0; - for (size_t axis = 0; axis < begin.size(); ++axis) { - // add dimensions hidden under the ellipsis mask if ellipsis mask is set - if (ellipsis_mask.count(axis)) { - // only one bit in ellipsis mask is allowed - int num_new_axis_after_ellipses = 0; - int num_input_axis_before_ellipses = 0; - for (size_t i = 0; i < axis; ++i) { - if (!new_axis_mask.count(i)) - num_input_axis_before_ellipses++; - } - for (size_t i = axis + 1; i < begin.size(); ++i) { - if (new_axis_mask.count(i)) - num_new_axis_after_ellipses++; - } - - // -1 because it's a position of ellipses - size_t num_input_axis_after_ellipses = (begin.size() - axis - num_new_axis_after_ellipses - 1); - size_t num_of_hidden_dims = - input_shape.size() - num_input_axis_after_ellipses - num_input_axis_before_ellipses; - for (size_t i = 0; i < num_of_hidden_dims; ++i) { - axes.emplace_back(uniq_id); - uniq_id++; - reshape_pattern.emplace_back(input_shape[input_shape_idx]); - offset.emplace_back(0); - - dim.emplace_back(input_shape[input_shape_idx]); - input_shape_idx++; - } - } else { - // add new single dimension if new_axis_mask is set - if (new_axis_mask.count(axis)) { - reshape_pattern.emplace_back(1); - dim.emplace_back(1); - offset.emplace_back(0); - } else if (shrink_axis_mask.count(axis)) { - // skip this dimension if shrink_axis_mask is set (input_shape_idx++) - dim.emplace_back(1); - offset.emplace_back(begin_mask.count(axis) ? 0 : begin[axis]); - reshape_pattern.emplace_back(1); - input_shape_idx++; - } else { - // calculate dimension using begin, end, begin_mask, end_mask, stride - reshape_pattern.emplace_back(input_shape[input_shape_idx]); - - int64_t lb = begin[axis]; - int64_t ub = end[axis]; - - // convert negative indexes to positive - if (lb < 0) - lb = std::max(static_cast(input_shape[input_shape_idx]) + lb, static_cast(0)); - if (ub < 0) - ub = std::max(static_cast(input_shape[input_shape_idx]) + ub, static_cast(0)); - - // apply restrictions when begin or end values more/less than max/min possible values. - lb = std::min(static_cast(input_shape[input_shape_idx]), lb); - ub = std::min(static_cast(input_shape[input_shape_idx]), ub); - - // set default value for stride or use given value - int64_t stride = 1; - if (strides.size() > axis) - stride = strides[axis]; - - int64_t dimension = 0; - if (stride < 0) { - // apply masks - if (begin_mask.count(axis)) - lb = static_cast(input_shape[input_shape_idx]) - 1; - if (end_mask.count(axis)) - ub = -1; - - lb = std::min(lb, static_cast(input_shape[input_shape_idx]) - 1); - offset.emplace_back(lb); - lb -= 1; // we always get 1st element, so we need decrease range - if (ub <= lb) - dimension = (ub - lb) / stride + 1; - } else { - // apply masks - if (begin_mask.count(axis)) - lb = 0; - offset.emplace_back(lb); - - if (end_mask.count(axis)) { - ub = static_cast(input_shape[input_shape_idx]); - } - - lb += 1; // we always get 1st element, so we need decrease range - if (ub >= lb) { - dimension = (ub - lb) / stride + 1; - } - } - - dim.emplace_back(dimension); - input_shape_idx++; - } - axes.emplace_back(uniq_id); - uniq_id++; - } - } - for (; input_shape_idx < input_shape.size(); ++input_shape_idx) { - reshape_pattern.emplace_back(input_shape[input_shape_idx]); - offset.emplace_back(0); - dim.emplace_back(input_shape[input_shape_idx]); - axes.emplace_back(uniq_id); - uniq_id++; - } - - // CLDNN: if (cropLayer->axis[i] < 0 || cropLayer->axis[i] > 3) -> invalid crop axis - if (axes.size() > 4) { - return false; - } - - NodeVector new_ops; - - // Reshape in case of new axis - if (!new_axis_mask.empty()) { - auto new_shape = std::make_shared(element::i64, - ngraph::Shape{reshape_pattern.size()}, - reshape_pattern); - auto data_node = std::make_shared(data_output, new_shape, true); - data_node->set_friendly_name(slice->get_friendly_name() + "/Reshape_before"); - new_ops.push_back(data_node); - data_output = data_node->output(0); - } - - auto data_node_shape = data_output.get_shape(); - if (data_node_shape.size() < 2 || data_node_shape.size() > 5) { - return false; - } - - // Crop - std::shared_ptr data_node = std::make_shared(data_output, axes, dim, offset); - data_node->set_friendly_name(slice->get_friendly_name()); - new_ops.push_back(data_node); - - auto crop_data_node = data_node; - - // Reshape in case of deleting of axis - if (!shrink_axis_mask.empty()) { - auto new_shape = std::make_shared(element::i64, - ngraph::Shape{output_shape.size()}, - output_shape); - data_node = std::make_shared(data_node->output(0), new_shape, true); - crop_data_node->set_friendly_name(slice->get_friendly_name() + "/Crop"); - data_node->set_friendly_name(slice->get_friendly_name()); - new_ops.push_back(data_node); - } - - ngraph::copy_runtime_info(slice, new_ops); - ngraph::replace_node(slice, data_node); - return true; - }; - - auto m = std::make_shared(m_slice, "ConvertStridedSliceToCrop"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_swish_to_swish_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_swish_to_swish_ie.cpp deleted file mode 100644 index 5845dc1a171..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_swish_to_swish_ie.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_swish_to_swish_ie.hpp" - -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertSwishToSwishIEMatcher::ConvertSwishToSwishIEMatcher() { - auto swish = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto swish = std::dynamic_pointer_cast(m.get_match_root()); - if (!swish) { - return false; - } - float beta_value = 1.0; - if (swish->input_values().size() == 2) { - auto beta_node = swish->input_value(1).get_node_shared_ptr(); - auto beta_const = std::dynamic_pointer_cast(beta_node); - - if (!beta_const) { - return false; - } - if (!ov::op::util::get_single_value(beta_const, beta_value)) { - return false; - } - } - - auto swish_ie = std::make_shared(swish->input(0).get_source_output(), beta_value); - swish_ie->set_friendly_name(swish->get_friendly_name()); - ngraph::copy_runtime_info(swish, swish_ie); - ngraph::replace_node(swish, swish_ie); - return true; - }; - - auto m = std::make_shared(swish, "ConvertSwishToSwishIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_tile_to_ie_tile.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_tile_to_ie_tile.cpp deleted file mode 100644 index c4012c07a21..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_tile_to_ie_tile.cpp +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_tile_to_ie_tile.hpp" - -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertTileToLegacyMatcher::ConvertTileToLegacyMatcher() { - auto tile = pattern::wrap_type( - {pattern::any_input(pattern::has_static_rank()), pattern::wrap_type()}); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto tile = std::dynamic_pointer_cast(m.get_match_root()); - if (!tile) { - return false; - } - - auto tiles_node = - std::dynamic_pointer_cast(tile->input_value(1).get_node_shared_ptr()); - if (!tiles_node) - return false; - - auto tiles = tiles_node->cast_vector(); - auto input_shape_rank = tile->get_input_partial_shape(0).rank().get_length(); - int64_t cur_dim_id = tiles.size() - 1; - - if (static_cast(tiles.size()) != input_shape_rank) - return false; - - // IE Tile operations supports only one axis to be tiled - // bool already_set = false; - // int64_t axis, tiles; - // for (size_t i = 0; i < input_shape.size(); ++i) { - // if (shape[i] != 1) { - // if (already_set) return false; - // axis = i; - // tiles = shape[i]; - // already_set = true; - // } - // } - // - // if (!already_set) return false; - auto last_node = tile->input_value(0); - auto friendly_name = tile->get_friendly_name(); - - int num_of_tile_dims = 0; - for (auto t : tiles) { - if (t != 1) { - num_of_tile_dims++; - } - } - // Will generate sequence of Tile operations if num_of_tile_dims != 1 - // because IE Tile operations supports only one axis to be tiled. - // To keep op name unique will use special IE specific delimiter ':' - // Original frameworks doesn't use such delimiter in names, so it will - // guarantee that newly generated name like "original_name:_1" doesn't - // match with already existed names. - if (num_of_tile_dims > 1) { - friendly_name += ":"; - } - - NodeVector new_ops; - - auto tiles_it = tiles.rbegin(); - while (tiles_it != tiles.rend()) { - int64_t tile_dim = *tiles_it; - if (tile_dim != 1) { - auto ie_tile = std::make_shared(last_node, cur_dim_id, tile_dim); - ie_tile->set_friendly_name(friendly_name); - friendly_name += "_" + std::to_string(cur_dim_id); - new_ops.push_back(ie_tile); - - last_node = ie_tile; - } - --cur_dim_id; - ++tiles_it; - } - - // TODO: If last_node points to input layer, its name will be changed to the tile layer name. There will be - // issue with conversion from ngraph::Function to CNNNetwork. - last_node.get_node_shared_ptr()->set_friendly_name(tile->get_friendly_name()); - ngraph::copy_runtime_info(tile, new_ops); - - ngraph::replace_node(tile, {last_node}); - return true; - }; - - auto m = std::make_shared(tile, "ConvertTileToIETiles"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_topk_to_topk_ie.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_topk_to_topk_ie.cpp deleted file mode 100644 index 0d7ee2d4929..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/convert_topk_to_topk_ie.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/convert_topk_to_topk_ie.hpp" - -#include -#include -#include -#include -#include -#include -#include - -ngraph::pass::ConvertTopKToTopKIEMatcher::ConvertTopKToTopKIEMatcher() { - auto topk = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto topk = std::dynamic_pointer_cast(m.get_match_root()); - if (!topk || topk->input(1).get_partial_shape().rank().is_dynamic()) { - return false; - } - if (topk->input(1).get_partial_shape().rank().get_length() == 1) { - return false; - } - - // WA: if we replace TopK second input with Unsqueeze operation we will get dynamic shape until first CF pass - // but due to not all legacy operations support dynamic input shapes and dynamic shape can break pipeline we - // need to unsqueeze constant manually. - Output unsqueezed_k; - NodeVector new_ops; - if (auto k_const = std::dynamic_pointer_cast(topk->input_value(1).get_node_shared_ptr())) { - auto k_value = k_const->cast_vector(); - unsqueezed_k = opset1::Constant::create(element::i64, Shape{1}, k_value); - } else { - unsqueezed_k = std::make_shared(topk->input_value(1), - opset1::Constant::create(element::i64, Shape{1}, {0})); - new_ops.push_back(unsqueezed_k.get_node_shared_ptr()); - } - - auto topk_ie = std::make_shared(topk->input_value(0), - unsqueezed_k, - topk->get_axis(), - topk->get_mode(), - topk->get_sort_type(), - topk->get_index_element_type()); - new_ops.push_back(topk_ie); - - Output element_output; - Output index_output; - // insert Convert if index element type not equal to i32 and output #1 of TopK has consumers - if (topk->get_index_element_type() == element::i32 || topk->get_output_target_inputs(1).size() == 0) { - element_output = topk_ie->output(0); - index_output = topk_ie->output(1); - topk_ie->set_friendly_name(topk->get_friendly_name()); - } else if (topk->get_output_target_inputs(0).size() == 0) { - index_output = std::make_shared(topk_ie->output(1), topk->get_index_element_type()); - new_ops.push_back(index_output.get_node_shared_ptr()); - - // workaround for naming output #1 of TopK - index_output.get_node_shared_ptr()->set_friendly_name(topk->get_friendly_name() + ".1"); - } else { - // create fake convert for 0 output, it is a workaround in purpose of correct output names preserving - element_output = std::make_shared(topk_ie->output(0), topk->get_output_element_type(0)); - index_output = std::make_shared(topk_ie->output(1), topk->get_index_element_type()); - new_ops.push_back(element_output.get_node_shared_ptr()); - new_ops.push_back(index_output.get_node_shared_ptr()); - - // workaround for naming two outputs of TopK - element_output.get_node_shared_ptr()->set_friendly_name(topk->get_friendly_name() + ".0"); - index_output.get_node_shared_ptr()->set_friendly_name(topk->get_friendly_name() + ".1"); - } - - ngraph::copy_runtime_info(topk, new_ops); - topk->output(0).replace(element_output); - topk->output(1).replace(index_output); - return true; - }; - - auto m = std::make_shared(topk, "ConvertTopKToTopKIE"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp deleted file mode 100644 index 054917a5747..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/fc_bias_fusion.hpp" - -#include -#include -#include -#include -#include -#include - -ngraph::pass::FullyConnectedBiasFusion::FullyConnectedBiasFusion() { - auto m_fc = ngraph::pattern::wrap_type([](Output output) { - return pattern::consumers_count(1)(output) && pattern::has_static_shape()(output); - }); - auto m_bias = pattern::any_input(); - auto m_add = ngraph::pattern::wrap_type({m_fc, m_bias}); - - ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - - auto add = pattern_to_output.at(m_add).get_node_shared_ptr(); - auto bias = pattern_to_output.at(m_bias).get_node_shared_ptr(); - auto fc = std::dynamic_pointer_cast(pattern_to_output.at(m_fc).get_node_shared_ptr()); - if (!fc) { - return false; - } - - if (auto bcast = std::dynamic_pointer_cast(bias)) { - bias = bcast->input_value(0).get_node_shared_ptr(); - } - - if (!std::dynamic_pointer_cast(bias)) { - return false; - } - - Shape bias_shape(bias->get_shape()); - Shape output_shape(fc->get_shape()); - size_t bias_size = std::accumulate(bias_shape.begin(), bias_shape.end(), size_t{1}, std::multiplies()); - if (bias_shape.empty() || (bias_shape.back() != output_shape.back() && bias_shape.back() != 1) || - bias_shape.back() != bias_size) { - return false; - } - - NodeVector new_ops; - - auto new_bias = std::make_shared(fc->input(2).get_source_output(), bias); - new_ops.push_back(new_bias); - std::shared_ptr final_bias = new_bias; - if (new_bias->get_shape().size() >= 2) { - final_bias = std::make_shared(final_bias, - opset1::Constant::create(element::i64, Shape{1}, {-1}), - true); - new_ops.push_back(final_bias); - } - - auto new_fc = std::make_shared(fc->input(0).get_source_output(), - fc->input(1).get_source_output(), - final_bias, - fc->get_shape(), - fc->get_output_type()); - new_ops.push_back(new_fc); - - new_fc->set_friendly_name(add->get_friendly_name()); - ngraph::copy_runtime_info({fc, add}, new_ops); - ngraph::replace_node(add, new_fc); - return true; - }; - - auto m = std::make_shared(m_add, "FullyConnectedBiasFusion"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/reshape_1d_ops.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/reshape_1d_ops.cpp deleted file mode 100644 index 1c13d096e69..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/reshape_1d_ops.cpp +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/reshape_1d_ops.hpp" - -#include -#include -#include -#include -#include - -#include "legacy/ngraph_ops/convolution_ie.hpp" -#include "transformations/utils/utils.hpp" - -using namespace ngraph; - -namespace { - -template -std::shared_ptr convert(const Output& data, std::shared_ptr node, NodeVector& new_ops); - -template <> -std::shared_ptr convert(const Output& data, std::shared_ptr node, NodeVector& new_ops) { - // Update Convolution attributes with additional dimension - auto new_strides = node->get_strides(); - auto new_dilations = node->get_dilations(); - auto new_pads_begin = node->get_pads_begin(); - auto new_pad_end = node->get_pads_end(); - - new_strides.insert(new_strides.begin(), 1); - new_dilations.insert(new_dilations.begin(), 1); - new_pads_begin.insert(new_pads_begin.begin(), 0); - new_pad_end.insert(new_pad_end.begin(), 0); - - Shape new_weights_shape(node->input_value(1).get_shape()); - new_weights_shape.insert(new_weights_shape.begin() + 2, 1); - auto weights = ov::op::util::reshapeTo(node->input_value(1), new_weights_shape); - new_ops.push_back(weights); - - if (node->inputs().size() == 2) { - return std::make_shared(data, - weights, - new_strides, - new_dilations, - new_pads_begin, - new_pad_end, - node->get_output_element_type(0), - node->get_group(), - node->get_auto_pad()); - } else { - return std::make_shared(data, - weights, - node->input_value(2), - new_strides, - new_dilations, - new_pads_begin, - new_pad_end, - node->get_output_element_type(0), - node->get_group(), - node->get_auto_pad()); - } -} - -template <> -std::shared_ptr convert(const Output& data, std::shared_ptr node, NodeVector& new_ops) { - // Update Pooling attributes with additional dimension - auto new_strides = node->get_strides(); - auto new_pads_begin = node->get_pads_begin(); - auto new_pad_end = node->get_pads_end(); - auto new_kernel = node->get_kernel(); - - new_strides.insert(new_strides.begin(), 1); - new_pads_begin.insert(new_pads_begin.begin(), 0); - new_pad_end.insert(new_pad_end.begin(), 0); - new_kernel.insert(new_kernel.begin(), 1); - - return std::make_shared(data, - new_strides, - new_pads_begin, - new_pad_end, - new_kernel, - node->get_rounding_type(), - node->get_auto_pad()); -} - -template <> -std::shared_ptr convert(const Output& data, std::shared_ptr node, NodeVector& new_ops) { - // Update Pooling attributes with additional dimension - auto new_strides = node->get_strides(); - auto new_pads_begin = node->get_pads_begin(); - auto new_pad_end = node->get_pads_end(); - auto new_kernel = node->get_kernel(); - - new_strides.insert(new_strides.begin(), 1); - new_pads_begin.insert(new_pads_begin.begin(), 0); - new_pad_end.insert(new_pad_end.begin(), 0); - new_kernel.insert(new_kernel.begin(), 1); - - return std::make_shared(data, - new_strides, - new_pads_begin, - new_pad_end, - new_kernel, - node->get_exclude_pad(), - node->get_rounding_type(), - node->get_auto_pad()); -} - -matcher_pass_callback get_callback() { - return [](pattern::Matcher& m) { - auto node = m.get_match_root(); - if (node->input(0).get_partial_shape().rank().get_length() != 3) { - return false; - } - - // Insert H dimension equal to 1 - auto input_shape = node->input(0).get_shape(); - auto output_shape = node->output(0).get_shape(); - - input_shape.insert(input_shape.begin() + 2, 1); - - NodeVector new_ops; - - // Reshape(input_shape)->Op->Reshape(output_shape) - Output last = ov::op::util::reshapeTo(node->input_value(0), input_shape); - last.get_node_shared_ptr()->set_friendly_name(node->get_friendly_name() + "/reshape_begin"); - new_ops.push_back(last.get_node_shared_ptr()); - - if (auto conv = std::dynamic_pointer_cast(node)) { - last = convert(last, conv, new_ops); - } else if (auto max_pool = std::dynamic_pointer_cast(node)) { - last = convert(last, max_pool, new_ops); - } else if (auto avg_pool = std::dynamic_pointer_cast(node)) { - last = convert(last, avg_pool, new_ops); - } else { - OPENVINO_THROW("Reshape1DOps: op type is not supported"); - } - - last.get_node_shared_ptr()->set_friendly_name(node->get_friendly_name() + "/new"); - new_ops.push_back(last.get_node_shared_ptr()); - - last = ov::op::util::reshapeTo(last, output_shape); - last.get_node_shared_ptr()->set_friendly_name(node->get_friendly_name()); - new_ops.push_back(last.get_node_shared_ptr()); - - ngraph::copy_runtime_info(node, new_ops); - node->output(0).replace(last); - return true; - }; -} - -} // namespace - -ngraph::pass::Reshape1DConvolution::Reshape1DConvolution() { - auto conv = ngraph::pattern::wrap_type(pattern::has_static_shape()); - auto m = std::make_shared(conv, "Reshape1DConvolution"); - this->register_matcher(m, get_callback()); -} - -ngraph::pass::Reshape1DAvgPool::Reshape1DAvgPool() { - auto pool = ngraph::pattern::wrap_type(pattern::has_static_shape()); - auto m = std::make_shared(pool, "Reshape1DAvgPool"); - this->register_matcher(m, get_callback()); -} - -ngraph::pass::Reshape1DMaxPool::Reshape1DMaxPool() { - auto pool = ngraph::pattern::wrap_type(pattern::has_static_shape()); - auto m = std::make_shared(pool, "Reshape1DMaxPool"); - this->register_matcher(m, get_callback()); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/reshape_fc_fusion.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/reshape_fc_fusion.cpp deleted file mode 100644 index 51f78b916d7..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/reshape_fc_fusion.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp" - -#include -#include -#include -#include -#include -#include - -ngraph::pass::ReshapeFullyConnectedFusion::ReshapeFullyConnectedFusion() { - auto m_reshape = pattern::wrap_type(pattern::has_static_shape()); - auto m_fc = pattern::wrap_type({m_reshape, pattern::any_input(), pattern::any_input()}); - - ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { - auto& pattern_to_output = m.get_pattern_value_map(); - auto fc = pattern_to_output[m_fc].get_node_shared_ptr(); - auto reshape = pattern_to_output[m_reshape].get_node_shared_ptr(); - - // Check that Reshape reshapes 4D tensor to 2D or input shape = output shape - auto shape_in = reshape->input_value(0).get_shape(); - auto shape_out = reshape->get_shape(); - if (!((shape_in.size() == 4 && reshape->get_shape().size() == 2) || - (shape_in == shape_out && !shape_in.empty()))) { - return false; - } - - // Check that Weights[O, C*H*W] consistent with Input[N, C, H, W] - auto shape_w = fc->input_value(1).get_shape(); - if (shape_in[0] != shape_out[0] || - std::accumulate(shape_in.begin() + 1, shape_in.end(), size_t{1}, std::multiplies()) != shape_w[1]) { - return false; - } - - auto new_fc = std::make_shared(reshape->input_value(0), - fc->input_value(1), - fc->input_value(2), - fc->get_shape(), - fc->output(0).get_element_type()); - - new_fc->set_friendly_name(fc->get_friendly_name()); - ngraph::copy_runtime_info({reshape, fc}, new_fc); - ngraph::replace_node(fc, new_fc); - return true; - }; - - auto m = std::make_shared(m_fc, "ReshapeFullyConnectedFusion"); - register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/reshape_fully_connected.cpp b/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/reshape_fully_connected.cpp deleted file mode 100644 index dd15512a0ae..00000000000 --- a/src/plugins/intel_gna/legacy/src/transformations/convert_opset1_to_legacy/reshape_fully_connected.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "legacy/transformations/convert_opset1_to_legacy/reshape_fully_connected.hpp" - -#include -#include -#include -#include -#include - -#include "legacy/ngraph_ops/fully_connected.hpp" -#include "transformations/utils/utils.hpp" - -ngraph::pass::ReshapeFullyConnected::ReshapeFullyConnected() { - auto fc = pattern::wrap_type( - {pattern::any_input(pattern::has_static_shape()), pattern::any_input(), pattern::any_input()}, - pattern::has_static_shape()); - - ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { - auto fc = std::dynamic_pointer_cast(m.get_match_root()); - if (!fc || transformation_callback(fc)) { - return false; - } - - auto input_shape = fc->input_value(0).get_shape(); - auto output_shape = fc->get_shape(); - - if (input_shape.size() == 2) { - return false; - } - - NodeVector new_ops; - - std::vector reshape_shape{-1, static_cast(input_shape.back())}; - auto reshape = - std::make_shared(fc->input_value(0), - opset1::Constant::create(element::i64, Shape{2}, reshape_shape), - true); - new_ops.push_back(reshape); - - reshape->set_friendly_name(fc->get_friendly_name() + "/Reshape"); - - // Calculate output shape for new FullyConnected layer - // [I, K] * [O, K] = [I, O] - auto I = reshape->get_shape()[0]; - auto O = fc->input_value(1).get_shape()[0]; - Shape output_shape_new{I, O}; - - auto fc_new = std::make_shared(reshape, - fc->input_value(1), - fc->input_value(2), - output_shape_new, - fc->get_output_type()); - new_ops.push_back(fc_new); - - if (output_shape != output_shape_new) { - auto reshape_output = ov::op::util::reshapeTo(fc_new, output_shape); - new_ops.push_back(reshape_output); - reshape_output->set_friendly_name(fc->get_friendly_name()); - fc_new->set_friendly_name(fc->get_friendly_name() + "/FC"); - ngraph::copy_runtime_info(fc, new_ops); - ngraph::replace_node(fc, reshape_output); - } else { - fc_new->set_friendly_name(fc->get_friendly_name()); - ngraph::copy_runtime_info(fc, new_ops); - ngraph::replace_node(fc, fc_new); - } - - return true; - }; - - auto m = std::make_shared(fc, "ReshapeFullyConnected"); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/legacy/tests/CMakeLists.txt b/src/plugins/intel_gna/legacy/tests/CMakeLists.txt deleted file mode 100644 index 55771645c79..00000000000 --- a/src/plugins/intel_gna/legacy/tests/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -if(CMAKE_COMPILER_IS_GNUCXX) - ov_add_compiler_flags(-Wno-missing-declarations) - ov_add_compiler_flags(-Wno-bool-compare) -endif() - -set(TARGET_NAME ov_legacy_transformations_tests) - -ov_add_test_target( - NAME ${TARGET_NAME} - ROOT ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDENCIES - LINK_LIBRARIES - gmock - func_test_utils - sharedTestClasses - ov_lpt_models - inference_engine_legacy - ADD_CLANG_FORMAT - INCLUDES - $/src - LABELS - OV UNIT TRANSFORMATIONS -) - -if(WIN32) - string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") -endif() diff --git a/src/plugins/intel_gna/legacy/tests/conv_fusion_test.cpp b/src/plugins/intel_gna/legacy/tests/conv_fusion_test.cpp deleted file mode 100644 index 5a2e9e46de4..00000000000 --- a/src/plugins/intel_gna/legacy/tests/conv_fusion_test.cpp +++ /dev/null @@ -1,546 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "common_test_utils/test_common.hpp" - -using namespace ov; -using namespace testing; - -using InputShape = ov::PartialShape; -using WeightsShape = ov::Shape; -using EltwiseType = ov::NodeTypeInfo; -using EltwiseShape = ov::Shape; -using IsNegative = bool; - -class ConvFusionTests - : public ov::test::TestsCommon, - public testing::WithParamInterface> { -public: - std::shared_ptr f, f_ref; - - void SetUp() override { - const auto& input_shape = std::get<0>(GetParam()); - const auto& weights_shape = std::get<1>(GetParam()); - const auto& eltwise_type = std::get<2>(GetParam()); - const auto& eltwise_shape = std::get<3>(GetParam()); - const auto& is_negative = std::get<4>(GetParam()); - - f = get_initial_model(input_shape, weights_shape, eltwise_type, eltwise_shape); - - if (is_negative) { - f_ref = get_initial_model(input_shape, weights_shape, eltwise_type, eltwise_shape); - } else { - f_ref = get_reference_function(input_shape, weights_shape, eltwise_type, eltwise_shape); - ov::pass::Manager manager; - manager.register_pass(); - manager.run_passes(f_ref); - } - } - -private: - std::shared_ptr get_initial_model(const InputShape& input_shape, - const WeightsShape& weights_shape, - const EltwiseType& eltwise_type, - const EltwiseShape& eltwise_shape) { - auto spatial_dims = input_shape.rank().get_length() - 2; - auto input = std::make_shared(ov::element::f32, input_shape); - auto weights = ov::opset5::Constant::create(ov::element::f32, weights_shape, {1}); - auto conv = std::make_shared(input, - weights, - ov::Strides(spatial_dims, 1), - ov::Strides(spatial_dims, 1), - ov::CoordinateDiff(spatial_dims, 0), - ov::CoordinateDiff(spatial_dims, 0), - ov::element::f32); - - auto const_node = ov::opset5::Constant::create(ov::element::f32, eltwise_shape, {1.1}); - ov::Output eltwise; - if (eltwise_type == ov::opset5::Add::get_type_info_static()) { - eltwise = std::make_shared(conv, const_node); - } else if (eltwise_type == ov::opset5::Multiply::get_type_info_static()) { - eltwise = std::make_shared(conv, const_node); - } else { - OPENVINO_THROW("Unsupported element type"); - } - - return std::make_shared(ov::NodeVector{eltwise.get_node_shared_ptr()}, ov::ParameterVector{input}); - } - - std::shared_ptr get_reference_function(const InputShape& input_shape, - const WeightsShape& weights_shape, - const EltwiseType& eltwise_type, - const EltwiseShape& eltwise_shape) { - auto spatial_dims = input_shape.rank().get_length() - 2; - auto input = std::make_shared(ov::element::f32, input_shape); - ov::Output weights = ov::opset5::Constant::create(ov::element::f32, weights_shape, {1}); - ov::Output conv = std::make_shared(input, - weights, - ov::Strides(spatial_dims, 1), - ov::Strides(spatial_dims, 1), - ov::CoordinateDiff(spatial_dims, 0), - ov::CoordinateDiff(spatial_dims, 0), - ov::element::f32); - - ov::Output const_node; - const_node = ov::opset5::Constant::create(ov::element::f32, eltwise_shape, {1.1}); - if (eltwise_type == ov::opset5::Add::get_type_info_static()) { - if (eltwise_shape.size() != 1) { - const_node = ov::op::util::reshapeTo(const_node, ov::Shape{ov::shape_size(eltwise_shape)}); - } - conv = conv.get_node_shared_ptr()->copy_with_new_inputs({input, weights, const_node}); - } else if (eltwise_type == ov::opset5::Multiply::get_type_info_static()) { - if (eltwise_shape.size() > 1) { - const_node = ov::op::util::reshapeTo(const_node, ov::Shape{ov::shape_size(eltwise_shape)}); - } - ov::Shape const_shape(weights_shape.size(), 1); - const_shape[0] = weights_shape[0]; - weights = std::make_shared(weights, ov::op::util::reshapeTo(const_node, const_shape)); - conv = conv.get_node_shared_ptr()->copy_with_new_inputs({input, weights}); - } else { - OPENVINO_THROW("Unsupported element type"); - } - - return std::make_shared(ov::NodeVector{conv.get_node_shared_ptr()}, ov::ParameterVector{input}); - } -}; - -TEST_P(ConvFusionTests, CompareFunctions) { - auto unh = std::make_shared(); - ov::pass::Manager manager; - manager.register_pass(unh); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(unh); - manager.run_passes(f); - ASSERT_NO_THROW(check_rt_info(f)); - - auto fc = - FunctionsComparator::no_default().enable(FunctionsComparator::NODES).enable(FunctionsComparator::PRECISIONS); - auto res = fc.compare(f, f_ref); - ASSERT_TRUE(res.valid) << res.message; -} - -using add = ov::opset5::Add; -using mul = ov::opset5::Multiply; - -INSTANTIATE_TEST_SUITE_P(ConvAddFusion, - ConvFusionTests, - testing::Values(std::make_tuple(InputShape{DYN, DYN, DYN, DYN, DYN}, - WeightsShape{8, 3, 1, 2, 3}, - add::get_type_info_static(), - EltwiseShape{8, 1, 1, 1}, - false), - std::make_tuple(InputShape{DYN, 3, 64, 64, 64}, - WeightsShape{8, 3, 1, 2, 3}, - add::get_type_info_static(), - EltwiseShape{8, 1, 1, 1}, - false), - std::make_tuple(InputShape{2, DYN, 64, 64, 64}, - WeightsShape{9, 3, 2, 3, 1}, - add::get_type_info_static(), - EltwiseShape{9, 1, 1, 1}, - false), - std::make_tuple(InputShape{3, 3, DYN, 64, 64}, - WeightsShape{6, 3, 3, 4, 2}, - add::get_type_info_static(), - EltwiseShape{6, 1, 1, 1}, - false), - std::make_tuple(InputShape{3, 3, 64, DYN, 64}, - WeightsShape{5, 3, 3, 4, 3}, - add::get_type_info_static(), - EltwiseShape{5, 1, 1, 1}, - false), - std::make_tuple(InputShape{3, 3, 64, 64, DYN}, - WeightsShape{5, 3, 3, 4, 3}, - add::get_type_info_static(), - EltwiseShape{5, 1, 1, 1}, - false), - std::make_tuple(InputShape{1, 3, 64, 64}, - WeightsShape{6, 3, 1, 1}, - add::get_type_info_static(), - EltwiseShape{6, 1, 1}, - false), - std::make_tuple(InputShape{DYN, DYN, DYN, DYN}, - WeightsShape{7, 3, 1, 1}, - add::get_type_info_static(), - EltwiseShape{7, 1, 1}, - false), - std::make_tuple(InputShape{DYN, 3, 64, 64}, - WeightsShape{8, 3, 1, 2}, - add::get_type_info_static(), - EltwiseShape{8, 1, 1}, - false), - std::make_tuple(InputShape{2, DYN, 64, 64}, - WeightsShape{9, 3, 2, 3}, - add::get_type_info_static(), - EltwiseShape{9, 1, 1}, - false), - std::make_tuple(InputShape{3, 3, DYN, 64}, - WeightsShape{6, 3, 3, 4}, - add::get_type_info_static(), - EltwiseShape{6, 1, 1}, - false), - std::make_tuple(InputShape{3, 3, 64, DYN}, - WeightsShape{5, 3, 3, 4}, - add::get_type_info_static(), - EltwiseShape{5, 1, 1}, - false), - std::make_tuple(InputShape{DYN, DYN, DYN}, - WeightsShape{5, 3, 1}, - add::get_type_info_static(), - EltwiseShape{5, 1}, - false), - std::make_tuple(InputShape{DYN, 3, 10}, - WeightsShape{3, 3, 1}, - add::get_type_info_static(), - EltwiseShape{3, 1}, - false), - std::make_tuple(InputShape{2, DYN, 9}, - WeightsShape{2, 3, 2}, - add::get_type_info_static(), - EltwiseShape{2, 1}, - false), - std::make_tuple(InputShape{3, 3, DYN}, - WeightsShape{1, 3, 3}, - add::get_type_info_static(), - EltwiseShape{1, 1}, - false))); - -INSTANTIATE_TEST_SUITE_P(ConvAddFusionNegative, - ConvFusionTests, - testing::Values(std::make_tuple(InputShape{DYN, DYN, DYN, DYN, DYN}, - WeightsShape{8, 3, 1, 2, 3}, - add::get_type_info_static(), - EltwiseShape{2, 1}, - true), - std::make_tuple(InputShape{DYN, 3, 64, 64, 64}, - WeightsShape{8, 3, 1, 2, 3}, - add::get_type_info_static(), - EltwiseShape{8, 1, 1, 1, 1}, - true), - std::make_tuple(InputShape{2, DYN, 64, 64, 64}, - WeightsShape{9, 3, 2, 3, 1}, - add::get_type_info_static(), - EltwiseShape{2, 1, 1, 1, 1}, - true))); - -INSTANTIATE_TEST_SUITE_P(ConvMulFusion, - ConvFusionTests, - testing::Values(std::make_tuple(InputShape{DYN, DYN, DYN, DYN, DYN}, - WeightsShape{8, 3, 1, 2, 3}, - mul::get_type_info_static(), - EltwiseShape{8, 1, 1, 1}, - false), - std::make_tuple(InputShape{DYN, 3, 64, 64, 64}, - WeightsShape{8, 3, 1, 2, 3}, - mul::get_type_info_static(), - EltwiseShape{8, 1, 1, 1}, - false), - std::make_tuple(InputShape{2, DYN, 64, 64, 64}, - WeightsShape{9, 3, 2, 3, 1}, - mul::get_type_info_static(), - EltwiseShape{9, 1, 1, 1}, - false), - std::make_tuple(InputShape{3, 3, DYN, 64, 64}, - WeightsShape{6, 3, 3, 4, 2}, - mul::get_type_info_static(), - EltwiseShape{6, 1, 1, 1}, - false), - std::make_tuple(InputShape{3, 3, 64, DYN, 64}, - WeightsShape{5, 3, 3, 4, 3}, - mul::get_type_info_static(), - EltwiseShape{5, 1, 1, 1}, - false), - std::make_tuple(InputShape{3, 3, 64, 64, DYN}, - WeightsShape{5, 3, 3, 4, 3}, - mul::get_type_info_static(), - EltwiseShape{5, 1, 1, 1}, - false), - std::make_tuple(InputShape{1, 3, 64, 64}, - WeightsShape{6, 3, 1, 1}, - mul::get_type_info_static(), - EltwiseShape{6, 1, 1}, - false), - std::make_tuple(InputShape{DYN, DYN, DYN, DYN}, - WeightsShape{7, 3, 1, 1}, - mul::get_type_info_static(), - EltwiseShape{7, 1, 1}, - false), - std::make_tuple(InputShape{DYN, 3, 64, 64}, - WeightsShape{8, 3, 1, 2}, - mul::get_type_info_static(), - EltwiseShape{8, 1, 1}, - false), - std::make_tuple(InputShape{2, DYN, 64, 64}, - WeightsShape{9, 3, 2, 3}, - mul::get_type_info_static(), - EltwiseShape{9, 1, 1}, - false), - std::make_tuple(InputShape{3, 3, DYN, 64}, - WeightsShape{6, 3, 3, 4}, - mul::get_type_info_static(), - EltwiseShape{6, 1, 1}, - false), - std::make_tuple(InputShape{3, 3, 64, DYN}, - WeightsShape{5, 3, 3, 4}, - mul::get_type_info_static(), - EltwiseShape{5, 1, 1}, - false), - std::make_tuple(InputShape{DYN, DYN, DYN}, - WeightsShape{5, 3, 1}, - mul::get_type_info_static(), - EltwiseShape{5, 1}, - false), - std::make_tuple(InputShape{DYN, 3, 10}, - WeightsShape{3, 3, 1}, - mul::get_type_info_static(), - EltwiseShape{3, 1}, - false), - std::make_tuple(InputShape{2, DYN, 9}, - WeightsShape{2, 3, 2}, - mul::get_type_info_static(), - EltwiseShape{2, 1}, - false), - std::make_tuple(InputShape{3, 3, DYN}, - WeightsShape{1, 3, 3}, - mul::get_type_info_static(), - EltwiseShape{1, 1}, - false))); - -INSTANTIATE_TEST_SUITE_P(ConvMulFusionNegative, - ConvFusionTests, - testing::Values(std::make_tuple(InputShape{DYN, DYN, DYN, DYN, DYN}, - WeightsShape{8, 3, 1, 2, 3}, - mul::get_type_info_static(), - EltwiseShape{2, 1}, - true), - std::make_tuple(InputShape{DYN, 3, 64, 64}, - WeightsShape{3, 3, 2, 3}, - mul::get_type_info_static(), - EltwiseShape{8, 1, 1, 1}, - true), - std::make_tuple(InputShape{2, DYN, 64, 64}, - WeightsShape{3, 2, 3, 1}, - mul::get_type_info_static(), - EltwiseShape{9, 1, 1, 1, 1}, - true))); - -TEST_F(TransformationTestsF, WeightsWithReshape) { - { - auto data = std::make_shared(element::f32, Shape{1, 4, 7, 7}); - auto weights = opset5::Constant::create(element::f32, Shape{4, 1, 3, 3}, std::vector(36, 1)); - auto reshape = - std::make_shared(weights, - opset5::Constant::create(element::i64, Shape{5}, Shape{4, 1, 1, 3, 3}), - false); - auto conv = std::make_shared(data, - reshape, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - auto mul = std::make_shared( - conv, - opset5::Constant::create(element::f32, Shape{4, 1, 1}, std::vector(4, 2))); - model = std::make_shared(NodeVector{mul}, ParameterVector{data}); - - manager.register_pass(); - manager.register_pass(); - } - - { - auto data = std::make_shared(element::f32, Shape{1, 4, 7, 7}); - auto weights = opset5::Constant::create(element::f32, Shape{4, 1, 1, 3, 3}, std::vector(36, 2)); - auto conv = std::make_shared(data, - weights, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - model_ref = std::make_shared(NodeVector{conv}, ParameterVector{data}); - } -} - -TEST_F(TransformationTestsF, NegativeWeightsWithReshape) { - { - auto data = std::make_shared(element::f32, Shape{1, 4, 7, 7}); - auto weights = opset5::Constant::create(element::f32, Shape{36}, std::vector(36, 1)); - auto reshape = - std::make_shared(weights, - opset5::Constant::create(element::i64, Shape{5}, Shape{4, 1, 1, 3, 3}), - false); - auto conv = std::make_shared(data, - reshape, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - auto mul = std::make_shared( - conv, - opset5::Constant::create(element::f32, Shape{4, 1, 1}, std::vector(4, 2))); - model = std::make_shared(NodeVector{mul}, ParameterVector{data}); - - manager.register_pass(); - } - - { - auto data = std::make_shared(element::f32, Shape{1, 4, 7, 7}); - auto weights = opset5::Constant::create(element::f32, Shape{36}, std::vector(36, 1)); - auto reshape = - std::make_shared(weights, - opset5::Constant::create(element::i64, Shape{5}, Shape{4, 1, 1, 3, 3}), - false); - auto conv = std::make_shared(data, - reshape, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - auto mul = std::make_shared( - conv, - opset5::Constant::create(element::f32, Shape{4, 1, 1}, std::vector(4, 2))); - model_ref = std::make_shared(NodeVector{mul}, ParameterVector{data}); - } -} - -TEST_F(TransformationTestsF, WeightsWithReshapeScalarMultiplier) { - { - auto data = std::make_shared(element::f32, Shape{1, 4, 7, 7}); - auto weights = opset5::Constant::create(element::f32, Shape{36}, std::vector(36, 1)); - auto reshape = - std::make_shared(weights, - opset5::Constant::create(element::i64, Shape{5}, Shape{4, 1, 1, 3, 3}), - false); - auto conv = std::make_shared(data, - reshape, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - auto mul = std::make_shared(conv, opset5::Constant::create(element::f32, Shape{1}, {2.0f})); - model = std::make_shared(NodeVector{mul}, ParameterVector{data}); - - manager.register_pass(); - manager.register_pass(); - } - - { - auto data = std::make_shared(element::f32, Shape{1, 4, 7, 7}); - auto weights = opset5::Constant::create(element::f32, Shape{4, 1, 1, 3, 3}, std::vector(36, 2)); - auto conv = std::make_shared(data, - weights, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - model_ref = std::make_shared(NodeVector{conv}, ParameterVector{data}); - } -} - -TEST_F(TransformationTestsF, WeightsWithoutReshape) { - { - auto data = std::make_shared(element::f32, Shape{1, 4, 7, 7}); - auto weights = opset5::Constant::create(element::f32, Shape{4, 1, 1, 3, 3}, std::vector(36, 1)); - auto conv = std::make_shared(data, - weights, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - auto mul = std::make_shared( - conv, - opset5::Constant::create(element::f32, Shape{4, 1, 1}, std::vector(4, 2))); - model = std::make_shared(NodeVector{mul}, ParameterVector{data}); - - manager.register_pass(); - manager.register_pass(); - } - - { - auto data = std::make_shared(element::f32, Shape{1, 4, 7, 7}); - auto weights = opset5::Constant::create(element::f32, Shape{4, 1, 1, 3, 3}, std::vector(36, 2)); - auto conv = std::make_shared(data, - weights, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - model_ref = std::make_shared(NodeVector{conv}, ParameterVector{data}); - } -} - -TEST_F(TransformationTestsF, WeightsWithFakeQuantizeAndReshape) { - { - auto data = std::make_shared(element::f32, Shape{1, 4, 7, 7}); - auto weights = opset5::Constant::create(element::f32, Shape{6, 2, 3, 3}, std::vector(108, 1)); - auto fq = std::make_shared(weights, - opset5::Constant::create(element::f32, Shape{1}, {0}), - opset5::Constant::create(element::f32, Shape{1}, {1}), - opset5::Constant::create(element::f32, Shape{1}, {0}), - opset5::Constant::create(element::f32, Shape{1}, {10}), - 2); - auto reshape = - std::make_shared(fq, - opset5::Constant::create(element::i64, Shape{5}, Shape{2, 3, 2, 3, 3}), - false); - auto conv = std::make_shared(data, - reshape, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - auto mul = std::make_shared( - conv, - opset5::Constant::create(element::f32, Shape{6, 1, 1}, std::vector(6, 2))); - model = std::make_shared(NodeVector{mul}, ParameterVector{data}); - - manager.register_pass(); - manager.register_pass(); - } - - { - auto data = std::make_shared(element::f32, Shape{1, 4, 7, 7}); - auto weights = opset5::Constant::create(element::f32, Shape{6, 2, 3, 3}, std::vector(108, 1)); - auto fq = std::make_shared(weights, - opset5::Constant::create(element::f32, Shape{1}, {0}), - opset5::Constant::create(element::f32, Shape{1}, {1}), - opset5::Constant::create(element::f32, Shape{1}, {0}), - opset5::Constant::create(element::f32, Shape{1}, {10}), - 2); - auto mul = std::make_shared( - fq, - opset5::Constant::create(element::f32, Shape{6, 1, 1, 1}, std::vector(6, 2))); - auto reshape = - std::make_shared(mul, - opset5::Constant::create(element::i64, Shape{5}, Shape{2, 3, 2, 3, 3}), - false); - auto conv = std::make_shared(data, - reshape, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - model_ref = std::make_shared(NodeVector{conv}, ParameterVector{data}); - } -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_cells_to_cells_ie_test.cpp b/src/plugins/intel_gna/legacy/tests/convert_cells_to_cells_ie_test.cpp deleted file mode 100644 index dcc57170121..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_cells_to_cells_ie_test.cpp +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "common_test_utils/test_common.hpp" - -using namespace testing; - -TEST_F(TransformationTestsF, GRUCellConversionTest) { - std::shared_ptr cell; - - const size_t batch_size = 2; - const size_t input_size = 3; - const size_t hidden_size = 3; - const size_t gates_count = 3; - { - const auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, input_size}); - const auto W = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, input_size}); - const auto R = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ov::element::f32, ov::Shape{batch_size, hidden_size}); - const auto B = std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size}); - cell = std::make_shared(X, H_t, W, R, B, hidden_size); - cell->set_friendly_name("test_cell"); - - model = std::make_shared(ov::NodeVector{cell}, ov::ParameterVector{X, H_t}); - manager.register_pass(); - } - - { - const auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, input_size}); - const auto W = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, input_size}); - const auto R = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ov::element::f32, ov::Shape{batch_size, hidden_size}); - const auto B = std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size}); - auto concat = std::make_shared(ov::NodeVector({W, R}), 1); - auto cell_ie = std::make_shared(X, - H_t, - concat, - B, - cell->get_hidden_size(), - cell->get_activations(), - cell->get_activations_alpha(), - cell->get_activations_beta(), - cell->get_clip(), - cell->get_linear_before_reset()); - cell_ie->set_friendly_name("test_cell"); - - model_ref = std::make_shared(ov::NodeVector{cell_ie}, ov::ParameterVector{X, H_t}); - } -} - -TEST_F(TransformationTestsF, RNNCellConversionTest) { - const size_t hidden_size = 3; - std::shared_ptr cell; - - { - auto X = std::make_shared(ov::element::f32, ov::Shape{2, 3}); - auto H = std::make_shared(ov::element::f32, ov::Shape{2, 3}); - auto W = std::make_shared(ov::element::f32, ov::Shape{3, 3}); - auto R = std::make_shared(ov::element::f32, ov::Shape{3, 3}); - auto B = std::make_shared(ov::element::f32, ov::Shape{3}); - - cell = std::make_shared(X, H, W, R, B, hidden_size); - cell->set_friendly_name("test_cell"); - - model = std::make_shared(ov::NodeVector{cell}, ov::ParameterVector{X, H}); - manager.register_pass(); - } - - { - auto X = std::make_shared(ov::element::f32, ov::Shape{2, 3}); - auto H = std::make_shared(ov::element::f32, ov::Shape{2, 3}); - auto W = std::make_shared(ov::element::f32, ov::Shape{3, 3}); - auto R = std::make_shared(ov::element::f32, ov::Shape{3, 3}); - auto B = std::make_shared(ov::element::f32, ov::Shape{3}); - auto concat = std::make_shared(ov::NodeVector({W, R}), 1); - auto cell_ie = std::make_shared(X, - H, - concat, - B, - cell->get_hidden_size(), - cell->get_activations(), - cell->get_activations_alpha(), - cell->get_activations_beta(), - cell->get_clip()); - - cell_ie->set_friendly_name("test_cell"); - model_ref = std::make_shared(ov::NodeVector{cell_ie}, ov::ParameterVector{X, H}); - } -} - -TEST_F(TransformationTestsF, LSTMCellConversionTest_opset3) { - const size_t batch_size = 2; - const size_t input_size = 3; - const size_t hidden_size = 3; - const size_t gates_count = 4; - - std::shared_ptr cell; - { - const auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, input_size}); - const auto W = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, input_size}); - const auto R = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ov::element::f32, ov::Shape{batch_size, hidden_size}); - const auto C_t = std::make_shared(ov::element::f32, ov::Shape{batch_size, hidden_size}); - const auto B = std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size}); - - cell = std::make_shared(X, H_t, C_t, W, R, B, hidden_size); - cell->set_friendly_name("test_cell"); - - model = std::make_shared(ov::NodeVector{cell}, ov::ParameterVector{X, H_t, C_t}); - manager.register_pass(); - } - - { - const auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, input_size}); - const auto W = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, input_size}); - const auto R = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ov::element::f32, ov::Shape{batch_size, hidden_size}); - const auto C_t = std::make_shared(ov::element::f32, ov::Shape{batch_size, hidden_size}); - const auto B = std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size}); - - auto concat = std::make_shared(ov::NodeVector({W, R}), 1); - auto cell_ie = std::make_shared(X, - H_t, - C_t, - concat, - B, - cell->get_hidden_size(), - cell->get_activations(), - cell->get_activations_alpha(), - cell->get_activations_beta(), - cell->get_clip()); - cell_ie->set_friendly_name("test_cell"); - - model_ref = std::make_shared(ov::NodeVector{cell_ie}, ov::ParameterVector{X, H_t, C_t}); - } -} - -TEST_F(TransformationTestsF, LSTMCellConversionTest_opset4) { - const size_t batch_size = 2; - const size_t input_size = 3; - const size_t hidden_size = 3; - const size_t gates_count = 4; - - std::shared_ptr cell; - { - const auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, input_size}); - const auto W = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, input_size}); - const auto R = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ov::element::f32, ov::Shape{batch_size, hidden_size}); - const auto C_t = std::make_shared(ov::element::f32, ov::Shape{batch_size, hidden_size}); - const auto B = std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size}); - - cell = std::make_shared(X, H_t, C_t, W, R, B, hidden_size); - - model = std::make_shared(ov::NodeVector{cell}, ov::ParameterVector{X, H_t, C_t}); - manager.register_pass(); - } - - { - const auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, input_size}); - const auto W = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, input_size}); - const auto R = - std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ov::element::f32, ov::Shape{batch_size, hidden_size}); - const auto C_t = std::make_shared(ov::element::f32, ov::Shape{batch_size, hidden_size}); - const auto B = std::make_shared(ov::element::f32, ov::Shape{gates_count * hidden_size}); - - auto concat = std::make_shared(ov::NodeVector({W, R}), 1); - auto cell_ie = std::make_shared(X, - H_t, - C_t, - concat, - B, - cell->get_hidden_size(), - cell->get_activations(), - cell->get_activations_alpha(), - cell->get_activations_beta(), - cell->get_clip()); - model_ref = std::make_shared(ov::NodeVector{cell_ie}, ov::ParameterVector{X, H_t, C_t}); - } -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_convolution_test.cpp b/src/plugins/intel_gna/legacy/tests/convert_convolution_test.cpp deleted file mode 100644 index 1adb814f3ad..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_convolution_test.cpp +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "common_test_utils/test_common.hpp" - -using namespace testing; -using namespace ov; -using namespace ov::opset1; - -using InputShape = PartialShape; -using WeightsShape = PartialShape; - -class ConvertConvolutionTest : public ov::test::TestsCommon, - public testing::WithParamInterface> { -public: - std::shared_ptr f, f_ref; - - void SetUp() override { - const auto& input_shape = std::get<0>(GetParam()); - const auto& weights_shape = std::get<1>(GetParam()); - - f = get_initial_model(input_shape, weights_shape); - f_ref = get_reference_function(input_shape, weights_shape); - } - -private: - std::shared_ptr get_initial_model(const PartialShape& input_shape, const PartialShape& weights_shape) { - assert(weights_shape.is_static()); - auto spatial_dims = input_shape.rank().get_length() - 2; - auto input = std::make_shared(element::f32, input_shape); - auto weights = Constant::create(element::f32, weights_shape.to_shape(), {1}); - auto conv = std::make_shared(input, - weights, - Strides(spatial_dims, 1), - CoordinateDiff(spatial_dims, 0), - CoordinateDiff(spatial_dims, 0), - Strides(spatial_dims, 1)); - - return std::make_shared(NodeVector{conv}, ParameterVector{input}); - } - - std::shared_ptr get_reference_function(const PartialShape& input_shape, const PartialShape& weights_shape) { - assert(weights_shape.is_static()); - auto spatial_dims = input_shape.rank().get_length() - 2; - auto input = std::make_shared(element::f32, input_shape); - auto weights = Constant::create(element::f32, weights_shape.get_shape(), {1}); - auto conv = std::make_shared(input, - weights, - Strides(spatial_dims, 1), - Strides(spatial_dims, 1), - CoordinateDiff(spatial_dims, 0), - CoordinateDiff(spatial_dims, 0), - element::f32); - - return std::make_shared(NodeVector{conv}, ParameterVector{input}); - } -}; - -TEST_P(ConvertConvolutionTest, CompareFunctions) { - const auto orig_shape = f->get_output_partial_shape(0); - pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(f); - - ASSERT_NO_THROW(check_rt_info(f)); - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; - ASSERT_TRUE(orig_shape.same_scheme(f->get_output_partial_shape(0))) - << "Shape " << orig_shape << " is not equal to " << f->get_output_partial_shape(0); -} - -INSTANTIATE_TEST_SUITE_P(ConvertConvolution, - ConvertConvolutionTest, - testing::Values(std::make_tuple(InputShape{DYN, DYN, DYN, DYN, DYN}, - WeightsShape{8, 3, 1, 2, 3}), - std::make_tuple(InputShape{DYN, 3, 64, 64, 64}, WeightsShape{8, 3, 1, 2, 3}), - std::make_tuple(InputShape{2, DYN, 64, 64, 64}, WeightsShape{9, 3, 2, 3, 1}), - std::make_tuple(InputShape{3, 3, DYN, 64, 64}, WeightsShape{6, 3, 3, 4, 2}), - std::make_tuple(InputShape{3, 3, 64, DYN, 64}, WeightsShape{5, 3, 3, 4, 3}), - std::make_tuple(InputShape{3, 3, 64, 64, DYN}, WeightsShape{5, 3, 3, 4, 3}), - std::make_tuple(InputShape{1, 3, 64, 64}, WeightsShape{6, 3, 1, 1}), - std::make_tuple(InputShape{DYN, DYN, DYN, DYN}, WeightsShape{7, 3, 1, 1}), - std::make_tuple(InputShape{DYN, 3, 64, 64}, WeightsShape{8, 3, 1, 2}), - std::make_tuple(InputShape{2, DYN, 64, 64}, WeightsShape{9, 3, 2, 3}), - std::make_tuple(InputShape{3, 3, DYN, 64}, WeightsShape{6, 3, 3, 4}), - std::make_tuple(InputShape{3, 3, 64, DYN}, WeightsShape{5, 3, 3, 4}), - std::make_tuple(InputShape{DYN, DYN, DYN}, WeightsShape{5, 3, 1}), - std::make_tuple(InputShape{DYN, 3, 10}, WeightsShape{3, 3, 1}), - std::make_tuple(InputShape{2, DYN, 9}, WeightsShape{2, 3, 2}), - std::make_tuple(InputShape{3, 3, DYN}, WeightsShape{1, 3, 3}))); - -TEST(ConvertConvolutionTest, GroupConvolutionWithReshape) { - PartialShape input_shape{1, 6, 64, 64}; - PartialShape weights_shape_before{2 * 3, 3, 5, 5}; - PartialShape weights_shape_after{2, 3, 3, 5, 5}; - size_t group = 2; - - std::shared_ptr f, f_ref; - { - auto spatial_dims = input_shape.rank().get_length() - 2; - auto input = std::make_shared(element::f32, input_shape); - auto weights = std::make_shared(element::f32, weights_shape_before); - auto reshape = std::make_shared( - weights, - Constant::create(element::i64, - Shape{static_cast(weights_shape_after.rank().get_length())}, - weights_shape_after.to_shape()), - true); - auto conv = std::make_shared(input, - reshape, - Strides(spatial_dims, 1), - CoordinateDiff(spatial_dims, 0), - CoordinateDiff(spatial_dims, 0), - Strides(spatial_dims, 1)); - - f = std::make_shared(NodeVector{conv}, ParameterVector{input, weights}); - } - - { - auto spatial_dims = input_shape.rank().get_length() - 2; - auto input = std::make_shared(element::f32, input_shape); - auto weights = std::make_shared(element::f32, weights_shape_before); - auto conv = std::make_shared(input, - weights, - Strides(spatial_dims, 1), - Strides(spatial_dims, 1), - CoordinateDiff(spatial_dims, 0), - CoordinateDiff(spatial_dims, 0), - element::f32, - group); - - f_ref = std::make_shared(NodeVector{conv}, ParameterVector{input, weights}); - } - - pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(f); - ASSERT_NO_THROW(check_rt_info(f)); - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; -} - -TEST(ConvertConvolutionTest, GroupConvolutionWithReshapeNeg) { - PartialShape input_shape{1, 6, 64, 64}; - PartialShape weights_shape_before{3, 2, 3, 5, 5}; - PartialShape weights_shape_after{2, 3, 3, 5, 5}; - PartialShape weights_shape_ref{2 * 3, 3, 5, 5}; - size_t group = 2; - - std::shared_ptr f, f_ref; - { - auto spatial_dims = input_shape.rank().get_length() - 2; - auto input = std::make_shared(element::f32, input_shape); - auto weights = std::make_shared(element::f32, weights_shape_before); - auto reshape = std::make_shared( - weights, - Constant::create(element::i64, - Shape{static_cast(weights_shape_after.rank().get_length())}, - weights_shape_after.to_shape()), - true); - auto conv = std::make_shared(input, - reshape, - Strides(spatial_dims, 1), - CoordinateDiff(spatial_dims, 0), - CoordinateDiff(spatial_dims, 0), - Strides(spatial_dims, 1)); - - f = std::make_shared(NodeVector{conv}, ParameterVector{input, weights}); - } - - { - auto spatial_dims = input_shape.rank().get_length() - 2; - auto input = std::make_shared(element::f32, input_shape); - auto weights_param = std::make_shared(element::f32, weights_shape_before); - auto reshape = std::make_shared( - weights_param, - Constant::create(element::i64, - Shape{static_cast(weights_shape_after.rank().get_length())}, - weights_shape_after.to_shape()), - true); - auto weights = std::make_shared( - reshape, - Constant::create(element::i64, - Shape{static_cast(weights_shape_ref.rank().get_length())}, - weights_shape_ref.to_shape()), - true); - auto conv = std::make_shared(input, - weights, - Strides(spatial_dims, 1), - Strides(spatial_dims, 1), - CoordinateDiff(spatial_dims, 0), - CoordinateDiff(spatial_dims, 0), - element::f32, - group); - - f_ref = std::make_shared(NodeVector{conv}, ParameterVector{input, weights_param}); - } - - pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(f); - // FIXME: 42956 - // ASSERT_NO_THROW(check_rt_info(f)); - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_deconvolution_test.cpp b/src/plugins/intel_gna/legacy/tests/convert_deconvolution_test.cpp deleted file mode 100644 index 32118727546..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_deconvolution_test.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "common_test_utils/test_common.hpp" - -using namespace testing; - -using InputShape = ov::PartialShape; -using WeightsShape = ov::Shape; - -class ConvertDeconvolutionTest : public ov::test::TestsCommon, - public testing::WithParamInterface> { -public: - std::shared_ptr f, f_ref; - - void SetUp() override { - const auto& input_shape = std::get<0>(GetParam()); - const auto& weights_shape = std::get<1>(GetParam()); - - f = get_initial_model(input_shape, weights_shape); - f_ref = get_reference_function(input_shape, weights_shape); - } - -private: - std::shared_ptr get_initial_model(const ov::PartialShape& input_shape, const ov::Shape& weights_shape) { - auto spatial_dims = input_shape.rank().get_length() - 2; - auto input = std::make_shared(ov::element::f32, input_shape); - auto weights = ov::opset1::Constant::create(ov::element::f32, weights_shape, {1}); - auto conv = std::make_shared(input, - weights, - ov::Strides(spatial_dims, 1), - ov::CoordinateDiff(spatial_dims, 0), - ov::CoordinateDiff(spatial_dims, 0), - ov::Strides(spatial_dims, 1)); - - return std::make_shared(ov::NodeVector{conv}, ov::ParameterVector{input}); - } - - std::shared_ptr get_reference_function(const ov::PartialShape& input_shape, - const ov::Shape& weights_shape) { - auto spatial_dims = input_shape.rank().get_length() - 2; - auto input = std::make_shared(ov::element::f32, input_shape); - auto weights = ov::opset1::Constant::create(ov::element::f32, weights_shape, {1}); - auto conv = std::make_shared(input, - weights, - ov::Strides(spatial_dims, 1), - ov::Strides(spatial_dims, 1), - ov::CoordinateDiff(spatial_dims, 0), - ov::CoordinateDiff(spatial_dims, 0), - ov::element::f32); - - return std::make_shared(ov::NodeVector{conv}, ov::ParameterVector{input}); - } -}; - -TEST_P(ConvertDeconvolutionTest, CompareFunctions) { - const auto orig_shape = f->get_output_partial_shape(0); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(f); - ASSERT_NO_THROW(check_rt_info(f)); - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; - ASSERT_TRUE(orig_shape.same_scheme(f->get_output_partial_shape(0))) - << "Shape " << orig_shape << " is not equal to " << f->get_output_partial_shape(0); -} - -INSTANTIATE_TEST_SUITE_P(ConvertDeconvolution, - ConvertDeconvolutionTest, - testing::Values(std::make_tuple(InputShape{DYN, DYN, DYN, DYN, DYN}, - WeightsShape{3, 8, 1, 2, 3}), - std::make_tuple(InputShape{DYN, 3, 64, 64, 64}, WeightsShape{3, 8, 1, 2, 3}), - std::make_tuple(InputShape{2, DYN, 64, 64, 64}, WeightsShape{3, 9, 2, 3, 1}), - std::make_tuple(InputShape{3, 3, DYN, 64, 64}, WeightsShape{3, 6, 3, 4, 2}), - std::make_tuple(InputShape{3, 3, 64, DYN, 64}, WeightsShape{3, 5, 3, 4, 3}), - std::make_tuple(InputShape{3, 3, 64, 64, DYN}, WeightsShape{3, 3, 3, 4, 3}), - std::make_tuple(InputShape{1, 3, 64, 64}, WeightsShape{3, 6, 1, 1}), - std::make_tuple(InputShape{DYN, DYN, DYN, DYN}, WeightsShape{3, 7, 1, 1}), - std::make_tuple(InputShape{DYN, 3, 64, 64}, WeightsShape{3, 8, 1, 2}), - std::make_tuple(InputShape{2, DYN, 64, 64}, WeightsShape{3, 9, 2, 3}), - std::make_tuple(InputShape{3, 3, DYN, 64}, WeightsShape{3, 6, 3, 4}), - std::make_tuple(InputShape{3, 3, 64, DYN}, WeightsShape{3, 5, 3, 4}), - std::make_tuple(InputShape{DYN, DYN, DYN}, WeightsShape{3, 5, 1}), - std::make_tuple(InputShape{DYN, 3, 10}, WeightsShape{3, 3, 1}), - std::make_tuple(InputShape{2, DYN, 9}, WeightsShape{3, 2, 2}), - std::make_tuple(InputShape{3, 3, DYN}, WeightsShape{3, 1, 3}))); diff --git a/src/plugins/intel_gna/legacy/tests/convert_gather_to_gather_ie.cpp b/src/plugins/intel_gna/legacy/tests/convert_gather_to_gather_ie.cpp deleted file mode 100644 index b1877d7b379..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_gather_to_gather_ie.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" - -using namespace testing; -using namespace ov; - -TEST_F(TransformationTestsF, ConvertGatherToGatherIEStatic1) { - { - auto input = std::make_shared(element::f32, Shape{6, 12, 10, 24}); - auto indices = std::make_shared(element::f32, Shape{15, 4, 20, 28}); - auto axis_const = opset1::Constant::create(element::i64, Shape{}, {1}); - auto gather = std::make_shared(input, indices, axis_const); - - model = std::make_shared(NodeVector{gather}, ParameterVector{input, indices}); - manager.register_pass(); - } - - { - auto input = std::make_shared(element::f32, Shape{6, 12, 10, 24}); - auto indices = std::make_shared(element::f32, Shape{15, 4, 20, 28}); - auto gather = std::make_shared(input, indices, 1); - - model_ref = std::make_shared(NodeVector{gather}, ParameterVector{input, indices}); - } -} - -TEST_F(TransformationTestsF, ConvertGatherToGatherIEStatic2) { - { - auto input = std::make_shared(element::f32, Shape{6, 12, 10, 24}); - auto indices = std::make_shared(element::f32, Shape{}); - auto axis_const = opset1::Constant::create(element::i64, Shape{}, {1}); - auto gather = std::make_shared(input, indices, axis_const); - - model = std::make_shared(NodeVector{gather}, ParameterVector{input, indices}); - manager.register_pass(); - } - - { - auto input = std::make_shared(element::f32, Shape{6, 12, 10, 24}); - auto indices = std::make_shared(element::f32, Shape{}); - auto unsqueeze = - std::make_shared(indices, opset1::Constant::create(element::i64, Shape{1}, {0})); - auto gather = std::make_shared(input, unsqueeze, 1); - auto squeeze = std::make_shared(gather, opset1::Constant::create(element::i64, Shape{1}, {1})); - - model_ref = std::make_shared(NodeVector{squeeze}, ParameterVector{input, indices}); - } -} - -TEST_F(TransformationTestsF, ConvertGatherToGatherIEDynamic1) { - { - auto input = std::make_shared(element::f32, PartialShape{DYN, DYN, DYN, DYN}); - auto indices = std::make_shared(element::f32, PartialShape{DYN, DYN}); - auto axis_const = opset1::Constant::create(element::i64, Shape{}, {1}); - auto gather = std::make_shared(input, indices, axis_const); - - model = std::make_shared(NodeVector{gather}, ParameterVector{input, indices}); - manager.register_pass(); - } - - { - auto input = std::make_shared(element::f32, PartialShape{DYN, DYN, DYN, DYN}); - auto indices = std::make_shared(element::f32, PartialShape{DYN, DYN}); - auto gather = std::make_shared(input, indices, 1); - - model_ref = std::make_shared(NodeVector{gather}, ParameterVector{input, indices}); - } -} - -TEST_F(TransformationTestsF, ConvertGatherToGatherIEDynamic2) { - { - auto input = std::make_shared(element::f32, PartialShape{DYN, DYN}); - auto indices = std::make_shared(element::f32, Shape{}); - auto axis_const = opset1::Constant::create(element::i64, Shape{}, {1}); - auto gather = std::make_shared(input, indices, axis_const); - - model = std::make_shared(NodeVector{gather}, ParameterVector{input, indices}); - manager.register_pass(); - } - - { - auto input = std::make_shared(element::f32, PartialShape{DYN, DYN}); - auto indices = std::make_shared(element::f32, Shape{}); - auto unsqueeze = - std::make_shared(indices, opset1::Constant::create(element::i64, Shape{1}, {0})); - auto gather = std::make_shared(input, unsqueeze, 1); - auto squeeze = std::make_shared(gather, opset1::Constant::create(element::i64, Shape{1}, {1})); - - model_ref = std::make_shared(NodeVector{squeeze}, ParameterVector{input, indices}); - } -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_interpolate_to_legacy.cpp b/src/plugins/intel_gna/legacy/tests/convert_interpolate_to_legacy.cpp deleted file mode 100644 index 27f11605168..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_interpolate_to_legacy.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" - -using namespace testing; - -TEST(TransformationTests, ConvertInterpolateDynamic) { - auto data = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto shape = ov::opset1::Constant::create(ov::element::i64, ov::Shape{2}, {30, 60}); - auto interp = std::make_shared(data, shape, ov::op::v0::Interpolate::Attributes()); - - auto f = std::make_shared(ov::NodeVector{interp}, ov::ParameterVector{data}); - - ov::pass::Manager m; - m.register_pass(); - ASSERT_NO_THROW(m.run_passes(f)); -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_lrn_to_legacy.cpp b/src/plugins/intel_gna/legacy/tests/convert_lrn_to_legacy.cpp deleted file mode 100644 index 5830fb44602..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_lrn_to_legacy.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" - -using namespace testing; - -TEST(TransformationTests, ConvertLRNToLegacyDynamic) { - auto data = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto axis = ov::opset1::Constant::create(ov::element::i64, ov::Shape{1}, {0}); - auto lrn = std::make_shared(data, axis, 1, 2, 3, 4); - - auto f = std::make_shared(ov::NodeVector{lrn}, ov::ParameterVector{data}); - - ov::pass::Manager m; - m.register_pass(); - ASSERT_NO_THROW(m.run_passes(f)); -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_matmul_test.cpp b/src/plugins/intel_gna/legacy/tests/convert_matmul_test.cpp deleted file mode 100644 index 1b81e71e89d..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_matmul_test.cpp +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "common_test_utils/test_common.hpp" - -using namespace testing; - -TEST_F(TransformationTestsF, ConvertMatMulTest1) { - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 1, 2}); - auto input2 = std::make_shared(ov::element::f32, ov::Shape{2, 1}); - auto matmul = std::make_shared(input1, input2, false, false); - - model = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1, input2}); - - manager.register_pass(); - manager.register_pass(); - } - - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 1, 2}); - auto input2 = std::make_shared(ov::element::f32, ov::Shape{2, 1}); - - auto reshape = ov::op::util::reshapeTo(input2, {1, 2, 1}); - - auto matmul = std::make_shared(input1, reshape, false, false); - - model_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1, input2}); - } -} - -TEST_F(TransformationTestsF, ConvertMatMulTest2) { - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 1, 2}); - auto input2 = std::make_shared(ov::element::f32, ov::Shape{2}); - auto matmul = std::make_shared(input1, input2, false, false); - - model = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1, input2}); - - manager.register_pass(); - manager.register_pass(); - } - - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 1, 2}); - auto input2 = std::make_shared(ov::element::f32, ov::Shape{2}); - - auto usnqueeze_input2 = - std::make_shared(input2, - ov::opset1::Constant::create(ov::element::i64, ov::Shape{1}, {1})); - auto reshape = ov::op::util::reshapeTo(usnqueeze_input2, {1, 2, 1}); - auto matmul = std::make_shared(input1, reshape, false, false); - auto reshape_output = ov::op::util::reshapeTo(matmul, {3, 1}); - - model_ref = std::make_shared(ov::NodeVector{reshape_output}, ov::ParameterVector{input1, input2}); - } -} - -TEST_F(TransformationTestsF, ConvertMatMulTest3) { - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{2}); - auto input2 = std::make_shared(ov::element::f32, ov::Shape{3, 2, 1}); - auto matmul = std::make_shared(input1, input2, false, false); - - model = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1, input2}); - manager.register_pass(); - manager.register_pass(); - } - - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{2}); - auto input2 = std::make_shared(ov::element::f32, ov::Shape{3, 2, 1}); - - auto usnqueeze_input1 = - std::make_shared(input1, - ov::opset1::Constant::create(ov::element::i64, ov::Shape{1}, {0})); - auto reshape = ov::op::util::reshapeTo(usnqueeze_input1, {1, 1, 2}); - auto matmul = std::make_shared(reshape, input2, false, false); - auto reshape_output = ov::op::util::reshapeTo(matmul, {3, 1}); - - model_ref = std::make_shared(ov::NodeVector{reshape_output}, ov::ParameterVector{input1, input2}); - } -} - -TEST_F(TransformationTestsF, ConvertMatMulTest4) { - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 1, 2}); - auto input2 = std::make_shared(ov::element::f32, ov::Shape{3, 2, 1}); - auto matmul = std::make_shared(input1, input2, false, false); - - model = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1, input2}); - manager.register_pass(); - manager.register_pass(); - } - - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 1, 2}); - auto input2 = std::make_shared(ov::element::f32, ov::Shape{3, 2, 1}); - auto matmul = std::make_shared(input1, input2, false, false); - - model_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1, input2}); - } -} - -TEST_F(TransformationTestsF, ConvertMatMulTest5) { - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 2, 2}); - auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 2}, {1}); - auto matmul = std::make_shared(input1, input2, false, true); - - model = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1}); - manager.register_pass(); - manager.register_pass(); - } - - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 2, 2}); - auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 2}, {1}); - auto input3 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2}, {1}); - auto matmul = std::make_shared(input1, input2, input3, ov::Shape{3, 2, 2}); - - model_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1}); - } -} - -TEST_F(TransformationTestsF, ConvertMatMulTest6) { - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 2, 2}); - auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 2}, {1}); - auto matmul = std::make_shared(input1, input2, false, true); - - model = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1}); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - } - - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 2, 2}); - auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 2}, {1}); - auto input3 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2}, {1}); - auto reshape_begin = ov::op::util::reshapeTo(input1, ov::Shape{6, 2}); - auto fc = std::make_shared(reshape_begin, input2, input3, ov::Shape{6, 2}); - auto reshape_end = ov::op::util::reshapeTo(fc, ov::Shape{3, 2, 2}); - - model_ref = std::make_shared(ov::NodeVector{reshape_end}, ov::ParameterVector{input1}); - } -} - -TEST_F(TransformationTestsF, ConvertMatMulTest7) { - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 2, 2}); - auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 2}, {1}); - auto matmul = std::make_shared(input1, input2, false, true); - - model = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1}); - - auto pass_config = manager.get_pass_config(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - - auto callback = [](const std::shared_ptr& node) -> bool { - if (auto fc_op = std::dynamic_pointer_cast(node)) { - if (fc_op->input_value(0).get_shape().size() == 3) { - return true; - } - } - return false; - }; - - pass_config->set_callback(callback); - } - - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{3, 2, 2}); - auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 2}, {1}); - auto input3 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2}, {1}); - auto matmul = std::make_shared(input1, input2, input3, ov::Shape{3, 2, 2}); - - model_ref = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1}); - } -} - -TEST(TransformationTests, ConvertMatMulDynamic) { - auto input1 = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 2}, {1}); - auto matmul = std::make_shared(input1, input2, false, true); - - auto f = std::make_shared(ov::NodeVector{matmul}, ov::ParameterVector{input1}); - - ov::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.register_pass(); - m.register_pass(); - ASSERT_NO_THROW(m.run_passes(f)); -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_ngraph_to_cnn_network_tests.cpp b/src/plugins/intel_gna/legacy/tests/convert_ngraph_to_cnn_network_tests.cpp deleted file mode 100644 index 6accecd8998..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_ngraph_to_cnn_network_tests.cpp +++ /dev/null @@ -1,478 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include - -#include // deprecated API -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace testing; -using namespace InferenceEngine; - -TEST(ConvertFunctionToCNNNetworkTests, ConvertPReLUNetwork) { - std::shared_ptr f; - { - auto param1 = std::make_shared(ov::element::f32, ov::Shape{2, 2}); - auto param2 = std::make_shared(ov::element::f32, ov::Shape{2, 2}); - auto prelu = std::make_shared(param1, param2); - prelu->set_friendly_name("prelu"); - auto result = std::make_shared(prelu); - - f = std::make_shared(ngraph::ResultVector{result}, ov::ParameterVector{param1, param2}); - ov::pass::Manager manager; - manager.register_pass(); - manager.run_passes(f); - } - - InferenceEngine::CNNNetwork nGraphImpl(f); - try { - auto net = std::make_shared(nGraphImpl); - } catch (InferenceEngine::Exception& err) { - const std::string ref_msg = - "Error of validate layer: prelu with type: PReLU. Number of inputs (2) is not equal to expected ones: 1"; - const std::string resp_msg = err.what(); - ASSERT_TRUE(resp_msg.find(ref_msg) != std::string::npos) << resp_msg; - } -} - -TEST(ConvertFunctionToCNNNetworkTests, ConvertConvolutionNetwork) { - std::shared_ptr f; - { - auto param1 = std::make_shared(ov::element::f32, ov::Shape{1, 3, 64, 64}); - auto param2 = std::make_shared(ov::element::f32, ov::Shape{3, 3, 1, 1}); - auto convolution = std::make_shared(param1, - param2, - ov::Strides{1, 1}, - ov::Strides{1, 1}, - ov::CoordinateDiff{0, 0}, - ov::CoordinateDiff{0, 0}, - ov::element::f32); - convolution->set_friendly_name("convolution"); - auto result = std::make_shared(convolution); - - f = std::make_shared(ngraph::ResultVector{result}, ov::ParameterVector{param1, param2}); - ov::pass::Manager manager; - manager.register_pass(); - manager.run_passes(f); - } - - InferenceEngine::CNNNetwork nGraphImpl(f); - try { - auto net = std::make_shared(nGraphImpl); - } catch (InferenceEngine::Exception& err) { - FAIL() << err.what(); - } -} - -TEST(ConvertFunctionToCNNNetworkTests, OpsShouldBeConvertedToIERepresentation) { - ov::NodeVector should_converted_to_ie = { - std::make_shared(), - std::make_shared(), - std::make_shared(), - std::make_shared(), - std::make_shared(), - // std::make_shared(), todo: enable after GRUSequence support - std::make_shared(), - std::make_shared(), - std::make_shared(), - // std::make_shared(), todo: enable after LSTMSequence support - std::make_shared(), - std::make_shared(), - std::make_shared(), - // std::make_shared(), todo: enable after RNNSequence support - std::make_shared(), - std::make_shared(), - std::make_shared(), - std::make_shared(), - std::make_shared(), - std::make_shared(), - std::make_shared(), - }; - - // create simple ngraph function Parameter -> Result - std::shared_ptr f; - auto param = std::make_shared(ov::element::f32, ov::Shape{}); - auto res = std::make_shared(param); - f = std::make_shared(ngraph::ResultVector{res}, ov::ParameterVector{param}); - InferenceEngine::CNNNetwork nGraphImpl(f); - - for (const auto& ngraph_node : should_converted_to_ie) { - // add node without inputs to the ngraph function - ngraph_node->set_output_type(0, ov::element::f32, ov::Shape{}); - res->input(0).replace_source_output(ngraph_node->output(0)); - - EXPECT_THROW(InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl, true), - InferenceEngine::Exception) - << "failed node: " << ngraph_node->get_type_name() << std::endl; - try { - InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl, true); - } catch (InferenceEngine::Exception& err) { - std::string type_name = ngraph_node->get_type_name(); - - std::map exceptions = { - {"Broadcast", "Tile"}, - {"Interpolate", "Interp"}, - {"NormalizeL2", "NormalizeIE"}, - {"GroupConvolution", "ConvolutionIE"}, - {"ConvolutionBackpropData", "DeconvolutionIE"}, - {"GroupConvolutionBackpropData", "DeconvolutionIE"}, - }; - std::string type_name_ie = type_name + "IE"; - if (exceptions[type_name].empty()) { - type_name_ie = type_name + "IE"; - } else { - type_name_ie = exceptions[type_name]; - } - std::string expected_error_message = type_name + " operation has a form that is not supported. " + - ngraph_node->get_friendly_name() + " should be converted to " + - type_name_ie + " operation."; - std::string real_message = err.what(); - bool is_messages_match = real_message.find(expected_error_message) != std::string::npos; - EXPECT_TRUE(is_messages_match) << "failed node: " << type_name << std::endl - << "Exception massage: " << err.what() << std::endl - << "Expected message: " << expected_error_message << std::endl; - } catch (...) { - FAIL() << "ERROR: Unexpected exception thrown: " << std::current_exception << std::endl; - } - } -} - -TEST(ConvertFunctionToCNNNetworkTests, ConvertTopKWithOneInput) { - std::shared_ptr f; - { - auto param = std::make_shared(ov::element::f32, ov::Shape{1, 3, 22, 22}); - ov::Shape const_shape = {}; - std::vector val = {5}; - auto k = std::make_shared(ov::element::i64, const_shape, val); - auto topK = std::make_shared(param, - k, - 2, - ov::opset4::TopK::Mode::MAX, - ov::opset4::TopK::SortType::SORT_VALUES); - topK->set_friendly_name("topK"); - auto result = std::make_shared(topK->output(1)); - - f = std::make_shared(ngraph::ResultVector{result}, ov::ParameterVector{param}); - ov::pass::Manager manager; - manager.register_pass(); - manager.run_passes(f); - } - - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - - static const precisions_map convert_precision_map{ - {ov::element::i64, ov::element::i32}, - {ov::element::u64, ov::element::i32}, - {ov::element::u16, ov::element::i32}, - {ov::element::u32, ov::element::i32}, - {ov::element::f16, ov::element::f32}, - {ov::element::boolean, ov::element::u8}, - }; - - manager.register_pass(convert_precision_map); - manager.register_pass(); - manager.register_pass(precisions_map{{ov::element::i64, ov::element::i32}}); - - manager.run_passes(f); - - InferenceEngine::CNNNetwork nGraphImpl(f); - IE_SUPPRESS_DEPRECATED_START - nGraphImpl = CNNNetwork(InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl)); - IE_SUPPRESS_DEPRECATED_END - - try { - OutputsDataMap outputs = nGraphImpl.getOutputsInfo(); - ASSERT_EQ(outputs.size(), 1); - ASSERT_EQ(outputs.begin()->first, "topK.1"); - } catch (InferenceEngine::Exception& err) { - const std::string ref_msg = - "Error of validate layer: prelu with type: PReLU. Number of inputs (2) is not equal to expected ones: 1"; - const std::string resp_msg = err.what(); - ASSERT_TRUE(resp_msg.find(ref_msg) != std::string::npos) << resp_msg; - } -} - -TEST(ConvertFunctionToCNNNetworkTests, UnsupportedDynamicOps) { - std::shared_ptr f; - { - auto param = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - param->set_friendly_name("param"); - auto relu = std::make_shared(param); - relu->set_friendly_name("relu"); - auto non_zero = std::make_shared(relu); - non_zero->set_friendly_name("non_zero"); - auto result = std::make_shared(non_zero->output(0)); - result->set_friendly_name("result"); - - f = std::make_shared(ngraph::ResultVector{result}, ov::ParameterVector{param}); - } - - InferenceEngine::CNNNetwork nGraphImpl(f); - try { - InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl); - FAIL() << "InferenceEngine::Exception must be thrown"; - } catch (InferenceEngine::Exception& e) { - EXPECT_THAT(e.what(), - testing::HasSubstr(std::string("Unsupported dynamic ops: \n" - "opset1::Parameter param () -> (f32[...])\n" - "opset1::Relu relu (param[0]:f32[...]) -> (f32[...])\n" - "opset3::NonZero non_zero (relu[0]:f32[...]) -> (i64[?,?])\n" - "opset1::Result result (non_zero[0]:i64[?,?]) -> (i64[?,?])"))); - } -} - -TEST(ConvertFunctionToCNNNetworkTests, NonUniqueNamesAllInternal) { - std::shared_ptr f(nullptr); - { - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 3}); - auto begin = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - auto end = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - end->set_friendly_name(begin->get_name()); - auto stride = ov::opset1::Constant::create(ov::element::i64, {2}, {1, 1}); - auto ss = std::make_shared(input, - begin, - end, - stride, - std::vector{1, 1}, - std::vector{1, 1}); - - f = std::make_shared(ov::NodeVector{ss}, ov::ParameterVector{input}); - } - - InferenceEngine::CNNNetwork nGraphImpl(f); - IE_SUPPRESS_DEPRECATED_START - nGraphImpl = CNNNetwork(InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl)); - IE_SUPPRESS_DEPRECATED_END - ASSERT_EQ(nGraphImpl.layerCount(), 5); -} - -TEST(ConvertFunctionToCNNNetworkTests, NonUniqueNamesHasResult1) { - std::shared_ptr f(nullptr); - { - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 3}); - auto begin = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - auto end = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - end->set_friendly_name(begin->get_name()); - auto stride = ov::opset1::Constant::create(ov::element::i64, {2}, {1, 1}); - auto ss = std::make_shared(input, - begin, - end, - stride, - std::vector{1, 1}, - std::vector{1, 1}); - - f = std::make_shared(ov::NodeVector{ss, begin}, ov::ParameterVector{input}); - } - - InferenceEngine::CNNNetwork nGraphImpl(f); - IE_SUPPRESS_DEPRECATED_START - nGraphImpl = CNNNetwork(InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl)); - IE_SUPPRESS_DEPRECATED_END - ASSERT_EQ(nGraphImpl.layerCount(), 5); -} - -TEST(ConvertFunctionToCNNNetworkTests, NonUniqueNamesHasResult2) { - std::shared_ptr f(nullptr); - { - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 3}); - auto begin = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - begin->set_friendly_name("const"); - auto end = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - end->set_friendly_name("const"); - auto stride = ov::opset1::Constant::create(ov::element::i64, {2}, {1, 1}); - stride->set_friendly_name("const"); - auto ss = std::make_shared(input, - begin, - end, - stride, - std::vector{1, 1}, - std::vector{1, 1}); - - f = std::make_shared(ov::NodeVector{ss, begin}, ov::ParameterVector{input}); - } - - InferenceEngine::CNNNetwork nGraphImpl(f); - IE_SUPPRESS_DEPRECATED_START - nGraphImpl = CNNNetwork(InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl)); - IE_SUPPRESS_DEPRECATED_END - ASSERT_EQ(nGraphImpl.layerCount(), 5); -} - -TEST(ConvertFunctionToCNNNetworkTests, NonUniqueNamesHasResult3) { - std::shared_ptr f(nullptr); - { - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 3}); - auto begin = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - begin->set_friendly_name("const"); - auto end = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - end->set_friendly_name("const"); - auto stride = ov::opset1::Constant::create(ov::element::i64, {2}, {1, 1}); - stride->set_friendly_name("const"); - auto ss = std::make_shared(input, - begin, - end, - stride, - std::vector{1, 1}, - std::vector{1, 1}); - ss->set_friendly_name("node"); - auto squeeze = - std::make_shared(ss, ov::opset1::Constant::create(ov::element::i64, {1}, {0})); - squeeze->set_friendly_name("node"); - f = std::make_shared(ov::NodeVector{squeeze, begin}, ov::ParameterVector{input}); - } - - InferenceEngine::CNNNetwork nGraphImpl(f); - IE_SUPPRESS_DEPRECATED_START - nGraphImpl = CNNNetwork(InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl)); - IE_SUPPRESS_DEPRECATED_END - ASSERT_EQ(nGraphImpl.layerCount(), 7); - auto outputs_info = nGraphImpl.getOutputsInfo(); - ASSERT_TRUE(outputs_info.count("node")); - ASSERT_TRUE(outputs_info.count("const")); -} - -TEST(ConvertFunctionToCNNNetworkTests, NonUniqueNamesNegative) { - std::shared_ptr f(nullptr); - { - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 3}); - auto begin = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - begin->set_friendly_name("const"); - auto end = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - end->set_friendly_name("const"); - auto stride = ov::opset1::Constant::create(ov::element::i64, {2}, {1, 1}); - auto ss = std::make_shared(input, - begin, - end, - stride, - std::vector{1, 1}, - std::vector{1, 1}); - - f = std::make_shared(ov::NodeVector{ss, begin, end}, ov::ParameterVector{input}); - } - - ASSERT_THROW(InferenceEngine::CNNNetwork{f}, InferenceEngine::Exception); -} - -TEST(ConvertFunctionToCNNNetworkTests, NonUniqueNamesParametersNegative) { - std::shared_ptr f(nullptr); - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 3}); - input->set_friendly_name("param"); - auto begin = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - auto end = ov::opset1::Constant::create(ov::element::i64, {2}, {0, 0}); - auto stride = ov::opset1::Constant::create(ov::element::i64, {2}, {1, 1}); - auto ss = std::make_shared(input, - begin, - end, - stride, - std::vector{1, 1}, - std::vector{1, 1}); - auto input2 = std::make_shared(ov::element::f32, ov::Shape{1, 3}); - auto concat = std::make_shared(ov::NodeVector{ss, input2}, 0); - - f = std::make_shared(ov::NodeVector{concat}, ov::ParameterVector{input, input2}); - - InferenceEngine::CNNNetwork nGraphImpl(f); - try { - input2->set_friendly_name("param"); - InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl); - FAIL() << "InferenceEngine::Exception must be thrown"; - } catch (InferenceEngine::Exception& e) { - EXPECT_THAT(e.what(), testing::HasSubstr(std::string("Detected two output operations with the same name:"))); - } -} - -TEST(ConvertFunctionToCNNNetworkTests, IteratorForMemoryLayers) { - std::shared_ptr f(nullptr); - { - auto constReadVal = ov::opset5::Constant::create(ov::element::f32, {1, 37632}, {0}); - constReadVal->set_friendly_name("const"); - auto readVal = std::make_shared(constReadVal, "buffer_1"); - readVal->set_friendly_name("readVal_Buf1"); - - auto constVarSplit1 = ov::opset5::Constant::create(ov::element::i64, {}, {1}); - constVarSplit1->set_friendly_name("varSplitConst1"); - auto constVarSplit2 = ov::opset5::Constant::create(ov::element::i64, {2}, {5376, 32256}); - constVarSplit2->set_friendly_name("varSplitConst2"); - - auto varSplit = std::make_shared(readVal, constVarSplit1, constVarSplit2); - - auto param1 = std::make_shared(ov::element::f32, ov::Shape{1, 5376}); - auto varConcat = std::make_shared(ov::OutputVector{varSplit->output(0), param1}, 1); - auto result = std::make_shared(varConcat); - - auto param2 = std::make_shared(ov::element::f32, ov::Shape{1, 5376}); - auto varConcat2 = std::make_shared(ov::OutputVector{varSplit->output(1), param2}, 1); - - auto assign = std::make_shared(varConcat2, "buffer_1"); - f = std::make_shared(ngraph::ResultVector{result}, - ngraph::SinkVector{assign}, - ov::ParameterVector{param1, param2}); - } - - InferenceEngine::CNNNetwork nGraphImpl(f); - IE_SUPPRESS_DEPRECATED_START - nGraphImpl = CNNNetwork(InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl)); - int memory_count(0); - for (details::CNNNetworkIterator itLayer{nGraphImpl}; itLayer != details::CNNNetworkIterator(); itLayer++) { - if ((*itLayer)->type == "Memory") - memory_count++; - } - IE_SUPPRESS_DEPRECATED_END - ASSERT_EQ(2, memory_count); -} - -TEST(ConvertFunctionToCNNNetworkTests, IteratorForMemoryLayers2) { - std::shared_ptr f(nullptr); - { - auto constReadVal = ov::opset5::Constant::create(ov::element::f32, {1, 37632}, {0}); - constReadVal->set_friendly_name("const"); - auto readVal = std::make_shared(constReadVal, "buffer_1"); - readVal->set_friendly_name("readVal_Buf1"); - - auto constVarSplit1 = ov::opset5::Constant::create(ov::element::i64, {}, {1}); - constVarSplit1->set_friendly_name("varSplitConst1"); - auto constVarSplit2 = ov::opset5::Constant::create(ov::element::i64, {2}, {5376, 32256}); - constVarSplit2->set_friendly_name("varSplitConst2"); - - auto varSplit = std::make_shared(readVal, constVarSplit1, constVarSplit2); - - auto param2 = std::make_shared(ov::element::f32, ov::Shape{1, 5376}); - auto varConcat2 = std::make_shared(ov::OutputVector{varSplit->output(1), param2}, 1); - - auto assign = std::make_shared(varConcat2, "buffer_1"); - f = std::make_shared(ngraph::ResultVector{}, - ngraph::SinkVector{assign}, - ov::ParameterVector{param2}); - } - - InferenceEngine::CNNNetwork nGraphImpl(f); - IE_SUPPRESS_DEPRECATED_START - nGraphImpl = CNNNetwork(InferenceEngine::details::convertFunctionToICNNNetwork(f, nGraphImpl)); - int memory_count(0); - for (details::CNNNetworkIterator itLayer{nGraphImpl}; itLayer != details::CNNNetworkIterator(); itLayer++) { - if ((*itLayer)->type == "Memory") - memory_count++; - } - IE_SUPPRESS_DEPRECATED_END - ASSERT_EQ(2, memory_count); -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_nms5_test.cpp b/src/plugins/intel_gna/legacy/tests/convert_nms5_test.cpp deleted file mode 100644 index 91bbab21cc9..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_nms5_test.cpp +++ /dev/null @@ -1,819 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" - -using namespace testing; -using namespace ov; - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEStaticSixInputs) { - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - auto soft_nms_sigma = ov::opset5::Constant::create(element::f32, Shape{}, {0.25}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - soft_nms_sigma, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - auto soft_nms_sigma = ov::opset5::Constant::create(element::f32, Shape{}, {0.25}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_soft_nms_sigma = - std::make_shared(soft_nms_sigma, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - new_soft_nms_sigma, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEStaticFiveInputs) { - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEStaticFourInputs) { - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEStaticThreeInputs) { - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEStaticTwoInputs) { - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto nms = std::make_shared(boxes, - scores, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i32, Shape{}, {0}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEDynamic1SixInputs) { - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - auto soft_nms_sigma = ov::opset5::Constant::create(element::f32, Shape{}, {0.25}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - soft_nms_sigma, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - auto soft_nms_sigma = ov::opset5::Constant::create(element::f32, Shape{}, {0.25}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_soft_nms_sigma = - std::make_shared(soft_nms_sigma, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - new_soft_nms_sigma, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEDynamic1FiveInputs) { - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEDynamic1FourInputs) { - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEDynamic1ThreeInputs) { - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEDynamic1TwoInputs) { - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto nms = std::make_shared(boxes, - scores, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto max_output_boxes_per_class = opset5::Constant::create(element::i32, Shape{}, {0}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEDynamic2SixInputs) { - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - auto soft_nms_sigma = ov::opset5::Constant::create(element::f32, Shape{}, {0.25}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - soft_nms_sigma, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - auto soft_nms_sigma = ov::opset5::Constant::create(element::f32, Shape{}, {0.25}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_soft_nms_sigma = - std::make_shared(soft_nms_sigma, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - new_soft_nms_sigma, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEDynamic2FiveInputs) { - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.7}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEDynamic2FourInputs) { - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEDynamic2ThreeInputs) { - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMS5ToNMSIEDynamic2TwoInputs) { - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto nms = std::make_shared(boxes, - scores, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i32, Shape{}, {0}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.0f}); - - auto one_dim_shape = Shape{1}; - auto new_max_per_class = - std::make_shared(max_output_boxes_per_class, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_iou_threshold = - std::make_shared(iou_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto new_score_threshold = - std::make_shared(score_threshold, - opset5::Constant::create(ov::element::i64, one_dim_shape, one_dim_shape), - true); - auto nms = std::make_shared(boxes, - scores, - new_max_per_class, - new_iou_threshold, - new_score_threshold, - 0, - true, - element::i32); - - auto convert_0 = std::make_shared(nms->output(0), element::i64); - - model_ref = std::make_shared(NodeVector{convert_0}, ParameterVector{boxes, scores}); - } -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_nms_to_nms_ie_test.cpp b/src/plugins/intel_gna/legacy/tests/convert_nms_to_nms_ie_test.cpp deleted file mode 100644 index f4cc881d9c1..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_nms_to_nms_ie_test.cpp +++ /dev/null @@ -1,266 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" - -using namespace testing; -using namespace ov; - -TEST_F(TransformationTestsF, ConvertNMSToNMSIEStatic) { - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - opset3::NonMaxSuppression::BoxEncodingType::CORNER, - true); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - - // as inside test infrastructure we can not predict output names for given Function - // we have to enable soft names comparison manually - enable_soft_names_comparison(); - } - - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{1}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared( - boxes, - scores, - max_output_boxes_per_class, - std::make_shared(iou_threshold, opset1::Constant::create(element::i64, Shape{1}, {0})), - std::make_shared(score_threshold, opset1::Constant::create(element::i64, Shape{1}, {0})), - 0, - true); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMSToNMSIEDynamic1) { - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - opset3::NonMaxSuppression::BoxEncodingType::CORNER, - true); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape::dynamic()); - auto scores = std::make_shared(element::f32, PartialShape::dynamic()); - auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{1}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared( - boxes, - scores, - max_output_boxes_per_class, - std::make_shared(iou_threshold, opset1::Constant::create(element::i64, Shape{1}, {0})), - std::make_shared(score_threshold, opset1::Constant::create(element::i64, Shape{1}, {0})), - 0, - true); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMSToNMSIEDynamic2) { - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - opset3::NonMaxSuppression::BoxEncodingType::CORNER, - true); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, PartialShape{DYN, 1000, 4}); - auto scores = std::make_shared(element::f32, PartialShape{DYN, 1, 1000}); - auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{1}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared( - boxes, - scores, - max_output_boxes_per_class, - std::make_shared(iou_threshold, opset1::Constant::create(element::i64, Shape{1}, {0})), - std::make_shared(score_threshold, opset1::Constant::create(element::i64, Shape{1}, {0})), - 0, - true); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMST1oNMSIE) { - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - op::v1::NonMaxSuppression::BoxEncodingType::CORNER, - true); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{1}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - 0, - true, - element::i32); - auto convert = std::make_shared(nms->output(0), element::i64); - - model_ref = std::make_shared(NodeVector{convert}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMST3oNMSIE) { - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset1::Constant::create(element::i32, Shape{}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - opset3::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset1::Constant::create(element::i32, Shape{1}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} - -TEST_F(TransformationTestsF, ConvertNMST4oNMSIE) { - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset1::Constant::create(element::i32, Shape{}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - opset4::NonMaxSuppression::BoxEncodingType::CORNER, - true, - element::i32); - - model = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - - manager.register_pass(); - } - - { - auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); - auto max_output_boxes_per_class = opset1::Constant::create(element::i32, Shape{1}, {10}); - auto iou_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.75}); - auto score_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.7}); - auto nms = std::make_shared(boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - 0, - true, - element::i32); - - model_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); - } -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_pad_to_legacy.cpp b/src/plugins/intel_gna/legacy/tests/convert_pad_to_legacy.cpp deleted file mode 100644 index 7f2324c7135..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_pad_to_legacy.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" - -using namespace testing; - -TEST(TransformationTests, ConvertPadToLegacyDynamic) { - auto data = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto pad_begin = ov::opset1::Constant::create(ov::element::i64, ov::Shape{2}, {1, 0}); - auto pad_end = ov::opset1::Constant::create(ov::element::i64, ov::Shape{2}, {0, 1}); - auto pad = std::make_shared(data, pad_begin, pad_end, ngraph::op::PadMode::SYMMETRIC); - - auto f = std::make_shared(ov::NodeVector{pad}, ov::ParameterVector{data}); - - ov::pass::Manager m; - m.register_pass(); - ASSERT_NO_THROW(m.run_passes(f)); -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_sequences_to_sequences_ie_test.cpp b/src/plugins/intel_gna/legacy/tests/convert_sequences_to_sequences_ie_test.cpp deleted file mode 100644 index 2eb898f46b9..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_sequences_to_sequences_ie_test.cpp +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "common_test_utils/test_common.hpp" - -using namespace testing; - -TEST_F(TransformationTestsF, GRUSequenceConversionTest) { - std::shared_ptr sequence; - - const size_t batch_size = 2; - const size_t input_size = 3; - const size_t hidden_size = 3; - const size_t gates_count = 3; - const size_t num_directions = 1; - { - const auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, 1, input_size}); - const auto W = - std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size, input_size}); - const auto R = - std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ov::element::f32, - ov::Shape{batch_size, num_directions, hidden_size}); - const auto B = std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size}); - - const auto seq_len = std::make_shared(ov::element::i32, ov::Shape{batch_size}); - sequence = std::make_shared(X, - H_t, - seq_len, - W, - R, - B, - hidden_size, - ngraph::op::RecurrentSequenceDirection::FORWARD); - - model = std::make_shared(ov::NodeVector{sequence}, ov::ParameterVector{X, H_t}); - manager.register_pass(); - } - - { - const auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, 1, input_size}); - const auto W = - std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size, input_size}); - const auto R = - std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ov::element::f32, - ov::Shape{batch_size, num_directions, hidden_size}); - const auto B = std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size}); - - const auto seq_len = std::make_shared(ov::element::i32, ov::Shape{batch_size}, 1); - auto axis_1 = ov::opset5::Constant::create(ov::element::i64, ov::Shape{1}, {1}); - auto in_1 = std::make_shared(H_t, axis_1); - auto concat = std::make_shared(ov::NodeVector({W, R}), 2); - auto axis_2 = ov::opset5::Constant::create(ov::element::i64, ov::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(B, axis_2); - auto sequence_ie = std::make_shared(X, - in_1, - seq_len, // this input is not supported - in_3, - in_4, - sequence->get_hidden_size(), - sequence->get_direction(), - sequence->get_activations(), - sequence->get_activations_alpha(), - sequence->get_activations_beta(), - sequence->get_clip(), - sequence->get_linear_before_reset()); - - auto unsqueeze_axis = ov::opset5::Constant::create(ov::element::i64, ov::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(sequence_ie->output(1), unsqueeze_axis); - model_ref = std::make_shared(ov::NodeVector{unsqueeze_1}, ov::ParameterVector{X, H_t}); - } -} - -TEST_F(TransformationTestsF, RNNSequenceConversionTest) { - const size_t hidden_size = 3; - const size_t num_directions = 1; - const size_t batch_size = 2; - std::shared_ptr sequence; - - { - auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, 1, 3}); - auto H = std::make_shared(ov::element::f32, ov::Shape{batch_size, num_directions, 3}); - auto W = std::make_shared(ov::element::f32, ov::Shape{num_directions, 3, 3}); - auto R = std::make_shared(ov::element::f32, ov::Shape{num_directions, 3, 3}); - auto B = std::make_shared(ov::element::f32, ov::Shape{num_directions, 3}); - auto seq_len = std::make_shared(ov::element::f32, ov::Shape{2}); - sequence = std::make_shared(X, - H, - seq_len, - W, - R, - B, - hidden_size, - ngraph::op::RecurrentSequenceDirection::FORWARD); - - model = std::make_shared(ov::NodeVector{sequence}, ov::ParameterVector{X, H}); - manager.register_pass(); - } - - { - auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, 1, 3}); - auto H = std::make_shared(ov::element::f32, ov::Shape{batch_size, num_directions, 3}); - auto W = std::make_shared(ov::element::f32, ov::Shape{num_directions, 3, 3}); - auto R = std::make_shared(ov::element::f32, ov::Shape{num_directions, 3, 3}); - auto B = std::make_shared(ov::element::f32, ov::Shape{num_directions, 3}); - auto seq_len = std::make_shared(ov::element::f32, ov::Shape{batch_size}, 1); - auto axis_1 = ov::opset5::Constant::create(ov::element::i64, ov::Shape{1}, {1}); - auto in_1 = std::make_shared(H, axis_1); - auto concat = std::make_shared(ov::NodeVector({W, R}), 2); - auto axis_2 = ov::opset5::Constant::create(ov::element::i64, ov::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(B, axis_2); - auto sequence_ie = std::make_shared(X, - in_1, - seq_len, - in_3, - in_4, - sequence->get_hidden_size(), - sequence->get_direction(), - sequence->get_activations(), - sequence->get_activations_alpha(), - sequence->get_activations_beta(), - sequence->get_clip()); - - auto unsqueeze_axis = ov::opset5::Constant::create(ov::element::i64, ov::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(sequence_ie->output(1), unsqueeze_axis); - model_ref = std::make_shared(ov::NodeVector{unsqueeze_1}, ov::ParameterVector{X, H}); - } -} - -TEST_F(TransformationTestsF, LSTMSequenceConversionTest) { - const size_t batch_size = 2; - const size_t input_size = 3; - const size_t hidden_size = 3; - const size_t gates_count = 4; - const size_t num_directions = 1; - std::shared_ptr sequence; - { - const auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, 10, input_size}); - const auto W = - std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size, input_size}); - const auto R = - std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ov::element::f32, - ov::Shape{batch_size, num_directions, hidden_size}); - const auto C_t = std::make_shared(ov::element::f32, - ov::Shape{batch_size, num_directions, hidden_size}); - const auto B = std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size}); - - const auto seq_len = std::make_shared(ov::element::f32, ov::Shape{batch_size}); - sequence = std::make_shared(X, - H_t, - C_t, - seq_len, - W, - R, - B, - hidden_size, - ngraph::op::RecurrentSequenceDirection::FORWARD); - sequence->set_friendly_name("test_sequence"); - - model = std::make_shared(ov::OutputVector{sequence->output(0)}, ov::ParameterVector{X, H_t, C_t}); - manager.register_pass(); - } - - { - const auto X = std::make_shared(ov::element::f32, ov::Shape{batch_size, 10, input_size}); - const auto W = - std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size, input_size}); - const auto R = - std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ov::element::f32, - ov::Shape{batch_size, num_directions, hidden_size}); - const auto C_t = std::make_shared(ov::element::f32, - ov::Shape{batch_size, num_directions, hidden_size}); - const auto seq_lengths = std::make_shared(ov::element::f32, ov::Shape{batch_size}); - const auto B = std::make_shared(ov::element::f32, - ov::Shape{num_directions, gates_count * hidden_size}); - // const auto seq_len = std::make_shared(ov::element::i32, ov::Shape{1}, 1); - auto axis_1 = ov::opset5::Constant::create(ov::element::i64, ov::Shape{1}, {1}); - auto in_1 = std::make_shared(H_t, axis_1); - auto in_2 = std::make_shared(C_t, axis_1); - auto concat = std::make_shared(ov::NodeVector({W, R}), 2); - auto axis_2 = ov::opset5::Constant::create(ov::element::i64, ov::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(B, axis_2); - auto sequence_ie = std::make_shared(X, - in_1, - in_2, - seq_lengths, - in_3, - in_4, - sequence->get_hidden_size(), - sequence->get_direction(), - sequence->get_activations(), - sequence->get_activations_alpha(), - sequence->get_activations_beta(), - sequence->get_clip()); - auto unsqueeze_axis = ov::opset5::Constant::create(ov::element::i64, ov::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(sequence_ie->output(1), unsqueeze_axis); - auto unsqueeze_3 = std::make_shared(sequence_ie->output(2), unsqueeze_axis); - model_ref = std::make_shared(ov::NodeVector{unsqueeze_1}, ov::ParameterVector{X, H_t, C_t}); - } -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_strided_slice_to_crop_test.cpp b/src/plugins/intel_gna/legacy/tests/convert_strided_slice_to_crop_test.cpp deleted file mode 100644 index 5c54aec78a2..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_strided_slice_to_crop_test.cpp +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "common_test_utils/test_common.hpp" - -using namespace testing; - -TEST_F(TransformationTestsF, ConvertStridedSliceToCropTests1) { - { - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 2, 384, 640}); - auto slice_begin = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {0, 1, 0, 0}); - auto slice_end = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 0, 0}); - auto slice_stride = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {1, 1, 1, 1}); - - std::vector begin_mask = {1, 0, 1, 1}; - std::vector end_mask = {1, 0, 1, 1}; - std::vector new_axis_mask = {0, 0, 0, 0}; - std::vector shrink_axis_mask = {0, 1, 0, 0}; - std::vector ellipsis_mask = {0, 0, 0, 0}; - - auto sslice = std::make_shared(input, - slice_begin, - slice_end, - slice_stride, - begin_mask, - end_mask, - new_axis_mask, - shrink_axis_mask, - ellipsis_mask); - sslice->set_friendly_name("strided_slice"); - - model = std::make_shared(ov::NodeVector{sslice}, ov::ParameterVector{input}); - manager.register_pass(); - } - - { - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 2, 384, 640}); - - std::vector axes = {0, 1, 2, 3}; - std::vector dim = {1, 1, 384, 640}; - std::vector offset = {0, 1, 0, 0}; - - auto crop = std::make_shared(input, axes, dim, offset); - crop->set_friendly_name("strided_slice/Crop"); - - auto reshape = ov::op::util::reshapeTo(crop, {1, 384, 640}); - reshape->set_friendly_name("strided_slice"); - - model_ref = std::make_shared(ov::NodeVector{reshape}, ov::ParameterVector{input}); - } -} - -TEST_F(TransformationTestsF, ConvertStridedSliceToCropTests2) { - { - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 2, 384, 640}); - auto slice_begin = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {0, 0, 0, 0}); - auto slice_end = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {0, 1, 0, 0}); - auto slice_stride = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {1, 1, 1, 1}); - - std::vector begin_mask = {1, 1, 1, 1}; - std::vector end_mask = {1, 0, 1, 1}; - std::vector new_axis_mask = {0, 0, 0, 0}; - std::vector shrink_axis_mask = {0, 1, 0, 0}; - std::vector ellipsis_mask = {0, 0, 0, 0}; - - auto sslice = std::make_shared(input, - slice_begin, - slice_end, - slice_stride, - begin_mask, - end_mask, - new_axis_mask, - shrink_axis_mask, - ellipsis_mask); - sslice->set_friendly_name("strided_slice"); - - model = std::make_shared(ov::NodeVector{sslice}, ov::ParameterVector{input}); - manager.register_pass(); - } - - { - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 2, 384, 640}); - - std::vector axes = {0, 1, 2, 3}; - std::vector dim = {1, 1, 384, 640}; - std::vector offset = {0, 1, 0, 0}; - - auto crop = std::make_shared(input, axes, dim, offset); - crop->set_friendly_name("strided_slice/Crop"); - - auto reshape = ov::op::util::reshapeTo(crop, {1, 384, 640}); - reshape->set_friendly_name("strided_slice"); - - model_ref = std::make_shared(ov::NodeVector{reshape}, ov::ParameterVector{input}); - } -} - -TEST_F(TransformationTestsF, ConvertStridedSliceToCropNegative) { - { - auto input = std::make_shared(ov::element::f32, ov::PartialShape::dynamic(4)); - auto slice_begin = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {0, 1, 0, 0}); - auto slice_end = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 0, 0}); - auto slice_stride = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {1, 1, 1, 1}); - - std::vector begin_mask = {1, 0, 1, 1}; - std::vector end_mask = {1, 0, 1, 1}; - std::vector new_axis_mask = {0, 0, 0, 0}; - std::vector shrink_axis_mask = {0, 1, 0, 0}; - std::vector ellipsis_mask = {0, 0, 0, 0}; - - auto sslice = std::make_shared(input, - slice_begin, - slice_end, - slice_stride, - begin_mask, - end_mask, - new_axis_mask, - shrink_axis_mask, - ellipsis_mask); - sslice->set_friendly_name("strided_slice"); - - model = std::make_shared(ov::NodeVector{sslice}, ov::ParameterVector{input}); - manager.register_pass(); - } - - { - auto input = std::make_shared(ov::element::f32, ov::PartialShape::dynamic(4)); - auto slice_begin = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {0, 1, 0, 0}); - auto slice_end = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 0, 0}); - auto slice_stride = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {1, 1, 1, 1}); - - std::vector begin_mask = {1, 0, 1, 1}; - std::vector end_mask = {1, 0, 1, 1}; - std::vector new_axis_mask = {0, 0, 0, 0}; - std::vector shrink_axis_mask = {0, 1, 0, 0}; - std::vector ellipsis_mask = {0, 0, 0, 0}; - - auto sslice = std::make_shared(input, - slice_begin, - slice_end, - slice_stride, - begin_mask, - end_mask, - new_axis_mask, - shrink_axis_mask, - ellipsis_mask); - sslice->set_friendly_name("strided_slice"); - - model_ref = std::make_shared(ov::NodeVector{sslice}, ov::ParameterVector{input}); - } -} - -TEST_F(TransformationTestsF, ConvertStridedSliceToCropNoneZeroBeginValuesWithMask) { - // when begin_mask/end_mask are present begin/end values should not affect output shape - { - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 2, 4}); - auto slice_begin = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {0, 3, 2, 1}); - auto slice_end = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {0, 0, 0, 2}); - auto slice_stride = ov::opset1::Constant::create(ov::element::i64, ov::Shape{4}, {1, 1, 1, 1}); - - std::vector begin_mask = {1, 0, 1, 1}; - std::vector end_mask = {1, 0, 1, 0}; - std::vector new_axis_mask = {0, 1, 0, 0}; - std::vector shrink_axis_mask = {0, 0, 0, 0}; - std::vector ellipsis_mask = {0, 0, 0, 0}; - - auto sslice = std::make_shared(input, - slice_begin, - slice_end, - slice_stride, - begin_mask, - end_mask, - new_axis_mask, - shrink_axis_mask, - ellipsis_mask); - sslice->set_friendly_name("strided_slice"); - - model = std::make_shared(ov::NodeVector{sslice}, ov::ParameterVector{input}); - manager.register_pass(); - } - - { - auto input = std::make_shared(ov::element::f32, ov::Shape{1, 2, 4}); - - std::vector axes = {0, 1, 2, 3}; - std::vector dim = {1, 1, 2, 2}; - std::vector offset = {0, 0, 0, 0}; - - auto reshape = ov::op::util::reshapeTo(input, {1, 1, 2, 4}); - reshape->set_friendly_name("strided_slice/Reshape_for_Crop"); - - auto crop = std::make_shared(reshape, axes, dim, offset); - crop->set_friendly_name("strided_slice"); - - model_ref = std::make_shared(ov::NodeVector{crop}, ov::ParameterVector{input}); - } -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_tile_to_legacy.cpp b/src/plugins/intel_gna/legacy/tests/convert_tile_to_legacy.cpp deleted file mode 100644 index ef388748261..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_tile_to_legacy.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" - -using namespace testing; -using namespace ov; - -TEST(TransformationTests, ConvertTileToLegacyDynamic1) { - auto data = std::make_shared(element::f32, PartialShape{1, Dimension::dynamic()}); - auto axes = opset1::Constant::create(element::i64, Shape{1}, {0}); - auto tile = std::make_shared(data, axes); - - auto f = std::make_shared(NodeVector{tile}, ParameterVector{data}); - pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - ASSERT_NO_THROW(manager.run_passes(f)); - ASSERT_NO_THROW(check_rt_info(f)); -} - -TEST(TransformationTests, ConvertTileToLegacyDynamic2) { - auto data = std::make_shared(element::f32, PartialShape::dynamic()); - auto axes = opset1::Constant::create(element::i64, Shape{1}, {0}); - auto tile = std::make_shared(data, axes); - - auto f = std::make_shared(NodeVector{tile}, ParameterVector{data}); - pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - ASSERT_NO_THROW(manager.run_passes(f)); - ASSERT_NO_THROW(check_rt_info(f)); -} diff --git a/src/plugins/intel_gna/legacy/tests/convert_topk_test.cpp b/src/plugins/intel_gna/legacy/tests/convert_topk_test.cpp deleted file mode 100644 index 1e52ba47638..00000000000 --- a/src/plugins/intel_gna/legacy/tests/convert_topk_test.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" - -using namespace testing; - -TEST_F(TransformationTestsF, ConvertTopKToTopKIEStatic) { - { - auto input = std::make_shared(ov::element::f32, ov::Shape{15, 20, 3}); - auto k = ov::opset1::Constant::create(ov::element::i64, ov::Shape{}, {10}); - auto topk = std::make_shared(input, k, 1, "min", "value", ov::element::i32); - // due to the 'compare_functions' limitation we will check only one output - model = std::make_shared(ov::OutputVector{topk->output(0)}, ov::ParameterVector{input}); - - manager.register_pass(); - manager.register_pass([](std::shared_ptr f) { - check_rt_info(f); - }); - manager.register_pass(); - } - - { - auto input = std::make_shared(ov::element::f32, ov::Shape{15, 20, 3}); - auto k = ov::opset1::Constant::create(ov::element::i64, ov::Shape{1}, {10}); - // auto unsqueezed_k = std::make_shared(k, - // ov::opset1::Constant::create(ov::element::i64, ov::Shape{1}, {0})); - auto topk = std::make_shared(input, - k, - 1, - ngraph::op::TopKMode::MIN, - ngraph::op::TopKSortType::SORT_VALUES); - // due to the 'compare_functions' limitation we will check only one output - model_ref = std::make_shared(ov::OutputVector{topk->output(0)}, ov::ParameterVector{input}); - } -} - -TEST_F(TransformationTestsF, ConvertTopKToTopKIEDynamic1) { - { - auto input = std::make_shared(ov::element::f32, ov::PartialShape{DYN, 20, 3}); - auto k = ov::opset1::Constant::create(ov::element::i64, ov::Shape{}, {10}); - auto topk = std::make_shared(input, k, 1, "min", "value", ov::element::i32); - // due to the 'compare_functions' limitation we will check only one output - model = std::make_shared(ov::OutputVector{topk->output(0)}, ov::ParameterVector{input}); - manager.register_pass(); - manager.register_pass(); - } - - { - auto input = std::make_shared(ov::element::f32, ov::PartialShape{DYN, 20, 3}); - auto k = ov::opset1::Constant::create(ov::element::i64, ov::Shape{1}, {10}); - // auto unsqueezed_k = std::make_shared(k, - // ov::opset1::Constant::create(ov::element::i64, ov::Shape{1}, {0})); - auto topk = std::make_shared(input, - k, - 1, - ngraph::op::TopKMode::MIN, - ngraph::op::TopKSortType::SORT_VALUES); - // due to the 'compare_functions' limitation we will check only one output - model_ref = std::make_shared(ov::OutputVector{topk->output(0)}, ov::ParameterVector{input}); - } -} - -TEST_F(TransformationTestsF, ConvertTopKToTopKIEDynamic2) { - { - auto input = std::make_shared(ov::element::f32, ov::PartialShape{1, DYN, 3}); - auto k = ov::opset1::Constant::create(ov::element::i64, ov::Shape{}, {10}); - auto topk = std::make_shared(input, k, 1, "min", "value", ov::element::i32); - // due to the 'compare_functions' limitation we will check only one output - model = std::make_shared(ov::OutputVector{topk->output(0)}, ov::ParameterVector{input}); - manager.register_pass(); - manager.register_pass(); - } - - { - auto input = std::make_shared(ov::element::f32, ov::PartialShape{1, DYN, 3}); - auto k = ov::opset1::Constant::create(ov::element::i64, ov::Shape{1}, {10}); - // auto unsqueezed_k = std::make_shared(k, - // ov::opset1::Constant::create(ov::element::i64, ov::Shape{1}, {0})); - auto topk = std::make_shared(input, - k, - 1, - ngraph::op::TopKMode::MIN, - ngraph::op::TopKSortType::SORT_VALUES); - // due to the 'compare_functions' limitation we will check only one output - model_ref = std::make_shared(ov::OutputVector{topk->output(0)}, ov::ParameterVector{input}); - } -} - -TEST_F(TransformationTestsF, ConvertTopKToTopKIEDynamic3) { - { - auto input = std::make_shared(ov::element::f32, ov::PartialShape{1, 20, DYN}); - auto k = ov::opset1::Constant::create(ov::element::i64, ov::Shape{}, {10}); - auto topk = std::make_shared(input, k, 1, "min", "value", ov::element::i32); - // due to the 'compare_functions' limitation we will check only one output - model = std::make_shared(ov::OutputVector{topk->output(0)}, ov::ParameterVector{input}); - manager.register_pass(); - manager.register_pass(); - } - - { - auto input = std::make_shared(ov::element::f32, ov::PartialShape{1, 20, DYN}); - auto k = ov::opset1::Constant::create(ov::element::i64, ov::Shape{1}, {10}); - // auto unsqueezed_k = std::make_shared(k, - // ov::opset1::Constant::create(ov::element::i64, ov::Shape{1}, {0})); - auto topk = std::make_shared(input, - k, - 1, - ngraph::op::TopKMode::MIN, - ngraph::op::TopKSortType::SORT_VALUES); - // due to the 'compare_functions' limitation we will check only one output - model_ref = std::make_shared(ov::OutputVector{topk->output(0)}, ov::ParameterVector{input}); - } -} - -TEST_F(TransformationTestsF, ConvertTopKToTopKIENegative) { - { - auto input = std::make_shared(ov::element::f32, ov::Shape{15, 20, 3}); - auto k = std::make_shared(ov::element::i32, ov::PartialShape::dynamic()); - auto topk = std::make_shared(input, k, 1, "min", "value", ov::element::i32); - // due to the 'compare_functions' limitation we will check only one output - model = std::make_shared(ov::OutputVector{topk->output(0)}, ov::ParameterVector{input, k}); - manager.register_pass(); - manager.register_pass(); - } - - { - auto input = std::make_shared(ov::element::f32, ov::Shape{15, 20, 3}); - auto k = std::make_shared(ov::element::i32, ov::PartialShape::dynamic()); - auto topk = std::make_shared(input, k, 1, "min", "value", ov::element::i32); - // due to the 'compare_functions' limitation we will check only one output - model_ref = std::make_shared(ov::OutputVector{topk->output(0)}, ov::ParameterVector{input, k}); - } -} diff --git a/src/plugins/intel_gna/legacy/tests/fc_bias_fusion_test.cpp b/src/plugins/intel_gna/legacy/tests/fc_bias_fusion_test.cpp deleted file mode 100644 index edb49a7ea8f..00000000000 --- a/src/plugins/intel_gna/legacy/tests/fc_bias_fusion_test.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "common_test_utils/test_common.hpp" - -using namespace testing; - -TEST_F(TransformationTestsF, FullyConnectedBiasFusionTest3D) { - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{1, 128, 3072}); - auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786, 3072}, {1}); - auto empty_bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786}, {0}); - auto fc = std::make_shared(input1, weights, empty_bias, ov::Shape{1, 128, 786}); - - auto const_bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786}, {1}); - auto add = std::make_shared(fc, const_bias); - - model = std::make_shared(ov::NodeVector{add}, ov::ParameterVector{input1}); - - manager.register_pass(); - manager.register_pass([](std::shared_ptr f) { - check_rt_info(f); - }); - manager.register_pass(); - } - - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{1, 128, 3072}); - auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786, 3072}, {1}); - auto bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786}, {1}); - auto fc = std::make_shared(input1, weights, bias, ov::Shape{1, 128, 786}); - - model_ref = std::make_shared(ov::NodeVector{fc}, ov::ParameterVector{input1}); - } -} - -TEST_F(TransformationTestsF, FullyConnectedBiasFusionTest2D) { - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{1, 128}); - auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786, 128}, {1}); - auto empty_bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786}, {0}); - auto fc = std::make_shared(input1, weights, empty_bias, ov::Shape{1, 786}); - - auto const_bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 786}, {1}); - auto add = std::make_shared(fc, const_bias); - - model = std::make_shared(ov::NodeVector{add}, ov::ParameterVector{input1}); - manager.register_pass(); - manager.register_pass([](std::shared_ptr f) { - check_rt_info(f); - }); - manager.register_pass(); - } - - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{1, 128}); - auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786, 128}, {1}); - auto empty_bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786}, {0}); - auto fc = std::make_shared(input1, weights, empty_bias, ov::Shape{1, 786}); - - model_ref = std::make_shared(ov::NodeVector{fc}, ov::ParameterVector{input1}); - } -} - -TEST_F(TransformationTestsF, FullyConnectedBiasFusionTestBias1x1) { - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{1, 128}); - - auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786, 128}, {1}); - auto empty_bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786}, {0}); - auto fc = std::make_shared(input1, weights, empty_bias, ov::Shape{1, 786}); - - auto const_bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1}, {1}); - auto add = std::make_shared(fc, const_bias); - - model = std::make_shared(ov::NodeVector{add}, ov::ParameterVector{input1}); - - manager.register_pass(); - manager.register_pass([](std::shared_ptr function) { - check_rt_info(function); - }); - manager.register_pass(); - } - - { - auto input1 = std::make_shared(ov::element::f32, ov::Shape{1, 128}); - auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786, 128}, {1}); - auto bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786}, {1}); - auto fc = std::make_shared(input1, weights, bias, ov::Shape{1, 786}); - - model_ref = std::make_shared(ov::NodeVector{fc}, ov::ParameterVector{input1}); - } -} - -TEST(TransformationTests, FullyConnectedBiasFusionDynamic) { - auto input1 = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); - auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786, 128}, {1}); - auto empty_bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786}, {0}); - auto fc = std::make_shared(input1, weights, empty_bias, ov::Shape{1, 786}); - - auto const_bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 786}, {1}); - auto add = std::make_shared(fc, const_bias); - - auto f = std::make_shared(ov::NodeVector{add}, ov::ParameterVector{input1}); - ov::pass::Manager manager; - manager.register_pass(); - ASSERT_NO_THROW(manager.run_passes(f)); -} diff --git a/src/plugins/intel_gna/legacy/tests/keep_constant_inputs_tests.cpp b/src/plugins/intel_gna/legacy/tests/keep_constant_inputs_tests.cpp deleted file mode 100644 index e8c1852eb0c..00000000000 --- a/src/plugins/intel_gna/legacy/tests/keep_constant_inputs_tests.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include - -#include -#include -#include // deprecated API -#include -#include // deprecated API -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/subgraph_builders/conv_bias.hpp" -#include "common_test_utils/subgraph_builders/conv_pool_relu.hpp" -#include "ov_models/subgraph_builders.hpp" -#include "shared_test_classes/base/low_precision_transformations/layer_transformation.hpp" - -using namespace testing; -using namespace InferenceEngine; - -int numberOfInputsForLayerInCNNNetwork(const InferenceEngine::CNNNetwork& network, std::string layerType) { - int numberOfInputs = 0; - - IE_SUPPRESS_DEPRECATED_START - for (auto it = details::CNNNetworkIterator(network); it != details::CNNNetworkIterator(); it++) { - InferenceEngine::CNNLayerPtr layer = *it; - if (layer->type == layerType) { - numberOfInputs = (int)layer->insData.size(); - break; - } - } - IE_SUPPRESS_DEPRECATED_END - return numberOfInputs; -} - -void transformNetwork(InferenceEngine::CNNNetwork& clonedNetwork, bool keep_constant_inputs) { - if (clonedNetwork.getFunction()) { - auto nGraphFunc = clonedNetwork.getFunction(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.run_passes(nGraphFunc); - IE_SUPPRESS_DEPRECATED_START - clonedNetwork = InferenceEngine::CNNNetwork( - InferenceEngine::details::convertFunctionToICNNNetwork(nGraphFunc, clonedNetwork, keep_constant_inputs)); - IE_SUPPRESS_DEPRECATED_END - } -} - -TEST(KeepConstantInputsTests, ConvertConvolutionPoolReluNetworkWithTrue) { - std::shared_ptr f_ptr; - f_ptr = ov::test::utils::make_conv_pool_relu(); - InferenceEngine::CNNNetwork network(f_ptr), originalNetwork = network; - transformNetwork(originalNetwork, true); - ASSERT_EQ(numberOfInputsForLayerInCNNNetwork(originalNetwork, "Convolution"), 2); -} - -TEST(KeepConstantInputsTests, ConvertConvolutionPoolReluNetworkWithFalse) { - std::shared_ptr f_ptr; - f_ptr = ov::test::utils::make_conv_pool_relu(); - InferenceEngine::CNNNetwork network(f_ptr), originalNetwork = network; - transformNetwork(originalNetwork, false); - ASSERT_EQ(numberOfInputsForLayerInCNNNetwork(originalNetwork, "Convolution"), 1); -} - -TEST(KeepConstantInputsTests, ConvertConvolutionBiasNetworkWithTrue) { - std::shared_ptr f_ptr; - f_ptr = ov::test::utils::make_conv_bias(); - InferenceEngine::CNNNetwork network(f_ptr), originalNetwork = network; - transformNetwork(originalNetwork, true); - ASSERT_EQ(numberOfInputsForLayerInCNNNetwork(originalNetwork, "Convolution"), 3); -} - -TEST(KeepConstantInputsTests, ConvertConvolutionBiasNetworkWithFalse) { - std::shared_ptr f_ptr; - f_ptr = ov::test::utils::make_conv_bias(); - InferenceEngine::CNNNetwork network(f_ptr), originalNetwork = network; - transformNetwork(originalNetwork, false); - ASSERT_EQ(numberOfInputsForLayerInCNNNetwork(originalNetwork, "Convolution"), 1); -} - -TEST(KeepConstantInputsTests, ConvertFullyConnectedNetworkWithTrue) { - std::shared_ptr f_ptr; - auto input1 = std::make_shared(ov::element::f32, ov::Shape{1, 128}); - auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786, 128}, {1}); - auto empty_bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786}, {0}); - auto fc = std::make_shared(input1, weights, empty_bias, ov::Shape{1, 786}); - f_ptr = std::make_shared(ov::NodeVector{fc}, ov::ParameterVector{input1}); - InferenceEngine::CNNNetwork network(f_ptr), originalNetwork = network; - transformNetwork(originalNetwork, true); - ASSERT_EQ(numberOfInputsForLayerInCNNNetwork(originalNetwork, "FullyConnected"), 3); -} - -TEST(KeepConstantInputsTests, ConvertFullyConnectedNetworkWithFalse) { - std::shared_ptr f_ptr; - auto input1 = std::make_shared(ov::element::f32, ov::Shape{1, 128}); - auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786, 128}, {1}); - auto empty_bias = ov::opset1::Constant::create(ov::element::f32, ov::Shape{786}, {0}); - auto fc = std::make_shared(input1, weights, empty_bias, ov::Shape{1, 786}); - f_ptr = std::make_shared(ov::NodeVector{fc}, ov::ParameterVector{input1}); - InferenceEngine::CNNNetwork network(f_ptr), originalNetwork = network; - transformNetwork(originalNetwork, false); - ASSERT_EQ(numberOfInputsForLayerInCNNNetwork(originalNetwork, "FullyConnected"), 1); -} diff --git a/src/plugins/intel_gna/legacy/tests/mul_add_conversion_test.cpp b/src/plugins/intel_gna/legacy/tests/mul_add_conversion_test.cpp deleted file mode 100644 index ba38b703807..00000000000 --- a/src/plugins/intel_gna/legacy/tests/mul_add_conversion_test.cpp +++ /dev/null @@ -1,329 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "common_test_utils/test_common.hpp" -#include "ov_lpt_models/common/builders.hpp" - -using namespace testing; - -using InputShape = ov::PartialShape; -struct ConstantParams { - ov::Shape shape; - float value; - bool skip; - ConstantParams() : skip(true) {} - ConstantParams(const ov::Shape& shape, float value) : shape(shape), value(value), skip(false) {} -}; -using MulConstant = ConstantParams; -using AddConstant = ConstantParams; -using IsDequantization = bool; -using RefFunction = std::function< - std::shared_ptr(const InputShape&, const MulConstant&, const AddConstant&, const IsDequantization&)>; - -class MulAddConversionTests - : public ov::test::TestsCommon, - public testing::WithParamInterface< - std::tuple, RefFunction>> { -public: - std::shared_ptr f, f_ref; - - void SetUp() override { - const auto& attrs = std::get<0>(GetParam()); - const auto& input_shape = std::get<0>(attrs); - const auto& mul_const = std::get<1>(attrs); - const auto& add_const = std::get<2>(attrs); - const auto& is_dequantization = std::get<3>(attrs); - const auto& get_ref_model = std::get<1>(GetParam()); - - f = get_initial_model(input_shape, mul_const, add_const, is_dequantization); - f_ref = get_ref_model(input_shape, mul_const, add_const, is_dequantization); - } - - static std::shared_ptr get_initial_model(const InputShape& input_shape, - const MulConstant& mul_const, - const AddConstant& add_const, - const IsDequantization& is_dequantization) { - auto input = std::make_shared(ov::element::f32, input_shape); - ov::Output last = input; - if (!mul_const.skip) { - last = std::make_shared(last, create_constant(mul_const.shape, mul_const.value)); - } - if (!add_const.skip) { - last = std::make_shared(last, create_constant(add_const.shape, add_const.value)); - } - last = std::make_shared(last); - return std::make_shared(ov::NodeVector{last.get_node_shared_ptr()}, ov::ParameterVector{input}); - } - - static std::shared_ptr get_scale_shift_reference(const InputShape& input_shape, - const MulConstant& mul_const, - const AddConstant& add_const, - const IsDequantization& is_dequanization) { - if (mul_const.skip && add_const.skip) { - OPENVINO_THROW("Invalid arguments"); - } - - auto input = std::make_shared(ov::element::f32, input_shape); - auto scsh = std::make_shared( - input, - (!mul_const.skip ? create_constant(mul_const.shape, mul_const.value) : create_constant(add_const.shape, 1)), - (!add_const.skip ? create_constant(add_const.shape, add_const.value) - : create_constant(mul_const.shape, 0))); - auto relu = std::make_shared(scsh); - return std::make_shared(ov::NodeVector{relu}, ov::ParameterVector{input}); - } - - static std::shared_ptr get_power_reference(const InputShape& input_shape, - const MulConstant& mul_const, - const AddConstant& add_const, - const IsDequantization& is_dequanization) { - auto input = std::make_shared(ov::element::f32, input_shape); - float scale(1), shift(0); - if (!mul_const.skip) - scale = mul_const.value; - if (!add_const.skip) - shift = add_const.value; - auto pow = std::make_shared(input, 1.f, scale, shift); - auto relu = std::make_shared(pow); - return std::make_shared(ov::NodeVector{relu}, ov::ParameterVector{input}); - } - - static std::shared_ptr get_eltwise_add_reference(const InputShape& input_shape, - const MulConstant& mul_const, - const AddConstant& add_const, - const IsDequantization& is_dequanization) { - auto input = std::make_shared(ov::element::f32, input_shape); - auto add = std::make_shared(input, - create_constant(add_const.shape, add_const.value), - ELTWISE_TYPE::Sum); - auto relu = std::make_shared(add); - return std::make_shared(ov::NodeVector{relu}, ov::ParameterVector{input}); - } - - static std::shared_ptr get_eltwise_mul_reference(const InputShape& input_shape, - const MulConstant& mul_const, - const AddConstant& add_const, - const IsDequantization& is_dequanization) { - auto input = std::make_shared(ov::element::f32, input_shape); - auto mul = std::make_shared(input, - create_constant(mul_const.shape, mul_const.value), - ELTWISE_TYPE::Prod); - auto relu = std::make_shared(mul); - return std::make_shared(ov::NodeVector{relu}, ov::ParameterVector{input}); - } - - static std::shared_ptr create_constant(const ov::Shape& shape, float init_value) { - return ov::opset1::Constant::create(ov::element::f32, shape, {init_value}); - } -}; - -class MulOrAddConversionTests : public MulAddConversionTests {}; - -TEST_P(MulAddConversionTests, CompareFunctions) { - auto unh = std::make_shared(); - - ov::pass::Manager manager; - manager.register_pass(unh); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(unh); - manager.register_pass([](std::shared_ptr f) { - check_rt_info(f); - }); - manager.register_pass(); - ASSERT_NO_THROW(manager.run_passes(f)); - f->validate_nodes_and_infer_types(); - - auto fc = - FunctionsComparator::no_default().enable(FunctionsComparator::NODES).enable(FunctionsComparator::PRECISIONS); - auto res = fc.compare(f, f_ref); - ASSERT_TRUE(res.valid) << res.message; -} - -TEST_P(MulOrAddConversionTests, CompareFunctions) { - auto unh = std::make_shared(); - - ov::pass::Manager manager; - manager.register_pass(unh); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(unh); - manager.register_pass([](std::shared_ptr f) { - check_rt_info(f); - }); - manager.register_pass(); - ASSERT_NO_THROW(manager.run_passes(f)); - - f->validate_nodes_and_infer_types(); - - auto fc = - FunctionsComparator::no_default().enable(FunctionsComparator::NODES).enable(FunctionsComparator::PRECISIONS); - auto res = fc.compare(f, f_ref); - ASSERT_TRUE(res.valid) << res.message; -} - -#define CONST(A, B) ConstantParams(A, B) -#define NONE ConstantParams() -#define SCALESHIFT MulAddConversionTests::get_scale_shift_reference -#define POWER MulAddConversionTests::get_power_reference -#define SAME MulAddConversionTests::get_initial_model -#define ELTWISE_SUM MulAddConversionTests::get_eltwise_add_reference -#define ELTWISE_PROD MulAddConversionTests::get_eltwise_mul_reference - -INSTANTIATE_TEST_SUITE_P(MulAddToScaleShift, - MulAddConversionTests, - testing::Combine(testing::Values(std::make_tuple(InputShape{DYN, 3, 64, 64}, - CONST(ov::Shape({1, 3, 1, 1}), 0.5), - CONST(ov::Shape({1, 3, 1, 1}), 0.5), - false), - std::make_tuple(InputShape{DYN, 3, DYN, 64}, - CONST(ov::Shape({1, 3, 1, 1}), 0.5), - CONST(ov::Shape({1, 3, 1, 1}), 0.5), - false), - std::make_tuple(InputShape{DYN, 3, DYN, DYN}, - CONST(ov::Shape({1, 3, 1, 1}), 0.5), - CONST(ov::Shape({1, 3, 1, 1}), 0.5), - false)), - testing::Values(SCALESHIFT))); - -INSTANTIATE_TEST_SUITE_P( - MulToScaleShift, - MulOrAddConversionTests, - testing::Combine( - testing::Values( - std::make_tuple(InputShape{DYN, 3, 64, 64}, CONST(ov::Shape({1, 3, 1, 1}), 0.5), NONE, false), - std::make_tuple(InputShape{DYN, 3, DYN, 64}, CONST(ov::Shape({1, 3, 1, 1}), 0.5), NONE, false), - std::make_tuple(InputShape{DYN, 3, DYN, DYN}, CONST(ov::Shape({1, 3, 1, 1}), 0.5), NONE, false)), - testing::Values(SCALESHIFT))); - -INSTANTIATE_TEST_SUITE_P( - AddToScaleShift, - MulOrAddConversionTests, - testing::Combine( - testing::Values( - std::make_tuple(InputShape{DYN, 3, 64, 64}, NONE, CONST(ov::Shape({1, 3, 1, 1}), 0.5), false), - std::make_tuple(InputShape{DYN, 3, DYN, 64}, NONE, CONST(ov::Shape({1, 3, 1, 1}), 0.5), false), - std::make_tuple(InputShape{DYN, 3, DYN, DYN}, NONE, CONST(ov::Shape({1, 3, 1, 1}), 0.5), false)), - testing::Values(SCALESHIFT))); - -INSTANTIATE_TEST_SUITE_P( - MulAddToPower, - MulAddConversionTests, - testing::Combine( - testing::Values( - std::make_tuple(InputShape{DYN, 3, 64, 64}, CONST(ov::Shape({1}), 0.5), CONST(ov::Shape({1}), 0.5), false), - std::make_tuple(InputShape{DYN, 3, DYN, 64}, CONST(ov::Shape({1}), 0.5), CONST(ov::Shape({1}), 0.5), false), - std::make_tuple(InputShape{DYN, 3, DYN, DYN}, - CONST(ov::Shape({1}), 0.5), - CONST(ov::Shape({1}), 0.5), - false)), - testing::Values(POWER))); - -INSTANTIATE_TEST_SUITE_P( - MulToPower, - MulOrAddConversionTests, - testing::Combine( - testing::Values(std::make_tuple(InputShape{DYN, 3, 64, 64}, CONST(ov::Shape({1}), 0.5), NONE, false), - std::make_tuple(InputShape{DYN, 3, DYN, 64}, CONST(ov::Shape({1}), 0.5), NONE, false), - std::make_tuple(InputShape{DYN, 3, DYN, DYN}, CONST(ov::Shape({1}), 0.5), NONE, false)), - testing::Values(POWER))); - -INSTANTIATE_TEST_SUITE_P( - AddToPower, - MulOrAddConversionTests, - testing::Combine( - testing::Values(std::make_tuple(InputShape{DYN, 3, 64, 64}, NONE, CONST(ov::Shape({1}), 0.5), false), - std::make_tuple(InputShape{DYN, 3, DYN, 64}, NONE, CONST(ov::Shape({1}), 0.5), false), - std::make_tuple(InputShape{DYN, 3, DYN, DYN}, NONE, CONST(ov::Shape({1}), 0.5), false)), - testing::Values(POWER))); - -INSTANTIATE_TEST_SUITE_P( - MulAddNegative, - MulAddConversionTests, - testing::Combine(testing::Values(std::make_tuple(InputShape{DYN, 3, DYN}, - CONST(ov::Shape({1, 1, 3, 1}), 0.5), - CONST(ov::Shape({3, 1}), 0.5) /*detect broadcast case*/, - false), - std::make_tuple(InputShape{DYN, 3, DYN}, - CONST(ov::Shape({3, 1}), 0.5), - CONST(ov::Shape({1, 1, 3, 1}), 0.5) /*detect broadcast case*/, - false), - std::make_tuple(InputShape{DYN, DYN, DYN, DYN}, - CONST(ov::Shape({1, 3, 1, 1}), 0.5), - CONST(ov::Shape({1, 3, 1, 1}), 0.5), - false), - std::make_tuple(InputShape{DYN, DYN, DYN, DYN}, - CONST(ov::Shape({1, 3, 2, 1}), 0.5), - CONST(ov::Shape({1, 3, 1, 1}), 0.5), - false), - std::make_tuple(InputShape{1, 3, 2}, - CONST(ov::Shape({1, 3, 1}), 0.5), - CONST(ov::Shape({1, 3, 2}), 0.5), - false), - std::make_tuple(InputShape{1, DYN, 64, 64}, - CONST(ov::Shape({1, 3, 1, 1}), 0.5), - CONST(ov::Shape({1, 3, 1, 1}), 0.5), - false)), - testing::Values(SAME))); - -INSTANTIATE_TEST_SUITE_P( - MulToEltwise, - MulOrAddConversionTests, - testing::Combine( - testing::Values( - std::make_tuple(InputShape{DYN, 3, 64}, CONST(ov::Shape({1, 1, 64}), 0.5), NONE, false), - std::make_tuple(InputShape{DYN, 3, DYN}, CONST(ov::Shape({1, 1, 3, 1}), 0.5), NONE, false), - std::make_tuple(InputShape{DYN, DYN, DYN, DYN}, CONST(ov::Shape({1, 3, 1, 1}), 0.5), NONE, false), - std::make_tuple(InputShape{DYN, 3, DYN, DYN}, CONST(ov::Shape({1, 3, 2, 1}), 0.5), NONE, false), - std::make_tuple(InputShape{1, 3, 2}, CONST(ov::Shape({1, 3, 2}), 0.5), NONE, false), - std::make_tuple(InputShape{1, DYN, 64, 64}, CONST(ov::Shape({1, 3, 1, 1}), 0.5), NONE, false), - std::make_tuple(InputShape{64, 1, 64}, CONST(ov::Shape({64, 64, 64}), 1), NONE, false), - std::make_tuple(InputShape{64, 64, 1}, CONST(ov::Shape({1, 1, 64}), 1), NONE, false), - std::make_tuple(InputShape{DYN, 1, 64}, CONST(ov::Shape({64, 1, 64}), 1), NONE, false), - std::make_tuple(InputShape{1, 1024, 768}, CONST(ov::Shape({768}), 0.5), NONE, true)), - testing::Values(ELTWISE_PROD))); - -INSTANTIATE_TEST_SUITE_P( - AddToEltwise, - MulOrAddConversionTests, - testing::Combine( - testing::Values( - std::make_tuple(InputShape{DYN, 3, 64}, NONE, CONST(ov::Shape({1, 1, 64}), 0.5), false), - std::make_tuple(InputShape{DYN, 3, DYN}, NONE, CONST(ov::Shape({1, 1, 3, 1}), 0.5), false), - std::make_tuple(InputShape{DYN, DYN, DYN, DYN}, NONE, CONST(ov::Shape({1, 3, 1, 1}), 0.5), false), - std::make_tuple(InputShape{DYN, 3, DYN, DYN}, NONE, CONST(ov::Shape({1, 3, 2, 1}), 0.5), false), - std::make_tuple(InputShape{1, 3, 2}, NONE, CONST(ov::Shape({1, 3, 2}), 0.5), false), - std::make_tuple(InputShape{1, DYN, 64, 64}, NONE, CONST(ov::Shape({1, 3, 1, 1}), 0.5), false), - std::make_tuple(InputShape{1, 1024, 768}, NONE, CONST(ov::Shape({768}), 0.5), true)), - testing::Values(ELTWISE_SUM))); - -#undef CONST -#undef SCALESHIFT -#undef POWER -#undef SAME -#undef ELTWISE_PROD -#undef ELTWISE_SUM diff --git a/src/plugins/intel_gna/legacy/tests/reshape_fc_fusion_test.cpp b/src/plugins/intel_gna/legacy/tests/reshape_fc_fusion_test.cpp deleted file mode 100644 index 0b7fc397e8f..00000000000 --- a/src/plugins/intel_gna/legacy/tests/reshape_fc_fusion_test.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "common_test_utils/test_common.hpp" - -using namespace testing; - -TEST(TransformationTests, ReshapeFCFusiuonTest1) { - std::shared_ptr f(nullptr); - { - auto input = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1, 3, 64, 64}, {1}); - auto reshape_shape = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {1, 3 * 64 * 64}); - auto fc_weights = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{6, 3 * 64 * 64}, {1}); - auto fc_biases = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{6}, {1}); - - auto reshape = std::make_shared(input, reshape_shape, true); - auto fc = std::make_shared(reshape, fc_weights, fc_biases, ov::Shape{1, 6}); - - f = std::make_shared(ov::NodeVector{fc}, ov::ParameterVector{}); - - auto unh = std::make_shared(); - ov::pass::Manager m; - m.register_pass(unh); - m.register_pass(); - m.register_pass(); - m.register_pass(unh); - m.run_passes(f); - ASSERT_NO_THROW(check_rt_info(f)); - } - ASSERT_EQ(f->get_ops().size(), 5); -} - -TEST(TransformationTests, ReshapeFCFusiuonTest2) { - std::shared_ptr f(nullptr); - { - auto input = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1, 3, 64, 64}, {1}); - auto reshape_shape = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {1, 3, 64, 64}); - auto fc_weights = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{6, 3 * 64 * 64}, {1}); - auto fc_biases = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{6}, {1}); - - auto reshape = std::make_shared(input, reshape_shape, true); - auto fc = std::make_shared(reshape, fc_weights, fc_biases, ov::Shape{1, 6}); - - f = std::make_shared(ov::NodeVector{fc}, ov::ParameterVector{}); - auto unh = std::make_shared(); - ov::pass::Manager m; - m.register_pass(unh); - m.register_pass(); - m.register_pass(); - m.register_pass(unh); - m.run_passes(f); - ASSERT_NO_THROW(check_rt_info(f)); - } - ASSERT_EQ(f->get_ops().size(), 5); -} - -TEST(TransformationTests, ReshapeFCFusiuonTest3) { - std::shared_ptr f(nullptr); - { - auto input = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{2, 3, 64, 64}, {1}); - auto reshape_shape = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {1, 2 * 3 * 64 * 64}); - auto fc_weights = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{6, 2 * 3 * 64 * 64}, {1}); - auto fc_biases = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{6}, {1}); - - auto reshape = std::make_shared(input, reshape_shape, true); - auto fc = std::make_shared(reshape, fc_weights, fc_biases, ov::Shape{2, 6}); - - f = std::make_shared(ov::NodeVector{fc}, ov::ParameterVector{}); - auto unh = std::make_shared(); - ov::pass::Manager m; - m.register_pass(unh); - m.register_pass(); - m.register_pass(); - m.register_pass(unh); - m.run_passes(f); - ASSERT_NO_THROW(check_rt_info(f)); - } - ASSERT_EQ(f->get_ops().size(), 7); -} - -TEST(TransformationTests, ReshapeFCFusiuonDynamic) { - auto input = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1, 3, 64, 64}, {1}); - auto reshape_shape = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {1, 3, 64, 64}); - auto fc_weights = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{6, 3 * 64 * 64}, {1}); - auto fc_biases = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{6}, {1}); - - auto reshape = std::make_shared(input, reshape_shape, true); - auto fc = std::make_shared(reshape, fc_weights, fc_biases, ov::Shape{1, 6}); - - auto f = std::make_shared(ov::NodeVector{fc}, ov::ParameterVector{}); - auto unh = std::make_shared(); - ov::pass::Manager m; - m.register_pass(unh); - m.register_pass(); - m.register_pass(); - m.register_pass(unh); - m.run_passes(f); - ASSERT_NO_THROW(check_rt_info(f)); -} diff --git a/src/plugins/intel_gna/src/backend/am_intel_dnn.cpp b/src/plugins/intel_gna/src/backend/am_intel_dnn.cpp deleted file mode 100644 index 43d3b7438e5..00000000000 --- a/src/plugins/intel_gna/src/backend/am_intel_dnn.cpp +++ /dev/null @@ -1,1881 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined __INTEL_COMPILER || defined _MSC_VER -# include -#else -# include -#endif - -#include -#include - -#include "backend/am_intel_dnn.hpp" -#include "backend/dnn_types.hpp" -#include "backend/gna_limitations.hpp" -#include "backend/gna_types.hpp" -#include "gna/gna_config.hpp" -#include "gna2_model_helper.hpp" -#include "layers/gna_convolution_layer.hpp" -#include "log/dump.hpp" -#include "log/log.hpp" -#include "memory/gna_memory.hpp" -#include "memory/gna_memory_util.hpp" - -/** - * whether to dump weights and biases - */ -#define DUMP_WB -/** - * in light mode only layer names are dumped - * @param filename - * @param number_type - * @return - */ -#define LIGHT_DUMP - -using ov::intel_gna::gna_convolution_layer::outputFromConv; -using ov::intel_gna::gna_convolution_layer::outputFromPooling; - -using namespace ov::intel_gna::limitations; - -namespace ov { -namespace intel_gna { -namespace backend { - -void AMIntelDNN::BeginNewWrite(uint32_t index) { - dump_write_index = index; -} - -void AMIntelDNN::Init(memory::GNAMemoryInterface* memoryInterface, - intel_dnn_number_type_t compute_precision, - float scale_factor) { - memory = memoryInterface; - compute_precision_ = compute_precision; - input_scale_factor_ = scale_factor; - - ptr_active_outputs_ = nullptr; - num_active_outputs_ = 0; -} - -AMIntelDNN::~AMIntelDNN() { - component.clear(); -} - -void AMIntelDNN::InitActiveList(uint32_t* ptr_active_list) { - ptr_active_outputs_ = ptr_active_list; - if (ptr_active_list == nullptr) { - if (component[component.size() - 1].orientation_out == kDnnInterleavedOrientation) { - num_active_outputs_ = component[component.size() - 1].num_rows_out; - } else { - num_active_outputs_ = component[component.size() - 1].num_columns_out; - } - } else { - num_active_outputs_ = 0; - } -} - -void AMIntelDNN::InitAffineComponentPrivate(intel_dnn_component_t& comp, - uint32_t num_rows_in, - uint32_t num_columns, - uint32_t num_rows_out, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - uint32_t num_bytes_per_weight, - uint32_t num_bytes_per_bias, - float weight_scale_factor, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - void*& ptr_weights, - void*& ptr_biases, - bool isDiag, - bool postInitMem) { - comp.num_rows_in = num_rows_in; - comp.num_columns_in = num_columns; - comp.num_rows_out = num_rows_out; - comp.num_columns_out = num_columns; - comp.num_bytes_per_input = num_bytes_per_input; - comp.num_bytes_per_output = num_bytes_per_output; - comp.operation = isDiag ? kDnnDiagonalOp : kDnnAffineOp; - comp.orientation_in = kDnnInterleavedOrientation; - comp.orientation_out = kDnnInterleavedOrientation; - comp.op.affine.num_bytes_per_weight = num_bytes_per_weight; - comp.op.affine.num_bytes_per_bias = num_bytes_per_bias; - comp.op.affine.weight_scale_factor = weight_scale_factor; - comp.output_scale_factor = output_scale_factor; - comp.input_scale_factor = output_scale_factor / weight_scale_factor; - if (!postInitMem) { - comp.op.affine.ptr_weights = ptr_weights; - comp.op.affine.ptr_biases = ptr_biases; - comp.ptr_inputs = ptr_inputs; - comp.ptr_outputs = ptr_outputs; - } else { - ptr_weights = &comp.op.affine.ptr_weights; - ptr_biases = &comp.op.affine.ptr_biases; - ptr_inputs = &comp.ptr_inputs; - ptr_outputs = &comp.ptr_outputs; - } -} - -void AMIntelDNN::InitConvolutional1DComponentPrivate(intel_dnn_component_t& comp, - uint32_t num_columns_in, - uint32_t num_columns_out, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - uint32_t num_bytes_per_weight, - uint32_t num_bytes_per_bias, - uint32_t num_filters, - uint32_t num_filter_coefficients, - const uint32_t convStride, - float weight_scale_factor, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - void*& ptr_filters, - void*& ptr_biases, - bool postInitMem) { - comp.num_rows_in = 1; - comp.num_columns_in = num_columns_in; - comp.num_rows_out = 1; - comp.num_columns_out = num_columns_out; - comp.num_bytes_per_input = num_bytes_per_input; - comp.num_bytes_per_output = num_bytes_per_output; - comp.operation = kDnnConvolutional1dOp; - comp.orientation_in = kDnnNonInterleavedOrientation; - comp.orientation_out = kDnnNonInterleavedOrientation; - comp.ptr_inputs = ptr_inputs; - comp.ptr_outputs = ptr_outputs; - comp.op.conv1D.num_bytes_per_weight = num_bytes_per_weight; - comp.op.conv1D.num_bytes_per_bias = num_bytes_per_bias; - comp.op.conv1D.num_filters = num_filters; - comp.op.conv1D.num_filter_coefficients = num_filter_coefficients; - comp.op.conv1D.convStride = convStride; - comp.op.conv1D.weight_scale_factor = weight_scale_factor; - comp.output_scale_factor = output_scale_factor; - comp.input_scale_factor = output_scale_factor / weight_scale_factor; - - if (!postInitMem) { - comp.op.conv1D.ptr_filters = ptr_filters; - comp.op.conv1D.ptr_biases = ptr_biases; - comp.ptr_inputs = ptr_inputs; - comp.ptr_outputs = ptr_outputs; - } else { - ptr_filters = &comp.op.conv1D.ptr_filters; - ptr_biases = &comp.op.conv1D.ptr_biases; - ptr_inputs = &comp.ptr_inputs; - ptr_outputs = &comp.ptr_outputs; - } - - if (num_columns_in % 8 != 0) { - THROW_GNA_EXCEPTION << "Number of inputs to Convolutional1DComponent (" << num_columns_in - << ") is not a multiply by 8"; - } - if (num_filters < Limitations::kConvMinFiltersNum || num_filters > Limitations::kConvMaxFiltersNum || - num_filters % Limitations::kConvFiltersNumDivider != 0) { - THROW_GNA_EXCEPTION << "Unsupported number of filters in Convolutional1DComponent: " << num_filters; - } - auto max_number_of_out_elements = outputFromConv(num_columns_in, num_filter_coefficients, convStride); - if (num_columns_out / max_number_of_out_elements != num_filters) { - THROW_GNA_EXCEPTION << "Number of outputs or feature map config is incorrect in Convolutional1DComponent"; - } -} - -void AMIntelDNN::InitConvolutional2DComponentPrivate(intel_dnn_component_t& comp, - OvGnaTensor inputTensor, - OvGnaTensor outputTensor, - OvGnaTensor filterTensor, - OvGnaTensor biasTensor, - std::array convStride, - std::array zeroPadding, - float weight_scale_factor, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - void*& ptr_filters, - void*& ptr_biases) { - comp.tensors.clear(); - comp.tensors.push_back(inputTensor); - comp.tensors.push_back(outputTensor); - comp.tensors.push_back(filterTensor); - comp.tensors.push_back(biasTensor); - comp.operation = kDnnConvolutional2dOp; - comp.orientation_in = kDnnNonInterleavedOrientation; - comp.orientation_out = kDnnNonInterleavedOrientation; - comp.ptr_inputs = ptr_inputs; - comp.ptr_outputs = ptr_outputs; - comp.op.conv2D.convStride = convStride; - comp.op.conv2D.zeroPadding = zeroPadding; - comp.op.conv2D.weight_scale_factor = weight_scale_factor; - comp.output_scale_factor = output_scale_factor; - comp.input_scale_factor = output_scale_factor / weight_scale_factor; - - ptr_filters = &comp.op.conv2D.ptr_filters; - ptr_biases = &comp.op.conv2D.ptr_biases; - ptr_inputs = &comp.ptr_inputs; - ptr_outputs = &comp.ptr_outputs; -} - -bool AMIntelDNN::isOperationCnnLegacySpecific(const Gna2Operation& op) { - // GNA compile target GNA_TARGET_3_0 does not support pooling window < pooling stride - return op.Type == Gna2OperationTypeConvolution && - op.NumberOfParameters > std::max(PoolStrideParamIdx, PoolWinParamIdx) && - op.Parameters[PoolStrideParamIdx] != nullptr && op.Parameters[PoolWinParamIdx] != nullptr && - static_cast(op.Parameters[PoolStrideParamIdx])->NumberOfDimensions == 1 && - static_cast(op.Parameters[PoolStrideParamIdx])->Dimensions[0] > - static_cast(op.Parameters[PoolWinParamIdx])->Dimensions[0]; -} - -void AMIntelDNN::updateNumberOfOutputsIfPoolingEnabled(Gna2Model& gnaModel, bool useLegacyFormula) { - IE_ASSERT(gnaModel.Operations != nullptr || gnaModel.NumberOfOperations == 0); - for (uint32_t i = 0; i < gnaModel.NumberOfOperations; i++) { - auto& gnaOp = gnaModel.Operations[i]; - IE_ASSERT(gnaOp.Operands != nullptr); - IE_ASSERT(gnaOp.Operands[InOpIdx] != nullptr); - auto& inputShape = gnaOp.Operands[InOpIdx]->Shape; - IE_ASSERT(gnaOp.Parameters != nullptr || gnaOp.NumberOfParameters == 0); - if (gnaOp.Type == Gna2OperationTypeConvolution && inputShape.NumberOfDimensions == 2 && - gnaOp.NumberOfParameters >= PoolStrideParamIdx && gnaOp.Parameters != nullptr && - gnaOp.Parameters[PoolWinParamIdx] != nullptr && gnaOp.Parameters[PoolStrideParamIdx] != nullptr) { - IE_ASSERT(gnaOp.Operands[OutOpIdx] != nullptr); - IE_ASSERT(gnaOp.Operands[FilterOpIdx] != nullptr); - IE_ASSERT(gnaOp.Parameters[ConvStrideParamIdx] != nullptr); - - const auto& fltStrideShape = *reinterpret_cast(gnaOp.Parameters[ConvStrideParamIdx]); - const auto fltStride = fltStrideShape.Dimensions[0]; - const auto inVecCnt = inputShape.Dimensions[1]; - const auto nFltSize = gnaOp.Operands[FilterOpIdx]->Shape.Dimensions[1]; - const auto outFromConv = gna_convolution_layer::outputFromConv(inVecCnt, nFltSize, fltStride); - const auto& poolWindow = *static_cast(gnaOp.Parameters[PoolWinParamIdx]); - const auto& poolStride = *static_cast(gnaOp.Parameters[PoolStrideParamIdx]); - const auto numberOfOutputs = - gna_convolution_layer::outputFromPooling(outFromConv, - poolWindow.Dimensions[0], - poolStride.Dimensions[0], - useLegacyFormula || isOperationCnnLegacySpecific(gnaOp)); - auto& outputTensor = *gnaOp.Operands[OutOpIdx]; - const_cast(outputTensor.Shape.Dimensions[1]) = numberOfOutputs; - } - } -} - -void AMIntelDNN::InitMaxpoolComponentPrivate(intel_dnn_component_t& comp, - std::array inCHW, - std::array outCHW, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - std::array poolingWindowXY, - std::array poolingStrideXY, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - bool postInitMem) { - comp.num_bytes_per_input = num_bytes_per_input; - comp.num_bytes_per_output = num_bytes_per_output; - comp.operation = kDnnMaxPoolOp; - comp.orientation_in = kDnnNonInterleavedOrientation; - comp.orientation_out = kDnnNonInterleavedOrientation; - comp.op.maxpool.inCHW = inCHW; - comp.op.maxpool.outCHW = outCHW; - comp.op.maxpool.poolingWindowXY = poolingWindowXY; - comp.op.maxpool.poolingStrideXY = poolingStrideXY; - comp.output_scale_factor = output_scale_factor; - comp.input_scale_factor = output_scale_factor; - if (!postInitMem) { - comp.ptr_inputs = ptr_inputs; - comp.ptr_outputs = ptr_outputs; - } else { - ptr_inputs = &comp.ptr_inputs; - ptr_outputs = &comp.ptr_outputs; - } -} - -void AMIntelDNN::InitCopyComponentPrivate(intel_dnn_component_t& comp, - intel_dnn_orientation_t orientation, - uint32_t num_rows_in, - uint32_t num_columns_in, - uint32_t num_rows_out, - uint32_t num_columns_out, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - float output_scale_factor, - uint32_t num_copy_rows, - uint32_t num_copy_columns, - void*& ptr_inputs, - void*& ptr_outputs, - bool postInitMem) { - comp.num_rows_in = num_rows_in; - comp.num_columns_in = num_columns_in; - comp.num_rows_out = num_rows_out; - comp.num_columns_out = num_columns_out; - comp.num_bytes_per_input = num_bytes_per_input; - comp.num_bytes_per_output = num_bytes_per_output; - comp.operation = kDnnCopyOp; - comp.orientation_in = orientation; - comp.orientation_out = orientation; - comp.ptr_inputs = ptr_inputs; - comp.ptr_outputs = ptr_outputs; - comp.output_scale_factor = output_scale_factor; - comp.input_scale_factor = output_scale_factor; - comp.op.copy.num_copy_rows = num_copy_rows; - comp.op.copy.num_copy_columns = num_copy_columns; - - if (!postInitMem) { - comp.ptr_inputs = ptr_inputs; - comp.ptr_outputs = ptr_outputs; - } else { - ptr_inputs = &comp.ptr_inputs; - ptr_outputs = &comp.ptr_outputs; - } -} - -void AMIntelDNN::InitPiecewiseLinearComponentPrivate(intel_dnn_component_t& comp, - const DnnActivation& function_id, - intel_dnn_orientation_t orientation, - uint32_t num_rows, - uint32_t num_columns, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - uint32_t num_segments, - float output_scale_factor, - float input_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - gna_pwl_segment_t* ptr_segments, - bool postInitMem) { - comp.num_rows_in = num_rows; - comp.num_columns_in = num_columns; - comp.num_rows_out = num_rows; - comp.num_columns_out = num_columns; - comp.num_bytes_per_input = num_bytes_per_input; - comp.num_bytes_per_output = num_bytes_per_output; - comp.operation = kDnnPiecewiselinearOp; - comp.orientation_in = orientation; - comp.orientation_out = orientation; - comp.op.pwl.func_id = function_id; - comp.op.pwl.num_segments = num_segments; - comp.output_scale_factor = output_scale_factor; - comp.input_scale_factor = input_scale_factor; - - if (!postInitMem) { - comp.ptr_inputs = ptr_inputs; - comp.ptr_outputs = ptr_outputs; - comp.op.pwl.ptr_segments = ptr_segments; - } else { - ptr_inputs = &comp.ptr_inputs; - ptr_outputs = &comp.ptr_outputs; - if (ptr_segments != nullptr) { - *reinterpret_cast(ptr_segments) = - reinterpret_cast(&comp.op.pwl.ptr_segments); - } - } -} - -void AMIntelDNN::InitInterleaveComponentPrivate(intel_dnn_component_t& comp, - uint32_t num_rows_in, - uint32_t num_columns_in, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - bool postInitMem) { - comp.num_rows_in = num_rows_in; - comp.num_columns_in = num_columns_in; - comp.num_rows_out = num_columns_in; - comp.num_columns_out = num_rows_in; - comp.num_bytes_per_input = num_bytes_per_input; - comp.num_bytes_per_output = num_bytes_per_output; - comp.operation = kDnnInterleaveOp; - comp.orientation_in = kDnnNonInterleavedOrientation; - comp.orientation_out = kDnnInterleavedOrientation; - comp.output_scale_factor = output_scale_factor; - comp.input_scale_factor = output_scale_factor; - if (!postInitMem) { - comp.ptr_inputs = ptr_inputs; - comp.ptr_outputs = ptr_outputs; - } else { - ptr_inputs = &comp.ptr_inputs; - ptr_outputs = &comp.ptr_outputs; - } -} - -void AMIntelDNN::InitDeinterleaveComponentPrivate(intel_dnn_component_t& comp, - uint32_t num_rows_in, - uint32_t num_columns_in, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - bool postInitMem) { - comp.num_rows_in = num_rows_in; - comp.num_columns_in = num_columns_in; - comp.num_rows_out = num_columns_in; - comp.num_columns_out = num_rows_in; - comp.num_bytes_per_input = num_bytes_per_input; - comp.num_bytes_per_output = num_bytes_per_output; - comp.operation = kDnnDeinterleaveOp; - comp.orientation_in = kDnnInterleavedOrientation; - comp.orientation_out = kDnnInterleavedOrientation; - comp.output_scale_factor = output_scale_factor; - comp.input_scale_factor = output_scale_factor; - if (!postInitMem) { - comp.ptr_inputs = ptr_inputs; - comp.ptr_outputs = ptr_outputs; - } else { - ptr_inputs = &comp.ptr_inputs; - ptr_outputs = &comp.ptr_outputs; - } -} - -float AMIntelDNN::OutputScaleFactor(intel_dnn_component_t& comp) { - return comp.output_scale_factor; -} - -struct InputEndPoint { - int idx = 0; - size_t size = 0; - size_t num_bytes_per_output = 1; - InputEndPoint() = default; - InputEndPoint(int nidx, size_t sz, size_t esize) : idx(nidx), size(sz), num_bytes_per_output(esize) {} -}; - -void AMIntelDNN::WriteGraphWizModel(const char* filename) { - auto& components = component; - -#define IS_AFFINE(k) (components[k].operation == kDnnAffineOp || components[k].operation == kDnnDiagonalOp) - -#define IS_CONV_1D(k) (components[k].operation == kDnnConvolutional1dOp) - -#define IS_RELU(k) (components[k].operation == kDnnPiecewiselinearOp && components[k].op.pwl.func_id == kActRelu) - -#define IS_DIAG(k) (components[k].operation == kDnnDiagonalOp) - -#define IS_POW(k) (components[k].operation == kDnnPiecewiselinearOp && components[k].op.pwl.func_id == kActPow) - -#define OUTPUTS(idx) \ - components[idx].ptr_outputs, \ - components[idx].num_rows_out* components[idx].num_columns_out* components[idx].num_bytes_per_output - -#define INPUTS(idx) \ - components[idx].ptr_inputs, \ - components[idx].num_rows_in* components[idx].num_columns_in* components[idx].num_bytes_per_input - -#define BIASES(idx) \ - components[idx].op.affine.ptr_biases, \ - components[idx].num_rows_in* components[idx].num_columns_in* components[idx].op.affine.num_bytes_per_bias - -#define WEIGHTS(idx) \ - components[idx].op.affine.ptr_weights, \ - components[idx].op.affine.num_bytes_per_weight* components[idx].num_rows_in* components[idx].num_columns_in*( \ - IS_DIAG(idx) ? 1 : components[idx].num_rows_out * components[idx].num_columns_out) - - auto intersected = [](void* ptra, size_t asize, void* ptrb, size_t bsize) { - return !(((reinterpret_cast(ptra) + asize) <= ptrb) || - ((reinterpret_cast(ptrb) + bsize) <= ptra)); - }; - - auto equals = [](void* ptra, size_t asize, void* ptrb, size_t bsize) { - // return !((((char*)ptra + asize) < ptrb) || (((char*)ptrb + bsize) < ptra)); - return ptra >= ptrb && ptra < reinterpret_cast(ptrb) + bsize; - }; - - auto startPtr = [](void* ptr, size_t size) { - return reinterpret_cast(ptr); - }; - auto endPtr = [](void* ptr, size_t size) { - return reinterpret_cast(ptr) + size; - }; - auto sizeofTensor = [](void* ptr, size_t size) { - return size; - }; - - std::fstream graph(filename, std::ios::out); - graph << "strict digraph {"; - std::set weights; - std::set biases; - std::map outputs; - std::set layersNames; - - auto generate_layer_name = [&](size_t k) { - std::string l; - if (components[k].operation == kDnnPiecewiselinearOp) { - l += intel_dnn_activation_name[components[k].op.pwl.func_id]; - } else { - l += intel_dnn_operation_name[components[k].operation]; - } - l += "_" + std::to_string(k); - if (components[k].operation == kDnnPiecewiselinearOp) { - graph << l << " [shape=box, style=filled, fillcolor=yellow"; - } else { - graph << l << " [shape=box"; - } - - graph << ", label=<\n" - " \n"; - - if (components[k].original_layer_name != nullptr) { - graph << " \n"; - } - graph << " \n"; - if (IS_AFFINE(k)) { - graph << " \n"; - graph << " \n"; - graph << " \n"; - - graph << " \n"; - graph << " \n"; - } - if (IS_RELU(k)) { - graph << " \n"; - } - if (IS_POW(k)) { - graph << " \n"; - graph << " \n"; - graph << " \n"; - } - if (IS_CONV_1D(k)) { - auto& conv = components[k].op.conv1D; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - } - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << "
" - << l << "
IR " << components[k].original_layer_name << "
dims" << components[k].num_rows_in << "x" << components[k].num_rows_out - << "
wscale" << components[k].op.affine.weight_scale_factor << "
wbit" << components[k].op.affine.num_bytes_per_weight << "
bbit" << components[k].op.affine.num_bytes_per_bias << "
wadr" << components[k].op.affine.ptr_weights << "
badr" << components[k].op.affine.ptr_biases << "
negative_slope" << components[k].op.pwl.func_id.args.lrelu.negative_slope - << "
exponent" << components[k].op.pwl.func_id.args.pow.exponent << "
scale" << components[k].op.pwl.func_id.args.pow.scale << "
offset" << components[k].op.pwl.func_id.args.pow.offset << "
num_filters" << conv.num_filters << "
num_filter_coefficients" << conv.num_filter_coefficients << "
conv_stride" << conv.convStride << "
wscale" << conv.weight_scale_factor << "
wbit" << conv.num_bytes_per_weight << "
bbit" << conv.num_bytes_per_bias << "
wadr" << components[k].op.conv1D.ptr_filters << "
badr" << components[k].op.conv1D.ptr_biases << "
iadr" << components[k].ptr_inputs << "
oadr" << components[k].ptr_outputs << "
num_rows_in" << components[k].num_rows_in << "
num_columns_in" << components[k].num_columns_in << "
num_rows_out" << components[k].num_rows_out << "
num_columns_out" << components[k].num_columns_out << "
oscale" << components[k].output_scale_factor << "
ibit" << components[k].num_bytes_per_input << "
obit" << components[k].num_bytes_per_output << "
>];\n"; - - return l; - }; - - for (size_t k = 0; k < components.size(); ++k) { - std::string l = generate_layer_name(k); - layersNames.insert(l); - int lidx = static_cast(std::distance(layersNames.begin(), layersNames.find(l))); - int widx = 0; - int bidx = 0; - - if (IS_AFFINE(k)) { - weights.insert(components[k].op.affine.ptr_weights); - biases.insert(components[k].op.affine.ptr_biases); - - widx = static_cast(std::distance(weights.begin(), weights.find(components[k].op.affine.ptr_weights))); - bidx = static_cast(std::distance(biases.begin(), biases.find(components[k].op.affine.ptr_biases))); - } - - auto lw = "weights_" + std::to_string(lidx) + "_" + std::to_string(widx); - ; - auto lb = "biases_" + std::to_string(lidx) + "_" + std::to_string(bidx); - - if (IS_AFFINE(k)) { - graph << lw << " -> " << l << "[style=bold];"; - graph << lb << " -> " << l << "[style=bold];"; - } - - graph << "\n"; - - bool inputConnected = false; - - for (size_t k2 = 0; k2 < components.size(); ++k2) { - if (k2 == k) - continue; - - std::string r = generate_layer_name(k2); - - int w2idx = 0; - int b2idx = 0; - - if (IS_AFFINE(k2)) { - weights.insert(components[k2].op.affine.ptr_weights); - biases.insert(components[k2].op.affine.ptr_biases); - - w2idx = static_cast( - std::distance(weights.begin(), weights.find(components[k2].op.affine.ptr_weights))); - b2idx = - static_cast(std::distance(biases.begin(), biases.find(components[k2].op.affine.ptr_biases))); - } - - auto rw = "weights_" + std::to_string(w2idx); - auto rb = "biases_" + std::to_string(b2idx); - - // ---------------------------------------------------------- - // output to input connections - if (intersected(OUTPUTS(k2), INPUTS(k))) { - graph << r << " -> " << l << ";"; - inputConnected = true; - } - - // ---------------------------------------------------------- - // output to biases connections - if (IS_AFFINE(k) && intersected(OUTPUTS(k2), BIASES(k))) { - graph << r << " -> " << lb << " [label=\"OB\", fontcolor=blue, color=blue, style=dashed];"; - } - - // ---------------------------------------------------------- - // output to weights connections - if (IS_AFFINE(k) && equals(OUTPUTS(k2), WEIGHTS(k))) { - graph << r << " -> " << lw << " [label=\"OW\", fontcolor=magenta, color=magenta, style=dashed];"; - } - - // ---------------------------------------------------------- - // weights to input connections - if (IS_AFFINE(k2) && equals(WEIGHTS(k2), INPUTS(k))) { - graph << rw << " -> " << l << " [label=\"WI\", fontcolor=red, color=red, style=dashed];"; - inputConnected = true; - } - - // ---------------------------------------------------------- - // weights to bias connections - if (IS_AFFINE(k2) && IS_AFFINE(k) && equals(WEIGHTS(k2), BIASES(k))) { - graph << rw << " -> " << lb << " [label=\"WB\", fontcolor=darkgreen,color=darkgreen, style=dashed];"; - } - } - if (!inputConnected) { - // searching for TMP connection - size_t tidx = std::numeric_limits::max(); - for (auto&& en : outputs) { - if (intersected(en.first, en.second.size, INPUTS(k))) { - tidx = en.second.idx; - auto updated_ptr = std::min(startPtr(en.first, en.second.size), startPtr(INPUTS(k))); - auto updated_size = std::max(endPtr(en.first, en.second.size), endPtr(INPUTS(k))) - updated_ptr; - outputs.erase(en.first); - outputs[updated_ptr] = - InputEndPoint(static_cast(tidx), updated_size, components[k].num_bytes_per_input); - break; - } - } - - if (tidx == std::numeric_limits::max()) { - outputs[components[k].ptr_inputs] = InputEndPoint(static_cast(outputs.size()), - sizeofTensor(INPUTS(k)), - components[k].num_bytes_per_input); - } - tidx = outputs[components[k].ptr_inputs].idx; - graph << "parameter_" << tidx << " -> " << l << " [fontcolor=darkgreen,color=orange, style=dashed];"; - } - } - - for (size_t k = 0; k < components.size(); ++k) { - std::string l = generate_layer_name(k); - - int tidx = 0; - for (const auto& tmpOutPtrs : outputs) { - if (components[k].ptr_outputs == tmpOutPtrs.first) { - graph << l << " -> " << tidx << " [label=\"TO_TMP\", fontcolor=darkgreen,color=orange, style=dashed];"; - } - tidx++; - } - } - - // writing inputs info - for (auto&& en : outputs) { - std::string l = "parameter_" + std::to_string(en.second.idx); - graph << l << " [shape=box, style=filled, fillcolor=\"#85C1E9\""; - graph << ", label=<\n" - " \n"; - graph << " \n"; - graph << " \n"; - graph << " \n"; - graph << "
" - << l << "
dims" << 1 << "x" << en.second.size / en.second.num_bytes_per_output - << "
obit" << en.second.num_bytes_per_output << "
ptr" << en.first << "
>];\n"; - } - - graph << "}"; -} - -template -void PrintTensors(std::ofstream& out, T tensors) { - size_t i = 0; - for (auto&& t : tensors) { - out << " " << OvGnaModeToString(t.mode) << "\n"; - out << " " << OvGnaTypeToString(t.type) << "\n"; - size_t j = 0; - for (auto&& d : t.dimensions) { - out << " " << std::dec << d << "\n"; - } - } -} - -void AMIntelDNN::PrintOffset(std::ofstream& out, const std::string& type, void* ptr) { - auto flags = out.flags(); - const auto queue = memory->getQueue(ptr); - std::string typeOfRegion = "UNKNOWN_QUEUE"; - auto offset = std::numeric_limits::max(); - if (queue != nullptr) { - typeOfRegion = memory::rRegionToStr(queue->regionType()); - offset = queue->getOffset(ptr).second; - } - out << " " << typeOfRegion << "\n"; - out << "<" << type << "_address> " - << "0x" << std::setfill('0') << std::setw(8) << std::hex << offset << "\n"; - out.flags(flags); -} - -void AMIntelDNN::WriteDnnText(const char* filename, intel_dnn_number_type_t logging_precision) { - if ((compute_precision_ == kDnnFloat) && (logging_precision == kDnnInt)) { - fprintf(stderr, "Error trying to write floating point DNN as integer in AMIntelDNN::WriteDnnText().\n"); - fprintf(stderr, " Please convert to integer first.\n"); - throw - 1; - } -#ifndef LIGHT_DUMP - std::ofstream out_file1(filename, std::ios::out); - std::ofstream& out_file = out_file1; -#else - std::ofstream out_file((std::string(filename) + ".light").c_str(), std::ios::out); -#endif - if (out_file.good()) { - uint32_t num_inputs = this->num_inputs(); - uint32_t num_outputs = this->num_outputs(); - uint32_t num_layers = num_gna_layers(); - uint32_t num_group = this->num_group_in(); - uint32_t layer = 0; - - out_file << "\n"; - out_file << " " << intel_dnn_number_type_name[logging_precision] << "\n"; - const auto& regionsMap = memory::GetAllRegionsToStrMap(); - for (const auto& regionPair : regionsMap) { - out_file << " " << std::dec << regionPair.second << "\n"; - out_file << " " << std::dec << memory->getRegionBytes(regionPair.first) << "\n"; - } - out_file << " " << std::dec << num_group << "\n"; - out_file << " " << std::dec << num_inputs << "\n"; - out_file << " " << std::dec << num_outputs << "\n"; - out_file << " " << std::dec << num_layers << "\n"; - for (uint32_t i = 0; i < component.size(); i++) { -#ifdef LIGHT_DUMP - std::stringstream out_file_name; - out_file_name << getDumpFolderName() << std::setfill('0') << std::setw(2) << i << "_" - << intel_dnn_operation_name[component[i].operation] << "-" << component[i].num_rows_in << "-" - << component[i].num_rows_out; - if (component[i].operation == kDnnPiecewiselinearOp) { - out_file_name << "-" << intel_dnn_activation_name[component[i].op.pwl.func_id.type]; - } - std::ofstream out_file((out_file_name.str() + ".txt").c_str(), std::ios::out); - if (!out_file) - return; -#endif - - uint32_t num_rows_in = component[i].num_rows_in; - uint32_t num_columns_in = component[i].num_columns_in; - uint32_t num_rows_out = component[i].num_rows_out; - uint32_t num_columns_out = component[i].num_columns_out; - uint32_t num_bytes_per_input = component[i].num_bytes_per_input; - uint32_t num_bytes_per_output = component[i].num_bytes_per_output; - if ((component[i].operation == kDnnAffineOp) || (component[i].operation == kDnnDiagonalOp) || - (component[i].operation == kDnnRecurrentOp) || (component[i].operation == kDnnConvolutional1dOp) || - (component[i].operation == kDnnInterleaveOp) || (component[i].operation == kDnnDeinterleaveOp) || - (component[i].operation == kDnnCopyOp)) { - out_file << " " << std::dec << layer << "\n"; - layer++; - } - out_file << " " << intel_dnn_operation_name[component[i].operation] << "\n"; - out_file << " " << std::dec << num_rows_in << "\n"; - out_file << " " << std::dec << num_columns_in << "\n"; - out_file << " " << std::dec << num_rows_out << "\n"; - out_file << " " << std::dec << num_columns_out << "\n"; - out_file << " " << std::dec - << (component[i].orientation_in == kDnnInterleavedOrientation ? "interleaved" : "deinterleaved") - << "\n"; - out_file << " " << std::dec - << (component[i].orientation_out == kDnnInterleavedOrientation ? "interleaved" : "deinterleaved") - << "\n"; - - if ((compute_precision_ == kDnnInt) && (logging_precision == kDnnFloat)) { - out_file << " " << std::dec << sizeof(float) << "\n"; - out_file << " " << std::dec << sizeof(float) << "\n"; - } else { - out_file << " " << std::dec << num_bytes_per_input << "\n"; - out_file << " " << std::dec << num_bytes_per_output << "\n"; - } - PrintOffset(out_file, "input", component[i].ptr_inputs); - PrintOffset(out_file, "output", component[i].ptr_outputs); - switch (component[i].operation) { - case kDnnAffineOp: - case kDnnDiagonalOp: { - uint32_t num_bytes_per_weight = component[i].op.affine.num_bytes_per_weight; - uint32_t num_bytes_per_bias = component[i].op.affine.num_bytes_per_bias; - float weight_scale_factor = component[i].op.affine.weight_scale_factor; - float output_scale_factor = component[i].output_scale_factor; -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - uint32_t num_weight_rows = (component[i].operation == kDnnDiagonalOp) ? 1 : num_rows_out; - uint32_t num_weight_columns = num_rows_in; -#endif - if ((compute_precision_ == kDnnInt) && (logging_precision == kDnnFloat)) { - out_file << " " << std::dec << 4 << "\n"; - out_file << " " << std::dec << 4 << "\n"; - } else { - out_file << " " << std::dec << num_bytes_per_weight << "\n"; - out_file << " " << std::dec << num_bytes_per_bias << "\n"; - } - if ((compute_precision_ == kDnnInt) && (logging_precision == kDnnFloat)) { - out_file << std::setprecision(12) << std::scientific << " " << 1.0 << "\n"; - out_file << std::setprecision(12) << std::scientific << " " << 1.0 << "\n"; - } else { - out_file << std::setprecision(12) << std::scientific << " " - << weight_scale_factor << "\n"; - out_file << std::setprecision(12) << std::scientific << " " - << output_scale_factor << "\n"; - } - PrintOffset(out_file, "weight", component[i].op.affine.ptr_weights); - PrintOffset(out_file, "bias", component[i].op.affine.ptr_biases); -#ifdef LIGHT_DUMP - std::ofstream out_wfile((out_file_name.str() + "_weights.txt").c_str(), std::ios::out); - std::ofstream out_bfile((out_file_name.str() + "_biases.txt").c_str(), std::ios::out); -#endif - if (num_bytes_per_weight == 1) { - if (num_bytes_per_bias != 1) { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - int8_t* ptr_weight = reinterpret_cast(component[i].op.affine.ptr_weights); - gna_compound_bias_t* ptr_bias = - reinterpret_cast(component[i].op.affine.ptr_biases); - for (uint32_t row = 0; row < num_weight_rows; row++) { - for (uint32_t col = 0; col < num_weight_columns; col++) { - if (logging_precision == kDnnFloat) { - float val = static_cast(ptr_weight[row * num_weight_columns + col]) * - ptr_bias[row].multiplier / weight_scale_factor; - out_wfile << std::setprecision(4) << val << " "; - } else { - out_wfile << int((int8_t)ptr_weight[row * num_weight_columns + col]) << " "; - } - out_wfile << "\n"; - } - } -#endif - } else { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - int8_t* ptr_weight = reinterpret_cast(component[i].op.affine.ptr_weights); - for (uint32_t row = 0; row < num_weight_rows; row++) { - for (uint32_t col = 0; col < num_weight_columns; col++) { - if (logging_precision == kDnnFloat) { - float val = static_cast(ptr_weight[row * num_weight_columns + col]) / - weight_scale_factor; - out_wfile << std::setprecision(4) << val << " "; - } else { - out_wfile << int((int8_t)ptr_weight[row * num_weight_columns + col]) << " "; - } - out_wfile << "\n"; - } - } -#endif - } - } else if (num_bytes_per_weight == 2) { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - int16_t* ptr_weight = reinterpret_cast(component[i].op.affine.ptr_weights); - for (uint32_t row = 0; row < num_weight_rows; row++) { - for (uint32_t col = 0; col < num_weight_columns; col++) { - if (logging_precision == kDnnFloat) { - out_wfile << std::setprecision(12) - << ptr_weight[row * num_weight_columns + col] / weight_scale_factor << " "; - } else { - out_wfile << ptr_weight[row * num_weight_columns + col] << " "; - } - out_wfile << "\n"; - } - } -#endif - } else if (compute_precision_ == kDnnFloat) { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - float* ptr_weight = reinterpret_cast(component[i].op.affine.ptr_weights); - for (uint32_t row = 0; row < num_weight_rows; row++) { - for (uint32_t col = 0; col < num_weight_columns; col++) { - out_wfile << std::setprecision(5) << ptr_weight[row * num_weight_columns + col] << " "; - out_wfile << "\n"; - } - } -#endif - } else { - fprintf(stderr, "Unsupported weight type in WriteDnnText!\n"); - throw - 1; - } - if (compute_precision_ == kDnnInt) { - if (num_bytes_per_weight == 1) { - if (num_bytes_per_bias != 1) { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - gna_compound_bias_t* ptr_biases = - reinterpret_cast(component[i].op.affine.ptr_biases); - for (uint32_t row = 0; row < num_rows_out; row++) { - if (logging_precision == kDnnInt) { - out_bfile << std::setw(8) << ptr_biases[row].bias << ", "; - out_bfile << std::setw(8) << int(ptr_biases[row].multiplier) << "\n"; - } else { - out_bfile << std::setw(8) << ptr_biases[row].bias / output_scale_factor << "\n"; - } - } -#endif - } else { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - int8_t* ptr_biases = reinterpret_cast(component[i].op.affine.ptr_biases); - for (uint32_t row = 0; row < num_rows_out; row++) { - if (logging_precision == kDnnInt) { - out_bfile << std::setw(8) << ptr_biases[row] << "\n"; - } else { - out_bfile << std::setw(8) << ptr_biases[row] / output_scale_factor << "\n"; - } - } -#endif - } - } else { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - int32_t* ptr_biases = reinterpret_cast(component[i].op.affine.ptr_biases); - for (uint32_t row = 0; row < num_rows_out; row++) { - if (logging_precision == kDnnInt) { - out_bfile << std::setw(8) << ptr_biases[row] << "\n"; - } else { - out_bfile << std::setw(8) << ptr_biases[row] / output_scale_factor << "\n"; - } - } -#endif - } - } else { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - float* ptr_biases = reinterpret_cast(component[i].op.affine.ptr_biases); - for (uint32_t row = 0; row < num_rows_out; row++) { - out_bfile << std::setprecision(5) << ptr_biases[row] << "\n"; - } -#endif - } - } break; - case kDnnConvolutional1dOp: { - uint32_t num_filters = component[i].op.conv1D.num_filters; - uint32_t num_filter_coefficients = component[i].op.conv1D.num_filter_coefficients; - const auto convStride = component[i].op.conv1D.convStride; - uint32_t num_bytes_per_weight = component[i].op.conv1D.num_bytes_per_weight; - uint32_t num_bytes_per_bias = component[i].op.conv1D.num_bytes_per_bias; - float weight_scale_factor = component[i].op.conv1D.weight_scale_factor; - float output_scale_factor = component[i].output_scale_factor; - out_file << " " << std::dec << num_filters << "\n"; - out_file << " " << std::dec << num_filter_coefficients << "\n"; - out_file << " " << std::dec << convStride << "\n"; - if ((compute_precision_ == kDnnInt) && (logging_precision == kDnnFloat)) { - out_file << " " << std::dec << 4 << "\n"; - out_file << " " << std::dec << 4 << "\n"; - } else { - out_file << " " << std::dec << num_bytes_per_weight << "\n"; - out_file << " " << std::dec << num_bytes_per_bias << "\n"; - } - if ((compute_precision_ == kDnnInt) && (logging_precision == kDnnFloat)) { - out_file << std::setprecision(12) << std::scientific << " " << 1.0 << "\n"; - out_file << std::setprecision(12) << std::scientific << " " << 1.0 << "\n"; - } else { - out_file << std::setprecision(12) << std::scientific << " " - << weight_scale_factor << "\n"; - out_file << std::setprecision(12) << std::scientific << " " - << output_scale_factor << "\n"; - } - PrintOffset(out_file, "filter", component[i].op.conv1D.ptr_filters); - PrintOffset(out_file, "bias", component[i].op.conv1D.ptr_biases); - -#ifdef LIGHT_DUMP - std::ofstream out_wfile((out_file_name.str() + "_weights.txt").c_str(), std::ios::out); - std::ofstream out_bfile((out_file_name.str() + "_biases.txt").c_str(), std::ios::out); -#endif - - if (num_bytes_per_weight == 1) { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - int8_t* ptr_weight = reinterpret_cast(component[i].op.conv1D.ptr_filters); - gna_compound_bias_t* ptr_bias = - reinterpret_cast(component[i].op.conv1D.ptr_biases); - for (uint32_t row = 0; row < num_filters; row++) { - for (uint32_t col = 0; col < num_filter_coefficients; col++) { - if (logging_precision == kDnnFloat) { - float val = static_cast(ptr_weight[row * num_filter_coefficients + col]) * - ptr_bias[row].multiplier / weight_scale_factor; - out_wfile << std::setprecision(12) << val << "\n"; - } else { - out_wfile << "0x" << std::setfill('0') << std::setw(2) << std::hex - << int((uint8_t)ptr_weight[row * num_filter_coefficients + col]) << "\n"; - } - } - } -#endif - } else if (num_bytes_per_weight == 2) { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - int16_t* ptr_weight = reinterpret_cast(component[i].op.conv1D.ptr_filters); - for (uint32_t row = 0; row < num_filters; row++) { - for (uint32_t col = 0; col < num_filter_coefficients; col++) { - if (logging_precision == kDnnFloat) { - out_wfile << std::setprecision(12) - << ptr_weight[row * num_filter_coefficients + col] / weight_scale_factor - << "\n"; - } else { - out_wfile << "0x" << std::setfill('0') << std::setw(4) << std::hex - << ptr_weight[row * num_filter_coefficients + col] << "\n"; - } - } - } -#endif - } else if (compute_precision_ == kDnnFloat) { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - float* ptr_weight = reinterpret_cast(component[i].op.conv1D.ptr_filters); - for (uint32_t row = 0; row < num_filters; row++) { - for (uint32_t col = 0; col < num_filter_coefficients; col++) { - out_wfile << std::setprecision(12) << ptr_weight[row * num_filter_coefficients + col] - << "\n"; - } - } -#endif - } else { - fprintf(stderr, "Unsupported filter weight type in WriteDnnText!\n"); - throw - 1; - } - - if (compute_precision_ == kDnnInt) { - if (logging_precision == kDnnInt) { - if (num_bytes_per_weight == 1) { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - gna_compound_bias_t* ptr_biases = - reinterpret_cast(component[i].op.conv1D.ptr_biases); - for (uint32_t row = 0; row < num_filters; row++) { - out_bfile << "0x" << std::setfill('0') << std::setw(8) << std::hex - << ptr_biases[row].bias << " "; - out_bfile << "0x" << std::setfill('0') << std::setw(8) << std::hex - << int(ptr_biases[row].multiplier) << "\n"; - } -#endif - } else { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - int32_t* ptr_biases = reinterpret_cast(component[i].op.conv1D.ptr_biases); - for (uint32_t row = 0; row < num_filters; row++) { - out_bfile << "0x" << std::setfill('0') << std::setw(8) << std::hex << ptr_biases[row] - << "\n"; - } -#endif - } - } else { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - int32_t* ptr_biases = reinterpret_cast(component[i].op.conv1D.ptr_biases); - for (uint32_t row = 0; row < num_filters; row++) { - out_bfile << std::setprecision(12) << ptr_biases[row] / output_scale_factor << "\n"; - } -#endif - } - } else { -#if defined(DUMP_WB) || defined(LIGHT_DUMP) - float* ptr_biases = reinterpret_cast(component[i].op.conv1D.ptr_biases); - for (uint32_t row = 0; row < num_filters; row++) { - out_bfile << std::setprecision(12) << ptr_biases[row] << "\n"; - } -#endif - } - out_file << "\n"; - } break; - case kDnnConvolutional2dOp: { - const auto output_scale_factor = component[i].output_scale_factor; - const auto weight_scale_factor = component[i].op.conv2D.weight_scale_factor; - const auto convolution_stride_0 = component[i].op.conv2D.convStride[0]; - const auto convolution_stride_1 = component[i].op.conv2D.convStride[1]; - - const auto zero_padding_0 = component[i].op.conv2D.zeroPadding[0]; - const auto zero_padding_1 = component[i].op.conv2D.zeroPadding[1]; - - out_file << std::setprecision(12) << std::scientific << " " << output_scale_factor - << "\n"; - out_file << std::setprecision(12) << std::scientific << " " << weight_scale_factor - << "\n"; - PrintTensors(out_file, component[i].tensors); - out_file << " " << std::dec << convolution_stride_0 << "\n"; - out_file << " " << std::dec << convolution_stride_1 << "\n"; - - out_file << " " << std::dec << zero_padding_0 << "\n"; - out_file << " " << std::dec << zero_padding_1 << "\n"; - out_file << "\n"; - } break; - case kDnnRecurrentOp: { - float weight_scale_factor = component[i].op.recurrent.weight_scale_factor; - float output_scale_factor = component[i].output_scale_factor; - uint32_t num_vector_delay = component[i].op.recurrent.num_vector_delay; - uint32_t num_bytes_per_weight = component[i].op.recurrent.num_bytes_per_weight; - uint32_t num_bytes_per_bias = component[i].op.recurrent.num_bytes_per_bias; -#ifdef DUMP_WB - uint32_t num_weight_rows = num_columns_out; - uint32_t num_weight_columns = num_columns_in + num_columns_out; -#endif - out_file << " " << std::dec << num_vector_delay << "\n"; - if ((compute_precision_ == kDnnInt) && (logging_precision == kDnnFloat)) { - out_file << " " << std::dec << 4 << "\n"; - out_file << " " << std::dec << 4 << "\n"; - } else { - out_file << " " << std::dec << num_bytes_per_weight << "\n"; - out_file << " " << std::dec << num_bytes_per_bias << "\n"; - } - if ((compute_precision_ == kDnnInt) && (logging_precision == kDnnFloat)) { - out_file << std::setprecision(12) << std::scientific << " " << 1.0 << "\n"; - out_file << std::setprecision(12) << std::scientific << " " << 1.0 << "\n"; - } else { - out_file << std::setprecision(12) << std::scientific << " " - << weight_scale_factor << "\n"; - out_file << std::setprecision(12) << std::scientific << " " - << output_scale_factor << "\n"; - } - PrintOffset(out_file, "weight", component[i].op.recurrent.ptr_weights); - PrintOffset(out_file, "bias", component[i].op.recurrent.ptr_biases); - PrintOffset(out_file, "feedback", component[i].op.recurrent.ptr_feedbacks); - if (num_bytes_per_weight == 1) { -#ifdef DUMP_WB - int8_t* ptr_weight = reinterpret_cast(component[i].op.recurrent.ptr_weights); - gna_compound_bias_t* ptr_bias = - reinterpret_cast(component[i].op.recurrent.ptr_biases); - for (uint32_t row = 0; row < num_weight_rows; row++) { - out_file << " "; - for (uint32_t col = 0; col < num_weight_columns; col++) { - if (logging_precision == kDnnFloat) { - float val = static_cast(ptr_weight[row * num_weight_columns + col]) * - ptr_bias[col].multiplier / weight_scale_factor; - out_file << std::setprecision(12) << std::scientific << val << " "; - } else { - out_file << "0x" << std::setfill('0') << std::setw(2) << std::hex - << int((uint8_t)ptr_weight[row * num_weight_columns + col]) << " "; - } - } - out_file << "\n"; - } -#endif - } else if (num_bytes_per_weight == 2) { -#ifdef DUMP_WB - int16_t* ptr_weight = reinterpret_cast(component[i].op.recurrent.ptr_weights); - for (uint32_t row = 0; row < num_weight_rows; row++) { - out_file << " "; - for (uint32_t col = 0; col < num_weight_columns; col++) { - if (logging_precision == kDnnFloat) { - out_file << std::setprecision(12) << std::scientific - << ptr_weight[row * num_weight_columns + col] / weight_scale_factor << " "; - } else { - out_file << "0x" << std::setfill('0') << std::setw(4) << std::hex - << ptr_weight[row * num_weight_columns + col] << " "; - } - } - out_file << "\n"; - } -#endif - } else if (compute_precision_ == kDnnFloat) { -#ifdef DUMP_WB - float* ptr_weight = reinterpret_cast(component[i].op.recurrent.ptr_weights); - for (uint32_t row = 0; row < num_weight_rows; row++) { - out_file << " "; - for (uint32_t col = 0; col < num_weight_columns; col++) { - out_file << std::setprecision(12) << std::scientific - << ptr_weight[row * num_weight_columns + col] << " "; - } - out_file << "\n"; - } -#endif - } else { - fprintf(stderr, "Unsupported weight type in WriteDnnText!\n"); - throw - 1; - } - if (compute_precision_ == kDnnInt) { - if (logging_precision == kDnnInt) { - if (num_bytes_per_weight == 1) { - out_file << "" - << " "; -#ifdef DUMP_WB - gna_compound_bias_t* ptr_biases = - reinterpret_cast(component[i].op.recurrent.ptr_biases); - for (uint32_t col = 0; col < num_columns_out; col++) { - out_file << "0x" << std::setfill('0') << std::setw(8) << std::hex - << ptr_biases[col].bias << " "; - out_file << "0x" << std::setfill('0') << std::setw(8) << std::hex - << ptr_biases[col].multiplier << " "; - } -#endif - } else { - out_file << "" - << " "; -#ifdef DUMP_WB - int32_t* ptr_biases = reinterpret_cast(component[i].op.recurrent.ptr_biases); - for (uint32_t col = 0; col < num_columns_out; col++) { - out_file << "0x" << std::setfill('0') << std::setw(8) << std::hex << ptr_biases[col] - << " "; - } -#endif - } - } else { - out_file << "" - << " "; -#ifdef DUMP_WB - int32_t* ptr_biases = reinterpret_cast(component[i].op.recurrent.ptr_biases); - for (uint32_t col = 0; col < num_columns_out; col++) { - out_file << std::setprecision(12) << std::scientific - << ptr_biases[col] / output_scale_factor << " "; - } -#endif - } - } else { - out_file << "" - << " "; -#ifdef DUMP_WB - float* ptr_biases = reinterpret_cast(component[i].op.recurrent.ptr_biases); - for (uint32_t col = 0; col < num_columns_out; col++) { - out_file << std::setprecision(12) << std::scientific << ptr_biases[col] << " "; - } -#endif - } - out_file << "\n"; - } break; - case kDnnMaxPoolOp: { - out_file << " MAX\n"; - out_file << " " << std::dec << component[i].op.maxpool.poolingWindowXY[0] << "\n"; - out_file << " " << std::dec << component[i].op.maxpool.poolingWindowXY[1] << "\n"; - out_file << " " << std::dec << component[i].op.maxpool.poolingStrideXY[0] << "\n"; - out_file << " " << std::dec << component[i].op.maxpool.poolingStrideXY[1] << "\n"; - out_file << " " << std::dec << component[i].op.maxpool.inCHW[0] << "\n"; - out_file << " " << std::dec << component[i].op.maxpool.inCHW[1] << "\n"; - out_file << " " << std::dec << component[i].op.maxpool.inCHW[2] << "\n"; - out_file << " " << std::dec << component[i].op.maxpool.outCHW[0] << "\n"; - out_file << " " << std::dec << component[i].op.maxpool.outCHW[1] << "\n"; - out_file << " " << std::dec << component[i].op.maxpool.outCHW[2] << "\n"; - out_file << std::setprecision(12) << std::scientific << " " - << component[i].output_scale_factor << "\n"; - } break; - case kDnnPiecewiselinearOp: { - gna_pwl_segment_t* ptr_segment = component[i].op.pwl.ptr_segments; - DnnActivationType func_id = component[i].op.pwl.func_id.type; - uint32_t num_segments = component[i].op.pwl.num_segments; - float output_scale_factor = component[i].output_scale_factor; - out_file << " " << intel_dnn_activation_name[func_id] << "\n"; - out_file << " " << std::dec << sizeof(int16_t) << "\n"; - out_file << " " << std::dec << sizeof(int16_t) << "\n"; - out_file << " " << std::dec << sizeof(int32_t) << "\n"; - switch (func_id) { - case kActRelu: - case kActLeakyRelu: - out_file << " " << std::setprecision(12) << std::scientific - << component[i].op.pwl.func_id.args.lrelu.negative_slope << "\n"; - break; - case kActPow: - out_file << " " << std::setprecision(12) << std::scientific - << component[i].op.pwl.func_id.args.pow.exponent << "\n"; - out_file << " " << std::setprecision(12) << std::scientific - << component[i].op.pwl.func_id.args.pow.scale << "\n"; - out_file << " " << std::setprecision(12) << std::scientific - << component[i].op.pwl.func_id.args.pow.offset << "\n"; - break; - case kActFakeQuantize: - out_file << " " << std::dec << component[i].op.pwl.func_id.fqParams.levels - << "\n"; - out_file << " " << std::setprecision(12) << std::scientific - << component[i].op.pwl.func_id.fqParams.input_low << "\n"; - out_file << " " << std::setprecision(12) << std::scientific - << component[i].op.pwl.func_id.fqParams.input_high << "\n"; - out_file << " " << std::setprecision(12) << std::scientific - << component[i].op.pwl.func_id.fqParams.output_low << "\n"; - out_file << " " << std::setprecision(12) << std::scientific - << component[i].op.pwl.func_id.fqParams.output_high << "\n"; - break; - default: - break; - } - if (logging_precision == kDnnFloat) { - out_file << std::setprecision(12) << std::scientific << " " << 1.0 << "\n"; - out_file << " " << std::dec << 0 << "\n"; - PrintOffset(out_file, "segment", component[i].op.pwl.ptr_segments); - } else { - out_file << std::setprecision(12) << std::scientific << " " - << output_scale_factor << "\n"; - out_file << " " << std::dec << num_segments << "\n"; - PrintOffset(out_file, "segment", component[i].op.pwl.ptr_segments); - if (compute_precision_ == kDnnInt) { - out_file << " "; - for (uint32_t segment = 0; segment < num_segments; segment++) { - out_file << "0x" << std::setfill('0') << std::setw(4) << std::hex - << ptr_segment[segment].slope << " "; - } - out_file << "\n"; - out_file << " "; - for (uint32_t segment = 0; segment < component[i].op.pwl.num_segments; segment++) { - out_file << "0x" << std::setfill('0') << std::setw(4) << std::hex - << ptr_segment[segment].yBase << " "; - } - out_file << "\n"; - out_file << " "; - for (uint32_t segment = 0; segment < component[i].op.pwl.num_segments; segment++) { - out_file << "0x" << std::setfill('0') << std::setw(8) << std::hex - << ptr_segment[segment].xBase << " "; - } - out_file << "\n"; - } else if (num_segments > 0) { - fprintf(stderr, "Number of segments must be zero in floating point model in WriteDnnText!\n"); - throw - 1; - } - } - } break; - case kDnnInterleaveOp: - out_file << std::setprecision(12) << std::scientific << " " - << component[i].output_scale_factor << "\n"; - break; - case kDnnDeinterleaveOp: - out_file << std::setprecision(12) << std::scientific << " " - << component[i].output_scale_factor << "\n"; - break; - case kDnnCopyOp: - out_file << std::setprecision(12) << std::scientific << " " - << component[i].output_scale_factor << "\n"; - out_file << " " << std::dec << component[i].op.copy.num_copy_rows << "\n"; - out_file << " " << std::dec << component[i].op.copy.num_copy_columns << "\n"; - break; - default: - out_file << " Unsupported Component : " << intel_dnn_operation_name[component[i].operation] - << "\n"; - break; - } - } - if (ptr_active_outputs() != nullptr) { - PrintOffset(out_file, "activelist", ptr_active_outputs()); - } - out_file << "\n"; - out_file.close(); - } else { - fprintf(stderr, "Failed to open %s for writing!\n", filename); - throw - 1; - } -} - -uint32_t AMIntelDNN::CountLayers() { - uint32_t n = 0; - for (auto&& c : component) { - if (c.operation == kDnnAffineOp || (c.operation == kDnnDiagonalOp) || (c.operation == kDnnConvolutional1dOp) || - (c.operation == kDnnConvolutional2dOp) || (c.operation == kDnnDeinterleaveOp) || - (c.operation == kDnnInterleaveOp) || (c.operation == kDnnRecurrentOp) || (c.operation == kDnnCopyOp)) { - n++; - } - } - return n; -} - -void AMIntelDNN::InitGNAStruct(Gna2Model* gnaModel) { - Gna2Operation* gnaOperation; - if (gnaModel == nullptr) - THROW_GNA_EXCEPTION << "Invalid input parameter"; - if (gnaModel->Operations != nullptr) - THROW_GNA_EXCEPTION << "InitGNAStruct can't work on preallocated layers array"; - - if (component.empty()) - THROW_GNA_EXCEPTION << "empty model in AMIntelDNN::InitGNAStruct()"; - - gnaModel->NumberOfOperations = CountLayers(); - gnaModel->Operations = - reinterpret_cast(gnaUserAllocator(gnaModel->NumberOfOperations * sizeof(Gna2Operation))); - if (gnaModel->Operations == nullptr) - THROW_GNA_EXCEPTION << "out of memory in AMIntelDNN::InitGNAStruct()"; - memset(gnaModel->Operations, 0, gnaModel->NumberOfOperations * sizeof(Gna2Operation)); - gnaOperation = gnaModel->Operations; - for (size_t i = 0; i < component.size(); i++) { - log::debug() << "Component + " << i << "=GNA_" << std::distance(gnaModel->Operations, gnaOperation) << "\n"; - - auto& comp = component[i]; - switch (comp.operation) { - case kDnnAffineOp: - HelperGna2OperationInitFullyConnectedAffine( - gnaOperation, - gnaUserAllocator, - gnaUserFree, - createGna2Tensor2D(comp.num_rows_in, comp.num_columns_in, comp.num_bytes_per_input, comp.ptr_inputs), - createGna2Tensor2D(comp.num_rows_out, - comp.num_columns_out, - comp.num_bytes_per_output, - comp.ptr_outputs), - createGna2Tensor2D(comp.num_rows_out, - comp.num_rows_in, - comp.op.affine.num_bytes_per_weight, - comp.op.affine.ptr_weights), - createGna2BiasTensor1D(comp.num_rows_out, comp.op.affine.num_bytes_per_bias, comp.op.affine.ptr_biases), - nullptr); - AdvanceOperationIfAllApplied(component, i, gnaOperation); - break; - case kDnnDiagonalOp: - HelperGna2OperationInitElementWiseAffine( - gnaOperation, - gnaUserAllocator, - gnaUserFree, - createGna2Tensor2D(comp.num_rows_in, comp.num_columns_in, comp.num_bytes_per_input, comp.ptr_inputs), - createGna2Tensor2D(comp.num_rows_out, - comp.num_columns_out, - comp.num_bytes_per_output, - comp.ptr_outputs), - createGna2Tensor1D(comp.num_rows_out, comp.op.affine.num_bytes_per_weight, comp.op.affine.ptr_weights), - createGna2Tensor1D(comp.num_rows_out, comp.op.affine.num_bytes_per_bias, comp.op.affine.ptr_biases), - nullptr); - AdvanceOperationIfAllApplied(component, i, gnaOperation); - break; - case kDnnRecurrentOp: - HelperGna2OperationInitRecurrent( - gnaOperation, - gnaUserAllocator, - gnaUserFree, - createGna2Tensor2D(comp.num_rows_in, comp.num_columns_in, comp.num_bytes_per_input, comp.ptr_inputs), - createGna2Tensor2D(comp.num_rows_out, - comp.num_columns_out, - comp.num_bytes_per_output, - comp.ptr_outputs), - createGna2Tensor2D(comp.num_columns_out, - comp.num_columns_in + comp.num_columns_out, - comp.op.affine.num_bytes_per_weight, - comp.op.affine.ptr_weights), - createGna2Tensor1D(comp.num_columns_out, comp.op.affine.num_bytes_per_bias, comp.op.affine.ptr_biases), - nullptr, - create_uint32_parameter(1)); // TODO: GNA2: Handle other delays - AdvanceOperationIfAllApplied(component, i, gnaOperation); - break; - case kDnnConvolutional1dOp: - HelperGna2OperationInitConvolution( - gnaOperation, - gnaUserAllocator, - gnaUserFree, - createGna2Tensor2D(comp.num_rows_in, comp.num_columns_in, comp.num_bytes_per_input, comp.ptr_inputs), - createGna2Tensor3D(comp.num_rows_out, - comp.num_columns_out / comp.op.conv1D.num_filters, - comp.op.conv1D.num_filters, - comp.num_bytes_per_output, - comp.ptr_outputs), - createGna2Tensor2D(comp.op.conv1D.num_filters, - comp.op.conv1D.num_filter_coefficients, - comp.op.conv1D.num_bytes_per_weight, - comp.op.conv1D.ptr_filters), - createGna2Tensor1D(comp.op.conv1D.num_filters, - comp.op.conv1D.num_bytes_per_bias, - comp.op.conv1D.ptr_biases), - nullptr, - create_shape1D_parameter(comp.op.conv1D.convStride), - nullptr, - nullptr); - - AdvanceCnnOperationIfAllApplied(component, i, gnaOperation); - break; - case kDnnConvolutional2dOp: - HelperGna2OperationInitConvolution( - gnaOperation, - gnaUserAllocator, - gnaUserFree, - createGna2Tensor(comp.tensors[0], comp.ptr_inputs), - createGna2Tensor(comp.tensors[1], comp.ptr_outputs), - createGna2Tensor(comp.tensors[2], comp.op.conv2D.ptr_filters), - createGna2Tensor(comp.tensors[3], comp.op.conv2D.ptr_biases), - nullptr, - create_shape2D_parameter(comp.op.conv2D.convStride[0], comp.op.conv2D.convStride[1]), - nullptr, - create_shape2D_parameter(comp.op.conv2D.zeroPadding[0], comp.op.conv2D.zeroPadding[1])); - - AdvanceCnnOperationIfAllApplied(component, i, gnaOperation); - break; - case kDnnMaxPoolOp: - if (i == 0) { - THROW_GNA_EXCEPTION << "Pooling component with no preceeding component"; - } else if (gnaOperation->Type == Gna2OperationTypeConvolution) { - if (gnaOperation->Operands == nullptr || gnaOperation->NumberOfOperands <= PwlOpIdx) { - THROW_GNA_EXCEPTION << "Number and details of operands are wrong"; - } - auto pwlOperand = gnaOperation->Operands[PwlOpIdx]; - if (pwlOperand != nullptr && pwlOperand->Shape.Dimensions[0] != 0 && - gnaOperation->Operands[InOpIdx]->Shape.NumberOfDimensions == 2) { // kDnnConvolutional1dOp - THROW_GNA_EXCEPTION << "Encountered activation component before pooling component at index == " - << i; - } else { - const auto poolMode = reinterpret_cast(gnaUserAllocator(sizeof(Gna2PoolingMode))); - IE_ASSERT(poolMode != nullptr); - *poolMode = Gna2PoolingModeMax; - - Gna2Shape* poolWindow{}; - Gna2Shape* poolStride{}; - - if (gnaOperation->Operands[InOpIdx]->Shape.NumberOfDimensions == 2) { // kDnnConvolutional1dOp - poolWindow = create_shape1D_parameter(comp.op.maxpool.poolingWindowXY[0]); - poolStride = create_shape1D_parameter(comp.op.maxpool.poolingStrideXY[0]); - } else { - poolWindow = create_shape2D_parameter(comp.op.maxpool.poolingWindowXY[1], - comp.op.maxpool.poolingWindowXY[0]); - poolStride = create_shape2D_parameter(comp.op.maxpool.poolingStrideXY[1], - comp.op.maxpool.poolingStrideXY[0]); - } - - // number of output columns correction - based on GNA-library expectations - - if ((gnaOperation->NumberOfParameters > PoolModeParamIdx && - gnaOperation->Parameters[PoolModeParamIdx] != nullptr) || - (gnaOperation->NumberOfParameters > PoolWinParamIdx && - gnaOperation->Parameters[PoolWinParamIdx] != nullptr) || - (gnaOperation->NumberOfParameters > PoolStrideParamIdx && - gnaOperation->Parameters[PoolStrideParamIdx] != nullptr)) { - THROW_GNA_EXCEPTION << "Pooling parameters should not be initialized"; - } - HelperGna2OperationSetParameter(gnaOperation, - gnaUserAllocator, - gnaUserFree, - PoolModeParamIdx, - poolMode); - HelperGna2OperationSetParameter(gnaOperation, - gnaUserAllocator, - gnaUserFree, - PoolWinParamIdx, - poolWindow); - HelperGna2OperationSetParameter(gnaOperation, - gnaUserAllocator, - gnaUserFree, - PoolStrideParamIdx, - poolStride); - - // adjust Gna2OperationTypeConvolution fused layer output dimensions to reflect convolution - // zeroPadding and pooling - if (gnaOperation->Operands[InOpIdx]->Shape.NumberOfDimensions != 2) { // kDnnConvolutional2dOp - auto& outputTensor = const_cast(*gnaOperation->Operands[OutOpIdx]); - const auto fltStrideShape = - reinterpret_cast(gnaOperation->Parameters[ConvStrideParamIdx]); - // Override GNA operation output pointer with the one from pooling component - outputTensor.Data = comp.ptr_outputs; - - Gna2Shape zeroPadding{}; - if (gnaOperation->NumberOfParameters > ZeroPaddingParamIdx && - gnaOperation->Parameters[ZeroPaddingParamIdx] != nullptr) { - zeroPadding = *reinterpret_cast(gnaOperation->Parameters[ZeroPaddingParamIdx]); - } - const int beginOfHInNHWC = 1; - const int beginOfHInHW = 0; - for (auto&& dimHW : {0, 1}) { - const auto inputPadded = - gnaOperation->Operands[InOpIdx]->Shape.Dimensions[beginOfHInNHWC + dimHW] + - zeroPadding.Dimensions[beginOfHInHW + dimHW] * 2; - const auto nFltSize = - gnaOperation->Operands[FilterOpIdx]->Shape.Dimensions[beginOfHInNHWC + dimHW]; - const auto fltStride = fltStrideShape->Dimensions[beginOfHInHW + dimHW]; - const auto outFromConv = outputFromConv(inputPadded, nFltSize, fltStride); - outputTensor.Shape.Dimensions[beginOfHInNHWC + dimHW] = - outputFromPooling(outFromConv, - poolWindow->Dimensions[beginOfHInHW + dimHW], - poolStride->Dimensions[beginOfHInHW + dimHW]); - } - } - AdvanceOperationIfAllApplied(component, i, gnaOperation); - } - } else { - THROW_GNA_EXCEPTION << "Pooling component applied to non-convolutional layer"; - } - break; - case kDnnPiecewiselinearOp: { - IE_ASSERT(gnaOperation->Operands != nullptr); - IE_ASSERT(OutOpIdx < gnaOperation->NumberOfOperands); - auto& outputTensor = const_cast(*gnaOperation->Operands[OutOpIdx]); - outputTensor.Data = comp.ptr_outputs; - outputTensor.Type = Gna2DataTypeFromBytes(comp.num_bytes_per_output); - if (i == 0) { - THROW_GNA_EXCEPTION << "PWL component with no preceding component."; - } - if ((component[i - 1].operation == kDnnAffineOp) || (component[i - 1].operation == kDnnDiagonalOp) || - (component[i - 1].operation == kDnnRecurrentOp) || - (component[i - 1].operation == kDnnConvolutional1dOp) || - (component[i - 1].operation == kDnnConvolutional2dOp) || - ((component[i - 1].operation == kDnnMaxPoolOp) && - (component[i - 2].operation == kDnnConvolutional1dOp || - component[i - 2].operation == kDnnConvolutional2dOp))) { - if (gnaOperation->Operands[PwlOpIdx] == nullptr) { - HelperGna2OperationSetOperand(gnaOperation, - gnaUserAllocator, - gnaUserFree, - PwlOpIdx, - createGna2TensorPwl(1, nullptr)); - } - auto& pwlTensor = const_cast(*gnaOperation->Operands[PwlOpIdx]); - pwlTensor = - HelperGna2TensorInit1D(comp.op.pwl.num_segments, Gna2DataTypePwlSegment, comp.op.pwl.ptr_segments); - if (component[i - 1].operation == kDnnConvolutional1dOp) { - if (outputTensor.Shape.NumberOfDimensions != 3) { - THROW_GNA_EXCEPTION << "CNN output NumberOfDimensions != 3"; - } - if (outputTensor.Shape.Dimensions[0] * outputTensor.Shape.Dimensions[1] * - outputTensor.Shape.Dimensions[2] != - comp.num_columns_out * comp.num_rows_out) { - THROW_GNA_EXCEPTION << "PWL after CNN output size mismatch"; - } - } - if (component[i - 1].operation == kDnnConvolutional2dOp) { - if (outputTensor.Shape.NumberOfDimensions != 4) { - THROW_GNA_EXCEPTION << "CNN2D output NumberOfDimensions != 4"; - } - if (outputTensor.Shape.Dimensions[0] * outputTensor.Shape.Dimensions[1] * - outputTensor.Shape.Dimensions[2] * outputTensor.Shape.Dimensions[3] != - comp.num_columns_out * comp.num_rows_out) { - THROW_GNA_EXCEPTION << "PWL after CNN2D output size mismatch"; - } - } - } - } - AdvancePwlOperationIfAllApplied(component, i, gnaOperation); - break; - case kDnnInterleaveOp: - HelperGna2OperationInitInterleave( - gnaOperation, - gnaUserAllocator, - gnaUserFree, - createGna2Tensor2D(comp.num_rows_in, comp.num_columns_in, comp.num_bytes_per_input, comp.ptr_inputs), - createGna2Tensor2D(comp.num_rows_out, - comp.num_columns_out, - comp.num_bytes_per_output, - comp.ptr_outputs)); - gnaOperation++; - break; - case kDnnDeinterleaveOp: - HelperGna2OperationInitDeInterleave( - gnaOperation, - gnaUserAllocator, - gnaUserFree, - createGna2Tensor2D(comp.num_rows_in, comp.num_columns_in, comp.num_bytes_per_input, comp.ptr_inputs), - createGna2Tensor2D(comp.num_rows_out, - comp.num_columns_out, - comp.num_bytes_per_output, - comp.ptr_outputs)); - gnaOperation++; - break; - case kDnnCopyOp: - HelperGna2OperationInitCopy( - gnaOperation, - gnaUserAllocator, - gnaUserFree, - createGna2Tensor2D(comp.num_columns_in, comp.num_rows_in, comp.num_bytes_per_input, comp.ptr_inputs), - createGna2Tensor2D(comp.num_columns_out, - comp.num_rows_out, - comp.num_bytes_per_output, - comp.ptr_outputs), - create_shape2D_parameter(comp.op.copy.num_copy_columns, comp.op.copy.num_copy_rows)); - gnaOperation++; - break; - default: { - THROW_GNA_EXCEPTION << "GNA does yet not support " << intel_dnn_operation_name[component[i].operation]; - } - } - } - // enable debugging of partial array of components - gnaModel->NumberOfOperations = static_cast(std::distance(gnaModel->Operations, gnaOperation)); -} - -void AMIntelDNN::DestroyGNAStruct(Gna2Model* gnaModel) { - if (gnaModel->Operations != nullptr) { - for (uint32_t i = 0; i < gnaModel->NumberOfOperations; i++) { - switch (gnaModel->Operations[i].Type) { - case Gna2OperationTypeFullyConnectedAffine: - break; - case Gna2OperationTypeElementWiseAffine: - break; - case Gna2OperationTypeRecurrent: - break; - case Gna2OperationTypeConvolution: - break; - case Gna2OperationTypeTransposition: - break; - case Gna2OperationTypeCopy: - break; - default: - break; - } - freeGna2Operation(gnaModel->Operations[i]); - } - gnaUserFree(gnaModel->Operations); - gnaModel->Operations = nullptr; - } - gnaModel->NumberOfOperations = 0; -} - -void AMIntelDNN::WriteInputAndOutputTextGNA(const Gna2Model& model) { -#ifdef LIGHT_DUMP - dump::WriteInputAndOutputTextGNAImpl(model, getDumpFilePrefixGNA(), getRefFolderName()); -#endif -} - -void AMIntelDNN::WriteInputAndOutputText() { -#ifdef LIGHT_DUMP - for (uint32_t i = 0; i < num_components(); i++) { - std::stringstream out_file_name; - out_file_name << std::setfill('0') << std::setw(2) << i << "_" - << intel_dnn_operation_name[component[i].operation] << "-" << component[i].num_rows_in << "-" - << component[i].num_rows_out; - if (component[i].operation == kDnnPiecewiselinearOp) { - out_file_name << "-" << intel_dnn_activation_name[component[i].op.pwl.func_id]; - } - auto inputfileName = getDumpFolderName() + out_file_name.str() + "_input.txt"; - auto outFileName = getDumpFolderName() + out_file_name.str() + "_output.txt"; - auto refOutputFileName = getRefFolderName() + out_file_name.str() + "_output.txt"; - - std::ofstream out_file(outFileName.c_str(), std::ios::out); - std::ifstream ref_out_file(refOutputFileName.c_str(), std::ios::in); - std::ofstream in_file(inputfileName.c_str(), std::ios::out); - - // assume that ref only mode not used - if (!out_file.good() || !in_file.good()) - return; - - float summOfDiff = 0.f; - float summOfSqDiff = 0.f; - float maxD = 0.0f; - int numItems = 0; - - for (uint32_t k = 0; k < component[i].num_rows_out; k++) { - for (uint32_t j = 0; j < component[i].num_columns_out; j++) { - float floatValue = 0.f; - if (component[i].num_bytes_per_output == 4) { - if (compute_precision_ == kDnnInt) { - auto value = - reinterpret_cast(component[i].ptr_outputs)[k * component[i].num_columns_out + j]; - floatValue = static_cast(value); - - } else { - floatValue = - reinterpret_cast(component[i].ptr_outputs)[k * component[i].num_columns_out + j]; - } - } else if (component[i].num_bytes_per_output == 2) { - auto value = - reinterpret_cast(component[i].ptr_outputs)[k * component[i].num_columns_out + j]; - floatValue = static_cast(value); - } else { - auto value = - reinterpret_cast(component[i].ptr_outputs)[k * component[i].num_columns_out + j]; - floatValue = static_cast(value); - } - floatValue /= component[i].output_scale_factor; - out_file << std::setw(8) << floatValue << "\n"; - - if (ref_out_file) { - float ref_value = 0.f; - ref_out_file >> ref_value; - float diff = (ref_value - floatValue); - diff = diff < 0.f ? -diff : diff; - summOfDiff += diff; - summOfSqDiff += diff * diff; - maxD = std::max(maxD, diff); - numItems++; - } - } - } - if (numItems) { - auto rmse = sqrt(summOfSqDiff / numItems); - auto avg = summOfDiff / numItems; - log::trace() << std::left << std::setw(55) << out_file_name.str() << " RMSE=" << std::fixed - << std::setprecision(5) << std::right << std::setw(8) << rmse << " avg=" << std::fixed - << std::setprecision(5) << std::right << std::setw(8) << avg << " maxD=" << std::fixed - << std::setprecision(5) << std::right << std::setw(8) << maxD << std::endl; - } - - float input_scale_factor = component[i].input_scale_factor; - - for (uint32_t k = 0; k < component[i].num_rows_in; k++) { - for (uint32_t j = 0; j < component[i].num_columns_in; j++) { - float floatValue = 0.f; - if (component[i].num_bytes_per_input == 4) { - if (compute_precision_ == kDnnInt) { - auto value = - reinterpret_cast(component[i].ptr_inputs)[k * component[i].num_columns_in + j]; - floatValue = static_cast(value); - } else { - floatValue = - reinterpret_cast(component[i].ptr_inputs)[k * component[i].num_columns_in + j]; - } - } else if (component[i].num_bytes_per_input == 2) { - auto value = - reinterpret_cast(component[i].ptr_inputs)[k * component[i].num_columns_in + j]; - floatValue = static_cast(value); - } else { - auto value = - reinterpret_cast(component[i].ptr_inputs)[k * component[i].num_columns_in + j]; - floatValue = static_cast(value); - } - - in_file << std::setw(8) << floatValue / input_scale_factor << "\n"; - } - } - } -#endif -} - -uint32_t AMIntelDNN::num_components() { - return static_cast(component.size()); -} - -uint32_t AMIntelDNN::num_gna_layers() { - uint32_t num_layers = 0; - std::set gna_layers({kDnnAffineOp, - kDnnDiagonalOp, - kDnnConvolutional1dOp, - kDnnCopyOp, - kDnnDeinterleaveOp, - kDnnInterleaveOp, - kDnnRecurrentOp}); - for (auto& i : component) { - if (gna_layers.find(i.operation) != gna_layers.end()) { - num_layers++; - } - } - return num_layers; -} - -uint32_t AMIntelDNN::num_group_in() { - return ((!component.empty()) - ? ((component[0].orientation_in == kDnnInterleavedOrientation) ? component[0].num_columns_in - : component[0].num_rows_in) - : 0); -} - -uint32_t AMIntelDNN::num_group_out() { - return ((!component.empty()) ? ((component[component.size() - 1].orientation_out == kDnnInterleavedOrientation) - ? component[component.size() - 1].num_columns_out - : component[component.size() - 1].num_rows_out) - : 0); -} - -uint32_t AMIntelDNN::num_inputs() { - return component.empty() ? 0 : component[0].num_rows_in; -} - -uint32_t AMIntelDNN::num_outputs() { - return (component[component.size() - 1].orientation_out == kDnnInterleavedOrientation) - ? component[component.size() - 1].num_rows_out - : component[component.size() - 1].num_columns_out; -} - -std::string AMIntelDNN::getDumpFilePrefix(const std::string& folder) { - const char pathSeparator = -#ifdef _WIN32 - '\\'; -#else - '/'; -#endif - return std::string(".") + pathSeparator + folder + pathSeparator + std::to_string(dump_write_index) + pathSeparator; -} - -std::string AMIntelDNN::getDumpFilePrefixGNA() { - return getDumpFilePrefix("gna_layers"); -} - -std::string AMIntelDNN::getDumpFolderName() { - return getDumpFilePrefix("layers"); -} - -std::string AMIntelDNN::getRefFolderName() { - return getDumpFilePrefix("ref_layers"); -} - -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/am_intel_dnn.hpp b/src/plugins/intel_gna/src/backend/am_intel_dnn.hpp deleted file mode 100644 index 9f76209c480..00000000000 --- a/src/plugins/intel_gna/src/backend/am_intel_dnn.hpp +++ /dev/null @@ -1,488 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include "common/gna_target.hpp" -#include "dnn_types.hpp" -#include "gna/gna_config.hpp" -#include "gna_types.hpp" -#include "log/debug.hpp" -#include "memory/gna_memory.hpp" - -namespace ov { -namespace intel_gna { -namespace backend { - -class AMIntelDNN { -public: - AMIntelDNN() - : do_rotate_input(false), - num_rotate_rows(0), - num_rotate_columns(0), - ptr_active_outputs_(NULL), - num_active_outputs_(0), - compute_precision_(kDnnNumNumberType), - input_scale_factor_(1.0) {} - - ~AMIntelDNN(); - - void Init(memory::GNAMemoryInterface* memoryInterface, - intel_dnn_number_type_t compute_precision, - float scale_factor); - - void InitActiveList(uint32_t* ptr_active_list); - - template - static void InitAffineComponent(intel_dnn_component_t& comp, - uint32_t num_rows_in, - uint32_t num_columns, - uint32_t num_rows_out, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - uint32_t num_bytes_per_weight, - uint32_t num_bytes_per_bias, - float weight_scale_factor, - float output_scale_factor, - A*& ptr_inputs, - B*& ptr_outputs, - C*& ptr_weights, - D*& ptr_biases, - bool isDiag = false) { - InitAffineComponentPrivate(comp, - num_rows_in, - num_columns, - num_rows_out, - num_bytes_per_input, - num_bytes_per_output, - num_bytes_per_weight, - num_bytes_per_bias, - weight_scale_factor, - output_scale_factor, - (void*&)ptr_inputs, - (void*&)ptr_outputs, - (void*&)ptr_weights, - (void*&)ptr_biases, - isDiag, - true); - } - - template - static void InitConvolutional1DComponent(intel_dnn_component_t& comp, - uint32_t num_columns_in, - uint32_t num_columns_out, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - uint32_t num_bytes_per_weight, - uint32_t num_bytes_per_bias, - uint32_t num_filters, - uint32_t num_filter_coefficients, - uint32_t convStride, - float weight_scale_factor, - float output_scale_factor, - A*& ptr_inputs, - B*& ptr_outputs, - C*& ptr_filters, - D*& ptr_biases) { - InitConvolutional1DComponentPrivate(comp, - num_columns_in, - num_columns_out, - num_bytes_per_input, - num_bytes_per_output, - num_bytes_per_weight, - num_bytes_per_bias, - num_filters, - num_filter_coefficients, - convStride, - weight_scale_factor, - output_scale_factor, - (void*&)ptr_inputs, - (void*&)ptr_outputs, - (void*&)ptr_filters, - (void*&)ptr_biases, - true); - } - - template - static void InitConvolutional2DComponent(intel_dnn_component_t& comp, - OvGnaTensor inputTensor, - OvGnaTensor outputTensor, - OvGnaTensor filterTensor, - OvGnaTensor biasTensor, - std::array convStride, - std::array zeroPadding, - float weight_scale_factor, - float output_scale_factor, - A*& ptr_inputs, - B*& ptr_outputs, - C*& ptr_filters, - D*& ptr_biases) { - InitConvolutional2DComponentPrivate(comp, - inputTensor, - outputTensor, - filterTensor, - biasTensor, - convStride, - zeroPadding, - weight_scale_factor, - output_scale_factor, - (void*&)ptr_inputs, - (void*&)ptr_outputs, - (void*&)ptr_filters, - (void*&)ptr_biases); - } - - // Checks whether operation is Convolution and its parameters makes it specific to GNA1/GNA2 targets - // It does not guarantee that operation fully compatible to GNA1/GNA2, but for sure is not comaptible with GNA3 - // target - static bool isOperationCnnLegacySpecific(const Gna2Operation& operation); - // Recomputes number of outputs from CNN1D operations using legacy or new formula - // If isOperationCnnLegacySpecific() is true the number of outputs will also be recomputed for legacy compatibility - static void updateNumberOfOutputsIfPoolingEnabled(Gna2Model& gnaModel, bool useLegacyFormula); - - template - static void InitMaxpoolComponent(intel_dnn_component_t& cmp, - std::array inCHW, - std::array outCHW, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - std::array poolingWindowXY, - std::array poolingStrideXY, - float output_scale_factor, - A*& ptr_inputs, - B*& ptr_outputs) { - InitMaxpoolComponentPrivate(cmp, - inCHW, - outCHW, - num_bytes_per_input, - num_bytes_per_output, - poolingWindowXY, - poolingStrideXY, - output_scale_factor, - (void*&)ptr_inputs, - (void*&)ptr_outputs, - true); - } - - template - static void InitPiecewiseLinearComponent(intel_dnn_component_t& cmp, - const DnnActivation& function_id, - intel_dnn_orientation_t orientation, - uint32_t num_rows, - uint32_t num_columns, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - uint32_t num_segments, - float output_scale_factor, - float input_scale_factor, - A*& ptr_inputs, - B*& ptr_outputs, - gna_pwl_segment_t* ptr_segments) { - InitPiecewiseLinearComponentPrivate(cmp, - function_id, - orientation, - num_rows, - num_columns, - num_bytes_per_input, - num_bytes_per_output, - num_segments, - output_scale_factor, - input_scale_factor, - (void*&)ptr_inputs, - (void*&)ptr_outputs, - ptr_segments, - true); - } - - template - static void InitDeinterleaveComponent(intel_dnn_component_t& cmp, - uint32_t num_rows_in, - uint32_t num_columns_in, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - float output_scale_factor, - A*& ptr_inputs, - B*& ptr_outputs) { - InitDeinterleaveComponentPrivate(cmp, - num_rows_in, - num_columns_in, - num_bytes_per_input, - num_bytes_per_output, - output_scale_factor, - (void*&)ptr_inputs, - (void*&)ptr_outputs, - true); - } - - template - static void InitInterleaveComponent(intel_dnn_component_t& cmp, - uint32_t num_rows_in, - uint32_t num_columns_in, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - float output_scale_factor, - A*& ptr_inputs, - B*& ptr_outputs) { - InitInterleaveComponentPrivate(cmp, - num_rows_in, - num_columns_in, - num_bytes_per_input, - num_bytes_per_output, - output_scale_factor, - (void*&)ptr_inputs, - (void*&)ptr_outputs, - true); - } - - template - static void InitCopyComponent(intel_dnn_component_t& cmp, - intel_dnn_orientation_t orientation, - uint32_t num_rows_in, - uint32_t num_columns_in, - uint32_t num_rows_out, - uint32_t num_columns_out, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - float output_scale_factor, - uint32_t num_copy_rows, - uint32_t num_copy_columns, - A*& ptr_inputs, - B*& ptr_outputs) { - InitCopyComponentPrivate(cmp, - orientation, - num_rows_in, - num_columns_in, - num_rows_out, - num_columns_out, - num_bytes_per_input, - num_bytes_per_output, - output_scale_factor, - num_copy_rows, - num_copy_columns, - (void*&)ptr_inputs, - (void*&)ptr_outputs, - true); - } - - template - void AdvanceOperationIfAllApplied(const std::vector& cmp, size_t i, T*& operation) { - if (i == cmp.size() - 1 || cmp[i + 1].operation != kDnnPiecewiselinearOp) { - ++operation; - } - } - - template - void AdvanceCnnOperationIfAllApplied(const std::vector& cmp, size_t i, T*& operation) { - if (i == cmp.size() - 1 || - ((cmp[i + 1].operation != kDnnMaxPoolOp) && (cmp[i + 1].operation != kDnnPiecewiselinearOp))) { - operation++; - } - } - - template - void AdvancePwlOperationIfAllApplied(const std::vector& cmp, size_t i, T*& operation) { - if (i == cmp.size() - 1 || - ((cmp[i + 1].operation != kDnnMaxPoolOp) && (cmp[i + 1].operation != kDnnPiecewiselinearOp))) { - operation++; - } - } - - float OutputScaleFactor(uint32_t cmp_index) { - return OutputScaleFactor(component[cmp_index]); - } - - float OutputScaleFactor(intel_dnn_component_t& comp); - - void WriteGraphWizModel(const char* filename); - - void PrintOffset(std::ofstream& out, const std::string& type, void* ptr); - - void WriteDnnText(const char* filename, intel_dnn_number_type_t logging_precision); - - void InitGNAStruct(Gna2Model* gnaModel); - - void DestroyGNAStruct(Gna2Model* gnaModel); - - uint32_t* ptr_active_outputs() { - return (ptr_active_outputs_); - } - - uint32_t num_active_outputs() { - return (num_active_outputs_); - } - - uint32_t num_components(); - - uint32_t num_gna_layers(); - - uint32_t num_group_in(); - - uint32_t num_group_out(); - - uint32_t num_inputs(); - - uint32_t num_outputs(); - - std::vector component; - uint32_t new_num_conv_columns = 0; - bool do_rotate_input; - uint32_t num_rotate_rows = 0; - uint32_t num_rotate_columns = 0; - - void WriteInputAndOutputText(); - - void WriteInputAndOutputTextGNA(const Gna2Model& model); - - void BeginNewWrite(uint32_t index); - -private: - memory::GNAMemoryInterface* memory = nullptr; - uint32_t* ptr_active_outputs_; - uint32_t num_active_outputs_; - intel_dnn_number_type_t compute_precision_; - float input_scale_factor_; - uint32_t dump_write_index = 0; - - uint32_t CountLayers(); - - static void InitCopyComponentPrivate(intel_dnn_component_t& cmp, - intel_dnn_orientation_t orientation, - uint32_t num_rows_in, - uint32_t num_columns_in, - uint32_t num_rows_out, - uint32_t num_columns_out, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - float output_scale_factor, - uint32_t num_copy_rows, - uint32_t num_copy_columns, - void*& ptr_inputs, - void*& ptr_outputs, - bool postInitMem); - - static void InitMaxpoolComponentPrivate(intel_dnn_component_t& cmp, - std::array inCHW, - std::array outCHW, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - std::array poolingWindowXY, - std::array poolingStrideXY, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - bool postInitMem); - - static void InitPiecewiseLinearComponentPrivate(intel_dnn_component_t& cmp, - const DnnActivation& function_id, - intel_dnn_orientation_t orientation, - uint32_t num_rows, - uint32_t num_columns, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - uint32_t num_segments, - float output_scale_factor, - float input_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - gna_pwl_segment_t* ptr_segments, - bool postInitMem); - - static void InitInterleaveComponentPrivate(intel_dnn_component_t& cmp, - uint32_t num_rows_in, - uint32_t num_columns_in, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - bool postInitMem); - - static void InitDeinterleaveComponentPrivate(intel_dnn_component_t& cmp, - uint32_t num_rows_in, - uint32_t num_columns_in, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - bool postInitMem); - - static void InitConvolutional1DComponentPrivate(intel_dnn_component_t& comp, - uint32_t num_columns_in, - uint32_t num_columns_out, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - uint32_t num_bytes_per_weight, - uint32_t num_bytes_per_bias, - uint32_t num_filters, - uint32_t num_filter_coefficients, - uint32_t convStride, - float weight_scale_factor, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - void*& ptr_filters, - void*& ptr_biases, - bool postInitMem); - - static void InitConvolutional2DComponentPrivate(intel_dnn_component_t& comp, - OvGnaTensor inputTensor, - OvGnaTensor outputTensor, - OvGnaTensor filterTensor, - OvGnaTensor biasTensor, - std::array convStride, - std::array zeroPadding, - float weight_scale_factor, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - void*& ptr_filters, - void*& ptr_biases); - - static void InitDWSCComponentPrivate(intel_dnn_component_t& comp, - OvGnaTensor inputTensor, - OvGnaTensor outputTensor, - OvGnaTensor filterTensor, - OvGnaTensor biasTensor, - std::array convStride, - std::array zeroPadding, - float weight_scale_factor, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - void*& ptr_filters, - void*& ptr_biases); - - static void InitAffineComponentPrivate(intel_dnn_component_t& comp, - uint32_t num_rows_in, - uint32_t num_columns, - uint32_t num_rows_out, - uint32_t num_bytes_per_input, - uint32_t num_bytes_per_output, - uint32_t num_bytes_per_weight, - uint32_t num_bytes_per_bias, - float weight_scale_factor, - float output_scale_factor, - void*& ptr_inputs, - void*& ptr_outputs, - void*& ptr_weights, - void*& ptr_biases, - bool isDiag, - bool postInitMem); - - std::string getDumpFilePrefix(const std::string& folder); - std::string getDumpFilePrefixGNA(); - std::string getDumpFolderName(); - std::string getRefFolderName(); -}; - -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/dnn_components.cpp b/src/plugins/intel_gna/src/backend/dnn_components.cpp deleted file mode 100644 index 6e3ea794be5..00000000000 --- a/src/plugins/intel_gna/src/backend/dnn_components.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "dnn_components.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "log/log.hpp" - -namespace ov { -namespace intel_gna { -namespace backend { - -intel_dnn_component_t& DnnComponents::addComponent(const std::string layerName, const std::string layerMetaType) { - auto isDelayed = InferenceEngine::details::CaselessEq()(layerMetaType, DelayedCopyLayerName); - delayedOperations += isDelayed ? 1 : 0; - components.emplace_back(DnnComponentExtra{layerName, {}, isDelayed}); - auto& currentComponent = components.back().dnnComponent; - - log::trace() << "IR layer : " << std::left << std::setw(20) << layerName << " " << layerMetaType << "_" - << components.size() - 1 << std::endl; - - currentComponent.original_layer_name = components.back().name.c_str(); - int execOrder = 0; - if (!isDelayed) { - execOrder = static_cast(components.size() - 1 - delayedOperations); - } else { - // todo: not perfect - propose to create mapping table that will be printed out by extra request - execOrder = -static_cast(delayedOperations); - } - - log::debug() << "IR layer : " << std::left << std::setw(20) << layerName << " " << layerMetaType << "_" << execOrder - << std::endl; - return currentComponent; -} - -intel_dnn_component_t* DnnComponents::findComponent(InferenceEngine::CNNLayerPtr layer) { - if (layer) { - return findComponent(layer->name); - } - - return nullptr; -} - -intel_dnn_component_t* DnnComponents::findComponent(const std::string& layerName) { - auto component = std::find_if(begin(components), end(components), [&](const storage_type ::value_type& comp) { - return comp.name == layerName; - }); - if (component != components.end()) { - return &component->dnnComponent; - } - return nullptr; -} - -const intel_dnn_component_t* DnnComponents::findComponent(const InferenceEngine::CNNLayerPtr layer) const { - if (layer) { - return findComponent(layer->name); - } - - return nullptr; -} - -const intel_dnn_component_t* DnnComponents::findComponent(const std::string& layerName) const { - auto component = std::find_if(begin(components), end(components), [&](const storage_type ::value_type& comp) { - return comp.name == layerName; - }); - if (component != components.end()) { - return &component->dnnComponent; - } - return nullptr; -} - -std::vector DnnComponents::getExecutionOrder() { - std::vector result(components.size()); - - uint32_t direct_id = 0; - uint32_t delayed_id = static_cast(components.size() - delayedOperations); - - for (auto&& c : components) { - uint32_t& id = c.isDelayed ? delayed_id : direct_id; - result[id] = c.dnnComponent; - id++; - } - return result; -} - -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/dnn_components.hpp b/src/plugins/intel_gna/src/backend/dnn_components.hpp deleted file mode 100644 index 265304c8431..00000000000 --- a/src/plugins/intel_gna/src/backend/dnn_components.hpp +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include -#include -#include -#include - -#include "dnn_types.hpp" - -namespace ov { -namespace intel_gna { -namespace backend { - -struct DnnComponentExtra { - std::string name; - intel_dnn_component_t dnnComponent; - bool isDelayed; - DnnComponentExtra(std::string name, const intel_dnn_component_t& dnnComponent, bool isDelayed) - : name(name), - dnnComponent(dnnComponent), - isDelayed(isDelayed) {} -}; - -/** - * maps layer name to dnn.component, in topological order, or execution order - */ -struct DnnComponents { - using storage_type = std::list; - storage_type components; - /** - * @brief initializes new empty intel_dnn_component_t object - * @param layerName - layer name in IR - * @param layerMetaType - usually either gna of original layer type - * @return - */ - intel_dnn_component_t& addComponent(const std::string layerName, const std::string layerMetaType); - /** - * @brief returns corresponding dnn layer for topology layer - * @return - */ - intel_dnn_component_t* findComponent(InferenceEngine::CNNLayerPtr layer); - - /** - * @brief returns Pointer to corresponding dnn layer for topology layer name - * @return - */ - intel_dnn_component_t* findComponent(const std::string& layerName); - - /** - * @brief returns Pointer to const corresponding dnn layer for topology layer - * @return - */ - const intel_dnn_component_t* findComponent(InferenceEngine::CNNLayerPtr layer) const; - - /** - * @brief returns const Pointer to const corresponding dnn layer name for topology layer name - * @return - */ - const intel_dnn_component_t* findComponent(const std::string& layerName) const; - - /** - * @brief extract components in execution order - */ - std::vector getExecutionOrder(); - -private: - uint32_t delayedOperations = 0; -}; - -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/dnn_types.cpp b/src/plugins/intel_gna/src/backend/dnn_types.cpp deleted file mode 100644 index 11aec9d2e7b..00000000000 --- a/src/plugins/intel_gna/src/backend/dnn_types.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "dnn_types.hpp" - -const char* intel_dnn_activation_name[kActNumType] = {"kActNone", - "kActSigmoid", - "kActTanh", - "kActRelu", - "kActLeakyRelu", - "kActIdentity", - "kActKaldiLstmClipping", - "kActCustom", - "kActExp", - "kActLog", - "kActSign", - "kActAbs", - "kActNegLog", - "kActNegHalfLog", - "kActSoftSign", - "kActPow", - "kActFakeQuantize", - "kActPwl"}; - -const char* intel_dnn_operation_name[kDnnNumOp] = {"kDnnNullOp", - "kDnnAffineOp", - "kDnnDiagonalOp", - "kDnnConvolutional1dOp", - "kDnnConvolutional2dOp", - "kDnnPiecewiselinearOp", - "kDnnMaxPoolOp", - "kDnnRecurrentOp", - "kDnnInterleaveOp", - "kDnnDeinterleaveOp", - "kDnnCopyOp"}; - -const char* intel_dnn_number_type_name[kDnnNumNumberType] = {"kDnnFloat", "kDnnInt"}; diff --git a/src/plugins/intel_gna/src/backend/dnn_types.hpp b/src/plugins/intel_gna/src/backend/dnn_types.hpp deleted file mode 100644 index 77a79855724..00000000000 --- a/src/plugins/intel_gna/src/backend/dnn_types.hpp +++ /dev/null @@ -1,267 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include - -#include "gna_types.hpp" -#include "log/debug.hpp" - -enum DnnActivationType : uint8_t { - kActNone, - kActSigmoid, - kActTanh, - kActRelu, - kActLeakyRelu, - kActIdentity, - kActKaldiLstmClipping, - kActCustom, - kActExp, - kActLog, - kActSign, - kActAbs, - kActNegLog, - kActNegHalfLog, - kActSoftSign, - kActPow, - kActFakeQuantize, - kActPwl, - kActNumType -}; - -struct FakeQuantizeParams { - int8_t set; - size_t levels; - // if input is per-channel quantization - input pointers contains per-channel ranges - int8_t inputPerChannel; - float* input_low; - float* input_high; - // if output is per-channel quantization - output pointers contains per-channel ranges - int8_t outputPerChannel; - float* output_low; - float* output_high; -}; - -struct DnnActivation { - // for prelu - DnnActivationType type; - FakeQuantizeParams fqParams; - FakeQuantizeParams srcFQParams; - - union { - struct { - float negative_slope; - } lrelu; - struct { - float exponent; - float scale; - float offset; - } pow; - struct { - float low; - float high; - } clamp; - } args; - operator DnnActivationType() const noexcept { - return type; - } - static DnnActivation fromType(DnnActivationType type) { - DnnActivation activation{}; - activation.type = type; - activation.args = {}; - return activation; - } -}; - -static_assert(std::is_trivial::value, "DnnActivation is not trival type"); - -extern const char* intel_dnn_activation_name[kActNumType]; - -typedef enum { - kDnnUnknownOrientation = 100, - kDnnInterleavedOrientation, - kDnnNonInterleavedOrientation, - kDnnNumOrientation -} intel_dnn_orientation_t; - -typedef enum { - kDnnNullOp, - kDnnAffineOp, - kDnnDiagonalOp, - kDnnConvolutional1dOp, - kDnnConvolutional2dOp, - kDnnPiecewiselinearOp, - kDnnMaxPoolOp, - kDnnRecurrentOp, - kDnnInterleaveOp, - kDnnDeinterleaveOp, - kDnnCopyOp, - kDnnNumOp -} intel_dnn_operation_t; - -extern const char* intel_dnn_operation_name[kDnnNumOp]; - -typedef enum { kDnnFloat, kDnnInt, kDnnNumNumberType } intel_dnn_number_type_t; - -extern const char* intel_dnn_number_type_name[kDnnNumNumberType]; - -typedef struct { - uint32_t num_bytes_per_weight; - uint32_t num_bytes_per_bias; - float weight_scale_factor; - void* ptr_weights; - void* ptr_biases; -} intel_affine_t; - -typedef struct { - uint32_t num_bytes_per_weight; - uint32_t num_bytes_per_bias; - uint32_t num_filters; - uint32_t num_filter_coefficients; - uint32_t convStride; - float weight_scale_factor; - void* ptr_filters; // filters stored one after the other - void* ptr_biases; -} intel_convolutional1D_t; - -typedef struct { - std::array convStride; - std::array zeroPadding; - float weight_scale_factor; - void* ptr_filters; // filters stored one after the other - void* ptr_biases; -} intel_convolutional2D_t; - -typedef struct { - std::array poolingWindowXY; - std::array poolingStrideXY; - std::array inCHW; - std::array outCHW; -} intel_maxpool_t; - -typedef struct { - DnnActivation func_id; // identifies function being approximated - uint32_t num_segments; - gna_pwl_segment_t* ptr_segments; -} intel_piecewiselinear_t; - -typedef struct { - uint32_t num_vector_delay; - uint32_t num_bytes_per_weight; - uint32_t num_bytes_per_bias; - float weight_scale_factor; - void* ptr_feedbacks; - void* ptr_weights; - void* ptr_biases; -} intel_recurrent_t; - -typedef struct { -} intel_interleave_t; - -typedef struct { -} intel_deinterleave_t; - -typedef struct { - uint32_t num_copy_columns; // number of columns to copy - uint32_t num_copy_rows; // number of rows to copy -} intel_copy_t; - -enum OvGnaType { - OvGnaTypeInt8 = 1, - OvGnaTypeInt16 = 2, - OvGnaTypeInt32 = 4, - OvGnaTypePwl = 8, -}; - -template -OvGnaType OvGnaTypeIntFromBytes(T bytesPerElement) { - static const std::map m = {{1, OvGnaTypeInt8}, {2, OvGnaTypeInt16}, {4, OvGnaTypeInt32}}; - const auto r = m.find(bytesPerElement); - if (r == m.end()) { - THROW_GNA_EXCEPTION << "OvGnaTypeIntFromBytes: unknown bytesPerElement == " << bytesPerElement; - } - return r->second; -} - -enum OvGnaMode { OvGnaModeDefault = 0, OvGnaModeDisabled = -1 }; - -struct OvGnaTensor { - std::vector dimensions; - OvGnaType type; - OvGnaMode mode; -}; - -inline std::string OvGnaTypeToString(OvGnaType type) { - static const std::map typeToString = { - {OvGnaTypeInt8, "OvGnaTypeInt8"}, - {OvGnaTypeInt16, "OvGnaTypeInt16"}, - {OvGnaTypeInt32, "OvGnaTypeInt32"}, - {OvGnaTypePwl, "OvGnaTypePwl"}, - }; - const auto r = typeToString.find(type); - if (r == typeToString.end()) { - THROW_GNA_EXCEPTION << "OvGnaTypeToString: unknown type == " << type; - } - return r->second; -} - -inline std::string OvGnaModeToString(OvGnaMode mode) { - static const std::map modeToString = { - {OvGnaModeDefault, "OvGnaModeDefault"}, - {OvGnaModeDisabled, "OvGnaModeDisabled"}, - }; - const auto r = modeToString.find(mode); - if (r == modeToString.end()) { - THROW_GNA_EXCEPTION << "OvGnaModeToString: unknown mode == " << mode; - } - return r->second; -} - -struct intel_dnn_component_t { - std::vector tensors; - uint32_t num_rows_in; - uint32_t num_columns_in; - uint32_t num_rows_out; - uint32_t num_columns_out; - uint32_t num_bytes_per_input; - uint32_t num_bytes_per_output; - intel_dnn_operation_t operation; - intel_dnn_orientation_t orientation_in; - intel_dnn_orientation_t orientation_out; - union operation_struct_t { - intel_affine_t affine; - intel_convolutional1D_t conv1D; - intel_convolutional2D_t conv2D; - intel_maxpool_t maxpool; - intel_piecewiselinear_t pwl; - intel_recurrent_t recurrent; - intel_interleave_t interleave; - intel_deinterleave_t deinterleave; - intel_copy_t copy; - } op; - void* ptr_inputs; - void* ptr_outputs; - float output_scale_factor; - float input_scale_factor; - const char* original_layer_name = nullptr; -}; - -struct intel_score_error_t { - uint32_t num_scores; - uint32_t num_errors; - float threshold; - float max_error; - float rms_error; - float sum_error; - float sum_rms_error; - float sum_squared_error; - float max_rel_error; - float sum_rel_error; - float sum_squared_rel_error; -}; diff --git a/src/plugins/intel_gna/src/backend/gna_limitations.cpp b/src/plugins/intel_gna/src/backend/gna_limitations.cpp deleted file mode 100644 index 276ea7c5f2f..00000000000 --- a/src/plugins/intel_gna/src/backend/gna_limitations.cpp +++ /dev/null @@ -1,1187 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "gna_limitations.hpp" - -#include - -#include -#include -#include -#include -#include - -#include "common/gna_target.hpp" -#include "common/graph_utils.hpp" -#include "gna/gna_config.hpp" -#include "gna_graph_tools.hpp" -#include "gna_lib_ver_selector.hpp" -#include "ie_ngraph_utils.hpp" -#include "log/log.hpp" -#include "openvino/opsets/opset12.hpp" - -namespace std { -inline std::ostream& operator<<(std::ostream& os, const std::set& t) { - for (auto it = t.begin(); it != t.end(); ++it) { - if (it != t.begin()) { - os << ", " << *it; - } else { - os << *it; - } - } - return os; -} -} // namespace std - -namespace ov { -namespace intel_gna { -using namespace target; -using namespace opset12; -namespace limitations { - -class SupportedElementTypes { -public: - static bool IsParameterTypeSupported(ov::element::Type type, bool is_exception_allowed = false); - static bool IsConstantTypeSupported(ov::element::Type type, bool is_exception_allowed = false); - -private: - static const std::set supported_parameter_types; - static const std::set supported_constant_types; -}; - -const std::set SupportedElementTypes::supported_parameter_types = {ov::element::u8, - ov::element::i16, - ov::element::f32}; - -namespace cnn2d { - -bool IsEqualToLimit::IsValid(const uint32_t val) const { - return val == compared_value; -} - -std::string IsEqualToLimit::GetErrorOrEmpty(const uint32_t val) const { - std::ostringstream out; - if (!IsValid(val)) { - out << "Unsupported " << what << ", actual value: " << val << ", but should be equal to " << compared_value - << "\n"; - } - return out.str(); -} - -bool IsLessThanLimit::IsValid(const uint32_t val) const { - return val < compared_value; -} - -std::string IsLessThanLimit::GetErrorOrEmpty(const uint32_t val) const { - std::ostringstream out; - if (!IsValid(val)) { - out << "Unsupported " << what << ", actual value: " << val << ", but should be less than " << compared_value - << "\n"; - } - return out.str(); -} - -bool RangeLimit::IsValid(const uint32_t val) const { - return val >= min && val <= max; -} - -std::string RangeLimit::GetErrorOrEmpty(const uint32_t val) const { - std::ostringstream out; - if (!IsValid(val)) { - out << "Unsupported " << what << ", actual value: " << val << ", valid range [" << min << ", " << max << "]\n"; - } - return out.str(); -} - -bool RangeLimit2D::IsValid(const uint32_t h, const uint32_t w) const { - return hLimit.IsValid(h) && wLimit.IsValid(w); -} - -std::string RangeLimit2D::GetErrorOrEmpty(const uint32_t h, const uint32_t w) const { - return hLimit.GetErrorOrEmpty(h) + wLimit.GetErrorOrEmpty(w); -} - -RangeMultipleLimit::RangeMultipleLimit(RangeLimit rlIn, uint32_t multiplierIn) - : RangeLimit(rlIn), - multiplier(multiplierIn) {} - -bool RangeMultipleLimit::IsValid(const uint32_t val) const { - return RangeLimit::IsValid(val) && (val % multiplier == 0); -} - -std::string RangeMultipleLimit::GetErrorOrEmpty(const uint32_t val) const { - auto e = RangeLimit::GetErrorOrEmpty(val); - std::ostringstream out; - if (val % multiplier != 0) { - out << "Unsupported " << what << ": " << val << ", must be multiple of " << multiplier << "\n"; - } - return e + out.str(); -} - -bool VectorOrSquareLimit::IsValid(const uint32_t h, const uint32_t w) const { - if (w == 1 && h >= 1 && h <= maxVectorHeight) - return true; - if (h == 1 && w >= 1 && w <= maxVectorWidth) - return true; - if (h == w && h <= maxSquare && h >= 1) - return true; - return false; -} - -std::string VectorOrSquareLimit::GetErrorOrEmpty(const uint32_t h, const uint32_t w, std::string what) const { - std::ostringstream out; - if (!IsValid(h, w)) { - out << "Unsupported " << what << " shape, actual HxW: " << h << "x" << w << ", only vertical vector up to " - << maxVectorHeight << "x1, horizontal up to 1x" << maxVectorWidth << " or square up to " << maxSquare << "x" - << maxSquare << " are valid\n"; - } - return out.str(); -} - -bool RectLimit::IsValid(const uint32_t h, const uint32_t w) const { - if (h >= 1 && h <= maxVectorHeight && w >= 1 && w <= maxVectorWidth) - return true; - return false; -} - -std::string RectLimit::GetErrorOrEmpty(const uint32_t h, const uint32_t w, std::string what) const { - std::ostringstream out; - if (!IsValid(h, w)) { - out << "Unsupported " << what << " shape, actual HxW: " << h << "x" << w << ", only rectangular shapes up to " - << maxVectorHeight << "x" << maxVectorWidth << " are valid\n"; - } - return out.str(); -} - -RectLimit RectLimitByChannels::GetByChannels(const uint32_t channels) const { - for (auto&& limit : limitPerChannel) { - if (limit.first >= channels) { - return limit.second; - } - } - return RectLimit{0, 0}; -} - -bool RectLimitByChannels::IsValid(const uint32_t h, const uint32_t w, const uint32_t channels) const { - return GetByChannels(channels).IsValid(h, w); -} - -std::string RectLimitByChannels::GetErrorOrEmpty(const uint32_t h, - const uint32_t w, - const uint32_t channels, - std::string what) const { - return GetByChannels(channels).GetErrorOrEmpty(h, w, what); -} - -RectLimitByChannels RectLimitByChannelsAndPrecision::GetByPrecision(const OvGnaType precision) const { - return precision == OvGnaTypeInt8 ? limit_for_int8 : limit_for_int16; -} - -bool RectLimitByChannelsAndPrecision::IsValid(const uint32_t h, - const uint32_t w, - const OvGnaType precision, - const uint32_t channels) const { - return GetByPrecision(precision).IsValid(h, w, channels); -} - -std::string RectLimitByChannelsAndPrecision::GetErrorOrEmpty(const uint32_t h, - const uint32_t w, - const OvGnaType precision, - const uint32_t channels, - std::string what) const { - return GetByPrecision(precision).GetErrorOrEmpty(h, w, channels, what); -} - -class Validator_30 : public AbstractValidator { - static const RangeLimit2D kInputHWLimit; - static const RangeMultipleLimit kInputChannelsNumberLimit; - - static const RangeMultipleLimit kKernelNumberLimit; - static const RectLimitByChannelsAndPrecision kKernelLimit; - static const RangeLimit2D kDilationLimit; - - static const VectorOrSquareLimit kPoolingWindowLimit; - -public: - Validator_30() = default; - - bool ValidateCnn2D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kH, - const uint32_t kW, - const uint32_t kN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - OvGnaType inPrecision, - bool exception = true) const override; - - bool ValidatePooling2D(const std::string& name, - const uint32_t windowH, - const uint32_t windowW, - const uint32_t strideH, - const uint32_t strideW, - bool exception = true) const override; - - bool ValidateInputPadding(const std::string& name, - const uint32_t pad_h_begin, - const uint32_t pad_h_end, - const uint32_t pad_w_begin, - const uint32_t pad_w_end, - const uint32_t kernel_h, - const uint32_t kernel_w, - const bool throwOnError = true) const override; - - bool ShouldUseOnlyConv2DGnaIface() const override; - - bool ValidateCnn1D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kH, - const uint32_t kW, - const uint32_t kN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - OvGnaType inPrecision, - bool exception = true) const override; -}; - -const RangeLimit2D Validator_30::kInputHWLimit{{16, 384, "input height"}, {16, 240, "input width"}}; -const RangeMultipleLimit Validator_30::kInputChannelsNumberLimit{{8, 384, "number of input channels"}, 8}; - -const RangeMultipleLimit Validator_30::kKernelNumberLimit{{8, 1024, "number of kernels"}, 8}; -const RectLimitByChannelsAndPrecision Validator_30::kKernelLimit{ - {{{96, {7, 7}}, {136, {7, 5}}, {168, {7, 4}}, {240, {7, 3}}, {384, {7, 2}}}}, - {{{48, {7, 7}}, {64, {7, 5}}, {80, {7, 4}}, {120, {7, 3}}, {384, {7, 1}}}}, -}; - -const RangeLimit2D Validator_30::kDilationLimit{ - {Limitations::kConvDilationHeight, Limitations::kConvDilationHeight, "dilation height"}, - {Limitations::kConvDilationWidth, Limitations::kConvDilationWidth, "dilation width"}}; - -bool Validator_30::ValidateCnn2D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kernelH, - const uint32_t kernelW, - const uint32_t kernelN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - const OvGnaType inPrecision, - const bool throwOnError) const { - const auto& kStrideLimit = kKernelLimit; - auto error = kInputHWLimit.GetErrorOrEmpty(inHeight, inWidth); - - error += kKernelNumberLimit.GetErrorOrEmpty(kernelN); - error += kInputChannelsNumberLimit.GetErrorOrEmpty(inChannels); - error += kKernelLimit.GetErrorOrEmpty(kernelH, kernelW, inPrecision, inChannels, "kernel"); - error += kStrideLimit.GetErrorOrEmpty(strideH, strideW, inPrecision, inChannels, "convolution stride"); - - const RangeLimit kKernelStrideHLimit{1, kernelH, "kernel stride height (must be up to kernel height)"}; - const RangeLimit kKernelStrideWLimit{1, kernelW, "kernel stride width (must be up to kernel width)"}; - - error += kKernelStrideHLimit.GetErrorOrEmpty(strideH); - error += kKernelStrideWLimit.GetErrorOrEmpty(strideW); - - error += kDilationLimit.GetErrorOrEmpty(dilationH, dilationW); - - return ValidationSuccesful(throwOnError, error, name, "Convolution2D"); -} - -bool Validator_30::ValidateCnn1D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kH, - const uint32_t kW, - const uint32_t kN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - OvGnaType inPrecision, - bool exception) const { - return false; -} - -const VectorOrSquareLimit Validator_30::kPoolingWindowLimit{3, 1, 1}; - -bool Validator_30::ValidatePooling2D(const std::string& name, - const uint32_t windowH, - const uint32_t windowW, - const uint32_t strideH, - const uint32_t strideW, - const bool throwOnError) const { - auto error = kPoolingWindowLimit.GetErrorOrEmpty(windowH, windowW, "pooling window"); - const RangeLimit poolingStrideHLimit{1, windowH, "pooling stride height (must be up to pooling window height)"}; - const RangeLimit poolingStrideWLimit{1, windowW, "pooling stride width (must be up to pooling window width)"}; - - error += poolingStrideHLimit.GetErrorOrEmpty(strideH); - error += poolingStrideWLimit.GetErrorOrEmpty(strideW); - - return ValidationSuccesful(throwOnError, error, name, "Pooling2D"); -} - -bool Validator_30::ValidateInputPadding(const std::string& name, - const uint32_t pad_h_begin, - const uint32_t pad_h_end, - const uint32_t pad_w_begin, - const uint32_t pad_w_end, - const uint32_t, - const uint32_t, - const bool throwOnError) const { - const IsEqualToLimit padding_zero{0, "convolution input padding size (must equal zero)"}; - auto error = padding_zero.GetErrorOrEmpty(pad_h_begin); - error += padding_zero.GetErrorOrEmpty(pad_h_end); - error += padding_zero.GetErrorOrEmpty(pad_w_begin); - error += padding_zero.GetErrorOrEmpty(pad_w_end); - return ValidationSuccesful(throwOnError, error, name, "Convolution2D"); -} - -bool Validator_30::ShouldUseOnlyConv2DGnaIface() const { - return false; -} - -class Validator_35 : public AbstractValidator { - struct CnnLimits { - const RangeLimit2D kInputHWLimit; - const RangeLimit kInputChannelsNumberLimit1B; - const RangeLimit kInputChannelsNumberLimit2B; - const RangeLimit kKernelNumberLimit; - const RangeLimit2D kKerneHWlLimit1B; - const RangeLimit2D kKerneHWlLimit2B; - const RangeLimit2D kStrideHWLimit1B; - const RangeLimit2D kStrideHWLimit2B; - const RangeLimit2D kDilationLimit; - const RangeLimit2D kPoolingWindowHWLimit; - const RangeLimit2D kPoolingStrideHWLimit; - }; - - static const CnnLimits kCnn2DLimits; - static const CnnLimits kCnn1DLimits; - - std::string ValidateCnn(const CnnLimits& limits, - const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kH, - const uint32_t kW, - const uint32_t kN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - OvGnaType inPrecision) const; - - std::string ValidatePooling(const CnnLimits& limits, - const std::string& name, - const uint32_t windowH, - const uint32_t windowW, - const uint32_t strideH, - const uint32_t strideW) const; - -public: - Validator_35() = default; - - bool ValidateCnn2D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kH, - const uint32_t kW, - const uint32_t kN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - OvGnaType inPrecision, - bool exception = true) const override; - - bool ValidatePooling2D(const std::string& name, - const uint32_t windowH, - const uint32_t windowW, - const uint32_t strideH, - const uint32_t strideW, - bool exception = true) const override; - - bool ValidateInputPadding(const std::string& name, - const uint32_t pad_h_begin, - const uint32_t pad_h_end, - const uint32_t pad_w_begin, - const uint32_t pad_w_end, - const uint32_t kernel_h, - const uint32_t kernel_w, - const bool throwOnError = true) const override; - - bool ShouldUseOnlyConv2DGnaIface() const override; - - bool ValidateCnn1D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kH, - const uint32_t kW, - const uint32_t kN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - OvGnaType inPrecision, - bool exception = true) const override; -}; - -const Validator_35::CnnLimits Validator_35::kCnn2DLimits{ - {{1, 65535, "input height"}, {1, 65535, "input width"}}, // kInputHWLimit - {1, 2048, "number of input channels"}, // kInputChannelsNumberLimit1B - {1, 1024, "number of input channels"}, // kInputChannelsNumberLimit2B - {1, 8192, "number of kernels"}, // kKernelNumberLimit - {{1, 255, "kernel height"}, {1, 256, "kernel width"}}, // kKerneHWlLimit1B - {{1, 255, "kernel height"}, {1, 256, "kernel width"}}, // kKerneHWlLimit2B - {{1, 255, "convolution stride height"}, {1, 256, "convolution stride width"}}, // kStrideHWLimit1B - {{1, 255, "convolution stride height"}, {1, 256, "convolution stride width"}}, // kStrideHWLimit2B - {{Limitations::kConvDilationHeight, Limitations::kConvDilationHeight, "dilation height"}, // kDilationLimit - {Limitations::kConvDilationWidth, Limitations::kConvDilationWidth, "dilation width"}}, - {{1, 255, "pooling window height"}, {1, 255, "pooling window width"}}, // kPoolingWindowHWLimit - {{1, 255, "pooling stride height"}, {1, 255, "pooling stride width"}} // kPoolingStrideHWLimit -}; - -const Validator_35::CnnLimits Validator_35::kCnn1DLimits{ - {{1, 1, "input height"}, {1, 65535, "input width"}}, // kInputHWLimit - {1, 1, "number of input channels"}, // kInputChannelsNumberLimit1B - {1, 1, "number of input channels"}, // kInputChannelsNumberLimit2B - {1, 8192, "number of kernels"}, // kKernelNumberLimit - {{1, 1, "kernel height"}, {1, 4096, "kernel width"}}, // kKerneHWlLimit1B - {{1, 1, "kernel height"}, {1, 2048, "kernel width"}}, // kKerneHWlLimit2B - {{1, 1, "convolution stride height"}, {1, 4096, "convolution stride width"}}, // kStrideHWLimit1B - {{1, 1, "convolution stride height"}, {1, 2048, "convolution stride width"}}, // kStrideHWLimit2B - {{Limitations::kConvDilationHeight, Limitations::kConvDilationHeight, "dilation height"}, // kDilationLimit - {Limitations::kConvDilationWidth, Limitations::kConvDilationWidth, "dilation width"}}, - {{1, 1, "pooling window height"}, {1, 255, "pooling window width"}}, // kPoolingWindowHWLimit - {{1, 1, "pooling stride height"}, {1, 255, "pooling stride width"}} // kPoolingStrideHWLimit -}; - -std::string Validator_35::ValidateCnn(const Validator_35::CnnLimits& limits, - const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kernelH, - const uint32_t kernelW, - const uint32_t kernelN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - const OvGnaType inPrecision) const { - auto error = limits.kInputHWLimit.GetErrorOrEmpty(inHeight, inWidth); - error += limits.kKernelNumberLimit.GetErrorOrEmpty(kernelN); - auto& inputChannelsNumberLimit = - (inPrecision == OvGnaTypeInt8) ? limits.kInputChannelsNumberLimit1B : limits.kInputChannelsNumberLimit2B; - error += inputChannelsNumberLimit.GetErrorOrEmpty(inChannels); - auto& kerneHWlLimit = (inPrecision == OvGnaTypeInt8) ? limits.kKerneHWlLimit1B : limits.kKerneHWlLimit2B; - error += kerneHWlLimit.GetErrorOrEmpty(kernelH, kernelW); - auto& strideHWLimit = (inPrecision == OvGnaTypeInt8) ? limits.kStrideHWLimit1B : limits.kStrideHWLimit2B; - error += strideHWLimit.GetErrorOrEmpty(strideH, strideW); - - const RangeLimit kKernelStrideHLimit{1, kernelH, "kernel stride height (must be up to kernel height)"}; - const RangeLimit kKernelStrideWLimit{1, kernelW, "kernel stride width (must be up to kernel width)"}; - - error += kKernelStrideHLimit.GetErrorOrEmpty(strideH); - error += kKernelStrideWLimit.GetErrorOrEmpty(strideW); - - error += limits.kDilationLimit.GetErrorOrEmpty(dilationH, dilationW); - return error; -} - -bool Validator_35::ValidateCnn2D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kernelH, - const uint32_t kernelW, - const uint32_t kernelN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - const OvGnaType inPrecision, - const bool throwOnError) const { - auto error = ValidateCnn(kCnn2DLimits, - name, - inHeight, - inWidth, - inChannels, - kernelH, - kernelW, - kernelN, - strideH, - strideW, - dilationH, - dilationW, - inPrecision); - return ValidationSuccesful(throwOnError, error, name, "Convolution2D"); -} - -bool Validator_35::ValidateCnn1D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kernelH, - const uint32_t kernelW, - const uint32_t kernelN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - const OvGnaType inPrecision, - const bool throwOnError) const { - auto error = ValidateCnn(kCnn1DLimits, - name, - inHeight, - inWidth, - inChannels, - kernelH, - kernelW, - kernelN, - strideH, - strideW, - dilationH, - dilationW, - inPrecision); - return ValidationSuccesful(throwOnError, error, name, "Convolution1D"); -} - -std::string Validator_35::ValidatePooling(const CnnLimits& limits, - const std::string& name, - const uint32_t windowH, - const uint32_t windowW, - const uint32_t strideH, - const uint32_t strideW) const { - auto error = limits.kPoolingWindowHWLimit.GetErrorOrEmpty(windowH, windowW); - error += limits.kPoolingStrideHWLimit.GetErrorOrEmpty(strideH, strideW); - - const RangeLimit poolingStrideHLimit{1, windowH, "pooling stride height (must be up to pooling window height)"}; - const RangeLimit poolingStrideWLimit{1, windowW, "pooling stride width (must be up to pooling window width)"}; - - error += poolingStrideHLimit.GetErrorOrEmpty(strideH); - error += poolingStrideWLimit.GetErrorOrEmpty(strideW); - - return error; -} - -bool Validator_35::ValidatePooling2D(const std::string& name, - const uint32_t windowH, - const uint32_t windowW, - const uint32_t strideH, - const uint32_t strideW, - const bool throwOnError) const { - auto error = ValidatePooling(kCnn2DLimits, name, windowH, windowW, strideH, strideW); - return ValidationSuccesful(throwOnError, error, name, "Pooling2D"); -} - -bool Validator_35::ValidateInputPadding(const std::string& name, - const uint32_t pad_h_begin, - const uint32_t pad_h_end, - const uint32_t pad_w_begin, - const uint32_t pad_w_end, - const uint32_t kernel_h, - const uint32_t kernel_w, - const bool throwOnError) const { - const IsEqualToLimit padding_h_symetric{pad_h_end, - "convolution input padding along height axis (must be symmetric)"}; - const IsEqualToLimit padding_w_symetric{pad_w_end, - "convolution input padding along width axis (must be symmetric)"}; - - const IsLessThanLimit padding_h_limit{kernel_h, - "convolution input padding height (must be less than kernel height)"}; - const IsLessThanLimit padding_w_limit{kernel_w, "convolution input padding width (must be less than kernel width)"}; - - auto error = padding_h_symetric.GetErrorOrEmpty(pad_h_begin); - error += padding_w_symetric.GetErrorOrEmpty(pad_w_begin); - - error += padding_h_limit.GetErrorOrEmpty(pad_h_begin); - error += padding_w_limit.GetErrorOrEmpty(pad_w_begin); - - return ValidationSuccesful(throwOnError, error, name, "Convolution2D"); -} - -bool Validator_35::ShouldUseOnlyConv2DGnaIface() const { - return true; -} - -std::shared_ptr AbstractValidator::Create(const DeviceVersion& target) { - switch (target) { - case DeviceVersion::GNA3_0: - case DeviceVersion::GNA3_1: - return std::make_shared(); - case DeviceVersion::GNA3_5: - case DeviceVersion::GNAEmbedded3_5: - case DeviceVersion::GNA3_6: - case DeviceVersion::GNA4_0: - return std::make_shared(); - default: - return nullptr; - } -} - -void AbstractValidator::ThrowIfNotEmpty(const std::string& prefix, const std::string& error) { - if (!error.empty()) { - THROW_GNA_EXCEPTION << prefix << error; - } -} - -bool AbstractValidator::ValidationSuccesful(const bool throwOnError, - const std::string& error, - const std::string& operationName, - const std::string& type) { - if (throwOnError) { - const std::string prefix = "Layer " + type + ": " + operationName + ":"; - ThrowIfNotEmpty(prefix, error); - } - - return error.empty(); -} - -} // namespace cnn2d - -constexpr uint32_t Limitations::kBufferMaxSize; -constexpr uint32_t Limitations::kConvMinFiltersNum; -constexpr uint32_t Limitations::kConvMaxFiltersNum; -constexpr uint32_t Limitations::kConvDilationHeight; -constexpr uint32_t Limitations::kConvDilationWidth; -constexpr uint32_t Limitations::kConvFiltersNumDivider; -constexpr uint32_t Limitations::kConvFilterSizeDivider; -constexpr uint32_t Limitations::kConvFilterMaxSize; -constexpr uint32_t Limitations::kConvEachKernelByteAlignment; -constexpr uint32_t Limitations::kNoOfInputsDivisor; -constexpr uint32_t Limitations::kNoOfInputsLowPrecDivisor; -constexpr uint32_t Limitations::kAffineMaxBatchSize; -constexpr uint32_t Limitations::kMaxPoolMaxWindowSize; -constexpr uint32_t Limitations::kCopyMaxGrouping; -constexpr uint32_t Limitations::kTransposeMaxSize; -constexpr uint32_t Limitations::kMaxLayersCountGNA1_0; -constexpr uint32_t Limitations::kMaxLayersCountGNA2_0; -constexpr uint32_t Limitations::kMaxLayersCountGNA3_X; -constexpr uint32_t Limitations::kBytesPerSplitElement; -constexpr uint32_t Limitations::kBytesPerCropElement; -constexpr uint32_t Limitations::kBytesPerConcatElement; -constexpr uint32_t Limitations::kMemoryPageSize; - -ov::threading::ThreadLocal> Limitations::kInstance{nullptr}; - -Limitations::Limitations(const DeviceVersion& target) { - m_use_only_16bit_conv_weights = - (target == DeviceVersion::GNA1_0 || target == DeviceVersion::GNAEmbedded1_0 || - target == DeviceVersion::GNA2_0 || target == DeviceVersion::GNA3_0 || target == DeviceVersion::GNA3_1); - - m_mem_alignment = get_memory_alignment_bytes(target); - m_cnn_validator = cnn2d::AbstractValidator::Create(target); -} - -void Limitations::init(const DeviceVersion& compile_target) { - auto& localInstance = kInstance.local(); - localInstance.reset(new Limitations(compile_target)); -} - -void Limitations::deinit() { - auto& localInstance = kInstance.local(); - localInstance.reset(); -} - -size_t Limitations::get_min_batch_to_fit_in_buffer(InferenceEngine::DataPtr input) { - auto total_size = InferenceEngine::details::product(std::begin(input->getDims()), std::end(input->getDims())); - return total_size / kBufferMaxSize + 1; -} - -size_t Limitations::get_memory_alignment_bytes(const DeviceVersion& target) const { - static const std::unordered_map mem_alignment_map{{DeviceVersion::GNA1_0, 64}, - {DeviceVersion::GNAEmbedded1_0, 64}, - {DeviceVersion::GNA2_0, 64}, - {DeviceVersion::GNA3_0, 64}, - {DeviceVersion::GNA3_1, 64}, - {DeviceVersion::GNA3_5, 64}, - {DeviceVersion::GNAEmbedded3_5, 64}, - {DeviceVersion::GNA3_6, 16}, - {DeviceVersion::GNA4_0, 16}}; - - return common::GetValueForKey(target, mem_alignment_map); -} - -bool SupportedElementTypes::IsParameterTypeSupported(ov::element::Type elem_type, bool is_exception_allowed) { - if (supported_parameter_types.count(elem_type) == 0) { - if (is_exception_allowed) { - THROW_GNA_EXCEPTION << "The plugin does not support input precision with " << elem_type.get_type_name() - << " format. Supported precisions " << supported_parameter_types << "\n"; - } - return false; - } - return true; -} - -const std::set SupportedElementTypes::supported_constant_types = {ov::element::i8, - ov::element::u8, - ov::element::i16, - ov::element::u16, - ov::element::i32, - ov::element::f32, - ov::element::f64}; - -bool SupportedElementTypes::IsConstantTypeSupported(ov::element::Type elem_type, bool is_exception_allowed) { - if (supported_constant_types.count(elem_type) == 0) { - if (is_exception_allowed) { - THROW_GNA_EXCEPTION << "The plugin does not support constant precision with " << elem_type.get_type_name() - << " format. Supported precisions " << supported_constant_types << "\n"; - } - return false; - } - return true; -} - -bool Limitations::is_transpose_supported(const ov::Shape& shape) { - const ov::Shape squeezed_shape = graph_utils::squeeze_shape(shape); - - // GNA transpose limitations: - // - supports 2d transposes only - // - smaller dimension should be less or equal to 8 - // - bigger dimension should be a multiple of limitations::noOfInputsDivisor - if (squeezed_shape.size() == 2) { - const size_t min_input_dim = std::min(squeezed_shape[0], squeezed_shape[1]); - const size_t max_input_dim = std::max(squeezed_shape[0], squeezed_shape[1]); - if (min_input_dim <= 8 && max_input_dim % Limitations::kNoOfInputsDivisor == 0 && - max_input_dim <= kTransposeMaxSize) { - return true; - } - } else if (graph_utils::is_one_dim_shape(squeezed_shape)) { - // it means that transpose input has only one dimension > 1 - return true; - } - return false; -} - -bool Limitations::is_transpose_supported(const std::shared_ptr& node) { - OPENVINO_ASSERT(node, "Transpose node is empty!"); - return is_transpose_supported(node->get_input_shape(0)); -} - -bool Limitations::is_conv_supported(const std::shared_ptr& conv_gna, - const InferenceEngine::Precision gna_precision, - bool is_exception_allowed) { - OPENVINO_ASSERT(conv_gna, "GNAConvolution node is empty!"); - size_t batch_size = conv_gna->input_value(0).get_shape()[0]; - if (batch_size != 1) { - if (is_exception_allowed) { - THROW_GNA_EXCEPTION << "topology with layer: " + conv_gna->get_friendly_name() + - ", type: " + conv_gna->get_type_name() + ", and batch size(" + - std::to_string(batch_size) + ") != 1 not supported"; - } - return false; - } - auto check_dilation = [&](size_t filter_dilation_height, size_t filter_stride_width) -> bool { - cnn2d::RangeLimit2D dilation_limit{{kConvDilationHeight, kConvDilationHeight, "dilation height"}, - {kConvDilationWidth, kConvDilationWidth, "dilation width"}}; - std::string error = dilation_limit.GetErrorOrEmpty(static_cast(filter_dilation_height), - static_cast(filter_stride_width)); - return cnn2d::AbstractValidator::ValidationSuccesful(is_exception_allowed, - error, - conv_gna->get_friendly_name(), - conv_gna->get_type_name()); - }; - auto input_shape = conv_gna->input_value(0).get_shape(); - auto filter_shape = conv_gna->input_value(1).get_shape(); - if ((4 == filter_shape.size() && filter_shape[1] > 1 && filter_shape[2] > 1) || - (4 == input_shape.size() && input_shape[1] > 1 && input_shape[2] > 1)) { - pass::helper::ConvData conv_data; - pass::helper::GetConvData(conv_gna, conv_data); - if (gna_convolution_layer::isMappableFrom2DTo1D(static_cast(conv_data.input_height), - static_cast(conv_data.input_width), - static_cast(conv_data.input_channel_count), - static_cast(conv_data.filter_height), - static_cast(conv_data.filter_width), - static_cast(conv_data.filter_stride_height), - static_cast(conv_data.filter_stride_width))) { - return check_dilation(conv_data.filter_dilation_height, conv_data.filter_dilation_width); - } - - if (m_cnn_validator) { - return m_cnn_validator->ValidateCnn2D(conv_gna->get_friendly_name(), - static_cast(conv_data.input_height), - static_cast(conv_data.input_width), - static_cast(conv_data.input_channel_count), - static_cast(conv_data.filter_height), - static_cast(conv_data.filter_width), - static_cast(conv_data.filter_channel_count), - static_cast(conv_data.filter_stride_height), - static_cast(conv_data.filter_stride_width), - static_cast(conv_data.filter_dilation_height), - static_cast(conv_data.filter_dilation_width), - OvGnaTypeIntFromBytes(gna_precision.size()), - is_exception_allowed); - } - } - - return check_dilation(conv_gna->get_dilations()[0], - conv_gna->get_dilations()[conv_gna->get_dilations().size() - 1]); -} - -bool Limitations::is_pooling_supported(const std::shared_ptr max_pool, - bool is_exception_allowed) { - OPENVINO_ASSERT(max_pool, "MaxPool node is empty!"); - auto kernels = max_pool->get_kernel(); - if (2 == kernels.size() && kernels[0] > 1 && kernels[1] > 1) { - if (m_cnn_validator) { - auto strides = max_pool->get_strides(); - return m_cnn_validator->ValidatePooling2D(max_pool->get_friendly_name(), - static_cast(kernels[0]), - static_cast(kernels[1]), - static_cast(strides[0]), - static_cast(strides[1]), - is_exception_allowed); - } - } - return true; -} - -bool Limitations::is_fc_supported(const std::shared_ptr& fully_connected, - bool is_exception_allowed) { - OPENVINO_ASSERT(fully_connected, "FullyConnected node is empty!"); - size_t output_batch_size = fully_connected->get_output_shape(0)[0]; - if (output_batch_size > 8) { - if (is_exception_allowed) { - THROW_GNA_EXCEPTION << "topology with layer: " + fully_connected->get_friendly_name() + - ", type: " + fully_connected->get_type_name() + ", and batch size(" + - std::to_string(output_batch_size) + ") not supported"; - } - return false; - } - return true; -} - -bool Limitations::is_split_supported(const std::shared_ptr& node, bool is_exception_allowed) { - OPENVINO_ASSERT(node, "Split node is empty!"); - bool is_aligned = true; - for (size_t i = 0; i < node->get_output_size(); i++) { - is_aligned &= ov::intel_gna::graph_utils::is_aligned_split(node, i); - } - return is_aligned; -} - -bool Limitations::is_concat_supported(const std::shared_ptr& node, bool is_exception_allowed) { - OPENVINO_ASSERT(node, "Concat node is empty!"); - auto concat_node = std::dynamic_pointer_cast(node); - const ov::Shape& concat_shape_out = concat_node->get_output_shape(0); - auto axis = concat_node->get_axis(); - - std::function)> is_skipped_layer = [](std::shared_ptr node) { - return graph_utils::is_non_functional(node) || graph_utils::is_split(node) || graph_utils::is_copy(node) || - graph_utils::is_activation(node); - }; - - size_t skipped_ops_count = 0; - bool is_interleaved = false; - for (size_t i = 0; i < concat_node->inputs().size(); ++i) { - auto concat_input = - graph_utils::get_prev_node_skipping_certain(concat_node->get_input_node_shared_ptr(i), is_skipped_layer); - if (ov::op::util::is_parameter(concat_input) || ov::op::util::is_constant(concat_input)) { - skipped_ops_count++; - } - const ov::Shape concat_input_shape = concat_input->get_output_shape(0); - // graph compiler changes the concat axis if one of the inputs is interleaved layer output - if (graph_utils::squeeze_shape(concat_input_shape).size() >= 2 && graph_utils::is_interleaved(concat_input)) { - is_interleaved = true; - } - } - bool is_supported = false; - if (skipped_ops_count == concat_node->inputs().size()) { - is_supported = true; - } else if (is_interleaved) { - // TODO: need to extend interleaved layers detection patterns when migration to ngraph is finished. - // make interleaved shape - ov::Shape tr_shape(concat_shape_out); - std::rotate(tr_shape.begin(), tr_shape.begin() + 1, tr_shape.end()); - - // make interleaved order - std::vector tr_order(concat_shape_out.size()); - std::iota(tr_order.begin(), tr_order.end(), 0); - std::rotate(tr_order.begin(), tr_order.begin() + 1, tr_order.end()); - - const int64_t tr_axis = std::distance(tr_order.begin(), std::find(tr_order.begin(), tr_order.end(), axis)); - - is_supported = graph_utils::get_first_valuable_dim_id(tr_shape) == tr_axis; - } else { - is_supported = graph_utils::get_first_valuable_dim_id(concat_shape_out) == axis; - } - - if (!is_supported && is_exception_allowed) { - THROW_GNA_EXCEPTION << concat_node->get_friendly_name() - << " Unsupported concatenation axis=" << concat_node->get_axis() - << " for input dimensions: " << concat_node->get_input_shape(0); - } - - return is_supported; -} - -bool Limitations::is_forward_transposed_concat_supported(const std::shared_ptr& node, - const AxisVector& order) { - auto concat_node = std::dynamic_pointer_cast(node); - if (!concat_node) { - log::debug() << "Concat node is empty!" << std::endl; - return false; - } - - const ov::Shape& output_shape = concat_node->get_output_shape(0); - auto axis = concat_node->get_axis(); - - const ov::Shape& transposed_shape = - graph_utils::transpose_shape(output_shape, pass::helper::reverse_transpose_order(order)); - const size_t transposed_concat_axis = order[axis]; - - return graph_utils::get_first_valuable_dim_id(transposed_shape) == static_cast(transposed_concat_axis); -} - -bool Limitations::is_backward_transposed_concat_supported(const std::shared_ptr& node, - const AxisVector& order) { - auto concat_node = std::dynamic_pointer_cast(node); - if (!concat_node) { - log::debug() << "Concat node is empty!" << std::endl; - return false; - } - - const ov::Shape& output_shape = concat_node->get_output_shape(0); - auto axis = concat_node->get_axis(); - - const ov::Shape& transposed_shape = graph_utils::transpose_shape(output_shape, order); - const size_t transposed_concat_axis = order[axis]; - - return graph_utils::get_first_valuable_dim_id(transposed_shape) == static_cast(transposed_concat_axis); -} - -bool Limitations::is_forward_transposed_split_supported(const std::shared_ptr& node, - const AxisVector& order) { - std::shared_ptr split_node = nullptr; - if (std::dynamic_pointer_cast(node)) { - split_node = std::dynamic_pointer_cast(node); - } else if (std::dynamic_pointer_cast(node)) { - split_node = std::dynamic_pointer_cast(node); - } else { - log::debug() << "Split node is empty!" << std::endl; - return false; - } - - const ov::Shape& output_shape = split_node->get_output_shape(0); - auto constant_node = as_type_ptr(split_node->input_value(1).get_node_shared_ptr()); - if (!constant_node) - return false; - auto axis = constant_node->get_axis_vector_val()[0]; - - const ov::Shape& transposed_shape = - graph_utils::transpose_shape(output_shape, pass::helper::reverse_transpose_order(order)); - const size_t transposed_concat_axis = order[axis]; - - return graph_utils::get_first_valuable_dim_id(transposed_shape) == static_cast(transposed_concat_axis); -} - -bool Limitations::is_backward_transposed_split_supported(const std::shared_ptr& node, - const AxisVector& order) { - std::shared_ptr split_node = nullptr; - if (std::dynamic_pointer_cast(node)) { - split_node = std::dynamic_pointer_cast(node); - } else if (std::dynamic_pointer_cast(node)) { - split_node = std::dynamic_pointer_cast(node); - } else { - log::debug() << "Split node is empty!" << std::endl; - return false; - } - - const ov::Shape& output_shape = split_node->get_output_shape(0); - auto constant_node = as_type_ptr(split_node->input_value(1).get_node_shared_ptr()); - if (!constant_node) - return false; - auto axis = constant_node->get_axis_vector_val()[0]; - - const ov::Shape& transposed_shape = - graph_utils::transpose_shape(output_shape, pass::helper::reverse_transpose_order(order)); - const int64_t transposed_concat_axis = order[axis]; - - return graph_utils::get_first_valuable_dim_id(transposed_shape) == transposed_concat_axis; -} - -bool Limitations::is_op_supported(const std::shared_ptr& node, - const InferenceEngine::Precision gna_precision, - bool is_exception_allowed) { - if (ov::op::util::is_parameter(node)) { - return SupportedElementTypes::IsParameterTypeSupported(node->get_element_type(), is_exception_allowed); - } else if (ov::op::util::is_constant(node)) { - return SupportedElementTypes::IsConstantTypeSupported(node->get_element_type(), is_exception_allowed); - } else if (auto conv = std::dynamic_pointer_cast(node)) { - return is_conv_supported(conv, gna_precision, is_exception_allowed); - } else if (auto concat = std::dynamic_pointer_cast(node)) { - return is_concat_supported(concat, is_exception_allowed); - } else if (auto fully_connected = std::dynamic_pointer_cast(node)) { - return is_fc_supported(fully_connected, is_exception_allowed); - } else if (ov::intel_gna::graph_utils::is_pooling(node)) { - return is_pooling_supported(std::dynamic_pointer_cast(node), - is_exception_allowed); - } else if (ov::op::util::is_output(node) || ov::op::util::is_sink(node) || - ov::intel_gna::graph_utils::is_eltwise_add(node) || ov::intel_gna::graph_utils::is_eltwise_mul(node) || - ov::intel_gna::graph_utils::is_crop_affined(node) || - ov::intel_gna::graph_utils::is_activation(node.get()) || - ov::intel_gna::graph_utils::is_gna_precision_agnostic( - node) || // check concat/split are aligned when transformations will be moved to ngraph - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr)) { - return true; - } else if (ov::intel_gna::graph_utils::is_gna_precision_agnostic(node)) { - if ((std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr)) { - return is_split_supported(node, is_exception_allowed); - } - // TODO check concat are aligned when transformation will be moved to ngraph - return true; - } - return false; -} - -void Limitations::check_all_ops_supported(const std::shared_ptr& model, - const InferenceEngine::Precision gna_precision) { - std::stringstream error; - // Walk through the transformed model - for (auto& op : model->get_ops()) { - try { - if (!is_op_supported(op, gna_precision, true)) { - error << "The plugin does not support layer " << op->get_friendly_name() << " (type " - << op->get_type_name() << ")!" << std::endl; - } - } catch (const InferenceEngine::GeneralError& e) { - error << e.what() << std::endl; - } - } - if (!error.str().empty()) { - THROW_GNA_EXCEPTION << error.str(); - } -} - -bool Limitations::use_only_16bit_convolution_weights() const { - return m_use_only_16bit_conv_weights; -} - -bool Limitations::validate_conv_concat_axis(const InferenceEngine::ConcatLayer* concat_layer) { - IE_ASSERT(concat_layer); - auto dims_size = concat_layer->insData[0].lock()->getDims().size(); - - if (dims_size >= 2) { - InferenceEngine::CNNLayerPtr prev_layer; - - // Skipping here all layers which would disappear or otherwise fuse with convolution in the final GNA graph - auto isFusableWithConv = [](InferenceEngine::CNNLayerPtr ptr) { - return (LayerInfo(ptr).isFusableWithConv() || LayerInfo(ptr).isNonFunctional() || - LayerInfo(ptr).isConcat()); - }; - - auto in_dims = concat_layer->insData[0].lock()->getDims(); - auto concat_axis = concat_layer->_axis; - auto concat_layout = concat_layer->input()->getLayout(); - - for (size_t input_idx = 0; input_idx != concat_layer->insData.size(); input_idx++) { - // Supported cases for concatenation of a convolution - prev_layer = InferenceEngine::CNNNetPrevLayerSkipCertain(concat_layer, - static_cast(input_idx), - isFusableWithConv); - if (prev_layer && LayerInfo(prev_layer).isConvolution()) { - // Allow concatenation along N axis for non-interleaved primitives - // (currently only convolution) - if (concat_layer->_axis == 0) - break; - - // Convert dims to NHWC layout to allow later verification - auto new_order = permute::GetPermuteOrder(concat_layout, InferenceEngine::Layout::NHWC); - InferenceEngine::SizeVector new_dims; - for (size_t i = 0; i < dims_size; ++i) { - new_dims.push_back(in_dims[new_order[i]]); - } - concat_axis = permute::GetPermuteOrder(InferenceEngine::Layout::NHWC, concat_layout)[concat_axis]; - - // Looking for any axis with dimension > 1 before concatentaion axis; - // in general such concatenation is unsupported - auto end_dim = new_dims.begin() + concat_axis; - auto unsupportedconcat_axis = std::find_if(new_dims.begin(), end_dim, [](const size_t& inDim) { - return (inDim > 1); - }); - - if (unsupportedconcat_axis != end_dim) { - return false; - } - - break; - } - } - } - return true; -} - -bool Limitations::are_layers_supported(InferenceEngine::CNNNetwork& network, std::string& errMessage) { - IE_SUPPRESS_DEPRECATED_START - InferenceEngine::InputsDataMap inputs = network.getInputsInfo(); - std::unordered_set allLayers; - InferenceEngine::CNNLayerPtr startLayer; - if (inputs.empty()) { - auto outputs = network.getOutputsInfo(); - IE_ASSERT(!outputs.empty()); - // If there are no inputs start search from an output - startLayer = getCreatorLayer(outputs.begin()->second).lock(); - } else { - SupportedElementTypes::IsParameterTypeSupported( - InferenceEngine::details::convertPrecision(inputs.begin()->second->getPrecision()), - true); - - auto& secondLayers = getInputTo(inputs.begin()->second->getInputData()); - if (secondLayers.empty()) { - errMessage = "Network consists of input layer only (GNA)\n"; - return false; - } - startLayer = secondLayers.begin()->second; - } - auto batch_size = network.getBatchSize(); - bool check_result = true; - InferenceEngine::details::UnorderedDFS( - allLayers, - startLayer, - [&](const InferenceEngine::CNNLayerPtr layer) { - LayerInfo info(layer); - if (LayerTypeFromStr(layer->type) == LayerType::NO_TYPE) { - errMessage = "The plugin does not support layer: " + layer->name + ":" + layer->type + "\n"; - check_result = false; - } - if (batch_size != 1 && info.isBatchSizeConstrained()) { - errMessage = "topology with layer: " + layer->name + ", type: " + layer->type + ", and batch size(" + - std::to_string(batch_size) + ") != 1 not supported"; - check_result = false; - } - if (info.isFullyConnected()) { - size_t output_batch_size = info.getOutputBatchSize(); - if (output_batch_size > 8) { - errMessage = "topology with layer: " + layer->name + ", type: " + layer->type + - ", and batch size(" + std::to_string(output_batch_size) + ") not supported"; - check_result = false; - } - } - }, - false); - return check_result; -} -IE_SUPPRESS_DEPRECATED_END - -} // namespace limitations -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/gna_limitations.hpp b/src/plugins/intel_gna/src/backend/gna_limitations.hpp deleted file mode 100644 index bfb68b3f35f..00000000000 --- a/src/plugins/intel_gna/src/backend/gna_limitations.hpp +++ /dev/null @@ -1,349 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include -#include -#include -#include - -#include "common/gna_target.hpp" -#include "common/misc_utils.hpp" -#include "dnn_types.hpp" -#include "gna_lib_ver_selector.hpp" -#include "legacy/ngraph_ops/convolution_ie.hpp" -#include "legacy/ngraph_ops/fully_connected.hpp" -#include "ngraph/opsets/opset7.hpp" -#include "ngraph/opsets/opset9.hpp" -#include "openvino/runtime/threading/thread_local.hpp" -#include "ops/gna_convolution.hpp" -#include "ops/gna_max_pool.hpp" - -namespace ov { -namespace intel_gna { -namespace limitations { - -namespace cnn2d { - -struct IsEqualToLimit { - uint32_t compared_value; - std::string what; - bool IsValid(const uint32_t val) const; - std::string GetErrorOrEmpty(const uint32_t val) const; -}; - -struct IsLessThanLimit { - uint32_t compared_value; - std::string what; - bool IsValid(const uint32_t val) const; - std::string GetErrorOrEmpty(const uint32_t val) const; -}; - -struct RangeLimit { - uint32_t min; - uint32_t max; - std::string what; - bool IsValid(const uint32_t val) const; - std::string GetErrorOrEmpty(const uint32_t val) const; -}; - -struct RangeLimit2D { - RangeLimit hLimit; - RangeLimit wLimit; - bool IsValid(const uint32_t h, const uint32_t w) const; - std::string GetErrorOrEmpty(const uint32_t h, const uint32_t w) const; -}; - -struct RangeMultipleLimit : public RangeLimit { - uint32_t multiplier; - RangeMultipleLimit(RangeLimit rlIn, uint32_t multiplierIn); - bool IsValid(const uint32_t val) const; - std::string GetErrorOrEmpty(const uint32_t val) const; -}; - -struct RectLimit { - uint32_t maxVectorHeight; - uint32_t maxVectorWidth; - bool IsValid(const uint32_t h, const uint32_t w) const; - std::string GetErrorOrEmpty(const uint32_t h, const uint32_t w, std::string what) const; -}; - -struct VectorOrSquareLimit { - uint32_t maxSquare; - uint32_t maxVectorHeight; - uint32_t maxVectorWidth; - bool IsValid(const uint32_t h, const uint32_t w) const; - std::string GetErrorOrEmpty(const uint32_t h, const uint32_t w, std::string what) const; -}; - -struct RectLimitByChannels { - std::vector> limitPerChannel; - RectLimit GetByChannels(const uint32_t channels) const; - bool IsValid(const uint32_t h, const uint32_t w, const uint32_t channels) const; - std::string GetErrorOrEmpty(const uint32_t h, const uint32_t w, const uint32_t channels, std::string what) const; -}; - -struct RectLimitByChannelsAndPrecision { - RectLimitByChannels limit_for_int8; - RectLimitByChannels limit_for_int16; - RectLimitByChannels GetByPrecision(const OvGnaType precision) const; - bool IsValid(const uint32_t h, const uint32_t w, const OvGnaType precision, const uint32_t channels) const; - std::string GetErrorOrEmpty(const uint32_t h, - const uint32_t w, - const OvGnaType precision, - const uint32_t channels, - std::string what) const; -}; - -class AbstractValidator { -protected: - static void ThrowIfNotEmpty(const std::string& prefix, const std::string& error); - -public: - static bool ValidationSuccesful(const bool throwOnError, - const std::string& error, - const std::string& operation, - const std::string& type); - - virtual ~AbstractValidator() = default; - virtual bool ValidateCnn2D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kH, - const uint32_t kW, - const uint32_t kN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - OvGnaType inPrecision, - bool exception = true) const = 0; - - virtual bool ValidatePooling2D(const std::string& name, - const uint32_t windowH, - const uint32_t windowW, - const uint32_t strideH, - const uint32_t strideW, - bool exception = true) const = 0; - - virtual bool ValidateInputPadding(const std::string& name, - const uint32_t pad_h_begin, - const uint32_t pad_h_end, - const uint32_t pad_w_begin, - const uint32_t pad_w_end, - const uint32_t kernel_h, - const uint32_t kernel_w, - const bool throwOnError = true) const = 0; - - virtual bool ShouldUseOnlyConv2DGnaIface() const = 0; - - virtual bool ValidateCnn1D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kH, - const uint32_t kW, - const uint32_t kN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilationH, - const uint32_t dilationW, - OvGnaType inPrecision, - bool exception = true) const = 0; - - static std::shared_ptr Create(const target::DeviceVersion& target); -}; - -} // namespace cnn2d - -class Limitations { -public: - /** - * @brief Create an instance of the Limitations class. Since Limitations is designed as a singleton, multiple - * instances of the plugin with different compilation targets cannot coexist simultaneously for the same thread. - * @param compile_target GNA compile target - */ - static void init(const target::DeviceVersion& compile_target); - - /** - * @brief Delete the instance of the Limitations class for the currently running thread. - */ - static void deinit(); - - /** - * @brief Returns the instance of Limitations object. Requires an Init call before the first usage - */ - static inline std::shared_ptr get_instance(); - - static size_t get_min_batch_to_fit_in_buffer(InferenceEngine::DataPtr input); - - /** - * @brief Validates if concat layer axis is supported by GNA - * @param layer concat layer - * @return true if concat layer axis is valid - */ - IE_SUPPRESS_DEPRECATED_START - static bool validate_conv_concat_axis(const InferenceEngine::ConcatLayer* concatLayer); - static bool are_layers_supported(InferenceEngine::CNNNetwork& network, std::string& errMessage); - IE_SUPPRESS_DEPRECATED_END - - /** - * @brief Validates if fully connected is supported by GNA - * @param fully_connected fully connected - * @param is_exception_allowed flag specifies whether exception is allowed - * @return true if supported - */ - static bool is_fc_supported(const std::shared_ptr& fully_connected, - bool is_exception_allowed = false); - /** - * @brief Validates if split is supported by GNA - * @param node split - * @param is_exception_allowed flag specifies whether exception is allowed - * @return true if supported - */ - static bool is_split_supported(const std::shared_ptr& node, bool is_exception_allowed = false); - - /** - * @brief Validates if transpose is supported by GNA - * @param shape transpose - * @return true if supported - */ - static bool is_transpose_supported(const ov::Shape& shape); - /** - * @brief Validates if transpose is supported by GNA - * @param node transpose - * @return true if supported - */ - static bool is_transpose_supported(const std::shared_ptr& node); - /** - * @brief Validates if convolution is supported by GNA - * @param conv_gna GNA convolution - * @param gna_precision GNA inference precision - * @param is_exception_allowed flag specifies whether exception is allowed - * @return true if supported - */ - bool is_conv_supported(const std::shared_ptr& conv_gna, - const InferenceEngine::Precision gna_precision, - bool is_exception_allowed = false); - /** - * @brief Validates if max pooling is supported by GNA - * @param max_pool max pooling - * @param is_exception_allowed flag specifies whether exception is allowed - * @return true if precision is found in supported - */ - bool is_pooling_supported(const std::shared_ptr max_pool, - bool is_exception_allowed = false); - - static bool is_concat_supported(const std::shared_ptr& node, bool is_exception_allowed); - static bool is_forward_transposed_concat_supported(const std::shared_ptr& node, - const AxisVector& order); - static bool is_backward_transposed_concat_supported(const std::shared_ptr& node, - const AxisVector& order); - static bool is_forward_transposed_split_supported(const std::shared_ptr& node, - const AxisVector& order); - static bool is_backward_transposed_split_supported(const std::shared_ptr& node, - const AxisVector& order); - - /** - * @brief Validates if operation is supported by GNA - * @param node operation - * @param gna_precision GNA inference precision - * @param is_exception_allowed flag specifies whether exception is allowed - * @return true if supported - */ - bool is_op_supported(const std::shared_ptr& node, - const InferenceEngine::Precision gna_precision, - bool is_exception_allowed = false); - - /** - * @brief Check if all operations are supported by GNA - * @param model ngraph model - * @param gna_precision GNA inference precision - */ - void check_all_ops_supported(const std::shared_ptr& model, - const InferenceEngine::Precision gna_precision); - - bool use_only_16bit_convolution_weights() const; - bool is_crop_affined_offset(size_t numberOfElements) const; - bool is_aligned(size_t addr) const; - size_t get_memory_alignment() const; - std::shared_ptr get_cnn_validator() const; - - constexpr static uint32_t kBufferMaxSize = 65528; - constexpr static uint32_t kConvMinFiltersNum = 4; - constexpr static uint32_t kConvMaxFiltersNum = 65532; - constexpr static uint32_t kConvDilationHeight = 1; - constexpr static uint32_t kConvDilationWidth = 1; - constexpr static uint32_t kConvFiltersNumDivider = 4; - constexpr static uint32_t kConvFilterSizeDivider = 8; - constexpr static uint32_t kConvFilterMaxSize = 768; - constexpr static uint32_t kConvEachKernelByteAlignment = 16; - constexpr static uint32_t kNoOfInputsDivisor = 8; - constexpr static uint32_t kNoOfInputsLowPrecDivisor = 16; - constexpr static uint32_t kAffineMaxBatchSize = 8; - constexpr static uint32_t kMaxPoolMaxWindowSize = 6; - constexpr static uint32_t kCopyMaxGrouping = 8; - constexpr static uint32_t kTransposeMaxSize = 65528; - constexpr static uint32_t kMaxLayersCountGNA1_0 = 1023; - constexpr static uint32_t kMaxLayersCountGNA2_0 = 4096; - constexpr static uint32_t kMaxLayersCountGNA3_X = 8192; - - // Currently split layer only supports 2 bytes in int16 and int8 mode. - // In fp32 mode this is not necessary but is useful for testing - constexpr static uint32_t kBytesPerSplitElement = 2; - // Currently crop layer only supports 2 bytes in int16 and int8 mode. - // In fp32 mode this is not necessary but is useful for testing - constexpr static uint32_t kBytesPerCropElement = 2; - // currently concat layer only supports 2 bytes in int16 and int8 mode. In fp32 mode this no necessary but usefull - // for testing - constexpr static uint32_t kBytesPerConcatElement = 2; - constexpr static uint32_t kMemoryPageSize = 4096; - -private: - Limitations(const target::DeviceVersion& target); - Limitations(const Limitations&) = delete; - Limitations& operator=(const Limitations&) = delete; - - size_t get_memory_alignment_bytes(const target::DeviceVersion& target) const; - - bool m_use_only_16bit_conv_weights = false; - size_t m_mem_alignment = 0; - std::shared_ptr m_cnn_validator; - - static ov::threading::ThreadLocal> kInstance; -}; - -inline std::shared_ptr Limitations::get_instance() { - auto& instance = kInstance.local(); - if (!instance) { - THROW_GNA_EXCEPTION << "Limitations instance is not initialized.\n"; - } - return instance; -} - -inline bool Limitations::is_crop_affined_offset(size_t numberOfElements) const { - const auto cropOffset = numberOfElements * kBytesPerCropElement; - return !is_aligned(cropOffset); -} - -inline bool Limitations::is_aligned(size_t addr) const { - return (addr == ALIGN(addr, get_memory_alignment())); -} - -inline size_t Limitations::get_memory_alignment() const { - return m_mem_alignment; -} - -inline std::shared_ptr Limitations::get_cnn_validator() const { - return m_cnn_validator; -} - -} // namespace limitations -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/gna_types.hpp b/src/plugins/intel_gna/src/backend/gna_types.hpp deleted file mode 100644 index d6aaeada9bc..00000000000 --- a/src/plugins/intel_gna/src/backend/gna_types.hpp +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -/** PWL Segment - as read directly by the accelerator */ -typedef struct _pwl_segment_t { - int32_t xBase; // X Component of segment starting point, with scaling encoded if needed. - int16_t yBase; // Y Component of segment starting point. - int16_t slope; // Slope of linear function. -} gna_pwl_segment_t; -static_assert(8 == sizeof(gna_pwl_segment_t), "Invalid size of gna_pwl_segment_t"); - -/** Piecewise-linear activation function (PWL) details */ -typedef struct _pwl_func_t { - uint32_t nSegments; // Number of segments, set to 0 to disable activation function. - gna_pwl_segment_t* pSegments; // Activation function segments data or NULL if disabled. -} gna_pwl_func_t; - -/** - * Compound bias - * Used for nBytesPerWeight=GNA_INT8 and nBytesPerBias=GNA_INT16 only. - * As read directly by the accelerator. - */ -typedef struct _compound_bias_t { - int32_t bias; // 4B Signed integer bias (constant) value. - uint8_t multiplier; // Scaling factor that weight elements are multiplied by. - uint8_t reserved[3]; // Not used. -} gna_compound_bias_t; -static_assert(8 == sizeof(gna_compound_bias_t), "Invalid size of gna_compound_bias_t"); - -/** - * Layer operation type. - * Defines type of layer "core" operation. - * All nodes/cells within a layer are of the same type, - * e.g. affine transform cell, convolutional cell, recurrent cell. - * Affine, convolutional and recurrent layers are in fact "fused operation" layers - * and "core" operation is fused with activation and/or pooling functions. - * NOTE: Operation types are exclusive. - */ -typedef enum _layer_operation { - // Fully connected affine transform (deep feed forward) with activation function. Cast pLayerStruct to - // intel_affine_layer_t. - INTEL_AFFINE, - // Fully connected affine transform (matrix x vector) (deep feed forward) with activation function.Cast pLayerStruct - // to intel_affine_layer_t. - INTEL_AFFINE_DIAGONAL, - /* - * Fully connected affine transform (with grouped bias vectors) (deep feed forward) with activation function. - * Cast pLayerStruct to intel_affine_multibias_layer_t. - */ - INTEL_AFFINE_MULTIBIAS, - INTEL_CONVOLUTIONAL, // Convolutional transform with activation function and pooling. Cast pLayerStruct to - // intel_convolutional_layer_t. - INTEL_CONVOLUTIONAL_2D, // Convolutional transform with activation function and pooling. Cast pLayerStruct to - // nn_layer_cnn2d. - INTEL_COPY, // Auxiliary data copy operation. Cast pLayerStruct to intel_copy_layer_t. - INTEL_DEINTERLEAVE, // Auxiliary 2D tensor transpose operation (interleave to flat). No casting, always set - // pLayerStruct to null. - INTEL_GMM, // Gaussian Mixture Model operation. Cast pLayerStruct to intel_gmm_layer_t. - INTEL_INTERLEAVE, // Auxiliary 2D tensor transpose operation (flat to interleave). No casting, always set - // pLayerStruct to null. - INTEL_RECURRENT, // Fully connected affine transform with recurrence and activation function. Cast pLayerStruct to - // intel_recurrent_layer_t. - GNA_LAYER_CNN_2D_POOLING, - LAYER_OPERATION_TYPE_COUT, -} gna_layer_operation; - -typedef enum _layer_mode { - INTEL_INPUT, // Layer serves as model input layer (usually first layer) - INTEL_OUTPUT, // Layer serves as model output layer (usually last layer) - INTEL_INPUT_OUTPUT, // Layer serves as model input nad output layer (usually in single layer topology) - INTEL_HIDDEN, // Layer serves as model hidden layer (layers between input and output layers) - LAYER_MODE_COUNT // Number of Layer modes. -} gna_layer_mode; - -/** Layer common configuration descriptor */ -typedef struct _nnet_layer_t { - gna_layer_operation operation; // Layer operation type. - gna_layer_mode mode; // Layer connection mode. - uint32_t nInputColumns; // Number of input columns. - uint32_t nInputRows; // Number of input rows. - uint32_t nOutputColumns; // Number of output columns. - uint32_t nOutputRows; // Number of output rows. - uint32_t nBytesPerInput; // Precision/mode of input node, use a value from gna_data_mode. Valid values {GNA_INT8, - // GNA_INT16, GNA_DATA_DISABLED} - // Precision/ activation mode of output node, use a value from gna_data_mode. Valid values {GNA_INT8, GNA_INT16, - // GNA_INT32, GNA_DATA_ACTIVATION_DISABLED} - uint32_t nBytesPerOutput; - uint32_t nBytesPerIntermediateOutput; // Number of bytes per intermediate output node, always set to GNA_INT32. - void* pLayerStruct; // Layer detailed configuration, cast to intel_[LAYER_KIND]_layer_t. - void* pInputs; // Signed integer NN or GMM input buffer. - void* pOutputsIntermediate; // 4B Signed integer Auxiliary output buffer. - void* pOutputs; // Signed integer output buffer. -} gna_nnet_layer_t; - -/** GNA Network descriptor */ -typedef struct _nnet_type_t { - uint32_t nLayers; // The number of layers in the network. - uint32_t nGroup; // Input vector grouping level. - gna_nnet_layer_t* pLayers; // Layer configurations. -} gna_nnet_type_t; - -/** Affine function details */ -typedef struct _affine_func_t { - uint32_t nBytesPerWeight; // Precision/mode of weight element, use a value from gna_data_mode. - uint32_t nBytesPerBias; // Precision/mode of bias (constant) element, use a value from gna_data_mode. - void* pWeights; // Signed integer weights data buffer. - void* pBiases; // Biases (constants) data buffer. Signed integer biases or gna_compound_bias_t -} gna_affine_func_t; - -/** Fully connected affine layer detailed descriptor */ -typedef struct _affine_layer_t { - gna_affine_func_t affine; // Affine function details. - gna_pwl_func_t pwl; // Activation function details. -} gna_affine_layer_t; - -/** Pooling function types */ -typedef enum _pool_type_t { - INTEL_NO_POOLING = 0, // Pooling function disabled. - INTEL_MAX_POOLING = 1, // Max Pooling function. - INTEL_SUM_POOLING = 2, // Sum Pooling function. - NUM_POOLING_TYPES // Number of Pooling function types. -} gna_pool_type_t; - -/** Convolutional Layer detailed descriptor */ -typedef struct _convolutional_layer_t { - uint32_t nFilters; // Number of filters. - uint32_t nFilterCoefficients; // Number of filter elements, including 0-padding if necessary. - uint32_t nFilterRows; // Number of rows in each filter. - uint32_t nBytesFilterCoefficient; // Precision/mode of filter coefficient element, use a value from gna_data_mode. - uint32_t nBytesBias; // Precision/mode of bias (constant) element, use a value from gna_data_mode. - uint32_t nFeatureMaps; // Number of feature maps. - uint32_t nFeatureMapRows; // Number of rows in each feature map. - uint32_t nFeatureMapColumns; // Number of columns in each feature map. - void* pFilters; // Signed integer Filters data buffer, filters stored one after the other. - void* pBiases; // Signed integer Biases (constants) data buffer, biases are specified per kernel/filter. - gna_pool_type_t poolType; // Pooling function type. - uint32_t nPoolSize; // Pool size, set 1 to disable pooling. - uint32_t nPoolStride; // Pool stride. - gna_pwl_func_t pwl; // Activation function details. -} gna_convolutional_layer_t; - -/** - The list of processing acceleration modes. - Current acceleration modes availability depends on the CPU type. - Available modes are detected by GNA. - - NOTE: - - GNA_HARDWARE: in some GNA hardware generations, model components unsupported - by hardware will be processed using software acceleration. - When software inference is used, by default "fast" algorithm is used - and results may be not bit-exact with these produced by hardware device. - */ -typedef enum _acceleration { - GNA_HARDWARE = static_cast(0xFFFFFFFE), // GNA Hardware acceleration enforcement - GNA_AUTO = 0x3, // GNA selects the best available acceleration - GNA_SOFTWARE = 0x5, // GNA selects the best available software acceleration - GNA_GENERIC = 0x7, // Enforce the usage of generic software mode - GNA_SSE4_2 = 0x9, // Enforce the usage of SSE 4.2 CPU instruction set - GNA_AVX1 = 0xB, // Enforce the usage of AVX1 CPU instruction set - GNA_AVX2 = 0xD // Enforce the usage of AVX2 CPU instruction set -} gna_acceleration; - -static_assert(4 == sizeof(gna_acceleration), "Invalid size of gna_acceleration"); diff --git a/src/plugins/intel_gna/src/backend/make_pwl.cpp b/src/plugins/intel_gna/src/backend/make_pwl.cpp deleted file mode 100644 index 231f87a7ff8..00000000000 --- a/src/plugins/intel_gna/src/backend/make_pwl.cpp +++ /dev/null @@ -1,434 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "make_pwl.hpp" - -#include -#include -#include -#include -#include - -#include "backend/gna_types.hpp" -#include "common/numerical_utils.hpp" -#include "dnn_types.hpp" -#include "gna_slope_scale.hpp" -#include "log/log.hpp" -#include "pwl_input_params.hpp" -#include "pwl_segments_creator_factory.hpp" -#include "runtime/pwl.h" - -using namespace ov::intel_gna; -using namespace ov::intel_gna::common; - -// This function performs emulation of HW saturation of PWL segments in SW -// by inserting additional segments when overflow would happen -static void insert_extra_pwl_segments(std::vector& gna_pwl, - const int16_t y_min, - const int16_t y_max) { - std::map extra_segments; - gna_pwl_segment_t extra_segment; - size_t gna_pwl_size = gna_pwl.size(); - - if (gna_pwl_size == 0) - return; - - // We're adding a segment at the beginning if the first one doesn't cover min value - if ((gna_pwl[0].xBase & XBASEMASK) != (INT32_MIN & XBASEMASK)) { - extra_segment.xBase = INT32_MIN & XBASEMASK; - extra_segment.yBase = gna_pwl[0].yBase; - extra_segment.slope = 0; - extra_segments[0] = extra_segment; - } - - // We're checking here if saturation could potentially happen at the trailing segments - if (gna_pwl[gna_pwl_size - 1].slope != 0) { - int16_t slope = gna_pwl[gna_pwl_size - 1].slope; - int32_t xBase = gna_pwl[gna_pwl_size - 1].xBase & XBASEMASK; - int16_t yBase = gna_pwl[gna_pwl_size - 1].yBase; - float scale = static_cast(pow(2, ((gna_pwl[gna_pwl_size - 1].xBase & ~XBASEMASK) + 1) * 8)); - float y_value = ((static_cast(INT32_MAX) - xBase) * slope) / scale + yBase; - - if (y_value > static_cast(INT16_MAX) || y_value < static_cast(INT16_MIN)) { - float x_value = ((static_cast(y_max) - yBase) * scale) / slope + xBase; - extra_segment.xBase = FloatToInt32(x_value) & XBASEMASK; - extra_segment.yBase = slope > 0 ? y_max : y_min; - extra_segment.slope = 0; - extra_segments[gna_pwl_size] = extra_segment; - } - } - - if (!extra_segments.empty()) - log::debug() << "Additional segment(s) added to protect against saturation\n"; - - for (auto i = extra_segments.rbegin(); i != extra_segments.rend(); i++) { - gna_pwl.insert(gna_pwl.begin() + i->first, i->second); - } -} - -static void print_segments_header(const DnnActivation& fun) { - log::debug() << "=========================== " << intel_dnn_activation_name[fun] - << " segments ===========================\n"; - log::debug() << std::setw(12) << std::setfill(' ') << "x" << std::setw(12) << std::setfill(' ') << "y" - << std::setw(12) << std::setfill(' ') << "slope" << std::endl; -} - -static void print_segments_header() { - log::debug() << "=========================== segments ===========================\n"; - log::debug() << std::setw(12) << std::setfill(' ') << "x" << std::setw(12) << std::setfill(' ') << "y" - << std::setw(12) << std::setfill(' ') << "slope" << std::endl; -} - -static void print_segment(double x, double y, double slope) { - log::debug() << std::setw(12) << std::setfill(' ') << x << std::setw(12) << std::setfill(' ') << y << std::setw(12) - << std::setfill(' ') << slope << std::endl; -} - -void make_gna_pwl(const DnnActivation& fun, - const std::vector& pwl, - const double l_bound, - const double u_bound, - const double in_scale, - const double out_scale, - const bool low_precision, - const bool is_fused_with_conv2d, - std::vector& gna_pwl) { - log::debug() << "make_gna_pwl\n"; - log::debug() << " in_scale " << in_scale << "\n"; - log::debug() << " out_scale " << out_scale << "\n"; - print_segments_header(fun); - if (fun.type == kActIdentity) { - auto pwl_creator = ov::intel_gna::backend::PWLSegmentsCreatorFactory::CreateCreator(fun.type); - if (pwl_creator == nullptr) { - THROW_GNA_EXCEPTION << "Could not find creator for function type equal: " << static_cast(fun.type); - } - ov::intel_gna::backend::PWLInputParams input_data(low_precision, fun.fqParams, in_scale, out_scale); - auto segments_with_borders = pwl_creator->CreateSegmentsWithBorders(input_data); - gna_pwl = segments_with_borders.segments; - auto& y_min_max = segments_with_borders.border_values.y_min_max; - // Extra segments are needed only in case activation function was fused with Conv2D layer - if (is_fused_with_conv2d) { - insert_extra_pwl_segments(gna_pwl, y_min_max.y_min, y_min_max.y_max); - } - return; - } - - pwl_gna_slope_scale_t s; - const int16_t y_min = low_precision ? INT8_MIN : INT16_MIN; - const int16_t y_max = low_precision ? INT8_MAX : INT16_MAX; - switch (fun) { - case kActRelu: - case kActLeakyRelu: { - auto n_segments = 2; - gna_pwl.resize(n_segments); - int32_t x_lower = INT32_MIN; - int32_t x_upper = INT32_MAX; - int32_t y_lower = y_min; - int16_t y_upper = y_max; - if (fun.fqParams.set) { - x_lower = static_cast( - std::max(DoubleToInt64(*fun.fqParams.input_low * 1.25 * in_scale), static_cast(x_lower))); - x_upper = static_cast( - std::min(DoubleToInt64(*fun.fqParams.input_high * 1.25 * in_scale), static_cast(x_upper))); - // y_lower can be reduced with negative slope - y_lower = static_cast(*fun.fqParams.input_low * 1.25 * out_scale); - y_upper = static_cast( - std::min(DoubleToInt32(*fun.fqParams.input_high * 1.25 * out_scale), static_cast(y_upper))); - } else { - if (x_lower < y_lower * in_scale / out_scale) - x_lower = DoubleToInt32(y_lower * in_scale / out_scale); - if (y_lower < x_lower * out_scale / in_scale) - y_lower = DoubleToInt16(x_lower * out_scale / in_scale); - } - - gna_pwl[0].yBase = std::max(FloatToInt32(y_lower * fun.args.lrelu.negative_slope), static_cast(y_min)); - s = gna_slope(fun.args.lrelu.negative_slope, in_scale, out_scale); - gna_pwl[0].xBase = (x_lower & XBASEMASK) | s.slope_scale_index; // zero out the 2 lsb - gna_pwl[0].slope = DoubleToInt16(s.slope * s.slope_scale); - - print_segment((int32_t)(gna_pwl[0].xBase & XBASEMASK) / in_scale, - gna_pwl[0].yBase / out_scale, - (gna_pwl[0].slope * in_scale) / (out_scale * s.slope_scale)); - - gna_pwl[1].xBase = 0; - gna_pwl[1].yBase = 0; - s = gna_slope(1.0, in_scale, out_scale); - gna_pwl[1].slope = DoubleToInt16(s.slope * s.slope_scale); - gna_pwl[1].xBase = gna_pwl[1].xBase | s.slope_scale_index; - print_segment(0.0, 0.0, (gna_pwl[1].slope * in_scale) / (out_scale * s.slope_scale)); - - if (fun.fqParams.set) { // need a right segment - gna_pwl.push_back({static_cast(x_upper & XBASEMASK), // zero out the 2 lsb - y_upper, - 0}); - - print_segment((x_upper & XBASEMASK) / in_scale, gna_pwl[n_segments].yBase / out_scale, 0.0); - } - break; - } - case kActSign: { - auto n_segments = 3; - gna_pwl.resize(n_segments); - - int32_t x_lower = INT32_MIN; - int16_t y_lower = static_cast(-1.0 * out_scale); - gna_pwl[0].yBase = y_lower; - gna_pwl[0].xBase = (x_lower & XBASEMASK); // zero out the 2 lsb - gna_pwl[0].slope = 0; - - print_segment(gna_pwl[0].xBase / in_scale, - gna_pwl[0].yBase / out_scale, - (gna_pwl[0].slope * in_scale) / (out_scale * s.slope_scale)); - gna_pwl[1].xBase = -1; - gna_pwl[1].yBase = 0; - gna_pwl[1].slope = 0; - gna_pwl[1].xBase = gna_pwl[1].xBase & XBASEMASK; - print_segment(gna_pwl[1].xBase / in_scale, - gna_pwl[1].yBase / out_scale, - (gna_pwl[1].slope * in_scale) / (out_scale * s.slope_scale)); - - gna_pwl[2].xBase = 1 + ~XBASEMASK; // smallest representable positive number - gna_pwl[2].yBase = static_cast(1.0 * out_scale); - s = gna_slope(1.0, in_scale, out_scale); - gna_pwl[2].slope = 0; - gna_pwl[2].xBase = gna_pwl[2].xBase & XBASEMASK; - print_segment(gna_pwl[2].xBase / in_scale, - gna_pwl[2].yBase / out_scale, - (gna_pwl[2].slope * in_scale) / (out_scale * s.slope_scale)); - break; - } - case kActKaldiLstmClipping: - case kActFakeQuantize: { - int32_t x_lower = INT32_MIN; - int32_t x_upper = INT32_MAX; - int16_t y_lower = y_min; - int16_t y_upper = y_max; - if (fun.fqParams.set) { - x_lower = static_cast( - std::max(static_cast(*fun.fqParams.input_low * in_scale), static_cast(x_lower))); - x_upper = static_cast( - std::min(static_cast(*fun.fqParams.input_high * in_scale), static_cast(x_upper))); - y_lower = - std::max(static_cast(*fun.fqParams.input_low * out_scale), static_cast(y_lower)); - y_upper = - std::min(static_cast(*fun.fqParams.input_high * out_scale), static_cast(y_upper)); - } - auto n_segments = 2; - if (fun == kActKaldiLstmClipping) { - if (x_lower < l_bound * in_scale) { - if (y_lower < l_bound * out_scale) { - x_lower = DoubleToInt32(l_bound * in_scale); - y_lower = DoubleToInt16(l_bound * out_scale); - } else { - x_lower = DoubleToInt32(y_lower * in_scale / out_scale); - } - } - if (x_upper > u_bound * in_scale) { - if (y_upper > u_bound * out_scale) { - x_upper = DoubleToInt32(u_bound * in_scale); - y_upper = DoubleToInt16(u_bound * out_scale); - } else { - x_upper = DoubleToInt32(y_upper * in_scale / out_scale); - } - } - } - - gna_pwl.resize(n_segments); - gna_pwl[0].xBase = INT32_MIN & XBASEMASK; // zero out the 2 lsb - gna_pwl[0].yBase = y_lower; - gna_pwl[0].slope = 0; - print_segment(gna_pwl[0].xBase / in_scale, gna_pwl[0].yBase / out_scale, 0.0); - - gna_pwl[1].xBase = x_lower & XBASEMASK; // zero out the 2 lsb - gna_pwl[1].yBase = y_lower; - s = gna_slope(1.0, in_scale, out_scale); - gna_pwl[1].slope = DoubleToInt16(s.slope * s.slope_scale); - gna_pwl[1].xBase = gna_pwl[1].xBase | s.slope_scale_index; - print_segment((int32_t)(gna_pwl[1].xBase & XBASEMASK) / in_scale, gna_pwl[1].yBase / out_scale, 1.0); - - if (INT32_MAX > x_upper) { // need a right segment - gna_pwl.push_back({static_cast(x_upper & XBASEMASK), // zero out the 2 lsb - y_upper, - 0}); - - print_segment((x_upper & XBASEMASK) / in_scale, gna_pwl[n_segments].yBase / out_scale, 0.0); - } - break; - } - case kActAbs: { - int32_t x_upper = INT32_MAX; - int16_t y_upper = y_max; - int32_t i = 0; - - auto n_segments = 2; - - if (y_upper > x_upper * out_scale / in_scale) - y_upper = DoubleToInt16(x_upper * out_scale / in_scale); - if (x_upper > y_upper * in_scale / out_scale) - x_upper = DoubleToInt32(y_upper * in_scale / out_scale); - - if (y_upper == y_max) { // saturation at ends - need one more segment - n_segments += 1; - gna_pwl.resize(n_segments); - gna_pwl[i].xBase = INT32_MIN & XBASEMASK; // zero out the 2 lsb - gna_pwl[i].yBase = y_max; - gna_pwl[i].slope = 0; - i++; - } else { - gna_pwl.resize(n_segments); - } - - gna_pwl[i].xBase = (-x_upper) & XBASEMASK; // zero out the 2 lsb - gna_pwl[i].yBase = y_upper; - s = gna_slope(-1.0, in_scale, out_scale); - gna_pwl[i].slope = DoubleToInt16(s.slope * s.slope_scale); - gna_pwl[i].xBase = gna_pwl[i].xBase | s.slope_scale_index; - print_segment((int32_t)(gna_pwl[i].xBase & XBASEMASK) / in_scale, gna_pwl[i].yBase / out_scale, -1.0); - - gna_pwl[i + 1].xBase = 0; - gna_pwl[i + 1].yBase = 0; - s = gna_slope(1.0, in_scale, out_scale); - gna_pwl[i + 1].slope = DoubleToInt16(s.slope * s.slope_scale); - gna_pwl[i + 1].xBase = gna_pwl[i + 1].xBase | s.slope_scale_index; - print_segment((int32_t)(gna_pwl[i + 1].xBase & XBASEMASK) / in_scale, gna_pwl[i + 1].yBase / out_scale, 1.0); - break; - } - default: - THROW_GNA_EXCEPTION << "Unexpected function activation!" << fun; - } - - // Extra segments are needed only in case activation function was fused with Conv2D layer - if (is_fused_with_conv2d) { - insert_extra_pwl_segments(gna_pwl, y_min, y_max); - } -} - -template -static T cast_check_overflow(double v, bool round = true) { - if (v == std::numeric_limits::infinity() || v > std::numeric_limits::max()) { - return std::numeric_limits::max(); - } - - if (v == -std::numeric_limits::infinity() || v < std::numeric_limits::min()) { - return std::numeric_limits::min(); - } - - return round ? DoubleToInt32(v) : static_cast(v); -} - -/** - * Make GNA segments from PWL (m*x + b). - * @param m - array of slopes of a function - * @param b - array of offset of a function - * @param alpha - array x-the value of the beginning of a segments - * @param count - number of PWL segments - * @param in_scale - input scale factor - * @param out_scale - output scale factor - */ -template -static void make_gna_pwl(const T* m, - const T* b, - const T* alpha, - size_t count, - double in_scale, - double out_scale, - std::vector& gna_pwl) { - auto mul_check_overflow = [](double a, double b) -> double { - if (a == 0 || b == 0) { - return 0; - } - - if (std::fabs(a) == std::numeric_limits::infinity() || - std::fabs(b) == std::numeric_limits::infinity()) { - return ((a > 0 && b > 0) || (a < 0 && b < 0)) ? std::numeric_limits::infinity() - : -std::numeric_limits::infinity(); - } - - if (b != 0 && std::fabs(a) > std::numeric_limits::max() / std::fabs(b)) { - return ((a > 0 && b > 0) || (a < 0 && b < 0)) ? std::numeric_limits::infinity() - : -std::numeric_limits::infinity(); - } - - return a * b; - }; - - auto add_check_overflow = [](double a, double b) -> double { - if (((a > 0 && b > 0) || (a < 0 && b < 0)) && - std::fabs(a) > std::numeric_limits::max() - std::fabs(b)) { - return a > 0 && b > 0 ? std::numeric_limits::infinity() : -std::numeric_limits::infinity(); - } - - return a + b; - }; - - log::debug() << "make_gna_pwl\n"; - log::debug() << " in_scale " << in_scale << "\n"; - log::debug() << " out_scale " << out_scale << "\n"; - print_segments_header(); - gna_pwl.resize(0); - for (size_t i = 0; i < count; i++) { - auto s = gna_slope(m[i], in_scale, out_scale); - int32_t xbase = (cast_check_overflow(mul_check_overflow(in_scale, alpha[i]), false) & XBASEMASK) | - s.slope_scale_index; - int16_t ybase = cast_check_overflow( - mul_check_overflow(add_check_overflow(mul_check_overflow(m[i], alpha[i]), b[i]), out_scale)); - int16_t slope = cast_check_overflow(mul_check_overflow(s.slope, static_cast(s.slope_scale))); - gna_pwl.push_back({xbase, ybase, slope}); - print_segment(alpha[i], add_check_overflow(mul_check_overflow(m[i], alpha[i]), b[i]), m[i]); - } -} - -static void make_gna_pwl(std::tuple<>&&, - const std::shared_ptr&, - const std::shared_ptr&, - const std::shared_ptr&, - double, - double, - std::vector&) {} - -template -static void make_gna_pwl(std::tuple&& types, - const std::shared_ptr& m, - const std::shared_ptr& b, - const std::shared_ptr& alpha, - double in_scale, - double out_scale, - std::vector& gna_pwl) { - if (m->get_element_type() != T::value) { - make_gna_pwl(std::tuple(), m, b, alpha, in_scale, out_scale, gna_pwl); - return; - } - - using A = typename ngraph::element_type_traits::value_type; - make_gna_pwl(m->get_data_ptr
(), - b->get_data_ptr(), - alpha->get_data_ptr(), - m->get_byte_size() / sizeof(A), - in_scale, - out_scale, - gna_pwl); -} - -void make_gna_pwl(const std::shared_ptr& node, - double in_scale, - double out_scale, - bool low_precision, - std::vector& gna_pwl) { - auto m_node = std::dynamic_pointer_cast(node->get_input_node_shared_ptr(1)); - IE_ASSERT(!!m_node); - auto b_node = std::dynamic_pointer_cast(node->get_input_node_shared_ptr(2)); - IE_ASSERT(!!b_node); - auto alpha_node = std::dynamic_pointer_cast(node->get_input_node_shared_ptr(3)); - IE_ASSERT(!!alpha_node); - IE_ASSERT(m_node->get_element_type() == b_node->get_element_type() && - m_node->get_element_type() == alpha_node->get_element_type()); - make_gna_pwl(std::tuple, - std::integral_constant>(), - m_node, - b_node, - alpha_node, - in_scale, - out_scale, - gna_pwl); -} diff --git a/src/plugins/intel_gna/src/backend/make_pwl.hpp b/src/plugins/intel_gna/src/backend/make_pwl.hpp deleted file mode 100644 index deec11c2b92..00000000000 --- a/src/plugins/intel_gna/src/backend/make_pwl.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "runtime/pwl.h" - -void make_gna_pwl(const DnnActivation& fun, - const std::vector& pwl, - const double l_bound, - const double u_bound, - const double in_scale, - const double out_scale, - const bool low_precision, - const bool is_fused_with_conv2d, - std::vector& gna_pwl); -void make_gna_pwl(const std::shared_ptr& node, - const double in_scale, - const double out_scale, - const bool low_precision, - std::vector& gna_pwl); diff --git a/src/plugins/intel_gna/src/backend/pwl_border_values_counter.hpp b/src/plugins/intel_gna/src/backend/pwl_border_values_counter.hpp deleted file mode 100644 index 7ec013a85d0..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_border_values_counter.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace backend { - -class PWLInputParams; - -struct YMinMax { - int16_t y_min; - int16_t y_max; -}; -struct BorderValues { - int32_t x_lower; - int32_t x_upper; - int16_t y_lower; - int16_t y_upper; - YMinMax y_min_max; -}; - -class PWLBorderValuesCounter { -public: - virtual ~PWLBorderValuesCounter() = default; - virtual BorderValues CreateBorderValues(const PWLInputParams& input_params) const = 0; -}; -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/pwl_border_values_counter_identity.cpp b/src/plugins/intel_gna/src/backend/pwl_border_values_counter_identity.cpp deleted file mode 100644 index 36305209e19..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_border_values_counter_identity.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "pwl_border_values_counter_identity.hpp" - -#include - -#include "common/numerical_utils.hpp" -#include "log/debug.hpp" -#include "pwl_input_params.hpp" - -namespace ov { -namespace intel_gna { -namespace backend { - -BorderValues BorderValuesCounterIdentity::CreateBorderValues(const PWLInputParams& input_params) const { - auto results = CreateDefaultBorderValues(input_params.is_low_precision()); - - const auto& fake_quantize_params = input_params.fake_quntize_params(); - auto in_scale = input_params.in_scale(); - auto out_scale = input_params.out_scale(); - if (static_cast(input_params.fake_quntize_params().set)) { - results = CreateBorderValuesWithFakeQuantize(results, fake_quantize_params, in_scale, out_scale); - } else { - results = CreateBorderValues(results, in_scale, out_scale); - } - if (!AreValuesValid(results)) { - THROW_GNA_EXCEPTION << "Unacceptable scale factors. Difference between factors is too big: in_scale=" - << in_scale << ", out_scale: " << out_scale; - } - - return results; -} - -BorderValues BorderValuesCounterIdentity::CreateBorderValues(const BorderValues& default_values, - double in_scale, - double out_scale) { - int32_t x_lower = default_values.x_lower; - int32_t x_upper = default_values.x_upper; - int16_t y_lower = default_values.y_lower; - int16_t y_upper = default_values.y_upper; - if (x_lower < y_lower * in_scale / out_scale) - x_lower = common::DoubleToInt32(y_lower * in_scale / out_scale); - if (x_upper > y_upper * in_scale / out_scale) - x_upper = common::DoubleToInt32(y_upper * in_scale / out_scale); - if (y_lower < x_lower * out_scale / in_scale) - y_lower = common::DoubleToInt16(x_lower * out_scale / in_scale); - if (y_upper > x_upper * out_scale / in_scale) - y_upper = common::DoubleToInt16(x_upper * out_scale / in_scale); - return {x_lower, x_upper, y_lower, y_upper, {default_values.y_lower, default_values.y_upper}}; -} - -BorderValues BorderValuesCounterIdentity::CreateBorderValuesWithFakeQuantize( - const BorderValues& default_values, - const FakeQuantizeParams& fake_quantize_params, - double in_scale, - double out_scale) { - int32_t x_lower = - static_cast(std::max(static_cast(*fake_quantize_params.input_low * in_scale), - static_cast(default_values.x_lower))); - int32_t x_upper = - static_cast(std::min(static_cast(*fake_quantize_params.input_high * in_scale), - static_cast(default_values.x_upper))); - int16_t y_lower = std::max(static_cast(*fake_quantize_params.input_low * out_scale), - static_cast(default_values.y_lower)); - int16_t y_upper = std::min(static_cast(*fake_quantize_params.input_high * out_scale), - static_cast(default_values.y_upper)); - - return {x_lower, x_upper, y_lower, y_upper, {default_values.y_lower, default_values.y_upper}}; -} - -BorderValues BorderValuesCounterIdentity::CreateDefaultBorderValues(bool is_low_precision) { - const int16_t y_min = is_low_precision ? std::numeric_limits::min() : std::numeric_limits::min(); - const int16_t y_max = is_low_precision ? std::numeric_limits::max() : std::numeric_limits::max(); - return {std::numeric_limits::min(), std::numeric_limits::max(), y_min, y_max, {y_min, y_max}}; -} - -bool BorderValuesCounterIdentity::AreValuesValid(const BorderValues& values) { - if (values.x_lower == values.x_upper && values.x_upper == values.y_lower && values.y_lower == values.y_upper && - values.y_upper == 0) { - return false; - } - return true; -} -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/pwl_border_values_counter_identity.hpp b/src/plugins/intel_gna/src/backend/pwl_border_values_counter_identity.hpp deleted file mode 100644 index 843409511cc..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_border_values_counter_identity.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "pwl_border_values_counter.hpp" - -struct FakeQuantizeParams; - -namespace ov { -namespace intel_gna { -namespace backend { - -class BorderValuesCounterIdentity : public PWLBorderValuesCounter { -public: - BorderValuesCounterIdentity() = default; - ~BorderValuesCounterIdentity() override = default; - BorderValues CreateBorderValues(const PWLInputParams& input_params) const override; - -private: - static BorderValues CreateBorderValues(const BorderValues& default_values, double in_scale, double out_scale); - static BorderValues CreateBorderValuesWithFakeQuantize(const BorderValues& default_values, - const FakeQuantizeParams& fake_quantize_params, - double in_scale, - double out_scale); - static BorderValues CreateDefaultBorderValues(bool is_low_precision); - static bool AreValuesValid(const BorderValues& values); -}; - -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/pwl_input_params.cpp b/src/plugins/intel_gna/src/backend/pwl_input_params.cpp deleted file mode 100644 index 43c90b25409..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_input_params.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "pwl_input_params.hpp" - -namespace ov { -namespace intel_gna { -namespace backend { - -PWLInputParams::PWLInputParams(bool is_low_precision, - const FakeQuantizeParams& fake_qunatize_params, - double in_scale, - double out_scale) - : is_low_precision_(is_low_precision), - fake_quntize_params_(fake_qunatize_params), - in_scale_(in_scale), - out_scale_(out_scale) {} - -bool PWLInputParams::is_low_precision() const { - return is_low_precision_; -} - -const FakeQuantizeParams& PWLInputParams::fake_quntize_params() const { - return fake_quntize_params_; -} - -double PWLInputParams::in_scale() const { - return in_scale_; -} - -double PWLInputParams::out_scale() const { - return out_scale_; -} - -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/pwl_input_params.hpp b/src/plugins/intel_gna/src/backend/pwl_input_params.hpp deleted file mode 100644 index 2a5b55fd199..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_input_params.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "backend/dnn_types.hpp" - -namespace ov { -namespace intel_gna { -namespace backend { - -class PWLInputParams { -public: - PWLInputParams(bool is_low_precision, - const FakeQuantizeParams& fake_qunatize_params, - double in_scale, - double out_scale); - - bool is_low_precision() const; - const FakeQuantizeParams& fake_quntize_params() const; - double in_scale() const; - double out_scale() const; - -private: - bool is_low_precision_; - FakeQuantizeParams fake_quntize_params_; - double in_scale_; - double out_scale_; -}; -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/pwl_segments_creator.hpp b/src/plugins/intel_gna/src/backend/pwl_segments_creator.hpp deleted file mode 100644 index 257447a9551..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_segments_creator.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "backend/gna_types.hpp" -#include "pwl_border_values_counter.hpp" - -namespace ov { -namespace intel_gna { -namespace backend { - -class PWLInputParams; - -struct PWLSegmentsWithBorderValues { - BorderValues border_values; - std::vector segments; -}; - -class PWLSegmentsCreator { -public: - virtual std::vector CreateSegments(const PWLInputParams& input_params) const = 0; - virtual PWLSegmentsWithBorderValues CreateSegmentsWithBorders(const PWLInputParams& input_params) const = 0; - virtual ~PWLSegmentsCreator() = default; - -private: - std::shared_ptr counter_; -}; - -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/pwl_segments_creator_factory.cpp b/src/plugins/intel_gna/src/backend/pwl_segments_creator_factory.cpp deleted file mode 100644 index d6a723367f8..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_segments_creator_factory.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "pwl_segments_creator_factory.hpp" - -#include -#include - -#include "backend/dnn_types.hpp" -#include "pwl_border_values_counter_identity.hpp" -#include "pwl_segments_creator_identity.hpp" - -namespace ov { -namespace intel_gna { -namespace backend { - -std::shared_ptr PWLSegmentsCreatorFactory::CreateCreator(DnnActivationType activation_type) { - static auto create_identity = []() -> std::shared_ptr { - auto border_values_counter = std::make_shared(); - return std::make_shared(border_values_counter); - }; - - std::unordered_map(void)>> - supported_activations{{kActIdentity, create_identity}}; - - auto activation_itr = supported_activations.find(activation_type); - - if (activation_itr == supported_activations.end()) { - return nullptr; - } - - return activation_itr->second(); -} - -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/pwl_segments_creator_factory.hpp b/src/plugins/intel_gna/src/backend/pwl_segments_creator_factory.hpp deleted file mode 100644 index 3361b4e9e40..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_segments_creator_factory.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "pwl_segments_creator.hpp" - -enum DnnActivationType : uint8_t; - -namespace ov { -namespace intel_gna { -namespace backend { - -class PWLSegmentsCreatorFactory { -public: - static std::shared_ptr CreateCreator(DnnActivationType activation_type); -}; - -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/pwl_segments_creator_identity.cpp b/src/plugins/intel_gna/src/backend/pwl_segments_creator_identity.cpp deleted file mode 100644 index adb8e285854..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_segments_creator_identity.cpp +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "pwl_segments_creator_identity.hpp" - -#include "gna_slope_scale.hpp" -#include "log/debug.hpp" -#include "log/log.hpp" -#include "pwl_input_params.hpp" -#include "pwl_tools.hpp" -#include "runtime/pwl.h" - -namespace ov { -namespace intel_gna { -namespace backend { -using namespace pwl_tools; - -PWLSegmentsCreatorIdentity::PWLSegmentsCreatorIdentity(std::shared_ptr border_counter) - : border_counter_(std::move(border_counter)) { - if (border_counter_ == nullptr) { - THROW_GNA_EXCEPTION << "Passed border_counter() is nullptr"; - } -} - -std::vector PWLSegmentsCreatorIdentity::CreateSegments(const PWLInputParams& input_params) const { - const auto border_values = border_counter_->CreateBorderValues(input_params); - return CreateSegments(input_params, border_values); -} - -PWLSegmentsWithBorderValues PWLSegmentsCreatorIdentity::CreateSegmentsWithBorders( - const PWLInputParams& input_params) const { - const auto border_values = border_counter_->CreateBorderValues(input_params); - auto segments = CreateSegments(input_params, border_values); - return {border_values, segments}; -} - -std::vector PWLSegmentsCreatorIdentity::CreateSegments(const PWLInputParams& input_params, - const BorderValues& border_values) const { - std::vector segments; - - // segment 0 - segments.push_back(CreateSegment0(border_values)); - - // segment 1 - segments.push_back(CreateSegment1(input_params, border_values)); - - // It was decided based on 89164 to introduce extra segment to ensure that PWL for Identity will cross (0,0). - // count zero of function for middle segment. - // - // Check if segment 1 passes passes throygh the point (0,0) - auto y0 = CountYAndValidateForX0(border_values, segments[1]); - - if (y0 != 0) { - log::debug() << "PWL does not pass (0,0), F(0)=" << y0 << "! Adjusting PWL segments."; - // if y0 != 0 add new segment, update previous one and cound properly next one if needed. - - // create a new segment with xBase = 0 and yBase = 0 - // use the same slope and scale as for previous segment - segments.push_back(CreateSegment0_0(input_params)); - - // adapt xBase for point on the left side of 0,0 to ensure that F(-1) <= F(0) - UpdateSegmentOnTheLeftOf0_0(segments[0], segments[1], y0); - } - - AddRightSegmentIFNeeded(border_values, segments); - - return segments; -} - -void PWLSegmentsCreatorIdentity::AddRightSegmentIFNeeded(const ov::intel_gna::backend::BorderValues& border_values, - std::vector& segments) const { - if (std::numeric_limits::max() > border_values.x_upper) { - segments.push_back(CreateSegmentOnTheRight(segments.back(), border_values)); - } -} - -gna_pwl_segment_t PWLSegmentsCreatorIdentity::CreateSegment0( - const ov::intel_gna::backend::BorderValues& border_values) const { - return {ComputeXBaseForSegment(std::numeric_limits::min(), 0), border_values.y_lower, 0}; -} - -gna_pwl_segment_t PWLSegmentsCreatorIdentity::CreateSegment1( - const PWLInputParams& input_params, - const ov::intel_gna::backend::BorderValues& border_values) const { - auto slope = ComputeSlopeForSegment(1.0, input_params.in_scale(), input_params.out_scale()); - int32_t x_base = ComputeXBaseForSegment(border_values.x_lower, slope.index); - return {x_base, border_values.y_lower, slope.value}; -} - -gna_pwl_segment_t PWLSegmentsCreatorIdentity::CreateSegment0_0(const PWLInputParams& input_params) const { - auto slope = ComputeSlopeForSegment(1.0, input_params.in_scale(), input_params.out_scale()); - auto x_base = ComputeXBaseForSegment(0, slope.index); - return {x_base, 0, slope.value}; -} - -int16_t PWLSegmentsCreatorIdentity::CountYAndValidateForX0(const ov::intel_gna::backend::BorderValues& border_values, - const gna_pwl_segment_t& segment) const { - auto y0 = ComputePWL(segment, 0); - - if (y0 > border_values.y_upper || y0 < border_values.y_lower) { - THROW_GNA_EXCEPTION << "Invalid parameters. F(0)=" << y0 << " exceedes allowed values <" - << border_values.y_lower << ", " << border_values.y_upper << ">"; - } - return static_cast(y0); -} - -void PWLSegmentsCreatorIdentity::UpdateSegmentOnTheLeftOf0_0(const gna_pwl_segment_t& segment_0, - gna_pwl_segment_t& segment_1, - const int64_t delta_y) const { - // new_segment_1_x_base = segment_1.xBase - (segment_0.yBase - segment_1.yBase - y_delta) * segment_1.scale_factor / - // segment_1.slope - auto segment_0_in_int64 = ConvertSegmentTo64(segment_0); - auto segment_1_in_int64 = ConvertSegmentTo64(segment_1); - - if (segment_1_in_int64.slope == 0) { - THROW_GNA_EXCEPTION << "Slope is 0 possible division by 0 when updating left segment!."; - } - - int64_t new_segment_1_x_base = - segment_1_in_int64.x_base - (segment_0_in_int64.y_base - segment_1_in_int64.y_base - delta_y) * - segment_1_in_int64.slope_scale / segment_1_in_int64.slope; - - // to ensure that segment 1 will not have x_base lower than segment 0 - if (new_segment_1_x_base < segment_0_in_int64.x_base && new_segment_1_x_base + 1 < 0) { - new_segment_1_x_base = segment_0_in_int64.x_base + 1; - } - - new_segment_1_x_base = Round2LSBTowardZero(new_segment_1_x_base); - auto slope_scale_index = GetScaleIndex(segment_1.xBase); - segment_1.xBase = ComputeXBaseForSegment(static_cast(new_segment_1_x_base), slope_scale_index); -} - -gna_pwl_segment_t PWLSegmentsCreatorIdentity::CreateSegmentOnTheRight(const gna_pwl_segment_t& segment_0_0, - const BorderValues& border_values) const { - // right_segment_x_base = segment_0_0.xBase + (border_values.y_upper - segment_0_0.yBase ) * - // segment_0_0.scale_facotr / segment_0_0.slope - auto segment_0_0_in_int64 = ConvertSegmentTo64(segment_0_0); - int64_t right_y_base_64 = static_cast(border_values.y_upper); - - if (segment_0_0_in_int64.slope == 0) { - THROW_GNA_EXCEPTION << "Slope is 0 possible division by 0 when calculating right segment!."; - } - - int64_t right_segment_x_base = segment_0_0_in_int64.x_base + (right_y_base_64 - segment_0_0_in_int64.y_base) * - segment_0_0_in_int64.slope_scale / - segment_0_0_in_int64.slope; - if (right_segment_x_base > std::numeric_limits::max()) { - right_segment_x_base = std::numeric_limits::max(); - } - - right_segment_x_base = Round2LSBTowardZero(right_segment_x_base); - auto segment_x_base_32 = ComputeXBaseForSegment(static_cast(right_segment_x_base), 0); - return {segment_x_base_32, border_values.y_upper, 0}; -} - -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/pwl_segments_creator_identity.hpp b/src/plugins/intel_gna/src/backend/pwl_segments_creator_identity.hpp deleted file mode 100644 index 0caf921d0f3..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_segments_creator_identity.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "pwl_segments_creator.hpp" - -enum DnnActivationType : uint8_t; - -namespace ov { -namespace intel_gna { -namespace backend { - -class PWLSegmentsCreatorIdentity : public PWLSegmentsCreator { -public: - PWLSegmentsCreatorIdentity(std::shared_ptr border_counter); - ~PWLSegmentsCreatorIdentity() override = default; - -protected: - std::vector CreateSegments(const PWLInputParams& input_params) const override; - PWLSegmentsWithBorderValues CreateSegmentsWithBorders(const PWLInputParams& input_params) const override; - -private: - std::vector CreateSegments(const PWLInputParams& input_params, - const BorderValues& border_values) const; - void AddRightSegmentIFNeeded(const ov::intel_gna::backend::BorderValues& border_values, - std::vector& segments) const; - gna_pwl_segment_t CreateSegment0(const ov::intel_gna::backend::BorderValues& border_values) const; - gna_pwl_segment_t CreateSegment1(const PWLInputParams& input_params, - const ov::intel_gna::backend::BorderValues& border_values) const; - gna_pwl_segment_t CreateSegment0_0(const PWLInputParams& input_params) const; - int16_t CountYAndValidateForX0(const ov::intel_gna::backend::BorderValues& border_values, - const gna_pwl_segment_t& segment) const; - - void UpdateSegmentOnTheLeftOf0_0(const gna_pwl_segment_t& before_left_segment, - gna_pwl_segment_t& left_segment, - const int64_t delta_y) const; - gna_pwl_segment_t CreateSegmentOnTheRight(const gna_pwl_segment_t& segment_0_0, - const BorderValues& border_values) const; - -private: - std::shared_ptr border_counter_; -}; - -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/pwl_tools.cpp b/src/plugins/intel_gna/src/backend/pwl_tools.cpp deleted file mode 100644 index ea709589d66..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_tools.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "pwl_tools.hpp" - -#include "common/numerical_utils.hpp" -#include "gna_slope_scale.hpp" -#include "runtime/pwl.h" - -namespace ov { -namespace intel_gna { -namespace backend { -namespace pwl_tools { - -int32_t GetXBaseValue(const int32_t x_base) { - return static_cast(x_base & XBASEMASK); -} - -int32_t ComputeXBaseForSegment(const int32_t x_base, const int32_t index) { - auto result = GetXBaseValue(x_base); - return static_cast(result |= index); -} - -int64_t ComputeSlopeScale(const int32_t x_base) { - return static_cast(1ULL << (8 * (GetScaleIndex(x_base) + 1))); -} - -PWLSegmentSlope ComputeSlopeForSegment(double slope, double in_scale, double out_scale) { - const auto gna_slope_value = gna_slope(slope, in_scale, out_scale); - auto segment_slope = common::DoubleToInt64(gna_slope_value.slope * gna_slope_value.slope_scale); - - if (segment_slope > std::numeric_limits::max()) { - segment_slope = std::numeric_limits::max(); - } - return {static_cast(segment_slope), static_cast(gna_slope_value.slope_scale_index)}; -} - -int32_t GetScaleIndex(const int32_t x_base) { - return static_cast(x_base & XBASE_SCALE_INDEX_MASK); -} - -int64_t ComputePWL(const gna_pwl_segment_t& segment, int64_t x) { - auto segment_in_int64 = ConvertSegmentTo64(segment); - if (segment_in_int64.slope_scale == 0) { - THROW_GNA_EXCEPTION << "slope_scale is 0, possible division by 0 when calculating function value"; - } - return (x - segment_in_int64.x_base) * segment_in_int64.slope / segment_in_int64.slope_scale + - segment_in_int64.y_base; -} - -int64_t ComputeXForValuePWL(const gna_pwl_segment_t& segment, int64_t y) { - auto segment_in_int64 = ConvertSegmentTo64(segment); - if (segment.slope == 0) { - THROW_GNA_EXCEPTION << "Slope is 0, possible division by when calculation x for given y"; - } - return segment_in_int64.x_base - segment_in_int64.y_base * segment_in_int64.slope_scale / segment_in_int64.slope; -} - -PWLSegmentAs64 ConvertSegmentTo64(const gna_pwl_segment_t& segment) { - // conversion to int64_t done to avoid unitended converion to unsigned which cause errors - const int64_t x_base = GetXBaseValue(segment.xBase); - const int64_t y_base = static_cast(segment.yBase); - const int64_t slope = static_cast(segment.slope); - const int64_t slope_scale = ComputeSlopeScale(segment.xBase); - return {x_base, y_base, slope, slope_scale}; -} - -int64_t Round2LSBTowardZero(const int64_t value) { - // ensure that masking 2LSB will not affect final results - return value / 4 * 4; -} -} // namespace pwl_tools -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/backend/pwl_tools.hpp b/src/plugins/intel_gna/src/backend/pwl_tools.hpp deleted file mode 100644 index e5d33a2e257..00000000000 --- a/src/plugins/intel_gna/src/backend/pwl_tools.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "backend/gna_types.hpp" - -namespace ov { -namespace intel_gna { -namespace backend { -namespace pwl_tools { - -/** - * Extract data from gna_pwl_segment_t and prepare in the form ready to be used in calculation. - */ -struct PWLSegmentAs64 { - int64_t x_base; // contains xBase & XBASEMASK - int64_t y_base; // yBase - int64_t slope; // slope - int64_t slope_scale; // 2^(3 * ( z + 1)) where z is the 2 less significant bits of xBase -}; - -struct PWLSegmentSlope { - int16_t value; - int32_t index; -}; - -int32_t GetXBaseValue(const int32_t x_base); -int32_t ComputeXBaseForSegment(const int32_t x_base, const int32_t index); -PWLSegmentSlope ComputeSlopeForSegment(double slope, double in_scale, double out_scale); -int64_t ComputeSlopeScale(const int32_t x_base); -int32_t GetScaleIndex(const int32_t x_base); -int64_t ComputePWL(const gna_pwl_segment_t& segment, int64_t x); -int64_t ComputeXForValuePWL(const gna_pwl_segment_t& segment, int64_t y); -PWLSegmentAs64 ConvertSegmentTo64(const gna_pwl_segment_t& segment); -int64_t Round2LSBTowardZero(const int64_t value); -} // namespace pwl_tools -} // namespace backend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/common/gna_target.cpp b/src/plugins/intel_gna/src/common/gna_target.cpp deleted file mode 100644 index 3f0240721bc..00000000000 --- a/src/plugins/intel_gna/src/common/gna_target.cpp +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_target.hpp" - -#include -#include - -#include "log/debug.hpp" -#include "misc_utils.hpp" - -namespace ov { -namespace intel_gna { -using namespace common; -namespace target { - -static constexpr const char* kGnaTargetUnspecified = ""; -static constexpr const char* kGnaTargetSoftwareEmulation = "GNA_SW_EMULATION"; -static constexpr const char* kGnaTarget1_0 = "GNA_TARGET_1_0"; -static constexpr const char* kGnaTarget1_0_e = "GNA_TARGET_1_0_E"; -static constexpr const char* kGnaTarget2_0 = "GNA_TARGET_2_0"; -static constexpr const char* kGnaTarget3_0 = "GNA_TARGET_3_0"; -static constexpr const char* kGnaTarget3_1 = "GNA_TARGET_3_1"; -static constexpr const char* kGnaTarget3_5 = "GNA_TARGET_3_5"; -static constexpr const char* kGnaTarget3_5_e = "GNA_TARGET_3_5_E"; -static constexpr const char* kGnaTarget3_6 = "GNA_TARGET_3_6"; -static constexpr const char* kGnaTarget4_0 = "GNA_TARGET_4_0"; - -static const std::unordered_map HWGenerationDeviceMap{ - {HWGeneration::GNA_1_0, DeviceVersion::GNA1_0}, - {HWGeneration::GNA_1_0_E, DeviceVersion::GNAEmbedded1_0}, - {HWGeneration::GNA_2_0, DeviceVersion::GNA2_0}, - {HWGeneration::GNA_3_0, DeviceVersion::GNA3_0}, - {HWGeneration::GNA_3_1, DeviceVersion::GNA3_1}, - {HWGeneration::GNA_3_5, DeviceVersion::GNA3_5}, - {HWGeneration::GNA_3_5_E, DeviceVersion::GNAEmbedded3_5}, - {HWGeneration::GNA_3_6, DeviceVersion::GNA3_6}, - {HWGeneration::GNA_4_0, DeviceVersion::GNA4_0}, - {HWGeneration::UNDEFINED, DeviceVersion::NotSet}}; - -static const std::unordered_map GnaDeviceMap{ - {Gna2DeviceVersion1_0, DeviceVersion::GNA1_0}, - {Gna2DeviceVersionEmbedded1_0, DeviceVersion::GNAEmbedded1_0}, - {Gna2DeviceVersion2_0, DeviceVersion::GNA2_0}, - {Gna2DeviceVersion3_0, DeviceVersion::GNA3_0}, - {Gna2DeviceVersionEmbedded3_1, DeviceVersion::GNA3_1}, - {Gna2DeviceVersion3_5, DeviceVersion::GNA3_5}, - {Gna2DeviceVersionEmbedded3_5, DeviceVersion::GNAEmbedded3_5}, - {Gna2DeviceVersionEmbedded3_5, DeviceVersion::GNA3_6}, - {Gna2DeviceVersionEmbedded3_5, DeviceVersion::GNA4_0}, - {Gna2DeviceVersionSoftwareEmulation, DeviceVersion::SoftwareEmulation}}; - -static const std::unordered_map StringDeviceMap{ - {kGnaTarget1_0, DeviceVersion::GNA1_0}, - {kGnaTarget1_0_e, DeviceVersion::GNAEmbedded1_0}, - {kGnaTarget2_0, DeviceVersion::GNA2_0}, - {kGnaTarget3_0, DeviceVersion::GNA3_0}, - {kGnaTarget3_1, DeviceVersion::GNA3_1}, - {kGnaTarget3_5, DeviceVersion::GNA3_5}, - {kGnaTarget3_5_e, DeviceVersion::GNAEmbedded3_5}, - {kGnaTarget3_6, DeviceVersion::GNA3_6}, - {kGnaTarget4_0, DeviceVersion::GNA4_0}, - {kGnaTargetSoftwareEmulation, DeviceVersion::SoftwareEmulation}, - {kGnaTargetUnspecified, DeviceVersion::NotSet}}; - -static const std::vector EmbeddedDevices{DeviceVersion::GNAEmbedded1_0, - DeviceVersion::GNA3_1, - DeviceVersion::GNAEmbedded3_5, - DeviceVersion::GNA3_6, - DeviceVersion::GNA4_0}; - -DeviceVersion HwGenerationToDevice(const HWGeneration& target) { - return GetValueForKey(target, HWGenerationDeviceMap); -} - -HWGeneration DeviceToHwGeneration(const DeviceVersion& target) { - return GetKeyForValue(target, HWGenerationDeviceMap); -} - -DeviceVersion GnaToDevice(const Gna2DeviceVersion& target) { - return GetValueForKey(target, GnaDeviceMap); -} - -Gna2DeviceVersion DeviceToGna(const DeviceVersion& target) { - return GetKeyForValue(target, GnaDeviceMap); -} - -DeviceVersion StringToDevice(const std::string& target) { - return GetValueForKey(target, StringDeviceMap); -} - -std::string DeviceToString(const DeviceVersion& target) { - return GetKeyForValue(target, StringDeviceMap); -} - -bool IsEmbeddedDevice(const DeviceVersion& target) { - return std::find(EmbeddedDevices.begin(), EmbeddedDevices.end(), target) != EmbeddedDevices.end(); -} - -DeviceVersion Target::get_detected_device_version() const { - return detected_device_version; -} - -DeviceVersion Target::get_user_set_execution_target() const { - return user_set_execution_target; -} - -DeviceVersion Target::get_user_set_compile_target() const { - return user_set_compile_target; -} - -void Target::set_detected_device_version(DeviceVersion detected_device) { - detected_device_version = detected_device; -} - -void Target::set_user_set_execution_target(DeviceVersion execution_target) { - user_set_execution_target = execution_target; -} - -void Target::set_user_set_compile_target(DeviceVersion compile_target) { - user_set_compile_target = compile_target; -} - -DeviceVersion Target::get_effective_execution_target() const { - if (user_set_execution_target != DeviceVersion::NotSet) { - return user_set_execution_target; - } else if (detected_device_version == DeviceVersion::SoftwareEmulation) { - return DeviceVersion::Default; - } else { - return detected_device_version; - } -} - -DeviceVersion Target::get_effective_compile_target() const { - if (user_set_compile_target != DeviceVersion::NotSet) { - return user_set_compile_target; - } else if (detected_device_version == DeviceVersion::SoftwareEmulation) { - return DeviceVersion::Default; - } else { - return get_effective_execution_target(); - } -} - -} // namespace target -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/common/gna_target.hpp b/src/plugins/intel_gna/src/common/gna_target.hpp deleted file mode 100644 index 203d0ffb92d..00000000000 --- a/src/plugins/intel_gna/src/common/gna_target.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "gna2-common-api.h" -#include "openvino/runtime/intel_gna/properties.hpp" - -namespace ov { -namespace intel_gna { -namespace target { - -enum class DeviceVersion { - NotSet = -1, - SoftwareEmulation = 0, - GNA1_0 = 0x10, - GNAEmbedded1_0 = 0x10e, - GNA2_0 = 0x20, - GNA3_0 = 0x30, - GNA3_1 = 0x31e, - GNA3_5 = 0x35, - GNAEmbedded3_5 = 0x35e, - GNA3_6 = 0x36e, - GNA4_0 = 0x40e, - Default = GNA3_5 -}; - -class Target { -public: - DeviceVersion get_detected_device_version() const; - DeviceVersion get_user_set_execution_target() const; - DeviceVersion get_user_set_compile_target() const; - void set_detected_device_version(DeviceVersion detected_device); - void set_user_set_execution_target(DeviceVersion execution_target); - void set_user_set_compile_target(DeviceVersion compile_target); - DeviceVersion get_effective_execution_target() const; - DeviceVersion get_effective_compile_target() const; - -private: - DeviceVersion detected_device_version = DeviceVersion::SoftwareEmulation; - DeviceVersion user_set_execution_target = DeviceVersion::NotSet; - DeviceVersion user_set_compile_target = DeviceVersion::NotSet; -}; - -DeviceVersion HwGenerationToDevice(const HWGeneration& target); -HWGeneration DeviceToHwGeneration(const DeviceVersion& target); -DeviceVersion GnaToDevice(const Gna2DeviceVersion& target); -Gna2DeviceVersion DeviceToGna(const DeviceVersion& target); -DeviceVersion StringToDevice(const std::string& target); -std::string DeviceToString(const DeviceVersion& target); -bool IsEmbeddedDevice(const DeviceVersion& target); - -} // namespace target -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/common/graph_utils.hpp b/src/plugins/intel_gna/src/common/graph_utils.hpp deleted file mode 100644 index 07df0a23ffe..00000000000 --- a/src/plugins/intel_gna/src/common/graph_utils.hpp +++ /dev/null @@ -1,707 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include -#include - -#include "backend/gna_limitations.hpp" -#include "gna_plugin_config.hpp" -#include "layers/gna_convolution_layer.hpp" -#include "layers/gna_permute.hpp" -#include "legacy/ngraph_ops/convolution_ie.hpp" -#include "legacy/ngraph_ops/crop_ie.hpp" -#include "legacy/ngraph_ops/eltwise.hpp" -#include "legacy/ngraph_ops/fully_connected.hpp" -#include "legacy/ngraph_ops/power.hpp" -#include "legacy/ngraph_ops/relu_ie.hpp" -#include "legacy/ngraph_ops/scaleshift.hpp" -#include "ngraph/opsets/opset7.hpp" -#include "ngraph/opsets/opset8.hpp" -#include "ngraph/opsets/opset9.hpp" -#include "openvino/opsets/opset10.hpp" -#include "openvino/opsets/opset12.hpp" -#include "ops/copy.hpp" -#include "ops/identity.hpp" -#include "ops/pwl.hpp" -#include "transformations/rt_info/gna_transpose_fusable.hpp" -#include "transformations/utils/transformation_helper.hpp" -#include "transformations/utils/utils.hpp" - -namespace ov { -namespace intel_gna { -namespace graph_utils { - -template -inline bool get_constant_value(const std::shared_ptr& constant, std::vector& values) { - using A = typename ov::element_type_traits::value_type; - const auto& v = constant->get_vector(); - std::transform(v.begin(), v.end(), std::back_inserter(values), [](A value) { - return static_cast(value); - }); - return true; -} - -inline bool get_constant_value(std::tuple<>&&, const std::shared_ptr&, std::vector&) { - return false; -} - -template -inline bool get_constant_value(std::tuple&&, - const std::shared_ptr& constant, - std::vector& values) { - return (constant->get_element_type() == T::value && get_constant_value(constant, values)) || - get_constant_value(std::tuple(), constant, values); -} - -inline bool get_constant_value(const std::shared_ptr& constant, std::vector& values) { - return get_constant_value(std::tuple, - std::integral_constant, - std::integral_constant, - std::integral_constant, - std::integral_constant, - std::integral_constant, - std::integral_constant>(), - constant, - values); -} - -inline bool get_constant_value(const std::shared_ptr& constant, double& value) { - std::vector values; - if (!get_constant_value(constant, values)) { - return false; - } - - if (values.empty() || values.size() > 1) { - throw std::runtime_error("The size of values is more than 1."); - } - - value = values[0]; - return true; -} - -/** - * @brief Checks if 2 shapes are the same - */ -inline bool are_shapes_equal(const ov::Shape& shape_1, const ov::Shape& shape_2) { - return (shape_1.size() == shape_2.size()) && std::equal(shape_1.begin(), shape_1.end(), shape_2.begin()); -} - -inline bool is_aligned_split(const std::shared_ptr input_op, size_t input_op_out_index) { - size_t offset = 0; - - if (std::dynamic_pointer_cast(input_op) || - std::dynamic_pointer_cast(input_op)) { - for (size_t index = 0; index < input_op_out_index; index++) { - size_t outputSize = ngraph::shape_size(input_op->get_output_shape(index)); - offset += outputSize * limitations::Limitations::kBytesPerSplitElement; - } - } - return limitations::Limitations::get_instance()->is_aligned(offset); -} - -inline bool is_crop_affined(std::shared_ptr node) { - auto crop = std::dynamic_pointer_cast(node); - if (crop != nullptr && !crop->offset.empty()) { - return limitations::Limitations::get_instance()->is_crop_affined_offset(crop->offset.back()); - } - return false; -} - -// this not only mathematically trivial -inline bool is_trivial_transpose(std::shared_ptr node) { - auto transpose = std::dynamic_pointer_cast(node); - if (!transpose) - return false; - - if (transpose->get_input_size() == 0) - return false; // unsupported case - - if (ov::intel_gna::rt_info::is_transpose_fusable(transpose)) - return true; - - auto transpose_const = - std::dynamic_pointer_cast(transpose->input_value(1).get_node_shared_ptr()); - if (!transpose_const) - return false; - - auto node_order = transpose_const->cast_vector(); - - auto input = transpose->input(0).get_source_output().get_node_shared_ptr(); - auto input_order = transpose->get_input_shape(0); - - return permute::isTrivialPermute(node_order, input_order); -} - -inline std::shared_ptr get_prev_node_skipping_certain( - const std::shared_ptr& node, - const std::function)>& skip) { - auto current_node = node; - while (skip(current_node)) { - current_node = current_node->get_input_node_shared_ptr(0); - } - return current_node; -} - -inline std::shared_ptr get_next_node_skipping_certain( - const std::shared_ptr& node, - const std::function)>& skip) { - auto current_node = node; - while (skip(current_node)) { - current_node = current_node->output(0).get_target_inputs().begin()->get_node()->shared_from_this(); - } - return current_node; -} - -inline bool is_gna_non_functional_node(const std::shared_ptr& node) { - return std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || is_trivial_transpose(node); -} - -inline bool is_one_dim_shape(const ov::Shape& dims) { - return std::count_if(std::begin(dims), std::end(dims), [](size_t dim) { - return dim != 1; - }) <= 1; -} - -inline bool is_one_dim_shapes(const ov::Shape& in_dims, const ov::Shape& out_dims) { - return is_one_dim_shape(in_dims) && is_one_dim_shape(out_dims); -} - -inline bool is_power_activation(const ov::Node* node) noexcept { - if (auto power_op = dynamic_cast(node)) { - auto const_node = std::dynamic_pointer_cast(power_op->get_input_node_shared_ptr(1)); - if (!const_node) - return false; - float value; - if (!ov::op::util::get_single_value(const_node, value)) { - return true; - } - return (1.0f != value); - } else if (auto power_op = dynamic_cast(node)) { - return (1.0f != power_op->power); - } - return false; -} - -inline bool is_power_activation(const std::shared_ptr& node) noexcept { - return is_power_activation(node.get()); -} - -inline bool is_eltwise_mul(const std::shared_ptr& node) { - auto eltwise = std::dynamic_pointer_cast(node); - if (!eltwise) - return false; - return eltwise->eltwise_type == ELTWISE_TYPE::Prod; -} - -inline bool is_eltwise_add(const std::shared_ptr& node) { - auto eltwise = std::dynamic_pointer_cast(node); - if (!eltwise) - return false; - return eltwise->eltwise_type == ELTWISE_TYPE::Sum; -} - -inline bool is_pooling(const std::shared_ptr& node) { - return ((std::dynamic_pointer_cast(node) != nullptr) || - std::dynamic_pointer_cast(node) != nullptr); -} - -inline bool is_concat(const std::shared_ptr& node) { - return (std::dynamic_pointer_cast(node) != nullptr); -} - -inline bool is_fake_quantize(const std::shared_ptr& node) { - return (std::dynamic_pointer_cast(node) != nullptr); -} - -inline bool is_read_value(const std::shared_ptr& node) { - return (std::dynamic_pointer_cast(node) != nullptr); -} - -template -inline bool is_Tbit_fq(const std::shared_ptr& node) { - auto fq_node = std::dynamic_pointer_cast(node); - if (!fq_node) - return false; - auto levels = fq_node->get_levels(); - return (std::numeric_limits::max() == levels) || (std::numeric_limits::max() == levels - 1); -} - -inline bool is_32bit_fq(const std::shared_ptr& node) { - return is_Tbit_fq(node); -} - -inline bool is_16bit_fq(const std::shared_ptr& node) { - return is_Tbit_fq(node); -} - -inline bool is_8bit_fq(const std::shared_ptr& node) { - return is_Tbit_fq(node); -} - -inline bool is_activation(const ov::Node* node) noexcept { - return ((dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr) || is_power_activation(node) || - (dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr) || - (dynamic_cast(node) != nullptr)); -} - -inline bool is_activation(const std::shared_ptr& node) noexcept { - return is_activation(node.get()); -} - -inline bool is_non_functional(const std::shared_ptr& node) { - return std::dynamic_pointer_cast(node) != nullptr || - std::dynamic_pointer_cast(node) != nullptr || - std::dynamic_pointer_cast(node) != nullptr || - std::dynamic_pointer_cast(node) != nullptr; -} - -inline bool is_copy(const std::shared_ptr& node) { - return std::dynamic_pointer_cast(node) != nullptr; -} - -inline bool is_matmul(const std::shared_ptr& node) { - return std::dynamic_pointer_cast(node) != nullptr; -} - -inline bool is_fully_connected(const std::shared_ptr& node) { - return std::dynamic_pointer_cast(node) != nullptr; -} - -inline bool is_split(const std::shared_ptr& node) { - return std::dynamic_pointer_cast(node) != nullptr || - std::dynamic_pointer_cast(node) != nullptr; -} - -inline bool is_interleaved(const std::shared_ptr& node) { - return is_matmul(node) || is_fully_connected(node); -} - -inline bool is_gna_precision_agnostic(std::shared_ptr node) { - return ((std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || is_concat(node) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - ((std::dynamic_pointer_cast(node) != nullptr) && !is_crop_affined(node))); -} - -inline bool has_8bit_or_16_bit_output(const std::shared_ptr& node) noexcept { - return ((ngraph::op::is_parameter(node)) || (ngraph::op::is_constant(node)) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (is_activation(node) && (!is_32bit_fq(node))) || (is_8bit_fq(node) || (is_16bit_fq(node))) || - is_gna_precision_agnostic(node)); -} - -inline bool has_32bit_output(const std::shared_ptr& node) { - return ((std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || - (std::dynamic_pointer_cast(node) != nullptr) || is_pooling(node) || - ((std::dynamic_pointer_cast(node) != nullptr) && !is_power_activation(node)) || - ((std::dynamic_pointer_cast(node) != nullptr) && !is_power_activation(node)) || - is_crop_affined(node) || is_32bit_fq(node)); -} - -inline bool has_32bit_input(const std::shared_ptr& node) { - return is_activation(node) || is_pooling(node); -} - -/** - * @brief Remove all dimensions equal to 1 from the tensor shape vector - * @param shape original tensor shape vector - * @return modified shape - */ -inline ov::Shape squeeze_shape(const ov::Shape& shape) { - ov::Shape squeezed_shape; - squeezed_shape.reserve(shape.size()); - - auto if_not_eq_1 = [](ov::Shape::value_type value) { - return value != 1; - }; - std::copy_if(shape.begin(), shape.end(), std::back_inserter(squeezed_shape), if_not_eq_1); - - return squeezed_shape; -} - -/** - * @brief Remove all dimensions equal to 1 from the left and right of the tensor shape vector - * @param shape original tensor shape vector - * @return modified shape - */ -inline ov::Shape trim_shape(const ov::Shape& shape) { - auto comp = [](size_t x) { - return x != 1; - }; - - auto start_it = std::find_if(shape.begin(), shape.end(), comp); - auto end_it = std::find_if(shape.rbegin(), shape.rend(), comp); - if (start_it == shape.end() || end_it == shape.rend()) { - return ov::Shape(shape.begin(), shape.end()); - } - return ov::Shape(start_it, end_it.base()); -} - -/** - * @brief Transpose shape - * @param shape the shape to be transposed - * @param order the permutation array to apply to the input shape - * @return transposed shape - */ -inline ov::Shape transpose_shape(const ov::Shape& shape, std::vector order) { - if (shape.size() != order.size()) { - THROW_GNA_EXCEPTION << "Sizes of the shape " << shape.size() << " and transpose axis " << order.size() - << " are different"; - } - ov::Shape transposed(shape.size()); - for (size_t i = 0; i < shape.size(); ++i) { - transposed[i] = shape[order[i]]; - } - return transposed; -} - -/** - * @brief Create gather indexes using transpose axes. - * @param input_shape the shape to be transposed as gather - * @param order the permutation array to apply to the input shape - * @return vector with indexes to gather - */ -inline std::vector make_gather_indexes_from_transpose_axes(const Shape& input_shape, const AxisVector& order) { - // Supported shape ranks: 2d, 3d, 4d - if (input_shape.size() < 2 || input_shape.size() > 4) { - THROW_GNA_EXCEPTION << "Usupported shape size: " << input_shape.size(); - } - - ov::Shape input_shape_4d = input_shape; - ov::AxisVector order_4d = order; - // Just to simplify the code we transform all shapes to 4d by adding dimension(s) equal to 1 at the end - while (input_shape_4d.size() < 4) { - input_shape_4d.push_back(1); - order_4d.push_back(order_4d.size()); - } - ov::Shape output_shape_4d = transpose_shape(input_shape_4d, order_4d); - - // common case when shape is 4d - std::vector xyz_4d = {input_shape_4d[3] * input_shape_4d[2] * input_shape_4d[1], - input_shape_4d[3] * input_shape_4d[2], - input_shape_4d[3], - 1}; - - std::vector xyz = transpose_shape(xyz_4d, order_4d); - std::vector gather_order; - - for (size_t n = 0; n < output_shape_4d[0]; ++n) { - for (size_t i = 0; i < output_shape_4d[1]; ++i) { - for (size_t j = 0; j < output_shape_4d[2]; ++j) { - for (size_t k = 0; k < output_shape_4d[3]; ++k) { - gather_order.push_back(n * xyz[0] + i * xyz[1] + j * xyz[2] + k * xyz[3]); - } - } - } - } - - return gather_order; -} - -inline int64_t get_first_valuable_dim_id(const ov::Shape& shape) { - for (size_t i = 0; i < shape.size(); ++i) { - if (shape[i] != 1) { - return i; - } - } - return -1; -} - -/** - * @brief Converts Gather indexes into positive form - */ -template -std::vector normalize_gather_indices(const std::vector& indices) { - std::vector normalized(indices.size()); - for (size_t i = 0; i < indices.size(); ++i) { - T index = indices[i]; - if (index < 0) - index += indices.size(); - normalized[i] = index; - } - return normalized; -} - -/** - * @brief Gets Gather indexes from Constant and converts them into positive form - */ -inline std::vector get_normalized_gather_indices(const std::shared_ptr& indices) { - return normalize_gather_indices(indices->cast_vector()); -} - -/** - * @brief Checks if node has dynamic rank inputs - */ -inline bool has_dynamic_rank_input(const std::shared_ptr& node) { - for (const auto& input_node : node->input_values()) { - const Rank output_rank = input_node.get_partial_shape().rank(); - if (output_rank.is_dynamic()) - return true; - } - return false; -} - -/** - * @brief Gets maximum rank of all input nodes - */ -inline Rank::value_type get_max_input_rank(const std::shared_ptr& node) { - Rank::value_type max_input_rank = 0; - for (auto& input_node : node->input_values()) { - const Rank output_rank = input_node.get_partial_shape().rank(); - if (output_rank.is_dynamic()) - return -1; - const Rank::value_type output_rank_len = output_rank.get_length(); - if (output_rank_len > max_input_rank) - max_input_rank = output_rank_len; - } - return max_input_rank; -} - -/** - * @brief Gets dimension value by axis (works if axis could be < 0) - */ -inline Shape::value_type get_dim_by_axis(const Shape& shape, int64_t axis) { - if (axis < 0) - axis += static_cast(shape.size()); - if (axis < 0 || axis >= static_cast(shape.size())) - throw std::runtime_error("get_dim_by_axis invalid axis"); - return shape[axis]; -} - -/** - * @brief unsqueezes shape to rank - */ -inline Shape unsqueeze_shape(const Shape& shape, ov::Rank::value_type rank) { - const ov::Rank::value_type rank_delta = rank - static_cast(shape.size()); - - if (rank_delta <= 0) - return shape; - - Shape broadcasted(rank); - for (int i = 0; i < rank_delta; ++i) { - broadcasted[i] = 1; - } - std::copy(shape.begin(), shape.end(), broadcasted.begin() + rank_delta); - - return broadcasted; -} - -/** - * @brief Converts axis to positive form - */ -inline int64_t convert_axis_to_positive(int64_t axis, ov::Rank rank) { - const auto rank_val = rank.get_length(); - if (axis < 0) - axis += rank_val; - if (axis < 0 || axis >= rank_val) - throw std::runtime_error("convert_axis_to_positive invalid axis"); - return axis; -} - -/** - * @brief Reverts gather indices in such a way that reverted and initial gather will do nothing if - * they stay one after another. Works only with positive form (no negative indices). - */ -inline std::vector reverse_gather_indexes(const std::vector& indexes) { - std::vector out(indexes.size()); - for (size_t i = 0; i < indexes.size(); i++) { - out.at(indexes[i]) = i; - } - return out; -} - -/** - * @brief Finds first consumer node - */ -inline Node* find_first_consumer(const std::shared_ptr& node) { - for (const auto& output : node->outputs()) { - auto inputs = output.get_target_inputs(); - if (inputs.empty()) - continue; - return inputs.begin()->get_node(); - } - return nullptr; -} - -/** - * @brief Finds first input node with type NodeT - */ -template -std::shared_ptr find_first_input_node(const std::shared_ptr& node) { - for (size_t input_idx = 0; input_idx < node->get_input_size(); ++input_idx) { - std::shared_ptr input_node = node->get_input_node_shared_ptr(input_idx); - auto target_node = ov::as_type_ptr(input_node); - if (target_node) - return target_node; - } - return {}; -} - -/** - * @brief Gets split axis from Constant converting it to positive form - */ -inline bool get_split_axis(const std::shared_ptr& split_axis, - const ov::Rank& rank, - int64_t& axis) { - auto split_axis_val = split_axis->cast_vector(); - if (split_axis_val.empty()) { - return false; - } - axis = convert_axis_to_positive(split_axis_val[0], rank); - return true; -} - -/** - * @brief Checks if has 2D input shape inputs - */ -inline bool has_2d_inputs(const ov::Output& output) { - auto node = output.get_node_shared_ptr(); - auto input_left_rank = node->get_input_partial_shape(0).rank(); - auto input_right_rank = node->get_input_partial_shape(0).rank(); - return (input_left_rank.is_static() && input_right_rank.is_static() && input_left_rank.get_length() == 2 && - input_right_rank.get_length() == 2); -} - -/** - * @brief Checks if the permutation does nothing - */ -inline bool is_pointless_permutation(const std::vector& indices) { - for (size_t i = 0; i < indices.size(); ++i) { - if (indices[i] != static_cast(i)) - return false; - } - return true; -} - -/** - * @brief Checks if MatMul input with @arg input_idx input is transposed - */ -inline bool is_matmul_input_transposed(const std::shared_ptr& matmul, size_t input_idx) { - if (!input_idx) - return matmul->get_transpose_a(); - return matmul->get_transpose_b(); -} - -/** - * @brief Checks if Reshape node is Unsqueeze - */ -inline bool is_reshape_unsqueeze(const ov::Output& output) { - auto reshape = output.get_node_shared_ptr(); - const ov::Shape input_shape = trim_shape(reshape->get_input_shape(0)); - const ov::Shape output_shape = trim_shape(reshape->get_output_shape(0)); - return are_shapes_equal(input_shape, output_shape); -} - -/** - * @brief Checks if output has rank not more than expected - */ -inline std::function)> rank_not_more_than(const ov::Rank::value_type expected_rank) { - return [=](Output output) -> bool { - const Rank rank = output.get_partial_shape().rank(); - return (rank.is_static() && (rank.get_length() <= expected_rank)); - }; -} - -/** - * @brief Checks if output has rank not more than expected - */ -inline bool constant_has_rank_not_more_than(const std::shared_ptr& node, - const ov::Rank::value_type expected_rank) { - const ov::Rank rank = node->get_output_partial_shape(0).rank(); - return (rank.is_static() && (rank.get_length() <= expected_rank)); -} - -/** - * @brief Checks if output is Constant with rank 1 - */ -inline bool is_constant_1d(const Output& output) { - return ov::pass::pattern::rank_equals(0)(output) || ov::pass::pattern::rank_equals(1)(output); -} - -/** - * @brief Checks if node has parent node with type T - */ -template -bool has_parent_node(std::shared_ptr node) { - for (const auto& parent : node->input_values()) { - if (dynamic_cast(parent.get_node())) - return true; - } - return false; -} - -/** - * @brief Checks if node has child node with type T - */ -template -bool has_child_node(std::shared_ptr node) { - for (size_t output_idx = 0; output_idx < node->get_output_size(); ++output_idx) { - for (auto& input : node->get_output_target_inputs(output_idx)) { - if (dynamic_cast(input.get_node())) - return true; - } - } - return false; -} - -/** - * @brief Checks if shape without dimensions == 1 is 2D - */ -inline bool is_shape_2d(const ov::Shape& shape) { - return graph_utils::squeeze_shape(shape).size() == 2; -} - -/** - * @brief Checks if node has N consumers - */ -inline bool has_n_consumers(const std::shared_ptr& node, size_t n_consumers) { - return node->output(0).get_target_inputs().size() == n_consumers; -} - -/** - * @brief Merge gather indexes. - * @param ids_in vector with indexes to 1st gather - * @param ids_out vector with indexes to 2nd gather - * @return vector with indexes to merged gather - */ -inline std::vector combine_gather_indexes(const std::vector& ids_in, - const std::vector& ids_out) { - if (ids_in.size() != ids_out.size()) - return {}; - std::vector result(ids_in.size()); - for (size_t i = 0; i < result.size(); ++i) { - result[i] = ids_in[ids_out[i]]; - } - return result; -} - -} // namespace graph_utils -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/common/misc_utils.hpp b/src/plugins/intel_gna/src/common/misc_utils.hpp deleted file mode 100644 index d5d56cde915..00000000000 --- a/src/plugins/intel_gna/src/common/misc_utils.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "log/debug.hpp" - -namespace ov { -namespace intel_gna { -namespace common { - -template -U GetValueForKey(const T& key, const std::unordered_map& mapping) { - const auto key_iter = mapping.find(key); - if (key_iter != mapping.end()) { - return key_iter->second; - } - THROW_GNA_EXCEPTION << "Unsupported map key" << std::endl; -} - -template -T GetKeyForValue(const U& value, const std::unordered_map& mapping) { - for (const auto& item : mapping) { - if (item.second == value) { - return item.first; - } - } - THROW_GNA_EXCEPTION << "Unsupported map value" << std::endl; -} - -} // namespace common -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/common/numerical_utils.hpp b/src/plugins/intel_gna/src/common/numerical_utils.hpp deleted file mode 100644 index b44dc0a8dfd..00000000000 --- a/src/plugins/intel_gna/src/common/numerical_utils.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -namespace ov { -namespace intel_gna { -namespace common { - -template ::value>::type* = nullptr> -inline T FloatingToInteger(U a) { - return static_cast((a < 0.0f) ? (a - static_cast(0.5)) : (a + static_cast(0.5))); -} -inline int8_t FloatToInt8(float a) { - return FloatingToInteger(a); -} -inline int16_t FloatToInt16(float a) { - return FloatingToInteger(a); -} -inline int32_t FloatToInt32(float a) { - return FloatingToInteger(a); -} -inline int64_t FloatToInt64(float a) { - return FloatingToInteger(a); -} -inline int8_t DoubleToInt8(double a) { - return FloatingToInteger(a); -} -inline int16_t DoubleToInt16(double a) { - return FloatingToInteger(a); -} -inline int32_t DoubleToInt32(double a) { - return FloatingToInteger(a); -} -inline int64_t DoubleToInt64(double a) { - return FloatingToInteger(a); -} - -/** - * @brief Compare two floating point values and return true if they are equal with given accuracy - * @param p1 First floating point value - * @param p2 Second floating point value - * @param accuracy accuracy of comparision - * @return Returns true if two floating point values are equal - */ -template ::value, int>::type = 0> -bool AreFpEq(T p1, T p2, T accuracy = std::numeric_limits::epsilon()) { - return (std::abs(p1 - p2) <= accuracy * std::min(std::abs(p1), std::abs(p2))); -} - -} // namespace common -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/common/versioning.cpp b/src/plugins/intel_gna/src/common/versioning.cpp deleted file mode 100644 index 1ddaee1ce46..00000000000 --- a/src/plugins/intel_gna/src/common/versioning.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "versioning.hpp" - -#include -#include - -#include "openvino/core/version.hpp" - -namespace ov { -namespace intel_gna { -namespace common { - -std::string get_openvino_version_string() { - std::stringstream s; - s << ov::get_openvino_version(); - return s.str(); -} -} // namespace common -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/common/versioning.hpp b/src/plugins/intel_gna/src/common/versioning.hpp deleted file mode 100644 index 72dcba73d7b..00000000000 --- a/src/plugins/intel_gna/src/common/versioning.hpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include -namespace ov { -namespace intel_gna { -namespace common { -// Returns string representing current version of OpenVINO -std::string get_openvino_version_string(); -} // namespace common -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/connection_details.hpp b/src/plugins/intel_gna/src/connection_details.hpp deleted file mode 100644 index 39b05869360..00000000000 --- a/src/plugins/intel_gna/src/connection_details.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { - -struct ConnectionDetails { - InferenceEngine::CNNLayerPtr input; - bool needTransposeWeights = false; - InferenceEngine::CNNLayerPtr permute; - ConnectionDetails(InferenceEngine::CNNLayerPtr input, - bool bTranspose = false, - InferenceEngine::CNNLayerPtr permute = nullptr) - : input(input), - needTransposeWeights(bTranspose), - permute(permute) {} -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/descriptions/gna_desc.hpp b/src/plugins/intel_gna/src/descriptions/gna_desc.hpp deleted file mode 100644 index 3b1e1414c59..00000000000 --- a/src/plugins/intel_gna/src/descriptions/gna_desc.hpp +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -#include "backend/dnn_types.hpp" -#include "gna_plugin_config.hpp" -#include "ie_algorithm.hpp" -#include "ie_input_info.hpp" -#include "ie_precision.hpp" - -namespace ov { -namespace intel_gna { - -/* - * This base structure accumulates all required information for network inputs and outputs - */ -struct GnaDesc { - // common OV properties - std::string name = ""; - std::unordered_set tensor_names = {}; - InferenceEngine::Layout model_layout = InferenceEngine::Layout::ANY; - InferenceEngine::SizeVector dims = {}; - InferenceEngine::Precision model_precision = InferenceEngine::Precision::UNSPECIFIED; - InferenceEngine::Precision tensor_precision = InferenceEngine::Precision::UNSPECIFIED; - - // gna specific properties - float scale_factor = kScaleFactorDefault; - intel_dnn_orientation_t orientation = kDnnUnknownOrientation; - uint32_t num_elements = 0; - uint32_t allocated_size = 0; - std::vector ptrs = {}; // ptr per each infer request - - // pre/post processing model - std::shared_ptr pre_post_process_model = nullptr; - - // help methods - uint32_t get_required_size() const { - return num_elements * static_cast(tensor_precision.size()); - } - - uint32_t get_allocated_size() const { - return allocated_size; - } - - void set_precision(InferenceEngine::Precision::ePrecision precision) { - this->tensor_precision = precision; - } - - // helps to get the precision for gna layers, because they use num_bytes instead of precision values - void set_precision(uint32_t num_bytes) { - switch (num_bytes) { - case sizeof(int8_t): { - set_precision(InferenceEngine::Precision::I8); - break; - } - case sizeof(int16_t): { - set_precision(InferenceEngine::Precision::I16); - break; - } - case sizeof(int32_t): { - set_precision(InferenceEngine::Precision::I32); - break; - } - default: - set_precision(InferenceEngine::Precision::UNSPECIFIED); - } - } - - InferenceEngine::DataPtr to_ie_data() { - OPENVINO_SUPPRESS_DEPRECATED_START - return std::make_shared( - name, - InferenceEngine::TensorDesc(model_precision, dims, model_layout)); - OPENVINO_SUPPRESS_DEPRECATED_END - } -}; - -/* - * This structure accumulates all required information for one the network input - */ -struct InputDesc : GnaDesc { - InputDesc(const std::string& name) { - this->name = name; - } - - void Update(const InferenceEngine::InputInfo::Ptr inputInfo) { - this->model_precision = inputInfo->getPrecision(); - this->tensor_precision = inputInfo->getPrecision(); - this->model_layout = inputInfo->getLayout(); - this->dims = inputInfo->getTensorDesc().getDims(); - this->name = inputInfo->name(); - this->num_elements = static_cast(InferenceEngine::details::product(dims.begin(), dims.end())); - } - - InferenceEngine::InputInfo::Ptr ToIEInputInfo() { - OPENVINO_SUPPRESS_DEPRECATED_START - InferenceEngine::InputInfo::Ptr input_info = std::make_shared(); - input_info->setInputData(this->to_ie_data()); - return input_info; - OPENVINO_SUPPRESS_DEPRECATED_END - } -}; - -/* - * This structure accumulates all required information for one network output - */ -struct OutputDesc : GnaDesc { - OutputDesc(const std::string& name) { - this->name = name; - } - - void Update(const InferenceEngine::DataPtr outputData) { - this->model_precision = outputData->getPrecision(); - this->tensor_precision = outputData->getPrecision(); - this->model_layout = outputData->getLayout(); - this->dims = outputData->getTensorDesc().getDims(); - this->name = outputData->getName(); - this->num_elements = static_cast(InferenceEngine::details::product(dims.begin(), dims.end())); - } -}; - -/** - * Wraps vectors of input/output structure to keep their order and simplify usage. - * @tparam T - InputDesc/OutputDesc - */ -template -class GnaNetworkInfo { -private: - std::vector infos_; - -public: - GnaNetworkInfo() : infos_({}) {} - - const T& at(const std::string& key) const { - if (key.empty()) { - throw std::invalid_argument("The key cannot be empty"); - } - auto desc_it = find(key); - if (desc_it == infos_.end()) { - throw std::out_of_range("The key cannot be found"); - } - return *desc_it; - } - - T& at(const std::string& key) { - return const_cast(static_cast(*this).at(key)); - } - - typename std::vector::iterator end() { - return infos_.end(); - } - - typename std::vector::const_iterator find(const std::string& key) const { - return std::find_if(infos_.cbegin(), infos_.cend(), [&key](const T& desc) { - return desc.name == key; - }); - } - - typename std::vector::iterator find(const std::string& key) { - return std::find_if(infos_.begin(), infos_.end(), [&key](const T& desc) { - return desc.name == key; - }); - } - - T& operator[](const std::string& key) { - if (key.empty()) { - throw std::invalid_argument("The key cannot be empty"); - } - auto desc_it = std::find_if(infos_.begin(), infos_.end(), [&key](const T& desc) { - return desc.name == key; - }); - if (desc_it == infos_.end()) { - infos_.push_back(T(key)); - return infos_.back(); - } - return *desc_it; - } - - size_t size() const { - return infos_.size(); - } - - bool empty() const { - return infos_.empty(); - } - - const std::vector& Get() const { - return infos_; - } - - std::vector& Get() { - return infos_; - } -}; - -typedef GnaNetworkInfo GnaInputs; -typedef GnaNetworkInfo GnaOutputs; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/descriptions/gna_flags.hpp b/src/plugins/intel_gna/src/descriptions/gna_flags.hpp deleted file mode 100644 index c84975b9a42..00000000000 --- a/src/plugins/intel_gna/src/descriptions/gna_flags.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "gna/gna_config.hpp" -#include "openvino/runtime/intel_gna/properties.hpp" - -namespace ov { -namespace intel_gna { - -struct GNAFlags { - uint8_t num_requests = 1; - bool compact_mode = true; - bool exclusive_async_requests = false; - ov::intel_gna::PWLDesignAlgorithm pwl_design_algorithm = ov::intel_gna::PWLDesignAlgorithm::UNDEFINED; - bool uniformPwlDesign = false; - float pwlMaxErrorPercent = 1.0f; - bool gna_openmp_multithreading = false; - bool sw_fp32 = false; - bool performance_counting = false; - bool input_low_precision = false; - ov::log::Level log_level = ov::log::Level::NO; -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/frontend/layer_quantizer.cpp b/src/plugins/intel_gna/src/frontend/layer_quantizer.cpp deleted file mode 100644 index d4423f14af8..00000000000 --- a/src/plugins/intel_gna/src/frontend/layer_quantizer.cpp +++ /dev/null @@ -1,383 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "layer_quantizer.hpp" - -#include "backend/gna_types.hpp" -#include "common/gna_target.hpp" -#include "gna_graph_tools.hpp" -#include "weights_converter.hpp" - -namespace ov { -namespace intel_gna { -using namespace limitations; -namespace frontend { - -template -inline bool LayerQuantizer::ShouldAlwaysAllocate() { - return false; -} - -template <> -inline bool LayerQuantizer::ShouldAlwaysAllocate() { - return true; -} - -template -InferenceEngine::Blob::Ptr LayerQuantizer::FP32ToPrecisionBlob(InferenceEngine::Blob::Ptr fp32_blob, - InferenceEngine::Precision precision, - QuantizationParams& dst_quant_params) { - auto prec_blob = InferenceEngine::make_shared_blob( - {precision, fp32_blob->getTensorDesc().getDims(), fp32_blob->getTensorDesc().getLayout()}); - prec_blob->allocate(); - - auto input_low = 0.0f; - auto input_high = 0.0f; - auto output_low = 0.0f; - auto output_high = 0.0f; - uint32_t levels = 1; - - if (dst_quant_params.IsStatsSet()) { - input_low = dst_quant_params.GetMinValues(true).front(); - input_high = dst_quant_params.GetMaxValues(true).front(); - output_low = dst_quant_params.GetMinValues(false).front(); - output_high = dst_quant_params.GetMaxValues(false).front(); - levels = static_cast(dst_quant_params.GetLevels()); - } - - auto f32_value_array = fp32_blob->buffer().as(); - - for (auto& prec_value : *prec_blob) { - auto f32_value = *f32_value_array++; - - if (dst_quant_params.IsStatsSet()) { - f32_value = ApplyFQ(f32_value, input_low, input_high, output_low, output_high, levels); - } - - f32_value = f32_value * dst_quant_params.GetScale(); - prec_value = SaturationCast(f32_value); - } - - return static_cast(prec_blob); -} - -InferenceEngine::Blob::Ptr LayerQuantizer::FP32ToPrecisionBlob(InferenceEngine::Blob::Ptr fp32_blob, - InferenceEngine::Precision precision, - QuantizationParams& dst_quant_params) { - InferenceEngine::Blob::Ptr result_ptr = nullptr; - switch (precision) { - case InferenceEngine::Precision::FP32: - result_ptr = FP32ToPrecisionBlob(fp32_blob, precision, dst_quant_params); - break; - case InferenceEngine::Precision::I32: - result_ptr = FP32ToPrecisionBlob(fp32_blob, precision, dst_quant_params); - break; - case InferenceEngine::Precision::I16: - result_ptr = FP32ToPrecisionBlob(fp32_blob, precision, dst_quant_params); - break; - case InferenceEngine::Precision::I8: - result_ptr = FP32ToPrecisionBlob(fp32_blob, precision, dst_quant_params); - break; - default: - THROW_GNA_EXCEPTION << "FP32 to " << precision << " not supported"; - } - return result_ptr; -} - -size_t LayerQuantizer::GetBiasSizeForLayer(InferenceEngine::WeightableLayer& wl) { - if (wl._biases) { - return wl._biases->size(); - } else if (LayerInfo(wl).isConvolution()) { - // Calculating biases len using outdata dims: biases number should be equal to output channels number - return InferenceEngine::GetDataDimSizeNHWC(wl.outData.front(), InferenceEngine::DataDimName::C); - } else { - // Calculating biases size using outData dimensions - return wl.outData.front()->getDims().back(); - } -} - -std::pair LayerQuantizer::GetNumRowsColumns(InferenceEngine::WeightableLayer& wl) { - size_t num_rows = 0; - size_t num_columns = 0; - - if (LayerInfo(wl).isScaleShift()) { - num_columns = 1; - num_rows = wl._weights->size(); - } else if (LayerInfo(wl).isConvolution() || LayerInfo(wl).isConvolutionFilter()) { - num_rows = GetBiasSizeForLayer(wl); - - if (num_rows == 0) { - THROW_GNA_EXCEPTION << "Invalid nummber of rows"; - } - - num_columns = wl._weights->size() / num_rows; - } else if (LayerInfo(wl).isAffineFilter() || LayerInfo(wl).isConcatAlignFilter()) { - // For affine filter layer insdata size is not equal to the one stored in input layer - num_rows = wl.outData.front()->getDims().back(); - num_columns = wl._weights->size() / num_rows; - } else { - num_rows = wl.outData.front()->getDims().back(); - num_columns = wl.insData.front().lock().get()->getDims().back(); - } - - return {num_rows, num_columns}; -} - -template -void LayerQuantizer::QuantizeWeightsPrep(InferenceEngine::WeightableLayer& wl, QuantizationData& common_data) { - const auto weights_precision = InferenceEngine::Precision::fromType(); - const auto int_weights = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(weights_precision, - InferenceEngine::SizeVector({wl._weights->size()}), - InferenceEngine::C)); - - int_weights->allocate(); - - if (int_weights->buffer() == nullptr) { - IE_THROW(NotAllocated) << "[GNAPlugin] in function " << __PRETTY_FUNCTION__ << ": " - << "cannot copy weights for layer :" << wl.name << " of size" << int_weights->byteSize(); - } - - common_data.scale_factor = InferenceEngine::getInjectedData(wl)->_weights_quant.GetScale(); - const auto& blob_precision = wl._weights->getTensorDesc().getPrecision(); - const auto& quantized_weights = - blob_precision != InferenceEngine::Precision::FP32 && blob_precision != InferenceEngine::Precision::FP16; - const bool& compound_bias = - IsBiasCompound(LayerInfo(wl), *InferenceEngine::getInjectedData(wl), gna_config); - const auto& compound_bias_ptr = - (compound_bias && wl._biases) ? wl._biases->buffer().as() : nullptr; - - QuantizeWeights(common_data, - wl._weights->buffer().as(), - int_weights->buffer(), - compound_bias_ptr, - quantized_weights); - - wl._weights = int_weights; - - // Correcting precision for outdata - wl.precision = weights_precision; -} - -void LayerQuantizer::QuantizeWeightsPrep(InferenceEngine::Precision precision, - InferenceEngine::WeightableLayer& wl, - QuantizationData& common_data) { - switch (precision) { - case InferenceEngine::Precision::I8: - QuantizeWeightsPrep(wl, common_data); - break; - case InferenceEngine::Precision::I16: - QuantizeWeightsPrep(wl, common_data); - break; - default: - THROW_GNA_EXCEPTION << "Weights precision " << precision << " not supported!"; - } -} - -template -void LayerQuantizer::QuantizeBiasesPrep(InferenceEngine::WeightableLayer& wl, QuantizationData& common_data) { - const auto bias_maker = [&]() { - InferenceEngine::Blob::Ptr zero; - if (!wl._biases && !ShouldAlwaysAllocate()) { - return zero; - } - - InferenceEngine::Blob::Ptr bias = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(InferenceEngine::Precision::fromType(), - InferenceEngine::SizeVector({GetBiasSizeForLayer(wl)}), - InferenceEngine::C)); - - bias->allocate(); - - if (bias->buffer() == nullptr) { - IE_THROW(NotAllocated) << "[GNAPlugin] in function " << __PRETTY_FUNCTION__ << ": " - << "cannot copy bias for layer :" << wl.name << "of size" << bias->byteSize(); - } - - memset(bias->buffer(), 0, bias->byteSize()); - - return bias; - }; - - const auto int_biases = bias_maker(); - common_data.scale_factor = InferenceEngine::getInjectedData(wl)->_dst_quant.GetScale(); - - QuantizeBiases(common_data, - wl._biases ? wl._biases->buffer().as() : nullptr, - int_biases ? int_biases->buffer() : static_cast(nullptr)); - - wl._biases = int_biases; -} - -void LayerQuantizer::QuantizeBiasesPrep(InferenceEngine::Precision precision, - InferenceEngine::WeightableLayer& wl, - QuantizationData& common_data) { - const auto compound_bias_precision = InferenceEngine::Precision::fromType(); - - if (precision == InferenceEngine::Precision::I8) { - QuantizeBiasesPrep(wl, common_data); - } else if (precision == InferenceEngine::Precision::I16) { - QuantizeBiasesPrep(wl, common_data); - } else if (precision == InferenceEngine::Precision::I32) { - QuantizeBiasesPrep(wl, common_data); - } else if (precision == compound_bias_precision) { - QuantizeBiasesPrep(wl, common_data); - } else { - THROW_GNA_EXCEPTION << "Biases precision " << precision << " not supported!"; - } -} - -void LayerQuantizer::QuantizeWeightsBiases(InferenceEngine::WeightableLayer& wl) { - float input_scale_factor = 1.f; - - if (InferenceEngine::CNNNetHasPrevLayer(&wl)) { - auto quant_data_for_input_layer = - InferenceEngine::getInjectedData(InferenceEngine::CNNNetPrevLayer(&wl)); - input_scale_factor = quant_data_for_input_layer->_dst_quant.GetScale(); - if (std::isnan(input_scale_factor) || std::isinf(input_scale_factor)) { - IE_THROW() << "Unsupported input scale factor value " << input_scale_factor; - } - } - - size_t num_rows; - size_t num_columns; - - std::tie(num_rows, num_columns) = GetNumRowsColumns(wl); - - auto quant_layer_params = InferenceEngine::getInjectedData(wl); - - QuantizationData common_data{num_rows, num_columns, kScaleFactorDefault, quant_layer_params->_weights_quant}; - - auto bias_prec = GetBiasesPrecision(LayerInfo(wl), *quant_layer_params, gna_config); - auto weight_prec = GetWeightsPrecision(LayerInfo(wl), *quant_layer_params, gna_config); - - QuantizeBiasesPrep(bias_prec, wl, common_data); - QuantizeWeightsPrep(weight_prec, wl, common_data); - - // Correct precision for outdata - for (auto&& outData : wl.outData) { - outData->setPrecision(GetOutputPrecision()); - } -} - -void LayerQuantizer::SetLayerOutputPrecision(InferenceEngine::CNNLayer& cnn_layer) { - // Set scale factor for input layers - if (cnn_layer.insData.empty() || LayerInfo(cnn_layer).isCrop() || LayerInfo(cnn_layer).isConcat() || - LayerInfo(cnn_layer).isSplit() || LayerInfo(cnn_layer).isActivation() || LayerInfo(cnn_layer).isCopy() || - LayerInfo(cnn_layer).isNonFunctional() || LayerInfo(cnn_layer).isPermute() || LayerInfo(cnn_layer).isConst() || - LayerInfo(cnn_layer).isMaxPooling()) { - // Precision of activation and pooling layers is always equal input precision - for (auto&& out_data : cnn_layer.outData) { - out_data->setPrecision(GetInputPrecision()); - } - } else { - for (auto&& out_data : cnn_layer.outData) { - out_data->setPrecision(GetOutputPrecision()); - } - } -} - -void LayerQuantizer::CreateConstBlob(InferenceEngine::CNNLayer& cnn_layer) { - auto initial_precision = cnn_layer.blobs["custom"]->getTensorDesc().getPrecision(); - IE_ASSERT(initial_precision != InferenceEngine::Precision::I32); - - if (initial_precision == InferenceEngine::Precision::FP16) { - cnn_layer.blobs["custom"] = make_fp32_blob(cnn_layer.blobs["custom"]); - } - - auto quant_params = InferenceEngine::getInjectedData(cnn_layer); - auto new_const_blob = InferenceEngine::Blob::CreateFromData(cnn_layer.outData.front()); - auto const_blob = cnn_layer.blobs["custom"]; - - if (const_blob->getTensorDesc().getPrecision() == InferenceEngine::Precision::FP32) { - cnn_layer.blobs["custom"] = - FP32ToPrecisionBlob(const_blob, cnn_layer.outData.front()->getPrecision(), quant_params->_dst_quant); - } -} - -void LayerQuantizer::quantize(InferenceEngine::CNNLayer& layer) { - auto layer_info = LayerInfo(layer); - - if (layer_info.isWeightable()) { - QuantizeWeightsBiases(dynamic_cast(layer)); - } else { - layer.precision = GetInputPrecision(); - - SetLayerOutputPrecision(layer); - - if (layer_info.isConst()) { - CreateConstBlob(layer); - } - } -} - -LayerQuantizer::LayerQuantizer(const Config& gna_config) : gna_config(gna_config) {} - -InferenceEngine::Precision LayerQuantizer::GetOutputPrecision() { - return InferenceEngine::Precision::I32; -} - -InferenceEngine::Precision GetBiasesPrecision(const LayerInfo& layer_info, - const QuantizedLayerParams& quant_layer_params, - const Config& gna_config) { - if (layer_info.isConvolution() || layer_info.isConvolutionFilter() || layer_info.isScaleShift()) { - return InferenceEngine::Precision::I32; - } - - if (quant_layer_params._weights_quant.IsStatsSet()) { - // For networks with FakeQuantize layers - const auto fq_levels = quant_layer_params._weights_quant.GetLevels(); - - if (fq_levels <= std::numeric_limits::max()) { - return InferenceEngine::Precision::fromType(); - } else { - return InferenceEngine::Precision::I32; - } - } else { - if (gna_config.gnaFlags.input_low_precision) { - return InferenceEngine::Precision::I8; - } else { - return (GetWeightsPrecision(layer_info, quant_layer_params, gna_config) == InferenceEngine::Precision::I8) - ? InferenceEngine::Precision::fromType() - : InferenceEngine::Precision{InferenceEngine::Precision::I32}; - } - } -} - -InferenceEngine::Precision GetInputPrecision() { - return InferenceEngine::Precision::I16; -} - -InferenceEngine::Precision GetWeightsPrecision(const LayerInfo& layer_info, - const QuantizedLayerParams& quant_layer_params, - const Config& gna_config) { - if (((layer_info.isConvolution() || layer_info.isConvolutionFilter()) && - Limitations::get_instance()->use_only_16bit_convolution_weights()) || - layer_info.isScaleShift()) { - return InferenceEngine::Precision::I16; - } - - if (quant_layer_params._weights_quant.IsStatsSet()) { - // For networks with FakeQuantize layers - if (quant_layer_params._weights_quant.GetLevels() <= std::numeric_limits::max()) { - return InferenceEngine::Precision::I8; - } else { - return InferenceEngine::Precision::I16; - } - } else { - return gna_config.gnaPrecision; - } -} - -bool IsBiasCompound(const LayerInfo& layer_info, - const QuantizedLayerParams& quant_layer_params, - const Config& gna_config) { - auto biases_precision = GetBiasesPrecision(layer_info, quant_layer_params, gna_config); - auto compound_bias_precision = InferenceEngine::Precision::fromType(); - return (biases_precision == compound_bias_precision); -} - -} // namespace frontend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/frontend/layer_quantizer.hpp b/src/plugins/intel_gna/src/frontend/layer_quantizer.hpp deleted file mode 100644 index 2a7a3ac9f03..00000000000 --- a/src/plugins/intel_gna/src/frontend/layer_quantizer.hpp +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "descriptions/gna_desc.hpp" -#include "layers/gna_layer_info.hpp" -#include "quantization.hpp" -#include "quantized_layer_params.hpp" - -namespace ov { -namespace intel_gna { -namespace frontend { - -/** - * @brief Returns layer's target input precision - * @return layer's target input precision - */ -InferenceEngine::Precision GetInputPrecision(); - -/** - * @brief Returns layer's target weights precision - * @param layer_info Layer's information - * @param quant_layer_params Layer's quantization parameters - * @param gna_config GNA Plugin configuration - * @return layer's target weights precision - */ -InferenceEngine::Precision GetWeightsPrecision(const LayerInfo& layer_info, - const QuantizedLayerParams& quant_layer_params, - const Config& gna_config); - -/** - * @brief Returns layer's target biases precision - * @param layer_info Layer's information - * @param quant_layer_params Layer's quantization parameters - * @param gna_config GNA Plugin configuration - * @return layer's target biases precision - */ -InferenceEngine::Precision GetBiasesPrecision(const LayerInfo& layer_info, - const QuantizedLayerParams& quant_layer_params, - const Config& gna_config); - -/** - * @brief Checks whether layer's target biases are compound - * @param layer_info Layer's information - * @param quant_layer_params Layer's quantization parameters - * @param gna_config GNA Plugin configuration - * @return true if layer's target biases are compound - */ -bool IsBiasCompound(const LayerInfo& layer_info, - const QuantizedLayerParams& quant_layer_params, - const Config& gna_config); - -class LayerQuantizer { - const Config& gna_config; - - void QuantizeWeightsBiases(InferenceEngine::WeightableLayer& wl); - void SetLayerOutputPrecision(InferenceEngine::CNNLayer& cnn_layer); - void CreateConstBlob(InferenceEngine::CNNLayer& cnn_layer); - std::pair GetNumRowsColumns(InferenceEngine::WeightableLayer& wl); - InferenceEngine::Blob::Ptr FP32ToPrecisionBlob(InferenceEngine::Blob::Ptr fp32_blob, - InferenceEngine::Precision precision, - QuantizationParams& dst_quant_params); - - template - InferenceEngine::Blob::Ptr FP32ToPrecisionBlob(InferenceEngine::Blob::Ptr fp32_blob, - InferenceEngine::Precision precision, - QuantizationParams& dst_quant_params); - - template - void QuantizeWeightsPrep(InferenceEngine::WeightableLayer& wl, QuantizationData& common_data); - - void QuantizeWeightsPrep(InferenceEngine::Precision precision, - InferenceEngine::WeightableLayer& wl, - QuantizationData& common_data); - - template - void QuantizeBiasesPrep(InferenceEngine::WeightableLayer& wl, QuantizationData& common_data); - - void QuantizeBiasesPrep(InferenceEngine::Precision precision, - InferenceEngine::WeightableLayer& wl, - QuantizationData& common_data); - - template - inline bool ShouldAlwaysAllocate(); - - size_t GetBiasSizeForLayer(InferenceEngine::WeightableLayer& wl); - InferenceEngine::Precision GetOutputPrecision(); - -public: - LayerQuantizer(const Config& gna_config); - - void quantize(InferenceEngine::CNNLayer& layer); -}; - -template <> -inline bool LayerQuantizer::ShouldAlwaysAllocate(); - -} // namespace frontend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/frontend/model_quantizer.hpp b/src/plugins/intel_gna/src/frontend/model_quantizer.hpp deleted file mode 100644 index 3de59b15f80..00000000000 --- a/src/plugins/intel_gna/src/frontend/model_quantizer.hpp +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -#include "descriptions/gna_desc.hpp" -#include "gna_graph_tools.hpp" -#include "gna_itt.hpp" -#include "gna_plugin_config.hpp" -#include "gna_transformations_pipeline.hpp" -#include "layer_quantizer.hpp" -#include "scale_factor_calc.hpp" -#include "weights_converter.hpp" - -namespace ov { -namespace intel_gna { -namespace frontend { - -/** - * Quantize entire network - */ -class ModelQuantizer { - ov::intel_gna::TransformationsPipeline& gna_transformer; - -public: - ModelQuantizer(ov::intel_gna::TransformationsPipeline& transformer) : gna_transformer(transformer) {} - InferenceEngine::CNNNetwork quantize(const InferenceEngine::CNNNetwork& model, const GnaInputs& inputs) const { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "ModelQuantizer::quantize"); - auto visitor = [&](InferenceEngine::CNNLayerPtr layer_ptr) { - auto new_layer = InferenceEngine::injectData(layer_ptr); - convert_blobs_precision(*new_layer); - return new_layer; - }; - - InferenceEngine::CNNNetwork copied_net = InferenceEngine::CNNNetCopy(model); - gna_transformer.apply_legacy(copied_net, true); - copied_net = InferenceEngine::CNNNetCopy(copied_net, visitor); - - // Allow client code to access copied topology, to avoid copies if user would like to chain quantisation with - // another preprocessing - gna_transformer.apply_legacy(copied_net, false); - - auto sorted_new_net = InferenceEngine::details::CNNNetSortTopologically(copied_net); - log::debug() << "Sorted layers: " << std::endl; - - // Filling scale factors for input layers, memory layers will have scale factor of 1.0 by default - InferenceEngine::InputsDataMap dm = copied_net.getInputsInfo(); - for (auto&& inputData : dm) { - auto input_layer = getCreatorLayer(inputData.second->getInputData()).lock(); - auto quant_data = InferenceEngine::getInjectedData(input_layer); - IE_ASSERT(quant_data != nullptr); - quant_data->_src_quant.SetScale(inputs.at(input_layer->name).scale_factor); - } - - // Propagate scale factor and quantize layers - propagateScaleFactor(sorted_new_net); - frontend::LayerQuantizer lq(gna_transformer.config); - - for (auto&& layer : sorted_new_net) { - lq.quantize(*layer); - } - - return copied_net; - } - -private: - void propagateScaleFactor(std::vector& net) const { - ScaleFactorCalculator sf(net, gna_transformer.config, gna_transformer.is_fake_quantized()); - uint32_t inf_loop_count = 0; - std::vector inf_loop_pattern; - std::vector inf_loop_history; - while (!sf.allLayersProcessed() && inf_loop_count <= 2) { - auto layers = sf.getStartLayers(); - inf_loop_history.emplace_back(layers.front()->name); - for (auto&& layer : layers) { - sf.CalculateScaleFactor(layer); - // transforming until we reached cases where output scale updated due to situation in downstream layer - if (sf.needToRestart()) { - inf_loop_history.back() += "#" + layer->name; - break; - } - } - - // We are looking for infinite loop by using algorithm of compute prefix function, complexity O(N) - // (a part of the Knuth–Morris–Pratt algorithm). - std::map prefix_function; - auto k = static_cast(inf_loop_history.size()); - for (int32_t i = static_cast(inf_loop_history.size()) - 2; i >= 0; i--) { - while (k < static_cast(inf_loop_history.size()) && - inf_loop_history[k - 1] != inf_loop_history[i]) { - auto iter = prefix_function.find(k); - k = iter == prefix_function.end() ? static_cast(inf_loop_history.size()) : iter->second; - } - - if (inf_loop_history[k - 1] == inf_loop_history[i]) { - k--; - } - - // The pattern length is a length of a repeating string sequence (it is 2 in the example below). - // concat_14_input_0_reshape#concat_15 - // concat_15_input_1_reshape#add_12 - // add_12#Add_16 - // Reshape_41#add_12 - // add_12#Add_16 - // Reshape_41#add_12 - // - // In the case of pattern length is 1, an infinite loop can be found on 2 consecutive strings. - // To avoid this, we will expect the appearance of 4 equal strings for the case pattern length is 1. - if ((inf_loop_history.size() - i) % 2 == 0 && - (inf_loop_history.size() - i) / 2 == inf_loop_history.size() - k && - ((inf_loop_history.size() - i) / 2 > 1 || - std::distance(inf_loop_history.rbegin(), - std::find_if_not(inf_loop_history.rbegin(), - inf_loop_history.rend(), - [&inf_loop_history](const std::string& str) { - return str == inf_loop_history.back(); - })) > 3)) { - log::debug() << "inf_loop_pattern:\n"; - for (const auto& s : inf_loop_pattern) { - log::debug() << "\t " << s << '\n'; - } - inf_loop_pattern.clear(); - auto pattern_len = (static_cast(inf_loop_history.size()) - i) / 2; - log::debug() << "pattern_len: " << pattern_len << '\n'; - for (int j = 0; j < pattern_len; j++) { - inf_loop_pattern.emplace_back(inf_loop_history[inf_loop_history.size() - pattern_len + j]); - } - log::debug() << "inf_loop_history:\n"; - for (const auto& s : inf_loop_history) { - log::debug() << "\t " << s << '\n'; - } - inf_loop_history.clear(); - log::debug() << "infinite loop detected\n"; - break; - } - - prefix_function.emplace(i, k); - } - - if (inf_loop_history.empty()) { - inf_loop_count++; - } else { - if (inf_loop_count > 0 && - ((inf_loop_pattern.size() > 0 && (inf_loop_history.size() % inf_loop_pattern.size() == 0)) || - sf.allLayersProcessed())) { - size_t history_shift = 0; - size_t pattern_shift = 0; - - if (inf_loop_history.size() > inf_loop_pattern.size()) { - history_shift = inf_loop_history.size() - inf_loop_pattern.size(); - } else { - pattern_shift = inf_loop_pattern.size() - inf_loop_history.size(); - } - - if (!std::equal(inf_loop_history.begin() + history_shift, - inf_loop_history.end(), - inf_loop_pattern.begin() + pattern_shift)) { - inf_loop_count = 0; - log::debug() << "inf_loop_pattern:\n"; - for (const auto& s : inf_loop_pattern) { - log::debug() << "\t " << s << '\n'; - } - inf_loop_pattern.clear(); - log::debug() << "infinite loop fixed\n"; - } - } - } - - sf.SetInfiniteLoopCount(inf_loop_count); - } - - if (inf_loop_count > 0) { - std::string additional_info; - for (const auto& p : inf_loop_pattern) { - additional_info += '\n' + p; - } - THROW_GNA_EXCEPTION << "infinite loop: " + additional_info; - } - } -}; - -} // namespace frontend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/frontend/precision_ex.hpp b/src/plugins/intel_gna/src/frontend/precision_ex.hpp deleted file mode 100644 index d50c2301c54..00000000000 --- a/src/plugins/intel_gna/src/frontend/precision_ex.hpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "ie_precision.hpp" - -namespace InferenceEngine { - -/** - * @brief reverse trait for getting some precision from it's underlined memory type - * this might not work for certain precisions : for Q78, U16 - * @tparam T - */ -template -struct precision_from_media { - static const Precision::ePrecision type = Precision::CUSTOM; -}; - -template <> -struct precision_from_media { - static const Precision::ePrecision type = Precision::FP32; -}; - -template <> -struct precision_from_media { - static const Precision::ePrecision type = Precision::FP16; -}; - -template <> -struct precision_from_media { - static const Precision::ePrecision type = Precision::I16; -}; - -template <> -struct precision_from_media { - static const Precision::ePrecision type = Precision::U8; -}; - -template <> -struct precision_from_media { - static const Precision::ePrecision type = Precision::I8; -}; - -template <> -struct precision_from_media { - static const Precision::ePrecision type = Precision::I32; -}; - -/** - * @brief container for storing both precision and it's underlined media type - * @tparam TMedia - */ -template -class TPrecision : public Precision { -public: - typedef TMedia MediaType; - TPrecision() : Precision(precision_from_media::type) {} - explicit TPrecision(const Precision& that) : Precision(that) {} - TPrecision& operator=(const Precision& that) { - Precision::operator=(that); - return *this; - } - explicit TPrecision(const Precision::ePrecision value) : Precision(value) {} -}; - -// special case for Mixed, or undefined precisions -template <> -class TPrecision : public Precision { -public: - typedef void MediaType; - TPrecision() = default; - explicit TPrecision(const Precision& that) : Precision(that) {} - TPrecision& operator=(const Precision& that) { - Precision::operator=(that); - return *this; - } - explicit TPrecision(const Precision::ePrecision value) : Precision(value) {} -}; - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/src/frontend/quantization.cpp b/src/plugins/intel_gna/src/frontend/quantization.cpp deleted file mode 100644 index deb8663801a..00000000000 --- a/src/plugins/intel_gna/src/frontend/quantization.cpp +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "quantization.hpp" - -#include -#include -#include - -#include "backend/gna_types.hpp" -#include "layers/gna_fake_quantize_layer.hpp" -#include "log/debug.hpp" -#include "log/log.hpp" - -namespace ov { -namespace intel_gna { -namespace frontend { - -float ApplyFQ(float value, float input_low, float input_high, float output_low, float output_high, uint32_t levels) { - if (value <= std::min(input_low, input_high)) { - return output_low; - } else if (value > std::max(input_low, input_high)) { - return output_high; - } else { - return nearbyint((value - input_low) / (input_high - input_low) * (levels - 1)) / (levels - 1) * - (output_high - output_low) + - output_low; - } -} - -std::pair FindMinMaxValues(void* ptr_float_memory, size_t num_elements) { - float* ptr_float_feat = reinterpret_cast(ptr_float_memory); - float min = num_elements ? ptr_float_feat[0] : 0.0f; - float max = num_elements ? ptr_float_feat[0] : 0.0f; - - for (size_t i = 1; i < num_elements; i++) { - if (fabs(ptr_float_feat[i]) > max) { - max = fabs(ptr_float_feat[i]); - } - - if (fabs(ptr_float_feat[i]) < min) { - min = fabs(ptr_float_feat[i]); - } - } - - return {min, max}; -} - -float ScaleFactorForQuantization(void* ptr_float_memory, float target_max, size_t num_elements) { - float* ptr_float_feat = reinterpret_cast(ptr_float_memory); - float max = 0.0f; - float scale_factor; - - for (size_t i = 0; i < num_elements; i++) { - if (fabs(ptr_float_feat[i]) > max) { - max = fabs(ptr_float_feat[i]); - } - } - - if (max == 0) { - scale_factor = -1.0f; // need to handle all zeros as a special case - } else { - scale_factor = target_max / max; - } - - return (scale_factor); -} - -template -void QuantizeWeights(const QuantizationData& data, - float* ptr_float_weights, - T* ptr_int_weights, - gna_compound_bias_t* ptr_int_biases, - const bool quantized_weights) {} - -template -void QuantizeBiases(const QuantizationData& data, float* ptr_float_biases, T* ptr_int_biases) {} - -template <> -void QuantizeWeights(const QuantizationData& data, - float* ptr_float_weights, - int8_t* ptr_int_weights, - gna_compound_bias_t* ptr_int_biases, - const bool quantized_weights) { - if (!ptr_int_biases && quantized_weights) { - THROW_GNA_EXCEPTION << "Quantized weights are not yet supported in int8 quantization mode"; - } - - uint32_t num_saturate = 0; - auto input_low = 0.0f; - auto input_high = 0.0f; - auto output_low = 0.0f; - auto output_high = 0.0f; - uint32_t levels = 1; - const auto min_values_size = data.weights_quant_params.GetMinValues().size(); - - if (min_values_size > 0) { - input_low = data.weights_quant_params.GetMinValues(true).front(); - input_high = data.weights_quant_params.GetMaxValues(true).front(); - output_low = data.weights_quant_params.GetMinValues(false).front(); - output_high = data.weights_quant_params.GetMaxValues(false).front(); - levels = static_cast(data.weights_quant_params.GetLevels()); - } - - for (size_t row = 0; row < data.num_rows; row++) { - uint32_t channel_multiplier = 1; - - if (ptr_int_biases) { - if (min_values_size > 0) { - auto idx = min_values_size == 1 ? 0 : row; - input_low = data.weights_quant_params.GetMinValues(true).at(idx); - input_high = data.weights_quant_params.GetMaxValues(true).at(idx); - output_low = data.weights_quant_params.GetMinValues(false).at(idx); - output_high = data.weights_quant_params.GetMaxValues(false).at(idx); - levels = static_cast(data.weights_quant_params.GetLevels()); - channel_multiplier = - static_cast(((input_high - input_low) * data.scale_factor) / (levels - 1)); - } else { - float scaled_row_max = 0; - for (size_t col = 0; col < data.num_columns; col++) { - float value = ptr_float_weights[row * data.num_columns + col] * data.scale_factor; - if (fabs(value) > scaled_row_max) { - scaled_row_max = fabs(value); - } - } - - channel_multiplier = - static_cast((scaled_row_max / static_cast(MAX_VAL_1B_WEIGHT) + 0.5f)); - } - - if (channel_multiplier > MAX_OUT_MULTIPLIER) { - THROW_GNA_EXCEPTION << "invalid channel multiplier: " << channel_multiplier; - } - - // channel multiplier shouldn't be 0 - ptr_int_biases[row].multiplier = (channel_multiplier == 0) ? 1 : channel_multiplier; - } - - for (uint32_t col = 0; col < data.num_columns; col++) { - auto offset = row * data.num_columns + col; - float rounding_value = (ptr_float_weights[offset] > 0) ? 0.5f : -0.5f; - float value = ptr_float_weights[offset]; - - if (min_values_size > 0) { - value = ApplyFQ(value, input_low, input_high, output_low, output_high, levels); - } - - if (ptr_int_biases) { - if (quantized_weights) { - value -= MAX_VAL_1B_WEIGHT; - } else { - value = value * (data.scale_factor / ptr_int_biases[row].multiplier) + rounding_value; - } - } else { - value = value * data.scale_factor + rounding_value; - } - - int8_t* ptr_weight_8 = ptr_int_weights + offset; - - *ptr_weight_8 = SaturationCast(value, &num_saturate); - } - } - - if (num_saturate > 0) { - log::warning() << num_saturate << " / " << (data.num_rows * data.num_columns) - << " saturations in int8 weights quantization." << std::endl; - } -} - -template <> -void QuantizeWeights(const QuantizationData& data, - float* ptr_float_weights, - int16_t* ptr_int_weights, - gna_compound_bias_t* ptr_int_biases, - const bool quantized_weights) { - if (quantized_weights) { - THROW_GNA_EXCEPTION << "Quantized weights are not yet supported in int16 quantization mode"; - } - - uint32_t num_saturate = 0; - auto input_low = 0.0f; - auto input_high = 0.0f; - auto output_low = 0.0f; - auto output_high = 0.0f; - uint32_t levels = 1; - const auto min_values_size = data.weights_quant_params.GetMinValues().size(); - - if (min_values_size > 0) { - input_low = data.weights_quant_params.GetMinValues(true).front(); - input_high = data.weights_quant_params.GetMaxValues(true).front(); - output_low = data.weights_quant_params.GetMinValues(false).front(); - output_high = data.weights_quant_params.GetMaxValues(false).front(); - levels = static_cast(data.weights_quant_params.GetLevels()); - } - - for (size_t row = 0; row < data.num_rows; row++) { - for (size_t col = 0; col < data.num_columns; col++) { - float rounding_value = (ptr_float_weights[row * data.num_columns + col] > 0) ? 0.5f : -0.5f; - float value = ptr_float_weights[row * data.num_columns + col]; - if (min_values_size > 0) { - value = ApplyFQ(value, input_low, input_high, output_low, output_high, levels); - } - - value = value * data.scale_factor + rounding_value; - - int16_t* ptr_weight_16 = ptr_int_weights + (row * data.num_columns + col); - - *ptr_weight_16 = SaturationCast(value, &num_saturate); - } - } - - if (num_saturate > 0) { - log::warning() << num_saturate << " / " << (data.num_rows * data.num_columns) - << " saturations in int16 weights quantization." << std::endl; - } -} - -template <> -void QuantizeBiases(const QuantizationData& data, float* ptr_float_biases, int8_t* ptr_int_biases) { - // Stub -} - -template <> -void QuantizeBiases(const QuantizationData& data, float* ptr_float_biases, int16_t* ptr_int_biases) { - // Stub -} - -template <> -void QuantizeBiases(const QuantizationData& data, float* ptr_float_biases, int32_t* ptr_int_biases) { - uint32_t num_saturate = 0; - - // case for element wise layer - if (ptr_float_biases != nullptr && ptr_int_biases != nullptr) { - for (size_t row = 0; row < data.num_rows; row++) { - float rounding_value = (ptr_float_biases[row] > 0) ? 0.5f : -0.5f; - float value = ptr_float_biases[row] * data.scale_factor + rounding_value; - - ptr_int_biases[row] = SaturationCast(value, &num_saturate); - } - } - - if (num_saturate > 0) { - log::warning() << num_saturate << " / " << data.num_rows << " saturations in int32 biases quantization." - << std::endl; - } -} - -template <> -void QuantizeBiases(const QuantizationData& data, - float* ptr_float_biases, - gna_compound_bias_t* ptr_int_biases) { - uint32_t num_saturate = 0; - - if (ptr_float_biases != nullptr) { - for (size_t row = 0; row < data.num_rows; row++) { - float rounding_value = (ptr_float_biases[row] > 0) ? 0.5f : -0.5f; - float value = ptr_float_biases[row] * data.scale_factor + rounding_value; - - ptr_int_biases[row].bias = SaturationCast(value, &num_saturate); - } - } - if (num_saturate > 0) { - log::warning() << num_saturate << " / " << data.num_rows << " saturations in compound biases quantization." - << std::endl; - } -} - -} // namespace frontend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/frontend/quantization.hpp b/src/plugins/intel_gna/src/frontend/quantization.hpp deleted file mode 100644 index 27f88d8c6af..00000000000 --- a/src/plugins/intel_gna/src/frontend/quantization.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "backend/gna_types.hpp" -#include "quantized_layer_params.hpp" - -namespace ov { -namespace intel_gna { -namespace frontend { - -#define MAX_OUT_MULTIPLIER 230 -#define MAX_VAL_1B_WEIGHT 127 -#define MAX_VAL_1B_FEAT 64 -#define MAX_VAL_1B_BIAS 127 -#define MAX_VAL_2B_WEIGHT 16384 -#define MAX_VAL_2B_FEAT 16384 -#define MAX_VAL_4B_BIAS 1073741824 - -// Common data required for quantization of weights and biases -struct QuantizationData { - const size_t num_rows; - const size_t num_columns; - float scale_factor; - // This field is currently used for weights as well as for biases - QuantizationParams& weights_quant_params; -}; - -std::pair FindMinMaxValues(void* ptr_float_memory, size_t num_elements); -float ScaleFactorForQuantization(void* ptr_float_memory, float target_max, size_t num_elements); -template -extern void QuantizeWeights(const QuantizationData& data, - float* ptr_float_weights, - T* ptr_int_weights, - gna_compound_bias_t* ptr_int_biases, - const bool quantized_weights); -template -extern void QuantizeBiases(const QuantizationData& data, float* ptr_float_biases, T* ptr_int_biases); - -#ifdef __clang__ -# pragma clang diagnostic push -# ifdef __has_warning -# if __has_warning("-Wimplicit-const-int-float-conversion") -# pragma clang diagnostic ignored "-Wimplicit-const-int-float-conversion" -# elif __has_warning("-Wimplicit-int-float-conversion") -# pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" -# endif -# endif -#endif - -template -inline T SaturationCast(float value, uint32_t* saturation_counter = nullptr) { - if (value > std::numeric_limits::max()) { - if (saturation_counter) { - (*saturation_counter)++; - } - return std::numeric_limits::max(); - } else if (value < std::numeric_limits::min()) { - if (saturation_counter) { - (*saturation_counter)++; - } - return std::numeric_limits::min(); - } else { - return static_cast(value); - } -} - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - -/** - * @brief Apply FQ levels onto a value - */ -float ApplyFQ(float value, float input_low, float input_high, float output_low, float output_high, uint32_t levels); - -} // namespace frontend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/frontend/quantized_layer_params.hpp b/src/plugins/intel_gna/src/frontend/quantized_layer_params.hpp deleted file mode 100644 index a26003a567f..00000000000 --- a/src/plugins/intel_gna/src/frontend/quantized_layer_params.hpp +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -namespace ov { -namespace intel_gna { -namespace frontend { - -class QuantizationParams { - float scale = 1.0f; - bool scale_set = false; - size_t levels = 0; - std::vector input_min_values; - std::vector input_max_values; - std::vector output_min_values; - std::vector output_max_values; - -public: - void SetScale(float s) { - scale = s; - scale_set = true; - } - float GetScale() const { - return scale; - } - bool IsScaleSet() const { - return scale_set; - } - void SetLevels(size_t l) { - levels = l; - } - size_t GetLevels() const { - return levels; - } - bool IsStatsSet() const { - return !input_min_values.empty() && !input_max_values.empty(); - } - void SetMinValues(const std::vector& min, bool input = true) { - if (input) { - input_min_values.clear(); - input_min_values.insert(input_min_values.end(), min.begin(), min.end()); - } else { - output_min_values.clear(); - output_min_values.insert(output_min_values.end(), min.begin(), min.end()); - } - } - std::vector& GetMinValues(bool input = true) { - if (input) { - return input_min_values; - } - - return output_min_values; - } - void SetMaxValues(const std::vector& max, bool input = true) { - if (input) { - input_max_values.clear(); - input_max_values.insert(input_max_values.end(), max.begin(), max.end()); - } else { - output_max_values.clear(); - output_max_values.insert(output_max_values.end(), max.begin(), max.end()); - } - } - std::vector& GetMaxValues(bool input = true) { - if (input) { - return input_max_values; - } - - return output_max_values; - } - void CopyStats(QuantizationParams& src) { - levels = src.GetLevels(); - SetMinValues(src.GetMinValues(true), true); - SetMaxValues(src.GetMaxValues(true), true); - SetMinValues(src.GetMinValues(false), false); - SetMaxValues(src.GetMaxValues(false), false); - } -}; - -struct QuantizedLayerParams { - QuantizationParams _src_quant; - QuantizationParams _dst_quant; - - // deprecate this - QuantizationParams _weights_quant; - QuantizationParams _bias_quant; -}; - -} // namespace frontend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/frontend/scale_factor_calc.cpp b/src/plugins/intel_gna/src/frontend/scale_factor_calc.cpp deleted file mode 100644 index 5995d2c95ae..00000000000 --- a/src/plugins/intel_gna/src/frontend/scale_factor_calc.cpp +++ /dev/null @@ -1,1358 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "scale_factor_calc.hpp" - -#include "common/numerical_utils.hpp" -#include "gna_slope_scale.hpp" -#include "gna_upstream_iterator.hpp" -#include "layer_quantizer.hpp" -#include "layers/gna_convolution_layer.hpp" -#include "log/debug.hpp" -#include "weights_converter.hpp" - -namespace ov { -namespace intel_gna { -using namespace common; -namespace frontend { - -constexpr float activation_scale_factor = 2048.f; -constexpr float low_prec_activation_scale_factor = 4.f; -constexpr float identity_scale_factor = 2049.0f; -constexpr float max_activation_scale_factor = 4096.0f; -constexpr double pow_domain = 16; -constexpr float min_search_weights_val = 1.0f; -constexpr float max_search_weights_val = 1024.0f; -constexpr double initial_weights_reducer_val = 1.0; - -float GetScaleFactor(InferenceEngine::CNNLayerPtr layer, QuantizedDataType data_type) { - IE_ASSERT(layer != nullptr); - auto quantized = InferenceEngine::getInjectedData(layer); - float scale_factor; - if (!quantized) { - scale_factor = 1.0f; - } else { - switch (data_type) { - case QuantizedDataType::input: - scale_factor = quantized->_src_quant.GetScale(); - break; - case QuantizedDataType::output: - scale_factor = quantized->_dst_quant.GetScale(); - break; - case QuantizedDataType::weights: - scale_factor = quantized->_weights_quant.GetScale(); - break; - case QuantizedDataType::bias: - scale_factor = quantized->_bias_quant.GetScale(); - break; - default: - THROW_GNA_LAYER_EXCEPTION(layer) - << "Unsupported data type for quantization: " << static_cast(data_type); - } - } - - if (scale_factor <= 0.0 || std::isinf(scale_factor)) { - THROW_GNA_LAYER_EXCEPTION(layer) << "Invalid scale factor: " << scale_factor; - } - - return scale_factor; -} - -float CalculateScaleFactorFromStats(size_t levels, float minValue, float maxValue) { - return maxValue == minValue ? 1.0f : (levels - 1) / (maxValue - minValue); -} - -/** - * @brief Calculates PWL slopes for specified function in a given input range - * @param info Layer information - * @return Array of slopes for a function - */ -std::vector ScaleFactorCalculator::getPWLSlopes(const LayerInfo& info) const { - if (info.isIdentity() || info.isFakeQuantize() || info.isRelu() || info.isClamp() || info.isAbs()) { - return {1.0f}; - } - - return {}; -} - -/** - * @brief Finds the best output activation scale factor that allows to get the most precise PWL slope - * @param inScale Input activation layer scale factor - * @param outScales Array of output activation scale factors - * @param slopes Array of slopes for a given function - * @return Best output activation scale factor - */ -float ScaleFactorCalculator::selectBestOutputScaleFactors(float inScale, - std::vector outScales, - const std::vector& slopes) { - std::vector scaleErrors; - for (size_t i = 0; i < outScales.size(); ++i) { - auto outScale = outScales[i]; - - auto sd = 0.0f; - for (size_t j = 0; j < slopes.size(); ++j) { - auto s = gna_slope(slopes[j], inScale, outScale); - auto slope = DoubleToInt16(s.slope * s.slope_scale); - if (slope < std::numeric_limits::min() || slope > std::numeric_limits::max()) { - sd += std::numeric_limits::max(); - continue; - } - - auto testSlope = static_cast(slope) / s.slope_scale * inScale / outScale; - if (AreFpEq(static_cast(testSlope), static_cast(slopes[j]), 1.0E-6f)) { - return outScale; - } - - sd += static_cast(pow(testSlope - slopes[j], 2.0)); - } - - sd /= slopes.size(); - sd = sqrtf(sd); - scaleErrors.push_back(sd); - } - - size_t minIndex = 0; - auto minError = scaleErrors[0]; - for (size_t i = 1; i < scaleErrors.size(); ++i) { - if (scaleErrors[i] < minError) { - minError = scaleErrors[i]; - minIndex = i; - } - } - - return outScales[minIndex]; -} - -/** - * @brief Finds the weights scale factor that allows to get the most precise PWL slope - * @param inScale Input weightable layer scale factor - * @param outScale Output activation scale factor - * @param weightsScales Array of weights scales to check - * @return Best weights scale factor - */ -float ScaleFactorCalculator::selectBestWeightsScaleFactors(float inScale, - float outScale, - std::vector weightsScales, - const std::vector& slopes) { - std::vector scaleErrors; - for (size_t i = 0; i < weightsScales.size(); ++i) { - auto weightScale = weightsScales[i]; - - auto sd = 0.0f; - for (size_t j = 0; j < slopes.size(); ++j) { - auto s = gna_slope(slopes[j], inScale * weightScale, outScale); - auto slope = static_cast(s.slope * s.slope_scale); - if (slope < static_cast(std::numeric_limits::min()) && - slope > static_cast(std::numeric_limits::max())) { - sd += std::numeric_limits::max(); - continue; - } - - auto testSlope = static_cast(slope) / s.slope_scale * (inScale * weightScale) / outScale; - if (AreFpEq(static_cast(testSlope), static_cast(slopes[j]))) { - return outScale; - } - sd += static_cast(pow(testSlope - slopes[j], 2.0)); - } - - sd /= slopes.size(); - sd = sqrtf(sd); - scaleErrors.push_back(sd); - } - - size_t minIndex = 0; - auto minError = scaleErrors[0]; - for (size_t i = 1; i < scaleErrors.size(); ++i) { - if (scaleErrors[i] < minError) { - minError = scaleErrors[i]; - minIndex = i; - } - } - - return weightsScales[minIndex]; -} - -/** - * @brief Generates specified number of scale factors in a given range. - * @param startRange First scale factor - * @param endRange Last scale factor - * @param numIterations number of scale factors to generate - * @return Array of scale factors - */ -std::vector ScaleFactorCalculator::generateScaleFactors(float startRange, - float endRange, - size_t numScaleFactors) { - if (!numScaleFactors) { - return {startRange, endRange}; - } - - auto scaleFactors = std::vector{}; - auto domain = endRange - startRange; - auto step = domain / numScaleFactors; - for (size_t i = 0; i <= numScaleFactors; ++i) { - auto scale = startRange + step * i; - if (!std::isnan(scale)) { - scaleFactors.push_back(scale); - } - } - - return scaleFactors; -} - -/** - * @brief Calculates weights reducer using statistics from the destination quantization statistics. - * @param dst_quant destination quantization statistics - * @return Weights reducer - */ -double ScaleFactorCalculator::calculateWeightsReducerFromDstStats(QuantizationParams dst_quant) { - auto maxAbsVal = std::max(std::abs(dst_quant.GetMinValues().front()), std::abs(dst_quant.GetMaxValues().front())); - auto maxIntVal = static_cast(maxAbsVal * dst_quant.GetScale() + 0.5f); - double weightsReducer = static_cast(maxIntVal) / std::numeric_limits::max(); - weightsReducer = std::max(initial_weights_reducer_val, weightsReducer); - return weightsReducer; -} - -/** - * @brief Tries to re-quantize an input to reach the desired output scale factor value. - * This function searches for layers above which output scale factors can be changed: - * - activations, - * - constants, - * - weightable layers (output scale factor is modified by modification of weights scale factor). - * @param input input to be re-quantized - * @param newOutputScale the desired output scale factor value - * @param result information about the restarted layer - * @return true if the input can be re-quantized - */ -bool ScaleFactorCalculator::requantizeInput(InferenceEngine::CNNLayerPtr input, - float newOutputScale, - ScaleFactorUpdateResult& result, - int infiniteLoopCount) { - auto layer = input; - if (!layer || LayerInfo(layer).isInput() || LayerInfo(layer).isMemory() || LayerInfo(layer).isCopy()) { - return false; - } - - int prevInputIdx = 0; - auto info = LayerInfo(layer); - auto quantDataForInputLayer = InferenceEngine::getInjectedData(*layer); - if (quantDataForInputLayer->_dst_quant.IsStatsSet()) { - auto levels = LayerInfo(layer).has32BOutput() ? (std::numeric_limits::max() + 1ul) - : (std::numeric_limits::max() + 1ul); - auto maxSF = CalculateScaleFactorFromStats(levels, - quantDataForInputLayer->_dst_quant.GetMinValues().front(), - quantDataForInputLayer->_dst_quant.GetMaxValues().front()); - if (newOutputScale > maxSF) { - log::debug() << layer->name << ": Scale factor " << newOutputScale - << " is too large. The maximum scale factor: " << maxSF << " levels=" << levels - << " min=" << quantDataForInputLayer->_dst_quant.GetMinValues().front() - << " max=" << quantDataForInputLayer->_dst_quant.GetMaxValues().front() << "\n"; - return false; - } - } - if (info.isActivation() || info.isConst()) { - log::warning() << "[WARNING] requantize " << layer->name << ". Layer new output scale: " << newOutputScale - << ", was " << quantDataForInputLayer->_dst_quant.GetScale() << std::endl; - quantDataForInputLayer->_dst_quant.SetScale(newOutputScale); - result = ScaleFactorUpdateResult(layer.get()); - return true; - } - - if (info.isWeightableIdentity() && !AreFpEq(quantDataForInputLayer->_weights_quant.GetScale(), 1.0f)) { - auto reducer = std::max(1.0f, quantDataForInputLayer->_dst_quant.GetScale() / newOutputScale); - auto newWeightsScale = std::max(1.0f, quantDataForInputLayer->_weights_quant.GetScale() / reducer); - quantDataForInputLayer->_weights_quant.SetScale(trunc(newWeightsScale)); - quantDataForInputLayer->_dst_quant.SetScale(quantDataForInputLayer->_weights_quant.GetScale() * - quantDataForInputLayer->_src_quant.GetScale()); - - result = ScaleFactorUpdateResult(layer.get()); - return true; - } - - if (info.isFullyConnected() || info.isConvolution() || info.isPower()) { - quantDataForInputLayer->_dst_quant.SetScale(newOutputScale); - quantDataForInputLayer->_weights_quant.SetScale(newOutputScale / quantDataForInputLayer->_src_quant.GetScale()); - result = ScaleFactorUpdateResult(layer.get()); - return true; - } - - if (LayerInfo(layer).isEltwiseSum() && LayerInfo(input).has32BOutput()) { - // re-quantize bias branch for Eltwise layer - for (uint8_t ix = 0; ix < 2; ++ix) { - if (LayerInfo(InferenceEngine::CNNNetPrevLayer(layer, ix)).has32BOutput()) { - prevInputIdx = ix; - break; - } - } - auto prevLayer = InferenceEngine::CNNNetPrevLayer(layer, prevInputIdx); - auto prevQuantData = InferenceEngine::getInjectedData(*prevLayer); - newOutputScale *= prevQuantData->_dst_quant.GetScale() / quantDataForInputLayer->_dst_quant.GetScale(); - } - - if (LayerInfo(layer).isEltwiseMul()) { - for (uint8_t ix = 0; ix < 2; ++ix) { - auto restartedPrevLayer = InferenceEngine::CNNNetPrevLayer(layer, ix); - auto otherPrevLayer = InferenceEngine::CNNNetPrevLayer(layer, !ix); - if (infiniteLoopCount % 2 == 1) { - log::warning() << "[WARNING] going into the loop: swap inputs order for Eltwise Multiply" << std::endl; - std::swap(restartedPrevLayer, otherPrevLayer); - } - auto otherPrevQuantData = InferenceEngine::getInjectedData(*otherPrevLayer); - auto newScale = newOutputScale / otherPrevQuantData->_dst_quant.GetScale(); - if (requantizeInput(restartedPrevLayer, newScale, result, infiniteLoopCount)) { - return true; - } - } - return false; - } - - auto prevLayer = InferenceEngine::CNNNetHasPrevLayer(layer.get(), prevInputIdx) - ? InferenceEngine::CNNNetPrevLayer(layer, prevInputIdx) - : nullptr; - return requantizeInput(prevLayer, newOutputScale, result, infiniteLoopCount); -} - -/** - * @brief Adjust output scale factor to get the most precise PWL slope. - * NOTE: Currently it is only implemented for identity, clamp, relu and FQ layers. - * For all other layers, it does not improve accuracy. - * @param sf Scale factor to be adjusted - * @param layer Layer information - * @param quantizedParams Quantization parameters - * @return the adjusted scale factor - */ -float ScaleFactorCalculator::adjustScaleFactor(float sf, - InferenceEngine::CNNLayer const* cnnLayer, - LayerInfo const& layer, - QuantizedLayerParams* quantizedParams) const { - auto get_rank = [](uint32_t value) { - uint8_t rank = 0; - while (value >= 1) { - ++rank; - value /= 10; - } - return rank; - }; - auto pow_10 = [](uint8_t degree) { - uint32_t value = 1; - for (uint8_t i = 0; i < degree; ++i) { - value *= 10; - } - return value; - }; - - auto slopes = getPWLSlopes(layer); - if (!slopes.empty()) { - auto div = 10; - auto startRange = sf > 1.0f ? static_cast(sf) : sf; - auto endRange = startRange - startRange / div; - endRange = endRange > 1.0f ? static_cast(endRange) : endRange; - uint32_t steps = 10000; - uint32_t rangeSize = static_cast(startRange - endRange); - if (rangeSize >= 1) { - steps *= rangeSize / pow_10(get_rank(rangeSize) - 1); - } - - auto scaleFactors = generateScaleFactors(startRange, endRange, steps); - auto newScaleFactor = - selectBestOutputScaleFactors(quantizedParams->_src_quant.GetScale(), scaleFactors, slopes); - if (!AreFpEq(sf, newScaleFactor) && !AreFpEq(newScaleFactor, 0.0f) && !std::isinf(newScaleFactor)) { - log::debug() << "[INFO] Adjusting scale factor for " << cnnLayer->name << " from: " << sf - << " to: " << newScaleFactor << "\n"; - sf = newScaleFactor; - } - } - return sf; -} - -float ScaleFactorCalculator::getActivationScale(InferenceEngine::CNNLayer const* cnnLayer, - LayerInfo const& layer, - int inputsSize, - const bool fake_quantized) const { - auto quantizedParams = InferenceEngine::getInjectedData(*cnnLayer); - - // todo: calculate proper scale factor where we need to expand it a bit to be safe to stay in int16 weights - // set the initial value - float result = (inputsSize == 2 ? activation_scale_factor : low_prec_activation_scale_factor); - if (layer.isIdentity()) { -// #define accurate_identity_scale_factor -#ifdef accurate_identity_scale_factor - // searching more accurate scale factor for identity - const double min_range = 1024.0; - const double max_range = 2049.0; - - // gna encoded scale factor - the max this is the more accurate PWL approximation - double optimalK = 0.0f; - result = min_range; - - for (int slope_scale_index = 1; slope_scale_index != 5; slope_scale_index++) { - auto slope_scale = static_cast(static_cast(1) << (8 * slope_scale_index)); - auto mink = min_range * slope_scale / quantizedParams->_src_quant.GetScale(); - auto maxk = max_range * slope_scale / quantizedParams->_src_quant.GetScale(); - - if (mink < std::numeric_limits::max()) { - auto localMaxK = std::min(static_cast(std::numeric_limits::max()), maxk); - if (localMaxK > optimalK) { - result = localMaxK / slope_scale * quantizedParams->_src_quant.GetScale(); - optimalK = localMaxK; - } - } - } -#else - // GNA scale factor encoding might poor represent target slop scale, we are probing 2 values - auto s = gna_slope(1.0, quantizedParams->_src_quant.GetScale(), identity_scale_factor); - auto scale_default = s.slope * s.slope_scale; - // probing one more quite good approximation for identity - s = gna_slope(1.0, quantizedParams->_src_quant.GetScale(), identity_scale_factor / 2); - auto scale_extra = s.slope * s.slope_scale; - result = fabs(scale_extra) > fabs(scale_default) ? identity_scale_factor / 2 : identity_scale_factor; - -#endif - } else if (layer.isRelu()) { - // if activation is one from relu family, we need to apply heuristic to avoid activation output overflow - auto limit = static_cast( - (inputsSize == 1 ? std::numeric_limits::max() : std::numeric_limits::max()) - 1); - - if (static_cast(result * quantizedParams->_src_quant.GetScale()) > limit) { - result *= 0.5; - } - } else if (layer.isPower()) { - double exponent = 0; - double scale = 0; - double offset = 0; - auto powerLayer = dynamic_cast(cnnLayer); - if (!powerLayer) { - std::shared_ptr pwl_node; - if (!cnnLayer->getNode() || !(pwl_node = std::dynamic_pointer_cast(cnnLayer->getNode()))) { - IE_THROW() << "Incorrect Power Layer pointer \n"; - } else { - auto powerIE = std::dynamic_pointer_cast(pwl_node->get_base_node()); - if (!powerIE) { - IE_THROW() << "Incorrect Power Layer pointer \n"; - } else { - exponent = powerIE->power; - scale = powerIE->scale; - offset = powerIE->shift; - } - } - } else { - exponent = powerLayer->power; - scale = powerLayer->scale; - offset = powerLayer->offset; - } - - auto input_min_value = static_cast(std::numeric_limits::min()); - auto input_max_value = static_cast(std::numeric_limits::max()); - auto output_max_value = static_cast((inputsSize == 2) ? std::numeric_limits::max() - : std::numeric_limits::max()); - - auto x_min = AreFpEq(fmod(exponent, 1.0), 0.0) ? input_min_value / quantizedParams->_src_quant.GetScale() : 0.0; - x_min = std::max(x_min, -pow_domain); - - auto x_max = input_max_value / quantizedParams->_src_quant.GetScale(); - x_max = std::min(x_max, pow_domain); - - auto val1 = pow(x_min * scale + offset, exponent); - auto val2 = pow(x_max * scale + offset, exponent); - - auto abs_val = std::max(std::abs(val1), std::abs(val2)); - auto scale_val = output_max_value / abs_val; - - if (!std::isinf(scale_val)) { - result = static_cast(scale_val); - } - } - - // Identity layer is inserted by GNA passes and requires statistics to correctly set output - // scale factor. POT does not produce any statistics for this layer as it does not exist - // in the source IR. - if (fake_quantized && !quantizedParams->_dst_quant.IsScaleSet() && layer.isIdentity()) { - auto prevLayer = CNNNetPrevLayer(cnnLayer); - while (prevLayer != nullptr) { - auto prevQuantParams = InferenceEngine::getInjectedData(*prevLayer); - if (prevQuantParams->_dst_quant.IsStatsSet()) { - quantizedParams->_dst_quant.CopyStats(prevQuantParams->_dst_quant); - quantizedParams->_src_quant.CopyStats(prevQuantParams->_dst_quant); - break; - } - - // Take the input statistics only if layer does not modify input values. - if (prevQuantParams->_src_quant.IsStatsSet() && - (LayerInfo(prevLayer).isNonFunctional() || LayerInfo(prevLayer).isMemory() || - LayerInfo(prevLayer).isConst() || LayerInfo(prevLayer).isInput())) { - quantizedParams->_dst_quant.CopyStats(prevQuantParams->_src_quant); - quantizedParams->_src_quant.CopyStats(prevQuantParams->_src_quant); - break; - } - - // Stop searching for statistics if previous layer does not modify input values. - if ((LayerInfo(prevLayer).isWeightable() && !LayerInfo(prevLayer).isWeightableIdentity()) || - LayerInfo(prevLayer).isEltwise() || LayerInfo(prevLayer).isActivation()) { - break; - } - - if (!CNNNetHasPrevLayer(prevLayer.get())) { - break; - } - - prevLayer = CNNNetPrevLayer(prevLayer); - } - - // If did not find statistics by searching previous layers, check if a next layer has - // statistics set. - if (!quantizedParams->_dst_quant.IsStatsSet()) { - auto donotSkip = [](InferenceEngine::CNNLayerPtr) { - return false; - }; - - auto nextLayers = CNNNetGetAllNextLayersSkipCertain(cnnLayer, -1, donotSkip); - for (auto& l : nextLayers) { - auto nextQuantParams = InferenceEngine::getInjectedData(*l); - if (nextQuantParams->_src_quant.IsStatsSet()) { - quantizedParams->_dst_quant.CopyStats(nextQuantParams->_src_quant); - quantizedParams->_src_quant.CopyStats(nextQuantParams->_src_quant); - break; - } - - // Take output statistics only if a next layer does not modify input values - if (nextQuantParams->_dst_quant.IsStatsSet() && - (LayerInfo(l).isNonFunctional() || LayerInfo(l).isMemory())) { - quantizedParams->_dst_quant.CopyStats(nextQuantParams->_dst_quant); - quantizedParams->_src_quant.CopyStats(nextQuantParams->_dst_quant); - break; - } - } - } - } - - // Adjust output scale factor based on statistics (if present) in the following steps: - // 1. calculate scale factor based on output min and max values - // 2. (temporary W/A) clamp scale factor to maximum activation scale factor - // 3. search previous layers if there was already scale factor set - // 4. adjust output scale factor to get the most precise PWL slope - if (quantizedParams->_dst_quant.IsStatsSet()) { - auto minOutValue = quantizedParams->_dst_quant.GetMinValues().front(); - auto maxOutValue = quantizedParams->_dst_quant.GetMaxValues().front(); - auto absMax = std::max(std::abs(minOutValue), std::abs(maxOutValue)); - - auto levels = std::min(quantizedParams->_dst_quant.GetLevels(), - static_cast(std::numeric_limits::max()) + 1); - result = CalculateScaleFactorFromStats(levels, minOutValue, maxOutValue); - if (std::isinf(result) || AreFpEq(absMax, 0.0f)) { - result = max_activation_scale_factor; - } - - // TODO: remove clamping maximum scale factor - result = result > max_activation_scale_factor ? max_activation_scale_factor : result; - if (!layer.isIdentity() && !layer.isFakeQuantize() && !layer.isRelu() && !layer.isClamp()) { - result = result > activation_scale_factor ? activation_scale_factor : result; - } - - // Take input scale factor from previous layer if previous layer does not modify - // input values - bool usePrevScaleFactor = false; - auto skipNonFunctional = [](InferenceEngine::CNNLayerPtr l) { - return LayerInfo(l).isNonFunctional(); - }; - - auto prevLayer = - CNNNetHasPrevLayer(cnnLayer, 0) ? CNNNetPrevLayerSkipCertain(cnnLayer, 0, skipNonFunctional) : nullptr; - if (prevLayer != nullptr && (layer.isIdentity() || layer.isFakeQuantize()) && - LayerInfo(prevLayer).isWeightableIdentity()) { - auto prevLayerQuant = InferenceEngine::getInjectedData(*prevLayer); - auto prevLayer2 = CNNNetHasPrevLayer(prevLayer.get(), 0) - ? CNNNetPrevLayerSkipCertain(prevLayer, 0, skipNonFunctional) - : nullptr; - if (!AreFpEq(prevLayerQuant->_src_quant.GetScale(), 1.0f) && prevLayerQuant->_src_quant.IsStatsSet() && - (prevLayer2 == nullptr || LayerInfo(prevLayer2).has8BOr16BOutput())) { - result = prevLayerQuant->_src_quant.GetScale(); - usePrevScaleFactor = true; - } - } - - if (!usePrevScaleFactor) { - result = adjustScaleFactor(result, cnnLayer, layer, quantizedParams); - } - } - - /* Destination max value for Relu is equal to its source max value, - * so we can control overflows if we know only destination statistics - */ - if (!quantizedParams->_dst_quant.IsStatsSet() && quantizedParams->_src_quant.IsStatsSet() && layer.isRelu()) { - auto maxInValue = quantizedParams->_src_quant.GetMaxValues().front(); - auto limit = (inputsSize == 1 ? std::numeric_limits::max() : std::numeric_limits::max()) - 1; - if (result * maxInValue > limit) { - result = limit / maxInValue; - } - } - - return result; -} - -bool ScaleFactorCalculator::ScaleFactorPerLayerCNN(InferenceEngine::CNNLayer* cnnLayer, - ScaleFactorUpdateResult& result, - int infiniteLoopCount, - const Config& gna_config) const { - if (!cnnLayer) { - IE_THROW() << "Incorrect Layer pointer \n"; - } - - int inputsSize = static_cast(GetInputPrecision().size()); - - LayerInfo layerInfo(*cnnLayer); - // TODO: current approach set input scale factor for true input layer(s) equals to provided factor, - auto quant = InferenceEngine::getInjectedData(*cnnLayer); - - if (layerInfo.isMemory()) { - if (CNNNetHasPrevLayer(cnnLayer) && quant->_dst_quant.IsStatsSet() && !quant->_dst_quant.IsScaleSet()) { - auto minOutValue = quant->_dst_quant.GetMinValues().front(); - auto maxOutValue = quant->_dst_quant.GetMaxValues().front(); - auto scale = CalculateScaleFactorFromStats(quant->_dst_quant.GetLevels(), minOutValue, maxOutValue); - quant->_dst_quant.SetScale(scale); - quant->_src_quant = quant->_dst_quant; - } - - if (CNNNetHasPrevLayer(cnnLayer)) { - auto prevLayer = CNNNetPrevLayer(cnnLayer); - auto inputQuant = InferenceEngine::getInjectedData(prevLayer); - // locating corresponding memory layers with same ID - for (auto&& input : CNNNetGetAllInputLayers(cnnLayer)) { - LayerInfo ll(input); - if (!ll.isMemory() || - !InferenceEngine::details::CaselessEq()(input->params["id"], cnnLayer->params["id"])) { - continue; - } - - auto quantSibling = InferenceEngine::getInjectedData(input); - - // after restarting from memory input - quant is fine - if (AreFpEq(quantSibling->_dst_quant.GetScale(), inputQuant->_dst_quant.GetScale())) { - quant->_src_quant.SetScale(inputQuant->_dst_quant.GetScale()); - quant->_dst_quant.SetScale(inputQuant->_dst_quant.GetScale()); - return true; - } - - if ((!fake_quantized && quantSibling->_dst_quant.IsScaleSet()) || - (fake_quantized && quantSibling->_dst_quant.IsScaleSet() && - !AreFpEq(quantSibling->_dst_quant.GetScale(), 1.0f) && - quantSibling->_dst_quant.GetScale() < inputQuant->_dst_quant.GetScale()) || - (quantSibling->_dst_quant.IsScaleSet() && infiniteLoopCount > 0)) { - // means we already restarted propagation input memory layer - // need to search for requantiseable layer prior memory output layer - InferenceEngine::CNNLayerPtr restartedLayer; - - log::debug() << "Memory layer :" << input->name - << " scale factor: " << quantSibling->_dst_quant.GetScale() - << " doesn't match its outputs counterpart: " << cnnLayer->name - << " scale factor: " << inputQuant->_dst_quant.GetScale() << "\n"; - log::debug() << "[UFS] searching for quantizeable input layer for: " << cnnLayer->name << "\n"; - - CNNNetDFS( - InferenceEngine::CNNLayerPtr(cnnLayer, [](InferenceEngine::CNNLayer*) {}), - [&restartedLayer, cnnLayer](InferenceEngine::CNNLayerPtr layer) { - log::debug() << "[UFS] from : " << cnnLayer->name << " reached: " << layer->name; - // found that direct input to concat is a indirect parent of align filter - so no link - // required - auto info = LayerInfo(layer); - if (!info.isWeightable() && !info.isActivation()) { - log::debug() << "... skipped\n"; - return; - } - restartedLayer = layer; - log::debug() << "... OK, need requantize\n"; - }, - true, - [&restartedLayer](InferenceEngine::CNNLayer* from) { - // aborting UFS once found suitable layer - return make_upstream_order(restartedLayer == nullptr ? from : nullptr); - }); - - if (restartedLayer == nullptr) { - THROW_GNA_EXCEPTION << "cannot requantize input to " << cnnLayer->name; - } - - auto quantDataForMemoryOutput = - InferenceEngine::getInjectedData(*restartedLayer); - - auto restarLayerInfo = LayerInfo(restartedLayer); - if (restarLayerInfo.isActivation()) { - // requantize activation by just changing it's output scale factor - quantDataForMemoryOutput->_dst_quant.SetScale(quantSibling->_dst_quant.GetScale()); - } else { - THROW_GNA_EXCEPTION << "quantization error : input scale factor ( " - << inputQuant->_dst_quant.GetScale() << ") " - << " for " << cnnLayer->name << ", that is child of " << prevLayer->name - << " doesnt match : " << activation_scale_factor; - } - - result = ScaleFactorUpdateResult(restartedLayer.get()); - return true; - } - - log::warning() << "[INFO] quantization : input scale factor (" << inputQuant->_dst_quant.GetScale() - << ")" - << " for " << cnnLayer->name << ", that is child of " << prevLayer->name - << " doesnt match : " << activation_scale_factor - << ", restarting from corresponding memory: " << input->name << std::endl; - - // try updating memory input layer scale factor and restart from it - quantSibling->_src_quant.SetScale(inputQuant->_dst_quant.GetScale()); - quantSibling->_dst_quant.SetScale(inputQuant->_dst_quant.GetScale()); - result = ScaleFactorUpdateResult(input.get()); - return true; - } - } - return true; - } - - if (cnnLayer->type == "Const") { - if (quant->_dst_quant.IsScaleSet()) { - quant->_src_quant = quant->_dst_quant; - return true; - } - - auto max_val = std::numeric_limits::min(); - auto min_val = std::numeric_limits::max(); - if (quant->_dst_quant.IsStatsSet()) { - min_val = quant->_dst_quant.GetMinValues().front(); - max_val = quant->_dst_quant.GetMaxValues().front(); - } else { - auto blob = cnnLayer->blobs["custom"]; - auto blob_precision = blob->getTensorDesc().getPrecision(); - - if (blob_precision != InferenceEngine::Precision::FP32 && - blob_precision != InferenceEngine::Precision::FP16) { - quant->_dst_quant.SetScale(1.0f); - return true; - } - - if (blob_precision == InferenceEngine::Precision::FP16) { - blob = make_fp32_blob(blob); - } - - auto flt_buf = blob->buffer().as(); - auto size = blob->size(); - - for (size_t i = 0; i < size; i++) { - auto val = flt_buf[i]; - if (val > max_val) - max_val = val; - if (val < min_val) - min_val = val; - } - } - - auto levels = 0; - if (fake_quantized) { - levels = (inputsSize == 2) ? MAX_VAL_2B_FEAT : MAX_VAL_1B_FEAT; - } else { - levels = (inputsSize == 2) ? std::numeric_limits::max() : std::numeric_limits::max(); - } - - auto abs_val = std::max(std::abs(max_val), std::abs(min_val)); - auto scale_val = static_cast(levels) / abs_val; - // TODO: use FQ formula for scale factor calculation - - if (std::isinf(scale_val) || AreFpEq(abs_val, 0.0f)) { - quant->_dst_quant.SetScale(fake_quantized ? levels : 1.0f); - } else { - quant->_dst_quant.SetScale(scale_val); - } - quant->_src_quant.SetScale(quant->_dst_quant.GetScale()); - - return true; - } - - if (!CNNNetHasPrevLayer(cnnLayer)) { - quant->_dst_quant = quant->_src_quant; - return true; - } - - // by default layer is pass thru its scale factor - auto inputQuant = InferenceEngine::getInjectedData(CNNNetPrevLayer(cnnLayer)); - if (!inputQuant) { - THROW_GNA_EXCEPTION << "layer: " << CNNNetPrevLayer(cnnLayer)->name << "not quantized"; - } - - if (layerInfo.isPower() && !layerInfo.isActivation()) { - auto quant = InferenceEngine::getInjectedData(*cnnLayer); - auto powerLayer = dynamic_cast(cnnLayer); - if (!powerLayer) { - IE_THROW() << "Incorrect Power Layer pointer \n"; - } - - auto powerScale = std::abs(powerLayer->scale); - if (AreFpEq(powerScale, 0.0f)) { - powerScale = 1.0f; - } - auto weightsScaleFactor = MAX_VAL_2B_WEIGHT / powerScale; - quant->_src_quant.SetScale(inputQuant->_dst_quant.GetScale()); - quant->_weights_quant.SetScale(weightsScaleFactor); - quant->_dst_quant.SetScale(quant->_weights_quant.GetScale() * quant->_src_quant.GetScale()); - return true; - } else if (layerInfo.isActivation()) { - // todo: calculate proper scale factor where we need to expand it a bit to be safe to stay in int16 weights - // set the initial value - if (!quant->_dst_quant.IsScaleSet() || AreFpEq(quant->_dst_quant.GetScale(), 1.0f) || - !AreFpEq(quant->_src_quant.GetScale(), inputQuant->_dst_quant.GetScale())) { - quant->_src_quant.SetScale(inputQuant->_dst_quant.GetScale()); - auto scale = getActivationScale(cnnLayer, layerInfo, inputsSize, fake_quantized); - quant->_dst_quant.SetScale(scale); - } - return true; - } else if (layerInfo.isCropAffined()) { - auto weightsScaleFactor = 1.0f; - quant->_weights_quant.SetScale(weightsScaleFactor); - quant->_src_quant.SetScale(inputQuant->_dst_quant.GetScale()); - quant->_dst_quant.SetScale(quant->_weights_quant.GetScale() * quant->_src_quant.GetScale()); - return true; - } - quant->_src_quant.SetScale(inputQuant->_dst_quant.GetScale()); - quant->_dst_quant.SetScale(inputQuant->_dst_quant.GetScale()); - - return true; -} - -bool ScaleFactorCalculator::ScaleFactorPerLayerEltwise(InferenceEngine::EltwiseLayer* eltwiseLayer, - ScaleFactorUpdateResult& result, - int infiniteLoopCount, - const Config& gna_config) const { - if (!eltwiseLayer) { - THROW_GNA_EXCEPTION << "Incorrect Eltwise Layer pointer \n"; - } - auto in0 = InferenceEngine::CNNNetPrevLayer(eltwiseLayer, 0); - auto in1 = InferenceEngine::CNNNetPrevLayer(eltwiseLayer, 1); - - auto quantParams0 = InferenceEngine::getInjectedData(in0); - auto quantParams1 = InferenceEngine::getInjectedData(in1); - - auto quantData = InferenceEngine::getInjectedData(*eltwiseLayer); - - switch (eltwiseLayer->_operation) { - case InferenceEngine::EltwiseLayer::Prod: { - quantData->_weights_quant.SetScale(quantParams1->_dst_quant.GetScale()); - quantData->_dst_quant.SetScale(quantParams0->_dst_quant.GetScale() * quantParams1->_dst_quant.GetScale()); - break; - } - case InferenceEngine::EltwiseLayer::Sub: - case InferenceEngine::EltwiseLayer::Sum: { - // detect which input will be used as biases - auto eltwiseFunctionalPrev = LayerInfo(in0).isNonFunctional() && CNNNetHasPrevLayer(in0.get(), 0) - ? CNNNetPrevLayerSkipCertain(in0, - 0, - [](InferenceEngine::CNNLayerPtr l) { - return LayerInfo(l).isNonFunctional(); - }) - : in0; - - if (LayerInfo(in0).has32BOutput() || - (LayerInfo(in0).isNonFunctional() && LayerInfo(eltwiseFunctionalPrev).has32BOutput())) { - std::swap(in0, in1); - std::swap(quantParams0, quantParams1); - } - - auto prevLayer = in1; - while (LayerInfo(prevLayer).isNonFunctional() && CNNNetHasPrevLayer(prevLayer.get(), 0)) { - prevLayer = CNNNetPrevLayer(prevLayer); - } - - // this path might result in significant data loss - quantData->_bias_quant.SetScale(quantParams1->_dst_quant.GetScale() / quantParams0->_dst_quant.GetScale()); - auto weightsScale = quantParams1->_dst_quant.GetScale() / quantParams0->_dst_quant.GetScale(); - - // If a previous layer is a layer where freely weights scale factor can be selected, - // try to find the scale factor that will allow to use integer as weights scale factor for eltwise - // operation. - // If the weights scale factor for eltwise sum/sub is not integer, it will cause accuracy degradation. - if (fake_quantized) { - auto prevLayerIn1 = CNNNetPrevLayer(in1); - if (LayerInfo(in1).isWeightableIdentity() && - (prevLayerIn1 == nullptr || LayerInfo(prevLayerIn1).has8BOr16BOutput())) { - auto bestWeightsScale = 0.0f; - auto bestError = static_cast(std::numeric_limits::max()); - auto scaleIn0Dst = quantParams0->_dst_quant.GetScale(); - auto scaleIn1Src = quantParams1->_src_quant.GetScale(); - for (size_t i = MAX_VAL_2B_FEAT; i > 0; --i) { - auto scaleIn1Dst = i * scaleIn1Src; - auto eltwiseWeightsScale = scaleIn1Dst / scaleIn0Dst; - if (eltwiseWeightsScale < 1.0 || eltwiseWeightsScale > std::numeric_limits::max() - 1) { - continue; - } - - auto error = std::abs(eltwiseWeightsScale - static_cast(eltwiseWeightsScale)); - if (error < bestError) { - bestError = error; - bestWeightsScale = static_cast(i); - } - - if (AreFpEq(error, 0.0f)) { - break; - } - } - - if (bestWeightsScale > 0.0f && !AreFpEq(bestWeightsScale, quantParams1->_weights_quant.GetScale())) { - quantParams1->_weights_quant.SetScale(bestWeightsScale); - quantParams1->_dst_quant.SetScale(quantParams1->_weights_quant.GetScale() * - quantParams1->_src_quant.GetScale()); - result = ScaleFactorUpdateResult(in1.get()); - return true; - } - } - } - - quantData->_weights_quant.SetScale(weightsScale); - quantData->_dst_quant.SetScale(quantParams1->_dst_quant.GetScale()); - - // eltwise will work in int16 or int8 if low precision inputs are used - auto maxValue = (GetInputPrecision() == InferenceEngine::Precision::I8) ? std::numeric_limits::max() - : std::numeric_limits::max(); - if (quantData->_weights_quant.GetScale() > maxValue && - !AreFpEq(quantData->_weights_quant.GetScale(), static_cast(maxValue))) { - float newOutputScale = quantParams0->_dst_quant.GetScale() * maxValue; - log::debug() << "[INFO] weights saturated for " << eltwiseLayer->name << ", try to requiantize input " - << in1->name << std::endl; - if (requantizeInput(in1, newOutputScale, result, infiniteLoopCount)) { - return true; - } - // Unable to rescale the input - results might be bad - log::warning() << "[INFO] weights saturated for " << eltwiseLayer->name << "\n"; - } - - if (!quantData->_dst_quant.IsStatsSet()) { - return true; - } - - auto weightsReducer = calculateWeightsReducerFromDstStats(quantData->_dst_quant); - if (weightsReducer > initial_weights_reducer_val) { - float newOutputScale = static_cast(quantParams1->_dst_quant.GetScale() / weightsReducer); - if (requantizeInput(in1, newOutputScale, result, infiniteLoopCount)) { - return true; - } - THROW_GNA_EXCEPTION << "Unable to quantize " << eltwiseLayer->name; - } - } break; - default: - THROW_GNA_EXCEPTION << "Unsupported Eltwise layer for quantisation: " << eltwiseLayer->_operation; - } - return true; -} - -bool ScaleFactorCalculator::ScaleFactorPerLayerConcat(InferenceEngine::ConcatLayer* concatLayer, - ScaleFactorUpdateResult& result, - int infiniteLoopCount, - const Config& gna_config) const { - if (!concatLayer) { - THROW_GNA_EXCEPTION << "Incorrect Concat Layer pointer \n"; - } - - if (concatLayer->insData.size() < 2) { - THROW_GNA_EXCEPTION << "Concat layer has unsupported number of incoming layers."; - } - - auto quantData = InferenceEngine::getInjectedData(*concatLayer); - std::vector inputLayers; - for (size_t input_idx = 0; input_idx != concatLayer->insData.size(); input_idx++) { - auto notChangeScaleFactors = [](InferenceEngine::CNNLayerPtr layer) { - return LayerInfo(layer).isNonFunctional() || LayerInfo(layer).isSplit() || LayerInfo(layer).isCopy(); - }; - auto prev_layer = CNNNetPrevLayerSkipCertain(concatLayer, static_cast(input_idx), notChangeScaleFactors); - inputLayers.push_back(prev_layer); - } - - // if all inputs have same quant value - trivial propagation - auto in0 = inputLayers.front(); - auto quantParams0 = InferenceEngine::getInjectedData(in0); - auto scaleFactor = quantParams0->_dst_quant.GetScale(); - auto scaleFactorCheck = [scaleFactor](InferenceEngine::CNNLayerPtr& inputLayer) { - auto quantParams = InferenceEngine::getInjectedData(inputLayer); - return AreFpEq(quantParams->_dst_quant.GetScale(), scaleFactor); - }; - - if (std::find_if_not(inputLayers.begin() + 1, inputLayers.end(), scaleFactorCheck) == inputLayers.end()) { - quantData->_dst_quant.SetScale(quantParams0->_dst_quant.GetScale()); - quantData->_src_quant.SetScale(quantParams0->_dst_quant.GetScale()); - return true; - } - - // verify if all "Input"-type inputs have the same quant value - auto inputLayerCheck = [](InferenceEngine::CNNLayerPtr& inputLayer) { - auto info = LayerInfo(inputLayer); - return info.isInput(); - }; - - QuantizedLayerParams* sourceQuantParams = nullptr; - auto sourceLayerIt = std::find_if(inputLayers.begin(), inputLayers.end(), inputLayerCheck); - if (sourceLayerIt != inputLayers.end()) { - auto quantParamsFirst = InferenceEngine::getInjectedData(*sourceLayerIt); - auto nextInputIt = sourceLayerIt + 1; - while ((nextInputIt = std::find_if(nextInputIt, inputLayers.end(), inputLayerCheck)) != inputLayers.end()) { - auto quantParamsSecond = InferenceEngine::getInjectedData(*nextInputIt); - if (!common::AreFpEq(quantParamsSecond->_dst_quant.GetScale(), quantParamsFirst->_dst_quant.GetScale())) { - THROW_GNA_EXCEPTION << "Two Input layers " << (*sourceLayerIt)->name << " and " << (*nextInputIt)->name - << " have different scales in concat!!! \n"; - } - ++nextInputIt; - } - } - - // find a source quant value - // - 1st candidate - input layer - // - 2nd candidate - non-activation layer with non-1 scale factor - if (sourceLayerIt == inputLayers.end()) { - if (infiniteLoopCount % 2 == 1) { - std::reverse(inputLayers.begin(), inputLayers.end()); - } - - if (fake_quantized) { - sourceLayerIt = inputLayers.begin(); - auto quantParamsFirst = InferenceEngine::getInjectedData(*inputLayers.begin()); - auto minScaleFactor = quantParamsFirst->_dst_quant.GetScale(); - for (auto it = inputLayers.begin(); it != inputLayers.end(); ++it) { - auto quantParams = InferenceEngine::getInjectedData(*it); - if ((quantParams->_dst_quant.GetScale() < minScaleFactor && - !AreFpEq(quantParams->_dst_quant.GetScale(), 1.0f)) || - AreFpEq(minScaleFactor, 1.0f)) { - minScaleFactor = quantParams->_dst_quant.GetScale(); - sourceLayerIt = it; - } - } - } else { - if (infiniteLoopCount % 4 == 2 || infiniteLoopCount % 4 == 3) { - auto sourceLayerCheck = [](InferenceEngine::CNNLayerPtr& inputLayer) { - auto quantParams = InferenceEngine::getInjectedData(inputLayer); - LayerInfo info(inputLayer); - return !info.isActivation() && !AreFpEq(quantParams->_dst_quant.GetScale(), 1.0f); - }; - sourceLayerIt = std::find_if(inputLayers.begin(), inputLayers.end(), sourceLayerCheck); - } - - if (sourceLayerIt == inputLayers.end()) { - auto nonDefaultScaleFactor = [](InferenceEngine::CNNLayerPtr& inputLayer) { - auto quantParams = InferenceEngine::getInjectedData(inputLayer); - return !AreFpEq(quantParams->_dst_quant.GetScale(), 1.0f); - }; - - sourceLayerIt = std::find_if(inputLayers.begin(), inputLayers.end(), nonDefaultScaleFactor); - } - } - } - - std::set concatIdxToUpdate; - if (sourceLayerIt != inputLayers.end()) { - auto quantParams = InferenceEngine::getInjectedData(*sourceLayerIt); - auto scaleFactor = quantParams->_dst_quant.GetScale(); - sourceQuantParams = quantParams; - - for (auto it = inputLayers.begin(); it != inputLayers.end(); ++it) { - auto quantParamsIn = InferenceEngine::getInjectedData(*it); - if (AreFpEq(quantParamsIn->_dst_quant.GetScale(), scaleFactor)) { - continue; - } - - if (fake_quantized) { - concatIdxToUpdate.insert(std::distance(inputLayers.begin(), it)); - quantParamsIn->_dst_quant.SetScale(quantParams->_dst_quant.GetScale()); - } else { - // possible case when some of the concat inputs are free to select scale ex: const->concat<-affine - if (!AreFpEq(quantParamsIn->_dst_quant.GetScale(), 1.0f) && !LayerInfo(*it).isActivation()) { - concatIdxToUpdate.insert(std::distance(inputLayers.begin(), it)); - } - - quantParamsIn->_dst_quant.SetScale(quantParams->_dst_quant.GetScale()); - } - } - } - - auto updatedScaleFactor = InferenceEngine::getInjectedData(in0)->_dst_quant.GetScale(); - auto equalScaleFactor = [updatedScaleFactor](InferenceEngine::CNNLayerPtr& inputLayer) { - auto quantParams = InferenceEngine::getInjectedData(inputLayer); - return AreFpEq(quantParams->_dst_quant.GetScale(), updatedScaleFactor); - }; - - auto layerIt = std::find_if_not(inputLayers.begin() + 1, inputLayers.end(), equalScaleFactor); - if (layerIt != inputLayers.end()) { - THROW_GNA_EXCEPTION << "layers entered into concat have different scale factors. Layer name: " - << concatLayer->name; - } - - if (sourceQuantParams == nullptr) { - THROW_GNA_EXCEPTION << "Source quantization parameters have not been initialized"; - } - - quantData->_dst_quant.SetScale(sourceQuantParams->_dst_quant.GetScale()); - quantData->_src_quant.SetScale(sourceQuantParams->_dst_quant.GetScale()); - - if (layerIt == inputLayers.end() && concatIdxToUpdate.empty()) { - return true; - } - - for (auto& layerIdToUpdate : concatIdxToUpdate) { - auto destinationQuantParams = InferenceEngine::getInjectedData(*concatLayer); - destinationQuantParams->_dst_quant.SetScale(sourceQuantParams->_dst_quant.GetScale()); - - InferenceEngine::CNNLayerPtr restartedLayer; - // making a link activation possible without extra layer if first input to concat not a parent / indirect parent - // of second input using ufs - upper first search - log::debug() << "[UFS] searching for quantizeable layer prior: " << concatLayer->name << ", via " - << layerIdToUpdate << "\n"; - - CNNNetDFS( - InferenceEngine::CNNLayerPtr(concatLayer, [](InferenceEngine::CNNLayer*) {}), - [&restartedLayer, concatLayer](InferenceEngine::CNNLayerPtr layer) { - log::debug() << "[UFS] from : " << concatLayer->name << " reached: " << layer->name; - // found that direct input to concat is a indirect parent of align filter - so no link required - auto info = LayerInfo(layer); - if (!info.isWeightable() && !info.isActivation() && !info.isConst() && !info.isMemory()) { - log::debug() << "... skipped\n"; - return; - } - restartedLayer = layer; - log::debug() << "... OK, need requantize\n"; - }, - true, - [&restartedLayer, &concatLayer, &layerIdToUpdate](InferenceEngine::CNNLayer* from) { - // aborting UFS once found functional layer, and using only specified input of concat - return make_upstream_order(restartedLayer == nullptr ? from : nullptr, - from == concatLayer ? static_cast(layerIdToUpdate) : -1); - }); - - if (restartedLayer == nullptr) { - THROW_GNA_EXCEPTION << "cannot requantize " << layerIdToUpdate << " input to concat: " << concatLayer->name; - } - auto quantDataForConCatInput = InferenceEngine::getInjectedData(*restartedLayer); - - auto restarLayerInfo = LayerInfo(restartedLayer); - if (restarLayerInfo.isActivation()) { - // requantize activation by just changing it's output scale factor - auto newScaleFactor = sourceQuantParams->_dst_quant.GetScale(); - auto skipNonFunctional = [](InferenceEngine::CNNLayerPtr l) { - return LayerInfo(l).isNonFunctional(); - }; - - auto prevLayer = CNNNetPrevLayerSkipCertain(restartedLayer, 0, skipNonFunctional); - auto prevLayer2 = - prevLayer != nullptr ? CNNNetPrevLayerSkipCertain(prevLayer, 0, skipNonFunctional) : nullptr; - - if (fake_quantized && prevLayer != nullptr && - (LayerInfo(prevLayer).isConcatAlignFilter() || LayerInfo(prevLayer).isSyntheticScaleShift()) && - (prevLayer2 == nullptr || LayerInfo(prevLayer2).has8BOr16BOutput())) { - auto weightsScales = - generateScaleFactors(min_search_weights_val, - max_search_weights_val, - static_cast(max_search_weights_val - min_search_weights_val)); - - auto prevLayerQuant = InferenceEngine::getInjectedData(*prevLayer); - auto bestWeightsScale = 1.0f; - auto slopes = getPWLSlopes(restarLayerInfo); - if (!slopes.empty() && !AreFpEq(prevLayerQuant->_src_quant.GetScale(), newScaleFactor)) { - bestWeightsScale = selectBestWeightsScaleFactors(prevLayerQuant->_src_quant.GetScale(), - newScaleFactor, - weightsScales, - {1.0f}); - } - if (!slopes.empty() && !AreFpEq(bestWeightsScale, prevLayerQuant->_weights_quant.GetScale())) { - log::debug() << "[INFO][Concat] Optimizing weights scale factor for '" << prevLayer->name - << "' layer. Change from " << prevLayerQuant->_weights_quant.GetScale() << " to " - << bestWeightsScale << "\n"; - - prevLayerQuant->_weights_quant.SetScale(bestWeightsScale); - prevLayerQuant->_dst_quant.SetScale(prevLayerQuant->_weights_quant.GetScale() * - prevLayerQuant->_src_quant.GetScale()); - result = ScaleFactorUpdateResult(prevLayer.get()); - return true; - } - } - - quantDataForConCatInput->_dst_quant.SetScale(newScaleFactor); - } else if (restarLayerInfo.isConst() || restarLayerInfo.isMemory()) { - log::debug() << "... warning " << restartedLayer->type << " layer will be requantized\n"; - quantDataForConCatInput->_src_quant.SetScale(sourceQuantParams->_dst_quant.GetScale()); - quantDataForConCatInput->_dst_quant.SetScale(sourceQuantParams->_dst_quant.GetScale()); - } else { - THROW_GNA_EXCEPTION << "cannot requantize '" << restartedLayer->name - << "' input to concat: " << concatLayer->name; - } - result = ScaleFactorUpdateResult(restartedLayer.get()); - } - - return true; -} - -const std::vector> thresholds = { - // tuple values: scale factor threshold, scale factor reduction factor for I16 precision, for I8 precision - std::make_tuple(30, 0.50f, 0.50f), // entry check value - std::make_tuple(100, 0.50f, 0.50f), // if below this threshold, then use this factor - std::make_tuple(150, 0.45f, 0.45f), - std::make_tuple(200, 0.40f, 0.40f), - std::make_tuple(200, 0.35f, 0.35f) // max level -> if above, then use this factor -}; - -bool ScaleFactorCalculator::ScaleFactorPerLayerWeightable(InferenceEngine::WeightableLayer* wl, - ScaleFactorUpdateResult& result, - int infiniteLoopCount, - const Config& gna_config) const { - if (!wl) { - THROW_GNA_EXCEPTION << "Incorrect Weightable Layer pointer \n"; - } else if (!wl->_weights) { - THROW_GNA_EXCEPTION << "Incorrect weight value for " << wl->name << ":" << wl->type << "\n"; - } - - auto quant = InferenceEngine::getInjectedData(*wl); - size_t inputsSize = GetInputPrecision().size(); - const auto weights_prec = GetWeightsPrecision(LayerInfo(wl), *quant, gna_config); - const auto is_bias_compound = IsBiasCompound(LayerInfo(wl), *quant, gna_config); - auto prevLayer = CNNNetPrevLayer(wl); - auto quantDataForInputLayer = InferenceEngine::getInjectedData(*prevLayer.get()); - - quant->_src_quant = quantDataForInputLayer->_dst_quant; - - if (quant->_weights_quant.IsStatsSet() && !quant->_weights_quant.IsScaleSet()) { - auto getScale = [&quant](size_t i) { - return CalculateScaleFactorFromStats(quant->_weights_quant.GetLevels(), - quant->_weights_quant.GetMinValues(false)[i], - quant->_weights_quant.GetMaxValues(false)[i]); - }; - - float min_channel_scale = getScale(0); - for (uint32_t i = 1; i < quant->_weights_quant.GetMinValues().size(); i++) { - min_channel_scale = std::min(min_channel_scale, getScale(i)); - } - - auto multiplier = 1.0f; - if (is_bias_compound) { - // GNA supports additional multiplier only for weights used in combination with compound bias. - // The multipler is used to extend dynamic range. - multiplier = MAX_OUT_MULTIPLIER; - } - - // Common weights scale calculation - quant->_weights_quant.SetScale(min_channel_scale * multiplier); - } - - if (!quant->_weights_quant.IsScaleSet()) { - size_t scaleRange = 0; - if (weights_prec == InferenceEngine::Precision::I16) { - scaleRange = MAX_VAL_2B_WEIGHT; - } else if (weights_prec == InferenceEngine::Precision::I8) { - scaleRange = MAX_VAL_1B_WEIGHT; - } else { - THROW_GNA_EXCEPTION << "Unsupported weights precision of: " << weights_prec.name(); - } - quant->_weights_quant.SetScale(ScaleFactorForQuantization(wl->_weights->buffer().as(), - static_cast(scaleRange), - wl->_weights->size())); - if (quant->_weights_quant.GetScale() == -1.0f || (fake_quantized && LayerInfo(wl).isConcatAlignFilter())) { - quant->_weights_quant.SetScale(1.0f); - } - - if (wl->_biases) { - // for now the only case of bias we support with INT8 inputs and weights is INT32 - quant->_bias_quant.SetScale( - ScaleFactorForQuantization(wl->_biases->buffer().as(), MAX_VAL_4B_BIAS, wl->_biases->size())); - if (quant->_bias_quant.GetScale() != -1.0f) { - quant->_bias_quant.SetScale(std::min(quant->_weights_quant.GetScale() * quant->_src_quant.GetScale(), - quant->_bias_quant.GetScale())); - quant->_weights_quant.SetScale(quant->_bias_quant.GetScale() / quant->_src_quant.GetScale()); - } - } - - // use the MAX_OUT_MULTIPLIER only for int8_t weigths with compound bias (for now handled here only with int16_t - // inputs) it gives the possibility to exetend the output dynamic range - if (is_bias_compound) { - quant->_weights_quant.SetScale(quant->_weights_quant.GetScale() * MAX_OUT_MULTIPLIER); - } - - double weights_reducer = 1.0; - auto conv = dynamic_cast(wl); - if (conv && !LayerInfo(conv).isConvolutionFilter()) { - const auto inDepth = GetDataDimSizeNHWC(conv->insData.front().lock(), InferenceEngine::DataDimName::C); - weights_reducer = gna_convolution_layer::getWeightsReducer(*conv); - weights_reducer *= MAX_VAL_2B_FEAT * scaleRange * inDepth / std::numeric_limits::max(); - weights_reducer = std::max(1.0, weights_reducer); - } - quant->_weights_quant.SetScale(quant->_weights_quant.GetScale() / static_cast(weights_reducer)); - } - - double tmp_dst_quant_scale = quant->_weights_quant.GetScale() * quant->_src_quant.GetScale(); - if (weights_prec == InferenceEngine::Precision::I8 && - !(LayerInfo(wl).isConvolution() || LayerInfo(wl).isConvolutionFilter())) { - auto itt = thresholds.begin(); - auto limit = std::numeric_limits::max(); - - if (inputsSize == 1) { - limit = std::numeric_limits::max(); - } - - if (static_cast(tmp_dst_quant_scale * quant->_src_quant.GetScale()) > - static_cast(limit - 1) * std::get<0>(*itt)) { - log::warning() << "Output scale for " << wl->name - << " too large and are being reduced. Else saturations likely will happen \n"; - // reduce weight scale according experimental heuristic - while ((itt + 1) != thresholds.end() && - quant->_dst_quant.GetScale() * quant->_src_quant.GetScale() / static_cast(limit) >= - std::get<0>(*(++itt))) { - } - quant->_weights_quant.SetScale(quant->_weights_quant.GetScale() * - (inputsSize == 2 ? std::get<1>(*itt) : std::get<2>(*itt))); - } - } - - quant->_dst_quant.SetScale(quant->_weights_quant.GetScale() * quant->_src_quant.GetScale()); - if (quant->_dst_quant.IsStatsSet()) { - // Adjust weights scale factor if output values exceed int32 maximum value - - if (wl->_biases && !quant->_bias_quant.IsScaleSet()) { - auto minMax = FindMinMaxValues(wl->_biases->buffer().as(), wl->_biases->size()); - quant->_bias_quant.SetMinValues({minMax.first}); - quant->_bias_quant.SetMaxValues({minMax.second}); - - auto biasScale = - ScaleFactorForQuantization(wl->_biases->buffer().as(), MAX_VAL_4B_BIAS, wl->_biases->size()); - quant->_bias_quant.SetScale(biasScale); - if (quant->_bias_quant.GetScale() != -1.0f && - quant->_bias_quant.GetScale() < quant->_dst_quant.GetScale()) { - quant->_weights_quant.SetScale(quant->_bias_quant.GetScale() / quant->_src_quant.GetScale()); - quant->_dst_quant.SetScale(quant->_weights_quant.GetScale() * quant->_src_quant.GetScale()); - } - } - - auto weightsReducer = calculateWeightsReducerFromDstStats(quant->_dst_quant); - // This correction should be done by POT, but we observed issues with int8 quantization - if (weightsReducer > initial_weights_reducer_val) { - log::warning() << "Potential overload correction issue at layer " << wl->name; - quant->_weights_quant.SetScale(static_cast(quant->_weights_quant.GetScale() / weightsReducer)); - } - quant->_dst_quant.SetScale(quant->_weights_quant.GetScale() * quant->_src_quant.GetScale()); - } - - return true; -} - -bool ScaleFactorCalculator::ScaleFactorPerLayerGemm(InferenceEngine::GemmLayer* gl, - ScaleFactorUpdateResult& result, - int infiniteLoopCount, - const Config& gna_config) const { - if (!gl) { - THROW_GNA_EXCEPTION << "Incorrect Gemm Layer pointer \n"; - } - auto in0 = InferenceEngine::CNNNetPrevLayer(gl, 0); - auto in1 = InferenceEngine::CNNNetPrevLayer(gl, 1); - - auto quant = InferenceEngine::getInjectedData(*gl); - auto quantParams1 = InferenceEngine::getInjectedData(in1); - auto quantParams0 = InferenceEngine::getInjectedData(in0); - quant->_src_quant.SetScale(quantParams0->_dst_quant.GetScale()); - quant->_weights_quant.SetScale(quantParams1->_dst_quant.GetScale()); - quant->_dst_quant.SetScale(quant->_src_quant.GetScale() * quant->_weights_quant.GetScale()); - - if (quant->_dst_quant.IsStatsSet() && - calculateWeightsReducerFromDstStats(quant->_dst_quant) > initial_weights_reducer_val) { - log::warning() << "Potential overload correction issue at layer " << gl->name; - } - - return true; -} - -} // namespace frontend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/frontend/scale_factor_calc.hpp b/src/plugins/intel_gna/src/frontend/scale_factor_calc.hpp deleted file mode 100644 index bb81ebba511..00000000000 --- a/src/plugins/intel_gna/src/frontend/scale_factor_calc.hpp +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "gna_data_types.hpp" -#include "gna_plugin_config.hpp" -#include "layers/gna_layer_info.hpp" -#include "quantized_layer_params.hpp" - -namespace ov { -namespace intel_gna { -namespace frontend { - -enum class QuantizedDataType { input, output, weights, bias }; - -/** - * @brief Returns a scale factor for specific layer data - * @param layer Layer to be quantized - * @param data_type Type of data to be quantized - * @return scale factor - */ -float GetScaleFactor(InferenceEngine::CNNLayerPtr layer, QuantizedDataType data_type); - -/** - * @brief Calculates a scale factor from FakeQuantize statistics according to the formula: - * scale factor = max representable value / max absolute input value - * @param levels Number of integer quants - * @param minValue Minimum value to be quantized - * @param maxValue Maximum value to be quantized - */ -float CalculateScaleFactorFromStats(size_t levels, float minValue, float maxValue); - -struct ScaleFactorUpdateResult { - InferenceEngine::CNNLayer* restartLayer = nullptr; - ScaleFactorUpdateResult() = default; - explicit ScaleFactorUpdateResult(InferenceEngine::CNNLayer* restartlayer) : restartLayer(restartlayer) {} - operator bool() { - return restartLayer == nullptr; - } -}; - -/** - * @brief scale factor calculator will calculate only output scale factors for the layer - * if scale factor propagation is not possible, it will fall indicate a restart condition - */ -class ScaleFactorCalculator { - using Cnt = std::vector; - Cnt net; - const Config& gna_config; - const bool fake_quantized; - mutable Cnt::const_iterator idx; - mutable bool needRestart = false; - int infiniteLoopCount = 0; - - std::vector getPWLSlopes(const LayerInfo& info) const; - static float selectBestOutputScaleFactors(float inScale, - std::vector outScales, - const std::vector& slopes); - static float selectBestWeightsScaleFactors(float inScale, - float outScale, - std::vector weightsScales, - const std::vector& slopes); - static std::vector generateScaleFactors(float startRange, float endRange, size_t numScaleFactors); - static double calculateWeightsReducerFromDstStats(QuantizationParams dst_quant); - static bool requantizeInput(InferenceEngine::CNNLayerPtr input, - float newOutputScale, - ScaleFactorUpdateResult& result, - int infiniteLoopCount); - float adjustScaleFactor(float sf, - InferenceEngine::CNNLayer const* cnnLayer, - LayerInfo const& layer, - QuantizedLayerParams* quantizedParams) const; - float getActivationScale(InferenceEngine::CNNLayer const* cnnLayer, - LayerInfo const& layer, - int inputsSize, - const bool fakeQuantize) const; - bool ScaleFactorPerLayerCNN(InferenceEngine::CNNLayer* cnnLayer, - ScaleFactorUpdateResult& result, - int infiniteLoopCount, - const Config& gna_config) const; - bool ScaleFactorPerLayerConcat(InferenceEngine::ConcatLayer* concatLayer, - ScaleFactorUpdateResult& result, - int infiniteLoopCount, - const Config& gna_config) const; - bool ScaleFactorPerLayerEltwise(InferenceEngine::EltwiseLayer* eltwiseLayer, - ScaleFactorUpdateResult& result, - int infiniteLoopCount, - const Config& gna_config) const; - bool ScaleFactorPerLayerGemm(InferenceEngine::GemmLayer* gemmLayer, - ScaleFactorUpdateResult& result, - int infiniteLoopCount, - const Config& gna_config) const; - bool ScaleFactorPerLayerWeightable(InferenceEngine::WeightableLayer* wl, - ScaleFactorUpdateResult& result, - int infiniteLoopCount, - const Config& gna_config) const; - -public: - ScaleFactorCalculator(Cnt& net, const Config& gna_config, const bool fake_quantized) - : net(net), - gna_config(gna_config), - fake_quantized(fake_quantized) { - idx = std::begin(this->net); - } - bool needToRestart() const { - return needRestart; - } - bool allLayersProcessed() const { - return idx == std::end(net); - } - std::vector getStartLayers() const { - return std::vector(idx, std::end(net)); - } - void SetInfiniteLoopCount(int infiniteLoopCount) { - this->infiniteLoopCount = infiniteLoopCount; - } - bool CalculateScaleFactor(InferenceEngine::CNNLayerPtr layer_ptr) const { - ScaleFactorUpdateResult result; - needRestart = false; - auto layer_info = LayerInfo(layer_ptr); - - if (layer_info.isConcat()) { - if (!ScaleFactorPerLayerConcat(dynamic_cast(layer_ptr.get()), - result, - infiniteLoopCount, - gna_config)) { - return false; - } - } else if (layer_info.isEltwise()) { - if (!ScaleFactorPerLayerEltwise(dynamic_cast(layer_ptr.get()), - result, - infiniteLoopCount, - gna_config)) { - return false; - } - } else if (layer_info.isGemm()) { - if (!ScaleFactorPerLayerGemm(dynamic_cast(layer_ptr.get()), - result, - infiniteLoopCount, - gna_config)) { - return false; - } - } else if (layer_info.isWeightable()) { - if (!ScaleFactorPerLayerWeightable(dynamic_cast(layer_ptr.get()), - result, - infiniteLoopCount, - gna_config)) { - return false; - } - } else { - if (!ScaleFactorPerLayerCNN(layer_ptr.get(), result, infiniteLoopCount, gna_config)) { - return false; - } - } - - if (result) { - idx++; - return true; - } - - idx = std::find_if(net.begin(), net.end(), [&](InferenceEngine::CNNLayerPtr cnnLayer) { - if (!result) { - return result.restartLayer == cnnLayer.get(); - } - return layer_ptr == cnnLayer; - }); - - if (idx != net.end()) { - idx++; - } - - needRestart = true; - return true; - } -}; - -} // namespace frontend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/frontend/weights_converter.cpp b/src/plugins/intel_gna/src/frontend/weights_converter.cpp deleted file mode 100644 index 3f9655ff3c8..00000000000 --- a/src/plugins/intel_gna/src/frontend/weights_converter.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "weights_converter.hpp" - -namespace ov { -namespace intel_gna { -namespace frontend { - -static void fp16_to_fp32(InferenceEngine::WeightableLayer& wl) { - InferenceEngine::BlobMap newBlobs; - for (auto& blob : wl.blobs) { - if (blob.second->getTensorDesc().getPrecision() != InferenceEngine::Precision::FP16) { - THROW_GNA_EXCEPTION << "Unsupported precision. Layer: " << wl.name << " , Blob: " << blob.first; - } - auto fp32_blob = make_fp32_blob(blob.second); - newBlobs[blob.first] = fp32_blob; - } - wl._biases = newBlobs["biases"]; - wl._weights = newBlobs["weights"]; - wl.blobs = newBlobs; - wl.precision = InferenceEngine::Precision::FP32; - for (auto& dataItem : wl.outData) { - dataItem->setPrecision(InferenceEngine::Precision::FP32); - } -} - -InferenceEngine::Blob::Ptr make_fp32_blob(InferenceEngine::Blob::Ptr fp16_blob) { - auto fp32_blob = InferenceEngine::make_shared_blob({InferenceEngine::Precision::FP32, - fp16_blob->getTensorDesc().getDims(), - fp16_blob->getTensorDesc().getLayout()}); - fp32_blob->allocate(); - auto f16_value_array = fp16_blob->buffer().as(); - - for (auto& f32Value : *fp32_blob) { - auto f16Value = *f16_value_array++; - f32Value = InferenceEngine::PrecisionUtils::f16tof32(f16Value); - } - - return static_cast(fp32_blob); -} - -void convert_blobs_precision(InferenceEngine::CNNLayer& layer) { - auto layer_info = LayerInfo(layer); - - if (layer_info.isWeightable()) { - InferenceEngine::WeightableLayer& wl = dynamic_cast(layer); - if (wl.precision == InferenceEngine::Precision::FP16) { - fp16_to_fp32(wl); - } - } else { - layer.precision = InferenceEngine::Precision::FP32; - for (auto& dataItem : layer.outData) { - dataItem->setPrecision(InferenceEngine::Precision::FP32); - } - for (auto& blob_pair : layer.blobs) { - auto& blob_ptr = blob_pair.second; - if (blob_ptr->getTensorDesc().getPrecision() == InferenceEngine::Precision::FP16) { - blob_ptr = make_fp32_blob(blob_ptr); - } - } - } -} - -} // namespace frontend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/frontend/weights_converter.hpp b/src/plugins/intel_gna/src/frontend/weights_converter.hpp deleted file mode 100644 index 953235a802c..00000000000 --- a/src/plugins/intel_gna/src/frontend/weights_converter.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "layers/gna_layer_info.hpp" -#include "precision_utils.h" - -namespace ov { -namespace intel_gna { -namespace frontend { - -/** - * @brief Create an FP32 blob from an FP16 one - * @param fp16_blob Pointer to an FP16 blob - * @return Pointer to an FP32 blob - */ -InferenceEngine::Blob::Ptr make_fp32_blob(InferenceEngine::Blob::Ptr fp16_blob); - -/** - * @brief Convert all blobs of a layer from FP32 to FP16 precision - * @param layer A layer which blobs are to be converted - */ -void convert_blobs_precision(InferenceEngine::CNNLayer& layer); - -} // namespace frontend -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna2_model_export_helper.cpp b/src/plugins/intel_gna/src/gna2_model_export_helper.cpp deleted file mode 100644 index 1a942e69eb8..00000000000 --- a/src/plugins/intel_gna/src/gna2_model_export_helper.cpp +++ /dev/null @@ -1,259 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna2_model_export_helper.hpp" - -#include -#include -#include - -#include "common/versioning.hpp" -#include "gna/gna_config.hpp" -#include "gna2-device-api.h" -#include "gna2-model-export-api.h" -#include "gna2-model-suecreek-header.h" -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable : 4200) -# include "gna2-tlv-writer.h" -# pragma warning(pop) -#else -# include "gna2-tlv-writer.h" -#endif // _MSC_VER -#include "gna2_model_helper.hpp" -#include "gna_device.hpp" -#include "log/log.hpp" - -namespace ov { -namespace intel_gna { - -#define Gna2TlvTypeOVInputScaleFactor GNA2_TLV_IMPL_CHAR_TO_TYPE("OVIS") -#define Gna2TlvTypeOVOutputScaleFactor GNA2_TLV_IMPL_CHAR_TO_TYPE("OVOS") -#define Gna2TlvTypeOVString GNA2_TLV_IMPL_CHAR_TO_TYPE("OVSS") -#define Gna2TlvTypeOVVersion GNA2_TLV_IMPL_CHAR_TO_TYPE("OVVR") - -static_assert(std::numeric_limits::is_iec559, "Float is not IEC 559 compatible"); -typedef std::array TlvFloatRecord; - -static TlvFloatRecord GetFloatInTLV(Gna2TlvType type, float value) { - TlvFloatRecord r{}; - reinterpret_cast(r.data())->type = type; - reinterpret_cast(r.data())->length = sizeof(float); - *reinterpret_cast(r.data() + sizeof(Gna2TlvRecord)) = value; - return r; -} - -static std::vector GetStringAsTlv(Gna2TlvType type, const std::string& s) { - std::vector record(sizeof(Gna2TlvRecord)); - reinterpret_cast(record.data())->type = type; - - std::vector vs(s.begin(), s.end()); - vs.resize(vs.size() + (4 - vs.size() % 4) % 4, 0); - reinterpret_cast(record.data())->length = static_cast(vs.size()); - record.insert(record.end(), vs.begin(), vs.end()); - return record; -} - -static std::string WriteAllEndpoints(std::ostream& outStream, - const std::vector& allEndpoints, - const Gna2TlvType sfTlvType, - const GnaAllocation* allocation) { - const std::string endPointType = sfTlvType == Gna2TlvTypeOVInputScaleFactor ? "Input" : "Output"; - - if (allEndpoints.size() >= 1) { - const auto scaleFactorTlv = GetFloatInTLV(sfTlvType, allEndpoints[0].scaleFactor); - outStream.write(scaleFactorTlv.data(), scaleFactorTlv.size()); - } - if (allEndpoints.size() != 1) { - log::warning() << "Number of endpoints: " << allEndpoints.size() << " for " << endPointType << "\n"; - } - - std::stringstream stream; - stream << "Endpoints for " << endPointType << ":\n"; - for (const auto& endpoint : allEndpoints) { - stream << "name=[" << endpoint.name << "]\n"; - stream << "scaleFactor=[" << endpoint.scaleFactor << "]\n"; - stream << "byteSize=[" << endpoint.byteSize << "]\n"; - stream << "numberOfBytesPerElement=[" << endpoint.numberOfBytesPerElement << "]\n"; - if (allocation == nullptr) { - stream << "allocation=[nullptr]\n"; - } - if (endpoint.gnaPointer == nullptr) { - stream << "gnaPointer=[nullptr]\n"; - } - if (allocation != nullptr && endpoint.gnaPointer != nullptr) { - const auto gnaOffset = allocation->getOffset(endpoint.gnaPointer); - if (!gnaOffset.first) { - stream << "offset=[invalid]\n"; - } - stream << "offset=[" << gnaOffset.second << "]\n"; - } - } - return stream.str(); -} - -static void WriteStringToTlv(std::ostream& outStream, const Gna2TlvType tlvType, const std::string& value) { - const auto& valueTlv = GetStringAsTlv(tlvType, value); - outStream.write(valueTlv.data(), valueTlv.size()); -} - -void ExportTlvModel(uint32_t modelId, - uint32_t deviceIndex, - std::ostream& outStream, - const target::DeviceVersion& compile_target, - const std::vector& allInputs, - const std::vector& allOutputs, - const GnaAllocations& allAllocations) { - if (compile_target == target::DeviceVersion::GNAEmbedded1_0) { - THROW_GNA_EXCEPTION << "Unsupported compile target for TLV export: GNA Embedded 1.0" << std::endl; - } - - uint32_t exportConfig; - auto status = Gna2ModelExportConfigCreate(gnaUserAllocatorAlignedPage, &exportConfig); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigCreate"); - - status = Gna2ModelExportConfigSetSource(exportConfig, deviceIndex, modelId); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigSetSource"); - status = Gna2ModelExportConfigSetTarget(exportConfig, DeviceToGna(compile_target)); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigSetTarget"); - - // first descriptors - void* bufferLayerDescriptors = nullptr; - uint32_t sizeOfLayerDescriptors; - - status = Gna2ModelExport(exportConfig, - Gna2ModelExportComponentLayerDescriptors, - &bufferLayerDescriptors, - &sizeOfLayerDescriptors); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExport(Gna2ModelExportComponentLayerDescriptors)"); - - // RO - void* bufferROData = nullptr; - uint32_t sizeOfROData; - - status = Gna2ModelExport(exportConfig, Gna2ModelExportComponentReadOnlyDump, &bufferROData, &sizeOfROData); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExport(Gna2ModelExportComponentReadOnlyDump)"); - - // RW - scratch - void* bufferScratchRWData = nullptr; - uint32_t sizeOfScratchRWData; - - status = - Gna2ModelExport(exportConfig, Gna2ModelExportComponentScratchDump, &bufferScratchRWData, &sizeOfScratchRWData); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExport(Gna2ModelExportComponentScratchDump)"); - - // TODO: This must be first cover by model creation code - void* bufferStateRWData = nullptr; - uint32_t sizeOfStateRWData = 0; - - // RW - state - status = Gna2ModelExport(exportConfig, Gna2ModelExportComponentStateDump, &bufferStateRWData, &sizeOfStateRWData); - if (!Gna2StatusIsSuccessful(status)) { - bufferStateRWData = nullptr; - sizeOfStateRWData = 0; - } - - // RW - external Input - void* bufferInputRWData = nullptr; - uint32_t sizeOfInputRWData; - status = Gna2ModelExport(exportConfig, Gna2ModelExportComponentInputDump, &bufferInputRWData, &sizeOfInputRWData); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExport(Gna2ModelExportComponentInputDump)"); - - // RW - external Output - void* bufferOutputRWData = nullptr; - uint32_t sizeOfOutputRWData; - status = - Gna2ModelExport(exportConfig, Gna2ModelExportComponentOutputDump, &bufferOutputRWData, &sizeOfOutputRWData); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExport(Gna2ModelExportComponentOutputDump)"); - - char* outTlv = nullptr; - - const auto gnaLibraryVersion = GNADeviceHelper::GetGnaLibraryVersion(); - - uint32_t outTlvSize = 0; - - auto tlv_status = Gna2ExportTlv(DeviceToGna(compile_target), - gnaUserAllocator, - &outTlv, - &outTlvSize, - (const char*)bufferLayerDescriptors, - sizeOfLayerDescriptors, - (const char*)bufferROData, - sizeOfROData, - (const char*)bufferStateRWData, - sizeOfStateRWData, - sizeOfScratchRWData, - GnaEndpoint::GetTotalByteSize(allInputs), - GnaEndpoint::GetTotalByteSize(allOutputs), - gnaLibraryVersion.c_str(), - nullptr, - 0); - - if (Gna2TlvStatusSuccess == tlv_status) { - outStream.write(outTlv, outTlvSize); - auto metadata = WriteAllEndpoints(outStream, - allInputs, - Gna2TlvTypeOVInputScaleFactor, - allAllocations.Get(Gna2MemoryTagInput)); - metadata += WriteAllEndpoints(outStream, - allOutputs, - Gna2TlvTypeOVOutputScaleFactor, - allAllocations.Get(Gna2MemoryTagOutput)); - WriteStringToTlv(outStream, Gna2TlvTypeOVString, metadata); - const auto& ovVersionString = common::get_openvino_version_string(); - WriteStringToTlv(outStream, Gna2TlvTypeOVVersion, ovVersionString); - } - - gnaUserFree(outTlv); - - gnaUserFree(bufferLayerDescriptors); - gnaUserFree(bufferROData); - gnaUserFree(bufferScratchRWData); - gnaUserFree(bufferStateRWData); - - gnaUserFree(bufferInputRWData); - gnaUserFree(bufferOutputRWData); - - status = Gna2ModelExportConfigRelease(exportConfig); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigRelease"); - if (Gna2TlvStatusSuccess != tlv_status) { - THROW_GNA_EXCEPTION << "Not succesfull status returned: " << tlv_status << ", from Gna2ExportTlv() function\n"; - } -} - -void* ExportSueLegacyUsingGnaApi2(uint32_t modelId, uint32_t deviceIndex, Gna2ModelSueCreekHeader* modelHeader) { - uint32_t exportConfig; - auto status = Gna2ModelExportConfigCreate(gnaUserAllocatorAlignedPage, &exportConfig); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigCreate"); - - status = Gna2ModelExportConfigSetSource(exportConfig, deviceIndex, modelId); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigSetSource"); - status = Gna2ModelExportConfigSetTarget(exportConfig, DeviceToGna(target::DeviceVersion::GNAEmbedded1_0)); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigSetTarget"); - - void* bufferSueCreekHeader = nullptr; - uint32_t bufferSueCreekHeaderSize; - - status = Gna2ModelExport(exportConfig, - Gna2ModelExportComponentLegacySueCreekHeader, - &bufferSueCreekHeader, - &bufferSueCreekHeaderSize); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExport(LegacySueCreekHeader)"); - - (*modelHeader) = *(reinterpret_cast(bufferSueCreekHeader)); - - void* bufferDump = nullptr; - uint32_t bufferDumpSize; - status = Gna2ModelExport(exportConfig, Gna2ModelExportComponentLegacySueCreekDump, &bufferDump, &bufferDumpSize); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExport(LegacySueCreekDump)"); - - status = Gna2ModelExportConfigRelease(exportConfig); - GNADeviceHelper::checkGna2Status(status, "Gna2ModelExportConfigRelease"); - - gnaUserFree(bufferSueCreekHeader); - return bufferDump; -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna2_model_export_helper.hpp b/src/plugins/intel_gna/src/gna2_model_export_helper.hpp deleted file mode 100644 index 40b19d847ec..00000000000 --- a/src/plugins/intel_gna/src/gna2_model_export_helper.hpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common/gna_target.hpp" -#include "gna2-model-export-api.h" -#include "gna2-model-suecreek-header.h" -#include "gna_device_allocation.hpp" - -namespace ov { -namespace intel_gna { - -struct GnaEndpoint { - std::string name; - uint32_t byteSize = 0; - uint32_t offset = 0; - uint32_t numberOfBytesPerElement = 0; - float scaleFactor = 0; - void* gnaPointer = nullptr; - - template - static uint32_t GetTotalByteSize(const T& container); - - template - static GnaEndpoint CreateFromDescriptor(const T& descriptor); - - template - static std::vector CreateFromDescriptorContainer(const T& container); -}; - -template -uint32_t GnaEndpoint::GetTotalByteSize(const T& container) { - return std::accumulate(container.begin(), container.end(), 0, [](uint32_t cur, const GnaEndpoint& next) { - return cur + next.byteSize; - }); -} - -template -GnaEndpoint GnaEndpoint::CreateFromDescriptor(const T& descriptor) { - GnaEndpoint e; - e.scaleFactor = descriptor.scale_factor; - e.byteSize = descriptor.get_required_size(); - e.name = descriptor.name; - e.numberOfBytesPerElement = static_cast(descriptor.tensor_precision.size()); - if (!descriptor.ptrs.empty()) { - e.gnaPointer = descriptor.ptrs.front(); - } - return e; -} - -template -std::vector GnaEndpoint::CreateFromDescriptorContainer(const T& container) { - std::vector result; - for (const auto& e : container) { - result.push_back(CreateFromDescriptor(e)); - } - return result; -} - -void* ExportSueLegacyUsingGnaApi2(uint32_t modelId, uint32_t deviceIndex, Gna2ModelSueCreekHeader* modelHeader); - -void ExportTlvModel(uint32_t modelId, - uint32_t deviceIndex, - std::ostream& outStream, - const target::DeviceVersion& compileTarget, - const std::vector& inputs, - const std::vector& outputs, - const GnaAllocations& allAllocation); - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna2_model_helper.cpp b/src/plugins/intel_gna/src/gna2_model_helper.cpp deleted file mode 100644 index 93a0e71ce62..00000000000 --- a/src/plugins/intel_gna/src/gna2_model_helper.cpp +++ /dev/null @@ -1,352 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#if defined __INTEL_COMPILER || defined _MSC_VER -# include -#else -# include -#endif - -#include - -#include - -#include "gna2_model_helper.hpp" -#include "log/debug.hpp" - -Gna2DataType Gna2DataTypeFromBytes(uint32_t num_bytes_per_input) { - if (num_bytes_per_input == 1) - return Gna2DataTypeInt8; - if (num_bytes_per_input == 2) - return Gna2DataTypeInt16; - if (num_bytes_per_input == 4) - return Gna2DataTypeInt32; - if (num_bytes_per_input == 0) - return Gna2DataTypeNone; - THROW_GNA_EXCEPTION << "Not supported num_bytes_per_input: " << num_bytes_per_input; -} - -void* gnaUserAllocatorAlignedPage(uint32_t size) { - return _mm_malloc(size, 4096); -} - -void* gnaUserAllocator(uint32_t size) { - return _mm_malloc(size, 64); -} - -void gnaUserFree(void* ptr) { - _mm_free(ptr); -} - -Gna2Tensor HelperGna2TensorInit1D(uint32_t x, Gna2DataType dataType, void* data) { - Gna2Tensor t{}; - t.Type = dataType; - t.Data = data; - t.Shape = {1, {x}}; - return t; -} - -Gna2Tensor HelperGna2TensorInit2D(uint32_t x, uint32_t y, Gna2DataType dataType, void* data) { - auto t = HelperGna2TensorInit1D(x, dataType, data); - t.Shape = {2, {x, y}}; - return t; -} - -Gna2Tensor HelperGna2TensorInit3D(uint32_t x, uint32_t y, uint32_t z, Gna2DataType dataType, void* data) { - auto t = HelperGna2TensorInit1D(x, dataType, data); - t.Shape = {3, {x, y, z}}; - return t; -} - -namespace { - -Gna2DataType FromOvDataType(OvGnaType t) { - static const std::map m = {{OvGnaTypeInt8, Gna2DataTypeInt8}, - {OvGnaTypeInt16, Gna2DataTypeInt16}, - {OvGnaTypeInt32, Gna2DataTypeInt32}, - {OvGnaTypePwl, Gna2DataTypePwlSegment}}; - const auto r = m.find(t); - if (r != m.end()) { - return r->second; - } - THROW_GNA_EXCEPTION << "FromOvDataType: unknown type"; -} - -Gna2Tensor HelperGna2TensorInit(OvGnaTensor tensor, void* data) { - Gna2Tensor t{}; - IE_ASSERT(tensor.dimensions.size() <= 8); - for (auto d : tensor.dimensions) { - t.Shape.Dimensions[t.Shape.NumberOfDimensions] = d; - t.Shape.NumberOfDimensions++; - } - t.Data = data; - t.Type = FromOvDataType(tensor.type); - return t; -} - -} // namespace - -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; -} - -Gna2Tensor* createGna2TensorPwl(uint32_t x, void* data) { - auto ret = createGna2Tensor1D(x, 1, data); - ret->Type = Gna2DataTypePwlSegment; - if (data == nullptr) - ret->Mode = Gna2TensorModeDisabled; - return ret; -} - -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 { - *input = HelperGna2TensorInit1D(x, Gna2DataTypeFromBytes(byteSize), data); - } - return input; -} - -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* createGna2Tensor(OvGnaTensor tensor, void* data) { - auto input = reinterpret_cast(gnaUserAllocator(sizeof(Gna2Tensor))); - IE_ASSERT(input != nullptr); - *input = HelperGna2TensorInit(tensor, 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; -} - -Gna2Shape* create_shape2D_parameter(uint32_t x, uint32_t y) { - const auto shp = create_shape1D_parameter(x); - shp->NumberOfDimensions++; - shp->Dimensions[1] = y; - return shp; -} - -void freeGna2Operation(Gna2Operation& operation) { - if (operation.Operands != nullptr) { - for (uint32_t i = 0; i < operation.NumberOfOperands; i++) { - if (operation.Operands[i] != nullptr) { - gnaUserFree(const_cast(operation.Operands[i])); - operation.Operands[i] = nullptr; - } - } - gnaUserFree(operation.Operands); - operation.Operands = nullptr; - operation.NumberOfOperands = 0; - } - if (operation.Parameters != nullptr) { - for (uint32_t i = 0; i < operation.NumberOfParameters; i++) { - if (operation.Parameters[i] != nullptr) { - gnaUserFree(operation.Parameters[i]); - operation.Parameters[i] = nullptr; - } - } - gnaUserFree(operation.Parameters); - operation.Parameters = nullptr; - operation.NumberOfParameters = 0; - } - operation.Type = Gna2OperationTypeNone; -} - -void HelperGna2OperationInit(Gna2Operation* operation, Gna2OperationType type) { - operation->Type = type; - operation->NumberOfOperands = 0; - operation->NumberOfParameters = 0; -} - -void HelperGna2OperationSetOperand(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - uint32_t index, - Gna2Tensor* inputs) { - if (index >= GNA_MAX_OP_PARAM) { - THROW_GNA_EXCEPTION << "HelperGna2OperationSetOperand: index >= GNA_MAX_OP_PARAM"; - } - if (operation->NumberOfOperands <= index) { - const auto o = reinterpret_cast(userAllocator(sizeof(Gna2Tensor*) * (index + 1))); - for (unsigned i = 0; i < operation->NumberOfOperands; i++) { - o[i] = operation->Operands[i]; - } - for (auto i = operation->NumberOfOperands; i <= index; i++) { - o[i] = nullptr; - } - operation->NumberOfOperands = index + 1; - userFree(operation->Operands); - operation->Operands = o; - } - operation->Operands[index] = inputs; -} - -void HelperGna2OperationSetParameter(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - uint32_t index, - void* param) { - if (index >= GNA_MAX_OP_PARAM) { - THROW_GNA_EXCEPTION << "HelperGna2OperationSetParameter: (index >= GNA_MAX_OP_PARAM) index=" << index - << " GNA_MAX_OP_PARAM=" << GNA_MAX_OP_PARAM; - } - if (operation->NumberOfParameters <= index) { - const auto p = reinterpret_cast(userAllocator(sizeof(void*) * (index + 1))); - for (unsigned i = 0; i < operation->NumberOfParameters; i++) { - p[i] = operation->Parameters[i]; - } - for (unsigned i = operation->NumberOfParameters; i <= index; i++) { - p[i] = nullptr; - } - operation->NumberOfParameters = index + 1; - userFree(operation->Parameters); - operation->Parameters = p; - } - operation->Parameters[index] = param; -} - -void HelperGna2OperationInitElementWiseAffine(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs, - Gna2Tensor* weights, - Gna2Tensor* biases, - Gna2Tensor* activation) { - HelperGna2OperationInit(operation, Gna2OperationTypeElementWiseAffine); - HelperGna2OperationSetOperand(operation, userAllocator, userFree, InOpIdx, inputs); - HelperGna2OperationSetOperand(operation, userAllocator, userFree, OutOpIdx, outputs); - HelperGna2OperationSetOperand(operation, userAllocator, userFree, FilterOpIdx, weights); - HelperGna2OperationSetOperand(operation, userAllocator, userFree, BiasOpIdx, biases); - HelperGna2OperationSetOperand(operation, userAllocator, userFree, PwlOpIdx, activation); -} - -void HelperGna2OperationInitFullyConnectedAffine(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs, - Gna2Tensor* weights, - Gna2Tensor* biases, - Gna2Tensor* activation) { - HelperGna2OperationInitElementWiseAffine(operation, - userAllocator, - userFree, - inputs, - outputs, - weights, - biases, - activation); - operation->Type = Gna2OperationTypeFullyConnectedAffine; - // TODO: GNA2: remove when GNA2 library does not expect optional operands/parameters to be provided - HelperGna2OperationSetOperand(operation, userAllocator, userFree, WeightScaleFactorOpIdx, nullptr); - HelperGna2OperationSetParameter(operation, userAllocator, userFree, BiasModeFCAffineParamIdx, nullptr); -} - -void HelperGna2OperationInitRecurrent(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs, - Gna2Tensor* weights, - Gna2Tensor* biases, - Gna2Tensor* activation, - uint32_t* delay) { - HelperGna2OperationInitElementWiseAffine(operation, - userAllocator, - userFree, - inputs, - outputs, - weights, - biases, - activation); - operation->Type = Gna2OperationTypeRecurrent; - HelperGna2OperationSetParameter(operation, userAllocator, userFree, DelayParamIdx, delay); -} - -void HelperGna2OperationInitConvolution(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs, - Gna2Tensor* filters, - Gna2Tensor* biases, - Gna2Tensor* activation, - Gna2Shape* convolutionStride, - Gna2BiasMode* biasMode, - Gna2Shape* zeroPadding) { - HelperGna2OperationInitElementWiseAffine(operation, - userAllocator, - userFree, - inputs, - outputs, - filters, - biases, - activation); - operation->Type = Gna2OperationTypeConvolution; - HelperGna2OperationSetParameter(operation, userAllocator, userFree, ConvStrideParamIdx, convolutionStride); - HelperGna2OperationSetParameter(operation, userAllocator, userFree, BiasModeCnnParamIdx, biasMode); - HelperGna2OperationSetParameter(operation, userAllocator, userFree, ZeroPaddingParamIdx, zeroPadding); -} - -void HelperGna2OperationInitCopy(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs, - Gna2Shape* copyShape) { - HelperGna2OperationInit(operation, Gna2OperationTypeCopy); - HelperGna2OperationSetOperand(operation, userAllocator, userFree, InOpIdx, inputs); - HelperGna2OperationSetOperand(operation, userAllocator, userFree, OutOpIdx, outputs); - HelperGna2OperationSetParameter(operation, userAllocator, userFree, CopyShapeParamIdx, copyShape); -} - -void HelperGna2OperationInitInterleave(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs) { - HelperGna2OperationInit(operation, Gna2OperationTypeTransposition); - HelperGna2OperationSetOperand(operation, userAllocator, userFree, InOpIdx, inputs); - HelperGna2OperationSetOperand(operation, userAllocator, userFree, OutOpIdx, outputs); -} - -void HelperGna2OperationInitDeInterleave(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs) { - HelperGna2OperationInit(operation, Gna2OperationTypeTransposition); - HelperGna2OperationSetOperand(operation, userAllocator, userFree, InOpIdx, inputs); - HelperGna2OperationSetOperand(operation, userAllocator, userFree, OutOpIdx, outputs); -} diff --git a/src/plugins/intel_gna/src/gna2_model_helper.hpp b/src/plugins/intel_gna/src/gna2_model_helper.hpp deleted file mode 100644 index f8f0c7f6140..00000000000 --- a/src/plugins/intel_gna/src/gna2_model_helper.hpp +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "backend/dnn_types.hpp" -#include "gna2-model-api.h" - -constexpr uint32_t InOpIdx = 0; -constexpr uint32_t OutOpIdx = 1; -constexpr uint32_t FilterOpIdx = 2; -constexpr uint32_t BiasOpIdx = 3; -constexpr uint32_t PwlOpIdx = 4; -constexpr uint32_t WeightScaleFactorOpIdx = 5; - -constexpr uint32_t ConvStrideParamIdx = 0; -constexpr uint32_t BiasModeCnnParamIdx = 1; -constexpr uint32_t BiasModeFCAffineParamIdx = 0; -constexpr uint32_t CopyShapeParamIdx = 0; -constexpr uint32_t DelayParamIdx = 0; -constexpr uint32_t PoolModeParamIdx = 2; -constexpr uint32_t PoolWinParamIdx = 3; -constexpr uint32_t PoolStrideParamIdx = 4; -constexpr uint32_t ZeroPaddingParamIdx = 5; -constexpr uint32_t MaximumScoreParamIdx = 0; - -#define GNA_MAX_OP_PARAM 10 -typedef void (*GnaUserFree)(void*); - -Gna2DataType Gna2DataTypeFromBytes(uint32_t num_bytes_per_input); - -void* gnaUserAllocatorAlignedPage(uint32_t size); - -void* gnaUserAllocator(uint32_t size); - -void gnaUserFree(void* ptr); - -Gna2Tensor HelperGna2TensorInit1D(uint32_t x, Gna2DataType dataType, void* data); - -Gna2Tensor HelperGna2TensorInit2D(uint32_t x, uint32_t y, Gna2DataType dataType, void* data); - -Gna2Tensor HelperGna2TensorInit3D(uint32_t x, uint32_t y, uint32_t z, Gna2DataType dataType, void* data); - -Gna2Tensor* createGna2Tensor1D(uint32_t x, uint32_t byteSize, void* data); - -Gna2Tensor* createGna2TensorPwl(uint32_t x, void* data); - -Gna2Tensor* createGna2BiasTensor1D(uint32_t x, uint32_t byteSize, void* data); - -Gna2Tensor* createGna2Tensor(OvGnaTensor tensor, void* data); - -Gna2Tensor* createGna2Tensor2D(uint32_t x, uint32_t y, uint32_t byteSize, void* data); - -Gna2Tensor* createGna2Tensor3D(uint32_t x, uint32_t y, uint32_t z, uint32_t byteSize, void* data); - -uint32_t* create_uint32_parameter(uint32_t value); - -Gna2Shape* create_shape1D_parameter(uint32_t x); - -Gna2Shape* create_shape2D_parameter(uint32_t x, uint32_t y); - -void freeGna2Operation(Gna2Operation& operation); - -void HelperGna2OperationInit(Gna2Operation* operation, Gna2OperationType type); - -void HelperGna2OperationSetOperand(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - uint32_t index, - Gna2Tensor* inputs); - -void HelperGna2OperationSetParameter(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - uint32_t index, - void* param); - -void HelperGna2OperationInitElementWiseAffine(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs, - Gna2Tensor* weights, - Gna2Tensor* biases, - Gna2Tensor* activation); - -void HelperGna2OperationInitFullyConnectedAffine(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs, - Gna2Tensor* weights, - Gna2Tensor* biases, - Gna2Tensor* activation); - -void HelperGna2OperationInitRecurrent(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs, - Gna2Tensor* weights, - Gna2Tensor* biases, - Gna2Tensor* activation, - uint32_t* delay); - -void HelperGna2OperationInitConvolution(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs, - Gna2Tensor* filters, - Gna2Tensor* biases, - Gna2Tensor* activation, - Gna2Shape* convolutionStride, - enum Gna2BiasMode* biasMode, - Gna2Shape* zeroPadding); - -void HelperGna2OperationInitCopy(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs, - Gna2Shape* copyShape); - -void HelperGna2OperationInitInterleave(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs); - -void HelperGna2OperationInitDeInterleave(Gna2Operation* operation, - Gna2UserAllocator userAllocator, - GnaUserFree userFree, - Gna2Tensor* inputs, - Gna2Tensor* outputs); diff --git a/src/plugins/intel_gna/src/gna_data_types.hpp b/src/plugins/intel_gna/src/gna_data_types.hpp deleted file mode 100644 index d2e276b35a6..00000000000 --- a/src/plugins/intel_gna/src/gna_data_types.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include - -#include "layers/gna_concat_layer.hpp" -#include "layers/gna_crop_layer.hpp" -#include "layers/gna_memory_layer.hpp" -#include "layers/gna_split_layer.hpp" -#include "memory/gna_memory.hpp" - -namespace ov { -namespace intel_gna { - -using gna_memory_type = memory::GNAMemoryInterface; -using gna_memory_float = memory::GNAMemory; -using gna_memory_device = memory::GNAMemory<>; - -using DnnComponentsForLayer = std::list>; -using MemoryConnection = std::list>; -using ConcatConnection = std::unordered_map; -using SplitConnection = std::unordered_map; -using CropConnection = std::unordered_map; -using ConstConnections = std::unordered_map; -using PrePostProcessModels = std::unordered_map>; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_device.cpp b/src/plugins/intel_gna/src/gna_device.cpp deleted file mode 100644 index 378c1d325f8..00000000000 --- a/src/plugins/intel_gna/src/gna_device.cpp +++ /dev/null @@ -1,593 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_device.hpp" - -#include -#include -#include -#include -#include -#include - -#include "backend/am_intel_dnn.hpp" -#include "backend/gna_limitations.hpp" -#include "common/gna_target.hpp" -#include "gna/gna_config.hpp" -#include "gna2-capability-api.h" -#include "gna2-device-api.h" -#include "gna2-inference-api.h" -#include "gna2-instrumentation-api.h" -#include "gna2-memory-api.h" -#include "gna2-model-export-api.h" -#include "gna2_model_export_helper.hpp" -#include "gna2_model_helper.hpp" -#include "layers/gna_convolution_layer.hpp" -#include "log/dump.hpp" -#include "log/log.hpp" -#include "memory/gna_mem_requests.hpp" - -namespace ov { -namespace intel_gna { -using namespace target; - -std::mutex GNADeviceHelper::acrossPluginsSync{}; - -GNADeviceHelper::GNADeviceHelper(std::shared_ptr targetIn, bool isPerformanceMeasuring, bool deviceEmbedded) - : target(targetIn), - nGnaDeviceIndex{selectGnaDevice()}, - useDeviceEmbeddedExport(deviceEmbedded), - isPerformanceMeasuring(isPerformanceMeasuring) { - per_request_diagnostics = log::get_log_level() >= ov::log::Level::TRACE; - per_model_diagnostics = log::get_log_level() >= ov::log::Level::DEBUG; - open(); - initGnaPerfCounters(); - - // check GNA Library version - GetGnaLibraryVersion(); - - maxLayersCount_ = retrieveMaxLayersCount(); -} - -GNADeviceHelper::~GNADeviceHelper() { - if (deviceOpened) { - close(); - } -} - -uint8_t* GNADeviceHelper::alloc(uint32_t size_requested, uint32_t* size_granted) { - std::unique_lock lockGnaCalls{acrossPluginsSync}; - void* memPtr = nullptr; - const auto status = Gna2MemoryAlloc(size_requested, size_granted, &memPtr); - checkGna2Status(status, "Gna2MemoryAlloc"); - - log::debug() << "Gna2MemoryAlloc(" << size_requested << ") -> " << *size_granted << ", " << memPtr << "\n"; - allAllocations.Add(memPtr, size_requested, *size_granted); - if (memPtr == nullptr) { - THROW_GNA_EXCEPTION << "GNAAlloc failed to allocate memory. Requested: " << size_requested - << " Granted: " << *(size_granted); - } - - dumpXNNROPtr = memPtr; - dumpXNNROSize = *size_granted; - return static_cast(memPtr); -} - -void GNADeviceHelper::tagMemoryRegion(void* memPtr, const memory::rRegion tag) { - std::unique_lock lockGnaCalls{acrossPluginsSync}; - using memory::rRegion; - static const std::map tagMap{ - {rRegion::REGION_INPUTS, Gna2MemoryTagInput}, - {rRegion::REGION_OUTPUTS, Gna2MemoryTagOutput}, - {rRegion::REGION_SCRATCH, Gna2MemoryTagScratch}, - {rRegion::REGION_RO, Gna2MemoryTagReadOnly}, - {rRegion::REGION_STATES, Gna2MemoryTagState}, - {rRegion::REGION_AUTO, Gna2MemoryTagState}, - }; - auto memoryTag = tagMap.at(tag); - if (tag == rRegion::REGION_AUTO) { - return; - } - const auto status = Gna2MemorySetTag(memPtr, memoryTag); - checkGna2Status(status, "Gna2MemorySetTag"); - log::debug() << "Gna2MemorySetTag(" << memPtr << ", " << memoryTag << ")\n"; - const auto tagSuccess = allAllocations.SetTagFor(memPtr, memoryTag); - if (!tagSuccess) { - THROW_GNA_EXCEPTION << "Allocation not found when tagging memory\n"; - } -} - -void GNADeviceHelper::free(void* ptr) { - Gna2Status status; - bool removeSuccess; - std::string message; - { - std::unique_lock lockGnaCalls{acrossPluginsSync}; - status = Gna2MemoryFree(ptr); - message = checkGna2Status(status, "Gna2MemoryFree", true); - removeSuccess = allAllocations.Remove(ptr); - } - if (!message.empty()) { - log::error() << message; - } - if (!removeSuccess) { - log::error() << "Allocation not found when freeing memory\n"; - } -} - -std::string GNADeviceHelper::getGnaLibraryVersionPrivate() { - char buffer[64] = {}; - const auto status = Gna2GetLibraryVersion(buffer, sizeof(buffer)); - if (status != Gna2StatusSuccess) { - return "2.Gna2GetLibraryVersionReturned[" + std::to_string(status) + "]"; - } - return buffer; -} - -std::string GNADeviceHelper::GetGnaLibraryVersion() { - static std::string gnaLibraryVersion{getGnaLibraryVersionPrivate()}; - return gnaLibraryVersion; -} - -void GNADeviceHelper::dumpAllAllocations(const uint64_t idx, const std::string& infix) const { - for (auto&& a : allAllocations.GetAllocationsInExportOrder()) { - const auto& name = a.GetTagName(); - const auto filename = std::to_string(idx) + name + kDumpDelimiter + infix + kDumpExt; - std::ofstream file(filename, std::ios::out | std::ios::binary); - if (file) { - file.write(static_cast(a.ptr), a.sizeGranted); - } else { - log::error() << "Can not dump memory region, file not created: '" << filename << "'\n"; - } - } -} - -uint32_t GNADeviceHelper::enqueueRequest(const uint32_t requestConfigID, Gna2AccelerationMode gna2AccelerationMode) { - std::unique_lock lockGnaCalls{acrossPluginsSync}; - uint32_t reqId{}; - if ((gna2AccelerationMode == Gna2AccelerationModeHardware || - gna2AccelerationMode == Gna2AccelerationModeHardwareWithSoftwareFallback) && - target->get_detected_device_version() == DeviceVersion::SoftwareEmulation) { - log::warning() << "GNA Device not detected, consider using other mode of acceleration"; - } - - const auto status1 = Gna2RequestConfigSetAccelerationMode(requestConfigID, gna2AccelerationMode); - checkGna2Status(status1, "Gna2RequestConfigSetAccelerationMode"); - - if (per_request_diagnostics) { - dumpAllAllocations(debugLogIndexRequestEnqueue, "BeforeGna2RequestEnqueue"); - debugLogIndexRequestEnqueue++; - } - - const auto status2 = Gna2RequestEnqueue(requestConfigID, &reqId); - checkGna2Status(status2, "Gna2RequestEnqueue"); - - unwaitedRequestIds.insert(reqId); - - return reqId; -} - -inline void enforceLegacyCnn(Gna2Operation& operation) { - snprintf(const_cast(operation.Operands[1]->Layout), - sizeof(operation.Operands[1]->Layout) / sizeof(char), - "GNA1"); -} - -void GNADeviceHelper::enforceLegacyCnns(Gna2Model& gnaModel) { - for (uint32_t i = 0; i < gnaModel.NumberOfOperations; i++) { - if (gnaModel.Operations[i].Type == Gna2OperationTypeConvolution) { - enforceLegacyCnn(gnaModel.Operations[i]); - } - } -} - -void GNADeviceHelper::enforceLegacyCnnsWhenNeeded(Gna2Model& gnaModel) { - for (uint32_t i = 0; i < gnaModel.NumberOfOperations; i++) { - auto& op = gnaModel.Operations[i]; - if (backend::AMIntelDNN::isOperationCnnLegacySpecific(op)) { - enforceLegacyCnn(op); - } - } -} - -uint32_t GNADeviceHelper::createModel(Gna2Model& gnaModel) const { - std::unique_lock lockGnaCalls{acrossPluginsSync}; - uint32_t modelId = 0; - const auto legacyExecTarget = enforceLegacyCnnNeeded(); - if (legacyExecTarget) { - enforceLegacyCnns(gnaModel); - } - enforceLegacyCnnsWhenNeeded(gnaModel); - - backend::AMIntelDNN::updateNumberOfOutputsIfPoolingEnabled(gnaModel, legacyExecTarget); - - if (per_model_diagnostics) { - std::string path = -#ifdef _WIN32 - ".\\"; -#else - "./"; -#endif - const std::string mode = useDeviceEmbeddedExport ? "_ee" : ""; - const auto fileSuffix = - mode + "_devVersion_" + toHexString(DeviceToString(target->get_detected_device_version())); - dump::DumpGna2Model(gnaModel, path, false, allAllocations, fileSuffix); - } - - const auto status = Gna2ModelCreate(nGnaDeviceIndex, &gnaModel, &modelId); - - checkGna2Status(status, gnaModel); - return modelId; -} - -void GNADeviceHelper::releaseModel(const uint32_t model_id) { - std::unique_lock lockGnaCalls{acrossPluginsSync}; - const auto status = Gna2ModelRelease(model_id); - checkGna2Status(status, "Gna2ModelRelease"); -} - -bool GNADeviceHelper::enforceLegacyCnnNeeded() const { - const auto execution_target = target->get_effective_execution_target(); - return is_up_to_20_hw(execution_target); -} - -uint32_t GNADeviceHelper::createRequestConfig(const uint32_t modelID) const { - std::unique_lock lockGnaCalls{acrossPluginsSync}; - uint32_t reqConfId = 0; - auto status = Gna2RequestConfigCreate(modelID, &reqConfId); - checkGna2Status(status, "Gna2RequestConfigCreate"); - - status = Gna2InstrumentationConfigAssignToRequestConfig(instrumentationConfigId, reqConfId); - checkGna2Status(status, "Gna2InstrumentationConfigAssignToRequestConfig"); - - return reqConfId; -} - -uint32_t GNADeviceHelper::getNumberOfGnaDevices() { - std::unique_lock lockGnaCalls{acrossPluginsSync}; - uint32_t numberOfGnaDevices = 0; - auto status = Gna2DeviceGetCount(&numberOfGnaDevices); - checkGna2Status(status, "Gna2DeviceGetCount"); - return numberOfGnaDevices; -} - -uint32_t GNADeviceHelper::selectGnaDevice() { - const auto deviceCount = getNumberOfGnaDevices(); - if (deviceCount != 1) { - THROW_GNA_EXCEPTION << "Unsupported number of GNA devices detected = " << deviceCount; - } - return 0; -} - -void GNADeviceHelper::checkGna2Status(Gna2Status status, const Gna2Model& gnaModel) { - if (!Gna2StatusIsSuccessful(status)) { - std::vector gna2StatusBuffer(1024); - const auto s = - Gna2StatusGetMessage(status, gna2StatusBuffer.data(), static_cast(gna2StatusBuffer.size())); - if (!Gna2StatusIsSuccessful(s)) - snprintf(gna2StatusBuffer.data(), - gna2StatusBuffer.size(), - "Gna2StatusGetMessage(%d) returned (%d)", - static_cast(status), - static_cast(s)); - if (status == Gna2StatusDeviceIngoingCommunicationError || - status == Gna2StatusDeviceOutgoingCommunicationError) { - THROW_GNA_EXCEPTION << "Unsuccessful Gna2Status: (" << status << ") " << gna2StatusBuffer.data() - << ", consider updating the GNA driver" << decoratedGnaLibVersion(); - } - - Gna2ModelError error{}; - auto getLastErrorStatus = Gna2ModelGetLastError(&error); - checkGna2Status(getLastErrorStatus, "Gna2ModelGetLastError"); - - std::stringstream ss; - ss << "\n GNA Library Error:\n"; - const Gna2ItemType type = error.Source.Type; - const std::string errorType = - errorTypes.find(type) != errorTypes.end() ? errorTypes.at(type) : "Unknown Error Type"; - - ss << " Type (" << std::to_string(type) << "): " << errorType << "\n"; - - if (error.Source.OperationIndex != GNA2_DISABLED) { - const Gna2OperationType opTypeIndex = gnaModel.Operations[error.Source.OperationIndex].Type; - const std::string operationType = operationTypes.find(opTypeIndex) != operationTypes.end() - ? operationTypes.at(opTypeIndex) - : "Unknown Operation Type"; - const std::string operandType = - operandTypes.find({opTypeIndex, error.Source.OperandIndex}) != operandTypes.end() - ? operandTypes.at({opTypeIndex, error.Source.OperandIndex}) - : "Unknown Operand Type"; - - ss << " OperationIndex (" << std::to_string(error.Source.OperationIndex) << "): " << operationType - << "\n"; - ss << " OperandIndex(" << std::to_string(error.Source.OperandIndex) << "): " << operandType << "\n"; - ss << " ParamIndex (" << std::to_string(error.Source.ParameterIndex) << ")\n"; - ss << " DimIndex (" << std::to_string(error.Source.ShapeDimensionIndex) << ")\n"; - } - - const Gna2ErrorType reason = error.Reason; - const std::string errorReason = - errorReasons.find(reason) != errorReasons.end() ? errorReasons.at(reason) : "Unknown Error Reason"; - ss << " Reason (" << std::to_string(reason) << "): " << errorReason << "\n"; - ss << " Value (0x" << std::hex << error.Value << ")"; - - THROW_GNA_EXCEPTION << "\nUnsuccessful Gna2Status: (" << status << ") " << gna2StatusBuffer.data() << ss.str() - << decoratedGnaLibVersion(); - } -} - -std::string GNADeviceHelper::checkGna2Status(Gna2Status status, const std::string& from, bool returnInsteadThrow) { - if (!Gna2StatusIsSuccessful(status)) { - std::vector gna2StatusBuffer(1024); - const auto prefix = "Unsuccessful " + from + " call, Gna2Status: ("; - const auto s = - Gna2StatusGetMessage(status, gna2StatusBuffer.data(), static_cast(gna2StatusBuffer.size())); - if (!Gna2StatusIsSuccessful(s)) - snprintf(gna2StatusBuffer.data(), - gna2StatusBuffer.size(), - "Gna2StatusGetMessage(%d) returned (%d)", - static_cast(status), - static_cast(s)); - std::string suffix; - if (status == Gna2StatusDeviceIngoingCommunicationError || - status == Gna2StatusDeviceOutgoingCommunicationError) { - suffix = ", consider updating the GNA driver"; - } - std::ostringstream message; - message << prefix << status << ") " << gna2StatusBuffer.data() << suffix << decoratedGnaLibVersion(); - if (returnInsteadThrow) { - return message.str(); - } - THROW_GNA_EXCEPTION << message.str(); - } - return {}; -} - -const std::map GNADeviceHelper::errorTypes = { - {Gna2ItemTypeNone, "Model context is not applicable or unnecessary"}, - {Gna2ItemTypeModelNumberOfOperations, "Gna2Model::NumberOfOperations"}, - {Gna2ItemTypeModelOperations, "Gna2Model::Operations array"}, - {Gna2ItemTypeOperationType, "Gna2Model::Operations[x]->Gna2Operation::Type"}, - {Gna2ItemTypeOperationOperands, "Gna2Model::Operations[x]->Gna2Operation::Operands array"}, - {Gna2ItemTypeOperationNumberOfOperands, "Gna2Model::Operations[x]->Gna2Operation::NumberOfOperands"}, - {Gna2ItemTypeOperationParameters, "Gna2Model::Operations[x]->Gna2Operation::Parameters array"}, - {Gna2ItemTypeOperationNumberOfParameters, "Gna2Model::Operations[x]->Gna2Operation::NumberOfParameters"}, - {Gna2ItemTypeOperandMode, "Gna2Model::Operations[x]->Gna2Operation::Operands[y]->Gna2Tensor::Mode"}, - {Gna2ItemTypeOperandLayout, "Gna2Model::Operations[x]->Gna2Operation::Operands[y]->Gna2Tensor::Layout"}, - {Gna2ItemTypeOperandType, "Gna2Model::Operations[x]->Gna2Operation::Operands[y]->Gna2Tensor::Type"}, - {Gna2ItemTypeOperandData, "Gna2Model::Operations[x]->Gna2Operation::Operands[y]->Gna2Tensor::Data"}, - {Gna2ItemTypeParameter, - "Gna2Model::Operations[x]->Gna2Operation::Parameters[z]->Parameter, can be of type Gna2Shape, enumeration or " - "integer"}, - {Gna2ItemTypeShapeNumberOfDimensions, - "Gna2Model::Operations[x]->{Gna2Tensor}, Parameter}->Gna2Shape::NumberOfDimensions"}, - {Gna2ItemTypeShapeDimensions, "Gna2Model::Operations[x]->{Gna2Tensor}, Parameter}->Gna2Shape::Dimensions"}, - {Gna2ItemTypeInternal, "Internal model item, that is a derivative of other model parameters"}}; - -const std::map GNADeviceHelper::errorReasons = { - {Gna2ErrorTypeNone, "No error detected"}, - {Gna2ErrorTypeNotTrue, "Item value was expected to be true"}, - {Gna2ErrorTypeNotFalse, "Item value was expected to be false"}, - {Gna2ErrorTypeNullNotAllowed, "Item value was expected to be not null"}, - {Gna2ErrorTypeNullRequired, "Item value was expected to be null"}, - {Gna2ErrorTypeBelowRange, "Item value was below supported range"}, - {Gna2ErrorTypeAboveRange, "Item value was above supported range"}, - {Gna2ErrorTypeNotEqual, "Item value was not equal supported one"}, - {Gna2ErrorTypeNotGtZero, "Item value was below zero"}, - {Gna2ErrorTypeNotZero, "Item value was not equal zero"}, - {Gna2ErrorTypeNotOne, "Item value was not equal one"}, - {Gna2ErrorTypeNotInSet, "Item value was not in supported set of values"}, - {Gna2ErrorTypeNotMultiplicity, "Item value was not multiple of supported value"}, - {Gna2ErrorTypeNotSuccess, "Item value was invalid, no detailed information available"}, - {Gna2ErrorTypeNotAligned, "Item value was not aligned to supported value"}, - {Gna2ErrorTypeArgumentMissing, "Some operation argument was not provided"}, - {Gna2ErrorTypeArgumentInvalid, "Given operation argument was invalid or unexpected"}, - {Gna2ErrorTypeRuntime, "Runtime error occurred during model creation"}, - {Gna2ErrorTypeOther, "Unable to determine the root cause of the issue"}}; - -const std::map GNADeviceHelper::operationTypes = { - {Gna2OperationTypeNone, "None"}, - {Gna2OperationTypeConvolution, "Convolution"}, - {Gna2OperationTypeCopy, "Copy"}, - {Gna2OperationTypeFullyConnectedAffine, "FullyConnectedAffine"}, - {Gna2OperationTypeElementWiseAffine, "ElementWiseAffine"}, - {Gna2OperationTypeGmm, "GMM"}, - {Gna2OperationTypeRecurrent, "Recurrent"}, - {Gna2OperationTypeTransposition, "Transpose"}, - {Gna2OperationTypeThreshold, "Threshold"}}; - -const std::map, const std::string> GNADeviceHelper::operandTypes = { - {{Gna2OperationTypeConvolution, 0}, "Input"}, - {{Gna2OperationTypeConvolution, 1}, "Output"}, - {{Gna2OperationTypeConvolution, 2}, "Filters"}, - {{Gna2OperationTypeConvolution, 3}, "Biases"}, - {{Gna2OperationTypeConvolution, 4}, "Activation"}, - {{Gna2OperationTypeCopy, 0}, "Input"}, - {{Gna2OperationTypeCopy, 1}, "Output"}, - {{Gna2OperationTypeFullyConnectedAffine, 0}, "Input"}, - {{Gna2OperationTypeFullyConnectedAffine, 1}, "Output"}, - {{Gna2OperationTypeFullyConnectedAffine, 2}, "Weights"}, - {{Gna2OperationTypeFullyConnectedAffine, 3}, "Biases"}, - {{Gna2OperationTypeFullyConnectedAffine, 4}, "Activation"}, - {{Gna2OperationTypeFullyConnectedAffine, 5}, "WeightScaleFactors"}, - {{Gna2OperationTypeElementWiseAffine, 0}, "Input"}, - {{Gna2OperationTypeElementWiseAffine, 1}, "Output"}, - {{Gna2OperationTypeElementWiseAffine, 2}, "Weights"}, - {{Gna2OperationTypeElementWiseAffine, 3}, "Biases"}, - {{Gna2OperationTypeElementWiseAffine, 4}, "Activation"}, - {{Gna2OperationTypeGmm, 0}, "Input"}, - {{Gna2OperationTypeGmm, 1}, "Output"}, - {{Gna2OperationTypeGmm, 2}, "Means"}, - {{Gna2OperationTypeGmm, 3}, "InverseCovariances"}, - {{Gna2OperationTypeGmm, 4}, "Constants"}, - {{Gna2OperationTypeRecurrent, 0}, "Input"}, - {{Gna2OperationTypeRecurrent, 1}, "Output"}, - {{Gna2OperationTypeRecurrent, 2}, "Weights"}, - {{Gna2OperationTypeRecurrent, 3}, "Biases"}, - {{Gna2OperationTypeRecurrent, 4}, "Activation"}, - {{Gna2OperationTypeTransposition, 0}, "Input"}, - {{Gna2OperationTypeTransposition, 1}, "Output"}, - {{Gna2OperationTypeThreshold, 0}, "Input"}, - {{Gna2OperationTypeThreshold, 1}, "Output"}}; - -RequestStatus GNADeviceHelper::waitForRequest(uint32_t requestID, int64_t timeoutMilliseconds) { - std::unique_lock lockGnaCalls{acrossPluginsSync}; - const auto status = Gna2RequestWait(requestID, static_cast(timeoutMilliseconds)); - if (status == Gna2StatusWarningDeviceBusy) { - return RequestStatus::kPending; - } - unwaitedRequestIds.erase(requestID); - if (status == Gna2StatusDriverQoSTimeoutExceeded) { - return RequestStatus::kAborted; - } - - if (per_request_diagnostics) { - dumpAllAllocations(debugLogIndexRequestWait, "AfterGna2RequestWait"); - debugLogIndexRequestWait++; - } - updateGnaPerfCounters(); - - // handle error case after updating statistics data. - checkGna2Status(status, "Gna2RequestWait"); - - return RequestStatus::kCompleted; -} - -GNADeviceHelper::DumpResult GNADeviceHelper::dumpXnn(const uint32_t modelId) { - DumpResult r; - - r.model.reset(ExportSueLegacyUsingGnaApi2(modelId, nGnaDeviceIndex, &r.header), gnaUserFree); - - if (r.model == nullptr) { - THROW_GNA_EXCEPTION << "GNADumpXnn returned nullptr"; - } - - return r; -} - -void GNADeviceHelper::dumpTLVForDeviceVersion(const uint32_t modelId, - std::ostream& outStream, - const std::vector& inputsContainer, - const std::vector& outputsContainer) { - ExportTlvModel(modelId, - nGnaDeviceIndex, - outStream, - target->get_effective_compile_target(), - inputsContainer, - outputsContainer, - allAllocations); -} - -void GNADeviceHelper::createVirtualDevice(const DeviceVersion& devVersion) { - const auto status = Gna2DeviceCreateForExport(DeviceToGna(devVersion), &nGnaDeviceIndex); - GNADeviceHelper::checkGna2Status(status, "Gna2DeviceCreateForExport(" + DeviceToString(devVersion) + ")"); -} - -void GNADeviceHelper::updateGnaDeviceVersion() { - Gna2DeviceVersion device_version = Gna2DeviceVersionSoftwareEmulation; - const auto status = Gna2DeviceGetVersion(nGnaDeviceIndex, &device_version); - checkGna2Status(status, "Gna2DeviceGetVersion"); - target->set_detected_device_version(GnaToDevice(device_version)); -} - -void GNADeviceHelper::open() { - std::unique_lock lockGnaCalls{acrossPluginsSync}; - updateGnaDeviceVersion(); - const auto execution_target = target->get_user_set_execution_target(); - - if (useDeviceEmbeddedExport) { - createVirtualDevice(target->get_user_set_compile_target()); - updateGnaDeviceVersion(); - } else if (execution_target != DeviceVersion::NotSet && execution_target != target->get_detected_device_version()) { - createVirtualDevice(execution_target); - updateGnaDeviceVersion(); - if (target->get_detected_device_version() != execution_target) { - THROW_GNA_EXCEPTION << "Wrong virtual GNA device version reported: " - << DeviceToString(target->get_detected_device_version()) - << " instead of: " << DeviceToString(execution_target); - } - } else { - const auto status = Gna2DeviceOpen(nGnaDeviceIndex); - checkGna2Status(status, "Gna2DeviceOpen"); - } - deviceOpened = true; -} - -void GNADeviceHelper::close() { - if (!deviceOpened) - return; - - acrossPluginsSync.lock(); - auto requestsToClose = unwaitedRequestIds; - acrossPluginsSync.unlock(); - - for (auto requestId : requestsToClose) - try { - if (waitForRequest(requestId) == RequestStatus::kPending) - log::warning() << "Request with Id " << requestId << " is still pending"; - } catch (...) { - log::warning() << "Request with Id " << requestId << " was not awaited successfully"; - } - - std::unique_lock lockGnaCalls{acrossPluginsSync}; - const auto status = Gna2DeviceClose(nGnaDeviceIndex); - const auto message = checkGna2Status(status, "Gna2DeviceClose", true); - if (!message.empty()) { - log::warning() << "GNA Device was not successfully closed: " << message << std::endl; - } - deviceOpened = false; -} - -void GNADeviceHelper::updateGnaPerfCounters() { - if (!isPerformanceMeasuring) - return; - instrumentationTotal[0] = instrumentationResults[0]; - instrumentationTotal[1] = instrumentationResults[1]; - instrumentationResults[0] = 0; - instrumentationResults[1] = 0; -} - -void GNADeviceHelper::getGnaPerfCounters( - std::map& retPerfCounters) { - InferenceEngine::InferenceEngineProfileInfo info; - info.status = InferenceEngine::InferenceEngineProfileInfo::EXECUTED; - info.cpu_uSec = 0; - info.execution_index = 0; - info.realTime_uSec = 0; - // Hardware - info.realTime_uSec = instrumentationTotal[0]; - retPerfCounters["1.1 Total scoring time in HW"] = info; - info.realTime_uSec = instrumentationTotal[1]; - retPerfCounters["1.2 Stall scoring time in HW"] = info; -} - -uint32_t GNADeviceHelper::maxLayersCount() const { - return maxLayersCount_; -} - -uint32_t GNADeviceHelper::retrieveMaxLayersCount() { - using namespace limitations; - - switch (target->get_effective_execution_target()) { - case DeviceVersion::GNA1_0: - case DeviceVersion::GNAEmbedded1_0: - case DeviceVersion::GNA2_0: - return Limitations::kMaxLayersCountGNA2_0; - case DeviceVersion::GNA3_0: - case DeviceVersion::GNA3_1: - case DeviceVersion::GNA3_5: - case DeviceVersion::GNAEmbedded3_5: - case DeviceVersion::GNA3_6: - case DeviceVersion::GNA4_0: - default: - return Limitations::kMaxLayersCountGNA3_X; - } -} - -bool GNADeviceHelper::isHwAvailable() { - return target->get_detected_device_version() != DeviceVersion::SoftwareEmulation && - target->get_detected_device_version() != DeviceVersion::NotSet; -} -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_device.hpp b/src/plugins/intel_gna/src/gna_device.hpp deleted file mode 100644 index e254a8ff174..00000000000 --- a/src/plugins/intel_gna/src/gna_device.hpp +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common/gna_target.hpp" -#include "gna2-inference-api.h" -#include "gna2-instrumentation-api.h" -#include "gna2-memory-api.h" -#include "gna2-model-api.h" -#include "gna2-model-export-api.h" -#include "gna2-model-suecreek-header.h" -#include "gna2_model_export_helper.hpp" -#include "gna_device_allocation.hpp" -#include "gna_device_interface.hpp" -#include "memory/gna_mem_requests.hpp" - -namespace ov { -namespace intel_gna { - -/** - * holds gna - style handle in RAII way - */ -class GNADeviceHelper : public GNADevice { - using UnwaitedRequestIds = std::set; - static std::mutex acrossPluginsSync; - static std::string decoratedGnaLibVersion() { - static std::string gnaLibraryVersion{", GNA library version: " + GNADeviceHelper::GetGnaLibraryVersion()}; - return gnaLibraryVersion; - } - std::shared_ptr target; - std::string modeOfOperation = "default"; - GnaAllocations allAllocations; - uint32_t nGnaDeviceIndex = 0; - bool useDeviceEmbeddedExport = false; - uint32_t maxLayersCount_ = 0; - - static const uint32_t TotalGna2InstrumentationPoints = 2; - Gna2InstrumentationPoint gna2InstrumentationPoints[TotalGna2InstrumentationPoints] = { - Gna2InstrumentationPointHwTotal, - Gna2InstrumentationPointHwStall}; - - uint64_t instrumentationResults[TotalGna2InstrumentationPoints] = {}; - uint64_t instrumentationTotal[TotalGna2InstrumentationPoints] = {}; - uint32_t instrumentationConfigId = 0; - UnwaitedRequestIds unwaitedRequestIds; -#define MAX_TIMEOUT 500000 - bool isPerformanceMeasuring = false; - bool deviceOpened = false; - - bool per_request_diagnostics = false; - bool per_model_diagnostics = false; - uint64_t debugLogIndexRequestEnqueue = 0; - uint64_t debugLogIndexRequestWait = 0; - static constexpr const char* kDumpExt = ".bin"; - static constexpr const char* kDumpDelimiter = "."; - -public: - explicit GNADeviceHelper(std::shared_ptr target = std::make_shared(), - bool isPerformanceMeasuring = false, - bool deviceEmbedded = false); - - GNADeviceHelper(const GNADeviceHelper&) = delete; - GNADeviceHelper& operator=(const GNADeviceHelper&) = delete; - GNADeviceHelper(GNADeviceHelper&&) = delete; - GNADeviceHelper& operator=(GNADeviceHelper&&) = delete; - ~GNADeviceHelper() override; - - /** - * @brief Dump raw memory of each GNA allocation to files - * @param idx index to be appended to the file name - * @param infix File name would a form of - */ - void dumpAllAllocations(uint64_t idx, const std::string& infix) const; - - uint8_t* alloc(uint32_t size_requested, uint32_t* size_granted); - void tagMemoryRegion(void* memPtr, const ov::intel_gna::memory::rRegion memoryTag); - - void releaseModel(const uint32_t model_id); - static uint32_t getNumberOfGnaDevices(); - static uint32_t selectGnaDevice(); - static bool is_hw_target(const target::DeviceVersion device_version) { - return target::DeviceVersion::SoftwareEmulation != device_version; - } - bool is_hw_detected() const { - return is_hw_target(target->get_detected_device_version()); - } - bool enforceLegacyCnnNeeded() const; - static std::string checkGna2Status(Gna2Status status, const std::string& from, bool returnInsteadThrow = false); - static void checkGna2Status(Gna2Status status, const Gna2Model& gnaModel); - - struct DumpResult { - Gna2ModelSueCreekHeader header; - std::shared_ptr model; - }; - - const void* dumpXNNROPtr = nullptr; - uint32_t dumpXNNROSize = 0; - - DumpResult dumpXnn(const uint32_t modelId); - - void dumpTLVForDeviceVersion(const uint32_t modelId, - std::ostream& outStream, - const std::vector& inputsContainer, - const std::vector& outputsContainer); - - void free(void* ptr); - - void updateGnaPerfCounters(); - void getGnaPerfCounters(std::map& retPerfCounters); - static std::string GetGnaLibraryVersion(); - - bool isHwAvailable(); - const GnaAllocations& getAllAllocations() const { - return allAllocations; - } - - /** - * @see GNADevice::createModel() - */ - uint32_t createModel(Gna2Model& gnaModel) const override; - - /** - * @see GNADevice::createRequestConfig() - */ - uint32_t createRequestConfig(const uint32_t modelID) const override; - - /** - * @see GNADevice::enqueueRequest() - */ - uint32_t enqueueRequest(const uint32_t requestConfigID, const Gna2AccelerationMode gna2AccelerationMode) override; - - /** - * @see GNADevice::waitForRequest() - */ - ov::intel_gna::RequestStatus waitForRequest(uint32_t requestID, int64_t timeoutMilliseconds = MAX_TIMEOUT) override; - - /** - * @see GNADevice::maxLayersCount() - */ - uint32_t maxLayersCount() const override; - - /** - * @brief close the device - **/ - void close() override; - -private: - void open(); - - uint32_t retrieveMaxLayersCount(); - - static std::string getGnaLibraryVersionPrivate(); - static const std::map errorTypes; - static const std::map errorReasons; - static const std::map operationTypes; - static const std::map, const std::string> operandTypes; - - static void enforceLegacyCnns(Gna2Model& gnaModel); - static void enforceLegacyCnnsWhenNeeded(Gna2Model& gnaModel); - static bool is_up_to_20_hw(const target::DeviceVersion device_version) { - switch (device_version) { - case target::DeviceVersion::GNA1_0: - case target::DeviceVersion::GNAEmbedded1_0: - case target::DeviceVersion::GNA2_0: - return true; - default: - return false; - } - } - void createVirtualDevice(const target::DeviceVersion& devVersion); - void updateGnaDeviceVersion(); - - void initGnaPerfCounters() { - std::unique_lock lockGnaCalls{acrossPluginsSync}; - const auto status = Gna2InstrumentationConfigCreate(TotalGna2InstrumentationPoints, - gna2InstrumentationPoints, - instrumentationResults, - &instrumentationConfigId); - checkGna2Status(status, "Gna2InstrumentationConfigCreate"); - } -}; // NOLINT - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_device_allocation.hpp b/src/plugins/intel_gna/src/gna_device_allocation.hpp deleted file mode 100644 index 1fadef5c385..00000000000 --- a/src/plugins/intel_gna/src/gna_device_allocation.hpp +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "gna2-model-export-api.h" -#include "gna_lib_ver_selector.hpp" -#include "memory/gna_mem_regions.hpp" - -using ov::intel_gna::memory::rRegion; - -struct GnaAllocation { - void* ptr = nullptr; - size_t sizeRequested = 0; - size_t sizeGranted = 0; - void SetTag(Gna2MemoryTag in) { - isTagSet = true; - tag = in; - } - bool isTag(Gna2MemoryTag in) const { - return isTagSet && in == tag; - } - std::string GetTagName() const { - static const std::map tm = { - {Gna2MemoryTagReadWrite, "Gna2MemoryTagReadWrite"}, - {Gna2MemoryTagInput, "Gna2MemoryTagInput"}, - {Gna2MemoryTagOutput, "Gna2MemoryTagOutput"}, - {Gna2MemoryTagReadOnly, "Gna2MemoryTagReadOnly"}, - {Gna2MemoryTagExternalBufferInput, "Gna2MemoryTagExternalBufferInput"}, - {Gna2MemoryTagExternalBufferOutput, "Gna2MemoryTagExternalBufferOutput"}, - {Gna2MemoryTagScratch, "Gna2MemoryTagScratch"}, - {Gna2MemoryTagState, "Gna2MemoryTagState"}, - }; - if (!isTagSet) { - return "Gna2MemoryTag_NotSet_"; - } - auto f = tm.find(tag); - if (f != tm.end()) { - return f->second; - } - return "Gna2MemoryTag_" + std::to_string(tag) + "_"; - } - - static rRegion GetRegionForTag(Gna2MemoryTag tag) { - static const std::map tm = { - {Gna2MemoryTagInput, rRegion::REGION_INPUTS}, - {Gna2MemoryTagOutput, rRegion::REGION_OUTPUTS}, - {Gna2MemoryTagReadOnly, rRegion::REGION_RO}, - {Gna2MemoryTagScratch, rRegion::REGION_SCRATCH}, - {Gna2MemoryTagState, rRegion::REGION_STATES}, - {Gna2MemoryTagExternalBufferInput, rRegion::REGION_INPUTS}, - {Gna2MemoryTagExternalBufferOutput, rRegion::REGION_OUTPUTS}, - }; - auto f = tm.find(tag); - if (f != tm.end()) { - return f->second; - } - return rRegion::REGION_AUTO; - } - - bool operator<(const GnaAllocation& right) const { - const auto region = GetRegionForTag(tag); - const auto regionRight = GetRegionForTag(right.tag); - return region < regionRight; - } - - std::pair getOffset(void* offset) const { - std::pair v; - v.first = offset >= ptr && offset < static_cast(ptr) + sizeGranted; - v.second = v.first ? static_cast(offset) - static_cast(ptr) : 0; - return v; - } - - uint32_t sizeForExport() const { - return ALIGN64(static_cast(sizeRequested)); - } - -private: - Gna2MemoryTag tag = Gna2MemoryTagScratch; - bool isTagSet = false; -}; - -class GnaAllocations { - std::list allocations; - -public: - GnaAllocations() = default; - template - explicit GnaAllocations(T b, T e) : allocations(b, e) {} - - static uint32_t GetSizeForExport(const std::list& allocations) { - uint32_t total = 0; - for (auto& a : allocations) { - total += a.sizeForExport(); - } - return total; - } - - uint32_t GetSizeForExport() const { - return GetSizeForExport(allocations); - } - - std::list GetAllocationsInExportOrder() const { - std::vector temp(allocations.begin(), allocations.end()); - std::stable_sort(temp.begin(), temp.end()); - return std::list(temp.begin(), temp.end()); - } - - static std::pair GetOffsetForExport(const std::list& orderedAllocations, void* ptr) { - uint64_t curOffset = 0; - for (auto& r : orderedAllocations) { - auto ptrBegin = static_cast(r.ptr); - const auto size = r.sizeForExport(); - if (ptr >= ptrBegin && ptr < ptrBegin + size) { - curOffset += static_cast(ptr) - ptrBegin; - return {true, curOffset}; - } - curOffset += size; - } - return {false, 0}; - } - - bool SetTagFor(void* memPtr, Gna2MemoryTag memoryTag) { - auto found = std::find_if(allocations.begin(), allocations.end(), [memPtr](const GnaAllocation& a) { - return a.ptr == memPtr; - }); - if (found != allocations.end()) { - found->SetTag(memoryTag); - return true; - } - return false; - } - - bool Remove(void* memPtr) { - auto found = std::find_if(allocations.begin(), allocations.end(), [memPtr](const GnaAllocation& a) { - return a.ptr == memPtr; - }); - if (found != allocations.end()) { - allocations.erase(found); - return true; - } - return false; - } - - void Add(void* memPtr, uint32_t sizeRequested, uint32_t sizeGranted) { - GnaAllocation newAllocation; - newAllocation.ptr = memPtr; - newAllocation.sizeRequested = sizeRequested; - newAllocation.sizeGranted = sizeGranted; - allocations.push_back(newAllocation); - } - - const GnaAllocation* Get(const Gna2MemoryTag tag) const { - for (auto&& a : allocations) { - if (a.isTag(tag)) { - return &a; - } - } - return nullptr; - } -}; diff --git a/src/plugins/intel_gna/src/gna_device_interface.hpp b/src/plugins/intel_gna/src/gna_device_interface.hpp deleted file mode 100644 index 2904fc4b5ec..00000000000 --- a/src/plugins/intel_gna/src/gna_device_interface.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "request_status.hpp" - -enum Gna2AccelerationMode; -struct Gna2Model; - -namespace ov { -namespace intel_gna { - -// Interface name is different to the file naem due the lagacy reason. -// 1. Implementation file names should be changed in next PR. -// 2. Implementation of interface should be moved to ov::intel_gna namespace - -/** - * @interface Interface for invoking operation on GNA device. - */ -class GNADevice { -public: - /** - * @brief Destruct {GNADevice} object - */ - virtual ~GNADevice() = default; - - /** - * @brief Create gna model on device. - * @param gna_model gna modle to by created on device - * @return model id on device - * @throw Exception in case of error - */ - virtual uint32_t createModel(Gna2Model& gnaModel) const = 0; - - /** - * @brief create request configuration for give id of model - * @param modelID id of model on device - * @return id of configuration for model - * @throw Exception in case of error - */ - virtual uint32_t createRequestConfig(const uint32_t modelID) const = 0; - - /** - * @brief Add request to the execution queue. - * @param requestConfigID id of request configuration to be used for equing request - * @param gna2AccelerationMode acceleration mode of GNA device - * @return enqueued request id on device - * @throw Exception in case of error - */ - virtual uint32_t enqueueRequest(const uint32_t requestConfigID, Gna2AccelerationMode gna2AccelerationMode) = 0; - - /** - * @brief Wait for request to be finished. - * @param requestID id of request enqueued on device - * @param timeoutMilliseconds maximum timeout to be used for waiting - * @return status of request given to the methoid. @see RequestStatus. - * @throw Exception in case of error - */ - virtual RequestStatus waitForRequest(uint32_t requestID, int64_t timeoutMilliseconds) = 0; - - /** - * @brief Return maximum number of layers supported by device. - * @return maximum layers count - **/ - virtual uint32_t maxLayersCount() const = 0; - - /** - * @brief close the device. - **/ - virtual void close() {} -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_executable_network.hpp b/src/plugins/intel_gna/src/gna_executable_network.hpp deleted file mode 100644 index e6f1c6d1e43..00000000000 --- a/src/plugins/intel_gna/src/gna_executable_network.hpp +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include -#include -#include -#include -#include -#include -#include - -#include "gna_infer_request.hpp" -#include "gna_plugin.hpp" - -namespace ov { -namespace intel_gna { - -class GNAExecutableNetwork : public InferenceEngine::IExecutableNetworkInternal { - std::shared_ptr plg; - -public: - GNAExecutableNetwork(const std::string& aotFileName, std::shared_ptr plg) : plg(plg) { - std::fstream inputStream(aotFileName, std::ios_base::in | std::ios_base::binary); - if (inputStream.fail()) { - THROW_GNA_EXCEPTION << "Cannot open file to import model: " << aotFileName; - } - plg->ImportNetwork(inputStream); - // old API - setNetworkInputs(plg->GetNetworkInputs()); - setNetworkOutputs(plg->GetNetworkOutputs()); - // new API - setInputs(plg->GetInputs()); - setOutputs(plg->GetOutputs()); - } - - GNAExecutableNetwork(std::istream& networkModel, std::shared_ptr plg) : plg(plg) { - plg->ImportNetwork(networkModel); - // old API - setNetworkInputs(plg->GetNetworkInputs()); - setNetworkOutputs(plg->GetNetworkOutputs()); - // new API - setInputs(plg->GetInputs()); - setOutputs(plg->GetOutputs()); - } - - GNAExecutableNetwork(const InferenceEngine::CNNNetwork& network, std::shared_ptr plg) : plg(plg) { - plg->LoadNetwork(network); - } - - GNAExecutableNetwork(const std::string& aotFileName, const std::map& config) - : GNAExecutableNetwork(aotFileName, std::make_shared(config)) {} - - GNAExecutableNetwork(InferenceEngine::CNNNetwork& network, const std::map& config) - : GNAExecutableNetwork(network, std::make_shared(config)) {} - - InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl( - InferenceEngine::InputsDataMap networkInputs, - InferenceEngine::OutputsDataMap networkOutputs) override { - return std::make_shared(plg, networkInputs, networkOutputs); - } - - InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl( - const std::vector>& inputs, - const std::vector>& outputs) override { - if (!this->_plugin || !_plugin->IsNewAPI()) - return nullptr; - return std::make_shared(plg, inputs, outputs); - } - - void Export(const std::string& modelFileName) override { - plg->UpdateInputs(getInputs()); - plg->UpdateOutputs(getOutputs()); - plg->Export(modelFileName); - } - - void Export(std::ostream& modelStream) override { - plg->UpdateInputs(getInputs()); - plg->UpdateOutputs(getOutputs()); - plg->Export(modelStream); - } - - void SetConfig(const std::map& config) override { - using namespace InferenceEngine::GNAConfigParams; - if (config.empty()) { - IE_THROW() << "The list of configuration values is empty"; - } - - auto supported_properties = Config::GetSupportedProperties(true).as>(); - for (auto&& item : config) { - auto it = std::find(supported_properties.begin(), supported_properties.end(), item.first); - if (it != supported_properties.end()) { - if (!it->is_mutable()) { - IE_THROW() << "The following config value cannot be changed dynamically " - << "for compiled model in the GNA plugin: " << item.first; - } - } else if (item.first != KEY_GNA_DEVICE_MODE) { - IE_THROW() << "The following config value cannot be changed dynamically for ExecutableNetwork in the " - "GNA plugin: " - << item.first << ". Only " << KEY_GNA_DEVICE_MODE << " is supported."; - } - } - - InferenceEngine::Parameter old_mode_parameter = GetConfig(KEY_GNA_DEVICE_MODE); - auto old_mode = old_mode_parameter.as(); - if (old_mode == InferenceEngine::GNAConfigParams::GNA_SW_FP32) { - IE_THROW() << "Dynamic switching from GNA_SW_FP32 mode is not supported for ExecutableNetwork."; - } - - auto new_mode = config.begin()->second.as(); - if (new_mode == InferenceEngine::GNAConfigParams::GNA_SW_FP32) { - IE_THROW() << "Dynamic switching to GNA_SW_FP32 mode is not supported for ExecutableNetwork."; - } - - std::map configForPlugin; - configForPlugin[KEY_GNA_DEVICE_MODE] = new_mode; - plg->SetConfig(configForPlugin); - } - - InferenceEngine::Parameter GetConfig(const std::string& name) const override { - return plg->GetConfig(name, {}); - } - - InferenceEngine::Parameter GetMetric(const std::string& name) const override { - if (ov::supported_properties == name) { - return Config::GetSupportedProperties(true); - } else { - return plg->GetMetric(name, {}); - } - } -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_fused_iterator.hpp b/src/plugins/intel_gna/src/gna_fused_iterator.hpp deleted file mode 100644 index d91a230f532..00000000000 --- a/src/plugins/intel_gna/src/gna_fused_iterator.hpp +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include -#include -#include -#include - -#include "gna_graph_tools.hpp" -#include "layers/gna_layer_helpers.hpp" - -namespace ov { -namespace intel_gna { - -/** - * @brief Modify child layers walking order to maintain strict ordering required for gna_fuse logic - */ -class FuzedLayersIterator { - friend class FuzedLayersContainer; - using iterator = std::map::iterator; - std::list allOutputs; - bool needReorder = false; - InferenceEngine::details::OutLayersIterator standardIterator; - std::list::iterator reorderedIterator; - -public: - FuzedLayersIterator() = default; - explicit FuzedLayersIterator(InferenceEngine::CNNLayer* origin) { - bool hasActivation = false; - for (auto&& data : origin->outData) { - auto& inputTo = getInputTo(data); - for (auto i = inputTo.begin(); i != inputTo.end(); i++) { - LayerInfo info(i->second); - if (info.isActivation()) { - hasActivation = true; - allOutputs.push_back(i); - } else { - allOutputs.push_front(i); - } - } - } - - if (hasActivation && allOutputs.size() > 1) { - needReorder = true; - } - - if (!needReorder) { - standardIterator = InferenceEngine::details::OutInfoWrapper(origin).begin(); - } else { - reorderedIterator = allOutputs.begin(); - } - } - - void operator++() { - if (!needReorder) { - standardIterator.operator++(); - return; - } - reorderedIterator++; - } - - bool operator==(FuzedLayersIterator that) const { - if (!needReorder) { - return standardIterator == that.standardIterator; - } - if (that.reorderedIterator == std::list::iterator()) { - return reorderedIterator == allOutputs.end(); - } - - return that.reorderedIterator == reorderedIterator; - } - - bool operator!=(FuzedLayersIterator that) const { - return !this->operator==(that); - } - - InferenceEngine::CNNLayerPtr operator*() const { - if (!needReorder) { - return *standardIterator; - } - return (*reorderedIterator)->second; - } -}; - -class FuzedLayersContainer { - InferenceEngine::CNNLayer* origin; - -public: - explicit FuzedLayersContainer(InferenceEngine::CNNLayer* origin) : origin(origin) {} - FuzedLayersIterator begin() { - return FuzedLayersIterator(origin); - } - - FuzedLayersIterator end() { - return FuzedLayersIterator(); - } -}; - -inline FuzedLayersContainer make_fuzed_order(InferenceEngine::CNNLayer* origin) { - FuzedLayersContainer fusedCnt(origin); - return fusedCnt; -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_graph_compiler.cpp b/src/plugins/intel_gna/src/gna_graph_compiler.cpp deleted file mode 100644 index a3b7939677a..00000000000 --- a/src/plugins/intel_gna/src/gna_graph_compiler.cpp +++ /dev/null @@ -1,2850 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#define NOMINMAX - -#include "gna_graph_compiler.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "backend/am_intel_dnn.hpp" -#include "backend/gna_limitations.hpp" -#include "caseless.hpp" -#include "common/numerical_utils.hpp" -#include "descriptions/gna_desc.hpp" -#include "frontend/layer_quantizer.hpp" -#include "frontend/scale_factor_calc.hpp" -#include "gna_data_types.hpp" -#include "gna_graph_tools.hpp" -#include "gna_groups.hpp" -#include "ie_memcpy.h" -#include "layers/gna_concat_layer.hpp" -#include "layers/gna_convolution_layer.hpp" -#include "layers/gna_crop_layer.hpp" -#include "layers/gna_fake_quantize_layer.hpp" -#include "layers/gna_layer_info.hpp" -#include "layers/layers_builder.hpp" -#include "log/log.hpp" -#include "ops/pwl.hpp" -#include "runtime/pwl.h" - -using namespace InferenceEngine; -using namespace std; - -namespace ov { -namespace intel_gna { -using namespace frontend; -using namespace common; -using namespace memory; -using namespace limitations; - -static bool CheckIFLastComponentIsPrecededByConv2D(const backend::DnnComponents::storage_type& components, - bool verify_with_pooling = true) { - bool proceded_by_conv2D = false; - auto last_element = components.rbegin(); - if (components.size() > 1) { - last_element++; - if (last_element->dnnComponent.operation == kDnnConvolutional2dOp) { - proceded_by_conv2D = true; - } else if (verify_with_pooling && components.size() > 2) { - auto prev_operation = last_element->dnnComponent.operation; - last_element++; - if (last_element->dnnComponent.operation == kDnnConvolutional2dOp) { - proceded_by_conv2D = (prev_operation == kDnnMaxPoolOp); - } - } - } - return proceded_by_conv2D; -} - -#define CREATE(name) \ - [](GNAGraphCompiler* p, CNNLayerPtr l) { \ - p->name(l); \ - } - -static uint32_t count_conv2D_input_width_for_expected_output_width(uint32_t expected_ouput_width, - uint32_t kernel_width, - uint32_t stride_width, - uint32_t padding_width) { - return (expected_ouput_width - 1) * stride_width - 2 * padding_width + kernel_width; -}; - -GNAGraphCompiler::GNAGraphCompiler(const Config& gna_config, - std::shared_ptr dnn_ptr, - std::shared_ptr inputs_ptr, - std::shared_ptr cnn2d_validator_ptr, - std::shared_ptr gna_mem_ptr) - : gna_config(gna_config) { - dnn = std::move(dnn_ptr); - inputs_ptr_ = std::move(inputs_ptr); - m_cnn2d_validator = std::move(cnn2d_validator_ptr); - gnamem = std::move(gna_mem_ptr); -} - -void GNAGraphCompiler::setGNAMemoryPtr(std::shared_ptr gnaMemPtr) { - this->gnamem = std::move(gnaMemPtr); -} - -intel_dnn_component_t* GNAGraphCompiler::find_first_unused_input(InferenceEngine::CNNLayerPtr current) { - if (current->insData.empty()) - return nullptr; - auto inData = current->insData.front().lock(); - if (inData == nullptr) - return nullptr; - - auto prev_layer = getCreatorLayer(inData).lock(); - - return dnnComponents.findComponent(prev_layer); -} - -void GNAGraphCompiler::fillMemoryConnections( - std::unordered_map>& memoryPairs) { - for (auto& memory : memoryPairs) { - auto inputLayer = memory.second[1]; - auto outputLayer = memory.second[0]; - - IE_ASSERT(1 == outputLayer->insData.size()); - - // creating connection for layers output as form of extramap - memory_connection.emplace_back(memory.first, - GNAMemoryLayer(inputLayer, outputLayer, gna_config.gnaFlags.sw_fp32 ? 4 : 2)); - } -} - -void GNAGraphCompiler::fillConcatConnections(InferenceEngine::CNNLayerPtr layer) { - // creating connection for each layer outputs as form of extramap - GNAConcatLayer layerInfoItem(layer); - size_t concat_size = 0; - std::string& id = layer->name; - - for (size_t i = 0; i < layer->insData.size(); ++i) { - auto ptrConcatLayerInput = CNNNetPrevLayerSkipCertain(layer, static_cast(i), [](CNNLayerPtr lp) { - LayerInfo info(lp); - return info.isNonFunctional(); - }); - auto dataInput = layer->insData[i].lock(); - if (!dataInput) { - THROW_GNA_EXCEPTION << "Input layer pointer for concat is unexpectedly absent"; - } - - if (!ptrConcatLayerInput) { - THROW_GNA_EXCEPTION << "Input layer for concat is unexpectedly absent"; - } - - size_t layer_size = InferenceEngine::details::product(begin(dataInput->getDims()), end(dataInput->getDims())) * - dataInput->getPrecision().size(); - - // concat align layer can have additional padding, so the size of layer needs to be calculated - // based on original number of rows - if (ptrConcatLayerInput->CheckParamPresence("original_num_rows")) { - layer_size = ptrConcatLayerInput->GetParamAsInt("original_num_rows") * dataInput->getPrecision().size(); - } - - layerInfoItem.concatInputLayers.emplace_back( - GNAConcatLayer::ConcatConnectedLayerInfo{ptrConcatLayerInput->name, concat_size, layer_size}); - - concat_size += layer_size; - } - layerInfoItem.reserved_size = concat_size; - concat_connection.emplace(id, layerInfoItem); -} - -void GNAGraphCompiler::fillSplitConnections(InferenceEngine::CNNLayerPtr layer) { - // creating connection for each layer inputs as form of extramap - GNASplitLayer layerInfoItem(layer); - size_t split_size = 0; - std::string& id = layer->name; - IE_ASSERT(!layer->insData.empty()); - - auto dataInput = layer->insData.begin()->lock(); - if (!dataInput) { - THROW_GNA_LAYER_EXCEPTION(layer) << "Input layer pointer is unexpectedly absent"; - } - auto ptrSplitLayerInput = getCreatorLayer(dataInput).lock(); - if (!ptrSplitLayerInput) { - THROW_GNA_LAYER_EXCEPTION(layer) << "Input layer for is unexpectedly absent"; - } - - for (size_t i = 0; i < layer->outData.size(); ++i) { - size_t padding = 0; - size_t output_layer_size = 0; - - for (int j = 0; j != static_cast(getInputTo(layer->outData[i]).size()); j++) { - auto outFunctionalLayer = - CNNNetCheckNextLayerSkipCertain(layer, static_cast(i), j, true, [](CNNLayerPtr l) { - return LayerInfo(l).isNonFunctional(); - }); - - if (!outFunctionalLayer.first) { - output_layer_size = InferenceEngine::details::product(begin(layer->outData[i]->getDims()), - end(layer->outData[i]->getDims())) * - layer->outData[i]->getPrecision().size(); - continue; - } - - for (int idx : outFunctionalLayer.second) { - auto dataOutput = outFunctionalLayer.first->insData[idx].lock(); - - padding = std::max(padding, LayerInfo(outFunctionalLayer.first).paddingSize()) * - dataOutput->getPrecision().size(); - output_layer_size = - InferenceEngine::details::product(begin(dataOutput->getDims()), end(dataOutput->getDims())) * - dataOutput->getPrecision().size(); - - if (LayerInfo(outFunctionalLayer.first).isConvolutionFilter()) { - size_t aligned64_offset = outFunctionalLayer.first->GetParamAsInt("offset"); - layerInfoItem.splitOutputLayers.emplace_back(outFunctionalLayer.first, - idx, - aligned64_offset * dataOutput->getPrecision().size(), - output_layer_size); - } else { - layerInfoItem.splitOutputLayers.emplace_back(outFunctionalLayer.first, - idx, - split_size, - output_layer_size); - } - } - } - - // in case of unconnected split - we need properly increment size - if (getInputTo(layer->outData[i]).empty()) { - output_layer_size = InferenceEngine::details::product(begin(layer->outData[i]->getDims()), - end(layer->outData[i]->getDims())) * - layer->outData[i]->getPrecision().size(); - } - - split_size += padding + output_layer_size; - } - layerInfoItem.reserved_size = split_size; - split_connection.emplace(id, layerInfoItem); -} - -bool GNAGraphCompiler::ShouldUseOnlyConv2DGnaIface() const { - return m_cnn2d_validator && m_cnn2d_validator->ShouldUseOnlyConv2DGnaIface(); -} - -void GNAGraphCompiler::ValidateCnn2D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kH, - const uint32_t kW, - const uint32_t kN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilH, - const uint32_t dilW, - OvGnaType inPrecision) const { - if (m_cnn2d_validator) { - if (m_cnn2d_validator->ValidateCnn1D(name, - inHeight, - inWidth, - inChannels, - kH, - kW, - kN, - strideH, - strideW, - dilH, - dilW, - inPrecision, - false)) { - return; - } - m_cnn2d_validator - ->ValidateCnn2D(name, inHeight, inWidth, inChannels, kH, kW, kN, strideH, strideW, dilH, dilW, inPrecision); - } else { - THROW_GNA_EXCEPTION << "No Cnn2D validator found for layer " << name; - } -} - -void GNAGraphCompiler::ValidatePooling2D(const std::string& name, - const uint32_t windowH, - const uint32_t windowW, - const uint32_t strideH, - const uint32_t strideW) const { - if (m_cnn2d_validator) { - m_cnn2d_validator->ValidatePooling2D(name, windowH, windowW, strideH, strideW); - } else { - THROW_GNA_EXCEPTION << "No Pooling2D validator found for layer " << name; - } -} - -void GNAGraphCompiler::DiagonalPrimitive(InferenceEngine::CNNLayerPtr layer) { - AffinePrimitive(layer, true); -} - -void GNAGraphCompiler::ConstPrimitive(InferenceEngine::CNNLayerPtr constLayer) { - if (constLayer->blobs.find("custom") == constLayer->blobs.end()) { - THROW_GNA_EXCEPTION << "const layer: " << constLayer->name << "doesn't have custom in blobs section"; - } - auto const_blob = constLayer->blobs["custom"]; - - const_connections[constLayer->name] = &const_connections[constLayer->name]; - void* ptr_for_const_blob = &const_connections[constLayer->name]; - - connectOutput(constLayer, ptr_for_const_blob, const_blob->byteSize()); - - // TODO: segment type for bind, bind initializer not used - need refactor to separate bind and allocation requests - // dont see practical use case when bind storage type need to be different that allocation type - gnamem->getQueue(REGION_AUTO)->bind_initializer(nullptr, ptr_for_const_blob, [const_blob](void* data, size_t size) { - ie_memcpy(data, size, const_blob->buffer(), const_blob->byteSize()); - }); -} - -void GNAGraphCompiler::assertConvolutionLayoutProper(const InferenceEngine::DataPtr& data) { - if (data->getLayout() != InferenceEngine::Layout::NHWC && data->getLayout() != InferenceEngine::Layout::NCHW && - data->getLayout() != InferenceEngine::Layout::NC && data->getLayout() != InferenceEngine::Layout::CHW) { - THROW_GNA_EXCEPTION << "layer: \"Convolution\" with layout " << data->getLayout() - << " isn't currently supported on GNA"; - } -} - -namespace { - -template -PropertyVector property_vector_append(PropertyVector properties, T value) { - std::vector new_values; - for (size_t i = 0; i < properties.size(); ++i) - new_values.push_back(properties[i]); - new_values.push_back(value); - - return PropertyVector(new_values); -} - -} // namespace - -/** - * Create AMIntelDNN Convolutional1DComponent from ConvolutionLayer - * - * GNA Convolution input is NHCW and output is transposed to NHWC - * - * OpenVINO default layout is NCHW - * TensorFlow default layout is NHWC - * - * There is option in ModelOptimizer - * --disable_nhwc_to_nchw - * Disables default translation from NHWC to NCHW - * By default MO converts TensorFlow default NHWC to OpenVino default NCHW - * So when MR was created with this option layout will be NHWC - * - * @param layer Pointer to ConvolutionLayer - */ -void GNAGraphCompiler::ConvolutionPrimitive(InferenceEngine::CNNLayerPtr layer) { - auto& convolution = dynamic_cast(*layer.get()); - IE_ASSERT(!layer->insData.empty()); - IE_ASSERT(!layer->outData.empty()); - - const auto inputs = layer->insData.front().lock(); - const auto outputs = layer->outData.front(); - assertConvolutionLayoutProper(inputs); - - const auto in_batch = GetDataDimSizeNHWC(inputs, InferenceEngine::DataDimName::N); - const auto in_channels = GetDataDimSizeNHWC(inputs, InferenceEngine::DataDimName::C); - auto in_height = GetDataDimSizeNHWC(inputs, InferenceEngine::DataDimName::H); - auto in_width = GetDataDimSizeNHWC(inputs, InferenceEngine::DataDimName::W); - const auto out_batch = GetDataDimSizeNHWC(outputs, InferenceEngine::DataDimName::N); - const auto out_channels = GetDataDimSizeNHWC(outputs, InferenceEngine::DataDimName::C); - auto out_height = GetDataDimSizeNHWC(outputs, InferenceEngine::DataDimName::H); - auto out_width = GetDataDimSizeNHWC(outputs, InferenceEngine::DataDimName::W); - - if (inputs->getLayout() == InferenceEngine::Layout::CHW) { - // convolution is ngraph-3D here. Make some fixes to work with it as it's ngraph-4D - convolution._kernel_y = 1; - convolution._dilation_y = 1; - convolution._stride_y = 1; - - convolution._padding = property_vector_append(convolution._padding, 0); - convolution._pads_end = property_vector_append(convolution._pads_end, 0); - } - - if (in_height > 1 && in_width == 1 && !ShouldUseOnlyConv2DGnaIface()) { - std::swap(in_height, in_width); - std::swap(out_height, out_width); - std::swap(convolution._kernel_x, convolution._kernel_y); - std::swap(convolution._padding_x, convolution._padding_y); - std::swap(convolution._pads_end_x, convolution._pads_end_y); - std::swap(convolution._stride_x, convolution._stride_y); - std::swap(convolution._dilation_x, convolution._dilation_y); - } - - auto in_kernel_w = convolution._kernel_x; - auto in_kernel_h = convolution._kernel_y; - bool transpose_h_w = false; - - // Map 2d convolution to 1d if it's possible. - if (!ShouldUseOnlyConv2DGnaIface() && gna_convolution_layer::isMappableFrom2DTo1D(in_height, - in_width, - in_channels, - convolution._kernel_y, - convolution._kernel_x, - convolution._stride_y, - convolution._stride_x)) { - transpose_h_w = gna_convolution_layer::should_transpose_h_w(in_height, - convolution._kernel_y, - in_channels, - convolution._stride_y); - in_width *= in_height; - in_height = 1; - out_width *= out_height; - out_height = 1; - convolution._stride_x *= transpose_h_w ? (convolution._stride_y * convolution._kernel_y) - : (convolution._stride_y * convolution._kernel_x); - convolution._kernel_x *= convolution._kernel_y; - convolution._kernel_y = 1; - // since _kernel_y = 1 && in_height = 1 - // it will be finalized with finalizeConvolution1DPrimitive() - // unless some other exception thrown - } - - if (in_batch != 1 || out_batch != 1) { - THROW_GNA_LAYER_EXCEPTION(layer) << "with batch size not equals 1 is not supported"; - } - - if (convolution._kernel_x > in_width * in_height) { - THROW_GNA_LAYER_EXCEPTION(layer) << "Kernel dimensions X (" << convolution._kernel_x << ")" - << " is bigger than total input dimensions WxH (" << in_width << "x" - << in_height << ")"; - } - - if (out_channels != convolution._out_depth) { - THROW_GNA_LAYER_EXCEPTION(layer) << "Output channels do not equal output depth. " << out_channels << " vs " - << convolution._out_depth; - } - - if (dnn->new_num_conv_columns) { - dnn->new_num_conv_columns = 0; - } - - if (ShouldUseOnlyConv2DGnaIface() || - gna_convolution_layer::is3DInputOr2DKernel(in_height, - in_width, - in_channels, - convolution._kernel_y, - convolution._kernel_x) || - in_height != 1) { - // TensorFlow default layout is NHWC - // OpenVino Default layout is NCHW - // GNA Convolution input is NHCW (old) or NHWC (new) - // When layer layout is in NHWC it means that is was created by PassManager - return finalizeConvolution2DPrimitive(layer, - in_batch, - in_channels, - in_height, - in_width, - out_batch, - out_channels, - out_height, - out_width); - } - finalizeConvolution1DPrimitive(layer, - in_batch, - in_channels, - in_width, - out_batch, - out_channels, - out_width, - in_kernel_w, - in_kernel_h, - transpose_h_w); -} - -void GNAGraphCompiler::finalizeConvolution1DPrimitive(InferenceEngine::CNNLayerPtr layer, - uint32_t in_batch, - uint32_t in_channels, - uint32_t in_width, - uint32_t out_batch, - uint32_t out_channels, - uint32_t out_width, - uint32_t in_kernel_w, - uint32_t in_kernel_h, - bool transpose_h_w) { - auto& convolution = dynamic_cast(*layer.get()); - printConvolutionLayer(convolution); - - const auto inputs = convolution.insData.front().lock(); - const auto outputs = convolution.outData.front(); - - if (layer->GetParamAsString("auto_pad", "explicit") != "valid" && - (convolution._padding[0] != 0 || convolution._padding[0] != 0 || convolution._pads_end[0] != 0 || - convolution._pads_end[1] != 0)) { - THROW_GNA_LAYER_EXCEPTION(&convolution) << "Padding isn't supported by GNA"; - } - - std::size_t calculated_out_width = - (in_width - convolution._kernel_x + 2 * convolution._padding_x) / convolution._stride_x + 1; - if (out_width != calculated_out_width) { - THROW_GNA_LAYER_EXCEPTION(&convolution) - << "Invalid output configuration. " << calculated_out_width << " != " << out_width; - } - - IE_ASSERT(convolution._kernel_y == 1); - uint32_t total_conv_kernel_size = convolution._kernel_x * convolution._out_depth * in_channels; - const uint32_t single_conv_kernel_size = convolution._kernel_x * in_channels; - auto actual_kernel_size = details::product(convolution._weights->getTensorDesc().getDims()); - if (total_conv_kernel_size != actual_kernel_size) { - THROW_GNA_LAYER_EXCEPTION(&convolution) - << "Weights size does not equal kernel size " << actual_kernel_size << " vs " << total_conv_kernel_size; - } - - // GNA HW Convolution 1D layer natively supports single channel input and filter - // to use it for multiple channels input and filter - // the convolution stride must be multiplied accordingly - auto effectiveStride = in_channels * convolution._stride_x; - - if (convolution._stride_y == 1 && in_width == 1 && convolution._stride_x != 1) { - // TODO: investigate whether this condition is needed at all - // seams that if in_width == 1, then convolution._stride_x == 1 as well - THROW_GNA_LAYER_EXCEPTION(&convolution) - << "Convolution 1D Layer has horizontal stride != 1 despite input width == 1\n"; - } - - // padding of convolution kernel to be multiply of 8 - // additionally have to pad filter for stride > filter since - // GNA HW supports CNN1D with convolution stride not greater than filter length - const auto num_filter_coefficients = ALIGN(std::max(single_conv_kernel_size, effectiveStride), 8); - const auto num_conv_kernel_padding = num_filter_coefficients - single_conv_kernel_size; - if (num_conv_kernel_padding == 0) { - log::debug() << LAYER_NAME(&convolution) << "Kernel is aligned \n"; - } else { - log::debug() << LAYER_NAME(&convolution) << "Kernel padding is " << num_conv_kernel_padding << "\n"; - } - - // have to pad input to let last kernel meet its corresponding input - const auto num_inputs = in_width * in_channels; - - uint32_t num_input_padding = ALIGN(num_inputs, 8) - num_inputs; - uint32_t num_columns_in = num_inputs + num_input_padding; - - const uint32_t num_filters = convolution._out_depth; - uint32_t num_columns_out = (((num_inputs - num_filter_coefficients) / effectiveStride) + 1) * num_filters; - uint32_t num_columns_out_unpadded = (((num_inputs - single_conv_kernel_size) / effectiveStride) + 1) * num_filters; - - uint32_t original_input_padding = num_input_padding; - uint32_t additional_padding = 0; - - // if kernel padding to multiple of 8 will cause missed outputs, need to pad further - while (num_columns_out < out_batch * out_channels * out_width) { - num_input_padding = original_input_padding + additional_padding; - num_columns_in = num_inputs + num_input_padding; - num_columns_out = - (((num_inputs + num_input_padding - num_filter_coefficients) / effectiveStride) + 1) * num_filters; - dnn->new_num_conv_columns = num_columns_out; - additional_padding += 8; - } - - if (num_input_padding == 0) { - log::debug() << LAYER_NAME(&convolution) << "Inputs are aligned \n"; - } else { - log::debug() << LAYER_NAME(&convolution) << "Inputs padding is " << num_input_padding << "\n"; - } - - if (num_columns_out_unpadded != out_batch * out_channels * out_width) { - THROW_GNA_LAYER_EXCEPTION(&convolution) - << "Number of output columns does not equal output tensor size " << num_columns_out_unpadded << " vs " - << out_batch * out_channels * out_width; - } - - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - void* ptr_weights = nullptr; - void* ptr_biases = nullptr; - - // TODO: questionable why for biases that are not in IR we inventing precision - auto biasPrecision = - convolution._biases ? convolution._biases->getTensorDesc().getPrecision() : outputs->getPrecision(); - - uint32_t num_bytes_per_input = static_cast(inputs->getPrecision().size()); - uint32_t num_bytes_per_output = static_cast(outputs->getPrecision().size()); - uint32_t num_bytes_per_weight = static_cast(convolution._weights->getTensorDesc().getPrecision().size()); - uint32_t num_bytes_per_bias = static_cast(biasPrecision.size()); - - float weight_scale_factor = GetScaleFactor(layer, QuantizedDataType::weights); - float output_scale_factor = GetScaleFactor(layer, QuantizedDataType::output); - - auto& currentComponent = dnnComponents.addComponent(convolution.name, "convolution"); - dnn->InitConvolutional1DComponent(currentComponent, - num_columns_in, - num_columns_out, - num_bytes_per_input, - num_bytes_per_output, - num_bytes_per_weight, - num_bytes_per_bias, - num_filters, - num_filter_coefficients, - effectiveStride, - weight_scale_factor, - output_scale_factor, - ptr_inputs, - ptr_outputs, - ptr_weights, - ptr_biases); - - // Keep both variants of kaldi models working: - // Old one has layout which is different from NHWC - // New one has layout NHWC, but it is mapped from 2d by H - if (inputs->getLayout() == InferenceEngine::Layout::NHWC && !transpose_h_w) { - currentComponent.orientation_in = kDnnInterleavedOrientation; - currentComponent.orientation_out = kDnnInterleavedOrientation; - } - - size_t num_data_bytes_out = num_columns_out * outputs->getPrecision().size(); - size_t num_data_bytes_in = (num_inputs + num_input_padding) * inputs->getPrecision().size(); - - auto connectedInputLayer = connectInput(layer, ptr_inputs, num_data_bytes_in).input; - // Skip FakeQuantize and ScaleShift between Convolution and Input - if (LayerInfo(connectedInputLayer).isFakeQuantize()) { - connectedInputLayer = CNNNetPrevLayerSkipCertain(connectedInputLayer, 0, [](CNNLayerPtr l) { - return LayerInfo(l).isScaleShift(); - }); - } - - connectOutput(layer, ptr_outputs, num_data_bytes_out); - - if (num_conv_kernel_padding == 0) { - gnamem->getQueue(REGION_RO)->push_local_ptr(layer, - ptr_weights, - convolution._weights->cbuffer(), - convolution._weights->byteSize()); - } else { - auto paddedWeights = num_filter_coefficients * num_filters; - auto paddedWeightsSize = paddedWeights * convolution.precision.size(); - std::string layerName = (layer)->type + " layer : \"" + (layer)->name + "\" "; - const auto cpSize = convolution.precision.size(); - - auto initializer = [paddedWeightsSize, - layerName, - num_conv_kernel_padding, - cpSize, - convolution, - num_filters, - single_conv_kernel_size](void* data, std::size_t size) { - if (paddedWeightsSize > size) { - THROW_GNA_EXCEPTION << layerName << "size is less than paddedWeightsSize"; - } - std::size_t offset = 0; - std::vector padding_zeros(num_conv_kernel_padding * cpSize, 0); - uint8_t* dstPtr = reinterpret_cast(data); - for (uint32_t i = 0; i < num_filters; i++) { - ie_memcpy(dstPtr + offset, - size - offset, - convolution._weights->cbuffer().as() + single_conv_kernel_size * i * cpSize, - single_conv_kernel_size * cpSize); - offset += single_conv_kernel_size * cpSize; - ie_memcpy(dstPtr + offset, size - offset, &padding_zeros[0], padding_zeros.size()); - offset += padding_zeros.size(); - } - }; - - gnamem->getQueue(REGION_RO)->push_initializer(layer, ptr_weights, paddedWeightsSize, initializer); - } - - if (convolution._biases) { - gnamem->getQueue(REGION_RO)->push_ptr(layer, - ptr_biases, - convolution._biases->cbuffer().as(), - convolution._biases->byteSize()); - } else { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0.0f, out_channels); - } -} - -void GNAGraphCompiler::finalizeConvolution2DPrimitive(InferenceEngine::CNNLayerPtr layer, - uint32_t in_batch, - uint32_t in_channels, - uint32_t in_height, - uint32_t in_width, - uint32_t out_batch, - uint32_t out_channels, - uint32_t out_height, - uint32_t out_width) { - auto& convolution = dynamic_cast(*layer.get()); - - // TODO add function - // printConvolution2DLayer(convolution); - - if (!m_cnn2d_validator) { - THROW_GNA_EXCEPTION << "No Cnn2D validator found for layer " << convolution.name; - } - - m_cnn2d_validator->ValidateInputPadding(convolution.name, - convolution._padding_y, - convolution._pads_end_y, - convolution._padding_x, - convolution._pads_end_x, - convolution._kernel_y, - convolution._kernel_x); - - // Check if kernel width needs to be extended to stride width. - const auto effective_kernel_width = std::max(convolution._kernel_x, convolution._stride_x); - - // Check if convolution input needs to be extended to accommodate for new stride - const auto temp_effective_input_width = count_conv2D_input_width_for_expected_output_width(out_width, - effective_kernel_width, - convolution._stride_x, - convolution._padding_x); - - const auto effective_input_width = std::max(in_width, temp_effective_input_width); - - const auto inputs = convolution.insData.front().lock(); - const auto outputs = convolution.outData.front(); - - // have to pad input to let last kernel meets it's corresponding input - const auto num_inputs = in_batch * effective_input_width * in_height * in_channels; - - uint32_t num_input_padding = ALIGN(num_inputs, Limitations::kNoOfInputsDivisor) - num_inputs; - - const uint32_t filter_n = convolution._out_depth; - - // if kernel padding to multiple of 8 will cause missed outputs, need to pad further - if (num_input_padding == 0) { - log::debug() << LAYER_NAME(&convolution) << "Inputs are aligned \n"; - } else { - log::debug() << LAYER_NAME(&convolution) << "Inputs padding is " << num_input_padding << "\n"; - } - - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - void* ptr_weights = nullptr; - void* ptr_biases = nullptr; - - // TODO: questionable why for biases that are not in IR we inventing precision - auto biasPrecision = - convolution._biases ? convolution._biases->getTensorDesc().getPrecision() : outputs->getPrecision(); - - const auto inputPrec = OvGnaTypeIntFromBytes(inputs->getPrecision().size()); - const auto outputPrec = OvGnaTypeIntFromBytes(outputs->getPrecision().size()); - const auto weightPrec = OvGnaTypeIntFromBytes(convolution._weights->getTensorDesc().getPrecision().size()); - const auto biasPrec = OvGnaTypeIntFromBytes(biasPrecision.size()); - - ValidateCnn2D(layer->name, - in_height, - effective_input_width, - in_channels, - convolution._kernel_y, - effective_kernel_width, - filter_n, - convolution._stride_y, - convolution._stride_x, - convolution._dilation_y, - convolution._dilation_x, - inputPrec); - - float weight_scale_factor = GetScaleFactor(layer, QuantizedDataType::weights); - float output_scale_factor = GetScaleFactor(layer, QuantizedDataType::output); - - auto& currentComponent = dnnComponents.addComponent(convolution.name, "convolution"); - dnn->InitConvolutional2DComponent( - currentComponent, - {{in_batch, in_height, effective_input_width, in_channels}, inputPrec, {}}, // NHWC for GNA - {{out_batch, out_height, out_width, out_channels}, outputPrec, {}}, - {{filter_n, convolution._kernel_y, effective_kernel_width, in_channels}, weightPrec, {}}, - {{filter_n}, biasPrec, {}}, - {convolution._stride_y, convolution._stride_x}, - {convolution._padding_y, convolution._padding_x}, - weight_scale_factor, - output_scale_factor, - ptr_inputs, - ptr_outputs, - ptr_weights, - ptr_biases); - currentComponent.num_bytes_per_input = static_cast(inputs->getPrecision().size()); - currentComponent.num_bytes_per_output = static_cast(outputs->getPrecision().size()); - - if (inputs->getLayout() == InferenceEngine::Layout::NHWC) { - currentComponent.orientation_in = kDnnInterleavedOrientation; - currentComponent.orientation_out = kDnnInterleavedOrientation; - } - - size_t num_data_bytes_out = InferenceEngine::details::product(begin(outputs->getDims()), end(outputs->getDims())) * - outputs->getPrecision().size(); - - size_t num_data_bytes_in = (num_inputs + num_input_padding) * inputs->getPrecision().size(); - - auto connectedInputLayer = connectInput(layer, ptr_inputs, num_data_bytes_in).input; - - connectOutput(layer, ptr_outputs, num_data_bytes_out); - - const auto convolution_precision = convolution.precision.size(); - const auto kernelHW = convolution._kernel_y * convolution._kernel_x; - const auto single_kernel_size = in_channels * kernelHW * convolution_precision; - - const auto effective_kernel_h_w = convolution._kernel_y * effective_kernel_width; - const auto effective_single_kernel_size = in_channels * effective_kernel_h_w * convolution_precision; - - std::vector transposed_weights; - - // Kernel is extended only for 1D case which allows to add 0-s at the end of the kernel. - const auto kernel_pad = - ALIGN(effective_single_kernel_size, Limitations::kConvEachKernelByteAlignment) - effective_single_kernel_size; - for (uint32_t k = 0; k < convolution._out_depth; k++) { - uint8_t* ptr_filt_current = convolution._weights->cbuffer().as() + k * single_kernel_size; - auto transposed_part = copy_matrix(ptr_filt_current, convolution.precision.size(), in_channels, kernelHW); - transposed_weights.insert(transposed_weights.end(), transposed_part.begin(), transposed_part.end()); - transposed_weights.resize(transposed_weights.size() + effective_single_kernel_size - single_kernel_size + - kernel_pad); - } - - gnamem->getQueue(REGION_RO)->push_local_ptr(layer, - ptr_weights, - transposed_weights.data(), - transposed_weights.size()); - - if (convolution._biases) { - gnamem->getQueue(REGION_RO)->push_ptr(layer, - ptr_biases, - convolution._biases->cbuffer().as(), - convolution._biases->byteSize()); - } else { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0.0f, out_channels); - } -} - -void GNAGraphCompiler::PowerPrimitive(InferenceEngine::CNNLayerPtr layer) { - auto& power = dynamic_cast(*layer.get()); - if (power.power < 0.0f || power.power > 2.8f) { - IE_THROW() << "[GNA plugin] unsupported power factor, expected be in <0, 2.8> range but was " << power.power; - } - - auto input = layer->insData[0].lock(); - - auto outputs = *layer->outData.begin(); - auto reshaped_dims = Get2DReshapedData(input, Limitations::get_min_batch_to_fit_in_buffer(input), 8)->getDims(); - const uint32_t num_of_inputs_divisor = gna_config.gnaFlags.input_low_precision - ? Limitations::kNoOfInputsLowPrecDivisor - : Limitations::kNoOfInputsDivisor; - uint32_t num_rows_in = static_cast(reshaped_dims[1]); - uint32_t num_columns_in = static_cast(reshaped_dims[0]); - uint32_t num_rows_out = num_rows_in; - uint32_t num_columns_out = num_columns_in; - uint32_t num_padding = ALIGN(num_rows_in, num_of_inputs_divisor) - num_rows_in; - - size_t num_data_bytes_out = num_columns_out * (num_rows_out + num_padding) * outputs->getPrecision().size(); - size_t num_data_bytes_in = num_columns_in * (num_rows_in + num_padding) * input->getPrecision().size(); - - if (power.power == 1.0f) { - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - void* ptr_weights = nullptr; - void* ptr_biases = nullptr; - - auto& currentComponent = dnnComponents.addComponent(layer->name, "power"); - - auto quantized = InferenceEngine::getInjectedData(layer); - IE_ASSERT(gna_config.gnaFlags.sw_fp32 ? (quantized == nullptr) : (quantized != nullptr)); - dnn->InitAffineComponent(currentComponent, - num_rows_in + num_padding, - num_columns_in, - num_rows_out + num_padding, - static_cast(input->getPrecision().size()), - static_cast(outputs->getPrecision().size()), - // TODO: only fp32 and Int16 tested - quantized == nullptr ? static_cast(input->getPrecision().size()) - : (gna_config.gnaFlags.input_low_precision ? 1 : 2), - quantized == nullptr ? static_cast(input->getPrecision().size()) - : (gna_config.gnaFlags.input_low_precision ? 1 : 4), - quantized == nullptr ? 1 : quantized->_weights_quant.GetScale(), - quantized == nullptr ? 1 : quantized->_dst_quant.GetScale(), - ptr_inputs, - ptr_outputs, - ptr_weights, - ptr_biases, - true); - connectOutput(layer, ptr_outputs, num_data_bytes_out); - connectInput(layer, ptr_inputs, num_data_bytes_in, 0, 0); - - if (gna_config.gnaFlags.sw_fp32) { - IE_ASSERT(quantized == nullptr); - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_weights, power.scale, num_rows_out + num_padding); - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, power.offset, num_rows_out + num_padding); - } else { - IE_ASSERT(quantized != nullptr); - if (!gna_config.gnaFlags.input_low_precision) { - auto quantizedScale = FloatToInt16( - std::min(quantized->_weights_quant.GetScale() * power.scale, static_cast(INT16_MAX))); - auto quantizedOffset = FloatToInt32( - std::min(quantized->_dst_quant.GetScale() * power.offset, static_cast(INT32_MAX))); - gnamem->getQueue(REGION_RO)->push_value(layer, - ptr_weights, - quantizedScale, - num_rows_out + num_padding); - gnamem->getQueue(REGION_RO)->push_value(layer, - ptr_biases, - quantizedOffset, - num_rows_out + num_padding); - } else { - auto quantizedScale = FloatToInt8( - std::min(quantized->_weights_quant.GetScale() * power.scale, static_cast(INT8_MAX))); - auto quantizedOffset = FloatToInt8( - std::min(quantized->_dst_quant.GetScale() * power.offset, static_cast(INT8_MAX))); - gnamem->getQueue(REGION_RO)->push_value(layer, - ptr_weights, - quantizedScale, - num_rows_out + num_padding); - gnamem->getQueue(REGION_RO)->push_value(layer, - ptr_biases, - quantizedOffset, - num_rows_out + num_padding); - } - } - } else { - // use PWL to calculate power - std::vector ptr_pwl_segments; - - auto orientation = kDnnInterleavedOrientation; - - auto activation_type = DnnActivation::fromType(kActPow); - activation_type.fqParams.set = false; - activation_type.srcFQParams.set = false; - activation_type.args.pow.exponent = power.power; - activation_type.args.pow.scale = power.scale; - activation_type.args.pow.offset = power.offset; - - auto& pwlComponent = dnnComponents.addComponent(layer->name, "power"); - - gna_pwl_segment_t* ptr_pwl_segments_target = nullptr; - - float output_pwl_scale_factor = GetScaleFactor(layer, QuantizedDataType::output); - float input_pwl_scale_factor = GetScaleFactor(layer, QuantizedDataType::input); - - if (!gna_config.gnaFlags.sw_fp32 && gna_config.gnaFlags.uniformPwlDesign) { - uint32_t num_segments = POW_NUM_SEGMENTS; - if (activation_type.args.pow.exponent == 0.0f) { - num_segments = 3; - } - ptr_pwl_segments.resize(num_segments); - - PwlDesign(activation_type, - &*ptr_pwl_segments.begin(), - static_cast(ptr_pwl_segments.size()), - input_pwl_scale_factor, - output_pwl_scale_factor, - gna_config.gnaFlags.input_low_precision); - } - - ptr_pwl_segments_target = reinterpret_cast(&ptr_pwl_segments_target); - - void* ptr_pwl_input = nullptr; - void* ptr_pwl_outputs = nullptr; - dnn->InitPiecewiseLinearComponent(pwlComponent, - activation_type, - orientation, - num_rows_in + num_padding, - num_columns_in, - static_cast(input->getPrecision().size()), - static_cast(outputs->getPrecision().size()), - static_cast(ptr_pwl_segments.size()), - output_pwl_scale_factor, - output_pwl_scale_factor, - ptr_pwl_input, - ptr_pwl_outputs, - ptr_pwl_segments_target); - connectOutput(layer, ptr_pwl_outputs, num_data_bytes_out); - connectInput(layer, ptr_pwl_input, num_data_bytes_in, 0, 0); - - if (ptr_pwl_segments_target != nullptr) { - gnamem->getQueue(REGION_RO)->push_local_ptr(layer, - ptr_pwl_segments_target, - &ptr_pwl_segments.front(), - ptr_pwl_segments.size() * sizeof(gna_pwl_segment_t)); - } - } -} - -void GNAGraphCompiler::PoolingPrimitive(InferenceEngine::CNNLayerPtr layer) { - auto& pooling = dynamic_cast(*layer.get()); - - IE_ASSERT(!layer->insData.empty()); - IE_ASSERT(!layer->outData.empty()); - printPoolingLayer(pooling); - - auto inputs = layer->insData.begin()->lock(); - auto outputs = *layer->outData.begin(); - - uint32_t w_dim_in = GetDataDimSizeNHWC(inputs, InferenceEngine::DataDimName::W); - uint32_t h_dim_in = GetDataDimSizeNHWC(inputs, InferenceEngine::DataDimName::H); - const uint32_t c_dim_in = GetDataDimSizeNHWC(inputs, InferenceEngine::DataDimName::C); - - uint32_t w_dim_out = GetDataDimSizeNHWC(outputs, InferenceEngine::DataDimName::W); - uint32_t h_dim_out = GetDataDimSizeNHWC(outputs, InferenceEngine::DataDimName::H); - const uint32_t c_dim_out = GetDataDimSizeNHWC(outputs, InferenceEngine::DataDimName::C); - - if (inputs->getLayout() == InferenceEngine::Layout::CHW) { - // Pooling is ngraph-3D here. Make some fixes to work with it as it's ngraph-4D - pooling._kernel = property_vector_append(pooling._kernel, 1); - pooling._stride = property_vector_append(pooling._stride, 1); - } - - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - - bool is2DPooling = false; - if (dnnComponents.components.size() > 0) { - const auto last = dnnComponents.components.back(); - if (last.dnnComponent.operation == kDnnConvolutional2dOp) { - is2DPooling = true; - } else if (last.dnnComponent.operation == kDnnPiecewiselinearOp && dnnComponents.components.size() > 1) { - const auto& prev2 = *std::prev(dnnComponents.components.cend(), 2); - is2DPooling = prev2.dnnComponent.operation == kDnnConvolutional2dOp; - } - } - - if (w_dim_in == 1 && !ShouldUseOnlyConv2DGnaIface()) { // swap dimensions if needed to support swapped 1D case - std::swap(h_dim_in, w_dim_in); - std::swap(h_dim_out, w_dim_out); - std::swap(pooling._kernel[X_AXIS], pooling._kernel[Y_AXIS]); - std::swap(pooling._stride[X_AXIS], pooling._stride[Y_AXIS]); - } - - if (is2DPooling) { - ValidatePooling2D(layer->name, pooling._kernel_y, pooling._kernel_x, pooling._stride_y, pooling._stride_x); - } - - auto& currentComponent = dnnComponents.addComponent(layer->name, "pooling"); - - switch (pooling._type) { - case PoolingLayer::MAX: - break; - // we are loosing precision here - case PoolingLayer::AVG: - default: - // TODO: convert to SUMM pooling - THROW_GNA_EXCEPTION << "Layer :" << layer->name << " not supported"; - } - - dnn->InitMaxpoolComponent(currentComponent, - {c_dim_in, h_dim_in, w_dim_in}, - {c_dim_out, h_dim_out, w_dim_out}, - static_cast(inputs->getPrecision().size()), - static_cast(outputs->getPrecision().size()), - {pooling._kernel[X_AXIS], pooling._kernel[Y_AXIS]}, - {pooling._stride[X_AXIS], pooling._stride[Y_AXIS]}, - GetScaleFactor(layer, QuantizedDataType::output), - ptr_inputs, - ptr_outputs); - size_t num_data_bytes_out = InferenceEngine::details::product(begin(outputs->getDims()), end(outputs->getDims())); - - // Need to reserve more memory otherwise the compiled model would not be - // backward compatible with GNA 2.0 - // GNA 2.0 produces more outputs from 1D pooling than later GNA generations (including GNA 3.0) - // When the model is compiled for some newer GNA generation (than GNA 2.0) - // but it does not use any specific new GNA features it should be correct to import and run using previous GNA HW - if (!is2DPooling) { - const auto hLegacy = gna_convolution_layer::outputFromPoolingLegacy(h_dim_in, pooling._stride[X_AXIS]); - const auto wLegacy = gna_convolution_layer::outputFromPoolingLegacy(w_dim_in, pooling._stride[Y_AXIS]); - if (num_data_bytes_out < hLegacy * wLegacy * c_dim_out) { - num_data_bytes_out = hLegacy * wLegacy * c_dim_out; - } - } - - num_data_bytes_out *= outputs->getPrecision().size(); - const auto hw_in = h_dim_in * w_dim_in; - - // TODO: Is this really needed?, find out why - uint32_t num_padding = ALIGN(hw_in, 8) - hw_in; - size_t num_data_bytes_in = c_dim_in * (hw_in + num_padding) * inputs->getPrecision().size(); - - if (dnn->new_num_conv_columns) { - uint32_t num_rows = 1; - uint32_t num_columns = c_dim_in * w_dim_in + (ALIGN(c_dim_in * w_dim_in, 8) - c_dim_in * w_dim_in); - if (dnn->new_num_conv_columns % num_columns == 0) { - num_rows = dnn->new_num_conv_columns / num_columns; - } else { - num_columns = dnn->new_num_conv_columns; - } - dnn->new_num_conv_columns = 0; - num_data_bytes_in = num_rows * num_columns * inputs->getPrecision().size(); - } - - auto fused_to_layer = connectInput(layer, ptr_inputs, num_data_bytes_in); - // Pooling will be fused with the previous layer and we need to use it's order id - layer->userValue.v_int = fused_to_layer.input->userValue.v_int; - connectOutput(layer, ptr_outputs, num_data_bytes_out); -} - -void GNAGraphCompiler::CopyPrimitive(InferenceEngine::CNNLayerPtr layer) { - IE_ASSERT(!layer->insData.empty()); - IE_ASSERT(!layer->outData.empty()); - auto inputs = layer->insData.begin()->lock(); - auto outputs = *layer->outData.begin(); - - auto reshaped_dims = Get2DReshapedData(inputs, Limitations::get_min_batch_to_fit_in_buffer(inputs), 8)->getDims(); - uint32_t num_rows_in = static_cast(reshaped_dims[1]); - uint32_t num_columns_in = static_cast(reshaped_dims[0]); - uint32_t num_rows_out = num_rows_in; - uint32_t num_columns_out = num_columns_in; - uint32_t num_padding_out = ALIGN(num_rows_out, 8) - num_rows_out; - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - auto orientation = kDnnInterleavedOrientation; - - auto& currentComponent = dnnComponents.addComponent(layer->name, layer->type); - - dnn->InitCopyComponent(currentComponent, - orientation, - ALIGN(num_rows_in, 8), - num_columns_in, - ALIGN(num_rows_out, 8), - num_columns_out, - static_cast(inputs->getPrecision().size()), - static_cast(outputs->getPrecision().size()), - GetScaleFactor(layer, QuantizedDataType::output), - num_rows_out + num_padding_out, - num_columns_out, - ptr_inputs, - ptr_outputs); - size_t num_data_bytes_out = - ALIGN(InferenceEngine::details::product(begin(outputs->getDims()), end(outputs->getDims())), 8) * - outputs->getPrecision().size(); - size_t num_data_bytes_in = num_columns_in * ALIGN(num_rows_in, 8) * inputs->getPrecision().size(); - - connectInput(layer, ptr_inputs, num_data_bytes_in); - connectOutput(layer, ptr_outputs, num_data_bytes_out); -} - -void GNAGraphCompiler::ConcatPrimitive(InferenceEngine::CNNLayerPtr layer) { - auto concatLayer = dynamic_cast(layer.get()); - if (concatLayer == nullptr) { - return; - } - if (concatLayer->insData.size() < 2) { - THROW_GNA_EXCEPTION << "Concat layer has unsupported number of incoming layers."; - } - - for (std::size_t layerIndex = 0; layerIndex < concatLayer->insData.size(); layerIndex++) { - auto input = concatLayer->insData[layerIndex].lock(); - if (!input) { - THROW_GNA_EXCEPTION << "Input layer " << layerIndex << " for concat is unexpectedly absent"; - } - } - - std::size_t layerPrecisionSize = concatLayer->insData[0].lock()->getPrecision().size(); - for (std::size_t layerIndex = 0; layerIndex < concatLayer->insData.size(); layerIndex++) { - auto currentSize = concatLayer->insData[layerIndex].lock()->getPrecision().size(); - if (layerPrecisionSize != currentSize) { - THROW_GNA_EXCEPTION << "Different precision for Concat Layer '" << concatLayer->name << "' input layers." - << "input 0 precision is '" << concatLayer->insData[0].lock()->getPrecision().name() - << "' but input " << layerIndex << " precision is '" - << concatLayer->insData[layerIndex].lock()->getPrecision().name() << "'"; - } - } - - // Concat axis validation - if (!Limitations::validate_conv_concat_axis(concatLayer)) { - std::ostringstream in_dims_oss; - auto in_dims = concatLayer->insData[0].lock()->getDims(); - std::copy(in_dims.begin(), in_dims.end(), std::ostream_iterator(in_dims_oss, ",")); - THROW_GNA_EXCEPTION << "Topology with layer: " + layer->name + ", type: " + layer->type + - ", and concatenation axis(" + std::to_string(concatLayer->_axis) + - ") for input dimensions(" + in_dims_oss.str() + ") not supported\n"; - } - - auto& concatLayerInfo = concat_connection.find(concatLayer->name)->second; - std::function find_cascaded_concat_recursively = - [&find_cascaded_concat_recursively](InferenceEngine::CNNLayerPtr concat_candidate) { - if (LayerInfo(concat_candidate).isConcat()) { - return concat_candidate; - } - - if (!LayerInfo(concat_candidate).isNonFunctional()) { - return InferenceEngine::CNNLayerPtr(nullptr); - } - - for (auto&& child_layer : getInputTo(concat_candidate->outData.front())) { - auto child_concat = find_cascaded_concat_recursively(child_layer.second); - if (child_concat) - return child_concat; - } - - return InferenceEngine::CNNLayerPtr(nullptr); - }; - - for (auto&& outLayer : getInputTo(concatLayer->outData.front())) { - auto concatCandidate = find_cascaded_concat_recursively(outLayer.second); - if (!concatCandidate) - continue; - log::debug() << "Cascaded concat connection found from: " << layer->name << ", to: " << concatCandidate->name - << std::endl; - connectOutput(layer, &concatLayerInfo.gna_ptr, concatLayerInfo.reserved_size); - } - - size_t idx = 0; - for (auto&& inputLayer : concatLayerInfo.concatInputLayers) { - auto concatLayerInput = concat_connection.find(concatLayer->name)->second.getConcat(); - CNNLayerPtr concatParent; - int it = 0; - - for (; it != static_cast(concatLayerInput->insData.size()); it++) { - concatParent = CNNNetPrevLayerSkipCertain(concatLayerInput, it, [](CNNLayerPtr l) { - return LayerInfo(l).isNonFunctional(); - }); - if (concatParent->name.find(inputLayer.name) != std::string::npos) { - break; - } - } - IE_ASSERT(it != static_cast(concatLayerInput->insData.size())); - auto layerInfo = LayerInfo(concatParent); - // auto layerInfo = LayerInfo(getCreatorLayer(concatLayerInput->insData[it].lock()).lock()); - if (layerInfo.isInput()) { - connectInput(layer, - &concatLayerInfo.gna_ptr, - inputLayer.tensorSize, - static_cast(inputLayer.offset), - static_cast(idx), - false); - concatLayerInfo.input_allocated = true; - } else if (layerInfo.isMemory()) { - connectInput(layer, - &concatLayerInfo.gna_ptr, - concatLayerInfo.reserved_size, - static_cast(inputLayer.offset), - static_cast(idx), - false); - concatLayerInfo.input_allocated = true; - } - ++idx; - } -} - -void GNAGraphCompiler::CropPrimitive(InferenceEngine::CNNLayerPtr layer) { - auto cropLayer = dynamic_cast(layer.get()); - - if (cropLayer == nullptr) { - return; - } - - IE_ASSERT(!layer->insData.empty()); - auto inputs = layer->insData.begin()->lock(); - - const auto crop_params = GetCropParams(cropLayer); - size_t cropOffsetBytes = crop_params.start_offset * cropLayer->precision.size(); - size_t cropOutputSizeBytes = crop_params.crop_size * cropLayer->precision.size(); - - if (!LayerInfo(cropLayer).isCropAffined()) { - // leave crop as it is - GNACropLayer cropLayerInfoItem(layer); - std::string& id = layer->name; - crop_connection.emplace(id, cropLayerInfoItem); - auto cropLayerInfo = crop_connection.find(cropLayer->name); - - if (cropLayerInfo == crop_connection.end()) { - THROW_GNA_EXCEPTION << "Item is not in the storage but it was added recently...\n"; - } - - // calculate index idx for connectInput last parameter - connectInput(layer, - &cropLayerInfo->second.gna_ptr, - static_cast(cropOutputSizeBytes + cropOffsetBytes), - static_cast(cropOffsetBytes), - 0); - - // cases for certain output layers - for (auto&& outLayer : getInputTo(layer->outData.front())) { - auto& nextLayer = outLayer.second; - if (LayerInfo(nextLayer).isConcat()) { - connectOutput(layer, &cropLayerInfo->second.gna_ptr, cropOutputSizeBytes); - } - } - } else { - log::debug() << "Crop " << layer->name << " is being replaced by Affine layer...\n"; - IE_ASSERT(!layer->outData.empty()); - auto outputs = *layer->outData.begin(); - - // TODO: add unit tests for 4d crops blobs - uint32_t num_rows_in = - static_cast(InferenceEngine::details::product(begin(inputs->getDims()), end(inputs->getDims()))); - uint32_t num_columns_in = 1; - - uint32_t num_rows_out = static_cast( - InferenceEngine::details::product(begin(outputs->getDims()), end(outputs->getDims()))); - const uint32_t num_of_inputs_divisor = gna_config.gnaFlags.input_low_precision - ? Limitations::kNoOfInputsLowPrecDivisor - : Limitations::kNoOfInputsDivisor; - uint32_t num_padding = ALIGN(num_rows_in, num_of_inputs_divisor) - num_rows_in; - - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - void* ptr_weights = nullptr; - void* ptr_biases = nullptr; - - auto& currentComponent = dnnComponents.addComponent(layer->name, "crop"); - - auto quantized = InferenceEngine::getInjectedData(layer); - dnn->InitAffineComponent(currentComponent, - num_rows_in + num_padding, - num_columns_in, - num_rows_out, - static_cast(inputs->getPrecision().size()), - static_cast(outputs->getPrecision().size()), - quantized == nullptr ? static_cast(inputs->getPrecision().size()) - : (gna_config.gnaFlags.input_low_precision ? 1 : 2), - gna_config.gnaFlags.input_low_precision ? 1 : 4, - GetScaleFactor(layer, QuantizedDataType::weights), - GetScaleFactor(layer, QuantizedDataType::output), - ptr_inputs, - ptr_outputs, - ptr_weights, - ptr_biases, - false); - size_t num_data_bytes_out = - InferenceEngine::details::product(begin(outputs->getDims()), end(outputs->getDims())) * 4; - - size_t num_data_bytes_in = - num_columns_in * ALIGN(num_rows_in, num_of_inputs_divisor) * inputs->getPrecision().size(); - - connectInput(layer, ptr_inputs, num_data_bytes_in, 0, 0); - connectOutput(layer, ptr_outputs, num_data_bytes_out); - - FillWeightOfAligningFilter(layer, ptr_weights, crop_params.start_offset, (quantized == nullptr) ? false : true); - - (quantized == nullptr) ? gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0.0f, num_rows_out) - : gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0, num_rows_out); - } -} - -void GNAGraphCompiler::SplitPrimitive(InferenceEngine::CNNLayerPtr layer) { - // Nothing to do -} - -void GNAGraphCompiler::SlicePrimitive(InferenceEngine::CNNLayerPtr layer) { - // Nothing to do -} - -void GNAGraphCompiler::EltwisePrimitive(InferenceEngine::CNNLayerPtr layer) { - auto& eltwise = dynamic_cast(*layer.get()); - auto quantized = InferenceEngine::getInjectedData(layer); - const uint32_t num_of_inputs_divisor = gna_config.gnaFlags.input_low_precision - ? Limitations::kNoOfInputsLowPrecDivisor - : Limitations::kNoOfInputsDivisor; - - // for eltwise sum/sub in 16-bit precision one input should be 4 bytes and one 2 bytes - detecting that below - // the names of variables are left for clarity although not always reflecting the real precision/size - auto inputs2Bytes = layer->insData[0].lock(); - auto inputs4Bytes = layer->insData[1].lock(); - auto nonFunctional = [](CNNLayerPtr ptr) { - return LayerInfo(ptr).isNonFunctional(); - }; - auto inputFunc2Bytes = CNNNetPrevLayerSkipCertain(layer, 0, nonFunctional)->outData[0]; - auto inputFunc4Bytes = CNNNetPrevLayerSkipCertain(layer, 1, nonFunctional)->outData[0]; - - int biasesLayerIdx = 1; - - if (quantized) { - switch (eltwise._operation) { - case InferenceEngine::EltwiseLayer::Sum: - case InferenceEngine::EltwiseLayer::Sub: { - if (gna_config.gnaFlags.input_low_precision == false) { - if (inputFunc4Bytes->getPrecision().size() != 4) { - std::swap(inputFunc4Bytes, inputFunc2Bytes); - std::swap(inputs4Bytes, inputs2Bytes); - biasesLayerIdx = 0; - } - GNA_LAYER_ASSERT(layer, inputFunc2Bytes->getPrecision().size() == 2); - GNA_LAYER_ASSERT(layer, inputFunc4Bytes->getPrecision().size() == 4); - } else { - // for low precision both inputs should be 1 bytes in size - GNA_LAYER_ASSERT(layer, inputFunc2Bytes->getPrecision().size() == 1); - GNA_LAYER_ASSERT(layer, inputFunc4Bytes->getPrecision().size() == 1); - } - break; - } - case InferenceEngine::EltwiseLayer::Prod: { - if (gna_config.gnaFlags.input_low_precision == false) { - // for mul both inputs should be 2 bytes precision - GNA_LAYER_ASSERT(layer, inputFunc2Bytes->getPrecision().size() == 2); - GNA_LAYER_ASSERT(layer, inputFunc4Bytes->getPrecision().size() == 2); - } else { - // for mul both inputs should be 1 byte precision - GNA_LAYER_ASSERT(layer, inputFunc2Bytes->getPrecision().size() == 1); - GNA_LAYER_ASSERT(layer, inputFunc4Bytes->getPrecision().size() == 1); - } - - break; - } - default: - THROW_GNA_EXCEPTION << "Unsupported eltwise operation for quantization: " << eltwise._operation; - } - } - - auto outputs = *layer->outData.begin(); - - auto in_4b_batch = InferenceEngine::GetDataDimByName(inputs4Bytes, InferenceEngine::DataDimName::N); - auto in_4b_channels = InferenceEngine::GetDataDimByName(inputs4Bytes, InferenceEngine::DataDimName::C); - auto in_4b_height = InferenceEngine::GetDataDimByName(inputs4Bytes, InferenceEngine::DataDimName::H); - auto in_4b_width = InferenceEngine::GetDataDimByName(inputs4Bytes, InferenceEngine::DataDimName::W); - auto in_4b_total_size = in_4b_batch * in_4b_channels * in_4b_height * in_4b_width; - - auto in_2b_batch = InferenceEngine::GetDataDimByName(inputs2Bytes, InferenceEngine::DataDimName::N); - auto in_2b_channels = InferenceEngine::GetDataDimByName(inputs2Bytes, InferenceEngine::DataDimName::C); - auto in_2b_height = InferenceEngine::GetDataDimByName(inputs2Bytes, InferenceEngine::DataDimName::H); - auto in_2b_width = InferenceEngine::GetDataDimByName(inputs2Bytes, InferenceEngine::DataDimName::W); - auto in_2b_total_size = in_2b_batch * in_2b_channels * in_2b_height * in_2b_width; - - if (in_2b_batch != in_4b_batch) { - THROW_GNA_LAYER_EXCEPTION(layer) << " Inputs with different batch sizes " << in_2b_batch << " and " - << in_4b_batch << " are not supported"; - } - - if (in_4b_total_size != in_2b_total_size) { - THROW_GNA_LAYER_EXCEPTION(layer) - << " Inputs size mismatch " - << "(note: For Multiply, Add and Subtract layers, auto broadcasting is only supported for constant inputs) " - << in_4b_total_size << " != " << in_2b_total_size; - } - - // If batch size > 1 the data is reshaped to one with batch size = 1 - uint32_t num_rows_in = in_4b_total_size; - uint32_t num_columns_in = 1; - uint32_t num_rows_out = num_rows_in; - uint32_t num_columns_out = num_columns_in; - uint32_t num_padding = ALIGN(num_rows_in, num_of_inputs_divisor) - num_rows_in; - - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - void* ptr_weights = nullptr; - void* ptr_biases = nullptr; - - auto& currentComponent = dnnComponents.addComponent(layer->name, "diagonal"); - dnn->InitAffineComponent(currentComponent, - num_rows_in + num_padding, - num_columns_in, - num_rows_out + num_padding, - static_cast(inputs2Bytes->getPrecision().size()), - static_cast(outputs->getPrecision().size()), - // TODO: only fp32 and Int16 tested - quantized == nullptr ? static_cast(inputs2Bytes->getPrecision().size()) - : (gna_config.gnaFlags.input_low_precision ? 1 : 2), - quantized == nullptr ? static_cast(inputs4Bytes->getPrecision().size()) - : (gna_config.gnaFlags.input_low_precision ? 1 : 4), - GetScaleFactor(layer, QuantizedDataType::weights), - GetScaleFactor(layer, QuantizedDataType::output), - ptr_inputs, - ptr_outputs, - ptr_weights, - ptr_biases, - true); - size_t num_data_bytes_out = num_columns_out * (num_rows_out + num_padding) * outputs->getPrecision().size(); - size_t num_data_bytes_in = num_columns_in * (num_rows_in + num_padding) * inputs2Bytes->getPrecision().size(); - - connectOutput(layer, ptr_outputs, num_data_bytes_out); - connectInput(layer, ptr_inputs, num_data_bytes_in, 0, 1 - biasesLayerIdx); - - switch (eltwise._operation) { - case EltwiseLayer::Sub: - if (quantized == nullptr) { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_weights, -1.0f, num_rows_out + num_padding); - } else { - auto scaledIdentity = -quantized->_weights_quant.GetScale(); - - if (gna_config.gnaFlags.input_low_precision == false) { - auto quantizedIdentity = FloatToInt16(std::min(scaledIdentity, static_cast(INT16_MAX))); - gnamem->getQueue(REGION_RO)->push_value(layer, - ptr_weights, - quantizedIdentity, - num_rows_out + num_padding); - } else { - auto quantizedIdentity = FloatToInt8(std::min(scaledIdentity, static_cast(INT8_MAX))); - - gnamem->getQueue(REGION_RO)->push_value(layer, - ptr_weights, - quantizedIdentity, - num_rows_out + num_padding); - } - } - connectInput(layer, ptr_biases, num_data_bytes_in, 0, biasesLayerIdx); - break; - case EltwiseLayer::Sum: - if (quantized == nullptr) { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_weights, 1.0f, num_rows_out + num_padding); - } else { - auto scaledIdentity = quantized->_weights_quant.GetScale(); - - if (gna_config.gnaFlags.input_low_precision == false) { - auto quantizedIdentity = FloatToInt16(std::min(scaledIdentity, static_cast(INT16_MAX))); - - gnamem->getQueue(REGION_RO)->push_value(layer, - ptr_weights, - quantizedIdentity, - num_rows_out + num_padding); - } else { - auto quantizedIdentity = FloatToInt8(std::min(scaledIdentity, static_cast(INT8_MAX))); - - gnamem->getQueue(REGION_RO)->push_value(layer, - ptr_weights, - quantizedIdentity, - num_rows_out + num_padding); - } - } - connectInput(layer, ptr_biases, num_data_bytes_in, 0, biasesLayerIdx); - break; - - case EltwiseLayer::Prod: - if (quantized == nullptr) { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0.0f, num_rows_out + num_padding); - } else { - if (gna_config.gnaFlags.input_low_precision == false) { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0, num_rows_out + num_padding); - } else { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0, num_rows_out + num_padding); - } - } - connectInput(layer, ptr_weights, num_data_bytes_in, 0, biasesLayerIdx); - break; - - default: - THROW_GNA_EXCEPTION << "Unsupported eltwise operation: " << eltwise._operation; - } -} - -void GNAGraphCompiler::GemmPrimitive(InferenceEngine::CNNLayerPtr layer) { - auto quantized = InferenceEngine::getInjectedData(layer); - - IE_ASSERT(!layer->insData.empty()); - IE_ASSERT(!layer->outData.empty()); - IE_ASSERT(layer->insData.size() == 2); - auto input_1 = layer->insData[0].lock(); - auto input_2 = layer->insData[1].lock(); // the second input corresponds to ptr_weights in component - auto outputs = *layer->outData.begin(); - auto input1_precision = quantized ? Precision(Precision::I16) : input_1->getPrecision(); - auto input2_precision = quantized ? Precision(Precision::I16) : input_2->getPrecision(); - - auto in_dims = input_1->getDims(); - auto batch_size = (in_dims.size() == 1) ? 1 : in_dims.front(); - uint32_t num_rows_in = static_cast(InferenceEngine::details::product(in_dims) / batch_size); - uint32_t num_columns_in = static_cast(batch_size); - const auto out_dims = outputs->getDims(); - const auto out_dims_size = ngraph::shape_size(out_dims); - uint32_t num_rows_out = InferenceEngine::GetDimFromBack(out_dims, 1); - uint32_t num_padding = ALIGN(num_rows_in, Limitations::kNoOfInputsDivisor) - num_rows_in; - - // Gemm gets two inputs - void* ptr_input_1 = nullptr; // the first input - void* ptr_outputs = nullptr; - void* ptr_input_2 = nullptr; // the second input corresponds to ptr_weights in component - void* ptr_biases = nullptr; - - auto& currentComponent = dnnComponents.addComponent(layer->name, ("affine")); - - dnn->InitAffineComponent(currentComponent, - num_rows_in + num_padding, - num_columns_in, - num_rows_out, - static_cast(input1_precision.size()), - static_cast(outputs->getPrecision().size()), - static_cast(input2_precision.size()), - quantized == nullptr ? static_cast(input_2->getPrecision().size()) : 4, - GetScaleFactor(layer, QuantizedDataType::weights), - GetScaleFactor(layer, QuantizedDataType::output), - ptr_input_1, - ptr_outputs, - ptr_input_2, - ptr_biases, - false); - - size_t num_data_bytes_out = out_dims_size * outputs->getPrecision().size(); - size_t num_data_bytes_in_1 = (num_rows_in + num_padding) * num_columns_in * input1_precision.size(); - size_t num_data_bytes_in_2 = (num_rows_in + num_padding) * num_columns_in * num_rows_out * input2_precision.size(); - - connectOutput(layer, ptr_outputs, num_data_bytes_out); - connectInput(layer, ptr_input_1, num_data_bytes_in_1); - connectInput(layer, ptr_input_2, num_data_bytes_in_2, 0, 1); - if (gna_config.gnaFlags.sw_fp32) { - IE_ASSERT(quantized == nullptr); - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0, num_rows_out); - } else { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0, num_rows_out); - } -} - -void GNAGraphCompiler::AffinePrimitive(InferenceEngine::CNNLayerPtr layer, bool isDiag) { - auto& weightable = dynamic_cast(*layer.get()); - auto quantized = InferenceEngine::getInjectedData(layer); - - IE_ASSERT(!layer->insData.empty()); - IE_ASSERT(!layer->outData.empty()); - auto inputs = layer->insData.begin()->lock(); - auto outputs = *layer->outData.begin(); - const auto out_dims = outputs->getDims(); - Precision inputPrecision; - uint32_t num_of_inputs_divisor = Limitations::kNoOfInputsDivisor; - - if (!quantized) { - inputPrecision = inputs->getPrecision(); - } else if (gna_config.gnaFlags.input_low_precision == false) { - inputPrecision = Precision(Precision::I16); - } else { - inputPrecision = Precision(Precision::I8); - num_of_inputs_divisor = Limitations::kNoOfInputsLowPrecDivisor; - } - - auto input_data = HasTo2DReshapeData(layer) - ? Get2DReshapedData(inputs, Limitations::get_min_batch_to_fit_in_buffer(inputs), 8) - : inputs; - auto in_dims = input_data->getDims(); - auto batch_size = (in_dims.size() == 1) ? 1 : in_dims.front(); - uint32_t num_rows_in = static_cast(InferenceEngine::details::product(in_dims) / batch_size); - uint32_t num_columns_in = static_cast(batch_size); - uint32_t num_rows_out = isDiag ? num_rows_in : InferenceEngine::GetDimFromBack(out_dims, 1); - uint32_t num_columns_out = num_columns_in; - uint32_t num_padding = ALIGN(num_rows_in, num_of_inputs_divisor) - num_rows_in; - uint32_t num_padding_out = isDiag ? num_padding : 0; - - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - void* ptr_weights = nullptr; - void* ptr_biases = nullptr; - - // TODO: questionable why for biases that are not in IR we inventing precision - auto biasPrecisionSize = weightable._biases ? weightable._biases->getTensorDesc().getPrecision().size() - : (gna_config.gnaFlags.input_low_precision ? 1 : 4); - - // layer without biases might be connected to functional layer without activations - auto prevLayer = CNNNetPrevLayer(layer); - bool useBiasConnection = false; - if (LayerInfo(prevLayer).has32BOutput()) { - if (weightable._biases) { - THROW_GNA_EXCEPTION << "Layer: " << layer->name - << ", cannot be connected to its parent: " << prevLayer->name - << " due to precision mismatch"; - } - log::debug() << "Connection " << prevLayer->name << " to " << layer->name << " is using BIAS as input" - << std::endl; - useBiasConnection = true; - } - - auto& currentComponent = dnnComponents.addComponent(layer->name, (isDiag ? "diagonal" : "affine")); - - dnn->InitAffineComponent(currentComponent, - num_rows_in + num_padding, - num_columns_in, - num_rows_out + num_padding_out, - static_cast(inputPrecision.size()), - static_cast(outputs->getPrecision().size()), - static_cast(weightable._weights->getTensorDesc().getPrecision().size()), - static_cast(biasPrecisionSize), - GetScaleFactor(layer, QuantizedDataType::weights), - GetScaleFactor(layer, QuantizedDataType::output), - ptr_inputs, - ptr_outputs, - ptr_weights, - ptr_biases, - isDiag); - - size_t num_data_bytes_out = num_columns_out * (num_rows_out + num_padding_out) * outputs->getPrecision().size(); - - size_t num_data_bytes_in = num_columns_in * (num_rows_in + num_padding) * inputs->getPrecision().size(); - - auto connectionInfo = connectInput(layer, useBiasConnection ? ptr_biases : ptr_inputs, num_data_bytes_in); - connectOutput(layer, ptr_outputs, num_data_bytes_out); - - auto transpose = false; - size_t transposedRows = 0; - size_t transposedCols = 0; - - if (0 && connectionInfo.needTransposeWeights) { - // direct order is 0, 1, 2, 3, supported order is only 0,3,2,1 where dim 2 is usually equals to 1 - auto permuteOrder = connectionInfo.permute->GetParamAsInts("order"); - if (permuteOrder != vector({0, 3, 2, 1})) { - IE_THROW() << "[GNA plugin] Unsupported permute order: was " << layer->GetParamAsString("order") - << ", but only support 0, 3, 2, 1"; - } - - /** - * TODO: weights transpose happened after quantisation might result in poor quality for in 8 - move this to - * passes - */ - if (weightable._weights->getTensorDesc().getPrecision() == Precision::I8) { - IE_THROW() << "[GNA plugin] Unsupported permute operation for 8 bit weights for layer: " << layer->name; - } - - // this affine connected to convolution via pool or activation - log::debug() << "Transposing weights for layer: " << layer->name << "\n"; - - transpose = !isDiag; - transposedRows = connectionInfo.permute->input()->getDims()[3]; - transposedCols = connectionInfo.permute->input()->getDims()[1]; - } - - auto wpSize = weightable.precision.size(); - const auto weightsBuffer = weightable._weights->cbuffer().as(); - - if (num_padding == 0) { - if (!transpose) { - gnamem->getQueue(REGION_RO)->push_ptr(layer, - ptr_weights, - weightable._weights->cbuffer().as(), - weightable._weights->byteSize()); - } else { - gnamem->getQueue(REGION_RO)->push_initializer( - layer, - ptr_weights, - weightable._weights->byteSize(), - [isDiag, num_rows_out, transposedRows, transposedCols, weightsBuffer, wpSize](void* data, size_t size) { - for (uint32_t k = 0; k < (isDiag ? 1 : num_rows_out); k++) { - auto rowOffset = k * transposedRows * transposedCols * wpSize; - auto cbuffer = weightsBuffer + rowOffset; - auto u8Data = reinterpret_cast(data) + rowOffset; - for (size_t j = 0; j < transposedCols; j++) { - for (size_t i = 0; i < transposedRows; i++) { - auto offsetWrite = (transposedRows * j + i) * wpSize; - auto offsetRead = (i * transposedCols + j) * wpSize; - if (size < rowOffset + offsetWrite) { - // zero out dest if error detected - memset(data, 0, size); - THROW_GNA_EXCEPTION << "Size error"; - } - ie_memcpy(u8Data + offsetWrite, - size - rowOffset - offsetWrite, - cbuffer + offsetRead, - wpSize); - } - } - } - }); - } - } else { - if (transpose) { - THROW_GNA_EXCEPTION << "transposed weights with non zero padding not yet supported"; - } - auto elementsIn = (num_rows_in + num_padding) * num_columns_in; - auto paddedWeights = isDiag ? elementsIn : elementsIn * num_rows_out; - auto paddedWeightsSize = paddedWeights * weightable.precision.size(); - - gnamem->getQueue(REGION_RO)->push_initializer( - layer, - ptr_weights, - paddedWeightsSize, - [isDiag, num_rows_in, num_rows_out, num_padding, weightsBuffer, wpSize](void* data, size_t size) { - for (uint32_t i = 0; i < (isDiag ? 1 : num_rows_out); i++) { - ie_memcpy(data, size, weightsBuffer + num_rows_in * i * wpSize, num_rows_in * wpSize); - data = reinterpret_cast(data) + (num_rows_in + num_padding) * wpSize; - } - }); - } - - if (weightable._biases) { - gnamem->getQueue(REGION_RO)->push_ptr(layer, - ptr_biases, - weightable._biases->cbuffer().as(), - weightable._biases->byteSize()); - } else { - // in that case input from previous layer goes into biases, so we have to initialize input pointer by zero - if (useBiasConnection) { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_inputs, 0.0f, num_rows_in + num_padding); - } else { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0.0f, num_rows_out + num_padding_out); - } - } -} - -void GNAGraphCompiler::FillWeightOfAligningFilter(InferenceEngine::CNNLayerPtr layer, - void* ptrWeights, - size_t offset, - bool isQuantized) { - IE_ASSERT(!layer->outData.empty()); - IE_ASSERT(!layer->insData.empty()); - auto outputs = *layer->outData.begin(); - auto inputs = layer->insData.begin()->lock(); - - uint32_t num_rows_in = - static_cast(InferenceEngine::details::product(begin(inputs->getDims()), end(inputs->getDims()))); - uint32_t num_rows_out = - static_cast(InferenceEngine::details::product(begin(outputs->getDims()), end(outputs->getDims()))); - - if (!ptrWeights) { - THROW_GNA_EXCEPTION << "Weights memory is not allocated!!!"; - } - - gnamem->getQueue(REGION_RO)->push_initializer( - layer, - ptrWeights, - num_rows_out * ALIGN(num_rows_in, 8) * layer->precision.size(), - [=](void* data, size_t size) { - int out = 0; - for (size_t input = offset; input < num_rows_out + offset; ++input) { - auto mem_ptr = reinterpret_cast(data) + input * layer->precision.size() + - out * ALIGN(num_rows_in, 8) * layer->precision.size(); - if (!isQuantized) { - auto float_ptr = reinterpret_cast(mem_ptr); - *float_ptr = 1.0f; - } else { - auto int_ptr = reinterpret_cast(mem_ptr); - *int_ptr = 1; - } - ++out; - } - }); -} - -void GNAGraphCompiler::ConcatAlignFilterPrimitive(InferenceEngine::CNNLayerPtr layer) { - auto filterLayer = dynamic_cast(layer.get()); - - if (filterLayer == nullptr) { - return; - } - - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - void* ptr_weights = nullptr; - void* ptr_biases = nullptr; - - IE_ASSERT(!layer->outData.empty()); - IE_ASSERT(!layer->insData.empty()); - auto outputs = *layer->outData.begin(); - auto inputs = layer->insData.begin()->lock(); - - const uint32_t num_of_inputs_divisor = gna_config.gnaFlags.input_low_precision - ? Limitations::kNoOfInputsLowPrecDivisor - : Limitations::kNoOfInputsDivisor; - uint32_t num_columns_in = GetDimFromBack(inputs->getDims(), 2); - uint32_t num_rows_out = GetDimFromBack(outputs->getDims(), 1); - uint32_t num_rows_in = static_cast(filterLayer->_weights->size()) / num_rows_out; - uint32_t num_padding = ALIGN(num_rows_in, num_of_inputs_divisor) - num_rows_in; - - auto numRowsPadded = filterLayer->GetParamAsInt("num_rows_padded"); - // number of rows we handled by inserting copy layer - uint32_t num_rows_copied = 0; - // in case of left alignment succeed, but due to number of elements not multiple of 8 we need to insert align_filter - // we are improving it by inserting copy layer of size that covers most of elements - remained max of 32x31 affine - // filter - if (0 == numRowsPadded && ALIGN(num_rows_in, 32) > 32) { - // can we use copy at all - num_rows_copied = ALIGN(num_rows_in, 32) - 32; - - auto orientation = kDnnInterleavedOrientation; - - auto& copyComponent = dnnComponents.addComponent(layer->name + "_synthetic_copy", CopyLayerName); - - dnn->InitCopyComponent(copyComponent, - orientation, - num_rows_copied, - num_columns_in, - num_rows_copied, - num_columns_in, - static_cast(inputs->getPrecision().size()), - static_cast(inputs->getPrecision().size()), - GetScaleFactor(layer, QuantizedDataType::output), - num_rows_copied, - num_columns_in, - ptr_inputs, - ptr_outputs); - - size_t num_data_bytes_in = num_rows_copied * num_rows_copied * num_columns_in * inputs->getPrecision().size(); - // need to reserve full tensor so using original size with assumption of identity activation attached to filter - // lateron - size_t num_data_bytes_out = num_rows_out * num_columns_in * inputs->getPrecision().size(); - - connectInput(layer, ptr_inputs, num_data_bytes_in); - auto isNonFunctional = [](CNNLayerPtr l) { - return LayerInfo(l).isNonFunctional(); - }; - auto identity = CNNNetGetNextLayerSkipCertain(layer, 0, 0, isNonFunctional); - connectOutput(identity.first, ptr_outputs, num_data_bytes_out); - - num_rows_in -= num_rows_copied; - num_rows_out -= num_rows_copied; - } - filterLayer->params["rows_copied_offset"] = std::to_string(num_rows_copied * inputs->getPrecision().size()); - - // TODO: questionable why for biases that are not in IR we inventing precision - auto biasPrecisionSize = filterLayer->_biases ? filterLayer->_biases->getTensorDesc().getPrecision().size() - : (gna_config.gnaFlags.input_low_precision ? 1 : 4); - auto& currentComponent = dnnComponents.addComponent(layer->name, "affine"); - - dnn->InitAffineComponent(currentComponent, - num_rows_in + num_padding, - num_columns_in, - num_rows_out, - static_cast(inputs->getPrecision().size()), - static_cast(outputs->getPrecision().size()), - static_cast(filterLayer->_weights->getTensorDesc().getPrecision().size()), - static_cast(biasPrecisionSize), - GetScaleFactor(layer, QuantizedDataType::weights), - GetScaleFactor(layer, QuantizedDataType::output), - ptr_inputs, - ptr_outputs, - ptr_weights, - ptr_biases, - false); - - size_t num_data_bytes_out = num_rows_out * num_columns_in * outputs->getPrecision().size(); - size_t num_data_bytes_in = - num_columns_in * ALIGN(num_rows_in, num_of_inputs_divisor) * inputs->getPrecision().size(); - - connectInput(layer, - ptr_inputs, - num_data_bytes_in, - static_cast(num_rows_copied * inputs->getPrecision().size()), - 0); - connectOutput(layer, ptr_outputs, num_data_bytes_out); - - { - auto weightsElementSize = filterLayer->_weights->getTensorDesc().getPrecision().size(); - auto elementsIn = (num_rows_in + num_padding) * num_columns_in; - auto paddedWeights = elementsIn * num_rows_out; - auto paddedWeightsSize = paddedWeights * weightsElementSize; - - // TODO: this can be improved to not generate unneeded weights at all - - size_t weights_stride = (num_rows_in + num_rows_copied) * weightsElementSize; - size_t weights_offset = weights_stride * num_rows_copied + num_rows_copied * weightsElementSize; - - gnamem->getQueue(REGION_RO) - ->push_initializer(layer, ptr_weights, paddedWeightsSize, [=](void* data, size_t size) { - size_t roffset = weights_offset; - size_t woffset = 0; - for (uint32_t i = 0; i < num_rows_out && size >= woffset; i++) { - ie_memcpy(reinterpret_cast(data) + woffset, - size - woffset, - filterLayer->_weights->cbuffer().as() + roffset, - num_rows_in * weightsElementSize); - roffset += weights_stride; - woffset += elementsIn * weightsElementSize; - } - }); - } - - if (filterLayer->_biases) { - gnamem->getQueue(REGION_RO)->push_ptr(layer, - ptr_biases, - filterLayer->_biases->cbuffer().as(), - filterLayer->_biases->byteSize()); - } else { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0.0f, num_rows_out); - } -} - -void GNAGraphCompiler::ConvolutionFilterPrimitive(InferenceEngine::CNNLayerPtr layer) { - auto filterLayer = dynamic_cast(layer.get()); - - if (filterLayer == nullptr) { - return; - } - - auto prevLayer = CNNNetPrevLayer(layer.get(), 0); - if (!LayerInfo(prevLayer).isSplit() && !LayerInfo(prevLayer).isSlice()) { - THROW_GNA_EXCEPTION << "Case with Affine Aligning Filter for not Split/Slice layers is not implemented yet!"; - } - - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - void* ptr_weights = nullptr; - void* ptr_biases = nullptr; - - IE_ASSERT(!layer->outData.empty()); - IE_ASSERT(!layer->insData.empty()); - auto outputs = *layer->outData.begin(); - auto inputs = layer->insData.begin()->lock(); - - const auto num_of_inputs_divisor = gna_config.gnaFlags.input_low_precision ? Limitations::kNoOfInputsLowPrecDivisor - : Limitations::kNoOfInputsDivisor; - const uint32_t orginalInputSize = static_cast( - InferenceEngine::details::product(std::next(inputs->getDims().begin()), inputs->getDims().end())); - const uint32_t orginalOutputSize = static_cast( - InferenceEngine::details::product(std::next(outputs->getDims().begin()), outputs->getDims().end())); - if (orginalInputSize != orginalOutputSize) { - THROW_GNA_LAYER_EXCEPTION(filterLayer) - << "Number in inputs (" << orginalInputSize << ") should be equal to number of outputs (" - << orginalOutputSize << ")!"; - } - const auto numberOfFilters = filterLayer->_out_depth; - const auto convolutionStride = numberOfFilters; - const auto filterWidth = filterLayer->_kernel_x; - const auto minOutputsPerFilter = ALIGN(orginalOutputSize, numberOfFilters) / numberOfFilters; - const auto minInputsNeeded = (minOutputsPerFilter - 1) * convolutionStride + filterWidth; - const auto numInputsFullyPadedAndAligned = ALIGN(minInputsNeeded, num_of_inputs_divisor); - - auto numOutputs = - gna_convolution_layer::outputFromConv(numInputsFullyPadedAndAligned, filterWidth, convolutionStride); - numOutputs *= numberOfFilters; - const auto& biasPrecision = - filterLayer->_biases ? filterLayer->_biases->getTensorDesc().getPrecision() : outputs->getPrecision(); - auto& currentComponent = dnnComponents.addComponent(layer->name, "affine"); - - layer->params["num_rows_for_pwl"] = std::to_string(numOutputs); - dnn->InitConvolutional1DComponent( - currentComponent, - numInputsFullyPadedAndAligned, - numOutputs, - static_cast(inputs->getPrecision().size()), - static_cast(outputs->getPrecision().size()), - static_cast(filterLayer->_weights->getTensorDesc().getPrecision().size()), - static_cast(biasPrecision.size()), - numberOfFilters, - filterWidth, - convolutionStride, - GetScaleFactor(layer, QuantizedDataType::weights), - GetScaleFactor(layer, QuantizedDataType::output), - ptr_inputs, - ptr_outputs, - ptr_weights, - ptr_biases); - - size_t num_data_bytes_out = - InferenceEngine::details::product(begin(outputs->getDims()), end(outputs->getDims())) * 4; - - size_t num_data_bytes_in = numInputsFullyPadedAndAligned * inputs->getPrecision().size(); - - connectInput(layer, ptr_inputs, num_data_bytes_in, 0, 0); - connectOutput(layer, ptr_outputs, num_data_bytes_out); - - gnamem->getQueue(REGION_RO)->push_ptr(layer, - ptr_weights, - filterLayer->_weights->cbuffer().as(), - filterLayer->_weights->byteSize()); - - if (filterLayer->_biases) { - gnamem->getQueue(REGION_RO)->push_ptr(layer, - ptr_biases, - filterLayer->_biases->cbuffer().as(), - filterLayer->_biases->byteSize()); - } else { - gnamem->getQueue(REGION_RO)->push_value(layer, ptr_biases, 0.0f, numberOfFilters); - } -} - -void GNAGraphCompiler::PWLPrimitive(InferenceEngine::CNNLayerPtr layer) { - auto* generic = dynamic_cast(layer.get()); - std::string type; - std::vector ptr_pwl_segments; - uint32_t num_rows; - uint32_t num_columns; - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - - do { - if (generic == nullptr) { - type = layer->type; - break; - } - - if (InferenceEngine::details::CaselessEq()(layer->type, "activation")) { - type = generic->GetParamAsString("type"); - break; - } else { - type = layer->type; - break; - } - } while (false); - - GNA_LAYER_ASSERT(layer, !layer->insData.empty()); - GNA_LAYER_ASSERT(layer, !layer->outData.empty()); - - auto inputs = layer->insData.begin()->lock(); - auto outputs = *layer->outData.begin(); - float output_pwl_scale_factor = GetScaleFactor(layer, QuantizedDataType::output); - float input_pwl_scale_factor = GetScaleFactor(layer, QuantizedDataType::input); - - auto orientation = kDnnInterleavedOrientation; - - uint32_t w_dim_in = GetDataDimByName(inputs, DataDimName::W); - uint32_t h_dim_in = GetDataDimByName(inputs, DataDimName::H); - uint32_t c_dim_in = GetDataDimByName(inputs, DataDimName::C); - uint32_t n_dim_in = GetDataDimByName(inputs, DataDimName::N); - num_columns = n_dim_in; - num_rows = w_dim_in * h_dim_in * c_dim_in; - - if (dnn->new_num_conv_columns) { - if (dnn->new_num_conv_columns % num_columns == 0) { - num_rows = dnn->new_num_conv_columns / num_columns; - } else { - num_columns = dnn->new_num_conv_columns; - num_rows = 1; - } - dnn->new_num_conv_columns = 0; - } - - // TODO: solve this by layer level transformations - auto prevLayer = CNNNetPrevLayer(layer, 0); - if (LayerInfo(prevLayer).isConcatAlignFilter()) { - auto rowsCopiedOffset = prevLayer->GetParamAsInt("rows_copied_offset"); - if (rowsCopiedOffset != 0) { - num_rows -= static_cast(rowsCopiedOffset / outputs->getPrecision().size()); - layer->params["output_offset"] = std::to_string(rowsCopiedOffset); - } - } else if (LayerInfo(prevLayer).isConvolutionFilter()) { - const auto num_rows_for_pwl = prevLayer->GetParamAsInt("num_rows_for_pwl", 0); - if (num_rows_for_pwl != 0) { - num_rows = num_rows_for_pwl; - } - } - size_t num_data_bytes_out = num_columns * num_rows * outputs->getPrecision().size(); - size_t num_data_bytes_in = num_columns * num_rows * inputs->getPrecision().size(); - - static InferenceEngine::details::caseless_unordered_map supportedActivations = { - {"sigmoid", kActSigmoid}, - {"tanh", kActTanh}, - {"relu", kActRelu}, - {"leakyrelu", kActLeakyRelu}, - {"clamp", kActKaldiLstmClipping}, - {"exp", kActExp}, - {"log", kActLog}, - {"sign", kActSign}, - {"abs", kActAbs}, - {"neglog", kActNegLog}, - {"neghalflog", kActNegHalfLog}, - {"identity", kActIdentity}, - {"softsign", kActSoftSign}, - {"fakequantize", kActFakeQuantize}, - {"pwl", kActPwl}}; - - auto it = supportedActivations.find(type); - if (it == supportedActivations.end()) { - THROW_GNA_EXCEPTION << "Activation function type not yet supported: " << type; - } - auto activation_type = DnnActivation::fromType(it->second); - activation_type.fqParams.set = false; - auto quantized = InferenceEngine::getInjectedData(layer); - if (quantized != nullptr && quantized->_dst_quant.IsStatsSet()) { - activation_type.fqParams.set = true; - activation_type.fqParams.levels = quantized->_dst_quant.GetLevels(); - activation_type.fqParams.inputPerChannel = false; - activation_type.fqParams.input_low = &(quantized->_dst_quant.GetMinValues(true).front()); - activation_type.fqParams.input_high = &(quantized->_dst_quant.GetMaxValues(true).front()); - } - - activation_type.srcFQParams.set = false; - if (quantized != nullptr && quantized->_src_quant.IsStatsSet()) { - activation_type.srcFQParams.set = true; - activation_type.srcFQParams.levels = quantized->_src_quant.GetLevels(); - activation_type.srcFQParams.inputPerChannel = false; - activation_type.srcFQParams.input_low = &(quantized->_src_quant.GetMinValues(true).front()); - activation_type.srcFQParams.input_high = &(quantized->_src_quant.GetMaxValues(true).front()); - } - - if (it->second == kActRelu) { - auto reluLayer = dynamic_cast(layer.get()); - activation_type.args.lrelu.negative_slope = reluLayer != nullptr ? reluLayer->negative_slope : 0.0f; - } else { - activation_type.args.lrelu.negative_slope = 0.0f; - } - - if (quantized == nullptr && it->second == kActFakeQuantize) { - activation_type = GNAFakeQuantizeLayer(layer).parseAsActivation(); - } else if (it->second == kActKaldiLstmClipping) { - auto clamp_layer = dynamic_cast(layer.get()); - if (clamp_layer) { - if (clamp_layer->min_value == 0 && clamp_layer->max_value == 0) { - // Clamp layer may be not initialized due to backward compatibility - // use in such case old default values - activation_type.args.clamp.low = KALDI_LSTM_CLIP_LOWER; - activation_type.args.clamp.high = KALDI_LSTM_CLIP_UPPER; - } else { - activation_type.args.clamp.low = clamp_layer->min_value; - activation_type.args.clamp.high = clamp_layer->max_value; - } - } else { - activation_type.args.clamp.low = KALDI_LSTM_CLIP_LOWER; - activation_type.args.clamp.high = KALDI_LSTM_CLIP_UPPER; - } - } - string actName = "unknown"; - -#ifdef PLOT -# define GET_ACTIVATION_NAME(name) \ - case name: \ - actName = #name; \ - break - switch (activation_type) { - GET_ACTIVATION_NAME(kActSigmoid); - GET_ACTIVATION_NAME(kActTanh); - GET_ACTIVATION_NAME(kActRelu); - GET_ACTIVATION_NAME(kActLeakyRelu); - GET_ACTIVATION_NAME(kActKaldiLstmClipping); - GET_ACTIVATION_NAME(kActIdentity); - GET_ACTIVATION_NAME(kActSoftSign); - GET_ACTIVATION_NAME(kActCustom); - GET_ACTIVATION_NAME(kActSign); - GET_ACTIVATION_NAME(kActAbs); - GET_ACTIVATION_NAME(kActNegLog); - GET_ACTIVATION_NAME(kActNegHalfLog); - default: - break; - } -#endif - - auto& currentComponent = dnnComponents.addComponent(layer->name, actName); - gna_pwl_segment_t* ptr_pwl_segments_target = nullptr; - - if (!gna_config.gnaFlags.sw_fp32) { - // TODO: generalize activation function code - // now that scale factors are known, create PWL approximations to activation functions - if (gna_config.gnaFlags.uniformPwlDesign) { - switch (activation_type) { - case kActSigmoid: - ptr_pwl_segments.resize(SIGMOID_NUM_SEGMENTS); - break; - case kActTanh: - ptr_pwl_segments.resize(TANH_NUM_SEGMENTS); - break; - case kActRelu: - ptr_pwl_segments.resize(RELU_NUM_SEGMENTS); - break; - case kActLeakyRelu: - ptr_pwl_segments.resize(RELU_NUM_SEGMENTS); - break; - case kActKaldiLstmClipping: - case kActIdentity: - ptr_pwl_segments.resize(IDENTITY_NUM_SEGMENTS); - break; - case kActSoftSign: - ptr_pwl_segments.resize(SOFTSIGN_NUM_SEGMENTS); - break; - case kActCustom: - default: - THROW_GNA_EXCEPTION << "Activation function type not yet supported " << activation_type; - } - PwlDesign(activation_type, - &*ptr_pwl_segments.begin(), - static_cast(ptr_pwl_segments.size()), - input_pwl_scale_factor, - output_pwl_scale_factor, - gna_config.gnaFlags.input_low_precision); - } else { - PwlDesignOpt(activation_type, - input_pwl_scale_factor, - output_pwl_scale_factor, - gna_config.gnaFlags.input_low_precision, - layer->getNode(), - CheckIFLastComponentIsPrecededByConv2D(dnnComponents.components), - ptr_pwl_segments); - } - ptr_pwl_segments_target = reinterpret_cast(&ptr_pwl_segments_target); - } - - dnn->InitPiecewiseLinearComponent(currentComponent, - activation_type, - orientation, - num_rows, - num_columns, - static_cast(inputs->getPrecision().size()), - static_cast(outputs->getPrecision().size()), - static_cast(ptr_pwl_segments.size()), - output_pwl_scale_factor, - input_pwl_scale_factor, - ptr_inputs, - ptr_outputs, - ptr_pwl_segments_target); - - auto fused_to_layer = connectInput(layer, ptr_inputs, num_data_bytes_in); - // PWL will be fused with the previous layer and we need to use it's order id - layer->userValue.v_int = fused_to_layer.input->userValue.v_int; - connectOutput(layer, ptr_outputs, num_data_bytes_out); - - if (ptr_pwl_segments_target != nullptr) { - gnamem->getQueue(REGION_RO)->push_local_ptr(layer, - ptr_pwl_segments_target, - &ptr_pwl_segments.front(), - ptr_pwl_segments.size() * sizeof(gna_pwl_segment_t)); - } -} - -void GNAGraphCompiler::PermutePrimitive(InferenceEngine::CNNLayerPtr layer) { - if (LayerInfo(layer).isTrivialPermute()) { - return; - } - auto layerOrder = layer->GetParamAsInts("order"); - 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(); - - // squeeze order vector - SizeVector squeezedInputOrder; - for (auto input_shape : inputsOrder) { - if (input_shape != 1) - squeezedInputOrder.push_back(input_shape); - } - SizeVector squeezedOutputOrder; - for (auto output_shape : layerOrder) { - if (output_shape != 0) - squeezedOutputOrder.push_back(output_shape); - } - - void* ptr_inputs = nullptr; - void* ptr_outputs = nullptr; - - if (squeezedInputOrder.size() > 2) { - THROW_GNA_LAYER_EXCEPTION(layer) << "unsupported permute (requested transpose is not 2D)"; - } - - if (std::min(squeezedInputOrder[0], squeezedInputOrder[1]) > 8) { - THROW_GNA_LAYER_EXCEPTION(layer) << "unsupported permute (minor dimension=" - << std::min(squeezedInputOrder[0], squeezedInputOrder[1]) << " > 8)"; - } - - const uint32_t num_of_inputs_divisor = gna_config.gnaFlags.input_low_precision - ? Limitations::kNoOfInputsLowPrecDivisor - : Limitations::kNoOfInputsDivisor; - - // now this can be run on GNA - if (squeezedInputOrder[0] < squeezedInputOrder[1]) { // interleave case - if (ALIGN(squeezedInputOrder[1], num_of_inputs_divisor) != squeezedInputOrder[1]) { - THROW_GNA_LAYER_EXCEPTION(layer) - << "unsupported permute (row size not a multiple of " << num_of_inputs_divisor << ")"; - } else { - auto& currentComponent = dnnComponents.addComponent(layer->name, "interleave"); - dnn->InitInterleaveComponent(currentComponent, - static_cast(squeezedInputOrder[0]), - static_cast(squeezedInputOrder[1]), - static_cast(inputs->getPrecision().size()), - static_cast(outputs->getPrecision().size()), - GetScaleFactor(layer, QuantizedDataType::output), - ptr_inputs, - ptr_outputs); - } - - } else { // deinterleave case - if (ALIGN(squeezedInputOrder[0], num_of_inputs_divisor) != squeezedInputOrder[0]) { - THROW_GNA_LAYER_EXCEPTION(layer) - << "[GNA plugin] unsupported permute (column size not a multiple of " << num_of_inputs_divisor << ")"; - } else { - auto& currentComponent = dnnComponents.addComponent(layer->name, "deinterleave"); - dnn->InitDeinterleaveComponent(currentComponent, - static_cast(squeezedInputOrder[0]), - static_cast(squeezedInputOrder[1]), - static_cast(inputs->getPrecision().size()), - static_cast(outputs->getPrecision().size()), - GetScaleFactor(layer, QuantizedDataType::output), - ptr_inputs, - ptr_outputs); - } - } - - size_t num_data_bytes_out = - ALIGN(InferenceEngine::details::product(begin(outputs->getDims()), end(outputs->getDims())), - num_of_inputs_divisor) * - outputs->getPrecision().size(); - size_t num_data_bytes_in = squeezedInputOrder[0] * squeezedInputOrder[1] * inputs->getPrecision().size(); - - connectInput(layer, ptr_inputs, num_data_bytes_in); - connectOutput(layer, ptr_outputs, num_data_bytes_out); -} - -inline void SKIP(GNAGraphCompiler*, CNNLayerPtr) {} - -void GNAGraphCompiler::CreateLayerPrimitive(CNNLayerPtr layer) { - static const LayersBuilder layersBuilder[] = { - {{"Input"}, - [](GNAGraphCompiler*, CNNLayerPtr l) { - }}, // skip input layers they are not used in GNA lib, only as a memory blobs - {{"FullyConnected", "InnerProduct"}, CREATE(AffinePrimitive)}, - {{"Gemm"}, CREATE(GemmPrimitive)}, - {{"ScaleShift"}, CREATE(DiagonalPrimitive)}, - {{"ConvolutionFilter"}, CREATE(ConvolutionFilterPrimitive)}, - {{"ConcatAlignFilter"}, CREATE(ConcatAlignFilterPrimitive)}, - {{"Const"}, CREATE(ConstPrimitive)}, - {{"Eltwise"}, CREATE(EltwisePrimitive)}, // same as diagonal while weights are not taken from network, rather - // than from another output - {{"Split"}, - SKIP}, // skip information about which part of prev layer need to consume handle during layer creation - {{"Slice"}, SKIP}, - {{"link"}, SKIP}, - {{"clamp", - "sigmoid", - "relu", - "tanh", - "identity", - "softsign", - "exp", - "log", - "sign", - "abs", - "neglog", - "neghalflog", - "pwl"}, - CREATE(PWLPrimitive)}, - {{"Convolution"}, CREATE(ConvolutionPrimitive)}, - {{"Permute"}, - CREATE(PermutePrimitive)}, // permute of certain form (2D transpose) can be assimilated in followed FC layer - {{"Pooling"}, CREATE(PoolingPrimitive)}, - {{"Power"}, CREATE(PowerPrimitive)}, - {{"Concat"}, CREATE(ConcatPrimitive)}, - {{"Reshape"}, SKIP}, // TODO: handled not in GNA but rather in GNA plugin - {{"Squeeze"}, SKIP}, // TODO: handled not in GNA but rather in GNA plugin - {{"Crop"}, CREATE(CropPrimitive)}, - {{CopyLayerName}, CREATE(CopyPrimitive)}, - {{DelayedCopyLayerName}, CREATE(CopyPrimitive)}, - {{"TensorIterator"}, SKIP}, - {{"LSTMCell"}, SKIP}, - {{"FakeQuantize"}, CREATE(PWLPrimitive)}}; - (void)layersBuilder; - auto it = LayersBuilder::getStorage().find(layer->type); - if (it != LayersBuilder::getStorage().end()) { - it->second(this, layer); - } else { - THROW_GNA_EXCEPTION << "Unsupported layer: " << layer->name << ":" << layer->type; - } -} - -void GNAGraphCompiler::connectOutput(InferenceEngine::CNNLayerPtr layer, void* ptr, size_t num_data_bytes_out) { - auto getOffsetForBinding = [](InferenceEngine::CNNLayerPtr layer) { - int32_t output_offset = 0; - if (layer->params.find("output_offset") != layer->params.end()) { - output_offset = layer->GetParamAsInt("output_offset"); - } - return output_offset; - }; - - log::debug() << "Connecting output " << layer->name << " ...\n"; - // in case of Memory Layer it's input allocated in meminput layer - if (layer->outData.size() == 1) { - auto isNonFunctional = [](CNNLayerPtr l) { - return LayerInfo(l).isNonFunctional(); - }; - - auto next_layers = CNNNetGetAllNextLayersSkipCertain(layer, -1, isNonFunctional); - for (auto& next_layer : next_layers) { - auto nextMemoryLayerIt = - std::find_if(begin(memory_connection), end(memory_connection), [&](MemoryConnection::value_type& comp) { - return comp.second.getOutput()->name == next_layer->name; - }); - if (nextMemoryLayerIt != memory_connection.end()) { - auto& nextMemoryLayer = nextMemoryLayerIt->second; - // memory layer not yet initialized - if (nextMemoryLayer.reserved_size == 0) { - nextMemoryLayer.reserved_size = ALIGN(nextMemoryLayer.getByteSize(), gnamem->getDataMemAlignment()); - gnamem->getQueue(REGION_STATES) - ->reserve_ptr(nullptr, &nextMemoryLayer.gna_ptr, nextMemoryLayer.reserved_size); - gnamem->getQueue(REGION_AUTO) - ->bind_ptr(nullptr, ptr, &nextMemoryLayer.gna_ptr, getOffsetForBinding(layer)); - } else { - // We may need to extend memory buffer if connected input size is bigger, for example for concat - // connection - gnamem->getQueue(REGION_AUTO) - ->bind_ptr(nullptr, - ptr, - &nextMemoryLayer.gna_ptr, - getOffsetForBinding(layer), - num_data_bytes_out); - } - return; - } - } - - // if one of next direct or via split layers is concat... - auto concatChild = [](CNNLayerPtr layer) { - CNNLayerPtr concat; - for (auto&& outLayer : getInputTo(layer->outData.front())) { - auto nextLayer = outLayer.second; - if (LayerInfo(nextLayer).isConcat()) { - concat = nextLayer; - } - } - return concat; - }; - auto splitChild = [](CNNLayerPtr layer) { - std::list split; - for (auto&& outLayer : getInputTo(layer->outData.front())) { - auto nextLayer = outLayer.second; - if (LayerInfo(nextLayer).isSplit() || LayerInfo(nextLayer).isNonFunctional()) { - split.push_back(nextLayer); - } - } - return split; - }; - - std::list splits; - auto concat = concatChild(layer); - auto concatFather = layer; - if (!concat) { - splits = splitChild(layer); - } - - while (!concat && !splits.empty()) { - auto firstSplit = splits.front(); - concat = concatChild(firstSplit); - // now concat prev layer would be this one - concatFather = firstSplit; - if (concat) { - break; - } - // inserting into front of queue alow DFS simulation while searching - splits.pop_front(); - auto nexSplits = splitChild(firstSplit); - splits.insert(splits.begin(), nexSplits.begin(), nexSplits.end()); - } - - if (concat) { - // concat father might be non functional - in that case lets skip it - auto concatFatherActual = LayerInfo(concatFather).isNonFunctional() - ? CNNNetPrevLayerSkipCertain(concatFather, - 0, - [](CNNLayerPtr l) { - return LayerInfo(l).isNonFunctional(); - }) - : concatFather; - - auto& name = concatFatherActual->name; - // we look for this concat layer pointer in extra concat map - auto concatLayerInfo = concat_connection.find(concat->name); - - if (concatLayerInfo == concat_connection.end()) { - THROW_GNA_EXCEPTION << "Cannot find corresponding concat layer: " << concat->name; - } - auto& concatLayerInfoItem = concatLayerInfo->second; - - // find this input in vector sum all outputs in primitive - auto it = std::find_if(concatLayerInfoItem.concatInputLayers.begin(), - concatLayerInfoItem.concatInputLayers.end(), - [&name](GNAConcatLayer::ConcatConnectedLayerInfo& item) { - return item.name == name; - }); - 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& concatItem) -> bool { - auto it = std::find_if( - concatItem.second.concatInputLayers.begin(), - concatItem.second.concatInputLayers.end(), - [&concatLayerInfo](const GNAConcatLayer::ConcatConnectedLayerInfo& item) -> bool { - return item.name == concatLayerInfo->first; - }); - return it != concatItem.second.concatInputLayers.end(); - }); - if (included == concat_connection.end()) { - auto outputSize = std::max(concatLayerInfoItem.reserved_size, num_data_bytes_out * 2); - gnamem->getQueue(REGION_SCRATCH)->reserve_ptr(layer, &concatLayerInfoItem.gna_ptr, outputSize); - - std::function allocate_input_recursively = - [&allocate_input_recursively](GNAConcatLayer clayer, - GnaInputs& inputs, - ConcatConnection& concat_connection) { - size_t concatInputIdx = 0; - for (auto&& inputLayer : clayer.concatInputLayers) { - // skipping non functional and reshape layer, as in that case input might be not - // connected to anything - auto realConcatInputs = CNNNetGetPrevLayersSkip( - clayer.getConcat(), - [](CNNLayerPtr l) { - return !LayerInfo(l).isNonFunctional() && !LayerInfo(l).isSplit(); - }, - static_cast(concatInputIdx++)); - - for (auto& rInput : realConcatInputs) { - if (LayerInfo(rInput.first).isInput()) { - inputs[rInput.first->name].allocated_size += - static_cast(inputLayer.tensorSize + inputLayer.offset); - } - if (LayerInfo(rInput.first).isConcat()) { - auto concatLayerInfo = concat_connection.find(rInput.first->name); - allocate_input_recursively(concatLayerInfo->second, - inputs, - concat_connection); - } - } - } - clayer.input_allocated = true; - }; - - allocate_input_recursively(concatLayerInfoItem, *inputs_ptr_, concat_connection); - } - concatLayerInfo->second.output_allocation_flag = true; - } - // output offset precalculated to serve GNAAlignment requirements - auto output_offset = it->offset; - if (layer->params.find("output_offset") != layer->params.end()) { - output_offset = layer->GetParamAsInt("output_offset"); - } - gnamem->getQueue(REGION_AUTO) - ->bind_ptr(layer, ptr, &concatLayerInfoItem.gna_ptr, output_offset, num_data_bytes_out); - } - return; - } - } - // real output should be allocated in separate region. - auto mem_region = REGION_SCRATCH; - - auto nextLayer = CNNNetCheckNextLayerSkipCertain(layer, 0, 0, true, [](CNNLayerPtr l) { - return LayerInfo(l).isNonFunctional(); - }).first; - // Check that layer will be an output - if (LayerInfo(layer).isOutput() || !nextLayer) { - mem_region = REGION_OUTPUTS; - } - if (LayerInfo(layer).isConst()) { - mem_region = REGION_RO; - } - gnamem->getQueue(mem_region)->reserve_ptr(layer, ptr, num_data_bytes_out); -} - -ConnectionDetails GNAGraphCompiler::connectInput(CNNLayerPtr layer, - void* ptr, - size_t num_data_bytes_in, - int32_t offset, - int idx, - bool connectTo) { - // selecting particular input layers - // auto prevLayer = CNNNetPrevLayer(layer, idx); - auto prevLayer = CNNNetPrevLayerSkipCertain(layer, idx, [](CNNLayerPtr l) { - return LayerInfo(l).isNonFunctional(); - }); - if (!prevLayer) { - THROW_GNA_EXCEPTION << "Input layer was not found"; - } - - log::debug() << "Connecting input " << layer->name << " to " << prevLayer->name << " ...\n"; - - // real input not a memory input - if (LayerInfo(prevLayer).isInput()) { - auto quantized = getInjectedData(prevLayer); - if (quantized) { - inputs_ptr_->at(prevLayer->name).set_precision(GetInputPrecision()); - } - if (0 == inputs_ptr_->at(prevLayer->name).get_allocated_size()) { - // if request for allocation less that realTensorInput - we need to extend request - auto minInput = inputs_ptr_->at(prevLayer->name).get_required_size(); - if (num_data_bytes_in < minInput) { - const uint32_t num_of_inputs_divisor = gna_config.gnaFlags.input_low_precision - ? Limitations::kNoOfInputsLowPrecDivisor - : Limitations::kNoOfInputsDivisor; - log::debug() << "[INPUT] : requested bytes: " << num_data_bytes_in << ", extended to" - << ALIGN(minInput, num_of_inputs_divisor); - num_data_bytes_in = ALIGN(minInput, num_of_inputs_divisor); - } - - // real allocation pointer will be kept in ptr not in ptr_inputs_global - if (!connectTo) { - gnamem->getQueue(REGION_INPUTS)->push_value(layer, ptr, static_cast(0), num_data_bytes_in); - } else { - gnamem->getQueue(REGION_INPUTS) - ->push_value(layer, - &inputs_ptr_->at(prevLayer->name).ptrs.front(), - static_cast(0), - num_data_bytes_in); - } - inputs_ptr_->at(prevLayer->name).allocated_size = static_cast(num_data_bytes_in); - } - if (ALIGN(num_data_bytes_in, gnamem->getDataMemAlignment()) > - ALIGN(inputs_ptr_->at(prevLayer->name).get_allocated_size(), gnamem->getDataMemAlignment())) { - THROW_GNA_EXCEPTION << "Layer: " << layer->name << " Cannot bind pointer to already allocated input(" - << prevLayer->name - << "), due to size_allocated=" << inputs_ptr_->at(prevLayer->name).get_allocated_size() - << ", and size_requested=" << num_data_bytes_in; - } - - if (connectTo) { - gnamem->getQueue(REGION_AUTO) - ->bind_ptr(layer, ptr, &inputs_ptr_->at(prevLayer->name).ptrs.front(), offset, num_data_bytes_in); - } else { - gnamem->getQueue(REGION_AUTO) - ->bind_ptr(layer, &inputs_ptr_->at(prevLayer->name).ptrs.front(), ptr, offset, num_data_bytes_in); - } - - return prevLayer; - } - // const input - if (LayerInfo(prevLayer).isConst()) { - if (connectTo) { - gnamem->getQueue(REGION_AUTO) - ->bind_ptr(layer, ptr, const_connections[prevLayer->name], offset, num_data_bytes_in); - } else { - gnamem->getQueue(REGION_AUTO) - ->bind_ptr(layer, const_connections[prevLayer->name], ptr, offset, num_data_bytes_in); - } - - return prevLayer; - } - - LayerInfo layerInfoObj(prevLayer); - - // connecting to split/slice splitiing layers - if (layerInfoObj.isSplit() || layerInfoObj.isSlice()) { - auto& splittingLayer = prevLayer; - auto& splitName = splittingLayer->name; - - // we look for this split layer pointer in pre calculated map - auto splitLayerInfo = split_connection.find(splitName); - - if (splitLayerInfo != split_connection.end()) { - auto& splitLayerInfoItem = splitLayerInfo->second; - // find this input in vector sum all outputs in primitive - auto it = std::find_if(splitLayerInfoItem.splitOutputLayers.begin(), - splitLayerInfoItem.splitOutputLayers.end(), - [&idx, &layer](GNASplitLayer::SplitConnectedLayerInfo& item) { - return item.connectedTo == layer && item.insDataIdx == idx; - }); - - if (it != splitLayerInfoItem.splitOutputLayers.end()) { - log::debug() << "Connecting " << splitName << " input \n"; - // splitting layer should take the execution order from the connected layer - splittingLayer->userValue = layer->userValue; - auto res = connectInput(splittingLayer, - ptr, - std::max(splitLayerInfoItem.reserved_size, num_data_bytes_in), - static_cast(it->offset) + offset, - 0); - log::debug() << "Connected \n"; - return res; - } - } - THROW_GNA_EXCEPTION << prevLayer->type << " layer: " << splitName << " is not included in extra map"; - } else if (layerInfoObj.isConcat()) { - auto concatLayerInfo = concat_connection.find(prevLayer->name); - if (concatLayerInfo != concat_connection.end()) { - auto& concatLayerInfoItem = concatLayerInfo->second; - // dnnLayer that is input for concat layer - gnamem->getQueue(REGION_AUTO) - ->bind_ptr(layer, ptr, &concatLayerInfoItem.gna_ptr, offset, num_data_bytes_in, false); - // return layer over concat - return CNNNetPrevLayer(prevLayer); - } - } else if (layerInfoObj.isCrop()) { - auto cropLayerInfo = crop_connection.find(prevLayer->name); - if (cropLayerInfo != crop_connection.end()) { - auto& cropLayerInfoItem = cropLayerInfo->second; - gnamem->getQueue(REGION_AUTO)->bind_ptr(layer, ptr, &cropLayerInfoItem.gna_ptr, offset); - return CNNNetPrevLayer(prevLayer); - } - } - auto prevDnnLayer = dnnComponents.findComponent(prevLayer); - - // check for generic prev layer - if (prevDnnLayer != nullptr) { - gnamem->getQueue(REGION_AUTO) - ->bind_ptr(layer, ptr, &prevDnnLayer->ptr_outputs, offset, num_data_bytes_in, false); - return prevLayer; - } - - auto prevMemoryLayer = - std::find_if(begin(memory_connection), end(memory_connection), [&](MemoryConnection::value_type& comp) { - return comp.second.getInput()->params.at("id") == prevLayer->params.at("id"); - }); - if (prevMemoryLayer != memory_connection.end()) { - // dnnLayer that is input for memory output layer - // TODO: this is duplicate with connect output - auto& memoryLayer = prevMemoryLayer->second; - if (memoryLayer.reserved_size == 0) { - memoryLayer.reserved_size = ALIGN(memoryLayer.getByteSize(), gnamem->getDataMemAlignment()); - // connectTo used for indicate that memory layer should be bound to given buffer - if (connectTo) { - memoryLayer.reserved_size = - ALIGN(std::max(memoryLayer.reserved_size, num_data_bytes_in), gnamem->getDataMemAlignment()); - gnamem->getQueue(REGION_STATES)->reserve_ptr(nullptr, &memoryLayer.gna_ptr, memoryLayer.reserved_size); - gnamem->getQueue(REGION_AUTO)->bind_ptr(nullptr, ptr, &memoryLayer.gna_ptr, offset); - } else { - if (ALIGN(num_data_bytes_in, gnamem->getDataMemAlignment()) < - ALIGN(memoryLayer.reserved_size + offset, gnamem->getDataMemAlignment())) { - THROW_GNA_LAYER_EXCEPTION(layer) - << " invalid allocation request of " << num_data_bytes_in - << " is more then state tensor size of: " << memoryLayer.reserved_size + offset; - } - gnamem->getQueue(REGION_AUTO)->bind_ptr(nullptr, &memoryLayer.gna_ptr, ptr, offset, num_data_bytes_in); - } - } else { - // We may need to extend memory buffer if connected input size is bigger, for example for concat connection - gnamem->getQueue(REGION_AUTO)->bind_ptr(nullptr, ptr, &memoryLayer.gna_ptr, offset, num_data_bytes_in); - } - return prevLayer; - } - - // several layers are to be skipped right now - if (LayerInfo(prevLayer).isNonFunctional()) { - log::debug() << "Skipping non functional layer: " << prevLayer->name << "\n"; - return connectInput(prevLayer, ptr, num_data_bytes_in, offset, 0); - } - - // permute layer resulted in trivial permute - if (LayerInfo(prevLayer).isPermute()) { - if (!LayerInfo(prevLayer).isTrivialPermute()) { - // we should have GNA primitive for it - THROW_GNA_EXCEPTION << "missed gna primitive for permute: " << prevLayer->name; - } - log::debug() << "Skipping trivial permute layer: " << prevLayer->name << "\n"; - return connectInput(prevLayer, ptr, num_data_bytes_in, offset, 0); - } - - THROW_GNA_EXCEPTION << "Cannot connect input for: " << layer->name; -} - -void GNAGraphCompiler::Reset() { - for (auto&& memLayer : memory_connection) { - std::memset(memLayer.second.gna_ptr, 0, memLayer.second.reserved_size); - } - for (auto&& concatLayer : concat_connection) { - std::memset(concatLayer.second.gna_ptr, 0, concatLayer.second.reserved_size); - } -} - -void GNAGraphCompiler::printTensorDesc(const std::string& name, const InferenceEngine::TensorDesc& desc) { - log::debug() << name << " layout: " << desc.getLayout() << " shape: "; - for (size_t i = 0; i < desc.getDims().size(); i++) { - if (i > 0) { - log::debug() << 'x'; - } - log::debug() << desc.getDims()[i]; - } - log::debug() << "\n"; -} - -void GNAGraphCompiler::printConvolutionLayer(const InferenceEngine::ConvolutionLayer& layer) { - const char x = 'x'; - - log::debug() << "ConvolutionLayer '" << layer.name << "' Kernel: " << layer._kernel_x << x << layer._kernel_y - << " Padding: " << layer._padding_x << x << layer._padding_y << " Stride: " << layer._stride_x << x - << layer._stride_y << " Dilation: " << layer._dilation_x << x << layer._dilation_y - << " Auto Padding: '" << layer._auto_pad << "'"; - log::debug() << "\n"; - printTensorDesc("Input", layer.input()->getTensorDesc()); - printTensorDesc("Output", layer.outData.front()->getTensorDesc()); -} - -void GNAGraphCompiler::printPoolingLayer(const InferenceEngine::PoolingLayer& layer) { - const char x = 'x'; - - log::debug() << "PoolingLayer '" << layer.name << "' Kernel: " << layer._kernel_x << x << layer._kernel_y - << " Padding: " << layer._padding_x << x << layer._padding_y << " Stride: " << layer._stride_x << x - << layer._stride_y << " Auto Padding: '" << layer._auto_pad << "'"; - log::debug() << "\n"; - printTensorDesc("Input", layer.input()->getTensorDesc()); - printTensorDesc("Output", layer.outData.front()->getTensorDesc()); -} - -std::vector GNAGraphCompiler::transposeMatrix(uint8_t* ptr_matrix, - size_t element_size, - uint32_t num_rows, - uint32_t num_cols) { - std::vector temp_buffer(num_rows * num_cols * element_size); - for (uint32_t i = 0; i < num_rows; i++) { - for (uint32_t j = 0; j < num_cols; j++) { - ie_memcpy(&temp_buffer.front() + (j * num_rows + i) * element_size, - temp_buffer.size() - (i * num_cols + j) * element_size, - ptr_matrix + (i * num_cols + j) * element_size, - element_size); - } - } - return temp_buffer; -} - -std::vector GNAGraphCompiler::copy_matrix(uint8_t* ptr_matrix, - size_t element_size, - uint32_t num_rows, - uint32_t num_cols) { - const size_t dest_size = num_rows * num_cols * element_size; - std::vector temp_buffer(dest_size); - ::memcpy(temp_buffer.data(), ptr_matrix, dest_size); - return temp_buffer; -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_graph_compiler.hpp b/src/plugins/intel_gna/src/gna_graph_compiler.hpp deleted file mode 100644 index 72fca25ab7d..00000000000 --- a/src/plugins/intel_gna/src/gna_graph_compiler.hpp +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include - -#include "backend/am_intel_dnn.hpp" -#include "backend/dnn_components.hpp" -#include "backend/gna_limitations.hpp" -#include "connection_details.hpp" -#include "descriptions/gna_desc.hpp" -#include "descriptions/gna_flags.hpp" -#include "gna_data_types.hpp" -#include "gna_device.hpp" -#include "layers/gna_concat_layer.hpp" -#include "layers/gna_crop_layer.hpp" -#include "layers/gna_memory_layer.hpp" -#include "layers/gna_split_layer.hpp" -#include "memory/gna_memory.hpp" - -namespace ov { -namespace intel_gna { - -class GNAGraphCompiler { -private: - std::shared_ptr dnn; - std::shared_ptr gnamem; - std::shared_ptr inputs_ptr_; - - // layers with extra storage for connections and additional - // non trivial processing - - SplitConnection split_connection; - CropConnection crop_connection; - const Config& gna_config; - - intel_dnn_component_t* find_first_unused_input(InferenceEngine::CNNLayerPtr current); - - static void printTensorDesc(const std::string& name, const InferenceEngine::TensorDesc& desc); - static void printConvolutionLayer(const InferenceEngine::ConvolutionLayer& layer); - static void printPoolingLayer(const InferenceEngine::PoolingLayer& layer); - static void assertConvolutionLayoutProper(const InferenceEngine::DataPtr&); - std::vector static transposeMatrix(uint8_t* ptr_matrix, - size_t element_size, - uint32_t num_rows, - uint32_t num_cols); - std::vector static copy_matrix(uint8_t* ptr_matrix, - size_t element_size, - uint32_t num_rows, - uint32_t num_cols); - - bool ShouldUseOnlyConv2DGnaIface() const; - - std::shared_ptr m_cnn2d_validator; - -public: - backend::DnnComponents dnnComponents; - MemoryConnection memory_connection; - ConcatConnection concat_connection; - ConstConnections const_connections; - - GNAGraphCompiler(const Config& gna_config, - std::shared_ptr dnn_ptr, - std::shared_ptr inputs_ptr, - std::shared_ptr cnn2d_validator, - std::shared_ptr gna_mem_ptr); - void setGNAMemoryPtr(std::shared_ptr gnaMemPtr); - - void fillMemoryConnections(std::unordered_map>& memoryPairs); - - void fillConcatConnections(InferenceEngine::CNNLayerPtr layer); - void fillSplitConnections(InferenceEngine::CNNLayerPtr layer); - - void ValidateCnn2D(const std::string& name, - const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kH, - const uint32_t kW, - const uint32_t kN, - const uint32_t strideH, - const uint32_t strideW, - const uint32_t dilH, - const uint32_t dilW, - OvGnaType inPrecision) const; - - void ValidatePooling2D(const std::string& name, - const uint32_t windowH, - const uint32_t windowW, - const uint32_t strideH, - const uint32_t strideW) const; - - /** - * Connects either memory output, or generic output to a layer - * @param layer - layer pointer - * @param ptr_outputs - pointer to pointer where to store output layer information - * @param ptr_inputs - sizeof output blob - * @param sz - sizeof output blob - * @param ptr_inputs - sizeof output blob - */ - void connectOutput(InferenceEngine::CNNLayerPtr layer, void* ptr_outputs, size_t sz); - /** - * Connects certain input to this layer - * @param layer - layer that we connect input to - * @param pVoid - pointer that holds current layer pointer in gna_mem request - * @param num_data_bytes_in - size - * @param offset - num bytes to advance in buffer - * @param idx - index of input port that we are connecting - * @param connectTo - connectTo is true is alternative to positive or equal to zero offset - * in case when we would like to use zero offset and connect from pointer set this to negative - * @return layer used as input - */ - ConnectionDetails connectInput(InferenceEngine::CNNLayerPtr layer, - void* pVoid, - size_t num_data_bytes_in, - int32_t offset = 0, - int idx = 0, - bool connectTo = true); - - /** - * Fill in the Affine layer weights - * @param layer - affine layer pointer - * @param ptrWeights - pointer to weights memory - * @param offset - memory before offset value will be zeroed - * @param isQuantized - information about layer quantization - */ - void FillWeightOfAligningFilter(InferenceEngine::CNNLayerPtr layer, - void* ptrWeights, - size_t offset, - bool isQuantized = false); - - void CreateLayerPrimitive(InferenceEngine::CNNLayerPtr); - - void AffinePrimitive(InferenceEngine::CNNLayerPtr, bool isDiag = false); - void ConvolutionFilterPrimitive(InferenceEngine::CNNLayerPtr); - void ConcatAlignFilterPrimitive(InferenceEngine::CNNLayerPtr); - void DiagonalPrimitive(InferenceEngine::CNNLayerPtr); - void ConstPrimitive(InferenceEngine::CNNLayerPtr); - void ConvolutionPrimitive(InferenceEngine::CNNLayerPtr); - void PermutePrimitive(InferenceEngine::CNNLayerPtr); - void PoolingPrimitive(InferenceEngine::CNNLayerPtr); - void PowerPrimitive(InferenceEngine::CNNLayerPtr); - void ConcatPrimitive(InferenceEngine::CNNLayerPtr); - void CropPrimitive(InferenceEngine::CNNLayerPtr); - void EltwisePrimitive(InferenceEngine::CNNLayerPtr); - void SplitPrimitive(InferenceEngine::CNNLayerPtr); - void SlicePrimitive(InferenceEngine::CNNLayerPtr); - void PWLPrimitive(InferenceEngine::CNNLayerPtr); - void FakeQuantizePrimitive(InferenceEngine::CNNLayerPtr); - void CopyPrimitive(InferenceEngine::CNNLayerPtr); - void GemmPrimitive(InferenceEngine::CNNLayerPtr); - - void finalizeConvolution1DPrimitive(InferenceEngine::CNNLayerPtr, - uint32_t in_batch, - uint32_t in_channels, - uint32_t in_width, - uint32_t out_batch, - uint32_t out_channels, - uint32_t out_width, - uint32_t in_kernel_x, - uint32_t in_kernel_y, - bool transpose); - void finalizeConvolution2DPrimitive(InferenceEngine::CNNLayerPtr, - uint32_t in_batch, - uint32_t in_channels, - uint32_t in_height, - uint32_t in_width, - uint32_t out_batch, - uint32_t out_channels, - uint32_t out_height, - uint32_t out_width); - - void Reset(); -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_graph_patterns.hpp b/src/plugins/intel_gna/src/gna_graph_patterns.hpp deleted file mode 100644 index 06d6a6da8e9..00000000000 --- a/src/plugins/intel_gna/src/gna_graph_patterns.hpp +++ /dev/null @@ -1,437 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include - -#include "common/graph_utils.hpp" -#include "gna_data_types.hpp" -#include "gna_graph_tools.hpp" -#include "gna_upstream_iterator.hpp" -#include "layers/gna_layer_info.hpp" -#include "log/debug.hpp" -#include "pre_post_process/transposition_info.hpp" - -namespace ov { -namespace intel_gna { - -using TranspositionInfo = pre_post_processing::TranspositionInfo; - -/** - * @brief checks if it's a reshape from 4d to 3d tensor - * @param layer Non-functional layer - */ -inline bool IsReshapeFrom4dTo3d(InferenceEngine::CNNLayerPtr layer) { - if (!LayerInfo(layer).isNonFunctional()) { - return false; - } - - auto input_dims = layer->insData[0].lock()->getDims(); - auto output_dims = layer->outData[0]->getDims(); - // If H input dimension is not 1, it can't be just skipped during reshape to 3d - if (input_dims.size() != 4 || output_dims.size() != 3 || input_dims[2] != 1) { - return false; - } - - input_dims.erase(std::begin(input_dims) + 2); - if (input_dims != output_dims) { - return false; - } - - return true; -} - -/** - * @brief checks if it's a reshape from 3d to 4d tensor inserted before convolution - * @param layer Non-functional layer - */ -inline bool IsReshapeFrom3dTo4d(InferenceEngine::CNNLayerPtr layer) { - if (!LayerInfo(layer).isNonFunctional()) { - return false; - } - - auto input_dims = layer->insData[0].lock()->getDims(); - auto output_dims = layer->outData[0]->getDims(); - if (input_dims.size() != 3 || output_dims.size() != 4) { - return false; - } - - input_dims.insert(std::begin(input_dims) + 2, 1); - if (input_dims != output_dims) { - return false; - } - - return true; -} - -/** - * @brief searches for a pattern: Permute(NHWC->NCHW) -> ... -> Convolution -> ... -> Permute(NCHW->NHWC) or - * Reshape(NHWC->NCHW) -> ... -> Convolution -> ... -> Reshape(NCHW->NHWC) if Convolution has only one input/output - * dimension not equal to 1, - * if the original convolution layout is 3d, 3d->4d/4d->3d reshapes will be inserted before/after the convolution, - * so the possible patterns will be: - * Permute(NWC->NCW) -> ... -> Reshape(NCW ->NCHW) -> Convolution -> Reshape(NCHW->NCW) ... -> Permute(NCW->NWC) or - * Reshape(NWC->NCW) -> ... -> Reshape(NCW ->NCHW) -> Convolution -> Reshape(NCHW->NCW) ... -> Reshape(NCW->NWC) - * if Convolution has only one input/output dimension not equal to 1. - * @param layer convolution layer - * @return the found permutations before and after convolution - */ -inline std::pair -FindPermutationsAroundConvolutionInNHWCModel(InferenceEngine::CNNLayerPtr layer) { - // Skip a convolution which doesn't have previous or next layers - if (layer->outData.size() != 1) { - return std::make_pair(nullptr, nullptr); - } - - if (getInputTo(layer->outData.front()).empty()) { - return std::make_pair(nullptr, nullptr); - } - - if (!InferenceEngine::CNNNetHasPrevLayer(layer.get())) { - return std::make_pair(nullptr, nullptr); - } - - auto next = getInputTo(layer->outData.front()).begin()->second; - // Permute is inserted before Reshape by MO in NHWC models, so we need to find either permute, or reshape, or output - while (!LayerInfo(next).isPermute() && !LayerInfo(next).isPermuteViaReshape() && !LayerInfo(next).isOutput() && - next->outData.size() == 1) { - if (LayerInfo(next).isNonFunctional() && !IsReshapeFrom4dTo3d(next) && !IsReshapeFrom3dTo4d(next)) { - break; - } - auto input_to = getInputTo(next->outData.front()); - if (input_to.size() != 1) - break; - next = input_to.begin()->second; - } - - // Check if the found layer is NCHW to NHWC permute or has 1D data, if it's not just skip this convolution - if (LayerInfo(next).isPermute()) { - const auto layout = next->outData[0]->getLayout(); - const auto order = next->GetParamAsInts("order"); - if ((layout != InferenceEngine::Layout::NCHW && layout != InferenceEngine::Layout::CHW) || - (order != permute::GetPermuteOrder(InferenceEngine::Layout::NCHW, InferenceEngine::Layout::NHWC) && - order != std::vector{0, 2, 1} /* NCW to NWC */)) { - return std::make_pair(nullptr, nullptr); - } - } else if (LayerInfo(next).isReshape()) { - if (next->outData.size() != 1) { - return std::make_pair(nullptr, nullptr); - } - auto input_dims = next->insData[0].lock()->getDims(); - auto in_dims_size = input_dims.size(); - auto output_dims = next->outData[0]->getDims(); - auto out_dims_size = output_dims.size(); - if (in_dims_size == 4 && out_dims_size == 4) { - if (!LayerInfo(next).isPermuteViaReshape() || (input_dims[0] != output_dims[0]) || // N - (input_dims[1] != output_dims[3]) || // C - (input_dims[2] != output_dims[1]) || // H - (input_dims[3] != output_dims[2])) { // W - return std::make_pair(nullptr, nullptr); - } - } else { - // Check if reshape is expected for this pattern: - // the next layer has the both, height and width dimensions > 1 - IE_ASSERT(in_dims_size == 3 || in_dims_size == 4); - size_t height = in_dims_size == 3 ? 1 - : InferenceEngine::GetDataDimByName(next->insData[0].lock(), - InferenceEngine::DataDimName::H); - size_t width = InferenceEngine::GetDataDimByName(next->insData[0].lock(), InferenceEngine::DataDimName::W); - if (out_dims_size < 3 || height != 1 || width != 1) { - return std::make_pair(nullptr, nullptr); - } - } - } else { - return std::make_pair(nullptr, nullptr); - } - - // Permute is inserted after Reshape by MO in NHWC models, so we need to find either permute, or reshape, or input - auto parent = InferenceEngine::CNNNetPrevLayer(layer); - auto prev = parent; - while (!LayerInfo(prev).isPermute() && !LayerInfo(prev).isPermuteViaReshape() && !LayerInfo(prev).isInput() && - InferenceEngine::CNNNetHasPrevLayer(prev.get())) { - if (LayerInfo(prev).isNonFunctional() && !IsReshapeFrom4dTo3d(prev) && !IsReshapeFrom3dTo4d(prev)) { - break; - } - prev = InferenceEngine::CNNNetPrevLayer(prev); - } - // Check if the found layer is NHWC to NCHW permute or has 1D data, if it's not just skip this convolution - if (LayerInfo(prev).isPermute()) { - const auto layout = prev->outData[0]->getLayout(); - const auto order = prev->GetParamAsInts("order"); - if ((layout != InferenceEngine::Layout::NCHW && layout != InferenceEngine::Layout::CHW) || - (order != permute::GetPermuteOrder(InferenceEngine::Layout::NHWC, InferenceEngine::Layout::NCHW) && - order != std::vector{0, 2, 1} /* NWC to NCW */)) { - return std::make_pair(nullptr, nullptr); - } - } else if (LayerInfo(prev).isReshape()) { - auto input_dims = prev->insData[0].lock()->getDims(); - auto in_dims_size = input_dims.size(); - auto output_dims = prev->outData[0]->getDims(); - auto out_dims_size = output_dims.size(); - - if (in_dims_size == 4 && out_dims_size == 4) { - if (!LayerInfo(prev).isPermuteViaReshape() || (input_dims[0] != output_dims[0]) || // N - (input_dims[1] != output_dims[2]) || // H - (input_dims[2] != output_dims[3]) || // W - (input_dims[3] != output_dims[1])) { // C - return std::make_pair(nullptr, nullptr); - } - } else { - if (parent->outData.size() != 1 || InferenceEngine::getInputTo(parent->outData[0]).size() != 1) { - return std::make_pair(nullptr, nullptr); - } - // Check if reshape is expected for this pattern: - // the previous layer has number of channels > 1 and one of height/width dimensions is also > 1 - in_dims_size = parent->insData[0].lock()->getDims().size(); - const auto out_dims = parent->outData[0]->getDims(); - out_dims_size = out_dims.size(); - IE_ASSERT(out_dims_size == 3 || out_dims_size == 4); - size_t channels = InferenceEngine::GetDimFromFront(out_dims, 1); - size_t height = out_dims_size == 3 ? 1 - : InferenceEngine::GetDataDimByName(parent->outData[0], - InferenceEngine::DataDimName::H); - size_t width = InferenceEngine::GetDimFromBack(out_dims, 3); - if (in_dims_size < 3 || (channels != 1 && (height != 1 || width != 1))) { - return std::make_pair(nullptr, nullptr); - } - } - } else { - return std::make_pair(nullptr, nullptr); - } - return std::make_pair(prev, next); -} - -/** - * @brief searches for a pattern Convolution -> ... -> Permute(0,3,2,1) -> ... -> ScaleShift | FullyConnected - * @param layer convolution layer - * @return the found permutation layer - */ -inline InferenceEngine::CNNLayerPtr FindPermutationAfterConvolutionInKaldiModel(InferenceEngine::CNNLayerPtr layer) { - // Skip a convolution which doesn't have next layers - if (layer->outData.size() != 1) { - return nullptr; - } - - if (getInputTo(layer->outData.front()).empty()) { - return nullptr; - } - - /* Permute is inserted between a convolution and a scaleshift|fullyconnected layer by MO in Kaldi models, - * so we need to fing either permute, or fullyconnected, or scaleshift, or output, or reshape to 2D - */ - auto next = getInputTo(layer->outData.front()).begin()->second; - while ( - !LayerInfo(next).isPermute() && !LayerInfo(next).isFullyConnected() && !LayerInfo(next).isScaleShift() && - !LayerInfo(next).isOutput() && - (!LayerInfo(next).isNonFunctional() || next->outData[0]->getDims().size() == next->input()->getDims().size())) { - next = getInputTo(next->outData.front()).begin()->second; - } - - // Check if the found layer is NCHW to NWHC permute - if (!LayerInfo(next).isPermuteFusable() || next->input()->getLayout() != InferenceEngine::Layout::NCHW) { - return nullptr; - } - - return next; -} - -/** - * @brief returns transposition information for a layer based on the previous convolution or pooling dimensions order - * @param layer layer from which transposition info search must be started - * @return bool value which identifies if transposition info is found and transposition information - */ -inline std::vector FindTranspositionInfoFromPrevLayers(InferenceEngine::CNNLayerPtr layer) { - std::function(InferenceEngine::CNNLayerPtr)> findTranspositionInfoRecursive = - [&findTranspositionInfoRecursive](InferenceEngine::CNNLayerPtr layer) -> std::vector { - auto getTransposeInfoFromData = [](InferenceEngine::DataPtr data, bool transpose = true) { - auto rows = InferenceEngine::GetDataDimByName(data, InferenceEngine::DataDimName::C); - auto columns = InferenceEngine::GetDataDimByName(data, InferenceEngine::DataDimName::H) * - InferenceEngine::GetDataDimByName(data, InferenceEngine::DataDimName::W); - return std::vector{{transpose, rows, columns}}; - }; - if (LayerInfo(layer).isConvolution() || LayerInfo(layer).isPooling()) { - return getTransposeInfoFromData(layer->outData[0]); - } - - /* If a fullyconnected or input layers are reached, it means that transposition isn't needed, but we should keep - * its output size to skip this part during transposition if transposed layer is a result of concatination */ - if (LayerInfo(layer).isFullyConnected() || LayerInfo(layer).isInput()) { - auto out_dims = layer->outData[0]->getDims(); - return {{false, 1, InferenceEngine::details::product(std::begin(out_dims), std::end(out_dims))}}; - } - - // If an eltwise is reached we should follow only one not-const direction - if (LayerInfo(layer).isEltwise()) { - auto input1 = InferenceEngine::CNNNetPrevLayer(layer, 0); - auto input2 = InferenceEngine::CNNNetPrevLayer(layer, 1); - if (LayerInfo(input1).isConst() || LayerInfo(input1).isInput()) { - return findTranspositionInfoRecursive(input2); - } - return findTranspositionInfoRecursive(input1); - } - - /* If it's a concat along not channel axis and its inputs are transposed the whole concat output must be - * transposed, otherwise every part corresponding to some input must be transposed separately */ - if (LayerInfo(layer).isConcat() && !layer->insData.empty()) { - auto concatLayer = LayerInfo(layer).as(); - IE_ASSERT(concatLayer != nullptr); - if (concatLayer->_axis > 1) { - for (const auto& input : layer->insData) { - auto in_dims = input.lock()->getDims(); - if (in_dims.size() <= 2) { - THROW_GNA_EXCEPTION << layer->name << " Invalid number of input dimensions " << in_dims.size() - << " for a concat with axis=" << concatLayer->_axis; - } - if (concatLayer->_axis == in_dims.size() - 1 && in_dims[in_dims.size() - 2] > 1) { - std::ostringstream in_dims_oss; - std::copy(in_dims.begin(), in_dims.end(), std::ostream_iterator(in_dims_oss, ",")); - THROW_GNA_EXCEPTION << layer->name << " Unsupported concatenation axis=" << concatLayer->_axis - << " for input dimensions: " << in_dims_oss.str(); - } - } - // Check if non-const inputs are transposed - bool transpose = false; - int nonConstInputIx = 0; - for (int i = 0; InferenceEngine::CNNNetHasPrevLayer(layer.get(), i); ++i) { - auto input = InferenceEngine::CNNNetPrevLayer(layer, i); - if (LayerInfo(input).isConst()) - continue; - auto transpositionInfo = FindTranspositionInfoFromPrevLayers(input); - auto partToTranspose = std::find_if(std::begin(transpositionInfo), - std::end(transpositionInfo), - [](const TranspositionInfo& infoPart) { - return infoPart.transpose; - }); - bool inputTranspose = (partToTranspose != std::end(transpositionInfo)); - if (nonConstInputIx == 0) { - transpose = inputTranspose; - } else if (inputTranspose != transpose) { - THROW_GNA_EXCEPTION << layer->name << " concat has inputs with different layouts"; - } - ++nonConstInputIx; - } - return getTransposeInfoFromData(layer->outData[0], transpose); - } - } - - std::vector transpositionInfo; - for (int idx = 0; idx < static_cast(layer->insData.size()); ++idx) { - if (!InferenceEngine::CNNNetHasPrevLayer(layer.get(), idx)) - continue; - auto inputLayer = InferenceEngine::CNNNetPrevLayer(layer, idx); - if (LayerInfo(inputLayer).isSplit()) { - // If we found split it's not possible to rotate data - auto in_dims = layer->insData[idx].lock()->getDims(); - transpositionInfo.push_back( - {false, 1, InferenceEngine::details::product(std::begin(in_dims), std::end(in_dims))}); - } else if (LayerInfo(layer).isConcat() && LayerInfo(inputLayer).isConst()) { - auto in_dims = layer->insData[idx].lock()->getDims(); - // We should keep its size to skip this part during transposition - auto data_size = InferenceEngine::details::product(std::begin(in_dims), std::end(in_dims)); - transpositionInfo.push_back({false, 1, data_size}); - } else { - std::vector results = findTranspositionInfoRecursive(inputLayer); - transpositionInfo.insert(std::end(transpositionInfo), std::begin(results), std::end(results)); - } - } - return transpositionInfo; - }; - return findTranspositionInfoRecursive(layer); -} - -/** - * @brief returns transposition information for a layer based on the next convolution layer dimensions order - * @param layer layer from which transposition info search must be started - * @return bool value which identifies if transposition info is found and transposition information - */ -inline std::vector FindTranspositionInfoFromNextLayers(InferenceEngine::CNNLayerPtr layer) { - std::function(InferenceEngine::CNNLayerPtr)> findTranspositionInfoRecursive = - [&findTranspositionInfoRecursive](InferenceEngine::CNNLayerPtr layer) -> std::vector { - if (LayerInfo(layer).isConvolution()) { - auto rows = InferenceEngine::GetDataDimByName(layer->input(), InferenceEngine::DataDimName::C); - auto columns = InferenceEngine::GetDataDimByName(layer->input(), InferenceEngine::DataDimName::H) * - InferenceEngine::GetDataDimByName(layer->input(), InferenceEngine::DataDimName::W); - return {{true, rows, columns}}; - } - - /* If a fullyconnected or output layers are reached, it means that transposition isn't needed, but we should - * keep its input size to skip this part during transposition if transposed layer is splitting */ - if (LayerInfo(layer).isFullyConnected() || layer->outData.empty()) { - auto in_dims = layer->input()->getDims(); - return {{false, 1, InferenceEngine::details::product(std::begin(in_dims), std::end(in_dims))}}; - } - - std::vector transpositionInfo; - for (const auto& output : layer->outData) { - if (getInputTo(output).empty()) { - auto out_dims = output->getDims(); - transpositionInfo.push_back( - {false, 1, InferenceEngine::details::product(std::begin(out_dims), std::end(out_dims))}); - continue; - } - std::vector results; - // Return transposition info from the first branch where convolution is found - for (const auto& inputTo : getInputTo(output)) { - if (LayerInfo(inputTo.second).isConcat()) { - // If we found concat it's not possible to rotate data - auto out_dims = output->getDims(); - results = {{false, 1, InferenceEngine::details::product(std::begin(out_dims), std::end(out_dims))}}; - } else { - results = findTranspositionInfoRecursive(inputTo.second); - } - auto found = std::find_if(std::begin(results), std::end(results), [](const TranspositionInfo& result) { - return result.transpose; - }); - if (found != std::end(results)) - break; - } - if (results.empty()) { - THROW_GNA_EXCEPTION << layer->name << " Failed to find transposition info"; - } - transpositionInfo.insert(std::end(transpositionInfo), std::begin(results), std::end(results)); - } - - if (LayerInfo(layer).isCrop()) { - auto in_dims = layer->input()->getDims(); - auto in_total_size = InferenceEngine::details::product(std::begin(in_dims), std::end(in_dims)); - auto crop_layer = LayerInfo(layer).as(); - IE_ASSERT(crop_layer != nullptr); - size_t crop_offset = 1; - size_t crop_out_size = 1; - bool first_cropped_dim = true; - for (size_t i = 0; i < crop_layer->axis.size(); ++i) { - if (crop_layer->offset[i] == 0 && crop_layer->dim[i] == static_cast(in_dims[i])) - continue; - crop_offset *= first_cropped_dim ? crop_layer->offset[i] : crop_layer->dim[i]; - crop_out_size *= crop_layer->dim[i]; - first_cropped_dim = false; - } - auto crop_rest_size = in_total_size - crop_offset - crop_out_size; - if (crop_offset > 0) { - transpositionInfo.insert(std::begin(transpositionInfo), {false, 1, crop_offset}); - } - if (crop_rest_size > 0) { - transpositionInfo.push_back({false, 1, crop_rest_size}); - } - } - return transpositionInfo; - }; - - return findTranspositionInfoRecursive(layer); -} - -/** - * @brief Return true if the layer has max one non-1 dimension - * (because we can treat it as a single dimension layer, then) - */ -inline bool IsOneDimLayer(InferenceEngine::CNNLayerPtr layer) { - auto dims = layer->insData[0].lock()->getDims(); - return std::count_if(std::begin(dims), std::end(dims), [](size_t dim) { - return dim > 1; - }) <= 1; -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_graph_tools.hpp b/src/plugins/intel_gna/src/gna_graph_tools.hpp deleted file mode 100644 index 67f15c81ba7..00000000000 --- a/src/plugins/intel_gna/src/gna_graph_tools.hpp +++ /dev/null @@ -1,961 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "frontend/quantized_layer_params.hpp" -#include "log/debug.hpp" -#include "log/log.hpp" - -using namespace ov::intel_gna; - -namespace InferenceEngine { - -static constexpr size_t invalid_data_idx = std::numeric_limits::max(); - -inline bool DoNotSkip(CNNLayerPtr layer) { - return false; -}; - -// compares data, for copied network and in old network -inline bool areEqualDatas(DataPtr source, DataPtr target) { - if (source.get() == target.get()) { - return true; - } - - // dims comparison - - // actual dims value might be incorrect dueto syntetic case - // , when getbatch() size returns value not reflect in actual data - - if (source->getTensorDesc().getDims().size() != target->getTensorDesc().getDims().size()) { - return false; - } - - // name comparison - if (source->getName() != target->getName()) { - return false; - } - - // inputTO layers are identical by design - return true; -} - -/// @brief utility to locate input data idx from given outdata and given layer -inline std::vector CNNLayerFindInsDataIdxes(DataPtr sourceData, CNNLayerPtr layer) { - std::vector dataIdxes; - auto outLayers = getInputTo(sourceData); - for (auto& outLayer : outLayers) { - if (outLayer.second.get() != layer.get()) { - continue; - } - for (size_t j = 0; j < layer->insData.size(); j++) { - if (areEqualDatas(layer->insData[j].lock(), sourceData)) { - dataIdxes.push_back(static_cast(j)); - } - } - } - IE_ASSERT(!dataIdxes.empty()); - return dataIdxes; -} - -/** - * @brief pointer of previous layers - * @param idx - index in previous layer collection - * @param layer - */ -inline InferenceEngine::CNNLayerPtr CNNNetPrevLayer(const InferenceEngine::CNNLayerPtr& layer, int idx = 0) { - if (CNNNetHasPrevLayer(layer.get(), idx)) { - auto prevData = layer->insData[idx].lock(); - IE_ASSERT(prevData != nullptr); - return getCreatorLayer(prevData).lock(); - } else { - IE_THROW() << "Layer " << layer->name << " has no previous layer"; - } -} - -/** - * @brief pointer of previous layers - * @param idx - index in previous layer collection - * @param layer - */ -inline InferenceEngine::CNNLayerPtr CNNNetPrevLayer(const InferenceEngine::CNNLayer* layer, int idx = 0) { - IE_ASSERT(layer != nullptr); - if (CNNNetHasPrevLayer(layer, idx)) { - auto prevData = layer->insData[idx].lock(); - return getCreatorLayer(prevData).lock(); - } else { - IE_THROW() << "Layer " << layer->name << " has no previous layer"; - } -} - -template -class ExtractRawPtr { - T ptr; - -public: - using raw_ptr_type = T; - explicit ExtractRawPtr(T ptr) : ptr(ptr) {} - T raw() { - return ptr; - } -}; - -template -class ExtractRawPtr> { - std::shared_ptr ptr; - -public: - using raw_ptr_type = U*; - explicit ExtractRawPtr(const std::shared_ptr& ptr) : ptr(ptr) {} - U* raw() { - return ptr.get(); - } -}; - -template -inline typename ExtractRawPtr::raw_ptr_type raw_ptr(T obj) { - ExtractRawPtr x(obj); - return x.raw(); -} - -/** - * @brief gets pointer to previous layer - * @param idx - index in previous layer connection - in other layers only zero idx will be used - * @param layer - source layer - * @param shouldSkip - skip kriteria - */ -template -inline InferenceEngine::CNNLayerPtr CNNNetPrevLayerSkipCertain(Layer layer, - int idx, - const std::function& shouldSkip) { - IE_ASSERT(layer != nullptr); - if (!CNNNetHasPrevLayer(raw_ptr(layer), idx)) { - THROW_GNA_EXCEPTION << "Can't find PrevLayer. All layers are skipped."; - return nullptr; - } - auto prev = CNNNetPrevLayer(layer, idx); - - /// using upper search simplified version - while (shouldSkip(prev)) { - if (!CNNNetHasPrevLayer(prev.get(), 0)) { - THROW_GNA_EXCEPTION << "Can't find PrevLayer. All layers are skipped."; - return nullptr; - } - prev = CNNNetPrevLayer(prev, 0); - } - - return prev; -} - -/** - * @brief returns next layer, skipping certain layers based on given functor - * @param layer - given start layer - * @param oidx - index of output data for start layer, in other layers only zero oidx will be used - * @param iidx - index of input layers for given output right after start layer, in other layers only zero oidx will be - * used - * @param bOnlyCheck - doesn't throw exception if next layer missed - * @param shouldSkip - * @return layer pointer and it's insData index that uses to connect to previous layer in chain - */ - -template -inline std::pair> CNNNetCheckNextLayerSkipCertain( - Layer layer, - int oidx, - int iidx, - bool bOnlyCheck, - const std::function& shouldSkip) { - if (oidx >= static_cast(layer->outData.size())) { - if (bOnlyCheck) - return {nullptr, {}}; - THROW_GNA_LAYER_EXCEPTION(layer) << " no next output layer for outdata: " << oidx; - } - if (getInputTo(layer->outData[oidx]).empty() || iidx >= static_cast(getInputTo(layer->outData[oidx]).size())) { - if (bOnlyCheck) - return {nullptr, {}}; - THROW_GNA_LAYER_EXCEPTION(layer) << " no next output layer for outdata: " << oidx - << " and inputTo index: " << iidx; - } - - auto outLayer = getInputTo(layer->outData[oidx]).begin(); - std::advance(outLayer, iidx); - - int new_oidx = shouldSkip(outLayer->second) ? 0 : oidx; - int new_iidx = shouldSkip(outLayer->second) ? 0 : iidx; - - while (shouldSkip(outLayer->second)) { - if (static_cast(outLayer->second->outData.size()) <= new_oidx) { - if (bOnlyCheck) - return {nullptr, {}}; - THROW_GNA_LAYER_EXCEPTION(outLayer->second) << " no next output layer for outdata: " << new_oidx; - } - - if (static_cast(getInputTo(outLayer->second->outData[new_oidx]).size()) <= new_iidx) { - if (bOnlyCheck) - return {nullptr, {}}; - THROW_GNA_LAYER_EXCEPTION(outLayer->second) - << " no next output layer for outdata: " << new_oidx << " and inputTo index: " << new_iidx; - } - - layer = outLayer->second; - outLayer = getInputTo(layer->outData[new_oidx]).begin(); - } - - auto insDataIdx = CNNLayerFindInsDataIdxes(layer->outData[new_oidx], outLayer->second); - return {outLayer->second, insDataIdx}; -} - -/** - * @brief return all layers reachable from given one - * @param layer - * @param oDataIdx - -1 means iterate over all odata indexes - * @param shouldSkip - * @return - */ -template -inline std::vector CNNNetGetAllNextLayersSkipCertain(Layer layer, - int oDataIdx, - const std::function& shouldSkip) { - std::list currentSet; - std::vector resultSet; - - std::vector> start; - if (oDataIdx == -1) { - for (size_t i = 0; i != layer->outData.size(); i++) { - start.push_back(getInputTo(layer->outData[i])); - } - } else { - start.push_back(getInputTo(layer->outData[oDataIdx])); - } - - auto separate_layers = [¤tSet, &resultSet, &shouldSkip](std::map& inputTo) { - for (auto&& bfsLayer : inputTo) { - if (shouldSkip(bfsLayer.second)) { - currentSet.push_back(bfsLayer.second); - continue; - } - resultSet.push_back(bfsLayer.second); - } - }; - - int startIdx, endIdx; - if (oDataIdx == -1) { - startIdx = 0; - endIdx = static_cast(layer->outData.size()); - } else { - startIdx = oDataIdx; - endIdx = oDataIdx + 1; - } - - for (int i = startIdx; i != endIdx; i++) { - separate_layers(getInputTo(layer->outData[i])); - } - - std::set visited; - while (!currentSet.empty()) { - auto currentLayer = currentSet.front(); - currentSet.pop_front(); - if (visited.count(currentLayer)) { - continue; - } - visited.insert(currentLayer); - for (auto&& oData : currentLayer->outData) { - separate_layers(getInputTo(oData)); - } - } - return resultSet; -} - -/// @brief alias for strict checkNextLayer (false) -template -inline std::pair> -CNNNetGetNextLayerSkipCertain(Layer layer, int oidx, int iidx, const std::function& shouldSkip) { - return CNNNetCheckNextLayerSkipCertain(layer, oidx, iidx, false, shouldSkip); -} - -/// @brief alias for non-strict checkNextLayer (false) -template -inline bool CNNNetHasNextLayerSkipCertain(Layer layer, - int oidx, - int iidx, - const std::function& shouldSkip) { - auto l = CNNNetCheckNextLayerSkipCertain(layer, oidx, iidx, true, shouldSkip); - return l.first.get() != nullptr; -} - -/// @brief utility to locate output data idx from given insData index and given layer -inline int CNNLayerFindOutDataIdx(CNNLayerPtr layer, int insDataIdx) { - auto prevLayer = CNNNetPrevLayer(layer, insDataIdx); - auto outDataToSearch = layer->insData[insDataIdx].lock(); - auto outDataIt = std::find(prevLayer->outData.begin(), prevLayer->outData.end(), outDataToSearch); - return static_cast(std::distance(prevLayer->outData.begin(), outDataIt)); -} - -/// @brief utility to locate output data from given insData index and given layer -/// also it returns iterator that represent link to this layer in inputToMap -inline std::pair::iterator> CNNLayerFindOutData(CNNLayerPtr layer, - int insDataIdx) { - auto oDataIdx = CNNLayerFindOutDataIdx(layer, insDataIdx); - auto prevLayer = CNNNetPrevLayer(layer, insDataIdx); - auto oData = prevLayer->outData[oDataIdx]; - for (auto inputTo = getInputTo(oData).begin(); inputTo != getInputTo(oData).end(); inputTo++) { - if (inputTo->second == layer) { - return {oData, inputTo}; - } - } - THROW_GNA_LAYER_EXCEPTION(layer) << "cannot locate input data for: " << insDataIdx; -} - -/** - * @brief swap two layer in graph - with modifying input/output references - * also if layers have different dimensions they are preserved, so layers should be dimensions agnostic - * lhs is a first node in topological order - this is current limitation to avoid passing cnnnetwork object - */ -inline void CNNNetSwapLayers(InferenceEngine::CNNLayerPtr lhs, InferenceEngine::CNNLayerPtr rhs) { - if (lhs == nullptr || rhs == nullptr) { - IE_THROW() << "CNNNetSwapLayers : nullptr"; - } - if (lhs.get() == rhs.get()) - return; - - if (lhs->outData.size() > 1) { - IE_THROW() << "Unsupported layer for swap operation : " << lhs->name; - } - if (rhs->outData.size() > 1) { - IE_THROW() << "Unsupported layer for swap operation : " << rhs->name; - } - - auto& rhs_outputs = getInputTo(rhs->outData.front()); - auto& lhs_outputs = getInputTo(lhs->outData.front()); - - // fixing input layers edges - for (int i = 0; true; i++) { - if (!CNNNetHasPrevLayer(lhs.get(), i)) - break; - auto prev_lhs = CNNNetPrevLayer(lhs, i); - if (!prev_lhs) - break; - if (prev_lhs == rhs) - continue; - - for (auto& prev_next : prev_lhs->outData) { - auto lhs_ptr = getInputTo(prev_next).find(lhs->name); - lhs_ptr->second = rhs; - } - } - - for (int i = 0; true; i++) { - if (!CNNNetHasPrevLayer(rhs.get(), i)) - break; - auto prev_rhs = CNNNetPrevLayer(rhs, i); - if (!prev_rhs) - break; - if (prev_rhs == lhs) - continue; - - for (auto& prev_next : prev_rhs->outData) { - auto lhs_ptr = getInputTo(prev_next).find(rhs->name); - lhs_ptr->second = lhs; - } - } - - // fixing output layers back edges - for (auto& next_lhs : lhs_outputs) { - if (next_lhs.second == rhs) - continue; - - bool hasHrsConnection = false; - for (auto& ins_for_lhs_next : next_lhs.second->insData) { - if (getCreatorLayer(ins_for_lhs_next.lock()).lock() != rhs) - continue; - hasHrsConnection = true; - break; - } - if (!hasHrsConnection) { - for (auto& ins_for_lhs_next : next_lhs.second->insData) { - if (getCreatorLayer(ins_for_lhs_next.lock()).lock() != lhs) - continue; - ins_for_lhs_next = rhs->outData.front(); - } - } - } - - for (auto& next_rhs : rhs_outputs) { - if (next_rhs.second == lhs) - continue; - - bool hasLHSConnection = false; - for (auto& ins_for_rhs_next : next_rhs.second->insData) { - if (getCreatorLayer(ins_for_rhs_next.lock()).lock() != lhs) - continue; - hasLHSConnection = true; - break; - } - if (!hasLHSConnection) { - for (auto& ins_for_rhs_next : next_rhs.second->insData) { - if (getCreatorLayer(ins_for_rhs_next.lock()).lock() != rhs) - continue; - ins_for_rhs_next = lhs->outData.front(); - } - } - } - - // fixing layers itself output references - { - // c++11 lacks generic lambda - using inputTo_element = std::remove_reference::type; - - std::remove_reference::type tmp; - bool bHadInterconnectR2L = false; - - // 0. remove interconnect rhs->lhs - details::erase_if(rhs_outputs, [&bHadInterconnectR2L, &lhs](inputTo_element& element) { - bHadInterconnectR2L |= element.second == lhs; - return element.second == lhs; - }); - - // 1. move all output references from rhs to tmp - tmp.insert(std::begin(rhs_outputs), std::end(rhs_outputs)); - rhs_outputs.clear(); - - // 2. removing lhs->rhs interconnect - bool bHadInterConnect = false; - details::erase_if(lhs_outputs, [&bHadInterConnect, &rhs](inputTo_element& element) { - bHadInterConnect |= element.second == rhs; - return element.second == rhs; - }); - - // 3. move all output references from lhs to rhs - rhs_outputs.insert(std::begin(lhs_outputs), std::end(lhs_outputs)); - lhs_outputs.clear(); - - // 4. move from tmp to lhs - lhs_outputs.insert(std::begin(tmp), std::end(tmp)); - - // 5.restore interconnects - if (bHadInterConnect) { - rhs_outputs[lhs->name] = lhs; - } - if (bHadInterconnectR2L) { - lhs_outputs[rhs->name] = rhs; - } - } - - // fixing layers itself input references - { - // 1. removing interconnects lhs->rhs - bool interConnectBackL2R = false; - details::erase_if(lhs->insData, [&interConnectBackL2R, &rhs](DataWeakPtr weakData) { - InferenceEngine::CNNLayerPtr creator = nullptr; - auto data = weakData.lock(); - if (data != nullptr) - creator = getCreatorLayer(data).lock(); - interConnectBackL2R |= creator == rhs; - return creator == rhs; - }); - - // 2. removing interconnects rhs->lhs - auto interConnectBackR2L = false; - if (!interConnectBackL2R) { - details::erase_if(rhs->insData, [&interConnectBackR2L, &lhs](DataWeakPtr weakData) { - auto data = weakData.lock(); - IE_ASSERT(data != nullptr); - interConnectBackR2L |= getCreatorLayer(data).lock() == lhs; - return getCreatorLayer(data).lock() == lhs; - }); - } - - // swap back edges - std::swap(lhs->insData, rhs->insData); - - // 4. Restoring interconnections - if (interConnectBackL2R) { - rhs->insData.push_back(lhs->outData.front()); - } - if (interConnectBackR2L) { - lhs->insData.push_back(rhs->outData.front()); - } - } - - // TODO : - // 1. step find out what layer is first in topological order - // 2. integrate shape infer mechanism starting from lhs - lhs->outData.front()->setDims(rhs->outData.front()->getDims()); -} - -/** - * @brief changes the Tensor Desctiption if data by created a new one with correct description and replacing original - * one - */ -inline DataPtr CNNReplaceDataWithChangedTensorDescription(DataPtr old_data, TensorDesc& new_td) { - auto new_dataPtr = std::make_shared(old_data->getName() + "_reshaped", new_td); - getInputTo(new_dataPtr) = getInputTo(old_data); - auto creatorLayer = getCreatorLayer(old_data).lock(); - getCreatorLayer(new_dataPtr) = creatorLayer; - size_t idx = invalid_data_idx; - for (size_t i = 0; i < creatorLayer->outData.size(); i++) { - if (areEqualDatas(old_data, creatorLayer->outData[i])) { - idx = i; - break; - } - } - if (idx == invalid_data_idx) - THROW_GNA_EXCEPTION << "No idx for data was found"; - - creatorLayer->outData[idx] = new_dataPtr; - auto input_to = getInputTo(new_dataPtr); - for (auto& input : input_to) { - for (auto& input_idx : CNNLayerFindInsDataIdxes(old_data, input.second)) { - input.second->insData[input_idx] = new_dataPtr; - } - } - return new_dataPtr; -} - -/** - * @brief Creates a Reshape with given name and tensor description - */ -inline CNNLayerPtr CNNNetworkCreateReshape(const TensorDesc& td, const std::string& name, bool quantized) { - auto reshape = std::make_shared(LayerParams({name, "reshape", Precision::FP32})); - auto reshapeLayerWithQuant = - quantized ? InferenceEngine::injectData(reshape) : reshape; - auto dataPtr = std::make_shared(name + "_data", td); - getCreatorLayer(dataPtr) = reshapeLayerWithQuant; - reshapeLayerWithQuant->outData.push_back(dataPtr); - - return reshapeLayerWithQuant; -} - -/** - * @@brief insertLayer between given layers - * @param after, insertion happened after this layer, if after is nullptr, insertion happened after all inputLayers for - * before layer - * @param before, insertion happened before layer, if before is nullptr, insertion happened before all outputLayers of - * after layer - * @param layerToInsert inserted layer - * @param outDataIndex index data to be used to insert layer after it. Cannot be used to specify allOutputDatas - */ -inline void CNNNetworkInsertLayer(CNNLayerPtr after, - CNNLayerPtr before, - CNNLayerPtr layerToInsert, - size_t outDataIndex = invalid_data_idx, - size_t inDataIndex = invalid_data_idx) { - if (after == nullptr && before == nullptr) { - IE_THROW() << "Cannot Insert Layer: before or after layers should be valid layer pointers"; - } - - bool bLocated = false; - bool hasOutputIndex = outDataIndex != invalid_data_idx; - int number_of_connections_between_after_n_before = 0; - - if (after != nullptr) { - int nUnconnectedOData = 0; - for (auto&& data : after->outData) { - if (hasOutputIndex && outDataIndex) { - --outDataIndex; - continue; - } - auto inputTo = getInputTo(data); - for (auto inputIt = inputTo.begin(); inputIt != inputTo.end(); ++inputIt) { - auto input = inputIt->second; - if (before != nullptr && input.get() != before.get()) - continue; - - // located data - for (auto input_port_idx : CNNLayerFindInsDataIdxes(data, input)) { - if ((inDataIndex == static_cast(input_port_idx)) || inDataIndex == invalid_data_idx) - input->insData[input_port_idx] = layerToInsert->outData.front(); - number_of_connections_between_after_n_before++; - } - - getInputTo(layerToInsert->outData.front())[inputIt->first] = input; - - bLocated = true; - - // erasing only one particular connection - // we must check if there is only one connection between after <=> before - if (number_of_connections_between_after_n_before == 1) - getInputTo(data).erase(inputIt->first); - - if (before != nullptr) { - break; - } - } - if (inputTo.empty()) { - nUnconnectedOData++; - } - if (bLocated) { - // erasing all connection - if (before == nullptr) { - getInputTo(data).clear(); - } - - getInputTo(data)[layerToInsert->outData.front()->getName()] = layerToInsert; - layerToInsert->insData.push_back(data); - break; - } - if (hasOutputIndex) { - break; - } - } - - // separately checking case of possible single unconnected output of given layer - if (!bLocated && !before && !hasOutputIndex) { - if (nUnconnectedOData != 1 && number_of_connections_between_after_n_before <= 1) { - THROW_GNA_EXCEPTION << "Cannot insert layer: " << LAYER_NAME(layerToInsert) - << " after: " << LAYER_NAME(after); - } - - for (auto&& data : after->outData) { - if (!getInputTo(data).empty()) - continue; - - bLocated = true; - getInputTo(data)[layerToInsert->outData.front()->getName()] = layerToInsert; - layerToInsert->insData.push_back(data); - - break; - } - } - - // if given outputDataIndex is not correct, lets find index that matches *before* layer - if (!bLocated) { - if (before != nullptr) { - IE_ASSERT(before->insData.size() == 1 || - (inDataIndex != invalid_data_idx && inDataIndex < before->insData.size())); - auto prevLayer = after; - for (auto idx = prevLayer->outData.begin(); idx != prevLayer->outData.end(); idx++) { - auto& outputports = getInputTo(*idx); - for (auto ll = outputports.begin(); ll != outputports.end(); ll++) { - if (ll->second.get() == before.get()) { - // looks we found where need to remove - outputports.erase(ll); - before->insData[inDataIndex != invalid_data_idx ? inDataIndex : 0] = - layerToInsert->outData.front(); - getInputTo(layerToInsert->outData.front())[before->name] = before; - - bLocated = true; - break; - } - } - if (bLocated) { - break; - } - } - // now we have a before layer with one input less - } - if (bLocated) { - // inserting into node that doesnt have child - IE_ASSERT(!after->outData.empty()); - for (auto&& next : after->outData) { - if (!getInputTo(next).empty()) - continue; - getInputTo(next)[layerToInsert->name] = layerToInsert; - layerToInsert->insData.push_back(next); - } - } - } - } - if (!bLocated) { - IE_THROW() << "Cannot insert layer between: " << ((after == nullptr) ? std::string("nullptr") : after->name) - << " and " << ((before == nullptr) ? std::string("nullptr") : before->name); - } -} - -/** - * @brief returns previous layers and outData index for it - * @tparam T - * @param origin - * @param acceptanceCriteria - * @param idx - */ -template -std::vector> CNNNetGetPrevLayersSkip(CNNLayerPtr origin, - const T& acceptanceCriteria, - int idx = -1) { - std::vector> prevLayers; - for (int i = idx == -1 ? 0 : idx; CNNNetHasPrevLayer(origin.get(), i) && (idx == -1 || i == idx); i++) { - auto prevLayer = CNNNetPrevLayer(origin, i); - if (acceptanceCriteria(prevLayer)) { - prevLayers.push_back({prevLayer, CNNLayerFindOutDataIdx(origin, i)}); - } else { - // if for some input we need to look in upper layers - original index not used here intentionally - auto prevPrevLayers = CNNNetGetPrevLayersSkip(prevLayer, acceptanceCriteria); - prevLayers.insert(prevLayers.end(), prevPrevLayers.begin(), prevPrevLayers.end()); - } - } - - return prevLayers; -} - -/** - * @brief Removes 'to_remove' layer from between two other - 'prev' and 'next', then connects 'prev' and 'next' - * @param prev Layer before 'to_remove' - * @param to_remove Layer to be removed - * @param prevOutputNo Output number of 'prev', which will be connected with 'next' - * @param nextInputNo Input number of 'next', which will be connected with 'prev' - * @return true if layer was removed, otherwise return false - */ - -inline bool CNNRemoveAndConnect(CNNLayerPtr prev, CNNLayerPtr to_remove, int prevOutputNo = 0, int nextInputNo = 0) { - CNNLayerPtr next = CNNNetCheckNextLayerSkipCertain(to_remove, 0, 0, true, DoNotSkip).first; - - if (!prev || !next) { - return false; - } - - IE_ASSERT(prev->outData.size() > 0); - IE_ASSERT(next->outData.size() > 0); - - if (to_remove->outData.size() != 1) { - // Cannot remove layer, which has different number of outputs than 1 - return false; - } - - // Get first output ptr of 'prev' - auto prevDPtr = prev->outData[prevOutputNo]; - - // Assign first output of 'prev' to first input of 'next' - next->insData[nextInputNo] = prevDPtr; - - // Add 'next' to inputTo map of 'prev', - // so now it will point 'next' as a layer, which uses 'prev' as its input. - auto& prevInputToMap = getInputTo(prevDPtr); - prevInputToMap[next->name] = next; - - // Remove reference to 'to_remove' from inputTo map of 'prev' - prevInputToMap.erase(to_remove->name); - - return true; -} - -/** - * @brief remove given layer from topology, currently only layers with one input data and one output data supported - */ -inline void CNNNetworkRemoveLayer(CNNLayerPtr layer, bool checkDims = true) { - if (!layer) { - IE_THROW() << "Cannot remove layer pointed to NULL"; - } - log::debug() << "Removing " << layer->name << " layer\n"; - if (layer->insData.size() != 1) { - IE_THROW() << "Cannot remove layer : " << layer->name << " that has different number of inputs than 1"; - } - if (layer->outData.size() != 1) { - IE_THROW() << "Cannot remove layer : " << layer->name << " that has different number of outputs than 1"; - } - - auto isp = layer->insData.front().lock(); - if (!isp) { - IE_THROW() << "Cannot remove layer : " << layer->name << " cannot get it's input"; - } - // if dimensions of input layer not equal target dimensions - shape infer or reshape layer required, so skipping - // those cases - auto osp = layer->outData.front(); - if (checkDims && isp->getDims() != osp->getDims()) { - IE_THROW() << "Cannot remove layer : " << layer->name << " its input layer(" << isp->getName() - << ") and output(" << osp->getName() << ") have incompatible dimensions"; - } - - // remove isp->layer connection - for (auto i = getInputTo(isp).begin(); i != getInputTo(isp).end(); i++) { - if (i->second.get() == layer.get()) { - getInputTo(isp).erase(i); - break; - } - } - - // remove osp->layer connection - for (auto&& outData : getInputTo(osp)) { - for (size_t i = 0; i < outData.second->insData.size(); i++) { - auto insData = outData.second->insData[i].lock(); - if (!insData) { - IE_THROW() << "Cannot remove layer : " << layer->name << ", its output layer(" << outData.first - << " has invalid input configuration"; - } - auto creator = getCreatorLayer(insData).lock(); - if (!creator) { - IE_THROW() << "Cannot remove layer : " << layer->name << ", its output layer(" << outData.first - << " has invalid input configuration"; - } - - // found layer that need to be removed - if (creator.get() == layer.get()) { - outData.second->insData[i] = isp; - break; - } - } - } - - // add isp->osp connections - for (auto&& outData : getInputTo(osp)) { - // new syntetic name to avoid duplicates in map - getInputTo(isp)[layer->name + "_" + outData.first] = outData.second; - } - - // removing layer->osp, and layer->isp connection not necessary - layer will delete it by itself -} - -/** - * @brief reconnects given layer to different parent - * before: - * old_prev_layer --> layer - * after: - * new_prev_layer --> layer - * limitations: - * - new & old prev layer must have exactly one outgoing port - */ -inline void CNNNetworkReconnectLayer(CNNLayerPtr old_prev_layer, - CNNLayerPtr new_prev_layer, - CNNLayerPtr layer, - bool checkDims = true) { - if (!layer) { - IE_THROW() << "Cannot reconnect layer pointed to NULL"; - } - if (!old_prev_layer) { - IE_THROW() << "Cannot reconnect layer old parent is NULL"; - } - if (!new_prev_layer) { - IE_THROW() << "Cannot reconnect layer new parent is NULL"; - } - - log::debug() << "Reconnecting " << old_prev_layer->name << " --> " << layer->name << " layer to " - << new_prev_layer->name << " -- > " << layer->name << "layer\n"; - - if (layer->insData.size() < 1) { - IE_THROW() << "Cannot reconnect layer : " << layer->name - << " operation supports only layers with at least 1 incomming port"; - } - - if (old_prev_layer->outData.size() != 1) { - IE_THROW() << "Cannot reconnect layer : " << old_prev_layer->name << " must have exactly 1 outgoing port"; - } - - if (new_prev_layer->outData.size() != 1) { - IE_THROW() << "Cannot reconnect layer : " << new_prev_layer->name << " must have exactly 1 outgoing port"; - } - // layer has ports - // each port has several layers connected to port - // we are assuming that old & new prev has only one outgoing port - auto old_prev_layer_out_port_0 = old_prev_layer->outData.front(); - auto new_prev_layer_out_port_0 = new_prev_layer->outData.front(); - - if (checkDims && old_prev_layer_out_port_0->getDims() != new_prev_layer_out_port_0->getDims()) { - IE_THROW() << "Cannot reconnect layer : " << old_prev_layer->name << " as its output have different dims than" - << new_prev_layer->name; - } - - // find connection between old_prev & layer connection in layer input collection - for (auto layer_input_port : CNNLayerFindInsDataIdxes(old_prev_layer_out_port_0, layer)) { - layer->insData[layer_input_port] = new_prev_layer_out_port_0; - } - - // remove old_prev->layer connection - for (auto i = getInputTo(old_prev_layer_out_port_0).begin(); i != getInputTo(old_prev_layer_out_port_0).end(); - i++) { - if (i->second.get() == layer.get()) { - getInputTo(new_prev_layer_out_port_0).insert({layer->name, layer}); - getInputTo(old_prev_layer_out_port_0).erase(i); - break; - } - } -} - -inline uint32_t GetDimFromFront(const InferenceEngine::SizeVector& dims, uint32_t dim) { - if (dim >= dims.size()) { - return 1; - } - return static_cast(dims[dim]); -} - -/** - * @brief returns a specified dimension depending on its back offset - * @param dims vector of dimensions - * @param backOffset back dimension offset - */ - -inline uint32_t GetDimFromBack(const InferenceEngine::SizeVector& dims, const uint32_t backOffset) { - if (backOffset > dims.size()) { - return 1; - } - const auto indexFromFront = static_cast(dims.size()) - backOffset; - return GetDimFromFront(dims, indexFromFront); -} - -enum class DataDimName { N, C, H, W }; - -/** - * @brief returns a size of a specified data dimension depending on the layout - * @param data a pointer to the data - * @param dimName dimension name - */ -inline uint32_t GetDataDimByName(InferenceEngine::DataPtr data, DataDimName dimName) { - uint32_t dimIxInNCHW = static_cast(dimName); - IE_ASSERT(dimIxInNCHW <= 3); - - std::vector backOffsets; - switch (data->getLayout()) { - case Layout::C: - case Layout::NC: - // 1 will be returned for offsets > 2 - backOffsets = std::vector{2, 1, 3, 4}; - break; - case Layout::HWC: - // 1 will be returned for offset 4 - case Layout::NHWC: - backOffsets = std::vector{4, 1, 3, 2}; - break; - case Layout::CHW: - // 1 will be returned for offset 4 - case Layout::NCHW: - backOffsets = std::vector{4, 3, 2, 1}; - break; - default: - THROW_GNA_EXCEPTION << data->getName() << " Unexpected layout " << data->getLayout(); - } - auto dims = data->getDims(); - return GetDimFromBack(dims, backOffsets[dimIxInNCHW]); -} - -/** - * @brief returns a size of a specified data dimension depending on the layout - * NHWC specialization - * @param data a pointer to the data - * @param dimName dimension name - */ -inline uint32_t GetDataDimSizeNHWC(InferenceEngine::DataPtr data, DataDimName dimName) { - uint32_t dimIxInNCHW = static_cast(dimName); - IE_ASSERT(dimIxInNCHW <= 3); - - std::vector backOffsets; - switch (data->getLayout()) { - case Layout::C: - case Layout::NC: - // 1 will be returned for offsets > 2 - backOffsets = std::vector{2, 1, 3, 4}; - break; - case Layout::HWC: - // 1 will be returned for offset 4 - case Layout::NHWC: - backOffsets = std::vector{4, 3, 2, 1}; - break; - case Layout::CHW: - // 1 will be returned for offset 4 - case Layout::NCHW: - backOffsets = std::vector{4, 1, 3, 2}; - break; - default: - THROW_GNA_EXCEPTION << data->getName() << " Unexpected layout " << data->getLayout(); - } - auto dims = data->getDims(); - return GetDimFromBack(dims, backOffsets[dimIxInNCHW]); -} - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/src/gna_groups.hpp b/src/plugins/intel_gna/src/gna_groups.hpp deleted file mode 100644 index eabe1abed91..00000000000 --- a/src/plugins/intel_gna/src/gna_groups.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "gna_graph_tools.hpp" -#include "layers/gna_layer_info.hpp" - -namespace ov { -namespace intel_gna { - -/** - * @brief returns a pointer to 2D reshaped data to satisfy maximum size of zero dimension - * @param input a pointer to data to be reshaped - * @param maxZeroDimSize the maximum size of zero dimension - */ -inline InferenceEngine::DataPtr Get2DReshapedData(InferenceEngine::DataPtr input, - size_t minZeroDimSize, - size_t maxZeroDimSize) { - IE_ASSERT(minZeroDimSize > 0); - auto dims = input->getDims(); - uint32_t numRowsIn = static_cast(InferenceEngine::details::product(begin(dims), end(dims))); - uint32_t numColumnsIn = 1; - // Rows number should be 8-elements aligned - if (numRowsIn % 8 == 0) { - if (dims.size() >= 2 || dims[0] >= maxZeroDimSize) { - size_t indexDivide = maxZeroDimSize; - while (indexDivide > minZeroDimSize) { - if ((numRowsIn / 8) % indexDivide == 0) - break; - --indexDivide; - } - numRowsIn /= static_cast(indexDivide); - numColumnsIn = static_cast(indexDivide); - } - } - - size_t newDimsSize = (dims.size() > 1) ? dims.size() : 2; - InferenceEngine::Layout new_layout = (dims.size() > 1) ? input->getLayout() : InferenceEngine::Layout::NC; - InferenceEngine::SizeVector newDims(newDimsSize, 1); - newDims[0] = numColumnsIn; - newDims[1] = numRowsIn; - return std::make_shared( - input->getName(), - InferenceEngine::TensorDesc(input->getPrecision(), newDims, new_layout)); -} - -/** - * @brief returns true if input data should be 2D reshaped for the layer - * @param layer - */ -inline bool HasTo2DReshapeData(InferenceEngine::CNNLayerPtr layer) { - if (LayerInfo(layer).isPower() || LayerInfo(layer).isCopy()) - return true; - - if (!LayerInfo(layer).isSyntheticScaleShift()) - return false; - - // Don't reshape diagonallayers with bias connection - return !LayerInfo(getCreatorLayer(layer->insData.front().lock()).lock()).has32BOutput(); -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_infer_request.cpp b/src/plugins/intel_gna/src/gna_infer_request.cpp deleted file mode 100644 index 52473e70d34..00000000000 --- a/src/plugins/intel_gna/src/gna_infer_request.cpp +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_infer_request.hpp" - -#include "gna_plugin.hpp" - -namespace ov { -namespace intel_gna { - -GNAInferRequest::GNAInferRequest(const std::shared_ptr& plg, - const std::vector>& inputs, - const std::vector>& outputs) - : InferenceEngine::IInferRequestInternal(inputs, outputs), - plg(plg) { - CreateInferRequest(); -} - -GNAInferRequest::GNAInferRequest(const std::shared_ptr& plg, - InferenceEngine::InputsDataMap networkInputs, - InferenceEngine::OutputsDataMap networkOutputs) - : InferenceEngine::IInferRequestInternal(networkInputs, networkOutputs), - plg(plg) { - CreateInferRequest(); -} - -void GNAInferRequest::InferImpl() { - // execute input pre-processing. - execDataPreprocessing(_inputs); - // result returned from sync infer wait method - - auto infer_call = [&]() { - auto result = plg->Infer(_inputs, _outputs); - // if result is false we are dealing with QoS feature and set kRequestIndexInvalid - // if result is ok we set kRequestIndexCompleted to not execute request if it is not - // in the queue. - auto result_request_index = result ? kRequestIndexCompleted : kRequestIndexInvalid; - SetRequestIndex(result_request_index); - }; - - CallCleanupAndRethrowOnException(std::move(infer_call)); -} - -std::map GNAInferRequest::GetPerformanceCounts() const { - return plg->GetPerformanceCounts(); -} - -void GNAInferRequest::StartAsyncImpl() { - // execute input pre-processing. - execDataPreprocessing(_inputs); - - auto queue_call = [&]() { - SetRequestIndex(plg->QueueInference(_inputs, _outputs)); - }; - - CallCleanupAndRethrowOnException(std::move(queue_call)); - - // workaround to unblock callback-based flows - if (_callback) { - auto res = Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); - std::exception_ptr exceptionPtr; - if (res != InferenceEngine::StatusCode::OK) { - try { - IE_EXCEPTION_SWITCH( - res, - ExceptionType, - InferenceEngine::details::ThrowNow{IE_LOCATION_PARAM} <<= std::stringstream{}); - } catch (...) { - exceptionPtr = std::current_exception(); - } - } - _callback(exceptionPtr); - } -} - -InferenceEngine::StatusCode GNAInferRequest::Wait(int64_t millis_timeout) { - if (!IsRequestIndexValid()) { - return InferenceEngine::INFER_NOT_STARTED; - } - - ValidateAndConfigureTimeout(millis_timeout); - - if (IsRequestCompleted()) { - return InferenceEngine::OK; - } - - auto waitStatus = RequestStatus::kAborted; - auto wait_call = [&]() { - waitStatus = plg->WaitFor(_infer_request_idx, millis_timeout); - }; - CallCleanupAndRethrowOnException(std::move(wait_call)); - - return HandleRequestWaitStatus(waitStatus); -} - -std::vector> GNAInferRequest::QueryState() { - auto pluginStates = plg->QueryState(); - std::vector state(pluginStates.begin(), pluginStates.end()); - return plg->QueryState(); -} - -bool GNAInferRequest::IsRequestIndexValid() { - return _infer_request_idx != kRequestIndexInvalid; -} - -bool GNAInferRequest::IsRequestCompleted() { - return _infer_request_idx == kRequestIndexCompleted; -} - -bool GNAInferRequest::SetRequestIndex(uint32_t request_index) { - return (_infer_request_idx = request_index); -} - -void GNAInferRequest::ValidateAndConfigureTimeout(int64_t& millis_timeout) { - if (millis_timeout == InferenceEngine::InferRequest::WaitMode::RESULT_READY) { - millis_timeout = MAX_TIMEOUT; - } - - if (millis_timeout < 0) { - IE_THROW(ParameterMismatch) << "Invalid timeout value in milliseconds: " << millis_timeout << "!"; - } -} - -InferenceEngine::StatusCode GNAInferRequest::HandleRequestWaitStatus(const RequestStatus& request_status) { - if (request_status == RequestStatus::kPending) { - // request is still pending so Wait() is needed once again - return InferenceEngine::RESULT_NOT_READY; - } - - if (request_status == RequestStatus::kAborted) { - // need to preserve invalid state here to avoid next Wait() from clearing it - SetRequestIndex(kRequestIndexInvalid); - return InferenceEngine::INFER_NOT_STARTED; - } - - if (request_status == RequestStatus::kCompletedWithError) { - SetRequestIndex(kRequestIndexInvalid); - THROW_GNA_EXCEPTION << "Error when waiting for inference results!"; - } - - return InferenceEngine::OK; -} - -void GNAInferRequest::CallCleanupAndRethrowOnException(std::function&& function_to_invoke) { - try { - function_to_invoke(); - } catch (...) { - // need to preserve invalid state here to avoid next Wait() from clearing it - // and next rethrow issue. - SetRequestIndex(kRequestIndexInvalid); - throw; - } -} - -void GNAInferRequest::CreateInferRequest() { - // TODO: internal connection API - better to generalize - if (_networkOutputs.empty()) { - THROW_GNA_EXCEPTION << "GNAInferRequest :: network has zero outputs"; - } - - // copy inputs blobs since we need to have them in separate address space to allow simultaneous infer requests - for (const auto& output : _networkOutputs) { - _outputs[output.first] = plg->GetOutputBlob(output.first, output.second->getTensorDesc().getPrecision()); - } - - for (const auto& input : _networkInputs) { - _inputs[input.first] = plg->GetInputBlob(input.first, input.second->getTensorDesc().getPrecision()); - } -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_infer_request.hpp b/src/plugins/intel_gna/src/gna_infer_request.hpp deleted file mode 100644 index d52daba124f..00000000000 --- a/src/plugins/intel_gna/src/gna_infer_request.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" -#include "request_status.hpp" - -namespace ov { -namespace intel_gna { - -class GNAPlugin; - -class GNAInferRequest : public InferenceEngine::IInferRequestInternal { -public: - GNAInferRequest(const std::shared_ptr& plg, - const std::vector>& inputs, - const std::vector>& outputs); - GNAInferRequest(const std::shared_ptr& plg, - InferenceEngine::InputsDataMap network_inputs, - InferenceEngine::OutputsDataMap network_outputs); - /** - * @brief Infers specified input(s) in synchronous mode - * @note blocks all method of InferRequest while request is ongoing (running or waiting in queue) - */ - void InferImpl() override; - - /** - * @brief Queries performance measures per layer to get feedback of what is the most time consuming layer. - * Note: not all plugins may provide meaningful data - * @param perfMap - a map of layer names to profiling information for that layer. - */ - std::map GetPerformanceCounts() const override; - - /** - * @brief methods with _ThreadUnsafe prefix are to implement in plugins - * or in default wrapper (e.g. AsyncInferRequestThreadSafeDefault) - */ - void StartAsyncImpl() override; - - InferenceEngine::StatusCode Wait(int64_t millis_timeout) override; - - std::vector> QueryState() override; - -protected: - bool SetRequestIndex(uint32_t request_index); - bool IsRequestIndexValid(); - bool IsRequestCompleted(); - -private: - void CreateInferRequest(); - InferenceEngine::StatusCode HandleRequestWaitStatus(const RequestStatus& request_status); - void ValidateAndConfigureTimeout(int64_t& millis_timeout); - void CallCleanupAndRethrowOnException(std::function&& function_to_invoke); - - static constexpr const uint32_t kRequestIndexInvalid = std::numeric_limits::max(); - static constexpr const uint32_t kRequestIndexCompleted = std::numeric_limits::max() - 1; - - uint32_t _infer_request_idx = kRequestIndexInvalid; - std::shared_ptr plg; -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_itt.hpp b/src/plugins/intel_gna/src/gna_itt.hpp deleted file mode 100644 index fc728b6d589..00000000000 --- a/src/plugins/intel_gna/src/gna_itt.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief Defines openvino domains for tracing - * @file gna_itt.hpp - */ - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace itt { -namespace domains { - -OV_ITT_DOMAIN(GNAPlugin); -OV_ITT_DOMAIN(GNA_LT); - -} // namespace domains -} // namespace itt -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_lib_ver_selector.hpp b/src/plugins/intel_gna/src/gna_lib_ver_selector.hpp deleted file mode 100644 index 3589b43edfc..00000000000 --- a/src/plugins/intel_gna/src/gna_lib_ver_selector.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#define nLayerKind operation -#define intel_layer_kind_t gna_layer_operation -#define intel_gna_proc_t uint32_t - -/** - * Rounds a number up, to the nearest multiple of significance - * Used for calculating the memory sizes of GNA data buffers - * - * @param number Memory size or a number to round up. - * @param significance Informs the function how to round up. The function "ceils" - * the number to the lowest possible value divisible by "significance". - * @return Rounded integer value. - */ -#define ALIGN(number, significance) ((((number) + (significance)-1) / (significance)) * (significance)) - -/** - * Rounds a number up, to the nearest multiple of 64 - * Used for calculating memory sizes of GNA data arrays - */ -#define ALIGN64(number) ALIGN(number, 64) - -namespace ov { -namespace intel_gna { -namespace tools { - -template -std::unique_ptr make_unique(Args&&... args) { - return std::unique_ptr(new T(std::forward(args)...)); -} - -} // namespace tools -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_plugin.cpp b/src/plugins/intel_gna/src/gna_plugin.cpp deleted file mode 100644 index ef658a339a1..00000000000 --- a/src/plugins/intel_gna/src/gna_plugin.cpp +++ /dev/null @@ -1,1434 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#define NOMINMAX - -#include "gna_plugin.hpp" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "backend/am_intel_dnn.hpp" -#include "backend/gna_limitations.hpp" -#include "common/gna_target.hpp" -#include "frontend/model_quantizer.hpp" -#include "frontend/scale_factor_calc.hpp" -#include "frontend/weights_converter.hpp" -#include "gna2-model-api.h" -#include "gna2_model_export_helper.hpp" -#include "gna2_model_helper.hpp" -#include "gna_fused_iterator.hpp" -#include "gna_graph_patterns.hpp" -#include "gna_itt.hpp" -#include "gna_plugin_config.hpp" -#include "gna_tensor_tools.hpp" -#include "gna_transformations_pipeline.hpp" -#include "layers/gna_layer_type.hpp" -#include "log/log.hpp" -#include "memory/gna_memory_state.hpp" -#include "orientation_helper.hpp" -#include "pre_post_process/converter_factory.hpp" -#include "pre_post_process/transposition_info.hpp" -#include "request/model_wrapper_factory.hpp" -#include "request/worker_factory.hpp" -#include "request/worker_pool_impl.hpp" -#include "runtime/gna_float_runtime.hpp" -#include "scale_factor_helper.hpp" -#include "serial/gna_model_serial.hpp" - -using namespace ov::intel_gna::limitations; -using namespace ov::intel_gna::graph_utils; - -inline uint32_t ToByteSize(const Gna2DataType type) { - switch (type) { - case Gna2DataTypeInt8: - case Gna2DataTypeUint8: - return 1; - case Gna2DataTypeInt16: - case Gna2DataTypeUint16: - return 2; - case Gna2DataTypeInt32: - case Gna2DataTypeUint32: - return 4; - case Gna2DataTypeInt64: - case Gna2DataTypeUint64: - return 8; - default: - return 0; - } -} - -using namespace std; -using namespace InferenceEngine; -using namespace InferenceEngine::details; - -using namespace ov::intel_gna::memory; -using namespace ov::intel_gna::frontend; -using namespace ov::intel_gna::pre_post_processing; - -void GNAPlugin::PrePostProcess(InferenceEngine::Blob::Ptr input_blob, - InferenceEngine::Blob::Ptr output_blob, - std::shared_ptr model) { - const ov::element::Type input_type = details::convertPrecision(input_blob->getTensorDesc().getPrecision()); - const ov::element::Type output_type = details::convertPrecision(output_blob->getTensorDesc().getPrecision()); - const ov::Shape& output_shape = output_blob->getTensorDesc().getDims(); - - for (const auto& param : model->get_parameters()) { - param->set_element_type(input_type); - } - model->validate_nodes_and_infer_types(); - const ov::Shape& input_shape = model->get_parameters()[0]->get_output_shape(0); - - ov::TensorVector inputs = {ov::Tensor(input_type, input_shape, input_blob->cbuffer().as())}; - ov::TensorVector results = {ov::Tensor(output_type, output_shape, output_blob->buffer().as())}; - - if (!model->evaluate(results, inputs)) { - THROW_GNA_EXCEPTION << "Failed to evaluate model " << model->get_friendly_name() << std::endl; - } -} - -GNAPlugin::GNAPlugin() { - Init(); - UpdateFieldsFromConfig(); - InitGNADevice(); - Limitations::init(config.target->get_effective_compile_target()); - InitGNAMemory(); - InitGraphCompiler(); - m_input_output_handler = InputOutputDataHandler(ConverterFactory::create_converter()); -} - -GNAPlugin::GNAPlugin(const std::map& configMap) { - Init(); - SetConfig(configMap); - log::set_log_level(gnaFlags->log_level); - InitGNADevice(); - Limitations::init(config.target->get_effective_compile_target()); - InitGNAMemory(); - InitGraphCompiler(); - m_input_output_handler = InputOutputDataHandler(ConverterFactory::create_converter()); -} - -void GNAPlugin::Init() { - OV_ITT_SCOPED_TASK(itt::domains::GNAPlugin, "Init"); - dnn = std::make_shared(backend::AMIntelDNN()); - gnaFlags = std::make_shared(GNAFlags()); - inputs_ptr_ = std::make_shared(GnaInputs()); - outputs_ = GnaOutputs(); - requestWorkerPool_ = std::make_shared(); -} - -void GNAPlugin::InitGNADevice() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "InitGNADevice"); - - if (!gnaFlags->sw_fp32) { - gnadevice = std::make_shared(config.target, - gnaFlags->performance_counting, - !config.embedded_export_path.empty()); - } -} - -void GNAPlugin::InitGNAMemory() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "InitGNAMemory"); - - if (gnaFlags->sw_fp32) { - gnamem.reset(new gna_memory_float(memory::GNAFloatAllocator{})); - } else { - gnamem = std::make_shared(memory::GNAAllocator(gnadevice), - Limitations::get_instance()->get_memory_alignment(), - Limitations::kMemoryPageSize); - } -} - -void GNAPlugin::InitGraphCompiler() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "InitGraphCompiler"); - - m_graph_compiler = std::make_shared( - GNAGraphCompiler(config, dnn, inputs_ptr_, Limitations::get_instance()->get_cnn_validator(), gnamem)); -} - -void GNAPlugin::UpdateInputScaleFromNetwork(InferenceEngine::CNNNetwork& network) { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "UpdateInputScaleFromNetwork"); - // fp32 emulation mode dont need any modifications to configuration - if (config.gnaFlags.sw_fp32) - return; - - // search for FQ layers - // only supports cases of int16 or int8 - InputsDataMap inputs = network.getInputsInfo(); - size_t inputIdx = 0; - for (auto&& input : inputs) { - auto data = input.second->getInputData(); - for (auto&& nextToInputLayer : getInputTo(data)) { - CNNLayerPtr next_layer = nextToInputLayer.second; - // FQ layer can be connected to the input via Reshape/Transpose/Gather and other non-functional layers. - if (LayerInfo(next_layer).is_fq_non_sensitive()) { - next_layer = CNNNetCheckNextLayerSkipCertain(nextToInputLayer.second, 0, 0, true, [](CNNLayerPtr l) { - return LayerInfo(l).is_fq_non_sensitive(); - }).first; - } - - if (!LayerInfo(next_layer).isFakeQuantize()) { - continue; - } - - // replacing scale factor from this fq layer - GNAFakeQuantizeLayer fqLayer(next_layer); - auto inputRange = fqLayer.getInputRange(); - auto outputRange = fqLayer.getOutputRange(); - if (inputRange.second.size() != 1 || outputRange.second.size() != 1) { - THROW_GNA_LAYER_EXCEPTION(next_layer) - << "unsupported, per-channel quantization for input layer : " << input.second->name(); - } - - // GNA input is always quantized to int16, so number of levels can't be greater than max uint16 - // todo: should be solved in POT (issue 63330) - size_t levels = - std::min(fqLayer.getLevels(), static_cast(std::numeric_limits::max() + 1)); - auto scaleInput = ov::intel_gna::frontend::CalculateScaleFactorFromStats(levels, - inputRange.first[0], - inputRange.second[0]); - - if (!config.inputScaleFactorsPerInput.empty() || !config.inputScaleFactors.empty()) { - log::warning() << "Scale factor calculated during model quantization (" << scaleInput - << ") will be used instead of user input (" << (*inputs_ptr_)[input.first].scale_factor - << ").\n"; - if ((*inputs_ptr_)[input.first].scale_factor < scaleInput) { - log::warning() << "Scale factor calculated based on input values (" - << (*inputs_ptr_)[input.first].scale_factor - << ") is smaller than scale factor used to quantize model (" << scaleInput << "). " - << "Input values will be clamped.\n"; - } - } - config.inputScaleFactorsPerInput[input.first] = scaleInput; - (*inputs_ptr_)[input.first].scale_factor = scaleInput; - } - - inputIdx++; - } -} - -void GNAPlugin::UpdateInputsAndOutputsInfoFromNetwork(InferenceEngine::CNNNetwork& network) { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "UpdateInputsAndOutputsInfoFromNetwork"); - - // update inputs - { - InputsDataMap network_inputs = network.getInputsInfo(); - for (const auto& input : network_inputs) { - (*inputs_ptr_)[input.first].Update(input.second); - } - } - - // update outputs - { - OutputsDataMap outputs = network.getOutputsInfo(); - for (const auto& output : outputs) { - outputs_[output.first].Update(output.second); - } - } -} - -void GNAPlugin::UpdateInputs(const std::vector>& params) { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "UpdateInputs"); - for (const auto& param : params) { - const std::string ie_name = param->get_friendly_name(); - (*inputs_ptr_)[ie_name].name = param->get_friendly_name(); - (*inputs_ptr_)[ie_name].tensor_names = param->get_output_tensor(0).get_names(); - - // find pre-processing model - auto subgraph_it = m_input_output_subgraphs.find(ie_name); - if (subgraph_it != m_input_output_subgraphs.end()) { - (*inputs_ptr_)[ie_name].pre_post_process_model = subgraph_it->second; - } - } -} - -void GNAPlugin::UpdateOutputs(const std::vector>& results) { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "UpdateOutputs"); - for (const auto& result : results) { - const std::string ie_name = ov::op::util::create_ie_output_name(result->input_value(0)); - outputs_[ie_name].name = ie_name; - outputs_[ie_name].tensor_names = result->get_output_tensor(0).get_names(); - - // find postprocessing model - auto subgraph_it = m_input_output_subgraphs.find(ie_name); - if (subgraph_it != m_input_output_subgraphs.end()) { - outputs_[ie_name].pre_post_process_model = subgraph_it->second; - } - } -} - -void GNAPlugin::UpdateInputsAndOutputsInfoFromModel(std::shared_ptr model) { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "UpdateInputsAndOutputsInfoFromFModel"); - - // update inputs - { - std::vector> node_vector; - for (auto& param : model->get_parameters()) { - node_vector.emplace_back(param); - } - UpdateInputs(node_vector); - } - - // update outputs - { - std::vector> node_vector; - for (auto& result : model->get_results()) { - node_vector.emplace_back(result); - } - UpdateOutputs(node_vector); - } -} - -bool GNAPlugin::TryToInitOutput(const std::string& portName, InferenceEngine::CNNLayerPtr layer) { - auto initOutput = [this, portName, layer](intel_dnn_orientation_t orientation, - size_t numBytesPerElem, - size_t numElem, - void* outputPtr) { - auto quantized = InferenceEngine::getInjectedData(layer); - - outputs_.at(portName).ptrs.resize(gnaFlags->num_requests); - outputs_.at(portName).orientation = orientation; - outputs_.at(portName).set_precision(static_cast(numBytesPerElem)); - outputs_.at(portName).scale_factor = - quantized != nullptr ? quantized->_dst_quant.GetScale() : kScaleFactorDefault; - outputs_.at(portName).num_elements = static_cast(numElem); - - // binding ptr for first infer request - then others will be setup during relocation - gnamem->getQueue(REGION_AUTO)->bind_ptr(layer, &outputs_.at(portName).ptrs.front(), outputPtr); - }; - - // probing gna_primitives - auto irLayerAvatar = std::find_if(m_graph_compiler->dnnComponents.components.begin(), - m_graph_compiler->dnnComponents.components.end(), - [&layer](const backend::DnnComponents::storage_type::value_type& value) { - return value.name == layer->name; - }); - if (irLayerAvatar != m_graph_compiler->dnnComponents.components.end()) { - initOutput(irLayerAvatar->dnnComponent.orientation_out, - irLayerAvatar->dnnComponent.num_bytes_per_output, - irLayerAvatar->dnnComponent.num_rows_out, - &irLayerAvatar->dnnComponent.ptr_outputs); - return true; - } - - // probing concatInfo - if (LayerInfo(layer).isConcat()) { - auto concatConnection = m_graph_compiler->concat_connection.find(layer->name); - if (concatConnection != m_graph_compiler->concat_connection.end()) { - auto precision = layer->outData.front()->getPrecision().size(); - initOutput(kDnnInterleavedOrientation, - precision, - concatConnection->second.reserved_size / precision, - &concatConnection->second.gna_ptr); - return true; - } - } - - // probing a constant info, for constant trivial networks support - if (LayerInfo(layer).isConst()) { - auto const_blob = layer->blobs["custom"]; - auto constConnection = m_graph_compiler->const_connections.find(layer->name); - if (constConnection != m_graph_compiler->const_connections.end()) { - initOutput(kDnnInterleavedOrientation, - layer->outData.front()->getPrecision().size(), - const_blob->size(), - &constConnection->second); - return true; - } - } - - return false; -} - -#ifdef PLOT -void GNAPlugin::AddDebugProperties(const InferenceEngine::CNNLayerPtr layer, - InferenceEngine::ordered_properties& printed_properties, - InferenceEngine::ordered_properties& node_properties) { - // printing quantized params - auto quantized = InferenceEngine::getInjectedData(layer); - if (!quantized) { - return; - } - if (LayerInfo(layer).isWeightable() || LayerInfo(layer).isEltwise()) { - printed_properties.emplace_back("weights scale factor", std::to_string(quantized->_weights_quant.GetScale())); - if (quantized->_weights_quant.IsStatsSet()) { - for (auto& min : quantized->_weights_quant.GetMinValues()) { - printed_properties.emplace_back("weights min val", std::to_string(min)); - } - for (auto& max : quantized->_weights_quant.GetMaxValues()) { - printed_properties.emplace_back("weights max val", std::to_string(max)); - } - } - - if (quantized->_bias_quant.IsStatsSet()) { - for (auto& min : quantized->_bias_quant.GetMinValues()) { - printed_properties.emplace_back("bias min val", std::to_string(min)); - } - for (auto& max : quantized->_bias_quant.GetMaxValues()) { - printed_properties.emplace_back("bias max val", std::to_string(max)); - } - } - } - printed_properties.emplace_back("src scale factor", std::to_string(quantized->_src_quant.GetScale())); - if (quantized->_src_quant.IsStatsSet()) { - for (auto& min : quantized->_src_quant.GetMinValues()) { - printed_properties.emplace_back("src min val", std::to_string(min)); - } - for (auto& max : quantized->_src_quant.GetMaxValues()) { - printed_properties.emplace_back("src max val", std::to_string(max)); - } - } - - printed_properties.emplace_back("dst scale factor", std::to_string(quantized->_dst_quant.GetScale())); - if (quantized->_dst_quant.IsStatsSet()) { - for (auto& min : quantized->_dst_quant.GetMinValues()) { - printed_properties.emplace_back("dst min val", std::to_string(min)); - } - for (auto& max : quantized->_dst_quant.GetMaxValues()) { - printed_properties.emplace_back("dst max val", std::to_string(max)); - } - } -} -#endif - -void GNAPlugin::LoadNetwork(const CNNNetwork& _network) { - OV_ITT_SCOPED_TASK(itt::domains::GNAPlugin, "LoadNetwork"); - _network_name = _network.getName(); - std::shared_ptr convertedNetwork; - - auto transformer = TransformationsPipeline(config); - - if (_network.getFunction()) { - CNNNetwork clonedNetwork = InferenceEngine::cloneNetwork(_network); - auto model = clonedNetwork.getFunction(); - transformer.apply(model, &m_input_output_subgraphs); - Limitations::get_instance()->check_all_ops_supported(model, config.gnaPrecision); - convertedNetwork = InferenceEngine::details::convertFunctionToICNNNetwork(model, clonedNetwork); - } - IE_SUPPRESS_DEPRECATED_START - InferenceEngine::CNNNetwork network = convertedNetwork ? InferenceEngine::CNNNetwork{convertedNetwork} : _network; - IE_SUPPRESS_DEPRECATED_END - - transformer.convert_precision_legacy(network); - - // Check the network - - std::string error; - if (!Limitations::are_layers_supported(network, error)) { - THROW_GNA_EXCEPTION << error.c_str(); - } - - // Set input and output information from ngraph function - if (_network.getFunction()) { - UpdateInputsAndOutputsInfoFromModel(_network.getFunction()); - } - - // Set input and output information from orginal network - UpdateInputsAndOutputsInfoFromNetwork(network); - - // DEPRECATED: To be removed after fully switching to POT optimized models. - // Set Scale Factors for inputs according to configuration. - ov::intel_gna::helpers::ApplyInputScaleFactors(*inputs_ptr_, config); - - if (transformer.is_fake_quantized()) { - UpdateInputScaleFromNetwork(network); - } - - InferenceEngine::CNNNetwork newNet; - - if (gnaFlags->sw_fp32) { - auto visitor = [&](InferenceEngine::CNNLayerPtr lp) { - ov::intel_gna::frontend::convert_blobs_precision(*lp); - return lp; - }; - newNet = InferenceEngine::CNNNetCopy(network, visitor); - // to run all passes need to have two calls to pass manager - transformer.apply_legacy(newNet, true); - transformer.apply_legacy(newNet, false); - } else { - ov::intel_gna::frontend::ModelQuantizer modelQuantizer(transformer); - newNet = modelQuantizer.quantize(network, *inputs_ptr_); - } - - auto inputLayers = CNNNetGetAllInputLayers(newNet); - -#ifdef PLOT - std::ofstream file("gna_passes.dot"); - saveGraphToDot( - newNet, - file, - [this](const CNNLayerPtr layer, ordered_properties& printed_properties, ordered_properties& node_properties) { - AddDebugProperties(layer, printed_properties, node_properties); - }); -#endif - - auto sortedNet = CNNNetSortTopologicallyEx(newNet, make_fuzed_order); - - if (sortedNet.empty()) { - THROW_GNA_EXCEPTION << "Sorted network is empty"; - } - // Copy operations connected to memory layer (Assign to state variable) should be executed when all functional - // layers are calculated. To simplify, just moving these Copy operations at the end of the execution list - std::stable_partition(sortedNet.begin(), sortedNet.end(), [&](CNNLayerPtr layer) { - return !LayerInfo(layer).isCopyToMemory(); - }); - - std::vector sortedNoMem; - std::unordered_map> memoryPairs; - // find all memory layers pairs and mark which one used as outputs - int id = 0; - for (auto& layer : sortedNet) { - // set order id for layers to use it in compact mode - LayerInfo layerInfo(layer); - IE_SUPPRESS_DEPRECATED_START - // Increase lifetime of input data buffer needed by DelayedCopy layer to avoid overwritting buffer - // by downstream layers. - layer->userValue.v_int = layerInfo.isCopyDelayed() ? std::numeric_limits::max() : id++; - IE_SUPPRESS_DEPRECATED_END - auto generic = dynamic_cast(layer.get()); - if (generic == nullptr) { - sortedNoMem.push_back(layer); - continue; - } - - if (layerInfo.isMemory()) { - // collect all memory pairs - auto id = generic->GetParamAsString("id"); - memoryPairs[id].resize(generic->GetParamAsInt("size")); - memoryPairs[id][generic->GetParamAsInt("index")] = layer; - continue; - } else if (layerInfo.isConcat()) { - m_graph_compiler->fillConcatConnections(layer); - } else if (layerInfo.isSplit() || layerInfo.isSlice()) { - m_graph_compiler->fillSplitConnections(layer); - } - sortedNoMem.push_back(layer); - } - - // fill in extra storage with memory layers - m_graph_compiler->fillMemoryConnections(memoryPairs); - - if (!m_graph_compiler->memory_connection.empty() && gnaFlags->num_requests != 1) { - gnaFlags->num_requests = 1; - } - - // keep inputs information and create input primitives - inputs_data_map_ = newNet.getInputsInfo(); - if (inputs_data_map_.empty()) { - log::warning() << "No inputs for the topology\n"; - } - - // keep output dims - outputs_data_map_ = newNet.getOutputsInfo(); - if (outputs_data_map_.empty()) { - THROW_GNA_EXCEPTION << "No outputs for the topology"; - } - - for (auto&& input : inputs_data_map_) { - inputs_ptr_->at(input.first).ptrs.resize(gnaFlags->num_requests); - } - - // Creating Layer primitives - for (auto& layer : sortedNoMem) { - m_graph_compiler->CreateLayerPrimitive(layer); - } - - for (auto& inputLayer : inputLayers) { - auto layerInfo = LayerInfo(inputLayer); - if (layerInfo.isInput() && 0 == inputs_ptr_->at(inputLayer->name).get_allocated_size()) { - m_graph_compiler->connectOutput(inputLayer, &inputs_ptr_->at(inputLayer->name).ptrs.front(), 0); - } - } - - if (m_graph_compiler->dnnComponents.components.empty()) { - log::warning() << "No GNA primitives created based on topology. This might indicate trivial topology\n"; - trivialTopology = true; - } - - /// setting-up output layers information - int portId = 0; - for (auto&& outPort : outputs_data_map_) { - // gets output layer pointer in original topology not in cloned - auto outLayer = getCreatorLayer(outPort.second).lock(); - - // Memory layers are not dnnComponents hence we need to make switch with identity layer - if (outLayer->type == "Memory") { - // traverse memory connection to find corresponding output_memory - for (auto&& memConnection : m_graph_compiler->memory_connection) { - if (memConnection.second.getInput()->name == outLayer->name) { - // if connection is found, replace memory input layer with memory output layer - outLayer = memConnection.second.getOutput(); - break; - } - } - } - - // searching for outData represented in GNA blob - // using ufs - upper first search - log::debug() << "[UFS] searching for : " << outPort.first << " representation in GNA\n"; - bool stopSearching = false; - - CNNNetDFS( - outLayer, - [this, &outPort, &stopSearching](CNNLayerPtr layer) { - log::debug() << "[UFS] from : " << outPort.first << " reached: " << layer->name << "\n"; - stopSearching = TryToInitOutput(outPort.first, layer); - }, - true, - [&stopSearching](InferenceEngine::CNNLayer* from) { - return make_upstream_order(!stopSearching ? from : nullptr); - }); - if (!stopSearching) { - THROW_GNA_EXCEPTION << "unsupported topology: cannot locate " << outPort.first - << " after compiling GNA graph"; - } - portId++; - } - - void* pParallelExecutionData = nullptr; - - // reserving more bytes for intermediate data in parallel case - // TODO: this works incorrectly in compact mode at lest - rwSegmentSize = gnamem->getRegionBytes(REGION_SCRATCH); - rwSegmentSize += gnamem->getRegionBytes(REGION_INPUTS); - rwSegmentSize += gnamem->getRegionBytes(REGION_OUTPUTS); - if (gnaFlags->num_requests > 1) { - gnamem->getQueue(REGION_SCRATCH) - ->reserve_ptr(nullptr, &pParallelExecutionData, rwSegmentSize * (gnaFlags->num_requests - 1)); - } - - gnamem->commit(gnaFlags->compact_mode); - - dnn->Init(gnamem.get(), gnaFlags->sw_fp32 ? kDnnFloat : kDnnInt, 1); - - // TODO: this copy is unneeded; in fact, we can directly create gna structs from list - auto execOrder = m_graph_compiler->dnnComponents.getExecutionOrder(); - dnn->component.insert(dnn->component.begin(), execOrder.begin(), execOrder.end()); - - // in fp32 mode last PWL cannot be computed without that - if (!m_graph_compiler->dnnComponents.components.empty()) { - dnn->InitActiveList(NULL); - } - - auto worker = createWorkerForLoadNetwork(trivialTopology, isFP32ModeActive()); - requestWorkerPool_->addModelWorker(std::move(worker)); - - // initialize paraler requests model - // creating same gna RW segment for parallel infer requests - for (int i = 1; i != gnaFlags->num_requests; i++) { - auto basePtr = reinterpret_cast(pParallelExecutionData) + rwSegmentSize * (i - 1); - - auto relocate = [basePtr, this](void*& ptr_out, void* ptr_in) { - if (ptr_in == nullptr) { - ptr_out = nullptr; - } else { - const auto found = gnamem->getOffsetForMerged(ptr_in); - if (!found.first) { - THROW_GNA_EXCEPTION << "Relocation offset for parallel infer requests was not found\n"; - } - ptr_out = basePtr + found.second; - } - }; - - for (auto& input : inputs_ptr_->Get()) { - relocate(input.ptrs[i], input.ptrs[0]); - } - - // relocating all output pointers - for (auto& output : outputs_.Get()) { - relocate(output.ptrs[i], output.ptrs[0]); - } - - auto worker = createWorkerForLoadNetwork(trivialTopology, isFP32ModeActive()); - auto model = worker->model(); - - // relocating all operations data pointers - for (uint32_t j = 0; j != model->NumberOfOperations; j++) { - auto& gnaOperation = model->Operations[j]; - relocate(const_cast(gnaOperation.Operands[0])->Data, gnaOperation.Operands[0]->Data); - relocate(const_cast(gnaOperation.Operands[1])->Data, gnaOperation.Operands[1]->Data); - } - requestWorkerPool_->addModelWorker(std::move(worker)); - } - - // calculating input orientation without memory layers, since their orientation not changed during infer right now - std::unordered_map> skippedLayers; - - // update orientation of model intput layer - for (auto& inputLayer : inputLayers) { - if (LayerInfo(inputLayer).isInput()) { - ov::intel_gna::helpers::updateModelInputOrientationWithoutConvolution(*inputLayer, - m_graph_compiler->dnnComponents, - *inputs_ptr_); - } - } - - // update orientation of model output layer - for (auto&& outPort : outputs_data_map_) { - auto outLayer = getCreatorLayer(outPort.second).lock(); - if (outLayer && LayerInfo(outLayer).isOutput()) { - ov::intel_gna::helpers::updateModelOutputOrientation(outPort.first, - outLayer->name, - m_graph_compiler->dnnComponents, - outputs_); - } - } - - DumpXNNToFile(); - -#ifdef PLOT - dnn->WriteGraphWizModel("gna-blob.dot"); -#endif -} - -bool GNAPlugin::isFP32ModeActive() const { - return gnaFlags->sw_fp32 || !gnadevice; -} - -std::shared_ptr GNAPlugin::createWorkerForLoadNetwork(bool trivial, bool fp32Mode) { - // Do not initialize gna model for fp32 mode (create trivial model wraper) - return createWorker(createModelWrapperForLoadNetwork(trivial || fp32Mode), trivial, fp32Mode); -} - -std::shared_ptr GNAPlugin::createWorker(std::shared_ptr modelWrapper, - bool trivial, - bool fp32Mode) { - if (trivial) { - return request::WorkerFactory::createWorkerTrivialTopology(std::move(modelWrapper)); - } - - if (fp32Mode) { - if (!dnn) { - THROW_GNA_EXCEPTION << "dnn is nullptr cannot run fp32 mode"; - } - return request::WorkerFactory::createWorkerFP32(std::move(modelWrapper), dnn); - } - - // This shouldn't happend due the fact device is created when gnaFlags->sw_fp32 is false. - if (!gnadevice) { - THROW_GNA_EXCEPTION << "device is nullptr cannot run in device mode"; - } - - return request::WorkerFactory::createWorker(std::move(modelWrapper), gnadevice, config.pluginGna2AccMode); -} - -std::shared_ptr GNAPlugin::createModelWrapperForLoadNetwork(bool trivial) { - if (trivial) { - return request::ModelWrapperFactory::createTrivial(); - } - - if (!dnn) { - THROW_GNA_EXCEPTION << "dnn is nullptr cannot load network"; - } - - std::weak_ptr weakDnn = dnn; - auto initializer = [weakDnn](Gna2Model* model) { - if (auto dnn = weakDnn.lock()) { - dnn->InitGNAStruct(model); - return; - } - THROW_GNA_EXCEPTION << "dnn is nullptr"; - }; - - return request::ModelWrapperFactory::createInitialized(std::move(initializer)); -} - -std::shared_ptr GNAPlugin::createModelWrapperForImportNetwork(uint32_t numberOfOperations) { - return request::ModelWrapperFactory::createWithNumberOfEmptyOperations(numberOfOperations); -} - -void GNAPlugin::DumpXNNToFile() const { - // TODO: output precision as well as pointer might be incorrect, LSTM for sure - // gna looks automatically set layer 0 as output and adjust it's pointer / precision/ size respectively - if (config.embedded_export_path.empty()) { - return; - } - - if (!gnadevice) { - THROW_GNA_EXCEPTION << "Cannot generate XNNDump for float network"; - } - - if (requestWorkerPool_->empty()) { - THROW_GNA_EXCEPTION << "Cannot generate XNNDump for not exsisting model"; - } - - std::ofstream dumpStream(config.embedded_export_path, std::ios::out | std::ios::binary); - - auto model = const_cast(requestWorkerPool_->firstWorker().model()); - - auto const modelId = gnadevice->createModel(*model); - const auto& inputsDesc = inputs_ptr_->Get(); - const auto& outputsDesc = outputs_.Get(); - - if (config.target->get_effective_compile_target() == target::DeviceVersion::GNAEmbedded1_0) { - auto dump = gnadevice->dumpXnn(modelId); - dump.header.RwRegionSize = static_cast(gnamem->getRegionBytes(REGION_SCRATCH)); - dump.header.InputScalingFactor = inputsDesc.begin()->scale_factor; - dump.header.OutputScalingFactor = outputsDesc.begin()->scale_factor; - dumpStream.write(reinterpret_cast(&dump.header), sizeof(Gna2ModelSueCreekHeader)); - dumpStream.write(reinterpret_cast(dump.model.get()), dump.header.ModelSize); - } else { - const auto inputsForTlv = GnaEndpoint::CreateFromDescriptorContainer(inputsDesc); - const auto outputsForTlv = GnaEndpoint::CreateFromDescriptorContainer(outputsDesc); - gnadevice->dumpTLVForDeviceVersion(modelId, dumpStream, inputsForTlv, outputsForTlv); - } - gnadevice->releaseModel(modelId); -} - -uint32_t GNAPlugin::QueueInference(const InferenceEngine::BlobMap& inputs, InferenceEngine::BlobMap& result) { - if (config.GetParameter(ov::intel_gna::execution_mode.name()).as() == "GNA_HW" && - !gnadevice->isHwAvailable()) { - THROW_GNA_EXCEPTION << "Execution mode GNA_HW is set, but hardware acceleration is unavailable"; - } - auto freeWorker = requestWorkerPool_->findFreeModelWorker(); - if (freeWorker == nullptr) { - if (!m_graph_compiler->memory_connection.empty()) { - Wait(requestWorkerPool_->firstWorker().representingIndex()); - freeWorker = requestWorkerPool_->findFreeModelWorker(); - if (freeWorker == nullptr) { - THROW_GNA_EXCEPTION << "could not find free executable network for request" << std::endl; - } - } else { - IE_THROW(RequestBusy) << "GNA executable network has max of " - << static_cast(gnaFlags->num_requests) - << " parallel infer requests, please sync one of already running"; - } - } - - auto index = freeWorker->representingIndex(); - - int inputNum = 0; - for (auto& input : inputs) { - std::string input_name = input.first; - InferenceEngine::Layout input_layout = input.second->getTensorDesc().getLayout(); - - if (input_layout != InferenceEngine::Layout::C && input_layout != InferenceEngine::Layout::NC && - input_layout != InferenceEngine::Layout::CN && input_layout != InferenceEngine::Layout::CHW && - input_layout != InferenceEngine::Layout::NCHW) { - THROW_GNA_EXCEPTION << "Expected input blob to have Layout::C, Layout::NC, Layout::CN, Layout::NCHW or " - "Layout::CHW. But was: " - << input_layout; - } - - if (input_layout == InferenceEngine::Layout::NCHW || input_layout == InferenceEngine::Layout::CHW) { - // specific case that can be squeezed to 2d - input_layout = InferenceEngine::Layout::NC; - } - - auto is1D = input_layout == InferenceEngine::Layout::C; - auto is3D = input_layout == InferenceEngine::Layout::CHW; - - if (inputs_ptr_->at(input_name).ptrs.empty()) { - // should not happen in user code however might happen if there any non executable network based integration - // of GNAPlugin instance - THROW_GNA_EXCEPTION << "network not loaded : input pointer for " << input_name << " not set"; - } - - if (inputs_ptr_->at(input_name).ptrs[index] == nullptr) { - // should not happen in user code however might happen if there any non executable network based integration - // of GNAPlugin instance - THROW_GNA_EXCEPTION << "network not loaded : input pointer for (" << input_name << " at inferRequest #" - << index << " not set"; - } - const auto inputOrientation = inputs_ptr_->at(input_name).orientation; - if (inputOrientation == kDnnUnknownOrientation) { - // should not happen in user code however might happen if there any non executable network based integration - // of GNAPlugin instance - THROW_GNA_EXCEPTION << "network not loaded : input orientation for " << input_name << " not set"; - } - - for (auto& output : outputs_.Get()) { - if (output.orientation == kDnnUnknownOrientation) { - // should not happen in user code however might happen if there any non executable network based - // integration of GNAPlugin instance - THROW_GNA_EXCEPTION << "network not loaded : output orientation not set"; - } - } - - auto dims = input.second->getTensorDesc().getDims(); - auto importedElements = - is1D ? dims[0] : InferenceEngine::details::product(std::next(std::begin(dims)), std::end(dims)); - auto importedFrames = (is3D || is1D) ? 1 : dims[0]; - auto targetGroups = is1D ? 1 : dims[0]; // TODO: no proper support for groups yet - - auto importedElementSizeBytes = gnaFlags->sw_fp32 ? 4 : (gnaFlags->input_low_precision ? 1 : 2); - auto importedBytes = importedElements * importedFrames * importedElementSizeBytes; - - if (inputs_ptr_->at(input_name).get_required_size() < importedBytes) { - THROW_GNA_EXCEPTION << "Cannot import input frames for :" << input_name - << ", allocated size: " << inputs_ptr_->at(input_name).get_required_size() - << ", but input blob size: " << importedBytes; - } - - // Perform pre-processing on CPU. - // When we need to perform pre-processing on CPU using ngraph model we copy user input to the buffer, - // then set preprocessing output blob as gna input blob. - std::shared_ptr model = inputs_ptr_->at(input_name).pre_post_process_model; - Blob::Ptr buff_blob = nullptr; - TensorDesc buff_tensor_desc(input.second->getTensorDesc()); - buff_tensor_desc.setPrecision(inputs_ptr_->at(input_name).tensor_precision); - - if (model) { - // WA: evaluate gather with int16 precision as fp16 - if (buff_tensor_desc.getPrecision() == Precision::I16) { - buff_tensor_desc.setPrecision(Precision::FP16); - } - buff_blob = make_blob_with_precision(buff_tensor_desc); - buff_blob->allocate(); - } else { - buff_blob = make_blob_with_precision(buff_tensor_desc, inputs_ptr_->at(input_name).ptrs[index]); - } - - m_input_output_handler.import_frames( - buff_blob->buffer(), - input.second->cbuffer().as(), - input.second->getTensorDesc().getPrecision(), - gnaFlags->sw_fp32 ? kScaleFactorDefault : inputs_ptr_->at(input_name).scale_factor, - inputOrientation, - importedFrames, - targetGroups, - importedElements, - importedElements, - gnaFlags->input_low_precision, - gnadevice.get() != nullptr); - - if (model) { - Precision output_prc = buff_blob->getTensorDesc().getPrecision(); - SizeVector output_dims = model->get_result()->get_shape(); - TensorDesc output_desc(output_prc, output_dims, InferenceEngine::Layout::ANY); - Blob::Ptr output_blob = make_blob_with_precision(output_desc, inputs_ptr_->at(input_name).ptrs[index]); - PrePostProcess(buff_blob, output_blob, model); - } - - ++inputNum; - } - - if (!freeWorker->enqueueRequest()) { - THROW_GNA_EXCEPTION << "Error with enqueueing inference request"; - } - - freeWorker->setResult(result); - -#ifdef PLOT - dnn->BeginNewWrite(dnn_dump_write_index); - if (dnn->num_components() != 0) { - dnn->WriteDnnText("Net_.txt", kDnnFloat); - } - dnn_dump_write_index++; -#endif - - return index; -} - -bool GNAPlugin::Wait(uint32_t request_idx) { - auto result = WaitFor(request_idx, MAX_TIMEOUT); - - if (result == RequestStatus::kCompletedWithError) { - THROW_GNA_EXCEPTION << "Error when waiting for inference results!"; - } - - return result == RequestStatus::kCompleted; -} - -RequestStatus GNAPlugin::WaitFor(uint32_t request_idx, int64_t millisTimeout) { - // TODO: GNA2: check whether - if (requestWorkerPool_->size() <= request_idx) { - return RequestStatus::kCompleted; - } - - auto& worker = requestWorkerPool_->worker(request_idx); - - if (worker.isFree()) { - return RequestStatus::kCompleted; - } - - const auto waitStatus = worker.wait(millisTimeout); - - if (waitStatus == RequestStatus::kCompletedWithError) { - return waitStatus; - } - - if (waitStatus == RequestStatus::kAborted) { - return waitStatus; - } - - if (waitStatus == RequestStatus::kPending) { - return waitStatus; - } - - auto& requestResult = worker.result(); - -#ifdef PLOT - if (dnn->num_components() != 0) { - dnn->WriteInputAndOutputText(); - } - - // TODO test - dnn->WriteInputAndOutputTextGNA(*worker.model()); -#endif - for (auto&& outputBlobIt : requestResult) { - const std::string& output_name = outputBlobIt.first; - Blob::Ptr output_blob = outputBlobIt.second; - const InferenceEngine::Layout output_layout = output_blob->getTensorDesc().getLayout(); - - if (output_layout != InferenceEngine::Layout::C && output_layout != InferenceEngine::Layout::NC && - output_layout != InferenceEngine::Layout::CN && output_layout != InferenceEngine::Layout::NCHW && - output_layout != InferenceEngine::Layout::CHW && output_layout != InferenceEngine::Layout::SCALAR) { - THROW_GNA_EXCEPTION << "Expected output blob to have Layout::C, Layout::NC, Layout::CN, Layout::NCHW or " - "Layout::CHW. But was " - << output_layout; - } - - auto dims = output_blob->getTensorDesc().getDims(); - auto is1D = output_layout == InferenceEngine::Layout::C; - auto isScalar = output_layout == InferenceEngine::Layout::SCALAR; - auto is3D = output_layout == InferenceEngine::Layout::CHW; - size_t batchSize = (is1D || isScalar || is3D) ? 1 : dims[0]; - size_t elementsPerBatch = - isScalar ? 1 : (is1D ? dims.front() : details::product(++std::begin(dims), std::end(dims))); - - OutputDesc& gna_output_desc = outputs_.at(output_name); - Blob::Ptr gna_output_blob = nullptr; - - // Perform postprocessing on CPU - std::shared_ptr model = gna_output_desc.pre_post_process_model; - if (model) { - // WA: evaluate gather with int16 precision as fp16 - Precision preproc_prc = (gna_output_desc.tensor_precision == Precision::I16) - ? Precision(Precision::FP16) - : gna_output_desc.tensor_precision; - const SizeVector& input_dims = model->get_parameters().front()->get_shape(); - TensorDesc input_desc(preproc_prc, input_dims, InferenceEngine::Layout::ANY); - Blob::Ptr input_blob = make_blob_with_precision(input_desc, gna_output_desc.ptrs[request_idx]); - - const SizeVector& output_dims = model->get_result()->get_shape(); - TensorDesc output_desc(preproc_prc, output_dims, InferenceEngine::Layout::ANY); - gna_output_blob = make_blob_with_precision(output_desc); - gna_output_blob->allocate(); - - PrePostProcess(input_blob, gna_output_blob, model); - } else { - log::debug() << "Postprocessing for output " << output_name << " is not required" << std::endl; - TensorDesc output_desc(gna_output_desc.tensor_precision, - gna_output_desc.dims, - gna_output_desc.model_layout); - gna_output_blob = make_blob_with_precision(output_desc, gna_output_desc.ptrs[request_idx]); - } - - if (!gnadevice) { - m_input_output_handler.export_scores(output_blob->buffer(), - gna_output_blob->cbuffer(), - gna_output_desc.orientation, - batchSize, - batchSize, - elementsPerBatch, - elementsPerBatch, - elementsPerBatch, - gna_output_desc.tensor_precision, - Precision::I32, - 1.0f); - } else { - m_input_output_handler.export_scores(output_blob->buffer(), - gna_output_blob->cbuffer(), - gna_output_desc.orientation, - batchSize, - batchSize, - elementsPerBatch, - elementsPerBatch, - elementsPerBatch, - gna_output_desc.tensor_precision, - gna_output_desc.model_precision, - gna_output_desc.scale_factor); - -#ifdef PLOT - FILE* f = nullptr; - static int num_infers = 0; - { - f = std::fopen("ex_scores.txt", "w"); - if (!f) { - THROW_GNA_EXCEPTION << "ex_scores.txt opening failed"; - } - } - num_infers++; - if (f) { - if (isScalar) { - fprintf(f, "%d ", output_blob->cbuffer().as()[0]); - } else { - for (int i = 0; i < batchSize; i++) { - for (int j = 0; j < dims[dims.size() - 1]; j++) { - fprintf(f, "%d ", output_blob->cbuffer().as()[dims[dims.size() - 1] * i + j]); - } - fprintf(f, "\n"); - } - } - fprintf(f, "\n\n"); - } - if (f) { - if (isScalar) { - fprintf(f, "%.7f ", output_blob->cbuffer().as()[0]); - } else { - auto dims = output_blob->getTensorDesc().getDims(); - for (int i = 0; i < batchSize; i++) { - for (int j = 0; j < dims[dims.size() - 1]; j++) { - fprintf(f, "%.7f ", output_blob->cbuffer().as()[dims[dims.size() - 1] * i + j]); - } - fprintf(f, "\n"); - } - } - fclose(f); - } -#endif - } - } - return RequestStatus::kCompleted; -} - -void GNAPlugin::Reset() { - m_graph_compiler->Reset(); -} - -bool GNAPlugin::Infer(const InferenceEngine::Blob& input, InferenceEngine::Blob& output) { - BlobMap bmInput; - BlobMap bmOutput; - if (inputs_data_map_.size() != 1) { - THROW_GNA_EXCEPTION << "cannot infer using Infer(Blob&, Blob&)" - << "model accepts " << inputs_data_map_.size() << " inputs"; - } - - IE_ASSERT(!inputs_data_map_.empty()); - bmInput[inputs_data_map_.begin()->first] = std::shared_ptr(const_cast(&input), [](Blob*) {}); - IE_ASSERT(!outputs_data_map_.empty()); - bmOutput[outputs_data_map_.begin()->first] = std::shared_ptr(&output, [](Blob*) {}); - return Infer(bmInput, bmOutput); -} - -bool GNAPlugin::Infer(const InferenceEngine::BlobMap& input, InferenceEngine::BlobMap& result) { - return Wait(QueueInference(input, result)); -} - -static InferenceEngine::Layout GetLayoutForDims(const InferenceEngine::SizeVector& dims) { - switch (dims.size()) { - case 0: - return SCALAR; - case 1: - return C; - case 2: - return NC; - case 3: - return CHW; - case 4: - return NCHW; - default: - THROW_GNA_EXCEPTION << "Unsupported dimensions size in GNA: " << dims.size(); - } -} - -Blob::Ptr GNAPlugin::GetOutputBlob(const std::string& name, InferenceEngine::Precision precision) { - // need to have intermediate blob for interleave conversion - InferenceEngine::Blob::Ptr outputBlob; - auto outputDataIt = outputs_data_map_.find(name); - if (outputDataIt == std::end(outputs_data_map_)) { - THROW_GNA_EXCEPTION << "Output " << name << " isn't found"; - } - auto outputDims = outputDataIt->second->getTensorDesc().getDims(); - outputBlob = make_blob_with_precision(TensorDesc(precision, outputDims, GetLayoutForDims(outputDims))); - outputBlob->allocate(); - return outputBlob; -} - -Blob::Ptr GNAPlugin::GetInputBlob(const std::string& name, InferenceEngine::Precision precision) { - InferenceEngine::Blob::Ptr inputBlob; - // need to have intermediate blob for interleave conversion - // TODO: NCHW format support is experimental = c++ MO did insert reshape, while TF mo - not - auto inputDataIt = inputs_data_map_.find(name); - if (inputDataIt == std::end(inputs_data_map_)) { - THROW_GNA_EXCEPTION << "Input " << name << " isn't found"; - } - auto inputDims = inputDataIt->second->getTensorDesc().getDims(); - inputBlob = make_blob_with_precision(TensorDesc(precision, inputDims, GetLayoutForDims(inputDims))); - inputBlob->allocate(); - return inputBlob; -} - -std::vector GNAPlugin::QueryState() { - if (memoryStates.size() != m_graph_compiler->memory_connection.size()) { - memoryStates.clear(); - for (auto& connection : m_graph_compiler->memory_connection) { - auto state = - std::make_shared(connection.first, - std::make_shared(connection.second)); - memoryStates.emplace_back(state); - } - } - return memoryStates; -} - -std::string GNAPlugin::GetName() const noexcept { - return _pluginName; -} - -void GNAPlugin::SetName(const std::string& pluginName) noexcept { - _pluginName = pluginName; -} - -InferenceEngine::IExecutableNetworkInternal::Ptr GNAPlugin::ImportNetwork(std::istream& networkModel) { - auto header = GNAModelSerial::ReadHeader(networkModel); - - void* basePtr = nullptr; - std::string modelLibVersion; //!< OpenVINO and GNA Library versions read from GNA model file - - gnamem->getQueue(REGION_SCRATCH)->reserve_ptr(nullptr, &basePtr, header.gnaMemSize, false); - - gnamem->commit(); - - auto model = createModelWrapperForImportNetwork(static_cast(header.layersCount)); - GNAModelSerial::MemoryType mt; - auto serial = GNAModelSerial(&model->object(), mt); - - serial.setHeader(header); - serial.Import(basePtr, - header.gnaMemSize, - networkModel, - *(inputs_ptr_), - outputs_, - transpose_inputs_info, - transpose_outputs_info, - modelLibVersion); - - // Print OV and GNA Lib versions used for model export - if (gnaFlags->log_level >= ov::log::Level::DEBUG) { - if (modelLibVersion.length()) { - std::cout << modelLibVersion << std::endl; - } else { - std::cout - << "Unable to read OpenVINO or GNA Library version from model file, consider model export with current " - "version of GNA plugin" - << std::endl; - } - } - - trivialTopology = (model->object().NumberOfOperations == 0); - - requestWorkerPool_->addModelWorker(createWorker(model, trivialTopology, isFP32ModeActive())); - - SetNetworkInputs(); - SetNetworkOutputs(); - - ov::intel_gna::helpers::ApplyInputScaleFactors(*inputs_ptr_, config, header); - - auto getOrientation = [](Gna2Operation& gnaOperation) { - return gnaOperation.Type == Gna2OperationTypeConvolution ? kDnnNonInterleavedOrientation - : kDnnInterleavedOrientation; - }; - (void)getOrientation; - - if (header.doRotateInput) { - for (auto&& input : inputs_data_map_) { - transpose_inputs_info.insert( - {input.first, {{header.doRotateInput, header.nRotateRows, header.nRotateColumns}}}); - } - } - if (header.doRotateOutput) { - for (auto&& output : outputs_data_map_) { - transpose_outputs_info.insert( - {output.first, {{header.doRotateOutput, header.nRotateOutputRows, header.nRotateOutputColumns}}}); - } - } - - // Support model versions <= 2.8 - if (!transpose_inputs_info.empty()) { - ConvertTransposeMapToModel(transpose_inputs_info, inputs_ptr_->Get()); - } - if (!transpose_outputs_info.empty()) { - ConvertTransposeMapToModel(transpose_outputs_info, outputs_.Get()); - } - - for (auto&& memory : mt) { - GNAMemoryLayer memoryLayer(nullptr, nullptr, gnaFlags->sw_fp32 ? 4 : 2); - std::string name; - std::tie(memoryLayer.gna_ptr, memoryLayer.reserved_size, name, memoryLayer.scale_factor) = memory; - m_graph_compiler->memory_connection.emplace_back(make_pair(name, memoryLayer)); - } - - // TODO update documenation to allow exporting tlv with importing cep only for sue creek - // TODO tlv + cep import + export - DumpXNNToFile(); - -#ifdef PLOT - dnn->WriteGraphWizModel("gna-blob-imported.dot"); -#endif - return {}; -} - -void GNAPlugin::Export(const std::string& fileName) { - std::fstream outStream(fileName, ios_base::out | ios_base::binary); - Export(outStream); -} - -void GNAPlugin::Export(std::ostream& outStream) { - if (inputs_ptr_->empty() || outputs_.empty()) { - THROW_GNA_EXCEPTION << " network not loaded"; - } - - // TODO: nnet group parameter looks only used in application - so can we move this line into load network. - IE_ASSERT(!inputs_data_map_.empty()); - auto inputDims = inputs_data_map_.begin()->second->getTensorDesc().getDims(); - - Gna2Model* model_to_serial = requestWorkerPool_->firstWorker().model(); - auto serial = GNAModelSerial(model_to_serial, *(inputs_ptr_), outputs_) - .SetInputRotation(transpose_inputs_info) - .SetOutputRotation(transpose_outputs_info); - - for (auto&& memoryConnection : m_graph_compiler->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); -} - -std::map GNAPlugin::GetPerformanceCounts() { - if (gnaFlags->performance_counting) { - std::map perfMap; - gnadevice->getGnaPerfCounters(perfMap); - return perfMap; - } else { - return {}; - } -} - -void GNAPlugin::AddExtension(const InferenceEngine::IExtensionPtr& extension) {} - -void GNAPlugin::SetConfig(const std::map& config_map) { - config.UpdateFromMap(config_map); - UpdateFieldsFromConfig(); -} - -void GNAPlugin::UpdateFieldsFromConfig() { - *gnaFlags = config.gnaFlags; -} - -void GNAPlugin::SetNetworkInputs() { - inputs_data_map_.clear(); - for (auto& input : inputs_ptr_->Get()) { - inputs_data_map_[input.name] = input.ToIEInputInfo(); - } -} - -void GNAPlugin::SetNetworkOutputs() { - outputs_data_map_.clear(); - for (auto& output : outputs_.Get()) { - outputs_data_map_[output.name] = output.to_ie_data(); - } -} - -std::vector> GNAPlugin::GetInputs() { - std::vector> params; - params.reserve(inputs_ptr_->size()); - for (auto&& input : inputs_ptr_->Get()) { - auto param = std::make_shared(convertPrecision(input.model_precision), - ov::PartialShape(input.dims)); - param->set_friendly_name(input.name); - param->get_output_tensor(0).add_names(input.tensor_names); - params.emplace_back(move(param)); - } - return params; -} - -std::vector> GNAPlugin::GetOutputs() { - std::vector> results; - results.reserve(outputs_.size()); - for (auto&& output : outputs_.Get()) { - auto param = std::make_shared(convertPrecision(output.model_precision), - ov::PartialShape(output.dims)); - param->set_friendly_name(output.name); - auto result = std::make_shared(param); - result->get_output_tensor(0).add_names(output.tensor_names); - results.emplace_back(std::move(result)); - } - return results; -} - -InferenceEngine::QueryNetworkResult GNAPlugin::QueryNetwork( - const InferenceEngine::CNNNetwork& network, - const std::map& config_map) const { - InferenceEngine::QueryNetworkResult res; - - Config qn_config(config); - qn_config.UpdateFromMap(config_map); - - auto model = network.getFunction(); - if (model) { - auto supported = GetSupportedNodes( - model, - [&](std::shared_ptr& model) { - TransformationsPipeline(qn_config).apply(model); - }, - [&](const std::shared_ptr& op) { - const auto res = Limitations::get_instance()->is_op_supported(op, qn_config.gnaPrecision); - return res; - }); - for (auto&& op_name : supported) { - res.supportedLayersMap.emplace(op_name, GetName()); - } - return res; - } - - std::unordered_set allLayers; - InferenceEngine::InputsDataMap inputs = network.getInputsInfo(); - std::vector sortedLayers = CNNNetSortTopologically(network); - - if (inputs.empty()) { - THROW_GNA_EXCEPTION << "Network is empty (GNA)\n"; - } - - auto const& secondLayers = getInputTo(inputs.begin()->second->getInputData()); - if (secondLayers.empty()) { - THROW_GNA_EXCEPTION << "Network consists of input layer only (GNA)\n"; - } - - InferenceEngine::details::UnorderedDFS( - allLayers, - secondLayers.begin()->second, - [&](CNNLayerPtr const& layer) { - if (LayerTypeFromStr(layer->type) != LayerType::NO_TYPE) { - res.supportedLayersMap.insert({layer->name, GetName()}); - } - }, - false); - - return res; -} - -GNAPlugin::~GNAPlugin() { - if (gnadevice) - gnadevice->close(); - - Limitations::deinit(); -} diff --git a/src/plugins/intel_gna/src/gna_plugin.hpp b/src/plugins/intel_gna/src/gna_plugin.hpp deleted file mode 100644 index bddd7ad51c4..00000000000 --- a/src/plugins/intel_gna/src/gna_plugin.hpp +++ /dev/null @@ -1,244 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "backend/am_intel_dnn.hpp" -#include "cpp_interfaces/interface/ie_ivariable_state_internal.hpp" -#include "descriptions/gna_desc.hpp" -#include "descriptions/gna_flags.hpp" -#include "gna_data_types.hpp" -#include "gna_graph_compiler.hpp" -#include "gna_plugin_config.hpp" -#include "log/debug.hpp" -#include "log/log.hpp" -#include "pre_post_process/input_output_data_handler.hpp" -#include "pre_post_process/transposition_info.hpp" - -namespace ov { -namespace intel_gna { -namespace request { -class ModelWrapper; -class WorkerPool; -class Worker; -} // namespace request - -using namespace ov::intel_gna::pre_post_processing; - -class GNAPlugin : public InferenceEngine::IInferencePlugin { -protected: - std::string _pluginName = "GNA"; - - Config config{}; - std::shared_ptr dnn; - std::shared_ptr gnaFlags; - std::shared_ptr gnamem; - std::shared_ptr inputs_ptr_; - GnaOutputs outputs_; - std::shared_ptr m_graph_compiler; - pre_post_processing::InputOutputDataHandler m_input_output_handler; - - uint32_t activeLayerIndex = 0xffffffff; - // TODO: transpose_inputs_info and transpose_outputs_info should be moved to GNAModelSerial class when ngraph - // migration is finished. Those structures are needed to support the exported models <= 2.8. - pre_post_processing::TranspositionInfoMap transpose_inputs_info; - pre_post_processing::TranspositionInfoMap transpose_outputs_info; - PrePostProcessModels m_input_output_subgraphs; - - uint32_t dnn_dump_write_index = 0; - intel_dnn_number_type_t output_type = kDnnInt; - - std::shared_ptr gnadevice; - - std::shared_ptr requestWorkerPool_; - - /** - * @brief size of RW segment without extra memory for parallel execution - */ - size_t rwSegmentSize = 0; - - InferenceEngine::InputsDataMap inputs_data_map_; //!< Holds information about network inputs info - InferenceEngine::OutputsDataMap outputs_data_map_; //!< Holds information about network outputs data - - std::string _network_name; - - std::vector memoryStates; - bool trivialTopology = false; - -public: - explicit GNAPlugin(const std::map& configMap); - /** - * @brief construct from aot rather then from cnn network - */ - GNAPlugin(); - - GNAPlugin(const GNAPlugin&) = delete; - GNAPlugin(GNAPlugin&&) = default; - - std::string GetName() const noexcept override; - void SetName(const std::string& pluginName) noexcept override; - - using InferenceEngine::IInferencePlugin::LoadNetwork; - void LoadNetwork(const InferenceEngine::CNNNetwork& network); - - bool Infer(const InferenceEngine::BlobMap& input, InferenceEngine::BlobMap& result); - std::map GetPerformanceCounts(); - void AddExtension(const InferenceEngine::IExtensionPtr& extension) override; - - void SetConfig(const std::map& config) override; - bool Infer(const InferenceEngine::Blob& input, InferenceEngine::Blob& result); - void Reset(); - InferenceEngine::QueryNetworkResult QueryNetwork(const InferenceEngine::CNNNetwork& network, - const std::map& config) const override; - uint32_t QueueInference(const InferenceEngine::BlobMap& input, InferenceEngine::BlobMap& result); - bool Wait(uint32_t idx); - RequestStatus WaitFor(uint32_t idx, int64_t millisTimeout); - - InferenceEngine::Parameter GetConfig( - const std::string& name, - const std::map& options) const override; - InferenceEngine::Parameter GetMetric( - const std::string& name, - const std::map& options) const override; - std::shared_ptr CreateContext(const InferenceEngine::ParamMap& params) override { - THROW_GNA_EXCEPTION << "Not implemented"; - } - std::shared_ptr GetDefaultContext(const InferenceEngine::ParamMap&) override { - THROW_GNA_EXCEPTION << "Not implemented"; - } - - void Wait(uint32_t sync, InferenceEngine::Blob& result) { - THROW_GNA_EXCEPTION << "Not implemented"; - } - - void Export(const std::string& fileName); - void Export(std::ostream& networkModel); - InferenceEngine::IExecutableNetworkInternal::Ptr ImportNetwork( - const std::string& modelFileName, - const std::map& config) override { - THROW_GNA_EXCEPTION << "Not implemented"; - } - InferenceEngine::IExecutableNetworkInternal::Ptr ImportNetwork( - std::istream& networkModel, - const std::shared_ptr& context, - const std::map& config) override { - THROW_GNA_EXCEPTION << "Not implemented"; - } - - InferenceEngine::IExecutableNetworkInternal::Ptr ImportNetwork( - std::istream& networkModel, - const std::map& config) override { - THROW_GNA_EXCEPTION << "Not implemented"; - } - - InferenceEngine::IExecutableNetworkInternal::Ptr ImportNetwork(std::istream& networkModel); - - /** - * utility to provide input and output blobs externally to be used by InferenceEngine request API clients - */ - InferenceEngine::Blob::Ptr GetInputBlob(const std::string& name, InferenceEngine::Precision precision); - InferenceEngine::Blob::Ptr GetOutputBlob(const std::string& name, InferenceEngine::Precision precision); - /** - * helpers to provide inputs info on AOT network - */ - InferenceEngine::InputsDataMap GetNetworkInputs() { - return inputs_data_map_; - } - InferenceEngine::OutputsDataMap GetNetworkOutputs() { - return outputs_data_map_; - } - std::vector> GetOutputs(); - std::vector> GetInputs(); - /** - * helpers to set inputs/output info on AOT network - */ - void SetNetworkInputs(); - void SetNetworkOutputs(); - /** - * helpers to update internal inputs/output descriptions from loaded network - */ - void UpdateInputs(const std::vector>& params); - void UpdateOutputs(const std::vector>& results); - /** - * QueryState API - * @return - */ - INFERENCE_ENGINE_DEPRECATED("Use InferRequest::QueryState instead") - std::vector QueryState(); - - /** - * QueryMetrics API - */ - InferenceEngine::Parameter GetAvailableDevices() const; - - ~GNAPlugin(); - -protected: - void Init(); - - void InitGNADevice(); - void InitGNAMemory(); - void InitGraphCompiler(); - - void DumpXNNToFile() const; - /** - * @brief Run ngraph model on CPU to modify input or output (transposing, gathering) - * Method supports only models with 1 input and 1 output. - * @param input_blob input blob memory - * @param output_blob output blob memory - * @param model ngraph function needs to be executed to modify input blob and put result to the output blob - * @return void - */ - void PrePostProcess(InferenceEngine::Blob::Ptr input_blob, - InferenceEngine::Blob::Ptr output_blob, - std::shared_ptr model); - - /** - * Run ngraph model on CPU to modify inputs/outputs - */ - void pre_post_process(InferenceEngine::Blob::Ptr input_blob, - InferenceEngine::Blob::Ptr output_blob, - std::shared_ptr model); - void UpdateFieldsFromConfig(); - void UpdateInputScaleFromNetwork(InferenceEngine::CNNNetwork& network); - void UpdateInputsAndOutputsInfoFromNetwork(InferenceEngine::CNNNetwork&); - void UpdateInputsAndOutputsInfoFromModel(std::shared_ptr model); - /** - * @brief Tries to init an output on the base of a layer data - * @param portId output port identificator - * @param layer layer pointer - * @return true if the output is initiated, false otherwise - */ - bool TryToInitOutput(const std::string& portName, InferenceEngine::CNNLayerPtr layer); - bool isFP32ModeActive() const; - std::shared_ptr createModelWrapperForLoadNetwork(bool trivial); - std::shared_ptr createModelWrapperForImportNetwork(uint32_t numberOfOperations); - std::shared_ptr createWorkerForLoadNetwork(bool trivial, bool fp32Mode); - std::shared_ptr createWorker(std::shared_ptr modelWrapper, - bool trivial, - bool fp32Mode); - -#ifdef PLOT - void AddDebugProperties(const InferenceEngine::CNNLayerPtr layer, - InferenceEngine::ordered_properties& printed_properties, - InferenceEngine::ordered_properties& node_properties); -#endif -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_plugin_config.cpp b/src/plugins/intel_gna/src/gna_plugin_config.cpp deleted file mode 100644 index 64dfaafb9d6..00000000000 --- a/src/plugins/intel_gna/src/gna_plugin_config.cpp +++ /dev/null @@ -1,426 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_plugin_config.hpp" - -#include -#include -#include -#include -#include - -#include "common/gna_target.hpp" -#include "common/numerical_utils.hpp" -#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" -#include "gna_plugin.hpp" -#include "ie_common.h" -#include "log/log.hpp" -#include "openvino/runtime/common.hpp" -#include "openvino/runtime/intel_gna/properties.hpp" - -using namespace InferenceEngine; -using namespace InferenceEngine::details; - -namespace ov { -namespace intel_gna { -using namespace target; - -const uint8_t Config::max_num_requests; - -OPENVINO_SUPPRESS_DEPRECATED_START -static const caseless_unordered_map> supported_values = { - {GNAConfigParams::GNA_AUTO, {Gna2AccelerationModeAuto, false}}, - {GNAConfigParams::GNA_HW, {Gna2AccelerationModeHardware, false}}, - {GNAConfigParams::GNA_HW_WITH_SW_FBACK, {Gna2AccelerationModeHardwareWithSoftwareFallback, false}}, - {GNAConfigParams::GNA_SW, {Gna2AccelerationModeSoftware, false}}, - {GNAConfigParams::GNA_SW_EXACT, {Gna2AccelerationModeSoftware, true}}, - {GNAConfigParams::GNA_GEN, {Gna2AccelerationModeGeneric, false}}, - {GNAConfigParams::GNA_GEN_EXACT, {Gna2AccelerationModeGeneric, true}}, - {GNAConfigParams::GNA_SSE, {Gna2AccelerationModeSse4x2, false}}, - {GNAConfigParams::GNA_SSE_EXACT, {Gna2AccelerationModeSse4x2, true}}, - {GNAConfigParams::GNA_AVX1, {Gna2AccelerationModeAvx1, false}}, - {GNAConfigParams::GNA_AVX1_EXACT, {Gna2AccelerationModeAvx1, true}}, - {GNAConfigParams::GNA_AVX2, {Gna2AccelerationModeAvx2, false}}, - {GNAConfigParams::GNA_AVX2_EXACT, {Gna2AccelerationModeAvx2, true}}, -}; -OPENVINO_SUPPRESS_DEPRECATED_END - -void Config::UpdateFromMap(const std::map& config) { - for (auto&& item : config) { - auto key = item.first; - auto value = item.second; - - auto check_scale_factor = [&](float scale_factor) { - if (common::AreFpEq(scale_factor, 0.0f) || std::isinf(scale_factor)) { - THROW_GNA_EXCEPTION << "input scale factor of 0.0f or +-inf not supported"; - } - }; - - auto check_compatibility = [&](const std::string& recommended_key) { - if (config.count(recommended_key)) { - if (value != config.at(recommended_key)) { - THROW_GNA_EXCEPTION << "Both " << key << " and " << recommended_key - << " properties are specified! Please use " << recommended_key << " only!"; - } - } - }; - - auto get_max_num_requests = [&]() -> uint8_t { - uint64_t num_requests; - try { - num_requests = std::stoul(value); - if (num_requests == 0 || num_requests > Config::max_num_requests) { - throw std::out_of_range(""); - } - } catch (std::invalid_argument&) { - THROW_GNA_EXCEPTION << "Invalid value of number of requests/threads"; - } - return static_cast(num_requests); - }; - - auto set_target = [&](const DeviceVersion& target_version) { - if (key == GNA_CONFIG_KEY(EXEC_TARGET) || key == ov::intel_gna::execution_target) { - target->set_user_set_execution_target(target_version); - if (target->get_user_set_compile_target() == DeviceVersion::NotSet) - target->set_user_set_compile_target(target_version); - } else { - target->set_user_set_compile_target(target_version); - } - }; - - if (key == ov::intel_gna::scale_factors_per_input) { - inputScaleFactorsPerInput = ov::util::from_string(value, ov::intel_gna::scale_factors_per_input); - for (auto&& sf : inputScaleFactorsPerInput) { - check_scale_factor(sf.second); - } - } else if (key.find(GNA_CONFIG_KEY(SCALE_FACTOR)) == 0) { - check_compatibility(ov::intel_gna::scale_factors_per_input.name()); - uint64_t input_index; - if (key == GNA_CONFIG_KEY(SCALE_FACTOR)) { - input_index = 0; - } else { - key.erase(0, strlen(GNA_CONFIG_KEY(SCALE_FACTOR))); - if (key[0] != '_') { - THROW_GNA_EXCEPTION << "Invalid format of scale factor configuration key"; - } - key.erase(0, 1); - try { - input_index = std::stoi(key); - if (input_index > 99) { - throw std::out_of_range(""); - } - } catch (std::invalid_argument&) { - THROW_GNA_EXCEPTION << "Invalid value of index of input scale factor"; - } catch (std::out_of_range&) { - THROW_GNA_EXCEPTION << "Index of input scale factor must be in the range [0..99], " << key - << " provided"; - } - } - auto scale_factor = InferenceEngine::CNNLayer::ie_parse_float(value); - check_scale_factor(scale_factor); - // missing scale factors are set to be 1.0f - if (inputScaleFactors.size() <= input_index) { - inputScaleFactors.resize(input_index + 1, kScaleFactorDefault); - } - inputScaleFactors[input_index] = InferenceEngine::CNNLayer::ie_parse_float(value); - } else if (key == GNA_CONFIG_KEY(FIRMWARE_MODEL_IMAGE) || key == ov::intel_gna::firmware_model_image_path) { - embedded_export_path = value; - OPENVINO_SUPPRESS_DEPRECATED_START - } else if (key == GNA_CONFIG_KEY(DEVICE_MODE) || key == ov::intel_gna::execution_mode) { - auto procType = supported_values.find(value); - if (procType == supported_values.end()) { - if (value == GNA_CONFIG_VALUE(SW_FP32)) { - gnaFlags.sw_fp32 = true; - } else { - THROW_GNA_EXCEPTION << "GNA device mode unsupported: " << value; - } - } else { - gnaFlags.sw_fp32 = false; - pluginGna2AccMode = procType->second.first; - swExactMode = procType->second.second; - } - OPENVINO_SUPPRESS_DEPRECATED_END - } else if (key == ov::intel_gna::execution_target || key == ov::intel_gna::compile_target) { - auto target = ov::util::from_string(value, ov::intel_gna::execution_target); - set_target(HwGenerationToDevice(target)); - } else if (key == GNA_CONFIG_KEY(EXEC_TARGET)) { - check_compatibility(ov::intel_gna::execution_target.name()); - set_target(StringToDevice(value)); - } else if (key == GNA_CONFIG_KEY(COMPILE_TARGET)) { - const auto target = StringToDevice(value); - check_compatibility(ov::intel_gna::compile_target.name()); - set_target(target); - } else if (key == GNA_CONFIG_KEY(COMPACT_MODE) || key == ov::intel_gna::memory_reuse) { - if (value == PluginConfigParams::YES) { - gnaFlags.compact_mode = true; - } else if (value == PluginConfigParams::NO) { - gnaFlags.compact_mode = false; - } else { - THROW_GNA_EXCEPTION << "GNA compact mode should be true/false (YES/NO), but not " << value; - } - } else if (key == ov::internal::exclusive_async_requests) { - if (value == PluginConfigParams::YES) { - gnaFlags.exclusive_async_requests = true; - } else if (value == PluginConfigParams::NO) { - gnaFlags.exclusive_async_requests = false; - } else { - THROW_GNA_EXCEPTION << "ov::internal::exclusive_async_requests should be YES/NO, but not" << value; - } - } else if (key == ov::hint::performance_mode) { - performance_mode = ov::util::from_string(value, ov::hint::performance_mode); - } else if (key == ov::hint::inference_precision) { - inference_precision = ov::util::from_string(value); - if ((inference_precision != ov::element::i8) && (inference_precision != ov::element::i16)) { - THROW_GNA_EXCEPTION << "Unsupported precision of GNA hardware, should be I16 or I8, but was: " << value; - } - gnaPrecision = inference_precision == ov::element::i8 ? InferenceEngine::Precision::I8 - : InferenceEngine::Precision::I16; - } else if (key == ov::hint::execution_mode) { - execution_mode = ov::util::from_string(value); - if ((execution_mode != ov::hint::ExecutionMode::ACCURACY) && - (execution_mode != ov::hint::ExecutionMode::PERFORMANCE)) { - THROW_GNA_EXCEPTION << "Unsupported execution mode, should be ACCURACY or PERFORMANCE, but was: " - << value; - } - // Update gnaPrecision basing on execution_mode only if inference_precision is not set - if (config.count(ov::hint::inference_precision.name()) == 0) { - gnaPrecision = execution_mode == ov::hint::ExecutionMode::PERFORMANCE ? InferenceEngine::Precision::I8 - : InferenceEngine::Precision::I16; - } - } else if (key == GNA_CONFIG_KEY(PRECISION)) { - auto precision = Precision::FromStr(value); - if (precision != Precision::I8 && precision != Precision::I16) { - THROW_GNA_EXCEPTION << "Unsupported precision of GNA hardware, should be Int16 or Int8, but was: " - << value; - } - gnaPrecision = precision; - } else if (key == ov::intel_gna::pwl_design_algorithm) { - gnaFlags.pwl_design_algorithm = ov::util::from_string(value, ov::intel_gna::pwl_design_algorithm); - gnaFlags.uniformPwlDesign = - (gnaFlags.pwl_design_algorithm == ov::intel_gna::PWLDesignAlgorithm::UNIFORM_DISTRIBUTION) ? true - : false; - OPENVINO_SUPPRESS_DEPRECATED_START - } else if (key == GNA_CONFIG_KEY(PWL_UNIFORM_DESIGN)) { - check_compatibility(ov::intel_gna::pwl_design_algorithm.name()); - // This key is deprecated and will be removed in a future release - if (value == PluginConfigParams::YES) { - gnaFlags.uniformPwlDesign = true; - } else if (value == PluginConfigParams::NO) { - gnaFlags.uniformPwlDesign = false; - } else { - THROW_GNA_EXCEPTION << "GNA pwl uniform algorithm parameter " - << "should be equal to YES/NO, but not" << value; - } - } else if (key == GNA_CONFIG_KEY(PWL_MAX_ERROR_PERCENT) || key == ov::intel_gna::pwl_max_error_percent) { - float max_error; - try { - max_error = InferenceEngine::CNNLayer::ie_parse_float(value); - if (max_error < 0.0f || max_error > 100.0f) { - throw std::out_of_range(""); - } - } catch (std::invalid_argument&) { - THROW_GNA_EXCEPTION << "Invalid value of PWL max error percent"; - } catch (std::out_of_range&) { - THROW_GNA_EXCEPTION << "Unsupported PWL error percent value: " << value - << ", should be greater than 0 and less than 100"; - } - gnaFlags.pwlMaxErrorPercent = max_error; - OPENVINO_SUPPRESS_DEPRECATED_END - } else if (key == CONFIG_KEY(PERF_COUNT) || key == ov::enable_profiling) { - if (value == PluginConfigParams::YES) { - gnaFlags.performance_counting = true; - } else if (value == PluginConfigParams::NO) { - gnaFlags.performance_counting = false; - } else { - THROW_GNA_EXCEPTION << "GNA performance counter enabling parameter " - << "should be equal to YES/NO, but not" << value; - } - OPENVINO_SUPPRESS_DEPRECATED_START - } else if (key == ov::hint::num_requests) { - try { - gnaFlags.num_requests = get_max_num_requests(); - } catch (std::out_of_range&) { - gnaFlags.num_requests = (0 == stoul(value)) ? 1 : Config::max_num_requests; - } - } else if (key == GNA_CONFIG_KEY(LIB_N_THREADS)) { - check_compatibility(ov::hint::num_requests.name()); - try { - gnaFlags.num_requests = get_max_num_requests(); - } catch (std::out_of_range&) { - THROW_GNA_EXCEPTION << "Unsupported accelerator lib number of threads: " << value - << ", should be greater than 0 and less than" << Config::max_num_requests; - } - } else if (key == CONFIG_KEY(SINGLE_THREAD)) { - if (value == PluginConfigParams::YES) { - gnaFlags.gna_openmp_multithreading = false; - } else if (value == PluginConfigParams::NO) { - gnaFlags.gna_openmp_multithreading = true; - } else { - THROW_GNA_EXCEPTION << "SINGLE_THREAD should be YES/NO, but not" << value; - } - OPENVINO_SUPPRESS_DEPRECATED_END - } else if (key == CONFIG_KEY(LOG_LEVEL) || key == ov::log::level) { - gnaFlags.log_level = ov::util::from_string(value, ov::log::level); - } else { - IE_THROW(NotFound) << "[GNAPlugin] in function " << __PRETTY_FUNCTION__ << ": " - << "Incorrect GNA Plugin config. Key " << item.first << " not supported"; - } - - if (gnaFlags.sw_fp32 && gnaFlags.num_requests > 1) { - THROW_GNA_EXCEPTION << "GNA plugin does not support async mode on GNA_SW_FP32!"; - } - } - - if (inputScaleFactorsPerInput.empty() && inputScaleFactors.empty()) { - inputScaleFactors.push_back(kScaleFactorDefault); - } - - AdjustKeyMapValues(); -} - -void Config::AdjustKeyMapValues() { - std::lock_guard lockGuard{mtx4keyConfigMap}; - keyConfigMap.clear(); - - if (!inputScaleFactorsPerInput.empty()) { - keyConfigMap[ov::intel_gna::scale_factors_per_input.name()] = ov::util::to_string(inputScaleFactorsPerInput); - } else { - if (inputScaleFactors.empty()) { - inputScaleFactors.push_back(kScaleFactorDefault); - } - keyConfigMap[GNA_CONFIG_KEY(SCALE_FACTOR)] = std::to_string(inputScaleFactors[0]); - for (size_t n = 0; n < inputScaleFactors.size(); n++) { - keyConfigMap[GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_") + std::to_string(n)] = - std::to_string(inputScaleFactors[n]); - } - } - keyConfigMap[ov::intel_gna::firmware_model_image_path.name()] = embedded_export_path; - std::string device_mode; - if (gnaFlags.sw_fp32) { - device_mode = ov::util::to_string(ov::intel_gna::ExecutionMode::SW_FP32); - } else { - for (auto&& value : supported_values) { - if (value.second.first == pluginGna2AccMode && value.second.second == swExactMode) { - device_mode = ov::util::to_string(value.first); - break; - } - } - } - IE_ASSERT(!device_mode.empty()); - keyConfigMap[ov::intel_gna::execution_mode.name()] = device_mode; - if (!embedded_export_path.empty() && !IsEmbeddedDevice(target->get_user_set_execution_target())) { - THROW_GNA_EXCEPTION << "Target device for embedded export should be one of embedded devices"; - } - keyConfigMap[GNA_CONFIG_KEY(EXEC_TARGET)] = DeviceToString(target->get_user_set_execution_target()); - keyConfigMap[GNA_CONFIG_KEY(COMPILE_TARGET)] = DeviceToString(target->get_user_set_compile_target()); - keyConfigMap[ov::intel_gna::memory_reuse.name()] = - gnaFlags.compact_mode ? PluginConfigParams::YES : PluginConfigParams::NO; - keyConfigMap[ov::internal::exclusive_async_requests.name()] = - gnaFlags.exclusive_async_requests ? PluginConfigParams::YES : PluginConfigParams::NO; - keyConfigMap[ov::hint::performance_mode.name()] = ov::util::to_string(performance_mode); - if (inference_precision != ov::element::undefined) { - keyConfigMap[ov::hint::inference_precision.name()] = ov::util::to_string(inference_precision); - } else { - keyConfigMap[GNA_CONFIG_KEY(PRECISION)] = gnaPrecision.name(); - } - keyConfigMap[ov::hint::execution_mode.name()] = ov::util::to_string(execution_mode); - OPENVINO_SUPPRESS_DEPRECATED_START - if (gnaFlags.pwl_design_algorithm != ov::intel_gna::PWLDesignAlgorithm::UNDEFINED) { - keyConfigMap[ov::intel_gna::pwl_design_algorithm.name()] = ov::util::to_string(gnaFlags.pwl_design_algorithm); - } else { - keyConfigMap[GNA_CONFIG_KEY(PWL_UNIFORM_DESIGN)] = - gnaFlags.uniformPwlDesign ? PluginConfigParams::YES : PluginConfigParams::NO; - } - keyConfigMap[ov::intel_gna::pwl_max_error_percent.name()] = std::to_string(gnaFlags.pwlMaxErrorPercent); - keyConfigMap[ov::hint::num_requests.name()] = std::to_string(gnaFlags.num_requests); - keyConfigMap[GNA_CONFIG_KEY(LIB_N_THREADS)] = std::to_string(gnaFlags.num_requests); - keyConfigMap[CONFIG_KEY(SINGLE_THREAD)] = - gnaFlags.gna_openmp_multithreading ? PluginConfigParams::NO : PluginConfigParams::YES; - OPENVINO_SUPPRESS_DEPRECATED_END - keyConfigMap[ov::enable_profiling.name()] = - gnaFlags.performance_counting ? PluginConfigParams::YES : PluginConfigParams::NO; - keyConfigMap[ov::log::level.name()] = ov::util::to_string(gnaFlags.log_level); -} - -Parameter Config::GetParameter(const std::string& name) const { - std::lock_guard lockGuard{mtx4keyConfigMap}; - if (name == ov::intel_gna::scale_factors_per_input) { - return decltype(ov::intel_gna::scale_factors_per_input)::value_type{inputScaleFactorsPerInput}; - } else if (name == ov::intel_gna::pwl_design_algorithm) { - return gnaFlags.pwl_design_algorithm; - } else if (name == ov::intel_gna::execution_target) { - return DeviceToHwGeneration(target->get_user_set_execution_target()); - } else if (name == ov::intel_gna::compile_target) { - return DeviceToHwGeneration(target->get_user_set_compile_target()); - } else if (name == ov::hint::performance_mode) { - return performance_mode; - } else if (name == ov::hint::inference_precision) { - return inference_precision; - } else { - auto result = keyConfigMap.find(name); - if (result == keyConfigMap.end()) { - THROW_GNA_EXCEPTION << "Unsupported config key: " << name; - } - return result->second; - } -} - -const Parameter Config::GetImpactingModelCompilationProperties(bool compiled) { - ov::PropertyMutability model_mutability = compiled ? ov::PropertyMutability::RO : ov::PropertyMutability::RW; - const std::vector supported_properties = { - {ov::intel_gna::scale_factors_per_input.name(), model_mutability}, - {ov::intel_gna::firmware_model_image_path.name(), model_mutability}, - {ov::intel_gna::execution_target.name(), model_mutability}, - {ov::intel_gna::compile_target.name(), model_mutability}, - {ov::intel_gna::pwl_design_algorithm.name(), model_mutability}, - {ov::intel_gna::pwl_max_error_percent.name(), model_mutability}, - {ov::hint::inference_precision.name(), model_mutability}, - {ov::hint::execution_mode.name(), model_mutability}, - {ov::hint::num_requests.name(), model_mutability}, - }; - return supported_properties; -} - -const Parameter Config::GetSupportedProperties(bool compiled) { - std::vector supported_properties = { - {ov::supported_properties.name(), ov::PropertyMutability::RO}, - {ov::available_devices.name(), ov::PropertyMutability::RO}, - {ov::optimal_number_of_infer_requests.name(), ov::PropertyMutability::RO}, - {ov::range_for_async_infer_requests.name(), ov::PropertyMutability::RO}, - {ov::device::capabilities.name(), ov::PropertyMutability::RO}, - {ov::device::full_name.name(), ov::PropertyMutability::RO}, - {ov::intel_gna::library_full_version.name(), ov::PropertyMutability::RO}, - {ov::intel_gna::execution_mode.name(), ov::PropertyMutability::RW}, - {ov::hint::performance_mode.name(), ov::PropertyMutability::RW}, - {ov::log::level.name(), ov::PropertyMutability::RW}, - {ov::execution_devices.name(), ov::PropertyMutability::RO}, - }; - - const auto impacting_model_compilation_properties = - GetImpactingModelCompilationProperties(compiled).as>(); - - supported_properties.insert(supported_properties.end(), - impacting_model_compilation_properties.begin(), - impacting_model_compilation_properties.end()); - return supported_properties; -} - -const Parameter Config::GetSupportedInternalProperties() { - std::vector supported_internal_properties = { - {ov::internal::caching_properties.name(), ov::PropertyMutability::RO}, - {ov::internal::exclusive_async_requests.name(), ov::PropertyMutability::RW}}; - return supported_internal_properties; -} - -std::vector Config::GetSupportedKeys() const { - std::lock_guard lockGuard{mtx4keyConfigMap}; - std::vector result; - for (auto&& configOption : keyConfigMap) { - result.push_back(configOption.first); - } - return result; -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_plugin_config.hpp b/src/plugins/intel_gna/src/gna_plugin_config.hpp deleted file mode 100644 index 467fa5eb3a7..00000000000 --- a/src/plugins/intel_gna/src/gna_plugin_config.hpp +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "common/gna_target.hpp" -#include "descriptions/gna_flags.hpp" -#include "gna2-inference-api.h" -#include "ie_parameter.hpp" -#include "ie_precision.hpp" -#include "openvino/runtime/intel_gna/properties.hpp" - -namespace ov { -namespace intel_gna { - -static const float kScaleFactorDefault = 1.f; - -struct Config { - Config() { - AdjustKeyMapValues(); - } - Config(const Config& r) { - Copy(r); - } - Config& operator=(const Config& r) { - Copy(r); - return *this; - } - void Copy(const Config& r) { - performance_mode = r.performance_mode; - inference_precision = r.inference_precision; - gnaPrecision = r.gnaPrecision; - embedded_export_path = r.embedded_export_path; - target = std::make_shared(); - if (r.target) { - *target = *r.target; - } - pluginGna2AccMode = r.pluginGna2AccMode; - swExactMode = r.swExactMode; - inputScaleFactorsPerInput = r.inputScaleFactorsPerInput; - inputScaleFactors = r.inputScaleFactors; - gnaFlags = r.gnaFlags; - std::lock_guard lock(r.mtx4keyConfigMap); - keyConfigMap = r.keyConfigMap; - } - void UpdateFromMap(const std::map& configMap); - void AdjustKeyMapValues(); - InferenceEngine::Parameter GetParameter(const std::string& name) const; - std::vector GetSupportedKeys() const; - static const InferenceEngine::Parameter GetImpactingModelCompilationProperties(bool compiled); - static const InferenceEngine::Parameter GetSupportedProperties(bool compiled = false); - static const InferenceEngine::Parameter GetSupportedInternalProperties(); - - ov::hint::PerformanceMode performance_mode = ov::hint::PerformanceMode::LATENCY; - - // default precision of GNA hardware model - ov::element::Type inference_precision = ov::element::undefined; - InferenceEngine::Precision gnaPrecision = InferenceEngine::Precision::I16; - ov::hint::ExecutionMode execution_mode = ov::hint::ExecutionMode::ACCURACY; - - std::string embedded_export_path; - - std::shared_ptr target = std::make_shared(); - - Gna2AccelerationMode pluginGna2AccMode = Gna2AccelerationModeSoftware; - bool swExactMode = true; - - std::map inputScaleFactorsPerInput; - std::vector inputScaleFactors; // Legacy one, should be removed with old confg API - GNAFlags gnaFlags; - - mutable std::mutex mtx4keyConfigMap; - std::map keyConfigMap; - static const uint8_t max_num_requests = 127; -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_plugin_entry_points.cpp b/src/plugins/intel_gna/src/gna_plugin_entry_points.cpp deleted file mode 100644 index ee1267572dc..00000000000 --- a/src/plugins/intel_gna/src/gna_plugin_entry_points.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "gna_plugin_internal.hpp" - -using namespace InferenceEngine; -using namespace std; - -static const Version gnaPluginDescription = {{2, 1}, - CI_BUILD_NUMBER "_with_GNA_LIB_VER==2", - "openvino_intel_gna_plugin"}; - -IE_DEFINE_PLUGIN_CREATE_FUNCTION(GNAPluginInternal, gnaPluginDescription) diff --git a/src/plugins/intel_gna/src/gna_plugin_internal.hpp b/src/plugins/intel_gna/src/gna_plugin_internal.hpp deleted file mode 100644 index 16bd61198e3..00000000000 --- a/src/plugins/intel_gna/src/gna_plugin_internal.hpp +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "gna_executable_network.hpp" -#include "gna_plugin_config.hpp" - -namespace ov { -namespace intel_gna { - -class GNAPluginInternal : public InferenceEngine::IInferencePlugin { -private: - mutable std::mutex syncCalls; - Config defaultConfig; - std::weak_ptr plgPtr; - std::shared_ptr GetCurrentPlugin() const { - std::lock_guard lock{syncCalls}; - auto ptr = plgPtr.lock(); - if (ptr == nullptr) { - return std::make_shared(); - } else { - return ptr; - } - } - -protected: - std::string _pluginInternalName = "GNA"; - -public: - InferenceEngine::IExecutableNetworkInternal::Ptr LoadExeNetworkImpl( - const InferenceEngine::CNNNetwork& network, - const std::map& config) override { - std::lock_guard lock{syncCalls}; - Config updated_config(defaultConfig); - updated_config.UpdateFromMap(config); - auto plg = std::make_shared(updated_config.keyConfigMap); - plgPtr = plg; - InferenceEngine::CNNNetwork clonedNetwork(InferenceEngine::cloneNetwork(network)); - return std::make_shared(clonedNetwork, plg); - } - - void SetConfig(const std::map& config) override { - defaultConfig.UpdateFromMap(config); - } - - InferenceEngine::IExecutableNetworkInternal::Ptr ImportNetwork( - const std::string& modelFileName, - const std::map& config) override { - std::lock_guard lock{syncCalls}; - Config updated_config(defaultConfig); - updated_config.UpdateFromMap(config); - auto plg = std::make_shared(updated_config.keyConfigMap); - plgPtr = plg; - auto network_impl = std::make_shared(modelFileName, plg); - // set pointer for IInferencePlugin interface - network_impl->SetPointerToPlugin(shared_from_this()); - - return network_impl; - } - - InferenceEngine::IExecutableNetworkInternal::Ptr ImportNetwork( - std::istream& networkModel, - const std::map& config) override { - std::lock_guard lock{syncCalls}; - Config updated_config(defaultConfig); - updated_config.UpdateFromMap(config); - auto plg = std::make_shared(updated_config.keyConfigMap); - plgPtr = plg; - auto network_impl = std::make_shared(networkModel, plg); - // set pointer for IInferencePlugin interface - network_impl->SetPointerToPlugin(shared_from_this()); - - return network_impl; - } - - std::string GetName() const noexcept override { - auto ptr = plgPtr.lock(); - if (ptr == nullptr) { - return _pluginInternalName; - } else { - return ptr->GetName(); - } - } - - InferenceEngine::QueryNetworkResult QueryNetwork(const InferenceEngine::CNNNetwork& network, - const std::map& config) const override { - auto plg = GetCurrentPlugin(); - try { - plg->SetConfig(config); - } catch (InferenceEngine::Exception&) { - } - return plg->QueryNetwork(network, config); - } - - InferenceEngine::Parameter GetMetric( - const std::string& name, - const std::map& options) const override { - return GetCurrentPlugin()->GetMetric(name, options); - } - - InferenceEngine::Parameter GetConfig( - const std::string& name, - const std::map& options) const override { - return defaultConfig.GetParameter(name); - } -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_plugin_query_api.cpp b/src/plugins/intel_gna/src/gna_plugin_query_api.cpp deleted file mode 100644 index 8cb32a35645..00000000000 --- a/src/plugins/intel_gna/src/gna_plugin_query_api.cpp +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include -#include - -#include "gna/gna_config.hpp" -#include "gna_plugin.hpp" -#include "openvino/runtime/intel_gna/properties.hpp" - -using namespace InferenceEngine; -using namespace InferenceEngine::PluginConfigParams; - -Parameter GNAPlugin::GetConfig(const std::string& name, const std::map& /*options*/) const { - return config.GetParameter(name); -} - -Parameter GNAPlugin::GetMetric(const std::string& name, - const std::map& options) const { - if (ov::supported_properties == name) { - return config.GetSupportedProperties(); - } else if (ov::internal::supported_properties == name) { - return config.GetSupportedInternalProperties(); - } else if (ov::available_devices == name) { - return GetAvailableDevices().as>(); - } else if (ov::optimal_number_of_infer_requests == name) { - uint32_t nireq = 1; - return nireq; - } else if (ov::range_for_async_infer_requests == name) { - std::tuple range{1, 1, 1}; - return range; - } else if (ov::device::capabilities == name) { - std::vector supported_capabilities = { - ov::device::capability::INT16, - ov::device::capability::INT8, - ov::device::capability::EXPORT_IMPORT, - }; - if (options.count(ov::device::id.name())) { - if (options.at(ov::device::id.name()).as().compare("GNA_HW") != 0) { - supported_capabilities.emplace_back(ov::device::capability::FP32); - } - } - return supported_capabilities; - } else if (ov::device::full_name == name) { - if (!options.count(ov::device::id.name())) { - auto availableDevices = GetAvailableDevices().as>(); - if (availableDevices.empty()) { - THROW_GNA_EXCEPTION << "No devices available."; - } else if (availableDevices.size() > 2) { - THROW_GNA_EXCEPTION << "ov::device::id not set in request for ov::device::full_name"; - } - return availableDevices.back(); - } else { - return options.at(ov::device::id.name()); - } - } else if (ov::intel_gna::library_full_version == name) { - return GNADeviceHelper::GetGnaLibraryVersion(); - } else if (ov::execution_devices == name) { - return decltype(ov::execution_devices)::value_type{GetName()}; - } else if (ov::model_name == name) { - return _network_name; - } else if (name == ov::internal::caching_properties) { - auto cachingProperties = - Config::GetImpactingModelCompilationProperties(true).as>(); - cachingProperties.push_back(ov::PropertyName(ov::log::level.name(), ov::PropertyMutability::RO)); - return decltype(ov::internal::caching_properties)::value_type(cachingProperties); - } else { - const std::unordered_map> queryApiSupported = { - {METRIC_KEY(AVAILABLE_DEVICES), - [this]() { - return GetAvailableDevices(); - }}, - {METRIC_KEY(SUPPORTED_CONFIG_KEYS), - [this]() { - return config.GetSupportedKeys(); - }}, - {METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS), - []() { - uint32_t nireq = 1; - return nireq; - }}, - {METRIC_KEY(FULL_DEVICE_NAME), - [&options, this]() { - auto availableDevices = GetAvailableDevices().as>(); - - if (availableDevices.empty()) { - THROW_GNA_EXCEPTION << "No devices available."; - } - - if (!options.count(KEY_DEVICE_ID)) { - if (availableDevices.size() == 1 || availableDevices.size() == 2) { - return availableDevices.back(); // detection order is GNA_SW, GNA_HW - } else { - THROW_GNA_EXCEPTION << "KEY_DEVICE_ID not set in request for FULL_DEVICE_NAME"; - } - } - - auto deviceName = options.at(KEY_DEVICE_ID).as(); - return deviceName; - }}, - {METRIC_KEY(GNA_LIBRARY_FULL_VERSION), - []() { - return GNADeviceHelper::GetGnaLibraryVersion(); - }}, - {METRIC_KEY(SUPPORTED_METRICS), - [&queryApiSupported]() { - std::vector availablesMetrics; - for (auto&& supportedAPI : queryApiSupported) { - availablesMetrics.push_back(supportedAPI.first); - } - return availablesMetrics; - }}, - {METRIC_KEY(IMPORT_EXPORT_SUPPORT), []() { - return true; - }}}; - - auto it = queryApiSupported.find(name); - if (it == queryApiSupported.end()) { - THROW_GNA_EXCEPTION << "Unsupported parameters for GetMetric: " << name; - } - - return it->second(); - } -} - -Parameter GNAPlugin::GetAvailableDevices() const { - std::vector devices; - - try { - GNADeviceHelper helper; - devices.push_back("GNA_SW"); - if (helper.is_hw_detected()) { - devices.push_back("GNA_HW"); - } - } catch (...) { - } - - return devices; -} diff --git a/src/plugins/intel_gna/src/gna_slope_scale.cpp b/src/plugins/intel_gna/src/gna_slope_scale.cpp deleted file mode 100644 index 5d2eed96621..00000000000 --- a/src/plugins/intel_gna/src/gna_slope_scale.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_slope_scale.hpp" - -#include -#include - -pwl_gna_slope_scale_t gna_slope(const double slope, const double in_scale, const double out_scale) { - pwl_gna_slope_scale_t s; - s.slope = slope * out_scale / in_scale; - - for (s.slope_scale_index = 3; s.slope_scale_index > 0; --s.slope_scale_index) { - s.slope_scale = static_cast(1) << (8 * (1 + s.slope_scale_index)); - if (((s.slope * s.slope_scale) <= std::numeric_limits::max()) && - ((s.slope * s.slope_scale) >= std::numeric_limits::min())) - break; - } - s.slope_scale = static_cast(1) << (8 * (1 + s.slope_scale_index)); - - return (s); -} diff --git a/src/plugins/intel_gna/src/gna_slope_scale.hpp b/src/plugins/intel_gna/src/gna_slope_scale.hpp deleted file mode 100644 index 09a5879c9c6..00000000000 --- a/src/plugins/intel_gna/src/gna_slope_scale.hpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -struct pwl_gna_slope_scale_t { - double slope{}; - uint64_t slope_scale = 0; - uint32_t slope_scale_index{}; -}; - -pwl_gna_slope_scale_t gna_slope(const double slope, const double in_scale, const double out_scale); diff --git a/src/plugins/intel_gna/src/gna_tensor_tools.hpp b/src/plugins/intel_gna/src/gna_tensor_tools.hpp deleted file mode 100644 index 9a3b0b834b6..00000000000 --- a/src/plugins/intel_gna/src/gna_tensor_tools.hpp +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "gna_data_types.hpp" - -namespace ov { -namespace intel_gna { - -/** - * @brief convert a tensor or its parts from NCHW to NHWC order on the base of transposition information. - * The tensor to be converted from NCHW to NHWC may be 2D. But we may need to change data order inside one of its - * dimensions since its data is reshaped to/from 4D data used by convolution. TranspositionInfo contains number of rows - * (corresponds to C dimension) and columns (corresponds to HW dimensions) of every part of the tensor which should or - * shouldn't be transposed (for example if output of some convolution layer is concatenated with output of another - * convolution layer and there is a fully connected layer after that, we need to transpose its weights parts - * corresponding to different convolutions outputs separately). If the tensor is input, output data, scaleshift weights - * or a constant input of eltwise, it's rows number is equal to 1 and its columns number is equal to the product of - * input dimensions (N * C * H * W). The row (or its separate parts) should be transposed. If the tensor is fully - * connected layer weights, it's rows number is equal to the product of input dimensions and it's columns number is - * equal to the product of output dimensions. Every row of this tensor (or its separate parts) should be transposed if - * there are convolution layers before this layer. Every column (or its separate parts) should be transposed if there - * are convolution layers after this layer. - * @param precision data precision - * @param rows number of rows in the whole tensor - * @param columns number of columns in the whole tensor - * @param buffer pointer to a tensor buffer - * @param transpose_rows flag indicated if tensor rows or tensor columns must be transposed - * @param transpositionInfo vector of structures with information about transposition: every element contains - * information about tensor part which should be transposed separately or shouldn't be transposed - */ -inline void ConvertTensorFromNCHWToNHWC(size_t precision, - size_t rows, - size_t columns, - uint8_t* buffer, - bool transpose_rows, - const std::vector& transpositionInfo) { - size_t weightsTotalSize = rows * columns * precision; - std::vector transposedWeights(weightsTotalSize); - size_t weightsPartOffset = 0; - bool transposed = false; - for (const auto& transpositionInfoPart : transpositionInfo) { - auto partSize = transpositionInfoPart.num_transpose_rows * transpositionInfoPart.num_transpose_columns; - size_t weightsPartSize = partSize * precision * (transpose_rows ? rows : columns); - if (transpositionInfoPart.transpose && transpositionInfoPart.num_transpose_rows != 1 && - transpositionInfoPart.num_transpose_columns != 1) { - if (transpose_rows) { - for (size_t weightsRowIx = 0; weightsRowIx < rows; ++weightsRowIx) { - auto weightsRowsOffset = weightsRowIx * partSize * precision; - auto cbuffer = buffer + weightsPartOffset + weightsRowsOffset; - auto weights_ptr = transposedWeights.data() + weightsPartOffset + weightsRowsOffset; - for (size_t colsIx = 0; colsIx < transpositionInfoPart.num_transpose_columns; ++colsIx) { - for (size_t rowIx = 0; rowIx < transpositionInfoPart.num_transpose_rows; ++rowIx) { - auto offsetWrite = (colsIx * transpositionInfoPart.num_transpose_rows + rowIx) * precision; - auto offsetRead = - (transpositionInfoPart.num_transpose_columns * rowIx + colsIx) * precision; - ie_memcpy(weights_ptr + offsetWrite, - weightsPartSize - weightsRowsOffset - offsetWrite, - cbuffer + offsetRead, - precision); - } - } - } - } else { - auto cbuffer = buffer + weightsPartOffset; - auto weights_ptr = transposedWeights.data() + weightsPartOffset; - for (size_t colsIx = 0; colsIx < transpositionInfoPart.num_transpose_columns; ++colsIx) { - for (size_t rowIx = 0; rowIx < transpositionInfoPart.num_transpose_rows; ++rowIx) { - auto offsetWrite = - (colsIx * transpositionInfoPart.num_transpose_rows + rowIx) * columns * precision; - auto offsetRead = - (transpositionInfoPart.num_transpose_columns * rowIx + colsIx) * columns * precision; - ie_memcpy(weights_ptr + offsetWrite, - weightsPartSize - offsetWrite, - cbuffer + offsetRead, - columns * precision); - } - } - } - transposed = true; - } else { - // Just copy data which should not be transposed - ie_memcpy(transposedWeights.data() + weightsPartOffset, - weightsPartSize, - buffer + weightsPartOffset, - weightsPartSize); - } - weightsPartOffset += weightsPartSize; - } - if (transposed) { - ie_memcpy(buffer, weightsTotalSize, transposedWeights.data(), weightsTotalSize); - } -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_transformations_pipeline.cpp b/src/plugins/intel_gna/src/gna_transformations_pipeline.cpp deleted file mode 100644 index eabb6e77196..00000000000 --- a/src/plugins/intel_gna/src/gna_transformations_pipeline.cpp +++ /dev/null @@ -1,360 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_transformations_pipeline.hpp" - -#include "gna_itt.hpp" -#include "legacy/net_pass.h" -#include "legacy/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_strided_slice_to_crop.hpp" -#include "ngraph/opsets/opset2.hpp" -#include "ngraph/opsets/opset7.hpp" -#include "openvino/pass/manager.hpp" -#include "optimizer/gna_pass_manager.hpp" -#include "transformations/broadcast_const.hpp" -#include "transformations/common_optimizations/add_fake_quantize_fusion.hpp" -#include "transformations/common_optimizations/common_optimizations.hpp" -#include "transformations/common_optimizations/concat_reduce_fusion.hpp" -#include "transformations/common_optimizations/fq_mul_fusion.hpp" -#include "transformations/common_optimizations/fq_reshape_fusion.hpp" -#include "transformations/common_optimizations/pull_transpose_through_fq.hpp" -#include "transformations/common_optimizations/relu_fake_quantize_fusion.hpp" -#include "transformations/common_optimizations/reshape_sequence_fusion.hpp" -#include "transformations/common_optimizations/transpose_sinking.hpp" -#include "transformations/common_optimizations/transpose_to_reshape.hpp" -#include "transformations/control_flow/unroll_tensor_iterator.hpp" -#include "transformations/convert_dwsc_to_scaleshifts.hpp" -#include "transformations/convert_matmul_to_pointwise_convolution.hpp" -#include "transformations/convert_padded_to_valid_convolution.hpp" -#include "transformations/convert_precision.hpp" -#include "transformations/decompose_2d_convolution.hpp" -#include "transformations/decompose_mvn.hpp" -#include "transformations/fp16_compression/convert_compression_only_to_legacy.hpp" -#include "transformations/fp16_compression/mark_decompression_convert_constant_folding.hpp" -#include "transformations/fuse_conv_bias_activation.hpp" -#include "transformations/gather_sinking.hpp" -#include "transformations/gather_sinking_transpose.hpp" -#include "transformations/handle_transposes_around_matmul.hpp" -#include "transformations/init_node_info.hpp" -#include "transformations/insert_copy_layer.hpp" -#include "transformations/insert_identity_layer.hpp" -#include "transformations/insert_reshape_around_matmul.hpp" -#include "transformations/insert_transpose_after_convolution_or_pooling.hpp" -#include "transformations/markup_fusable_transpose.hpp" -#include "transformations/op_conversions/convert_mvn1_to_mvn6.hpp" -#include "transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp" -#include "transformations/op_conversions/convert_slice_to_strided_slice.hpp" -#include "transformations/op_conversions/gru_cell_decomposition.hpp" -#include "transformations/op_conversions/lstm_cell_decomposition.hpp" -#include "transformations/op_conversions/softsign_decomposition.hpp" -#include "transformations/opset_conversions/convert_opset2_to_opset1.hpp" -#include "transformations/opset_conversions/convert_opset3_to_opset2.hpp" -#include "transformations/pwl_approximation.hpp" -#include "transformations/remove_converts.hpp" -#include "transformations/remove_extra_reshapes.hpp" -#include "transformations/remove_in_out_processing.hpp" -#include "transformations/remove_single_input_concat.hpp" -#include "transformations/reorder_activation_and_pooling.hpp" -#include "transformations/replace_gna_nhwc_layers.hpp" -#include "transformations/reshape_transpose_substitute.hpp" -#include "transformations/rotate_inputs.hpp" -#include "transformations/split_convolution_with_large_buffer_size.hpp" -#include "transformations/split_eltwise.hpp" -#include "transformations/substitute_softsign.hpp" -#include "transformations/swap_input_matmul_gna.hpp" -#include "transformations/transpose_compress.hpp" -#include "transformations/transpose_sinking/ts_concat.hpp" -#include "transformations/transpose_sinking/ts_fuse.hpp" -#include "transformations/transpose_sinking/ts_general.hpp" -#include "transformations/transpose_sinking/ts_split.hpp" -#include "transformations/ts_concat_forward.hpp" -#include "transformations/ts_split_backward.hpp" -#include "transformations/unfuse_reshape_and_transpose.hpp" -#include "transformations/utils/transformation_helper.hpp" -#include "transformations/utils/utils.hpp" - -using namespace ov; -using namespace ov::opset8; -using namespace ov::intel_gna::limitations; -using namespace ov::intel_gna::pass::helper; - -namespace ov { -namespace intel_gna { - -void TransformationsPipeline::apply(const std::shared_ptr& model, - ov::intel_gna::PrePostProcessModels* input_output_subgraphs) { - OV_ITT_SCOPED_TASK(itt::domains::GNAPlugin, "TransformationsPipeline::apply"); - - fake_quantized = ov::op::util::has_op_with_type(model); - const bool has_convolution = ov::op::util::has_op_with_type(model); - const bool has_maxpool = ov::op::util::has_op_with_type(model); - const bool has_slice = ov::op::util::has_op_with_type(model); - const bool has_matmul = ov::op::util::has_op_with_type(model); - const bool has_mvn = ov::op::util::has_op_with_type(model) || - ov::op::util::has_op_with_type(model); - ov::pass::Manager manager; - manager.register_pass(); - // In OV API 2.0(IRv10) default convertion to fp32 (inputs, outputs and weights) is disabled - // and we need to run the ConvertPrecision transformation to support old networks. - manager.register_pass(precisions_map{{ngraph::element::f16, ngraph::element::f32}}); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(config.gnaPrecision); - manager.register_pass(config.gnaPrecision); - manager.register_pass(config.gnaPrecision); - if (!has_convolution) { - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - } - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - // TODO enable this transformation for networks without convolutions - if (has_convolution || has_maxpool || has_mvn || has_matmul) { - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - } - manager.register_pass(input_output_subgraphs); - manager.register_pass(input_output_subgraphs); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - /* - Put BroadcastAddMultiplyConst here after ConvertOpSet..() transformations since there are conficts with them. - ngraph::pass::ConvertOpSet1ToLegacy -> ngraph::pass::BiasFusions -> - ngraph::pass::ConvAddFusion, ngraph::pass::ConvMultiplyFusion - That transormations fuse bias into convolution and recognizes const node as [1, C, 1, 1]. - TODO: move that transformation just beyond RemoveSingleInputConcat pass after removing ConvertOpSet1ToLegacy - transormations - */ - manager.register_pass(); - /* - SplitEltwise has dependency on BroadcastAddMultiplyConst for case when spliting of Constant - input is doing - */ - manager.register_pass(); - /* The following transformations perform insertion of Identity layer in 3 steps: - 1. Mark inputs with rt_info attribute where precision change from i32 to i16/i8 is happened - 2. Insert Identity after operation which have consumers marked with precision change - 3. Cleanup appropriate attribute from rt_info - */ - manager.register_pass(config.gnaFlags.input_low_precision); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - // Breaks fusing of layers before result - manager.register_pass(); - if (!config.gnaFlags.sw_fp32 && !config.gnaFlags.uniformPwlDesign) { - manager.register_pass(config.gnaFlags.pwlMaxErrorPercent); - manager.register_pass(config.gnaFlags.pwlMaxErrorPercent); - } - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - - manager.register_pass(precisions_map{{ov::element::i64, ov::element::i32}, - {ov::element::u64, ov::element::i32}, - {ov::element::u32, ov::element::i32}}); - const auto& pass_config = manager.get_pass_config(); - - pass_config->set_callback( - [](const std::shared_ptr& node) -> bool { - const TransposeInfo transpose_info = get_first_input_transpose(node); - if (transpose_info.isEmpty()) - return false; - const bool is_supported = Limitations::is_forward_transposed_concat_supported( - node, - transpose_info.transpose_const->get_axis_vector_val()); - if (!is_supported) - mark_input_transposes_as_nosinking(node); - return !is_supported; - }); - - pass_config->set_callback( - [](const std::shared_ptr& node) -> bool { - const TransposeInfo transpose_info = get_first_output_transpose(node); - if (transpose_info.isEmpty()) - return false; - return !Limitations::is_backward_transposed_concat_supported( - node, - transpose_info.transpose_const->get_axis_vector_val()); - }); - - pass_config->set_callback( - [](const std::shared_ptr& node) -> bool { - const TransposeInfo transpose_info = get_first_input_transpose(node); - if (transpose_info.isEmpty()) - return false; - const bool is_supported = Limitations::is_forward_transposed_split_supported( - node, - transpose_info.transpose_const->get_axis_vector_val()); - if (!is_supported) - mark_input_transposes_as_nosinking(node); - return !is_supported; - }); - - pass_config->set_callback( - [](const std::shared_ptr& node) -> bool { - const TransposeInfo transpose_info = get_first_output_transpose(node); - if (transpose_info.isEmpty()) - return false; - return !Limitations::is_backward_transposed_split_supported( - node, - transpose_info.transpose_const->get_axis_vector_val()); - }); - - /** - * TransposeSinking doesn't currently support StridedSlice. We disable SliceToStridedSlice - * transformation to prevent convert Slice to StridedSlice. This allows us to work with - * networks, that initialy have Slice. - * That could be removed after StridedSlice implementation in TransposeSinking - */ - if (has_slice && (has_convolution || has_maxpool || has_mvn)) { - pass_config->disable(); - } - - // Allowing FP16 Converts to be folded and FP16 constants to upgrade to FP32 data type - pass_config->disable(); - pass_config->disable(); - - pass_config->disable(); - pass_config->disable(); - pass_config->disable(); - pass_config->disable(); - // Consider to enable after per-channel quantization on FakeQuantize layer is supported in GNAPlugin, see issue - // 52034 - pass_config->disable(); - // TransposeReduction can be enabled when Transpose-Conv-Transpose patterns will be handled in ngraph - // transformations - pass_config->disable(); - // Operations Max and Min aren't supported - pass_config->disable(); - - pass_config->disable(); - manager.run_passes(model); - - /** - * As we disabled SliceToStridedSlice, we have after all transformations - * Slice, that is not supported natively in our plugin. Here we convert - * Slice -> StridedSlice -> CropIE - * That could be removed after StridedSlice implementation in TransposeSinking - */ - if (has_slice && (has_convolution || has_maxpool || has_mvn)) { - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(true); - manager.register_pass(); - manager.run_passes(model); - } - - is_ngraph_passes_used = true; -} - -IE_SUPPRESS_DEPRECATED_START -void TransformationsPipeline::apply_legacy(const InferenceEngine::CNNNetwork& network, bool runBeforeCopy) { - OV_ITT_SCOPED_TASK(itt::domains::GNAPlugin, "TransformationsPipeline::apply_legacy"); - auto passes = - std::make_shared(PassManagerSettings{runBeforeCopy, config.gnaFlags.input_low_precision}, network); - passes->registerPass(); - if (!is_ngraph_passes_used) { - passes->registerPass(); - passes->registerPass(); - passes->registerPass(); - passes->registerPass(); - passes->registerPass(); - passes->registerPass(); - } - - if (fake_quantized) - passes->registerPass(); - - // fake quantisation aware passes - passes->registerPass(); - passes->registerPass(); - - passes->registerPass(); - - if (!is_ngraph_passes_used) { - passes->registerPass(); - passes->registerPass(); - } - - passes->registerPass(); - - if (!is_ngraph_passes_used) { - passes->registerPass(); - } - passes->registerPass(); - passes->registerPass(); - passes->registerPass(); - - // Keep legacy inserting of Identity layer here - // because concat and split aliging passes are not moved to ngraph yet - passes->registerPass(); - passes->registerPass(); - passes->registerPass(); - passes->registerPass(); - passes->registerPass(); - passes->registerPass(); - passes->registerPass(); - legacy_pass_index = passes->run(legacy_pass_index); -} - -void TransformationsPipeline::convert_precision_legacy(InferenceEngine::CNNNetwork& network) { - if (!is_ngraph_passes_used) { - InferenceEngine::NetPass::ConvertPrecision(network, - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I32); - InferenceEngine::NetPass::ConvertPrecision(network, - InferenceEngine::Precision::U64, - InferenceEngine::Precision::I32); - InferenceEngine::NetPass::ConvertPrecision(network, - InferenceEngine::Precision::U32, - InferenceEngine::Precision::I32); - } -} -IE_SUPPRESS_DEPRECATED_END -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_transformations_pipeline.hpp b/src/plugins/intel_gna/src/gna_transformations_pipeline.hpp deleted file mode 100644 index 02a52ad7fb1..00000000000 --- a/src/plugins/intel_gna/src/gna_transformations_pipeline.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "cpp/ie_cnn_network.h" -#include "gna_data_types.hpp" -#include "gna_plugin_config.hpp" -#include "openvino/core/model.hpp" - -namespace ov { -namespace intel_gna { - -class TransformationsPipeline { -public: - explicit TransformationsPipeline(const Config& config) : config(config) { - effective_compile_target = config.target->get_effective_compile_target(); - } - void apply(const std::shared_ptr& model, - ov::intel_gna::PrePostProcessModels* input_output_subgraphs = nullptr); - IE_SUPPRESS_DEPRECATED_START - void apply_legacy(const InferenceEngine::CNNNetwork& network, bool runBeforeCopy); - void convert_precision_legacy(InferenceEngine::CNNNetwork& network); - IE_SUPPRESS_DEPRECATED_END - bool is_fake_quantized() { - return fake_quantized; - }; - const ov::intel_gna::Config& config; - -private: - bool is_ngraph_passes_used = false; - bool fake_quantized = false; - int legacy_pass_index = 0; - ov::intel_gna::target::DeviceVersion effective_compile_target; -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/gna_upstream_iterator.hpp b/src/plugins/intel_gna/src/gna_upstream_iterator.hpp deleted file mode 100644 index dde74cd2ede..00000000000 --- a/src/plugins/intel_gna/src/gna_upstream_iterator.hpp +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include -#include -#include -#include - -#include "gna_graph_tools.hpp" - -namespace ov { -namespace intel_gna { - -/** - * @brief implements upstream search for BFS routine - */ -class UpstreamLayersIterator { - using iterator = std::vector::iterator; - InferenceEngine::details::OutLayersIterator standardIterator; - InferenceEngine::CNNLayer* origin = nullptr; - iterator currentLayer; - iterator endLayer; - -public: - UpstreamLayersIterator() = default; - explicit UpstreamLayersIterator(InferenceEngine::CNNLayer* origin, iterator beg) : origin(origin) { - currentLayer = beg; - endLayer = origin->insData.end(); - } - - void operator++() { - currentLayer++; - } - - bool operator==(UpstreamLayersIterator that) const { - // probing for end - if (origin != nullptr && that.origin == nullptr) { - return currentLayer == endLayer; - } - - if (origin == nullptr && that.origin != nullptr) { - return that.currentLayer == that.endLayer; - } - - if (origin != that.origin) { - THROW_GNA_EXCEPTION << "iterator not comparable for layers: " << origin->name << ", and " - << that.origin->name; - } - - return currentLayer == that.currentLayer; - } - - bool operator!=(UpstreamLayersIterator that) const { - return !this->operator==(that); - } - - InferenceEngine::CNNLayerPtr operator*() const { - if (origin == nullptr) { - return nullptr; - } - auto data = currentLayer->lock(); - if (!data) { - THROW_GNA_EXCEPTION << "Cannot lock insData for layer: " << origin->name; - } - auto parent = getCreatorLayer(data).lock(); - if (!parent) { - THROW_GNA_EXCEPTION << "Cannot getParent for layer: " << origin->name; - } - return parent; - } -}; - -class UpstreamLayersContainer { - InferenceEngine::CNNLayer* origin; - int startIdx = -1; - -public: - explicit UpstreamLayersContainer(InferenceEngine::CNNLayer* origin, int startIdx = -1) - : origin(origin), - startIdx(startIdx) {} - - UpstreamLayersIterator begin() { - if (origin == nullptr) { - return end(); - } - auto beg = origin->insData.begin(); - if (startIdx > 0) { - std::advance(beg, startIdx); - } - return UpstreamLayersIterator(origin, beg); - } - - UpstreamLayersIterator end() { - if (origin == nullptr) { - return UpstreamLayersIterator(); - } - auto end = origin->insData.end(); - if (startIdx != -1) { - end = ++makeBeginIterator(); - } - - return UpstreamLayersIterator(origin, end); - } - -protected: - std::vector::iterator makeBeginIterator() { - auto beg = origin->insData.begin(); - if (startIdx > 0) { - std::advance(beg, startIdx); - } - return beg; - } -}; - -inline UpstreamLayersContainer make_upstream_order(InferenceEngine::CNNLayer* origin, int startIdx = -1) { - UpstreamLayersContainer fusedCnt(origin, startIdx); - return fusedCnt; -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_concat_layer.hpp b/src/plugins/intel_gna/src/layers/gna_concat_layer.hpp deleted file mode 100644 index 90aec585a02..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_concat_layer.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -namespace ov { -namespace intel_gna { - -class GNAConcatLayer { - InferenceEngine::CNNLayerPtr concatLayer; - -public: - explicit GNAConcatLayer(InferenceEngine::CNNLayerPtr layer) : concatLayer(layer) {} - - InferenceEngine::CNNLayerPtr getConcat() { - return concatLayer; - } - /** - * pointer to gna memory request - */ - void* gna_ptr = nullptr; - /** - * gna memory of this size is reserved for concat - */ - size_t reserved_size = 0; - bool output_allocation_flag = false; - bool input_allocated = false; - /** - * gna memory of this offset from gna_ptr - */ - struct ConcatConnectedLayerInfo { - ConcatConnectedLayerInfo(const std::string& n, size_t o, size_t sz) : name(n), offset(o), tensorSize(sz) {} - std::string name = ""; - size_t offset = 0; - size_t tensorSize = 0; - }; - - std::vector concatInputLayers; -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_convolution_layer.cpp b/src/plugins/intel_gna/src/layers/gna_convolution_layer.cpp deleted file mode 100644 index 2cf83de19f5..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_convolution_layer.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_convolution_layer.hpp" - -#include - -#include -#include -#include -#include -#include - -#include "gna_graph_tools.hpp" -#include "log/debug.hpp" - -namespace ov { -namespace intel_gna { -namespace gna_convolution_layer { - -bool should_transpose_h_w(const uint32_t in_height, - const uint32_t kernel_height, - const uint32_t in_channels, - const uint32_t stride_height) { - return in_height == kernel_height && in_channels == 1 && stride_height == 1; -} - -bool isMappableFrom2DTo1D(const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t in_channels, - const uint32_t kernelHeight, - const uint32_t kernelWidth, - const uint32_t strideHeight, - const uint32_t strideWidth) { - if (inHeight <= 1 || inWidth <= 1) { - // Mapping not needed since input is already 1D - return false; - } - return (inWidth == kernelWidth && strideWidth == 1) || - should_transpose_h_w(inHeight, kernelHeight, in_channels, strideHeight); -} - -bool is3DInputOr2DKernel(const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inDepth, - const uint32_t kernelHeight, - const uint32_t kernelWidth) { - return (kernelHeight > 1 && kernelWidth > 1) || (inHeight > 1 && inWidth > 1 && inDepth > 1); -} - -double getWeightsReducer(InferenceEngine::ConvolutionLayer& conv) { - using KRT = std::pair; - // Empirically determined weights reducers for 2D Convolution - // i.e.: - // for kernelSize >= 14 -> 1.7 - // for kernelSize >= 9 -> 1.3 - // for kernelSize in {7, 8} -> 1.2 - const std::vector reducers{{49, 3.0}, {36, 2.6}, {21, 2.3}, {14, 1.7}, {9, 1.3}, {7, 1.2}}; - auto reducer = 1.0; - const auto inDepth = - InferenceEngine::GetDataDimSizeNHWC(conv.insData.front().lock(), InferenceEngine::DataDimName::C); - const auto inHeight = - InferenceEngine::GetDataDimSizeNHWC(conv.insData.front().lock(), InferenceEngine::DataDimName::H); - const auto inWidth = - InferenceEngine::GetDataDimSizeNHWC(conv.insData.front().lock(), InferenceEngine::DataDimName::W); - if (is3DInputOr2DKernel(inHeight, inWidth, inDepth, conv._kernel_y, conv._kernel_x) && - !isMappableFrom2DTo1D(inHeight, - inWidth, - inDepth, - conv._kernel_y, - conv._kernel_x, - conv._stride_y, - conv._stride_x)) { - const auto kernelSize = conv._kernel_x * conv._kernel_y; - auto r = - std::lower_bound(reducers.begin(), reducers.end(), kernelSize, [](const KRT& l, const KRT::first_type& r) { - return l.first > r; - }); - if (r != reducers.end()) - reducer = r->second; - } - return reducer; -} - -uint32_t outputFromConv(const uint32_t in, const uint32_t flt, const uint32_t stride) { - // floor[(in - flt)/stride] + 1, GNA Spec 1.24 - if (flt > in || flt == 0 || stride == 0) { - THROW_GNA_EXCEPTION << "Invalid (input, filter, stride) = (" << in << "," << flt << "," << stride << ")"; - } - return (in - flt) / stride + 1; -} - -uint32_t outputFromPooling(const uint32_t in, const uint32_t window, const uint32_t stride, const bool legacy) { - if (legacy) { - return outputFromPoolingLegacy(in, stride); - } - // ceil[(in - window)/stride] + 1, GNA Spec 1.24 - if (window > in || window == 0 || stride == 0) { - THROW_GNA_EXCEPTION << "Invalid (input, window, stride) = (" << in << "," << window << "," << stride << ")"; - } - if (window == in) - return 1; - - return (in - window - 1) / stride + 2; -} - -uint32_t outputFromPoolingLegacy(const uint32_t in, const uint32_t stride) { - // floor[(in - 1)/stride] + 1, GNA 1.0/2.0 HW Spec - // See issue 50386 for details - if (in == 0 || stride == 0) { - THROW_GNA_EXCEPTION << "Invalid (input, stride) = (" << in << "," << stride << ")"; - } - return (in - 1) / stride + 1; -} - -} // namespace gna_convolution_layer -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_convolution_layer.hpp b/src/plugins/intel_gna/src/layers/gna_convolution_layer.hpp deleted file mode 100644 index 6c6727b022c..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_convolution_layer.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -namespace ov { -namespace intel_gna { -namespace gna_convolution_layer { - -bool should_transpose_h_w(const uint32_t in_height, - const uint32_t kernel_height, - const uint32_t in_channels, - const uint32_t stride_height); - -bool isMappableFrom2DTo1D(const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inChannels, - const uint32_t kernelHeight, - const uint32_t kernelWidth, - const uint32_t strideHeight, - const uint32_t strideWidth); - -bool is3DInputOr2DKernel(const uint32_t inHeight, - const uint32_t inWidth, - const uint32_t inDepth, - const uint32_t kernelHeight, - const uint32_t kernelWidth); - -double getWeightsReducer(InferenceEngine::ConvolutionLayer& conv); - -uint32_t outputFromConv(const uint32_t in, const uint32_t flt, const uint32_t stride); - -uint32_t outputFromPooling(const uint32_t in, const uint32_t window, const uint32_t stride, bool legacy = false); - -uint32_t outputFromPoolingLegacy(const uint32_t in, const uint32_t stride); - -} // namespace gna_convolution_layer -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_copy_layer.hpp b/src/plugins/intel_gna/src/layers/gna_copy_layer.hpp deleted file mode 100644 index 7b1ec134b04..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_copy_layer.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -namespace ov { -namespace intel_gna { - -/** - * GNA primitive created in sorting order for this copy layer - */ -static constexpr auto CopyLayerName = "Copy"; -/** - * GNA primitive created at the end of primitives sequence - */ -static constexpr auto DelayedCopyLayerName = "DelayedCopy"; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_crop_layer.cpp b/src/plugins/intel_gna/src/layers/gna_crop_layer.cpp deleted file mode 100644 index f03c4cff45a..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_crop_layer.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "gna_crop_layer.hpp" - -#include - -#include "log/debug.hpp" -#include "log/log.hpp" - -namespace ov { -namespace intel_gna { - -SimpleCrop get_crop_params(const std::vector& axis_in, - const std::vector& offset_in, - const std::vector& dim_in, - const std::vector& input_dims) { - const auto total_size_to_crop = ov::shape_size(input_dims); - - SimpleCrop ret{0, total_size_to_crop}; - - auto crop_axis_detected = false; - auto cropped_dim_size = total_size_to_crop; - for (size_t n = 0; n < axis_in.size(); n++) { - const auto axis = axis_in[n]; - if (axis < 0 || axis >= static_cast(input_dims.size())) { - log::warning() << "Crop axis outside of input shape size detected.\n"; - continue; - } - const auto input_dim = input_dims[axis]; - // Skip axis that is untouched - if (offset_in[n] == 0 && dim_in[n] == static_cast(input_dim)) { - continue; - } - if (crop_axis_detected) { - THROW_GNA_EXCEPTION - << "Crop layer does not support the number of (non-trivial) cropped dimensions more than 1."; - } - crop_axis_detected = true; - ret.crop_size = dim_in[n]; - ret.start_offset = offset_in[n]; - cropped_dim_size = input_dim; - } - - if (crop_axis_detected) { - ret.start_offset *= (total_size_to_crop / cropped_dim_size); - ret.crop_size *= (total_size_to_crop / cropped_dim_size); - } - - return ret; -} - -SimpleCrop GetCropParams(InferenceEngine::CropLayer* cropLayer) { - auto input_dims = cropLayer->insData.begin()->lock()->getDims(); - - const auto out_val = get_crop_params(cropLayer->axis, cropLayer->offset, cropLayer->dim, input_dims); - return out_val; -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_crop_layer.hpp b/src/plugins/intel_gna/src/layers/gna_crop_layer.hpp deleted file mode 100644 index cf4a6985206..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_crop_layer.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -namespace ov { -namespace intel_gna { - -class GNACropLayer { - InferenceEngine::CNNLayerPtr cropLayer; - -public: - explicit GNACropLayer(InferenceEngine::CNNLayerPtr layer) : cropLayer(layer) {} - - InferenceEngine::CNNLayerPtr getCrop() { - return cropLayer; - } - - /** - * pointer to gna croped memory beginning - */ - void* gna_ptr = nullptr; -}; - -struct SimpleCrop { - size_t start_offset; - size_t crop_size; -}; - -/** - * @brief returns parameters extracted from Crop layer: elements offset, elements output size and axes - * @param cropLayer pointer to a Crop layer - */ -SimpleCrop get_crop_params(const std::vector& axis_in, - const std::vector& offset_in, - const std::vector& dim_in, - const std::vector& input_dims); - -SimpleCrop GetCropParams(InferenceEngine::CropLayer* cropLayer); - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_fake_quantize_layer.hpp b/src/plugins/intel_gna/src/layers/gna_fake_quantize_layer.hpp deleted file mode 100644 index 2d7dfe83c32..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_fake_quantize_layer.hpp +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "frontend/weights_converter.hpp" -#include "gna_layer_helpers.hpp" -#include "gna_layer_info.hpp" - -using ov::intel_gna::frontend::make_fp32_blob; - -namespace ov { -namespace intel_gna { - -class GNAFakeQuantizeLayer { - InferenceEngine::CNNLayerPtr fqLayer; - -public: - GNAFakeQuantizeLayer(InferenceEngine::CNNLayerPtr fqLayer) : fqLayer(fqLayer) { - if (!LayerInfo(fqLayer).isFakeQuantize()) { - THROW_GNA_LAYER_EXCEPTION(fqLayer) << "cannot parse as fake quantize"; - } - } - - /** - * @brief Convert FQ layer directly to gna-pwl activation layer - */ - DnnActivation parseAsActivation() const { - DnnActivation fqActivation{}; - - fqActivation.fqParams.levels = fqLayer->GetParamAsSizeT("levels"); - auto inputShape = getShapeForRange(fqLayer, 1); - auto outputShape = getShapeForRange(fqLayer, 3); - - // TODO: check shapes broadcasting to shape of input at 0 - auto inputRangeSize = InferenceEngine::details::product(inputShape.begin(), inputShape.end()); - auto outputRangeSize = InferenceEngine::details::product(outputShape.begin(), outputShape.end()); - - fqActivation.fqParams.set = true; - - fqActivation.fqParams.inputPerChannel = inputRangeSize != 1; - fqActivation.fqParams.input_low = getParamFromInputAsFloats(fqLayer, 1); - fqActivation.fqParams.input_high = getParamFromInputAsFloats(fqLayer, 2); - - fqActivation.fqParams.outputPerChannel = outputRangeSize != 1; - fqActivation.fqParams.output_low = getParamFromInputAsFloats(fqLayer, 3); - fqActivation.fqParams.output_high = getParamFromInputAsFloats(fqLayer, 4); - fqActivation.type = kActFakeQuantize; - - return fqActivation; - } - - /** - * @brief Retrieve input blob for FQ layer that connected to const layer - */ - InferenceEngine::Blob::Ptr getConstInputData() const { - return layer_utils::getParamFromInputAsBlob(fqLayer, 0); - } - - /** - * @brief Fake quantize has 5 input layers, while 4 of them always constant layer, and 1 might be a tensor - - * connection - */ - InferenceEngine::CNNLayerPtr getInputLayer() const { - return getInputLayerAt(fqLayer, 0); - } - - size_t getLevels() { - return fqLayer->GetParamAsSizeT("levels"); - } - - std::pair, std::vector> getInputRange() { - return getRange(fqLayer, 1); - } - - std::pair, std::vector> getOutputRange() { - return getRange(fqLayer, 3); - } - - operator InferenceEngine::CNNLayerPtr() const { - return fqLayer; - } - - InferenceEngine::CNNLayerPtr operator->() const { - return fqLayer; - } - InferenceEngine::CNNLayerPtr operator*() const { - return fqLayer; - } - -protected: - static std::pair, std::vector> getRange(InferenceEngine::CNNLayerPtr input, size_t idx) { - auto shape = getShapeForRange(input, idx); - auto rangeSize = InferenceEngine::details::product(shape.begin(), shape.end()); - - auto dataMin = layer_utils::getParamFromInputAsBlob(input, idx); - auto dataMax = layer_utils::getParamFromInputAsBlob(input, idx + 1); - std::vector minValues(rangeSize), maxValues(rangeSize); - switch (dataMin->getTensorDesc().getPrecision()) { - case InferenceEngine::Precision::FP32: { - memcpy(&minValues[0], dataMin->buffer().as(), rangeSize * sizeof(float)); - memcpy(&maxValues[0], dataMax->buffer().as(), rangeSize * sizeof(float)); - break; - } - case InferenceEngine::Precision::FP16: { - auto dataMinFP32 = make_fp32_blob(dataMin); - memcpy(&minValues[0], dataMinFP32->buffer().as(), rangeSize * sizeof(float)); - - auto dataMaxFP32 = make_fp32_blob(dataMax); - memcpy(&maxValues[0], dataMaxFP32->buffer().as(), rangeSize * sizeof(float)); - break; - } - default: - THROW_GNA_LAYER_EXCEPTION(input) << "cannot cast custom blob to type FP32, since it is of type: " - << dataMin->getTensorDesc().getPrecision(); - break; - } - - return {minValues, maxValues}; - } - - static float* getParamFromInputAsFloats(InferenceEngine::CNNLayerPtr input, size_t idx) { - auto data = layer_utils::getParamFromInputAsBlob(input, idx); - if (data->getTensorDesc().getPrecision() != InferenceEngine::Precision::FP32) { - THROW_GNA_LAYER_EXCEPTION(input) << "cannot cast custom blob to type FP32, since it is of type: " - << data->getTensorDesc().getPrecision(); - } - return data->buffer().as(); - } - - static InferenceEngine::SizeVector getShapeFromInput(InferenceEngine::CNNLayerPtr input, size_t idx) { - auto data = layer_utils::getParamFromInputAsBlob(input, idx); - return data->getTensorDesc().getDims(); - } - - static InferenceEngine::CNNLayerPtr getInputLayerAt(InferenceEngine::CNNLayerPtr input, size_t idx) { - if (input->insData.size() <= idx) { - THROW_GNA_LAYER_EXCEPTION(input) << "cannot get data from " << idx << "input"; - } - auto iLayerData = input->insData[idx].lock(); - if (!iLayerData) { - THROW_GNA_LAYER_EXCEPTION(input) - << "cannot get data from " << idx << ", input: cannot dereference data weak-pointer"; - } - auto iLayer = getCreatorLayer(iLayerData).lock(); - if (!iLayer) { - THROW_GNA_LAYER_EXCEPTION(input) - << "cannot get data from " << idx << ", input: cannot dereference creator layer weak-pointer"; - } - return iLayer; - } - - static InferenceEngine::SizeVector getShapeForRange(InferenceEngine::CNNLayerPtr input, size_t idx) { - auto lowShape = getShapeFromInput(input, idx); - auto highShape = getShapeFromInput(input, idx + 1); - if (lowShape.size() != highShape.size()) { - THROW_GNA_LAYER_EXCEPTION(input) << "shapes mismatch for " << idx << " and " << idx + 1 << " inputs"; - } - for (size_t i = 0; i != lowShape.size(); i++) { - if (lowShape[i] != highShape[i]) { - THROW_GNA_LAYER_EXCEPTION(input) << "shapes mismatch for " << idx << " and " << idx + 1 << " inputs"; - } - } - return lowShape; - } -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_layer_helpers.hpp b/src/plugins/intel_gna/src/layers/gna_layer_helpers.hpp deleted file mode 100644 index e585f7af83e..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_layer_helpers.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "gna_layer_info.hpp" - -namespace ov { -namespace intel_gna { -namespace layer_utils { - -/** - * @brief retrievs blob from const layer connected to certain layer - * @param input - * @param idx - */ -inline InferenceEngine::Blob::Ptr getParamFromInputAsBlob(InferenceEngine::CNNLayerPtr input, size_t idx) { - if (input->insData.size() <= idx) { - THROW_GNA_LAYER_EXCEPTION(input) << "cannot get data from " << idx << "input"; - } - auto iLayerData = input->insData[idx].lock(); - if (!iLayerData) { - THROW_GNA_LAYER_EXCEPTION(input) << "cannot get data from " << idx - << ", input: cannot dereference data weak-pointer"; - } - auto iLayer = getCreatorLayer(iLayerData).lock(); - if (!iLayer) { - THROW_GNA_LAYER_EXCEPTION(input) << "cannot get data from " << idx - << ", input: cannot dereference creator layer weak-pointer"; - } - if (!LayerInfo(iLayer).isConst()) { - THROW_GNA_LAYER_EXCEPTION(input) << "cannot get data from " << idx - << ", input: expected to be of type const, but was: " << iLayer->type; - } - - if (!iLayer->blobs.count("custom")) { - THROW_GNA_LAYER_EXCEPTION(iLayer) << "cannot get custom blob"; - } - - return iLayer->blobs["custom"]; -} - -} // namespace layer_utils -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_layer_info.hpp b/src/plugins/intel_gna/src/layers/gna_layer_info.hpp deleted file mode 100644 index c17a18037ad..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_layer_info.hpp +++ /dev/null @@ -1,458 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "backend/gna_types.hpp" -#include "caseless.hpp" -#include "gna_copy_layer.hpp" -#include "gna_lib_ver_selector.hpp" -#include "gna_permute.hpp" -#include "ie_algorithm.hpp" -#include "layers/gna_crop_layer.hpp" -#include "ops/pwl.hpp" -#include "transformations/rt_info/gna_transpose_fusable.hpp" - -namespace ov { -namespace intel_gna { - -/** - * @brief detecting of const pointer for dynamic cast operations - * @tparam T - */ -template -struct is_const_pointer : public std::false_type {}; - -template -struct is_const_pointer : public std::true_type {}; - -/** - * similar to type traits determined in standard library this trait provides details per layer type, with some - * attributes specific for GNA we don't need to have compile time performance for this yet - */ -class LayerInfo { - InferenceEngine::CNNLayer* layer; - -#define IS_VALID() \ - if (nullptr == layer) \ - return false - -public: - explicit LayerInfo(InferenceEngine::CNNLayer& layer) : LayerInfo(&layer) {} - explicit LayerInfo(const InferenceEngine::CNNLayerPtr& layer) : LayerInfo(layer.get()) {} - explicit LayerInfo(InferenceEngine::CNNLayer* layer) : layer(layer) {} - bool hasMultipleInputs() const noexcept { - IS_VALID(); - return layer->insData.size() > 1; - } - // The name of the funciton may be somehwat misleading - // Explanation: when in low precision mode the listed layers have 8-bit outputs - // and when in 16-bit input mode, they have 16-bit outputs - bool has8BOr16BOutput() const { - IS_VALID(); - static InferenceEngine::details::caseless_set layersWith8BOr16BOutputs = - {"memory", "input", "split", "slice", "concat", "copy", "const"}; - return layersWith8BOr16BOutputs.find(layer->type) != layersWith8BOr16BOutputs.end() || isActivation() || - (isCrop() && !isCropAffined()) || isPermute(); - } - bool has32BOutput() const { - IS_VALID(); - std::vector> has32BOutputsProbes = { - [this]() { - return isFullyConnected(); - }, - [this]() { - return isAffineFilter(); - }, - [this]() { - return isConcatAlignFilter(); - }, - [this]() { - return isConvolutionFilter(); - }, - [this]() { - return isEltwise(); - }, - [this]() { - return isScaleShift(); - }, - [this]() { - return isConvolution(); - }, - [this]() { - return isPooling(); - }, - [this]() { - return isPower(); - }, - [this]() { - return isCropAffined(); - }, - [this]() { - return isGemm(); - }, - }; - - for (auto&& has32BOutputs : has32BOutputsProbes) { - if (has32BOutputs()) { - return true; - } - } - return false; - } - bool isBatchSizeConstrained() { - static InferenceEngine::details::caseless_set layersWithConstrains = {"memory", "convolution"}; - return layersWithConstrains.find(layer->name) != layersWithConstrains.end(); - } - size_t getOutputBatchSize() const { - if (!layer) { - THROW_GNA_EXCEPTION << "layer is null"; - } - if (!layer->outData[0]) { - THROW_GNA_EXCEPTION << "output data of layer '" << layer->name << "' is null"; - } - auto& dims = layer->outData[0]->getDims(); - auto layout = layer->outData[0]->getLayout(); - switch (dims.size()) { - case 1: - return 1; - case 2: - if (layout == InferenceEngine::Layout::NC) { - return dims[0]; - } else if (layout == InferenceEngine::Layout::CN) { - return dims[1]; - } else { - THROW_GNA_EXCEPTION << "batch size is not define in layer '" << layer->name << "'"; - } - case 4: - return dims[0]; - default: - THROW_GNA_EXCEPTION << "batch size is not define in layer '" << layer->name << "'"; - } - } - - bool isActivation() const noexcept { - IS_VALID(); - static InferenceEngine::details::caseless_set activations = {"clamp", - "sigmoid", - "identity", - "relu", - "leakyrelu", - "tanh", - "prelu", - "exp", - "log", - "sign", - "abs", - "neglog", - "neghalflog", - "softsign", - "power", - "fakequantize", - "pwl"}; - - if (isOfType("power")) { - auto powerLayer = as(); - return powerLayer != nullptr && powerLayer->power != 1.0f; - } - - return activations.find(layer->type) != activations.end(); - } - - bool isWeightable() const noexcept { - auto weigtable_ptr = as(); - return weigtable_ptr != nullptr; - } - bool isConcatAlignFilter() const noexcept { - return isOfType("ConcatAlignFilter"); - } - bool isLink() const noexcept { - return isOfType("Link"); - } - bool isAffineFilter() const noexcept { - return isOfType("AffineFilter"); - } - bool isConvolutionFilter() const noexcept { - return isOfType("ConvolutionFilter"); - } - bool isRelu() const noexcept { - return isOfType("relu"); - } - bool isConvolution() const noexcept { - return isOfType("convolution"); - } - bool isPower() const noexcept { - if (isOfType("power")) { - return true; - } - std::shared_ptr pwl_node; - if (!layer->getNode() || !(pwl_node = std::dynamic_pointer_cast(layer->getNode()))) { - return false; - } - return std::dynamic_pointer_cast(pwl_node->get_base_node()) || - std::dynamic_pointer_cast(pwl_node->get_base_node()); - } - bool has32BInput() const noexcept { - IS_VALID(); - return isActivation() || isPooling(); - } - bool isInput() const noexcept { - return isOfType("input"); - } - bool isOutput() const noexcept { - for (auto& out : layer->outData) { - if (getInputTo(out).empty()) { - return true; - } - } - return false; - } - bool isConst() const noexcept { - return isOfType("const"); - } - bool isScaleShift() const noexcept { - IS_VALID(); - return nullptr != as(); - } - bool isSyntheticScaleShift() const noexcept { - IS_VALID(); - return layer->name.find("SyntheticScaleShift") != std::string::npos; - } - bool isEltwise() const noexcept { - IS_VALID(); - return nullptr != as(); - } - bool isEltwiseSum() const noexcept { - IS_VALID(); - if (!isEltwise()) - return false; - // dynamic_cast(layer) is validated in isEltwise function - // coverity[var_deref_op] - return dynamic_cast(layer)->_operation == - InferenceEngine::EltwiseLayer::Sum; - } - bool isEltwiseSub() const noexcept { - IS_VALID(); - if (!isEltwise()) - return false; - // dynamic_cast(layer) is validated in isEltwise function - // coverity[var_deref_op] - return dynamic_cast(layer)->_operation == - InferenceEngine::EltwiseLayer::Sub; - } - - bool isEltwiseMul() const noexcept { - IS_VALID(); - if (!isEltwise()) - return false; - // dynamic_cast(layer) is validated in isEltwise function - // coverity[var_deref_op] - return dynamic_cast(layer)->_operation == - InferenceEngine::EltwiseLayer::Prod; - } - bool isAbs() const noexcept { - return isOfType("abs"); - } - bool isIdentity() const noexcept { - return isOfType("identity"); - } - bool isTanh() const noexcept { - return isOfType("tanh"); - } - bool isSigmoid() const noexcept { - return isOfType("sigmoid"); - } - bool isSoftSign() const noexcept { - return isOfType("softsign"); - } - bool isClamp() const noexcept { - return isOfType("clamp"); - } - bool isFullyConnected() const noexcept { - return isOfType("FullyConnected") || isOfType("InnerProduct"); - } - bool isGemm() const noexcept { - return isOfType("Gemm"); - } - bool isSplit() const noexcept { - return isOfType("split"); - } - bool isSlice() const noexcept { - return isOfType("slice"); - } - bool isConcat() const noexcept { - return isOfType("concat"); - } - bool isFakeQuantize() const noexcept { - return isOfType("FakeQuantize"); - } - bool isNonFunctional() const { - return isOfType("reshape") || isOfType("squeeze") || isOfType("unsqueeze") || isTrivialPermute() || is_gather(); - } - bool isReshape() const noexcept { - return isOfType("reshape"); - } - bool isPermute() const noexcept { - return isOfType("permute"); - } - bool is_gather() const noexcept { - return isOfType("gather"); - } - bool isPermuteFusable() const noexcept { - return isPermute() && - (layer->params.count(ov::intel_gna::rt_info::GNATransposeFusable::get_type_info_static()) > 0); - } - bool isPermuteViaReshape() const { - if (!isOfType("reshape")) - return false; - - auto input_dims = layer->insData[0].lock()->getDims(); - auto output_dims = layer->outData[0]->getDims(); - - if (input_dims.size() != output_dims.size()) { - return false; - } - - input_dims.erase(std::remove(input_dims.begin(), input_dims.end(), 1), input_dims.end()); - output_dims.erase(std::remove(output_dims.begin(), output_dims.end(), 1), output_dims.end()); - - if (input_dims != output_dims) { - return false; - } - return true; - } - - // @brief this not only mathematically trivial, has some WA for kaldi case - bool isTrivialPermute() const { - if (!isPermute()) - return false; - - if (isPermuteFusable()) - return true; - - auto layerOrder = layer->GetParamAsInts("order"); - if (layer->insData.empty()) { - return false; // unsupported case - } - auto inputs = layer->insData.begin()->lock(); - auto inputsOrder = inputs->getTensorDesc().getDims(); - - return permute::isTrivialPermute(std::vector{begin(layerOrder), end(layerOrder)}, inputsOrder); - } - bool isNonValuesChangable() const { - return isNonFunctional() || isSplit() || isSlice() || isConcat(); - } - bool is_fq_non_sensitive() const { - return isPermute() || isNonFunctional(); - } - bool isPooling() const noexcept { - return isOfType("pooling"); - } - bool isMaxPooling() const noexcept { - IS_VALID(); - if (!isPooling()) - return false; - return as()->_type == InferenceEngine::PoolingLayer::MAX; - } - bool isMemory() const noexcept { - return isOfType("memory"); - } - // @brief verify that it is Assign layer (Copy -> Memory) - bool isCopyToMemory() const { - if (isCopy()) { - for (auto&& out : getInputTo(layer->outData.front())) { - if (LayerInfo(out.second).isMemory()) { - return true; - } - } - } - return false; - } - bool isCrop() const noexcept { - return isOfType("crop"); - } - bool isCropAffined() const { - auto cropLayer = dynamic_cast(layer); - if (cropLayer != nullptr && !cropLayer->offset.empty()) { - const auto crop_params = GetCropParams(cropLayer); - return limitations::Limitations::get_instance()->is_crop_affined_offset(crop_params.start_offset); - } - return false; - } - bool isCopy() const noexcept { - return isOfType(CopyLayerName) || isOfType(DelayedCopyLayerName); - } - bool isCopyDelayed() const noexcept { - return isOfType(DelayedCopyLayerName); - } - bool isWeightableIdentity() const { - return isConcatAlignFilter() || isSyntheticScaleShift() || isCropAffined(); - } - bool isFusableWithConv() const noexcept { - return isActivation() || isMaxPooling(); - } - - bool isSynthetic() const noexcept { - return isConcatAlignFilter() || isSyntheticScaleShift() || isConvolutionFilter() || isAffineFilter(); - } - - size_t paddingSize() const { - static InferenceEngine::details::caseless_set layersWithPossiblePadding = {"FullyConnected", - "InnerProduct", - "Pooling", - "Convolution"}; - if (layersWithPossiblePadding.find(layer->type) != layersWithPossiblePadding.end()) { - size_t size_without_padding = 0; - IE_ASSERT(!layer->insData.empty()); - auto inputs = layer->insData.begin()->lock(); - if (inputs) { - size_without_padding = InferenceEngine::details::product(begin(inputs->getTensorDesc().getDims()), - end(inputs->getTensorDesc().getDims())); - } - return ALIGN(size_without_padding, 8) - size_without_padding; - } - return 0; - } - template - typename std::enable_if::value, T>::type as() noexcept { - return dynamic_cast(layer); - } - template - typename std::enable_if::value, T>::type as() const noexcept { - return dynamic_cast(layer); - } - operator InferenceEngine::CNNLayer*() noexcept { - return layer; - } - operator const InferenceEngine::CNNLayer*() const noexcept { - return layer; - } - operator InferenceEngine::CNNLayerPtr() const noexcept { - return std::shared_ptr(layer, [](InferenceEngine::CNNLayer* p) {}); - } - -protected: - bool isOfType(const std::string& type) const noexcept { - IS_VALID(); - return InferenceEngine::details::CaselessEq()(layer->type, type); - } -#undef IS_VALID -}; - -inline std::ostream& operator<<(std::ostream& os, const LayerInfo& info) { - os << static_cast(info)->name; - return os; -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_layer_type.cpp b/src/plugins/intel_gna/src/layers/gna_layer_type.cpp deleted file mode 100644 index ebc3ce32b32..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_layer_type.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_layer_type.hpp" - -#include -#include -#include - -#include "gna_layer_info.hpp" - -namespace ov { -namespace intel_gna { - -LayerType LayerTypeFromStr(const std::string& str) { - auto it = LayerNameToType.find(str); - if (it != LayerNameToType.end()) - return it->second; - else - return LayerType::NO_TYPE; -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_layer_type.hpp b/src/plugins/intel_gna/src/layers/gna_layer_type.hpp deleted file mode 100644 index 6f8cd8beb72..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_layer_type.hpp +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "backend/dnn_types.hpp" - -namespace ov { -namespace intel_gna { - -enum class LayerType { - Input, - Convolution, - ReLU, - LeakyReLU, - Sigmoid, - TanH, - Abs, - Activation, - Pooling, - FullyConnected, - InnerProduct, - Reshape, - Squeeze, - Unsqueeze, - Split, - Slice, - Eltwise, - ScaleShift, - Clamp, - Concat, - Const, - Copy, - Permute, - Memory, - Power, - Crop, - Exp, - Log, - Sign, - NegLog, - NegHalfLog, - LSTMCell, - TensorIterator, - SoftSign, - FakeQuantize, - Gemm, - Pwl, - Identity, - GNAConvolution, - GNAMaxPool, - NO_TYPE -}; - -static const InferenceEngine::details::caseless_map LayerNameToType = { - {"Input", LayerType::Input}, - {"Convolution", LayerType::Convolution}, - {"ReLU", LayerType::ReLU}, - {"Sigmoid", LayerType::Sigmoid}, - {"TanH", LayerType::TanH}, - {"Pooling", LayerType::Pooling}, - {"FullyConnected", LayerType::FullyConnected}, - {"InnerProduct", LayerType::InnerProduct}, - {"Split", LayerType::Split}, - {"Slice", LayerType::Slice}, - {"Eltwise", LayerType::Eltwise}, - {"Const", LayerType::Const}, - {"Reshape", LayerType::Reshape}, - {"Squeeze", LayerType::Squeeze}, - {"Unsqueeze", LayerType::Unsqueeze}, - {"ScaleShift", LayerType::ScaleShift}, - {"Clamp", LayerType::Clamp}, - {"Concat", LayerType::Concat}, - {"Copy", LayerType::Copy}, - {"Permute", LayerType::Permute}, - {"Power", LayerType::Power}, - {"Memory", LayerType::Memory}, - {"Crop", LayerType::Crop}, - {"Exp", LayerType::Exp}, - {"Log", LayerType::Log}, - {"Sign", LayerType::Sign}, - {"Abs", LayerType::Abs}, - {"NegLog", LayerType::NegLog}, - {"NegHalfLog", LayerType::NegHalfLog}, - {"LSTMCell", LayerType::LSTMCell}, - {"TensorIterator", LayerType::TensorIterator}, - {"Abs", LayerType::Abs}, - {"SoftSign", LayerType::SoftSign}, - {"FakeQuantize", LayerType::FakeQuantize}, - {"Pwl", LayerType::Pwl}, - {"Identity", LayerType::Identity}, - {"Gemm", LayerType::Gemm}, - {"GNAConvolution", LayerType::GNAConvolution}, - {"GNAMaxPool", LayerType::GNAMaxPool}, -}; - -LayerType LayerTypeFromStr(const std::string& str); - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_memory_layer.hpp b/src/plugins/intel_gna/src/layers/gna_memory_layer.hpp deleted file mode 100644 index 6427e85f1e8..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_memory_layer.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "debug.h" -#include "legacy/ie_layers.h" - -namespace ov { -namespace intel_gna { - -/** - * maps type of connection to input and output layers also stores gna_pointer for alloc request - */ -class GNAMemoryLayer { - InferenceEngine::CNNLayerPtr inputLayer; - InferenceEngine::CNNLayerPtr outputLayer; - const int elementSize; - -public: - GNAMemoryLayer(InferenceEngine::CNNLayerPtr inLayer, InferenceEngine::CNNLayerPtr outLayer, int elementSize) - : inputLayer(inLayer), - outputLayer(outLayer), - elementSize(elementSize) {} - - InferenceEngine::CNNLayerPtr getInput() const { - return inputLayer; - } - InferenceEngine::CNNLayerPtr getOutput() const { - return outputLayer; - } - InferenceEngine::SizeVector getDims() const { - return inputLayer->outData.front()->getDims(); - } - /** - * @brief Get size requred for the gna memory buffer - */ - size_t getByteSize() const { - return InferenceEngine::details::product(getDims()) * elementSizeBytes(); - } - /** - * @brief Reset the gna memory - */ - void Reset() { - std::memset(gna_ptr, 0, reserved_size); - } - - /** - * @brief possible to store memory in different precision - */ - int elementSizeBytes() const { - return elementSize; - } - - /** - * pointer to gna memory request - */ - void* gna_ptr = nullptr; - /** - * gna memory of this size is reserved - */ - size_t reserved_size = 0; - /** - * gna memory of this offset from gna_ptr - */ - size_t reserved_offset = 0; - /** - * scale factor to gna memory layer - */ - float scale_factor = 1.0f; -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_permute.hpp b/src/plugins/intel_gna/src/layers/gna_permute.hpp deleted file mode 100644 index 959f5e1814b..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_permute.hpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include -#include -#include - -#include "ie_common.h" -#include "log/debug.hpp" - -namespace ov { -namespace intel_gna { -namespace permute { - -template -class PermuteSequence { -public: - using cnt_type = std::vector>; - -private: - std::vector orderVec; - cnt_type permutes; - -public: - explicit PermuteSequence(std::vector&& orderVecIn) : orderVec(std::move(orderVecIn)) { - std::vector counter(orderVec.size()); - for (auto&& x : this->orderVec) { - if (x < 0) { - THROW_GNA_EXCEPTION << "invalid order: element " << x << " should be >= 0"; - } - if (static_cast(x) >= counter.size()) { - THROW_GNA_EXCEPTION << "invalid order: element " << x << " should be < " << counter.size(); - } - if (counter[x]) { - THROW_GNA_EXCEPTION << "invalid order: element " << x << " present more than once"; - } - counter[x] = true; - } - - // generating permutation graph - std::fill(counter.begin(), counter.end(), false); - - // length of current cycle - std::list permuteCycles; - bool newSeq = false; - - for (int i = 0; i != static_cast(orderVec.size());) { - // we have this permutation on the list already - if (counter[i]) { - newSeq = false; - i++; - continue; - } - counter[i] = true; - // looks we found a permutation - if (orderVec[i] != i) { - if (!newSeq) { - newSeq = true; - permuteCycles.push_back({}); - } - permuteCycles.back().push_back({i, orderVec[i]}); - counter[i] = true; - i = static_cast(orderVec[i]); - continue; - } - // this dims not permuted - i++; - } - - for (auto&& cycle : permuteCycles) { - for (size_t i = 0; i + 1 < cycle.size(); i++) { - permutes.push_back(cycle[i]); - } - } - } - const cnt_type& cnt() const noexcept { - return permutes; - } -}; - -/** - * @brief generates permutations sequence in order to reach given order - * @tparam Iterator - * @return - */ -template -inline typename PermuteSequence::value_type>::cnt_type genPermutations( - Iterator beg, - Iterator en) { - static_assert(std::is_same::iterator_category>::value, - "The genPermutations() function only accepts random access iterators or raw pointers to an array.\n"); - using value_type = typename std::iterator_traits::value_type; - std::vector v; - for (; beg != en; beg++) { - v.push_back(*beg); - } - auto permute = PermuteSequence(std::move(v)); - return permute.cnt(); -} - -template -inline typename PermuteSequence::cnt_type genPermutations(const std::initializer_list& lst) { - return genPermutations(lst.begin(), lst.end()); -} - -/** - * @brief returns dimensions order for permute from input to output layout - * @param in_layout - * @param out_layout - */ -inline std::vector GetPermuteOrder(InferenceEngine::Layout in_layout, InferenceEngine::Layout out_layout) { - if (in_layout == InferenceEngine::Layout::NHWC && out_layout == InferenceEngine::Layout::NCHW) { - return {0, 3, 1, 2}; - } - if (in_layout == InferenceEngine::Layout::NCHW && out_layout == InferenceEngine::Layout::NHWC) { - return {0, 2, 3, 1}; - } - return {0, 1, 2, 3}; -} - -inline bool isTrivialPermute(const std::vector order, const std::vector& input_shape) { - // cases when all permutations happened either between 1 and X shape where no other dims in between - auto transpose_seq = genPermutations(order.begin(), order.end()); - auto input_order_transformed = input_shape; - for (auto&& transp : transpose_seq) { - // check dims of transposed - if (input_order_transformed[transp.first] == 1 && input_order_transformed[transp.second] == 1) { - return true; - } - if (input_order_transformed[transp.first] != 1 && input_order_transformed[transp.second] != 1) { - return false; - } - // check dims in between - for (int64_t j = std::min(transp.first, transp.second) + 1; j < std::max(transp.first, transp.second); j++) { - if (input_order_transformed[j] != 1) { - return false; - } - } - // apply permutation - std::swap(input_order_transformed[transp.first], input_order_transformed[transp.second]); - } - return true; -} - -} // namespace permute -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/gna_split_layer.hpp b/src/plugins/intel_gna/src/layers/gna_split_layer.hpp deleted file mode 100644 index 7f76f24f761..00000000000 --- a/src/plugins/intel_gna/src/layers/gna_split_layer.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "backend/gna_limitations.hpp" - -namespace ov { -namespace intel_gna { - -// Split, Slice -class GNASplitLayer { - InferenceEngine::CNNLayerPtr splitLayer; - -public: - explicit GNASplitLayer(InferenceEngine::CNNLayerPtr layer) : splitLayer(layer) {} - - InferenceEngine::CNNLayerPtr getSplit() { - return splitLayer; - } - /** - * gna memory of this size is reserved for split - */ - size_t reserved_size = 0; - bool output_allocation_flag = false; - /** - * gna memory of this offset from gna_ptr - */ - struct SplitConnectedLayerInfo { - SplitConnectedLayerInfo() = default; - SplitConnectedLayerInfo(InferenceEngine::CNNLayerPtr connectedTo, int insDataIdx, size_t o, size_t p) - : connectedTo(connectedTo), - insDataIdx(insDataIdx), - offset(o), - pure_size(p) {} - - InferenceEngine::CNNLayerPtr connectedTo; - int insDataIdx = 0; - size_t offset = 0; // in number of elements of input layer - size_t pure_size = 0; - }; - std::vector splitOutputLayers; -}; - -// @brief Returns sizes of split outputs to split the input tensor into aligned parts that are not greater than the -// specified split size or alignment, depending on which one is larger -inline std::vector GetAlignedSplitSizes(uint32_t totalSize, uint32_t splitSize, uint32_t alignment) { - std::vector splitSizes; - uint32_t maxAlignedSplitSize = std::max(splitSize - splitSize % alignment, alignment); - uint32_t usedSize = 0; - while (usedSize < totalSize) { - uint32_t partSize = std::min(totalSize - usedSize, maxAlignedSplitSize); - splitSizes.push_back(partSize); - usedSize += partSize; - } - return splitSizes; -} - -// @brief Returns pair of axis and sizes of split outputs to split the input tensor to aligned parts, taking into -// account GNA HW limitations -inline std::pair> AlignedSplitSizesPerAxis(InferenceEngine::SizeVector dims) { - std::vector splitSizes = {}; - auto totalElementsSize = static_cast(InferenceEngine::details::product(std::begin(dims), std::end(dims))); - auto firstValuableDim = std::find_if(std::begin(dims), std::end(dims), [](size_t val) { - return val > 1; - }); - IE_ASSERT(firstValuableDim != std::end(dims)); - auto splittedElementsSize = static_cast(*firstValuableDim); - auto splittedDimIx = std::distance(std::begin(dims), firstValuableDim); - auto alignment = static_cast(limitations::Limitations::get_instance()->get_memory_alignment()); - - // Split output size should be multiple of device memory alignment to avoid align filters insertion, - // but we need to check if our input size to split exceeds alignment; if not we can always - // split if the remaining size is aligned - auto split_size = limitations::Limitations::kBufferMaxSize * splittedElementsSize / totalElementsSize; - - if (splittedElementsSize <= alignment || split_size < alignment) { - if ((totalElementsSize / splittedElementsSize) % alignment == 0) { - alignment = 1; - } else { - return {splittedDimIx, splitSizes}; - } - } - splitSizes = GetAlignedSplitSizes(splittedElementsSize, split_size, alignment); - return {splittedDimIx, splitSizes}; -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/layers/layers_builder.hpp b/src/plugins/intel_gna/src/layers/layers_builder.hpp deleted file mode 100644 index 2a3ee2ddc69..00000000000 --- a/src/plugins/intel_gna/src/layers/layers_builder.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include "gna_graph_compiler.hpp" - -namespace ov { -namespace intel_gna { - -class LayersBuilder { - using CreatorFnc = std::function; - -public: - LayersBuilder(const std::vector& types, CreatorFnc callback) { - for (auto&& str : types) { - getStorage()[str] = callback; - } - } - static InferenceEngine::details::caseless_unordered_map& getStorage() { - static InferenceEngine::details::caseless_unordered_map LayerBuilder; - return LayerBuilder; - } -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/log/debug.hpp b/src/plugins/intel_gna/src/log/debug.hpp deleted file mode 100644 index 04733a406a1..00000000000 --- a/src/plugins/intel_gna/src/log/debug.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#ifdef GNA_DEBUG - -/** - * @brief used for creating graphviz charts, and layers dump - */ -# define PLOT - -/** - * @brief used for dumping allocated memory - */ -# define GNA_MEMORY_DUMP - -#endif - -/** - * @brief gna_plugin exception unification - */ -#ifdef __PRETTY_FUNCTION__ -# undef __PRETTY_FUNCTION__ -#endif -#if defined(_WIN32) && !defined(__GNUC__) -# define __PRETTY_FUNCTION__ __FUNCSIG__ -#else -# define __PRETTY_FUNCTION__ __FUNCTION__ -#endif - -#define GNA_LAYER_ASSERT(layer, expr) \ - if (!(expr)) { \ - THROW_GNA_LAYER_EXCEPTION(layer) << ": " << #expr; \ - } -#define THROW_GNA_EXCEPTION IE_THROW() << "[openvino_intel_gna_plugin] in function " << __PRETTY_FUNCTION__ << ": " -#define THROW_GNA_LAYER_EXCEPTION(layer) THROW_GNA_EXCEPTION << LAYER_NAME(layer) -#define LAYER_NAME(layer) (layer)->type << " layer : \"" << (layer)->name << "\" " diff --git a/src/plugins/intel_gna/src/log/dump.cpp b/src/plugins/intel_gna/src/log/dump.cpp deleted file mode 100644 index b3cfc370fd1..00000000000 --- a/src/plugins/intel_gna/src/log/dump.cpp +++ /dev/null @@ -1,597 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "dump.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "gna2-model-api.h" -#include "gna2_model_helper.hpp" -#include "gna_device.hpp" -#include "log.hpp" - -using namespace ov::intel_gna::limitations; - -namespace ov { -namespace intel_gna { -namespace dump { - -inline std::string GetLayerType(Gna2OperationType type) { - switch (type) { - case Gna2OperationTypeFullyConnectedAffine: - return "Gna2OperationTypeFullyConnectedAffine"; - case Gna2OperationTypeElementWiseAffine: - return "Gna2OperationTypeElementWiseAffine"; - case Gna2OperationTypeRecurrent: - return "Gna2OperationTypeRecurrent"; - case Gna2OperationTypeConvolution: - return "Gna2OperationTypeConvolution"; - case Gna2OperationTypeTransposition: - return "Gna2OperationTypeTransposition"; - case Gna2OperationTypeCopy: - return "Gna2OperationTypeCopy"; - default: - return "Gna2OperationUNKNOWN"; - } -} - -inline void write_pwl(std::ostream& pwl_file, const Gna2PwlSegment* const segments, const uint32_t numberOfSegments) { - for (uint32_t k = 0; k < numberOfSegments; k++) { - pwl_file << segments[k].Slope << ", " << segments[k].xBase << ", " << segments[k].yBase << "\n"; - } -} - -inline void write_pwl(std::ostream& pwl_file, const Gna2Tensor& activation) { - write_pwl(pwl_file, static_cast(activation.Data), activation.Shape.Dimensions[0]); -} - -inline std::string GetSimpleString(Gna2Shape shape) { - std::stringstream out; - for (uint32_t i = 0; i < shape.NumberOfDimensions; i++) { - out << shape.Dimensions[i]; - if (i + 1 < shape.NumberOfDimensions) - out << 'x'; - } - return out.str(); -} - -template -uint32_t FindInMapOrReturnOne(MapType map, typename MapType::key_type key) { - auto value = map.find(key); - if (value != map.end()) { - return value->second; - } - return 1; -} - -inline uint32_t GetTypeByteSize(Gna2DataType type) { - static const std::map operandTypeMap = {{Gna2DataTypeNone, 1}, - {Gna2DataTypeBoolean, 1}, - {Gna2DataTypeInt4, 1}, - {Gna2DataTypeInt8, 1}, - {Gna2DataTypeInt16, 2}, - {Gna2DataTypeInt32, 4}, - {Gna2DataTypeUint4, 1}, - {Gna2DataTypeUint8, 1}, - {Gna2DataTypeUint16, 2}, - {Gna2DataTypeUint32, 4}, - {Gna2DataTypeUint64, 8}, - {Gna2DataTypeCompoundBias, 8}, - {Gna2DataTypePwlSegment, 8}, - {Gna2DataTypeWeightScaleFactor, 8}}; - return FindInMapOrReturnOne(operandTypeMap, type); -} - -inline uint32_t GetGnaShapeSize(const Gna2Shape& shape, const uint32_t bytesPerElement) { - if (shape.NumberOfDimensions == 0) { - return 0; - } - // to compute aligned filters (each filter begin is aligned to 16B) - // e.g., for 3x3 2B filter, its size is 18B, but the next filter will start at 32B offset - // filters are NHWC - uint32_t nAlignement = 1; - if (shape.NumberOfDimensions == 4 && shape.Dimensions[0] != 1) { - nAlignement = 16; - } - uint32_t total = 1; - for (uint32_t i = 1; i < shape.NumberOfDimensions; i++) { - total *= shape.Dimensions[i]; - } - total *= bytesPerElement; - auto totalAligned = Gna2RoundUp(total, nAlignement); - totalAligned *= shape.Dimensions[0]; - return totalAligned; -} - -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--; - } - if (elementIndex[idx] + 1 >= total.Dimensions[idx] && idx == 0) { - return false; - } - ++(elementIndex[idx]); - while (++idx < total.NumberOfDimensions) { - elementIndex[idx] = 0; - } - return true; -} - -template -uint32_t GetLinearIndex(const T& elementIndex, const Gna2Shape& total) { - uint32_t out = 0; - for (uint32_t idx = 0; idx < total.NumberOfDimensions; idx++) { - out += elementIndex[idx]; - if (idx + 1 < total.NumberOfDimensions) - out *= total.Dimensions[idx + 1]; - } - return out; -} - -template -int32_t GetValue(const Gna2Tensor& tensor, const T& elementIndex) { - int32_t intValue = -123; // fake value indicating problem - const auto linearIndex = GetLinearIndex(elementIndex, tensor.Shape); - if (tensor.Type == Gna2DataTypeInt32) { - intValue = (reinterpret_cast(tensor.Data)[linearIndex]); - } else if (tensor.Type == Gna2DataTypeInt16) { - intValue = reinterpret_cast(tensor.Data)[linearIndex]; - } else { - intValue = reinterpret_cast(tensor.Data)[linearIndex]; - } - return intValue; -} - -void WriteInputAndOutputTextGNAImpl(const Gna2Model& gnaModel, - const std::string dumpFolderNameGNA, - const std::string refFolderName) { - for (uint32_t i = 0; i < gnaModel.NumberOfOperations; i++) { - const auto& operation = gnaModel.Operations[i]; - if (operation.Type == Gna2OperationTypeNone) { - continue; - } - std::stringstream out_file_name; - const auto& outputTensor = *operation.Operands[OutOpIdx]; - const auto& intputTensor = *operation.Operands[InOpIdx]; - - out_file_name << std::setfill('0') << std::setw(2) << i << "_" << GetLayerType(operation.Type) << "-" - << GetSimpleString(intputTensor.Shape) << "-" << GetSimpleString(outputTensor.Shape); - - auto inputfileName = dumpFolderNameGNA + out_file_name.str() + "_input.txt"; - auto outFileName = dumpFolderNameGNA + out_file_name.str() + "_output.txt"; - auto pwlFileName = dumpFolderNameGNA + out_file_name.str() + "_pwl.txt"; - auto refOutputFileName = refFolderName + out_file_name.str() + "_output.txt"; - - std::ofstream out_file(outFileName.c_str(), std::ios::out); - std::ofstream pwl_file(pwlFileName.c_str(), std::ios::out); - std::ifstream ref_out_file(refOutputFileName.c_str(), std::ios::in); - std::ofstream in_file(inputfileName.c_str(), std::ios::out); - - float summOfDiff = 0.f; - float summOfSqDiff = 0.f; - float maxD = 0.0f; - int numItems = 0; - - if (operation.NumberOfOperands > PwlOpIdx && operation.Operands[PwlOpIdx] != nullptr) { - write_pwl(pwl_file, *operation.Operands[PwlOpIdx]); - } - - std::vector elementIndex(outputTensor.Shape.NumberOfDimensions); - - do { - float floatValue = static_cast(GetValue(outputTensor, elementIndex)); - - out_file << std::setw(8) << floatValue << "\n"; - if (ref_out_file) { - float ref_value = 0.f; - ref_out_file >> ref_value; - float diff = (ref_value - floatValue); - diff = diff < 0 ? -diff : diff; - summOfDiff += diff; - summOfSqDiff += diff * diff; - maxD = std::max(maxD, diff); - numItems++; - } - } while (NextElement(elementIndex, outputTensor.Shape)); - - if (numItems) { - auto rmse = std::sqrt(summOfSqDiff / numItems); - auto avg = summOfDiff / numItems; - log::debug() << std::left << std::setw(55) << out_file_name.str() << " RMSE=" << std::fixed - << std::setprecision(5) << std::right << std::setw(8) << rmse << " avg=" << std::fixed - << std::setprecision(5) << std::right << std::setw(8) << avg << " maxD=" << std::fixed - << std::setprecision(5) << std::right << std::setw(8) << maxD << std::endl; - } - - std::vector inputElementIndex(intputTensor.Shape.NumberOfDimensions); - - do { - int32_t intValue = GetValue(intputTensor, inputElementIndex); - in_file << std::setw(8) << intValue; - in_file << "\n"; - } while (NextElement(inputElementIndex, intputTensor.Shape)); - } -} - -template -static std::string GetName(T name, size_t index) { - return name; -} - -template <> -std::string GetName<>(std::vector names, size_t index) { - return names.at(index); -} - -template -std::string FindInMapOrReturnUnknown(MapType map, typename MapType::key_type key, size_t index = 0) { - auto value = map.find(key); - if (value != map.end()) { - return GetName(value->second, index); - } - return std::string{"unknown"}; -} - -inline std::string GetOperandType(Gna2DataType type) { - static const std::map operandTypeMap = { - {Gna2DataTypeNone, "Gna2DataTypeNone"}, - {Gna2DataTypeBoolean, "Gna2DataTypeBoolean"}, - {Gna2DataTypeInt4, "Gna2DataTypeInt4"}, - {Gna2DataTypeInt8, "Gna2DataTypeInt8"}, - {Gna2DataTypeInt16, "Gna2DataTypeInt16"}, - {Gna2DataTypeInt32, "Gna2DataTypeInt32"}, - {Gna2DataTypeUint4, "Gna2DataTypeUint4"}, - {Gna2DataTypeUint8, "Gna2DataTypeUint8"}, - {Gna2DataTypeUint16, "Gna2DataTypeUint16"}, - {Gna2DataTypeUint32, "Gna2DataTypeUint32"}, - {Gna2DataTypeUint64, "Gna2DataTypeUint64"}, - {Gna2DataTypeCompoundBias, "Gna2DataTypeCompoundBias"}, - {Gna2DataTypePwlSegment, "Gna2DataTypePwlSegment"}, - {Gna2DataTypeWeightScaleFactor, "Gna2DataTypeWeightScaleFactor"}}; - return FindInMapOrReturnUnknown(operandTypeMap, type); -} - -inline std::string GetOperandName(Gna2OperationType type, size_t index) { - static const std::map> operationOperandNamesMap = { - {Gna2OperationTypeConvolution, {"inputs", "outputs", "filters", "biases", "activationFunction"}}, - {Gna2OperationTypeCopy, {"inputs", "outputs"}}, - {Gna2OperationTypeFullyConnectedAffine, - {"inputs", "outputs", "weights", "biases", "activationFunction", "weightScaleFactors"}}, - {Gna2OperationTypeElementWiseAffine, {"inputs", "outputs", "weights", "biases", "activationFunction"}}, - {Gna2OperationTypeGmm, {"inputs", "outputs", "means/interleaved", "inverseCovariances", "constants"}}, - {Gna2OperationTypeRecurrent, {"inputs", "outputs", "weights", "biases", "activationFunction"}}, - {Gna2OperationTypeTransposition, {"inputs", "outputs"}}}; - return FindInMapOrReturnUnknown(operationOperandNamesMap, type, index); -} - -inline std::string GetBiasMode(Gna2BiasMode mode) { - static const std::map biasModeMap = {{Gna2BiasModeDefault, "Gna2BiasModeDefault"}, - {Gna2BiasModePerStride, "Gna2BiasModePerStride"}, - {Gna2BiasModeGrouping, "Gna2BiasModeGrouping"}}; - return FindInMapOrReturnUnknown(biasModeMap, mode); -} - -inline std::string GetPoolingMode(Gna2PoolingMode mode) { - static const std::map poolingModeMap = { - {Gna2PoolingModeDisabled, "Gna2PoolingModeDisabled"}, - {Gna2PoolingModeMax, "Gna2PoolingModeMax"}, - {Gna2PoolingModeSum, "Gna2PoolingModeSum"}}; - return FindInMapOrReturnUnknown(poolingModeMap, mode); -} - -inline void DumpShape(std::ostream& dumpFile, Gna2Shape* shape, const std::string paramName) { - dumpFile << "\tParameter name: " << paramName << ", "; - dumpFile << "parameter type: Gna2Shape\n"; - dumpFile << "\t\tNumber of dimensions: " << shape->NumberOfDimensions; - dumpFile << "\n\t\tDimensions: ["; - for (uint32_t i = 0; i < shape->NumberOfDimensions; i++) { - dumpFile << std::setw(8) << shape->Dimensions[i]; - } - dumpFile << "]\n"; -} - -inline void DumpConvolutionParameters(std::ostream& dumpFile, - void** parameters, - size_t knownParamCount, - const std::vector paramNames) { - size_t i = 0; - - while (i < knownParamCount) { - if (i == ConvStrideParamIdx || i == PoolWinParamIdx || i == PoolStrideParamIdx || i == ZeroPaddingParamIdx) { - Gna2Shape* shape = reinterpret_cast(parameters[i]); - if (shape != nullptr) - DumpShape(dumpFile, shape, paramNames[i]); - } else if (i == BiasModeCnnParamIdx) { - Gna2BiasMode* biasMode = reinterpret_cast(parameters[i]); - if (biasMode != nullptr) - dumpFile << "\tParameter name: " << paramNames[i] << ", value: " << GetBiasMode(*biasMode) << "\n"; - } else { - Gna2PoolingMode* poolingMode = reinterpret_cast(parameters[i]); - if (poolingMode != nullptr) - dumpFile << "\tParameter name: " << paramNames[i] << ", value: " << GetPoolingMode(*poolingMode) - << "\n"; - } - i++; - } -} - -inline void DumpCopyParameters(std::ostream& dumpFile, - void** parameters, - size_t knownParamCount, - const std::vector paramNames) { - Gna2Shape* subTensorShape = reinterpret_cast(parameters[CopyShapeParamIdx]); - DumpShape(dumpFile, subTensorShape, paramNames[CopyShapeParamIdx]); -} - -inline void DumpFCAffineParameters(std::ostream& dumpFile, - void** parameters, - size_t knownParamCount, - const std::vector paramNames) { - size_t i = 0; - - while (i < knownParamCount) { - if (i == BiasModeFCAffineParamIdx) { - Gna2BiasMode* biasMode = reinterpret_cast(parameters[BiasModeFCAffineParamIdx]); - if (biasMode != nullptr) - dumpFile << "\tParameter name: " << paramNames[i] << ", value: " << GetBiasMode(*biasMode) << "\n"; - } else { - uint32_t* biasVectorIndex = reinterpret_cast(parameters[BiasModeFCAffineParamIdx]); - if (biasVectorIndex != nullptr) - dumpFile << "\tParameter name: " << paramNames[i] << ", value: " << *biasVectorIndex << "\n"; - } - i++; - } -} - -inline void DumpIntParameter(std::ostream& dumpFile, - void** parameters, - size_t knownParamCount, - const std::vector paramNames) { - uint32_t* param = reinterpret_cast(parameters[0]); - if (param != nullptr) - dumpFile << "\tParameter name: " << paramNames[0] << ", value: " << *param << "\n"; -} - -inline std::vector GetParamaterNames(Gna2OperationType type) { - // This map must be aligned with dumpParamMap in this file - static const std::map> operationParamaterNamesMap = { - {Gna2OperationTypeConvolution, - {"convolutionStride", "biasMode", "poolingMode", "poolingWindow", "poolingStride", "zeroPadding"}}, - {Gna2OperationTypeCopy, {"shape (sub-tensor shape)"}}, - {Gna2OperationTypeFullyConnectedAffine, {"biasMode", "biasVectorIndex"}}, - {Gna2OperationTypeGmm, {"maximumScore"}}, - {Gna2OperationTypeRecurrent, {"delay"}}}; - return operationParamaterNamesMap.find(type) != operationParamaterNamesMap.end() - ? operationParamaterNamesMap.find(type)->second - : std::vector{}; -} - -typedef void (*dumpParameters)(std::ostream&, void**, size_t, const std::vector); - -inline dumpParameters GetParamDumpFunc(Gna2OperationType type) { - // This map must be aligned with operationParamaterNamesMap in this file - static const std::map dumpParamMap = { - {Gna2OperationTypeConvolution, DumpConvolutionParameters}, - {Gna2OperationTypeCopy, DumpCopyParameters}, - {Gna2OperationTypeFullyConnectedAffine, DumpFCAffineParameters}, - {Gna2OperationTypeGmm, DumpIntParameter}, - {Gna2OperationTypeRecurrent, DumpIntParameter}}; - return dumpParamMap.find(type) != dumpParamMap.end() ? dumpParamMap.find(type)->second : nullptr; -} - -inline void DumpPwl(std::ostream& dumpFile, const Gna2Tensor& activation) { - const Gna2PwlSegment* const segments = static_cast(activation.Data); - const uint32_t numberOfSegments = activation.Shape.Dimensions[0]; - - for (uint32_t k = 0; k < numberOfSegments; k++) { - uint32_t scale = ((segments[k].xBase & 3) + 1) * 8; - uint64_t factor = 1ULL << scale; - int32_t B = segments[k].xBase & 0xfffffffc; - double a = static_cast(segments[k].Slope) / factor; - double b = static_cast(segments[k].yBase) - ((static_cast(B) * segments[k].Slope) / factor); - - dumpFile << "\t\tBase input (B) : " << B << ", "; - dumpFile << "Base output (b) : " << segments[k].yBase << ", "; - dumpFile << "Slope (S): " << segments[k].Slope << ", "; - dumpFile << "Shift (scale) : " << scale << ", "; - dumpFile << "y = (" << a << ")x + (" << b << ")"; - if (segments[k].Slope != 0) { - double x0 = - static_cast(B) - ((static_cast(segments[k].yBase) * factor) / segments[k].Slope); - dumpFile << ", x0 = " << x0; - } - dumpFile << "\n"; - } -} - -inline void DumpCompoundBias(std::ostream& dumpFile, const Gna2Tensor& tensor) { - uint32_t i = 0; - - while (i < tensor.Shape.Dimensions[0]) { - const Gna2CompoundBias* const bias = static_cast(tensor.Data) + i; - dumpFile << "\t\tBias for row " << i << " : " << bias->Bias << ", multiplier: " << unsigned(bias->Multiplier) - << "\n"; - i++; - } -} - -inline void DumpCharArray(std::ostream& dumpFile, const char* carray, size_t count) { - size_t i = 0; - while (*(carray + i) != 0 && i < count) { - dumpFile << *(carray + i) << " "; - i++; - } - dumpFile << "\n"; -} - -class GnaMemStats { -public: - void Add(const std::string memory_tag, - const std::string operand_name, - const std::string operation_name, - const uint32_t size) { - if (size == 0) - return; - const std::pair key = std::make_pair(operation_name, memory_tag + " " + operand_name); - m_stats[key] = size; - } - std::string GetFormattedMemStats() { - std::stringstream output; - output << "Per Layer memory statistics: " << std::endl; - // Assumes that std::map with pair keys is lexicographically ordered which is true in this and previous versions - // of C++. - std::string previous_layer = ""; - for (auto pair : m_stats) { - std::string current_layer = pair.first.first; - if (current_layer != previous_layer) { - output << "\t" << current_layer << std::endl; - } - output << "\t\t" << pair.first.second << ": " << pair.second << " bytes." << std::endl; - previous_layer = current_layer; - } - output << "Aggregate memory statistics: " << std::endl; - std::map aggr_stats; - for (auto pair : m_stats) { - const std::string key = pair.first.second; - if (aggr_stats.count(key) == 0) { - aggr_stats[key] = pair.second; - } else { - aggr_stats[key] += pair.second; - } - } - for (auto stat : aggr_stats) { - output << "\t" << stat.first << ": " << stat.second << " bytes." << std::endl; - } - return output.str(); - } - -private: - // uint32_t allows for a little above 4 Gb of size without overflow so it's more than sufficient. - std::map, uint32_t> m_stats; -}; - -void DumpGna2Model(const Gna2Model& gnaModel, - const std::string& dumpFolderNameGNA, - bool dumpData, - const GnaAllocations& allAllocations, - const std::string& modeOfOperation) { - GnaMemStats gna_stats; - std::stringstream dumpFileName; - uint32_t opsNo = gnaModel.NumberOfOperations; - std::time_t currTime = std::time(nullptr); - - dumpFileName << dumpFolderNameGNA << "Gna2ModelDebugDump_" << opsNo << "_layer_" - << std::put_time(std::localtime(&currTime), "%Y%m%d%H%M%S") << modeOfOperation; - - std::ofstream dumpFile(dumpFileName.str() + ".txt", std::ios::out); - - const auto& allAllocationsSorted = allAllocations.GetAllocationsInExportOrder(); - for (auto&& a : allAllocationsSorted) { - dumpFile << "Allocation: ptr=" << a.ptr << "\tsizeRequested=" << a.sizeRequested - << "\tsizeGranted=" << a.sizeGranted << "\t tag=" << a.GetTagName() << "\n"; - } - - dumpFile << "Layers (operations) count: " << opsNo << "\n"; - - for (size_t i = 0; i < opsNo; i++) { - const auto& operation = gnaModel.Operations[i]; - - dumpFile << "------------------------------------------------------------------------\n\n"; - - dumpFile << "Layer (operation): " << i << "\n"; - dumpFile << "Layer (operation) type: " << GetLayerType(operation.Type) << "\n"; - dumpFile << "Number of possible operands: " << operation.NumberOfOperands << "\n"; - - for (size_t j = 0; j < operation.NumberOfOperands; j++) { - if (operation.Operands[j] == nullptr) { - dumpFile << "\tOperand " << j << " == nullptr\n"; - continue; - } - const auto& operand = *operation.Operands[j]; - void* foundPtr = nullptr; - std::string foundName = "AllocationNotFound"; - size_t offset = 0; - auto found = std::find_if(allAllocationsSorted.begin(), - allAllocationsSorted.end(), - [operand](const GnaAllocation& allocation) { - return allocation.getOffset(operand.Data).first; - }); - if (found != allAllocationsSorted.end()) { - foundPtr = found->ptr; - foundName = found->GetTagName(); - offset = found->getOffset(operand.Data).second; - } - const uint32_t size = - Gna2RoundUp(GetGnaShapeSize(operand.Shape, GetTypeByteSize(operand.Type)), - static_cast(Limitations::get_instance()->get_memory_alignment())); - dumpFile << "\tOperand " << j << " (" << GetOperandName(operation.Type, j) << ")" - << " type: " << GetOperandType(operand.Type) << " shape: " << GetSimpleString(operand.Shape) - << " tag: " << foundName << " offset: " << offset << " size: " << size << " data: " << operand.Data - << " baseAlloc: " << foundPtr << " layout: "; - gna_stats.Add(foundName, - GetOperandName(operation.Type, j), - std::to_string(i) + " " + GetLayerType(operation.Type), - size); - DumpCharArray(dumpFile, operand.Layout, GNA2_SHAPE_MAXIMUM_NUMBER_OF_DIMENSIONS); - - if (operand.Type == Gna2DataTypePwlSegment) { - DumpPwl(dumpFile, operand); - } else if (operand.Type == Gna2DataTypeCompoundBias) { - DumpCompoundBias(dumpFile, operand); - } else if (dumpData) { - std::ofstream datFile(dumpFileName.str() + ".dat", std::ios::app); - std::vector elementIndex(operand.Shape.NumberOfDimensions); - - auto beginItr = operand.Shape.Dimensions + 1; - auto endIter = operand.Shape.Dimensions + operand.Shape.NumberOfDimensions; - auto columnsValue = std::accumulate(beginItr, endIter, 1, std::multiplies()); - datFile << "Layer " << i << ", type " << GetLayerType(operation.Type) << ", operand " << j << " - " - << GetOperandName(operation.Type, j) << ", rows: " << operand.Shape.Dimensions[0] - << ", columns: " << columnsValue << "\n"; - - uint32_t ind = 0; - - do { - int32_t value = GetValue(operand, elementIndex); - datFile << std::setw(6) << value; - auto postValueCharackters = (++ind % columnsValue == 0) ? "\n" : ", "; - datFile << postValueCharackters; - } while (NextElement(elementIndex, operand.Shape)); - } - } - - dumpFile << "Parameters: \n"; - - if (operation.NumberOfParameters > 0 && GetParamDumpFunc(operation.Type) != nullptr) { - std::vector paramNames = GetParamaterNames(operation.Type); - if (!paramNames.empty()) { - size_t knownParamCount = operation.NumberOfParameters <= paramNames.size() - ? operation.NumberOfParameters - : paramNames.size(); - GetParamDumpFunc(operation.Type)(dumpFile, operation.Parameters, knownParamCount, paramNames); - } - } - } - dumpFile << "------------------------------------------------------------------------\n\n"; - dumpFile << gna_stats.GetFormattedMemStats() << std::endl; -} - -} // namespace dump -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/log/dump.hpp b/src/plugins/intel_gna/src/log/dump.hpp deleted file mode 100644 index 82319c4b6e5..00000000000 --- a/src/plugins/intel_gna/src/log/dump.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "gna2-model-api.h" -#include "gna_device.hpp" - -namespace ov { -namespace intel_gna { -namespace dump { - -void WriteInputAndOutputTextGNAImpl(const Gna2Model& gnaModel, - const std::string dumpFolderNameGNA, - const std::string refFolderName); - -void DumpGna2Model(const Gna2Model& gnaModel, - const std::string& dumpFolderNameGNA, - bool dumpData, - const GnaAllocations& allAllocations, - const std::string& modeOfOperation); - -} // namespace dump -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/log/log.cpp b/src/plugins/intel_gna/src/log/log.cpp deleted file mode 100644 index 19ba8533958..00000000000 --- a/src/plugins/intel_gna/src/log/log.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "log.hpp" - -namespace ov { -namespace intel_gna { -std::mutex GnaLog::mutex_; -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/log/log.hpp b/src/plugins/intel_gna/src/log/log.hpp deleted file mode 100644 index bd690b4b502..00000000000 --- a/src/plugins/intel_gna/src/log/log.hpp +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "openvino/runtime/properties.hpp" - -namespace ov { -namespace intel_gna { - -/** - * @brief Log manager. It supports all ov::log::Level values. - * To use it need to set log level then just call one of the logging methods: - * GnaLog::Gnalog(ov::log::Level::DEBUG); - * GnaLog::info() << "log message"; // this message will be printed - * GnaLog::trace() << "log message"; // this message shoudl not be printed - */ -class GnaLog { - GnaLog() = default; - - static GnaLog& log(ov::log::Level log_level) { - std::lock_guard guard(mutex_); - GnaLog& obj = get_instance(); - obj.message_level_ = log_level; - obj << "[" << log_level << "]" - << " "; - return obj; - } - - /** Configuration log level. It should be set in the plugin configuration */ - ov::log::Level log_level_ = ov::log::Level::NO; - - /** Log level of particular log message */ - ov::log::Level message_level_ = ov::log::Level::NO; - static std::mutex mutex_; - - static GnaLog& get_instance() { - static GnaLog log_obj; - return log_obj; - } - -public: - GnaLog(const GnaLog&) = delete; - void operator=(const GnaLog&) = delete; - - static void set_log_level(ov::log::Level log_level) { - get_instance().log_level_ = log_level; - } - - static ov::log::Level get_log_level() { - return get_instance().log_level_; - } - - /** - * @brief Set ERROR log level - * @return GnaLog object - */ - static GnaLog& error() { - return log(ov::log::Level::ERR); - } - - /** - * @brief Set WARNING log level - * @return GnaLog object - */ - static GnaLog& warning() { - return log(ov::log::Level::WARNING); - } - - /** - * @brief Set DEBUG log level - * @return GnaLog object - */ - static GnaLog& debug() { - return log(ov::log::Level::DEBUG); - } - - /** - * @brief Set INFO log level - * @return GnaLog object - */ - static GnaLog& info() { - return log(ov::log::Level::INFO); - } - - /** - * @brief Set TRACE log level - * @return GnaLog object - */ - static GnaLog& trace() { - return log(ov::log::Level::TRACE); - } - - template - GnaLog& operator<<(const T& obj) { - if (message_level_ <= log_level_) { - if (message_level_ == ov::log::Level::ERR) { - std::cerr << obj; - } else { - std::cout << obj; - } - } - return *this; - } - - GnaLog& operator<<(std::ostream& (*manip)(std::ostream&)) { - if (message_level_ <= log_level_) { - if (message_level_ == ov::log::Level::ERR) { - std::cerr << manip; - } else { - std::cout << manip; - } - } - return *this; - } -}; - -template -std::string toHexString(T t) { - std::ostringstream o; - o << std::hex << t; - return o.str(); -} - -// alias for GnaLog class to make it aligned with snake style code -using log = GnaLog; - -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/memory/gna_allocator.hpp b/src/plugins/intel_gna/src/memory/gna_allocator.hpp deleted file mode 100644 index e79e4615e9c..00000000000 --- a/src/plugins/intel_gna/src/memory/gna_allocator.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -#include "gna_device.hpp" -#include "memory/gna_mem_requests.hpp" - -namespace ov { -namespace intel_gna { -namespace memory { -/** - * wrap GNA interface into c++ allocator friendly one - */ -class GNAAllocator { - std::shared_ptr _device; - -public: - typedef uint8_t value_type; - - explicit GNAAllocator(std::shared_ptr device) : _device(device) {} - uint8_t* allocate(std::size_t n) { - uint32_t granted = 0; - auto result = _device->alloc(static_cast(n), &granted); - if (result == nullptr || granted == 0) { - throw std::bad_alloc(); - } - return result; - } - void deallocate(uint8_t* p, std::size_t n) { - _device->free(p); - } - void setTag(void* memPtr, memory::rRegion tagValue) { - _device->tagMemoryRegion(memPtr, tagValue); - } -}; - -} // namespace memory -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/memory/gna_mem_regions.hpp b/src/plugins/intel_gna/src/memory/gna_mem_regions.hpp deleted file mode 100644 index 29684b6d619..00000000000 --- a/src/plugins/intel_gna/src/memory/gna_mem_regions.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "log/debug.hpp" - -namespace ov { -namespace intel_gna { -namespace memory { - -/** - * @brief Logical region of model memory. - * Needed for models for embedded GNA - * When model is exported for non-embedded uses its memory is exported following the enum value order - */ -enum rRegion { - REGION_INPUTS = 0x0, - REGION_OUTPUTS = 0x1, - REGION_SCRATCH = 0x10, - REGION_STATES = 0x100, - REGION_RO = 0x1000, - REGION_AUTO = 0x10000, -}; - -inline std::map GetAllRegionsToStrMap() { - return {{REGION_INPUTS, "REGION_INPUTS"}, - {REGION_OUTPUTS, "REGION_OUTPUTS"}, - {REGION_SCRATCH, "REGION_SCRATCH"}, - {REGION_STATES, "REGION_STATES"}, - {REGION_RO, "REGION_RO"}, - {REGION_AUTO, "REGION_AUTO"}}; -} - -inline std::string rRegionToStr(const rRegion region) { - const auto& map = GetAllRegionsToStrMap(); - const auto found = map.find(region); - if (found == map.end()) { - return "UNKNOWN"; - } - return found->second; -} - -} // namespace memory -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/memory/gna_mem_requests.hpp b/src/plugins/intel_gna/src/memory/gna_mem_requests.hpp deleted file mode 100644 index 6fa4b8781ab..00000000000 --- a/src/plugins/intel_gna/src/memory/gna_mem_requests.hpp +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "gna_mem_regions.hpp" - -namespace ov { -namespace intel_gna { -namespace memory { - -enum rType : uint8_t { - REQUEST_STORE = 0x1, - REQUEST_ALLOCATE = 0x2, - REQUEST_BIND = 0x4, - REQUEST_INITIALIZER = 0x8, -}; - -#ifdef GNA_MEMORY_DUMP - -inline const char* rTypeToStr(uint8_t type) { - const char* strType = "UNKNOWN"; - switch (type) { - case REQUEST_STORE: - strType = "REQUEST_STORE"; - break; - case REQUEST_ALLOCATE: - strType = "REQUEST_ALLOCATE"; - break; - case REQUEST_BIND: - strType = "REQUEST_BIND"; - break; - case REQUEST_INITIALIZER | REQUEST_STORE: - case REQUEST_INITIALIZER | REQUEST_ALLOCATE: - case REQUEST_INITIALIZER | REQUEST_BIND: - strType = "INITIALIZER"; - break; - } - return strType; -} - -#endif - -struct MemRequest { - rRegion _region; - uint8_t _type; - void* _ptr_out; - const void* _ptr_in = nullptr; - std::function _initializer; - // holds arbitrary value - std::vector _data; - uint8_t _element_size; - size_t _num_elements; - size_t _alignment; - size_t _offset = 0; - // expansion in bytes due to large depended layers - size_t _padding = 0; - - // fields to sort regions by execution availability - std::pair _life_limits{0, UINT16_MAX}; - - MemRequest(rRegion region, - rType req, - void* ptr_out, - const void* ptr_in, - uint8_t element_size = 0, - size_t num_elements = 0, - size_t alignment = 1, - size_t offset = 0) - : _region(region), - _type(req), - _ptr_out(ptr_out), - _ptr_in(ptr_in), - _element_size(element_size), - _num_elements(num_elements), - _alignment(alignment), - _offset(offset) {} - - /** - * Store value only request - * @tparam T - * @param req - * @param ptr_out - * @param element - * @param num_elements - * @param alignment - */ - template - MemRequest(rRegion region, void* ptr_out, T element, size_t num_elements, size_t alignment = 1) - : _region(region), - _type(REQUEST_STORE), - _ptr_out(ptr_out), - _element_size(sizeof(T)), - _num_elements(num_elements), - _alignment(alignment) { - _data.resize(sizeof(T)); - std::copy(reinterpret_cast(&element), - reinterpret_cast(&element) + sizeof(T), - _data.begin()); - } - - /** - * Store initializer request - * @param req - * @param ptr_out - * @param element - * @param num_elements - * @param alignment - */ - MemRequest(rRegion region, - void* ptr_out, - size_t regionSize, - std::function initializer, - rType req = REQUEST_INITIALIZER, - size_t alignment = 1) - : _region(region), - _type(REQUEST_INITIALIZER | req), - _ptr_out(ptr_out), - _ptr_in(ptr_out), - _initializer(initializer), - _element_size(1), - _num_elements(regionSize), - _alignment(alignment) {} -}; - -} // namespace memory -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/memory/gna_mem_requests_queue.hpp b/src/plugins/intel_gna/src/memory/gna_mem_requests_queue.hpp deleted file mode 100644 index 24478f4e882..00000000000 --- a/src/plugins/intel_gna/src/memory/gna_mem_requests_queue.hpp +++ /dev/null @@ -1,289 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include -#include -#include -#include -#include - -#include "gna_lib_ver_selector.hpp" -#include "gna_mem_requests.hpp" -#include "log/log.hpp" -#include "openvino/runtime/memory_solver.hpp" - -using namespace ov::intel_gna; - -namespace ov { -namespace intel_gna { -namespace memory { - -/** - * @brief get layer id from legacy CNNLayer - */ -inline uint16_t getCNNLayerId(InferenceEngine::CNNLayerPtr layer) { - IE_SUPPRESS_DEPRECATED_START - return layer->userValue.v_int; - IE_SUPPRESS_DEPRECATED_END -} - -/** - * Adapter for requests submission and actual request queue - */ -class GNAMemRequestsQueue { -public: - explicit GNAMemRequestsQueue(rRegion region, size_t mem_alignment) - : _region_type(region), - m_alignment(mem_alignment) {} - virtual ~GNAMemRequestsQueue() {} - - rRegion _region_type; - size_t _size = 0; - std::vector _mem_requests; - std::list> _local_storage; - std::shared_ptr _basePtr = nullptr; - size_t m_alignment; - - /** - * @brief register initialiser to access memory once it is actually allocated - * @param ptr_out - * @param ptr_in - * @param num_bytes - * @param initializer - */ - void push_initializer(InferenceEngine::CNNLayerPtr layer, - void* ptr_out, - size_t num_bytes, - std::function initializer) { - futureHeap().push_back({regionType(), ptr_out, num_bytes, initializer, REQUEST_INITIALIZER, m_alignment}); - if (layer != nullptr) { - futureHeap().back()._life_limits = {0, getCNNLayerId(layer)}; - } - } - - void push_ptr(InferenceEngine::CNNLayerPtr layer, void* ptr_out, const void* ptr_in, size_t num_bytes) { - futureHeap().push_back({regionType(), REQUEST_STORE, ptr_out, ptr_in, 1, num_bytes, m_alignment}); - if (layer != nullptr) { - futureHeap().back()._life_limits = {0, getCNNLayerId(layer)}; - } - } - - /** - * @brief copy input to intermediate buffer, to further use in copying into gna-blob - * @param ptr_out - * @param ptr_in - * @param num_bytes - */ - void push_local_ptr(InferenceEngine::CNNLayerPtr layer, void* ptr_out, const void* ptr_in, size_t num_bytes) { - localStorage().emplace_back(reinterpret_cast(ptr_in), - reinterpret_cast(ptr_in) + num_bytes); - futureHeap().push_back( - {regionType(), REQUEST_STORE, ptr_out, &localStorage().back().front(), 1, num_bytes, m_alignment}); - if (layer != nullptr) { - futureHeap().back()._life_limits = {0, getCNNLayerId(layer)}; - } - } - - /** - * - * @param ptr_out - * @param num_bytes - * @param align_num_bytes - */ - void reserve_ptr(InferenceEngine::CNNLayerPtr layer, void* ptr_out, size_t num_bytes, bool align_num_bytes = true) { - futureHeap().push_back({regionType(), - REQUEST_ALLOCATE, - ptr_out, - nullptr, - 1, - align_num_bytes ? ALIGN(num_bytes, m_alignment) : num_bytes, - m_alignment}); - if (layer != nullptr) { - futureHeap().back()._life_limits = {getCNNLayerId(layer), getCNNLayerId(layer)}; - } - } - - /** - * - * @param source - * @param dest - source is binded to dest pointer after allocation - * @param offset - offset in bytes in source that will be set in dest - * @param num_bytes - bind can request for bigger buffer that originally allocated via reserve(), - * @param align_num_bytes - when true then align memory size to the alignment predefined for the queue - */ - void bind_ptr(InferenceEngine::CNNLayerPtr layer, - void* source, - const void* dest, - size_t offset = 0, - size_t num_bytes = 0, - bool align_num_bytes = true) { - futureHeap().push_back({regionType(), - REQUEST_BIND, - source, - dest, - 1, - align_num_bytes ? ALIGN(num_bytes, m_alignment) : num_bytes, - 1, - offset}); - if (layer != nullptr) { - futureHeap().back()._life_limits = {getCNNLayerId(layer), getCNNLayerId(layer)}; - } - } - - /** - * @brief allows initialisation of previously requested segment, ex. const input of concat layer - * @param ptr_out - previously requested buffer - * @param initializer - initialisation routine to be called on allocated memory - */ - void bind_initializer(InferenceEngine::CNNLayerPtr layer, - void* ptr_out, - std::function initializer) { - futureHeap().push_back({regionType(), ptr_out, 0, initializer, REQUEST_BIND, 1}); - if (layer != nullptr) { - futureHeap().back()._life_limits = {0, getCNNLayerId(layer)}; - } - } - - /** - * @brief allocates buffer and set all its values to T value - */ - template - void push_value(InferenceEngine::CNNLayerPtr layer, void* ptr_out, T value, size_t num_elements) { - futureHeap().push_back({regionType(), ptr_out, value, num_elements, m_alignment}); - if (layer != nullptr) { - futureHeap().back()._life_limits = {0, getCNNLayerId(layer)}; - } - } - - /** - * @brief interface for actual queue storage - */ - rRegion regionType() const { - return _region_type; - } - - std::vector& futureHeap() { - return _mem_requests; - } - - std::list>& localStorage() { - return _local_storage; - } - - virtual size_t calcSize(bool isCompact = false) { - _size = 0; - for (auto& re : _mem_requests) { - if (re._type == REQUEST_BIND || re._ptr_out == nullptr) - continue; - _size += ALIGN(re._num_elements * re._element_size + re._padding, re._alignment); - } - return _size; - } - - size_t getSize() const { - return _size; - } - - void* getBasePtr() const { - return _basePtr.get(); - } - - std::pair getOffset(void* ptr) const { - auto ptrBegin = static_cast(getBasePtr()); - auto size = getSize(); - if (ptr >= ptrBegin && ptr < ptrBegin + size) { - auto curOffset = static_cast(ptr) - ptrBegin; - return {true, static_cast(curOffset)}; - } - return {false, 0}; - } - - template - void iterate_binded(memory::MemRequest& reference, const T& visitor) { - for (auto& re : _mem_requests) { - if ((re._type & REQUEST_BIND) && (re._ptr_in == reference._ptr_out)) { - log::trace() << " [binded=" << re._type << ", ptr=" << re._ptr_out << "]\n"; - visitor(reference, re); - // primitive loop check - if (re._ptr_in == re._ptr_out) - continue; - // TODO: no circular dependency checking, only tree-style dependency with loops supported - iterate_binded(re, visitor); - } - } - } -}; - -class GNAMemRequestsInputsQueue : public GNAMemRequestsQueue { -public: - explicit GNAMemRequestsInputsQueue(size_t alignment) : GNAMemRequestsQueue(REGION_INPUTS, alignment) {} -}; - -class GNAMemRequestsOutputsQueue : public GNAMemRequestsQueue { -public: - explicit GNAMemRequestsOutputsQueue(size_t alignment) : GNAMemRequestsQueue(REGION_OUTPUTS, alignment) {} -}; - -class GNAMemRequestsScratchQueue : public GNAMemRequestsQueue { -public: - explicit GNAMemRequestsScratchQueue(size_t alignment) : GNAMemRequestsQueue(REGION_SCRATCH, alignment) {} - /** - * @brief optimize memory region by reusing buffers - */ - size_t calcSize(bool isCompact = false) override { - if (isCompact) { - _size = 0; - std::vector boxes; - for (size_t i = 0; i < _mem_requests.size(); ++i) { - // skipping BIND, cross-region and empty requests - if (_mem_requests[i]._type & REQUEST_BIND || _mem_requests[i]._ptr_out == nullptr) { - continue; - } - - auto original_with_pad = - ALIGN(_mem_requests[i]._num_elements * _mem_requests[i]._element_size + _mem_requests[i]._padding, - _mem_requests[i]._alignment); - int start = _mem_requests[i]._life_limits.first; - int stop = _mem_requests[i]._life_limits.second; - - boxes.push_back({start, stop, static_cast(original_with_pad), static_cast(i)}); - } - - ov::MemorySolver memSolver(boxes); - _size = memSolver.solve(); - - // setting offsets - for (auto const& box : boxes) { - _mem_requests[box.id]._offset = memSolver.get_offset(static_cast(box.id)); - } - return _size; - } else { - return GNAMemRequestsQueue::calcSize(isCompact); - } - } -}; - -class GNAMemRequestsReadOnlyQueue : public GNAMemRequestsQueue { -public: - explicit GNAMemRequestsReadOnlyQueue(size_t alignment) : GNAMemRequestsQueue(REGION_RO, alignment) {} -}; - -class GNAMemRequestsStatesQueue : public GNAMemRequestsQueue { -public: - explicit GNAMemRequestsStatesQueue(size_t alignment) : GNAMemRequestsQueue(REGION_STATES, alignment) {} -}; - -class GNAMemRequestsBindingsQueue : public GNAMemRequestsQueue { -public: - explicit GNAMemRequestsBindingsQueue(size_t alignment) : GNAMemRequestsQueue(REGION_AUTO, alignment) {} -}; - -} // namespace memory -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/memory/gna_memory.hpp b/src/plugins/intel_gna/src/memory/gna_memory.hpp deleted file mode 100644 index f2714648671..00000000000 --- a/src/plugins/intel_gna/src/memory/gna_memory.hpp +++ /dev/null @@ -1,314 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "gna_allocator.hpp" -#include "gna_lib_ver_selector.hpp" -#include "gna_mem_requests.hpp" -#include "gna_mem_requests_queue.hpp" -#include "log/log.hpp" -#include "memory/gna_allocator.hpp" -#include "openvino/runtime/memory_solver.hpp" - -#ifdef GNA_MEMORY_DUMP -# include -#endif - -namespace ov { -namespace intel_gna { -namespace memory { - -class GNAFloatAllocator : public std::allocator { -public: - void setTag(void*, memory::rRegion) {} -}; - -class GNAMemoryInterface { -public: - virtual GNAMemRequestsQueue* getQueue(rRegion region) = 0; - virtual GNAMemRequestsQueue* getQueue(void* ptr) = 0; - virtual void commit(bool isCompact = false) = 0; - virtual std::pair getOffsetForMerged(void* ptr) = 0; - virtual size_t getRegionBytes(rRegion region) = 0; - virtual size_t getDataMemAlignment() const = 0; - virtual ~GNAMemoryInterface() = default; -}; - -/** - * @brief encapsulate various request to allocate GNA specific memory, - * in order to issue single allocation call and configure actual pointers in requests - * @tparam Allocator - a GNAAllocator in case of actual HW offloads - */ -template -class GNAMemory : public GNAMemoryInterface { -protected: - std::map> _mem_queues; - size_t _total = 0; - Allocator _allocator; - size_t _data_alignment; - size_t _page_alignment; - bool _is_compact_mode = false; - -private: - void initMemQueses() { - _mem_queues[REGION_RO] = tools::make_unique(_data_alignment); - _mem_queues[REGION_INPUTS] = tools::make_unique(_data_alignment); - _mem_queues[REGION_OUTPUTS] = tools::make_unique(_data_alignment); - _mem_queues[REGION_SCRATCH] = tools::make_unique(_data_alignment); - _mem_queues[REGION_STATES] = tools::make_unique(_data_alignment); - _mem_queues[REGION_AUTO] = tools::make_unique(_data_alignment); - } - -public: - explicit GNAMemory(size_t dataAlignment = 1, size_t pageAlignment = 1) - : _data_alignment(dataAlignment), - _page_alignment(pageAlignment) { - initMemQueses(); - } - - explicit GNAMemory(const Allocator& a, size_t dataAlignment = 1, size_t pageAlignment = 1) - : _allocator(a), - _data_alignment(dataAlignment), - _page_alignment(pageAlignment) { - initMemQueses(); - } - - virtual ~GNAMemory() { - // we have to deallocate regions before _allocator is destoyed - _mem_queues.clear(); - } - - /** - * @brief enables memory optimization (compact mode). This mode can be enable in plugin configuration (COMPACT_MODE - * = Yes) - */ - void setCompactMode(bool isCompact) { - _is_compact_mode = isCompact; - } - - /** - * @brief calculates size required for all requests, allocates memory and updates pointers - */ - void commit(bool isCompact = false) override { - setCompactMode(isCompact); - - for (const auto& queue : _mem_queues) { - // 1st stage -- looking for expandable bind requests: - expandBindings(queue.second.get()); - - // 2nd stage -- setup offsets: - setRegionOffsets(queue.second.get()); - - if (queue.second->calcSize(_is_compact_mode) != 0) { - // 3rd stage -- allocation total memory setting to 0 internally - queue.second->_basePtr = allocate(ALIGN(queue.second->getSize(), _page_alignment)); - log::debug() << rRegionToStr(queue.second->_region_type) << "(" - << static_cast(queue.second->_basePtr.get()) << ")" - << " allocated: " << ALIGN(queue.second->getSize(), _page_alignment) << std::endl; - // 4th stage -- setting proper GNA memory region tag for embedded TLV export - _allocator.setTag(queue.second->getBasePtr(), queue.first); - // 5th stage -- store data and updates pointers - allocateRegion(queue.second.get()); - } - } -#ifdef GNA_MEMORY_DUMP - memoryDump(); -#endif - } - - GNAMemRequestsQueue* getQueue(rRegion region) override { - return _mem_queues[region].get(); - } - - GNAMemRequestsQueue* getQueue(void* ptr) override { - for (auto& queuePair : _mem_queues) { - const auto offset = queuePair.second->getOffset(ptr); - if (offset.first) { - return queuePair.second.get(); - } - } - return nullptr; - } - - std::pair getOffsetForMerged(void* ptr) override { - uint32_t curOffset = 0; - for (auto& queuePair : _mem_queues) { - const auto offset = queuePair.second->getOffset(ptr); - if (offset.first) { - curOffset += offset.second; - return {true, curOffset}; - } - const auto size = queuePair.second->getSize(); - curOffset += ALIGN(static_cast(size), static_cast(_data_alignment)); - } - return {false, 0}; - } - - size_t getRegionBytes(rRegion region) override { - return ALIGN(getQueue(region)->calcSize(), _page_alignment); - } - - template - void iterate_binded(memory::MemRequest& reference, const T& visitor) { - for (auto& re : getQueue(REGION_AUTO)->_mem_requests) { - if ((re._type & REQUEST_BIND) && (re._ptr_in == reference._ptr_out)) { - // log::trace() << " [binded=" << rTypeToStr(re._type) << ", ptr=" << re._ptr_out <<"]\n"; - visitor(reference, re); - // primitive loop check - if (re._ptr_in == re._ptr_out) - continue; - // TODO: no circular dependency checking, only tree-style dependency with loops supported - iterate_binded(re, visitor); - } - } -#ifdef GNA_MEMORY_DUMP - memoryDump(); -#endif - } - - size_t getDataMemAlignment() const override { - return _data_alignment; - } - -protected: - std::shared_ptr allocate(size_t bytes) { - Allocator nA = _allocator; - std::shared_ptr sp(_allocator.allocate(bytes), [nA, bytes](uint8_t* p) mutable { - nA.deallocate(p, bytes); - }); - std::fill(sp.get(), sp.get() + bytes, 0); - return sp; - } - - /** - * @brief expand BIND and (BIND | ) requests. Align size(_padding), set execution order - */ - void expandBindings(GNAMemRequestsQueue* mRequests) { - for (auto& originated : mRequests->_mem_requests) { - // skipping bind requests to avoid duplications - if (originated._type & REQUEST_BIND) - continue; - - size_t offset = 0; - iterate_binded(originated, [&](MemRequest& reference, MemRequest& binded) { - // aligning sizes - if (&originated == &reference) - offset = 0; - - offset += binded._offset; - auto current = offset + ALIGN(binded._num_elements * binded._element_size, binded._alignment); - auto original_no_pad = - ALIGN(originated._num_elements * originated._element_size, originated._alignment); - auto original_with_pad = - ALIGN(originated._num_elements * originated._element_size + originated._padding, - originated._alignment); - - originated._padding = - ALIGN(std::max(original_with_pad, current), originated._alignment) - original_no_pad; - - // set execution order - originated._life_limits.first = std::min(originated._life_limits.first, binded._life_limits.first); - originated._life_limits.second = std::max(originated._life_limits.second, binded._life_limits.second); - }); - } - } - - /** - * @brief set offsets for specific region - */ - size_t setRegionOffsets(GNAMemRequestsQueue* mRequests) { - size_t region_offset = 0; - for (auto& re : mRequests->_mem_requests) { - if (re._type & REQUEST_BIND || re._ptr_out == nullptr) - continue; - re._offset = region_offset; - region_offset += ALIGN(re._num_elements * re._element_size + re._padding, re._alignment); - } - return region_offset; - } - - /** - * @brief allocates memory and updates pointers - */ - void allocateRegion(GNAMemRequestsQueue* mRequests) { - size_t r_size = ALIGN(mRequests->getSize(), _page_alignment); - for (auto& re : mRequests->_mem_requests) { - // skipping Bind, crossregion and empty requests - if (re._type == REQUEST_BIND || re._ptr_out == nullptr) - continue; - - auto cptr = mRequests->_basePtr.get() + re._offset; - size_t cptr_avail_size = r_size - re._offset; - auto sz = re._element_size * re._num_elements; - if (re._type & REQUEST_BIND) { - cptr = reinterpret_cast(*reinterpret_cast(re._ptr_out)); - cptr_avail_size = sz; - } else { - *reinterpret_cast(re._ptr_out) = cptr; - } - iterate_binded(re, [](MemRequest& reference, MemRequest& binded) { - *reinterpret_cast(binded._ptr_out) = - binded._offset + reinterpret_cast(*reinterpret_cast(reference._ptr_out)); - binded._num_elements = reference._num_elements; - binded._element_size = reference._element_size; - }); - - log::debug() << static_cast(cptr) << "(" << sz + re._padding << ")" << std::endl; - switch (re._type & ~REQUEST_BIND) { - case REQUEST_ALLOCATE: - break; - case REQUEST_STORE: { - if (re._ptr_in != nullptr) { - ie_memcpy(cptr, cptr_avail_size, re._ptr_in, sz); - } else { - size_t of = 0; - for (size_t i = 0; i < re._num_elements; i++, of += re._element_size) { - std::copy(std::begin(re._data), std::end(re._data), cptr + of); - } - } - break; - } - case REQUEST_INITIALIZER: { - re._initializer(cptr, sz); - break; - } - } - } - } - -#ifdef GNA_MEMORY_DUMP - void memoryDump() { - for (const auto& queue : _mem_queues) { - std::ofstream dumpFile("gna_memory_requests_" + rRegionToStr(queue.first) + ".txt", std::ios::out); - for (auto& re : queue.second->_mem_requests) { - dumpFile << "region: " << rRegionToStr(re._region) << ", " - << "type: " << std::setw(17) << rTypeToStr(re._type) << " " - << "ptr_in: " << std::setw(15) << re._ptr_in << " " - << "ptr_out: " << std::setw(15) << re._ptr_out << " " << std::setw(8) << re._num_elements - << ", " << static_cast(re._element_size) << ", " << re._padding << ", " << std::setw(3) - << re._alignment << ", " << std::setw(8) << re._offset << ", " - << "life_time: " << re._life_limits.first << ":" << re._life_limits.second << ", " - << std::endl; - } - } - } -#endif -}; - -} // namespace memory -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/memory/gna_memory_state.cpp b/src/plugins/intel_gna/src/memory/gna_memory_state.cpp deleted file mode 100644 index d4944c19afd..00000000000 --- a/src/plugins/intel_gna/src/memory/gna_memory_state.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_memory_state.hpp" - -#include "frontend/quantized_layer_params.hpp" -#include "gna_graph_tools.hpp" -#include "ie_layouts.h" -#include "pre_post_process/data_conversion_helpers.hpp" - -namespace ov { -namespace intel_gna { -namespace memory { - -void GNAVariableState::Reset() { - state->Reset(); -} - -InferenceEngine::Precision GNAVariableState::getPrecision() const { - InferenceEngine::Precision state_precision; - - if (state->getInput()) { - state_precision = state->getInput()->precision; - } else { - auto element_size = state->elementSizeBytes(); - switch (element_size) { - case 4: - state_precision = InferenceEngine::Precision::FP32; - break; - case 2: - state_precision = InferenceEngine::Precision::I16; - break; - default: - THROW_GNA_EXCEPTION << "Incorrect state element size " << element_size - << " to determine precision for VariableState " << name; - } - } - - return state_precision; -} - -void GNAVariableState::SetState(const InferenceEngine::Blob::Ptr& newState) { - IE_ASSERT(newState != nullptr); - - auto data_ptr = newState->cbuffer().as(); - IE_ASSERT(data_ptr != nullptr); - auto data_size = newState->byteSize(); - auto data_elements = data_size / newState->element_size(); - if (state->reserved_size > (data_size / (newState->element_size() / state->elementSizeBytes()))) { - THROW_GNA_EXCEPTION << "Failed to SetState. Sizes of new and old states do not match. (" << state->reserved_size - << " != " << (newState->element_size() / state->elementSizeBytes()) << ")"; - } - - InferenceEngine::Precision state_precision = getPrecision(); - auto new_state_precision = newState->getTensorDesc().getPrecision(); - - if (state->gna_ptr == data_ptr) { - return; - } - - if (new_state_precision == state_precision) { - std::memcpy(state->gna_ptr, data_ptr, data_size); - return; - } - - switch (state_precision) { - case InferenceEngine::Precision::I16: { - if (new_state_precision == InferenceEngine::Precision::FP32) { - auto quantized = - InferenceEngine::getInjectedData(state->getInput()); - auto scale_factor = quantized != nullptr ? quantized->_dst_quant.GetScale() : state->scale_factor; - pre_post_processing::ConvertToInt16(static_cast(state->gna_ptr), - newState->buffer().as(), - 1, - static_cast(data_elements), - scale_factor); - } else { - THROW_GNA_EXCEPTION - << "Failed to SetState for VariableState " << name - << ". If old state precision is I16 only I16 and FP32 are allowed as new state precisions." - << " Old state: " << state_precision << " New state: " << new_state_precision; - } - break; - } - default: - THROW_GNA_EXCEPTION << "Failed to SetState for VariableState " << name << ". Incorrect new/old precision pair" - << " Old state: " << state_precision << " New state: " << new_state_precision; - } -} - -InferenceEngine::Blob::CPtr GNAVariableState::GetState() const { - auto elements = state->reserved_size / state->elementSizeBytes(); - InferenceEngine::Precision state_precision = getPrecision(); - - if (state->getInput() && state_precision == InferenceEngine::Precision::I16) { - auto quantized = - InferenceEngine::getInjectedData(state->getInput()); - auto scale_factor = quantized != nullptr ? quantized->_dst_quant.GetScale() : state->scale_factor; - - auto result_blob = - make_blob_with_precision(InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, - InferenceEngine::SizeVector({1, elements}), - InferenceEngine::NC)); - - result_blob->allocate(); - auto buffer = result_blob->buffer().as(); - auto new_gna_ptr = static_cast(state->gna_ptr); - - for (size_t i = 0; i < elements; i++) { - buffer[i] = new_gna_ptr[i] / scale_factor; - } - - return result_blob; - } else { - auto result_blob = - make_blob_with_precision(InferenceEngine::TensorDesc(state_precision, - InferenceEngine::SizeVector({1, elements}), - InferenceEngine::NC)); - result_blob->allocate(); - std::memcpy(result_blob->buffer(), state->gna_ptr, state->reserved_size); - return result_blob; - } -} - -float GNAVariableState::GetScaleFactor() const { - auto quantized = InferenceEngine::getInjectedData(state->getInput()); - auto scale_factor = quantized != nullptr ? quantized->_dst_quant.GetScale() : state->scale_factor; - return scale_factor; -} - -} // namespace memory -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/memory/gna_memory_state.hpp b/src/plugins/intel_gna/src/memory/gna_memory_state.hpp deleted file mode 100644 index 49c4bc1e7b9..00000000000 --- a/src/plugins/intel_gna/src/memory/gna_memory_state.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "gna_plugin.hpp" - -namespace ov { -namespace intel_gna { -namespace memory { - -class GNAVariableState : public InferenceEngine::IVariableStateInternal { -public: - GNAVariableState(std::string name, std::shared_ptr state) - : InferenceEngine::IVariableStateInternal{name}, - state(state) { - IE_ASSERT(state != nullptr); - } - - void Reset() override; - void SetState(const InferenceEngine::Blob::Ptr& newState) override; - InferenceEngine::Blob::CPtr GetState() const override; - float GetScaleFactor() const; - -private: - std::shared_ptr state; - std::string name; - - /** - * @brief Returns InferenceEngine::Precision of input of state depending of element size - * InferenceEngine::Precision::FP32 if element size equals 4 - * InferenceEngine::Precision::I16 if element size equals 2 - * Exception otherwise - */ - InferenceEngine::Precision getPrecision() const; -}; - -} // namespace memory -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/memory/gna_memory_util.cpp b/src/plugins/intel_gna/src/memory/gna_memory_util.cpp deleted file mode 100644 index f04ecb54e3d..00000000000 --- a/src/plugins/intel_gna/src/memory/gna_memory_util.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_memory_util.hpp" - -#include - -#include "log/debug.hpp" - -namespace ov { -namespace intel_gna { -namespace memory { - -int32_t MemoryOffset(void* ptr_target, void* ptr_base) { - auto target = reinterpret_cast(ptr_target); - auto base = reinterpret_cast(ptr_base); - if (target == 0) { // handle NULL pointers separately - return (-1); - } else if (target < base) { - THROW_GNA_EXCEPTION << "Target address value " << target << " is less than base address " << base; - } else { - uint64_t diff = target - base; - if (diff > 0x7fffffff) { - THROW_GNA_EXCEPTION << "Target address value " << target << " too far from base address " << base; - } - return static_cast(diff); - } -} - -} // namespace memory -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/memory/gna_memory_util.hpp b/src/plugins/intel_gna/src/memory/gna_memory_util.hpp deleted file mode 100644 index 34730ff3254..00000000000 --- a/src/plugins/intel_gna/src/memory/gna_memory_util.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace memory { - -int32_t MemoryOffset(void* ptr_target, void* ptr_base); - -} // namespace memory -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/ops/copy.cpp b/src/plugins/intel_gna/src/ops/copy.cpp deleted file mode 100644 index e1db1c177e1..00000000000 --- a/src/plugins/intel_gna/src/ops/copy.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "copy.hpp" - -#include -#include -#include - -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/runtime/host_tensor.hpp" - -namespace ov { -namespace intel_gna { -namespace op { - -Copy::Copy(const ngraph::Output& arg) : Op({arg}) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr Copy::clone_with_new_inputs(const ngraph::OutputVector& new_args) const { - check_new_args_count(this, new_args); - return std::make_shared(new_args.at(0)); -} - -void Copy::validate_and_infer_types() { - set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); -} - -bool Copy::visit_attributes(ngraph::AttributeVisitor& visitor) { - return true; -} - -} // namespace op -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/ops/copy.hpp b/src/plugins/intel_gna/src/ops/copy.hpp deleted file mode 100644 index cf6dee6c399..00000000000 --- a/src/plugins/intel_gna/src/ops/copy.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "ngraph/op/op.hpp" - -namespace ov { -namespace intel_gna { -namespace op { -/// \brief GNA specific copy layer operation -/// -class Copy : public ngraph::op::Op { -public: - OPENVINO_OP("Copy", "intel_gna", ov::op::Op); - - Copy() = default; - /// \brief Constructs a Copy operation. - /// - /// \param [in] arg Input tensor - Copy(const ngraph::Output& arg); - - void validate_and_infer_types() override; - std::shared_ptr clone_with_new_inputs(const ngraph::OutputVector& new_args) const override; - bool visit_attributes(ngraph::AttributeVisitor& visitor) override; -}; -} // namespace op -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/ops/gna_convolution.cpp b/src/plugins/intel_gna/src/ops/gna_convolution.cpp deleted file mode 100644 index 1afc4c27c7d..00000000000 --- a/src/plugins/intel_gna/src/ops/gna_convolution.cpp +++ /dev/null @@ -1,359 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_convolution.hpp" - -#include -#include -#include - -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/runtime/host_tensor.hpp" - -namespace ov { -namespace intel_gna { -namespace op { -namespace internal { - -int64_t calculate_num_spatial(const GNAConvolution* op, - const ov::PartialShape& input_shape, - const ov::PartialShape& filters_shape, - const int64_t& num_non_spatial_data_dims, - const int64_t& num_non_spatial_filter_dims) { - int64_t num_spatial = op->m_num_spatial; - if (num_spatial == -1) { - const auto& input_rank = input_shape.rank(); - const auto& filters_rank = filters_shape.rank(); - - if (const auto& size = op->m_dilations.size()) - num_spatial = static_cast(size); - if (const auto& size = op->m_strides.size()) - num_spatial = static_cast(size); - if (const auto& size = op->m_pads_begin.size()) - num_spatial = static_cast(size); - if (const auto& size = op->m_pads_end.size()) - num_spatial = static_cast(size); - if (input_rank.is_static()) - num_spatial = input_rank.get_length() - num_non_spatial_data_dims; - if (filters_rank.is_static()) - num_spatial = filters_rank.get_length() - num_non_spatial_filter_dims; - } - return num_spatial; -} - -void update_and_validate_attributes(GNAConvolution* op) { - const auto& num_spatial = op->m_num_spatial; - if (num_spatial != -1) { - auto& strides = op->m_strides; - auto& dilations = op->m_dilations; - auto& pad_begin = op->m_pads_begin; - auto& pad_end = op->m_pads_end; - auto& auto_pad = op->m_auto_pad; - - if (strides.empty()) - strides = ov::Strides(num_spatial, 1); - if (dilations.empty()) - dilations = ov::Strides(num_spatial, 1); - if (pad_begin.empty() || auto_pad == ov::op::PadType::VALID) - pad_begin = ov::CoordinateDiff(num_spatial, 0); - if (pad_end.empty() || auto_pad == ov::op::PadType::VALID) - pad_end = ov::CoordinateDiff(num_spatial, 0); - - NODE_VALIDATION_CHECK(op, - static_cast(strides.size()) == num_spatial, - "Strides should be defined for all and only spatial features."); - NODE_VALIDATION_CHECK(op, - static_cast(dilations.size()) == num_spatial, - "Dilations should be defined for all and only spatial features."); - NODE_VALIDATION_CHECK(op, - static_cast(pad_begin.size()) == num_spatial && - static_cast(pad_end.size()) == num_spatial, - "Pads should be defined for all and only spatial features."); - NODE_VALIDATION_CHECK(op, - std::all_of(dilations.begin(), - dilations.end(), - [](const size_t& i) { - return i > 0; - }), - "Filter dilation (", - dilations, - ") has zero dimension."); - NODE_VALIDATION_CHECK(op, - std::all_of(strides.begin(), - strides.end(), - [](const size_t& i) { - return i > 0; - }), - "Filter strides (", - strides, - ") has zero dimension."); - } -} - -// code is based on ngraph/core/shape_inference/include/convolution_shape_inference.hpp -// but instead of NCHW uses NHWC layout - -template -inline bool dynamic_check(const int64_t& num_spatial) { - OPENVINO_ASSERT(num_spatial != -1, - "Convolution shape inference doesn't have enough information for static shape calculation"); - return true; -} - -// FIXME: do we need that function as a template ? -template <> -inline bool dynamic_check(const int64_t& num_spatial) { - return num_spatial != -1; -} - -// FIXME: do we need that function as a template ? -// TODO: search where that function is used in openvino -template -bool resolve_auto_pad_for_shape(const GNAConvolution* op, - ov::CoordinateDiff& pads_begin, - ov::CoordinateDiff& pads_end, - const std::vector& input_shapes, - const int64_t& num_non_spatial_data_dims, - const int64_t& num_non_spatial_filter_dims) { - const auto& auto_pad = op->get_auto_pad(); - if (auto_pad != ov::op::PadType::SAME_UPPER && auto_pad != ov::op::PadType::SAME_LOWER) { - pads_begin = op->m_pads_begin; - pads_end = op->m_pads_end; - return true; - } - - auto& num_spatial = op->m_num_spatial; - if (!dynamic_check(num_spatial)) - return false; - - auto input_shape = input_shapes[0]; - auto filters_shape = input_shapes[1]; - - if (input_shape.rank().is_dynamic()) - input_shape.resize(num_spatial + num_non_spatial_data_dims); - if (filters_shape.rank().is_dynamic()) - filters_shape.resize(num_spatial + num_non_spatial_filter_dims); - - const auto& strides = op->m_strides; - const auto& dilations = op->m_dilations; - pads_begin.resize(num_spatial); - pads_end.resize(num_spatial); - - bool status = true; - for (int64_t i = 0; i < num_spatial; ++i) { - const auto& input_dim = input_shape[i + 1]; - const auto& filters_dim = filters_shape[i + 1]; - if (input_dim.is_static() && filters_dim.is_static()) { - const int64_t& window_dilated_dim = (filters_dim.get_length() - 1) * dilations[i] + 1; - NODE_VALIDATION_CHECK(op, - window_dilated_dim > 0, - "Window after dilation has dimension less than 1 (dim: ", - window_dilated_dim, - ") at axis ", - i, - "."); - - const int64_t& image_size = input_dim.get_length(); - const int64_t& filter_stride = strides[i]; - const int64_t& output_size = (image_size + filter_stride - 1) / filter_stride; - - const int64_t& tmp = (output_size - 1) * filter_stride + window_dilated_dim; - const int64_t& padding_needed = tmp > image_size ? tmp - image_size : 0; - - const size_t& padding_lhs = static_cast(padding_needed / 2); - const size_t& padding_rhs = static_cast(padding_needed - padding_lhs); - - pads_begin[i] = auto_pad == ov::op::PadType::SAME_UPPER ? padding_lhs : padding_rhs; - pads_end[i] = auto_pad == ov::op::PadType::SAME_UPPER ? padding_rhs : padding_lhs; - } else { - status = false; - } - } - return status; -} - -// FIXME: do we need that function as a template ? -// TODO: search where that function is used in openvino -template -void shape_infer(const GNAConvolution* op, - const ov::CoordinateDiff& pads_begin, - const ov::CoordinateDiff& pads_end, - const std::vector& input_shapes, - std::vector& output_shapes) { - NODE_VALIDATION_CHECK(op, input_shapes.size() == 2 && output_shapes.size() == 1); - auto input_shape = input_shapes[0], filters_shape = input_shapes[1]; - - const auto& num_spatial = op->m_num_spatial; - NODE_VALIDATION_CHECK(op, - num_spatial != -1, - "Convolution shape_infer should be provided with correct num_spatial attribute"); - - if (input_shape.rank().is_dynamic()) - input_shape.resize(num_spatial + 2); - if (filters_shape.rank().is_dynamic()) - filters_shape.resize(num_spatial + 2); - - NODE_VALIDATION_CHECK(op, - (static_cast(input_shape.size()) == (num_spatial + 2)) && - (static_cast(filters_shape.size()) == (num_spatial + 2)), - "Data batch and filters rank do not match (data batch shape: ", - input_shape, - ", filters shape: ", - filters_shape, - ")."); - - // ranks are originally static or aligned with num_spatial, attributes assumed to be valid - auto& output_shape = output_shapes[0]; - output_shape.resize(num_spatial + 2); - output_shape[0] = input_shape[0]; - // Channel is the last in NHWC layout - *(output_shape.rbegin()) = filters_shape[0]; // NHWC C is last instead of filters_shape[0] for NCHW layout - - const auto n_data_channel = *(input_shape.rbegin()); - const auto n_filter_channel = *(filters_shape.rbegin()); - - NODE_VALIDATION_CHECK( - op, - n_data_channel.compatible(n_filter_channel), // instead of input_shape[1].compatible(filters_shape[1]), - "Data batch channel count (", - n_data_channel, // instead of input_shape[1], - ") does not match filter input ", - "channel count (", - n_filter_channel, // instead of filters_shape[1], - ")."); - - const auto& dilations = op->m_dilations; - const auto& strides = op->m_strides; - - for (int64_t i = 0; i < num_spatial; ++i) { - const auto& input_dim = input_shape[i + 1]; - const auto& filters_dim = filters_shape[i + 1]; - if (input_dim.is_static() && filters_dim.is_static()) { - const int64_t& window_dilated_dim = (filters_dim.get_length() - 1) * dilations[i] + 1; - NODE_VALIDATION_CHECK(op, - window_dilated_dim > 0, - "Window after dilation has dimension less than 1 (dim: ", - window_dilated_dim, - ") at axis ", - i, - "."); - - const int64_t& data_padded_dilated_dim = input_dim.get_length() + pads_begin[i] + pads_end[i]; - NODE_VALIDATION_CHECK(op, - window_dilated_dim <= data_padded_dilated_dim, - "Window after dilation has dimension (dim: ", - window_dilated_dim, - ") larger than the data shape after padding (dim: ", - data_padded_dilated_dim, - ") at axis ", - i, - "."); - output_shape[i + 1] = (data_padded_dilated_dim - window_dilated_dim) / strides[i] + 1; - } - } -} - -} // namespace internal - -GNAConvolution::GNAConvolution(const ov::Output& data_batch, - const ov::Output& filters, - const ov::Output& bias, - const ov::Strides& strides, - const ov::CoordinateDiff& pads_begin, - const ov::CoordinateDiff& pads_end, - const ov::Strides& dilations, - const ov::op::PadType& auto_pad) - : ov::op::Op({data_batch, filters, bias}), - m_strides(strides), - m_dilations(dilations), - m_pads_begin(pads_begin), - m_pads_end(pads_end), - m_auto_pad(auto_pad) { - constructor_validate_and_infer_types(); -} - -GNAConvolution::GNAConvolution(const ov::Output& data_batch, - const ov::Output& filters, - const ov::Strides& strides, - const ov::CoordinateDiff& pads_begin, - const ov::CoordinateDiff& pads_end, - const ov::Strides& dilations, - const ov::op::PadType& auto_pad) - : ov::op::Op({data_batch, filters}), - m_strides(strides), - m_dilations(dilations), - m_pads_begin(pads_begin), - m_pads_end(pads_end), - m_auto_pad(auto_pad) { - constructor_validate_and_infer_types(); -} - -bool GNAConvolution::visit_attributes(ov::AttributeVisitor& visitor) { - visitor.on_attribute("strides", m_strides); - visitor.on_attribute("dilations", m_dilations); - visitor.on_attribute("pads_begin", m_pads_begin); - visitor.on_attribute("pads_end", m_pads_end); - visitor.on_attribute("auto_pad", m_auto_pad); - return true; -} - -void GNAConvolution::validate_and_infer_types() { - ov::element::Type data_batch_et = get_input_element_type(0); - ov::element::Type filters_et = get_input_element_type(1); - - ov::element::Type result_et; - NODE_VALIDATION_CHECK(this, - ov::element::Type::merge(result_et, data_batch_et, filters_et), - "Element types for data batch and filters do not match (data batch element type: ", - data_batch_et, - ", filters element type: ", - filters_et, - ")."); - - NODE_VALIDATION_CHECK(this, - result_et.is_real() || result_et.is_integral_number(), - "Element types must be numeric. Got: ", - result_et); - auto& data_shape = get_input_partial_shape(0); - auto& filter_shape = get_input_partial_shape(1); - - m_num_spatial = internal::calculate_num_spatial(this, data_shape, filter_shape, 2, 2); - internal::update_and_validate_attributes(this); - - std::vector input_shapes = {data_shape, filter_shape}; - std::vector output_shapes = {ov::PartialShape{}}; - - if (m_num_spatial != -1) { - internal::resolve_auto_pad_for_shape(this, m_pads_begin, m_pads_end, input_shapes, 2, 2); - internal::shape_infer(this, m_pads_begin, m_pads_end, input_shapes, output_shapes); - } - - set_output_type(0, result_et, output_shapes[0]); -} - -std::shared_ptr GNAConvolution::clone_with_new_inputs(const ov::OutputVector& new_args) const { - if (new_args.size() == 2) { - return std::make_shared(new_args.at(0), - new_args.at(1), - m_strides, - m_pads_begin, - m_pads_end, - m_dilations, - m_auto_pad); - } else if (new_args.size() == 3) { - return std::make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - m_strides, - m_pads_begin, - m_pads_end, - m_dilations, - m_auto_pad); - } - - OPENVINO_THROW("Unsupported number of arguments for GNAConvolution operation"); -} -} // namespace op -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/ops/gna_convolution.hpp b/src/plugins/intel_gna/src/ops/gna_convolution.hpp deleted file mode 100644 index f7ab08e1589..00000000000 --- a/src/plugins/intel_gna/src/ops/gna_convolution.hpp +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "ngraph/coordinate_diff.hpp" -#include "ngraph/node.hpp" -#include "ngraph/op/op.hpp" -#include "openvino/op/op.hpp" - -namespace ov { -namespace intel_gna { -namespace op { - -class GNAConvolution; - -namespace internal { - -int64_t calculate_num_spatial(const ov::intel_gna::op::GNAConvolution* op, - const ov::PartialShape& input_shape, - const ov::PartialShape& filters_shape, - const int64_t& num_non_spatial_data_dims, - const int64_t& num_non_spatial_filter_dims); - -void update_and_validate_attributes(ov::intel_gna::op::GNAConvolution* op); - -template -bool resolve_auto_pad_for_shape(const ov::intel_gna::op::GNAConvolution* op, - ov::CoordinateDiff& pads_begin, - ov::CoordinateDiff& pads_end, - const std::vector& input_shapes, - const int64_t& num_non_spatial_data_dims, - const int64_t& num_non_spatial_filter_dims); -template -void shape_infer(const ov::intel_gna::op::GNAConvolution* op, - const ov::CoordinateDiff& pads_begin, - const ov::CoordinateDiff& pads_end, - const std::vector& input_shapes, - std::vector& output_shapes); - -} // namespace internal - -/** - * @brief Activation modes for fused convolutions. - * - */ -enum class ActivationType { SIGMOID, RELU, TANH, ABS, LOG, EXP, SIGN, CLAMP, NO_ACTIVATION }; - -/// \brief Convolution with NHWC layout -/// -class GNAConvolution : public ov::op::Op { -public: - OPENVINO_OP("GNAConvolution", "intel_gna", ov::op::Op); - - /// \brief Constructs a convolution operation. - GNAConvolution() = default; - /// \brief Constructs a convolution operation. - /// - /// \param data_batch The node producing the input data batch tensor.
- /// `[N, C_IN, D1, ... Df]` - /// \param filters The node producing the filters tensor.
- /// `[C_OUT, C_IN, F1, ... Ff]` - /// \param strides The strides.
- /// `[f]` - /// \param dilations The dilations.
- /// `[f]` - /// \param pads_begin The beginning of padding shape.
- /// `[f]` - /// \param pads_end The end of padding shape.
- /// `[f]` - /// \param auto_pad The pad type for automatically computing padding sizes.
- /// `[f]` - /// - /// Output `[N, C_OUT, R1, ... Rf]` - /// - GNAConvolution(const ov::Output& data_batch, - const ov::Output& filters, - const ov::Output& bias, - const ov::Strides& strides, - const ov::CoordinateDiff& pads_begin, - const ov::CoordinateDiff& pads_end, - const ov::Strides& dilations, - const ov::op::PadType& auto_pad = ov::op::PadType::EXPLICIT); - - GNAConvolution(const ov::Output& data_batch, - const ov::Output& filters, - const ov::Strides& strides, - const ov::CoordinateDiff& pads_begin, - const ov::CoordinateDiff& pads_end, - const ov::Strides& dilations, - const ov::op::PadType& auto_pad = ov::op::PadType::EXPLICIT); - - void validate_and_infer_types() override; - bool visit_attributes(ov::AttributeVisitor& visitor) override; - - std::shared_ptr clone_with_new_inputs(const ov::OutputVector& new_args) const override; - - /// \return The strides. - const ov::Strides& get_strides() const { - return m_strides; - } - void set_strides(const ov::Strides& strides) { - m_strides = strides; - } - /// \return The dilations. - const ov::Strides& get_dilations() const { - return m_dilations; - } - void set_dilations(const ov::Strides& dilations) { - m_dilations = dilations; - } - /// \return The padding-below sizes (possibly negative). - const ov::CoordinateDiff& get_pads_begin() const { - return m_pads_begin; - } - void set_pads_begin(const ov::CoordinateDiff& pads_begin) { - m_pads_begin = pads_begin; - } - /// \return The padding-above sizes (possibly negative). - const ov::CoordinateDiff& get_pads_end() const { - return m_pads_end; - } - void set_adding_above(const ov::CoordinateDiff& pads_end) { - m_pads_end = pads_end; - } - /// \return The pad type for pooling. - ov::op::PadType get_auto_pad() const { - return m_auto_pad; - } - void set_auto_pad(const ov::op::PadType& auto_pad) { - m_auto_pad = auto_pad; - } - bool has_bias() const { - return m_has_add_node; - } - ActivationType get_activation() const { - return m_activation_type; - } - void set_activation(ActivationType activation_type) { - m_activation_type = activation_type; - } - -protected: - ov::Strides m_strides; - ov::Strides m_dilations; - ov::CoordinateDiff m_pads_begin; - ov::CoordinateDiff m_pads_end; - ov::op::PadType m_auto_pad; - int64_t m_num_spatial = -1; - -private: - friend int64_t internal::calculate_num_spatial(const ov::intel_gna::op::GNAConvolution* op, - const ov::PartialShape& input_shape, - const ov::PartialShape& filters_shape, - const int64_t& num_non_spatial_data_dims, - const int64_t& num_non_spatial_filter_dims); - - friend void internal::update_and_validate_attributes(ov::intel_gna::op::GNAConvolution* op); - - template - friend bool internal::resolve_auto_pad_for_shape(const ov::intel_gna::op::GNAConvolution* op, - ov::CoordinateDiff& pads_begin, - ov::CoordinateDiff& pads_end, - const std::vector& input_shapes, - const int64_t& num_non_spatial_data_dims, - const int64_t& num_non_spatial_filter_dims); - template - friend void internal::shape_infer(const ov::intel_gna::op::GNAConvolution* op, - const ov::CoordinateDiff& pads_begin, - const ov::CoordinateDiff& pads_end, - const std::vector& input_shapes, - std::vector& output_shapes); - bool m_has_add_node; - ActivationType m_activation_type; -}; -} // namespace op -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/ops/gna_max_pool.cpp b/src/plugins/intel_gna/src/ops/gna_max_pool.cpp deleted file mode 100644 index d82f164c4b8..00000000000 --- a/src/plugins/intel_gna/src/ops/gna_max_pool.cpp +++ /dev/null @@ -1,277 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_max_pool.hpp" - -#include - -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/node.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/validation_util.hpp" - -namespace ov { -namespace intel_gna { -namespace op { -// -// Infers the output batch shape and element type for batched pooling fprop. -// -ov::PartialShape infer_batched_pooling_forward(const ov::Node* node, - const ov::PartialShape& data_batch_shape, - const ov::CoordinateDiff& data_padding_below, - const ov::CoordinateDiff& data_padding_above, - const ov::PartialShape& window_shape, - const ov::Strides& window_strides, - bool is_window_all_in_padding_allowed, - bool ceil_mode, - const ov::Strides& window_dilation); - -// -// Infers the output batch shape and element type for batched pooling fprop. -// -ov::PartialShape infer_batched_pooling_forward(const ov::Node* node, - const ov::PartialShape& data_batch_shape, - const ov::CoordinateDiff& data_padding_below, - const ov::CoordinateDiff& data_padding_above, - const ov::PartialShape& window_shape, - const ov::Strides& window_strides, - bool is_window_all_in_padding_allowed, - bool ceil_mode, - const ov::Strides& window_dilation) { - NODE_VALIDATION_CHECK(node, - data_batch_shape.rank().is_dynamic() || - (data_batch_shape.rank().get_length() >= 3 && data_batch_shape.rank().get_length() <= 5), - "Data batch must have rank of at least 4 or 5 (one batch axis, ", - "one input-channel axis, and two or three spatial dimension) ", - "(data batch shape: ", - data_batch_shape, - ")."); - - ov::PartialShape data_spatial_shape{ov::PartialShape::dynamic()}; - - NODE_VALIDATION_CHECK(node, - data_spatial_shape.merge_rank(data_batch_shape.rank() - 2) && - data_spatial_shape.merge_rank(data_padding_below.size()) && - data_spatial_shape.merge_rank(data_padding_above.size()) && - data_spatial_shape.merge_rank(window_shape.rank()) && - data_spatial_shape.merge_rank(window_strides.size()), - "Ranks for data item shape (data batch has shape ", - data_batch_shape, - ", so data item rank is ", - (data_batch_shape.rank() - 2), - "), padding below (", - data_padding_below, - "), padding above (", - data_padding_above, - "), window shape (", - window_shape, - "), and window strides (", - window_strides, - ") do not match."); - - ov::Dimension batch_size{ov::Dimension::dynamic()}; - ov::Dimension channel_count{ov::Dimension::dynamic()}; - ov::PartialShape data_output_spatial_shape{ov::PartialShape::dynamic(data_spatial_shape.rank())}; - - if (data_batch_shape.rank().is_static()) { - batch_size = data_batch_shape[0]; - channel_count = *(data_batch_shape.end() - 1); // EMUTEX fix NCHW -> NHWC from data_batch_shape[1] - - for (int64_t i = 0; i < data_spatial_shape.rank().get_length(); i++) { - data_spatial_shape[i] = - data_batch_shape[i + - 1]; // EMUTEX fix NCHW -> NHWC from data_spatial_shape[i] = data_batch_shape[i + 2] - } - - NODE_VALIDATION_CHECK(node, batch_size.is_dynamic() || batch_size.get_length() > 0, "Batch size is zero."); - - NODE_VALIDATION_CHECK(node, - channel_count.is_dynamic() || channel_count.get_length() > 0, - "Channel count is zero."); - - // For pooling ops we don't need dilation, so we fill in the identity value (all 1). - ov::Strides data_dilation(data_spatial_shape.rank().get_length(), 1); - ov::Strides dilations = window_dilation; - // if the window_dilation was not specified, generate the default value (no dilations) - if (window_dilation.empty()) { - // dilations equal to 1 for each spatial axis mean that the window is not dilated - dilations = ov::Strides(data_spatial_shape.rank().get_length(), 1); - } - - data_output_spatial_shape = ngraph::infer_windowed_reduction_output_shape(node, - data_spatial_shape, - data_dilation, - data_padding_below, - data_padding_above, - window_shape, - window_strides, - dilations, - is_window_all_in_padding_allowed, - ceil_mode); - } - - ov::PartialShape data_batch_output_shape{ov::PartialShape::dynamic(data_output_spatial_shape.rank() + 2)}; - data_batch_output_shape[0] = batch_size; - *(data_batch_output_shape.end() - 1) = - channel_count; // EMUTEX fix NCHW -> NHWC data_batch_output_shape[1] = channel_count; - - for (int64_t i = 0; i < data_spatial_shape.rank().get_length(); i++) { - data_batch_output_shape[i + 1] = - data_output_spatial_shape[i]; // EMUTEX fix NCHW -> NHWC data_batch_output_shape[i + 2] = - // data_output_spatial_shape[i]; - } - - return data_batch_output_shape; -} - -GNAMaxPool::GNAMaxPool(const ov::Output& arg, - const ov::Strides& strides, - const ov::Shape& pads_begin, - const ov::Shape& pads_end, - const ov::Shape& kernel, - const ov::op::RoundingType rounding_type, - const ov::op::PadType auto_pad) - : Op({arg}), - m_kernel(kernel), - m_strides(strides), - m_pads_begin(pads_begin), - m_pads_end(pads_end), - m_auto_pad(auto_pad), - m_rounding_type(rounding_type) { - constructor_validate_and_infer_types(); -} - -bool GNAMaxPool::visit_attributes(ov::AttributeVisitor& visitor) { - visitor.on_attribute("strides", m_strides); - visitor.on_attribute("pads_begin", m_pads_begin); - visitor.on_attribute("pads_end", m_pads_end); - visitor.on_attribute("kernel", m_kernel); - visitor.on_attribute("rounding_type", m_rounding_type); - visitor.on_attribute("auto_pad", m_auto_pad); - return true; -} - -void GNAMaxPool::validate_and_infer_types() { - if (0 == m_strides.size()) { - m_strides = ov::Strides(m_kernel.size(), 1); - } - - if (0 == m_pads_begin.size()) { - m_pads_begin = ov::Shape(m_kernel.size(), 0); - } - - if (0 == m_pads_end.size()) { - m_pads_end = ov::Shape(m_kernel.size(), 0); - } - - const ov::PartialShape& arg_shape = get_input_partial_shape(0); - - NODE_VALIDATION_CHECK( - this, - arg_shape.rank().compatible(3) || arg_shape.rank().compatible(4) || arg_shape.rank().compatible(5), - "Expected a 3D, 4D or 5D tensor for the input. Got: ", - arg_shape); - - if (arg_shape.rank().is_static()) { - NODE_VALIDATION_CHECK(this, - static_cast(m_pads_end.size()) == arg_shape.rank().get_max_length() - 2, - "Expected pads_end size to be equal to input size - 2. Got: ", - m_pads_end.size()); - - NODE_VALIDATION_CHECK(this, - static_cast(m_pads_begin.size()) == arg_shape.rank().get_max_length() - 2, - "Expected pads_begin size to be equal to input size - 2. Got: ", - m_pads_begin.size()); - NODE_VALIDATION_CHECK(this, - static_cast(m_kernel.size()) == arg_shape.rank().get_max_length() - 2, - "Expected kernel size to be equal to input size - 2. Got: ", - m_kernel.size()); - NODE_VALIDATION_CHECK(this, - static_cast(m_strides.size()) == arg_shape.rank().get_max_length() - 2, - "Expected strides size to be equal to input size - 2. Got: ", - m_strides.size()); - } - - const ov::PartialShape output_shape = infer_output_shape(ov::Strides{}); // no dilations of the filter window - - set_output_type(0, get_input_element_type(0), output_shape); -} - -ov::PartialShape GNAMaxPool::infer_output_shape(const ov::Strides& dilations) { - const auto& arg_shape = get_input_partial_shape(0); - - bool update_auto_padding_succeed = true; - - if (m_auto_pad == ov::op::PadType::SAME_UPPER || m_auto_pad == ov::op::PadType::SAME_LOWER) { - const auto filter_dilations = dilations.empty() ? ov::Strides(m_kernel.size(), 1) : dilations; - update_auto_padding_succeed = update_auto_padding(arg_shape, filter_dilations, m_pads_end, m_pads_begin); - } - if (m_auto_pad == ov::op::PadType::VALID) { - m_pads_end = ov::Shape(m_pads_end.size(), 0); - m_pads_begin = ov::Shape(m_pads_begin.size(), 0); - } - - auto output_shape = ov::PartialShape::dynamic(); - if (update_auto_padding_succeed) { - ov::CoordinateDiff pads_begin(m_pads_begin.begin(), m_pads_begin.end()); - ov::CoordinateDiff pads_end(m_pads_end.begin(), m_pads_end.end()); - output_shape = ov::intel_gna::op::infer_batched_pooling_forward(this, - get_input_partial_shape(0), - pads_begin, - pads_end, - m_kernel, - m_strides, - true, - m_rounding_type == ov::op::RoundingType::CEIL, - dilations); - } else { - if (arg_shape.rank().is_static()) { - output_shape = std::vector(arg_shape.rank().get_max_length(), ov::Dimension::dynamic()); - if (arg_shape[0].is_static()) { - output_shape[0] = arg_shape[0]; // batch size - } - if ((arg_shape.end() - 1)->is_static()) { // EMUTEX FIXED: from [1] to end() - 1 NCHW -> NHWC - *(output_shape.end() - 1) = *(arg_shape.end() - 1); // channel size - } - } - } - - return output_shape; -} - -bool GNAMaxPool::update_auto_padding(const ov::PartialShape& in_shape, - const ov::Strides& filter_dilations, - ov::Shape& new_pads_end, - ov::Shape& new_pads_begin) const { - bool update_auto_padding_succeed = true; - if (m_auto_pad == ov::op::PadType::SAME_UPPER || m_auto_pad == ov::op::PadType::SAME_LOWER) { - ov::CoordinateDiff pads_end, pads_begin; - update_auto_padding_succeed = ngraph::try_apply_auto_padding(in_shape, - m_kernel, - m_strides, - filter_dilations, - m_auto_pad, - pads_end, - pads_begin); - new_pads_end = ov::Shape(pads_end.begin(), pads_end.end()); - new_pads_begin = ov::Shape(pads_begin.begin(), pads_begin.end()); - } - return update_auto_padding_succeed; -} - -std::shared_ptr GNAMaxPool::clone_with_new_inputs(const ov::OutputVector& new_args) const { - check_new_args_count(this, new_args); - return std::make_shared(new_args.at(0), - m_strides, - m_pads_begin, - m_pads_end, - m_kernel, - m_rounding_type, - m_auto_pad); -} - -} // namespace op -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/ops/gna_max_pool.hpp b/src/plugins/intel_gna/src/ops/gna_max_pool.hpp deleted file mode 100644 index 69a69b04dc4..00000000000 --- a/src/plugins/intel_gna/src/ops/gna_max_pool.hpp +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "ngraph/node.hpp" -#include "openvino/op/op.hpp" -#include "openvino/op/util/attr_types.hpp" -#include "openvino/op/util/max_pool_base.hpp" - -namespace ov { -namespace intel_gna { -namespace op { -/// \brief Batched max pooling operation. -class GNAMaxPool : public ov::op::Op { -public: - OPENVINO_OP("GNAMaxPool", "intel_gna", ov::op::Op); - - /// \brief Constructs a batched max pooling operation. - GNAMaxPool() = default; - - /// \brief Constructs a batched max pooling operation. - /// - /// \param arg The node producing the input data batch tensor. - /// \param strides The strides. - /// \param pads_begin The beginning of padding shape. - /// \param pads_end The end of padding shape. - /// \param kernel The kernel shape. - /// \param rounding_type Whether to use ceiling or floor rounding type while - /// computing output shape. - /// \param auto_pad The pad type for automatically computing padding sizes. - GNAMaxPool(const ov::Output& arg, - const ov::Strides& strides, - const ov::Shape& pads_begin, - const ov::Shape& pads_end, - const ov::Shape& kernel, - const ov::op::RoundingType rounding_type = ov::op::RoundingType::FLOOR, - const ov::op::PadType auto_pad = ov::op::PadType::EXPLICIT); - - void validate_and_infer_types() override; - bool visit_attributes(ov::AttributeVisitor& visitor) override; - - /// \return The kernel shape. - const ov::Shape& get_kernel() const { - return m_kernel; - } - void set_kernel(const ov::Shape& kernel) { - m_kernel = kernel; - } - /// \return The strides. - const ov::Strides& get_strides() const { - return m_strides; - } - void set_strides(const ov::Strides& strides) { - m_strides = strides; - } - /// \return The beginning of padding shape. - const ov::Shape& get_pads_begin() const { - return m_pads_begin; - } - void set_pads_begin(const ov::Shape& pads_begin) { - m_pads_begin = pads_begin; - } - /// \return The end of padding shape. - const ov::Shape& get_pads_end() const { - return m_pads_end; - } - void set_adding_above(const ov::Shape& pads_end) { - m_pads_end = pads_end; - } - /// \return The pad type for pooling. - ov::op::PadType get_auto_pad() const { - return m_auto_pad; - } - void set_auto_pad(const ov::op::PadType auto_pad) { - m_auto_pad = auto_pad; - } - /// \return The ceiling mode being used for output shape computations - ov::op::RoundingType get_rounding_type() const { - return m_rounding_type; - } - void set_rounding_type(ov::op::RoundingType rounding_type) { - m_rounding_type = rounding_type; - } - - std::shared_ptr clone_with_new_inputs(const ov::OutputVector& new_args) const override; - -protected: - bool update_auto_padding(const ov::PartialShape& in_shape, - const ov::Strides& filter_dilations, - ov::Shape& new_pads_end, - ov::Shape& new_pads_begin) const; - - ov::PartialShape infer_output_shape(const ov::Strides& dilations); - - ov::Shape m_kernel; - ov::Strides m_strides; - ov::Shape m_pads_begin; - ov::Shape m_pads_end; - ov::op::PadType m_auto_pad; - ov::op::RoundingType m_rounding_type; -}; -} // namespace op -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/ops/identity.cpp b/src/plugins/intel_gna/src/ops/identity.cpp deleted file mode 100644 index 7f57085dbf4..00000000000 --- a/src/plugins/intel_gna/src/ops/identity.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "identity.hpp" - -#include - -#include "ngraph/attribute_visitor.hpp" - -namespace ov { -namespace intel_gna { -namespace op { - -Identity::Identity(const ngraph::Output& arg) : Op({arg}) { - constructor_validate_and_infer_types(); -} - -std::shared_ptr Identity::clone_with_new_inputs(const ngraph::OutputVector& new_args) const { - check_new_args_count(this, new_args); - return std::make_shared(new_args.at(0)); -} - -void Identity::validate_and_infer_types() { - set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); -} - -bool Identity::visit_attributes(ngraph::AttributeVisitor& visitor) { - return true; -} - -} // namespace op -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/ops/identity.hpp b/src/plugins/intel_gna/src/ops/identity.hpp deleted file mode 100644 index 7b5dfa1e317..00000000000 --- a/src/plugins/intel_gna/src/ops/identity.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "ngraph/op/op.hpp" - -namespace ov { -namespace intel_gna { -namespace op { -/// \brief GNA specific Identity layer operation. -/// -class Identity : public ngraph::op::Op { -public: - OPENVINO_OP("Identity", "intel_gna", ov::op::Op); - - Identity() = default; - /// \brief Constructs a Identity operation. - /// - /// \param [in] arg Input tensor - Identity(const ngraph::Output& arg); - - void validate_and_infer_types() override; - std::shared_ptr clone_with_new_inputs(const ngraph::OutputVector& new_args) const override; - bool visit_attributes(ngraph::AttributeVisitor& visitor) override; -}; -} // namespace op -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/ops/pwl.cpp b/src/plugins/intel_gna/src/ops/pwl.cpp deleted file mode 100644 index b57a3b2ee83..00000000000 --- a/src/plugins/intel_gna/src/ops/pwl.cpp +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "pwl.hpp" - -#include "ngraph/runtime/host_tensor.hpp" -#include "reference/pwl.hpp" - -namespace ov { -namespace intel_gna { -namespace op { - -Pwl::Pwl(const ngraph::Output& data, - const ngraph::Output& m, - const ngraph::Output& b, - const ngraph::Output& knots) - : Op({data, m, b, knots}) { - constructor_validate_and_infer_types(); -} - -bool Pwl::visit_attributes(ov::AttributeVisitor& visitor) { - return true; -} - -std::shared_ptr Pwl::clone_with_new_inputs(const ov::OutputVector& new_args) const { - check_new_args_count(this, new_args); - return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2), new_args.at(3)); -} - -void Pwl::validate_and_infer_types() { - set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); -} - -template -bool Pwl::evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) const { - using A1 = typename ov::element_type_traits::value_type; - using A2 = typename ov::element_type_traits::value_type; - ov::intel_gna::op::reference::pwl(inputs[0].data(), - outputs[0].data(), - shape_size(get_input_shape(0)), - inputs[1].data(), - inputs[2].data(), - inputs[3].data(), - shape_size(get_input_shape(1))); - return true; -} - -bool Pwl::evaluate(ov::TensorVector& outputs, - const ov::TensorVector& inputs, - const ov::EvaluationContext& evaluation_context) const { - return evaluate_pwl(std::tuple, - std::integral_constant>(), - std::tuple, - std::integral_constant, - std::integral_constant, - std::integral_constant, - std::integral_constant, - std::integral_constant, - std::integral_constant>(), - outputs, - inputs); -} - -bool Pwl::has_evaluate() const { - switch (get_input_element_type(0)) { - case ov::element::i32: - case ov::element::i64: - case ov::element::u32: - case ov::element::u64: - case ov::element::f16: - case ov::element::f32: - return true; - default: - break; - } - return false; -} - -void Pwl::set_base_node(const std::shared_ptr& base_node) { - m_base_node = base_node; -} - -std::shared_ptr Pwl::get_base_node() { - return m_base_node; -} - -} // namespace op -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/ops/pwl.hpp b/src/plugins/intel_gna/src/ops/pwl.hpp deleted file mode 100644 index 94ab08e5831..00000000000 --- a/src/plugins/intel_gna/src/ops/pwl.hpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "ngraph/node.hpp" -#include "openvino/op/op.hpp" - -namespace ov { -namespace intel_gna { -namespace op { -/// \brief PWL activation function -class Pwl : public ov::op::Op { -public: - OPENVINO_OP("Pwl", "intel_gna", ov::op::Op); - - Pwl() = default; - /// \brief Constructs a Pwl node. - /// - /// \param data - The input data tensor. - /// \param m - The list of the slopes of segment. - /// \param b - The list of the y-intercepts of segment. - /// \param knots - The list of x-coordinates of segment endpoints (segments number + 1). - Pwl(const ngraph::Output& data, - const ngraph::Output& m, - const ngraph::Output& b, - const ngraph::Output& knots); - - void validate_and_infer_types() override; - bool visit_attributes(ov::AttributeVisitor& visitor) override; - std::shared_ptr clone_with_new_inputs(const ov::OutputVector& new_args) const override; - bool evaluate(ov::TensorVector& outputs, - const ov::TensorVector& inputs, - const ov::EvaluationContext& evaluation_context) const override; - bool has_evaluate() const override; - void set_base_node(const std::shared_ptr& base_node); - std::shared_ptr get_base_node(); - -private: - template - bool evaluate_pwl(const std::tuple<>&, ov::TensorVector&, const ov::TensorVector&) const { - return false; - } - - template - bool evaluate_pwl(const std::tuple<>&, - const std::tuple&, - ov::TensorVector&, - const ov::TensorVector&) const { - return false; - } - - template - bool evaluate_pwl(const std::tuple&, - const std::tuple& types2, - ov::TensorVector& outputs, - const ov::TensorVector& inputs) const { - if (evaluate_pwl(types2, outputs, inputs)) { - return true; - } - - return evaluate_pwl(std::tuple(), types2, outputs, inputs); - } - - template - bool evaluate_pwl(const std::tuple&, - ov::TensorVector& outputs, - const ov::TensorVector& inputs) const { - return (inputs[1].get_element_type() == T1::value && inputs[0].get_element_type() == T2::value && - evaluate(outputs, inputs)) || - evaluate_pwl(std::tuple(), outputs, inputs); - } - - template - bool evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) const; - - std::shared_ptr m_base_node; -}; // class Pwl -} // namespace op -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/ops/reference/pwl.hpp b/src/plugins/intel_gna/src/ops/reference/pwl.hpp deleted file mode 100644 index a182ca5bbf8..00000000000 --- a/src/plugins/intel_gna/src/ops/reference/pwl.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -namespace ov { -namespace intel_gna { -namespace op { -namespace reference { -template -size_t range_search(const T& arg, const A* knots, size_t knots_number) { - if (arg < knots[0]) - return 0; - - OPENVINO_ASSERT(knots_number >= 2, "The number of knots is less than 2."); - if (knots[knots_number - 1] < arg) - return knots_number - 2; - - size_t left = 0; - size_t right = knots_number - 2; - size_t mid = (right - left) / 2; - while (left < right && (arg < knots[mid] || knots[mid + 1] < arg)) { - if (arg < knots[mid]) { - right = mid - 1; - } else { - left = mid + 1; - } - - mid = left + (right - left) / 2; - } - - return mid; -} - -template -void pwl(const T* args, T* out, size_t count, const A* m, const A* b, const A* knots, size_t segments_number) { - for (size_t i = 0; i < count; i++) { - // knots is one more than segments - size_t segment_index = range_search(args[i], knots, segments_number + 1); - out[i] = static_cast(m[segment_index] * args[i] + b[segment_index]); - } -} -} // namespace reference -} // namespace op -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/optimizer/gna_pass_manager.cpp b/src/plugins/intel_gna/src/optimizer/gna_pass_manager.cpp deleted file mode 100644 index 16542afeeb4..00000000000 --- a/src/plugins/intel_gna/src/optimizer/gna_pass_manager.cpp +++ /dev/null @@ -1,2534 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_pass_manager.hpp" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "backend/dnn_types.hpp" -#include "backend/gna_limitations.hpp" -#include "common/numerical_utils.hpp" -#include "frontend/quantization.hpp" -#include "frontend/quantized_layer_params.hpp" -#include "gna_data_types.hpp" -#include "gna_graph_patterns.hpp" -#include "gna_graph_tools.hpp" -#include "gna_groups.hpp" -#include "gna_itt.hpp" -#include "gna_tensor_tools.hpp" -#include "gna_upstream_iterator.hpp" -#include "layers/gna_layer_info.hpp" -#include "log/debug.hpp" -#include "log/log.hpp" -#include "pre_post_process/transposition_info.hpp" - -using namespace InferenceEngine; -using namespace InferenceEngine::details; -using namespace ov::intel_gna::frontend; -using namespace ov::intel_gna::common; -using namespace ov::intel_gna::pre_post_processing; -using namespace ov::intel_gna::limitations; - -namespace ov { -namespace intel_gna { - -#define pass_trace() log::debug() << "[" << getName() << "] " - -std::shared_ptr BasePass::getPassManager() { - auto sharedMgr = mgr.lock(); - if (!sharedMgr) { - THROW_GNA_EXCEPTION << getName() << ": cannot get PassManager object"; - } - return sharedMgr; -} - -/** - * @brief Perform addition of two blobs values - */ -template -static void SumBlobs_t(Blob::Ptr& src_blob, Blob::Ptr& dst_blob) { - IE_ASSERT(src_blob != nullptr); - IE_ASSERT(dst_blob != nullptr); - IE_ASSERT(src_blob->size() == dst_blob->size()); - IE_ASSERT(src_blob->getTensorDesc().getPrecision() == dst_blob->getTensorDesc().getPrecision()); - - T* src_blob_buf = src_blob->buffer().as(); - T* dst_blob_buf = dst_blob->buffer().as(); - std::transform(dst_blob_buf, dst_blob_buf + dst_blob->size(), src_blob_buf, dst_blob_buf, std::plus()); -} - -static void SumBlobs(Blob::Ptr& src_blob, Blob::Ptr& dst_blob) { - IE_ASSERT(src_blob != nullptr); - - switch (src_blob->getTensorDesc().getPrecision()) { -#define CASE(x) \ - case x: \ - return SumBlobs_t::value_type>(src_blob, dst_blob); - CASE(InferenceEngine::Precision::FP32); - CASE(InferenceEngine::Precision::FP64); - CASE(InferenceEngine::Precision::FP16); - CASE(InferenceEngine::Precision::BF16); - CASE(InferenceEngine::Precision::I4); - CASE(InferenceEngine::Precision::I8); - CASE(InferenceEngine::Precision::I16); - CASE(InferenceEngine::Precision::I32); - CASE(InferenceEngine::Precision::I64); - CASE(InferenceEngine::Precision::U4); - CASE(InferenceEngine::Precision::U8); - CASE(InferenceEngine::Precision::U16); - CASE(InferenceEngine::Precision::U32); - CASE(InferenceEngine::Precision::U64); - CASE(InferenceEngine::Precision::Q78); - CASE(InferenceEngine::Precision::BIN); - CASE(InferenceEngine::Precision::BOOL); -#undef CASE - default: - IE_THROW() << "Wrong precision specified: " << src_blob->getTensorDesc().getPrecision().name(); - } -} - -// indexes stored in pass manager -static const char identityLayersCounterName[] = "identityLayerCounter"; -static const char diagonalLayersCounterName[] = "diagonalLayerCounter"; -static const char copyLayersCounter[] = "numCopyLayers"; -static const char softSignLayersCounter[] = "numSoftSignLayers"; - -/** - * @brief helper injections of diagonal layer with certain value - */ - -static void insertDiagonalLayerBetween(InferenceEngine::CNNLayerPtr prevLayer, - InferenceEngine::CNNLayerPtr nextLayer, - std::shared_ptr passmanager, - float fillValue, - size_t in_data_idx = invalid_data_idx) { - auto quantized = InferenceEngine::getInjectedData(prevLayer); - auto diagName = - std::string("SyntheticScaleShift_") + std::to_string(passmanager->getIntVar(diagonalLayersCounterName)++); - log::debug() << "Inserted Diagonal Layer " << diagName << " between: " << prevLayer->name << " and " - << nextLayer->name << "\n" - << std::flush; - - auto diagLayer = std::make_shared(LayerParams({diagName, "ScaleShift", Precision::FP32})); - IE_ASSERT(diagLayer != nullptr); - - auto inputLayer = InferenceEngine::CNNNetPrevLayerSkipCertain(nextLayer, 0, [](InferenceEngine::CNNLayerPtr ptr) { - return LayerInfo(ptr).isNonValuesChangable(); - }); - IE_ASSERT(inputLayer != nullptr); - size_t weightsSize = LayerInfo(prevLayer).has32BOutput() - ? nextLayer->outData[0]->getDims().back() - : Get2DReshapedData(nextLayer->outData[0], - Limitations::get_min_batch_to_fit_in_buffer(nextLayer->outData[0]), - 8) - ->getDims()[1]; - std::vector weightsValues(weightsSize, fillValue); - IE_ASSERT(diagLayer != nullptr); - diagLayer->_weights = make_shared_blob(TensorDesc(nextLayer->outData[0]->getTensorDesc().getPrecision(), - SizeVector({weightsValues.size()}), - InferenceEngine::Layout::C)); - diagLayer->_weights->allocate(); - CopyVectorToBlob(diagLayer->_weights, weightsValues); - auto dataPtr = std::make_shared(diagName, nextLayer->outData[0]->getTensorDesc()); - - auto diagonalWithQuant = quantized ? InferenceEngine::injectData(diagLayer) : diagLayer; - getCreatorLayer(dataPtr) = diagonalWithQuant; - diagonalWithQuant->outData.push_back(dataPtr); - // actual insertion - CNNNetworkInsertLayer(prevLayer, nextLayer, diagonalWithQuant, invalid_data_idx, in_data_idx); -} - -/** - * @brief copy layer inserted by several passes - * @returns pointer to newly created COPYLayer - */ -static CNNLayerPtr InsertCopyLayer(CNNLayerPtr prevLayer, - CNNLayerPtr nextLayer, - int beforeIdx, - std::shared_ptr passmanager, - std::string copyLayerType) { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "InsertCopyLayer"); - auto quantized = InferenceEngine::getInjectedData(prevLayer); - std::string copyName = - copyLayerType + std::string("_") + std::to_string(passmanager->getIntVar(copyLayersCounter)++); - log::debug() << "Inserted " << copyName << " between: " << prevLayer->name << " and " << nextLayer->name - << std::endl; - - CNNLayerPtr copyLayer = std::make_shared(LayerParams({copyName, copyLayerType, Precision::FP32})); - - auto inputData = nextLayer->insData[beforeIdx].lock(); - auto dataPtr = std::make_shared(copyName, inputData->getTensorDesc()); - auto copyWithQuant = quantized ? InferenceEngine::injectData(copyLayer) : copyLayer; - getCreatorLayer(dataPtr) = copyWithQuant; - copyWithQuant->outData.push_back(dataPtr); - CNNNetworkInsertLayer(prevLayer, nextLayer, copyWithQuant, invalid_data_idx, beforeIdx); - return copyWithQuant; -} - -static std::vector getCandidatesForIdentityInsertion(const CNNLayerPtr l, - std::shared_ptr passmanager, - bool skipFq = false) { - std::vector prevLayers; - - // skipping memory inputs and true inputs layers - if (l->insData.empty()) - return {}; - - auto eltwise = dynamic_cast(l.get()); - auto concat = dynamic_cast(l.get()); - - auto PrevFunctionalLayer = [skipFq](CNNLayerPtr l, int idx = 0) { - auto prevLayer = CNNNetPrevLayerSkipCertain(l, idx, [skipFq](CNNLayerPtr ptr) { - return LayerInfo(ptr).isNonFunctional() || (skipFq && LayerInfo(ptr).isFakeQuantize()); - }); - log::debug() << "CNNNetPrevLayerSkipCertain for :: " << l->name << "returned: " << prevLayer->name << std::endl; - return prevLayer; - }; - - // eltwise - if (eltwise != nullptr) { - // eltwise layer has 2 inputs, so depends on situation identity should or should not be inserted - - // for sum with 16-bit input precision - // if we have 4-4 inputs - we will handle that by inserting identity activation case (1) - // if we have 4-2 inputs - OK - // if we have 2-2 inputs - we need to insert diagonal - - // for sum with 8-bit input precision - // if we have 1-1 inputs - OK - // if we have 4-4 inputs - there are 2 options - // option 1 both inputs came from single outdata - we need to insert 1 identity activation to just - // convert single input into 1 byte option 2 each input came from its own outdata - we need to - // insert 2 identity activations to convert both and feed weights and inputs - - // for mul if we have 2-2 or 1-1 (low precision case) inputs - OK - // for mul if we have 2-4 or 1-4 (low precision case) inputs - we need to insert identity activation to make 2 - // bytes input - // or 1 byte input (low precision case) - // for mul if we have 4-4 inputs - there are 2 options - // option 1 both inputs came from single outdata - we need to insert 1 identity activation to just - // convert single input into 2 bytes - // or 1 byte (low precision case) - // option 2 each input came from its own outdata - we need to insert 2 identity activations to convert - // both and feed weights and inputs - - auto prev0 = PrevFunctionalLayer(l, 0); - auto prev1 = PrevFunctionalLayer(l, 1); - - switch (eltwise->_operation) { - case EltwiseLayer::Sub: - case EltwiseLayer::Sum: - if (!passmanager->isLowPrecision()) { - if (!LayerInfo(prev0).has32BOutput() || !LayerInfo(prev1).has32BOutput()) { - return prevLayers; - } - // TODO: whether there are possibility to select after what layer identity gets inserted - prevLayers.push_back(CNNNetPrevLayer(l, 0)); - } else { - if (LayerInfo(prev0).has8BOr16BOutput() && LayerInfo(prev1).has8BOr16BOutput()) { - return prevLayers; - } - - if (LayerInfo(prev0).has32BOutput()) { - prevLayers.push_back(CNNNetPrevLayer(l, 0)); - } - - // if layers of outdata are different - auto prevData0 = l->insData[0].lock(); - auto prevData1 = l->insData[1].lock(); - - if ((prev0 != prev1 || prevData0 != prevData1) && LayerInfo(prev1).has32BOutput()) { - prevLayers.push_back(CNNNetPrevLayer(l, 1)); - } - } - break; - case EltwiseLayer::Prod: { - if (LayerInfo(prev0).has8BOr16BOutput() && LayerInfo(prev1).has8BOr16BOutput()) { - return prevLayers; - } - - if (LayerInfo(prev0).has32BOutput()) { - prevLayers.push_back(CNNNetPrevLayer(l, 0)); - } - - // if layers of outdata are different - auto prevData0 = l->insData[0].lock(); - auto prevData1 = l->insData[1].lock(); - - if ((prev0 != prev1 || prevData0 != prevData1) && LayerInfo(prev1).has32BOutput()) { - prevLayers.push_back(CNNNetPrevLayer(l, 1)); - } - - break; - } - default: - THROW_GNA_EXCEPTION << "Eltwise Layer of type: " << eltwise->_operation << " not supported"; - } - } else if (concat != nullptr) { - for (int i = 0; CNNNetHasPrevLayer(l.get(), i); ++i) { - auto prev = PrevFunctionalLayer(l, i); - if (LayerInfo(prev).has32BOutput()) { - prevLayers.push_back(CNNNetPrevLayer(l, i)); - } - } - } else { - // not eltwise or concat - // other layers has 1 inputs - situation is easier - // ex. activation or pooling - no need to insert identity activation. - if (LayerInfo(l).isNonFunctional() || LayerInfo(l).has32BInput()) - return prevLayers; - - auto prevLayer = PrevFunctionalLayer(l, LayerInfo(l).isGemm() ? 1 : 0); - - // No need to instert identity activation - // when activation was already there before pooling - // in case of CNN -> Activation -> Pooling order - if (LayerInfo(prevLayer).isPooling()) { - auto prevPrevLayer = PrevFunctionalLayer(prevLayer, 0); - if (LayerInfo(prevPrevLayer).isActivation()) { - return prevLayers; - } - } - - if (!LayerInfo(prevLayer).has32BOutput()) - return prevLayers; - - prevLayers.push_back(CNNNetPrevLayer(l, 0)); - } - return prevLayers; -} - -void InsertDiagonalLayerPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "InsertDiagonalLayerPass"); - bool lowPrecision = getPassManager()->isLowPrecision(); - - for (auto& l : *pLayers) { - if (l->insData.empty()) - continue; - auto prevLayer = CNNNetPrevLayerSkipCertain(l, 0, [](CNNLayerPtr ptr) { - return LayerInfo(ptr).isNonFunctional(); - }); - if (LayerInfo(l).isActivation()) { - if (LayerInfo(prevLayer).has32BOutput()) { - continue; - } - } else { - auto eltwise = dynamic_cast(l.get()); - if (!eltwise) { - continue; - } - // in case of eltwise sum in 16-bit input precision, one of inputs is 4 bytes, the other is 2 bytes - // in case of eltwise mul in 16-bit input precision, both inputs are 2 bytes - // in case of eltwise sum in low (8-bit) input precision, both inputs are 1 byte - // in case of eltwise mul in low (8-bit) input precision, both inputs are 1 byte - // for e sum if we have 4-4 inputs we will handle that by inserting identity activation - // for e sum if we have 4-2 - OK - // for e sum if we have 2-2 inputs we need to insert diagonal -- handling here - // for e sum if we have 1-1 inputs in low precision mode - OK - // for e mul if we have 2-2 - OK - // for e mul if we have 1-1 in low precision mode - OK - // for e mul if we have 2-4 - inputs we need to insert identity to put 4 bytes input into weights - // for e mul if we have 4-4 - inputs we need to insert 2 identities to put both 4 bytes input into weights - - if (eltwise->_operation != EltwiseLayer::Sum && eltwise->_operation != EltwiseLayer::Sub) - continue; - - auto prevLayer1 = CNNNetPrevLayerSkipCertain(l, 1, [](CNNLayerPtr ptr) { - return LayerInfo(ptr).isNonFunctional(); - }); - if (!LayerInfo(prevLayer).has8BOr16BOutput() || !LayerInfo(prevLayer1).has8BOr16BOutput()) - continue; - - if (lowPrecision && LayerInfo(prevLayer).has8BOr16BOutput() && LayerInfo(prevLayer1).has8BOr16BOutput()) - continue; - } - auto prevDirectLayer = CNNNetPrevLayer(l, 0); - insertDiagonalLayerBetween(prevDirectLayer, l, getPassManager(), 1.f, 0); - } -} - -void HandleMultipleActivationsForTheLayerPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "HandleMultipleActivationsForTheLayerPass"); - // found layer followed by multiple activations - for (auto& l : *pLayers) { - CNNLayerSet activations; - - for (auto&& odata : l->outData) { - for (auto&& inputTo : getInputTo(odata)) { - LayerInfo info(inputTo.second); - - if (info.isActivation()) { - if (odata->getDims().empty()) - continue; - if (!activations.empty() && odata->getDims()[0] != 1) { - THROW_GNA_EXCEPTION << "Unsupported batch size " << odata->getDims()[0] - << " for diagonal layer insertion"; - } - activations.insert(inputTo.second); - } - } - } - // single or not activations case - if (activations.size() < 2) - continue; - - // insert diagonals one per each activation - for (auto&& activation : activations) { - insertDiagonalLayerBetween(l, activation, getPassManager(), 0.0f); - } - } -} - -void ForbidActivationFusingPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "ForbidActivationFusingPass"); - for (auto& l : *pLayers) { - if (LayerInfo(l).isActivation()) { - auto prevLayer = CNNNetPrevLayer(l); - if (LayerInfo(prevLayer).has32BOutput()) { - // find all layers directly connected to the outputs of the previous layer - const auto allUsingPrev = - CNNNetGetAllNextLayersSkipCertain(prevLayer, -1, [&](CNNLayerPtr nextLayer) -> bool { - for (const auto& input : nextLayer->insData) { - for (const auto& output : prevLayer->outData) { - if (areEqualDatas(input.lock(), output) && - areEqualDatas(l->insData[0].lock(), output) && - (LayerInfo(nextLayer).isEltwiseSum() || nextLayer == l)) { - return false; - } - } - } - return true; - }); - if (allUsingPrev.size() > 1) { - // the weights of MAX_VAL_2B_WEIGHT are used to enforce 1.0 scale factor - // so the scores are more correct - insertDiagonalLayerBetween(prevLayer, l, getPassManager(), MAX_VAL_2B_WEIGHT); - } - continue; - } - } - } -} - -namespace { -template -bool is2D(T&& vec) { - return vec.size() >= 2 && vec[0] > 1 && vec[1] > 1; -} -} // namespace - -void ReorderMaxPoolPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "ReorderMaxPoolPass"); - // detecting following pattern - // conv->activation->maxpooling - // changing it to conv->maxpooling->activation - for (auto& l : *pLayers) { - auto pool = LayerInfo(l); - if (!pool.isMaxPooling()) - continue; - - // don't reorder if pooling is 2D for CNN2D - auto pooling = dynamic_cast(l.get()); - // todo: return the check for stride after it'll be fixed in MO for Kaldi models - if (pooling == nullptr || (is2D(pooling->_kernel))) - continue; - - // checking prev layer type - auto actLayer = CNNNetPrevLayer(l); - auto activation = LayerInfo(actLayer); - if (!activation.isActivation() || actLayer->insData.size() > 1) - continue; - - // if activation came from convolution - auto convolution = LayerInfo(CNNNetPrevLayer(static_cast(activation))); - if (!convolution.isConvolution()) - continue; - - log::debug() << "MaxPooling: " << pool << ", reordered with activation: " << activation << "\n"; - - CNNNetSwapLayers(activation, pool); - } -} - -void SubstituteSoftSignPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "SubstituteSoftSignPass"); - /* detecting following pattern - * irv7 model: irv10 model: - * a layer a layer - * | \ | \ - * abs \ abs \ - * | | | | - * | | add | - * | | | | - * power | power | - * \ / \ / - * mul mul - */ - - auto hasNChildren = [](CNNLayerPtr l, size_t N) { - if (l->outData.size() != 1) - return false; - if (getInputTo(l->outData.front()).size() != N) - return false; - return true; - }; - auto getNthChild = [](CNNLayerPtr l, int N) { - auto first = getInputTo(l->outData.front()).begin(); - auto last = getInputTo(l->outData.front()).end(); - IE_ASSERT(first != last); - IE_ASSERT(N <= std::distance(first, last)); - std::advance(first, N); - return first->second; - }; - for (auto& l : *pLayers) { - if (!hasNChildren(l, 2)) - continue; - auto mul = getNthChild(l, 0); - auto abs = getNthChild(l, 1); - - bool cont = true; - if (LayerInfo(mul).isEltwiseMul() && LayerInfo(abs).isAbs()) { - cont = false; - } - if (cont && LayerInfo(abs).isEltwiseMul() && LayerInfo(mul).isAbs()) { - std::swap(mul, abs); - cont = false; - } - if (cont) - continue; - if (!hasNChildren(abs, 1)) - continue; - auto addition = getNthChild(abs, 0); - InferenceEngine::CNNLayerPtr power = nullptr; - - if (!LayerInfo(addition).isPower()) - continue; - auto powerLayer = LayerInfo(addition).as(); - - // first layer after abs must have scale of 1, offset of 1 and power of either 1 or -1 - if (!AreFpEq(powerLayer->scale, 1.0f) || !AreFpEq(powerLayer->offset, 1.0f) || - !AreFpEq(std::abs(powerLayer->power), 1.0f)) - continue; - // power == -1, offset = 1, scale = 1 - if (AreFpEq(powerLayer->power, -1.0f)) { - std::swap(addition, power); - } else { // power = 1, offset = 1, scale - 1 - power = getNthChild(addition, 0); - if (!LayerInfo(power).isPower()) - continue; - auto powerLayer_1 = LayerInfo(power).as(); - // layer after addition must have power of -1, offset of 0 and scale of 1 - if (!AreFpEq(powerLayer_1->power, -1.0f) || !AreFpEq(powerLayer_1->offset, 0.0f) || - !AreFpEq(powerLayer_1->scale, 1.0f)) - continue; - } - - if (!hasNChildren(power, 1)) - continue; - auto mulSame = getNthChild(power, 0); - if (mulSame != mul) - continue; - - // pattern matched - lets substitute - log::debug() << "SoftSign subgraph found consits of: \n" - << "\t" << abs->name << "\n"; - if (addition != nullptr) - log::debug() << "\t" << addition->name << "\n"; - log::debug() << "\t" << mul->name << "\n" << std::endl; - - // creating softsign layer - auto quantized = InferenceEngine::getInjectedData(l); - auto layerName = - std::string("Synthetic_SoftSign_") + std::to_string(getPassManager()->getIntVar(softSignLayersCounter)++); - - CNNLayerPtr activationLayer = - std::make_shared(LayerParams({layerName, "SoftSign", Precision::FP32})); - IE_ASSERT(activationLayer != nullptr); - auto activationLayerWithQuant = - quantized ? InferenceEngine::injectData(activationLayer) : activationLayer; - - auto mulData = mul->outData; - - // rebind outdata of mull to be outdata of softsign - for (auto&& data : mulData) { - getCreatorLayer(data) = activationLayerWithQuant; - data->setName("softsign_data_" + std::to_string(getPassManager()->getIntVar(softSignLayersCounter))); - activationLayerWithQuant->outData.push_back(data); - } - - // making connection l->softsign - getInputTo(l->outData.front()).clear(); - getInputTo(l->outData.front())[layerName] = activationLayerWithQuant; - - // making back connection softsign->mul - activationLayerWithQuant->insData.push_back(l->outData.front()); - } -} -void SubstitutePReluPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "SubstitutePReluPass"); - auto getScale = [](CNNLayer* layer) { - auto powerCandidate = LayerInfo(layer); - if (!powerCandidate.isPower()) - return 0.0f; - auto power = powerCandidate.as(); - - return power->power == 1 && power->offset == 0.0f ? power->scale : 0.0f; - }; - - auto isScale = [getScale](CNNLayer* layer) { - return getScale(layer) != 0.0f; - }; - - auto isNegate = [getScale](CNNLayer* layer) { - return getScale(layer) == -1.0f; - }; - - auto getNext = [](CNNLayer* layer) { - CNNLayer* next = nullptr; - if (layer == nullptr) - return next; - if (layer->outData.size() != 1) - return next; - return getInputTo(layer->outData[0]).begin()->second.get(); - }; - - // TODO: unit tests for bad cases - for (auto& l : *pLayers) { - // assume l is starting layer, that is followed by eltwise_sum(relu, negate/relu/scale/negate) - if (l->outData.size() != 1) - continue; - auto& outputLayers = getInputTo(l->outData[0]); - if (outputLayers.size() != 2) - continue; - - // one of followed layers need to be generic relu - auto first = LayerInfo(outputLayers.begin()->second); - auto second = LayerInfo((++outputLayers.begin())->second); - - auto relu1 = outputLayers.begin()->second; - auto neg1 = (++outputLayers.begin())->second; - if (second.isRelu()) { - std::swap(first, second); - std::swap(relu1, neg1); - } - if (!first.isRelu()) - continue; - // now we have relu as first layer, lets check second - // negate - if (!isNegate(neg1.get())) - continue; - - // relu - auto relu2 = getNext(second); - if (!LayerInfo(relu2).isRelu()) - continue; - - // scale - auto scale = getNext(relu2); - if (!isScale(scale)) - continue; - - // negate2 - auto negate = getNext(scale); - if (!isNegate(negate)) - continue; - - // sum - auto sum = getNext(negate); - IE_ASSERT(sum != nullptr); - if (!LayerInfo(sum).isEltwiseSum()) - continue; - if (sum->insData.size() != 2 || sum->insData[0].lock() == nullptr || sum->insData[1].lock() == nullptr) - continue; - - auto inData_0 = sum->insData[0].lock(); - IE_ASSERT(inData_0 != nullptr); - auto creatorLayer_0 = getCreatorLayer(inData_0).lock(); - IE_ASSERT(creatorLayer_0 != nullptr); - auto inData_1 = sum->insData[1].lock(); - IE_ASSERT(inData_1 != nullptr); - auto creatorLayer_1 = getCreatorLayer(inData_1).lock(); - IE_ASSERT(creatorLayer_1 != nullptr); - - auto s1 = creatorLayer_0.get(); - auto s2 = creatorLayer_1.get(); - - if (s1 != static_cast(first) && - s2 != static_cast(first)) { - continue; - } - - // hurray we found parametric relu group - dont know what to do with it though - log::debug() << "PRelu with negative slope of " << -LayerInfo(scale).as()->scale << " found" - << std::endl; - - // removing all layers references except of relu layer - outputLayers.clear(); - outputLayers[relu1->name] = relu1; - // pointing relu to output of eltwise_summ - relu1->outData = sum->outData; - // changing creator layer - getCreatorLayer(relu1->outData[0]) = relu1; - // pointing back to relu if any - if (!getInputTo(relu1->outData[0]).empty()) { - auto summOutputLayer = getInputTo(relu1->outData[0]).begin()->second; - summOutputLayer->insData.clear(); - summOutputLayer->insData.push_back(relu1->outData[0]); - } - - // changing negative slope - first.as()->negative_slope = LayerInfo(scale).as()->scale; - } -} - -void RemovePermutationsNHWCToNCHWPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "RemovePermutationsNHWCToNCHWPass"); - std::set permutations_to_remove; - std::list> nhwc_layout_patterns; - for (auto& l : *pLayers) { - if (!LayerInfo(l).isConvolution()) { - continue; - } - - CNNLayerPtr prev, next; - std::tie(prev, next) = FindPermutationsAroundConvolutionInNHWCModel(l); - - if (prev == nullptr || next == nullptr) - continue; - - if (LayerInfo(prev).isPermute() || LayerInfo(prev).isPermuteViaReshape()) { - permutations_to_remove.insert(prev); - } - - if (LayerInfo(next).isPermute() || LayerInfo(prev).isPermuteViaReshape()) { - permutations_to_remove.insert(next); - } - - nhwc_layout_patterns.push_back({prev, next}); - } - - for (const auto& layers : nhwc_layout_patterns) { - auto pattern_start = layers.first; - auto pattern_end = layers.second; - - auto getTransposedLayout = [](InferenceEngine::DataPtr data) { - size_t dims_size = data->getDims().size(); - if (dims_size < 3 || dims_size > 4) { - THROW_GNA_EXCEPTION << data->getName() - << " unexpected dimensions size in Permute - Conv - Permute pattern"; - } - // HWC layout enum is used here as the only available in CNNNetwork for 3D vectors, - // but the real layout is NCW and it's the one used in order vector later - return dims_size == 4 ? InferenceEngine::Layout::NHWC : InferenceEngine::Layout::HWC; - }; - - auto setTransposedOrder = [getTransposedLayout](InferenceEngine::DataPtr data) { - auto layout = getTransposedLayout(data); - if (data->getLayout() == layout) - return; - - auto current_layer = getCreatorLayer(data).lock(); - if (LayerInfo(current_layer).isConcat()) { - auto concat_layer = dynamic_cast(current_layer.get()); - auto dims_size = data->getDims().size(); - concat_layer->_axis = (dims_size == 4 ? permute::GetPermuteOrder(InferenceEngine::Layout::NHWC, - InferenceEngine::Layout::NCHW) - : std::vector{0, 2, 1})[concat_layer->_axis]; - } - - // NWC->NCW layouts are used here for order vector, see comments a few lines above - auto dims = data->getDims(); - auto order = dims.size() == 4 - ? permute::GetPermuteOrder(InferenceEngine::Layout::NCHW, InferenceEngine::Layout::NHWC) - : std::vector{0, 2, 1}; - InferenceEngine::SizeVector new_dims; - for (size_t i = 0; i < dims.size(); ++i) { - new_dims.push_back(dims[order[i]]); - } - data->setDims(new_dims); - data->setLayout(layout); - }; - - std::function(CNNLayerPtr, const std::list&)> - getPathBetweenTransposes = [pattern_start, pattern_end, &getPathBetweenTransposes]( - CNNLayerPtr current_layer, - const std::list& path) { - if (current_layer == pattern_end) { - // the pattern end has been found, return the full path - return path; - } - - // transpose is reached, the pattern end hasn't been found - if (current_layer != pattern_start && - (LayerInfo(current_layer).isPermute() || LayerInfo(current_layer).isPermuteViaReshape())) { - return std::list(); - } - - auto new_path(path); - std::list mergedChildPath; - for (const auto& output : current_layer->outData) { - new_path.push_back(output); - for (const auto& input : getInputTo(output)) { - auto childPath = getPathBetweenTransposes(input.second, new_path); - // only the branch with the pattern end will return not empty list - if (!childPath.empty()) { - mergedChildPath.insert(std::end(mergedChildPath), - std::begin(childPath), - std::end(childPath)); - break; - } - } - } - - return mergedChildPath; - }; - - auto path = getPathBetweenTransposes(pattern_start, std::list()); - for (const auto& data : path) { - setTransposedOrder(data); - } - - if ((LayerInfo(pattern_start).isPermute() || LayerInfo(pattern_start).isPermuteViaReshape()) && - !getInputTo(pattern_start->outData.front()).empty()) { - auto layer_before_permute = CNNNetPrevLayer(pattern_start); - DataPtr output = nullptr; - for (const auto& before_output : layer_before_permute->outData) { - if (areEqualDatas(pattern_start->input(), before_output)) { - output = before_output; - output->setLayout(getTransposedLayout(output)); - break; - } - } - if (output == nullptr) { - THROW_GNA_EXCEPTION << "Could not find correct data link between " << pattern_start->name << " and " - << layer_before_permute->name; - } - } - - if (!pattern_end->outData.empty() && !getInputTo(pattern_end->outData.front()).empty()) { - auto layer_after_permute = getInputTo(pattern_end->outData.front()).begin()->second; - layer_after_permute->input()->setLayout(getTransposedLayout(layer_after_permute->input())); - } - } - - for (auto&& to_remove : permutations_to_remove) { - log::debug() << to_remove->type << " layer '" << to_remove->name << "' will be removed" << '\n'; - CNNNetworkRemoveLayer(to_remove, false); - } -} - -void InsertIdentityLayerPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "InsertIdentityLayerPass"); - auto quantized = InferenceEngine::getInjectedData(pLayers->front()); - auto createIdentityLayer = [quantized, this](const TensorDesc& tensorDesc) { - int numOfIdentityLayers = this->getPassManager()->getIntVar(identityLayersCounterName)++; - auto activationName = std::string("identity_") + std::to_string(numOfIdentityLayers); - CNNLayerPtr activationLayer = - std::make_shared(LayerParams({activationName, "identity", Precision::FP32})); - CNNLayerPtr activationLayerWithQuant = - quantized ? InferenceEngine::injectData(activationLayer) : activationLayer; - auto dataPtr = std::make_shared("identity_data_" + std::to_string(numOfIdentityLayers), tensorDesc); - getCreatorLayer(dataPtr) = activationLayerWithQuant; - activationLayerWithQuant->outData.push_back(dataPtr); - return activationLayerWithQuant; - }; - - for (auto& l : *pLayers) { - if (LayerInfo(l).isPooling()) { - // Identity should be inserted after 1D pooling if it's the last functional layer. - auto pooling = LayerInfo(l).as(); - IE_ASSERT(pooling != nullptr); - if (is2D(pooling->_kernel)) - continue; - - auto hasNextFuncLayer = CNNNetHasNextLayerSkipCertain(l, 0, 0, [](CNNLayerPtr layer) { - return LayerInfo(layer).isNonFunctional(); - }); - if (hasNextFuncLayer) - continue; - - auto identityLayer = createIdentityLayer(l->outData[0]->getTensorDesc()); - log::debug() << "Inserted " << identityLayer->name << " after " << l->name << std::endl; - - auto nextLayer = CNNNetCheckNextLayerSkipCertain(l, 0, 0, true, [](CNNLayerPtr layer) { - return false; - }).first; - CNNNetworkInsertLayer(l, nextLayer, identityLayer); - } - - for (auto&& prev : getCandidatesForIdentityInsertion(l, getPassManager())) { - // Do an upstream search until Functional layer is found - auto original_prev_layer = prev; - auto true_layer = l; - while (LayerInfo(prev).isNonFunctional()) { - if (CNNNetHasPrevLayer(prev.get()) && prev->outData.size() == 1) { - true_layer = prev; - prev = CNNNetPrevLayer(prev); - } else { - log::warning() << "Could not find Functional parent for " << original_prev_layer->name - << ", using original layer"; - prev = original_prev_layer; - true_layer = l; - break; - } - } - // check if prev layer have id layer already connected to output - // if so reuse it instead of create new one - bool reconnected = false; - for (auto& prev_layer_output : prev->outData) { - // prev ---------+--> identity --> layer XYZ - // | - // | <= here we want to inject identity - // | - // +--> l layer - // but we may just connect l layer with existing identity - for (auto&& next_layer : getInputTo(prev_layer_output)) { - auto child_of_prev_layer = next_layer.second; - if (child_of_prev_layer.get() == true_layer.get()) { - continue; - } else if (LayerInfo(child_of_prev_layer).isIdentity()) { - CNNNetworkReconnectLayer(prev, child_of_prev_layer, true_layer); - reconnected = true; - break; - } - } - } - if (reconnected) - continue; - - // TODO: why index is 0 ? - better use direct indexing in getCandidateFunction - // detecting ins-data-idx - size_t insDataIdx = std::numeric_limits::max(); - for (size_t i = 0; i != true_layer->insData.size(); i++) { - if (getCreatorLayer(true_layer->insData[i].lock()).lock() == prev) { - insDataIdx = i; - break; - } - } - if (insDataIdx == std::numeric_limits::max()) { - THROW_GNA_EXCEPTION << "cannot insert identity layer after" << prev->name << " and before " - << true_layer->name; - } - - auto inputData = true_layer->insData[insDataIdx].lock(); - auto identityLayer = createIdentityLayer(inputData->getTensorDesc()); - - log::debug() << "Inserted " << identityLayer->name << " between: " << prev->name << " and " - << true_layer->name << "\n" - << std::flush; - - // copy offset - to be used while connecting outputs - if (prev->params.find("output_offset") != prev->params.end()) { - identityLayer->params["output_offset"] = prev->params["output_offset"]; - } - // copy offset - to be used while connecting outputs - if (prev->params.find("original_num_rows") != prev->params.end()) { - identityLayer->params["original_num_rows"] = prev->params["original_num_rows"]; - } - - CNNNetworkInsertLayer(prev, CNNLayerPtr(nullptr), identityLayer); - } - } -} - -void InsertCopyLayerPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "InsertCopyLayerPass"); - using FuncChildrenInfo = std::tuple; - // recursively searches for children functional layers skipping non-functional ones - std::function(CNNLayerPtr, CNNLayerPtr, int32_t)> find_func_layers = - [&find_func_layers](CNNLayerPtr currentLayer, CNNLayerPtr parentLayer, int32_t input_idx) { - if (!LayerInfo(currentLayer).isNonFunctional() || currentLayer->outData.size() == 0 || - getInputTo(currentLayer->outData[0]).size() == 0) { - return std::vector{std::make_tuple(parentLayer, currentLayer, input_idx)}; - } - std::vector results; - for (size_t i = 0; i < getInputTo(currentLayer->outData[0]).size(); ++i) { - auto next_layer = - CNNNetGetNextLayerSkipCertain(currentLayer, 0, static_cast(i), [](CNNLayerPtr origin) { - return false; - }).first; - auto result = find_func_layers(next_layer, - currentLayer, - CNNLayerFindInsDataIdxes(currentLayer->outData[0], next_layer)[0]); - results.insert(std::end(results), std::begin(result), std::end(result)); - } - return results; - }; - - // Copy layer insertion happens in few cases: - // Crop output goes to concat layer -> copy layer insertion - // Splitted part of input goes to concat layer -> copy layer insertion - // Concat|Split|Crop layer goes to memory layer -> delayed copy layer insertion - // One output goes to multiple concat and/or memory layers -> delayed copies before memory layers - // and copies before concat layers (one less copy than outputs) - // Concat has multiple connections to the same input - // Subgraph has only non-functional layers - for (auto& l : *pLayers) { - if (!LayerInfo(l).isConcat()) - continue; - - // Insert copy layers after concat inputs with multiple connections to concat - std::set parents; - for (size_t input_idx = 0; input_idx < l->insData.size(); ++input_idx) { - IE_ASSERT(l->insData[input_idx].lock() != nullptr); - auto inputData = l->insData[input_idx].lock(); - if (parents.find(inputData) != std::end(parents)) { - auto parent = getCreatorLayer(inputData); - IE_ASSERT(parent.lock() != nullptr); - InsertCopyLayer(parent.lock(), l, static_cast(input_idx), this->getPassManager(), CopyLayerName); - } else { - parents.insert(inputData); - } - } - } - - for (auto& l : *pLayers) { - if (LayerInfo(l).isNonFunctional()) - continue; - - // Crop -> Concat, Input -> Split -> Concat and Concat -> Memory cases - if ((LayerInfo(l).isCrop() && !LayerInfo(l).isCropAffined()) || LayerInfo(l).isConcat() || - LayerInfo(l).isSplit()) { - std::vector copy_insertion_tuples; - std::vector delayed_copy_insertion_tuples; - for (const auto& output : l->outData) { - auto& inputTo = getInputTo(output); - for (auto& childLayer : inputTo) { - std::vector connections = CNNLayerFindInsDataIdxes(output, childLayer.second); - for (auto input_idx : connections) { - auto children_info = find_func_layers(childLayer.second, l, input_idx); - for (const auto& child_info : children_info) { - CNNLayerPtr child = std::get<1>(child_info); - if ((LayerInfo(l).isConcat() || LayerInfo(l).isCrop() || LayerInfo(l).isSplit()) && - LayerInfo(child).isMemory()) { - // Concat|Split|Crop -> Memory case - delayed_copy_insertion_tuples.push_back(child_info); - } else if ((LayerInfo(l).isSplit() || LayerInfo(l).isCrop()) && - LayerInfo(child).isConcat()) { - // Split|Crop -> Concat case - // concat may be connected to previous layer with multiple connections - copy_insertion_tuples.push_back(child_info); - } - } - } - } - } - - for (auto& tuple : delayed_copy_insertion_tuples) { - // Concat -> Memory case - InsertCopyLayer(std::get<0>(tuple), - std::get<1>(tuple), - std::get<2>(tuple), - this->getPassManager(), - DelayedCopyLayerName); - } - for (auto& tuple : copy_insertion_tuples) { - // Crop -> Concat case - InsertCopyLayer(std::get<0>(tuple), - std::get<1>(tuple), - std::get<2>(tuple), - this->getPassManager(), - CopyLayerName); - } - } - - // Layer -> multiple concat/memory case - for (auto& output : l->outData) { - std::vector> MemoryLayers; - std::vector> ConcatLayers; - auto& inputTo = getInputTo(output); - if (inputTo.size() < 2) - continue; - for (auto& childLayer : inputTo) { - auto layer_to_insert = childLayer.second; - auto current_layer = childLayer.second; - auto previous_layer = l; - size_t input_idx = CNNLayerFindInsDataIdxes(output, current_layer)[0]; - - while (LayerInfo(current_layer).isNonFunctional()) { - if (current_layer->outData.size() == 0) - break; - if (getInputTo(current_layer->outData[0]).size() == 0) - break; - previous_layer = current_layer; - current_layer = CNNNetGetNextLayerSkipCertain(current_layer, 0, 0, [](CNNLayerPtr origin) { - return false; - }).first; - } - if (LayerInfo(current_layer).isConcat()) { - ConcatLayers.push_back(make_pair(layer_to_insert, input_idx)); - } else if (LayerInfo(current_layer).isMemory()) { - MemoryLayers.push_back(make_pair(layer_to_insert, input_idx)); - } - } - if (MemoryLayers.empty() && ConcatLayers.empty()) - continue; - auto toCopyCount = MemoryLayers.size() + ConcatLayers.size() - (LayerInfo(l).isInput() ? 0 : 1); - size_t currentCopyIdx = 0; - while (currentCopyIdx < toCopyCount) { - if (currentCopyIdx < MemoryLayers.size()) { - size_t memoryIdx = currentCopyIdx; - auto memoryLayer = MemoryLayers[memoryIdx].first; - auto inputIdx = MemoryLayers[memoryIdx].second; - InsertCopyLayer(l, - memoryLayer, - static_cast(inputIdx), - this->getPassManager(), - DelayedCopyLayerName); - } else { - size_t concatIdx = currentCopyIdx - MemoryLayers.size(); - auto concatLayer = ConcatLayers[concatIdx].first; - auto inputIdx = ConcatLayers[concatIdx].second; - InsertCopyLayer(l, concatLayer, static_cast(inputIdx), this->getPassManager(), CopyLayerName); - } - currentCopyIdx++; - } - } - } - - for (auto& l : *pLayers) { - if (l->outData.size() > 0 && getInputTo(l->outData[0]).size() > 0) - continue; - - bool bNeedInsertCopyLayer = true; - CNNNetDFS( - l, - [&bNeedInsertCopyLayer](CNNLayerPtr layer) { - if (!(LayerInfo(layer).isNonFunctional() || LayerInfo(layer).isSplit() || LayerInfo(layer).isCrop() || - LayerInfo(layer).isInput())) { - bNeedInsertCopyLayer = false; - } - }, - true, - [&bNeedInsertCopyLayer](InferenceEngine::CNNLayer* from) { - // aborting UFS if we found functional layer (excluding Splits and Crops) - return make_upstream_order(bNeedInsertCopyLayer ? from : nullptr); - }); - - if (bNeedInsertCopyLayer) { - for (size_t inputIdx = 0; inputIdx < l->insData.size(); ++inputIdx) { - IE_ASSERT(l->insData[inputIdx].lock() != nullptr); - auto inputData = l->insData[inputIdx].lock(); - auto parentLayer = getCreatorLayer(inputData); - IE_ASSERT(parentLayer.lock() != nullptr); - InsertCopyLayer(parentLayer.lock(), - l, - static_cast(inputIdx), - this->getPassManager(), - CopyLayerName); - } - } - } -} - -void FlattenTrivialConcatPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "FlattenTrivialConcatPass"); - // change all trivial concatenations (concatenation where output buffer is a buffer made by appending input buffers) - // by reshaping its inputs to 1 x total_input_size and its output to 1 x total_concat_size and changing the axis to - // 1 for example if 4D concat have unaligned inputs then ConcatAlignFilters need to be used; if sizes before concat - // axis are all ones then concat can be changed to 2D for example, let's say all inputs have the same shape equal - // to: 1, 1, 5, 3 then for axis 0, 1, 2 the change will be made and inputs will be reshaped to 1, 15, but for shape - // 2, 1, 5, 3 only axis 0 is valid and in such case inputs will be reshaped to 1, 30 - // TODO: detection of trivial cases could be moved to one common place when all transformations are migrated to - // ngraph. See as well code for detection of unsupported concat - auto quantized = InferenceEngine::getInjectedData(pLayers->front()); - - auto getLayerByIndex = [](int idx, ConcatLayer* concatLayer) { - auto input = concatLayer->insData[idx]; - auto lockedInput = input.lock(); - if (!lockedInput) { - THROW_GNA_EXCEPTION << "cannot get insdata : " << idx << " for layer: " << concatLayer->name; - } - return lockedInput; - }; - - for (auto& l : *pLayers) { - LayerInfo info(l); - auto concatLayer = info.as(); - if (!concatLayer) - continue; - if (concatLayer->insData.size() < 1) - continue; - - // Skip obvious supported cases - auto dims_size = concatLayer->insData[0].lock()->getDims().size(); - if (dims_size < 2 || concatLayer->_axis == dims_size - 1) - continue; - - // Skip cases which cannot be flattened (these might be unsupported at all) - auto axis = concatLayer->_axis; - bool skip_layer = false; - for (unsigned int i = 0; i < axis; i++) { - if (concatLayer->insData[0].lock()->getDims()[i] != 1) - skip_layer = true; - } - if (skip_layer) - continue; - - // Calculate total input sizes - std::vector total_sizes; - for (auto& input : concatLayer->insData) { - auto input_dims = input.lock()->getDims(); - total_sizes.push_back( - std::accumulate(input_dims.begin(), input_dims.end(), size_t(1), std::multiplies())); - } - - // Reshape concat inputs - for (size_t input_idx = 0; input_idx != concatLayer->insData.size(); input_idx++) { - auto concatInput = getLayerByIndex(static_cast(input_idx), concatLayer); - - auto tensor = InferenceEngine::TensorDesc(concatInput->getTensorDesc()); - tensor.reshape(SizeVector({1, total_sizes[input_idx]}), InferenceEngine::Layout::NC); - auto reshapeName = l->name + "_input_" + std::to_string(input_idx) + "_reshape"; - auto reshape = CNNNetworkCreateReshape(tensor, reshapeName, quantized); - - CNNNetworkInsertLayer(getCreatorLayer(concatInput).lock(), l, reshape); - log::debug() << "\tInserted " << reshapeName << " between " << getCreatorLayer(concatInput).lock()->name - << " and " << l->name << std::endl; - } - - // Reshape concat outputs back to the original size - for (size_t output_idx = 0; output_idx != concatLayer->outData.size(); output_idx++) { - auto output = concatLayer->outData[output_idx]; - auto output_tensor_copy = TensorDesc(output->getTensorDesc()); - - auto dims = output_tensor_copy.getDims(); - auto total_size = std::accumulate(dims.begin(), dims.end(), size_t(1), std::multiplies()); - - auto new_tensor = output->getTensorDesc(); - new_tensor.reshape(SizeVector({1, total_size}), InferenceEngine::Layout::NC); - - auto new_output = CNNReplaceDataWithChangedTensorDescription(output, new_tensor); - log::debug() << "\tChanged " << output->getName() << " dims to 2D" << std::endl; - - auto reshapeName = l->name + "_output_" + std::to_string(output_idx) + "_reshape"; - - auto reshape = CNNNetworkCreateReshape(output_tensor_copy, reshapeName, quantized); - if (getInputTo(new_output).empty()) { - reshape->insData.push_back(new_output); - getInputTo(new_output)[reshape->name] = reshape; - } else { - CNNNetworkInsertLayer(l, nullptr, reshape, output_idx); - } - log::debug() << "\tInserted " << reshapeName << " after " << l->name << std::endl; - } - - concatLayer->_axis = 1; - } -} - -void InsertConcatAligningFilterPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "InsertConcatAligningFilterPass"); - auto quantized = InferenceEngine::getInjectedData(pLayers->front()); - - int numOfFilterLayers = 0; - - for (auto& l : *pLayers) { - LayerInfo info(l); - if (!info.isConcat()) - continue; - size_t offset = 0; - auto concatLayer = info.as(); - IE_ASSERT(concatLayer != nullptr); - - for (auto input_idx = 0; input_idx != static_cast(concatLayer->insData.size()); input_idx++) { - auto getLayerByIndex = [&concatLayer](int idx) { - auto input = concatLayer->insData[idx]; - auto lockedInput = input.lock(); - if (!lockedInput) { - THROW_GNA_EXCEPTION << "cannot get insdata : " << idx << " for layer: " << concatLayer->name; - } - return lockedInput; - }; - - auto concatInput = getLayerByIndex(input_idx); - auto dims = concatInput->getDims(); - auto outputSize = details::product(++dims.begin(), dims.end()) * Limitations::kBytesPerConcatElement; - - auto useAlignFilterIf = [&concatLayer, &getLayerByIndex](int concat_input_idx) { - if (static_cast(concatLayer->insData.size()) <= concat_input_idx) - return false; - - auto nextInput = getCreatorLayer(getLayerByIndex(concat_input_idx)).lock(); - - if (LayerInfo(nextInput).isInput()) - return false; - - return true; - }; - - // correcting offset by copy layer insertion. This can be improved by collapsing copy and affine or diagonal - // later-on if next concat inputs requires align filter - then current input also requires either copy or - // align filter - if ((!Limitations::get_instance()->is_aligned(offset)) || - ((!Limitations::get_instance()->is_aligned(outputSize)) && useAlignFilterIf(input_idx + 1))) { - auto prevLayer = getCreatorLayer(concatInput).lock(); - // input layer parameters are copied not using GNA-primitives - so nothing to allign here. - if (!useAlignFilterIf(input_idx)) - continue; - - log::debug() << "Inserted Concat Aligning Layer between: " << prevLayer->name << " and " << l->name - << std::endl; - - // insert the filter - auto filterName = std::string("ConcatAlignFilter_") + std::to_string(numOfFilterLayers++); - auto concatAligningFilter = - std::make_shared(LayerParams({filterName, "ConcatAlignFilter", Precision::FP32})); - - if (dims.size() != 2) { - THROW_GNA_EXCEPTION << "unsupported concat input of dims.size()=" << dims.size() - << ", layer=" << prevLayer->name; - } - - auto num_rows_in = dims[1]; - size_t aligned_offset = - std::max(0, - static_cast(ALIGN(offset, Limitations::get_instance()->get_memory_alignment()) - - Limitations::get_instance()->get_memory_alignment())); - size_t num_rows_padded = (offset - aligned_offset) / Limitations::kBytesPerConcatElement; - size_t num_rows_out = num_rows_padded + num_rows_in; - - // encodes offset to beginning of split layer input - size_t bytesOffset = - (aligned_offset / Limitations::kBytesPerConcatElement) * - (quantized ? Limitations::kBytesPerConcatElement : Precision(Precision::FP32).size()); - concatAligningFilter->params["output_offset"] = std::to_string(bytesOffset); - - // for padded rows we cannot use copy layer - TBD how to implement - concatAligningFilter->params["num_rows_padded"] = std::to_string(num_rows_padded); - - // encodes original output size - concatAligningFilter->params["original_num_rows"] = std::to_string(num_rows_in); - - std::vector filterWeights(num_rows_out * num_rows_in, 0.f); - - auto identityIdx = num_rows_padded * num_rows_in; - for (size_t i = 0; i != num_rows_in; i++) { - filterWeights[identityIdx] = 1.0f; - identityIdx += num_rows_in + 1; - } - - concatAligningFilter->_weights = - make_shared_blob(TensorDesc(concatInput->getTensorDesc().getPrecision(), - SizeVector({filterWeights.size()}), - InferenceEngine::Layout::C)); - concatAligningFilter->_weights->allocate(); - if (!concatAligningFilter->_weights->buffer().as()) { - THROW_GNA_EXCEPTION << "Failed to allocate weights of size " << filterWeights.size() << " for " - << filterName; - } - - CopyVectorToBlob(concatAligningFilter->_weights, filterWeights); - - // modifying output rows to be used - to avoid modification to original concat we are store num of - // elements in params - dims[1] = num_rows_out; - - if ((concatInput->getLayout() == InferenceEngine::Layout::NC && dims[0] > 8) || - (concatInput->getLayout() == InferenceEngine::Layout::CN && dims[1] > 8)) { - THROW_GNA_EXCEPTION << "unsupported batch number '" - << (concatInput->getLayout() == InferenceEngine::Layout::NC ? dims[0] : dims[1]) - << "' in layer '" << concatLayer->name << "'"; - } - - auto outData = - std::make_shared(filterName, - TensorDesc(concatInput->getPrecision(), dims, concatInput->getLayout())); - - auto filterWithQuant = quantized - ? InferenceEngine::injectData(concatAligningFilter) - : concatAligningFilter; - getCreatorLayer(outData) = filterWithQuant; - filterWithQuant->outData.push_back(outData); - - CNNNetworkInsertLayer(prevLayer, l, filterWithQuant); - } - offset += outputSize; - } - } -} - -void ReorderConcatInputsPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "ReorderConcatInputsPass"); - auto quantized = InferenceEngine::getInjectedData(pLayers->front()); - int numOfLinkLayers = 0; - - for (auto& l : *pLayers) { - // 1st stage locate concat - LayerInfo info(l); - if (!info.isConcat()) { - continue; - } - - // 2nd stage locate first input in concat - if (l->insData.size() < 2) { - THROW_GNA_EXCEPTION << "Concat layer has unsupported number of incoming layers: " << l->name; - } - - auto concatLayer = info.as(); - auto getLayerByIndex = [&concatLayer](int idx) { - auto input = concatLayer->insData[idx]; - auto lockedInput = input.lock(); - if (!lockedInput) { - THROW_GNA_EXCEPTION << "cannot get insdata : " << idx << " for layer: " << concatLayer->name; - } - return lockedInput; - }; - - for (auto input_idx = 1; input_idx != static_cast(concatLayer->insData.size()); input_idx++) { - auto concatInput = getLayerByIndex(input_idx); - auto currConcatLayer = getCreatorLayer(concatInput).lock(); - - LayerInfo infoConcatInput(currConcatLayer); - if (!infoConcatInput.isConcatAlignFilter()) { - continue; - } - - auto inputsToConcatPrev = CNNNetGetPrevLayersSkip( - l, - [](CNNLayerPtr origin) { - return !LayerInfo(origin).isNonFunctional() && !LayerInfo(origin).isSplit(); - }, - input_idx - 1); - - if (inputsToConcatPrev.empty()) { - THROW_GNA_EXCEPTION << "cannot locate first input into concat layer: " << currConcatLayer; - } - - auto prevInputToConcat = inputsToConcatPrev.front().first; - - // concat has first input of concat align filter - dont need to reorder it - if (prevInputToConcat == currConcatLayer) { - continue; - } - - bool bFinish = false; - // making a link activation possible without extra layer if first input to concat not a parent / indirect - // parent of second input using ufs - upper first search - log::debug() << "[UFS] searching for: " << prevInputToConcat->name << "\n"; - - CNNNetDFS( - currConcatLayer, - [&currConcatLayer, &prevInputToConcat, &bFinish](CNNLayerPtr layer) { - log::debug() << "[UFS] from : " << currConcatLayer->name << " reached: " << layer->name << "\n"; - // found that direct input to concat is a indirect parent of align filter - so no link required - if (layer.get() == prevInputToConcat.get() || LayerInfo(prevInputToConcat).isInput()) { - log::debug() << "[UFS] copy layer insertion needed\n"; - bFinish = true; - } - }, - true, - [&bFinish](InferenceEngine::CNNLayer* from) { - // aborting UFS once link not needed - return make_upstream_order(!bFinish ? from : nullptr); - }); - - auto linkName = std::string("link_") + std::to_string(numOfLinkLayers++); - - auto linkWithoutQuant = std::make_shared(LayerParams({linkName, "link", Precision::FP32})); - - auto link = - quantized ? InferenceEngine::injectData(linkWithoutQuant) : linkWithoutQuant; - - auto linkOutData = - std::make_shared(linkName, - TensorDesc(Precision::FP32, SizeVector({1}), InferenceEngine::Layout::C)); - getCreatorLayer(linkOutData) = link; - - link->outData.push_back(linkOutData); - link->insData.push_back(currConcatLayer->outData.front()); - - getInputTo(linkOutData)[prevInputToConcat->name + ".via.link"] = prevInputToConcat; - prevInputToConcat->insData.push_back(linkOutData); - - getInputTo(currConcatLayer->outData.front())[linkName] = link; - } - } -} - -void InsertSplitAligningFilterPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "InsertSplitAligningFilterPass"); - - auto quantized = InferenceEngine::getInjectedData(pLayers->front()); - - int numOfFilterLayers = 0; - for (auto& l : *pLayers) { - auto info = LayerInfo(l); - if (!info.isSplit() && !info.isSlice()) { - continue; - } - - auto outFunctionalLayers = CNNNetGetAllNextLayersSkipCertain(l, -1, [](CNNLayerPtr next_layer) { - return LayerInfo(next_layer).isNonFunctional(); - }); - size_t padding = 0; - for (auto&& outFunctionalLayer : outFunctionalLayers) { - padding = std::max(padding, LayerInfo(outFunctionalLayer).paddingSize()); - } - - size_t currentOffset = 0; - int splitOutIndex = 0; - for (auto&& splitOutput : l->outData) { - auto outputSize = product(begin(splitOutput->getDims()), end(splitOutput->getDims())); - - if ((!Limitations::get_instance()->is_aligned(currentOffset)) || (padding != 0)) { - // check that this split output actually connected to further layers - if (getInputTo(splitOutput).empty()) { - log::debug() << "Output port: " << splitOutIndex << " of " << l->name << " unconnected, skipping\n"; - } else { - if (splitOutput->getDims().size() > 1 && splitOutput->getDims().front() > 1) { - THROW_GNA_EXCEPTION - << l->name - << " Convolution Filter doesn't support batch=" << splitOutput->getDims().front(); - } - - // this split output not beginning from aligned bytes boundary - need to correct by aligning - // filter layer insert the filter - auto filterName = std::string("AlignFilter_") + std::to_string(numOfFilterLayers++); - -#ifdef PLOT - // getting list of layers attached to current split output - log::debug() << "Inserted Affine Filter: " << filterName << " between: " << l->name << " and "; - for (auto&& followingLayers : getInputTo(splitOutput)) { - if (getInputTo(splitOutput).size() != 1) { - log::debug() << "\n "; - } - log::debug() << followingLayers.second->name; - } - log::debug() << std::endl; -#endif - auto filterLayer = std::make_shared( - LayerParams({filterName, "ConvolutionFilter", Precision::FP32})); - - auto inputData = splitOutput; - - size_t aligned_offset = std::max( - 0, - static_cast(ALIGN(currentOffset, Limitations::get_instance()->get_memory_alignment()) - - Limitations::get_instance()->get_memory_alignment())); - - IE_ASSERT(filterLayer != nullptr); - - // encodes offset to beginning of split layer input - filterLayer->params["offset"] = std::to_string(aligned_offset / Limitations::kBytesPerSplitElement); - auto dims = splitOutput->getTensorDesc().getDims(); - if (dims.size() > 3) { - THROW_GNA_EXCEPTION << "unsupported split layer dims size: " << dims.size(); - } - - const auto offsetOfUnalignment = - (currentOffset - aligned_offset) / Limitations::kBytesPerSplitElement; - // TODO consider to use a different number of filters do decrese the number of trailing zeros - // (additionalPaddingOfFilter) - const auto numberOfFilters = Limitations::kConvMinFiltersNum; - const auto filterSize = - ALIGN(offsetOfUnalignment + numberOfFilters, Limitations::kConvFilterSizeDivider); - - // filterWeights: numberOfFilters X (offsetOfUnalignment + additionalPaddingOfFilter + - // numberOfFilters) offsetOfUnalignment - the leading zeros in the filter - // | - // | additionalPaddingOfFilter = filterSize - offsetOfUnalignment - - // numberOfFilters - // ____|___ ___|___ - // | | | | - // 0 0 ... 0 1 0 0 0 0 ... 0 - // 0 0 ... 0 0 1 0 0 0 ... 0 - // 0 0 ... 0 0 0 1 0 0 ... 0 - // 0 0 ... 0 0 0 0 1 0 ... 0 - std::vector filterWeights(filterSize * 4, 0.f); - for (auto f = 0u; f < numberOfFilters; f++) { - filterWeights[f * filterSize + f + offsetOfUnalignment] = 1; - } - - filterLayer->_out_depth = numberOfFilters; - filterLayer->_stride_x = numberOfFilters; - filterLayer->_stride_y = 1; - filterLayer->_kernel_x = static_cast(filterSize); - filterLayer->_kernel_y = 1; - filterLayer->_padding_x = 0; - filterLayer->_padding_y = 0; - - filterLayer->_weights = - make_shared_blob(TensorDesc(inputData->getTensorDesc().getPrecision(), - SizeVector({filterWeights.size()}), - InferenceEngine::Layout::C)); - filterLayer->_weights->allocate(); - CopyVectorToBlob(filterLayer->_weights, filterWeights); - - std::vector biasWeights(numberOfFilters, 0.f); - - filterLayer->_biases = make_shared_blob(TensorDesc(inputData->getTensorDesc().getPrecision(), - SizeVector({biasWeights.size()}), - InferenceEngine::Layout::C)); - filterLayer->_biases->allocate(); - CopyVectorToBlob(filterLayer->_biases, biasWeights); - - auto outData = std::make_shared(filterName, - TensorDesc(splitOutput->getTensorDesc().getPrecision(), - splitOutput->getTensorDesc().getDims(), - inputData->getTensorDesc().getLayout())); - - auto filterWithQuant = - quantized ? InferenceEngine::injectData(filterLayer) : filterLayer; - getCreatorLayer(outData) = filterWithQuant; - filterWithQuant->outData.push_back(outData); - CNNNetworkInsertLayer(l, nullptr, filterWithQuant, splitOutIndex); - } - } - - // search data that starts from unaligned location - currentOffset += outputSize * Limitations::kBytesPerSplitElement; - splitOutIndex++; - } - } -} - -static InferenceEngine::Blob::Ptr tileBlob(Blob::Ptr& blob, size_t TileTo) { - auto weightsElements = blob->size(); - auto weightsBytes = blob->byteSize(); - if (weightsElements == 0) { - IE_THROW() << "Blob size is 0"; - } - - auto tiledBlob = make_plain_blob(blob->getTensorDesc().getPrecision(), {TileTo}); - tiledBlob->allocate(); - - for (size_t i = 0; i < (TileTo / weightsElements); ++i) { - ie_memcpy(tiledBlob->buffer().as() + i * weightsBytes, weightsBytes, blob->cbuffer(), weightsBytes); - } - return tiledBlob; -} - -void EltwiseSplitOverChannelsPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "EltwiseSplitOverChannelsPass"); - - for (auto& l : *pLayers) { - if (!LayerInfo(l).isEltwise()) { - continue; - } - auto masterEltwise = std::dynamic_pointer_cast(l); - IE_ASSERT(masterEltwise != nullptr); - - if (l->outData.size() != 1) { - THROW_GNA_LAYER_EXCEPTION(l) << "number of outputs expected to be 1"; - } - auto oData = l->outData.front(); - auto oDims = oData->getDims(); - auto totalElementsSize = details::product(std::begin(oDims), std::end(oDims)); - if (totalElementsSize <= Limitations::kBufferMaxSize) { - continue; - } - auto splitSizesPerAxis = AlignedSplitSizesPerAxis(oDims); - - if (0 == splitSizesPerAxis.second.size()) { - THROW_GNA_LAYER_EXCEPTION(l) << "splitting didn't succeed\n"; - } - - pass_trace() << "transforming " << LAYER_NAME(l) << " by splitting it to multiple eltwise operations\n"; - auto quantized = InferenceEngine::getInjectedData(l); - - bool sameInputs = l->insData[0].lock() == l->insData[1].lock(); - std::vector splitLayers(2); - for (size_t kThEltwiseInput = 0; kThEltwiseInput != 2; kThEltwiseInput++) { - // create split layer - auto splitRaw = std::make_shared( - LayerParams{l->name + "/split/" + std::to_string(kThEltwiseInput), "Split", Precision::FP32}); - auto split = quantized ? InferenceEngine::injectData(splitRaw) : splitRaw; - splitLayers[kThEltwiseInput] = split; - - split->insData.push_back(l->insData[kThEltwiseInput]); - auto inputDesc = l->insData[kThEltwiseInput].lock()->getTensorDesc(); - - // create split layer outputs - for (auto elementsNum : splitSizesPerAxis.second) { - auto newDims = oDims; - newDims[splitSizesPerAxis.first] = elementsNum; - auto newDesc = TensorDesc(inputDesc.getPrecision(), newDims, inputDesc.getLayout()); - auto data = std::make_shared(l->name + "/" + std::to_string(kThEltwiseInput) + "/1", newDesc); - getCreatorLayer(data) = split; - split->outData.push_back(data); - } - // replacing connection X->eltwise to X->split - auto oData = CNNLayerFindOutData(l, static_cast(kThEltwiseInput)); - oData.second->second = split; - - if (sameInputs) { - splitLayers[1] = splitLayers[0]; - break; - } - } - - // create concatlayer - auto concatRaw = std::make_shared(LayerParams{l->name + "/concat", "Concat", Precision::FP32}); - auto concat = quantized ? InferenceEngine::injectData(concatRaw) : concatRaw; - - concat->outData.push_back(masterEltwise->outData.front()); - getCreatorLayer(masterEltwise->outData.front()) = concat; - - for (size_t k = 0; k != splitSizesPerAxis.second.size(); k++) { - auto eltwiseRaw = std::make_shared( - LayerParams{l->name + "/eltwise/" + std::to_string(k), "Eltwise", Precision::FP32}); - IE_ASSERT(eltwiseRaw != nullptr); - eltwiseRaw->_operation = masterEltwise->_operation; - eltwiseRaw->coeff = masterEltwise->coeff; - auto eltwise = quantized ? InferenceEngine::injectData(eltwiseRaw) : eltwiseRaw; - - eltwise->insData.push_back(splitLayers[0]->outData[k]); - eltwise->insData.push_back(splitLayers[1]->outData[k]); - getInputTo(splitLayers[0]->outData[k])[eltwise->name] = eltwise; - getInputTo(splitLayers[1]->outData[k])[eltwise->name] = eltwise; - - SizeVector newDims = splitLayers[1]->outData[k]->getDims(); - auto newDesc = TensorDesc(splitLayers[1]->outData[k]->getPrecision(), - newDims, - splitLayers[1]->outData[k]->getLayout()); - auto data = std::make_shared(l->name + "/elwise/out/" + std::to_string(k), newDesc); - getCreatorLayer(data) = eltwise; - eltwise->outData.push_back(data); - if (quantized) { - auto eltwiseQuant = InferenceEngine::getInjectedData(eltwise); - if (quantized->_src_quant.IsStatsSet()) { - eltwiseQuant->_src_quant.CopyStats(quantized->_src_quant); - } - if (quantized->_dst_quant.IsStatsSet()) { - eltwiseQuant->_dst_quant.CopyStats(quantized->_dst_quant); - } - } - getInputTo(data)[concat->name] = concat; - concat->insData.push_back(data); - } - } -} - -void SubstituteScaleShiftBroadCastPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "SubstituteScaleShiftBroadCastPass"); - std::map reshaped_data; - auto quantized = InferenceEngine::getInjectedData(pLayers->front()); - - for (auto& l : *pLayers) { - LayerInfo layerInfo(l); - - if (!layerInfo.isScaleShift()) { - continue; - } - - auto scaleShift = layerInfo.as(); - IE_ASSERT(scaleShift != nullptr); - - auto insData = scaleShift->insData.front().lock(); - if (!insData) { - THROW_GNA_EXCEPTION << "Cannot get inputs data for layer: " << l->name; - } - - bool was_reshaped = reshaped_data.count(insData->getName()) != 0; - bool reshape_batch = HasTo2DReshapeData(l); - InferenceEngine::SizeVector dataDims; - if (was_reshaped) { - dataDims = reshaped_data[insData->getName()]; - } else { - dataDims = - HasTo2DReshapeData(l) - ? Get2DReshapedData(insData, Limitations::get_min_batch_to_fit_in_buffer(insData), 8)->getDims() - : insData->getDims(); - } - - if (dataDims.size() <= 2) { - // NC or C cannot do broadcast - continue; - } - - auto batchSize = dataDims[0]; - auto nElements = product(begin(dataDims), end(dataDims)) / batchSize; - auto weightsElements = scaleShift->_weights->size(); - - if (!reshape_batch && nElements == weightsElements) { - continue; - } - - // TODO: add broadcasting rules checks - - log::debug() << "Substitution ScaleShift broadcast for layer: " << l->name << "\n"; - if (nElements % scaleShift->_weights->size()) { - THROW_GNA_EXCEPTION << "Cannot tile weights for layer: " << l->name - << ", due to weights size not GCD of dims product"; - } - scaleShift->_weights = tileBlob(scaleShift->_weights, nElements); - if (scaleShift->_biases) { - if (nElements % scaleShift->_biases->size()) { - THROW_GNA_EXCEPTION << "Cannot tile biases for layer: " << l->name - << ", due to biases size not GCD of dims product"; - } - scaleShift->_biases = tileBlob(scaleShift->_biases, nElements); - } - - auto tensor = InferenceEngine::TensorDesc(insData->getTensorDesc()); - tensor.reshape(SizeVector{batchSize, nElements}, InferenceEngine::Layout::NC); - auto reshapeName = scaleShift->name + "_input_" + std::to_string(0) + "_reshape"; - auto reshape = CNNNetworkCreateReshape(tensor, reshapeName, quantized); - auto layer_before_scale_shift = getCreatorLayer(insData); - - CNNNetworkInsertLayer(layer_before_scale_shift.lock(), l, reshape); - log::debug() << "\tInserted " << reshapeName << " between " << layer_before_scale_shift.lock()->name << " and " - << l->name << std::endl; - } -} - -void BroadcastConstPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "BroadcastConstPass"); - for (auto& constLayer : *pLayers) { - if (!LayerInfo(constLayer).isConst()) { - continue; - } - - auto isNonFunctional = [](CNNLayerPtr layer) { - return LayerInfo(layer).isNonFunctional(); - }; - - auto nextLayer = CNNNetCheckNextLayerSkipCertain(constLayer, 0, 0, true, isNonFunctional).first; - if (!nextLayer || (!LayerInfo(nextLayer).isEltwise() && !LayerInfo(nextLayer).isFakeQuantize())) { - continue; - } - - auto prevLayer = nextLayer; - if (LayerInfo(nextLayer).isFakeQuantize()) { - if (CNNNetPrevLayer(nextLayer, 0) != constLayer) { - continue; - } - - nextLayer = CNNNetCheckNextLayerSkipCertain(nextLayer, 0, 0, true, isNonFunctional).first; - if (!nextLayer || !LayerInfo(nextLayer).isEltwise()) { - continue; - } - } - - auto& constDims = constLayer->outData.front()->getTensorDesc().getDims(); - auto constDimsSize = product(constDims.begin(), constDims.end()); - auto& eltwiseDims = nextLayer->outData.front()->getTensorDesc().getDims(); - auto eltwiseDimsSize = product(eltwiseDims.begin(), eltwiseDims.end()); - if (constDimsSize == eltwiseDimsSize || eltwiseDimsSize % constDimsSize) { - continue; - } - - auto blobsIter = constLayer->blobs.find("custom"); - if (blobsIter == constLayer->blobs.end()) { - THROW_GNA_LAYER_EXCEPTION(constLayer) - << "Const layer " << constLayer->name << " is missing 'custom' parameter"; - } - - auto currentConstBlob = blobsIter->second; - blobsIter->second = tileBlob(currentConstBlob, eltwiseDimsSize); - constLayer->outData.front()->setDims(nextLayer->outData.front()->getDims()); - constLayer->outData.front()->setLayout(nextLayer->outData.front()->getLayout()); - if (prevLayer != nextLayer) { - prevLayer->outData.front()->setDims(nextLayer->outData.front()->getDims()); - prevLayer->outData.front()->setLayout(nextLayer->outData.front()->getLayout()); - } - log::debug() << "Const layer '" << constLayer->name << "' was changed to match output of '" << nextLayer->name - << "'\n"; - } -} - -void BreakFusingOfOutputLayersPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "BreakFusingOfOutputLayersPass"); - OutputsDataMap outputsMap = this->getPassManager()->getNetwork().getOutputsInfo(); - for (auto& layer : *pLayers) { - /* Inserion of the second activation after pooling will break Conv - Pooling - Activation component - * since scaleshift layers will be inserted between the pooling and activations - */ - if (LayerInfo(layer).isPooling()) - continue; - for (size_t output_idx = 0; output_idx < layer->outData.size(); output_idx++) { - auto& output = layer->outData[output_idx]; - auto& input_to = getInputTo(output); - - auto output_name = output->getName(); - auto is_network_output = outputsMap.find(output_name) != outputsMap.end(); - // In cases that this layer is network output you cannot use identity as sole output on - // it since it will possibly be fused and layer outputs will be unavailable - if (is_network_output) { - if (input_to.size() != 1) - continue; - if (!LayerInfo(input_to.begin()->second).isActivation()) - continue; - - CNNLayerPtr additional_output = std::make_shared( - LayerParams({output_name + "_side_identity", "identity", InferenceEngine::Precision::FP32})); - - auto quantized = InferenceEngine::getInjectedData(layer); - auto additional_output_quant = - quantized ? InferenceEngine::injectData(additional_output) - : additional_output; - - additional_output_quant->insData.resize(1); - additional_output_quant->outData.resize(1); - - auto out_data = DataPtr(new Data(output_name + "_side_identity_data", output->getTensorDesc())); - getCreatorLayer(out_data) = additional_output_quant; - - additional_output_quant->outData[0] = out_data; - - input_to[additional_output_quant->name] = additional_output_quant; - additional_output_quant->insData[0] = output; - } - } - } -} - -void UnrollLSTMCellPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "UnrollLSTMCellPass"); - InferenceEngine::NetPass::UnrollRNN_if(getPassManager()->getNetwork(), [](const RNNCellBase& rnn) -> bool { - if (rnn.clip != 0.0f) - return true; - if (rnn.type == "GRUCell" || rnn.type == "GRUSequence" || rnn.type == "RNNCell" || rnn.type == "RNNSequence") - return true; - if (!(rnn.type == "LSTMCell" || rnn.type == "LSTMSequence") || - rnn.activations == std::vector{"relu"}) - return false; - return true; - }); -} - -void UnrollTIPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "UnrollTIPass"); - auto sts = InferenceEngine::NetPass::UnrollTI(getPassManager()->getNetwork()); - if (!sts) { - THROW_GNA_EXCEPTION << "TensorIterator layer cannot be unrolled!"; - } -} - -void RemoveConstPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "RemoveConstPass"); - auto network = getPassManager()->getNetwork(); - IE_SUPPRESS_DEPRECATED_START - auto& icnnnet = static_cast(network); - IE_SUPPRESS_DEPRECATED_END - auto* implNetwork = dynamic_cast(&icnnnet); - if (!implNetwork) { - THROW_GNA_EXCEPTION << "Remove const layers pass can only work on cnnnetworkimpl type"; - } - ConstTransformer transformer(implNetwork); - transformer.fullTrim(); -} - -void RemoveSingleInputConcatPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "RemoveSingleInputConcatPass"); - for (auto& l : *pLayers) { - if (l->type == "Concat") { - auto concat = dynamic_cast(l.get()); - if (concat == nullptr) { - THROW_GNA_EXCEPTION << "Layer has type Concat but faild during casting to ConcatLayer"; - } - if (concat->insData.size() == 1 && concat->outData.size() > 0) { - auto in = concat->insData[0]; - auto in_layer = getCreatorLayer(in.lock()); - - auto out = concat->outData[0]; - - for (auto& out_layer : getInputTo(out)) { - for (size_t i = 0; i < out_layer.second->insData.size(); i++) { - if (out_layer.second->insData[i].lock() == out) { - out_layer.second->insData[i] = in; - getInputTo(in.lock())[out_layer.second->name] = out_layer.second; - } - } - } - getInputTo(in.lock()).erase(concat->name); - getInputTo(out).clear(); - concat->insData.clear(); - concat->outData.clear(); - } - } - } -} - -void FuseMultipleIdentitiesPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "FuseMultipleIdentitiesPass"); - for (auto& l : *pLayers) { - if (l->insData.empty()) - continue; - - auto isNonFunctional = [](CNNLayerPtr ptr) { - return LayerInfo(ptr).isNonFunctional(); - }; - if (LayerInfo(l).hasMultipleInputs()) { - continue; - } - if (LayerInfo(l).isNonFunctional() || LayerInfo(l).has32BInput()) { - continue; - } - log::debug() << "CNNNetPrevLayer skip non functional from :: " << l->name; - auto isFunctional = [](CNNLayerPtr ptr) { - return !LayerInfo(ptr).isNonFunctional(); - }; - - auto prevLayersReached = CNNNetGetPrevLayersSkip(l, isFunctional); - if (!prevLayersReached.empty()) { - prevLayersReached.erase(std::remove_if(prevLayersReached.begin(), - prevLayersReached.end(), - [](const std::pair& candidate) { - return LayerInfo(candidate.first).isLink(); - }), - prevLayersReached.end()); - if (prevLayersReached.empty()) { - log::debug() << ", connected to link output only" << std::endl; - continue; - } - } - - if (prevLayersReached.size() != 1) { - std::stringstream layers; - for (auto&& prevLayer : prevLayersReached) { - layers << prevLayer.first->name; - layers << ", "; - } - THROW_GNA_LAYER_EXCEPTION(l) << "unsupported case: connected to " - << (prevLayersReached.empty() ? "zero" : "multiple") - << " outputs : " << layers.str(); - } - auto prevLayer = prevLayersReached.front().first; - auto outDataIdx = prevLayersReached.front().second; - log::debug() << ", reached " << prevLayer->name << " at " << outDataIdx << std::endl; - - if (!LayerInfo(prevLayer).has32BOutput()) - continue; - - std::vector resultSet = CNNNetGetAllNextLayersSkipCertain(prevLayer, outDataIdx, isNonFunctional); - - // now result set should have all needed layers - // checking that result set consist of already identity - CNNLayerPtr alreadyIdentity; - for (auto&& res : resultSet) { - if (LayerInfo(res).isIdentity()) { - alreadyIdentity = res; - break; - } - } - if (!alreadyIdentity) { - continue; - } else { - // just figure out how to connect to that "already identity" - // 1st stage - disconnect given layer from previous - auto directPrev = getCreatorLayer(l->insData.front().lock()).lock(); - auto oDataIdx = CNNLayerFindOutDataIdx(directPrev, 0); - auto& inputTo = getInputTo(directPrev->outData[oDataIdx]); - for (auto inIterator = inputTo.begin(); inIterator != inputTo.end(); inIterator++) { - if (inIterator->second == l) { - inputTo.erase(inIterator); - break; - } - } - l->insData.clear(); - - // 2nd stage - now setting up new connection - l->insData.push_back(alreadyIdentity->outData.front()); - getInputTo(alreadyIdentity->outData.front())[l->name] = l; - } - } -} - -void FuseFQIntoWeightsPass::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "FuseFQIntoWeightsPass"); - auto isNonFunctional = [](CNNLayerPtr ptr) { - return LayerInfo(ptr).isNonFunctional(); - }; - - auto assignWeightsAndBiases = [](CNNLayerPtr layer, Blob::Ptr weights, Blob::Ptr biases) { - auto weigtableLayer = std::dynamic_pointer_cast(layer); - if (nullptr == weigtableLayer) { - THROW_GNA_LAYER_EXCEPTION(layer) << " not a weightable layer"; - } - weigtableLayer->_weights = weights; - weigtableLayer->_biases = biases; - weigtableLayer->blobs["weights"] = weights; - weigtableLayer->blobs["biases"] = biases; - }; - - for (auto& l : *pLayers) { - if (!LayerInfo(l).isFakeQuantize()) { - continue; - } - // determine whether this FQ is actually ends into weigtable layer - auto fqLayer = l; - if (!CNNNetHasNextLayerSkipCertain(fqLayer, 0, 0, isNonFunctional)) { - continue; - } - - GNAFakeQuantizeLayer gnaFakeQuantizeLayer(fqLayer); - auto inputTo = getInputTo(fqLayer->outData[0]); - size_t layers_connected_to_fq_count = inputTo.size(); - auto layerBeforeWeightable = fqLayer; - while (layers_connected_to_fq_count == 1 && LayerInfo(inputTo.begin()->second).isNonFunctional()) { - layerBeforeWeightable = inputTo.begin()->second; - inputTo = getInputTo(layerBeforeWeightable->outData[0]); - layers_connected_to_fq_count = inputTo.size(); - } - for (int index = 0; index < static_cast(layers_connected_to_fq_count); index++) { - auto weightableLayer = - CNNNetCheckNextLayerSkipCertain(layerBeforeWeightable, 0, index, true, isNonFunctional).first; - if (!weightableLayer || !LayerInfo(weightableLayer).isWeightable()) { - continue; - } - if (weightableLayer->insData.size() < 2) { - continue; - } - - // check whether this FQ represents weights - it need to be at index 1 of weightable layer - const size_t weightsIdx = 1; - const size_t biasesIdx = 2; - auto prevLayerAt1 = CNNNetPrevLayerSkipCertain(weightableLayer, weightsIdx, isNonFunctional); - - if (prevLayerAt1 != fqLayer) { - continue; - } - - // now this FQ layer represents weights - lets apply it and fuse to given weightable layer. - pass_trace() << "found " << LAYER_NAME(fqLayer) << " that will be converted to weights of " - << LAYER_NAME(weightableLayer) << "\n"; - - auto biases = weightableLayer->insData.size() == 3 - ? layer_utils::getParamFromInputAsBlob(weightableLayer, biasesIdx) - : nullptr; - auto quantizedWeights = gnaFakeQuantizeLayer.getConstInputData(); - - // 1. broke existing connections - by detaching fq subgraph from rest of graph - auto prevData = weightableLayer->insData[weightsIdx].lock(); - auto prevLayer = getCreatorLayer(prevData).lock(); - auto weightDims = prevLayer->outData.front()->getDims(); - // input related to FakeQuantize layer is removed - auto& relatedInputs = getInputTo(prevLayer->outData[0]); - auto relatedInputsIter = relatedInputs.begin(); - while (relatedInputsIter != relatedInputs.end()) { - if (LayerInfo(relatedInputsIter->second).isFakeQuantize()) { - relatedInputsIter = relatedInputs.erase(relatedInputsIter); - } else { - ++relatedInputsIter; - } - } - - weightableLayer->insData.resize(1); - - // 2. running FQ function for given layer - auto outputSize = details::product(weightDims.begin(), weightDims.end()); - - // depending on compute precision weights will be recreated - // for integer mode - weights might be simply copied - to avoid furter quantisations overhead - auto quantized = InferenceEngine::getInjectedData(weightableLayer); - if (quantized) { - // assign already quantized Weights - assignWeightsAndBiases(weightableLayer, quantizedWeights, biases); - - // modify scale factors for quantized component - auto levels = gnaFakeQuantizeLayer.getLevels(); - auto inputRange = gnaFakeQuantizeLayer.getInputRange(); - auto outputRange = gnaFakeQuantizeLayer.getOutputRange(); - if (outputRange.first.size() != outputRange.second.size()) { - THROW_GNA_LAYER_EXCEPTION(fqLayer) - << " number of min and max data must be equal, min size: " << outputRange.first.size() - << ", max size: " << outputRange.second.size(); - } - - if (inputRange.first.size() != outputRange.first.size() || - inputRange.second.size() != outputRange.second.size()) { - THROW_GNA_LAYER_EXCEPTION(fqLayer) << " size of input and output range differs. " - << "input min size: " << inputRange.first.size() << ", " - << "output min size: " << outputRange.first.size() << ", " - << "input max size: " << inputRange.second.size() << ", " - << "output max size: " << outputRange.second.size(); - } - - if (levels > std::numeric_limits::max() && outputRange.first.size() > 1) { - // find min and max for input and output range - THROW_GNA_LAYER_EXCEPTION(fqLayer) << " unsupported per-channel quantization for int16 weights." - << " Per-channel quantization "; - } - - // check if - // - weights were float values and need to be quantized, - // - weights are integer values and quantization can be skipped - quantized->_weights_quant.SetMinValues(inputRange.first, true); - quantized->_weights_quant.SetMaxValues(inputRange.second, true); - quantized->_weights_quant.SetMinValues(outputRange.first, false); - quantized->_weights_quant.SetMaxValues(outputRange.second, false); - quantized->_weights_quant.SetLevels(levels); - - // lets find out minimum scale factor among channels - if (!quantized->_weights_quant.IsStatsSet()) { - THROW_GNA_LAYER_EXCEPTION(fqLayer) << " per channel/tensor weigths scales are missed"; - } - continue; - } - - size_t depth = 1; - intel_dnn_component_t component; - component.num_columns_in = static_cast(weightDims[1]); - component.num_rows_in = static_cast(weightDims[0]); - - if (LayerInfo(weightableLayer).isConvolution()) { - depth = (weightDims.size() == 4) ? weightDims[2] * weightDims[3] : 1; - } - - intel_piecewiselinear_t* transform = reinterpret_cast(&component.op.pwl); - transform->func_id = gnaFakeQuantizeLayer.parseAsActivation(); - - auto quantizedWeightsData = quantizedWeights->buffer(); - auto dequantizedWeights = - make_shared_blob(TensorDesc(Precision::FP32, {outputSize}, InferenceEngine::Layout::C)); - dequantizedWeights->allocate(); - - auto resultBuffer = dequantizedWeights->buffer(); - for (size_t i = 0; i < depth; ++i) { - component.ptr_inputs = - quantizedWeightsData.as() + i * component.num_columns_in * component.num_rows_in; - component.ptr_outputs = - resultBuffer.as() + i * component.num_columns_in * component.num_rows_in; - - PwlApply32(&component, 0, component.num_rows_in - 1, 0, component.num_columns_in - 1); - } - - // 3. assign dequantized const blob to weightable layer - assignWeightsAndBiases(weightableLayer, dequantizedWeights, biases); - } - } -} - -void MoveFakeQuantizeLayerIntoQuantParamsPass ::run() { - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "MoveFakeQuantizeLayerIntoQuantParamsPass"); - auto quantized = InferenceEngine::getInjectedData(pLayers->front()); - if (!quantized) { - return; - } - - auto allowFQFuse = [this](CNNLayerPtr layer) -> bool { - auto skipNonFunctionalOrMemory = [](CNNLayerPtr layer) { - return LayerInfo(layer).isNonFunctional() || LayerInfo(layer).isMemory(); - }; - auto skipNonFunctional = [](CNNLayerPtr layer) { - return LayerInfo(layer).isNonFunctional(); - }; - // Don't fuse FQ if it's the output layer for the network - if (CNNNetGetAllNextLayersSkipCertain(layer, -1, skipNonFunctionalOrMemory).empty()) { - return false; - } - // Fuse FQ if it's not required to change precision from int32 to int16 - auto nextLayers = CNNNetGetAllNextLayersSkipCertain(layer, -1, skipNonFunctional); - for (auto& l : nextLayers) { - if (getCandidatesForIdentityInsertion(l, getPassManager(), true).empty()) { - return true; - } - } - return false; - }; - - std::function propagateStatistics = - [&propagateStatistics](QuantizedLayerParams* srcQuantParams, CNNLayerPtr layer) { - if (LayerInfo(layer).isFakeQuantize()) { - return; - } - - auto quantParams = InferenceEngine::getInjectedData(layer); - IE_ASSERT(quantParams != nullptr); - - // Find all output layers connected to FQ - auto nextLayers = CNNNetGetAllNextLayersSkipCertain(layer.get(), -1, DoNotSkip); - if (nextLayers.empty()) { - quantParams->_src_quant.CopyStats(srcQuantParams->_dst_quant); - if (LayerInfo(layer).isNonFunctional()) { - quantParams->_dst_quant.CopyStats(srcQuantParams->_dst_quant); - } - return; - } - - auto srcMinVals = srcQuantParams->_dst_quant.GetMinValues().front(); - auto srcMaxVals = srcQuantParams->_dst_quant.GetMaxValues().front(); - // If a next layer is concat, find minimum nad maximum statistics - if (LayerInfo(layer).isConcat() && quantParams->_src_quant.IsStatsSet()) { - auto concatMinVal = quantParams->_src_quant.GetMinValues().front(); - auto concatMaxVal = quantParams->_src_quant.GetMaxValues().front(); - quantParams->_src_quant.SetMinValues({std::min(srcMinVals, concatMinVal)}); - quantParams->_src_quant.SetMaxValues({std::max(srcMaxVals, concatMaxVal)}); - } else if (quantParams->_src_quant.IsStatsSet()) { - return; - } else { - quantParams->_src_quant.CopyStats(srcQuantParams->_dst_quant); - } - - if (!LayerInfo(layer).isWeightable() && !LayerInfo(layer).isEltwise() && !LayerInfo(layer).isActivation() && - !LayerInfo(layer).isFakeQuantize()) { - auto doNotSetDstStats = false; - for (auto& l : nextLayers) { - if (LayerInfo(l).isFakeQuantize()) { - doNotSetDstStats = true; - continue; - } - } - - if (doNotSetDstStats) { - return; - } - - quantParams->_dst_quant.CopyStats(quantParams->_src_quant); - - for (auto& l : nextLayers) { - if (LayerInfo(l).isFakeQuantize()) { - continue; - } - - propagateStatistics(quantParams, l); - } - } - }; - - for (auto&& l : *pLayers) { - if (!LayerInfo(l).isFakeQuantize()) { - continue; - } - GNAFakeQuantizeLayer fqLayer(l); - auto prevLayer = CNNNetPrevLayerSkipCertain(*fqLayer, 0, DoNotSkip); - auto prevDataIt = std::find_if(std::begin(prevLayer->outData), std::end(prevLayer->outData), [l](DataPtr data) { - return getInputTo(data).find(l->name) != std::end(getInputTo(data)); - }); - if (prevDataIt == std::end(prevLayer->outData)) { - THROW_GNA_LAYER_EXCEPTION(fqLayer) - << "Invalid connection between " << prevLayer->name << " and " << l->name; - } - - auto inputRange = fqLayer.getInputRange(); - auto outputRange = fqLayer.getOutputRange(); - if (inputRange.first.size() != 1 || inputRange.second.size() != 1 || outputRange.first.size() != 1 || - outputRange.second.size() != 1) { - THROW_GNA_LAYER_EXCEPTION(fqLayer) << " unsupported per-channel quantisation"; - } - - if (!LayerInfo(prevLayer).isConst() && !AreFpEq(inputRange.first.front(), outputRange.first.front()) && - !AreFpEq(inputRange.second.front(), outputRange.second.front())) { - THROW_GNA_LAYER_EXCEPTION(fqLayer) - << " unsupported data range conversion. Input: (" << inputRange.first.front() << "," - << inputRange.second.front() << "), output: (" << outputRange.first.front() << "," - << outputRange.second.front() << ")"; - } - - auto fqLevels = fqLayer.getLevels(); - if (fqLevels == 0) { - THROW_GNA_LAYER_EXCEPTION(fqLayer) << "Zero levels"; - } - - // Before FQ layer is removed, the previous functional layer has to be updated with its quantization data - auto prevFuncLayer = CNNNetPrevLayerSkipCertain(*fqLayer, 0, [](CNNLayerPtr layer) { - return LayerInfo(layer).isNonFunctional() || LayerInfo(layer).isPooling(); - }); - auto quantParamsPrevLayer = InferenceEngine::getInjectedData(prevFuncLayer); - quantParamsPrevLayer->_dst_quant.SetLevels(fqLevels); - quantParamsPrevLayer->_dst_quant.SetMinValues({inputRange.first[0]}, true); - quantParamsPrevLayer->_dst_quant.SetMaxValues({inputRange.second[0]}, true); - quantParamsPrevLayer->_dst_quant.SetMinValues({outputRange.first[0]}, false); - quantParamsPrevLayer->_dst_quant.SetMaxValues({outputRange.second[0]}, false); - - // Propogate destination statistics to multiply layer if it's set for the next sum/sub layer (is considered as - // bias) - if (LayerInfo(prevLayer).isEltwiseSum() || LayerInfo(prevLayer).isEltwiseSub()) { - auto eltwPrevLayer = CNNNetPrevLayerSkipCertain(prevLayer, 0, DoNotSkip); - auto constLayer = CNNNetPrevLayerSkipCertain(prevLayer, 1, DoNotSkip); - if (LayerInfo(eltwPrevLayer).isEltwise() && LayerInfo(constLayer).isConst()) { - auto quantParamsEltwLayer = InferenceEngine::getInjectedData(eltwPrevLayer); - quantParamsEltwLayer->_dst_quant.CopyStats(quantParamsPrevLayer->_dst_quant); - } - } - - auto fqQauntParams = InferenceEngine::getInjectedData(l); - fqQauntParams->_dst_quant.SetLevels(UINT16_MAX); - fqQauntParams->_dst_quant.SetMinValues({inputRange.first[0]}, true); - fqQauntParams->_dst_quant.SetMaxValues({inputRange.second[0]}, true); - fqQauntParams->_dst_quant.SetMinValues({outputRange.first[0]}, false); - fqQauntParams->_dst_quant.SetMaxValues({outputRange.second[0]}, false); - fqQauntParams->_src_quant = fqQauntParams->_dst_quant; - - l->insData.resize(1); - if (!CNNNetHasPrevLayer(prevLayer.get())) { - quantParamsPrevLayer->_src_quant = quantParamsPrevLayer->_dst_quant; - } - - // Allow FQ Fuse checks if FQ layer can be fused to a layer before or after. - // FQ Layer is fused if it's not required for precision change. - bool isFQFuseAllowed = allowFQFuse(l); - auto prevData = *prevDataIt; - - // Find all output layers connected to FQ - auto nextLayers = CNNNetGetAllNextLayersSkipCertain(*fqLayer, -1, DoNotSkip); - if (nextLayers.empty()) { - continue; - } - - if (isFQFuseAllowed) { - getInputTo(prevData).erase(l->name); - } - - // Connect all next layers after FQ to the layer that is before FQ - // and propagate quantization data - for (size_t i = 0; i < nextLayers.size(); ++i) { - if (isFQFuseAllowed) { - auto insDatas = CNNLayerFindInsDataIdxes(fqLayer->outData.front(), nextLayers[i]); - if (insDatas.empty()) { - THROW_GNA_LAYER_EXCEPTION(fqLayer) - << " fake quantize connection to layer: " << LAYER_NAME(nextLayers[i]) << " is not correct"; - } - for (int insDataIdx : insDatas) { - nextLayers[i]->insData[insDataIdx] = prevData; - } - getInputTo(prevData)[nextLayers[i]->name] = nextLayers[i]; - } - - propagateStatistics(quantParamsPrevLayer, nextLayers[i]); - } - } -} - -void FuseFullyConnectedWithEltwisePass::run() { - // This legacy pass removes the Eltwise (only if it performs SUM op) from between FC and Any. - // The blob data of Const layer attached to Eltwise is added to biases blob data of FC layer. - // Finally Const is also removed. - // Permute and Reshape layers existing between FC and Eltwise remain in the network in order - // to keep final data shape unchanged. - // - // This operation can be illustrated as follows: - // - // -- - // Original: Result: Removed: - // - // FC FC (Eltwise) - // | | (Const) - // Permute Permute - // (optional) (if exists in Original) - // | | - // Reshape Reshape - // (optional) Const (if exists in Original) - // | / | - // Eltwise(sum) Any - // | - // Any (e.g. ReLU) - //-- - // - // NOTE: This pass is implemented to prevent unnecessary roundtrip to memory (additional layer). - // It can be fully removed if corresponding LPT transformation is already implemented. - OV_ITT_SCOPED_TASK(itt::domains::GNA_LT, "FuseFullyConnectedWithEltwisePass"); - - auto skipPermuteAndReshape = [](CNNLayerPtr layer) { - if (IsOneDimLayer(layer)) { - if (LayerInfo(layer).isPermute() || LayerInfo(layer).isReshape()) { - return true; - } - } - return false; - }; - - for (auto& layer : *pLayers) { - if (!LayerInfo(layer).isFullyConnected() || !layer->outData.size()) { - continue; - } - CNNLayerPtr next = nullptr; - - auto& fully_connected = layer; - - // Find Eltwise skipping Premutes and Reshapes - auto eltwise = CNNNetCheckNextLayerSkipCertain(fully_connected, 0, 0, true, skipPermuteAndReshape).first; - - // If the layer is not Eltwise or does not perform 'sum' operation, we should skip the pass - if (!eltwise || !LayerInfo(eltwise).isEltwiseSum()) { - continue; - } - - // Get the Eltwise's input layers - CNNLayerPtr eltwise_const = nullptr; - CNNLayerPtr eltwise_input = nullptr; - for (size_t i = 0; i < eltwise->insData.size(); i++) { - // Get Eltwise's prev layer and check its kind - auto before_eltwise = CNNNetHasPrevLayer(eltwise.get(), 0) - ? CNNNetPrevLayerSkipCertain(eltwise, static_cast(i), DoNotSkip) - : nullptr; - if (LayerInfo(before_eltwise).isConst()) { - eltwise_const = before_eltwise; - } else { - eltwise_input = before_eltwise; - } - } - if (!eltwise_const || !eltwise_input) { - continue; - } - - // Find (any) layer after Eltwise - auto any_layer = CNNNetCheckNextLayerSkipCertain(eltwise, 0, 0, true, DoNotSkip).first; - if (!any_layer) { - continue; - } - - // Connect FC with layer after Eltwise (Eltwise and Const will be removed) - if (CNNRemoveAndConnect(eltwise_input, eltwise)) { - // Add data from Const "custom" blob to FC "biases" blob - auto& const_blob = eltwise_const->blobs.find("custom")->second; - auto& fc_blob = fully_connected->blobs.find("biases")->second; - SumBlobs(const_blob, fc_blob); - } - } -} - -int PassManager::run(int index) { -#if defined PLOT || defined ENABLE_V7_SERIALIZE - auto dumpNetworkAfterPass = [&index, this](std::shared_ptr pass) { - std::string name = - std::string("gna_passes_") + (index < 10 ? "0" : "") + std::to_string(index) + "_" + pass->getName(); -# ifdef PLOT - std::ofstream out(name + ".dot"); - saveGraphToDot( - network, - out, - [](const CNNLayerPtr layer, ordered_properties& printed_properties, ordered_properties& node_properties) { - }); -# endif -# ifdef ENABLE_V7_SERIALIZE - network.serialize(name + ".xml", name + ".bin"); -# endif - }; -#else - auto dumpNetworkAfterPass = [](std::shared_ptr) {}; -#endif - - for (auto&& pass : passes) { - if (settings.runBeforeCopy != pass->runBeforeCopyPass()) { - continue; - } - auto layers = CNNNetSortTopologically(network); - pass->attach(layers); - log::debug() << "PASS: " << ++index << "/" << passes.size() << ":" << pass->getName() << "\n"; - pass->run(); - dumpNetworkAfterPass(pass); - } - return index; -} - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/optimizer/gna_pass_manager.hpp b/src/plugins/intel_gna/src/optimizer/gna_pass_manager.hpp deleted file mode 100644 index e3a8e2f7a2f..00000000000 --- a/src/plugins/intel_gna/src/optimizer/gna_pass_manager.hpp +++ /dev/null @@ -1,261 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -#include "cpp/ie_cnn_network.h" -#include "legacy/ie_layers.h" - -namespace ov { -namespace intel_gna { - -/** - * @brief interface for gna-pass, special transformer that will be run on input network in order to generate GNABlob - */ -class Pass { -public: - virtual ~Pass() = default; - virtual void attach(const std::vector& layers) = 0; - virtual std::string getName() const = 0; - virtual void run() = 0; - virtual bool runBeforeCopyPass() { - return false; - } -}; -/** - * Passmanager interface available for individual passes, usually needed to store shared data between passes - */ -class IPassManager { -public: - virtual ~IPassManager() = default; - virtual int& getIntVar(std::string name) = 0; - virtual const bool& isLowPrecision() const = 0; - virtual InferenceEngine::CNNNetwork& getNetwork() = 0; -}; - -class BasePass : public Pass { -protected: - const std::vector* pLayers = nullptr; - std::weak_ptr mgr; - -public: - BasePass() = default; - explicit BasePass(std::shared_ptr mgr) : mgr(mgr) {} - void attach(const std::vector& layersToAttach) override { - pLayers = &layersToAttach; - } - -protected: - std::shared_ptr getPassManager(); -}; - -#define DECL_PASS(PassName) \ - class PassName##Pass : public BasePass { \ - public: \ - using BasePass::BasePass; \ - void run() override; \ - std::string getName() const override { \ - return #PassName; \ - } \ - } - -#define DECL_PASS_BEFORE_COPY(PassName) \ - class PassName##Pass : public BasePass { \ - public: \ - using BasePass::BasePass; \ - void run() override; \ - bool runBeforeCopyPass() override { \ - return true; \ - }; \ - std::string getName() const override { \ - return #PassName; \ - } \ - } - -/** - * @brief GNA affine layers are always have activation attached, while IR not - */ -DECL_PASS(InsertIdentityLayer); - -/** - * @brief GNA cannot support broadcast - so we will tile weights and biases for scaleshift layer - */ -DECL_PASS(SubstituteScaleShiftBroadCast); - -/** - * @brief Pass support --disable_nhwc_to_nchw option in MO - * @param layers - */ -DECL_PASS(RemovePermutationsNHWCToNCHW); - -/** - * brief @search for specific patter in the graph (6 layers are replaced by single one) - */ -DECL_PASS(SubstitutePRelu); - -/** - * brief @search for specific patter in the graph (5 layers are replaced by single one) - */ -DECL_PASS(SubstituteSoftSign); - -/** - * brief split ofver channels for Elementwise-layer to avoid GNA-HW limitation of 65 elements per eltwise - */ -DECL_PASS(EltwiseSplitOverChannels); -/** - * diagonal layer insertion required in cases where activation followed by split layers, or any other - * topology changing layers - */ -DECL_PASS(InsertDiagonalLayer); - -/** - * @brief MaxPool can be reordered with activation, on GNA there is a strategy to have conv->maxpool->activation - * it means maxpool receives 4 bytes, and produces 4 bytes - */ -DECL_PASS(ReorderMaxPool); - -/** - * @brief GNA doesn't support multiple activations fused with functional layer - * currently for n activations for the layer X, it will be 1 PWL identity inserted, and n diagonal layers. - * if one of activations is already identity, n-1 diagonal layers will be inserted - */ -DECL_PASS(HandleMultipleActivationsForTheLayer); - -/** - * @brief GNA doesn't provide intermediate results (sums) when the layer is fused with activation. - * When more layers use the sums as inputs (beside the activation) then the diagonal layer - * is inserted before the activation to forbid the fusing and make the sums exposed. - * This is observed in the multiple_activations_onGNA_INT16 test. - */ -DECL_PASS(ForbidActivationFusing); - -/** - * @brief copy layer insertion required in cases where input layer does not have output memory - */ -DECL_PASS(InsertCopyLayer); - -/** - * @brief aligning filter layer insertion required in cases when split/slice have output connections on not aligned - * addresses - */ -DECL_PASS(InsertSplitAligningFilter); - -/** - * @brief Pass that flattens trivial concatenations inputs and output and changes its axis to 1 - */ -DECL_PASS(FlattenTrivialConcat); - -/** - * @brief concat-aligning filter layer insertion required in cases when concat inputs size are not aligned - */ -DECL_PASS(InsertConcatAligningFilter); - -/** - * @brief concat-aligning filter if inserted need to be folowed by left aligning inupt in multiple inputs to concate - * case or just followed by first input to concate. This cannot be done in inserting concat aliging phase - */ -DECL_PASS(ReorderConcatInputs); - -/** - * @brief in cases that network output layer is connected to only one layer which is activation additional identity is - * inserted so the operation is not fused with the activation allowing to get te results from said layer - */ -DECL_PASS(BreakFusingOfOutputLayers); - -/** - * @brief insert identity at the output of LSTMCell which fixes cases where data is not propagated correctly through - * network and LSTMCell returns all zeroes - */ -DECL_PASS_BEFORE_COPY(InsertIdentityToLSTMCell); - -/** - * @brief unrolled LSTM cell layer in supported GNA primitives - */ -DECL_PASS_BEFORE_COPY(UnrollLSTMCell); - -/** - * @brief unrolled Tensor Iterator layer in supported GNA layers - */ -DECL_PASS_BEFORE_COPY(UnrollTI); - -/** - * @brief removed const layer before reshape layer - */ -DECL_PASS_BEFORE_COPY(RemoveConst); - -/** - * @brief remove concat layers with single input - */ -DECL_PASS_BEFORE_COPY(RemoveSingleInputConcat); - -/** - * @brief removed extra identity layer for multi-output - */ -DECL_PASS(FuseMultipleIdentities); - -/** - * @brief Brodcast data in Const layer - */ -DECL_PASS(BroadcastConst); - -/** - * @brief runs static quantisation on given floating weights and replaces fakeQuantize with constblobs - */ -DECL_PASS(FuseFQIntoWeights); - -/** - * @brief remove all fake quantize layers while moving it's settings into QuantParams for certain layer - */ -DECL_PASS(MoveFakeQuantizeLayerIntoQuantParams); - -/** - * @brief fuse FullyConnected and Eltwise layers, also in case there is a Reshape between them having input with only - * one dimension > 1 - */ -DECL_PASS(FuseFullyConnectedWithEltwise); - -struct PassManagerSettings { - /// @brief whether to run passes before copy - bool runBeforeCopy; - bool lowPrecision; -}; - -class PassManager : public IPassManager, public std::enable_shared_from_this { - PassManagerSettings settings; - InferenceEngine::CNNNetwork network; - std::vector> passes; - std::map intMap; - -public: - explicit PassManager(PassManagerSettings settings, InferenceEngine::CNNNetwork network) noexcept - : settings(settings), - network(network) {} - - template - void registerPass() { - passes.push_back(std::make_shared(shared_from_this())); - } - int& getIntVar(std::string name) override { - return intMap[name]; - } - const bool& isLowPrecision() const override { - return settings.lowPrecision; - } - InferenceEngine::CNNNetwork& getNetwork() override { - return network; - } - /** - * @brief returns number of passes have been passed - * @param index - start index start index of first pass - used only in logging right now - */ - int run(int index = 0); -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/orientation_helper.cpp b/src/plugins/intel_gna/src/orientation_helper.cpp deleted file mode 100644 index fd60b33f0c1..00000000000 --- a/src/plugins/intel_gna/src/orientation_helper.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "orientation_helper.hpp" - -#include - -#include - -namespace ov { -namespace intel_gna { -namespace helpers { - -void updateModelInputOrientationWithoutConvolution(const InferenceEngine::CNNLayer& inputLayer, - const backend::DnnComponents& components, - GnaInputs& inputs) { - // does not make sense to go further is there is no input to set - auto input = inputs.find(inputLayer.name); - - if (input == inputs.end()) { - return; - } - - auto dims = input->dims; - if (dims.empty()) { - // If input is scalar there is no sense to update orientation. - return; - } - auto rowsNum = dims[0]; - - auto doesntHaveGnaMapping = [=](InferenceEngine::CNNLayerPtr l) { - auto dnnLayer = components.findComponent(l); - return dnnLayer == nullptr; - }; - - auto nextLayers = InferenceEngine::CNNNetGetAllNextLayersSkipCertain(&inputLayer, -1, doesntHaveGnaMapping); - if (nextLayers.empty()) { - input->orientation = kDnnInterleavedOrientation; - return; - } - - auto columnProduct = - std::accumulate(std::next(std::begin(dims)), std::end(dims), size_t{1}, std::multiplies()); - - // does not make sense to check if further if any of sizes is equal to 1 - // intput will be set to kDnnNonInterleavedOrientation - if (rowsNum == 1 || columnProduct == 1) { - input->orientation = kDnnNonInterleavedOrientation; - return; - } - - intel_dnn_orientation_t suggestedOrientation = kDnnUnknownOrientation; - bool orientationIsSet = false; - - for (auto& nextLayer : nextLayers) { - auto dnnLayer = components.findComponent(nextLayer); - - if (!dnnLayer) { - THROW_GNA_LAYER_EXCEPTION(nextLayer) << " gna mapped layer search connection failed"; - } - // Do not take Transposition operation intu consideration. - if (dnnLayer->operation == kDnnInterleaveOp || dnnLayer->operation == kDnnDeinterleaveOp) { - continue; - } - - if (!orientationIsSet) { - suggestedOrientation = dnnLayer->orientation_in; - orientationIsSet = true; - } else if (suggestedOrientation != dnnLayer->orientation_in) { - // unsupported case: orientations are different and they are important for these components - THROW_GNA_EXCEPTION << "Input layer[" << inputLayer.name - << "] is used as input by multiple layers with different orientation!"; - } - } - - if (!orientationIsSet) { - input->orientation = kDnnNonInterleavedOrientation; - return; - } - - input->orientation = suggestedOrientation; - return; -} - -void updateModelOutputOrientation(const std::string& outputName, - const std::string& cnnlayerName, - const backend::DnnComponents& components, - GnaOutputs& outputs) { - // if there is no output to set does not make sense to go further - auto output = outputs.find(outputName); - if (output == outputs.end()) { - return; - } - - auto dnnLayer = components.findComponent(cnnlayerName); - if (dnnLayer && (dnnLayer->operation == kDnnInterleaveOp || dnnLayer->operation == kDnnDeinterleaveOp || - dnnLayer->num_rows_out == 1 || dnnLayer->num_columns_out == 1)) { - output->orientation = kDnnNonInterleavedOrientation; - } -} -} // namespace helpers -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/orientation_helper.hpp b/src/plugins/intel_gna/src/orientation_helper.hpp deleted file mode 100644 index f8e491c9521..00000000000 --- a/src/plugins/intel_gna/src/orientation_helper.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include - -#include "backend/dnn_components.hpp" -#include "descriptions/gna_desc.hpp" - -namespace ov { -namespace intel_gna { - -/** - * @namespace helpers contains helpers tools for gna plugin. - */ -namespace helpers { - -/** - * @brief Update expected orientation for model input of given \p inputLayer. It is needed to recognize if extra - * transposition for input data of input layer is needed. - * - * @note Function check following parameters if: - * - there is at least one dnn input layer for given cnn layer - * - corresponding dnn layers operation are not kDnnInterleaveOp and not kDnnDeinterleaveOp - * - corresponding input layer first dimenions and product of rest of dimensions is greater than 1 - * - * If any of conditions is not met kDnnNonInterleavedOrientation is set. - * If all of conditions above will be met kDnnInterleavedOrientation is set. - * - * @param inputLayer model input layer - * @param components layers transformed to form consumable by GNA - * @param inputs of model - * - * @throws if orientations of input for multiple layers are different - */ -void updateModelInputOrientationWithoutConvolution(const InferenceEngine::CNNLayer& inputLayer, - const backend::DnnComponents& components, - GnaInputs& inputs); - -/** - * @brief Update expected orientation for model output of given \p outputName. It is needed to recognize if extra - * transposition for output data of output layer is needed. - * - * @note Function checks following parameters if: - * - corresponding dnn layer operation is kDnnInterleaveOp or kDnnDeinterleaveOp - * - corresponding dnn layer is present and columns and rows numbes are bigger than 1 - * - * If any of conditions above will be not met orientation is set to kDnnNonInterleavedOrientation. - * If there is no corespnding dnn layer orientation is untouched. - * - * @param outputName name of the model output - * @param cnnLayerName name of coresponding model input layer - * @param components layers transformed to form consumable by GNA - * @param outputs outputs of model - * - */ -void updateModelOutputOrientation(const std::string& outputName, - const std::string& cnnlayerName, - const backend::DnnComponents& components, - GnaOutputs& outputs); - -} // namespace helpers -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/pre_post_process/converter_factory.cpp b/src/plugins/intel_gna/src/pre_post_process/converter_factory.cpp deleted file mode 100644 index 9a9922a1efc..00000000000 --- a/src/plugins/intel_gna/src/pre_post_process/converter_factory.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "converter_factory.hpp" - -#include - -#include -#ifdef HAVE_AVX2 -# include "hw_accelerated_converter_avx2.hpp" -#endif - -namespace ov { -namespace intel_gna { -namespace pre_post_processing { - -std::shared_ptr ConverterFactory::create_converter() { -#ifdef HAVE_AVX2 - if (InferenceEngine::with_cpu_x86_avx2()) { - return std::make_shared(); - } else { - return nullptr; - } -#else - return nullptr; -#endif // HAVE_AVX2 -} -} // namespace pre_post_processing -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/pre_post_process/converter_factory.hpp b/src/plugins/intel_gna/src/pre_post_process/converter_factory.hpp deleted file mode 100644 index bb2f91e7a3e..00000000000 --- a/src/plugins/intel_gna/src/pre_post_process/converter_factory.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "hw_accelerated_converter.hpp" - -namespace ov { -namespace intel_gna { -namespace pre_post_processing { - -class ConverterFactory { -public: - static std::shared_ptr create_converter(); -}; -} // namespace pre_post_processing -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/pre_post_process/data_conversion_helpers.cpp b/src/plugins/intel_gna/src/pre_post_process/data_conversion_helpers.cpp deleted file mode 100644 index ac3b4122487..00000000000 --- a/src/plugins/intel_gna/src/pre_post_process/data_conversion_helpers.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "data_conversion_helpers.hpp" - -namespace ov { -namespace intel_gna { -namespace pre_post_processing { - -void ConvertToInt16(int16_t* ptr_dst, - const float* ptr_src, - const size_t num_rows, - const size_t num_columns, - const float scale_factor) { - if (!ptr_dst || !ptr_src) { - return; - } - for (size_t i = 0; i < num_rows * num_columns; i++) { - ptr_dst[i] = FloatToInt(ptr_src[i] * scale_factor); - } -} - -} // namespace pre_post_processing -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/pre_post_process/data_conversion_helpers.hpp b/src/plugins/intel_gna/src/pre_post_process/data_conversion_helpers.hpp deleted file mode 100644 index 3dd6a4f33c9..00000000000 --- a/src/plugins/intel_gna/src/pre_post_process/data_conversion_helpers.hpp +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "gna_data_types.hpp" - -namespace ov { -namespace intel_gna { -namespace pre_post_processing { - -void ConvertToInt16(int16_t* ptr_dst, - const float* ptr_src, - const size_t num_rows, - const size_t num_columns, - const float scale_factor); - -template -T FloatToInt(float src) { - float rounding_value = (src > 0) ? 0.5f : -0.5f; - float value = src + rounding_value; - if (value > static_cast(std::numeric_limits::max())) { - return std::numeric_limits::max(); - } else if (value < static_cast(std::numeric_limits::min())) { - return std::numeric_limits::min(); - } - return static_cast(value); -} - -template -inline void unscale_transpose_and_cast(T* ptr_dst, - const U* ptr_src, - intel_dnn_orientation_t orientation, - size_t num_frames, - size_t num_group, - size_t num_vector_elements, - size_t num_active_elements, - size_t num_vector_stride, - const float scale_factor) { - // source scores are possibly padded to multiple of 8 and possibly interleaved - // rotate if necessary and only copy actual scores (not padding) - if (orientation == kDnnInterleavedOrientation) { - for (size_t i = 0; i < num_frames; i++) { - for (size_t j = 0; j < num_active_elements; j++) { - ptr_dst[i * num_vector_elements + j] = static_cast(ptr_src[j * num_group + i] / scale_factor); - } - for (size_t j = num_active_elements; j < num_vector_elements; j++) { - ptr_dst[i * num_vector_elements + j] = 0; - } - } - } else { - for (size_t i = 0; i < num_frames; i++) { - for (size_t j = 0; j < num_vector_elements; j++) { - ptr_dst[i * num_vector_elements + j] = - static_cast(ptr_src[i * num_vector_stride + j] / scale_factor); - } - } - } -} - -template -void copy_input_data(T* dst, - const U* src, - size_t num_frames, - size_t num_group, - size_t num_vector_elements, - size_t num_vector_stride, - intel_dnn_orientation_t orientation, - float scale_factor) { - if (!dst || !src) { - return; - } - if (orientation == kDnnInterleavedOrientation) { - for (size_t i = 0; i < num_frames; i++) { - for (size_t j = 0; j < num_vector_elements; j++) { - if (!std::is_same::value) { - dst[j * num_group + i] = FloatToInt(src[i * num_vector_elements + j] * scale_factor); - } else { - dst[j * num_group + i] = static_cast(src[i * num_vector_elements + j]); - } - } - // pad to meet weight matrix row length requirement - for (size_t j = num_vector_elements; j < num_vector_stride; j++) { - dst[j * num_group + i] = 0; - } - } - // pad partial group - for (size_t i = num_frames; i < num_group; i++) { - for (size_t j = 0; j < num_vector_stride; j++) { - dst[j * num_group + i] = 0; - } - } - } else { - if (!std::is_same::value) { - for (size_t i = 0; i < num_frames; i++) { - T* ptr_dst_vec = reinterpret_cast(dst) + i * num_vector_stride; - const U* ptr_src_vec = reinterpret_cast(src) + i * num_vector_elements; - std::memset(ptr_dst_vec, 0, num_vector_stride * sizeof(T)); - for (size_t j = 0; j < num_vector_elements; j++) { - ptr_dst_vec[j] = FloatToInt(ptr_src_vec[j] * scale_factor); - } - } - } else { - for (size_t i = 0; i < num_frames; i++) { - void* ptr_dst_vec = reinterpret_cast(dst) + i * num_vector_stride * sizeof(T); - const void* ptr_src_vec = reinterpret_cast(src) + i * num_vector_elements * sizeof(U); - std::memset(ptr_dst_vec, 0, num_vector_stride * sizeof(T)); - ie_memcpy(ptr_dst_vec, num_vector_elements * sizeof(T), ptr_src_vec, num_vector_elements * sizeof(T)); - } - } - - for (size_t i = num_frames; i < num_group; i++) { - void* ptr_dst_vec = reinterpret_cast(dst) + i * num_vector_stride * sizeof(T); - std::memset(ptr_dst_vec, 0, num_vector_stride * sizeof(T)); - } - } -} - -} // namespace pre_post_processing -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/pre_post_process/hw_accelerated_converter.hpp b/src/plugins/intel_gna/src/pre_post_process/hw_accelerated_converter.hpp deleted file mode 100644 index 77ad88c2006..00000000000 --- a/src/plugins/intel_gna/src/pre_post_process/hw_accelerated_converter.hpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -namespace ov { -namespace intel_gna { -namespace pre_post_processing { - -class HwAcceleratedDataConverter { -public: - /** - * @brief Convert 2D matrix of fp32 to int16 using hardware acceleration. Rounding and integer overflow are taken - * into account. Zero-padding is not supported. - */ - virtual void convert_matrix_fp32_to_int16_no_zero_padding(int16_t* ptr_dst, - const float* ptr_src, - const size_t num_rows, - const size_t num_columns, - const float scale_factor, - bool transpose) const = 0; - /** - * @brief Convert 2D matrix of fp32 to int8 using hardware acceleration. Rounding and integer overflow are taken - * into account. Zero-padding is not supported. - */ - virtual void convert_matrix_fp32_to_int8_no_zero_padding(int8_t* ptr_dst, - const float* ptr_src, - const size_t num_rows, - const size_t num_columns, - const float scale_factor, - bool transpose) const = 0; - /** - * @brief Convert 2D matrix of int32 to fp32 using hardware acceleration. Zero-padding is not supported. - */ - virtual void convert_matrix_int32_to_fp32_no_zero_padding(float* ptr_dst, - const int32_t* ptr_src, - size_t num_rows, - size_t num_columns, - float scale_factor, - bool transpose) const = 0; - /** - * @brief Convert 2D matrix of int16 to fp32 using hardware acceleration. Zero-padding is not supported. - */ - virtual void convert_matrix_int16_to_fp32_no_zero_padding(float* ptr_dst, - const int16_t* ptr_src, - size_t num_rows, - size_t num_columns, - float scale_factor, - bool transpose) const = 0; - /** - * @brief Convert 2D matrix of int8 to fp32 using hardware acceleration. Zero-padding is not supported. - */ - virtual void convert_matrix_int8_to_fp32_no_zero_padding(float* ptr_dst, - const int8_t* ptr_src, - size_t num_rows, - size_t num_columns, - float scale_factor, - bool transpose) const = 0; -}; -} // namespace pre_post_processing -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/pre_post_process/hw_accelerated_converter_avx2.cpp b/src/plugins/intel_gna/src/pre_post_process/hw_accelerated_converter_avx2.cpp deleted file mode 100644 index ea1a0d06aae..00000000000 --- a/src/plugins/intel_gna/src/pre_post_process/hw_accelerated_converter_avx2.cpp +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#ifdef HAVE_AVX2 - -# include "hw_accelerated_converter_avx2.hpp" - -# include - -# include - -# include "data_conversion_helpers.hpp" - -namespace ov { -namespace intel_gna { -namespace pre_post_processing { - -template -void convert_matrix_fp32_to_int_avx(T* ptr_dst, - const float* ptr_src, - const size_t num_rows, - const size_t num_columns, - const float scale_factor, - bool transpose) { - const size_t num_elements = num_rows * num_columns; - size_t moves = num_elements / 8; - size_t mod = num_elements % 8; - size_t i, j; - size_t index = 0; - - __m256 v, zero, half, neg_half, scale_factors, mask, rounding_values, min, max, values; - - zero = _mm256_setzero_ps(); - half = _mm256_set1_ps(0.5f); - neg_half = _mm256_set1_ps(-0.5f); - scale_factors = _mm256_set1_ps(scale_factor); - max = _mm256_set1_ps(static_cast(std::numeric_limits::max())); - min = _mm256_set1_ps(static_cast(std::numeric_limits::min())); - - for (i = 0; i < moves; i++) { - v = _mm256_load_ps(&ptr_src[i * 8]); - - // rounding_values = (v>0) ? 0.5f : -0.5f; - mask = _mm256_cmp_ps(v, zero, _CMP_LT_OQ); - rounding_values = _mm256_blendv_ps(half, neg_half, mask); - - // values = v * scale_factors + rounding_values - values = _mm256_fmadd_ps(v, scale_factors, rounding_values); - - // shrink to <-32768.0f, 32767.0f> - values = _mm256_min_ps(values, max); - values = _mm256_max_ps(values, min); - - // cast - if (transpose) { - for (j = 0; j < 8; j++, index++) { - size_t target_column = index / num_columns; - size_t target_row = index % num_columns; - // target number of rows == source number of columns - size_t target_index = target_row * num_rows + target_column; - ptr_dst[target_index] = static_cast(values.m256_f32[j]); - } - } else { - for (j = 0; j < 8; j++) - ptr_dst[i * 8 + j] = static_cast(values.m256_f32[j]); - } - } - - if (transpose) { - for (i = 0; i < mod; i++, index++) { - size_t target_column = index / num_columns; - size_t target_row = index % num_columns; - // target number of rows == source number of columns - size_t target_index = target_row * num_rows + target_column; - ptr_dst[target_index] = FloatToInt(ptr_src[moves * 8 + i] * scale_factor); - } - } else { - for (i = 0; i < mod; i++, index++) { - ptr_dst[moves * 8 + i] = FloatToInt(ptr_src[moves * 8 + i] * scale_factor); - } - } -} - -void HwAcceleratedDataConverterAvx::convert_matrix_fp32_to_int16_no_zero_padding(int16_t* ptr_dst, - const float* ptr_src, - const size_t num_rows, - const size_t num_columns, - const float scale_factor, - bool transpose) const { - convert_matrix_fp32_to_int_avx(ptr_dst, ptr_src, num_rows, num_columns, scale_factor, transpose); -} - -void HwAcceleratedDataConverterAvx::convert_matrix_fp32_to_int8_no_zero_padding(int8_t* ptr_dst, - const float* ptr_src, - const size_t num_rows, - const size_t num_columns, - const float scale_factor, - bool transpose) const { - convert_matrix_fp32_to_int_avx(ptr_dst, ptr_src, num_rows, num_columns, scale_factor, transpose); -} - -template -void convert_matrix_int_to_fp32_avx(float* ptr_dst, - const T* ptr_src, - size_t num_rows, - size_t num_columns, - float scale_factor, - bool transpose) { - const size_t num_elements = num_rows * num_columns; - size_t moves = num_elements / 8; - size_t mod = num_elements % 8; - size_t i, j; - size_t index = 0; - - __m256 v, scale_factors, values; - scale_factors = _mm256_set1_ps(scale_factor); - for (i = 0; i < moves; i++) { - if (std::is_same::value) { - __m256i int32_values = _mm256_cvtepi8_epi32(*reinterpret_cast(&ptr_src[i * 8])); - v = _mm256_cvtepi32_ps(int32_values); - } else if (std::is_same::value) { - __m256i int32_values = _mm256_cvtepi16_epi32(*reinterpret_cast(&ptr_src[i * 8])); - v = _mm256_cvtepi32_ps(int32_values); - } else if (std::is_same::value) { - v = _mm256_cvtepi32_ps(*reinterpret_cast(&ptr_src[i * 8])); - } else { - THROW_GNA_EXCEPTION - << "Type not supported: AVX2 matrix conversion available only for int8, int16 and int32"; - } - - // values = v * 1/scale_factors - values = _mm256_div_ps(v, scale_factors); - if (transpose) { - for (j = 0; j < 8; j++, index++) { - size_t target_column = index / num_columns; - size_t target_row = index % num_columns; - // target number of rows == source number of columns - size_t target_index = target_row * num_rows + target_column; - ptr_dst[target_index] = values.m256_f32[j]; - } - } else { - _mm256_store_ps(&ptr_dst[i * 8], values); - } - } - if (transpose) { - for (i = 0; i < mod; i++, index++) { - size_t target_column = index / num_columns; - size_t target_row = index % num_columns; - // target number of rows == source number of columns - size_t target_index = target_row * num_rows + target_column; - ptr_dst[target_index] = static_cast(ptr_src[moves * 8 + i] / scale_factor); - } - } else { - for (i = 0; i < mod; i++, index++) { - ptr_dst[moves * 8 + i] = static_cast(ptr_src[moves * 8 + i] / scale_factor); - } - } -} - -void HwAcceleratedDataConverterAvx::convert_matrix_int32_to_fp32_no_zero_padding(float* ptr_dst, - const int32_t* ptr_src, - size_t num_rows, - size_t num_columns, - float scale_factor, - bool transpose) const { - convert_matrix_int_to_fp32_avx(ptr_dst, ptr_src, num_rows, num_columns, scale_factor, transpose); -} - -void HwAcceleratedDataConverterAvx::convert_matrix_int16_to_fp32_no_zero_padding(float* ptr_dst, - const int16_t* ptr_src, - size_t num_rows, - size_t num_columns, - float scale_factor, - bool transpose) const { - convert_matrix_int_to_fp32_avx(ptr_dst, ptr_src, num_rows, num_columns, scale_factor, transpose); -} - -void HwAcceleratedDataConverterAvx::convert_matrix_int8_to_fp32_no_zero_padding(float* ptr_dst, - const int8_t* ptr_src, - size_t num_rows, - size_t num_columns, - float scale_factor, - bool transpose) const { - convert_matrix_int_to_fp32_avx(ptr_dst, ptr_src, num_rows, num_columns, scale_factor, transpose); -} -} // namespace pre_post_processing -} // namespace intel_gna -} // namespace ov - -#endif // HAVE_AVX2 diff --git a/src/plugins/intel_gna/src/pre_post_process/hw_accelerated_converter_avx2.hpp b/src/plugins/intel_gna/src/pre_post_process/hw_accelerated_converter_avx2.hpp deleted file mode 100644 index 9e0a6eda2aa..00000000000 --- a/src/plugins/intel_gna/src/pre_post_process/hw_accelerated_converter_avx2.hpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "hw_accelerated_converter.hpp" - -namespace ov { -namespace intel_gna { -namespace pre_post_processing { - -class HwAcceleratedDataConverterAvx : public HwAcceleratedDataConverter { -public: - /** - * @brief Convert 2D matrix of fp32 to int16 using AVX2 acceleration. Rounding and integer overflow are taken into - * account. Zero-padding is not supported. - */ - void convert_matrix_fp32_to_int16_no_zero_padding(int16_t* ptr_dst, - const float* ptr_src, - const size_t num_rows, - const size_t num_columns, - const float scale_factor, - bool transpose) const override; - /** - * @brief Convert 2D matrix of fp32 to int8 using AVX2 acceleration. Rounding and integer overflow are taken into - * account. Zero-padding is not supported. - */ - void convert_matrix_fp32_to_int8_no_zero_padding(int8_t* ptr_dst, - const float* ptr_src, - const size_t num_rows, - const size_t num_columns, - const float scale_factor, - bool transpose) const override; - /** - * @brief Convert 2D matrix of int32 to fp32 using AVX2 acceleration. Zero-padding is not supported. - */ - void convert_matrix_int32_to_fp32_no_zero_padding(float* ptr_dst, - const int32_t* ptr_src, - size_t num_rows, - size_t num_columns, - float scale_factor, - bool transpose) const override; - /** - * @brief Convert 2D matrix of int16 to fp32 using AVX2 acceleration. Zero-padding is not supported. - */ - void convert_matrix_int16_to_fp32_no_zero_padding(float* ptr_dst, - const int16_t* ptr_src, - size_t num_rows, - size_t num_columns, - float scale_factor, - bool transpose) const override; - /** - * @brief Convert 2D matrix of int8 to fp32 using AVX2 acceleration. Zero-padding is not supported. - */ - void convert_matrix_int8_to_fp32_no_zero_padding(float* ptr_dst, - const int8_t* ptr_src, - size_t num_rows, - size_t num_columns, - float scale_factor, - bool transpose) const override; -}; -} // namespace pre_post_processing -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/pre_post_process/input_output_data_handler.cpp b/src/plugins/intel_gna/src/pre_post_process/input_output_data_handler.cpp deleted file mode 100644 index a0c6b9386be..00000000000 --- a/src/plugins/intel_gna/src/pre_post_process/input_output_data_handler.cpp +++ /dev/null @@ -1,320 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "input_output_data_handler.hpp" - -namespace ov { -namespace intel_gna { -namespace pre_post_processing { - -using InferenceEngine::Precision; - -InputOutputDataHandler::InputOutputDataHandler(std::shared_ptr converter) - : m_hw_accelerated_converter(converter) {} - -void InputOutputDataHandler::import_frames(void* ptr_dst, - const void* ptr_src, - const InferenceEngine::Precision& input_precision, - float scale_factor, - intel_dnn_orientation_t orientation, - size_t num_frames, - size_t num_group, - size_t num_vector_elements, - size_t num_vector_stride, - bool input_low_precision, - bool is_gna_device) { - switch (input_precision) { - case Precision::U8: - case Precision::I8: { - auto src = reinterpret_cast(ptr_src); - if (!input_low_precision) { - auto dst = reinterpret_cast(ptr_dst); - copy_input_data(dst, - src, - num_frames, - num_group, - num_vector_elements, - num_vector_stride, - orientation, - scale_factor); - } else { - auto dst = reinterpret_cast(ptr_dst); - copy_input_data(dst, - src, - num_frames, - num_group, - num_vector_elements, - num_vector_stride, - orientation, - scale_factor); - } - break; - } - case Precision::I16: { - auto src = reinterpret_cast(ptr_src); - if (!input_low_precision) { - auto dst = reinterpret_cast(ptr_dst); - copy_input_data(dst, - src, - num_frames, - num_group, - num_vector_elements, - num_vector_stride, - orientation, - scale_factor); - } else { - auto dst = reinterpret_cast(ptr_dst); - copy_input_data(dst, - src, - num_frames, - num_group, - num_vector_elements, - num_vector_stride, - orientation, - scale_factor); - } - break; - } - case Precision::FP32: { - auto src = reinterpret_cast(ptr_src); - if (!is_gna_device) { - auto dst = reinterpret_cast(ptr_dst); - copy_input_data(dst, - src, - num_frames, - num_group, - num_vector_elements, - num_vector_stride, - orientation, - scale_factor); - } else { - bool transpose = (orientation == kDnnInterleavedOrientation) && (num_group > 1) && (num_vector_stride > 1); - bool needs_zero_padding = (num_vector_elements != num_vector_stride) || (num_frames != num_group); - - if (!input_low_precision) { - auto dst = reinterpret_cast(ptr_dst); - - if (m_hw_accelerated_converter && !needs_zero_padding) { - m_hw_accelerated_converter->convert_matrix_fp32_to_int16_no_zero_padding(dst, - src, - num_group, - num_vector_stride, - scale_factor, - transpose); - } else { - copy_input_data(dst, - src, - num_frames, - num_group, - num_vector_elements, - num_vector_stride, - orientation, - scale_factor); - } - } else { - auto dst = reinterpret_cast(ptr_dst); - - if (m_hw_accelerated_converter && !needs_zero_padding) { - m_hw_accelerated_converter->convert_matrix_fp32_to_int8_no_zero_padding(dst, - src, - num_group, - num_vector_stride, - scale_factor, - transpose); - } else { - copy_input_data(dst, - src, - num_frames, - num_group, - num_vector_elements, - num_vector_stride, - orientation, - scale_factor); - } - } - } - break; - } - case Precision::I32: { - auto src = reinterpret_cast(ptr_src); - if (!is_gna_device) { - auto dst = reinterpret_cast(ptr_dst); - copy_input_data(dst, - src, - num_frames, - num_group, - num_vector_elements, - num_vector_stride, - orientation, - scale_factor); - } else { - if (!input_low_precision) { - auto dst = reinterpret_cast(ptr_dst); - copy_input_data(dst, - src, - num_frames, - num_group, - num_vector_elements, - num_vector_stride, - orientation, - scale_factor); - } else { - auto dst = reinterpret_cast(ptr_dst); - copy_input_data(dst, - src, - num_frames, - num_group, - num_vector_elements, - num_vector_stride, - orientation, - scale_factor); - } - } - break; - } - default: - break; - } -} - -void InputOutputDataHandler::export_scores(void* ptr_dst, - const void* ptr_src, - intel_dnn_orientation_t orientation, - size_t num_frames, - size_t num_group, - size_t num_vector_elements, - size_t num_active_elements, - size_t num_vector_stride, - const InferenceEngine::Precision& precision_in, - const InferenceEngine::Precision& precision_out, - const float scale_factor) { - if (ptr_src == nullptr || ptr_dst == nullptr) { - THROW_GNA_EXCEPTION << "Received null pointer arguments"; - } - if (precision_out != Precision::I32 && precision_out != Precision::FP32) { - THROW_GNA_EXCEPTION << "Unsupported target precision for infer : " << precision_out.name(); - } - - bool transpose = (orientation == kDnnInterleavedOrientation) && (num_group > 1) && (num_vector_stride > 1); - // TODO: AVX2 support for zero-padding isn't implemented yet; - // fall back to the non-vectorized version when it's necessary - bool needs_zero_padding = (num_active_elements != num_vector_stride) || (num_frames != num_group); - - switch (precision_out) { - case Precision::FP32: - switch (precision_in) { - case Precision::I8: - if (m_hw_accelerated_converter && !needs_zero_padding) { - m_hw_accelerated_converter->convert_matrix_int8_to_fp32_no_zero_padding( - reinterpret_cast(ptr_dst), - reinterpret_cast(ptr_src), - num_vector_stride, - num_frames, - scale_factor, - transpose); - } else { - unscale_transpose_and_cast(reinterpret_cast(ptr_dst), - reinterpret_cast(ptr_src), - orientation, - num_frames, - num_group, - num_vector_elements, - num_active_elements, - num_vector_stride, - scale_factor); - } - break; - case Precision::I16: - if (m_hw_accelerated_converter && !needs_zero_padding) { - m_hw_accelerated_converter->convert_matrix_int16_to_fp32_no_zero_padding( - reinterpret_cast(ptr_dst), - reinterpret_cast(ptr_src), - num_vector_stride, - num_frames, - scale_factor, - transpose); - } else { - unscale_transpose_and_cast(reinterpret_cast(ptr_dst), - reinterpret_cast(ptr_src), - orientation, - num_frames, - num_group, - num_vector_elements, - num_active_elements, - num_vector_stride, - scale_factor); - } - break; - case Precision::I32: - if (m_hw_accelerated_converter && !needs_zero_padding) { - m_hw_accelerated_converter->convert_matrix_int32_to_fp32_no_zero_padding( - reinterpret_cast(ptr_dst), - reinterpret_cast(ptr_src), - num_vector_stride, - num_frames, - scale_factor, - transpose); - } else { - unscale_transpose_and_cast(reinterpret_cast(ptr_dst), - reinterpret_cast(ptr_src), - orientation, - num_frames, - num_group, - num_vector_elements, - num_active_elements, - num_vector_stride, - scale_factor); - } - break; - default: - THROW_GNA_EXCEPTION << "Unsupported data type"; - } - break; - case Precision::I32: - switch (precision_in) { - case Precision::I8: - unscale_transpose_and_cast(reinterpret_cast(ptr_dst), - reinterpret_cast(ptr_src), - orientation, - num_frames, - num_group, - num_vector_elements, - num_active_elements, - num_vector_stride, - scale_factor); - break; - case Precision::I16: - unscale_transpose_and_cast(reinterpret_cast(ptr_dst), - reinterpret_cast(ptr_src), - orientation, - num_frames, - num_group, - num_vector_elements, - num_active_elements, - num_vector_stride, - scale_factor); - break; - case Precision::I32: - unscale_transpose_and_cast(reinterpret_cast(ptr_dst), - reinterpret_cast(ptr_src), - orientation, - num_frames, - num_group, - num_vector_elements, - num_active_elements, - num_vector_stride, - scale_factor); - break; - default: - THROW_GNA_EXCEPTION << "Unsupported data type"; - } - break; - - default: - THROW_GNA_EXCEPTION << "Unsupported data type"; - } -} -} // namespace pre_post_processing -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/pre_post_process/input_output_data_handler.hpp b/src/plugins/intel_gna/src/pre_post_process/input_output_data_handler.hpp deleted file mode 100644 index da47acbd0dd..00000000000 --- a/src/plugins/intel_gna/src/pre_post_process/input_output_data_handler.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "data_conversion_helpers.hpp" -#include "hw_accelerated_converter.hpp" - -namespace ov { -namespace intel_gna { -namespace pre_post_processing { - -class InputOutputDataHandler { -public: - InputOutputDataHandler(std::shared_ptr converter = nullptr); - void import_frames(void* ptr_dst, - const void* ptr_src, - const InferenceEngine::Precision& input_precision, - float scale_factor, - intel_dnn_orientation_t orientation, - size_t num_frames, - size_t num_group, - size_t num_vector_elements, - size_t num_vector_stride, - bool input_low_precision, - bool is_gna_device); - - void export_scores(void* ptr_dst, - const void* ptr_src, - intel_dnn_orientation_t orientation, - size_t num_frames, - size_t num_group, - size_t num_vector_elements, - size_t num_active_elements, - size_t num_vector_stride, - const InferenceEngine::Precision& precision_in, - const InferenceEngine::Precision& precision_out, - const float scale_factor); - -private: - std::shared_ptr m_hw_accelerated_converter; -}; -} // namespace pre_post_processing -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/pre_post_process/transposition_info.cpp b/src/plugins/intel_gna/src/pre_post_process/transposition_info.cpp deleted file mode 100644 index 57e9a9434a0..00000000000 --- a/src/plugins/intel_gna/src/pre_post_process/transposition_info.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "transposition_info.hpp" - -#include - -#include "common/graph_utils.hpp" -#include "log/debug.hpp" -#include "openvino/core/model.hpp" -#include "openvino/core/shape.hpp" -#include "openvino/opsets/opset10.hpp" -#include "openvino/pass/manager.hpp" - -namespace ov { -namespace intel_gna { -namespace pre_post_processing { - -using namespace ov::opset10; - -std::shared_ptr ToProcessModel(const TranspositionInfo& t_info) { - int32_t c_size = static_cast(t_info.num_transpose_rows); - int32_t hw_size = static_cast(t_info.num_transpose_columns); - - if (!t_info.transpose) { - return nullptr; - } - - ov::PartialShape input_shape{1, c_size, hw_size}; - auto param = std::make_shared(ov::element::f32, input_shape); - - // legacy way was to swap C and HW dimensions in the reshaped tensor - std::vector reshape_pattern{-1, c_size, hw_size}; - auto reshape_const = - std::make_shared(ov::element::i32, ov::Shape{reshape_pattern.size()}, reshape_pattern); - auto reshape = std::make_shared(param, reshape_const, false); - - // CHW -> HWC or HWC -> CHW - std::vector transpose_order{0, 2, 1}; - auto transpose_const = - std::make_shared(ov::element::i8, ov::Shape{transpose_order.size()}, transpose_order); - auto transpose = std::make_shared(reshape, transpose_const); - - auto result = std::make_shared(transpose); - - std::shared_ptr model = - std::make_shared(ov::ResultVector{result}, ov::ParameterVector{param}); - - return model; -} - -std::shared_ptr ToProcessModel(const std::vector& transposes) { - // count transposition parts need to be transposed - auto count_transposes = std::count_if(transposes.begin(), transposes.end(), [](TranspositionInfo t_info) { - return t_info.transpose || t_info.num_transpose_rows != 1 || t_info.num_transpose_columns != 1; - }); - if (count_transposes == 0) { - return nullptr; - } - - // case when the input should be transposed entirely - if (transposes.size() == 1) { - return ToProcessModel(transposes.front()); - } - - std::vector indices = {}; - for (auto& transpose : transposes) { - size_t c_size = transpose.num_transpose_rows; - size_t hw_size = transpose.num_transpose_columns; - if (c_size == 0 || hw_size == 0) { - THROW_GNA_EXCEPTION << "Incorrect transposition dimentions"; - } - std::vector slice_indices; - std::vector transpose_order = - transpose.transpose ? std::vector{1, 0} : std::vector{0, 1}; - slice_indices = - graph_utils::make_gather_indexes_from_transpose_axes(ov::Shape{c_size, hw_size}, transpose_order); - size_t id = indices.size(); - std::for_each(slice_indices.begin(), slice_indices.end(), [&id](size_t& i) { - i += id; - }); - indices.insert(indices.end(), slice_indices.begin(), slice_indices.end()); - } - - auto param = std::make_shared(ov::element::f32, ov::Shape{1, indices.size()}); - // legacy way was to swap C and HW dimensions in the reshaped tensor - std::vector reshape_pattern{-1, static_cast(indices.size())}; - auto reshape_const = - std::make_shared(ov::element::i32, ov::Shape{reshape_pattern.size()}, reshape_pattern); - auto reshape = std::make_shared(param, reshape_const, false); - - // CHW -> HWC or HWC -> CHW - auto gather_indices = std::make_shared(ov::element::i32, ov::Shape{indices.size()}, indices); - auto gather_axis = std::make_shared(ov::element::i8, ov::Shape{1}, std::vector{1}); - auto gather = std::make_shared(reshape, gather_indices, gather_axis); - - auto result = std::make_shared(gather); - - std::shared_ptr model = - std::make_shared(ov::ResultVector{result}, ov::ParameterVector{param}); - - return model; -} - -} // namespace pre_post_processing -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/pre_post_process/transposition_info.hpp b/src/plugins/intel_gna/src/pre_post_process/transposition_info.hpp deleted file mode 100644 index 234c559ff25..00000000000 --- a/src/plugins/intel_gna/src/pre_post_process/transposition_info.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "openvino/core/model.hpp" - -namespace ov { -namespace intel_gna { -namespace pre_post_processing { - -struct TranspositionInfo { - bool transpose; - size_t num_transpose_rows; - size_t num_transpose_columns; -}; - -using TranspositionInfoMap = std::map>; - -/* - * Converts TranspositionInfo struct to ngraph function. - * This method creates ngraph function with Transpose layer. - */ -std::shared_ptr ToProcessModel(const TranspositionInfo& t_info); -/* - * Converts several TranspositionInfo structures to ngraph function. - * This method creates ngraph function with Gather layer. - */ -std::shared_ptr ToProcessModel(const std::vector& transposes); - -/* - * Converts transposition maps to ngraph model, which will be ran on CPU as pre/post-processing step. - * This conversion is needed to support the exported models version <= 2.8 (OV < 2023.0) - * @return - */ -template -void ConvertTransposeMapToModel(T1& transposes, T2& nodes) { - for (auto&& node : nodes) { - auto t_it = transposes.find(node.name); - if (t_it != transposes.end() && !t_it->second.empty()) { - node.pre_post_process_model = ToProcessModel(t_it->second); - } - } -}; - -static inline bool FoundPartToTranspose(const std::vector& transposes) { - auto part_to_transpose = - std::find_if(std::begin(transposes), std::end(transposes), [](const TranspositionInfo& t_info) { - return t_info.transpose; - }); - return part_to_transpose != std::end(transposes); -} - -} // namespace pre_post_processing -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/model_wrapper.cpp b/src/plugins/intel_gna/src/request/model_wrapper.cpp deleted file mode 100644 index 24e5fffd0f9..00000000000 --- a/src/plugins/intel_gna/src/request/model_wrapper.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "model_wrapper.hpp" - -#include "gna2_model_helper.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -ModelWrapper::ModelWrapper(ConstructionPassKey) { - object_.NumberOfOperations = 0; - object_.Operations = nullptr; -} - -ModelWrapper::~ModelWrapper() { - if (object_.NumberOfOperations > 0) { - for (uint32_t i = 0; i < object_.NumberOfOperations; i++) { - freeGna2Operation(object_.Operations[i]); - } - gnaUserFree(object_.Operations); - object_.Operations = nullptr; - } -} - -Gna2Model& ModelWrapper::object() { - return object_; -} - -const Gna2Model& ModelWrapper::object() const { - return object_; -} - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/model_wrapper.hpp b/src/plugins/intel_gna/src/request/model_wrapper.hpp deleted file mode 100644 index cf8cde4f72d..00000000000 --- a/src/plugins/intel_gna/src/request/model_wrapper.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace request { - -class ModelWrapperFactory; - -/** - * @class Wrapper to ensure that c struct of gna model will be released in case of destruction. - */ -class ModelWrapper { -public: - /** - * @class Construction restriction key to ensure that wrapper will be created only by its factory. - */ - class ConstructionPassKey { - public: - ConstructionPassKey(const ConstructionPassKey&) = default; - ~ConstructionPassKey() = default; - - private: - ConstructionPassKey() = default; - friend class ModelWrapperFactory; - }; - - /** - * Construct {ModelWrapper} object. - */ - ModelWrapper(ConstructionPassKey); - - /** - * Destroy {ModelWrapper} object. - */ - ~ModelWrapper(); - - ModelWrapper(const ModelWrapper&) = delete; - ModelWrapper(ModelWrapper&&) = delete; - ModelWrapper& operator=(const ModelWrapper&) = delete; - ModelWrapper& operator=(ModelWrapper&&) = delete; - - /** - * @brief Return reference to the wrapped model object - */ - Gna2Model& object(); - - /** - * @brief Return const reference to the wrapped model object - */ - const Gna2Model& object() const; - -private: - Gna2Model object_; -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/model_wrapper_factory.cpp b/src/plugins/intel_gna/src/request/model_wrapper_factory.cpp deleted file mode 100644 index fb957e71f36..00000000000 --- a/src/plugins/intel_gna/src/request/model_wrapper_factory.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "model_wrapper_factory.hpp" - -#include - -#include "backend/am_intel_dnn.hpp" -#include "gna2_model_helper.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -std::shared_ptr ModelWrapperFactory::createTrivial() { - return std::make_shared(ModelWrapper::ConstructionPassKey()); -} - -std::shared_ptr ModelWrapperFactory::createWithNumberOfEmptyOperations(uint32_t number_of_operations) { - auto wrapper = createTrivial(); - - if (number_of_operations == 0) { - return wrapper; - } - - auto& object = wrapper->object(); - object.Operations = - reinterpret_cast(gnaUserAllocator(number_of_operations * sizeof(Gna2Operation))); - if (object.Operations == nullptr) { - THROW_GNA_EXCEPTION << "out of memory in while allocating " << number_of_operations << " GNA layers"; - } - - object.NumberOfOperations = number_of_operations; - for (uint32_t i = 0; i < object.NumberOfOperations; i++) { - object.Operations[i].Type = Gna2OperationTypeNone; - object.Operations[i].Operands = nullptr; - object.Operations[i].NumberOfOperands = 0; - object.Operations[i].Parameters = nullptr; - object.Operations[i].NumberOfParameters = 0; - } - - return wrapper; -} - -std::shared_ptr ModelWrapperFactory::createInitialized(ModelInitializer initializer) { - auto wrapper = createTrivial(); - initializer(&wrapper->object()); - return wrapper; -} - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/model_wrapper_factory.hpp b/src/plugins/intel_gna/src/request/model_wrapper_factory.hpp deleted file mode 100644 index 5e977a351c3..00000000000 --- a/src/plugins/intel_gna/src/request/model_wrapper_factory.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "model_wrapper.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -class ModelWrapperFactory { -public: - using ModelInitializer = std::function; - - static std::shared_ptr createTrivial(); - static std::shared_ptr createWithNumberOfEmptyOperations(uint32_t number_of_operations); - static std::shared_ptr createInitialized(ModelInitializer initializer); -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/subrequest.hpp b/src/plugins/intel_gna/src/request/subrequest.hpp deleted file mode 100644 index 84f8479bfee..00000000000 --- a/src/plugins/intel_gna/src/request/subrequest.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "request_status.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -/** - * @interface Interface representing subrequest of worker. - */ -class Subrequest { -public: - /** - * @brief Callback invoked by enqueue operation. - * @return request id - */ - using EnqueueHandler = std::function; - - /** - * @brief Callback invoked by wait operation. - * @param requestID id of request to be used for wait - * @param timeoutMilliseconds timeout of wait in milliseconds - * @return Status of subrequest @see RequestStatus - * - */ - using WaitHandler = std::function; - - virtual ~Subrequest() = default; - - /** - * @brief Wait until subrequest will be finished for given timeout. - * @param timeoutMilliseconds timeout in milliseconds - * @return status of execution of subrequest @see RequestStatus - */ - virtual RequestStatus wait(int64_t timeoutMilliseconds) = 0; - - /** - * @brief Add subrequest to execution queue. - * @return true in case subrequest was properly enqueued, otherwise return false - */ - virtual bool enqueue() = 0; - - /** - * @brief Finalize subrequest and set it status to RequestStatus::kNone - */ - virtual void cleanup() = 0; - - /** - * @brief Return true if subrequest is pending, otherwise return false - */ - virtual bool isPending() const = 0; - - /** - * @brief Return true if subrequest is aborted, otherwise return false - */ - virtual bool isAborted() const = 0; - - /** - * @brief Return true if subrequest is completed, otherwise return false - */ - virtual bool isCompleted() const = 0; -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/subrequest_impl.cpp b/src/plugins/intel_gna/src/request/subrequest_impl.cpp deleted file mode 100644 index 86eb6e58ebf..00000000000 --- a/src/plugins/intel_gna/src/request/subrequest_impl.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subrequest_impl.hpp" - -#include - -#include "log/debug.hpp" -#include "log/log.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -SubrequestImpl::SubrequestImpl(EnqueueHandler enqueueHandler, WaitHandler waitHandler) - : enqueueHandler_(std::move(enqueueHandler)), - waitHandler_(std::move(waitHandler)) { - if (!enqueueHandler_ || !waitHandler_) { - THROW_GNA_EXCEPTION << "handlers cannot be nullptr"; - } -} - -RequestStatus SubrequestImpl::wait(int64_t timeoutMilliseconds) { - if (!isPending()) { - return status_; - } - - try { - status_ = waitHandler_(requestID_, timeoutMilliseconds); - } catch (const std::exception& e) { - ov::intel_gna::log::error() << "Exception when execution wait: " << e.what() << std::endl; - status_ = RequestStatus::kCompletedWithError; - } - - return status_; -} - -bool SubrequestImpl::enqueue() { - try { - requestID_ = enqueueHandler_(); - status_ = RequestStatus::kPending; - } catch (const std::exception& e) { - ov::intel_gna::log::error() << "Exception when executiong enqueue: " << e.what() << std::endl; - status_ = RequestStatus::kCompletedWithError; - } - return status_ != RequestStatus::kCompletedWithError; -} - -void SubrequestImpl::cleanup() { - static_cast(wait(0)); - status_ = RequestStatus::kNone; -} - -bool SubrequestImpl::isPending() const { - return status_ == RequestStatus::kPending; -} - -bool SubrequestImpl::isAborted() const { - return status_ == RequestStatus::kAborted; -} - -bool SubrequestImpl::isCompleted() const { - return status_ == RequestStatus::kCompleted; -} - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/subrequest_impl.hpp b/src/plugins/intel_gna/src/request/subrequest_impl.hpp deleted file mode 100644 index 1654c1229bd..00000000000 --- a/src/plugins/intel_gna/src/request/subrequest_impl.hpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "subrequest.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -/** - * @class Implementation of interface @see Subrequest. - */ -class SubrequestImpl : public Subrequest { -public: - /** - * @brief Construct {Subrequest} - * @param enqueueHandler callback to be invoked on enqueue - * @param enqueueHandler callback to be invoked on wait - */ - SubrequestImpl(EnqueueHandler enqueueHandler, WaitHandler waitHandler); - - SubrequestImpl(const SubrequestImpl&) = delete; - SubrequestImpl(SubrequestImpl&&) = delete; - SubrequestImpl& operator=(const SubrequestImpl&) = delete; - SubrequestImpl& operator=(SubrequestImpl&&) = delete; - - /** - * @brief Destroy {SubrequestImpl} object - */ - ~SubrequestImpl() override = default; - - /** - * @brief Wait until subrequest will be finished for given timeout. - * @param timeoutMilliseconds timeout in milliseconds - * @return status of execution of subrequest @see RequestStatus - */ - RequestStatus wait(int64_t timeoutMilliseconds) override; - - /** - * @brief Add subrequest to execution queue. - * @return true in case subrequest was properly enqueued, otherwise return false - */ - bool enqueue() override; - - /** - * @brief Finalize subrequest and set it status to RequestStatus::kNone - */ - void cleanup() override; - - /** - * @brief Return true if subrequest is pending, otherwise return false - */ - bool isPending() const override; - - /** - * @brief Return true if subrequest is aborted, otherwise return false - */ - bool isAborted() const override; - - /** - * @brief Return true if subrequest is completed, otherwise return false - */ - bool isCompleted() const override; - -private: - RequestStatus status_{RequestStatus::kNone}; - uint32_t requestID_{0}; - EnqueueHandler enqueueHandler_; - WaitHandler waitHandler_; -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/worker.hpp b/src/plugins/intel_gna/src/request/worker.hpp deleted file mode 100644 index daefba03e9e..00000000000 --- a/src/plugins/intel_gna/src/request/worker.hpp +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include "request_status.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -class ModelWrapper; - -/** - * @interface Interface allowing to execute request for represented model in execution environment. - */ -class Worker { -public: - /** - * @brief Destroy {Worker} object - */ - virtual ~Worker() = default; - - /** - * @brief Return pointer to gna model represented by worker - */ - virtual Gna2Model* model() = 0; - - /** - * @brief Return pointer to gna model represented by worker - */ - virtual const Gna2Model* model() const = 0; - - /** - * @brief Enqueue request to requests queue for contained model. - * @return true in case subrequest was properly enqueued, otherwise return false - */ - virtual bool enqueueRequest() = 0; - - /** - * @brief Wait untril request will be not finished for give timeout. - * @param timeoutMilliseconds timeout in milliseconds - * @return status of execution of ongoing request. @see RequestStatus - */ - virtual RequestStatus wait(int64_t timeoutMilliseconds) = 0; - - /** - * @brief Return true if worker is free and can used for enqueueing new request. - */ - virtual bool isFree() const = 0; - - /** - * @brief Return number of representing index. Can be used for identification. - */ - virtual uint32_t representingIndex() const = 0; - - /** - * @brief Set representing index. - * @param index value to set for representing index - */ - virtual void setRepresentingIndex(uint32_t index) = 0; - - /** - * @brief return reference to result object for gna model represented by worker - */ - virtual InferenceEngine::BlobMap& result() = 0; - - /** - * @brief Set result object configuration for gna model represented by worker - * @param result Refrence to object represetning result. @see InferenceEngine::BlobMap - */ - virtual void setResult(const InferenceEngine::BlobMap& result) = 0; - - /** - * @brief Set result object configuration for gna model represented by worker - * @param result Refrence to object represetning result. @see InferenceEngine::BlobMap - */ - virtual void setResult(InferenceEngine::BlobMap&& result) = 0; -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/worker_factory.cpp b/src/plugins/intel_gna/src/request/worker_factory.cpp deleted file mode 100644 index 0f5849fae84..00000000000 --- a/src/plugins/intel_gna/src/request/worker_factory.cpp +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "worker_factory.hpp" - -#include "backend/am_intel_dnn.hpp" -#include "gna_device_interface.hpp" -#include "log/debug.hpp" -#include "request/model_wrapper.hpp" -#include "runtime/gna_float_runtime.hpp" -#include "subrequest_impl.hpp" -#include "worker_impl.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -constexpr const uint32_t WorkerFactory::kFakeRequestID; - -std::shared_ptr WorkerFactory::createWorker(std::shared_ptr model, - std::shared_ptr device, - const Gna2AccelerationMode accelerationMode) { - return std::make_shared(model, createModelSubrequests(model, std::move(device), accelerationMode)); -} - -std::shared_ptr WorkerFactory::createWorkerFP32(std::shared_ptr model, - std::shared_ptr dnn) { - return std::make_shared(model, createModelSubrequestsFP32(std::move(dnn))); -} - -std::shared_ptr WorkerFactory::createWorkerTrivialTopology(std::shared_ptr model) { - return std::make_shared(std::move(model), createModelSubrequestsTrivial()); -} - -std::vector> WorkerFactory::createModelSubrequests( - std::shared_ptr model, - std::shared_ptr device, - const Gna2AccelerationMode accelerationMode) { - if (!model) { - THROW_GNA_EXCEPTION << "model is nullptr"; - } - - if (!device) { - THROW_GNA_EXCEPTION << "device is nullptr"; - } - - std::vector> subrequests; - - uint16_t layersLimit = device->maxLayersCount(); - - if (layersLimit == 0) { - THROW_GNA_EXCEPTION << "received max layer count equal 0 from device"; - } - - auto submodelsNumber = model->object().NumberOfOperations / layersLimit; - submodelsNumber += (model->object().NumberOfOperations % layersLimit) ? 1 : 0; - auto totalOperationsNumber = model->object().NumberOfOperations; - - std::weak_ptr weakDevice = device; - - auto wait = [weakDevice](uint32_t requestID, int64_t timeoutMilliseconds) -> RequestStatus { - if (auto device = weakDevice.lock()) { - return device->waitForRequest(requestID, timeoutMilliseconds); - } - THROW_GNA_EXCEPTION << "device is nullptr"; - }; - - for (uint32_t i = 0; i < submodelsNumber; ++i) { - // this models are needed only temporarily to create configurations - Gna2Model tempModel; - tempModel.NumberOfOperations = - (i + 1 < submodelsNumber ? layersLimit : totalOperationsNumber - i * layersLimit); - tempModel.Operations = &model->object().Operations[i * layersLimit]; - const auto modelID = device->createModel(tempModel); - const auto requestConfigID = device->createRequestConfig(modelID); - - auto enqueue = [weakDevice, requestConfigID, accelerationMode]() -> uint32_t { - if (auto device = weakDevice.lock()) { - return device->enqueueRequest(requestConfigID, accelerationMode); - } - THROW_GNA_EXCEPTION << "device is nullptr"; - }; - - auto subrequest = std::make_shared(std::move(enqueue), wait); - subrequests.push_back(std::move(subrequest)); - } - return subrequests; -} - -std::vector> WorkerFactory::createModelSubrequestsFP32( - std::shared_ptr dnn) { - if (!dnn) { - THROW_GNA_EXCEPTION << "dnn is nullptr"; - } - - std::vector> subrequests; - - std::weak_ptr weak_dnn = dnn; - - auto enqueFP32 = [weak_dnn]() -> uint32_t { - if (auto dnn = weak_dnn.lock()) { - auto runtime = runtime::FP(dnn); - runtime.infer(); - return kFakeRequestID; - } - // maybe warning would be enough - THROW_GNA_EXCEPTION << "dnn is nullptr"; - }; - - auto waitSimple = [](uint32_t, int64_t) { - return RequestStatus::kCompleted; - }; - - auto subrequest = std::make_shared(std::move(enqueFP32), std::move(waitSimple)); - subrequests.push_back(std::move(subrequest)); - return subrequests; -} - -std::vector> WorkerFactory::createModelSubrequestsTrivial() { - std::vector> subrequests; - - auto enqueSimple = []() { - return kFakeRequestID; - }; - - auto waitSimple = [](uint32_t, int64_t) { - return RequestStatus::kCompleted; - }; - auto subrequest = std::make_shared(std::move(enqueSimple), std::move(waitSimple)); - subrequests.push_back(std::move(subrequest)); - return subrequests; -} - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/worker_factory.hpp b/src/plugins/intel_gna/src/request/worker_factory.hpp deleted file mode 100644 index 95b32a59b54..00000000000 --- a/src/plugins/intel_gna/src/request/worker_factory.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include "worker.hpp" - -namespace ov { -namespace intel_gna { - -class GNADevice; - -namespace backend { -class AMIntelDNN; -} - -namespace request { - -class ModelWrapper; -class Subrequest; - -class WorkerFactory { -public: - WorkerFactory() = delete; - - static std::shared_ptr createWorker(std::shared_ptr model, - std::shared_ptr device, - const Gna2AccelerationMode accelerationMode); - static std::shared_ptr createWorkerFP32(std::shared_ptr model, - std::shared_ptr dnn); - static std::shared_ptr createWorkerTrivialTopology(std::shared_ptr model); - - static std::vector> createModelSubrequests(std::shared_ptr model, - std::shared_ptr device, - const Gna2AccelerationMode accelerationMode); - static std::vector> createModelSubrequestsFP32( - std::shared_ptr dnn); - static std::vector> createModelSubrequestsTrivial(); - -private: - static constexpr const uint32_t kFakeRequestID{1}; -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/worker_impl.cpp b/src/plugins/intel_gna/src/request/worker_impl.cpp deleted file mode 100644 index 04b54798d51..00000000000 --- a/src/plugins/intel_gna/src/request/worker_impl.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "worker_impl.hpp" - -#include - -#include "log/debug.hpp" -#include "log/log.hpp" -#include "model_wrapper.hpp" -#include "subrequest.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -WorkerImpl::WorkerImpl(std::shared_ptr model, std::vector> modelSubrequests) - : fullModel_(std::move(model)), - modelSubrequests_(std::move(modelSubrequests)) { - if (!fullModel_) { - THROW_GNA_EXCEPTION << "cannot created request worker for nullptr model"; - } - - if (modelSubrequests_.empty()) { - THROW_GNA_EXCEPTION << "cannot created request worker for empty subrequest list"; - } - - for (const auto& sunrequest : modelSubrequests_) { - if (!sunrequest) { - THROW_GNA_EXCEPTION << "subrequsts cannot be nullptr"; - } - } -} - -const Gna2Model* WorkerImpl::model() const { - return &fullModel_->object(); -} - -Gna2Model* WorkerImpl::model() { - return &fullModel_->object(); -} - -bool WorkerImpl::enqueueRequest() { - if (!isFree()) { - ov::intel_gna::log::warning() << "Trying to propagate on busy request with id: " << representingIndex_; - return false; - } - - for (auto& subrequest : modelSubrequests_) { - if (!subrequest->enqueue()) { - cleanup_subrequests(); - return false; - } - } - return true; -} - -RequestStatus WorkerImpl::wait(int64_t timeoutMilliseconds) { - bool pending = false; - - // iterate over all configurations for requst - for (auto& subrequest : modelSubrequests_) { - if (!subrequest->isPending()) { - continue; - } - - auto result = subrequest->wait(timeoutMilliseconds); - - if (result == RequestStatus::kPending) { - pending = true; - } else if (result == RequestStatus::kCompletedWithError) { - cleanup_subrequests(); - return result; - } - } - - // return kPending if at least one subrequest is pending - if (pending) { - return RequestStatus::kPending; - } - - // return kAborted if at least one subrequest was aborter - for (const auto& subrequest : modelSubrequests_) { - if (subrequest->isAborted()) { - return RequestStatus::kAborted; - } - } - - // return kCompleted if all subrequsts are finish and none of them was aborted - return RequestStatus::kCompleted; -} - -bool WorkerImpl::isFree() const { - for (const auto& subrequest : modelSubrequests_) { - if (subrequest->isPending()) { - return false; - } - } - - return true; -} - -uint32_t WorkerImpl::representingIndex() const { - return representingIndex_; -} - -void WorkerImpl::setRepresentingIndex(uint32_t index) { - representingIndex_ = index; -} - -void WorkerImpl::setResult(const InferenceEngine::BlobMap& result) { - requestResult_ = result; -} - -void WorkerImpl::setResult(InferenceEngine::BlobMap&& result) { - requestResult_ = std::move(result); -} - -InferenceEngine::BlobMap& WorkerImpl::result() { - return requestResult_; -} - -void WorkerImpl::cleanup_subrequests() { - for (auto& subrequest : modelSubrequests_) { - if (subrequest->isPending()) { - subrequest->cleanup(); - } - } -} - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/worker_impl.hpp b/src/plugins/intel_gna/src/request/worker_impl.hpp deleted file mode 100644 index d2e488cc0d1..00000000000 --- a/src/plugins/intel_gna/src/request/worker_impl.hpp +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -#include "worker.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -class ModelWrapper; -class Subrequest; - -/** - * @class Implementation of @see Worker interface. - */ -class WorkerImpl : public Worker { -public: - /** - * @brief Contrcut {WorkerImpl} object - * @param model potiner to represented model - * @param modelSubrequests subrequests to enqueued for given model - * @throw Exception when model is nullptr,modelSubrequests is empty or any element in modelSubrequests is nullptr - */ - explicit WorkerImpl(std::shared_ptr model, std::vector> modelSubrequests); - - WorkerImpl(const WorkerImpl&) = delete; - WorkerImpl(WorkerImpl&&) = delete; - WorkerImpl& operator=(const WorkerImpl&) = delete; - WorkerImpl& operator=(WorkerImpl&&) = delete; - - /** - * @brief Destroy {WorkerImpl} object - */ - ~WorkerImpl() override = default; - - /** - * @see Worker::model() - */ - const Gna2Model* model() const override; - - /** - * @see Worker::model() - */ - Gna2Model* model() override; - - /** - * @see Worker::enqueueRequest() - */ - bool enqueueRequest() override; - - /** - * @see Worker::wait() - */ - RequestStatus wait(int64_t timeoutMilliseconds) override; - - /** - * @see Worker::isFree() - */ - bool isFree() const override; - - /** - * @see Worker::representingIndex() - */ - uint32_t representingIndex() const override; - - /** - * @see Worker::setRepresentingIndex() - */ - void setRepresentingIndex(uint32_t index) override; - - /** - * @see Worker::result() - */ - InferenceEngine::BlobMap& result() override; - - /** - * @see Worker::setResult() - */ - void setResult(const InferenceEngine::BlobMap& result) override; - - /** - * @see Worker::setResult() - */ - void setResult(InferenceEngine::BlobMap&& result) override; - -private: - void cleanup_subrequests(); - - uint32_t representingIndex_{0}; - std::shared_ptr fullModel_; - std::vector> modelSubrequests_; - InferenceEngine::BlobMap requestResult_; -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/worker_pool.hpp b/src/plugins/intel_gna/src/request/worker_pool.hpp deleted file mode 100644 index 7e6b49dc6b4..00000000000 --- a/src/plugins/intel_gna/src/request/worker_pool.hpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "worker.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -/** - * @interface Interface of pool of workers. Interface allows to add and retrieve the workers. - */ -class WorkerPool { -public: - /** - * Destruct {WorkerPool} object - */ - virtual ~WorkerPool() = default; - - /** - * @brief Add worker to the pool. If more than one worker is added more than request can be queued at the same time. - * @worker pointer to worker to tbe added to the pool. - */ - virtual void addModelWorker(std::shared_ptr worker) = 0; - - /** - * @brief Return number of workers in the pool. - */ - virtual size_t size() const = 0; - - /** - * @brief Return true if there is no workers in the pool, otherwise return false - */ - virtual size_t empty() const = 0; - - /** - * @brief Return worker for given index. - * @param index of worker to be returned - * @return reference to the worker for index. - * @throw exception in case index is invalid - */ - virtual Worker& worker(uint32_t index) = 0; - - /** - * @brief Return worker for given index. - * @param index of worker to be returned - * @return reference to the worker for index. - * @throw exception in case index is invalid - */ - virtual const Worker& worker(uint32_t index) const = 0; - - /** - * @brief Return worker which was added to the pool as the first one - * @throw exception in case no worker in pool - */ - virtual Worker& firstWorker() = 0; - - /** - * @brief Return worker which was added to the pool as the first one - * @throw exception in case no worker in pool - */ - virtual const Worker& firstWorker() const = 0; - - /** - * @brief Return worker which was added to the pool as the last one - * @throw exception in case no worker in pool - */ - virtual Worker& lastWorker() = 0; - - /** - * @brief Return worker which was added to the pool the last one - * @throw exception in case no worker in pool - */ - virtual const Worker& lastWorker() const = 0; - - /** - * @brief Return worker which is not busy. - * @return pointer to free worker, nullptr in case no free worker was found. - */ - virtual std::shared_ptr findFreeModelWorker() = 0; -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/worker_pool_impl.cpp b/src/plugins/intel_gna/src/request/worker_pool_impl.cpp deleted file mode 100644 index b4ed22c00eb..00000000000 --- a/src/plugins/intel_gna/src/request/worker_pool_impl.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "worker_pool_impl.hpp" - -#include "log/debug.hpp" -#include "worker.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -void WorkerPoolImpl::addModelWorker(std::shared_ptr worker) { - if (!worker) { - THROW_GNA_EXCEPTION << "cannot not add nullptr request worker to the pool"; - } - worker->setRepresentingIndex(static_cast(modelWorkers_.size())); - modelWorkers_.push_back(std::move(worker)); -} - -size_t WorkerPoolImpl::size() const { - return modelWorkers_.size(); -} - -size_t WorkerPoolImpl::empty() const { - return modelWorkers_.empty(); -} - -Worker& WorkerPoolImpl::worker(uint32_t requestIndex) { - return *modelWorkers_.at(requestIndex); -} - -const Worker& WorkerPoolImpl::worker(uint32_t requestIndex) const { - checkWorkerIndexValid(requestIndex); - return *modelWorkers_.at(requestIndex); -} - -Worker& WorkerPoolImpl::firstWorker() { - checkWorkerNotEmpty(); - return *modelWorkers_.front(); -} - -const Worker& WorkerPoolImpl::firstWorker() const { - checkWorkerNotEmpty(); - return *modelWorkers_.front(); -} - -Worker& WorkerPoolImpl::lastWorker() { - checkWorkerNotEmpty(); - return *modelWorkers_.back(); -} - -const Worker& WorkerPoolImpl::lastWorker() const { - checkWorkerNotEmpty(); - return *modelWorkers_.back(); -} - -std::shared_ptr WorkerPoolImpl::findFreeModelWorker() { - auto freeWorker = std::find_if(modelWorkers_.begin(), modelWorkers_.end(), [](const std::shared_ptr& item) { - if (item) { - return item->isFree(); - } - return false; - }); - if (freeWorker != modelWorkers_.end()) { - return *freeWorker; - } - return nullptr; -} - -void WorkerPoolImpl::checkWorkerIndexValid(uint32_t requestIndex) const { - if (requestIndex >= modelWorkers_.size()) { - THROW_GNA_EXCEPTION << " no request worker with index: " << requestIndex; - } -} - -void WorkerPoolImpl::checkWorkerNotEmpty() const { - if (modelWorkers_.empty()) { - THROW_GNA_EXCEPTION << " no request worker created."; - } -} - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request/worker_pool_impl.hpp b/src/plugins/intel_gna/src/request/worker_pool_impl.hpp deleted file mode 100644 index 5b80d44e38b..00000000000 --- a/src/plugins/intel_gna/src/request/worker_pool_impl.hpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "worker.hpp" -#include "worker_pool.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -/** - * @class Implementation of @see WorkerPool interface. - */ -class WorkerPoolImpl : public WorkerPool { -public: - /** - * @brief Destroy {WorkerPoolImpl} object - */ - ~WorkerPoolImpl() override = default; - - /** - * @see WorkerPool::addModelWorker() - */ - void addModelWorker(std::shared_ptr worker) override; - - /** - * @see WorkerPool::size() - */ - size_t size() const override; - - /** - * @see WorkerPool::empty() - */ - size_t empty() const override; - - /** - * @see WorkerPool::worker() - */ - Worker& worker(uint32_t requestIndex) override; - - /** - * @see WorkerPool::worker() - */ - const Worker& worker(uint32_t requestIndex) const override; - - /** - * @see WorkerPool::firstWorker() - */ - Worker& firstWorker() override; - - /** - * @see WorkerPool::firstWorker() - */ - const Worker& firstWorker() const override; - - /** - * @see WorkerPool::lastWorker() - */ - Worker& lastWorker() override; - - /** - * @see WorkerPool::lastWorker() - */ - const Worker& lastWorker() const override; - - /** - * @see WorkerPool::findFreeModelWorker() - */ - std::shared_ptr findFreeModelWorker() override; - -private: - void checkWorkerIndexValid(uint32_t requestIndex) const; - void checkWorkerNotEmpty() const; - - std::vector> modelWorkers_; -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/request_status.hpp b/src/plugins/intel_gna/src/request_status.hpp deleted file mode 100644 index 56a82dcda33..00000000000 --- a/src/plugins/intel_gna/src/request_status.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -namespace ov { -namespace intel_gna { - -/** - * @brief Enum representing status of request - */ -enum class RequestStatus { - kNone = 0, /// request was not initialized - kAborted = 1, /// request was aborted - kPending = 2, /// request was started and is onging - kCompleted = 3, /// request was completed with success - kCompletedWithError = 4 /// request was completed with error -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/runtime/cnn.cpp b/src/plugins/intel_gna/src/runtime/cnn.cpp deleted file mode 100644 index 307a70faaf3..00000000000 --- a/src/plugins/intel_gna/src/runtime/cnn.cpp +++ /dev/null @@ -1,336 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "cnn.h" - -#include -#include -#include -#include - -#include "backend/dnn_types.hpp" -#include "backend/gna_limitations.hpp" -#include "frontend/quantization.hpp" -#include "gna_lib_ver_selector.hpp" -#include "layers/gna_convolution_layer.hpp" -#include "log/debug.hpp" - -using namespace ov::intel_gna::gna_convolution_layer; -using namespace ov::intel_gna::limitations; - -void CNNFilter32(intel_dnn_component_t* component) { - auto filters = reinterpret_cast(component->op.conv1D.ptr_filters); - auto biases = reinterpret_cast(component->op.conv1D.ptr_biases); - auto input = reinterpret_cast(component->ptr_inputs); - auto output = reinterpret_cast(component->ptr_outputs); - - const auto convolutionStride = component->op.conv1D.convStride; - const auto filterSize = component->op.conv1D.num_filter_coefficients; - const auto numberOfInputs = component->num_columns_in; - const auto numberOfOutputsPerFilter = outputFromConv(numberOfInputs, filterSize, convolutionStride); - const auto numberOfFilters = component->op.conv1D.num_filters; - - std::string layer_name; - layer_name = " In layer '" + std::string(component->original_layer_name) + "'"; - if (component->num_rows_in != 1 || component->num_rows_out != 1) { - THROW_GNA_EXCEPTION << "Bad number of rows in CNNFilter32!" << layer_name; - } - if (component->num_columns_out < numberOfOutputsPerFilter * numberOfFilters) { - THROW_GNA_EXCEPTION << "Bad num_columns_out in CNNFilter32!" << layer_name; - } - - for (uint32_t j = 0; j < numberOfOutputsPerFilter; j++, input += convolutionStride, output += numberOfFilters) { - auto filter = filters; - for (uint32_t i = 0; i < numberOfFilters; i++, filter += filterSize) { - output[i] = biases[i]; - for (uint32_t k = 0; k < filterSize; k++) { - output[i] += input[k] * filter[k]; - } - } - } -} - -namespace { - -void CNNMaxPoolLegacy(intel_dnn_component_t* component, - intel_dnn_number_type_t number_type, - const bool sumPoolingOverRide) { - const uint32_t num_inputs = - component->op.maxpool.inCHW[0] * component->op.maxpool.inCHW[1] * component->op.maxpool.inCHW[2]; - const uint32_t in_c = component->op.maxpool.inCHW[0]; - const uint32_t num_pool_size = component->op.maxpool.poolingWindowXY[0]; - const uint32_t num_pool_step = component->op.maxpool.poolingStrideXY[0]; - const uint32_t num_rows_in = num_inputs / in_c; - - if (number_type == kDnnInt) { - int32_t* ptr_inputs = reinterpret_cast(component->ptr_inputs); - int32_t* ptr_outputs = reinterpret_cast(component->ptr_outputs); - - for (uint32_t i = 0; i < in_c; i++) { - int32_t m = 0; - if (sumPoolingOverRide) { - uint32_t num_saturate = 0; - for (uint32_t j = 0; j < num_rows_in; j += num_pool_step) { - int64_t sum = 0; - uint32_t num_end = (j + num_pool_size > num_rows_in) ? num_rows_in : j + num_pool_size; - for (uint32_t k = j; k < num_end; k++) { - sum += ptr_inputs[k * in_c + i]; - } - - ptr_outputs[m * in_c + i] = - ov::intel_gna::frontend::SaturationCast(static_cast(sum), &num_saturate); - m++; - } - if (num_saturate > 0) { - fprintf(stderr, "Warning: %d saturations in CNNMaxPool()\n", num_saturate); - } - } else { - for (uint32_t j = 0; j < num_rows_in; j += num_pool_step) { - int32_t max = INT32_MIN; - uint32_t num_end = (j + num_pool_size > num_rows_in) ? num_rows_in : j + num_pool_size; - for (uint32_t k = j; k < num_end; k++) { - if (ptr_inputs[k * in_c + i] > max) - max = ptr_inputs[k * in_c + i]; - } - ptr_outputs[m * in_c + i] = max; - m++; - } - } - } - } else { - float* ptr_inputs = reinterpret_cast(component->ptr_inputs); - float* ptr_outputs = reinterpret_cast(component->ptr_outputs); - - for (uint32_t i = 0; i < in_c; i++) { - int32_t m = 0; - if (sumPoolingOverRide) { - for (uint32_t j = 0; j < num_rows_in; j += num_pool_step) { - float sum = 0.0; - uint32_t num_end = (j + num_pool_size > num_rows_in) ? num_rows_in : j + num_pool_size; - for (uint32_t k = j; k < num_end; k++) { - sum += ptr_inputs[k * in_c + i]; - } - ptr_outputs[m * in_c + i] = sum; - m++; - } - } else { - for (uint32_t j = 0; j < num_rows_in; j += num_pool_step) { - float max = std::numeric_limits::lowest(); - uint32_t num_end = (j + num_pool_size > num_rows_in) ? num_rows_in : j + num_pool_size; - for (uint32_t k = j; k < num_end; k++) { - if (ptr_inputs[k * in_c + i] > max) - max = ptr_inputs[k * in_c + i]; - } - ptr_outputs[m * in_c + i] = max; - m++; - } - } - } - } -} - -// a1: fastest changing index -// A - size neede -template -T getQubeIndex(T a1, T a2, T a3, T A2, T A3) { - return a1 * A2 * A3 + a2 * A3 + a3; -} - -float MaxPool2D32SingleHWC(const unsigned poolWinH, - const unsigned poolWinW, - const float* input, - const unsigned IH, - const unsigned IW, - const unsigned IC, - const unsigned oh, - const unsigned ow, - const unsigned oc, - const uint32_t poolStrideH, - const uint32_t poolStrideW) { - float output = std::numeric_limits::lowest(); - const auto winStartH = oh * poolStrideH; - const auto winStartW = ow * poolStrideW; - for (unsigned winIdxH = 0; winIdxH < poolWinH && winStartH + winIdxH < IH; winIdxH++) { - for (unsigned winIdxW = 0; winIdxW < poolWinW && winStartW + winIdxW < IW; winIdxW++) { - const auto inputIndex = getQubeIndex(winStartH + winIdxH, winStartW + winIdxW, oc, IW, IC); - output = (std::max)(output, input[inputIndex]); - } - } - return output; -} - -void CNNMaxPool2DFloat(intel_dnn_component_t* component) { - float* ptr_inputs = reinterpret_cast(component->ptr_inputs); - float* ptr_outputs = reinterpret_cast(component->ptr_outputs); - const auto OC = component->op.maxpool.outCHW[0]; - const auto OH = component->op.maxpool.outCHW[1]; - const auto OW = component->op.maxpool.outCHW[2]; - - const auto IC = component->op.maxpool.inCHW[0]; - const auto IH = component->op.maxpool.inCHW[1]; - const auto IW = component->op.maxpool.inCHW[2]; - - const auto poolWinW = component->op.maxpool.poolingWindowXY[0]; - const auto poolWinH = component->op.maxpool.poolingWindowXY[1]; - const auto poolStrideW = component->op.maxpool.poolingStrideXY[0]; - const auto poolStrideH = component->op.maxpool.poolingStrideXY[1]; - - for (unsigned oc = 0; oc < OC; oc++) { - for (unsigned ow = 0; ow < OW; ow++) { - for (unsigned oh = 0; oh < OH; oh++) { - const auto outputIndex = getQubeIndex(oh, ow, oc, OW, OC); - ptr_outputs[outputIndex] = MaxPool2D32SingleHWC(poolWinH, - poolWinW, - ptr_inputs, - IH, - IW, - IC, - oh, - ow, - oc, - poolStrideH, - poolStrideW); - } - } - } -} - -} // namespace - -namespace { - -bool matchesPaddedArea(unsigned filterIndex, - unsigned outputIndex, - unsigned inputSize, - unsigned paddingSize, - unsigned stride) { - const auto paddedIndex = stride * outputIndex + filterIndex; - if (paddedIndex >= inputSize + 2 * paddingSize) { - THROW_GNA_EXCEPTION << "In: isZeroPaddingCase, paddedIndex >= inputSize + 2 * paddingSize"; - } - if (paddedIndex < paddingSize || paddedIndex >= inputSize + paddingSize) { - return true; - } - return false; -} - -float CNN2DFilter32SingleHWC(const float bias, - const float* filter, - const unsigned KH, - const unsigned KW, - const unsigned KC, - const float* image, - const unsigned IH, - const unsigned IW, - const unsigned IC, - const unsigned oh, - const unsigned ow, - const unsigned oc, - const std::array& convStride, - const std::array& zeroPadding) { - const auto cSH = convStride[0]; - const auto cSW = convStride[1]; - - const auto zPH = zeroPadding[0]; - const auto zPW = zeroPadding[1]; - float output = 0; - for (unsigned kh = 0; kh < KH; kh++) { - for (unsigned kw = 0; kw < KW; kw++) { - for (unsigned kc = 0; kc < KC; kc++) { - if (!matchesPaddedArea(kh, oh, IH, zPH, cSH) && !matchesPaddedArea(kw, ow, IW, zPW, cSW)) { - const auto ih = (cSH * oh + kh) - zPH; - const auto iw = (cSW * ow + kw) - zPW; - const auto ic = kc; - const auto imageIndex = getQubeIndex(ih, iw, ic, IW, IC); - const auto imageElement = image[imageIndex]; - const auto filterIndex = getQubeIndex(kh, kw, kc, KW, KC); - const auto filterElement = filter[filterIndex]; - const auto product = imageElement * filterElement; - output += product; - } - } - } - } - output += bias; - return output; -} - -} // namespace - -void CNN2DFilter32(intel_dnn_component_t* component) { - float* ptr_filters = reinterpret_cast(component->op.conv2D.ptr_filters); - float* ptr_biases = reinterpret_cast(component->op.conv2D.ptr_biases); - float* ptr_inputs = reinterpret_cast(component->ptr_inputs); - float* ptr_outputs = reinterpret_cast(component->ptr_outputs); - - std::string layer_name; - layer_name = " In layer '" + std::string(component->original_layer_name) + "'"; - - const auto IH = component->tensors[0].dimensions[1]; // NHWC - const auto IW = component->tensors[0].dimensions[2]; // NHWC - const auto IC = component->tensors[0].dimensions[3]; // NHWC - - const auto OH = component->tensors[1].dimensions[1]; // NHWC - const auto OW = component->tensors[1].dimensions[2]; // NHWC - const auto OC = component->tensors[1].dimensions[3]; // NHWC - - const auto kn = component->tensors[2].dimensions[0]; // NHWC - const auto kh = component->tensors[2].dimensions[1]; // NHWC - const auto kw = component->tensors[2].dimensions[2]; // NHWC - const auto kc = component->tensors[2].dimensions[3]; // NHWC - - if (kn != OC) { - THROW_GNA_EXCEPTION << "Number of filters should be equal to output depth!" << layer_name; - } - if (kc != IC) { - THROW_GNA_EXCEPTION << "Depth of filter should be equal to input depth!" << layer_name; - } - auto kernelIndex = 0; - for (unsigned oc = 0; oc < OC; oc++) { - for (unsigned ow = 0; ow < OW; ow++) { - for (unsigned oh = 0; oh < OH; oh++) { - const auto outputIndex = getQubeIndex(oh, ow, oc, OW, OC); - ptr_outputs[outputIndex] = CNN2DFilter32SingleHWC(*(ptr_biases + oc), - ptr_filters + kernelIndex, - kh, - kw, - kc, - ptr_inputs, - IH, - IW, - IC, - oh, - ow, - oc, - component->op.conv2D.convStride, - component->op.conv2D.zeroPadding); - } - } - // kernel padded to 16B = 4 * sizeof(float) - kernelIndex += ALIGN(kh * kw * kc, Limitations::kConvEachKernelByteAlignment / sizeof(float)); - } -} - -namespace { -template -bool is2D(T&& vec) { - return vec.size() >= 2 && vec[0] > 1 && vec[1] > 1; -} -} // namespace - -void CNNMaxPool(intel_dnn_component_t* component, - intel_dnn_number_type_t number_type, - const bool fused_with_convolution_2d, - const bool sumPoolingOverRide) { - if (fused_with_convolution_2d || is2D(component->op.maxpool.poolingStrideXY) || - is2D(component->op.maxpool.poolingWindowXY)) { - if (!sumPoolingOverRide) { - CNNMaxPool2DFloat(component); - } else { - THROW_GNA_EXCEPTION << "SUM pooling2D not supported"; - } - } else { - CNNMaxPoolLegacy(component, number_type, sumPoolingOverRide); - } -} diff --git a/src/plugins/intel_gna/src/runtime/cnn.h b/src/plugins/intel_gna/src/runtime/cnn.h deleted file mode 100644 index fd08180af70..00000000000 --- a/src/plugins/intel_gna/src/runtime/cnn.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "backend/dnn_types.hpp" - -#define CNN_MAX_POOL_SIZE 6 - -void CNNFilter32(intel_dnn_component_t* component); -void CNNMaxPool(intel_dnn_component_t* component, - intel_dnn_number_type_t number_type, - const bool fused_with_convolution_2d, - const bool sumPoolingOverRide = false); - -void CNN2DFilter32(intel_dnn_component_t* component); diff --git a/src/plugins/intel_gna/src/runtime/floatmath.cpp b/src/plugins/intel_gna/src/runtime/floatmath.cpp deleted file mode 100644 index 3bf2fd901fd..00000000000 --- a/src/plugins/intel_gna/src/runtime/floatmath.cpp +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -// floatmath.cpp : unoptimized floating point math routines (for reference) -// - -#include "floatmath.h" - -#include -#include - -#ifdef _NO_MKL_ -void cblas_sgemm1(const CBLAS_LAYOUT Layout, - const CBLAS_TRANSPOSE TransA, - const CBLAS_TRANSPOSE TransB, - const MKL_INT M, - const MKL_INT N, - const MKL_INT K, - const float alpha, - const float* A, - const MKL_INT lda, - const float* B, - const MKL_INT ldb, - const float beta, - float* C, - const MKL_INT ldc) { - int i, j, k; - - if (Layout != CblasRowMajor) { - fprintf(stderr, "Only row major is supported in cblas_sgemm!\n"); - throw - 1; - } - - if ((TransA == CblasNoTrans) && (TransB == CblasNoTrans)) { - for (i = 0; i < M; i++) { - for (j = 0; j < N; j++) { - float sum = (beta == 1.0) ? C[i * ldc + j] : 0; - for (k = 0; k < K; k++) { - sum += A[i * lda + k] * B[k * ldb + j]; - } - C[i * ldc + j] = sum; - } - } - } else if ((TransA == CblasNoTrans) && (TransB == CblasTrans)) { - for (i = 0; i < M; i++) { - for (j = 0; j < N; j++) { - float sum; - sum = beta * C[i * ldc + j]; - for (k = 0; k < K; k++) { - sum += alpha * A[i * lda + k] * B[j * ldb + k]; - } - C[i * ldc + j] = sum; - } - } - } else if ((TransA == CblasTrans) && (TransB == CblasNoTrans)) { - for (i = 0; i < M; i++) { - for (j = 0; j < N; j++) { - float sum = (beta == 1.0) ? C[i * ldc + j] : 0; - for (k = 0; k < K; k++) { - sum += A[k * lda + i] * B[k * ldb + j]; - } - C[i * ldc + j] = sum; - } - } - } else { - fprintf(stderr, "Expected A not transposed in cblas_sgemm!\n"); - throw - 1; - } -} -void cblas_ssbmv1(const CBLAS_LAYOUT Layout, - const CBLAS_UPLO Uplo, - const MKL_INT N, - const MKL_INT K, - const float alpha, - const float* A, - const MKL_INT lda, - const float* X, - const MKL_INT incX, - const float beta, - float* Y, - const MKL_INT incY) { - int i; - - if (Layout != CblasRowMajor) { - fprintf(stderr, "Only row major is supported in cblas_ssbmv!\n"); - throw - 1; - } - if (Uplo != CblasLower) { - fprintf(stderr, "Only lower format is supported in cblas_ssbmv!\n"); - throw - 1; - } - if (K != 0) { - fprintf(stderr, "Only diagonal matrices supported in cblas_ssbmv at this time!\n"); - throw - 1; - } - if ((alpha == 1.0) && (beta == 1.0) && (incX == 1) && (incY == 1)) { - for (i = 0; i < N; i++) { - Y[i] += A[i] * X[i]; - } - } else { - fprintf(stderr, "Only alpha=1, beta=1, incX=1, incY=1, LDA=1 supported in cblas_ssbmv at this time!\n"); - throw - 1; - } -} -#endif // #ifdef _NO_MKL_ - -void cblas_sgemm_subset(const CBLAS_LAYOUT Layout, - const CBLAS_TRANSPOSE TransA, - const CBLAS_TRANSPOSE TransB, - const MKL_INT M, - const MKL_INT N, - const MKL_INT K, - const float alpha, - const float* A, - const MKL_INT lda, - const float* B, - const MKL_INT ldb, - const float beta, - float* C, - const MKL_INT ldc, - const uint32_t* OutputList, - const MKL_INT L) { - int i, j, k, l; - - if (Layout != CblasRowMajor) { - fprintf(stderr, "Only row major is supported in cblas_sgemm_subset!\n"); - throw - 1; - } - - if ((TransA == CblasNoTrans) && (TransB == CblasNoTrans)) { - for (l = 0; l < L; l++) { - i = OutputList[l]; - for (j = 0; j < N; j++) { - float sum = (beta == 1.0) ? C[l * ldc + j] : 0; - for (k = 0; k < K; k++) { - sum += A[i * lda + k] * B[k * ldb + j]; - } - C[l * ldc + j] = sum; - } - } - } else if ((TransA == CblasNoTrans) && (TransB == CblasTrans)) { - for (i = 0; i < M; i++) { - for (l = 0; l < L; l++) { - float sum; - j = OutputList[l]; - sum = beta * C[i * ldc + l]; - for (k = 0; k < K; k++) { - sum += alpha * A[i * lda + k] * B[j * ldb + k]; - } - C[i * ldc + l] = sum; - } - } - } else if ((TransA == CblasTrans) && (TransB == CblasNoTrans)) { - for (l = 0; l < L; l++) { - i = OutputList[l]; - for (j = 0; j < N; j++) { - float sum = (beta == 1.0) ? C[l * ldc + j] : 0; - for (k = 0; k < K; k++) { - sum += A[k * lda + i] * B[k * ldb + j]; - } - C[l * ldc + j] = sum; - } - } - } else { - fprintf(stderr, "Expected A not transposed in cblas_sgemm_subset!\n"); - throw - 1; - } -} - -// C = [ A1 A2 ] * X + B -void sgemv_split(const uint32_t N, - const uint32_t K1, - const uint32_t K2, - const float* A1, - const float* A2, - const float* X, - const float* B, - float* C) { - uint32_t num_columns = K1 + K2; - uint32_t num_rows = N; - uint32_t i, j; - - for (i = 0; i < num_rows; i++) { - float sum = B[i]; - for (j = 0; j < K1; j++) { - sum += A1[j] * X[i * num_columns + j]; - } - for (j = K1; j < num_columns; j++) { - sum += A2[j - K1] * X[i * num_columns + j]; - } - C[i] = sum; - } -} diff --git a/src/plugins/intel_gna/src/runtime/floatmath.h b/src/plugins/intel_gna/src/runtime/floatmath.h deleted file mode 100644 index e26fb7da29c..00000000000 --- a/src/plugins/intel_gna/src/runtime/floatmath.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#ifndef _NO_MKL_ -# include -# include -#endif - -#ifndef CBLAS_LAYOUT -# define CBLAS_LAYOUT CBLAS_ORDER -#endif - -#ifdef _NO_MKL_ -# ifndef _MKL_H_ -# define _MKL_H_ -typedef enum { CblasRowMajor = 101, CblasColMajor = 102 } CBLAS_LAYOUT; -typedef enum { CblasNoTrans = 111, CblasTrans = 112, CblasConjTrans = 113 } CBLAS_TRANSPOSE; -typedef enum { CblasUpper = 121, CblasLower = 122 } CBLAS_UPLO; -typedef enum { CblasNonUnit = 131, CblasUnit = 132 } CBLAS_DIAG; -typedef enum { CblasLeft = 141, CblasRight = 142 } CBLAS_SIDE; -typedef CBLAS_LAYOUT CBLAS_ORDER; /* this for backward compatibility with CBLAS_ORDER */ -# define MKL_INT int -# endif // #ifndef _MKL_H_ -#endif // #ifdef _NO_MKL_ - -#ifdef _NO_MKL_ -void cblas_sgemm1(const CBLAS_LAYOUT Layout, - const CBLAS_TRANSPOSE TransA, - const CBLAS_TRANSPOSE TransB, - const MKL_INT M, - const MKL_INT N, - const MKL_INT K, - const float alpha, - const float* A, - const MKL_INT lda, - const float* B, - const MKL_INT ldb, - const float beta, - float* C, - const MKL_INT ldc); -void cblas_ssbmv1(const CBLAS_LAYOUT Layout, - const CBLAS_UPLO Uplo, - const MKL_INT N, - const MKL_INT K, - const float alpha, - const float* A, - const MKL_INT lda, - const float* X, - const MKL_INT incX, - const float beta, - float* Y, - const MKL_INT incY); -#endif // #ifdef _NO_MKL_ -void cblas_sgemm_subset(const CBLAS_LAYOUT Layout, - const CBLAS_TRANSPOSE TransA, - const CBLAS_TRANSPOSE TransB, - const MKL_INT M, - const MKL_INT N, - const MKL_INT K, - const float alpha, - const float* A, - const MKL_INT lda, - const float* B, - const MKL_INT ldb, - const float beta, - float* C, - const MKL_INT ldc, - const uint32_t* OutputList, - const MKL_INT L); -void sgemv_split(const uint32_t N, - const uint32_t K1, - const uint32_t K2, - const float* A1, - const float* A2, - const float* X, - const float* B, - float* C); diff --git a/src/plugins/intel_gna/src/runtime/gna_float_runtime.cpp b/src/plugins/intel_gna/src/runtime/gna_float_runtime.cpp deleted file mode 100644 index 9a500e4bac2..00000000000 --- a/src/plugins/intel_gna/src/runtime/gna_float_runtime.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "gna_float_runtime.hpp" - -#include - -#include "backend/dnn_types.hpp" -#include "log/debug.hpp" - -namespace ov { -namespace intel_gna { -namespace runtime { - -void FP::infer() { - if (!dnn) { - THROW_GNA_EXCEPTION << "[GNA FP32 RUNTIME] not initialized"; - } - - for (uint32_t i = 0; i < dnn->component.size(); i++) { - intel_dnn_component_t* comp = &dnn->component[i]; - uint32_t* ptr_active_outputs = nullptr; - uint32_t num_active_outputs = - (comp->orientation_out == kDnnInterleavedOrientation) ? comp->num_rows_out : comp->num_columns_out; - - if (i == dnn->component.size() - 1) { // active list applies to last component - ptr_active_outputs = dnn->ptr_active_outputs(); - num_active_outputs = dnn->num_active_outputs(); - } else if (i == dnn->component.size() - 2) { // also applies to last two components when last is PWL - if ((dnn->component[i].operation == kDnnAffineOp) && - (dnn->component[i + 1].operation == kDnnPiecewiselinearOp)) { - ptr_active_outputs = dnn->ptr_active_outputs(); - num_active_outputs = dnn->num_active_outputs(); - } - } - - switch (comp->operation) { - case kDnnAffineOp: { - ApplyAffineTransform(comp, ptr_active_outputs, num_active_outputs); - break; - } - case kDnnDiagonalOp: { - ApplyDiagonalTransform(comp); - break; - } - case kDnnRecurrentOp: { - if ((i < dnn->component.size() - 1) && (dnn->component[i + 1].operation == kDnnPiecewiselinearOp)) { - intel_dnn_component_t* comp_pwl = &dnn->component[i + 1]; - for (uint32_t j = 0; j < comp->num_rows_in; j++) { - void* ptr_feedbacks = reinterpret_cast( - reinterpret_cast(comp->op.recurrent.ptr_feedbacks) + j * comp_pwl->num_columns_out); - ApplyRecurrentTransform(comp, j, ptr_feedbacks); - ApplyPiecewiseLinearTransform(comp_pwl, kDnnFloat, num_active_outputs, j); - } - i++; // skip next component - } else { - THROW_GNA_EXCEPTION << "Missing PiecewiseLinear component after Recurrent component in Propagate!"; - } - break; - } - case kDnnConvolutional1dOp: { - ApplyConvolutional1DTransform(comp); - break; - } - case kDnnConvolutional2dOp: { - ApplyConvolutional2DTransform(comp); - break; - } - case kDnnPiecewiselinearOp: { - ApplyPiecewiseLinearTransform(comp, kDnnFloat, num_active_outputs); - break; - } - case kDnnMaxPoolOp: { - bool is_fused_with_convolution_2d = false; - if (i > 0 && dnn->component[i - 1].operation == kDnnConvolutional2dOp) { - is_fused_with_convolution_2d = true; - } - - ApplyMaxPoolTransform(comp, kDnnFloat, is_fused_with_convolution_2d); - break; - } - case kDnnInterleaveOp: { - ApplyTranspose(comp); - break; - } - case kDnnDeinterleaveOp: { - ApplyTranspose(comp); - break; - } - case kDnnCopyOp: { - ApplyCopy(comp); - break; - } - default: - THROW_GNA_EXCEPTION << "[GNA FP32 RUNTIME] Bad operation " << comp->operation; - } - } -} - -} // namespace runtime -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/runtime/gna_float_runtime.hpp b/src/plugins/intel_gna/src/runtime/gna_float_runtime.hpp deleted file mode 100644 index a6c5b890128..00000000000 --- a/src/plugins/intel_gna/src/runtime/gna_float_runtime.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include - -namespace ov { -namespace intel_gna { -namespace runtime { - -/** - * @brief floating runtime for gna-plugin, in most case it uses same gna-primitives description as integer runtime, but - * execute them on CPU - */ -class FP { - std::shared_ptr dnn; - -public: - FP(std::shared_ptr dnn) : dnn(dnn) {} - virtual void infer(); - - /** - * atomic operations for floating inference - */ - static void ApplyAffineTransform(intel_dnn_component_t* component, uint32_t* list, uint32_t listsize); - static void ApplyDiagonalTransform(intel_dnn_component_t* component); - static void ApplyRecurrentTransform(intel_dnn_component_t* component, uint32_t row, void* ptr_feedbacks); - static void ApplyConvolutional1DTransform(intel_dnn_component_t* component); - static void ApplyConvolutional2DTransform(intel_dnn_component_t* component); - static void ApplyPiecewiseLinearTransform(intel_dnn_component_t* component, - intel_dnn_number_type_t number_type, - uint32_t listsize); - static void ApplyPiecewiseLinearTransform(intel_dnn_component_t* component, - intel_dnn_number_type_t number_type, - uint32_t listsize, - uint32_t num_row); - static void ApplyMaxPoolTransform(intel_dnn_component_t* component, - intel_dnn_number_type_t number_type, - const bool fused_with_convolution_2d); - static void ApplyTranspose(intel_dnn_component_t* component); - static void ApplyCopy(intel_dnn_component_t* component); -}; - -} // namespace runtime -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/runtime/gna_float_runtime_op.cpp b/src/plugins/intel_gna/src/runtime/gna_float_runtime_op.cpp deleted file mode 100644 index b404dc5fa4a..00000000000 --- a/src/plugins/intel_gna/src/runtime/gna_float_runtime_op.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "cnn.h" -#include "floatmath.h" -#include "gna_float_runtime.hpp" -#include "pwl.h" - -namespace ov { -namespace intel_gna { -namespace runtime { - -void FP::ApplyAffineTransform(intel_dnn_component_t* component, uint32_t* list, uint32_t listsize) { - if (4 != component->num_bytes_per_input) { - THROW_GNA_EXCEPTION << "Bad data width: " << component->num_bytes_per_input; - } - - auto transform = &component->op.affine; - uint32_t m = component->num_rows_out; - uint32_t n = component->num_columns_in; - uint32_t k = component->num_rows_in; - uint32_t lda = component->num_rows_in; - uint32_t ldb = component->num_columns_in; - uint32_t ldc = component->num_columns_out; - - auto A = reinterpret_cast(transform->ptr_weights); - auto B = reinterpret_cast(component->ptr_inputs); - auto C = reinterpret_cast(component->ptr_outputs); - auto bias = reinterpret_cast(transform->ptr_biases); - if (list == nullptr) { - for (uint32_t i = 0; i < m; i++) { - for (uint32_t j = 0; j < n; j++) { - C[i * ldc + j] = bias[i]; - } - } - cblas_sgemm1(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, k, 1.0, A, lda, B, ldb, 1.0, C, ldc); - } else { - for (uint32_t l = 0; l < listsize; l++) { - int i = list[l]; - for (uint32_t j = 0; j < n; j++) { - C[l * ldc + j] = bias[i]; - } - } - cblas_sgemm_subset(CblasRowMajor, - CblasNoTrans, - CblasNoTrans, - m, - n, - k, - 1.0, - A, - lda, - B, - ldb, - 1.0, - C, - ldc, - list, - listsize); - } -} - -void FP::ApplyDiagonalTransform(intel_dnn_component_t* component) { - if (4 != component->num_bytes_per_input) { - THROW_GNA_EXCEPTION << "Bad data width: " << component->num_bytes_per_input; - } - - auto transform = &component->op.affine; - uint32_t m = component->num_rows_out; - uint32_t n = component->num_columns_in; - uint32_t ldc = component->num_columns_out; - - auto A = reinterpret_cast(transform->ptr_weights); - auto B = reinterpret_cast(component->ptr_inputs); - auto C = reinterpret_cast(component->ptr_outputs); - auto bias = reinterpret_cast(transform->ptr_biases); - for (uint32_t i = 0; i < m; i++) { - for (uint32_t j = 0; j < n; j++) { - C[i * ldc + j] = bias[i]; - } - } - std::vector Arow(n); - for (uint32_t i = 0; i < m; i++) { - float* Brow = B + i * n; - float* Crow = C + i * ldc; - std::fill(std::begin(Arow), std::end(Arow), A[i]); - cblas_ssbmv1(CblasRowMajor, CblasLower, n, 0, 1.0, Arow.data(), 1, Brow, 1, 1.0, Crow, 1); - } -} - -void FP::ApplyRecurrentTransform(intel_dnn_component_t* component, uint32_t row, void* ptr_feedbacks) { - if (4 != component->num_bytes_per_input) { - THROW_GNA_EXCEPTION << "Bad data width: " << component->num_bytes_per_input; - } - - intel_recurrent_t* transform = &component->op.recurrent; - int k1 = component->num_columns_in; - int k2 = component->num_columns_out; - int n = k2; - - if (component->op.recurrent.ptr_feedbacks == nullptr) { - THROW_GNA_EXCEPTION << "nullptr feedback pointer"; - } - auto A1 = reinterpret_cast(component->ptr_inputs) + row * component->num_columns_in; - auto A2 = reinterpret_cast(ptr_feedbacks); - auto X = reinterpret_cast(transform->ptr_weights); - auto B = reinterpret_cast(transform->ptr_biases); - auto C = reinterpret_cast(component->ptr_outputs) + row * component->num_columns_out; - sgemv_split(n, k1, k2, A1, A2, X, B, C); -} - -void FP::ApplyConvolutional1DTransform(intel_dnn_component_t* component) { - if (4 != component->num_bytes_per_input) { - THROW_GNA_EXCEPTION << "Bad data width: " << component->num_bytes_per_input; - } - CNNFilter32(component); -} - -void FP::ApplyConvolutional2DTransform(intel_dnn_component_t* component) { - CNN2DFilter32(component); -} - -void FP::ApplyPiecewiseLinearTransform(intel_dnn_component_t* component, - intel_dnn_number_type_t number_type, - uint32_t listsize) { - if (kDnnFloat != number_type) { - THROW_GNA_EXCEPTION << "Bad number type: " << number_type; - } - PwlApply32(component, listsize); -} - -void FP::ApplyPiecewiseLinearTransform(intel_dnn_component_t* component, - intel_dnn_number_type_t number_type, - uint32_t listsize, - uint32_t num_row) { - if (kDnnFloat != number_type) { - THROW_GNA_EXCEPTION << "Bad number type: " << number_type; - } - PwlApply32(component, num_row, num_row, 0, listsize - 1); -} - -void FP::ApplyMaxPoolTransform(intel_dnn_component_t* component, - intel_dnn_number_type_t number_type, - const bool fused_with_convolution_2d) { - if (4 != component->num_bytes_per_input) { - THROW_GNA_EXCEPTION << "Bad data width: " << component->num_bytes_per_input; - } - CNNMaxPool(component, number_type, fused_with_convolution_2d); -} - -void FP::ApplyTranspose(intel_dnn_component_t* component) { - if (4 != component->num_bytes_per_input) { - THROW_GNA_EXCEPTION << "Bad data width: " << component->num_bytes_per_input; - } - - uint32_t m = component->num_rows_in; - uint32_t n = component->num_columns_in; - uint32_t lda = component->num_columns_in; - uint32_t ldb = component->num_columns_out; - // B = Transpose(A) where A is mxn and B is nxm - auto A = reinterpret_cast(component->ptr_inputs); - auto B = reinterpret_cast(component->ptr_outputs); - for (uint32_t row = 0; row < m; row++) { - for (uint32_t col = 0; col < n; col++) { - B[col * ldb + row] = A[row * lda + col]; - } - } -} - -void FP::ApplyCopy(intel_dnn_component_t* component) { - if (4 != component->num_bytes_per_input) { - THROW_GNA_EXCEPTION << "Bad data width: " << component->num_bytes_per_input; - } - - auto src = reinterpret_cast(component->ptr_inputs); - auto dst = reinterpret_cast(component->ptr_outputs); - uint32_t m = component->op.copy.num_copy_rows; - uint32_t n = component->op.copy.num_copy_columns; - uint32_t lda = component->num_columns_in; - uint32_t ldb = component->num_columns_out; - if (m > component->num_rows_in) { - THROW_GNA_EXCEPTION << "Error: attempt to copy more columns than matrix has"; - } - auto A = reinterpret_cast(src); - auto B = reinterpret_cast(dst); - for (uint32_t row = 0; row < m; row++) { - for (uint32_t col = 0; col < n; col++) { - B[row * ldb + col] = A[row * lda + col]; - } - } -} - -} // namespace runtime -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/runtime/pwl.cpp b/src/plugins/intel_gna/src/runtime/pwl.cpp deleted file mode 100644 index ff6f0d6a1fc..00000000000 --- a/src/plugins/intel_gna/src/runtime/pwl.cpp +++ /dev/null @@ -1,555 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -// pwl_design.cpp : simple activation function designer -// - -#include -#include -#include -#include -#include - -#include "frontend/quantization.hpp" - -#ifdef _NO_MKL_ -# include - -# include "backend/make_pwl.hpp" - -# define SCOPY(num, in, inci, out, inco) \ - for (int i_ = 0; i_ < *(num); i_++) \ - *(out + i_ * *(inco)) = *(in + i_ * *(inci)); -# define SSCAL(num, scale, inout, inco) \ - for (int i_ = 0; i_ < *(num); i_++) \ - *(inout + i_ * *(inco)) = *(scale) * *(inout + i_ * *(inco)); -# define TANH(num, in, out) \ - for (int i_ = 0; i_ < num; i_++) \ - *(out + i_) = tanh(*(in + i_)) -#else -# include -# define SCOPY(num, in, incx, out, incy) scopy(num, in, incx, out, incy) -# define SSCAL(num, scale, inout, incx) sscal(num, scale, inout, incx) -# define TANH(num, in, out) vsTanh(num, in, out) -#endif - -#include "common/numerical_utils.hpp" -#include "gna_slope_scale.hpp" -#include "log/debug.hpp" -#include "log/log.hpp" -#include "ops/reference/pwl.hpp" -#include "pwl.h" - -using namespace ov::intel_gna; -using namespace ov::intel_gna::common; - -double relu(const double x) { - if (x < 0) { - return (0.0); - } else { - return (x); - } -} -double leaky_relu(const double x) { - if (x < 0.0) { - return (LEAKYRELU_SLOPE * x); - } else { - return (x); - } -} -double clipping(const double x, const double lbound, const double ubound) { - return ((x < lbound) ? lbound : ((x > ubound) ? ubound : x)); -} - -inline double power(const double x, const std::tuple& args) { - return (pow(std::get<2>(args) + std::get<1>(args) * x, std::get<0>(args))); -} - -void PwlDesignOpt(const DnnActivation& activation_type, - const float scale_in, - const float scale_out, - const bool low_precision, - const std::shared_ptr& node, - const bool is_fused_with_conv2d, - std::vector& ptr_segment) { - std::vector pwl; - switch (activation_type) { - case kActPwl: { - make_gna_pwl(node, scale_in, scale_out, low_precision, ptr_segment); - break; - } - case kActRelu: - make_gna_pwl(activation_type, - pwl, - -1.0, - 1.0, - scale_in, - scale_out, - low_precision, - is_fused_with_conv2d, - ptr_segment); - break; - case kActLeakyRelu: - make_gna_pwl(activation_type, - pwl, - -1.0, - 1.0, - scale_in, - scale_out, - low_precision, - is_fused_with_conv2d, - ptr_segment); - break; - case kActIdentity: - case kActFakeQuantize: - make_gna_pwl(activation_type, - pwl, - -1.0, - 1.0, - scale_in, - scale_out, - low_precision, - is_fused_with_conv2d, - ptr_segment); - break; - case kActKaldiLstmClipping: - make_gna_pwl(activation_type, - pwl, - activation_type.args.clamp.low, - activation_type.args.clamp.high, - scale_in, - scale_out, - low_precision, - is_fused_with_conv2d, - ptr_segment); - break; - case kActSign: - make_gna_pwl(activation_type, - pwl, - -1.0, - 1.0, - scale_in, - scale_out, - low_precision, - is_fused_with_conv2d, - ptr_segment); - break; - case kActAbs: - make_gna_pwl(activation_type, - pwl, - -1.0, - 1.0, - scale_in, - scale_out, - low_precision, - is_fused_with_conv2d, - ptr_segment); - break; - default: - THROW_GNA_EXCEPTION << "Unknown piecewise linear function type: " << activation_type.type; - } -} - -void PwlDesign(const DnnActivation& activation_type, - gna_pwl_segment_t* ptr_segment, - const uint32_t num_segments, - const float scale_in, - const float scale_out, - const bool low_precision) { - switch (activation_type) { - case kActSigmoid: { - log::debug() << "=========================== Sigmoid Segments===========================\n"; - uint32_t num_segment_size = 0; - int32_t offset = 0; - ptr_segment[0].xBase = static_cast(INT32_MIN & XBASEMASK); // zero out the 2 lsb - num_segment_size = static_cast(SIGMOID_DOMAIN * scale_in / ((num_segments - 2) / 2) + 0.5); - offset = -static_cast(num_segment_size * (num_segments - 2) / 2); - for (uint32_t i = 1; i < num_segments; i++) { - ptr_segment[i].xBase = static_cast(offset & XBASEMASK); // zero out the 2 lsb - offset += num_segment_size; - } - for (uint32_t i = 0; i < num_segments; i++) { - int32_t xbase = static_cast(ptr_segment[i].xBase & XBASEMASK); - int32_t xbasenext = - (i < num_segments - 1) ? static_cast(ptr_segment[i + 1].xBase & XBASEMASK) : INT32_MAX; - float floatarg = static_cast(xbase / (2 * scale_in)); - float floatargnext = static_cast(xbasenext / (2 * scale_in)); - float floatval, floatvalnext, slope; - TANH(1, &floatarg, &floatval); - floatval = 0.5f * (1.0f + floatval); - TANH(1, &floatargnext, &floatvalnext); - floatvalnext = 0.5f * (1.0f + floatvalnext); - slope = scale_out * (floatvalnext - floatval) / static_cast(xbasenext - xbase); - { - // find best scale factor - uint64_t slope_scale; - uint32_t slope_scale_index; - for (slope_scale_index = 3; slope_scale_index > 0; slope_scale_index--) { - slope_scale = static_cast(1) << (8 * (1 + slope_scale_index)); - if (((slope * slope_scale) <= 32767.0) && ((slope * slope_scale) >= -32768.0)) - break; - } - slope_scale = static_cast(1) << (8 * (1 + slope_scale_index)); - ptr_segment[i].slope = FloatToInt16(slope * slope_scale); - - ptr_segment[i].xBase = ptr_segment[i].xBase | slope_scale_index; - } - ptr_segment[i].yBase = FloatToInt16(floatval * scale_out); - log::debug() << (static_cast((ptr_segment[i].xBase & XBASEMASK)) / scale_out) << " " - << (static_cast((ptr_segment[i].yBase)) / scale_out) << " " << (slope / scale_out) - << "\n"; - } - } break; - case kActTanh: { - log::debug() << "=========================== Tanh Segments===========================\n"; - uint32_t num_segment_size = 0; - int32_t offset = 0; - ptr_segment[0].xBase = static_cast(INT32_MIN & XBASEMASK); // zero out the 2 lsb - num_segment_size = static_cast(TANH_DOMAIN * scale_in / ((num_segments - 2) / 2) + 0.5); - offset = -static_cast(num_segment_size * (num_segments - 2) / 2); - for (uint32_t i = 1; i < num_segments; i++) { - ptr_segment[i].xBase = static_cast(offset & XBASEMASK); // zero out the 2 lsb - offset += num_segment_size; - } - for (uint32_t i = 0; i < num_segments; i++) { - int32_t xbase = static_cast(ptr_segment[i].xBase & XBASEMASK); - int32_t xbasenext = - (i < num_segments - 1) ? static_cast(ptr_segment[i + 1].xBase & XBASEMASK) : INT32_MAX; - float floatarg = static_cast(xbase / scale_in); - float floatargnext = static_cast(xbasenext / scale_in); - float floatval, floatvalnext, slope; - TANH(1, &floatarg, &floatval); - TANH(1, &floatargnext, &floatvalnext); - slope = scale_out * (floatvalnext - floatval) / static_cast(xbasenext - xbase); - { - // find best scale factor - uint64_t slope_scale; - uint32_t slope_scale_index; - for (slope_scale_index = 3; slope_scale_index > 0; slope_scale_index--) { - slope_scale = static_cast(1) << (8 * (1 + slope_scale_index)); - if (((slope * slope_scale) <= 32767.0) && ((slope * slope_scale) >= -32768.0)) - break; - } - slope_scale = static_cast(1) << (8 * (1 + slope_scale_index)); - ptr_segment[i].slope = FloatToInt16(slope * slope_scale); - ptr_segment[i].xBase = ptr_segment[i].xBase | slope_scale_index; - } - ptr_segment[i].yBase = FloatToInt16(floatval * scale_out); - log::debug() << (static_cast((ptr_segment[i].xBase & XBASEMASK)) / scale_out) << " " - << (static_cast((ptr_segment[i].yBase)) / scale_out) << " " << (slope / scale_out) - << "\n"; - } - } break; - case kActSoftSign: { - auto softsign = [](const double x) { - return (x / (1.0 + fabs(x))); - }; - log::debug() << "=========================== SoftSign Segments===========================\n"; - uint32_t num_segment_size = 0; - int32_t offset = 0; - ptr_segment[0].xBase = static_cast(INT32_MIN & XBASEMASK); // zero out the 2 lsb - num_segment_size = static_cast(SOFTSIGN_DOMAIN * scale_in / ((num_segments - 2) / 2) + 0.5); - offset = -static_cast(num_segment_size * (num_segments - 2) / 2); - for (uint32_t i = 1; i < num_segments; i++) { - ptr_segment[i].xBase = static_cast(offset & XBASEMASK); // zero out the 2 lsb - offset += num_segment_size; - } - for (uint32_t i = 0; i < num_segments; i++) { - int32_t xbase = static_cast(ptr_segment[i].xBase & XBASEMASK); - int32_t xbasenext = - (i < num_segments - 1) ? static_cast(ptr_segment[i + 1].xBase & XBASEMASK) : INT32_MAX; - float floatarg = static_cast(xbase / (2 * scale_in)); - float floatargnext = static_cast(xbasenext / (2 * scale_in)); - float floatval, floatvalnext, slope; - floatval = static_cast(softsign(floatarg)); - floatvalnext = static_cast(softsign(floatargnext)); - slope = scale_out * (floatvalnext - floatval) / static_cast(xbasenext - xbase); - { - // find best scale factor - uint64_t slope_scale; - uint32_t slope_scale_index; - for (slope_scale_index = 3; slope_scale_index > 0; slope_scale_index--) { - slope_scale = static_cast(1) << (8 * (1 + slope_scale_index)); - if (((slope * slope_scale) <= 32767.0) && ((slope * slope_scale) >= -32768.0)) - break; - } - slope_scale = static_cast(1) << (8 * (1 + slope_scale_index)); - ptr_segment[i].slope = FloatToInt16(slope * slope_scale); - ptr_segment[i].xBase = ptr_segment[i].xBase | slope_scale_index; - } - ptr_segment[i].yBase = FloatToInt16(floatval * scale_out); - log::debug() << (static_cast((ptr_segment[i].xBase & XBASEMASK)) / scale_out) << " " - << (static_cast((ptr_segment[i].yBase)) / scale_out) << " " << (slope / scale_out) - << "\n"; - } - } break; - case kActRelu: - THROW_GNA_EXCEPTION << "Rectilinear activation function design not yet implemented!"; - case kActIdentity: - case kActKaldiLstmClipping: // clipping of IDENTITY is more aggressive than Kaldi - { - float slope = 0.0; - int64_t x_lower_limit = static_cast((INT16_MIN / scale_out) * scale_in - 0.5); - int64_t x_upper_limit = static_cast((INT16_MAX / scale_out) * scale_in + 0.5); - int16_t y_lower_limit = INT16_MIN; - int16_t y_upper_limit = INT16_MAX; - if (activation_type == kActKaldiLstmClipping) - log::debug() << "=========================== Clipping Segments ===========================\n"; - else - log::debug() << "=========================== Identity Segments ===========================\n"; - if (x_lower_limit < INT32_MIN) { - log::warning() << "Saturation in PwlDesign! " << x_lower_limit << " < INT32_MIN" << std::endl; - x_lower_limit = INT32_MIN; - y_lower_limit = static_cast((scale_out / scale_in) * static_cast(INT32_MIN) - 0.5); - } - if (x_upper_limit > INT32_MAX) { - log::warning() << "Saturation in PwlDesign! " << x_upper_limit << " > INT32_MAX" << std::endl; - x_upper_limit = INT32_MAX; - y_upper_limit = static_cast((scale_out / scale_in) * static_cast(INT32_MAX) + 0.5); - } - slope = static_cast(static_cast(y_upper_limit) - static_cast(y_lower_limit)) / - static_cast(static_cast(x_upper_limit) - static_cast(x_lower_limit)); - ptr_segment[0].xBase = static_cast(INT32_MIN & XBASEMASK); // zero out the 2 lsb - ptr_segment[0].yBase = y_lower_limit; - ptr_segment[0].slope = 0; - - log::debug() << ptr_segment[0].xBase / scale_in << " " << ptr_segment[0].yBase / scale_out << " " << 0 << "\n"; - - ptr_segment[1].xBase = static_cast(x_lower_limit & XBASEMASK); - ptr_segment[1].yBase = y_lower_limit; - { - // find best scale factor - uint64_t slope_scale = 0; - uint32_t slope_scale_index = 0; - for (slope_scale_index = 3; slope_scale_index > 0; slope_scale_index--) { - slope_scale = static_cast(1) << (8 * (1 + slope_scale_index)); - if (((slope * slope_scale) <= std::numeric_limits::max()) && - ((slope * slope_scale) >= std::numeric_limits::min())) - break; - } - slope_scale = static_cast(1) << (8 * (1 + slope_scale_index)); - ptr_segment[1].slope = FloatToInt16(slope * slope_scale); - ptr_segment[1].xBase = ptr_segment[1].xBase | slope_scale_index; - } - ptr_segment[2].xBase = static_cast(x_upper_limit & XBASEMASK); - ptr_segment[2].yBase = y_upper_limit; - ptr_segment[2].slope = 0; - } break; - case kActPow: { - log::debug() << "=========================== Pow Segments===========================\n"; - uint32_t num_segment_size = 0; - - auto args = std::tuple{activation_type.args.pow.exponent, - activation_type.args.pow.scale, - activation_type.args.pow.offset}; - - auto input_min_value = static_cast(std::numeric_limits::min()); - auto input_max_value = static_cast(std::numeric_limits::max()); - double x_min = AreFpEq(fmod(activation_type.args.pow.exponent, 1.0), 0.0) ? input_min_value / scale_in : 0.0; - x_min = std::max(x_min, -POW_DOMAIN); - - double x_max = input_max_value / scale_in; - x_max = std::min(x_max, POW_DOMAIN); - - double pow_domain = x_max - x_min; - ptr_segment[0].xBase = static_cast(INT32_MIN & XBASEMASK); // zero out the 2 lsb - num_segment_size = static_cast(pow_domain * scale_in / (num_segments - 2) + 0.5); - int32_t x_min_scaled = static_cast(x_min * scale_in + 0.5); - int32_t offset = x_min_scaled; - for (uint32_t i = 1; i < num_segments; i++) { - ptr_segment[i].xBase = static_cast(offset & XBASEMASK); // zero out the 2 lsb - offset += num_segment_size; - } - for (uint32_t i = 0; i < num_segments; i++) { - int32_t xbase = static_cast(ptr_segment[i].xBase & XBASEMASK); - int32_t xbasenext = - (i < num_segments - 1) ? static_cast(ptr_segment[i + 1].xBase & XBASEMASK) : INT32_MAX; - - double arg = xbase / scale_in; - arg = arg < x_min ? x_min : arg; - - double argnext = xbasenext / scale_in; - argnext = argnext < x_min ? x_min : argnext; - - double val = power(arg, args); - double valnext = power(argnext, args); - - double slope = (valnext - val) / (static_cast(xbasenext - xbase) / scale_in); - auto s = gna_slope(slope, scale_in, scale_out); - - ptr_segment[i].slope = DoubleToInt16(s.slope * s.slope_scale); - ptr_segment[i].xBase = ptr_segment[i].xBase | s.slope_scale_index; - - ptr_segment[i].yBase = DoubleToInt16(val * scale_out); - log::debug() << (static_cast((ptr_segment[i].xBase & XBASEMASK)) / scale_out) << " " - << (static_cast((ptr_segment[i].yBase)) / scale_out) << " " << (s.slope / scale_out) - << "\n"; - } - } break; - default: - fprintf(stderr, - "Activation function design for %s not yet implemented!\n", - intel_dnn_activation_name[activation_type]); - throw - 1; - } -} - -void PwlApply32(intel_dnn_component_t* component, uint32_t num_subset_size) { - if (component->orientation_in == kDnnInterleavedOrientation) { // subsets only supported in interleaved orientation - PwlApply32(component, 0, num_subset_size - 1, 0, component->num_columns_in - 1); - } else { - PwlApply32(component, 0, component->num_rows_in - 1, 0, component->num_columns_in - 1); - } -} - -void PwlApply32(intel_dnn_component_t* component, - uint32_t num_row_start, - uint32_t num_row_end, - uint32_t num_col_start, - uint32_t num_col_end) { - intel_piecewiselinear_t* transform = reinterpret_cast(&component->op.pwl); - float* ptr_in = reinterpret_cast(component->ptr_inputs); - float* ptr_out = reinterpret_cast(component->ptr_outputs); - uint32_t num_columns = component->num_columns_in; - switch (transform->func_id.type) { - case kActSigmoid: - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = 0.5f * (1.0f + tanh(0.5f * ptr_in[i * num_columns + j])); - } - } - break; - case kActTanh: - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = tanh(ptr_in[i * num_columns + j]); - } - } - break; - case kActSoftSign: - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = - static_cast(ptr_in[i * num_columns + j] / (1.0 + fabs(ptr_in[i * num_columns + j]))); - } - } - break; - case kActRelu: - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = - (ptr_in[i * num_columns + j] < 0.0f) - ? ptr_in[i * num_columns + j] * transform->func_id.args.lrelu.negative_slope - : ptr_in[i * num_columns + j]; - } - } - break; - case kActIdentity: - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = ptr_in[i * num_columns + j]; - } - } - break; - case kActKaldiLstmClipping: { - float upper_limit = component->op.pwl.func_id.args.clamp.high; - float lower_limit = component->op.pwl.func_id.args.clamp.low; - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - float val = ptr_in[i * num_columns + j]; - if (val > upper_limit) { - ptr_out[i * num_columns + j] = upper_limit; - } else if (val < lower_limit) { - ptr_out[i * num_columns + j] = lower_limit; - } else { - ptr_out[i * num_columns + j] = val; - } - } - } - break; - } - case kActExp: - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = exp(ptr_in[i * num_columns + j]); - } - } - break; - case kActLog: - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = std::log(ptr_in[i * num_columns + j]); - } - } - break; - case kActAbs: - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = fabs(ptr_in[i * num_columns + j]); - } - } - break; - case kActSign: - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = - (ptr_in[i * num_columns + j] == 0.f) ? 0.0f : ((ptr_in[i * num_columns + j] > 0) ? 1.0f : -1.0f); - } - } - break; - case kActNegLog: - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = static_cast(-1.0 * std::log(ptr_in[i * num_columns + j])); - } - } - break; - case kActNegHalfLog: - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = static_cast(-0.5 * std::log(ptr_in[i * num_columns + j])); - } - } - break; - case kActPow: { - float exponent = transform->func_id.args.pow.exponent; - float scale = transform->func_id.args.pow.scale; - float offset = transform->func_id.args.pow.offset; - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - ptr_out[i * num_columns + j] = - static_cast(pow(offset + scale * ptr_in[i * num_columns + j], exponent)); - } - } - } break; - case kActFakeQuantize: { - auto levels = static_cast(transform->func_id.fqParams.levels); - - for (uint32_t i = num_row_start; i <= num_row_end; i++) { - auto inputChannel = transform->func_id.fqParams.inputPerChannel ? i : 0; - auto outputChannel = transform->func_id.fqParams.outputPerChannel ? i : 0; - - float input_low = transform->func_id.fqParams.input_low[inputChannel]; - float input_high = transform->func_id.fqParams.input_high[inputChannel]; - float output_low = transform->func_id.fqParams.output_low[outputChannel]; - float output_high = transform->func_id.fqParams.output_high[outputChannel]; - - for (uint32_t j = num_col_start; j <= num_col_end; j++) { - auto offset = i * num_columns + j; - - ptr_out[offset] = ov::intel_gna::frontend::ApplyFQ(ptr_in[offset], - input_low, - input_high, - output_low, - output_high, - levels); - } - } - break; - } - case kActCustom: - default: - THROW_GNA_EXCEPTION << component->original_layer_name - << ", Unknown piecewise linear function type: " << transform->func_id.type; - } -} diff --git a/src/plugins/intel_gna/src/runtime/pwl.h b/src/plugins/intel_gna/src/runtime/pwl.h deleted file mode 100644 index 1f789580902..00000000000 --- a/src/plugins/intel_gna/src/runtime/pwl.h +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "backend/dnn_types.hpp" -#include "backend/gna_types.hpp" - -#define SIGMOID_NUM_SEGMENTS 65 -#define SIGMOID_DOMAIN 10.0f // portion of input to be approximated (-10,10) -#define TANH_NUM_SEGMENTS 65 -#define TANH_DOMAIN 5.0f // portion of input to be approximated (-5,5) -#define SOFTSIGN_NUM_SEGMENTS 65 -#define SOFTSIGN_DOMAIN 10.0f // portion of input to be approximated (-10,10) -#define RELU_NUM_SEGMENTS 2 -#define LEAKYRELU_SLOPE 0.01 -#define IDENTITY_NUM_SEGMENTS 3 -#define IDENTITY_DOMAIN 10.0f -#define ACTIVATION_SCALE_FACTOR 2048.0f -#define IDENTITY_SCALE_FACTOR 2049.0f -#define XBASEMASK 0xFFFFFFFC // only top 30 bits are used -#define XBASE_SCALE_INDEX_MASK ~XBASEMASK // only 2 LSB are used -#define KALDI_LSTM_CLIP_LOWER (-50.0) -#define KALDI_LSTM_CLIP_UPPER (50.0) -#define POW_DOMAIN (16.0) -#define POW_NUM_SEGMENTS 65 - -typedef struct { - double t; - double alpha; - double beta; - double m; - double b; -} pwl_t; - -double relu(const double x); -double leaky_relu(const double x); - -double clipping(const double x, const double lbound, const double ubound); - -double pivot_search(std::vector& result, - double (*f)(const double), - double (*first_deriv_f)(const double), - const uint32_t N, - const double alpha_0, - const double alpha_N, - const double threshold, - const bool negative, - size_t iter_num); - -inline std::vector negative_pwl(const std::vector& pwl); - -std::vector pwl_search(const DnnActivation& activation_type, - const double l_bound, - const double u_bound, - const double threshold, - const double allowed_err_pct, - const int samples, - double& err_pct); - -bool split_search(const DnnActivationType fun, const double l_bound, const double u_bound); - -double calculate_error_pct(const DnnActivation& activation_type, - const double l_bound, - const double u_bound, - const double offset, - const int samples); - -void PwlApply32(intel_dnn_component_t* component, const uint32_t num_subset_size); -void PwlApply32(intel_dnn_component_t* component, - const uint32_t num_row_start, - const uint32_t num_row_end, - const uint32_t num_col_start, - const uint32_t num_col_end); -void PwlDesign(const DnnActivation& activation_type, - gna_pwl_segment_t* ptr_segment, - const uint32_t num_segments, - const float scale_in, - const float scale_out, - const bool low_precision); -void PwlDesignOpt(const DnnActivation& activation_type, - const float scale_in, - const float scale_out, - const bool low_precision, - const std::shared_ptr& node, - const bool is_fused_with_conv2d, - std::vector& ptr_segment); diff --git a/src/plugins/intel_gna/src/scale_factor_helper.cpp b/src/plugins/intel_gna/src/scale_factor_helper.cpp deleted file mode 100644 index 49dd1b13d89..00000000000 --- a/src/plugins/intel_gna/src/scale_factor_helper.cpp +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "scale_factor_helper.hpp" - -#include "common/numerical_utils.hpp" -#include "gna_plugin_config.hpp" -#include "log/log.hpp" - -namespace ov { -namespace intel_gna { -using namespace common; -namespace helpers { - -static bool IsCustomInputScaleFactorAvailableLegacy(const std::vector& input_scale_factors) { - if (input_scale_factors.empty()) { - return false; - } - - bool is_scale_factor_custom = false; - for (const auto& scale_factor : input_scale_factors) { - if (!AreFpEq(scale_factor, kScaleFactorDefault)) { - is_scale_factor_custom = true; - break; - } - } - - return is_scale_factor_custom; -} - -static void ApplyScaleFactorsLegacy(const std::vector& input_scale_factors, GnaInputs& inputs) { - if (input_scale_factors.size() > inputs.size()) { - IE_THROW() << "Configuration input scale factors count is bigger than inputs count"; - } - - 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) { - inputs.Get().at(id).scale_factor = input_scale_factors[id]; - } else { - log::warning() << "Using default input scale factor: " << kScaleFactorDefault << " for input id: " << id - << std::endl; - } - } -} - -static bool IsCustomInputScaleFactorPerInputAvailable(const std::map& per_input_scale_factors) { - if (per_input_scale_factors.empty()) { - return false; - } - - bool is_scale_factor_custom = false; - for (const auto& scale_factor : per_input_scale_factors) { - if (!AreFpEq(scale_factor.second, kScaleFactorDefault)) { - is_scale_factor_custom = true; - break; - } - } - - return is_scale_factor_custom; -} - -static void ApplyScaleFactorsPerInput(const std::map& per_input_scale_factors, GnaInputs& inputs) { - if (per_input_scale_factors.size() > inputs.size()) { - IE_THROW() << "Configuration per input scale factors count is bigger than inputs count"; - } - - for (auto&& sf : per_input_scale_factors) { - // to support the both legacy and 2.0 API we need to check all possible names in the configuration - auto input_it = std::find_if(inputs.Get().begin(), inputs.Get().end(), [&](const InputDesc& input_desc) { - return sf.first == input_desc.name || input_desc.tensor_names.count(sf.first); - }); - - if (input_it == inputs.Get().end()) { - IE_THROW() << "Given scale factor for invalid input: " << sf.first; - } - ::log::warning() << "Using input scale factor: " << sf.second - << ", defined in configuration for input: " << sf.first << std::endl; - input_it->scale_factor = sf.second; - } -} - -static bool CheckIfCanApplyCustomScaleFactor(const header_latest::ModelHeader& header) { - static constexpr header_2_dot_8::ModelHeader::Version sc_forbid_override_scale_factor; - if (!header_latest::IsFirstVersionLower(header.version, sc_forbid_override_scale_factor)) { - ::log::warning() << "Cannot apply custom scale factor for model versions >= " - << sc_forbid_override_scale_factor.major << "." << sc_forbid_override_scale_factor.minor - << std::endl; - return false; - } - return true; -} - -void ApplyInputScaleFactors(GnaInputs& inputs, const Config& config, const header_latest::ModelHeader& header) { - // we have to check that SF exist in the configuration and values are not default - const bool custom_scale_factors = IsCustomInputScaleFactorPerInputAvailable(config.inputScaleFactorsPerInput); - const bool custom_scale_factors_legacy = IsCustomInputScaleFactorAvailableLegacy(config.inputScaleFactors); - if (!custom_scale_factors && !custom_scale_factors_legacy) { - return; - } - - if (!CheckIfCanApplyCustomScaleFactor(header)) { - return; - } - - if (custom_scale_factors) { - ApplyScaleFactorsPerInput(config.inputScaleFactorsPerInput, inputs); - } else if (custom_scale_factors_legacy) { - ApplyScaleFactorsLegacy(config.inputScaleFactors, inputs); - } - - return; -} - -void ApplyInputScaleFactors(GnaInputs& inputs, const Config& config) { - if (IsCustomInputScaleFactorPerInputAvailable(config.inputScaleFactorsPerInput)) { - ApplyScaleFactorsPerInput(config.inputScaleFactorsPerInput, inputs); - } else if (IsCustomInputScaleFactorAvailableLegacy(config.inputScaleFactors)) { - ApplyScaleFactorsLegacy(config.inputScaleFactors, inputs); - } - - return; -} - -} // namespace helpers -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/scale_factor_helper.hpp b/src/plugins/intel_gna/src/scale_factor_helper.hpp deleted file mode 100644 index 5f11ca35a0d..00000000000 --- a/src/plugins/intel_gna/src/scale_factor_helper.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "descriptions/gna_desc.hpp" -#include "serial/headers/latest/gna_model_header.hpp" - -namespace ov { -namespace intel_gna { - -struct Config; - -/** - * @namespace helpers contains helpers tools for gna plugin. - */ -namespace helpers { - -void ApplyInputScaleFactors(GnaInputs& inputs, const Config& config, const header_latest::ModelHeader& header); -void ApplyInputScaleFactors(GnaInputs& inputs, const Config& config); - -} // namespace helpers -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/serial/gna_model_serial.cpp b/src/plugins/intel_gna/src/serial/gna_model_serial.cpp deleted file mode 100644 index 5576a86d86e..00000000000 --- a/src/plugins/intel_gna/src/serial/gna_model_serial.cpp +++ /dev/null @@ -1,671 +0,0 @@ -// Copyright (C) 2018-2023 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 "common/versioning.hpp" -#include "gna2_model_helper.hpp" -#include "gna_model_serial.hpp" -#include "gna_plugin.hpp" -#include "openvino/pass/serialize.hpp" -#include "openvino/runtime/core.hpp" -#include "serial/headers/2dot2/gna_model_header.hpp" -#include "serial/headers/2dot5/gna_model_header.hpp" -#include "serial/headers/2dot7/gna_model_header.hpp" -#include "serial/headers/2dot8/gna_model_header.hpp" -#include "serial/headers/2dot9/gna_model_header.hpp" -#include "serial/headers/latest/gna_model_header.hpp" - -using namespace ov::intel_gna; - -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)); -} - -inline void writeString(const std::string& str, std::ostream& os) { - const char* c_str = str.c_str(); - const uint32_t str_len = static_cast(strlen(c_str)) + 1; - writeBits(str_len, os); - writeNBytes(c_str, str_len, os); -} - -inline void write_pre_processing_model(const std::shared_ptr& model, std::ostream& os) { - // allocate buffer for ir.xml - std::ostringstream xml_buf; - // allocate buffer for ir.bin - std::ostringstream bin_buf; - - // serialize IR to stream buffer (.xml + .bin) - ov::pass::Serialize serializer(xml_buf, bin_buf); - serializer.run_on_model(model); - - // write IR - writeString(xml_buf.str(), os); - - // write BIN - size_t ir_bin_size = bin_buf.str().size(); - writeBits(ir_bin_size, os); - writeNBytes(bin_buf.str().c_str(), static_cast(ir_bin_size), os); -} - -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 std::string readString(std::istream& is) { - uint32_t str_len = 0; - readNBits<32>(str_len, is); - std::string str(str_len, '\0'); - readNBytes(&str[0], str_len, is); - return str.substr(0, str_len - 1); -} - -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)); -} - -union { - uint16_t s; - uint8_t c[2]; -} constexpr static LECheck{1}; - -inline bool is_little_endian() { - return LECheck.c[0] == 1; -} - -void GNAVersionSerializer::Export(std::ostream& os) const { - writeString(ov::intel_gna::common::get_openvino_version_string(), os); - writeString(GNADeviceHelper::GetGnaLibraryVersion(), os); -} - -std::string GNAVersionSerializer::Import(std::istream& is) const { - std::string version; - if (is.peek() && !is.eof()) { - version = "The model was exported with OpenVINO version:\n" + readString(is) + "\n"; - version += "GNA Library version:\n" + readString(is) + "\n"; - } - return version; -} - -const int gna_header_magic = is_little_endian() ? 0x4d414e47 : 0x474e414d; - -header_latest::ModelHeader GNAModelSerial::ReadHeader(std::istream& is) { - is.exceptions(std::istream::failbit); - auto startPos = is.tellg(); - if (startPos == -1) { - THROW_GNA_EXCEPTION << "Can't open stream to import"; - } - is.seekg(0, is.end); - auto stream_len = is.tellg(); - if (stream_len == -1) { - THROW_GNA_EXCEPTION << "Can't open file to import"; - } - stream_len -= startPos; - is.seekg(startPos, is.beg); - - header_latest::ModelHeader header; - header.version.major = 0u; - header.version.minor = 0u; - auto size_of_headers_header = sizeof(header_latest::ModelHeader::gnam) + - sizeof(header_latest::ModelHeader::headerSize) + - sizeof(header_latest::ModelHeader::Version); - if (static_cast(stream_len) > size_of_headers_header) { - readNBytes(&header, static_cast(size_of_headers_header), is); - } else { - readNBytes(&header, static_cast(stream_len), is); - } - if (*reinterpret_cast(header.gnam) != gna_header_magic) { - THROW_GNA_EXCEPTION << "Imported file unsupported: magic number should be GNAM(0x474e414d), but was 0x" - << std::setfill('0') << std::hex << std::setw(2) << static_cast(header.gnam[0]) - << std::hex << std::setw(2) << static_cast(header.gnam[1]) << std::hex - << std::setw(2) << static_cast(header.gnam[2]) << std::hex << std::setw(2) - << static_cast(header.gnam[3]); - } - - is.seekg(startPos, is.beg); - header_2_dot_1::ModelHeader tempheader_2_dot_1; - switch (header.version.major) { - case 2: - switch (header.version.minor) { - case 1: - readBits(tempheader_2_dot_1, is); - header = header_latest::ModelHeader(tempheader_2_dot_1); - break; - case 2: - case 3: { - header_2_dot_3::ModelHeader tempheader_2_dot_3; - readBits(tempheader_2_dot_3, is); - header = header_latest::ModelHeader(tempheader_2_dot_3); - break; - } - case 4: { - header_2_dot_4::ModelHeader tempheader_2_dot_4; - readBits(tempheader_2_dot_4, is); - header = header_latest::ModelHeader(tempheader_2_dot_4); - break; - } - case 5: - case 6: - case 7: - case 8: - case 9: - readNBytes(&header, sizeof(header_latest::ModelHeader), is); - break; - default: - THROW_GNA_EXCEPTION - << "Imported file unsupported. minor version should have values in range 1 to 9 and is: " - << header.version.minor; - } - break; - default: - THROW_GNA_EXCEPTION << "Imported file unsupported. Import for files with major version equal to: " - << header.version.major << " is not implemented"; - } - - /* - * extra data need to be added into new header and modify check as appropriate - */ - - // forward compatible - if (header.headerSize > sizeof(header)) { - is.seekg(header.headerSize - sizeof(header), std::ios_base::cur); - } - return header; -} - -header_latest::RuntimeEndPoint GNAModelSerial::ReadEndPoint(std::istream& is) { - is.exceptions(std::istream::failbit); - - header_latest::RuntimeEndPoint endPoint; - switch (model_header_.version.major) { - case 2: - switch (model_header_.version.minor) { - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: { - header_2_dot_6::RuntimeEndPoint tempEndPoint2dot6; - readBits(tempEndPoint2dot6, is); - endPoint = header_latest::RuntimeEndPoint(tempEndPoint2dot6, model_header_.nGroup); - break; - } - case 7: { - header_2_dot_7::RuntimeEndPoint tempEndPoint2dot7; - readBits(tempEndPoint2dot7, is); - endPoint = header_latest::RuntimeEndPoint(tempEndPoint2dot7); - break; - } - case 8: - case 9: - readNBytes(&endPoint, sizeof(header_latest::RuntimeEndPoint), is); - break; - default: - THROW_GNA_EXCEPTION - << "Imported file unsupported. minor version should have values in range 1 to 9 and is: " - << model_header_.version.minor; - } - break; - default: - THROW_GNA_EXCEPTION << "Imported file unsupported. Import for files with major version equal to: " - << model_header_.version.major << " is not implemented"; - } - - return endPoint; -} - -#define offsetFromBase(field) getOffsetFromBase(field, #field) - -inline bool IsEmptyTensor(const Gna2Tensor& t) { - return t.Type == Gna2DataTypeNone && t.Data == nullptr && t.Layout[0] == '\0' && t.Mode == Gna2TensorModeDefault && - t.Shape.NumberOfDimensions == 0; -} - -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::Import(void* basePointer, - size_t gnaGraphSize, - std::istream& is, - GnaInputs& inputs, - GnaOutputs& outputs, - TranspositionInfoMap& inputsTranspositionInfo, - TranspositionInfoMap& outputsTranspositionInfo, - std::string& libVersionFromFile) { - is.exceptions(std::istream::failbit); - // 2. Read inputs names - if (model_header_.version.major == 2) { - for (uint32_t inputIndex = 0; inputIndex < model_header_.nInputs; inputIndex++) { - std::string name = - (model_header_.version.minor >= 3) ? readString(is) : std::string("input" + std::to_string(inputIndex)); - inputs[name] = InputDesc(name); - } - // Plugin uses ngraph pre/post-processing function to transpose inputs/outputs starting from version 2.9 - if (model_header_.version.minor >= 5 && model_header_.version.minor <= 8) { - // 3. Read transposition input info - for (uint32_t inputIx = 0; inputIx < model_header_.nTransposeInputs; ++inputIx) { - std::string inputName; - std::vector transpositionInfo; - ImportTranspositionInfo(is, inputName, transpositionInfo); - inputsTranspositionInfo[inputName] = transpositionInfo; - } - // 4. Read transposition output info - for (uint32_t outputIx = 0; outputIx < model_header_.nTransposeOutputs; ++outputIx) { - std::string outputName; - std::vector transpositionInfo; - ImportTranspositionInfo(is, outputName, transpositionInfo); - outputsTranspositionInfo[outputName] = transpositionInfo; - } - } - } - // 5. Read Inputs endpoints - ImportNodes(is, basePointer, inputs); - // 6. Read output names - if (model_header_.version.major == 2) { - for (uint32_t outputIndex = 0; outputIndex < model_header_.nOutputs; outputIndex++) { - std::string name = (model_header_.version.minor >= 3) ? readString(is) - : std::string("output" + std::to_string(outputIndex)); - outputs[name] = OutputDesc(name); - } - } - // 7. Read outputs - ImportNodes(is, basePointer, outputs); - - for (auto operation = gna2model_->Operations; operation != gna2model_->Operations + gna2model_->NumberOfOperations; - ++operation) { - 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); - if (IsEmptyTensor(t)) { - operation->Operands[i] = nullptr; - } else { - operation->Operands[i] = static_cast(gnaUserAllocator(sizeof(Gna2Tensor))); - t.Data = offsetToPointer(basePointer, reinterpret_cast(t.Data)); - const_cast(*operation->Operands[i]) = t; - } - } - readBits(operation->NumberOfParameters, is); - switch (operation->Type) { - case Gna2OperationTypeElementWiseAffine: - case Gna2OperationTypeFullyConnectedAffine: - case Gna2OperationTypeConvolution: - case Gna2OperationTypeCopy: - case Gna2OperationTypeTransposition: - break; - case Gna2OperationTypeRecurrent: - THROW_GNA_EXCEPTION << "Importing of recurrent operation not supported"; - default: - THROW_GNA_EXCEPTION << "Importing of unknown GNA operation type(" << operation->Type << ") not supported"; - } - if (operation->NumberOfParameters > 0) - operation->Parameters = - static_cast(gnaUserAllocator(sizeof(void*) * operation->NumberOfParameters)); - else - operation->Parameters = nullptr; - for (uint32_t i = 0; i < operation->NumberOfParameters; i++) { - uint32_t paramSize = 0; - readBits(paramSize, is); - IE_ASSERT(operation->Parameters != nullptr); - if (paramSize == 0) { - IE_ASSERT(operation->Parameters != nullptr); - operation->Parameters[i] = nullptr; - continue; - } - operation->Parameters[i] = gnaUserAllocator(paramSize); - readNBytes(operation->Parameters[i], paramSize, is); - - if (GnaParamSize.at(operation->Type).size() <= i) { - THROW_GNA_EXCEPTION << "Cannot import parameter of index: " << i; - } - if (paramSize != GnaParamSize.at(operation->Type).at(i)) { - THROW_GNA_EXCEPTION << "Parameter size mismatch on import: " << i; - } - } - } - - // writing memory information - uint32_t nStates = 0; - readBits(nStates, is); - if (pstates_ != nullptr) { - pstates_->resize(nStates); - } - - for (uint32_t i = 0; i != nStates; i++) { - void* pSegment; - if (model_header_.version.major == 2) { - if (model_header_.version.minor < 6) { - readOffset(pSegment, basePointer, is); - uint32_t segmentSz = 0; - readBits(segmentSz, is); - if (pstates_) { - (*pstates_)[i] = std::make_tuple(pSegment, segmentSz, "noname", 1.0f); - } - } else { - readOffset(pSegment, basePointer, is); - uint32_t segmentSz = 0; - readBits(segmentSz, is); - uint32_t nameSize = 0; - readNBits<32>(nameSize, is); - std::string inName(nameSize, '\0'); - readNBytes(&inName[0], nameSize, is); - float scale_factor = 1.0f; - readBits(scale_factor, is); - if (pstates_) { - (*pstates_)[i] = std::make_tuple(pSegment, segmentSz, inName.substr(0, nameSize - 1), scale_factor); - } - } - } - } - - // once structure has been read lets read whole gna graph - is.read(reinterpret_cast(basePointer), gnaGraphSize); - - // read OV and GNA versions if available in model file - if (model_header_.version.major == 2 && model_header_.version.minor >= 8) { - libVersionFromFile = version_.Import(is); - } -} - -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) { - header_latest::RuntimeEndPoint ep; - ep.elements_count = desc.num_elements; - ep.scaleFactor = desc.scale_factor; - ep.element_size = static_cast(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 = static_cast(desc.dims.size()); - for (size_t i = 0; i < ep.shape.NumberOfDimensions; ++i) { - ep.shape.Dimensions[i] = static_cast(desc.dims[i]); - } - return ep; - }; - - /** - * writing header - */ - header_latest::ModelHeader header; - header.gnam[0] = 'G'; - header.gnam[1] = 'N'; - header.gnam[2] = 'A'; - header.gnam[3] = 'M'; - header.headerSize = sizeof(header_latest::ModelHeader); - header.gnaMemSize = gnaGraphSize; - header.layersCount = layers.size(); - header.nGroup = 1; // just to support the old models - header.nInputs = static_cast(inputs_.size()); - header.nOutputs = static_cast(outputs_.size()); - header.nTransposeInputs = static_cast(inputs_transpose_info_.size()); - header.nTransposeOutputs = static_cast(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 - removed in v.2.9 - // 4. Write transposition output info - removed in v.2.9 - // 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); - } - // write pre-processing model - if (input.pre_post_process_model) { - write_pre_processing_model(input.pre_post_process_model, os); - } else { - // write empty string to detect that model is absent during the import - writeString("", 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); - } - - // write post-processing model - if (output.pre_post_process_model) { - write_pre_processing_model(output.pre_post_process_model, os); - } else { - // write empty string to detect that model is absent during the import - writeString("", 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 = static_cast(strlen(name.c_str()) + 1); - writeBits(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); -} - -template -void GNAModelSerial::ImportNodes(std::istream& is, void* base_ptr, T& nodes) { - for (auto& node : nodes.Get()) { - header_latest::RuntimeEndPoint ep = ReadEndPoint(is); - - node.ptrs.push_back(reinterpret_cast(reinterpret_cast(base_ptr) + ep.descriptor_offset)); - node.orientation = ep.orientation; - node.num_elements = ep.elements_count; - node.scale_factor = ep.scaleFactor; - node.model_precision = - InferenceEngine::Precision(static_cast(ep.precision)); - node.set_precision(ep.element_size); - node.model_layout = static_cast(ep.layout); - node.allocated_size = node.get_required_size(); - - auto inputDims = InferenceEngine::SizeVector(); - for (uint32_t i = 0; i < ep.shape.NumberOfDimensions; ++i) { - inputDims.push_back(ep.shape.Dimensions[i]); - } - node.dims = inputDims; - - // read tensor names - for (uint8_t tId = 0; tId < ep.tensor_names_count; ++tId) { - node.tensor_names.insert(readString(is)); - } - AppendTensorNameIfNeeded(node); - - // read pre-sprocessing model - if (model_header_.version.major == 2 && model_header_.version.minor >= 9) { - std::string ir_xml_str = readString(is); - if (!ir_xml_str.empty()) { - // read IR bin - size_t ir_bin_size = 0; - readBits(ir_bin_size, is); - - ov::Tensor ir_bin_tensor(ov::element::u8, ov::Shape({ir_bin_size})); - readNBytes(ir_bin_tensor.data(), static_cast(ir_bin_size), is); - - // restore model - ov::Core core; - node.pre_post_process_model = core.read_model(ir_xml_str, ir_bin_tensor); - } - } - } -} - -void GNAModelSerial::ImportTranspositionInfo(std::istream& is, - std::string& name, - std::vector& transpositionInfo) { - uint32_t nameSize = 0; - readNBits<32>(nameSize, is); - name.resize(nameSize, '\0'); - readNBytes(&name[0], nameSize, is); - uint32_t transposeFragmentsSize = 0; - readNBits<32>(transposeFragmentsSize, is); - for (uint32_t rotFragmIx = 0; rotFragmIx < transposeFragmentsSize; ++rotFragmIx) { - TranspositionInfo fragmentTranspositionInfo; - readNBytes(&fragmentTranspositionInfo, sizeof(TranspositionInfo), is); - transpositionInfo.push_back(fragmentTranspositionInfo); - } -} - -void GNAModelSerial::AppendTensorNameIfNeeded(GnaDesc& nodeDesc) const { - static constexpr header_2_dot_8::ModelHeader::Version kHasTensorNamesVersion; - - if (header_latest::IsFirstVersionLower(model_header_.version, kHasTensorNamesVersion) && - nodeDesc.tensor_names.empty()) { - nodeDesc.tensor_names.insert(nodeDesc.name); - } -} diff --git a/src/plugins/intel_gna/src/serial/gna_model_serial.hpp b/src/plugins/intel_gna/src/serial/gna_model_serial.hpp deleted file mode 100644 index 09de53cddc1..00000000000 --- a/src/plugins/intel_gna/src/serial/gna_model_serial.hpp +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -#include "descriptions/gna_desc.hpp" -#include "gna2-model-api.h" -#include "gna_device_allocation.hpp" -#include "pre_post_process/transposition_info.hpp" -#include "serial/headers/latest/gna_model_header.hpp" - -namespace ov { -namespace intel_gna { - -using TranspositionInfo = pre_post_processing::TranspositionInfo; -using TranspositionInfoMap = pre_post_processing::TranspositionInfoMap; - -/** - * @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_latest::ModelHeader model_header_; - GNAVersionSerializer version_; - - template - void ImportNodes(std::istream& is, void* basePtr, T& inputs); // inputs or outputs - - void ImportTranspositionInfo(std::istream& is, - std::string& name, - std::vector& transpositionInfo); - - /** - * @brief Update input or output description to support importing of < 2.8 format where tensor_names were not - * present - * @param nodeDesc input or output description to be appended - */ - 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_latest::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; - } - - /** - * @brief calculate memory required for import gna graph - * @param is - opened input stream - * @return - */ - static ov::intel_gna::header_latest::ModelHeader ReadHeader(std::istream& is); - - ov::intel_gna::header_latest::RuntimeEndPoint ReadEndPoint(std::istream& is); - - /** - * @brief Import model from FS into preallocated buffer, - * buffers for pLayers, and pStructs are allocated here and required manual deallocation using mm_free - * @param ptr_nnet - * @param basePointer - * @param is - stream without header structure - TBD heder might be needed - */ - void Import(void* basePointer, - size_t gnaGraphSize, - std::istream& is, - ov::intel_gna::GnaInputs& inputs, - ov::intel_gna::GnaOutputs& outputs, - TranspositionInfoMap& inputstranspositionInfo, - TranspositionInfoMap& outputstranspositionInfo, - std::string& modelLibVersion); - - /** - * save gna graph to an outpus stream - * @param allocations - * @param os - */ - void Export(const GnaAllocations& allocations, std::ostream& os) const; -}; - -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/serial/headers/2dot1/gna_model_header.hpp b/src/plugins/intel_gna/src/serial/headers/2dot1/gna_model_header.hpp deleted file mode 100644 index 0357f433a25..00000000000 --- a/src/plugins/intel_gna/src/serial/headers/2dot1/gna_model_header.hpp +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "backend/dnn_types.hpp" - -#pragma pack(push, 1) - -namespace ov { -namespace intel_gna { -namespace header_2_dot_1 { - -/** - * @brief Header version 2.1 - */ -struct ModelHeader { - /** - *@brief MagicNumber – GNAM in ascii table, equals to hex 0x474e414d - */ - char gnam[4] = {}; - /** - * @brief if header size is not equal to sizeof ModelHeader - some reserved data append in the end of header - * usually it is an indicator of working with version of model different that is current export function produce - */ - uint32_t headerSize = 0u; - struct Version { - /** - * @details Version of format Major – unsigned int, ex: 0x0001 - * every change in the header or in the layers definition should be reflected in version change - * for backward compatibility new parsers can read old versions of model with certain restrictions - */ - uint16_t major = 2u; - /** - * @details Version of Format Minor – unsigned int, corresponding to build revision for example - * changes in minor version are not affected layout of model - */ - uint32_t minor = 1u; - } version; - /** - * @brief Memory required to be allocated using GNAAlloc() - */ - uint64_t gnaMemSize = 0ull; - /** - * @brief Number of GNA Layers - */ - uint64_t layersCount = 0ull; - /** - * @brief Grouping level - */ - uint32_t nGroup = 0u; - /** - * Convolution related setting - they are affecting input transformation - */ - uint32_t nRotateRows = 0u; - uint32_t nRotateColumns = 0u; - - uint32_t nInputs = 0u; - uint32_t nOutputs = 0u; - - /** - * Reserved Data might be here - */ -}; -#pragma pack(pop) - -/* - * In runtime endpoint mostly same as in serial version, except of descriptor field - */ -struct RuntimeEndPoint { - /** - * if scale factor is different then pased into infer , network might need to be requantized - */ - float scaleFactor = 0; - /** - * Pointer descriptor - */ - void* descriptor_ptr = nullptr; - /** - * Endpoint resolution in bytes. - */ - uint32_t element_size = 0; - /** - * Number of elements - */ - uint32_t elements_count = 0; - /** - * Offset in bytes of pointer descriptor - */ - uint64_t descriptor_offset = 0ull; - - intel_dnn_orientation_t orientation = kDnnUnknownOrientation; - - RuntimeEndPoint() = default; - RuntimeEndPoint(double scaleFactor, - void* descriptor_ptr, - uint32_t element_size, - uint32_t elements_count, - intel_dnn_orientation_t orientation) - : scaleFactor(static_cast(scaleFactor)), - descriptor_ptr(descriptor_ptr), - element_size(element_size), - elements_count(elements_count), - orientation(orientation) {} -}; - -} // namespace header_2_dot_1 -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/serial/headers/2dot2/gna_model_header.hpp b/src/plugins/intel_gna/src/serial/headers/2dot2/gna_model_header.hpp deleted file mode 100644 index 51cb6e5d037..00000000000 --- a/src/plugins/intel_gna/src/serial/headers/2dot2/gna_model_header.hpp +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "backend/dnn_types.hpp" -#include "serial/headers/2dot1/gna_model_header.hpp" - -#pragma pack(push, 1) - -namespace ov { -namespace intel_gna { -namespace header_2_dot_2 { - -/** - * @brief Header version 2.2 - */ -struct ModelHeader { - /** - *@brief MagicNumber – GNAM in ascii table, equals to hex 0x474e414d - */ - char gnam[4] = {}; - /** - * @brief if header size is not equal to sizeof ModelHeader - some reserved data append in the end of header - * usually it is an indicator of working with version of model different that is current export function produce - */ - uint32_t headerSize = 0u; - struct Version { - /** - * @details Version of format Major – unsigned int, ex: 0x0001 - * every change in the header or in the layers definition should be reflected in version change - * for backward compatibility new parsers can read old versions of model with certain restrictions - */ - uint16_t major = 2u; - /** - * @details Version of Format Minor – unsigned int, corresponding to build revision for example - * changes in minor version are not affected layout of model - */ - uint32_t minor = 2u; - } version; - /** - * @brief Memory required to be allocated using GNAAlloc() - */ - uint64_t gnaMemSize = 0ull; - /** - * @brief Number of GNA Layers - */ - uint64_t layersCount = 0ull; - /** - * @brief Grouping level - */ - uint32_t nGroup = 0u; - /** - * Convolution related setting - they are affecting input transformation - */ - uint32_t nRotateRows = 0u; - uint32_t nRotateColumns = 0u; - bool doRotateInput = false; - - uint32_t nInputs = 0u; - uint32_t nOutputs = 0u; - - /** - * Reserved Data might be here - */ - ModelHeader() = default; - ModelHeader(header_2_dot_1::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - } -}; -#pragma pack(pop) - -/* - * In runtime endpoint mostly same as in serial version, except of descriptor field - */ -struct RuntimeEndPoint { - /** - * if scale factor is different then pased into infer , network might need to be requantized - */ - float scaleFactor = 0; - /** - * Pointer descriptor - */ - void* descriptor_ptr = nullptr; - /** - * Endpoint resolution in bytes. - */ - uint32_t element_size = 0; - /** - * Number of elements - */ - uint32_t elements_count = 0; - /** - * Offset in bytes of pointer descriptor - */ - uint64_t descriptor_offset = 0ull; - - intel_dnn_orientation_t orientation = kDnnUnknownOrientation; - - RuntimeEndPoint() = default; - RuntimeEndPoint(float scaleFactor, - void* descriptor_ptr, - uint32_t element_size, - uint32_t elements_count, - intel_dnn_orientation_t orientation) - : scaleFactor(scaleFactor), - descriptor_ptr(descriptor_ptr), - element_size(element_size), - elements_count(elements_count), - orientation(orientation) {} -}; - -} // namespace header_2_dot_2 -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/serial/headers/2dot3/gna_model_header.hpp b/src/plugins/intel_gna/src/serial/headers/2dot3/gna_model_header.hpp deleted file mode 100644 index aab0bb96030..00000000000 --- a/src/plugins/intel_gna/src/serial/headers/2dot3/gna_model_header.hpp +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "backend/dnn_types.hpp" -#include "serial/headers/2dot1/gna_model_header.hpp" - -#pragma pack(push, 1) - -namespace ov { -namespace intel_gna { -namespace header_2_dot_3 { - -/** - * @brief Header version 2.3 - */ -struct ModelHeader { - /** - *@brief MagicNumber – GNAM in ascii table, equals to hex 0x474e414d - */ - char gnam[4] = {}; - /** - * @brief if header size is not equal to sizeof ModelHeader - some reserved data append in the end of header - * usually it is an indicator of working with version of model different that is current export function produce - */ - uint32_t headerSize = 0u; - struct Version { - /** - * @details Version of format Major – unsigned int, ex: 0x0001 - * every change in the header or in the layers definition should be reflected in version change - * for backward compatibility new parsers can read old versions of model with certain restrictions - */ - uint16_t major = 2u; - /** - * @details Version of Format Minor – unsigned int, corresponding to build revision for example - * changes in minor version are not affected layout of model - */ - uint32_t minor = 3u; - } version; - /** - * @brief Memory required to be allocated using GNAAlloc() - */ - uint64_t gnaMemSize = 0ull; - /** - * @brief Number of GNA Layers - */ - uint64_t layersCount = 0ull; - /** - * @brief Grouping level - */ - uint32_t nGroup = 0u; - /** - * Convolution related setting - they are affecting input transformation - */ - uint32_t nRotateRows = 0u; - uint32_t nRotateColumns = 0u; - bool doRotateInput = false; - - uint32_t nInputs = 0u; - uint32_t nOutputs = 0u; - - /** - * Reserved Data might be here - */ - ModelHeader() = default; - ModelHeader(header_2_dot_1::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - } -}; -#pragma pack(pop) - -/* - * In runtime endpoint mostly same as in serial version, except of descriptor field - */ -struct RuntimeEndPoint { - /** - * if scale factor is different then pased into infer , network might need to be requantized - */ - float scaleFactor = 0; - /** - * Pointer descriptor - */ - void* descriptor_ptr = nullptr; - /** - * Endpoint resolution in bytes. - */ - uint32_t element_size = 0; - /** - * Number of elements - */ - uint32_t elements_count = 0; - /** - * Offset in bytes of pointer descriptor - */ - uint64_t descriptor_offset = 0ull; - - intel_dnn_orientation_t orientation = kDnnUnknownOrientation; - - RuntimeEndPoint() = default; - RuntimeEndPoint(double scaleFactor, - void* descriptor_ptr, - uint32_t element_size, - uint32_t elements_count, - intel_dnn_orientation_t orientation) - : scaleFactor(static_cast(scaleFactor)), - descriptor_ptr(descriptor_ptr), - element_size(element_size), - elements_count(elements_count), - orientation(orientation) {} -}; - -} // namespace header_2_dot_3 -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/serial/headers/2dot4/gna_model_header.hpp b/src/plugins/intel_gna/src/serial/headers/2dot4/gna_model_header.hpp deleted file mode 100644 index 0cf4c218a6a..00000000000 --- a/src/plugins/intel_gna/src/serial/headers/2dot4/gna_model_header.hpp +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "backend/dnn_types.hpp" -#include "serial/headers/2dot3/gna_model_header.hpp" - -#pragma pack(push, 1) - -namespace ov { -namespace intel_gna { -namespace header_2_dot_4 { - -/** - * @brief Header version 2.4 - */ -struct ModelHeader { - /** - *@brief MagicNumber – GNAM in ascii table, equals to hex 0x474e414d - */ - char gnam[4] = {}; - /** - * @brief if header size is not equal to sizeof ModelHeader - some reserved data append in the end of header - * usually it is an indicator of working with version of model different that is current export function produce - */ - uint32_t headerSize = 0u; - struct Version { - /** - * @details Version of format Major – unsigned int, ex: 0x0001 - * every change in the header or in the layers definition should be reflected in version change - * for backward compatibility new parsers can read old versions of model with certain restrictions - */ - uint16_t major = 2u; - /** - * @details Version of Format Minor – unsigned int, corresponding to build revision for example - * changes in minor version are not affected layout of model - */ - uint32_t minor = 4u; - } version; - /** - * @brief Memory required to be allocated using GNAAlloc() - */ - uint64_t gnaMemSize = 0ull; - /** - * @brief Number of GNA Layers - */ - uint64_t layersCount = 0ull; - /** - * @brief Grouping level - */ - uint32_t nGroup = 0u; - /** - * Convolution related setting - they are affecting input transformation - */ - uint32_t nRotateRows = 0u; - uint32_t nRotateColumns = 0u; - bool doRotateInput = false; - - uint32_t nInputs = 0u; - uint32_t nOutputs = 0u; - - /** - * Convolution related setting - they are affecting output transformation - */ - uint32_t nRotateOutputRows = 0u; - uint32_t nRotateOutputColumns = 0u; - bool doRotateOutput = false; - - /** - * Reserved Data might be here - */ - ModelHeader() = default; - ModelHeader(header_2_dot_1::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - version.minor = old.version.minor; - } - ModelHeader(header_2_dot_3::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - version.minor = old.version.minor; - } -}; -#pragma pack(pop) - -/* - * In runtime endpoint mostly same as in serial version, except of descriptor field - */ -struct RuntimeEndPoint { - /** - * if scale factor is different then pased into infer , network might need to be requantized - */ - float scaleFactor = 0; - /** - * Pointer descriptor - */ - void* descriptor_ptr = nullptr; - /** - * Endpoint resolution in bytes. - */ - uint32_t element_size = 0; - /** - * Number of elements - */ - uint32_t elements_count = 0; - /** - * Offset in bytes of pointer descriptor - */ - uint64_t descriptor_offset = 0ull; - - intel_dnn_orientation_t orientation = kDnnUnknownOrientation; - - RuntimeEndPoint() = default; - RuntimeEndPoint(double scaleFactor, - void* descriptor_ptr, - uint32_t element_size, - uint32_t elements_count, - intel_dnn_orientation_t orientation) - : scaleFactor(static_cast(scaleFactor)), - descriptor_ptr(descriptor_ptr), - element_size(element_size), - elements_count(elements_count), - orientation(orientation) {} -}; - -} // namespace header_2_dot_4 -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/serial/headers/2dot5/gna_model_header.hpp b/src/plugins/intel_gna/src/serial/headers/2dot5/gna_model_header.hpp deleted file mode 100644 index d58ae904a13..00000000000 --- a/src/plugins/intel_gna/src/serial/headers/2dot5/gna_model_header.hpp +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "backend/dnn_types.hpp" -#include "gna_data_types.hpp" -#include "serial/headers/2dot4/gna_model_header.hpp" -#pragma pack(push, 1) - -namespace ov { -namespace intel_gna { -namespace header_2_dot_5 { - -/** - * @brief Header version 2.5 - */ -struct ModelHeader { - /** - *@brief MagicNumber – GNAM in ascii table, equals to hex 0x474e414d - */ - char gnam[4] = {}; - /** - * @brief if header size is not equal to sizeof ModelHeader - some reserved data append in the end of header - * usually it is an indicator of working with version of model different that is current export function produce - */ - uint32_t headerSize = 0u; - struct Version { - /** - * @details Version of format Major – unsigned int, ex: 0x0001 - * every change in the header or in the layers definition should be reflected in version change - * for backward compatibility new parsers can read old versions of model with certain restrictions - */ - uint16_t major = 2u; - /** - * @details Version of Format Minor – unsigned int, corresponding to build revision for example - * changes in minor version are not affected layout of model - */ - uint32_t minor = 5u; - } version; - /** - * @brief Memory required to be allocated using GNAAlloc() - */ - uint64_t gnaMemSize = 0ull; - /** - * @brief Number of GNA Layers - */ - uint64_t layersCount = 0ull; - /** - * @brief Grouping level - */ - uint32_t nGroup = 0u; - - /** - * Convolution related setting - they are affecting input transformation - */ - uint32_t nRotateRows = 0u; - uint32_t nRotateColumns = 0u; - bool doRotateInput = false; - - uint32_t nInputs = 0u; - uint32_t nOutputs = 0u; - - /** - * Convolution related setting - they are affecting output transformation - */ - uint32_t nRotateOutputRows = 0u; - uint32_t nRotateOutputColumns = 0u; - bool doRotateOutput = false; - - uint32_t nTransposeInputs = 0u; - uint32_t nTransposeOutputs = 0u; - - /** - * Reserved Data might be here - */ - ModelHeader() = default; - ModelHeader(header_2_dot_1::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - version.minor = old.version.minor; - } - ModelHeader(header_2_dot_4::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - nRotateOutputRows = old.nRotateOutputRows; - nRotateOutputColumns = old.nRotateOutputColumns; - doRotateOutput = old.doRotateOutput; - version.minor = old.version.minor; - } - ModelHeader(header_2_dot_3::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - version.minor = old.version.minor; - } -}; -#pragma pack(pop) - -/* - * In runtime endpoint mostly same as in serial version, except of descriptor field - */ -struct RuntimeEndPoint { - /** - * if scale factor is different then pased into infer , network might need to be requantized - */ - float scaleFactor = 0; - /** - * Pointer descriptor - */ - void* descriptor_ptr = nullptr; - /** - * Endpoint resolution in bytes. - */ - uint32_t element_size = 0; - /** - * Number of elements - */ - uint32_t elements_count = 0; - /** - * Offset in bytes of pointer descriptor - */ - uint64_t descriptor_offset = 0ull; - - intel_dnn_orientation_t orientation = kDnnUnknownOrientation; - - RuntimeEndPoint() = default; - RuntimeEndPoint(float scaleFactor, - void* descriptor_ptr, - uint32_t element_size, - uint32_t elements_count, - intel_dnn_orientation_t orientation) - : scaleFactor(scaleFactor), - descriptor_ptr(descriptor_ptr), - element_size(element_size), - elements_count(elements_count), - orientation(orientation) {} -}; - -} // namespace header_2_dot_5 -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/serial/headers/2dot6/gna_model_header.hpp b/src/plugins/intel_gna/src/serial/headers/2dot6/gna_model_header.hpp deleted file mode 100644 index a46746c6b84..00000000000 --- a/src/plugins/intel_gna/src/serial/headers/2dot6/gna_model_header.hpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "backend/dnn_types.hpp" -#include "gna_data_types.hpp" -#include "serial/headers/2dot4/gna_model_header.hpp" -#pragma pack(push, 1) - -namespace ov { -namespace intel_gna { -namespace header_2_dot_6 { - -/** - * @brief Header version 2.6 - */ -struct ModelHeader { - /** - *@brief MagicNumber – GNAM in ascii table, equals to hex 0x474e414d - */ - char gnam[4] = {}; - /** - * @brief if header size is not equal to sizeof ModelHeader - some reserved data append in the end of header - * usually it is an indicator of working with version of model different that is current export function produce - */ - uint32_t headerSize = 0u; - struct Version { - /** - * @details Version of format Major – unsigned int, ex: 0x0001 - * every change in the header or in the layers definition should be reflected in version change - * for backward compatibility new parsers can read old versions of model with certain restrictions - */ - uint16_t major = 2u; - /** - * @details Version of Format Minor – unsigned int, corresponding to build revision for example - * changes in minor version are not affected layout of model - */ - uint32_t minor = 6u; - } version; - /** - * @brief Memory required to be allocated using GNAAlloc() - */ - uint64_t gnaMemSize = 0ull; - /** - * @brief Number of GNA Layers - */ - uint64_t layersCount = 0ull; - /** - * @brief Grouping level - */ - uint32_t nGroup = 0u; - - /** - * Convolution related setting - they are affecting input transformation - */ - uint32_t nRotateRows = 0u; - uint32_t nRotateColumns = 0u; - bool doRotateInput = false; - - uint32_t nInputs = 0u; - uint32_t nOutputs = 0u; - - /** - * Convolution related setting - they are affecting output transformation - */ - uint32_t nRotateOutputRows = 0u; - uint32_t nRotateOutputColumns = 0u; - bool doRotateOutput = false; - - uint32_t nTransposeInputs = 0u; - uint32_t nTransposeOutputs = 0u; - - /** - * Reserved Data might be here - */ - ModelHeader() = default; - ModelHeader(header_2_dot_1::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - version.minor = old.version.minor; - } - ModelHeader(header_2_dot_4::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - nRotateOutputRows = old.nRotateOutputRows; - nRotateOutputColumns = old.nRotateOutputColumns; - doRotateOutput = old.doRotateOutput; - version.minor = old.version.minor; - } -}; -#pragma pack(pop) - -/* - * In runtime endpoint mostly same as in serial version, except of descriptor field - */ -struct RuntimeEndPoint { - /** - * if scale factor is different then pased into infer , network might need to be requantized - */ - float scaleFactor = 0; - /** - * Pointer descriptor - */ - void* descriptor_ptr = nullptr; - /** - * Endpoint resolution in bytes. - */ - uint32_t element_size = 0; - /** - * Number of elements - */ - uint32_t elements_count = 0; - /** - * Offset in bytes of pointer descriptor - */ - uint64_t descriptor_offset = 0ull; - - intel_dnn_orientation_t orientation = kDnnUnknownOrientation; - - RuntimeEndPoint() = default; - RuntimeEndPoint(double scaleFactor, - void* descriptor_ptr, - uint32_t element_size, - uint32_t elements_count, - intel_dnn_orientation_t orientation) - : scaleFactor(static_cast(scaleFactor)), - descriptor_ptr(descriptor_ptr), - element_size(element_size), - elements_count(elements_count), - orientation(orientation) {} -}; - -} // namespace header_2_dot_6 -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/serial/headers/2dot7/gna_model_header.hpp b/src/plugins/intel_gna/src/serial/headers/2dot7/gna_model_header.hpp deleted file mode 100644 index 3edf9bfd1af..00000000000 --- a/src/plugins/intel_gna/src/serial/headers/2dot7/gna_model_header.hpp +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "backend/dnn_types.hpp" -#include "gna_data_types.hpp" -#include "serial/headers/2dot4/gna_model_header.hpp" -#include "serial/headers/2dot6/gna_model_header.hpp" - -#pragma pack(push, 1) - -namespace ov { -namespace intel_gna { -namespace header_2_dot_7 { - -/** - Maximal number of supported shape dimensions. - */ -#define GNA_SHAPE_MAXIMUM_NUMBER_OF_DIMENSIONS 8 - -/** - * @brief Header version 2.7 - */ -struct ModelHeader { - /** - *@brief MagicNumber – GNAM in ascii table, equals to hex 0x474e414d - */ - char gnam[4] = {}; - /** - * @brief if header size is not equal to sizeof ModelHeader - some reserved data append in the end of header - * usually it is an indicator of working with version of model different that is current export function produce - */ - uint32_t headerSize = 0u; - struct Version { - /** - * @details Version of format Major – unsigned int, ex: 0x0001 - * every change in the header or in the layers definition should be reflected in version change - * for backward compatibility new parsers can read old versions of model with certain restrictions - */ - uint16_t major = 2u; - /** - * @details Version of Format Minor – unsigned int, corresponding to build revision for example - * changes in minor version are not affected layout of model - */ - uint32_t minor = 7u; - } version; - /** - * @brief Memory required to be allocated using GNAAlloc() - */ - uint64_t gnaMemSize = 0ull; - /** - * @brief Number of GNA Layers - */ - uint64_t layersCount = 0ull; - /** - * @brief Grouping level - * This is depricted field and used for old models only (<=2.6) - */ - uint32_t nGroup = 0u; - - /** - * Convolution related setting - they are affecting input transformation - */ - uint32_t nRotateRows = 0u; - uint32_t nRotateColumns = 0u; - bool doRotateInput = false; - - uint32_t nInputs = 0u; - uint32_t nOutputs = 0u; - - /** - * Convolution related setting - they are affecting output transformation - */ - uint32_t nRotateOutputRows = 0u; - uint32_t nRotateOutputColumns = 0u; - bool doRotateOutput = false; - - uint32_t nTransposeInputs = 0u; - uint32_t nTransposeOutputs = 0u; - - /** - * Reserved Data might be here - */ - ModelHeader() = default; - ModelHeader(header_2_dot_1::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - version.minor = old.version.minor; - } - ModelHeader(header_2_dot_4::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - nRotateOutputRows = old.nRotateOutputRows; - nRotateOutputColumns = old.nRotateOutputColumns; - doRotateOutput = old.doRotateOutput; - version.minor = old.version.minor; - } -}; -#pragma pack(pop) - -/* - * In runtime endpoint mostly same as in serial version, except of descriptor field - */ -struct RuntimeEndPoint { - /** - * if scale factor is different then pased into infer , network might need to be requantized - */ - float scaleFactor = 0; - /** - * Pointer descriptor - */ - void* descriptor_ptr = nullptr; - /** - * Endpoint resolution in bytes. - */ - uint32_t element_size = 0; - /** - * Number of elements - */ - uint32_t elements_count = 0; - /** - * Offset in bytes of pointer descriptor - */ - uint64_t descriptor_offset = 0ull; - /** - Shape specifying dimension values. - */ - struct Shape { - /** - Number of dimensions or rank or order. - */ - uint32_t NumberOfDimensions = 0; - /** - array specifying value of each dimension. - Set all zeros for scalars. - */ - uint32_t Dimensions[GNA_SHAPE_MAXIMUM_NUMBER_OF_DIMENSIONS] = {0}; - } shape; - /** - * Blob layout - */ - uint8_t layout = InferenceEngine::Layout::NC; - /** - * Blob precision - */ - uint8_t precision = InferenceEngine::Precision::FP32; - - intel_dnn_orientation_t orientation = kDnnUnknownOrientation; - - RuntimeEndPoint() = default; - RuntimeEndPoint(const header_2_dot_6::RuntimeEndPoint& old, uint32_t ngroup) { - scaleFactor = old.scaleFactor; - descriptor_ptr = old.descriptor_ptr; - element_size = old.element_size; - elements_count = old.elements_count; - orientation = old.orientation; - layout = InferenceEngine::Layout::NC; - precision = InferenceEngine::Precision::FP32; - descriptor_offset = old.descriptor_offset; - InferenceEngine::SizeVector dims = {ngroup, elements_count / ngroup}; - shape.NumberOfDimensions = static_cast(dims.size()); - for (size_t i = 0; i < dims.size(); i++) { - shape.Dimensions[i] = static_cast(dims[i]); - } - } - RuntimeEndPoint(double scaleFactor, - void* descriptor_ptr, - uint32_t element_size, - uint32_t elements_count, - Shape shape, - uint8_t layout, - uint8_t precision, - intel_dnn_orientation_t orientation) - : scaleFactor(static_cast(scaleFactor)), - descriptor_ptr(descriptor_ptr), - element_size(element_size), - elements_count(elements_count), - shape(shape), - layout(layout), - precision(precision), - orientation(orientation) {} -}; - -} // namespace header_2_dot_7 -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/serial/headers/2dot8/gna_model_header.hpp b/src/plugins/intel_gna/src/serial/headers/2dot8/gna_model_header.hpp deleted file mode 100644 index 5021f663c17..00000000000 --- a/src/plugins/intel_gna/src/serial/headers/2dot8/gna_model_header.hpp +++ /dev/null @@ -1,217 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "backend/dnn_types.hpp" -#include "gna_data_types.hpp" -#include "serial/headers/2dot7/gna_model_header.hpp" - -#pragma pack(push, 1) - -namespace ov { -namespace intel_gna { -namespace header_2_dot_8 { - -/** - Maximal number of supported shape dimensions. - */ -#define GNA_SHAPE_MAXIMUM_NUMBER_OF_DIMENSIONS 8 - -/** - * @brief Header version 2.8 - */ -struct ModelHeader { - /** - *@brief MagicNumber – GNAM in ascii table, equals to hex 0x474e414d - */ - char gnam[4] = {}; - /** - * @brief if header size is not equal to sizeof ModelHeader - some reserved data append in the end of header - * usually it is an indicator of working with version of model different that is current export function produce - */ - uint32_t headerSize = 0u; - struct Version { - /** - * @details Version of format Major – unsigned int, ex: 0x0001 - * every change in the header or in the layers definition should be reflected in version change - * for backward compatibility new parsers can read old versions of model with certain restrictions - */ - uint16_t major = 2u; - /** - * @details Version of Format Minor – unsigned int, corresponding to build revision for example - * changes in minor version are not affected layout of model - */ - uint32_t minor = 8u; - } version; - /** - * @brief Memory required to be allocated using GNAAlloc() - */ - uint64_t gnaMemSize = 0ull; - /** - * @brief Number of GNA Layers - */ - uint64_t layersCount = 0ull; - /** - * @brief Grouping level - * This is depricted field and used for old models only (<=2.6) - */ - uint32_t nGroup = 0u; - - /** - * Convolution related setting - they are affecting input transformation - */ - uint32_t nRotateRows = 0u; - uint32_t nRotateColumns = 0u; - bool doRotateInput = false; - - uint32_t nInputs = 0u; - uint32_t nOutputs = 0u; - - /** - * Convolution related setting - they are affecting output transformation - */ - uint32_t nRotateOutputRows = 0u; - uint32_t nRotateOutputColumns = 0u; - bool doRotateOutput = false; - - uint32_t nTransposeInputs = 0u; - uint32_t nTransposeOutputs = 0u; - - /** - * Reserved Data might be here - */ - - ModelHeader() = default; - - ModelHeader(header_2_dot_1::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - version.minor = old.version.minor; - } - - ModelHeader(header_2_dot_4::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - nRotateOutputRows = old.nRotateOutputRows; - nRotateOutputColumns = old.nRotateOutputColumns; - doRotateOutput = old.doRotateOutput; - version.minor = old.version.minor; - } -}; -#pragma pack(pop) - -/* - * In runtime endpoint mostly same as in serial version, except of descriptor field - */ -struct RuntimeEndPoint { - /** - * if scale factor is different then pased into infer , network might need to be requantized - */ - float scaleFactor = 0; - /** - * Pointer descriptor - */ - void* descriptor_ptr = nullptr; - /** - * Endpoint resolution in bytes. - */ - uint32_t element_size = 0; - /** - * Number of elements - */ - uint32_t elements_count = 0; - /** - * Offset in bytes of pointer descriptor - */ - uint64_t descriptor_offset = 0ull; - /** - Shape specifying dimension values. - */ - struct Shape { - /** - Number of dimensions or rank or order. - */ - uint32_t NumberOfDimensions = 0; - /** - array specifying value of each dimension. - Set all zeros for scalars. - */ - uint32_t Dimensions[GNA_SHAPE_MAXIMUM_NUMBER_OF_DIMENSIONS] = {0}; - } shape; - /** - * Blob layout - */ - uint8_t layout = InferenceEngine::Layout::NC; - /** - * Blob precision - */ - uint8_t precision = InferenceEngine::Precision::FP32; - /** - * Number of tensor names - */ - uint8_t tensor_names_count = 0; - - intel_dnn_orientation_t orientation = kDnnUnknownOrientation; - - RuntimeEndPoint() = default; - - // support of previous versions - RuntimeEndPoint(const header_2_dot_6::RuntimeEndPoint& old, uint32_t ngroup) { - header_2_dot_7::RuntimeEndPoint ep_v7 = header_2_dot_7::RuntimeEndPoint(old, ngroup); - *this = header_2_dot_8::RuntimeEndPoint(ep_v7); - } - - RuntimeEndPoint(const header_2_dot_7::RuntimeEndPoint& old) { - scaleFactor = old.scaleFactor; - descriptor_ptr = old.descriptor_ptr; - element_size = old.element_size; - elements_count = old.elements_count; - orientation = old.orientation; - layout = old.layout; - precision = old.precision; - descriptor_offset = old.descriptor_offset; - shape.NumberOfDimensions = old.shape.NumberOfDimensions; - for (uint32_t i = 0; i < shape.NumberOfDimensions; i++) { - shape.Dimensions[i] = old.shape.Dimensions[i]; - } - tensor_names_count = 0; - } - - RuntimeEndPoint(double scaleFactor, - void* descriptor_ptr, - uint32_t element_size, - uint32_t elements_count, - Shape shape, - uint8_t layout, - uint8_t precision, - uint8_t tensor_names_count, - intel_dnn_orientation_t orientation) - : scaleFactor(static_cast(scaleFactor)), - descriptor_ptr(descriptor_ptr), - element_size(element_size), - elements_count(elements_count), - shape(shape), - layout(layout), - precision(precision), - tensor_names_count(tensor_names_count), - orientation(orientation) {} -}; - -} // namespace header_2_dot_8 -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/serial/headers/2dot9/gna_model_header.hpp b/src/plugins/intel_gna/src/serial/headers/2dot9/gna_model_header.hpp deleted file mode 100644 index 323871c6f13..00000000000 --- a/src/plugins/intel_gna/src/serial/headers/2dot9/gna_model_header.hpp +++ /dev/null @@ -1,223 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "backend/dnn_types.hpp" -#include "gna_data_types.hpp" -#include "serial/headers/2dot8/gna_model_header.hpp" - -#pragma pack(push, 1) - -namespace ov { -namespace intel_gna { -namespace header_2_dot_9 { - -/** - Maximal number of supported shape dimensions. - */ -#define GNA_SHAPE_MAXIMUM_NUMBER_OF_DIMENSIONS 8 - -/** - * @brief Header version 2.9 - */ -struct ModelHeader { - /** - *@brief MagicNumber – GNAM in ascii table, equals to hex 0x474e414d - */ - char gnam[4] = {}; - /** - * @brief if header size is not equal to sizeof ModelHeader - some reserved data append in the end of header - * usually it is an indicator of working with version of model different that is current export function produce - */ - uint32_t headerSize = 0u; - struct Version { - /** - * @details Version of format Major – unsigned int, ex: 0x0001 - * every change in the header or in the layers definition should be reflected in version change - * for backward compatibility new parsers can read old versions of model with certain restrictions - */ - uint16_t major = 2u; - /** - * @details Version of Format Minor – unsigned int, corresponding to build revision for example - * changes in minor version are not affected layout of model - */ - uint32_t minor = 9u; - } version; - /** - * @brief Memory required to be allocated using GNAAlloc() - */ - uint64_t gnaMemSize = 0ull; - /** - * @brief Number of GNA Layers - */ - uint64_t layersCount = 0ull; - /** - * @brief Grouping level - * This is depricted field and used for old models only (<=2.6) - */ - uint32_t nGroup = 0u; - - /** - * Convolution related setting - they are affecting input transformation - */ - uint32_t nRotateRows = 0u; - uint32_t nRotateColumns = 0u; - bool doRotateInput = false; - - uint32_t nInputs = 0u; - uint32_t nOutputs = 0u; - - /** - * Convolution related setting - they are affecting output transformation - */ - uint32_t nRotateOutputRows = 0u; - uint32_t nRotateOutputColumns = 0u; - bool doRotateOutput = false; - - uint32_t nTransposeInputs = 0u; - uint32_t nTransposeOutputs = 0u; - - /** - * Reserved Data might be here - */ - - ModelHeader() = default; - - ModelHeader(header_2_dot_1::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - version.minor = old.version.minor; - } - - ModelHeader(header_2_dot_4::ModelHeader const& old) { - gnaMemSize = old.gnaMemSize; - layersCount = old.layersCount; - nGroup = old.nGroup; - nRotateRows = old.nRotateRows; - nRotateColumns = old.nRotateColumns; - nInputs = old.nInputs; - nOutputs = old.nOutputs; - nRotateOutputRows = old.nRotateOutputRows; - nRotateOutputColumns = old.nRotateOutputColumns; - doRotateOutput = old.doRotateOutput; - version.minor = old.version.minor; - } -}; -#pragma pack(pop) - -/* - * In runtime endpoint mostly same as in serial version, except of descriptor field - */ -struct RuntimeEndPoint { - /** - * if scale factor is different then pased into infer , network might need to be requantized - */ - float scaleFactor = 0; - /** - * Pointer descriptor - */ - void* descriptor_ptr = nullptr; - /** - * Endpoint resolution in bytes. - */ - uint32_t element_size = 0; - /** - * Number of elements - */ - uint32_t elements_count = 0; - /** - * Offset in bytes of pointer descriptor - */ - uint64_t descriptor_offset = 0ull; - /** - Shape specifying dimension values. - */ - struct Shape { - /** - Number of dimensions or rank or order. - */ - uint32_t NumberOfDimensions = 0; - /** - array specifying value of each dimension. - Set all zeros for scalars. - */ - uint32_t Dimensions[GNA_SHAPE_MAXIMUM_NUMBER_OF_DIMENSIONS] = {0}; - } shape; - /** - * Blob layout - */ - uint8_t layout = InferenceEngine::Layout::NC; - /** - * Blob precision - */ - uint8_t precision = InferenceEngine::Precision::FP32; - /** - * Number of tensor names - */ - uint8_t tensor_names_count = 0; - - intel_dnn_orientation_t orientation = kDnnUnknownOrientation; - - RuntimeEndPoint() = default; - - // support of previous versions - RuntimeEndPoint(const header_2_dot_6::RuntimeEndPoint& old, uint32_t ngroup) { - header_2_dot_7::RuntimeEndPoint ep_v7 = header_2_dot_7::RuntimeEndPoint(old, ngroup); - *this = header_2_dot_9::RuntimeEndPoint(ep_v7); - } - - // support of previous versions - RuntimeEndPoint(const header_2_dot_7::RuntimeEndPoint& old) { - header_2_dot_8::RuntimeEndPoint ep_v8 = header_2_dot_8::RuntimeEndPoint(old); - *this = header_2_dot_9::RuntimeEndPoint(ep_v8); - } - - RuntimeEndPoint(header_2_dot_8::RuntimeEndPoint& old) { - scaleFactor = old.scaleFactor; - descriptor_ptr = old.descriptor_ptr; - element_size = old.element_size; - elements_count = old.elements_count; - orientation = old.orientation; - layout = old.layout; - precision = old.precision; - descriptor_offset = old.descriptor_offset; - shape.NumberOfDimensions = old.shape.NumberOfDimensions; - for (uint32_t i = 0; i < shape.NumberOfDimensions; i++) { - shape.Dimensions[i] = old.shape.Dimensions[i]; - } - tensor_names_count = 0; - } - - RuntimeEndPoint(double scaleFactor, - void* descriptor_ptr, - uint32_t element_size, - uint32_t elements_count, - Shape shape, - uint8_t layout, - uint8_t precision, - uint8_t tensor_names_count, - intel_dnn_orientation_t orientation) - : scaleFactor(static_cast(scaleFactor)), - descriptor_ptr(descriptor_ptr), - element_size(element_size), - elements_count(elements_count), - shape(shape), - layout(layout), - precision(precision), - tensor_names_count(tensor_names_count), - orientation(orientation) {} -}; - -} // namespace header_2_dot_9 -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/serial/headers/latest/gna_model_header.hpp b/src/plugins/intel_gna/src/serial/headers/latest/gna_model_header.hpp deleted file mode 100644 index d86b9b81b25..00000000000 --- a/src/plugins/intel_gna/src/serial/headers/latest/gna_model_header.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "serial/headers/2dot9/gna_model_header.hpp" - -namespace ov { -namespace intel_gna { -namespace header_latest { - -using ModelHeader = header_2_dot_9::ModelHeader; -using RuntimeEndPoint = header_2_dot_9::RuntimeEndPoint; - -template -bool IsFirstVersionLower(const A& first, const B& second) { - return first.major < second.major || (first.major == second.major && first.minor < second.minor); -} - -} // namespace header_latest -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/broadcast_const.cpp b/src/plugins/intel_gna/src/transformations/broadcast_const.cpp deleted file mode 100644 index bbf9e552664..00000000000 --- a/src/plugins/intel_gna/src/transformations/broadcast_const.cpp +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/broadcast_const.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "legacy/ngraph_ops/eltwise.hpp" -#include "legacy/ngraph_ops/scaleshift.hpp" -#include "transformations/utils/transformation_helper.hpp" - -using namespace ov::intel_gna::pass; - -using Node = std::shared_ptr; -using Nodes = std::vector; -using Input = ngraph::Input; -using Inputs = std::vector; -using AxisSet = std::set; - -namespace { - -bool HasDynamicShape(Node node) { - const auto& shape = node->get_output_partial_shape(0); - return shape.is_dynamic(); -} - -/* - * really returns only NUMPY and PDPD - * since another types are filtered out in matcher pattern - */ - -ov::op::BroadcastModeSpec GetBroadcastType(Node eltwise_node) { - auto node = std::dynamic_pointer_cast(eltwise_node); - - // check if it's an ngraph::op::Eltwise layer without broadcast type info - if (!node) - return ov::op::BroadcastType::NUMPY; - - switch (node->get_autob().m_type) { - case ov::op::AutoBroadcastType::NUMPY: - return ov::op::BroadcastType::NUMPY; - case ov::op::AutoBroadcastType::PDPD: - return ov::op::BroadcastType::PDPD; - default: - return ov::op::BroadcastType::NONE; - } - - return ov::op::BroadcastType::NONE; -} - -bool DoTransformation(Node const_node_1, Node const_node_2, Node eltwise_node) { - if (HasDynamicShape(const_node_1) || (const_node_2 != nullptr && HasDynamicShape(const_node_2)) || - HasDynamicShape(eltwise_node)) - return false; - const ngraph::Shape& eltwise_out_shape = eltwise_node->get_output_tensor(0).get_shape(); - - auto broadcast_const = ngraph::opset8::Constant::create(ngraph::element::Type_t::i64, - ngraph::Shape{eltwise_out_shape.size()}, - eltwise_out_shape); - - auto new_const_node_1 = ov::op::util::make_try_fold(const_node_1, - broadcast_const, - GetBroadcastType(eltwise_node)); - - ngraph::replace_node(const_node_1, new_const_node_1); - - if (const_node_2) { - auto new_const_node_2 = ov::op::util::make_try_fold(const_node_2, - broadcast_const, - GetBroadcastType(eltwise_node)); - - ngraph::replace_node(const_node_2, new_const_node_2); - } - return true; -} - -/* - * Do not transform graph with NONE/EXPLICIT broadcast modes eltwise layer - * since that types are not broadcastable at all - */ -bool IsEltwiseAcceptable(const ngraph::Output& output) { - auto node = std::dynamic_pointer_cast(output.get_node_shared_ptr()); - if (!node) - return true; - - const ov::op::AutoBroadcastType type = node->get_autob().m_type; - return (type == ov::op::AutoBroadcastType::NUMPY || type == ov::op::AutoBroadcastType::PDPD); -} - -} // namespace - -BroadcastAddMultiplyConst::BroadcastAddMultiplyConst() { - MATCHER_SCOPE(BroadcastAddMultiplyConst); - - auto constant_1 = ngraph::pattern::wrap_type(); - auto constant_2 = ngraph::pattern::wrap_type(); - auto fake_quantize_1 = ngraph::pattern::wrap_type( - {constant_1, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - auto fake_quantize_2 = ngraph::pattern::wrap_type( - {constant_2, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - auto input1 = std::make_shared(ngraph::OutputVector{constant_1, fake_quantize_1}); - auto input2 = std::make_shared(ngraph::OutputVector{constant_2, fake_quantize_2}); - auto eltwise_left_const = ngraph::pattern:: - wrap_type( - {input1, ngraph::pattern::any_input()}, - IsEltwiseAcceptable); - auto eltwise_right_const = ngraph::pattern:: - wrap_type( - {ngraph::pattern::any_input(), input1}, - IsEltwiseAcceptable); - auto scaleshift = - ngraph::pattern::wrap_type({ngraph::pattern::any_input(), input1, input2}, - IsEltwiseAcceptable); - auto eltwise = std::make_shared( - ngraph::OutputVector{eltwise_left_const, eltwise_right_const, scaleshift}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto const_node_1 = pattern_map.at(constant_1).get_node_shared_ptr(); - auto const_it_2 = pattern_map.find(constant_2); - auto const_node_2 = (const_it_2 == std::end(pattern_map) ? nullptr : const_it_2->second.get_node_shared_ptr()); - - auto eltwise_node_it = pattern_map.find(eltwise_left_const); - if (eltwise_node_it == pattern_map.end()) - eltwise_node_it = pattern_map.find(eltwise_right_const); - if (eltwise_node_it == pattern_map.end()) - eltwise_node_it = pattern_map.find(scaleshift); - if (eltwise_node_it == pattern_map.end()) - return false; - - return DoTransformation(const_node_1, const_node_2, eltwise_node_it->second.get_node_shared_ptr()); - }; - - auto m = std::make_shared(eltwise, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/broadcast_const.hpp b/src/plugins/intel_gna/src/transformations/broadcast_const.hpp deleted file mode 100644 index 32e4d61e5b6..00000000000 --- a/src/plugins/intel_gna/src/transformations/broadcast_const.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Brodcast data in Const layer - * Transformation recognizes the following patterns - * - * Constant Any - * | | - * Eltwise - * - * Constant - * | - * FakeQuantize Any - * | | - * Eltwise - * - * Where Eltwise node is one of the: Multiply, Substract, Add or ScaleShiftIE - * There are different types of broadcasting: NONE/EXPLICIT, NUMPY and PDPD - * - * If eltwise node inputs have different shapes and one the inputs is Constant node - * we can update (broadcast) Constant to have the same shape as another input. - * Transformation doesn't modify graph structure, but modifies Constant - * examples: - * - * NUMPY broadcasting - * Eltwise non-constant shape | Constant prev shape/values | Constant new shape/values - * {3,2} {2}/{1,2} {3,2}/{1, 2, 1, 2, 1, 2} - * {2,3} {2,1}/{1,2} {2,3}/{1, 1, 1, 2, 2, 2} - * - * PDPD broadcasting - * Eltwise non-constant shape | Constant prev shape/values | Constant new shape/values - * {3,2} {3, 1}/{1,2,3} {3,2}/{1, 1, 2, 2, 3, 3} - * - * NONE/EXPLICIT broadcasting doesn't support broadcasting at all - * - * For information about broadcasting rules see - * https://github.com/openvinotoolkit/openvino/blob/master/docs/ops/broadcast_rules.md - */ -class BroadcastAddMultiplyConst : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("BroadcastAddMultiplyConst", "0"); - BroadcastAddMultiplyConst(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/convert_dwsc_to_scaleshifts.cpp b/src/plugins/intel_gna/src/transformations/convert_dwsc_to_scaleshifts.cpp deleted file mode 100644 index 3a968782cfd..00000000000 --- a/src/plugins/intel_gna/src/transformations/convert_dwsc_to_scaleshifts.cpp +++ /dev/null @@ -1,238 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/convert_dwsc_to_scaleshifts.hpp" - -#include - -#include -#include -#include -#include -#include -#include - -#include "utils/transformation_helper.hpp" - -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::pass::helper; - -static std::shared_ptr DecomposeDWSC(std::shared_ptr dwsc, - std::shared_ptr bias_const, - std::shared_ptr fq_bias, - std::shared_ptr flat_input_plane, - std::shared_ptr flat_filters_plane) { - std::shared_ptr const_zero_padding; - std::shared_ptr reshaped_bias; - ngraph::OutputVector output_chunks; - auto input_channel_count = dwsc->get_input_shape(0)[1]; - auto input_width = dwsc->get_input_shape(0)[3]; - auto output_width = dwsc->get_output_shape(0)[3]; - auto filter_width = dwsc->get_input_shape(1)[4]; - auto pads_begin = dwsc->get_pads_begin()[1]; - auto stride_width = dwsc->get_strides()[1]; - auto dilation_width = dwsc->get_dilations()[1]; - - // Constant with zero padding - if (pads_begin) { - const_zero_padding = std::make_shared(dwsc->get_element_type(), - ngraph::Shape{1, input_channel_count}, - 0); - copy_runtime_info(dwsc, const_zero_padding); - } - - // Reshape bias const - if (bias_const) { - auto bias_size = shape_size(bias_const->get_shape()); - reshaped_bias = ov::op::util::make_try_fold( - bias_const, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{2}, ngraph::Shape{1, bias_size}), - false); - } - - // Move filter over input performing multiplication and addition (scaleshift), take padding, stride, dilation and - // bias into account - for (int32_t input_position = static_cast(-pads_begin), o = 0; o < static_cast(output_width); - input_position += static_cast(stride_width), o++) { - std::shared_ptr previous_layer_output, last_layer_output; - int32_t filter_end = static_cast(input_position + filter_width * dilation_width); - bool first = true; - - filter_end = filter_end < static_cast(input_width) ? filter_end : static_cast(input_width); - - for (int32_t filter_pos = input_position, filter_idx = 0; filter_pos < filter_end; - filter_pos += static_cast(dilation_width), filter_idx++) { - if (filter_pos >= 0) { - auto conv_input_slice = - FlatCrop(flat_input_plane, filter_pos * input_channel_count, input_channel_count); - auto conv_filter_slice = - FlatCrop(flat_filters_plane, filter_idx * input_channel_count, input_channel_count); - - if (first) { - first = false; - previous_layer_output = - std::make_shared(conv_input_slice, conv_filter_slice); - copy_runtime_info(dwsc, previous_layer_output); - if (bias_const) { - previous_layer_output = - std::make_shared(previous_layer_output, reshaped_bias); - copy_runtime_info(dwsc, previous_layer_output); - previous_layer_output = InsertFQLayer(fq_bias, previous_layer_output); - } - last_layer_output = previous_layer_output; - } else { - last_layer_output = std::make_shared(conv_input_slice, conv_filter_slice); - copy_runtime_info(dwsc, last_layer_output); - last_layer_output = std::make_shared(last_layer_output, previous_layer_output); - copy_runtime_info(dwsc, last_layer_output); - previous_layer_output = last_layer_output; - } - } - } - - if (!last_layer_output) { - IE_ASSERT(const_zero_padding); - last_layer_output = const_zero_padding; - } - - output_chunks.push_back(last_layer_output); - } - - // Concat is only needed when output width > 1 - if (output_chunks.size() > 1) { - auto concat_output_plane = std::make_shared(output_chunks, 0); - copy_runtime_info(dwsc, concat_output_plane); - return concat_output_plane; - } - - return output_chunks[0].get_node_shared_ptr(); -} - -static bool Convert(std::shared_ptr leading_transpose, - std::shared_ptr dwsc_node, - std::shared_ptr bias_const_node, - std::shared_ptr fq_bias_node, - std::shared_ptr trailing_transpose) { - auto dwsc = std::dynamic_pointer_cast(dwsc_node); - auto bias_const = std::dynamic_pointer_cast(bias_const_node); - auto fq_bias = std::dynamic_pointer_cast(fq_bias_node); - - // We are looking for Transpose(NHWC->NCHW) => GroupConv => Transpose(NCHW->NHWC) - // or similar cases, so required network must be in NHWC order like in TF - if (!TransposeOrderMatches(std::dynamic_pointer_cast(leading_transpose), {0, 3, 1, 2})) - return false; - - if (!TransposeOrderMatches(std::dynamic_pointer_cast(trailing_transpose), {0, 2, 3, 1})) - return false; - - auto output_channel_count = dwsc->get_output_shape(0)[1]; - auto output_width = dwsc->get_output_shape(0)[3]; - - // Prepare flat input data - auto flat_input_plane = std::make_shared( - leading_transpose->input_value(0), - ngraph::opset7::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - ngraph::Shape{1, shape_size(dwsc->input_value(0).get_shape())}), - false); - - // Prepare flat filter data - auto filters_const = std::dynamic_pointer_cast(dwsc->get_input_node_shared_ptr(1)); - auto filters_size = shape_size(filters_const->get_shape()); - - auto transposed_filters_const = ov::op::util::make_try_fold( - filters_const, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{5}, ngraph::Shape{4, 1, 2, 3, 0})); - - auto flat_filters_plane = ov::op::util::make_try_fold( - transposed_filters_const, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{2}, ngraph::Shape{1, filters_size}), - false); - - copy_runtime_info(dwsc, {flat_input_plane, transposed_filters_const, flat_filters_plane}); - - // Convert DWSC to a set of diagonal layers - auto output_plane = DecomposeDWSC(dwsc, bias_const, fq_bias, flat_input_plane, flat_filters_plane); - - // Restore the original output shape - auto result = std::make_shared( - output_plane, - ngraph::opset7::Constant::create(ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{1, output_channel_count, 1, output_width}), - false); - copy_runtime_info(dwsc, result); - - // We need to put here the original Group Convolution layer name, so the new layer output can be used as a network - // result - std::string result_name = trailing_transpose->get_friendly_name(); - replace_node(trailing_transpose, result); - result->set_friendly_name(result_name); - - return true; -} - -static bool VerifyDWSC(const ngraph::Output& output) { - auto dwsc = output.get_node(); - - // Verify it's a 1D convolution - // Verify that filter group count == input channel count - // Verify that per group filter output channel count == 1 - if (!consumers_and_rank(1, 4)(output) || dwsc->get_input_shape(1)[3] != 1 || dwsc->get_input_shape(0)[2] != 1 || - dwsc->get_output_shape(0)[2] != 1 || dwsc->get_input_shape(1)[0] != dwsc->get_input_shape(0)[1] || - dwsc->get_input_shape(1)[1] != 1) - return false; - - return true; -} - -ConvertDWSCToScaleShifts::ConvertDWSCToScaleShifts() { - MATCHER_SCOPE(ConvertDWSCToScaleShifts); - - auto const_input = ngraph::pattern::wrap_type(); - auto leading_transpose = - ngraph::pattern::wrap_type({ngraph::pattern::any_input(), const_input}, - consumers_and_rank(1, 4)); - auto filters_const_fq = ngraph::pattern::wrap_type(ngraph::pattern::rank_equals(4)); - auto fq_filters_const = ngraph::pattern::wrap_type( - {filters_const_fq, const_input, const_input, const_input, const_input}, - consumers_and_rank(1, 4)); - auto reshape_filters_const = ngraph::pattern::wrap_type({fq_filters_const, const_input}, - ngraph::pattern::rank_equals(5)); - auto filters_const = ngraph::pattern::wrap_type(ngraph::pattern::rank_equals(5)); - auto dwsc_filters = - std::make_shared(ngraph::OutputVector{filters_const, reshape_filters_const}); - auto dwsc = - ngraph::pattern::wrap_type({leading_transpose, dwsc_filters}, VerifyDWSC); - auto bias = ngraph::pattern::wrap_type({dwsc, const_input}); - auto fq_bias = ngraph::pattern::wrap_type( - {bias, const_input, const_input, const_input, const_input}, - consumers_and_rank(1, 4)); - auto transpose_input = std::make_shared(ngraph::OutputVector{dwsc, bias, fq_bias}); - auto trailing_transpose = - ngraph::pattern::wrap_type({transpose_input, const_input}, consumers_and_rank(1, 4)); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto bias_it = pattern_map.find(bias); - auto bias_node = (bias_it == std::end(pattern_map) ? nullptr : bias_it->second.get_node_shared_ptr()); - std::shared_ptr bias_const = nullptr; - - if (bias_node && - (bias_const = VerifyBiasGetConst(pattern_map.at(dwsc).get_node_shared_ptr(), bias_node)) == nullptr) - return false; - - auto fq_bias_it = pattern_map.find(fq_bias); - auto fq_bias_node = (fq_bias_it == std::end(pattern_map) ? nullptr : fq_bias_it->second.get_node_shared_ptr()); - - return Convert(pattern_map.at(leading_transpose).get_node_shared_ptr(), - pattern_map.at(dwsc).get_node_shared_ptr(), - bias_const, - fq_bias_node, - pattern_map.at(trailing_transpose).get_node_shared_ptr()); - }; - - auto m = std::make_shared(trailing_transpose, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/convert_dwsc_to_scaleshifts.hpp b/src/plugins/intel_gna/src/transformations/convert_dwsc_to_scaleshifts.hpp deleted file mode 100644 index 80163251528..00000000000 --- a/src/plugins/intel_gna/src/transformations/convert_dwsc_to_scaleshifts.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Convert a depthwise separable convolution (represented by a GroupConvolution) to a set of ScaleShift layers - * (MatMul + Add) Additionally supported are bias and fake quantize layers. - */ -class ConvertDWSCToScaleShifts : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertDWSCToScaleShifts", "0"); - ConvertDWSCToScaleShifts(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/convert_matmul_to_pointwise_convolution.cpp b/src/plugins/intel_gna/src/transformations/convert_matmul_to_pointwise_convolution.cpp deleted file mode 100644 index fc70a435044..00000000000 --- a/src/plugins/intel_gna/src/transformations/convert_matmul_to_pointwise_convolution.cpp +++ /dev/null @@ -1,245 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "transformations/convert_matmul_to_pointwise_convolution.hpp" - -#include -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "layers/gna_permute.hpp" -#include "log/log.hpp" - -using namespace ov::intel_gna; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::limitations; - -static bool BiasValidation(const ngraph::Output& output) { - auto bias_output_shape = output.get_node()->get_output_shape(0); - if (bias_output_shape.size() > 4) { - log::debug() << "bias output shape (" << output.get_node()->get_friendly_name() << ") is more than 4\n"; - return false; - } - - if (bias_output_shape.size() == 1) { - return true; - } - - return std::count_if(bias_output_shape.begin(), bias_output_shape.end(), [](size_t el) { - return el > 1; - }) < 2; -} - -static std::tuple VerifyAndGetConvParams( - std::shared_ptr matmul_node) { - auto input1_shape = matmul_node->get_input_shape(0); - auto input2_shape = matmul_node->get_input_shape(1); - auto output_shape = matmul_node->get_output_shape(0); - if (input1_shape.size() == 3 && input1_shape.front() == 1) { - input1_shape.erase(std::begin(input1_shape)); - } - - if (input1_shape.size() != 2 || input2_shape.size() != 2 || output_shape.size() < 2) { - return std::make_tuple(false, 0, 0, 0); - } - - // Check if MatMul or corresponding pointwise convolution are supported by GNA - const uint32_t width = static_cast(input1_shape.front()); - const uint32_t in_channels = static_cast(input2_shape.back()); - const uint32_t out_channels = static_cast(input2_shape.front()); - if (input1_shape.front() <= Limitations::kAffineMaxBatchSize || - out_channels % Limitations::kConvFiltersNumDivider != 0 || out_channels > Limitations::kConvMaxFiltersNum || - in_channels > Limitations::kConvFilterMaxSize) { - return std::make_tuple(false, 0, 0, 0); - } - - return std::make_tuple(true, width, in_channels, out_channels); -} - -static bool Convert(std::shared_ptr matmul_node, - std::shared_ptr add, - std::shared_ptr bias, - std::shared_ptr fq) { - bool supported; - uint32_t width, in_channels, out_channels; - std::tie(supported, width, in_channels, out_channels) = VerifyAndGetConvParams(matmul_node); - if (!supported) - return false; - - auto input_node = matmul_node->input_value(0).get_node_shared_ptr(); - auto weights_node = matmul_node->input_value(1).get_node_shared_ptr(); - auto base_name = matmul_node->get_friendly_name(); - - auto reshape_const_before = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{4}, - ngraph::Shape{1, 1, width, in_channels}); - auto reshape_before = std::make_shared(input_node, reshape_const_before, false); - reshape_before->set_friendly_name(base_name + "/reshape_in"); - ngraph::copy_runtime_info(input_node, reshape_before); - - auto transpose_before = std::make_shared( - reshape_before, - ngraph::opset7::Constant::create( - ngraph::element::i64, - ngraph::Shape{4}, - permute::GetPermuteOrder(InferenceEngine::Layout::NHWC, InferenceEngine::Layout::NCHW))); - transpose_before->set_friendly_name(base_name + "/transpose_in"); - ngraph::copy_runtime_info(matmul_node, transpose_before); - - auto weights_reshape_const = - std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{4}, - ngraph::Shape{out_channels, in_channels, 1, 1}); - auto weights_reshaped = std::make_shared(weights_node, weights_reshape_const, false); - ngraph::copy_runtime_info(weights_node, weights_reshaped); - - std::shared_ptr conv_node = - std::make_shared(transpose_before, - weights_reshaped, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}, - ngraph::op::PadType::VALID); - conv_node->set_friendly_name(base_name + "/conv"); - ngraph::copy_runtime_info(transpose_before, conv_node); - - std::shared_ptr root_node = matmul_node; - if (bias) { - auto bias_output_shape = bias->get_output_shape(0); - std::shared_ptr new_bias = bias; - if (bias_output_shape.size() > 1 || bias_output_shape.at(0) > 1) { - std::vector axes(4, 1); - auto iter = std::find_if(bias_output_shape.begin(), bias_output_shape.end(), [](size_t value) { - return value > 1; - }); - if (iter != bias_output_shape.end()) { - axes.at(1) = *iter; - } - new_bias = std::make_shared( - bias->get_output_element_type(0), - axes, - std::dynamic_pointer_cast(bias)->get_data_ptr()); - } - - conv_node = std::make_shared(conv_node, new_bias); - ngraph::copy_runtime_info(transpose_before, conv_node); - root_node = add; - } - - if (fq != nullptr) { - conv_node = fq->clone_with_new_inputs( - {conv_node, fq->input_value(1), fq->input_value(2), fq->input_value(3), fq->input_value(4)}); - ngraph::copy_runtime_info(fq, conv_node); - root_node = fq; - } - - auto transpose_after = std::make_shared( - conv_node, - ngraph::opset7::Constant::create( - ngraph::element::i64, - ngraph::Shape{4}, - permute::GetPermuteOrder(InferenceEngine::Layout::NCHW, InferenceEngine::Layout::NHWC))); - transpose_after->set_friendly_name(base_name + "/transpose_out"); - ngraph::copy_runtime_info(conv_node, transpose_after); - - auto output_shape = matmul_node->get_output_shape(0); - output_shape[output_shape.size() - 1] = out_channels; - output_shape[output_shape.size() - 2] = width; - auto reshape_const_after = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{output_shape.size()}, - output_shape); - auto reshape_after = std::make_shared(transpose_after, reshape_const_after, false); - reshape_after->set_friendly_name(base_name); - ngraph::copy_runtime_info(transpose_after, reshape_after); - - ngraph::replace_node(root_node, reshape_after); - return true; -} - -ConvertMatmulToPointWiseConvolution::ConvertMatmulToPointWiseConvolution() { - MATCHER_SCOPE(ConvertMatmulToPointWiseConvolution); - auto const_input = ngraph::pattern::wrap_type(); - auto const_fq = ngraph::pattern::wrap_type( - {const_input, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - auto second_input = std::make_shared(ngraph::OutputVector{const_input, const_fq}); - auto matmul = ngraph::pattern::wrap_type({ngraph::pattern::any_input(), second_input}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - return Convert(pattern_map.at(matmul).get_node_shared_ptr(), nullptr, nullptr, nullptr); - }; - - auto m = std::make_shared(matmul, matcher_name); - this->register_matcher(m, callback); -} - -ConvertMatmulWithBiasToPointWiseConvolution::ConvertMatmulWithBiasToPointWiseConvolution() { - MATCHER_SCOPE(ConvertMatmulWithBiasToPointWiseConvolution); - auto const_input = ngraph::pattern::wrap_type(); - auto const_fq = ngraph::pattern::wrap_type( - {const_input, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - auto second_input = std::make_shared(ngraph::OutputVector{const_input, const_fq}); - auto matmul = ngraph::pattern::wrap_type({ngraph::pattern::any_input(), second_input}); - auto bias = ngraph::pattern::wrap_type(BiasValidation); - auto add = ngraph::pattern::wrap_type({matmul, bias}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - return Convert(pattern_map.at(matmul).get_node_shared_ptr(), - pattern_map.at(add).get_node_shared_ptr(), - pattern_map.at(bias).get_node_shared_ptr(), - nullptr); - }; - - auto m = std::make_shared(add, matcher_name); - this->register_matcher(m, callback); -} - -ConvertMatmulWithFqToPointWiseConvolution::ConvertMatmulWithFqToPointWiseConvolution() { - MATCHER_SCOPE(ConvertMatmulWithFqToPointWiseConvolution); - auto const_input = ngraph::pattern::wrap_type(); - auto const_fq = ngraph::pattern::wrap_type( - {const_input, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - auto second_input = std::make_shared(ngraph::OutputVector{const_input, const_fq}); - auto matmul = ngraph::pattern::wrap_type({ngraph::pattern::any_input(), second_input}); - auto bias = ngraph::pattern::wrap_type(BiasValidation); - auto add = ngraph::pattern::wrap_type({matmul, bias}); - auto matmul_out = std::make_shared(ngraph::OutputVector{add, matmul}); - auto out_fq = ngraph::pattern::wrap_type( - {matmul_out, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto add_it = pattern_map.find(add); - auto add_node = (add_it == std::end(pattern_map) ? nullptr : add_it->second.get_node_shared_ptr()); - auto bias_it = pattern_map.find(bias); - auto bias_node = (bias_it == std::end(pattern_map) ? nullptr : bias_it->second.get_node_shared_ptr()); - return Convert(pattern_map.at(matmul).get_node_shared_ptr(), - add_node, - bias_node, - pattern_map.at(out_fq).get_node_shared_ptr()); - }; - - auto m = std::make_shared(out_fq, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/convert_matmul_to_pointwise_convolution.hpp b/src/plugins/intel_gna/src/transformations/convert_matmul_to_pointwise_convolution.hpp deleted file mode 100644 index 50bb2edc669..00000000000 --- a/src/plugins/intel_gna/src/transformations/convert_matmul_to_pointwise_convolution.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Convert a MatMul with batch size unsupported by GNA to a point-wise convolution with NHWC layout - * with transposes around it: - * Transose (NHWC -> NCHW) - * | - * Matmul Convolution in NHWC layout - * Input1: [A, B] B > 8 -------> Input: [1, 1, A, B] - * Input2: [B, C] Kernel: [C, B, 1, 1] - * Output: [A, C] Output: [1, 1, A, C] - * | - * Transose (NCHW -> NHWC) - */ -class ConvertMatmulToPointWiseConvolution : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertMatmulToPointWiseConvolution", "0"); - ConvertMatmulToPointWiseConvolution(); -}; - -/** - * @brief Convert a MatMul with batch size unsupported by GNA to a point-wise convolution with NHWC layout - * with transposes around it, moved add with bias before the last transpose: - * Transose (NHWC -> NCHW) - * | - * Matmul Convolution in NHWC layout - * Input1: [A, B] B > 8 -------> Input: [1, 1, A, B] - * Input2: [B, C] Kernel: [C, B, 1, 1] - * Output: [A, C] Output: [1, 1, A, C] - * | | - * Add (const) Add (const) - * | - * Transose (NCHW -> NHWC) - */ -class ConvertMatmulWithBiasToPointWiseConvolution : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertMatmulWithBiasToPointWiseConvolution", "0"); - ConvertMatmulWithBiasToPointWiseConvolution(); -}; - -/** - * @brief Convert a MatMul with batch size unsupported by GNA to a point-wise convolution with NHWC layout - * with transposes around it, moved add with bias and/or fake quantize before the last transpose: - * Transose (NHWC -> NCHW) - * | - * Matmul Convolution in NHWC layout - * Input1: [A, B] B > 8 -------> Input: [1, 1, A, B] - * Input2: [B, C] Kernel: [C, B, 1, 1] - * Output: [A, C] Output: [1, 1, A, C] - * | | - * Add (const) Add (const) - * | | - * FakeQuantize FakeQuantize - * | - * Transose (NCHW -> NHWC) - */ -class ConvertMatmulWithFqToPointWiseConvolution : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertMatmulWithFqToPointWiseConvolution", "0"); - ConvertMatmulWithFqToPointWiseConvolution(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/convert_padded_to_valid_convolution.cpp b/src/plugins/intel_gna/src/transformations/convert_padded_to_valid_convolution.cpp deleted file mode 100644 index e9ad8a4fb31..00000000000 --- a/src/plugins/intel_gna/src/transformations/convert_padded_to_valid_convolution.cpp +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/convert_padded_to_valid_convolution.hpp" - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "utils/transformation_helper.hpp" - -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::pass::helper; - -static bool VerifyAndGetConvData(std::shared_ptr conv, ConvData& conv_data) { - const auto& input = conv->input_value(0); - - // We support only batch 1 - if (input.get_shape()[0] != 1) { - return false; - } - - GetConvData(conv, conv_data); - - return conv_data.pads_begin_height || conv_data.pads_end_height || conv_data.pads_begin_width || - conv_data.pads_end_width; -} - -static void InsertPadding(ngraph::OutputVector& input_rows_to_concat, - size_t size, - const std::shared_ptr& conv, - const std::shared_ptr padding_const, - size_t biggest_padding) { - if (size == biggest_padding) { - input_rows_to_concat.push_back(padding_const); - } else { - auto slice = FlatCrop(padding_const, 0, size); - copy_runtime_info(conv, slice); - input_rows_to_concat.push_back(slice); - } -} - -static std::shared_ptr CreatePaddedNet(std::shared_ptr leading_transpose, - std::shared_ptr conv, - const ConvData& conv_data) { - size_t flat_left_padding = conv_data.input_channel_count * conv_data.pads_begin_width; - size_t flat_right_padding = conv_data.input_channel_count * conv_data.pads_end_width; - size_t padded_row_size = - flat_left_padding + conv_data.input_channel_count * conv_data.input_width + flat_right_padding; - size_t flat_top_padding = padded_row_size * conv_data.pads_begin_height; - size_t flat_bottom_padding = padded_row_size * conv_data.pads_end_height; - size_t biggest_padding = - std::max(std::max(flat_left_padding, flat_right_padding), std::max(flat_top_padding, flat_bottom_padding)); - - if (conv_data.input_height > 1 && (flat_top_padding > 1 || flat_bottom_padding > 1)) { - biggest_padding = biggest_padding > padded_row_size ? biggest_padding : padded_row_size; - } - - auto flat_input = std::make_shared( - leading_transpose->input_value(0), - ngraph::opset7::Constant::create( - ngraph::element::i64, - ngraph::Shape{2}, - ngraph::Shape{1ull, shape_size(leading_transpose->input_value(0).get_shape())}), - false); - - // Constant with zero padding - auto const_holding_padding = - std::make_shared(conv_data.element_type, ngraph::Shape{1, biggest_padding}, 0); - - copy_runtime_info(conv, const_holding_padding); - std::shared_ptr original_row = flat_input; - ngraph::OutputVector input_rows_to_concat; - - // Add top padding - for (size_t p = 0; p < conv_data.pads_begin_height; p++) { - InsertPadding(input_rows_to_concat, padded_row_size, conv, const_holding_padding, biggest_padding); - } - - if (flat_left_padding || flat_right_padding) { - // Pad every row of input plain if neccessary - for (size_t h = 0; h < conv_data.input_height; h++) { - // left padding input right padding - // | | | - // +--------------+-----------+ - // | - // concat - - if (conv_data.input_height > 1) - original_row = FlatCrop(flat_input, - h * conv_data.input_width * conv_data.input_channel_count, - conv_data.input_width * conv_data.input_channel_count); - copy_runtime_info(conv, original_row); - - ngraph::OutputVector single_row_concat_inputs; - if (flat_left_padding) { - InsertPadding(single_row_concat_inputs, - flat_left_padding, - conv, - const_holding_padding, - biggest_padding); - } - single_row_concat_inputs.push_back(original_row); - if (flat_right_padding) { - InsertPadding(single_row_concat_inputs, - flat_right_padding, - conv, - const_holding_padding, - biggest_padding); - } - auto padded_row_concat = std::make_shared(single_row_concat_inputs, 1); - copy_runtime_info(conv, padded_row_concat); - input_rows_to_concat.push_back(padded_row_concat); - } - } else { - copy_runtime_info(conv, original_row); - input_rows_to_concat.push_back(original_row); - } - - // Bottom padding - for (size_t p = 0; p < conv_data.pads_end_height; p++) { - InsertPadding(input_rows_to_concat, padded_row_size, conv, const_holding_padding, biggest_padding); - } - - auto padded_input_plane = std::make_shared(input_rows_to_concat, 1); - copy_runtime_info(conv, padded_input_plane); - return padded_input_plane; -} - -static void GeneratePadding(std::shared_ptr leading_transpose, - std::shared_ptr conv, - const ConvData& conv_data) { - // Add padding where neccessary - - // padding - // padding - // ... row ... - // ... row ... - // ........... - // ... row ... - // padding - // padding - auto padded_input_plane = CreatePaddedNet(leading_transpose, conv, conv_data); - - auto padded_input_plane_reshaped = std::make_shared( - padded_input_plane, - ngraph::opset7::Constant::create( - ngraph::element::i64, - ngraph::Shape{4}, - {static_cast(1), - conv_data.pads_begin_height + conv_data.input_height + conv_data.pads_end_height, - conv_data.pads_begin_width + conv_data.input_width + conv_data.pads_end_width, - conv_data.input_channel_count}), - false); - - // NHWC => NCHW - auto transposed2chw = std::make_shared( - padded_input_plane_reshaped, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0ull, 3ull, 1ull, 2ull})->output(0)); - - auto conv_copy = std::make_shared(transposed2chw->output(0), - conv->input_value(1), - conv->get_strides(), - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - conv->get_dilations(), - ngraph::op::PadType::EXPLICIT); - - replace_node(conv, conv_copy); -} - -static bool Convert(std::shared_ptr leading_transpose, - std::shared_ptr conv, - std::shared_ptr trailing_transpose, - std::shared_ptr bias) { - ConvData conv_data; - - if (!VerifyAndGetConvData(std::dynamic_pointer_cast(conv), conv_data)) - return false; - - // We are looking for Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) - // or similar cases, so required network must be in NHWC order like in TF - if (!TransposeOrderMatches(std::dynamic_pointer_cast(leading_transpose), {0, 3, 1, 2})) - return false; - - if (!TransposeOrderMatches(std::dynamic_pointer_cast(trailing_transpose), {0, 2, 3, 1})) - return false; - - GeneratePadding(std::dynamic_pointer_cast(leading_transpose), - std::dynamic_pointer_cast(conv), - conv_data); - - return true; -} - -ConvertPaddedToValidConv::ConvertPaddedToValidConv() { - MATCHER_SCOPE(ConvertPaddedToValidConv); - - auto const_input = ngraph::pattern::wrap_type(); - auto leading_transpose = - ngraph::pattern::wrap_type({ngraph::pattern::any_input(), const_input}, - consumers_and_rank(1, 4)); - auto conv = ngraph::pattern::wrap_type( - {leading_transpose, - ngraph::pattern::wrap_type( - ngraph::pattern::rank_equals(4))}, - ngraph::pattern::consumers_count(1)); - auto bias = - ngraph::pattern::wrap_type({conv, const_input}, ngraph::pattern::consumers_count(1)); - auto fq_bias = ngraph::pattern::wrap_type( - {bias, const_input, const_input, const_input, const_input}, - ngraph::pattern::consumers_count(1)); - auto max_pool1 = ngraph::pattern::wrap_type({bias}, ngraph::pattern::consumers_count(1)); - auto max_pool2 = - ngraph::pattern::wrap_type({fq_bias}, ngraph::pattern::consumers_count(1)); - auto af1 = ngraph::pattern::wrap_type({conv}, ngraph::pattern::consumers_count(1)); - auto af2 = ngraph::pattern::wrap_type({bias}, ngraph::pattern::consumers_count(1)); - auto af3 = ngraph::pattern::wrap_type({fq_bias}, ngraph::pattern::consumers_count(1)); - auto af4 = ngraph::pattern::wrap_type({max_pool1}, ngraph::pattern::consumers_count(1)); - auto af5 = ngraph::pattern::wrap_type({max_pool2}, ngraph::pattern::consumers_count(1)); - auto fq_af1 = ngraph::pattern::wrap_type( - {af3, const_input, const_input, const_input, const_input}, - ngraph::pattern::consumers_count(1)); - auto fq_af2 = ngraph::pattern::wrap_type( - {af5, const_input, const_input, const_input, const_input}, - ngraph::pattern::consumers_count(1)); - auto transpose_input = std::make_shared( - ngraph::OutputVector{conv, bias, max_pool1, max_pool2, fq_bias, af1, af2, af3, af4, af5, fq_af1, fq_af2}); - auto trailing_transpose = - ngraph::pattern::wrap_type({transpose_input, const_input}, consumers_and_rank(1, 4)); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto bias_it = pattern_map.find(bias); - auto bias_node = (bias_it == std::end(pattern_map) ? nullptr : bias_it->second.get_node_shared_ptr()); - - if (bias_node && !VerifyBiasGetConst(pattern_map.at(conv).get_node_shared_ptr(), bias_node)) - return false; - - return Convert(pattern_map.at(leading_transpose).get_node_shared_ptr(), - pattern_map.at(conv).get_node_shared_ptr(), - pattern_map.at(trailing_transpose).get_node_shared_ptr(), - bias_node); - }; - - auto m = std::make_shared(trailing_transpose, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/convert_padded_to_valid_convolution.hpp b/src/plugins/intel_gna/src/transformations/convert_padded_to_valid_convolution.hpp deleted file mode 100644 index aa19a6e253b..00000000000 --- a/src/plugins/intel_gna/src/transformations/convert_padded_to_valid_convolution.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Convert a padded convolution with bias, max pooling and activation function - * wrapped with transposes, to a valid convolution with padding added before the leading transpose, - * POT precessed models are supported (fake quantized layers omitted below for clarity): - * - * Padding - * | - * Transpose (NHWC -> NCHW) Transpose (NHWC -> NCHW) - * | | - * Convolution with padding Valid convolution - * | | - * Broadcast Bias (optional) Broadcast Bias (optional) - * | | - * Max Pooling (optional) Max Pooling (optional) - * | | - * Activation Function (optional) Activation Function (optional) - * | | - * Transpose (NCHW -> NHWC) Transpose (NCHW -> NHWC) - * - */ -class ConvertPaddedToValidConv : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ConvertPaddedToValidConv", "0"); - ConvertPaddedToValidConv(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/decompose_2d_convolution.cpp b/src/plugins/intel_gna/src/transformations/decompose_2d_convolution.cpp deleted file mode 100644 index 73d72caece0..00000000000 --- a/src/plugins/intel_gna/src/transformations/decompose_2d_convolution.cpp +++ /dev/null @@ -1,856 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/decompose_2d_convolution.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "layers/gna_convolution_layer.hpp" -#include "utils/transformation_helper.hpp" - -namespace ov { -namespace intel_gna { -using namespace target; -using namespace limitations; -namespace pass { -using namespace helper; - -struct GraphData { - std::shared_ptr leading_transpose; - std::shared_ptr fq_filters; - std::shared_ptr conv; - std::shared_ptr trailing_transpose; - std::shared_ptr fq_conv; - std::shared_ptr fq_bias; - std::shared_ptr max_pool; - std::shared_ptr af; - std::shared_ptr fq_af; - std::shared_ptr last_op_in_sequence_for_replacement; - std::shared_ptr bias_const; - size_t conv_count; - size_t pool_size_width; - size_t pool_stride_width; - // TODO: currently 2D max pool is not supported - // size_t pool_size_height; - // size_t pool_stride_height; -}; - -static bool VerifyAndGetConvData(std::shared_ptr conv, ConvData& conv_data) { - const auto& input = conv->input_value(0); - const auto& filters = conv->input_value(1); - - // We support only batch == 1 - if (input.get_shape()[0] != 1) { - return false; - } - - size_t filter_height = filters.get_shape()[2]; - size_t filter_width = filters.get_shape()[3]; - - if (filter_width > Limitations::kCopyMaxGrouping || filter_height > Limitations::kCopyMaxGrouping) { - return false; - } - - GetConvData(conv, conv_data); - - IE_ASSERT(conv_data.output_channel_count == conv->get_output_shape(0)[1]); - - return true; -} - -static bool VerifyMaxPool(GraphData& graph_data, std::shared_ptr max_pool) { - auto pool_filter = max_pool->get_kernel(); - auto pool_strides = max_pool->get_strides(); - - // Check Max Pool padding and limitations - // Allow only Max Pool 1D (2D is currently not supported by this transformation) - if ((max_pool->get_auto_pad() != ngraph::op::PadType::VALID && - (max_pool->get_auto_pad() != ngraph::op::PadType::EXPLICIT || - max_pool->get_pads_begin() != ngraph::Shape({0, 0}) || max_pool->get_pads_end() != ngraph::Shape({0, 0}))) || - pool_filter.size() != 2 || pool_strides.size() != 2 || pool_filter[0] > 1 || pool_strides[0] > 1 || - pool_filter[0] > Limitations::kMaxPoolMaxWindowSize) - return false; - - graph_data.pool_size_width = pool_filter[1]; - graph_data.pool_stride_width = pool_strides[1]; - return true; -} - -static bool GNA30SupportedConv(const InferenceEngine::Precision& gnaPrecision, - const GraphData& graph_data, - const ConvData& conv_data) { - const auto cnn2dValidatorPtr = Limitations::get_instance()->get_cnn_validator(); - - if (!cnn2dValidatorPtr) { - return false; - } - const auto cnnIsValid = cnn2dValidatorPtr->ValidateCnn2D(graph_data.conv->get_friendly_name(), - static_cast(conv_data.input_height), - static_cast(conv_data.input_width), - static_cast(conv_data.input_channel_count), - static_cast(conv_data.filter_height), - static_cast(conv_data.filter_width), - static_cast(conv_data.filter_channel_count), - static_cast(conv_data.filter_stride_height), - static_cast(conv_data.filter_stride_width), - static_cast(conv_data.filter_dilation_height), - static_cast(conv_data.filter_dilation_width), - OvGnaTypeIntFromBytes(gnaPrecision.size()), - false); - if (!cnnIsValid) { - return false; - } - if (!graph_data.max_pool) { - return true; - } - const auto poolingValid = - cnn2dValidatorPtr->ValidatePooling2D(graph_data.conv->get_friendly_name(), - static_cast(graph_data.max_pool->get_kernel()[0]), - static_cast(graph_data.max_pool->get_kernel()[1]), - static_cast(graph_data.max_pool->get_strides()[0]), - static_cast(graph_data.max_pool->get_strides()[1]), - false); - return poolingValid; -} - -static size_t CalculateConvCount(const ConvData& conv_data) { - // Check if split of plane due to GNA HW limitations of 768 filter elements is possible - size_t conv_count = 1; - size_t total_factorized_conv_channel_count = - (conv_data.input_channel_count * conv_data.filter_height * conv_data.filter_width); - while (total_factorized_conv_channel_count / conv_count > Limitations::kConvFilterMaxSize || - total_factorized_conv_channel_count % conv_count != 0 || conv_data.filter_channel_count % conv_count != 0) - conv_count++; - - return conv_count; -} - -static bool ShouldDecompose(GraphData& graph_data, const ConvData& conv_data) { - // Calculate the number of splits required - graph_data.conv_count = CalculateConvCount(conv_data); - - // Concat (copy) layer limitation allows to split up to a certain limit - // Currently we are able to split only convolutions without pooling in horizontal dimension - if (graph_data.conv_count > Limitations::kCopyMaxGrouping || - ((graph_data.pool_size_width > 1 || graph_data.pool_stride_width > 1) && graph_data.conv_count > 1)) - return false; - - // GNA supported features or handled otherwise - there is no need to decompose such convolution - if (graph_data.conv_count == 1 && - (((conv_data.input_height == 1 || conv_data.input_width == 1) && conv_data.filter_dilation_width == 1 && - conv_data.filter_dilation_height == 1) || - gna_convolution_layer::isMappableFrom2DTo1D(static_cast(conv_data.input_height), - static_cast(conv_data.input_width), - static_cast(conv_data.input_channel_count), - static_cast(conv_data.filter_height), - static_cast(conv_data.filter_width), - static_cast(conv_data.filter_stride_height), - static_cast(conv_data.filter_stride_width)))) - return false; - - return true; -} - -static std::vector> Split2DConvFilters(std::shared_ptr& filters, - const bool& vertical_permute, - const bool& horizontal_permute, - const size_t& split_channels) { - if (!horizontal_permute && !vertical_permute && split_channels == 1) - return {filters}; - - std::vector> result; - ngraph::Shape reshape_shape; - auto flat_filters = filters->outputs(); - const auto filter_shape = filters->get_output_shape(0); - IE_ASSERT(filter_shape.size() == 4); - - if (split_channels > 1) { - const auto axis_node = ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{}, {1}); - const auto split = std::make_shared(filters, axis_node, split_channels); - flat_filters = split->outputs(); - } - - for (size_t split_index = 0; split_index < split_channels; split_index++) { - ngraph::Output& flat_filter = flat_filters[split_index]; - if (horizontal_permute && !vertical_permute) { - result.push_back(std::make_shared( - flat_filter, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{4}, ngraph::Shape{0, 1, 3, 2}))); - } else { - result.push_back(flat_filter.get_node_shared_ptr()); - } - } - - if (vertical_permute && horizontal_permute) { - reshape_shape = - ngraph::Shape{filter_shape[0], filter_shape[1] * filter_shape[2] * filter_shape[3] / split_channels, 1, 1}; - } else if (vertical_permute && !horizontal_permute) { - reshape_shape = - ngraph::Shape{filter_shape[0], filter_shape[1] * filter_shape[2] / split_channels, 1, filter_shape[3]}; - } else if (!vertical_permute && horizontal_permute) { - reshape_shape = - ngraph::Shape{filter_shape[0], filter_shape[1] * filter_shape[3] / split_channels, filter_shape[2], 1}; - } else { - reshape_shape = - ngraph::Shape{filter_shape[0], filter_shape[1] / split_channels, filter_shape[2], filter_shape[3]}; - } - - for (auto& new_filter : result) - new_filter = ov::op::util::make_try_fold( - new_filter, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{4}, reshape_shape), - false); - - return result; -} - -static ngraph::OutputVector SplitInput(const GraphData& graph_data, ConvData& conv_data) { - // We need to have proper input shape first - ngraph::OutputVector split_planes; - auto padded_input_plane = std::make_shared( - graph_data.leading_transpose->input_value(0), - ngraph::opset7::Constant::create( - ngraph::element::i64, - ngraph::Shape{2}, - ngraph::Shape{1, shape_size(graph_data.leading_transpose->input_value(0).get_shape())}), - false); - copy_runtime_info(graph_data.conv, padded_input_plane); - - if (graph_data.conv_count > 1) { - // If we have split input plane and convolutions due to GNA limitation - we must sum their results at the end - conv_data.input_channel_count /= graph_data.conv_count; - - auto reshape_before_transpose = std::make_shared( - padded_input_plane, - ngraph::opset7::Constant::create( - ngraph::element::i64, - ngraph::Shape{2}, - {shape_size(padded_input_plane->get_shape()) / graph_data.conv_count, graph_data.conv_count}), - false); - - auto transpose_before_channel_wise_split = std::make_shared( - reshape_before_transpose, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 0})->output(0)); - - const auto axis_node = ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}); - const auto split = std::make_shared(transpose_before_channel_wise_split, - axis_node, - graph_data.conv_count); - split_planes = split->outputs(); - } else { - split_planes.push_back(padded_input_plane); - } - - return split_planes; -} - -static std::vector> SplitFilters(const GraphData& graph_data, ConvData& conv_data) { - // If the input plane exceeds GNA limits and we have split into several convolutions, then we need to split filter - // data as well; we also need to take filter height and potential dilation into account when modifying the filters - - // Take account of fake quantize when getting filter values - auto filter_values = std::dynamic_pointer_cast( - graph_data.fq_filters == nullptr ? graph_data.conv->input_value(1).get_node_shared_ptr() - : graph_data.fq_filters->input_value(0).get_node_shared_ptr()); - bool vertical_permute = (conv_data.filter_height > 1); - bool horizontal_permute = (conv_data.filter_dilation_width > 1); - std::vector> h_1_filters{}; - - h_1_filters = Split2DConvFilters(filter_values, vertical_permute, horizontal_permute, graph_data.conv_count); - - for (auto& filter : h_1_filters) - copy_runtime_info(graph_data.conv, filter); - - return h_1_filters; -} - -static void TransformInput(const GraphData& graph_data, - const ConvData& conv_data, - ngraph::Output& split_input_plane) { - /* - * Padded row - NHWC order - * | - * Split in vertical dim (filter height) - * / | \ - * Concat - * | - * Transpose - */ - - // First we need to prepare flat (height = 1) slices of input data proper for flattened (height = 1) filters created - // later on; the input data is overlapping (duplicated) - ngraph::OutputVector dilated_input_planes; - for (size_t filter_height = 0; filter_height < conv_data.filter_height; filter_height++) { - size_t offset; - - if (conv_data.filter_stride_height > 1) { - // Prepare strided slices of input data - for (size_t output_height = 0; output_height < conv_data.output_height; output_height++) { - offset = (filter_height * conv_data.filter_dilation_height + - output_height * conv_data.filter_stride_height) * - conv_data.input_width * conv_data.input_channel_count; - auto slice = FlatCrop(split_input_plane, offset, conv_data.input_width * conv_data.input_channel_count); - copy_runtime_info(graph_data.conv, slice); - dilated_input_planes.push_back(slice); - } - } else { - offset = filter_height * conv_data.filter_dilation_height * conv_data.input_width * - conv_data.input_channel_count; - auto slice = FlatCrop(split_input_plane, - offset, - conv_data.input_width * conv_data.input_channel_count * conv_data.output_height); - copy_runtime_info(graph_data.conv, slice); - dilated_input_planes.push_back(slice); - } - } - - // Interleaving dilated input planes - std::shared_ptr dilated_chunks_concat = - std::make_shared(dilated_input_planes, 0); - - // Additional reshape is required for strided slices of input intended for each filter row - if (conv_data.filter_stride_height > 1) { - dilated_chunks_concat = std::make_shared( - dilated_chunks_concat, - ngraph::opset7::Constant::create( - ngraph::element::i64, - ngraph::Shape{2}, - {conv_data.filter_height, - conv_data.input_width * conv_data.input_channel_count * conv_data.output_height}), - false); - } - - auto transposed_dilated_chunks = std::make_shared( - dilated_chunks_concat, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 0})->output(0)); - - // Flattening of interleaved input planes - auto flattened_dilated_transposed_input = std::make_shared( - transposed_dilated_chunks, - ngraph::opset7::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - {(size_t)1, - conv_data.input_width * conv_data.input_channel_count * - conv_data.output_height * conv_data.filter_height}), - false); - - copy_runtime_info(graph_data.conv, - {dilated_chunks_concat, flattened_dilated_transposed_input, transposed_dilated_chunks}); - split_input_plane = flattened_dilated_transposed_input; -} - -// Valid 1D (decomposed 2D) convolution wrapped with transposes NHWC => NCHW => conv => NCHW => NHWC -static std::shared_ptr Create1DConv(const GraphData& graph_data, - const ConvData& conv_data, - const ngraph::Output& input, - std::shared_ptr filters, - const size_t conv_index, - const size_t h_index) { - // Transpose NHWC => NCHW - std::shared_ptr nchw_input = std::make_shared( - input, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 3, 1, 2})->output(0)); - - // Fake quantize - filters = InsertFQLayer(graph_data.fq_filters, filters); - - // 1D Convolution & fake quantize - auto conv = std::make_shared(nchw_input, - filters, - ngraph::Strides{1, conv_data.filter_stride_width}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}, - ngraph::op::PadType::VALID); - std::string conv_name = - graph_data.conv->get_friendly_name() + "_H_" + std::to_string(h_index) + "_CH_" + std::to_string(0); - conv->set_friendly_name(conv_name); - std::shared_ptr last_conv_block_op = conv; - last_conv_block_op = InsertFQLayer(graph_data.fq_conv, last_conv_block_op); - - // Bias & fake quantize - if (graph_data.bias_const && conv_index == 0) { - auto bias_size = shape_size(graph_data.bias_const->get_shape()); - auto reshaped_bias_const = ov::op::util::make_try_fold( - graph_data.bias_const, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{4}, ngraph::Shape{1, bias_size, 1, 1}), - false); - last_conv_block_op = std::make_shared(conv, reshaped_bias_const); - copy_runtime_info(graph_data.conv, last_conv_block_op); - last_conv_block_op = InsertFQLayer(graph_data.fq_bias, last_conv_block_op); - } - - // Max pooling - if (graph_data.max_pool && (graph_data.pool_size_width > 1 || graph_data.pool_stride_width > 1)) { - last_conv_block_op = std::make_shared(last_conv_block_op, - ngraph::Strides{1, graph_data.pool_stride_width}, - ngraph::Shape{0, 0}, - ngraph::Shape{0, 0}, - ngraph::Shape{1, graph_data.pool_size_width}, - graph_data.max_pool->get_rounding_type(), - ngraph::op::PadType::VALID); - } - - // Activation function & fake quantize - if (graph_data.af && graph_data.conv_count == 1) { - last_conv_block_op = graph_data.af->clone_with_new_inputs({last_conv_block_op}); - copy_runtime_info(conv, last_conv_block_op); - last_conv_block_op = InsertFQLayer(graph_data.fq_af, last_conv_block_op); - } - - // Transpose NCHW => NHWC - auto nhwc_output = std::make_shared( - last_conv_block_op, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 2, 3, 1})->output(0)); - copy_runtime_info(graph_data.conv, {nchw_input, conv, nhwc_output}); - return nhwc_output; -} - -static std::shared_ptr CreateDecomposedConv(const GraphData& graph_data, - ConvData& conv_data, - ngraph::Output& reduced_input_plane, - const std::vector>& h_1_filters, - const size_t conv_index) { - ngraph::OutputVector result_chunks; - std::shared_ptr last_op; - bool horizontal_permute = (conv_data.filter_dilation_width > 1); - size_t h_1_filter_channel_count = (conv_data.input_channel_count * conv_data.filter_height); - - for (size_t output_height = 0; output_height < conv_data.output_height; output_height++) { - size_t offset = output_height * conv_data.input_width * h_1_filter_channel_count; - auto row = (conv_data.output_height == 1) - ? reduced_input_plane - : FlatCrop(reduced_input_plane, offset, conv_data.input_width * h_1_filter_channel_count); - /* - * Padded row - * | - * ??? ??? - * | - * Split in vertical dim - * / | \ - * Concat - * | - * Permute - * | - * Transpose (NHWC => NCHW) - * | - * 1D Conv (Bias | MaxPooling) - * | - * Transpose (NCHW => NHWC) - */ - auto nhwc_conv_y_input = row; - - if (horizontal_permute) { - // Horizontal split - transform input accordingly - ngraph::OutputVector dilated_chunks; - std::shared_ptr dilated_chunks_concat = nhwc_conv_y_input.get_node_shared_ptr(); - - // We need to calculate some parameters in case horizontal stride > 1 is used, because if we use the ones - // available from the original convolution we won't take into account the fact horizontal strides will be - // supported by the newly created 1D convolution, and not by decomposition - size_t filter_dilation_width = conv_data.filter_width > 1 ? conv_data.filter_dilation_width : 1; - size_t output_width = (conv_data.input_width - (filter_dilation_width * (conv_data.filter_width - 1))); - - if (conv_data.filter_width > 1) { - for (size_t filter_width = 0; filter_width < conv_data.filter_width; filter_width++) { - size_t offset = filter_width * conv_data.filter_dilation_width * h_1_filter_channel_count; - auto slice = FlatCrop(row, offset, h_1_filter_channel_count * output_width); - copy_runtime_info(graph_data.conv, slice); - dilated_chunks.push_back(slice); - } - - dilated_chunks_concat = std::make_shared(dilated_chunks, 0); - } - - auto transposed_dilated_chunks = std::make_shared( - dilated_chunks_concat, - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 0})->output(0)); - - auto flattened_dilated_conv_input = std::make_shared( - transposed_dilated_chunks, - ngraph::opset7::Constant::create( - ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{1, 1, output_width, h_1_filter_channel_count * conv_data.filter_width}), - false); - - copy_runtime_info( - graph_data.conv, - ngraph::NodeVector{flattened_dilated_conv_input, transposed_dilated_chunks, dilated_chunks_concat}); - - nhwc_conv_y_input = flattened_dilated_conv_input; - } else { - // If no horizontal split is done, only reshape is required before decomposed convolution - nhwc_conv_y_input = std::make_shared( - nhwc_conv_y_input, - ngraph::opset7::Constant::create(ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{1, 1, conv_data.input_width, h_1_filter_channel_count}), - false); - } - - // Pointwise convolutions - // Valid 1D convolution wrapped with transposes NHWC => NCHW => Conv => NCHW => NHWC - // Activation function can be fused with convolution only if it isn't split - auto nhwc_y_output = - Create1DConv(graph_data, conv_data, nhwc_conv_y_input, h_1_filters[conv_index], conv_index, output_height); - result_chunks.push_back(nhwc_y_output); - last_op = nhwc_y_output; - } - - // Horizontal dimemsion greater than 1 - if (result_chunks.size() > 1) { - // Concat in horizontal dimension - // In NHWC index of H is 1 - auto concatenated_sub_results = std::make_shared(result_chunks, 1); - copy_runtime_info(graph_data.conv, concatenated_sub_results); - last_op = concatenated_sub_results; - } - return last_op; -} - -static void Decompose(const GraphData& graph_data, ConvData& conv_data) { - std::vector> partial_conv_results; - - // Split input due to GNA filter element count limit - auto split_planes = SplitInput(graph_data, conv_data); - // Split filters due to GNA filter element count limit, 2D convolution shape, or dilations - auto h_1_filters = SplitFilters(graph_data, conv_data); - - // Do transformations in each of the splits created above - for (size_t conv_index = 0; conv_index < graph_data.conv_count; conv_index++) { - ngraph::Output& split_input_plane = split_planes[conv_index]; - - // Input data needs to be prepared before 2D convolution decomposition - if (conv_data.filter_height > 1 || conv_data.filter_stride_height > 1) { - TransformInput(graph_data, conv_data, split_input_plane); - } - - auto flat_conv = CreateDecomposedConv(graph_data, conv_data, split_input_plane, h_1_filters, conv_index); - partial_conv_results.push_back(flat_conv); - } - - std::shared_ptr conv_result = partial_conv_results.front(); - for (size_t i = 1; i < partial_conv_results.size(); i++) { - auto add_result = std::make_shared(partial_conv_results[i], conv_result); - copy_runtime_info(graph_data.conv, add_result); - conv_result = add_result; - } - - // TODO: Max Pool 2D case - // if (graph_data.max_pool && (graph_data.pool_size_height > 1 || graph_data.pool_stride_height > 1)) { - //} - - // Activation function after trailing Transpose NCHW->NHWC - if (graph_data.af && graph_data.conv_count > 1) { - auto af_result = graph_data.af->clone_with_new_inputs({conv_result}); - copy_runtime_info(graph_data.conv, af_result); - conv_result = af_result; - } - // We need to put the same name as before for the Convolution layer, so its output can be used as network result - std::string conv_result_name = graph_data.last_op_in_sequence_for_replacement->get_friendly_name(); - replace_node(graph_data.last_op_in_sequence_for_replacement, conv_result); - conv_result->set_friendly_name(conv_result_name); -} - -static bool Convert(const InferenceEngine::Precision& gnaPrecision, - std::shared_ptr leading_transpose, - std::shared_ptr fq_filters, - std::shared_ptr conv, - std::shared_ptr trailing_transpose, - std::shared_ptr fq_conv, - std::shared_ptr bias, - std::shared_ptr bias_const, - std::shared_ptr fq_bias, - std::shared_ptr max_pool, - std::shared_ptr af, - std::shared_ptr fq_af, - std::shared_ptr last_op_for_replacement) { - GraphData graph_data{std::dynamic_pointer_cast(leading_transpose), - std::dynamic_pointer_cast(fq_filters), - std::dynamic_pointer_cast(conv), - std::dynamic_pointer_cast(trailing_transpose), - std::dynamic_pointer_cast(fq_conv), - std::dynamic_pointer_cast(fq_bias), - std::dynamic_pointer_cast(max_pool), - std::dynamic_pointer_cast(af), - std::dynamic_pointer_cast(fq_af), - last_op_for_replacement, - bias_const, - 1, - 1, - 1}; - ConvData conv_data; - - if (!VerifyAndGetConvData(std::dynamic_pointer_cast(conv), conv_data)) - return false; - - if (max_pool && !VerifyMaxPool(graph_data, std::dynamic_pointer_cast(max_pool))) - return false; - - // If compile target is GNA 3.0 and the convolution is supported on it, then skip decomposition - if (GNA30SupportedConv(gnaPrecision, graph_data, conv_data)) - return false; - - // We are looking for Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) - // or similar cases, so required network must be in NHWC order like in TF - if (!TransposeOrderMatches(std::dynamic_pointer_cast(leading_transpose), {0, 3, 1, 2})) - return false; - - if (!TransposeOrderMatches(std::dynamic_pointer_cast(trailing_transpose), {0, 2, 3, 1})) - return false; - - if (!ShouldDecompose(graph_data, conv_data)) - return false; - - // All checks applied - now we may start decomposition - Decompose(graph_data, conv_data); - - return true; -} - -Decompose2DConv::Decompose2DConv(const InferenceEngine::Precision& gnaPrecision) { - MATCHER_SCOPE(Decompose2DConv); - - auto const_input = ngraph::pattern::wrap_type(); - auto leading_transpose = - ngraph::pattern::wrap_type({ngraph::pattern::any_input(), const_input}, - consumers_and_rank(1, 4)); - auto filters_const = ngraph::pattern::wrap_type(ngraph::pattern::rank_equals(4)); - auto fq_filters = ngraph::pattern::wrap_type( - {const_input, const_input, const_input, const_input, const_input}, - consumers_and_rank(1, 4)); - auto filters = std::make_shared(ngraph::OutputVector{filters_const, fq_filters}); - auto conv = - ngraph::pattern::wrap_type({leading_transpose, filters}, consumers_and_rank(1, 4)); - auto bias = - ngraph::pattern::wrap_type({conv, const_input}, ngraph::pattern::consumers_count(1)); - auto fq_bias = ngraph::pattern::wrap_type( - {bias, const_input, const_input, const_input, const_input}, - ngraph::pattern::consumers_count(1)); - auto max_pool1 = ngraph::pattern::wrap_type({bias}, ngraph::pattern::consumers_count(1)); - auto max_pool2 = - ngraph::pattern::wrap_type({fq_bias}, ngraph::pattern::consumers_count(1)); - auto af1 = ngraph::pattern::wrap_type({conv}, ngraph::pattern::consumers_count(1)); - auto af2 = ngraph::pattern::wrap_type({bias}, ngraph::pattern::consumers_count(1)); - auto af3 = ngraph::pattern::wrap_type({fq_bias}, ngraph::pattern::consumers_count(1)); - auto af4 = ngraph::pattern::wrap_type({max_pool1}, ngraph::pattern::consumers_count(1)); - auto af5 = ngraph::pattern::wrap_type({max_pool2}, ngraph::pattern::consumers_count(1)); - auto fq_af1 = ngraph::pattern::wrap_type( - {af3, const_input, const_input, const_input, const_input}, - ngraph::pattern::consumers_count(1)); - auto fq_af2 = ngraph::pattern::wrap_type( - {af5, const_input, const_input, const_input, const_input}, - ngraph::pattern::consumers_count(1)); - auto fq_conv = ngraph::pattern::wrap_type( - {conv, const_input, const_input, const_input, const_input}, - ngraph::pattern::consumers_count(1)); - auto transpose_input = std::make_shared( - ngraph::OutputVector{conv, bias, max_pool1, max_pool2, fq_bias, af1, af2, af3, af4, fq_af1, fq_af2, fq_conv}); - auto trailing_transpose = - ngraph::pattern::wrap_type({transpose_input, const_input}, consumers_and_rank(1, 4)); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto fq_filters_it = pattern_map.find(fq_filters); - auto fq_filters_node = - (fq_filters_it == std::end(pattern_map) ? nullptr : fq_filters_it->second.get_node_shared_ptr()); - auto bias_it = pattern_map.find(bias); - auto bias_node = (bias_it == std::end(pattern_map) ? nullptr : bias_it->second.get_node_shared_ptr()); - std::shared_ptr bias_const_node = nullptr; - - if (bias_node && !(bias_const_node = VerifyBiasGetConst(pattern_map.at(conv).get_node_shared_ptr(), bias_node))) - return false; - - auto fq_conv_it = pattern_map.find(fq_conv); - auto fq_conv_node = (fq_conv_it == std::end(pattern_map) ? nullptr : fq_conv_it->second.get_node_shared_ptr()); - auto fq_bias_it = pattern_map.find(fq_bias); - auto fq_bias_node = (fq_bias_it == std::end(pattern_map) ? nullptr : fq_bias_it->second.get_node_shared_ptr()); - auto fq_af1_it = pattern_map.find(fq_af1); - auto fq_af2_it = pattern_map.find(fq_af2); - auto fq_af_node = - (fq_af1_it == std::end(pattern_map) - ? ((fq_af2_it == std::end(pattern_map) ? nullptr : fq_af2_it->second.get_node_shared_ptr())) - : fq_af1_it->second.get_node_shared_ptr()); - auto max_pool1_it = pattern_map.find(max_pool1); - auto max_pool2_it = pattern_map.find(max_pool2); - auto max_pool_node = - (max_pool1_it == std::end(pattern_map) - ? ((max_pool2_it == std::end(pattern_map) ? nullptr : max_pool2_it->second.get_node_shared_ptr())) - : max_pool1_it->second.get_node_shared_ptr()); - std::shared_ptr af_node = nullptr; - std::vector af_it{pattern_map.find(af1), - pattern_map.find(af2), - pattern_map.find(af3), - pattern_map.find(af4)}; - - for (auto const& af : af_it) { - if (af != std::end(pattern_map)) { - af_node = af->second.get_node_shared_ptr(); - break; - } - } - - return Convert(gnaPrecision, - pattern_map.at(leading_transpose).get_node_shared_ptr(), - fq_filters_node, - pattern_map.at(conv).get_node_shared_ptr(), - pattern_map.at(trailing_transpose).get_node_shared_ptr(), - fq_conv_node, - bias_node, - bias_const_node, - fq_bias_node, - max_pool_node, - af_node, - fq_af_node, - pattern_map.at(trailing_transpose).get_node_shared_ptr()); - }; - - auto m = std::make_shared(trailing_transpose, matcher_name); - this->register_matcher(m, callback); -} - -Decompose2DConvTransposedWithBias::Decompose2DConvTransposedWithBias(const InferenceEngine::Precision& gnaPrecision) { - MATCHER_SCOPE(Decompose2DConvTransposedWithBias); - - auto const_input_i64 = - ngraph::pattern::wrap_type(ngraph::pattern::type_matches(ngraph::element::i64)); - auto const_input = ngraph::pattern::wrap_type(); - auto leading_transpose = - ngraph::pattern::wrap_type({ngraph::pattern::any_input(), const_input_i64}, - consumers_and_rank(1, 4)); - auto conv = ngraph::pattern::wrap_type( - {leading_transpose, ngraph::pattern::wrap_type(ngraph::pattern::rank_equals(4))}, - consumers_and_rank(1, 4)); - auto trailing_transpose = - ngraph::pattern::wrap_type({conv, const_input_i64}, consumers_and_rank(1, 4)); - auto bias = ngraph::pattern::wrap_type({trailing_transpose, const_input}, - ngraph::pattern::consumers_count(1)); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - std::shared_ptr bias_const_node = nullptr; - - if (!(bias_const_node = VerifyBiasGetConst(pattern_map.at(conv).get_node_shared_ptr(), - pattern_map.at(bias).get_node_shared_ptr()))) - return false; - - return Convert(gnaPrecision, - pattern_map.at(leading_transpose).get_node_shared_ptr(), - nullptr, - pattern_map.at(conv).get_node_shared_ptr(), - pattern_map.at(trailing_transpose).get_node_shared_ptr(), - nullptr, - pattern_map.at(bias).get_node_shared_ptr(), - bias_const_node, - nullptr, - nullptr, - nullptr, - nullptr, - pattern_map.at(bias).get_node_shared_ptr()); - }; - - auto m = std::make_shared(bias, matcher_name); - this->register_matcher(m, callback); -} - -Decompose2DConvTransposedWithBiasAF::Decompose2DConvTransposedWithBiasAF( - const InferenceEngine::Precision& gnaPrecision) { - MATCHER_SCOPE(Decompose2DConvTransposedWithBiasAF); - - auto const_input_i64 = - ngraph::pattern::wrap_type(ngraph::pattern::type_matches(ngraph::element::i64)); - auto const_input = ngraph::pattern::wrap_type(); - auto leading_transpose = - ngraph::pattern::wrap_type({ngraph::pattern::any_input(), const_input_i64}, - consumers_and_rank(1, 4)); - auto conv = ngraph::pattern::wrap_type( - {leading_transpose, ngraph::pattern::wrap_type(ngraph::pattern::rank_equals(4))}, - consumers_and_rank(1, 4)); - auto trailing_transpose = - ngraph::pattern::wrap_type({conv, const_input_i64}, consumers_and_rank(1, 4)); - auto bias = ngraph::pattern::wrap_type({trailing_transpose, const_input}, - ngraph::pattern::consumers_count(1)); - auto af = ngraph::pattern::wrap_type({bias}, ngraph::pattern::consumers_count(1)); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - std::shared_ptr bias_const_node = nullptr; - - if (!(bias_const_node = VerifyBiasGetConst(pattern_map.at(conv).get_node_shared_ptr(), - pattern_map.at(bias).get_node_shared_ptr()))) - return false; - - return Convert(gnaPrecision, - pattern_map.at(leading_transpose).get_node_shared_ptr(), - nullptr, - pattern_map.at(conv).get_node_shared_ptr(), - pattern_map.at(trailing_transpose).get_node_shared_ptr(), - nullptr, - pattern_map.at(bias).get_node_shared_ptr(), - bias_const_node, - nullptr, - nullptr, - pattern_map.at(af).get_node_shared_ptr(), - nullptr, - pattern_map.at(af).get_node_shared_ptr()); - }; - - auto m = std::make_shared(af, matcher_name); - this->register_matcher(m, callback); -} - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/decompose_2d_convolution.hpp b/src/plugins/intel_gna/src/transformations/decompose_2d_convolution.hpp deleted file mode 100644 index 8749e42203c..00000000000 --- a/src/plugins/intel_gna/src/transformations/decompose_2d_convolution.hpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "common/gna_target.hpp" -#include "ngraph/pass/graph_rewrite.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Decompose a 2D convolution, wrapped with transposes, - * to a set of valid 1D convolutions with padding added in front of the set: - * - * Padding - * | - * Transpose (NHWC -> NCHW) Transpose (NHWC -> NCHW) - * | | - * Convolution with padding Valid convolution - * | | - * Broadcast Bias (optional) Broadcast Bias (optional) - * | | - * Max Pooling (optional) Max Pooling (optional) - * | | - * Activation Function (optional) Activation Function (optional) - * | | - * Transpose (NCHW -> NHWC) Transpose (NCHW -> NHWC) - * - */ -class Decompose2DConv : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("Decompose2DConv", "0"); - Decompose2DConv(const InferenceEngine::Precision& gnaPrecision); -}; - -/** - * @brief Decomopose a 2D convolution wrapped with transposes, with bias after trailing transpose, - * to a set of valid 1D convolutions with padding added in front of the set: - * - * Padding - * | - * Transpose (NHWC -> NCHW) Transpose (NHWC -> NCHW) - * | | - * Convolution with padding Valid convolution - * | | - * Transpose (NCHW -> NHWC) Transpose (NCHW -> NHWC) - * | | - * Broadcast Bias Broadcast Bias - * - */ -class Decompose2DConvTransposedWithBias : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("Decompose2DConvTransposedWithBias", "0"); - Decompose2DConvTransposedWithBias(const InferenceEngine::Precision& gnaPrecision); -}; - -/** - * @brief Decomopose a 2D convolution wrapped with transposes, with bias - * to a set of valid 1D convolutions with padding added in front of the set: - * - * Padding - * | - * Transpose (NHWC -> NCHW) Transpose (NHWC -> NCHW) - * | | - * Convolution with padding Valid convolution - * | | - * Transpose (NCHW -> NHWC) Transpose (NCHW -> NHWC) - * | | - * Broadcast Bias Broadcast Bias - * | | - * Activation Function Activation Function - * - */ -class Decompose2DConvTransposedWithBiasAF : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("Decompose2DConvTransposedWithBiasAF", "0"); - Decompose2DConvTransposedWithBiasAF(const InferenceEngine::Precision& gnaPrecision); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/decompose_mvn.cpp b/src/plugins/intel_gna/src/transformations/decompose_mvn.cpp deleted file mode 100644 index de7fc6a5075..00000000000 --- a/src/plugins/intel_gna/src/transformations/decompose_mvn.cpp +++ /dev/null @@ -1,360 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/decompose_mvn.hpp" - -#include -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" - -using namespace ngraph; -using namespace ov::intel_gna::limitations; - -namespace ov { -namespace intel_gna { -namespace pass { - -struct MVNData { - size_t N; - size_t C; - size_t H; - size_t W; - size_t num_parts; - float eps; - ov::op::MVNEpsMode eps_mode; - bool normalize_variance; - element::Type element_type; - std::string name; -}; - -template -static bool ValidateAxes(const std::shared_ptr axes_const, const size_t& mvn_shape_size) { - T axes_value; - size_t axes_vector_size; - - std::vector axes_const_vector = axes_const->cast_vector(); - IE_ASSERT(!axes_const_vector.empty()); - axes_value = axes_const_vector[0]; - axes_vector_size = axes_const_vector.size(); - - if (axes_vector_size != mvn_shape_size - 2) { - return false; - } - - // Verify supported first axes value - if (axes_value != 2 && axes_value != static_cast(2 - mvn_shape_size)) - return false; - - return true; -} - -static bool GetVerifiedMVNData(const std::shared_ptr mvn, MVNData& mvn_data) { - const auto mvn_shape = mvn->get_output_shape(0); - auto mvn_shape_size = mvn_shape.size(); - - // Validate axes parameter - auto axes_const = std::dynamic_pointer_cast(mvn->input_value(1).get_node_shared_ptr()); - IE_ASSERT(axes_const); - auto element_type = axes_const->get_element_type(); - - if (!(element_type == element::Type_t::i64 ? ValidateAxes(axes_const, mvn_shape_size) - : ValidateAxes(axes_const, mvn_shape_size))) - return false; - - if (mvn_shape_size == 4) { - mvn_data.N = mvn_shape[0]; - mvn_data.C = mvn_shape[1]; - mvn_data.H = mvn_shape[2]; - mvn_data.W = mvn_shape[3]; - } else if (mvn_shape_size == 3) { - mvn_data.N = 1; - mvn_data.C = mvn_shape[0]; - mvn_data.H = mvn_shape[1]; - mvn_data.W = mvn_shape[2]; - } else { - THROW_GNA_EXCEPTION << "Unsupported MVN shape size: " << mvn_shape_size; - } - - // Check if average must be split - mvn_data.num_parts = 1; - while (mvn_data.W / mvn_data.num_parts > Limitations::kConvFilterMaxSize) { - mvn_data.num_parts *= 2; - } - - // Abort if W is not divisible by power of 2 - if ((mvn_data.W / mvn_data.num_parts) * mvn_data.num_parts != mvn_data.W) { - return false; - } - - mvn_data.eps = mvn->get_eps(); - mvn_data.eps_mode = mvn->get_eps_mode(); - mvn_data.normalize_variance = mvn->get_normalize_variance(); - mvn_data.element_type = mvn->get_element_type(); - mvn_data.name = mvn->get_friendly_name(); - - return true; -} - -static std::shared_ptr NormalizeVariance(const std::shared_ptr mvn, - const MVNData& mvn_data, - const std::shared_ptr& subtract_mean, - const std::shared_ptr& avg_broadcast_const) { - // Prepare consts - auto combined_C_H = mvn_data.C * mvn_data.H; - - std::vector avg_weights(8 * mvn_data.W / mvn_data.num_parts, 1.0f / mvn_data.W); - auto avg_weights_const = - opset8::Constant::create(mvn_data.element_type, Shape{8, mvn_data.W / mvn_data.num_parts, 1, 1}, avg_weights); - std::vector eps_tensor(combined_C_H * mvn_data.W, mvn_data.eps); - auto eps_tensor_const = - opset8::Constant::create(mvn_data.element_type, Shape{1, combined_C_H * mvn_data.W}, eps_tensor); - std::vector minus_half(combined_C_H * mvn_data.W, -0.5f); - auto minus_half_const = - opset8::Constant::create(mvn_data.element_type, Shape{1, combined_C_H * mvn_data.W}, minus_half); - - // Calculate square of the difference between input and its mean - auto squared_diff = std::make_shared(subtract_mean, subtract_mean); - squared_diff->set_friendly_name(mvn_data.name + "_SqrDiff"); - - // Calculate sum of the squares - auto squared_diff_reshape = std::make_shared( - squared_diff, - opset8::Constant::create( - element::i64, - Shape{4}, - Shape{mvn_data.N, combined_C_H * mvn_data.num_parts, 1ull, mvn_data.W / mvn_data.num_parts}), - false); - auto transposed_input_3 = - std::make_shared(squared_diff_reshape, - opset8::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2})); - auto transposed_avg_conv_3 = std::make_shared(transposed_input_3, - avg_weights_const, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}, - ov::op::PadType::VALID); - transposed_avg_conv_3->set_friendly_name(mvn_data.name + "_Avg3"); - auto avg_conv_3 = - std::make_shared(transposed_avg_conv_3, - opset8::Constant::create(element::i64, Shape{4}, {0, 2, 3, 1})); - auto reshape_avg_conv_3 = std::make_shared( - avg_conv_3, - opset8::Constant::create(element::i64, Shape{4}, Shape{mvn_data.N, 1ull, combined_C_H, 8 * mvn_data.num_parts}), - false); - auto transposed_input_4 = - std::make_shared(reshape_avg_conv_3, - opset8::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2})); - auto transposed_avg_conv_4 = std::make_shared(transposed_input_4, - avg_broadcast_const, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}, - ov::op::PadType::VALID); - transposed_avg_conv_4->set_friendly_name(mvn_data.name + "_Avg4"); - auto avg_conv_4 = - std::make_shared(transposed_avg_conv_4, - opset8::Constant::create(element::i64, Shape{4}, {0, 2, 3, 1})); - auto reshape_avg_conv_4 = std::make_shared( - avg_conv_4, - opset8::Constant::create(element::i64, Shape{2}, Shape{1ull, combined_C_H * mvn_data.W}), - false); - std::shared_ptr inv_stdev; - - // Create normalization part of the graph - // We ignore inside/outside epsilon position here and always use inside, to get better accuracy - // even though the built-in MVN1 to MVN6 transformation enforces outside setting - - // Add epsilon inside the square root - auto add_epsilon = std::make_shared(eps_tensor_const, reshape_avg_conv_4); - - // Calculate square root and inversion - auto log_var_eps = std::make_shared(add_epsilon); - log_var_eps->set_friendly_name(mvn_data.name + "_LogVarEps"); - auto log_inv_stdev = std::make_shared(log_var_eps, minus_half_const); - log_inv_stdev->set_friendly_name(mvn_data.name + "_LogInvStdev"); - inv_stdev = std::make_shared(log_inv_stdev); - inv_stdev->set_friendly_name(mvn_data.name + "_InvStdev"); - copy_runtime_info(mvn, {add_epsilon, log_var_eps, log_inv_stdev, inv_stdev}); - - auto normalized_output = std::make_shared(subtract_mean, inv_stdev); - normalized_output->set_friendly_name(mvn_data.name + "_Output"); - - copy_runtime_info(mvn, - {squared_diff, - squared_diff_reshape, - transposed_input_3, - transposed_avg_conv_3, - avg_conv_3, - reshape_avg_conv_3, - transposed_input_4, - transposed_avg_conv_4, - avg_conv_4, - reshape_avg_conv_4}); - - return normalized_output; -} - -static void Decompose(const std::shared_ptr mvn, const MVNData& mvn_data) { - // Prepare data - auto combined_C_H = mvn_data.C * mvn_data.H; - - std::vector neg_avg_weights(8 * mvn_data.W / mvn_data.num_parts, -1.0f / mvn_data.W); - auto neg_avg_weights_const = opset8::Constant::create(mvn_data.element_type, - Shape{8, mvn_data.W / mvn_data.num_parts, 1, 1}, - neg_avg_weights); - - std::vector avg_broadcast(8 * mvn_data.W * mvn_data.num_parts, 0.0f); - for (size_t i = 0; i < mvn_data.W * mvn_data.num_parts; i++) { - avg_broadcast[i * 8] = 1.0f; - } - auto avg_broadcast_const = - opset8::Constant::create(mvn_data.element_type, Shape{mvn_data.W, 8 * mvn_data.num_parts, 1, 1}, avg_broadcast); - - // Create average calculation part of the graph - // We assume C = 1 case (combined channels) - const auto input = mvn->input_value(0); - auto reshape = std::make_shared( - input, - opset8::Constant::create(element::i64, Shape{4}, Shape{mvn_data.N, 1ull, combined_C_H, mvn_data.W}), - false); - auto input_4d = std::make_shared( - reshape, - opset8::Constant::create( - element::i64, - Shape{4}, - Shape{mvn_data.N, combined_C_H * mvn_data.num_parts, 1ull, mvn_data.W / mvn_data.num_parts}), - false); - auto input_2d = std::make_shared( - reshape, - opset8::Constant::create(element::i64, Shape{2}, Shape{1ull, combined_C_H * mvn_data.W}), - false); - auto transposed_input_1 = - std::make_shared(input_4d, opset8::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2})); - auto transposed_avg_conv_1 = std::make_shared(transposed_input_1, - neg_avg_weights_const, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}, - ov::op::PadType::VALID); - transposed_avg_conv_1->set_friendly_name(mvn_data.name + "_Avg1"); - auto avg_conv_1 = - std::make_shared(transposed_avg_conv_1, - opset8::Constant::create(element::i64, Shape{4}, {0, 2, 3, 1})); - auto reshape_avg_conv_1 = std::make_shared( - avg_conv_1, - opset8::Constant::create(element::i64, Shape{4}, Shape{mvn_data.N, 1ull, combined_C_H, 8 * mvn_data.num_parts}), - false); - auto transposed_input_2 = - std::make_shared(reshape_avg_conv_1, - opset8::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2})); - auto transposed_avg_conv_2 = std::make_shared(transposed_input_2, - avg_broadcast_const, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}, - ov::op::PadType::VALID); - transposed_avg_conv_2->set_friendly_name(mvn_data.name + "_Avg2"); - auto avg_conv_2 = - std::make_shared(transposed_avg_conv_2, - opset8::Constant::create(element::i64, Shape{4}, {0, 2, 3, 1})); - auto avg_conv_2_2d = std::make_shared( - avg_conv_2, - opset8::Constant::create(element::i64, Shape{2}, Shape{1ull, combined_C_H * mvn_data.W}), - false); - auto subtract_mean = std::make_shared(input_2d, avg_conv_2_2d); - subtract_mean->set_friendly_name(mvn_data.name + "_SubMean"); - - std::shared_ptr mvn_output, pre_output = subtract_mean; - - // Normalize variance if required - if (mvn_data.normalize_variance) { - pre_output = NormalizeVariance(mvn, mvn_data, subtract_mean, avg_broadcast_const); - } - - // Reshape (combined channels) back to get the final output - if (mvn->get_output_shape(0).size() == 3) { - mvn_output = std::make_shared( - pre_output, - opset8::Constant::create(element::i64, Shape{3}, {mvn_data.C, mvn_data.H, mvn_data.W}), - false); - } else { - mvn_output = std::make_shared( - pre_output, - opset8::Constant::create(element::i64, Shape{4}, {mvn_data.N, mvn_data.C, mvn_data.H, mvn_data.W}), - false); - } - - copy_runtime_info(mvn, - {reshape, - input_4d, - input_2d, - transposed_input_1, - transposed_avg_conv_1, - avg_conv_1, - reshape_avg_conv_1, - transposed_input_2, - transposed_avg_conv_2, - avg_conv_2, - avg_conv_2_2d, - subtract_mean, - mvn_output}); - - // We need retain the MVN layer name, so its output can be used as a network result - replace_node(mvn, mvn_output); - mvn_output->set_friendly_name(mvn_data.name); -} - -static bool Convert(std::shared_ptr mvn_node) { - const auto mvn = std::dynamic_pointer_cast(mvn_node); - MVNData mvn_data = {}; - - if (!GetVerifiedMVNData(mvn, mvn_data)) - return false; - - Decompose(mvn, mvn_data); - - return true; -} - -static std::function)> verify_rank_batch() { - return [=](Output output) -> bool { - // Only rank 3 and 4 and batch 1 are supported for now - auto rank = output.get_partial_shape().rank(); - if (rank != 3 && rank != 4) - return false; - - auto batch = (rank == 3 ? 1 : output.get_partial_shape()[0]); - if (batch != 1) - return false; - - return true; - }; -} - -DecomposeMVN::DecomposeMVN() { - MATCHER_SCOPE(DecomposeMVN); - - auto axes = pattern::wrap_type(); - auto mvn = pattern::wrap_type({pattern::any_input(), axes}, verify_rank_batch()); - - matcher_pass_callback callback = [=](pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - return Convert(pattern_map.at(mvn).get_node_shared_ptr()); - }; - - auto m = std::make_shared(mvn, matcher_name); - this->register_matcher(m, callback); -} - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/decompose_mvn.hpp b/src/plugins/intel_gna/src/transformations/decompose_mvn.hpp deleted file mode 100644 index 39dfc6a9117..00000000000 --- a/src/plugins/intel_gna/src/transformations/decompose_mvn.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Decompose MVN operation - * See official OpenVINO documentation for the MVN formula - * implemented partially by this decomposition: - * https://docs.openvino.ai/2023.0/openvino_docs_ops_normalization_MVN_6.html - * - */ -class DecomposeMVN : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("DecomposeMVN", "0"); - DecomposeMVN(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/fuse_conv_bias_activation.cpp b/src/plugins/intel_gna/src/transformations/fuse_conv_bias_activation.cpp deleted file mode 100644 index 895bc4d0260..00000000000 --- a/src/plugins/intel_gna/src/transformations/fuse_conv_bias_activation.cpp +++ /dev/null @@ -1,390 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "fuse_conv_bias_activation.hpp" - -#include -#include -#include - -#include "exec_graph_info.hpp" -#include "openvino/cc/ngraph/itt.hpp" -#include "openvino/core/graph_util.hpp" -#include "openvino/core/node.hpp" -#include "openvino/core/node_output.hpp" -#include "openvino/core/rt_info.hpp" -#include "openvino/core/shape.hpp" -#include "openvino/core/type/element_type.hpp" -#include "openvino/op/util/multi_subgraph_base.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset10.hpp" -#include "openvino/pass/manager.hpp" -#include "openvino/pass/pattern/matcher.hpp" -#include "openvino/pass/pattern/op/label.hpp" -#include "openvino/pass/pattern/op/or.hpp" -#include "openvino/pass/pattern/op/pattern.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "ops/gna_convolution.hpp" -#include "rt_info/gna_node_id.hpp" - -using namespace ov::pass::pattern; -using namespace ov::intel_gna::op; -using namespace ov::intel_gna::rt_info; -using namespace ov::opset10; - -namespace { -template -std::pair, std::shared_ptr> parse_eltwise_inputs(std::shared_ptr node) { - auto eltwise = std::dynamic_pointer_cast
(node->input(0).get_source_output().get_node_shared_ptr()); - auto constant = std::dynamic_pointer_cast(node->input(1).get_source_output().get_node_shared_ptr()); - - if (!eltwise) { - eltwise = std::dynamic_pointer_cast(node->input(1).get_source_output().get_node_shared_ptr()); - constant = std::dynamic_pointer_cast(node->input(0).get_source_output().get_node_shared_ptr()); - } - - if (!eltwise || !constant) { - return {nullptr, nullptr}; - } - - return {eltwise, constant}; -} - -struct GnaConvCallbacks { - static bool gna_convolution_with_biasadd(Matcher& m) { - auto eltwise = m.get_match_root(); - auto m_conv_const_pair = parse_eltwise_inputs(eltwise); - auto m_conv = m_conv_const_pair.first; - auto m_const = m_conv_const_pair.second; - - if (!m_conv || !m_const) { - return false; - } - - if (m_conv->inputs().size() != 2) { - return false; - } - - if (std::dynamic_pointer_cast(eltwise) == nullptr) { - return false; - } - - const ov::Output& data = m_conv->input(0).get_source_output(); - const ov::Output& filters = m_conv->input(1).get_source_output(); - const ov::Output& bias = m_const->output(0); - - std::shared_ptr gna_conv = std::make_shared(data, - filters, - bias, - m_conv->get_strides(), - m_conv->get_pads_begin(), - m_conv->get_pads_end(), - m_conv->get_dilations(), - m_conv->get_auto_pad()); - - gna_conv->set_friendly_name(eltwise->get_friendly_name()); - - ov::copy_runtime_info({m_conv, eltwise}, gna_conv); - set_node_id(gna_conv, get_node_id(eltwise)); - - const std::string originalLayers = eltwise->get_friendly_name() + "," + m_conv->get_friendly_name(); - gna_conv->get_rt_info()[ExecGraphInfoSerialization::ORIGINAL_NAMES] = originalLayers; - - ov::replace_node(eltwise, gna_conv); - return true; - } - - static std::pair, std::shared_ptr> parse_gna_conv_inputs( - std::shared_ptr add) { - std::shared_ptr gna_conv = nullptr; - - auto input0 = add->input(0).get_source_output().get_node_shared_ptr(); - auto input1 = add->input(1).get_source_output().get_node_shared_ptr(); - - auto gna_conv0 = std::dynamic_pointer_cast(input0); - auto gna_conv1 = std::dynamic_pointer_cast(input1); - - auto can_be_fused = [](const std::shared_ptr& target, const std::shared_ptr& fused_input) { - return (target && fused_input && - (get_node_id(target) > get_node_id(fused_input) || ov::op::util::is_constant(fused_input))); - }; - - if (gna_conv0 && gna_conv1) { - if (can_be_fused(gna_conv0, input1)) { - return {gna_conv0, input1}; - } else if (can_be_fused(gna_conv1, input0)) { - return {gna_conv1, input0}; - } - } - - if (gna_conv0 && can_be_fused(gna_conv0, input1)) { - return {gna_conv0, input1}; - } - - if (gna_conv1 && can_be_fused(gna_conv1, input0)) { - return {gna_conv1, input0}; - } - return {nullptr, nullptr}; - } - - static bool sink_add_to_gna_convolution(Matcher& m) { - auto add = std::dynamic_pointer_cast(m.get_match_root()); - auto gna_conv_node_pair = parse_gna_conv_inputs(m.get_match_root()); - auto gna_conv = gna_conv_node_pair.first; - auto node = gna_conv_node_pair.second; - - if (!gna_conv || !node) { - return false; - } - - if (gna_conv->has_bias() || gna_conv->get_activation() != ActivationType::NO_ACTIVATION) { - return false; - } - - const ov::Output& data = gna_conv->input(0).get_source_output(); - const ov::Output& filters = gna_conv->input(1).get_source_output(); - const ov::Output& bias = gna_conv->input(2).get_source_output(); - - std::shared_ptr gna_conv_add = std::make_shared(data, - filters, - bias, - gna_conv->get_strides(), - gna_conv->get_pads_begin(), - gna_conv->get_pads_end(), - gna_conv->get_dilations(), - gna_conv->get_auto_pad()); - - gna_conv_add->set_friendly_name(add->get_friendly_name()); - ov::copy_runtime_info({node, gna_conv}, gna_conv_add); - set_node_id(gna_conv_add, get_node_id(add)); - - auto& rt_info = gna_conv->get_rt_info(); - if (rt_info.count(ExecGraphInfoSerialization::ORIGINAL_NAMES) > 0) { - auto& rt_info_layer_names = rt_info[ExecGraphInfoSerialization::ORIGINAL_NAMES]; - const auto original_names = rt_info_layer_names.template as(); - const std::string original_names_with_activation = add->get_friendly_name() + "," + original_names; - rt_info_layer_names = original_names_with_activation; - } - - ov::replace_node(gna_conv, gna_conv_add); - ov::replace_node(m.get_match_root(), gna_conv_add); - - return true; - } - - static bool sink_activation_to_gna_convolution(Matcher& m) { - auto activation_node = m.get_match_root(); - auto gna_conv = std::dynamic_pointer_cast( - activation_node->input(0).get_source_output().get_node_shared_ptr()); - if (gna_conv->get_activation() != ActivationType::NO_ACTIVATION) { - return false; - } - - ActivationType activation = ActivationType::NO_ACTIVATION; - if (ov::is_type(activation_node)) { - activation = ActivationType::RELU; - } else if (ov::is_type(activation_node)) { - activation = ActivationType::SIGMOID; - } else if (ov::is_type(activation_node)) { - activation = ActivationType::TANH; - } else if (ov::is_type(activation_node)) { - activation = ActivationType::LOG; - } else if (ov::is_type(activation_node)) { - activation = ActivationType::ABS; - } else if (ov::is_type(activation_node)) { - activation = ActivationType::SIGN; - } else if (ov::is_type(activation_node)) { - activation = ActivationType::CLAMP; - } else { - return false; - } - gna_conv->set_activation(activation); - - gna_conv->set_friendly_name(activation_node->get_friendly_name()); - set_node_id(gna_conv, get_node_id(activation_node)); - - auto& rt_info = gna_conv->get_rt_info(); - if (rt_info.count(ExecGraphInfoSerialization::ORIGINAL_NAMES) > 0) { - auto& rt_info_layer_names = rt_info[ExecGraphInfoSerialization::ORIGINAL_NAMES]; - const auto original_names = rt_info_layer_names.template as(); - const std::string original_names_with_activation = - activation_node->get_friendly_name() + "," + original_names; - rt_info_layer_names = original_names_with_activation; - } - - ov::replace_node(m.get_match_root(), gna_conv); - - return true; - } -}; // struct GnaConvCallbacks - -bool is_bias_to_be_fused(const ov::Output& output) { - constexpr auto conv_bias_rank_min{3}; - constexpr auto conv_bias_rank_max{5}; - auto node = std::dynamic_pointer_cast(output.get_node_shared_ptr()); - if (!node) { - return false; - } - - auto input0 = node->input(0); - auto input1 = node->input(1); - - const auto partial_shape0 = node->input(0).get_partial_shape(); - const auto partial_shape1 = node->input(1).get_partial_shape(); - - if (partial_shape0.is_dynamic() || partial_shape1.is_dynamic()) { - return false; - } - - if (node->get_autob() != ov::op::AutoBroadcastType::NUMPY) { - return false; - } - - if (input0.get_element_type() != input1.get_element_type()) { - return false; - } - - const auto conv_shape = partial_shape0.to_shape(); - const auto bias_shape = partial_shape1.to_shape(); - const auto bias_rank = bias_shape.size(); - if (bias_rank < conv_bias_rank_min || bias_rank > conv_bias_rank_max) { - return false; - } - - // NHWC or HWC - size_t bias_channel_index = bias_shape.size() - 1; - size_t conv_channel_index = conv_shape.size() - 1; - if (bias_shape.at(bias_channel_index) != conv_shape.at(conv_channel_index) && - bias_shape.at(bias_channel_index) != 1) { - return false; - } - for (size_t i = 0; i < bias_shape.size(); i++) { - if ((i != bias_channel_index) && (bias_shape.at(i) != 1)) - return false; - } - return true; -} -bool is_add_to_be_fused(const ov::Output& output) { - auto node = std::dynamic_pointer_cast(output.get_node_shared_ptr()); - if (!node) { - return false; - } - - auto input0 = node->input(0); - auto input1 = node->input(1); - - const auto partial_shape0 = node->input(0).get_partial_shape(); - const auto partial_shape1 = node->input(1).get_partial_shape(); - - if (input0.get_element_type() != input1.get_element_type()) { - return false; - } - - if (partial_shape0.is_dynamic() || partial_shape1.is_dynamic()) { - return false; - } - return (partial_shape0.to_shape() == partial_shape1.to_shape()); -} - -bool set_nodes_order(const std::shared_ptr& model, uint64_t& id) { - for (auto& node : model->get_ordered_ops()) { - if (auto sub_graph_node = std::dynamic_pointer_cast(node)) { - size_t sub_graphs_num = sub_graph_node->get_internal_subgraphs_size(); - for (size_t sub_graph_ind = 0; sub_graph_ind < sub_graphs_num; ++sub_graph_ind) { - const std::shared_ptr& sub_model = - sub_graph_node->get_function(static_cast(sub_graph_ind)); - set_nodes_order(sub_model, id); - } - } - set_node_id(node, id++); - } - return true; -} - -bool reset_nodes_order(const std::shared_ptr& model) { - for (auto& node : model->get_ordered_ops()) { - if (auto sub_graph_node = std::dynamic_pointer_cast(node)) { - size_t sub_graphs_num = sub_graph_node->get_internal_subgraphs_size(); - for (size_t sub_graph_ind = 0; sub_graph_ind < sub_graphs_num; ++sub_graph_ind) { - const std::shared_ptr& sub_model = - sub_graph_node->get_function(static_cast(sub_graph_ind)); - reset_nodes_order(sub_model); - } - } - remove_node_id(node); - } - return true; -} - -} // namespace - -bool ov::intel_gna::pass::GnaFuseMarkUpNodesOrder::run_on_model(const std::shared_ptr& m) { - RUN_ON_FUNCTION_SCOPE(GnaFuseMarkUpNodesOrder); - uint64_t init_id = 0; - return set_nodes_order(m, init_id); -} - -bool ov::intel_gna::pass::GnaFuseCleanUpNodesOrder::run_on_model(const std::shared_ptr& m) { - RUN_ON_FUNCTION_SCOPE(GnaFuseCleanUpNodesOrder); - return reset_nodes_order(m); -} - -ov::intel_gna::pass::FuseConvolutionWithBiasAdd::FuseConvolutionWithBiasAdd() { - MATCHER_SCOPE(FuseConvolutionWithBiasAdd); - auto conv = wrap_type(consumers_count(1)); - auto bias = wrap_type(); - auto add = wrap_type({conv, bias}, is_bias_to_be_fused); - - matcher_pass_callback callback = [](Matcher& m) { - return GnaConvCallbacks::gna_convolution_with_biasadd(m); - }; - - auto m = std::make_shared(add, matcher_name); - register_matcher(m, callback); -} - -ov::intel_gna::pass::FuseConvolutionWithBiasAddAdd::FuseConvolutionWithBiasAddAdd() { - MATCHER_SCOPE(FuseConvolutionWithBiasAddAdd); - auto gna_convolution = wrap_type(consumers_count(1)); - auto add1 = wrap_type({gna_convolution, any_input()}, is_add_to_be_fused); - auto add2 = wrap_type({any_input(), gna_convolution}, is_add_to_be_fused); - auto add = std::make_shared<::op::Or>(ov::OutputVector{add1, add2}); - - matcher_pass_callback callback = [](Matcher& m) { - return GnaConvCallbacks::sink_add_to_gna_convolution(m); - }; - - auto m = std::make_shared(add, matcher_name); - register_matcher(m, callback); -} - -ov::intel_gna::pass::SinkActivationToGnaConvolution::SinkActivationToGnaConvolution() { - MATCHER_SCOPE(SinkActivationToGnaConvolution); - auto gna_convolution = wrap_type(consumers_count(1)); - auto activation = wrap_type({gna_convolution}); - - matcher_pass_callback callback = [](Matcher& m) { - return GnaConvCallbacks::sink_activation_to_gna_convolution(m); - }; - - auto m = std::make_shared(activation, matcher_name); - register_matcher(m, callback); -} - -bool ov::intel_gna::pass::GnaConvolutionFusion::run_on_model(const std::shared_ptr& m) { - RUN_ON_FUNCTION_SCOPE(GnaConvolutionFusion); - ov::pass::Manager manager(get_pass_config()); - - manager.register_pass(); - - auto fuse_conv_bias_add_activation = manager.register_pass(); - ADD_MATCHER(fuse_conv_bias_add_activation, FuseConvolutionWithBiasAdd) - ADD_MATCHER(fuse_conv_bias_add_activation, FuseConvolutionWithBiasAddAdd) - ADD_MATCHER(fuse_conv_bias_add_activation, SinkActivationToGnaConvolution) - fuse_conv_bias_add_activation->set_name("ov::intel_gna::pass::fuse_conv_bias_add_activation"); - - manager.register_pass(); - - manager.run_passes(m); - return false; -} diff --git a/src/plugins/intel_gna/src/transformations/fuse_conv_bias_activation.hpp b/src/plugins/intel_gna/src/transformations/fuse_conv_bias_activation.hpp deleted file mode 100644 index 58a3e0290f3..00000000000 --- a/src/plugins/intel_gna/src/transformations/fuse_conv_bias_activation.hpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "openvino/pass/graph_rewrite.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -class GnaFuseMarkUpNodesOrder : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("GnaFuseMarkUpNodesOrder", "0"); - bool run_on_model(const std::shared_ptr& m) override; -}; - -class GnaFuseCleanUpNodesOrder : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("GnaFuseCleanUpNodesOrder", "0"); - bool run_on_model(const std::shared_ptr& m) override; -}; - -class FuseConvolutionWithBiasAdd : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("FuseConvolutionWithBiasAdd", "0"); - FuseConvolutionWithBiasAdd(); -}; - -class FuseGroupConvolutionWithBiasAdd : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("FuseGroupConvolutionWithBiasAdd", "0"); - FuseGroupConvolutionWithBiasAdd(); -}; - -class FuseConvolutionWithBiasAddAdd : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("FuseConvolutionWithBiasAddAdd", "0"); - FuseConvolutionWithBiasAddAdd(); -}; - -class SinkActivationToGnaConvolution : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("SinkActivationToGnaConvolution", "0"); - SinkActivationToGnaConvolution(); -}; - -class GnaConvolutionFusion : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("GnaConvolutionFusion", "0"); - bool run_on_model(const std::shared_ptr& m) override; -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking.cpp b/src/plugins/intel_gna/src/transformations/gather_sinking.cpp deleted file mode 100644 index 30e13146fa4..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking.hpp" - -#include "openvino/cc/pass/itt.hpp" -#include "openvino/core/rt_info.hpp" -#include "openvino/pass/constant_folding.hpp" -#include "openvino/pass/graph_rewrite.hpp" -#include "openvino/pass/manager.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "transformations/gather_sinking_binary.hpp" -#include "transformations/gather_sinking_fuse.hpp" -#include "transformations/gather_sinking_matmul.hpp" -#include "transformations/gather_sinking_reshape.hpp" -#include "transformations/gather_sinking_split.hpp" -#include "transformations/gather_sinking_transpose_reshape.hpp" -#include "transformations/gather_sinking_unary.hpp" - -using namespace ov; -using namespace ov::pass::pattern; -using namespace ov::op::util; -using namespace ov::intel_gna::pass; - -GatherSinkingGeneralForward::GatherSinkingGeneralForward() { - MATCHER_SCOPE(GatherSinkingGeneralForward); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); -} - -GatherSinkingGeneralBackward::GatherSinkingGeneralBackward() { - MATCHER_SCOPE(GatherSinkingGeneralBackward); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); -} - -bool GatherSinkingGeneral::run_on_model(const std::shared_ptr& f) { - RUN_ON_MODEL_SCOPE(GatherSinkingGeneral); - { - ov::pass::Manager manager(get_pass_config()); - manager.register_pass(); - manager.register_pass(); - manager.run_passes(f); - } - - { - ov::pass::Manager manager(get_pass_config()); - manager.register_pass(); - manager.register_pass(); - manager.run_passes(f); - } - - return false; -} diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking.hpp b/src/plugins/intel_gna/src/transformations/gather_sinking.hpp deleted file mode 100644 index 888fb8453da..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -class GatherSinkingGeneralForward : public ov::pass::GraphRewrite { -public: - OPENVINO_RTTI("GatherSinkingGeneralForward", "0"); - GatherSinkingGeneralForward(); -}; - -class GatherSinkingGeneralBackward : public ov::pass::GraphRewrite { -public: - OPENVINO_RTTI("GatherSinkingGeneralBackward", "0"); - GatherSinkingGeneralBackward(); -}; - -class GatherSinkingGeneral : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("GatherSinkingGeneral", "0"); - bool run_on_model(const std::shared_ptr& m) override; -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_binary.cpp b/src/plugins/intel_gna/src/transformations/gather_sinking_binary.cpp deleted file mode 100644 index 47a9cf51214..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_binary.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_binary.hpp" - -#include -#include - -#include "common/graph_utils.hpp" -#include "openvino/cc/ngraph/itt.hpp" -#include "openvino/op/util/op_types.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/opsets/opset9.hpp" -#include "openvino/pass/pattern/op/label.hpp" -#include "openvino/pass/pattern/op/or.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "openvino/util/common_util.hpp" -#include "openvino/util/log.hpp" -#include "transformations/rt_info/gather_sinking_attr.hpp" -#include "transformations/utils/gather_sinking_utils.hpp" -#include "transformations/utils/transformation_helper.hpp" - -using namespace ov; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace ov::op::util; -using namespace gather_sinking; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::rt_info; -using namespace ov::intel_gna::pass::helper; -using namespace ov::intel_gna::graph_utils; - -GatherSinkingBinaryForward::GatherSinkingBinaryForward() { - MATCHER_SCOPE(GatherSinkingBinaryForward); - - auto if_gather_has_constants_rank_not_more_than_one = [](const GatherInputsInfo& inputs_info) -> bool { - return constant_has_rank_not_more_than(inputs_info.axis_const, 1) && - constant_has_rank_not_more_than(inputs_info.indices_const, 1); - }; - - auto main_node_label = wrap_type( - [if_gather_has_constants_rank_not_more_than_one](const Output& output) -> bool { - return if_node_has_gather_inputs(output, if_gather_has_constants_rank_not_more_than_one); - }); - - matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - - auto& main_node_output = pattern_to_output.at(main_node_label); - auto main_node = main_node_output.get_node_shared_ptr(); - - GatherInputsInfo gather_input_info = get_first_gather_input(main_node); - - sink_forward::update_input_gather(main_node, gather_input_info); - for (auto& new_node : sink_forward::insert_output_gather(main_node, gather_input_info)) { - register_new_node(new_node); - gather_sinking::update_forward_gather_sinking_ability(new_node); - } - - return true; - }; - - auto m = std::make_shared(main_node_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} - -GatherSinkingBinaryBackward::GatherSinkingBinaryBackward() { - MATCHER_SCOPE(GatherSinkingBinaryBackward); - auto main_node_label = wrap_type([](const Output& output) -> bool { - return has_static_rank()(output) && has_same_output_gather_nodes(output); - }); - - auto indices_const_label = wrap_type(rank_not_more_than(1)); - auto axes_const_label = wrap_type(rank_not_more_than(1)); - - auto gather_label = wrap_type({main_node_label, indices_const_label, axes_const_label}, - [](const Output& output) -> bool { - return has_static_rank()(output) && is_gather_sinking_node(output); - }); - - matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto indices_const = as_type_ptr(pattern_to_output.at(indices_const_label).get_node_shared_ptr()); - auto axes_const = as_type_ptr(pattern_to_output.at(axes_const_label).get_node_shared_ptr()); - auto gather = as_type_ptr(pattern_to_output.at(gather_label).get_node_shared_ptr()); - auto main_node = pattern_to_output.at(main_node_label).get_node_shared_ptr(); - - for (auto& new_node : sink_backward::insert_gather_before_node(main_node, indices_const, axes_const, gather)) { - register_new_node(new_node); - } - - // remove output transposes - remove_single_output_consumers(main_node); - - swap_names(gather, main_node); - - return true; - }; - - auto m = std::make_shared(gather_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_binary.hpp b/src/plugins/intel_gna/src/transformations/gather_sinking_binary.hpp deleted file mode 100644 index 1511efdc4f9..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_binary.hpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" -#include "openvino/pass/pass.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief - * Moves Gather layer forward from the start to the end of the graph - * through the BinaryElementwiseArithmetic operations (it is called from GatherSinkingGeneral transformation). - * Gather layer is moved from the Binary input to the Binary output. Reversed Gather layer is moved - * to another Binary input. - * Reversed Gather is a layer which, when put after the original gather, results in a subgraph that has no effect - * Reversed Gather layer is expected to be pushed by backward GatherSinking to another - * Model input or a constant. After all sinking operations we hope to find all Gather - * layers on Model inputs and execute them on CPU or before constants and fold them. - * Transformation restrictions: - * - Gather has only 1D indices - * - all nodes have static ranks - * - * Any1 Any1 Any2 - * | | | - * Gather Any2 | Reversed-Gather - * | | => | | - * Binary Binary - * | | - * Any3 Gather - * | - * Any3 - * - * Any1 Any2 Any1 - * | | | - * Any2 Gather Reversed-Gather | - * | | => | | - * Binary Binary - * | | - * Any3 Gather - * | - * Any3 - * - * All GatherSinking tranformations are designed to work in 2 steps: - * - forward push - * - backward push - * Add flag into Gather layer rt_info that prevents backward sinking if the next layer - * after Gather does not support by GatherSinking transformations. That is done to - * prevent backward pushing the layer that already pushed forward through the graph. - */ -class GatherSinkingBinaryForward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingBinaryForward", "0"); - GatherSinkingBinaryForward(); -}; - -/** - * @brief - * Moves Gather layer backward from the end to the start of the graph - * - * Any1 Any2 Any1 Any2 - * | | | | - * Binary => Gather Gather - * | | | - * Gather Binary - * | | - * Any3 Any3 - * - * Any1 Any2 Any1 Any2 - * | | | | - * Binary => Gather Gather - * | | | | - * Gather Gather Binary - * | | | | - * Any3 Any4 Any3 Any4 - * - * Moves Gather layer backward only if: - * - Gather is not marked as non-sinkable - * - all Binary consumers are Gather layers - * - all that Gather layers equal each other - * - all Gather layers have only 1D indices - * - all nodes have static ranks - * - * This transformation is called called from GatherSinkingGeneral. - */ -class GatherSinkingBinaryBackward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingBinaryBackward", "0"); - GatherSinkingBinaryBackward(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_fuse.cpp b/src/plugins/intel_gna/src/transformations/gather_sinking_fuse.cpp deleted file mode 100644 index 8f21296de50..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_fuse.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_fuse.hpp" - -#include -#include - -#include "common/graph_utils.hpp" -#include "openvino/cc/ngraph/itt.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "transformations/rt_info/gather_sinking_attr.hpp" -#include "transformations/utils/gather_sinking_utils.hpp" - -using namespace ov; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace ov::op::util; -using namespace gather_sinking; -using namespace ov::intel_gna::graph_utils; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::rt_info; - -namespace { -bool is_gather_with_parent_gather_same_axis(const Output& output) { - int64_t output_gather_axis = {}; - if (!get_gather_axis(output.get_node_shared_ptr(), output_gather_axis)) - return false; - int64_t input_gather_axis = {}; - if (!get_gather_axis(output.get_node_shared_ptr()->input_value(0).get_node_shared_ptr(), input_gather_axis)) - return false; - return input_gather_axis == output_gather_axis; -} - -struct TransformationInfo { - std::shared_ptr input_indices_const; - std::shared_ptr input_axis_const; - std::shared_ptr input_gather; - std::shared_ptr output_indices_const; - std::shared_ptr output_axis_const; - std::shared_ptr output_gather; -}; - -std::vector combine_gather_permutations(const std::vector& input_gather_indices, - const std::vector& output_gather_indices) { - if (input_gather_indices.size() != output_gather_indices.size()) - return {}; - std::vector result(input_gather_indices.size()); - for (size_t i = 0; i < result.size(); ++i) { - result[i] = input_gather_indices[output_gather_indices[i]]; - } - - return result; -} - -std::shared_ptr fuse_gather_nodes(TransformationInfo& info) { - const std::vector input_gather_indices = get_normalized_gather_indices(info.input_indices_const); - const std::vector output_gather_indices = get_normalized_gather_indices(info.output_indices_const); - const std::vector result_gather_indices = - combine_gather_permutations(input_gather_indices, output_gather_indices); - if (is_pointless_permutation(result_gather_indices)) { - ov::replace_output_update_name(info.output_gather->output(0), info.input_gather->input_value(0)); - return {}; - } - - const auto indices_element_type = info.output_axis_const->get_element_type(); - auto new_indices_const = - std::make_shared(indices_element_type, Shape{result_gather_indices.size()}, result_gather_indices); - auto new_axis_const = info.output_axis_const->clone_with_new_inputs({}); - auto new_gather = std::make_shared(info.input_gather->input_value(0), new_indices_const, new_axis_const); - - ov::replace_node(info.output_gather, new_gather); - copy_runtime_info(info.input_gather, {new_gather, new_indices_const, new_axis_const}); - new_gather->set_friendly_name(info.output_gather->get_friendly_name()); - - return new_gather; -} -} // namespace - -GatherSinkingFuse::GatherSinkingFuse() { - MATCHER_SCOPE(GatherSinkingFuse); - - auto input_indices_const_label = wrap_type(is_constant_1d); - auto input_axis_const_label = wrap_type(is_constant_1d); - auto input_gather_label = wrap_type({any_input(), input_indices_const_label, input_axis_const_label}); - auto output_indices_const_label = wrap_type(is_constant_1d); - auto output_axis_const_label = wrap_type(is_constant_1d); - auto output_gather_label = - wrap_type({input_gather_label, output_indices_const_label, output_axis_const_label}, - is_gather_with_parent_gather_same_axis); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - TransformationInfo info; - info.input_indices_const = - as_type_ptr(pattern_to_output.at(input_indices_const_label).get_node_shared_ptr()); - info.input_axis_const = - as_type_ptr(pattern_to_output.at(input_axis_const_label).get_node_shared_ptr()); - info.input_gather = as_type_ptr(pattern_to_output.at(input_gather_label).get_node_shared_ptr()); - info.output_indices_const = - as_type_ptr(pattern_to_output.at(output_indices_const_label).get_node_shared_ptr()); - info.output_axis_const = - as_type_ptr(pattern_to_output.at(output_axis_const_label).get_node_shared_ptr()); - info.output_gather = as_type_ptr(pattern_to_output.at(output_gather_label).get_node_shared_ptr()); - - auto new_node = fuse_gather_nodes(info); - if (new_node) - register_new_node(new_node); - - return true; - }; - - auto m = std::make_shared(output_gather_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_fuse.hpp b/src/plugins/intel_gna/src/transformations/gather_sinking_fuse.hpp deleted file mode 100644 index 80a90ded0f5..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_fuse.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2023 Intel Corporation2 -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief - * Fuses (merges) 2 consecutive Gather nodes into one. If resulting Gather node - * does nothing with input (it does not actually permute items), just removes Gather nodes. - * - * Any #1 Any #1 - * | | - * Gather #1 Gather #3 - * | => | - * Gather #2 Any #2 - * | - * Any #2 - * - * or - * - * Any #1 Any #1 - * | | - * Gather #1 Any #2 - * | => - * Gather #2 - * | - * Any #2 - * - * This transformation is called called from GatherSinkingGeneral. - */ -class GatherSinkingFuse : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingFuse", "0"); - GatherSinkingFuse(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_matmul.cpp b/src/plugins/intel_gna/src/transformations/gather_sinking_matmul.cpp deleted file mode 100644 index 498d8303b15..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_matmul.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_matmul.hpp" - -#include -#include - -#include "common/graph_utils.hpp" -#include "openvino/cc/ngraph/itt.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "transformations/rt_info/gather_sinking_attr.hpp" -#include "transformations/utils/gather_sinking_utils.hpp" -#include "transformations/utils/transformation_helper.hpp" - -using namespace ov; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace ov::op::util; -using namespace gather_sinking; -using namespace ov::intel_gna::graph_utils; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::rt_info; -using namespace ov::intel_gna::pass::helper; - -namespace { -bool has_gather_inputs(const Output& output) { - return !get_first_gather_input(output.get_node_shared_ptr()).isEmpty(); -} - -bool is_matmul_sinked(const Output& output) { - return has_2d_inputs(output) && has_gather_inputs(output); -} - -int64_t get_another_input_negative_axis(int64_t axis) { - if (axis == -1) - return -2; - return -1; -} - -} // namespace - -GatherSinkingMatmulForward::GatherSinkingMatmulForward() { - MATCHER_SCOPE(GatherSinkingMatmulForward); - - auto matmul_label = wrap_type({any_input(), any_input()}, is_matmul_sinked); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto matmul = as_type_ptr(pattern_to_output.at(matmul_label).get_node_shared_ptr()); - GatherInputsInfo gather_input_info = get_first_gather_input(matmul); - - int64_t gather_negative_axis = get_normalized_negative_gather_axis( - gather_input_info.axis_const, - gather_input_info.gather->get_input_partial_shape(0).rank().get_length()); - gather_negative_axis = get_another_input_negative_axis(gather_negative_axis); - const auto another_input_idx = gather_input_info.input_idx ? 0 : 1; - if (is_matmul_input_transposed(matmul, another_input_idx)) - gather_negative_axis = get_another_input_negative_axis(gather_negative_axis); - - sink_forward::update_input_gather(matmul, gather_input_info, &gather_negative_axis); - return true; - }; - - auto m = std::make_shared(matmul_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} - -GatherSinkingMatmulBackward::GatherSinkingMatmulBackward() { - MATCHER_SCOPE(GatherSinkingMatmulBackward); - - auto matmul_label = wrap_type({any_input(), any_input()}, has_2d_inputs); - auto indices_const_label = wrap_type(is_constant_1d); - auto axis_const_label = wrap_type(is_constant_1d); - auto gather_label = wrap_type({matmul_label, indices_const_label, axis_const_label}, - [](const Output& output) -> bool { - return has_static_rank()(output) && is_gather_sinking_node(output); - }); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto matmul = as_type_ptr(pattern_to_output.at(matmul_label).get_node_shared_ptr()); - auto axis_const = as_type_ptr(pattern_to_output.at(axis_const_label).get_node_shared_ptr()); - auto indices_const = as_type_ptr(pattern_to_output.at(indices_const_label).get_node_shared_ptr()); - auto gather = as_type_ptr(pattern_to_output.at(gather_label).get_node_shared_ptr()); - - int64_t gather_negative_axis = - get_normalized_negative_gather_axis(axis_const, gather->get_input_partial_shape(0).rank().get_length()); - const int matmul_insert_input_idx = static_cast( - convert_axis_to_positive(gather_negative_axis, gather->get_input_partial_shape(0).rank().get_length())); - if (is_matmul_input_transposed(matmul, static_cast(gather_negative_axis))) - gather_negative_axis = get_another_input_negative_axis(gather_negative_axis); - auto new_axis_const = std::make_shared(axis_const->get_element_type(), Shape{}, gather_negative_axis); - for (auto& new_node : sink_backward::insert_gather_before_node(matmul, - indices_const, - new_axis_const, - gather, - std::vector{matmul_insert_input_idx})) { - register_new_node(new_node); - } - - // remove output transposes - remove_single_output_consumers(matmul); - - swap_names(gather, matmul); - - return true; - }; - - auto m = std::make_shared(gather_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_matmul.hpp b/src/plugins/intel_gna/src/transformations/gather_sinking_matmul.hpp deleted file mode 100644 index fd9818bfb7a..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_matmul.hpp +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** @brief - * Moves Gather node from one input to another. It is used as a forward Gather sinking - * step. - * - * Any #1 Any #2 Any #1 Any #2 - * | | | | - * Gather | => | reversed Gather - * | | | | - * MatMul MatMul - * | | - * Any #3 Any #3 - * - * or - * - * Any #1 Any #2 Any #1 Any #2 - * | | | | - * | Gather => reversed Gather | - * | | | | - * MatMul MatMul - * | | - * Any #3 Any #3 - * - * This transformation is called from GatherSinkingGeneral. - */ - -class GatherSinkingMatmulForward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingMatmulForward", "0"); - GatherSinkingMatmulForward(); -}; - -/** @brief - * Moves Gather layer through the MatMul operation within backward sinking step - * in a direction from end to start of the graph. - * - * Any #1 Any #2 Any #1 Any #2 - * | | | | - * | | => Gather | - * | | | | - * MatMul MatMul - * | | - * Gather Any3 - * | - * Any #3 - * - * or - * - * Any #1 Any #2 Any #1 Any #2 - * | | | | - * | | => | Gather - * | | | | - * MatMul MatMul - * | | - * Gather Any3 - * | - * Any #3 - * - * Input index depends on the shapes and Gather axis. - * This transformation is called from GatherSinkingGeneral. - */ - -class GatherSinkingMatmulBackward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingMatmulBackward", "0"); - GatherSinkingMatmulBackward(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_reshape.cpp b/src/plugins/intel_gna/src/transformations/gather_sinking_reshape.cpp deleted file mode 100644 index 4f25586598a..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_reshape.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_reshape.hpp" - -#include -#include - -#include "common/graph_utils.hpp" -#include "openvino/cc/ngraph/itt.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "transformations/rt_info/gather_sinking_attr.hpp" -#include "transformations/utils/gather_sinking_utils.hpp" - -using namespace ov; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace ov::op::util; -using namespace gather_sinking; -using namespace ov::intel_gna::graph_utils; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::rt_info; - -namespace { - -using NodePtr = std::shared_ptr; - -int get_shapes_squeeze_shift(const Shape& shape1, const Shape& shape2) { - const int index_1 = static_cast(get_first_valuable_dim_id(shape1)); - const int index_2 = static_cast(get_first_valuable_dim_id(shape2)); - - if (index_1 < 0 || index_2 < 0) - return 0; - return index_1 - index_2; -} - -} // namespace - -GatherSinkingReshapeBackward::GatherSinkingReshapeBackward() { - MATCHER_SCOPE(GatherSinkingReshapeBackward); - auto reshape_const_label = wrap_type(); - auto reshape_label = wrap_type({any_input(), reshape_const_label}, is_reshape_unsqueeze); - auto gather_indices_label = wrap_type(); - auto gather_axis_label = wrap_type(); - auto gather_label = - wrap_type({reshape_label, gather_indices_label, gather_axis_label}, is_gather_sinking_enabled); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto gather_indices = as_type_ptr(pattern_to_output.at(gather_indices_label).get_node_shared_ptr()); - auto gather_axis = as_type_ptr(pattern_to_output.at(gather_axis_label).get_node_shared_ptr()); - auto gather = as_type_ptr(pattern_to_output.at(gather_label).get_node_shared_ptr()); - auto reshape_const = as_type_ptr(pattern_to_output.at(reshape_const_label).get_node_shared_ptr()); - auto reshape = as_type_ptr(pattern_to_output.at(reshape_label).get_node_shared_ptr()); - - const int left_shift = get_shapes_squeeze_shift(reshape->get_input_shape(0), reshape->get_output_shape(0)); - size_t gather_axis_value_current = - convert_axis_to_positive(gather_axis->cast_vector()[0], gather->get_input_shape(0).size()); - size_t gather_axis_value_new = gather_axis_value_current - left_shift; - - auto gather_axis_new = std::make_shared(element::i64, Shape{}, gather_axis_value_new); - auto gather_indices_new = gather_indices->clone_with_new_inputs({}); - auto gather_new = std::make_shared(reshape->input_value(0), gather_indices_new, gather_axis_new); - - auto reshape_const_new = reshape_const->clone_with_new_inputs({}); - auto reshape_new = reshape->clone_with_new_inputs({gather_new, reshape_const_new}); - - replace_node_update_name(gather, reshape_new); - copy_runtime_info(gather, {gather_new, gather_indices_new, gather_axis_new, reshape_new}); - - register_new_node(gather_new); - register_new_node(reshape_new); - - return true; - }; - - auto m = std::make_shared(gather_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_reshape.hpp b/src/plugins/intel_gna/src/transformations/gather_sinking_reshape.hpp deleted file mode 100644 index 2061b5f390b..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_reshape.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** @brief - * Moves Gather through Reshape node in a backward sinking propagation - * (from the end to the start of the graph). - * - * Any #1 Any #1 - * | | - * Reshape Gather - * | => | - * Gather Reshape - * | | - * Any #2 Any #2 - * - * - Reshape is an unflatten type operation (one last dimension is expanded into multiple dimensions) - * - Gather is available for sinking (NoGatherSinkingAttr is not set) - * - * This transformation is called from GatherSinkingGeneral. - */ - -class GatherSinkingReshapeBackward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingReshapeBackward", "0"); - GatherSinkingReshapeBackward(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_split.cpp b/src/plugins/intel_gna/src/transformations/gather_sinking_split.cpp deleted file mode 100644 index 1afb57bc153..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_split.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_split.hpp" - -#include -#include - -#include "common/graph_utils.hpp" -#include "openvino/cc/ngraph/itt.hpp" -#include "openvino/op/util/op_types.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/pattern/op/label.hpp" -#include "openvino/pass/pattern/op/or.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "openvino/util/common_util.hpp" -#include "openvino/util/log.hpp" -#include "transformations/rt_info/gather_sinking_attr.hpp" -#include "transformations/utils/gather_sinking_utils.hpp" - -using namespace ov; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace ov::op::util; -using namespace gather_sinking; -using namespace ov::intel_gna::graph_utils; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::rt_info; - -namespace { - -using NodePtr = std::shared_ptr; - -struct OutputGather { - OutputGather() = default; - Gather* gather = {}; - Constant* gather_indices = {}; - Constant* gather_axis = {}; - int output_idx = {}; -}; - -OutputGather find_first_output_gather(NodePtr node) { - for (size_t output_idx = 0; output_idx < node->get_output_size(); ++output_idx) { - for (auto& input : node->get_output_target_inputs(output_idx)) { - auto gather_node = dynamic_cast(input.get_node()); - if (!gather_node) - continue; - auto indices_node = dynamic_cast(gather_node->input_value(1).get_node()); - if (!indices_node) - continue; - auto axis_node = dynamic_cast(gather_node->input_value(2).get_node()); - if (!axis_node) - continue; - { - OutputGather output_gather; - output_gather.gather = gather_node; - output_gather.gather_indices = indices_node; - output_gather.gather_axis = axis_node; - output_gather.output_idx = static_cast(output_idx); - - return output_gather; - } - } - } - - return {}; -} - -} // namespace - -/* - * We follow Gather operations rather than Split. We cannot create matcher pattern - * for Split with Transpose outputs since Split can have different number of outputs. - * We can just: - * - specify Split as searched node and check if it has gather outputs - * - specify Gather as searched node and check if it has Split input - * Transformations are called on each found node in sorted order from the start to end - * of the network. When we proceed Split backward sinking we move input Gather - * to the input of the Split operation. - * Consider case Split (1) -> Split (2) -> Gather - * If specify Split as main searched node after first transformation work we will have - * Split (1) -> Gather -> Split(2) - * Matcher pass will not call GatherSinkingSplitBackward since - * - matcher pattern has no Gather label - * - Split (1) has already been proceeded - * Adding Split(2) into the working queue as register_new_node(split) - * cannot help us. We just can try to find all input Split operations and add them with - * register_new_node(). Implemented way is simpler. - */ -GatherSinkingSplitBackward::GatherSinkingSplitBackward() { - MATCHER_SCOPE(GatherSinkingSplitBackward); - - auto gather_indices_label = wrap_type(); - auto gather_axis_label = wrap_type(); - auto gather_label = wrap_type({any_input(), gather_indices_label, gather_axis_label}, is_split_sinked); - - matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto gather = as_type_ptr(pattern_to_output.at(gather_label).get_node_shared_ptr()); - - auto split = find_first_input_node(gather); - auto split_axis_constant = as_type_ptr(split->input_value(1).get_node_shared_ptr()); - if (!split_axis_constant) { - return false; - } - - int64_t split_axis; - if (!get_split_axis(split_axis_constant, split->input_value(0).get_partial_shape().rank(), split_axis)) { - return false; - } - - OutputGather output_gather = find_first_output_gather(split); - const int64_t gather_axis = - convert_axis_to_positive(output_gather.gather_axis->cast_vector()[0], - output_gather.gather->input(0).get_partial_shape().rank().get_length()); - - const auto gather_indices = normalize_gather_indices(output_gather.gather_indices->cast_vector()); - std::vector new_indices(split->get_input_shape(0)[gather_axis]); - std::iota(new_indices.begin(), new_indices.end(), 0); - - const size_t base = output_gather.output_idx * split->get_output_shape(0)[gather_axis]; - for (size_t i = 0; i < gather_indices.size(); ++i) { - new_indices[base + i] = base + gather_indices[i]; - } - - auto split_input = split->input_value(0); - auto new_indices_const = std::make_shared(output_gather.gather_axis->get_element_type(), - Shape{new_indices.size()}, - new_indices); - auto new_axis_const = output_gather.gather_axis->clone_with_new_inputs({}); - auto new_gather = std::make_shared(split_input, new_indices_const, new_axis_const); - split->input(0).replace_source_output(new_gather->output(0)); - copy_runtime_info(split_input.get_node_shared_ptr(), {new_gather, new_indices_const, new_axis_const}); - register_new_node(new_gather); - - for (auto& input : split->get_output_target_inputs(output_gather.output_idx)) { - Node* consumer = input.get_node(); - if (consumer->get_output_size() != 1) - continue; - consumer->output(0).replace(split->output(output_gather.output_idx)); - } - - return true; - }; - - auto m = std::make_shared(gather_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_split.hpp b/src/plugins/intel_gna/src/transformations/gather_sinking_split.hpp deleted file mode 100644 index 5068a12eed5..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_split.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" -#include "openvino/pass/pass.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** @brief - * Moves Gather through Split layer in a backward step propagation. - * This transformation is called from GatherSinkingGeneral. - * - * Converts subgraph - * Any #1 - * | - * Split - * | | | - * Any #2 ... Gather ... Any #N - * | - * Any #K - * to - * Any #1 - * | - * Gather - * | - * Split - * | | | - * Any #2 ... Any #K ... Any #N - * - * - */ - -class GatherSinkingSplitBackward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingBinaryBackward", "0"); - GatherSinkingSplitBackward(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_transpose.cpp b/src/plugins/intel_gna/src/transformations/gather_sinking_transpose.cpp deleted file mode 100644 index 2347e2ebac9..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_transpose.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_transpose.hpp" - -#include - -#include "common/graph_utils.hpp" -#include "openvino/cc/ngraph/itt.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/manager.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" - -using namespace ov::opset10; -using namespace ov::pass::pattern; -using namespace ov::intel_gna; -using namespace ov::intel_gna::pass; - -namespace { - -inline std::vector> merge_nodes_forward(std::shared_ptr gather, - std::shared_ptr transpose) { - auto transpose_const = ov::as_type_ptr(transpose->get_input_node_shared_ptr(1)); - auto gather_ids = ov::as_type_ptr(gather->get_input_node_shared_ptr(1)); - auto gather_axis = ov::as_type_ptr(gather->get_input_node_shared_ptr(2)); - - // transpose ids -> gather indexes - const ov::AxisVector transpose_ids = - graph_utils::make_gather_indexes_from_transpose_axes(transpose->get_input_shape(0), - transpose_const->get_axis_vector_val()); - // merge gather indexes - const ov::AxisVector gather_new_ids = - graph_utils::combine_gather_indexes(gather_ids->get_axis_vector_val(), transpose_ids); - - // new gather - auto gather_new_const_ids = - std::make_shared(ov::element::i64, ov::Shape{gather_new_ids.size()}, gather_new_ids); - auto gather_new = std::make_shared(gather->input_value(0), gather_new_const_ids, gather_axis); - - ov::Shape shape_out = transpose->get_output_shape(0); - auto reshape_out_const = std::make_shared(ov::element::i64, ov::Shape{shape_out.size()}, shape_out); - auto reshape_out = std::make_shared(gather_new, reshape_out_const, false); - - replace_node_update_name(transpose, reshape_out); - - return std::vector>({gather_new, reshape_out}); -} - -inline std::vector> merge_nodes_backward(std::shared_ptr gather, - std::shared_ptr transpose) { - auto transpose_const = ov::as_type_ptr(transpose->get_input_node_shared_ptr(1)); - auto gather_ids = ov::as_type_ptr(gather->get_input_node_shared_ptr(1)); - auto gather_axis = ov::as_type_ptr(gather->get_input_node_shared_ptr(2)); - - ov::Shape shape_in = gather->get_input_shape(0); - auto reshape_in_const = std::make_shared(ov::element::i64, ov::Shape{shape_in.size()}, shape_in); - auto reshape_in = std::make_shared(transpose->input_value(0), reshape_in_const, false); - - // transpose ids -> gather indexes - const ov::AxisVector transpose_ids = - graph_utils::make_gather_indexes_from_transpose_axes(transpose->get_input_shape(0), - transpose_const->get_axis_vector_val()); - // merge gather indexes - const ov::AxisVector gather_new_ids = - graph_utils::combine_gather_indexes(gather_ids->get_axis_vector_val(), transpose_ids); - - // new gather - auto gather_new_const_ids = - std::make_shared(ov::element::i64, ov::Shape{gather_new_ids.size()}, gather_new_ids); - auto gather_new = std::make_shared(reshape_in, gather_new_const_ids, gather_axis); - - ov::replace_node_update_name(gather, gather_new); - - return std::vector>({reshape_in, gather_new}); -} - -inline bool is_skip_operation(const std::shared_ptr& node) { - return std::dynamic_pointer_cast(node) != nullptr && node->output(0).get_target_inputs().size() == 1; -} - -} // namespace - -GatherSinkingTransposeForward::GatherSinkingTransposeForward() { - MATCHER_SCOPE(GatherSinkingTransposeForward); - auto gather_ids_label = wrap_type(graph_utils::is_constant_1d); - auto gather_label = wrap_type({any_input(), gather_ids_label, any_input()}); - auto reshape_label = wrap_type({gather_label, any_input()}); - // auto transpose_label = wrap_type({reshape_label, any_input()}); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto gather = as_type_ptr(pattern_to_output.at(gather_label).get_node_shared_ptr()); - auto reshape = as_type_ptr(pattern_to_output.at(reshape_label).get_node_shared_ptr()); - - // skip all the Reshape layers - std::shared_ptr non_reshape_node = - graph_utils::get_next_node_skipping_certain(reshape, is_skip_operation); - auto transpose = std::dynamic_pointer_cast(non_reshape_node); - if (!transpose) { - return false; - } - - const std::vector> new_nodes = merge_nodes_forward(gather, transpose); - for (const auto& node : new_nodes) { - register_new_node(node); - } - return true; - }; - - auto m = std::make_shared(reshape_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} - -GatherSinkingTransposeBackward::GatherSinkingTransposeBackward() { - MATCHER_SCOPE(GatherSinkingTransposeBackward); - - auto reshape_label = wrap_type({any_input(), any_input()}); - auto gather_ids_label = wrap_type(graph_utils::is_constant_1d); - auto gather_label = wrap_type({reshape_label, gather_ids_label, any_input()}); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto reshape = as_type_ptr(pattern_to_output.at(reshape_label).get_node_shared_ptr()); - auto gather = as_type_ptr(pattern_to_output.at(gather_label).get_node_shared_ptr()); - - // skip all the Reshape layers - std::shared_ptr non_reshape_node = - graph_utils::get_prev_node_skipping_certain(reshape, is_skip_operation); - auto transpose = std::dynamic_pointer_cast(non_reshape_node); - if (!transpose) { - return false; - } - - const std::vector> new_nodes = merge_nodes_backward(gather, transpose); - for (const auto& node : new_nodes) { - register_new_node(node); - } - return true; - }; - - auto m = std::make_shared(gather_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} - -bool GatherSinkingTranspose::run_on_model(const std::shared_ptr& model) { - RUN_ON_FUNCTION_SCOPE(GatherSinkingTranspose); - { - ov::pass::Manager manager(get_pass_config()); - manager.register_pass(); - manager.register_pass(); - manager.run_passes(model); - } - return false; -} diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_transpose.hpp b/src/plugins/intel_gna/src/transformations/gather_sinking_transpose.hpp deleted file mode 100644 index fbccd5f0c9d..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_transpose.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Merge Gather with Transpose through Reshape or sequence of Reshapes. - * - * Any1[a,b,c] Any1[a,b,c] - * | | - * Reshape[1,a*b*c] Reshape[1,a*b*c] - * | | - * Gather[1,a*b*c] Gather[1,a*b*c] - * | | - * Reshape1[...] | - * | | - * ... | - * | | - * ReshapeN[a,b,c] | - * | => | - * Transpose[c,b,a] Reshape[c,b,a] - * | | - * Any2[c,b,a] Any2[c,b,a] - * - * Gather restrictions: - * - supported Scalar or 1D indexes - * i.e. [1, 64] or [64] - */ -class GatherSinkingTransposeForward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingTransposeForward", "0"); - GatherSinkingTransposeForward(); -}; - -/** - * @brief Merge Transpose with Gather through Reshape or sequence of Reshapes. - * - * Any1[a,b,c] Any1[a,b,c] - * | | - * Transpose[c,b,a] | - * | | - * Reshape1[...] | - * | | - * ... | - * | | - * Reshape[1, a*b*c] Reshape[1, a*b*c] - * | => | - * Gather[1, a*b*c] Gather[1, a*b*c] - * | | - * Reshape[c,b,a] Reshape[c,b,a] - * | | - * Any2[c,b,a] Any2[c,b,a] - * - * Gather restrictions: - * - supported Scalar or 1D indexes - * i.e. [1, 64] or [64] - */ -class GatherSinkingTransposeBackward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingTransposeBackward", "0"); - GatherSinkingTransposeBackward(); -}; - -class GatherSinkingTranspose : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("GatherSinkingTranspose", "0"); - bool run_on_model(const std::shared_ptr& model) override; -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_transpose_reshape.cpp b/src/plugins/intel_gna/src/transformations/gather_sinking_transpose_reshape.cpp deleted file mode 100644 index a54eac95351..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_transpose_reshape.cpp +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_transpose_reshape.hpp" - -#include -#include - -#include "backend/gna_limitations.hpp" -#include "common/graph_utils.hpp" -#include "log/debug.hpp" -#include "openvino/opsets/opset9.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "transformations/rt_info/transpose_sinking_attr.hpp" -#include "transformations/utils/gather_sinking_utils.hpp" -#include "transformations/utils/transformation_helper.hpp" - -using namespace ov::intel_gna; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::limitations; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace gather_sinking; - -namespace { - -std::vector> gather_sink_forward(std::shared_ptr transpose, - std::shared_ptr reshape) { - std::vector> new_nodes = {}; - - auto transpose_const = ov::as_type_ptr(transpose->get_input_node_shared_ptr(1)); - const auto gather_indexes_value = - graph_utils::make_gather_indexes_from_transpose_axes(transpose->get_input_shape(0), - transpose_const->get_axis_vector_val()); - ov::Shape shape_out = reshape->get_output_shape(0); - - // Set Gather input shape - std::vector reshape_in_dims = {1, -1}; - for (size_t i = reshape_in_dims.size(); i < shape_out.size(); ++i) { - if (shape_out[i] == 1) { - reshape_in_dims.push_back(1); - } - } - // reshape - auto reshape_in_const = - std::make_shared(ov::element::i64, ov::Shape{reshape_in_dims.size()}, reshape_in_dims); - auto reshape_in = reshape->clone_with_new_inputs({transpose->input_value(0), reshape_in_const}); - new_nodes.push_back(reshape_in); - - const int64_t gather_axis_value = graph_utils::get_first_valuable_dim_id(reshape_in->get_output_shape(0)); - auto gather_axis = std::make_shared(ov::element::i64, ov::Shape{}, gather_axis_value); - auto gather_indices = - std::make_shared(ov::element::i64, ov::Shape{gather_indexes_value.size()}, gather_indexes_value); - auto gather = std::make_shared(reshape_in, gather_indices, gather_axis); - new_nodes.push_back(gather); - - auto reshape_out_const = std::make_shared(ov::element::i64, ov::Shape{shape_out.size()}, shape_out); - auto reshape_out = std::make_shared(gather, reshape_out_const, false); - - if (!graph_utils::are_shapes_equal(reshape_out->get_input_shape(0), reshape_out->get_output_shape(0))) { - new_nodes.push_back(reshape_out); - } - - ov::replace_output_update_name(reshape->output(0), new_nodes.back()->output(0)); - ov::copy_runtime_info({reshape}, new_nodes); - - return new_nodes; -} - -std::vector> gather_sink_backward(std::shared_ptr reshape, - std::shared_ptr transpose) { - std::vector> new_nodes = {}; - auto transpose_const = ov::as_type_ptr(transpose->get_input_node_shared_ptr(1)); - ov::Shape shape_out = transpose->get_output_shape(0); - - // Set Gather input shape - std::vector reshape_in_dims = {1, -1}; - for (size_t i = reshape_in_dims.size(); i < shape_out.size(); ++i) { - if (shape_out[i] == 1) { - reshape_in_dims.push_back(1); - } - } - - // reshape - auto reshape_in_const = - std::make_shared(ov::element::i64, ov::Shape{reshape_in_dims.size()}, reshape_in_dims); - auto reshape_in = reshape->clone_with_new_inputs({reshape->input_value(0), reshape_in_const}); - new_nodes.push_back(reshape_in); - - const int64_t gather_axis_value = graph_utils::get_first_valuable_dim_id(reshape_in->get_output_shape(0)); - const auto gather_indexes_value = - graph_utils::make_gather_indexes_from_transpose_axes(transpose->get_input_shape(0), - transpose_const->get_axis_vector_val()); - - auto gather_axis = std::make_shared(ov::element::i64, ov::Shape{}, gather_axis_value); - auto gather_indices = - std::make_shared(ov::element::i64, ov::Shape{gather_indexes_value.size()}, gather_indexes_value); - auto gather = std::make_shared(reshape_in, gather_indices, gather_axis); - new_nodes.push_back(gather); - - auto reshape_out_const = std::make_shared(ov::element::i64, ov::Shape{shape_out.size()}, shape_out); - auto reshape_out = std::make_shared(gather, reshape_out_const, false); - - if (!graph_utils::are_shapes_equal(reshape_out->get_input_shape(0), reshape_out->get_output_shape(0))) { - new_nodes.push_back(reshape_out); - } - - ov::replace_node_update_name(transpose, new_nodes.back()); - ov::copy_runtime_info({transpose}, new_nodes); - - return new_nodes; -} - -bool is_transpose_unsupported(const ov::Output& output) { - return !Limitations::is_transpose_supported(output.get_node_shared_ptr()); -} - -bool is_backward_sinking_enabled(const ov::Output& output) { - return is_transpose_unsupported(output) && ov::is_sinking_node(output.get_node_shared_ptr()); -} - -} // namespace - -GatherSinkingTransposeReshapeForward::GatherSinkingTransposeReshapeForward() { - MATCHER_SCOPE(GatherSinkingTransposeReshapeForward); - - auto transpose_const_label = wrap_type(); - auto transpose_label = wrap_type({any_input(), transpose_const_label}, is_transpose_unsupported); - auto reshape_label = wrap_type({transpose_label, any_input()}); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - - auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr(); - auto reshape = pattern_to_output.at(reshape_label).get_node_shared_ptr(); - - const ov::Shape reshape_shape = graph_utils::trim_shape(reshape->get_shape()); - const ov::Shape transpose_shape = graph_utils::trim_shape(transpose->get_shape()); - if (reshape_shape == transpose_shape) { - pass::helper::remove_single_input_node(transpose); - return true; - } - - const std::vector> new_nodes = gather_sink_forward(transpose, reshape); - - for (const auto& node : new_nodes) { - register_new_node(node); - } - - return true; - }; - - auto m = std::make_shared(reshape_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} - -GatherSinkingTransposeReshapeBackward::GatherSinkingTransposeReshapeBackward() { - MATCHER_SCOPE(GatherSinkingTransposeReshapeBackward); - - auto reshape_label = wrap_type({any_input(), any_input()}); - auto transpose_const_label = wrap_type(); - auto transpose_label = wrap_type({reshape_label, transpose_const_label}, is_backward_sinking_enabled); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - - auto reshape = pattern_to_output.at(reshape_label).get_node_shared_ptr(); - auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr(); - - const ov::Shape reshape_shape = graph_utils::trim_shape(reshape->get_input_shape(0)); - const ov::Shape transpose_shape = graph_utils::trim_shape(transpose->get_shape()); - if (reshape_shape == transpose_shape) { - pass::helper::remove_single_input_node(transpose); - return true; - } - - const std::vector> new_nodes = gather_sink_backward(reshape, transpose); - for (const auto& node : new_nodes) { - register_new_node(node); - } - - return true; - }; - - auto m = std::make_shared(transpose_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_transpose_reshape.hpp b/src/plugins/intel_gna/src/transformations/gather_sinking_transpose_reshape.hpp deleted file mode 100644 index eabdfba794d..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_transpose_reshape.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief - * Sinks Transpose through Reshape from the start to the end of the graph. - * - * Any1 Any1 - * | | - * Transpose Reshape - * | => | - * Reshape Gather - * | | - * Any2 Any2 - * - * Reshape must be tail-flatten: it should squash last mulitple dimensions into one. - * i.e. [1, 2, 4] => [1, 8] - * - * Transpose restrictions: - * - permute only dims that are flattened by Reshape - * - 2D permutations - * i.e. [0, 2, 1] or [0, 3, 1, 2] - */ -class GatherSinkingTransposeReshapeForward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingTransposeReshapeForward", "0"); - GatherSinkingTransposeReshapeForward(); -}; - -/** - * @brief - * Sinks Transpose through Reshape from the end to the start of the graph. - * - * Any1 Any1 - * | | - * Reshape Gather - * | => | - * Transpose Reshape - * | | - * Any2 Any2 - * - * Reshape must be tail-unflatten: it should unsquash last dimension into multiple ones. - * i.e. [1, 8] => [1, 2, 4] - * - * Transpose restrictions: - * - permute only dims that are unflattened by Reshape - * - 2D permutations - * i.e. [0, 2, 1] or [0, 3, 1, 2] - */ -class GatherSinkingTransposeReshapeBackward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingTransposeReshapeBackward", "0"); - GatherSinkingTransposeReshapeBackward(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_unary.cpp b/src/plugins/intel_gna/src/transformations/gather_sinking_unary.cpp deleted file mode 100644 index 3e67c5bc493..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_unary.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_unary.hpp" - -#include -#include - -#include "openvino/cc/ngraph/itt.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/pattern/op/or.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "transformations/rt_info/gather_sinking_attr.hpp" -#include "transformations/utils/gather_sinking_utils.hpp" - -using namespace ov; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace ov::op::util; -using namespace gather_sinking; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::rt_info; - -namespace { - -using NodePtr = std::shared_ptr; -using NodePair = std::pair; - -/** - * @brief swap_nodes allows to perform swapping nodes even if there are more than one consumers but has less performance - * - * @param first_node first node pointer - * @param second_node first node pointer - * @return NodePair pair of nodes in new order that allows to register them in MatcherPass - */ -NodePair swap_nodes(NodePtr first_node, NodePtr second_node) { - auto second_node_inputs = second_node->input_values(); - second_node_inputs[0] = first_node->input_value(0); - - auto new_first_node = second_node->clone_with_new_inputs(second_node_inputs); - - auto first_node_inputs = first_node->input_values(); - first_node_inputs[0] = new_first_node; - auto new_second_node = first_node->clone_with_new_inputs(first_node_inputs); - - new_second_node->set_friendly_name(second_node->get_friendly_name()); - ov::copy_runtime_info({first_node, second_node}, {new_first_node, new_second_node}); - - ov::replace_node(second_node, new_second_node); - - return std::make_pair(new_first_node, new_second_node); -} - -/** - * @brief swap_outputs has much better performance than swap_nodes and covers the most of the real situations - * but cannot work when the consumers count greater than one - * @param first_node first node pointer - * @param second_node second node pointer - * @return NodePair pair of nodes in new order that allows to register them in MatcherPass - */ -NodePair swap_outputs(NodePtr first_node, NodePtr second_node) { - const auto first_node_output_names = first_node->output(0).get_names(); - const auto second_node_output_names = second_node->output(0).get_names(); - - auto swap_names = [&]() { - const std::string first_name = first_node->get_friendly_name(); - first_node->set_friendly_name(second_node->get_friendly_name()); - second_node->set_friendly_name(first_name); - - first_node->output(0).set_names(second_node_output_names); - second_node->output(0).set_names(first_node_output_names); - }; - - auto out_1 = first_node->input_value(0); - second_node->input(0).replace_source_output(out_1); - - auto out_2 = second_node->output(0); - second_node->output(0).replace(first_node->output(0)); - - first_node->input(0).replace_source_output(out_2); - - swap_names(); - - return std::make_pair(second_node, first_node); -} - -/** - * swapping inputs/outputs has better perfomance that swapping nodes with clone but it cannot be used - * in multiple consumers case - */ -NodePair swap_items(NodePtr first_node, NodePtr second_node) { - NodePair new_nodes; - - if (first_node->output(0).get_target_inputs().size() > 1 || second_node->output(0).get_target_inputs().size() > 1) - new_nodes = swap_nodes(first_node, second_node); - else - new_nodes = swap_outputs(first_node, second_node); - - return new_nodes; -} - -} // namespace - -GatherSinkingUnaryForward::GatherSinkingUnaryForward() { - MATCHER_SCOPE(GatherSinkingUnaryForward); - auto gather_label = wrap_type({any_input(), any_input(), any_input()}); - auto unary_label = wrap_type({gather_label}); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto gather = pattern_to_output.at(gather_label).get_node_shared_ptr(); - auto unary = pattern_to_output.at(unary_label).get_node_shared_ptr(); - - const NodePair new_nodes = swap_items(gather, unary); - - register_new_node(new_nodes.first); - register_new_node(new_nodes.second); - - update_forward_gather_sinking_ability(new_nodes.second); - - return true; - }; - - auto m = std::make_shared(unary_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} - -GatherSinkingUnaryBackwardSingleConsumer::GatherSinkingUnaryBackwardSingleConsumer() { - MATCHER_SCOPE(GatherSinkingUnaryBackwardSingleConsumer); - auto unary_label = - wrap_type({any_input()}, - consumers_count(1)); - // FakeQuantize pattern - auto fq_label = - wrap_type({any_input(), any_input(), any_input(), any_input(), any_input()}, consumers_count(1)); - - auto pattern_node = std::make_shared(ov::OutputVector{unary_label, fq_label}); - - auto gather_label = wrap_type({pattern_node, any_input(), any_input()}, is_gather_sinking_enabled); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto gather = pattern_to_output.at(gather_label).get_node_shared_ptr(); - auto unary = gather->get_input_node_shared_ptr(0); - - const NodePair new_nodes = swap_items(unary, gather); - - register_new_node(new_nodes.first); - register_new_node(new_nodes.second); - - return true; - }; - - auto m = std::make_shared(gather_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} - -GatherSinkingUnaryBackwardMultiConsumers::GatherSinkingUnaryBackwardMultiConsumers() { - MATCHER_SCOPE(GatherSinkingUnaryBackwardMultiConsumers); - auto unary_restrictions = [](const Output& output) -> bool { - return ov::pass::pattern::consumers_more_than(1)(output) && has_same_output_gather_nodes(output); - }; - - auto unary_label = - wrap_type({any_input()}, - unary_restrictions); - // FakeQuantize pattern - auto fq_label = - wrap_type({any_input(), any_input(), any_input(), any_input(), any_input()}, unary_restrictions); - - auto pattern_node = std::make_shared(ov::OutputVector{unary_label, fq_label}); - - auto indices_const_label = wrap_type(); - auto axes_const_label = wrap_type(); - auto gather_label = - wrap_type({pattern_node, indices_const_label, axes_const_label}, is_gather_sinking_enabled); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto indices_const = as_type_ptr(pattern_to_output.at(indices_const_label).get_node_shared_ptr()); - auto axes_const = as_type_ptr(pattern_to_output.at(axes_const_label).get_node_shared_ptr()); - auto gather = as_type_ptr(pattern_to_output.at(gather_label).get_node_shared_ptr()); - auto unary = gather->get_input_node_shared_ptr(0); - - for (auto& new_node : sink_backward::insert_gather_before_node(unary, indices_const, axes_const, gather)) { - register_new_node(new_node); - } - - // remove output transposes - remove_single_output_consumers(unary); - - return true; - }; - - auto m = std::make_shared(gather_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} - -GatherSinkingUnaryBackward::GatherSinkingUnaryBackward() { - MATCHER_SCOPE(GatherSinkingUnaryBackward); - add_matcher(); - add_matcher(); -} diff --git a/src/plugins/intel_gna/src/transformations/gather_sinking_unary.hpp b/src/plugins/intel_gna/src/transformations/gather_sinking_unary.hpp deleted file mode 100644 index 65c3d13222c..00000000000 --- a/src/plugins/intel_gna/src/transformations/gather_sinking_unary.hpp +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief - * Moves Gather layer forward from the start to the end of the graph - * through the unary operations UnaryElementwiseArithmetic, Clamp, Elu, SoftPlus, LogicalNot, Convert - * - * Gather Unary - * | => | - * Unary Gather - * | | - * Another Another - * - * Gather Unary - * | => | - * Unary Gather - * | | | | - * Any1 Any2 Any1 Any2 - * - * Gather Unary1 - * | => | | - * Unary1 Unary2 Unary3 - * | | | | - * Unary2 Unary3 Gather Gather - * - * Another1 Another1 - * | | | - * Gather Unary Gather - * | | => | | - * Unary Another2 Gather Another2 - * | | - * Another3 Another3 - * - * All GatherSinking tranformations are designed to work in 2 steps: - * - forward push - * - backward push - * Add flag into Gather layer rt_info that prevents backward sinking if the next layer - * after Gather does not support by GatherSinking transformations. That is done to - * prevent backward pushing the layer that already pushed forward through the graph. - */ -class GatherSinkingUnaryForward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingUnaryForward", "0"); - GatherSinkingUnaryForward(); -}; - -/** - * @brief - * Moves Gather layer backward from the end to the start of the graph - * Works only with single consumer case. If Gather is marked as not-sinkable - * (since it was moved previously by forward sinking) it is not proceeded. - * - * Any Any - * | | - * Unary => Gather - * | | - * Gather Unary - */ -class GatherSinkingUnaryBackwardSingleConsumer : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingUnaryBackwardSingleConsumer", "0"); - GatherSinkingUnaryBackwardSingleConsumer(); -}; - -/** - * @brief - * Moves Gather layer backward from the end to the start of the graph - * Works only with multiple consumer case. If Gather is marked as non-sinkable - * (since it was moved previously by forward sinking) it is not proceeded. - * - * Any1 Any1 - * | | - * Unary => Gather - * | | | - * Gather Gather Unary - * | | | | - * Any2 Any3 Any2 Any3 - * - * Moves Gather layer backward only if: - * - Gather is not marked as non-sinkable - * - Unary layer has > 1 gather consumers - * - All Unary consumers are Gather layers - * - All that Gather layers equal each other - */ -class GatherSinkingUnaryBackwardMultiConsumers : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("GatherSinkingUnaryBackwardMultiConsumers", "0"); - GatherSinkingUnaryBackwardMultiConsumers(); -}; - -/** - * @brief - * GatherSinkingUnaryBackward transformations calls GatherSinkingUnaryBackward and - * GatherSinkingUnaryBackwardMultiConsumers so there is no need to use them if GatherSinkingUnaryBackward is used - */ -class GatherSinkingUnaryBackward : public ov::pass::GraphRewrite { -public: - OPENVINO_RTTI("GatherSinkingUnaryBackward", "0"); - GatherSinkingUnaryBackward(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/transformations/handle_transposes_around_matmul.cpp b/src/plugins/intel_gna/src/transformations/handle_transposes_around_matmul.cpp deleted file mode 100644 index c3e737745fd..00000000000 --- a/src/plugins/intel_gna/src/transformations/handle_transposes_around_matmul.cpp +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/handle_transposes_around_matmul.hpp" - -#include - -#include -#include -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "common/graph_utils.hpp" - -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::limitations; -using namespace ov::intel_gna::graph_utils; - -namespace { - -void ReplaceTransposeWithReshape(std::shared_ptr transpose_node) { - auto shape = transpose_node->get_output_shape(0); - auto reshape_const = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{shape.size()}, shape); - auto reshape_node = std::make_shared(transpose_node->input_value(0), reshape_const, false); - reshape_node->set_friendly_name(transpose_node->get_friendly_name()); - ngraph::copy_runtime_info(transpose_node, {reshape_node, reshape_const}); - transpose_node->output(0).replace(reshape_node->output(0)); -} - -void InsertTranspose(std::shared_ptr prev_node, const std::string& base_name, bool before_matmul) { - ngraph::NodeVector new_ops; - auto create_reshape = - [&new_ops](const ngraph::Shape& shape, std::shared_ptr input_node, const std::string& name) { - auto reshape_const = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{shape.size()}, - shape); - new_ops.push_back(reshape_const); - auto node = std::make_shared(input_node, reshape_const, false); - new_ops.push_back(node); - node->set_friendly_name(name); - return node; - }; - - auto consumers = prev_node->output(0).get_target_inputs(); - const auto orig_shape = prev_node->get_output_shape(0); - std::vector transpose_ids; - for (size_t i = 0; i < orig_shape.size(); ++i) { - if (orig_shape[i] > 1) { - transpose_ids.push_back(i); - } - } - IE_ASSERT(transpose_ids.size() == 2); - std::vector permute_order(orig_shape.size()); - std::iota(std::begin(permute_order), std::end(permute_order), 0); - std::swap(permute_order[transpose_ids[0]], permute_order[transpose_ids[1]]); - - std::shared_ptr node = prev_node; - if (!before_matmul) { - auto shape = prev_node->get_output_shape(0); - std::swap(shape[0], shape[1]); - node = create_reshape(shape, node, base_name + "/reshape_before_transpose"); - } - - auto transpose_order = - ngraph::opset8::Constant::create(ngraph::element::i64, ngraph::Shape{permute_order.size()}, permute_order); - new_ops.push_back(transpose_order); - node = std::make_shared(node, transpose_order); - node->set_friendly_name(base_name + "/in_transpose"); - new_ops.push_back(node); - - if (before_matmul) { - node = create_reshape(orig_shape, node, base_name + "/reshape_after_transpose"); - } - - ngraph::copy_runtime_info(prev_node, new_ops); - - for (auto& input : consumers) { - input.replace_source_output(node); - } -} - -bool VerifyReshape(const ngraph::Output& reshape_out) { - auto in_shape = reshape_out.get_node_shared_ptr()->get_input_shape(0); - auto out_shape = reshape_out.get_node_shared_ptr()->get_output_shape(0); - - const auto is_input_scalar = in_shape.empty(); - const auto is_output_scalar = out_shape.empty(); - - if (is_input_scalar && is_output_scalar) { - // If both are scalar it means we don't need reshape. - return false; - } - - if (is_input_scalar || is_output_scalar) { - // If one is scalar it means we need reshape. - return true; - } - - return in_shape[0] != out_shape[0]; -} - -bool VerifyConcat(const ngraph::Output& node) { - auto concat_node = std::dynamic_pointer_cast(node.get_node_shared_ptr()); - return concat_node && (concat_node->get_axis() == 0); -} - -} // namespace - -HandleTransposeBeforeMatMul::HandleTransposeBeforeMatMul() { - auto concat1 = ngraph::pattern::wrap_type(VerifyConcat); - auto reshape1 = ngraph::pattern::wrap_type(VerifyReshape); - auto transpose_input1 = std::make_shared(ngraph::OutputVector{concat1, reshape1}); - auto transpose1 = - ngraph::pattern::wrap_type({transpose_input1, ngraph::pattern::any_input()}); - - auto concat2 = ngraph::pattern::wrap_type(VerifyConcat); - auto reshape2 = ngraph::pattern::wrap_type(VerifyReshape); - auto transpose_input2 = std::make_shared(ngraph::OutputVector{concat2, reshape2}); - auto transpose2 = - ngraph::pattern::wrap_type({transpose_input2, ngraph::pattern::any_input()}); - - auto constant = ngraph::pattern::wrap_type(); - auto fq = ngraph::pattern::wrap_type({constant, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}); - - auto matmul1 = ngraph::pattern::wrap_type( - {std::make_shared( - ngraph::OutputVector{reshape1, concat1, transpose1, constant, fq, ngraph::pattern::any_input()}), - std::make_shared(ngraph::OutputVector{reshape2, concat2, transpose2})}); - - auto matmul2 = ngraph::pattern::wrap_type( - {std::make_shared(ngraph::OutputVector{reshape1, concat1, transpose1, constant, fq}), - ngraph::pattern::any_input()}); - - auto matmul = std::make_shared(ngraph::OutputVector{matmul1, matmul2}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& matcher) { - const auto& pattern_map = matcher.get_pattern_value_map(); - auto matmul_iter = pattern_map.find(matmul1); - if (matmul_iter == std::end(pattern_map) && - (matmul_iter = pattern_map.find(matmul2)) == std::end(pattern_map)) { - return false; - } - - auto matmul_node = matmul_iter->second.get_node_shared_ptr(); - auto transpose_reshape_it = pattern_map.find(transpose1); - if (transpose_reshape_it != std::end(pattern_map)) { - ReplaceTransposeWithReshape(transpose_reshape_it->second.get_node_shared_ptr()); - } else { - std::shared_ptr prev_node = nullptr; - if ((transpose_reshape_it = pattern_map.find(reshape1)) != std::end(pattern_map)) { - prev_node = pattern_map.at(reshape1).get_node_shared_ptr(); - } else if ((transpose_reshape_it = pattern_map.find(concat1)) != std::end(pattern_map)) { - prev_node = pattern_map.at(concat1).get_node_shared_ptr(); - } - - if (prev_node) { - if (graph_utils::is_shape_2d(prev_node->get_output_shape(0)) && - Limitations::is_transpose_supported(prev_node->get_output_shape(0))) { - InsertTranspose(prev_node, matmul_node->get_friendly_name(), true); - } - } - } - - // Transpose the first input if it's a constant - auto iter = pattern_map.find(fq); - if (iter != pattern_map.end() || (iter = pattern_map.find(constant)) != pattern_map.end()) { - auto prev_node = iter->second.get_node_shared_ptr(); - if (is_shape_2d(prev_node->get_output_shape(0))) { - InsertTranspose(prev_node, prev_node->get_friendly_name(), true); - } - } - - transpose_reshape_it = pattern_map.find(transpose2); - if (transpose_reshape_it != std::end(pattern_map)) { - ReplaceTransposeWithReshape(transpose_reshape_it->second.get_node_shared_ptr()); - } else { - std::shared_ptr prev_node = nullptr; - if ((transpose_reshape_it = pattern_map.find(reshape2)) != std::end(pattern_map)) { - prev_node = pattern_map.at(reshape2).get_node_shared_ptr(); - } else if ((transpose_reshape_it = pattern_map.find(concat2)) != std::end(pattern_map)) { - prev_node = pattern_map.at(concat2).get_node_shared_ptr(); - } - - if (prev_node) { - if (graph_utils::is_shape_2d(prev_node->get_output_shape(0)) && - Limitations::is_transpose_supported(prev_node->get_output_shape(0))) { - InsertTranspose(prev_node, matmul_node->get_friendly_name(), true); - } - } - } - return true; - }; - - auto matcher = std::make_shared(matmul, "HandleTransposeBeforeMatMul"); - this->register_matcher(matcher, callback); -} - -HandleTransposeAfterMatMul::HandleTransposeAfterMatMul() { - auto matmul = ngraph::pattern::wrap_type({}, [](const ngraph::Output& node) { - auto out_shape = node.get_node_shared_ptr()->get_output_shape(0); - return std::count_if(out_shape.begin(), out_shape.end(), [](size_t n) { - return n > 1; - }) > 1; - }); - auto fq1 = ngraph::pattern::wrap_type({matmul, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}); - auto add_input = std::make_shared(ngraph::OutputVector{matmul, fq1}); - auto add_left = ngraph::pattern::wrap_type({add_input, ngraph::pattern::any_input()}); - auto add_right = ngraph::pattern::wrap_type({ngraph::pattern::any_input(), add_input}); - auto fq2_input = std::make_shared(ngraph::OutputVector{matmul, add_left, add_right}); - auto fq2 = ngraph::pattern::wrap_type({fq2_input, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}); - auto act_input = std::make_shared(ngraph::OutputVector{fq2_input, fq2}); - auto act = ngraph::pattern::wrap_type({act_input}); - auto transpose_input = std::make_shared(ngraph::OutputVector{act_input, act}); - auto transpose = - ngraph::pattern::wrap_type({transpose_input, ngraph::pattern::any_input()}); - auto reshape_input = std::make_shared(ngraph::OutputVector{transpose_input, transpose}); - auto reshape = ngraph::pattern::wrap_type({reshape_input, ngraph::pattern::any_input()}, - VerifyReshape); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& matcher) { - const auto& pattern_map = matcher.get_pattern_value_map(); - auto transpose_it = pattern_map.find(transpose); - if (transpose_it != std::end(pattern_map)) { - ReplaceTransposeWithReshape(transpose_it->second.get_node_shared_ptr()); - } else { - auto reshape_node = pattern_map.at(reshape).get_node_shared_ptr(); - if (!Limitations::is_transpose_supported(reshape_node->get_input_shape(0))) - return false; - auto iter = pattern_map.find(act); - if (iter == pattern_map.end() && (iter = pattern_map.find(fq2)) == pattern_map.end() && - (iter = pattern_map.find(add_left)) == pattern_map.end() && - (iter = pattern_map.find(add_right)) == pattern_map.end() && - (iter = pattern_map.find(matmul)) == pattern_map.end()) { - return false; - } - auto node = iter->second.get_node_shared_ptr(); - InsertTranspose(node, node->get_friendly_name(), false); - } - return true; - }; - - auto matcher = std::make_shared(reshape, "HandleTransposeAfterMatMul"); - this->register_matcher(matcher, callback); -} - -HandleTransposesAroundMatMul::HandleTransposesAroundMatMul() { - add_matcher(); - add_matcher(); -} diff --git a/src/plugins/intel_gna/src/transformations/handle_transposes_around_matmul.hpp b/src/plugins/intel_gna/src/transformations/handle_transposes_around_matmul.hpp deleted file mode 100644 index 8d4924ec812..00000000000 --- a/src/plugins/intel_gna/src/transformations/handle_transposes_around_matmul.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Inserts Transpose before MatMul or removes it (if it exists) - * if there is Reshape/Concat layer before MatMul which changes the batch size, - * or transpose the input if there's a Constant/FQ layer on the first input: - * [1, A*B] [1, A*B] - * | | - * Reshape / Concat Reshape / Concat - * | | - * [A, B] [A, B] - * | | - * | Transpose - * | -> | - * | <- [B, A] - * | | - * | Reshape - * | [A, B] - * | | - * MatMul MatMul - */ -class HandleTransposeBeforeMatMul : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("HandleTransposeBeforeMatMul", "0"); - HandleTransposeBeforeMatMul(); -}; - -/** - * @brief Inserts Transpose after MatMul or removes it (if it exists) if there is Reshape - * after MatMul which changes the batch size: - * MatMul MatMul - * [A, B] [A, B] - * | | - * [Add] [Add] - * | | - * [FakeQuantize] [FakeQuantize] - * | | - * [Activation] [Activation] - * | | - * | Reshape - * | [B, A] - * | | - * | Transpose - * | -> | - * | <- [A, B] - * | | - * Reshape Reshape - * | | - * [1, A*B] [1, A*B] - */ -class HandleTransposeAfterMatMul : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("HandleTransposeAfterMatMul", "0"); - HandleTransposeAfterMatMul(); -}; - -class HandleTransposesAroundMatMul : public ov::pass::GraphRewrite { -public: - OPENVINO_RTTI("HandleTransposesAroundMatMul", "0"); - HandleTransposesAroundMatMul(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/insert_copy_layer.cpp b/src/plugins/intel_gna/src/transformations/insert_copy_layer.cpp deleted file mode 100644 index f08cc9f4e2e..00000000000 --- a/src/plugins/intel_gna/src/transformations/insert_copy_layer.cpp +++ /dev/null @@ -1,409 +0,0 @@ -// Copyright (C) 2022-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "insert_copy_layer.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common/graph_utils.hpp" - -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::graph_utils; -using namespace ov::opset9; - -static const std::string kNonCompProperty("non_compute_node"); -static const std::string kResultProperty("result_vector"); - -NGRAPH_RTTI_DEFINITION(InsertCopyBeforeAssignLayer, "InsertCopyBeforeAssignLayer"); -NGRAPH_RTTI_DEFINITION(InsertCopyBeforeConcatLayer, "InsertCopyBeforeConcatLayer"); -NGRAPH_RTTI_DEFINITION(HandleMultiConnectedLayerToConcatAndMemory, "HandleMultiConnectedLayerToConcatAndMemory"); -NGRAPH_RTTI_DEFINITION(MatchNonComputationalLayers, "MatchNonComputationalLayers"); -NGRAPH_RTTI_DEFINITION(HandleNonFunctionalSubgraphs, "HandleNonFunctionalSubgraphs"); - -namespace { -void insert_copy_layer_between(std::shared_ptr input_op, - std::shared_ptr output_op, - const size_t& index) { - NGRAPH_CHECK(input_op); - NGRAPH_CHECK(output_op); - - auto input_op_out_index = output_op->input(index).get_source_output().get_index(); - // In this case we don't need copy layer insertion, because after insertion of aligning filter graph will include - // convolution layer Should be removed when InsertSplitAligningFilterPass is moved to nGraph, because it should run - // before the copy layer insertion passes - if (!is_aligned_split(input_op, input_op_out_index)) - return; - - auto copy_op = std::make_shared(input_op->output(input_op_out_index)); - copy_op->set_friendly_name(input_op->get_friendly_name() + "/copy_layer/" + output_op->get_friendly_name() + "." + - std::to_string(index)); - ngraph::copy_runtime_info(input_op, copy_op); - - output_op->input(index).replace_source_output(copy_op); -} - -class CopyInsertionForEliminatedLayersHandler { -public: - virtual ~CopyInsertionForEliminatedLayersHandler() = default; - bool InsertCopyBeforeIfNeeded(std::shared_ptr& layer); - -protected: - virtual bool WillLayerBeEliminated(std::shared_ptr& layer) = 0; -}; - -class BroadcastCopyInsertionHandler : public CopyInsertionForEliminatedLayersHandler { -protected: - bool WillLayerBeEliminated(std::shared_ptr& layer) override; -}; - -class TileCopyInsertionHandler : public CopyInsertionForEliminatedLayersHandler { -protected: - bool WillLayerBeEliminated(std::shared_ptr& layer) override; -}; - -bool CopyInsertionForEliminatedLayersHandler::InsertCopyBeforeIfNeeded(std::shared_ptr& layer) { - auto layer_input = layer->get_input_node_shared_ptr(0); - - // skip non functional layers - auto current_node = get_prev_node_skipping_certain(layer_input, is_gna_non_functional_node); - - if (!std::dynamic_pointer_cast(current_node)) { - return false; - } - - if (WillLayerBeEliminated(layer)) { - insert_copy_layer_between(layer_input, layer, 0); - return true; - } - return false; -} - -bool BroadcastCopyInsertionHandler::WillLayerBeEliminated(std::shared_ptr& layer) { - auto data_node = layer->input_value(0); - - // if input has dynamic shape - if (data_node.get_partial_shape().is_dynamic()) { - return false; - } - - auto input_shape = data_node.get_shape(); - auto output_shape = layer->get_output_shape(0); - - // if input shape rank is higher than output shape rank return false; - if (input_shape.size() > output_shape.size()) { - return false; - } - - // if size product is not the same - if (shape_size(input_shape) != shape_size(output_shape)) { - return false; - } - - return true; -} - -bool TileCopyInsertionHandler::WillLayerBeEliminated(std::shared_ptr& layer) { - static constexpr size_t index_of_repeats_shape = 1; - - auto repeats_node = - std::dynamic_pointer_cast(layer->input_value(index_of_repeats_shape).get_node_shared_ptr()); - - if (!repeats_node) - return false; - - auto repeats_vaues = repeats_node->cast_vector(); - - for (const auto& value : repeats_vaues) { - if (value != 1) { - return false; - } - } - - return true; -} - -std::shared_ptr GetCopyInsertionHandler(std::shared_ptr& layer) { - if (std::dynamic_pointer_cast(layer)) { - return std::make_shared(); - } - - if (std::dynamic_pointer_cast(layer)) { - return std::make_shared(); - } - - return nullptr; -} - -} // namespace - -InsertCopyBeforeAssignLayer::InsertCopyBeforeAssignLayer() { - MATCHER_SCOPE(InsertCopyBeforeAssignLayer); - - auto memory_op = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - auto node = std::dynamic_pointer_cast(m.get_match_root()); - - // Insert copy layers after concat inputs with multiple connections to concat - for (size_t i = 0; i < node->get_input_size(); i++) { - auto matched_node_input = node->get_input_node_shared_ptr(i); - auto current_node = get_prev_node_skipping_certain(matched_node_input, is_gna_non_functional_node); - - // Crop -> Memory, Input -> Split -> Memory, Concat -> Memory - if ((std::dynamic_pointer_cast(current_node) && !is_crop_affined(current_node)) || - is_concat(current_node) || std::dynamic_pointer_cast(current_node) || - std::dynamic_pointer_cast(current_node)) { - insert_copy_layer_between(matched_node_input, node, i); - } - } - - return true; - }; - - auto m = std::make_shared(memory_op, matcher_name); - this->register_matcher(m, callback); -} - -InsertCopyBeforeConcatLayer::InsertCopyBeforeConcatLayer() { - MATCHER_SCOPE(InsertCopyBeforeConcatLayer); - - auto concat_op = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - auto concat = m.get_match_root(); - - std::set> inputs; - // Insert copy layers after concat inputs with multiple connections to concat - for (size_t i = 0; i < concat->get_input_size(); i++) { - auto input_op = concat->get_input_node_shared_ptr(i); - - if (inputs.find(input_op) != inputs.end()) { - insert_copy_layer_between(input_op, concat, i); - } else { - inputs.insert(input_op); - } - } - - // Insert copy layers after concat inputs with multiple connections to concat - for (size_t i = 0; i < concat->get_input_size(); i++) { - auto concat_input = concat->get_input_node_shared_ptr(i); - auto current_node = get_prev_node_skipping_certain(concat_input, is_gna_non_functional_node); - - // Crop -> Concat, Input -> Split -> Concat - if ((std::dynamic_pointer_cast(current_node) && !is_crop_affined(current_node)) || - std::dynamic_pointer_cast(current_node) || - std::dynamic_pointer_cast(current_node)) { - insert_copy_layer_between(concat_input, concat, i); - } - } - - return true; - }; - - auto m = std::make_shared(concat_op, matcher_name); - this->register_matcher(m, callback); -} - -InsertCopyBeforeLayerToBeEliminated::InsertCopyBeforeLayerToBeEliminated() { - MATCHER_SCOPE(InsertCopyBeforeLayerToBeEliminated); - const auto constant = ngraph::pattern::wrap_type(); - const auto broadcast_op = ngraph::pattern::wrap_type({ngraph::pattern::any_input(), constant}); - - const auto tile_op = ngraph::pattern::wrap_type({ngraph::pattern::any_input(), constant}); - - const auto brodcast_tile = std::make_shared(OutputVector{broadcast_op, tile_op}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - auto node = m.get_match_root(); - - auto insertion_handler = GetCopyInsertionHandler(node); - - if (!insertion_handler) { - return false; - } - - // Parameter -> Tile/Broadcast to Parameter -> Copy -> Tile/Broadcast - // Parameter -> non functional -> Tile/Broadcast to Parameter -> non functional -> Copy -> Tile/Broadcast - return insertion_handler->InsertCopyBeforeIfNeeded(node); - }; - - auto m = std::make_shared(brodcast_tile, matcher_name); - this->register_matcher(m, callback); -} - -bool HandleMultiConnectedLayerToConcatAndMemory::run_on_model(const std::shared_ptr& f) { - RUN_ON_FUNCTION_SCOPE(HandleMultiConnectedLayerToConcatAndMemory); - - using FuncChildrenInfo = std::tuple, // parent node - std::shared_ptr, // child node - int32_t // input index - >; - - // recursively searches for children functional layers skipping non-functional ones - std::function(std::shared_ptr, std::shared_ptr, int32_t)> - find_func_layers = [&find_func_layers](std::shared_ptr current_node, - std::shared_ptr parent_node, - int32_t input_idx) { - if (!is_gna_non_functional_node(current_node) || current_node->get_output_size() == 0 || - current_node->output(0).get_target_inputs().size() == 0) { - return std::vector{std::make_tuple(parent_node, current_node, input_idx)}; - } - std::vector results; - for (auto& child : current_node->output(0).get_target_inputs()) { - auto next_node = std::dynamic_pointer_cast(child.get_node()->shared_from_this()); - auto result = find_func_layers(next_node, current_node, static_cast(child.get_index())); - results.insert(results.end(), result.begin(), result.end()); - } - - return results; - }; - - bool is_graph_modified = false; - for (auto& node : f->get_ordered_ops()) { - if (is_gna_non_functional_node(node) || std::dynamic_pointer_cast(node)) - continue; - for (auto& output : node->outputs()) { - auto input_to = output.get_target_inputs(); - if (input_to.size() < 2) - continue; - std::vector concat_nodes, memory_nodes; - for (auto& child : input_to) { - auto current_node = std::dynamic_pointer_cast(child.get_node()->shared_from_this()); - auto children_info = find_func_layers(current_node, node, static_cast(child.get_index())); - - for (const auto& child_info : children_info) { - auto child = std::get<1>(child_info); - - if (is_concat(child)) { - concat_nodes.push_back(child_info); - } else if (std::dynamic_pointer_cast(child) || - std::dynamic_pointer_cast(child)) { - memory_nodes.push_back(child_info); - } - } - } - - if (memory_nodes.empty() && concat_nodes.empty()) - continue; - - auto count_to_copy = memory_nodes.size() + concat_nodes.size() - - (std::dynamic_pointer_cast(node) ? 0 : 1); - // Insertion of copy to memory layers has a priority on the concat layers - for (size_t i = 0; i < count_to_copy; i++) { - std::shared_ptr in_layer, out_layer; - size_t input_id; - std::tie(in_layer, out_layer, input_id) = - (i < memory_nodes.size()) ? memory_nodes[i] : concat_nodes[i - memory_nodes.size()]; - insert_copy_layer_between(in_layer, out_layer, input_id); - } - is_graph_modified = true; - } - } - - return is_graph_modified; -} -/* The main idea, is that we match the non-computational layers - * one-by-one when traversing graph in reverse order. - * For each match we check, that node contains non-computational property, - * and then assign it for each input. We have to pass the result node too, because - * we need to insert the copy operation before it. - * If we found the "parameter" node with both of properties, it indicates that we found the - * non-computational subgraph, and we insert the copy layer. - */ -MatchNonComputationalLayers::MatchNonComputationalLayers() { - MATCHER_SCOPE(MatchNonComputationalLayers); - - auto noncompute_op = ngraph::pattern::wrap_type(); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - auto node = std::dynamic_pointer_cast(m.get_match_root()); - if (!(is_gna_non_functional_node(node) || std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node))) { - return false; - } - - // Since we traverse graph in reverse order, the result should be one of the first nodes - auto& rt_info = node->get_rt_info(); - auto res_node = std::dynamic_pointer_cast(node); - if (res_node) { - rt_info[kNonCompProperty] = true; - // We collect the results to the vector, because it possible to have - // two different non-computational subgraphs with different results - rt_info[kResultProperty] = ngraph::ResultVector{res_node}; - } - - if (!rt_info.count(kNonCompProperty) || !rt_info[kNonCompProperty].as()) { - return false; - } - - // if current node is non-computational, pass the properties for each input - for (size_t i = 0; i < node->get_input_size(); i++) { - auto& input_rti = node->get_input_node_shared_ptr(i)->get_rt_info(); - input_rti[kNonCompProperty] = true; - if (input_rti.count(kResultProperty) && !input_rti[kResultProperty].as().empty()) { - for (auto&& res : rt_info[kResultProperty].as()) { - input_rti[kResultProperty].as().push_back(res); - } - } else { - input_rti[kResultProperty] = rt_info[kResultProperty]; - } - } - // Found parameter node with non-computational property, so we detected desired subgraph - // Need to insert a copy op for each pre-result node, that runs out to this parameter - if (std::dynamic_pointer_cast(node)) { - auto result_vec = rt_info[kResultProperty].as(); - for (auto&& result_node : result_vec) { - auto copy_out = result_node->get_input_node_shared_ptr(0); - for (size_t i = 0; i < copy_out->get_input_size(); i++) { - auto copy_in = copy_out->get_input_node_shared_ptr(i); - if (!std::dynamic_pointer_cast(copy_in) && - // Copy already inserted from different result - !std::dynamic_pointer_cast(copy_in)) { - insert_copy_layer_between(copy_in, copy_out, i); - } - } - } - } - return true; - }; - - auto m = std::make_shared(noncompute_op, matcher_name); - this->register_matcher(m, callback); -} - -bool HandleNonFunctionalSubgraphsCleanup::run_on_model(const std::shared_ptr& m) { - RUN_ON_MODEL_SCOPE(HandleNonFunctionalSubgraphsCleanup); - - std::vector properties{kNonCompProperty, kResultProperty}; - - for (const auto& node : m->get_ops()) { - auto& rt_info = node->get_rt_info(); - for (const auto& property : properties) { - rt_info.erase(property); - } - } - - return false; -} diff --git a/src/plugins/intel_gna/src/transformations/insert_copy_layer.hpp b/src/plugins/intel_gna/src/transformations/insert_copy_layer.hpp deleted file mode 100644 index 5924be6ca6e..00000000000 --- a/src/plugins/intel_gna/src/transformations/insert_copy_layer.hpp +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (C) 2022-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { -/** - * @brief Inserts copy layer before ReadValue/Assign (memory) layer if the input is - * Crop/Concat/Split while skipping Reshape/Trivial transpose/Squeeze/Unsqueeze (Non-functional) layers: - * [Crop/Concat/Split] [Crop/Concat/Split] - * | | - * | => [Copy] - * | | - * [Memory] [Memory] - * - * With non-functional layers: - - * [Crop/Concat/Split] [Crop/Concat/Split] - * | | - * [Non-functional] [Non-functional] - * | | - * | => [Copy] - * | | - * [Memory] [Memory] - */ -class InsertCopyBeforeAssignLayer : public ov::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - InsertCopyBeforeAssignLayer(); -}; - -/** - * @brief Inserts Copy layer before Concat layer if the input is - * Crop/Split while skipping Reshape/Trivial transpose/Squeeze/Unsqueeze (non-functional) layers: - * [Crop/Split] [Crop/Split] - * | | - * | => [Copy] - * | | - * [Concat] [Concat] - * - * With non-functional layers: - - * [Crop/Split] [Crop/Split] - * | | - * [Non-functional] [Non-functional] - * | | - * | => [Copy] - * | | - * [Concat] [Concat] - * Or if a layer has multiple connections to Concat - * [any node] [any node] - * | | - * / \ / \ - * | | => | [Copy] - * | | | | - * [Concat] [Concat] - - * [any node] [any node] - * | | - * / \ \ / \ \ - * | | | | [Copy] [Copy] - * | | | | | / - * [Concat] [Concat] - */ -class InsertCopyBeforeConcatLayer : public ov::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - InsertCopyBeforeConcatLayer(); -}; - -/** - * @brief Inserts Copy layer before Broadcast/Tile in two cases: - * 1. If Parameter is an input to Broadcast/Tile layer. - * - * [Parameter] [Parameter] - * | | - * | => [Copy] - * | | - * [Broadcast/Tile] [Broadcast/Tile] - * - * - * 2. If there are Reshape/Trivial transpose/Squeeze/Unsqueeze (non-functional) layers - * between Parameter and Broadcast/Tile layer. - * - * [Parameter] [Parameter] - * | | - * [Non functional] => [Non functional] - * | | - * | => [Copy] - * | | - * [Broadcast/Tile] [Broadcast/Tile] - * - * Note: Changes is required due the issue with legacy transformations. - * Issue is related to renaming of network input layer in case of removing - * Broadcast/Tile layer. It happens when two following conditions are met: - * - input layer of Broadcast/Tile is also network input layer (skipping non-functional) - * - layer is removed from network: - * - layer is Broadcast and product of input and target shape is the same - * - layer is Tile amd all repeats values are equal 1 - */ -class InsertCopyBeforeLayerToBeEliminated : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("InsertCopyBeforeLayerToBeEliminated", "0"); - InsertCopyBeforeLayerToBeEliminated(); -}; - -/** - * @brief Inserts Copy layer before Concat or ReadValue/Assign (Memory) layer if they use a common input - * while skipping Reshape/Trivial transpose/Squeeze/Unsqueeze (non-functional) layers - * ReadValue/Assign layers have priority on Copy insertion: - * [Any node] [Any node] - * | | - * / \ => / \ - * | \ [Copy] \ - * | \ | \ - * [Memory] [Concat] [Memory] [Concat] - * - * [Parameter] [Parameter] - * | | - * / \ => / \ - * | \ [Copy] [Copy] - * | \ | \ - * [Memory] [Concat] [Memory] [Concat] - * - * With non-functional layers: - - * [Any node] [Any node] - * | | - * / \ / \ - * [Non functional] \ => [Non functional] \ - * | \ | \ - * | \ [Copy] \ - * | \ | \ - * [Memory] [Concat] [Memory] [Concat] - * - * [Parameter] [Parameter] - * | | - * / \ / \ - * [Non functional] \ => [Non functional] \ - * | \ | \ - * | \ [Copy] [Copy] - * | \ | \ - * [Memory] [Concat] [Memory] [Concat] - */ -class HandleMultiConnectedLayerToConcatAndMemory : public ov::pass::ModelPass { -public: - NGRAPH_RTTI_DECLARATION; - bool run_on_model(const std::shared_ptr& f) override; -}; - -/** - * @brief Matches the Reshape/Trivial transpose/Squeeze/Unsqueeze (Non-functional), Crop, Split and passes the rt_info - * to inputs nodes to identify the subgraph which contains only layers mentioned above. If find the parameter with - * non-functional rt_info, then inserts copy layer in subgraph: [Parameter] [Parameter] | | - * | [Copy] - * [Reshape] => | - * | [Reshape] - * | | - * [Result] [Result] - * - * [Parameter] [Parameter] - * | | - * [Reshape] [Reshape] - * | | - * | \ / \ - * | \ => [Copy] \ - * [Reshape] [Relu] | \ - * | | [Reshape] [Relu] - * | | | \ - * [Result] [Result] [Result] [Result] - */ -class MatchNonComputationalLayers : public ov::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - MatchNonComputationalLayers(); -}; - -/** - * @brief Runs MatchNonComputationalLayers transformation in reverse order to passthru rt_info and identify the - * non-computational subgraphs. - */ -class HandleNonFunctionalSubgraphs : public ngraph::pass::BackwardGraphRewrite { -public: - NGRAPH_RTTI_DECLARATION; - HandleNonFunctionalSubgraphs() { - add_matcher(); - } -}; - -class HandleNonFunctionalSubgraphsCleanup : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("HandleNonFunctionalSubgraphsCleanup", "0"); - bool run_on_model(const std::shared_ptr& m) override; -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/insert_identity_layer.cpp b/src/plugins/intel_gna/src/transformations/insert_identity_layer.cpp deleted file mode 100644 index 631e8821054..00000000000 --- a/src/plugins/intel_gna/src/transformations/insert_identity_layer.cpp +++ /dev/null @@ -1,328 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "transformations/insert_identity_layer.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common/graph_utils.hpp" -#include "log/log.hpp" -#include "transformations/rt_info/gna_precision_change_flag.hpp" - -using namespace ov::intel_gna; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::rt_info; -using namespace ov::intel_gna::graph_utils; -using namespace ov::pass::pattern; -using namespace ov::op::util; - -namespace { -void mark_for_identity_insertion(std::shared_ptr node, size_t input_index) { - log::debug() << "Mark input as candidate for identity insertion " << input_index << ":" << node->get_friendly_name() - << std::endl; - auto input = node->input(input_index); - add_precision_change_flag(input, ov::element::i32, ov::element::i16); -} - -std::shared_ptr create_indentity(std::shared_ptr& input_op) { - auto identity_op = std::make_shared(input_op); - // Keep name of previous operation - identity_op->set_friendly_name(input_op->get_friendly_name()); - input_op->set_friendly_name(input_op->get_friendly_name() + "/previous"); - ngraph::copy_runtime_info(input_op, identity_op); - return identity_op; -} - -void insert_identity_layer_after(std::shared_ptr& input_op, size_t index) { - NGRAPH_CHECK(input_op); - - log::debug() << "Insert identity layer after " << input_op->get_friendly_name() << " (" << input_op->get_type_name() - << "):" << index << std::endl; - - auto consumers = input_op->output(index).get_target_inputs(); - auto identity_op = create_indentity(input_op); - for (auto& consumer : consumers) { - consumer.replace_source_output(identity_op); - } -} - -void insert_identity_layer_between(std::shared_ptr& input_op, - std::shared_ptr& output_op, - size_t index) { - NGRAPH_CHECK(input_op); - NGRAPH_CHECK(output_op); - - log::debug() << "Insert identity layer after " << input_op->get_friendly_name() << " (" << input_op->get_type_name() - << ") and before " << index << ":" << output_op->get_friendly_name() << " (" - << output_op->get_type_name() << ")" << std::endl; - - auto identity_op = create_indentity(input_op); - output_op->input(index).replace_source_output(identity_op); -} - -// forward declaration -bool walk_through_the_outputs(std::shared_ptr& prev_node, - size_t& prev_node_output_index, - const std::shared_ptr& node, - bool first_iteration = false); - -bool process_next_node(std::shared_ptr& prev_node, - size_t& prev_node_output_index, - const std::shared_ptr& node, - const size_t input_index) { - // Check whether node is going to be skipped - bool to_be_skipped = (is_gna_precision_agnostic(node) && !is_concat(node)) || is_pooling(node); - if (to_be_skipped) { - // if it is pooling, update previous node, since activation - // should be inserted after the pooling - if (is_pooling(node)) { - prev_node = node; - // supported pooling from opset7 has 1 output port - prev_node_output_index = 0; - } - // walk over all outputs of this node - return walk_through_the_outputs(prev_node, prev_node_output_index, node); - } - // Don't skip this node, check whether precision is changed - if (is_precision_changed(node->input(input_index))) { - // if at least one target input requires Identity insertion, - // process the appropriate output port - // if there are other comsumers with i32 input - // diagonal layer will be insrted anyway before them - insert_identity_layer_after(prev_node, prev_node_output_index); - // graph modified - return true; - } - return false; -} - -bool walk_through_the_outputs(std::shared_ptr& prev_node, - size_t& prev_node_output_index, - const std::shared_ptr& node, - bool first_iteration) { - bool is_identity_inserted = false; - // walk over all outputs - for (size_t i = 0; i < node->get_output_size(); i++) { - // check all target inputs node of this output - for (auto&& input : node->output(i).get_target_inputs()) { - // if it is first iteration track output port id - // because prev_node is functional - if (first_iteration) - prev_node_output_index = i; - // recursively check next node, skipping precision agnostic - if (process_next_node(prev_node, - prev_node_output_index, - input.get_node()->shared_from_this(), - input.get_index())) { - // graph is modified - is_identity_inserted = true; - // go to the next output, other target inputs are not interesting anymore - break; - } - } - } - return is_identity_inserted; -} -} // namespace - -bool MarkIdentityCandidates::run_on_model(const std::shared_ptr& m) { - RUN_ON_FUNCTION_SCOPE(MarkIdentityCandidates); - for (auto& node : m->get_ordered_ops()) { - auto check_previous_node_and_mark = [&node]() { - for (size_t i = 0; i < node->get_input_size(); i++) { - auto prev_node = node->get_input_node_shared_ptr(i); - prev_node = get_prev_node_skipping_certain(prev_node, is_gna_precision_agnostic); - if (has_32bit_output(prev_node) || is_pooling(prev_node)) { - mark_for_identity_insertion(node, i); - } - } - }; - if (std::dynamic_pointer_cast(node)) { - auto input0_node = node->get_input_node_shared_ptr(0); - auto input1_node = node->get_input_node_shared_ptr(1); - auto func_input0_node = get_prev_node_skipping_certain(input0_node, is_gna_precision_agnostic); - auto func_input1_node = get_prev_node_skipping_certain(input1_node, is_gna_precision_agnostic); - if (is_eltwise_add(node) && !is_low_precision_input) { - if (!has_32bit_output(func_input0_node) || !has_32bit_output(func_input1_node)) - continue; - - mark_for_identity_insertion(node, 0); - } else if (is_eltwise_mul(node) || (is_eltwise_add(node) && is_low_precision_input)) { - if (has_8bit_or_16_bit_output(func_input0_node) && has_8bit_or_16_bit_output(func_input1_node)) - continue; - - if (has_32bit_output(func_input0_node)) { - mark_for_identity_insertion(node, 0); - } - - if (has_32bit_output(func_input1_node)) { - mark_for_identity_insertion(node, 1); - } - } - } else if (is_concat(node)) { - check_previous_node_and_mark(); - } else { - if (is_gna_precision_agnostic(node) || has_32bit_input(node) || ngraph::op::is_parameter(node) || - ngraph::op::is_constant(node) || ngraph::op::is_output(node) || ngraph::op::is_sink(node)) { - continue; - } - check_previous_node_and_mark(); - } - } - return false; -} - -BreakFusingOfOutputLayers::BreakFusingOfOutputLayers() { - MATCHER_SCOPE(BreakFusingOfOutputLayers); - - auto result_op = ngraph::pattern::wrap_type({ngraph::pattern::any_input()}); - - ngraph::matcher_pass_callback callback = [=](Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto result_node = pattern_map.at(result_op).get_node_shared_ptr(); - auto input_node = result_node->get_input_node_shared_ptr(0); - - for (size_t i = 0; i < input_node->get_output_size(); i++) { - for (auto&& input : input_node->output(i).get_target_inputs()) { - if (!is_activation(input.get_node())) { - continue; - } - insert_identity_layer_between(input_node, result_node, 0); - return true; - } - } - return false; - }; - - auto m = std::make_shared(result_op, matcher_name); - this->register_matcher(m, callback); -} - -bool InsertIdentity::run_on_model(const std::shared_ptr& m) { - RUN_ON_FUNCTION_SCOPE(InsertIdentity); - bool is_graph_modifed = false; - - for (auto& node : m->get_ordered_ops()) { - // if node has 8 bit or 16 bit output already or Result or State, it is not our case, skip it - if (has_8bit_or_16_bit_output(node) || ngraph::op::is_output(node) || ngraph::op::is_sink(node)) - continue; - - // walk through the all outputs - std::shared_ptr prev_node = node; - size_t prev_node_output_index = 0; - is_graph_modifed |= walk_through_the_outputs(prev_node, prev_node_output_index, node, true); - } - return is_graph_modifed; -} - -bool IdentityCandidatesCleanup::run_on_model(const std::shared_ptr& f) { - RUN_ON_FUNCTION_SCOPE(IdentityCandidatesCleanup); - for (auto& node : f->get_ordered_ops()) { - for (auto& input : node->inputs()) { - remove_precision_change_flag(input); - } - } - return false; -} - -bool InsertIdentityForPrecAgnosticConcatInput::are_all_inputs_pointing_the_same_node( - const std::shared_ptr& node) { - const auto& inputs = node->inputs(); - const auto& input0 = inputs[0].get_tensor_ptr(); - return all_of(inputs.begin(), inputs.end(), [&](const ov::Input& in) { - return in.get_tensor_ptr() == input0; - }); -} - -size_t InsertIdentityForPrecAgnosticConcatInput::find_prev_layer_output_index(const std::shared_ptr& prev, - const std::shared_ptr& next) { - for (const auto& output : prev->outputs()) { - for (const auto& input : output.get_target_inputs()) { - if (input.get_node() == next.get()) { - return output.get_index(); - } - } - } - THROW_GNA_EXCEPTION << "Output not found"; -} - -bool InsertIdentityForPrecAgnosticConcatInput::insert_identity_after_nodes( - const std::vector>& nodes, - const std::shared_ptr& next) { - for (auto node : nodes) { - size_t index = find_prev_layer_output_index(node, next); - insert_identity_layer_after(node, index); - } - return nodes.size() > 0; -} - -bool InsertIdentityForPrecAgnosticConcatInput::has_fq_on_any_input(const std::shared_ptr concat_node) { - auto is_not_fq = [](std::shared_ptr node) -> bool { - return !is_parameter(node) && !is_constant(node) && !is_fake_quantize(node); - }; - for (size_t i = 0; i < concat_node->get_input_size(); i++) { - auto concat_input_node = concat_node->get_input_node_shared_ptr(i); - auto prev_node = get_prev_node_skipping_certain(concat_input_node, is_not_fq); - if (!is_parameter(prev_node) && !is_constant(prev_node)) { - return true; - } - } - return false; -} - -std::vector> InsertIdentityForPrecAgnosticConcatInput::get_nodes_for_identity_insertion( - const std::shared_ptr& concat_node) { - auto not_able_to_hold_sf = [](std::shared_ptr node) -> bool { - return is_gna_precision_agnostic(node) || is_fake_quantize(node) || is_read_value(node); - }; - - std::vector> nodes; - for (size_t i = 0; i < concat_node->get_input_size(); i++) { - auto concat_input_node = concat_node->get_input_node_shared_ptr(i); - auto prev_node = get_prev_node_skipping_certain(concat_input_node, not_able_to_hold_sf); - if ((is_parameter(prev_node) || is_constant(prev_node)) && (!is_parameter(concat_input_node))) { - nodes.emplace_back(concat_input_node); - } - } - return nodes; -} - -bool InsertIdentityForPrecAgnosticConcatInput::insert_identity_for_prec_agnostic_concat_inputs( - const std::shared_ptr& concat_node) { - if (are_all_inputs_pointing_the_same_node(concat_node)) { - return false; - } - - if (!has_fq_on_any_input(concat_node)) { - return false; - } - - const auto& nodes = get_nodes_for_identity_insertion(concat_node); - - // Skip adding Identity if none of inputs can hold scale factors - bool no_input_can_hold_sf = concat_node->get_input_size() == nodes.size(); - if (no_input_can_hold_sf) { - return false; - } - - return insert_identity_after_nodes(nodes, concat_node); -} - -bool InsertIdentityForPrecAgnosticConcatInput::run_on_model(const std::shared_ptr& m) { - RUN_ON_FUNCTION_SCOPE(InsertIdentityForPrecAgnosticConcatInput); - bool is_graph_modified = false; - for (auto& node : m->get_ordered_ops()) { - if (is_concat(node)) { - is_graph_modified |= insert_identity_for_prec_agnostic_concat_inputs(node); - } - } - return is_graph_modified; -} diff --git a/src/plugins/intel_gna/src/transformations/insert_identity_layer.hpp b/src/plugins/intel_gna/src/transformations/insert_identity_layer.hpp deleted file mode 100644 index 091c5ecc12a..00000000000 --- a/src/plugins/intel_gna/src/transformations/insert_identity_layer.hpp +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { -/** - * Group of transformations which insert Identity layer in the following cases: - * in case of eltwise sum in 16-bit input precision, one of inputs is 4 bytes, the other is 2 bytes - * in case of eltwise mul in 16-bit input precision, both inputs are 2 bytes - * in case of eltwise sum in low (8-bit) input precision, both inputs are 1 byte - * in case of eltwise mul in low (8-bit) input precision, both inputs are 1 byte - * for e sum if we have 4-4 inputs we will handle that by inserting identity activation -- handling here - * for e sum if we have 4-2 - OK - * for e sum if we have 2-2 inputs we need to insert diagonal - * for e sum if we have 1-1 inputs in low precision mode - OK - * for e mul if we have 2-2 - OK - * for e mul if we have 1-1 in low precision mode - OK - * for e mul if we have 2-4 - inputs we need to insert identity to put 4 bytes input into weights -- handling here - * for e mul if we have 4-4 - inputs we need to insert 2 identities to put both 4 bytes input into weights -- handling - * here - */ - -/** - * @brief Transformation is looking for nodes before which Identity should be inserted and mark them with appropriate rt - * attribute - */ -class MarkIdentityCandidates : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("MarkIdentityCandidates", "0"); - MarkIdentityCandidates(bool is_low_precision_input) : is_low_precision_input(is_low_precision_input) {} - bool run_on_model(const std::shared_ptr& f) override; - -private: - bool is_low_precision_input; -}; - -/** - * @brief Transformation inserts Identity layer based on rt attribute - */ -class InsertIdentity : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("InsertIdentity", "0"); - bool run_on_model(const std::shared_ptr& f) override; -}; - -/** - * @brief In cases that network output layer is connected to only one layer which is activation additional identity is - * inserted so the operation is not fused with the activation allowing to get the results from said layer - */ -class BreakFusingOfOutputLayers : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("BreakFusingOfOutputLayers", "0"); - BreakFusingOfOutputLayers(); -}; - -/** - * @brief IdentityCandidates removes attribute mark for identity insertion - */ -class IdentityCandidatesCleanup : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("IdentityCandidatesCleanup", "0"); - bool run_on_model(const std::shared_ptr& m) override; -}; - -/** - * @brief Inserts identity for precision agnostic (or FQ) concat inputs - * Scale factor propagation requires unified scale factors for each Concat input. - * If some input does not contain any layer, which is capable of storing scale factors, - * additional layer must be introduced. - * InsertIdentityForPrecAgnosticConcatInput pass adds Identity layer, which - * is capable of storing scale factors, so the scale factors propagation can proceed. - * Note: Identity will be added to all affected inputs. - * Note: Algorighm does not depend on inputs order. - * - * Example model: - * - * Parameter - * | - * Functional ... Prec-Agnostic or FQ - * \ | / - * Concat - * | - * Result - * - * After execution: - * - * Parameter - * | - * Prec-Agnostic or FQ - * | - * Functional ... Identity - * \ | / - * Concat - * | - * Result - * - */ -class InsertIdentityForPrecAgnosticConcatInput : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("InsertIdentityForPrecAgnosticConcatInput", "0"); - bool run_on_model(const std::shared_ptr& m) override; - -private: - /** - * @brief Check if FakeQuantize exists on any input - */ - bool has_fq_on_any_input(const std::shared_ptr concat_node); - - /** - * @brief Check if at least two inputs are not identical - */ - bool are_all_inputs_pointing_the_same_node(const std::shared_ptr& node); - - /** - * @brief Return vector of nodes for Identity insertion - */ - std::vector> get_nodes_for_identity_insertion( - const std::shared_ptr& concat_node); - - /** - * @brief Invokes Identity layer insertion after each node in vector - * returns true if any Identity layer was inserted - */ - bool insert_identity_after_nodes(const std::vector>& nodes, - const std::shared_ptr& next); - - /** - * @brief Invoke Identity layer insertion in case the Concat input is unable - * to store scale factors - * returns true if any Identity layer was inserted - */ - bool insert_identity_for_prec_agnostic_concat_inputs(const std::shared_ptr& node); - - /** - * @brief Find the output index of 'prev' layer, on which it is connected to 'next' layer - */ - size_t find_prev_layer_output_index(const std::shared_ptr& prev, const std::shared_ptr& next); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/insert_reshape_around_matmul.cpp b/src/plugins/intel_gna/src/transformations/insert_reshape_around_matmul.cpp deleted file mode 100644 index e40d6d2c583..00000000000 --- a/src/plugins/intel_gna/src/transformations/insert_reshape_around_matmul.cpp +++ /dev/null @@ -1,306 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/insert_reshape_around_matmul.hpp" - -#include - -#include -#include -#include -#include -#include -#include - -#include "log/debug.hpp" - -using namespace ov::intel_gna::pass; - -static bool InsertReshape(ngraph::pattern::Matcher& matcher, - const std::shared_ptr& input, - const std::shared_ptr& matmul1, - const std::shared_ptr& matmul2, - const std::shared_ptr& add1 = nullptr, - const std::shared_ptr& add2 = nullptr, - const std::shared_ptr& fake_quantize = nullptr, - const std::shared_ptr& transpose = nullptr) { - const auto& pattern_map = matcher.get_pattern_value_map(); - size_t matmul_input_index = 1; - auto iter = pattern_map.find(matmul1); - if (iter == pattern_map.end()) { - iter = pattern_map.find(matmul2); - if ((iter = pattern_map.find(matmul2)) == pattern_map.end()) { - return false; - } - - matmul_input_index = 0; - } - - std::shared_ptr matmul_node = iter->second.get_node_shared_ptr(); - if ((iter = pattern_map.find(input)) == std::end(pattern_map)) { - return false; - } - - auto first_node = iter->second.get_node_shared_ptr(); - size_t add_input_index = 0; - iter = pattern_map.find(add1); - std::shared_ptr add_node = nullptr; - if (iter != pattern_map.end()) { - add_node = iter->second.get_node_shared_ptr(); - add_input_index = - std::dynamic_pointer_cast(add_node->get_input_node_shared_ptr(0)) ? 1 : 0; - } - - // If there is an Add layer, check if it doesn't require inserting a Reshape - // to align its dimensions with reshaped MatMul's dimensions - if (add_node) { - auto add_input = add_node->get_input_node_shared_ptr(add_input_index); - if (add_input->get_output_shape(0).size() != 2) { - auto consumers = add_input->output(0).get_target_inputs(); - std::vector before_shape = {-1, static_cast(add_input->get_output_shape(0).back())}; - auto reshape_add_input = ov::op::util::make_try_fold( - add_input, - std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{before_shape.size()}, - before_shape), - false); - reshape_add_input->set_friendly_name(reshape_add_input->get_friendly_name() + "/reshape_before_add"); - ngraph::copy_runtime_info(add_node, reshape_add_input); - for (auto& consumer : consumers) { - consumer.replace_source_output(reshape_add_input); - } - } - } - - std::vector> nodes = {matmul_node}; - for (auto& node : {add2, add1, fake_quantize, transpose}) { - iter = pattern_map.find(node); - if (iter != pattern_map.end()) { - nodes.push_back(iter->second.get_node_shared_ptr()); - } - } - - auto last_node_shape = nodes.back()->get_output_shape(0); - auto reshape_input_node = std::dynamic_pointer_cast(first_node); - bool need_reshape_before = !reshape_input_node || reshape_input_node->get_output_shape(0).size() != 2; - if (need_reshape_before) { - std::vector before_shape = {-1, static_cast(first_node->get_output_shape(0).back())}; - auto reshape_before_node_const = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{before_shape.size()}, - before_shape); - auto reshape_before_node = - std::make_shared(first_node, reshape_before_node_const, false); - reshape_before_node->set_friendly_name(matmul_node->get_friendly_name() + "/reshape_before_matmul"); - ngraph::copy_runtime_info(first_node, {reshape_before_node, reshape_before_node_const}); - matmul_node->input(matmul_input_index).replace_source_output(reshape_before_node->output(0)); - if (auto transpose_node = std::dynamic_pointer_cast(nodes.back())) { - nodes.pop_back(); - std::reverse(nodes.begin(), nodes.end()); - while (!nodes.empty()) { - auto node_copy = nodes.back()->clone_with_new_inputs(nodes.back()->input_values()); - ngraph::copy_runtime_info(nodes.back(), node_copy); - ngraph::replace_node(nodes.back(), node_copy); - nodes.pop_back(); - } - - auto transpose_input_shape = transpose_node->input_values()[0].get_node_shared_ptr()->get_output_shape(0); - auto transpose_constant_shape = - transpose_node->input_values()[1].get_node_shared_ptr()->get_output_shape(0); - if (std::count_if(transpose_input_shape.begin(), transpose_input_shape.end(), [](size_t n) { - return n > 1; - }) > 2) { - THROW_GNA_EXCEPTION << "The number of dimensions that are greater than 1 is greater than 2" - << " for Transpose layer (" << transpose_node->get_friendly_name() << ")." - << " For this reason, there is no way to determine permutation shape."; - } - std::vector permutation_shape = {1, 0}; - auto transpose_node_copy_const = - std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{permutation_shape.size()}, - permutation_shape); - auto transpose_node_copy = - transpose_node->clone_with_new_inputs({transpose_node->input_values()[0], transpose_node_copy_const}); - ngraph::copy_runtime_info(transpose_node, {transpose_node_copy, transpose_node_copy_const}); - ngraph::replace_node(transpose_node, transpose_node_copy); - nodes.push_back(transpose_node_copy); - } - } - - auto consumers = nodes.back()->output(0).get_target_inputs(); - bool need_reshape_after = false; - for (auto consumer : consumers) { - auto reshape_output_node = dynamic_cast(consumer.get_node()); - if (!reshape_output_node || reshape_output_node->get_output_shape(0).size() != last_node_shape.size()) { - need_reshape_after = true; - break; - } - } - - if (need_reshape_after) { - auto reshape_after_node_const = - std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{last_node_shape.size()}, - last_node_shape); - auto reshape_after_node = - std::make_shared(nodes.back(), reshape_after_node_const, false); - reshape_after_node->set_friendly_name(nodes.back()->get_friendly_name()); - ngraph::copy_runtime_info(nodes.back(), {reshape_after_node, reshape_after_node_const}); - for (auto consumer : consumers) { - consumer.replace_source_output(reshape_after_node); - } - } - - return need_reshape_before || need_reshape_after; -} - -static std::shared_ptr CreateMatmulPattern( - std::shared_ptr& input, - std::shared_ptr& matmul1, - std::shared_ptr& matmul2, - const ngraph::pattern::op::ValuePredicate& pred = [](const ngraph::Output& output) { - return true; - }) { - auto constant = ngraph::pattern::wrap_type(); - auto fake_quantize = ngraph::pattern::wrap_type( - {constant, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - auto matmul_input = std::make_shared(ngraph::OutputVector{constant, fake_quantize}); - input = ngraph::pattern::any_input([](const ngraph::Output& node) { - auto shape = node.get_node_shared_ptr()->get_output_shape(0); - return shape.size() > 2 && std::count_if(shape.begin(), shape.end(), [](size_t e) { - return e > 1; - }) <= 2; - }); - matmul1 = ngraph::pattern::wrap_type({matmul_input, input}, pred); - matmul2 = ngraph::pattern::wrap_type({input, matmul_input}, pred); - return std::make_shared(ngraph::OutputVector{matmul1, matmul2}); -} - -InsertReshapeAroundMatmul::InsertReshapeAroundMatmul() { - MATCHER_SCOPE(InsertReshapeAroundMatmul); - - auto pred = [](const ngraph::Output& node) { - const auto& outputs = node.get_node_shared_ptr()->outputs(); - const auto& inputs = outputs[0].get_target_inputs(); - if (inputs.empty()) { - return true; - } - - auto next_node = inputs.begin()->get_node(); - return outputs.size() != 1 || (!dynamic_cast(next_node) && - !dynamic_cast(next_node) && - !dynamic_cast(next_node)); - }; - - std::shared_ptr input; - std::shared_ptr matmul1; - std::shared_ptr matmul2; - auto matmul = CreateMatmulPattern(input, matmul1, matmul2, pred); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& matcher) { - return InsertReshape(matcher, input, matmul1, matmul2); - }; - - auto matcher = std::make_shared(matmul, matcher_name); - this->register_matcher(matcher, callback); -} - -InsertReshapeAroundMatmulWithAdd::InsertReshapeAroundMatmulWithAdd() { - MATCHER_SCOPE(InsertReshapeAroundMatmulWithAdd); - - auto pred = [](const ngraph::Output& node) { - const auto& outputs = node.get_node_shared_ptr()->outputs(); - const auto& inputs = outputs[0].get_target_inputs(); - if (inputs.empty()) { - return true; - } - - auto next_node = inputs.begin()->get_node(); - return outputs.size() != 1 || (!dynamic_cast(next_node) && - !dynamic_cast(next_node)); - }; - - std::shared_ptr input; - std::shared_ptr matmul1; - std::shared_ptr matmul2; - auto matmul = CreateMatmulPattern(input, matmul1, matmul2); - auto add_input = ngraph::pattern::any_input(); - auto add1 = ngraph::pattern::wrap_type({matmul, add_input}, pred); - auto add2 = ngraph::pattern::wrap_type({add_input, matmul}, pred); - auto add = std::make_shared(ngraph::OutputVector{add1, add2}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& matcher) { - return InsertReshape(matcher, input, matmul1, matmul2, add1, add2); - }; - - auto matcher = std::make_shared(add, matcher_name); - this->register_matcher(matcher, callback); -} - -InsertReshapeAroundMatmulWithFq::InsertReshapeAroundMatmulWithFq() { - MATCHER_SCOPE(InsertReshapeAroundMatmulWithFq); - - std::shared_ptr input; - std::shared_ptr matmul1; - std::shared_ptr matmul2; - auto matmul = CreateMatmulPattern(input, matmul1, matmul2); - auto add_input = ngraph::pattern::any_input(); - auto add1 = ngraph::pattern::wrap_type({matmul, add_input}); - auto add2 = ngraph::pattern::wrap_type({add_input, matmul}); - auto fq_input = std::make_shared(ngraph::OutputVector{matmul, add1, add2}); - auto fake_quantize2 = ngraph::pattern::wrap_type( - {fq_input, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - [](const ngraph::Output& node) { - const auto& outputs = node.get_node_shared_ptr()->outputs(); - const auto& inputs = outputs[0].get_target_inputs(); - if (inputs.empty()) { - return true; - } - - auto next_node = inputs.begin()->get_node(); - return outputs.size() != 1 || !dynamic_cast(next_node); - }); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& matcher) { - return InsertReshape(matcher, input, matmul1, matmul2, add1, add2, fake_quantize2); - }; - - auto matcher = std::make_shared(fake_quantize2, matcher_name); - this->register_matcher(matcher, callback); -} - -InsertReshapeAroundMatmulWithTranspose::InsertReshapeAroundMatmulWithTranspose() { - MATCHER_SCOPE(InsertReshapeAroundMatmulWithTranspose); - - std::shared_ptr input; - std::shared_ptr matmul1; - std::shared_ptr matmul2; - auto matmul = CreateMatmulPattern(input, matmul1, matmul2); - auto add_input = ngraph::pattern::any_input(); - auto add1 = ngraph::pattern::wrap_type({matmul, add_input}); - auto add2 = ngraph::pattern::wrap_type({add_input, matmul}); - auto fq_input = std::make_shared(ngraph::OutputVector{matmul, add1, add2}); - auto fake_quantize2 = ngraph::pattern::wrap_type({fq_input, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}); - auto transpose_input = std::make_shared(ngraph::OutputVector{fq_input, fake_quantize2}); - auto transpose = - ngraph::pattern::wrap_type({transpose_input, ngraph::pattern::any_input()}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& matcher) { - return InsertReshape(matcher, input, matmul1, matmul2, add1, add2, fake_quantize2, transpose); - }; - - auto matcher = std::make_shared(transpose, matcher_name); - this->register_matcher(matcher, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/insert_reshape_around_matmul.hpp b/src/plugins/intel_gna/src/transformations/insert_reshape_around_matmul.hpp deleted file mode 100644 index 2d5025ca9d4..00000000000 --- a/src/plugins/intel_gna/src/transformations/insert_reshape_around_matmul.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#ifndef INSERT_RESHAPE_AROUND_MATMUL_HPP -#define INSERT_RESHAPE_AROUND_MATMUL_HPP - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -// @brief Insert Reshapes from 3d/4d to 2d before MatMul and from 2d to 3d/4d after MatMul -class InsertReshapeAroundMatmul : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("InsertReshapeAroundMatmul", "0"); - InsertReshapeAroundMatmul(); -}; - -class InsertReshapeAroundMatmulWithAdd : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("InsertReshapeAroundMatmulWithAdd", "0"); - InsertReshapeAroundMatmulWithAdd(); -}; - -class InsertReshapeAroundMatmulWithFq : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("InsertReshapeAroundMatmulWithFq", "0"); - InsertReshapeAroundMatmulWithFq(); -}; - -class InsertReshapeAroundMatmulWithTranspose : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("InsertReshapeAroundMatmulWithTranspose", "0"); - InsertReshapeAroundMatmulWithTranspose(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov - -#endif // INSERT_RESHAPE_AROUND_MATMUL_HPP diff --git a/src/plugins/intel_gna/src/transformations/insert_transpose_after_convolution_or_pooling.cpp b/src/plugins/intel_gna/src/transformations/insert_transpose_after_convolution_or_pooling.cpp deleted file mode 100644 index 5c0d3e9cb32..00000000000 --- a/src/plugins/intel_gna/src/transformations/insert_transpose_after_convolution_or_pooling.cpp +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "transformations/insert_transpose_after_convolution_or_pooling.hpp" - -#include -#include -#include -#include -#include - -#include "log/debug.hpp" -#include "log/log.hpp" - -using namespace ov::intel_gna::pass; - -bool InsertTransposeAfterConvOrPool::run_on_model(const std::shared_ptr& f) { - RUN_ON_FUNCTION_SCOPE(InsertTransposeAfterConvOrPool); - bool is_graph_modfied = false; - for (auto& node : f->get_ordered_ops()) { - if (std::dynamic_pointer_cast(node) == nullptr && - std::dynamic_pointer_cast(node) == nullptr) { - continue; - } - - auto next_node = node->output(0).get_target_inputs().begin()->get_node()->shared_from_this(); - if (std::dynamic_pointer_cast(next_node) == nullptr) { - continue; - } - - bool found_reshape_to_1d = false; - std::shared_ptr reshape_node = next_node; - std::shared_ptr transpose_node = nullptr; - while ((reshape_node != nullptr || transpose_node != nullptr) && next_node->get_output_size() == 1) { - auto input_shape = next_node->get_input_shape(0); - auto output_shape = next_node->get_output_shape(0); - if (input_shape[1] > 1 && output_shape.back() == std::accumulate(std::begin(output_shape), - std::end(output_shape), - size_t(1), - std::multiplies())) { - found_reshape_to_1d = true; - break; - } - next_node = next_node->output(0).get_target_inputs().begin()->get_node()->shared_from_this(); - reshape_node = std::dynamic_pointer_cast(next_node); - transpose_node = std::dynamic_pointer_cast(next_node); - } - - if (!found_reshape_to_1d) - continue; - - // Search for a convolution after this reshape - bool found_next_conv_or_pool = false; - while (next_node->get_output_size() > 0 && next_node->output(0).get_target_inputs().size() > 0 && - std::dynamic_pointer_cast(next_node) == nullptr && - std::dynamic_pointer_cast(next_node) == nullptr) { - next_node = next_node->output(0).get_target_inputs().begin()->get_node()->shared_from_this(); - if (std::dynamic_pointer_cast(next_node) != nullptr || - std::dynamic_pointer_cast(next_node) != nullptr) { - found_next_conv_or_pool = true; - break; - } - } - - if (!found_next_conv_or_pool) - continue; - - // check if transpose is supported by GNA - auto output_shape = node->get_output_shape(0); - if (output_shape.size() < 3) - continue; - std::vector transpose_ids; - for (size_t ix = 0; ix < output_shape.size(); ++ix) { - if (output_shape[ix] > 1) { - transpose_ids.push_back(ix); - } - } - if (transpose_ids.size() == 1) { - continue; - } - if (transpose_ids.size() != 2) { - THROW_GNA_EXCEPTION << "Unable to insert transpose after: " << node->get_friendly_name() - << " number of dimensions to transpose: " << transpose_ids.size(); - } - size_t min, max; - std::tie(min, max) = std::minmax(output_shape[transpose_ids[0]], output_shape[transpose_ids[1]]); - if (min > 8 || max % 8 != 0) { - THROW_GNA_EXCEPTION << "Unable to insert transpose after: " << node->get_friendly_name() - << " min dimension size: " << min << " max dimension size: " << max; - } - - log::debug() << "Insert Transpose after " << node->get_friendly_name() << "\n"; - - auto consumers = node->output(0).get_target_inputs(); - - ngraph::Shape transposeInShape = output_shape; - std::swap(transposeInShape[transpose_ids[0]], transposeInShape[transpose_ids[1]]); - auto reshapeConstBefore = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{transposeInShape.size()}, - transposeInShape); - auto reshapeBefore = std::make_shared(node, reshapeConstBefore, false); - reshapeBefore->set_friendly_name(node->get_friendly_name() + "/reshape_out"); - ngraph::copy_runtime_info(node, {reshapeBefore, reshapeConstBefore}); - - auto transpose_order = transposeInShape.size() == 3 ? ngraph::Shape{0, 2, 1} : ngraph::Shape{0, 3, 1, 2}; - auto transpose_order_const = ngraph::opset7::Constant::create(ngraph::element::i64, - ngraph::Shape{transpose_order.size()}, - transpose_order); - auto transpose = std::make_shared(reshapeBefore, transpose_order_const); - transpose->set_friendly_name(node->get_friendly_name() + "/transpose_out"); - ngraph::copy_runtime_info(node, {transpose, transpose_order_const}); - - for (auto& input : consumers) { - input.replace_source_output(transpose); - } - is_graph_modfied = true; - } - - return is_graph_modfied; -} diff --git a/src/plugins/intel_gna/src/transformations/insert_transpose_after_convolution_or_pooling.hpp b/src/plugins/intel_gna/src/transformations/insert_transpose_after_convolution_or_pooling.hpp deleted file mode 100644 index b11dc5ea680..00000000000 --- a/src/plugins/intel_gna/src/transformations/insert_transpose_after_convolution_or_pooling.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Inserts transpose after convolution or pooling if its output is reshaped to 3D or 4D data with only one last - * dimension > 1 and the reshaped data is used as an input to the next convolution: Convolution / Pooling [1, C, 1, W] - * | - * Reshape [1, 1, 1, C*W] - * | - * ... - * | - * Convolution - */ -class InsertTransposeAfterConvOrPool : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("InsertTransposeAfterConvOrPool", "0"); - bool run_on_model(const std::shared_ptr& f) override; -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/markup_fusable_transpose.cpp b/src/plugins/intel_gna/src/transformations/markup_fusable_transpose.cpp deleted file mode 100644 index 78e6e7def5a..00000000000 --- a/src/plugins/intel_gna/src/transformations/markup_fusable_transpose.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "markup_fusable_transpose.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::pass::helper; -using namespace ov::intel_gna::graph_utils; -using namespace ov::intel_gna::rt_info; - -namespace { -bool is_skip_operation(const std::shared_ptr& node) { - return ( - !std::dynamic_pointer_cast(node) && - !std::dynamic_pointer_cast(node) && - !std::dynamic_pointer_cast(node) && - !std::dynamic_pointer_cast(node) && - (!is_gna_non_functional_node(node) || node->output(0).get_shape().size() == node->input(0).get_shape().size())); -} -} // namespace - -bool MarkupFusableTranspose::run_on_model(const std::shared_ptr& f) { - RUN_ON_FUNCTION_SCOPE(MarkupFusableTranspose); - - for (auto& node : f->get_ordered_ops()) { - if (!std::dynamic_pointer_cast(node) && - !std::dynamic_pointer_cast(node)) { - continue; - } - auto in_dims = node->input(0).get_shape(); - auto out_dims = node->output(0).get_shape(); - - if (is_one_dim_shapes(in_dims, out_dims)) { - continue; - } - - auto current_node = get_next_node_skipping_certain(node, is_skip_operation); - if (!TransposeOrderMatches(std::dynamic_pointer_cast(current_node), {0, 3, 2, 1})) { - continue; - } - add_transpose_fusable(current_node); - } - - return false; -} \ No newline at end of file diff --git a/src/plugins/intel_gna/src/transformations/markup_fusable_transpose.hpp b/src/plugins/intel_gna/src/transformations/markup_fusable_transpose.hpp deleted file mode 100644 index 6323409d6ac..00000000000 --- a/src/plugins/intel_gna/src/transformations/markup_fusable_transpose.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Markup fusable tranpose - * This transformation is written to support old IRs for Kaldi models - * with specific 0-3-2-1 transpose after Convolution and mark it up - * for special handling in compiler for backward compatibility purposes - */ -class MarkupFusableTranspose : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("MarkupFusableTranspose", "0"); - bool run_on_model(const std::shared_ptr& f) override; -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_gna/src/transformations/pwl_approximation.cpp b/src/plugins/intel_gna/src/transformations/pwl_approximation.cpp deleted file mode 100644 index 62329ba60ea..00000000000 --- a/src/plugins/intel_gna/src/transformations/pwl_approximation.cpp +++ /dev/null @@ -1,562 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "pwl_approximation.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common/graph_utils.hpp" -#include "common/numerical_utils.hpp" -#include "ops/pwl.hpp" -#include "ops/reference/pwl.hpp" -#include "transformations/utils/utils.hpp" - -static constexpr double EXP_BREAK = 0.045; - -using namespace ov::intel_gna; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::common; - -NGRAPH_RTTI_DEFINITION(PWLApproximation, "PWLApproximation"); -NGRAPH_RTTI_DEFINITION(PWLApproximationWithFq, "PWLApproximationWithFq"); - -template -double get_break_bound() { - if (std::is_same::value) { - return EXP_BREAK; - } - - return 0; -} - -template -bool split_search(double lower_bound, double upper_bound) { - if (lower_bound > upper_bound) { - return false; - } - - double break_bound = get_break_bound(); - if (std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value || - std::is_same::value) { - return lower_bound < break_bound && upper_bound > break_bound; - } - return false; -} - -template -double pivot_search(const details::Function& activation_function, - std::vector& result, - uint32_t N, - double alpha_0, - double alpha_N, - bool negative, - double max_error, - double threshold = 0.1) { - std::vector> t(N + 1); - std::vector> alpha(N + 1); - std::vector> epsilon(N + 1); - std::vector> d(N + 1); - bool same_epsilon = false; - double Delta; - double epsilon_final = 0.0; - double max_epsilon = 0.0; - double max_epsilon_prev; - double min_epsilon; - double sgn = (negative) ? -1.0 : 1.0; - int j; - - // Figure 4: Box #1 - j = 0; - Delta = 1.0; - - for (uint32_t i = 0; i < N; i++) { - t[i].push_back(alpha_0 + (static_cast((i + 1)) / static_cast((N + 1))) * (alpha_N - alpha_0)); - } - - while (true) { - // Figure 4: Box #2 - alpha[0].resize(j + 1); - alpha[0][j] = alpha_0; - for (uint32_t i = 1; i < N; i++) { - alpha[i].resize(j + 1); - alpha[i][j] = - (activation_function.get_value(t[i - 1][j]) - activation_function.get_value(t[i][j]) + - activation_function.first_derivative(t[i][j]) * t[i][j] - - activation_function.first_derivative(t[i - 1][j]) * t[i - 1][j]) / - (activation_function.first_derivative(t[i][j]) - activation_function.first_derivative(t[i - 1][j])); - } - alpha[N].resize(j + 1); - alpha[N][j] = alpha_N; - - // Figure 4: Box #3 - for (uint32_t i = 0; i < N; i++) { - epsilon[i].resize(j + 1); - epsilon[i][j] = sgn * (activation_function.first_derivative(t[i][j]) * (alpha[i][j] - t[i][j]) + - activation_function.get_value(t[i][j]) - activation_function.get_value(alpha[i][j])); - if (std::isnan(epsilon[i][j])) { - throw std::runtime_error("The value is out of range."); - } - } - epsilon[N].resize(j + 1); - epsilon[N][j] = sgn * (activation_function.first_derivative(t[N - 1][j]) * (alpha[N][j] - t[N - 1][j]) + - activation_function.get_value(t[N - 1][j]) - activation_function.get_value(alpha[N][j])); - if (std::isnan(epsilon[N][j])) { - throw std::runtime_error("The value is out of range."); - } - - // Figure 4: Test for completion - max_epsilon_prev = max_epsilon; - max_epsilon = std::fabs(epsilon[0][j]); - min_epsilon = std::fabs(epsilon[0][j]); - for (uint32_t i = 1; i < N + 1; i++) { - if (std::fabs(epsilon[i][j]) > max_epsilon) - max_epsilon = std::fabs(epsilon[i][j]); - if (std::fabs(epsilon[i][j]) < min_epsilon) - min_epsilon = std::fabs(epsilon[i][j]); - } - if (j == details::max_iterations() || max_epsilon - min_epsilon < threshold * min_epsilon) { - details::Pwl value; - result.resize(0); - epsilon_final = (max_epsilon + min_epsilon) / 4.0; // Andrzej's modification - for (uint32_t i = 0; i < N; i++) { - value.alpha = alpha[i][j]; - value.beta = sgn * activation_function.first_derivative(t[i][j]) * (value.alpha - t[i][j]) + - sgn * activation_function.get_value(t[i][j]) - epsilon_final; - value.m = sgn * activation_function.first_derivative(t[i][j]); - value.b = value.beta - value.m * value.alpha; - result.push_back(value); - } - - result.emplace_back(0, - 0, - alpha[N][j], - sgn * activation_function.first_derivative(t[N - 1][j]) * (alpha[N][j] - t[N - 1][j]) + - sgn * activation_function.get_value(t[N - 1][j]) - epsilon_final); - if (j == details::max_iterations()) { - throw std::runtime_error("Failed to converge in pivot_search!"); - } - return (epsilon_final); - } - - if (j > 0) { - if (max_epsilon > max_epsilon_prev) { - j = j - 1; - Delta = Delta / 2; - same_epsilon = false; - } else if (AreFpEq(max_epsilon, max_epsilon_prev)) { - if (!same_epsilon) { - same_epsilon = true; - } else { - j = j - 1; - Delta = Delta / 2; - same_epsilon = false; - } - } - } - - // Figure 4: Box #4 - for (uint32_t i = 0; i < N; i++) { - d[i].resize(j + 1); - d[i][j] = Delta * (epsilon[i + 1][j] - epsilon[i][j]) / - ((epsilon[i + 1][j] / (alpha[i + 1][j] - t[i][j])) + (epsilon[i][j] / (t[i][j] - alpha[i][j]))); - } - - // Figure 4: Box #5 - for (uint32_t i = 0; i < N; i++) { - t[i].resize(j + 2); - t[i][j + 1] = t[i][j] + d[i][j]; - } - t[N].resize(j + 2); - - j = j + 1; - } -} - -template -double calculate_error_pct(const details::Function& activation_function, - const std::vector& segments, - double lower_bound, - double upper_bound, - const double offset, - bool negative, - int samples = 500) { - double delta = (upper_bound - lower_bound) / (samples + 1); - if (delta < 0) { - return 0.0; - } - - double min_val = activation_function.get_value(lower_bound); - double max_val = activation_function.get_value(lower_bound); - for (int i = 0; i < samples; i++) { - double arg = lower_bound + i * delta; - double val = activation_function.get_value(arg); - if (val > max_val) - max_val = val; - if (val < min_val) - min_val = val; - } - - double max_err = (100.0 * std::fabs(offset) / (max_val - min_val)); - return max_err; -} - -template -bool is_negative(const details::Function& activation_function, double upper_bound) { - if (std::is_same::value || std::is_same::value || - std::is_same::value) { - return upper_bound == 0; - } - - if (std::is_same::value) { - return true; - } - - return false; -} - -template <> -bool is_negative(const details::Function& activation_function, - double upper_bound) { - return std::fmod(activation_function.m_exponent, 1.0) == 0; -} - -template -std::vector pwl_search(const details::Function& activation_function, - double lower_bound, - double upper_bound, - double allowed_err_pct, - double& err_pct) { - std::vector pwl; - if (lower_bound > upper_bound) { - return pwl; - } - - if (split_search(lower_bound, upper_bound)) { - auto negative_pwl = [](std::vector& data) { - for (auto& e : data) { - e.m = -e.m; - e.b = -e.b; - e.beta = -e.beta; - } - }; - - double err_pct1 = 0.0; - double err_pct2 = 0.0; - double break_bound = get_break_bound(); - pwl = pwl_search(activation_function, lower_bound, break_bound, allowed_err_pct, err_pct1); - negative_pwl(pwl); - std::vector pwl2 = - pwl_search(activation_function, break_bound, upper_bound, allowed_err_pct, err_pct2); - if (std::is_same::value || std::is_same::value) { - negative_pwl(pwl2); - } - - // merge - if (!pwl.empty()) - pwl.pop_back(); // remove final alpha from first half - pwl.insert(pwl.end(), pwl2.begin(), pwl2.end()); // concatenate the two halves - err_pct = (err_pct1 + err_pct2) / 2; // this is not quite correct but should give an indication - } else { - int segments_number = 1; - bool negative = is_negative(activation_function, upper_bound); - auto err = pivot_search(activation_function, - pwl, - segments_number, - lower_bound, - upper_bound, - negative, - allowed_err_pct); - err_pct = calculate_error_pct(activation_function, pwl, lower_bound, upper_bound, err, negative); - while (segments_number < details::max_segments_number() && allowed_err_pct < err_pct) { - segments_number++; - err = pivot_search(activation_function, - pwl, - segments_number, - lower_bound, - upper_bound, - negative, - allowed_err_pct); - err_pct = calculate_error_pct(activation_function, pwl, lower_bound, upper_bound, err, negative); - } - - if (segments_number >= details::max_segments_number()) { - throw std::runtime_error("Failed to converge in pwl_search!"); - } - } - - return pwl; -} - -template -std::pair get_bounds(const std::shared_ptr& fake_quantize) { - auto fq = std::dynamic_pointer_cast(fake_quantize); - auto lower_bound = details::lower_bound(); - auto upper_bound = details::upper_bound(); - if (fq) { - auto input_low = std::dynamic_pointer_cast(fq->get_input_node_shared_ptr(1)); - auto input_high = std::dynamic_pointer_cast(fq->get_input_node_shared_ptr(2)); - if (!graph_utils::get_constant_value(input_low, lower_bound) || - !graph_utils::get_constant_value(input_high, upper_bound)) { - throw std::runtime_error("The unsupported type of element."); - } - - auto abs_max = std::max(std::fabs(std::min(lower_bound, upper_bound) * 1.25), - std::fabs(std::max(lower_bound, upper_bound) * 1.25)); - lower_bound = abs_max < std::fabs(details::lower_bound()) ? -abs_max : details::lower_bound(); - upper_bound = abs_max < std::fabs(details::upper_bound()) ? abs_max : details::upper_bound(); - } - - return std::make_pair(lower_bound, upper_bound); -} - -template <> -std::pair get_bounds(const std::shared_ptr& fake_quantize) { - return std::make_pair(details::lower_bound(), details::upper_bound()); -} - -template -bool pwl_search(const std::shared_ptr& node, - const std::shared_ptr& fake_quantize, - double allowed_err_pct, - double& err_pct, - std::vector& segments) { - double lower_bound = 0; - double upper_bound = 0; - std::tie(lower_bound, upper_bound) = get_bounds(fake_quantize); - segments = pwl_search(details::Function(), lower_bound, upper_bound, allowed_err_pct, err_pct); - if (segments.size() <= 2) { - return false; - } - - if (segments.front().beta < details::Function::min_value()) { - segments.front().alpha += (details::Function::min_value() - segments.front().beta) / segments.front().m; - } - - segments.insert(segments.begin(), - {0, - std::max(segments.front().beta, details::Function::min_value()), - -std::numeric_limits::infinity()}); - - if (segments.back().beta > details::Function::max_value()) { - segments.back().alpha += - (details::Function::max_value() - segments.back().beta) / segments.at(segments.size() - 2).m; - } - - segments.back().b = std::min(segments.back().beta, details::Function::max_value()); - segments.push_back({0, 0, std::numeric_limits::infinity()}); - return true; -} - -static bool pwl_search_power(const std::shared_ptr& node, - double exponent, - double scale, - double offset, - const std::shared_ptr& fake_quantize, - double allowed_err_pct, - double& err_pct, - std::vector& segments) { - auto fq = std::dynamic_pointer_cast(fake_quantize); - auto lower_bound = details::lower_bound(exponent); - auto upper_bound = details::upper_bound(); - if (fq) { - auto output_low = std::dynamic_pointer_cast(fq->get_input_node_shared_ptr(1)); - auto output_high = std::dynamic_pointer_cast(fq->get_input_node_shared_ptr(2)); - if (!graph_utils::get_constant_value(output_low, lower_bound) || - !graph_utils::get_constant_value(output_high, upper_bound)) { - throw std::runtime_error("The unsupported type of element."); - } - } - - if (AreFpEq(exponent, 1.0)) { - // An affine primitive will be used in this case. - return false; - } else if (AreFpEq(exponent, 0.0)) { - segments.emplace_back(0, 1, -std::numeric_limits::infinity()); - segments.emplace_back(0, 1, std::numeric_limits::infinity()); - segments.emplace_back(0, 0, std::numeric_limits::infinity()); - return true; - } - - segments = pwl_search(details::Function(exponent, scale, offset), - lower_bound, - upper_bound, - allowed_err_pct > 0.015 ? 0.015 : allowed_err_pct, - err_pct); - if (segments.size() <= 2) { - return false; - } - - segments.insert( - segments.begin(), - {0, segments.front().beta, AreFpEq(fmod(exponent, 1.0), 0.0) ? -std::numeric_limits::infinity() : 0}); - segments.back().b = segments.back().beta; - segments.push_back({0, 0, std::numeric_limits::infinity()}); - return true; -} - -template <> -bool pwl_search(const std::shared_ptr& node, - const std::shared_ptr& fake_quantize, - double allowed_err_pct, - double& err_pct, - std::vector& segments) { - auto constant = std::dynamic_pointer_cast(node->get_input_node_shared_ptr(1)); - double exponent = 0; - if (!graph_utils::get_constant_value(constant, exponent)) { - throw std::runtime_error("The unsupported type of element."); - } - - return pwl_search_power(node, exponent, 1, 0, fake_quantize, allowed_err_pct, err_pct, segments); -} - -template <> -bool pwl_search(const std::shared_ptr& node, - const std::shared_ptr& fake_quantize, - double allowed_err_pct, - double& err_pct, - std::vector& segments) { - auto power = std::dynamic_pointer_cast(node); - return pwl_search_power(node, - power->power, - power->scale, - power->shift, - fake_quantize, - allowed_err_pct, - err_pct, - segments); -} - -template -bool transform_to_pwl(const std::shared_ptr& fake_quantize, - const std::shared_ptr& node, - double allowed_err_pct) { - double err_pct = 0; - std::vector segments; - if (!pwl_search(node, fake_quantize, allowed_err_pct, err_pct, segments)) { - return false; - } - - std::vector m(segments.size() - 1); - std::vector b(segments.size() - 1); - std::vector alpha(segments.size()); - for (size_t i = 0; i < segments.size() - 1; i++) { - m[i] = segments[i].m; - b[i] = segments[i].b; - alpha[i] = segments[i].alpha; - } - alpha[segments.size() - 1] = segments[segments.size() - 1].alpha; - - auto m_constant = - std::make_shared(ngraph::element::Type_t::f64, ngraph::Shape{segments.size() - 1}, m); - m_constant->set_friendly_name(node->get_friendly_name() + "/pwl_slope"); - auto b_constant = - std::make_shared(ngraph::element::Type_t::f64, ngraph::Shape{segments.size() - 1}, b); - b_constant->set_friendly_name(node->get_friendly_name() + "/pwl_offset"); - auto alpha_constant = - std::make_shared(ngraph::element::Type_t::f64, ngraph::Shape{segments.size()}, alpha); - alpha_constant->set_friendly_name(node->get_friendly_name() + "/pwl_alpha"); - auto pwl = std::make_shared(fake_quantize ? fake_quantize : node->input_value(0), - m_constant, - b_constant, - alpha_constant); - pwl->set_base_node(node); - pwl->set_friendly_name(node->get_friendly_name()); - ngraph::copy_runtime_info(node, {pwl, m_constant, b_constant, alpha_constant}); - replace_node(node, pwl); - return true; -} - -static bool transform_to_pwl(std::tuple<>&&, - const std::shared_ptr&, - const std::shared_ptr&, - double) { - return false; -} - -template -static bool transform_to_pwl(std::tuple&&, - const std::shared_ptr& fake_quantize, - const std::shared_ptr& node, - double allowed_err_pct) { - auto op = std::dynamic_pointer_cast(node); - if (op) { - return transform_to_pwl(fake_quantize, op, allowed_err_pct); - } - return transform_to_pwl(std::tuple(), fake_quantize, node, allowed_err_pct); -} - -static std::shared_ptr create_matcher(ov::graph_rewrite_callback& handler_callback, - double allowed_err_pct, - const std::string& matcher_name, - bool fq) { - auto activation_input = ngraph::pattern::any_input(); - auto fake_quantize = ngraph::pattern::wrap_type({ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}); - if (fq) - activation_input = fake_quantize; - auto sigmoid = ngraph::pattern::wrap_type({activation_input}); - auto tanh = ngraph::pattern::wrap_type({activation_input}); - auto exp = ngraph::pattern::wrap_type({activation_input}); - auto power = ngraph::pattern::wrap_type( - {activation_input, ngraph::pattern::any_input(), ngraph::pattern::any_input()}); - auto powerIE = ngraph::pattern::wrap_type({activation_input}); - auto log = ngraph::pattern::wrap_type({activation_input}); - auto softsign = ngraph::pattern::wrap_type({activation_input}); - auto activation_function = - std::make_shared(ov::OutputVector{sigmoid, tanh, exp, power, powerIE, log, softsign}); - - auto callback = [=](ngraph::pattern::Matcher& m) -> bool { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto iter = pattern_to_output.find(sigmoid); - if (iter == pattern_to_output.end() && (iter = pattern_to_output.find(tanh)) == pattern_to_output.end() && - (iter = pattern_to_output.find(exp)) == pattern_to_output.end() && - (iter = pattern_to_output.find(power)) == pattern_to_output.end() && - (iter = pattern_to_output.find(powerIE)) == pattern_to_output.end() && - (iter = pattern_to_output.find(log)) == pattern_to_output.end() && - (iter = pattern_to_output.find(softsign)) == pattern_to_output.end()) { - return false; - } - auto fake_quantize_iter = pattern_to_output.find(fake_quantize); - return transform_to_pwl(std::tuple(), - fake_quantize_iter != pattern_to_output.end() - ? fake_quantize_iter->second.get_node_shared_ptr() - : std::shared_ptr(), - iter->second.get_node_shared_ptr(), - allowed_err_pct); - }; - - handler_callback = callback; - return std::make_shared(activation_function, matcher_name); -} - -PWLApproximation::PWLApproximation(double allowed_err_pct) { - MATCHER_SCOPE(PWLApproximation); - ov::graph_rewrite_callback callback; - auto m = create_matcher(callback, allowed_err_pct, matcher_name, false); - register_matcher(m, callback); -} - -PWLApproximationWithFq::PWLApproximationWithFq(double allowed_err_pct) { - MATCHER_SCOPE(PWLApproximationWithFq); - ov::graph_rewrite_callback callback; - auto m = create_matcher(callback, allowed_err_pct, matcher_name, true); - register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/pwl_approximation.hpp b/src/plugins/intel_gna/src/transformations/pwl_approximation.hpp deleted file mode 100644 index b8fb9b5f58f..00000000000 --- a/src/plugins/intel_gna/src/transformations/pwl_approximation.hpp +++ /dev/null @@ -1,339 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common/numerical_utils.hpp" -#include "ngraph/pattern/matcher.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { -/** - * @ingroup ie_transformation_common_api - * @brief PWLApproximation transformation replaces suitable activation function with pwl - */ -class PWLApproximation : public ov::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - PWLApproximation(double max_error_percent); -}; - -class PWLApproximationWithFq : public ov::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - PWLApproximationWithFq(double max_error_percent); -}; - -namespace details { -struct Pwl { - Pwl() = default; - Pwl(double im, double ib, double ialpha, double ibeta = 0) : m(im), b(ib), alpha(ialpha), beta(ibeta) {} - double m; - double b; - double alpha; - double beta; -}; // struct Pwl - -template -struct Function; - -template <> -struct Function { - static const char* name() { - return "sigmoid"; - } - - double get_value(double x) const { - return 0.5 * (1.0 + tanh(x / 2.0)); - } - - double first_derivative(double x) const { - return get_value(x) * (1.0 - get_value(x)); - } - - static double lower_bound() { - return -10; - } - - static double upper_bound() { - return 10; - } - - static double min_value() { - return 0; - } - - static double max_value() { - return 1; - } -}; // struct Function - -template <> -struct Function { - static const char* name() { - return "tanh"; - } - - double get_value(double x) const { - return tanh(x); - } - - double first_derivative(double x) const { - return 1.0 - tanh(x) * tanh(x); - } - - static double lower_bound() { - return -5; - } - - static double upper_bound() { - return 5; - } - - static double min_value() { - return -1; - } - - static double max_value() { - return 1; - } -}; // struct Function - -template <> -struct Function { - static const char* name() { - return "exp"; - } - - double get_value(double x) const { - return exp(x); - } - - double first_derivative(double x) const { - return exp(x); - } - - static double lower_bound() { - return -std::log2(INT16_MAX); - } - - static double upper_bound() { - return std::log10(INT16_MAX); - } - - static double min_value() { - return 0; - } - - static double max_value() { - return INT16_MAX; - } -}; // struct Function - -template <> -struct Function { - static const char* name() { - return "log"; - } - - double get_value(double x) const { - return std::log(x); - } - - double first_derivative(double x) const { - return 1.0 / x; - } - - static double lower_bound() { - return 0.001; - } - - static double upper_bound() { - return 2981; - } - - static double min_value() { - return -11; - } - - static double max_value() { - return INT16_MAX; - } -}; // struct Function - -template <> -struct Function { - static const char* name() { - return "softsign"; - } - - double get_value(double x) const { - return x / (1.0 + std::abs(x)); - } - - double first_derivative(double x) const { - return 1.0 / ((1.0 + std::abs(x)) * (1.0 + std::abs(x))); - } - - static double lower_bound() { - return -10; - } - - static double upper_bound() { - return 10; - } - - static double min_value() { - return -1; - } - - static double max_value() { - return 1; - } -}; // struct Function - -template <> -struct Function { - static const char* name() { - return "power"; - } -}; // struct Function - -template <> -struct Function { - Function(double exponent, double scale, double shift) : m_exponent(exponent), m_scale(scale), m_shift(shift) {} - - static const char* name() { - return "power"; - } - - double get_value(double x) const { - return pow(x * m_scale + m_shift, m_exponent); - } - - double first_derivative(double x) const { - return m_exponent * m_scale * pow(m_shift + x * m_scale, m_exponent - 1); - } - - static double lower_bound(double exponent) { - return common::AreFpEq(fmod(exponent, 1.0), 0.0) ? -16.0 : 0.0; - } - - static double upper_bound() { - return 16.0; - } - - const double m_exponent; - const double m_scale; - const double m_shift; -}; // struct Function - -template -double lower_bound(std::true_type) { - return Function::lower_bound(); -} - -template -double lower_bound(std::false_type) { - throw std::runtime_error("Not supported"); -} - -template -double lower_bound() { - return lower_bound(std::integral_constant < bool, - std::is_same::value || std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value > ()); -} - -template -double lower_bound(double exponent, std::true_type) { - return Function::lower_bound(exponent); -} - -template -double lower_bound(double exponent, std::false_type) { - throw std::runtime_error("Not supported"); -} - -template -double lower_bound(double exponent) { - return lower_bound( - exponent, - std::integral_constant < bool, - std::is_same::value || std::is_same::value > ()); -} - -template -double upper_bound(std::true_type) { - return Function::upper_bound(); -} - -template -double upper_bound(std::false_type) { - throw std::runtime_error("Not supported"); -} - -template -double upper_bound() { - return upper_bound( - std::integral_constant < bool, - std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value || - std::is_same::value > ()); -} - -template -const char* name(std::true_type) { - return Function::name(); -} - -template -const char* name(std::false_type) { - throw std::runtime_error("Not supported"); -} - -template -const char* name() { - return name(std::integral_constant < bool, - std::is_same::value || std::is_same::value || - std::is_same::value || - std::is_same::value || std::is_same::value || - std::is_same::value || - std::is_same::value > ()); -} - -template -int max_segments_number() { - return 128; -} - -template -inline int max_iterations() { - return 2000; -} - -template <> -inline int max_iterations() { - return 5000; -} - -} // namespace details -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/remove_converts.cpp b/src/plugins/intel_gna/src/transformations/remove_converts.cpp deleted file mode 100644 index fb2e47bc261..00000000000 --- a/src/plugins/intel_gna/src/transformations/remove_converts.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/remove_converts.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace ov::intel_gna::pass; - -RemoveInputConvert::RemoveInputConvert() { - MATCHER_SCOPE(RemoveInputConvert); - - const auto input = ngraph::pattern::wrap_type( - ngraph::pattern::type_matches_any(kSupportedInputTypesFrom)); - const auto convert = - ngraph::pattern::wrap_type({input}, - ngraph::pattern::type_matches_any(kSupportedInputTypesTo)); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - - auto convert_node = pattern_map.at(convert).get_node_shared_ptr(); - auto input_node = pattern_map.at(input).get_node_shared_ptr(); - - // check the supported combinations - auto from_type = input_node->get_element_type(); - auto to_type = convert_node->get_element_type(); - if (std::count(kSupportedInputConverts.begin(), - kSupportedInputConverts.end(), - std::make_pair(from_type, to_type)) == 0) - return false; - - // replace input precision with convert's one - if (auto param = ov::as_type_ptr(input_node)) { - param->set_element_type(to_type); - } - - ngraph::replace_output_update_name(convert_node->output(0), convert_node->input_value(0)); - return true; - }; - - auto m = std::make_shared(convert, matcher_name); - this->register_matcher(m, callback); -} - -RemoveOutputConvert::RemoveOutputConvert() { - MATCHER_SCOPE(RemoveOutputConvert); - - auto output = ngraph::pattern::any_input(ngraph::pattern::type_matches_any(kSupportedOutputTypesFrom)); - const auto convert = - ngraph::pattern::wrap_type({output}, - ngraph::pattern::type_matches_any(kSupportedOutputTypesTo)); - const auto result = - ngraph::pattern::wrap_type({convert}, - ngraph::pattern::type_matches_any(kSupportedOutputTypesTo)); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - - auto output_node = pattern_map.at(output).get_node_shared_ptr(); - auto convert_node = pattern_map.at(convert).get_node_shared_ptr(); - - // check the supported combinations - auto from_type = output_node->get_element_type(); - auto to_type = convert_node->get_element_type(); - if (std::count(kSupportedOutputConverts.begin(), - kSupportedOutputConverts.end(), - std::make_pair(from_type, to_type)) == 0) { - return false; - } - - // the result precision will be changed automatically - ngraph::replace_output_update_name(convert_node->output(0), convert_node->input_value(0)); - return true; - }; - - auto m = std::make_shared(result, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/remove_converts.hpp b/src/plugins/intel_gna/src/transformations/remove_converts.hpp deleted file mode 100644 index cf222bfd8a3..00000000000 --- a/src/plugins/intel_gna/src/transformations/remove_converts.hpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief remove convert layers after inputs and changing it's precision - * to support preprocessing conversions from user's precision to network presicion - * - * Searches for next pattern - * Any input layer - * | - * Convert - * | - * Any layer - * - * And transforms to - * Any input layer - * | - * Any layer - */ -const std::vector kSupportedInputTypesFrom = {ov::element::u8, ov::element::i16, ov::element::f32}; - -const std::vector kSupportedInputTypesTo = {ov::element::u8, - ov::element::i8, - ov::element::i16, - ov::element::i32, - ov::element::f32}; - -const std::vector> kSupportedInputConverts{ - // FROM -> TO - {ov::element::u8, ov::element::u8}, - {ov::element::u8, ov::element::i8}, - {ov::element::u8, ov::element::i16}, - {ov::element::i16, ov::element::i8}, - {ov::element::i16, ov::element::i16}, - {ov::element::f32, ov::element::i8}, - {ov::element::f32, ov::element::i16}, - {ov::element::f32, ov::element::i32}, - {ov::element::f32, ov::element::f32}}; - -class RemoveInputConvert : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("RemoveInputConvert", "0"); - RemoveInputConvert(); -}; - -/** - * @brief remove convert layers after before outputs changing it's precision - * to support postprocessing conversions from network to user's precision - * - * Searches for next pattern - * Any layer - * | - * Convert - * | - * Any output layer - * - * And transforms to - * Any layer - * | - * Any output layer - */ - -const std::vector kSupportedOutputTypesFrom = {ov::element::f32}; - -const std::vector kSupportedOutputTypesTo = {ov::element::i32, ov::element::f32}; - -const std::vector> kSupportedOutputConverts{ - // FROM -> TO - {ov::element::f32, ov::element::f32}, - {ov::element::f32, ov::element::i32}}; - -class RemoveOutputConvert : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("RemoveOutputConvert", "0"); - RemoveOutputConvert(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/remove_extra_reshapes.cpp b/src/plugins/intel_gna/src/transformations/remove_extra_reshapes.cpp deleted file mode 100644 index 6046b25753e..00000000000 --- a/src/plugins/intel_gna/src/transformations/remove_extra_reshapes.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/remove_extra_reshapes.hpp" - -#include -#include -#include -#include - -using namespace ov::intel_gna::pass; - -RemoveExtraReshapes::RemoveExtraReshapes() { - MATCHER_SCOPE(RemoveExtraReshapes); - const auto reshape = - ngraph::pattern::wrap_type([](const ngraph::Output& value) { - return (value.get_node_shared_ptr()->get_input_shape(0) == - value.get_node_shared_ptr()->get_output_shape(0)); - }); - const auto pooling = ngraph::pattern::wrap_type({reshape}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - const auto reshape_node = pattern_map.at(reshape).get_node_shared_ptr(); - ngraph::replace_output_update_name(reshape_node->output(0), reshape_node->input_value(0)); - return true; - }; - - auto m = std::make_shared(pooling, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/remove_extra_reshapes.hpp b/src/plugins/intel_gna/src/transformations/remove_extra_reshapes.hpp deleted file mode 100644 index 0f3f5e3146f..00000000000 --- a/src/plugins/intel_gna/src/transformations/remove_extra_reshapes.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Removes reshapes before MaxPool which do nothing. Such reshapes can be a result of conversion from IR10 to - * IR7. - */ -class RemoveExtraReshapes : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("RemoveExtraReshapes", "0"); - RemoveExtraReshapes(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/remove_in_out_processing.cpp b/src/plugins/intel_gna/src/transformations/remove_in_out_processing.cpp deleted file mode 100644 index a5d716c38b1..00000000000 --- a/src/plugins/intel_gna/src/transformations/remove_in_out_processing.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/remove_in_out_processing.hpp" - -#include "backend/gna_limitations.hpp" -#include "common/graph_utils.hpp" -#include "openvino/cc/pass/itt.hpp" -#include "openvino/opsets/opset1.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/opsets/opset7.hpp" -#include "openvino/opsets/opset8.hpp" -#include "openvino/pass/manager.hpp" -#include "openvino/pass/pass.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "transformations/utils/transformation_helper.hpp" - -using namespace ov::opset12; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::limitations; - -namespace { - -inline bool is_preprocessing_layer_not_supported(std::shared_ptr& layer) { - // Gather layer is not supported by GNA and has to be executed on CPU - if (std::dynamic_pointer_cast(layer) || std::dynamic_pointer_cast(layer) || - std::dynamic_pointer_cast(layer)) { - return true; - } - - // Verify that transpose layer cannot be executed on GNA - if (std::dynamic_pointer_cast(layer)) { - return !Limitations::is_transpose_supported(layer); - } - - return false; -} -/* - Support only one input node as input 0 - */ -inline std::shared_ptr copy_single_input_node(std::shared_ptr node) { - const ov::element::Type& input_type = node->get_input_element_type(0); - const ov::Shape& input_shape = node->get_input_shape(0); - - auto param = std::make_shared(input_type, input_shape); - ov::OutputVector input_nodes = node->input_values(); - input_nodes[0] = param; - auto node_copy = node->clone_with_new_inputs(input_nodes); - auto result = std::make_shared(node_copy); - std::shared_ptr model = - std::make_shared(ov::ResultVector{result}, ov::ParameterVector{param}); - - return model; -} - -inline bool is_skip_operation(const std::shared_ptr& node) { - return std::dynamic_pointer_cast(node) != nullptr; -} - -} // namespace - -bool RemoveInputsProcessing::run_on_model(const std::shared_ptr& model) { - RUN_ON_MODEL_SCOPE(RemoveInputsProcessing); - bool result = false; - - for (const auto& param_node : model->inputs()) { - for (auto& param_target : param_node.get_target_inputs()) { - auto target_node = graph_utils::get_next_node_skipping_certain(param_target.get_node()->shared_from_this(), - is_skip_operation); - // Parameter -> Transpose, Parameter -> Gather - if (is_preprocessing_layer_not_supported(target_node)) { - if (m_input_subgraphs) { - m_input_subgraphs->emplace(param_node.get_node_shared_ptr()->get_friendly_name(), - copy_single_input_node(target_node)); - } - pass::helper::remove_single_input_node(target_node); - result = true; - } - } - } - return result; -} - -bool RemoveOutputsProcessing::run_on_model(const std::shared_ptr& model) { - RUN_ON_MODEL_SCOPE(RemoveOutputsProcessing); - bool result = false; - for (std::shared_ptr r_node : model->get_results()) { - for (auto& r_input : r_node->input_values()) { - auto r_input_node = - graph_utils::get_prev_node_skipping_certain(r_input.get_node_shared_ptr(), is_skip_operation); - // Transpose -> Result, Gather -> Result - if (is_preprocessing_layer_not_supported(r_input_node)) { - if (m_output_subgraphs) { - m_output_subgraphs->emplace(r_input.get_node_shared_ptr()->get_friendly_name(), - copy_single_input_node(r_input_node)); - } - pass::helper::remove_single_input_node(r_input_node); - result = true; - } - } - } - return result; -} \ No newline at end of file diff --git a/src/plugins/intel_gna/src/transformations/remove_in_out_processing.hpp b/src/plugins/intel_gna/src/transformations/remove_in_out_processing.hpp deleted file mode 100644 index b6ed9c0a65d..00000000000 --- a/src/plugins/intel_gna/src/transformations/remove_in_out_processing.hpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "gna_data_types.hpp" -#include "openvino/pass/graph_rewrite.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Remove Transpose/Gather layers connected to Inputs and create pre-processing model - * to support input pre-processing on CPU. - * Inserts Reshape layer instead of Transpose/Gater layer to avoid changing of the shapes. - * @param output_subgraphs Map where pre-processing model for each input will be saved - * - * Searches for the following pattern - * Any input layer - * | - * Transpose/Gather - * | - * Any layer - * - * and transforms it to - * Any input layer - * | - * Reshape - * | - * Any layer - */ -class RemoveInputsProcessing : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("RemoveInputsProcessing", "0"); - RemoveInputsProcessing(ov::intel_gna::PrePostProcessModels* input_subgraphs = nullptr) - : m_input_subgraphs(input_subgraphs) {} - bool run_on_model(const std::shared_ptr& model) override; - -private: - ov::intel_gna::PrePostProcessModels* m_input_subgraphs; -}; - -/** - * @brief Remove Transpose/Gather layers connected to Outputs and create post-processing model - * to support output pre-processing on CPU. - * Inserts Reshape layer instead of Transpose/Gather layer to avoid changing of the shapes. - * @param output_subgraphs Map where post-processing model for each output will be saved - * - * Searches for the following pattern - * Any input layer - * | - * Transpose/Gather - * | - * Result - * - * and transforms it to - * Any input layer - * | - * Reshape - * | - * Result - */ -class RemoveOutputsProcessing : public ov::pass::ModelPass { -public: - OPENVINO_RTTI("RemoveOutputsProcessing", "0"); - RemoveOutputsProcessing(ov::intel_gna::PrePostProcessModels* output_subgraphs = nullptr) - : m_output_subgraphs(output_subgraphs) {} - bool run_on_model(const std::shared_ptr& model) override; - -private: - ov::intel_gna::PrePostProcessModels* m_output_subgraphs; -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/remove_single_input_concat.cpp b/src/plugins/intel_gna/src/transformations/remove_single_input_concat.cpp deleted file mode 100644 index a732404ec60..00000000000 --- a/src/plugins/intel_gna/src/transformations/remove_single_input_concat.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/remove_single_input_concat.hpp" - -#include -#include -#include -#include -#include -#include - -using NodeInput = ngraph::Input; -using NodeOutput = ngraph::Output; - -using namespace ov::intel_gna::pass; - -RemoveSingleInputConcat::RemoveSingleInputConcat() { - MATCHER_SCOPE(RemoveSingleInputConcat); - - auto is_required_node = [](const ngraph::Output& value) { - return value.get_node_shared_ptr()->get_input_size() == 1; - }; - - auto concat_operation = ngraph::pattern::wrap_type(is_required_node); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto concat_operation_it = pattern_map.find(concat_operation); - if (concat_operation_it == pattern_map.end()) - return false; - auto concat_operation_node = concat_operation_it->second.get_node_shared_ptr(); - - NodeOutput prev_node_output = concat_operation_node->get_input_source_output(0); - - for (NodeInput child_input : concat_operation_node->get_output_target_inputs(0)) - child_input.replace_source_output(prev_node_output); - - return true; - }; - - auto m = std::make_shared(concat_operation, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/remove_single_input_concat.hpp b/src/plugins/intel_gna/src/transformations/remove_single_input_concat.hpp deleted file mode 100644 index d3183959062..00000000000 --- a/src/plugins/intel_gna/src/transformations/remove_single_input_concat.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief remove concat layers with single input - * - * Searches for next pattern - * Any input layer - * | - * Concat - * | - * Any output layer - * - * And transforms to - * Any input layer - * | - * Any output layer - */ -class RemoveSingleInputConcat : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("RemoveSingleInputConcat", "0"); - RemoveSingleInputConcat(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/reorder_activation_and_pooling.cpp b/src/plugins/intel_gna/src/transformations/reorder_activation_and_pooling.cpp deleted file mode 100644 index 73b0df51ae1..00000000000 --- a/src/plugins/intel_gna/src/transformations/reorder_activation_and_pooling.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/reorder_activation_and_pooling.hpp" - -#include -#include -#include -#include -#include - -#include "log/debug.hpp" -#include "log/log.hpp" - -using namespace ov::intel_gna; -using namespace ov::intel_gna::pass; - -ReorderActivationAndPooling::ReorderActivationAndPooling() { - MATCHER_SCOPE(ReorderActivationAndPooling); - auto conv = ngraph::pattern::wrap_type( - {ngraph::pattern::any_input(), ngraph::pattern::any_input()}); - auto add = ngraph::pattern::wrap_type({conv, ngraph::pattern::any_input()}); - auto il = ngraph::pattern::wrap_type(); - auto ih = ngraph::pattern::wrap_type(); - auto ol = ngraph::pattern::wrap_type(); - auto oh = ngraph::pattern::wrap_type(); - auto fq1 = ngraph::pattern::wrap_type({conv, il, ih, ol, oh}); - auto fq2 = ngraph::pattern::wrap_type({add, il, ih, ol, oh}); - auto act1 = ngraph::pattern::wrap_type({conv}); - auto act2 = ngraph::pattern::wrap_type({add}); - auto act = std::make_shared(ngraph::OutputVector{fq1, fq2, act1, act2}); - auto pool = ngraph::pattern::wrap_type({act}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - auto& pattern_map = m.get_pattern_value_map(); - auto pool_node = pattern_map.at(pool).get_node_shared_ptr(); - auto pool = std::dynamic_pointer_cast(pool_node); - IE_ASSERT(pool != nullptr); - auto kernel_shape = pool->get_kernel(); - auto act = pool_node->input_value(0).get_node_shared_ptr(); - IE_ASSERT(act != nullptr); - - log::debug() << "Reorder " << pool_node->get_friendly_name() << " and " << act->get_friendly_name() << "\n"; - - auto node_before_act = act->input_value(0).get_node_shared_ptr(); - IE_ASSERT(node_before_act != nullptr); - - auto consumers = node_before_act->output(0).get_target_inputs(); - auto new_pool = std::make_shared(node_before_act, - pool->get_strides(), - pool->get_pads_begin(), - pool->get_pads_end(), - kernel_shape, - pool->get_rounding_type(), - pool->get_auto_pad()); - for (auto& input : consumers) { - input.replace_source_output(new_pool); - } - - ngraph::replace_output_update_name(pool_node->output(0), pool_node->input_value(0)); - ngraph::copy_runtime_info(pool_node, new_pool); - return true; - }; - - auto m = std::make_shared(pool, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/reorder_activation_and_pooling.hpp b/src/plugins/intel_gna/src/transformations/reorder_activation_and_pooling.hpp deleted file mode 100644 index f8b7cf11011..00000000000 --- a/src/plugins/intel_gna/src/transformations/reorder_activation_and_pooling.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { -/** - * @brief Pooling can be reordered with activation, on GNA there is a strategy to have conv->maxpool->activation - * it means maxpool receives 4 bytes, and produces 4 bytes - */ -class ReorderActivationAndPooling : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ReorderActivationAndPooling", "0"); - ReorderActivationAndPooling(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/replace_gna_nhwc_layers.cpp b/src/plugins/intel_gna/src/transformations/replace_gna_nhwc_layers.cpp deleted file mode 100644 index 7f8fac2c58d..00000000000 --- a/src/plugins/intel_gna/src/transformations/replace_gna_nhwc_layers.cpp +++ /dev/null @@ -1,208 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/replace_gna_nhwc_layers.hpp" - -#include - -#include "common/graph_utils.hpp" -#include "openvino/cc/ngraph/itt.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/manager.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "ops/gna_convolution.hpp" -#include "ops/gna_max_pool.hpp" -#include "transformations/utils/transformation_helper.hpp" -#include "transformations/utils/utils.hpp" - -using namespace ov; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::pass::helper; - -NGRAPH_RTTI_DEFINITION(ov::intel_gna::pass::ReplaceGnaNHWCLayers, "ReplaceGnaNHWCLayers"); -NGRAPH_RTTI_DEFINITION(ov::intel_gna::pass::SubstituteGNAConvolution, "SubstituteGNAConvolution"); -NGRAPH_RTTI_DEFINITION(ov::intel_gna::pass::SubstituteGNAMaxPool, "SubstituteGNAMaxPool"); - -namespace { -ov::Shape make_transpose_order_nchw2nhwc(size_t shape_size); -ov::Shape make_transpose_order_nhwc2nchw(size_t shape_size); - -/* transpose orders - before convolution layout conversion NCHW -> NHWC - 3D: NCX {0, 1, 2} -> NXC {0, 2, 1} - 4D: NCHW {0, 1, 2, 3} -> NHWC {0, 2, 3, 1} - after convolution layout conversion NHWC -> NCHW - 3D: NXC {0, 1, 2} -> NCX {0, 2, 1} - 4D: NHWC {0, 1, 2, 3} -> NCHW {0, 3, 1, 2} - so just - 1) temp = A[N - 1] - 2) move A[j] -> A[j + 1] for 1 <= j <= N - 2 - 3) A[1] = temp -*/ - -ov::Shape make_transpose_order_nchw2nhwc(size_t shape_size) { - ov::Shape shape(shape_size); - std::iota(shape.begin(), shape.end(), 0); - - for (size_t i = 1; i < shape.size() - 1; ++i) - shape[i] = shape[i + 1]; - - *(shape.end() - 1) = 1; - - return shape; -} - -ov::Shape make_transpose_order_nhwc2nchw(size_t shape_size) { - ov::Shape shape(shape_size); - std::iota(shape.begin(), shape.end(), 0); - - const size_t channels_position = *(shape.end() - 1); - - for (size_t i = shape.size() - 1; i > 0; --i) - shape[i] = shape[i - 1]; - - shape[1] = channels_position; - - return shape; -} - -} // namespace - -namespace SubstituteGNAConvolutionNS { - -bool do_transformation(std::shared_ptr convolution); - -bool do_transformation(std::shared_ptr convolution) { - auto convolution_node = std::dynamic_pointer_cast(convolution); - auto convolution_input_data_node = convolution_node->input_value(0); - auto convolution_filters_node = convolution_node->input_value(1); - const ov::Shape convolution_input_shape = convolution_node->get_input_shape(0); - - if (convolution_input_shape.size() != 3 && convolution_input_shape.size() != 4) { - std::cout << "ReplaceGnaNHWCLayers: unsupported convolution size " << convolution_input_shape.size() - << std::endl; - return false; - } - - const ov::Shape transpose_before_order = make_transpose_order_nchw2nhwc(convolution_input_shape.size()); - - auto transpose_const = - Constant::create(element::i32, ov::Shape{transpose_before_order.size()}, transpose_before_order); - - auto transpose_before = std::make_shared(convolution_input_data_node, transpose_const); - - auto transpose_conv_constant = std::make_shared(convolution_filters_node, transpose_const); - auto conv_new = std::make_shared(transpose_before, - transpose_conv_constant, - convolution_node->get_strides(), - convolution_node->get_pads_begin(), - convolution_node->get_pads_end(), - convolution_node->get_dilations(), - convolution_node->get_auto_pad()); - - const ov::Shape transpose_after_order = make_transpose_order_nhwc2nchw(conv_new->get_output_shape(0).size()); - - auto transpose_after = std::make_shared( - conv_new, - Constant::create(element::i32, ov::Shape{transpose_after_order.size()}, transpose_after_order)); - - ov::copy_runtime_info(convolution_node, - {transpose_before, transpose_const, conv_new, transpose_after, transpose_conv_constant}); - - ov::replace_output_update_name(convolution->output(0), transpose_after->output(0)); - - return true; -} - -} // namespace SubstituteGNAConvolutionNS - -namespace SubstituteGNAMaxPoolNS { - -bool do_transformation(std::shared_ptr convolution); - -bool do_transformation(std::shared_ptr max_pool) { - auto max_pool_node = std::dynamic_pointer_cast(max_pool); - auto max_pool_input_data_node = max_pool_node->input_value(0); - const ov::Shape max_pool_input_shape = max_pool_node->get_input_shape(0); - - const ov::Shape transpose_before_order = make_transpose_order_nchw2nhwc(max_pool_input_shape.size()); - - auto transpose_const = - Constant::create(element::i32, ov::Shape{transpose_before_order.size()}, transpose_before_order); - - auto transpose_before = std::make_shared(max_pool_input_data_node, transpose_const); - - auto max_pool_new = std::make_shared(transpose_before, - max_pool_node->get_strides(), - max_pool_node->get_pads_begin(), - max_pool_node->get_pads_end(), - max_pool_node->get_kernel(), - max_pool_node->get_rounding_type(), - max_pool_node->get_auto_pad()); - - const ov::Shape transpose_after_order = make_transpose_order_nhwc2nchw(max_pool_new->get_output_shape(0).size()); - - auto transpose_after = std::make_shared( - max_pool_new, - Constant::create(element::i32, ov::Shape{transpose_after_order.size()}, transpose_after_order)); - - ov::copy_runtime_info(max_pool_node, {transpose_before, transpose_const, max_pool_new, transpose_after}); - - ov::replace_output_update_name(max_pool->output(0), transpose_after->output(0)); - - return true; -} - -} // namespace SubstituteGNAMaxPoolNS - -// ---------------------------------------------------------------------------- - -ov::intel_gna::pass::SubstituteGNAConvolution::SubstituteGNAConvolution() { - MATCHER_SCOPE(SubstituteGNAConvolution); - - auto convolution = wrap_type(); - - matcher_pass_callback callback = [=](Matcher& m) { - auto convolution_node = std::dynamic_pointer_cast(m.get_match_root()); - if (!convolution_node) { - return false; - } - - return SubstituteGNAConvolutionNS::do_transformation(convolution_node); - }; - - auto m = std::make_shared(convolution, matcher_name); - this->register_matcher(m, callback); -} - -ov::intel_gna::pass::SubstituteGNAMaxPool::SubstituteGNAMaxPool() { - MATCHER_SCOPE(SubstituteGNAMaxPool); - - auto max_pool = wrap_type(); - - matcher_pass_callback callback = [=](Matcher& m) { - auto max_pool_node = std::dynamic_pointer_cast(m.get_match_root()); - if (!max_pool_node) { - return false; - } - - return SubstituteGNAMaxPoolNS::do_transformation(max_pool_node); - }; - - auto m = std::make_shared(max_pool, matcher_name); - this->register_matcher(m, callback); -} - -bool ov::intel_gna::pass::ReplaceGnaNHWCLayers::run_on_model(const std::shared_ptr& function) { - RUN_ON_MODEL_SCOPE(ReplaceGnaNHWCLayers); - - ov::pass::Manager manager(get_pass_config()); - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - - return false; -} diff --git a/src/plugins/intel_gna/src/transformations/replace_gna_nhwc_layers.hpp b/src/plugins/intel_gna/src/transformations/replace_gna_nhwc_layers.hpp deleted file mode 100644 index 476a9adc630..00000000000 --- a/src/plugins/intel_gna/src/transformations/replace_gna_nhwc_layers.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Substitites ngraph::Convolution (NCHW) -> GNAConvolution (NHWC) - * - * Transpose (NCHW -> NHWC) - * | - * Convolution (NCHW) -> GNAConvolution (NHWC) - * | - * Transpose (NHWC -> NCHW) - */ -class SubstituteGNAConvolution : public ov::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - SubstituteGNAConvolution(); -}; - -/** - * @brief Substitites ngraph::MaxPool (NCHW) -> GNAMaxPool (NHWC) - * - * Transpose (NCHW -> NHWC) - * | - * MaxPool (NCHW) -> GNAMaxPool (NHWC) - * | - * Transpose (NHWC -> NCHW) - */ -class SubstituteGNAMaxPool : public ov::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - SubstituteGNAMaxPool(); -}; - -/** - * @brief calls SubstituteGNAConvolution and SubstituteGNAMaxPool together - */ -class ReplaceGnaNHWCLayers : public ov::pass::ModelPass { -public: - NGRAPH_RTTI_DECLARATION; - bool run_on_model(const std::shared_ptr& f) override; -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/reshape_transpose_substitute.cpp b/src/plugins/intel_gna/src/transformations/reshape_transpose_substitute.cpp deleted file mode 100644 index 3f7e91d478a..00000000000 --- a/src/plugins/intel_gna/src/transformations/reshape_transpose_substitute.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/reshape_transpose_substitute.hpp" - -#include -#include -#include - -#include "common/graph_utils.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" - -using namespace ov; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace ov::op::util; -using namespace ov::intel_gna; -using namespace ov::intel_gna::pass; - -namespace { - -/** - * @brief Checks if output_shape is just permutation of input_shape dimensions - */ -bool is_shape_permutation(const Shape& input_shape, const Shape& output_shape) { - std::unordered_map values_count; - for (const auto& dim : input_shape) { - auto it = values_count.find(dim); - if (it != values_count.end()) { - ++it->second; - continue; - } - values_count[dim] = 1; - } - for (const auto& dim : output_shape) { - auto it = values_count.find(dim); - if (it != values_count.end()) { - --it->second; - if (!it->second) { - values_count.erase(it); - } - continue; - } - return false; - } - return values_count.empty(); -} - -/** - * @brief Checks if all shape dimensions have different values - */ -bool are_dims_unique(const Shape& shape) { - std::unordered_set dims; - for (const auto& dim : shape) { - if (dims.find(dim) != dims.end()) - return false; - dims.insert(dim); - } - return true; -} - -AxisVector get_unique_shapes_transpose_order(const Shape& input_shape, const Shape& output_shape) { - std::unordered_map input_shape_items; - for (size_t i = 0; i < input_shape.size(); ++i) { - input_shape_items[input_shape[i]] = i; - } - - AxisVector order; - order.reserve(output_shape.size()); - for (const auto& output_dim : output_shape) { - order.push_back(input_shape_items.find(output_dim)->second); - } - - return order; -} - -/** - * @brief Changes shape according to specified order - */ -Shape apply_permutation(const Shape& shape, const AxisVector& order) { - Shape transposed_shape; - transposed_shape.reserve(shape.size()); - for (const auto& position : order) { - transposed_shape.push_back(shape[position]); - } - return transposed_shape; -} - -AxisVector find_suitable_transpose_order(const Shape& input_shape, - const Shape& output_shape, - const std::vector& orders) { - for (const auto& order : orders) { - const Shape transposed_shape = apply_permutation(input_shape, order); - if (graph_utils::are_shapes_equal(transposed_shape, output_shape)) - return order; - } - - return {}; -} - -AxisVector find_suitable_transpose_order(const Shape& input_shape, const Shape& output_shape) { - static std::vector orders_4d = {AxisVector{0, 2, 3, 1}, AxisVector{0, 3, 1, 2}}; - static std::vector orders_3d = {AxisVector{1, 2, 0}, AxisVector{2, 0, 1}}; - - switch (input_shape.size()) { - case 4: - return find_suitable_transpose_order(input_shape, output_shape, orders_4d); - case 3: - return find_suitable_transpose_order(input_shape, output_shape, orders_3d); - case 2: - return AxisVector{1, 0}; - default: - return {}; - } - return {}; -} - -/** - * @brief Finds applicable transpose order to get output_shape from input_shape if - * it is possible - * Returns empty AxisVector on unsupported case - */ -AxisVector get_transpose_order(const Shape& input_shape, const Shape& output_shape) { - if (are_dims_unique(input_shape)) - return get_unique_shapes_transpose_order(input_shape, output_shape); - return find_suitable_transpose_order(input_shape, output_shape); -} - -} // namespace - -ReshapeTransposeSubstitute::ReshapeTransposeSubstitute() { - MATCHER_SCOPE(ReshapeTransposeSubstitute); - - auto reshape_label = wrap_type({any_input(), any_input()}, [](const Output& output) { - if (!has_static_shape()(output)) - return false; - const Node* node = output.get_node(); - return is_shape_permutation(node->get_input_shape(0), node->get_output_shape(0)); - }); - - ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - auto reshape = as_type_ptr(pattern_to_output.at(reshape_label).get_node_shared_ptr()); - - const AxisVector transpose_order = - get_transpose_order(reshape->get_input_shape(0), reshape->get_output_shape(0)); - if (transpose_order.empty()) - return false; - - auto new_transpose_const = - std::make_shared(element::i64, Shape{transpose_order.size()}, transpose_order); - auto new_transpose = std::make_shared(reshape->input_value(0), new_transpose_const); - - replace_node_update_name(reshape, new_transpose); - - return true; - }; - - auto m = std::make_shared(reshape_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} diff --git a/src/plugins/intel_gna/src/transformations/reshape_transpose_substitute.hpp b/src/plugins/intel_gna/src/transformations/reshape_transpose_substitute.hpp deleted file mode 100644 index b883e719d6b..00000000000 --- a/src/plugins/intel_gna/src/transformations/reshape_transpose_substitute.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Substitute Reshape with Transpose if it possible. - * It is usefull with Tranpose/Gather sinking transformations to simplify Transpose movement. - * TransposeSinking is not possible to use with Reshapes (except some cases when Reshape is Squeeze/Unsqueeze). - * GatherSinking is much harder to implement for all existed layer types. - * - * any layer any layer - * | | - * Reshape => Transpose - * | | - * any layer any layer - */ -class ReshapeTransposeSubstitute : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ReshapeTransposeSubstitute", "0"); - ReshapeTransposeSubstitute(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/rotate_inputs.cpp b/src/plugins/intel_gna/src/transformations/rotate_inputs.cpp deleted file mode 100644 index fafaf442582..00000000000 --- a/src/plugins/intel_gna/src/transformations/rotate_inputs.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/rotate_inputs.hpp" - -#include "common/graph_utils.hpp" -#include "openvino/cc/ngraph/itt.hpp" -#include "openvino/opsets/opset11.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "ops/gna_convolution.hpp" - -using namespace ov::opset11; -using namespace ov::pass; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::graph_utils; - -namespace { -inline bool is_skip_operation(const std::shared_ptr& node) { - return (std::dynamic_pointer_cast(node) != nullptr || - std::dynamic_pointer_cast(node) != nullptr || - std::dynamic_pointer_cast(node) != nullptr || - std::dynamic_pointer_cast(node) != nullptr || - std::dynamic_pointer_cast(node) != nullptr) && - has_n_consumers(node, 1); -} -} // namespace - -InsertConvolutionTransposeHW::InsertConvolutionTransposeHW() { - MATCHER_SCOPE(InsertConvolutionTransposeHW); - - const auto conv_pattern = pattern::wrap_type( - {pattern::any_input(), pattern::any_input()}, - [](const ov::Output& node) { - std::shared_ptr conv = - std::dynamic_pointer_cast(node.get_node_shared_ptr()); - helper::ConvData conv_data; - helper::GetConvData(conv, conv_data); - auto validator = limitations::Limitations::get_instance()->get_cnn_validator(); - return (validator && !validator->ShouldUseOnlyConv2DGnaIface()) && - gna_convolution_layer::isMappableFrom2DTo1D(static_cast(conv_data.input_height), - static_cast(conv_data.input_width), - static_cast(conv_data.input_channel_count), - static_cast(conv_data.filter_height), - static_cast(conv_data.filter_width), - static_cast(conv_data.filter_stride_height), - static_cast(conv_data.filter_stride_width)) && - gna_convolution_layer::should_transpose_h_w(static_cast(conv_data.input_height), - static_cast(conv_data.filter_height), - static_cast(conv_data.input_channel_count), - static_cast(conv_data.filter_stride_height)); - }); - - ov::matcher_pass_callback callback = [=](pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - - // auto param_node = pattern_map.at(param_pattern).get_node_shared_ptr(); - auto conv_node = pattern_map.at(conv_pattern).get_node_shared_ptr(); - - std::shared_ptr target_node = - graph_utils::get_prev_node_skipping_certain(conv_node->get_input_node_shared_ptr(0), is_skip_operation); - std::shared_ptr param_node = std::dynamic_pointer_cast(target_node); - - if (!param_node) { - return false; - } - - // transpose all convolution inputs - for (const auto& conv_input : conv_node->inputs()) { - // Transpose H and W (NHWC -> NWHC) - ov::AxisVector tr_axis = {0, 2, 1, 3}; - auto transpose_const = std::make_shared(ov::element::i8, ov::Shape{tr_axis.size()}, tr_axis); - auto transpose = std::make_shared(conv_input.get_source_output(), transpose_const); - - // Reshape out - ov::Shape shape_out = conv_input.get_shape(); - auto reshape_out_const = - std::make_shared(ov::element::i32, ov::Shape{shape_out.size()}, shape_out); - auto reshape_out = std::make_shared(transpose, reshape_out_const, false); - - conv_input.replace_source_output(reshape_out); - } - return true; - }; - - auto m = std::make_shared(conv_pattern, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/rotate_inputs.hpp b/src/plugins/intel_gna/src/transformations/rotate_inputs.hpp deleted file mode 100644 index fc84b4f4065..00000000000 --- a/src/plugins/intel_gna/src/transformations/rotate_inputs.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Transpose convolution inputs (HW->WH) - * when it is directly connected to network inputs - * - * Searches for next pattern - * Any input layer - * | - * Reshape/FQ/Squeeze/Usqueeze - * | - * Convolution - * - * And transforms to - * Any input layer - * | - * Transpose - * | - * Reshape/FQ/Squeeze/Usqueeze - * | - * Convolution - */ -class InsertConvolutionTransposeHW : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("InsertConvolutionTransposeHW", "0"); - InsertConvolutionTransposeHW(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/rt_info/gather_sinking_attr.cpp b/src/plugins/intel_gna/src/transformations/rt_info/gather_sinking_attr.cpp deleted file mode 100644 index cd18a94db93..00000000000 --- a/src/plugins/intel_gna/src/transformations/rt_info/gather_sinking_attr.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gather_sinking_attr.hpp" - -void ov::intel_gna::rt_info::mark_as_no_gather_sinking_node(const std::shared_ptr& node) { - auto& rt_info = node->get_rt_info(); - rt_info[NoGatherSinkingAttr::get_type_info_static()] = NoGatherSinkingAttr(); -} - -template -bool is_gather_sinking_node_private(NodePtr node) { - const auto& rt_info = node->get_rt_info(); - return rt_info.find(ov::intel_gna::rt_info::NoGatherSinkingAttr::get_type_info_static()) == rt_info.end(); -} - -bool ov::intel_gna::rt_info::is_gather_sinking_node(const std::shared_ptr& node) { - return is_gather_sinking_node_private(node); -} - -bool ov::intel_gna::rt_info::is_gather_sinking_node(const Node* node) { - return is_gather_sinking_node_private(node); -} - -bool ov::intel_gna::rt_info::is_gather_sinking_node(Output output) { - return is_gather_sinking_node(output.get_node()); -} diff --git a/src/plugins/intel_gna/src/transformations/rt_info/gather_sinking_attr.hpp b/src/plugins/intel_gna/src/transformations/rt_info/gather_sinking_attr.hpp deleted file mode 100644 index 2848fae9513..00000000000 --- a/src/plugins/intel_gna/src/transformations/rt_info/gather_sinking_attr.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/core/node.hpp" -#include "openvino/core/runtime_attribute.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace rt_info { - -void mark_as_no_gather_sinking_node(const std::shared_ptr& node); - -bool is_gather_sinking_node(const std::shared_ptr& node); -bool is_gather_sinking_node(const Node* node); -bool is_gather_sinking_node(ov::Output output); - -/** - * @ingroup ie_runtime_attr_api - * @brief NoGatherSinkingAttr class represents runtime info attribute that marks gather - * operation should not be moved be backward sinking propagation. - */ -class NoGatherSinkingAttr : public RuntimeAttribute { -public: - OPENVINO_RTTI("no_gather_sinking", "0"); - virtual ~NoGatherSinkingAttr() = default; - bool is_copyable() const override { - return false; - } -}; - -} // namespace rt_info -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/rt_info/gna_node_id.cpp b/src/plugins/intel_gna/src/transformations/rt_info/gna_node_id.cpp deleted file mode 100644 index c067876cd1c..00000000000 --- a/src/plugins/intel_gna/src/transformations/rt_info/gna_node_id.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_node_id.hpp" - -void ov::intel_gna::rt_info::set_node_id(const std::shared_ptr& node, uint64_t id) { - auto& rt_info = node->get_rt_info(); - rt_info[GnaNodeId::get_type_info_static()] = id; -} - -void ov::intel_gna::rt_info::remove_node_id(const std::shared_ptr& node) { - auto& rt_info = node->get_rt_info(); - rt_info.erase(GnaNodeId::get_type_info_static()); -} - -uint64_t ov::intel_gna::rt_info::get_node_id(const std::shared_ptr& node) { - const auto& rt_info = node->get_rt_info(); - return rt_info.at(GnaNodeId::get_type_info_static()).as(); -} diff --git a/src/plugins/intel_gna/src/transformations/rt_info/gna_node_id.hpp b/src/plugins/intel_gna/src/transformations/rt_info/gna_node_id.hpp deleted file mode 100644 index 80117e6418b..00000000000 --- a/src/plugins/intel_gna/src/transformations/rt_info/gna_node_id.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/core/node.hpp" -#include "openvino/core/runtime_attribute.hpp" - -namespace ov { -namespace intel_gna { -namespace rt_info { - -void set_node_id(const std::shared_ptr& node, uint64_t id); - -void remove_node_id(const std::shared_ptr& node); - -uint64_t get_node_id(const std::shared_ptr& node); - -/** - * @ingroup ie_runtime_attr_api - * @brief GnaNodeId class represents runtime info attribute that marks operation - * with order id - */ -class GnaNodeId : public RuntimeAttribute { -public: - OPENVINO_RTTI("gna_node_id", "0"); - - GnaNodeId() = default; - - bool is_copyable() const override { - return false; - } -}; -} // namespace rt_info -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/rt_info/gna_precision_change_flag.cpp b/src/plugins/intel_gna/src/transformations/rt_info/gna_precision_change_flag.cpp deleted file mode 100644 index f320d4eca62..00000000000 --- a/src/plugins/intel_gna/src/transformations/rt_info/gna_precision_change_flag.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_precision_change_flag.hpp" - -void ov::intel_gna::rt_info::add_precision_change_flag(ov::Input& node, - const ov::element::Type& in, - const ov::element::Type& out) { - RTMap& rt_info = node.get_rt_info(); - rt_info[GNAPrecisionChangeFlag::get_type_info_static()] = GNAPrecisionChangeFlag{in, out}; -} - -void ov::intel_gna::rt_info::remove_precision_change_flag(ov::Input& node) { - RTMap& rt_info = node.get_rt_info(); - auto it = rt_info.find(GNAPrecisionChangeFlag::get_type_info_static()); - if (it != rt_info.end()) { - rt_info.erase(it); - } -} - -bool ov::intel_gna::rt_info::is_precision_changed(const ov::Input& node) { - const RTMap& rt_info = node.get_rt_info(); - if (rt_info.count(GNAPrecisionChangeFlag::get_type_info_static()) > 0) { - auto flag = rt_info.at(GNAPrecisionChangeFlag::get_type_info_static()).as(); - return flag.is_changed(); - } - return false; -} diff --git a/src/plugins/intel_gna/src/transformations/rt_info/gna_precision_change_flag.hpp b/src/plugins/intel_gna/src/transformations/rt_info/gna_precision_change_flag.hpp deleted file mode 100644 index a4b8b822e16..00000000000 --- a/src/plugins/intel_gna/src/transformations/rt_info/gna_precision_change_flag.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/core/node.hpp" -#include "openvino/core/runtime_attribute.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace rt_info { - -void add_precision_change_flag(ov::Input& node, const ov::element::Type& in, const ov::element::Type& out); - -void remove_precision_change_flag(ov::Input& node); - -bool is_precision_changed(const ov::Input& node); - -/** - * @ingroup ie_runtime_attr_api - * @brief GNAPrecisionChangeFlag class represents runtime info attribute that marks that precision - * is have to be changed before operation - */ -class GNAPrecisionChangeFlag : public RuntimeAttribute { -public: - OPENVINO_RTTI("gna_precision_change_flag", "0"); - - GNAPrecisionChangeFlag(const ov::element::Type& in, const ov::element::Type& out) : in(in), out(out) {} - - bool is_copyable() const override { - return false; - } - - bool is_changed() { - return in != out; - } - -private: - ov::element::Type in; - ov::element::Type out; -}; -} // namespace rt_info -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/rt_info/gna_transpose_fusable.cpp b/src/plugins/intel_gna/src/transformations/rt_info/gna_transpose_fusable.cpp deleted file mode 100644 index 5e2e3aba998..00000000000 --- a/src/plugins/intel_gna/src/transformations/rt_info/gna_transpose_fusable.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_transpose_fusable.hpp" - -void ov::intel_gna::rt_info::add_transpose_fusable(const std::shared_ptr& node) { - auto& rt_info = node->get_rt_info(); - rt_info[GNATransposeFusable::get_type_info_static()] = std::string(); -} - -void ov::intel_gna::rt_info::remove_transpose_fusable(const std::shared_ptr& node) { - auto& rt_info = node->get_rt_info(); - rt_info.erase(GNATransposeFusable::get_type_info_static()); -} - -bool ov::intel_gna::rt_info::is_transpose_fusable(const std::shared_ptr& node) { - const auto& rt_info = node->get_rt_info(); - return rt_info.count(GNATransposeFusable::get_type_info_static()); -} diff --git a/src/plugins/intel_gna/src/transformations/rt_info/gna_transpose_fusable.hpp b/src/plugins/intel_gna/src/transformations/rt_info/gna_transpose_fusable.hpp deleted file mode 100644 index 137b32c8f22..00000000000 --- a/src/plugins/intel_gna/src/transformations/rt_info/gna_transpose_fusable.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/core/node.hpp" -#include "openvino/core/runtime_attribute.hpp" -#include "transformations_visibility.hpp" - -namespace ov { -namespace intel_gna { -namespace rt_info { - -void add_transpose_fusable(const std::shared_ptr& node); - -void remove_transpose_fusable(const std::shared_ptr& node); - -bool is_transpose_fusable(const std::shared_ptr& node); - -/** - * @ingroup ie_runtime_attr_api - * @brief GNATransposeFusable class represents runtime info attribute that marks operation - * as fusable with functional layer - */ -class GNATransposeFusable : public RuntimeAttribute { -public: - OPENVINO_RTTI("gna_transpose_fusable", "0"); - - GNATransposeFusable() = default; - - bool is_copyable() const override { - return false; - } -}; -} // namespace rt_info -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/split_convolution_with_large_buffer_size.cpp b/src/plugins/intel_gna/src/transformations/split_convolution_with_large_buffer_size.cpp deleted file mode 100644 index e8bf8ba876a..00000000000 --- a/src/plugins/intel_gna/src/transformations/split_convolution_with_large_buffer_size.cpp +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "transformations/split_convolution_with_large_buffer_size.hpp" - -#include -#include -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "layers/gna_convolution_layer.hpp" -#include "layers/gna_split_layer.hpp" - -using namespace ov::intel_gna::limitations; - -namespace ov { -namespace intel_gna { -namespace pass { - -// Don't split when convolution is 2D and is not mappable to 1D -static bool shouldSplitCnn(const ngraph::Output& node) { - auto convolution = dynamic_cast(node.get_node()); - IE_ASSERT(convolution != nullptr); - auto& input = convolution->get_input_shape(0); - auto& filters = convolution->get_input_shape(1); - auto width = static_cast(input.back()); - auto in_channels = static_cast(input.at(1)); - if (input.size() >= 4 && filters.size() >= 4) { - auto height = static_cast(input.at(2)); - auto kH = static_cast(filters.at(2)); - auto kW = static_cast(filters.at(3)); - auto sH = static_cast(convolution->get_strides().at(0)); - auto sW = static_cast(convolution->get_strides().at(1)); - if (gna_convolution_layer::is3DInputOr2DKernel(height, width, in_channels, kH, kW) && - !gna_convolution_layer::isMappableFrom2DTo1D(height, width, in_channels, kH, kW, sH, sW)) { - return false; - } - } - return true; -} - -static std::shared_ptr getConvForMatcher() { - return ngraph::pattern::wrap_type( - {ngraph::pattern::any_input(), ngraph::pattern::any_input()}, - [](const ngraph::Output& convolution) { - return shouldSplitCnn(convolution); - }); -} - -static bool Convert(std::shared_ptr conv, - std::shared_ptr add, - std::shared_ptr bias, - std::shared_ptr fq) { - auto input_size = std::accumulate(std::begin(conv->get_input_shape(0)), - std::end(conv->get_input_shape(0)), - size_t(1), - std::multiplies()); - if (input_size <= Limitations::kBufferMaxSize) { - return false; - } - auto& input = conv->get_input_shape(0); - uint32_t width = static_cast(input.back()); - uint32_t in_channels = static_cast(input.at(1)); - auto split_sizes = GetAlignedSplitSizes(width, - Limitations::kBufferMaxSize / in_channels, - static_cast(Limitations::get_instance()->get_memory_alignment())); - IE_ASSERT(split_sizes.size() > 1); - std::vector split_sizes_casted(split_sizes.size()); - std::transform(std::begin(split_sizes), std::end(split_sizes), std::begin(split_sizes_casted), [](uint32_t size) { - return static_cast(size); - }); - - /* TODO check if it's NHWC convolution wrapped with transposes or all input dimensions except of width == 1, - otherwise this split axis isn't supported */ - const int64_t width_axis = input.size() - 1; - auto split_node = std::make_shared( - conv->input_value(0), - ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape({1}), std::vector{width_axis}), - ngraph::opset7::Constant::create(ngraph::element::i64, - ngraph::Shape({split_sizes_casted.size()}), - split_sizes_casted)); - ngraph::copy_runtime_info(conv, split_node); - split_node->set_friendly_name(conv->get_friendly_name() + "/split"); - ngraph::OutputVector convOutputs; - std::shared_ptr root_node = fq ? fq : (add ? add : conv); - for (size_t i = 0; i < split_sizes.size(); ++i) { - std::shared_ptr output = - conv->clone_with_new_inputs({split_node->output(i), conv->input_value(1)}); - ngraph::copy_runtime_info(split_node, output); - output->set_friendly_name(conv->get_friendly_name() + "_" + std::to_string(i)); - if (bias) { - output = std::make_shared(output, bias); - ngraph::copy_runtime_info(conv, output); - } - - if (fq) { - output = fq->clone_with_new_inputs( - {output, fq->input_value(1), fq->input_value(2), fq->input_value(3), fq->input_value(4)}); - ngraph::copy_runtime_info(fq, output); - } - convOutputs.push_back(output); - } - - auto concat = std::make_shared(convOutputs, width_axis); - ngraph::copy_runtime_info(conv, concat); - concat->set_friendly_name(conv->get_friendly_name()); - ngraph::replace_node(root_node, concat); - return true; -} - -SplitConvolution::SplitConvolution() { - MATCHER_SCOPE(SplitConvolution); - auto conv = getConvForMatcher(); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - return Convert(pattern_map.at(conv).get_node_shared_ptr(), nullptr, nullptr, nullptr); - }; - - auto m = std::make_shared(conv, matcher_name); - this->register_matcher(m, callback); -} - -SplitConvolutionWithBias::SplitConvolutionWithBias() { - MATCHER_SCOPE(SplitConvolutionWithBias); - auto conv = getConvForMatcher(); - auto bias = ngraph::pattern::wrap_type(); - auto add = ngraph::pattern::wrap_type({conv, bias}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - return Convert(pattern_map.at(conv).get_node_shared_ptr(), - pattern_map.at(add).get_node_shared_ptr(), - pattern_map.at(bias).get_node_shared_ptr(), - nullptr); - }; - - auto m = std::make_shared(add, matcher_name); - this->register_matcher(m, callback); -} - -SplitConvolutionWithFq::SplitConvolutionWithFq() { - MATCHER_SCOPE(SplitConvolutionWithFq); - auto conv = getConvForMatcher(); - auto bias = ngraph::pattern::wrap_type(); - auto add = ngraph::pattern::wrap_type({conv, bias}); - auto conv_output = std::make_shared(ngraph::OutputVector{conv, add}); - auto out_fq = ngraph::pattern::wrap_type( - {conv_output, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto add_it = pattern_map.find(add); - auto add_node = (add_it == std::end(pattern_map) ? nullptr : add_it->second.get_node_shared_ptr()); - auto bias_it = pattern_map.find(bias); - auto bias_node = (bias_it == std::end(pattern_map) ? nullptr : bias_it->second.get_node_shared_ptr()); - return Convert(pattern_map.at(conv).get_node_shared_ptr(), - add_node, - bias_node, - pattern_map.at(out_fq).get_node_shared_ptr()); - }; - - auto m = std::make_shared(out_fq, matcher_name); - this->register_matcher(m, callback); -} - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/split_convolution_with_large_buffer_size.hpp b/src/plugins/intel_gna/src/transformations/split_convolution_with_large_buffer_size.hpp deleted file mode 100644 index 04a3d418058..00000000000 --- a/src/plugins/intel_gna/src/transformations/split_convolution_with_large_buffer_size.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -// @brief Splits convolution with large input buffer -class SplitConvolution : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("SplitConvolution", "0"); - SplitConvolution(); -}; - -// @brief Splits convolution with large input buffer, move add with bias to each convolution before concat -class SplitConvolutionWithBias : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("SplitConvolutionWithBias", "0"); - SplitConvolutionWithBias(); -}; - -/* @brief Splits convolution with large input buffer, - * move add with bias and/or fake quantize to each convolution before concat - */ -class SplitConvolutionWithFq : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("SplitConvolutionWithFq", "0"); - SplitConvolutionWithFq(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/split_eltwise.cpp b/src/plugins/intel_gna/src/transformations/split_eltwise.cpp deleted file mode 100644 index b1baadbfcf1..00000000000 --- a/src/plugins/intel_gna/src/transformations/split_eltwise.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "transformations/split_eltwise.hpp" - -#include -#include -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "layers/gna_split_layer.hpp" -#include "legacy/ngraph_ops/eltwise.hpp" -#include "log/log.hpp" - -using namespace ov::intel_gna::limitations; - -namespace ov { -namespace intel_gna { -namespace pass { - -inline bool is_eltwise_has_to_be_splitted(const ngraph::Output& node) { - auto eltwise = std::dynamic_pointer_cast(node.get_node_shared_ptr()); - if (!eltwise) - return false; - auto o_dims = eltwise->get_output_shape(0); - auto total_elem_size = - std::accumulate(std::begin(o_dims), std::end(o_dims), std::size_t{1}, std::multiplies()); - return (total_elem_size > Limitations::kBufferMaxSize); -} - -static std::shared_ptr split_input( - const std::shared_ptr& node, - const std::pair>& split_sizes_per_axis) { - auto split = std::make_shared( - node, - ngraph::opset9::Constant::create(ngraph::element::i64, - ngraph::Shape({1}), - std::vector{split_sizes_per_axis.first}), - ngraph::opset9::Constant::create(ngraph::element::i64, - ngraph::Shape({split_sizes_per_axis.second.size()}), - split_sizes_per_axis.second)); - split->set_friendly_name(node->get_friendly_name() + "/split"); - ngraph::copy_runtime_info(node, split); - return split; -} - -static std::shared_ptr create_eltwise(const std::shared_ptr& node, - const std::shared_ptr& split0, - const std::shared_ptr& split1, - size_t index) { - auto root_eltwise = std::dynamic_pointer_cast(node); - auto eltwise = std::make_shared(split0->output(index), - split1->output(index), - root_eltwise->eltwise_type, - root_eltwise->get_output_element_type(0)); - eltwise->set_friendly_name(root_eltwise->get_friendly_name() + "/partition" + std::to_string(index)); - ngraph::copy_runtime_info(root_eltwise, eltwise); - return eltwise; -} - -SplitEltwise::SplitEltwise() { - MATCHER_SCOPE(SplitEltwise); - auto eltwise = - ngraph::pattern::wrap_type({ngraph::pattern::any_input(), ngraph::pattern::any_input()}, - is_eltwise_has_to_be_splitted); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto eltwise_node = pattern_map.at(eltwise).get_node_shared_ptr(); - auto consumers = eltwise_node->output(0).get_target_inputs(); - auto o_dims = eltwise_node->get_output_shape(0); - - auto split_sizes_per_axis = AlignedSplitSizesPerAxis(o_dims); - if (0 == split_sizes_per_axis.second.size()) { - log::debug() << "Splitting didn't succeed for layer " << eltwise_node->get_friendly_name() << " on axis " - << split_sizes_per_axis.first << std::endl; - return false; - } - - auto split_node0 = split_input(eltwise_node->get_input_node_shared_ptr(0), split_sizes_per_axis); - auto split_node1 = split_input(eltwise_node->get_input_node_shared_ptr(1), split_sizes_per_axis); - - ov::NodeVector concat_inputs; - for (size_t i = 0; i < split_sizes_per_axis.second.size(); i++) { - auto eltwise_node_part = create_eltwise(eltwise_node, split_node0, split_node1, i); - concat_inputs.push_back(eltwise_node_part); - } - auto concat = std::make_shared(concat_inputs, split_sizes_per_axis.first); - concat->set_friendly_name(eltwise_node->get_friendly_name()); - ngraph::copy_runtime_info(eltwise_node, concat); - for (auto&& input : consumers) { - input.replace_source_output(concat); - } - return true; - }; - - auto m = std::make_shared(eltwise, matcher_name); - this->register_matcher(m, callback); -} - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/split_eltwise.hpp b/src/plugins/intel_gna/src/transformations/split_eltwise.hpp deleted file mode 100644 index ca8f5fdc88f..00000000000 --- a/src/plugins/intel_gna/src/transformations/split_eltwise.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Split over channels for Eltwise to avoid GNA-HW kBufferMaxSize limitation per eltwise - */ -class SplitEltwise : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("SplitEltwise", "0"); - SplitEltwise(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/substitute_softsign.cpp b/src/plugins/intel_gna/src/transformations/substitute_softsign.cpp deleted file mode 100644 index 39779f9cf0a..00000000000 --- a/src/plugins/intel_gna/src/transformations/substitute_softsign.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/substitute_softsign.hpp" - -#include -#include -#include -#include -#include -#include - -#include "transformations/utils/transformation_helper.hpp" -#include "transformations/utils/utils.hpp" - -using namespace ov::intel_gna::pass; - -using Node = std::shared_ptr; - -namespace { - -void DoTransformation(Node start_node, Node last_node) { - auto activation = std::make_shared(start_node); - activation->set_friendly_name(last_node->get_friendly_name()); - ngraph::copy_runtime_info(last_node, activation); - ngraph::replace_node(last_node, activation); -} - -class IsConstValueAcceptable { -public: - IsConstValueAcceptable(double expected_value) : m_expected_value(expected_value) {} - - bool operator()(const ngraph::Output& output) const { - auto node = std::dynamic_pointer_cast(output.get_node_shared_ptr()); - if (!node) - return false; - - float value; - if (!ov::op::util::get_single_value(node, value)) { - return false; - } - - return (value == m_expected_value); - } - -private: - const double m_expected_value; -}; - -} // namespace - -SubstituteSoftsign::SubstituteSoftsign() { - MATCHER_SCOPE(SubstituteSoftsign); - - auto root = ngraph::pattern::any_input(); - auto abs = ngraph::pattern::wrap_type({root}); - - auto add_const = ngraph::pattern::wrap_type(IsConstValueAcceptable(1.0)); - auto add = ngraph::pattern::wrap_type({abs, add_const}); - - auto power_const = ngraph::pattern::wrap_type(IsConstValueAcceptable(-1.0)); - auto power = ngraph::pattern::wrap_type({add, power_const}); - - auto multiply = ngraph::pattern::wrap_type({root, power}); - auto divide = ngraph::pattern::wrap_type({root, add}); - auto last = std::make_shared(ngraph::OutputVector{multiply, divide}); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto root_node = pattern_map.at(root).get_node_shared_ptr(); - - auto last_node_it = pattern_map.find(multiply); - if (last_node_it == pattern_map.end()) - last_node_it = pattern_map.find(divide); - if (last_node_it == pattern_map.end()) - return false; - auto last_node = last_node_it->second.get_node_shared_ptr(); - - DoTransformation(root_node, last_node); - - return true; - }; - - auto m = std::make_shared(last, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/substitute_softsign.hpp b/src/plugins/intel_gna/src/transformations/substitute_softsign.hpp deleted file mode 100644 index 73155b3a8a7..00000000000 --- a/src/plugins/intel_gna/src/transformations/substitute_softsign.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Current version of ModelOptimizer substitutes SoftSign activation - * function with next subgraph - * a layer - * | \ - * abs \ - * | | - * add | - * | | - * power | - * \ / - * Divide - * - * See model-optimizer/extensions/front/softsign_replacer.py - * - * The ConvertDivide transformation from CommonOptimizations - * substitutes Divide with {-1} and add constant {1} - * - GNA supports Power [0, 2.8] - * - Add, Power, Divide layers are more perfomance expensive in GNA - * than SoftSign PWL - * - * Legacy SubstituteSoftSignPass supports irv7 model where SoftSign subgraph - * could have been without add layer. Current ModelOptimezer always generates - * SoftSign subgraph with that layer. - * - * SubstituteSoftsign transformation does backward substitution to SoftSign. - * TODO: remove that pass as soon as ModelOptimizer will not substitute SoftSign activation - */ -class SubstituteSoftsign : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("SubstituteSoftsign", "0"); - SubstituteSoftsign(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/swap_input_matmul_gna.cpp b/src/plugins/intel_gna/src/transformations/swap_input_matmul_gna.cpp deleted file mode 100644 index 35170b8bff8..00000000000 --- a/src/plugins/intel_gna/src/transformations/swap_input_matmul_gna.cpp +++ /dev/null @@ -1,386 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "log/log.hpp" - -using namespace ov::intel_gna; -using namespace ov::intel_gna::pass; - -static void SwapAndTransposeInputs(std::shared_ptr matmul_node, - const std::string& last_layer_name, - std::shared_ptr add = nullptr, - std::shared_ptr bias = nullptr, - std::shared_ptr fq = nullptr, - std::shared_ptr act = nullptr, - std::shared_ptr transpose = nullptr) { - ngraph::NodeVector new_ops; - - auto create_transpose = [&new_ops](ngraph::Output node, - const std::string& transpose_name) -> std::shared_ptr { - ngraph::Shape output_shape = node.get_node_shared_ptr()->get_shape(); - - std::vector transpose_order(output_shape.size()); - std::iota(transpose_order.begin(), transpose_order.end(), 0); - std::swap(*(transpose_order.end() - 1), *(transpose_order.end() - 2)); - - auto transpose_const = ngraph::opset8::Constant::create(ngraph::element::i64, - ngraph::Shape{transpose_order.size()}, - transpose_order); - new_ops.push_back(transpose_const); - auto transpose = std::make_shared(node, transpose_const); - transpose->set_friendly_name(transpose_name); - new_ops.push_back(transpose); - return transpose; - }; - - auto transpose_matmul_input = [matmul_node, create_transpose](size_t ix) { - std::shared_ptr matmul_input = matmul_node->input_value(ix).get_node_shared_ptr(); - auto input_transpose = std::dynamic_pointer_cast(matmul_input); - if (input_transpose != nullptr) { - matmul_input = matmul_input->input_value(0).get_node_shared_ptr(); - ngraph::replace_output_update_name(input_transpose->output(0), input_transpose->input_value(0)); - } else { - matmul_input = - create_transpose(matmul_node->input_value(ix), matmul_node->get_friendly_name() + "/input_transpose"); - } - return matmul_input; - }; - - log::debug() << "Swap and transpose inputs for " << matmul_node->get_friendly_name() << "\n"; - - bool first_input_const = false; - bool second_input_const = false; - auto first_input = matmul_node->input_value(0).get_node_shared_ptr(); - auto second_input = matmul_node->input_value(1).get_node_shared_ptr(); - if (std::dynamic_pointer_cast(first_input)) { - first_input = first_input->input_value(0).get_node_shared_ptr(); - } - if (std::dynamic_pointer_cast(second_input)) { - second_input = second_input->input_value(1).get_node_shared_ptr(); - } - if (std::dynamic_pointer_cast(first_input)) { - first_input_const = true; - } - if (std::dynamic_pointer_cast(second_input)) { - second_input_const = true; - } - - auto input1 = (!first_input_const && second_input_const) ? matmul_node->input_value(1) : transpose_matmul_input(1); - auto input2 = first_input_const ? matmul_node->input_value(0) : transpose_matmul_input(0); - bool transpose_1 = - (!first_input_const && second_input_const) ? !matmul_node->get_transpose_b() : matmul_node->get_transpose_b(); - bool transpose_2 = first_input_const ? !matmul_node->get_transpose_a() : matmul_node->get_transpose_a(); - std::shared_ptr new_node = - std::make_shared(input1, input2, transpose_1, transpose_2); - new_node->set_friendly_name(matmul_node->get_friendly_name() + "/swap_inputs"); - new_ops.push_back(new_node); - - std::shared_ptr old_root_node = matmul_node; - if (bias != nullptr) { - // output of MatMul will be transposed comparing with original one, so the bias should be transposed too - if (bias->get_output_shape(0).size() > 1) { - bias = create_transpose(bias, bias->get_friendly_name() + "/transpose"); - - auto transpose_shape = bias->get_output_shape(0); - auto matmul_shape = matmul_node->get_output_shape(0); - if (transpose_shape.size() > matmul_shape.size()) { - std::vector reshape_shape(matmul_shape.size(), 1); - std::copy_if(transpose_shape.begin(), transpose_shape.end(), reshape_shape.begin(), [](size_t e) { - return e > 1; - }); - auto bias_const = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{reshape_shape.size()}, - reshape_shape); - bias = std::make_shared(bias, bias_const, false); - bias->set_friendly_name(add->get_friendly_name() + "/reshape"); - ngraph::copy_runtime_info(add, {bias, bias_const}); - new_ops.push_back(bias); - } - } - - new_node = std::make_shared(new_node, bias); - old_root_node = add; - new_ops.push_back(new_node); - } - - if (fq != nullptr) { - new_node = fq->clone_with_new_inputs( - {new_node, fq->input_value(1), fq->input_value(2), fq->input_value(3), fq->input_value(4)}); - old_root_node = fq; - new_ops.push_back(new_node); - } - - if (act != nullptr) { - new_node = act->clone_with_new_inputs({new_node}); - old_root_node = act; - new_ops.push_back(new_node); - } - - if (transpose == nullptr) { - new_node = create_transpose(new_node, last_layer_name); - } else { - ngraph::replace_output_update_name(transpose->output(0), transpose->input_value(0)); - new_node->set_friendly_name(last_layer_name); - } - - ngraph::copy_runtime_info(matmul_node, new_ops); - ngraph::replace_node(old_root_node, new_node); -} - -static std::shared_ptr CreateMatmul( - bool is_first_constant, - ngraph::pattern::op::ValuePredicate const_predicate, - ngraph::pattern::op::ValuePredicate matmul_predicate = ngraph::pattern::has_static_shape()) { - auto constant = ngraph::pattern::wrap_type({}, const_predicate); - auto fake_quantize = ngraph::pattern::wrap_type( - {constant, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - auto matmul_const_input = std::make_shared(ngraph::OutputVector{constant, fake_quantize}); - auto transpose = ngraph::pattern::wrap_type(); - auto matmul_non_const_input = - std::make_shared(ngraph::OutputVector{transpose, ngraph::pattern::any_input()}); - if (is_first_constant) { - return ngraph::pattern::wrap_type({matmul_const_input, matmul_non_const_input}, - matmul_predicate); - } - return ngraph::pattern::wrap_type({ngraph::pattern::any_input(), matmul_non_const_input}, - matmul_predicate); -} - -static std::shared_ptr CreateMatmuls(std::shared_ptr& matmul1, - std::shared_ptr& matmul2) { - matmul1 = CreateMatmul( - true, - [](const ngraph::Output& node) { - return true; - }, - [](const ngraph::Output& node) { - auto matmul_node = std::dynamic_pointer_cast(node.get_node_shared_ptr()); - IE_ASSERT(matmul_node != nullptr); - auto input_shape = matmul_node->get_input_shape(0); - return input_shape.size() == 2 && ((!matmul_node->get_transpose_a() && input_shape[0] > 8) || - (matmul_node->get_transpose_a() && input_shape[1] > 8)); - }); - matmul2 = CreateMatmul( - false, - [](const ngraph::Output& node) { - return true; - }, - [](const ngraph::Output& node) { - auto matmul_node = std::dynamic_pointer_cast(node.get_node_shared_ptr()); - IE_ASSERT(matmul_node != nullptr); - auto first_input_shape = matmul_node->get_input_shape(0); - first_input_shape.erase(std::remove(first_input_shape.begin(), first_input_shape.end(), 1), - first_input_shape.end()); - auto second_input_shape = matmul_node->get_input_shape(1); - return node.get_partial_shape().is_static() && second_input_shape.size() == 2 && - ((!matmul_node->get_transpose_b() && second_input_shape[1] <= 8) || - (matmul_node->get_transpose_b() && second_input_shape[0] <= 8)) && - first_input_shape.size() == 2 && first_input_shape[0] > 8; - }); - return std::make_shared(ngraph::OutputVector{matmul1, matmul2}); -} - -SwapInputMatMul::SwapInputMatMul() { - MATCHER_SCOPE(SwapInputMatMul); - std::shared_ptr matmul1; - std::shared_ptr matmul2; - auto matmul = CreateMatmuls(matmul1, matmul2); - auto callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto iter = pattern_map.find(matmul1); - if (iter == pattern_map.end() && (iter = pattern_map.find(matmul2)) == pattern_map.end()) { - return false; - } - - auto matmul_node = std::dynamic_pointer_cast(iter->second.get_node_shared_ptr()); - IE_ASSERT(matmul_node != nullptr); - SwapAndTransposeInputs(matmul_node, matmul_node->get_friendly_name()); - return true; - }; - - auto matcher = std::make_shared(matmul, matcher_name); - this->register_matcher(matcher, callback); -} - -SwapInputMatMulWithBias::SwapInputMatMulWithBias() { - MATCHER_SCOPE(SwapInputMatMulWithBias); - std::shared_ptr matmul1; - std::shared_ptr matmul2; - auto matmul = CreateMatmuls(matmul1, matmul2); - auto bias = ngraph::pattern::wrap_type(); - auto add = ngraph::pattern::wrap_type({matmul, bias}); - auto callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto iter = pattern_map.find(matmul1); - if (iter == pattern_map.end() && (iter = pattern_map.find(matmul2)) == pattern_map.end()) { - return false; - } - - auto matmul_node = std::dynamic_pointer_cast(iter->second.get_node_shared_ptr()); - IE_ASSERT(matmul_node != nullptr); - SwapAndTransposeInputs(matmul_node, - pattern_map.at(add).get_node_shared_ptr()->get_friendly_name(), - pattern_map.at(add).get_node_shared_ptr(), - pattern_map.at(bias).get_node_shared_ptr()); - return true; - }; - - auto matcher = std::make_shared(add, matcher_name); - this->register_matcher(matcher, callback); -} - -SwapInputMatMulWithFq::SwapInputMatMulWithFq() { - MATCHER_SCOPE(SwapInputMatMulWithFq); - std::shared_ptr matmul1; - std::shared_ptr matmul2; - auto matmul = CreateMatmuls(matmul1, matmul2); - auto bias = ngraph::pattern::wrap_type(); - auto add = ngraph::pattern::wrap_type({matmul, bias}); - auto fq_input = std::make_shared(ngraph::OutputVector{add, matmul}); - auto fq = ngraph::pattern::wrap_type( - {fq_input, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - auto callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto iter = pattern_map.find(matmul1); - if (iter == pattern_map.end() && (iter = pattern_map.find(matmul2)) == pattern_map.end()) { - return false; - } - - auto iter_add = pattern_map.find(add); - auto iter_bias = pattern_map.find(bias); - auto matmul_node = std::dynamic_pointer_cast(iter->second.get_node_shared_ptr()); - IE_ASSERT(matmul_node != nullptr); - SwapAndTransposeInputs(matmul_node, - pattern_map.at(fq).get_node_shared_ptr()->get_friendly_name(), - iter_add != pattern_map.end() ? iter_add->second.get_node_shared_ptr() : nullptr, - iter_bias != pattern_map.end() ? iter_bias->second.get_node_shared_ptr() : nullptr, - pattern_map.at(fq).get_node_shared_ptr()); - return true; - }; - - auto matcher = std::make_shared(fq, matcher_name); - this->register_matcher(matcher, callback); -} - -SwapInputMatMulWithAct::SwapInputMatMulWithAct() { - MATCHER_SCOPE(SwapInputMatMulWithAct); - std::shared_ptr matmul1; - std::shared_ptr matmul2; - auto matmul = CreateMatmuls(matmul1, matmul2); - auto bias = ngraph::pattern::wrap_type(); - auto add = ngraph::pattern::wrap_type({matmul, bias}); - auto fq_input = std::make_shared(ngraph::OutputVector{add, matmul}); - auto fq = ngraph::pattern::wrap_type( - {fq_input, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - auto act_input = std::make_shared(ngraph::OutputVector{fq_input, fq}); - auto act = ngraph::pattern::wrap_type({act_input}); - auto callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto iter = pattern_map.find(matmul1); - if (iter == pattern_map.end() && (iter = pattern_map.find(matmul2)) == pattern_map.end()) { - return false; - } - - auto iter_add = pattern_map.find(add); - auto iter_bias = pattern_map.find(bias); - auto iter_fq = pattern_map.find(fq); - auto matmul_node = std::dynamic_pointer_cast(iter->second.get_node_shared_ptr()); - IE_ASSERT(matmul_node != nullptr); - SwapAndTransposeInputs(matmul_node, - pattern_map.at(act).get_node_shared_ptr()->get_friendly_name(), - iter_add != pattern_map.end() ? iter_add->second.get_node_shared_ptr() : nullptr, - iter_bias != pattern_map.end() ? iter_bias->second.get_node_shared_ptr() : nullptr, - iter_fq != pattern_map.end() ? iter_fq->second.get_node_shared_ptr() : nullptr, - pattern_map.at(act).get_node_shared_ptr()); - return true; - }; - - auto matcher = std::make_shared(act, matcher_name); - this->register_matcher(matcher, callback); -} - -SwapInputMatMulWithTrailingTranspose::SwapInputMatMulWithTrailingTranspose() { - MATCHER_SCOPE(SwapInputMatMulWithTrailingTranspose); - std::shared_ptr matmul1; - std::shared_ptr matmul2; - auto matmul = CreateMatmuls(matmul1, matmul2); - auto bias = ngraph::pattern::wrap_type(); - auto add = ngraph::pattern::wrap_type({matmul, bias}); - auto fq_input = std::make_shared(ngraph::OutputVector{add, matmul}); - auto fq = ngraph::pattern::wrap_type( - {fq_input, - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); - auto act_input = std::make_shared(ngraph::OutputVector{fq_input, fq}); - auto act = ngraph::pattern::wrap_type({act_input}); - auto transpose_input = std::make_shared(ngraph::OutputVector{act_input, act}); - auto transpose = - ngraph::pattern::wrap_type({transpose_input, ngraph::pattern::any_input()}); - auto callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - auto iter = pattern_map.find(matmul1); - if (iter == pattern_map.end() && (iter = pattern_map.find(matmul2)) == pattern_map.end()) { - return false; - } - - auto iter_add = pattern_map.find(add); - auto iter_bias = pattern_map.find(bias); - auto iter_fq = pattern_map.find(fq); - auto iter_act = pattern_map.find(act); - auto matmul_node = std::dynamic_pointer_cast(iter->second.get_node_shared_ptr()); - IE_ASSERT(matmul_node != nullptr); - SwapAndTransposeInputs(matmul_node, - pattern_map.at(transpose).get_node_shared_ptr()->get_friendly_name(), - iter_add != pattern_map.end() ? iter_add->second.get_node_shared_ptr() : nullptr, - iter_bias != pattern_map.end() ? iter_bias->second.get_node_shared_ptr() : nullptr, - iter_fq != pattern_map.end() ? iter_fq->second.get_node_shared_ptr() : nullptr, - iter_act != pattern_map.end() ? iter_act->second.get_node_shared_ptr() : nullptr, - pattern_map.at(transpose).get_node_shared_ptr()); - return true; - }; - - auto matcher = std::make_shared(transpose, matcher_name); - this->register_matcher(matcher, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/swap_input_matmul_gna.hpp b/src/plugins/intel_gna/src/transformations/swap_input_matmul_gna.hpp deleted file mode 100644 index aa268e6580d..00000000000 --- a/src/plugins/intel_gna/src/transformations/swap_input_matmul_gna.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2020-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#ifndef SWAP_INPUT_MATMUL_GNA_HPP -#define SWAP_INPUT_MATMUL_GNA_HPP - -#include - -namespace ov { -namespace intel_gna { -namespace pass { -/* @brief Swaps and transposes inputs of MatMul and transposes its output if - * 1. its first input is const and its batch size isn't supported by GNA - * 2. its first input is non-const and its batch size isn't supported by GNA - * The following pattern is detected: - * Constant Any input - * | | - * [FakeQuantize] [Transpose] - * \ / - * MatMul - * | - * [Add] - * | - * [FakeQuantize] - * | - * [Activation] - * | - * [Transpose] - * - * The existed Transposes will be removed instead of inserting new ones during transposition. - * Separate matchers are required for different last nodes. They should be registered in the order from the longest - * to the shortest pattern. - **/ -class SwapInputMatMul : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("SwapInputMatMul", "0"); - SwapInputMatMul(); -}; - -class SwapInputMatMulWithBias : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("SwapInputMatMulWithBias", "0"); - SwapInputMatMulWithBias(); -}; - -class SwapInputMatMulWithFq : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("SwapInputMatMulWithFq", "0"); - SwapInputMatMulWithFq(); -}; - -class SwapInputMatMulWithAct : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("SwapInputMatMulWithAct", "0"); - SwapInputMatMulWithAct(); -}; - -class SwapInputMatMulWithTrailingTranspose : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("SwapInputMatMulWithTrailingTranspose", "0"); - SwapInputMatMulWithTrailingTranspose(); -}; -} // namespace pass -} // namespace intel_gna -} // namespace ov -#endif // SWAP_INPUT_MATMUL_GNA_HPP diff --git a/src/plugins/intel_gna/src/transformations/transpose_compress.cpp b/src/plugins/intel_gna/src/transformations/transpose_compress.cpp deleted file mode 100644 index 0054a849b7f..00000000000 --- a/src/plugins/intel_gna/src/transformations/transpose_compress.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/transpose_compress.hpp" - -#include "common/graph_utils.hpp" -#include "openvino/cc/ngraph/itt.hpp" -#include "openvino/opsets/opset11.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" - -using namespace ov::opset11; -using namespace ov::pass; -using namespace ov::intel_gna::pass; - -namespace { - -inline std::vector fix_indexes(const std::vector& ids) { - std::vector ids_fixed(ids.size()); - std::iota(ids_fixed.begin(), ids_fixed.end(), 0); - stable_sort(ids_fixed.begin(), ids_fixed.end(), [&ids](size_t a, size_t b) { - return ids[a] < ids[b]; - }); - return ids_fixed; -} - -} // namespace - -TransposeCompress::TransposeCompress() { - MATCHER_SCOPE(TransposeCompress); - - auto transpose_const = pattern::wrap_type(); - auto transpose = - pattern::wrap_type({pattern::any_input(), transpose_const}, [](const ov::Output& node) { - return !limitations::Limitations::is_transpose_supported(node.get_node_shared_ptr()); - }); - - ov::matcher_pass_callback callback = [=](pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - const auto transpose_order = as_type_ptr(pattern_map.at(transpose_const).get_node_shared_ptr()); - const auto transpose_node = pattern_map.at(transpose).get_node_shared_ptr(); - const ov::Shape& shape = transpose_node->get_input_shape(0); - const ov::Shape& shape_out = transpose_node->get_output_shape(0); - ov::AxisVector axis = transpose_order->get_axis_vector_val(); - ov::AxisVector axis_compressed = {}; - ov::Shape shape_compressed_out = {}; - for (const size_t& axis : axis) { - if (axis_compressed.empty() || (axis - axis_compressed.back()) != 1) { - axis_compressed.push_back(axis); - shape_compressed_out.push_back(shape[axis]); - } else { - shape_compressed_out.back() *= shape[axis]; - } - } - // check that compressing is required - if (axis.size() == axis_compressed.size()) { - return false; - } - - // correct fused indexes, e.g. (2, 0, 3) -> (1, 0, 2) - ov::AxisVector axis_fused_fixed = fix_indexes(axis_compressed); - size_t fused_sz = axis_fused_fixed.size(); - // Restore input shape - ov::Shape shape_fused_in(fused_sz); - for (size_t i = 0; i < fused_sz; ++i) { - shape_fused_in[i] = shape_compressed_out[axis_fused_fixed[i]]; - } - - if (!limitations::Limitations::is_transpose_supported(shape_fused_in)) { - return false; - } - - // Reshape in - auto reshape_in_const = - std::make_shared(ov::element::i32, ov::Shape{shape_fused_in.size()}, shape_fused_in); - auto reshape_in = std::make_shared(transpose_node->input_value(0), reshape_in_const, false); - // Transpose - auto transpose_const = - std::make_shared(ov::element::i8, ov::Shape{axis_fused_fixed.size()}, axis_fused_fixed); - auto transpose = std::make_shared(reshape_in, transpose_const); - // Reshape out - auto reshape_out_const = std::make_shared(ov::element::i32, ov::Shape{shape_out.size()}, shape_out); - auto reshape_out = std::make_shared(transpose, reshape_out_const, false); - // - ov::replace_output_update_name(transpose_node->output(0), reshape_out->output(0)); - ov::copy_runtime_info({transpose_node, transpose_order}, - {transpose, transpose_const, reshape_in, reshape_in_const}); - - return true; - }; - - auto m = std::make_shared(transpose, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/transpose_compress.hpp b/src/plugins/intel_gna/src/transformations/transpose_compress.hpp deleted file mode 100644 index 621dd896642..00000000000 --- a/src/plugins/intel_gna/src/transformations/transpose_compress.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "openvino/pass/graph_rewrite.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Reduce the rank of Transpose shape by merging consecutive dimensions - * if those dimensions are not changed by transposition order. - * For example, shape[2,3,4] -> Transpose[2, 0, 1] -> shape[4,2,3] will be replaced with - * shape[6,4] -> Transpose[1, 0] -> shape[4,6] - * If the new Transpose layer is not supported by GNA (see full conditions in the is_transpose_supported()) - * then Transpose will not be changed. - * - * [A, B, C, D] [A, B, C, D] - * | | - * Transpose(0, 3, 1, 2) Reshape - * | | - * [A, D, B, C] [A, B*C, D] - * | | - * | Transpose(0, 2, 1) - * | -> | - * | <- [A, D, B*C] - * | | - * | Reshape - * | | - * | [A, D, B, C] - * | | - * Any Layer Any Layer - */ -class TransposeCompress : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("TransposeCompress", "0"); - TransposeCompress(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/ts_concat_forward.cpp b/src/plugins/intel_gna/src/transformations/ts_concat_forward.cpp deleted file mode 100644 index cdf26b5c2ee..00000000000 --- a/src/plugins/intel_gna/src/transformations/ts_concat_forward.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/ts_concat_forward.hpp" - -#include - -#include "backend/gna_limitations.hpp" -#include "common/graph_utils.hpp" -#include "openvino/core/rt_info.hpp" -#include "openvino/op/util/op_types.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "transformations/utils/transformation_helper.hpp" - -using namespace ov; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace ov::intel_gna; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::pass::helper; -using namespace ov::intel_gna::limitations; - -namespace { - -bool is_concat_sinked(const Output& output) { - auto concat_node = ov::as_type_ptr(output.get_node_shared_ptr()); - - const Shape concat_output_shape = concat_node->get_output_shape(0); - const int64_t axis = concat_node->get_concatenation_axis(); - if (graph_utils::get_first_valuable_dim_id(concat_output_shape) != axis) - return false; - - for (size_t i = 0; i < concat_node->get_input_size(); ++i) { - auto concat_input = concat_node->input_value(i); - - auto target_node = graph_utils::get_prev_node_skipping_certain(concat_input.get_node_shared_ptr(), - graph_utils::is_gna_non_functional_node); - std::shared_ptr transpose = ov::as_type_ptr(target_node); - - if (transpose && !Limitations::is_transpose_supported(transpose)) - return true; - } - - return false; -} - -} // namespace - -TSConcatForward::TSConcatForward() { - MATCHER_SCOPE(TSConcatForward); - - auto concat_node_label = wrap_type(is_concat_sinked); - - matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - - auto& concat_node_output = pattern_to_output.at(concat_node_label); - auto concat_node = as_type_ptr(concat_node_output.get_node_shared_ptr()); - - ov::AxisVector gather_ids = {}; - OutputVector concat_inputs = {}; - for (size_t i = 0; i < concat_node->get_input_size(); ++i) { - ov::Output concat_input = concat_node->input_value(i); - - auto target_node = graph_utils::get_prev_node_skipping_certain(concat_input.get_node_shared_ptr(), - graph_utils::is_gna_non_functional_node); - std::shared_ptr transpose = ov::as_type_ptr(target_node); - - ov::Shape transpose_shape = concat_input.get_shape(); - ov::AxisVector transpose_order(transpose_shape.size()); - if (transpose) { - std::shared_ptr transpose_const = - ov::as_type_ptr(transpose->get_input_node_shared_ptr(1)); - transpose_order = transpose_const->get_axis_vector_val(); - transpose_shape = transpose->get_input_shape(0); - concat_input = transpose->input_value(0); - } else { - std::iota(transpose_order.begin(), transpose_order.end(), 0); - } - ov::AxisVector slice_ids = - graph_utils::make_gather_indexes_from_transpose_axes(transpose_shape, transpose_order); - // shift slice indexes and insert at the end of the gather indexes vector - size_t id = gather_ids.size(); - std::for_each(slice_ids.begin(), slice_ids.end(), [&id](size_t& i) { - i += id; - }); - gather_ids.insert(gather_ids.end(), slice_ids.begin(), slice_ids.end()); - - std::vector reshape_dims = {1, -1}; - auto reshape_input_const = - std::make_shared(ov::element::i64, ov::Shape{reshape_dims.size()}, reshape_dims); - auto reshape_input = std::make_shared(concat_input, reshape_input_const, false); - concat_inputs.push_back(reshape_input->output(0)); - } - - // new concat node - size_t concat_axis = 1; - auto concat_new = std::make_shared(concat_inputs, concat_axis); - - // gather node - size_t gather_axis = 1; - auto gather_const_axis = std::make_shared(ov::element::u8, ov::Shape{}, gather_axis); - auto gather_const_ids = std::make_shared(ov::element::i64, ov::Shape{gather_ids.size()}, gather_ids); - auto gather_node = std::make_shared(concat_new, gather_const_ids, gather_const_axis); - - // reshape after gather - ov::Shape concat_shape_out = concat_node->get_output_shape(0); - auto reshape_output_const = - std::make_shared(ov::element::i64, ov::Shape{concat_shape_out.size()}, concat_shape_out); - auto reshape_output = std::make_shared(gather_node, reshape_output_const, false); - - // skip reshape if the input and output shapes are the same - if (graph_utils::are_shapes_equal(reshape_output->get_input_shape(0), reshape_output->get_output_shape(0))) { - ov::replace_node_update_name(concat_node, gather_node); - } else { - ov::replace_node_update_name(concat_node, reshape_output); - } - - return true; - }; - - auto m = std::make_shared(concat_node_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} diff --git a/src/plugins/intel_gna/src/transformations/ts_concat_forward.hpp b/src/plugins/intel_gna/src/transformations/ts_concat_forward.hpp deleted file mode 100644 index aa41b9e1bc5..00000000000 --- a/src/plugins/intel_gna/src/transformations/ts_concat_forward.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief This transformation is part of Transpose/Gather sinking group of transformations. - * This transformation moves Transpose through Concat layer. It changes Concat axis. - * Currently GNA plugin has restrictions working with Concat layers. - * It doesn't support all types of Concat layers. This transformation allows to remove Transpose layer - * on the Concat input and replace it with Gather layer on the output ensuring supported Concat axis. - * Substitute graph from - * Any#1 ... Any#K ... Any#N - * | | | - * | Transpose | - * | | | - * Concat - * | - * Any#M - * to - * Any#1 ... Any#K ... Any#N - * | | | - * Reshape Reshape Reshape - * | | | - * Concat - * | - * Gather - * | - * Reshape - * | - * Any#M - */ -class TSConcatForward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("TSConcatForward", "0"); - TSConcatForward(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/ts_split_backward.cpp b/src/plugins/intel_gna/src/transformations/ts_split_backward.cpp deleted file mode 100644 index 8935b49349a..00000000000 --- a/src/plugins/intel_gna/src/transformations/ts_split_backward.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/ts_split_backward.hpp" - -#include - -#include "backend/gna_limitations.hpp" -#include "common/graph_utils.hpp" -#include "openvino/core/rt_info.hpp" -#include "openvino/op/util/op_types.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "transformations/rt_info/transpose_sinking_attr.hpp" -#include "transformations/utils/transformation_helper.hpp" - -using namespace ov; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace ov::intel_gna::graph_utils; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::pass::helper; -using namespace ov::intel_gna::limitations; -using namespace ov::intel_gna::graph_utils; - -namespace { - -bool is_split_sinked(const Output& output) { - auto split_node = output.get_node_shared_ptr(); - for (size_t output_idx = 0; output_idx < split_node->get_output_size(); ++output_idx) { - for (auto& input : split_node->get_output_target_inputs(output_idx)) { - auto target_node = - get_next_node_skipping_certain(input.get_node()->shared_from_this(), is_gna_non_functional_node); - std::shared_ptr transpose = ov::as_type_ptr(target_node); - if (transpose && !Limitations::is_transpose_supported(transpose)) - return true; - } - } - return false; -} -} // namespace - -TSSplitBackward::TSSplitBackward() { - MATCHER_SCOPE(TSSplitBackward); - - auto split_node_label = wrap_type(is_split_sinked); - - matcher_pass_callback matcher_pass_callback = [=](Matcher& m) { - const auto& pattern_to_output = m.get_pattern_value_map(); - - auto& split_node_label_output = pattern_to_output.at(split_node_label); - std::shared_ptr split_node = as_type_ptr(split_node_label_output.get_node_shared_ptr()); - if (!split_node) { - split_node = as_type_ptr(split_node_label_output.get_node_shared_ptr()); - } - - ov::AxisVector gather_ids = {}; - std::vector gather_indices_vecs; - std::vector split_slices; - for (size_t output_idx = 0; output_idx < split_node->get_output_size(); ++output_idx) { - for (auto& input : split_node->get_output_target_inputs(output_idx)) { - auto target_node = - get_next_node_skipping_certain(input.get_node()->shared_from_this(), is_gna_non_functional_node); - std::shared_ptr transpose = ov::as_type_ptr(target_node); - - ov::Shape transpose_shape = split_node->get_output_shape(output_idx); - ov::AxisVector transpose_order(transpose_shape.size()); - - if (transpose) { - std::shared_ptr transpose_const = - ov::as_type_ptr(transpose->get_input_node_shared_ptr(1)); - transpose_order = transpose_const->get_axis_vector_val(); - transpose_shape = transpose->get_input_shape(0); - } else { - std::iota(transpose_order.begin(), transpose_order.end(), 0); - } - - ov::AxisVector slice_ids = - graph_utils::make_gather_indexes_from_transpose_axes(transpose_shape, transpose_order); - // shift slice indexes and insert at the end of the gather indexes vector - size_t id = gather_ids.size(); - std::for_each(slice_ids.begin(), slice_ids.end(), [&id](size_t& i) { - i += id; - }); - gather_ids.insert(gather_ids.end(), slice_ids.begin(), slice_ids.end()); - // collect slice sizes - split_slices.push_back(slice_ids.size()); - } - } - - const Shape& split_input_shape = split_node->get_input_shape(0); - const size_t split_input_dims = std::accumulate(split_input_shape.begin(), - split_input_shape.end(), - std::size_t{1}, - std::multiplies()); - - const Shape reshape_input_shape = {1, split_input_dims}; - auto reshape_input_const = std::make_shared(ov::element::i64, ov::Shape{2}, reshape_input_shape); - auto reshape_input = std::make_shared(split_node->input_value(0), reshape_input_const, false); - - ov::copy_runtime_info(split_node, {reshape_input, reshape_input_const}); - - std::shared_ptr gather; - auto gather_axis = std::make_shared(ov::element::i64, ov::Shape{}, 1); - auto gather_indices = std::make_shared(ov::element::i64, ov::Shape{gather_ids.size()}, gather_ids); - if (graph_utils::are_shapes_equal(split_input_shape, reshape_input_shape)) { - gather = std::make_shared(split_node->input_value(0), gather_indices, gather_axis); - } else { - gather = std::make_shared(reshape_input, gather_indices, gather_axis); - } - - auto split_new_axis = std::make_shared(ov::element::i64, ov::Shape{}, 1); - auto split_new_lengths = - std::make_shared(ov::element::i64, ov::Shape{split_slices.size()}, split_slices); - auto split_new = std::make_shared(gather, split_new_axis, split_new_lengths); - - ov::copy_runtime_info(split_node, {gather_axis, gather_indices, gather, split_new_axis, split_new}); - - for (size_t output_idx = 0; output_idx < split_node->get_output_size(); ++output_idx) { - for (auto& input : split_node->get_output_target_inputs(output_idx)) { - auto target_node = get_next_node_skipping_certain(input.get_node()->shared_from_this(), - graph_utils::is_gna_non_functional_node); - std::shared_ptr transpose = ov::as_type_ptr(target_node); - if (transpose) { - auto reshape_output_const_new = - std::make_shared(ov::element::i64, - ov::Shape{transpose->get_output_shape(0).size()}, - transpose->get_output_shape(0)); - auto reshape_output_new = - std::make_shared(split_new->output(output_idx), reshape_output_const_new, false); - ov::copy_runtime_info(split_node, {reshape_output_const_new, reshape_output_new}); - ov::replace_node_update_name(transpose, reshape_output_new); - } else { - for (auto consumer : split_node->output(output_idx).get_target_inputs()) { - consumer.replace_source_output(split_new->output(output_idx)); - } - } - } - } - return true; - }; - - auto m = std::make_shared(split_node_label, matcher_name); - register_matcher(m, matcher_pass_callback); -} diff --git a/src/plugins/intel_gna/src/transformations/ts_split_backward.hpp b/src/plugins/intel_gna/src/transformations/ts_split_backward.hpp deleted file mode 100644 index f6aa866aeda..00000000000 --- a/src/plugins/intel_gna/src/transformations/ts_split_backward.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief This transformation is a part of Transpose/Gather sinking group of transformations. - * This transformation moves Transpose through Split layer. It changes Split axis. - * Currently GNA plugin has restrictions working with Split layers. - * It doesn't support any Split layers. This transformation allows to remove Transpose layer - * on the Split output and replace it with a Gather layer on the input with ensuring supported Split axis. - * Substitute from - * Any#1 - * | - * Split - * | | | - * | Transpose | - * | | | - * Any#2 .. Any#K .. Any#N - * to - * Any#1 - * | - * Reshape - * | - * Gather - * | - * Split - * | | | - * Reshape Reshape Reshape - * | | | - * Any#2 .. Any#K .. Any#N - */ -class TSSplitBackward : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("TSSplitBackward", "0"); - TSSplitBackward(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/unfuse_reshape_and_transpose.cpp b/src/plugins/intel_gna/src/transformations/unfuse_reshape_and_transpose.cpp deleted file mode 100644 index f56b0ae29bb..00000000000 --- a/src/plugins/intel_gna/src/transformations/unfuse_reshape_and_transpose.cpp +++ /dev/null @@ -1,266 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/unfuse_reshape_and_transpose.hpp" - -#include -#include -#include -#include -#include - -#include "transformations/utils/transformation_helper.hpp" -#include "transformations/utils/utils.hpp" - -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::pass::helper; - -Unfuse2dto4dReshapeAndTranspose::Unfuse2dto4dReshapeAndTranspose() { - MATCHER_SCOPE(Unfuse2dto4dReshapeAndTranspose); - auto is_required_reshape = [](const ngraph::Output& value) { - auto input_shape = value.get_node_shared_ptr()->get_input_shape(0); - auto output_shape = value.get_node_shared_ptr()->get_output_shape(0); - return ((input_shape.size() == 2) && (output_shape.size() == 4) && - ((output_shape.at(1) == 1) || (output_shape.at(2) * output_shape.at(3) == 1))); - }; - const auto reshape = ngraph::pattern::wrap_type(is_required_reshape); - auto fq = ngraph::pattern::wrap_type({reshape, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - const auto conv = ngraph::pattern::wrap_type( - {std::make_shared(ngraph::OutputVector{reshape, fq}), ngraph::pattern::any_input()}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - const auto reshape_node = pattern_map.at(reshape).get_node_shared_ptr(); - auto consumers = reshape_node->output(0).get_target_inputs(); - - auto N = reshape_node->get_output_shape(0)[0]; - auto C = reshape_node->get_output_shape(0)[1]; - auto H = reshape_node->get_output_shape(0)[2]; - auto W = reshape_node->get_output_shape(0)[3]; - - // Create reshape NxW => NxHxWxC (C or HxW is equal to 1) - auto data = reshape_node->input_value(0); - auto reshape_nhwc_const = - ngraph::opset8::Constant::create(ngraph::element::i64, ngraph::Shape{4}, ngraph::Shape{N, H, W, C}); - auto reshape_nhwc = register_new_node(data, reshape_nhwc_const, false); - reshape_nhwc->set_friendly_name(reshape_node->get_friendly_name() + "/Reshape"); - - // Create transpose NxHxWxC => NxCxHxW - auto transpose_const = ngraph::opset8::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 3, 1, 2}); - auto transpose = register_new_node(reshape_nhwc, transpose_const); - transpose->set_friendly_name(reshape_node->get_friendly_name()); - - ngraph::copy_runtime_info(reshape, {reshape_nhwc, transpose}); - for (auto& consumer : consumers) { - consumer.replace_source_output(transpose); - } - - return true; - }; - - auto m = std::make_shared(conv, matcher_name); - this->register_matcher(m, callback); -} - -Unfuse4dto2dReshapeAndTranspose::Unfuse4dto2dReshapeAndTranspose() { - MATCHER_SCOPE(Unfuse4dto2dReshapeAndTranspose); - auto is_required_reshape = [](const ngraph::Output& value) { - auto input_shape = value.get_node_shared_ptr()->get_input_shape(0); - auto output_shape = value.get_node_shared_ptr()->get_output_shape(0); - return ((input_shape.size() == 4) && (output_shape.size() == 2) && - ((input_shape.at(1) == 1) || (input_shape.at(2) * input_shape.at(3) == 1))); - }; - // Convolution - auto conv = ngraph::pattern::wrap_type( - {ngraph::pattern::any_input(), ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - auto fq_conv = ngraph::pattern::wrap_type({conv, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - // Bias - auto bias = - ngraph::pattern::wrap_type({conv, ngraph::pattern::any_input()}, consumers_and_rank(1, 4)); - auto fq_bias = ngraph::pattern::wrap_type({bias, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - // Max Pooling - auto max_pool_conv = ngraph::pattern::wrap_type({conv}, consumers_and_rank(1, 4)); - auto max_pool_fq_conv = ngraph::pattern::wrap_type({fq_conv}, consumers_and_rank(1, 4)); - auto max_pool_bias = ngraph::pattern::wrap_type({bias}, consumers_and_rank(1, 4)); - auto max_pool_fq_bias = ngraph::pattern::wrap_type({fq_bias}, consumers_and_rank(1, 4)); - // Activation - auto fq_fq_conv = ngraph::pattern::wrap_type({fq_conv, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - auto fq_fq_bias = ngraph::pattern::wrap_type({fq_bias, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - auto act_conv = ngraph::pattern::wrap_type({conv}, consumers_and_rank(1, 4)); - auto act_bias = ngraph::pattern::wrap_type({bias}, consumers_and_rank(1, 4)); - auto act_max_pool_conv = - ngraph::pattern::wrap_type({max_pool_conv}, consumers_and_rank(1, 4)); - auto act_max_pool_bias = - ngraph::pattern::wrap_type({max_pool_bias}, consumers_and_rank(1, 4)); - auto act_fq_fq_conv = ngraph::pattern::wrap_type({fq_fq_conv}, consumers_and_rank(1, 4)); - auto act_fq_fq_bias = ngraph::pattern::wrap_type({fq_fq_bias}, consumers_and_rank(1, 4)); - auto fq_max_pool_fq_conv = ngraph::pattern::wrap_type({max_pool_fq_conv, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - auto act_fq_max_pool_fq_conv = - ngraph::pattern::wrap_type({fq_max_pool_fq_conv}, consumers_and_rank(1, 4)); - auto fq_max_pool_fq_bias = ngraph::pattern::wrap_type({max_pool_fq_bias, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - auto act_fq_max_pool_fq_bias = - ngraph::pattern::wrap_type({fq_max_pool_fq_bias}, consumers_and_rank(1, 4)); - auto fq_act_fq_fq_conv = ngraph::pattern::wrap_type({act_fq_fq_conv, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - auto fq_act_fq_fq_bias = ngraph::pattern::wrap_type({act_fq_fq_bias, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - auto fq_act_fq_max_pool_fq_conv = - ngraph::pattern::wrap_type({act_fq_max_pool_fq_conv, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - auto fq_act_fq_max_pool_fq_bias = - ngraph::pattern::wrap_type({act_fq_max_pool_fq_bias, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - consumers_and_rank(1, 4)); - auto root_reshape = std::make_shared(ngraph::OutputVector{conv, - bias, - max_pool_conv, - max_pool_fq_conv, - max_pool_bias, - max_pool_fq_bias, - fq_conv, - fq_bias, - act_conv, - act_bias, - act_max_pool_conv, - act_max_pool_bias, - fq_act_fq_fq_conv, - fq_act_fq_fq_bias, - fq_act_fq_max_pool_fq_conv, - fq_act_fq_max_pool_fq_bias}); - const auto reshape_const = ngraph::pattern::wrap_type(); - const auto reshape = - ngraph::pattern::wrap_type({root_reshape, reshape_const}, is_required_reshape); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - const auto reshape_node = pattern_map.at(reshape).get_node_shared_ptr(); - const auto reshape_const_node = pattern_map.at(reshape_const).get_node_shared_ptr(); - auto consumers = reshape_node->output(0).get_target_inputs(); - - // Create transpose NxCxHxW => NxHxWxC - auto data = reshape_node->input_value(0); - auto transpose_const = ngraph::opset8::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 2, 3, 1}); - auto transpose = register_new_node(data, transpose_const); - transpose->set_friendly_name(reshape_node->get_friendly_name() + "/Transpose"); - - // Create reshape NxHxWxC => NxW (C or HxW is equal to 1) - auto reshape_nw = register_new_node(transpose, reshape_const_node, false); - reshape_nw->set_friendly_name(reshape_node->get_friendly_name()); - - ngraph::copy_runtime_info(reshape_node, {transpose, reshape_nw}); - for (auto& consumer : consumers) { - consumer.replace_source_output(reshape_nw); - } - - return true; - }; - - auto m = std::make_shared(reshape, matcher_name); - this->register_matcher(m, callback); -} diff --git a/src/plugins/intel_gna/src/transformations/unfuse_reshape_and_transpose.hpp b/src/plugins/intel_gna/src/transformations/unfuse_reshape_and_transpose.hpp deleted file mode 100644 index 466f078101b..00000000000 --- a/src/plugins/intel_gna/src/transformations/unfuse_reshape_and_transpose.hpp +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_gna { -namespace pass { - -/** - * @brief Replace 2d->4d reshape to pair of 2 reshapes (before Convolution) - * Before: - * [N, HW] - * | - * Reshape - * | - * [N, C, H, W] - * | - * Convolution - * - * After (TransposeSinking friendly): - * [N, HW] - * | - * Reshape - * | - * [N, H, W, C] - * | - * Reshape - * | - * [N, C, H, W] - * | - * Convolution - */ -class Unfuse2dto4dReshapeAndTranspose : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("Unfuse2dto4dReshapeAndTranspose", "0"); - Unfuse2dto4dReshapeAndTranspose(); -}; - -/** - * @brief Replace 2d->4d reshape to pair of 2 reshapes (after Convolution) - * Before: - * Convolution (optionally + bias/pooling/activation) - * | - * [N, C, H, W] - * | - * Reshape - * | - * [N, HW] - * - * After (TransposeSinking friendly): - * Convolution - * | - * [N, C, H, W] - * | - * Reshape - * | - * [N, H, W, C] - * | - * Reshape - * | - * [N, HW] - * - */ -class Unfuse4dto2dReshapeAndTranspose : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("Unfuse4dto2dReshapeAndTranspose", "0"); - Unfuse4dto2dReshapeAndTranspose(); -}; - -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/utils/gather_sinking_utils.cpp b/src/plugins/intel_gna/src/transformations/utils/gather_sinking_utils.cpp deleted file mode 100644 index a1c21383394..00000000000 --- a/src/plugins/intel_gna/src/transformations/utils/gather_sinking_utils.cpp +++ /dev/null @@ -1,367 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/utils/gather_sinking_utils.hpp" - -#include -#include -#include - -#include "common/graph_utils.hpp" -#include "openvino/op/util/op_types.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/pattern/op/label.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "openvino/util/common_util.hpp" -#include "openvino/util/log.hpp" -#include "transformations/rt_info/gather_sinking_attr.hpp" -#include "transformations/utils/transformation_helper.hpp" - -using namespace ov; -using namespace ov::intel_gna::graph_utils; -using namespace ov::intel_gna::rt_info; -using namespace ov::opset12; -using namespace ov::pass::pattern; -using namespace ov::intel_gna::pass::helper; - -namespace gather_sinking { -using NodePtr = std::shared_ptr; - -GatherInputsInfo get_first_gather_input(NodePtr node) { - for (size_t input_idx = 0; input_idx < node->get_input_size(); ++input_idx) { - NodePtr input_node = node->get_input_node_shared_ptr(input_idx); - auto gather_node = as_type_ptr(input_node); - if (!gather_node) - continue; - auto indices_const_node = as_type_ptr(gather_node->input_value(1).get_node_shared_ptr()); - if (!indices_const_node) - continue; - auto axis_const_node = as_type_ptr(gather_node->input_value(2).get_node_shared_ptr()); - if (!axis_const_node) - continue; - { - GatherInputsInfo input_info; - input_info.gather = gather_node; - input_info.indices_const = indices_const_node; - input_info.axis_const = axis_const_node; - input_info.input_idx = input_idx; - return input_info; - } - } - - return GatherInputsInfo(); -} - -namespace sink_forward { -/** @brief - * Inserts inverted Gather layer on all @main_node inputs except input from GatherInputsInfo argument - * Works only with 1D indices. - */ -void update_input_gather(NodePtr main_node, - const GatherInputsInfo& gather_input_info, - const int64_t* a_gather_negative_axis) { - if (gather_input_info.isEmpty() || has_dynamic_rank_input(main_node)) - return; - - /* It's simpler to work with negative gather axis since it doesn't depend on shape unsqueezeing. - * Converts gather axis to a negative form - */ - int64_t gather_negative_axis = {}; - if (a_gather_negative_axis) - gather_negative_axis = *a_gather_negative_axis; - else - gather_negative_axis = get_normalized_negative_gather_axis( - gather_input_info.axis_const, - gather_input_info.gather->get_input_partial_shape(0).rank().get_length()); - - const std::vector gather_indices = get_normalized_gather_indices(gather_input_info.indices_const); - const std::vector reversed_gather_indices = reverse_gather_indexes(gather_indices); - - const auto indices_element_type = gather_input_info.indices_const->get_element_type(); - const auto axis_element_type = gather_input_info.axis_const->get_element_type(); - - const auto max_input_rank = get_max_input_rank(main_node); - if (max_input_rank < 0) - return; - - for (size_t i = 0; i < main_node->get_input_size(); ++i) { - auto input_node = main_node->input_value(i); - if (i == gather_input_info.input_idx) { - auto gather_parent = input_node.get_node()->input_value(0); - main_node->input(i).replace_source_output(gather_parent); - } else { - /* Doesn't add Gather layer if input_node_shape[axis] == 1 since it is useless and causes an invalid result. - * Input nodes can have different shapes. That shapes can have smaller or larger ranks. To manage it we need - * to find max input shape rank and unsqueeze all input shapes to it. - */ - const Shape unsqueezed_input_shape = unsqueeze_shape(input_node.get_shape(), max_input_rank); - if (get_dim_by_axis(unsqueezed_input_shape, gather_negative_axis) == 1) - continue; - - auto new_indices_const = std::make_shared(indices_element_type, - Shape{reversed_gather_indices.size()}, - reversed_gather_indices); - - const int64_t gather_positive_axis = - convert_axis_to_positive(gather_negative_axis, input_node.get_partial_shape().rank().get_length()); - auto new_axis_const = std::make_shared(axis_element_type, Shape{}, gather_positive_axis); - - auto new_gather = std::make_shared(input_node, new_indices_const, new_axis_const); - - main_node->input(i).replace_source_output(new_gather->output(0)); - - copy_runtime_info(input_node.get_node_shared_ptr(), {new_gather, new_indices_const, new_axis_const}); - } - } -} - -NodeVector insert_output_gather(NodePtr main_node, const GatherInputsInfo& gather_input_info) { - if (gather_input_info.isEmpty()) - return {}; - - const int64_t gather_negative_axis = - get_normalized_negative_gather_axis(gather_input_info.axis_const, - gather_input_info.gather->get_input_partial_shape(0).rank().get_length()); - const auto axis_element_type = gather_input_info.axis_const->get_element_type(); - - NodeVector new_nodes; - for (size_t i = 0; i < main_node->get_output_size(); ++i) { - auto main_node_consumers = main_node->output(i).get_target_inputs(); - - auto new_indices_const = gather_input_info.indices_const->clone_with_new_inputs({}); - - const int64_t gather_positive_axis = - convert_axis_to_positive(gather_negative_axis, - main_node->output(i).get_partial_shape().rank().get_length()); - auto new_axis_const = std::make_shared(axis_element_type, Shape{}, gather_positive_axis); - auto new_gather = std::make_shared(main_node->output(i), new_indices_const, new_axis_const); - - for (auto& consumer : main_node_consumers) { - consumer.replace_source_output(new_gather); - } - - copy_runtime_info(main_node, {new_gather, new_indices_const, new_axis_const}); - swap_output_names(main_node->output(i), new_gather->output(0)); - - if (main_node->get_output_size() > 1) - new_gather->set_friendly_name(main_node->get_friendly_name() + "." + std::to_string(i)); - else - swap_friendly_names(new_gather, main_node); - - new_nodes.push_back(new_gather); - } - - return new_nodes; -} - -} // namespace sink_forward - -namespace sink_backward { - -NodeVector insert_gather_before_node(NodePtr main_node, - const std::shared_ptr& indices_const, - const std::shared_ptr& axis_const, - const std::shared_ptr& gather_node, - std::vector input_indices) { - if (has_dynamic_rank_input(main_node)) - return {}; - - if (input_indices.empty()) { - input_indices.resize(main_node->get_input_size()); - std::iota(input_indices.begin(), input_indices.end(), 0); - } - - const int64_t gather_negative_axis = - get_normalized_negative_gather_axis(axis_const, gather_node->get_input_partial_shape(0).rank().get_length()); - const auto axis_element_type = axis_const->get_element_type(); - - const auto max_input_rank = get_max_input_rank(main_node); - if (max_input_rank < 0) - return {}; - - NodeVector new_nodes; - for (const auto& i : input_indices) { - auto input_node = main_node->input_value(i); - - const Shape unsqueezed_input_shape = unsqueeze_shape(input_node.get_shape(), max_input_rank); - if (get_dim_by_axis(unsqueezed_input_shape, gather_negative_axis) == 1) - continue; - - auto new_indices_const = indices_const->clone_with_new_inputs({}); - - const int64_t gather_positive_axis = - convert_axis_to_positive(gather_negative_axis, input_node.get_partial_shape().rank().get_length()); - auto new_axis_const = std::make_shared(axis_element_type, Shape{}, gather_positive_axis); - - auto new_gather = std::make_shared(input_node, new_indices_const, new_axis_const); - - main_node->input(i).replace_source_output(new_gather->output(0)); - - copy_runtime_info(input_node.get_node_shared_ptr(), {new_gather, new_indices_const, new_axis_const}); - - new_nodes.push_back(new_gather); - } - - return new_nodes; -} - -} // namespace sink_backward - -namespace { -#define CHECK_GATHER_SINKING_SUPPORTED(TYPE, node) \ - if (dynamic_cast(node)) { \ - return true; \ - } - -bool CanPropagateGatherForwardThrough(Node* node) { - CHECK_GATHER_SINKING_SUPPORTED(ov::op::util::UnaryElementwiseArithmetic, node); - CHECK_GATHER_SINKING_SUPPORTED(Clamp, node); - CHECK_GATHER_SINKING_SUPPORTED(Elu, node); - CHECK_GATHER_SINKING_SUPPORTED(SoftPlus, node); - CHECK_GATHER_SINKING_SUPPORTED(LogicalNot, node); - CHECK_GATHER_SINKING_SUPPORTED(Convert, node); - CHECK_GATHER_SINKING_SUPPORTED(ov::op::util::BinaryElementwiseArithmetic, node); - CHECK_GATHER_SINKING_SUPPORTED(Gather, node); - CHECK_GATHER_SINKING_SUPPORTED(Reshape, node); - CHECK_GATHER_SINKING_SUPPORTED(MatMul, node); - return false; -} - -#undef CHECK_GATHER_SINKING_SUPPORTED - -bool can_gather_propagate_forward(NodePtr node) { - for (const auto& output : node->outputs()) { - for (auto& consumer_input : output.get_target_inputs()) { - if (!CanPropagateGatherForwardThrough(consumer_input.get_node())) - return false; - } - } - - return true; -} - -} // namespace - -void update_forward_gather_sinking_ability(NodePtr node) { - if (!can_gather_propagate_forward(node)) - mark_as_no_gather_sinking_node(node); -} - -namespace { - -struct GatherInfo { - bool isEmpty() const { - return indices.empty(); - } - bool operator==(const GatherInfo& another) { - if (indices.size() != another.indices.size()) - return false; - if (!are_shapes_equal(indices, another.indices)) - return false; - return axis == another.axis; - } - bool operator!=(const GatherInfo& another) { - return !(*this == another); - } - - ov::AxisVector indices; - int64_t axis = {}; -}; - -GatherInfo GetGatherInfo(Node* node) { - GatherInfo gather_info; - - auto gather_node = dynamic_cast(node); - if (!gather_node) - return {}; - - auto constant_node = as_type_ptr(gather_node->input_value(1).get_node_shared_ptr()); - if (!constant_node) - return {}; - - gather_info.indices = constant_node->get_axis_vector_val(); - - constant_node = as_type_ptr(gather_node->input_value(2).get_node_shared_ptr()); - if (!constant_node) - return {}; - - gather_info.axis = constant_node->get_axis_vector_val()[0]; - - return gather_info; -} - -bool has_same_output_gather_nodes(NodePtr main_node) { - GatherInfo first_gather_info; - { - Node* first_consumer = find_first_consumer(main_node); - if (!first_consumer) - return false; - first_gather_info = GetGatherInfo(first_consumer); - if (first_gather_info.isEmpty()) - return false; - } - - for (size_t output_idx = 0; output_idx < main_node->get_output_size(); ++output_idx) { - for (auto& input : main_node->get_output_target_inputs(output_idx)) { - GatherInfo gather_info = GetGatherInfo(input.get_node()); - if (gather_info.isEmpty() || gather_info != first_gather_info) - return false; - } - } - - return true; -} - -} // namespace - -bool has_same_output_gather_nodes(const Output& output) { - return has_same_output_gather_nodes(output.get_node_shared_ptr()); -} - -void remove_single_output_consumers(NodePtr node) { - for (size_t output_idx = 0; output_idx < node->get_output_size(); ++output_idx) { - for (auto& input : node->get_output_target_inputs(output_idx)) { - Node* consumer = input.get_node(); - if (consumer->get_output_size() != 1) - continue; - consumer->output(0).replace(node->output(output_idx)); - } - } -} - -bool is_gather_sinking_enabled(const Output& output) { - auto node = ov::as_type_ptr(output.get_node_shared_ptr()); - if (!node) - return false; - return is_gather_sinking_node(output.get_node_shared_ptr()); -} - -bool is_split_sinked(const Output& output) { - return find_first_input_node(output.get_node_shared_ptr()) && is_gather_sinking_node(output); -} - -int64_t normalize_negative_gather_axis(int64_t axis, ov::Rank::value_type gather_input_rank) { - if (axis < 0) - return axis; - return axis - gather_input_rank; -} - -int64_t get_normalized_negative_gather_axis(const std::shared_ptr& axis, - ov::Rank::value_type gather_input_rank) { - return normalize_negative_gather_axis(axis->cast_vector()[0], gather_input_rank); -} - -bool get_gather_axis(const std::shared_ptr& gather, int64_t& axis) { - auto gather_node = as_type_ptr(gather); - if (!gather_node) - return false; - auto output_gather_axis_node = as_type_ptr(gather->input_value(2).get_node_shared_ptr()); - if (!output_gather_axis_node) - return false; - axis = get_normalized_negative_gather_axis(output_gather_axis_node, - gather->get_input_partial_shape(0).rank().get_length()); - return true; -} - -} // namespace gather_sinking diff --git a/src/plugins/intel_gna/src/transformations/utils/gather_sinking_utils.hpp b/src/plugins/intel_gna/src/transformations/utils/gather_sinking_utils.hpp deleted file mode 100644 index 036b4c07f4b..00000000000 --- a/src/plugins/intel_gna/src/transformations/utils/gather_sinking_utils.hpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "openvino/op/util/op_types.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/pattern/op/label.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "openvino/util/common_util.hpp" -#include "openvino/util/log.hpp" - -namespace gather_sinking { - -struct GatherInputsInfo { - std::shared_ptr gather; - std::shared_ptr indices_const; - std::shared_ptr axis_const; - size_t input_idx; - - bool isEmpty() const { - return !gather || !indices_const || !axis_const; - } -}; - -/** - * @brief Finds node first input that is a Gather operation and returns filled GatherInputsInfo - * for it - */ -GatherInputsInfo get_first_gather_input(std::shared_ptr); - -/** - * @brief Checks if @arg has any input node that is a Gather operation - */ -template -bool if_node_has_gather_inputs(const ov::Output& output, GatherInfoPredicate gather_info_predicate) { - GatherInputsInfo inputs_info = get_first_gather_input(output.get_node_shared_ptr()); - if (inputs_info.isEmpty()) - return false; - - return gather_info_predicate(inputs_info); -} - -namespace sink_forward { -/** - * @brief Inserts reversed Gather on @args main_node inputs. Removes input Gather specified in @arg - * transpose_input_info - */ -void update_input_gather(std::shared_ptr main_node, - const GatherInputsInfo&, - const int64_t* a_gather_negative_axis = nullptr); - -/** - * @brief Inserts Gather on each main_node output with the order specified in @arg GatherInputsInfo - */ -ov::NodeVector insert_output_gather(std::shared_ptr main_node, const GatherInputsInfo&); -} // namespace sink_forward - -namespace sink_backward { -/** - * @brief Inserts Gather layers on each input of @arg main_node with cloned indices and axes constants - */ -ov::NodeVector insert_gather_before_node(std::shared_ptr main_node, - const std::shared_ptr& indices_const, - const std::shared_ptr& axes_const, - const std::shared_ptr& gather_node, - std::vector input_indexes = {}); -} // namespace sink_backward - -void update_forward_gather_sinking_ability(std::shared_ptr); - -/** - * @brief Checks if @arg has consumers that all are the same Gather operation. If no consumers at all - * returns false. - */ -bool has_same_output_gather_nodes(const ov::Output&); - -/** - * Removes all direct node consumers that have one output - */ -void remove_single_output_consumers(std::shared_ptr); - -/** - * @brief Checks if Output is Gather node and it could be sinked - */ -bool is_gather_sinking_enabled(const ov::Output& output); - -/** - * @brief Finds Split first input Gather node and it could be sinked - */ -bool is_split_sinked(const ov::Output& output); - -/** - * @brief Converts Gather indices to negative form - */ -int64_t normalize_negative_gather_axis(int64_t axis, ov::Rank::value_type gather_input_rank); - -/** - * @brief Gets Gather indices from Constant converted into negative form - */ -int64_t get_normalized_negative_gather_axis(const std::shared_ptr& axis, - ov::Rank::value_type gather_input_rank); - -/** - * @brief Gets Gather axis if it's stored in a constant - */ -bool get_gather_axis(const std::shared_ptr& gather, int64_t& axis); - -} // namespace gather_sinking diff --git a/src/plugins/intel_gna/src/transformations/utils/transformation_helper.cpp b/src/plugins/intel_gna/src/transformations/utils/transformation_helper.cpp deleted file mode 100644 index 125259cc6d5..00000000000 --- a/src/plugins/intel_gna/src/transformations/utils/transformation_helper.cpp +++ /dev/null @@ -1,259 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformation_helper.hpp" - -#include "common/graph_utils.hpp" -#include "log/debug.hpp" -#include "openvino/core/rt_info.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include "ops/gna_convolution.hpp" -#include "ops/gna_max_pool.hpp" -#include "transformations/rt_info/transpose_sinking_attr.hpp" - -using namespace ov::opset12; -using namespace ov::intel_gna; - -namespace ov { -namespace intel_gna { -namespace pass { -namespace helper { - -void GetConvData(std::shared_ptr conv, ConvData& conv_data) { - OPENVINO_ASSERT(conv); - conv_data.output_height = conv->get_output_shape(0)[2]; - conv_data.output_width = conv->get_output_shape(0)[3]; - conv_data.input_channel_count = conv->input_value(0).get_shape()[1]; - conv_data.input_height = conv->input_value(0).get_shape()[2]; - conv_data.input_width = conv->input_value(0).get_shape()[3]; - conv_data.filter_count = conv->input_value(1).get_shape()[0]; - conv_data.filter_channel_count = conv->input_value(1).get_shape()[1]; - conv_data.filter_height = conv->input_value(1).get_shape()[2]; - conv_data.filter_width = conv->input_value(1).get_shape()[3]; - conv_data.filter_dilation_height = conv->get_dilations()[0]; - conv_data.filter_dilation_width = conv->get_dilations()[1]; - conv_data.filter_stride_height = conv->get_strides()[0]; - conv_data.filter_stride_width = conv->get_strides()[1]; - conv_data.output_channel_count = conv_data.filter_count; - conv_data.pads_begin_height = conv->get_pads_begin()[0]; - conv_data.pads_begin_width = conv->get_pads_begin()[1]; - conv_data.pads_end_height = conv->get_pads_end()[0]; - conv_data.pads_end_width = conv->get_pads_end()[1]; - conv_data.padding_type = conv->get_auto_pad(); - conv_data.element_type = conv->get_element_type(); -} - -void GetConvData(std::shared_ptr conv, ConvData& conv_data) { - OPENVINO_ASSERT(conv); - conv_data.output_height = conv->get_output_shape(0)[2]; - conv_data.output_width = conv->get_output_shape(0)[3]; - conv_data.input_channel_count = conv->input_value(0).get_shape()[3]; - conv_data.input_height = conv->input_value(0).get_shape()[1]; - conv_data.input_width = conv->input_value(0).get_shape()[2]; - conv_data.filter_count = conv->input_value(1).get_shape()[0]; - conv_data.filter_channel_count = conv->input_value(1).get_shape()[3]; - conv_data.filter_height = conv->input_value(1).get_shape()[1]; - conv_data.filter_width = conv->input_value(1).get_shape()[2]; - conv_data.filter_dilation_height = conv->get_dilations()[0]; - conv_data.filter_dilation_width = conv->get_dilations()[1]; - conv_data.filter_stride_height = conv->get_strides()[0]; - conv_data.filter_stride_width = conv->get_strides()[1]; - conv_data.output_channel_count = conv_data.filter_count; - conv_data.pads_begin_height = conv->get_pads_begin()[0]; - conv_data.pads_begin_width = conv->get_pads_begin()[1]; - conv_data.pads_end_height = conv->get_pads_end()[0]; - conv_data.pads_end_width = conv->get_pads_end()[1]; - conv_data.padding_type = conv->get_auto_pad(); - conv_data.element_type = conv->get_element_type(); -} - -std::function)> consumers_and_rank(const size_t expected_count, - const ov::Dimension& expected_rank) { - return [=](ov::Output output) -> bool { - return ov::pass::pattern::consumers_count(expected_count)(output) && - ov::pass::pattern::rank_equals(expected_rank)(output); - }; -} - -bool TransposeOrderMatches(std::shared_ptr transpose, std::vector order) { - if (!transpose) - return false; - const ov::Output& transpose_order = transpose->input_value(1); - auto transpose_order_dim = transpose_order.get_shape().size(); - - if (transpose_order_dim != 1 || transpose_order.get_shape()[0] != order.size()) - return false; - - auto const_with_order_values = std::dynamic_pointer_cast(transpose_order.get_node_shared_ptr()); - if (!const_with_order_values) - return false; - - const auto data = const_with_order_values->cast_vector(); - if (data.empty()) - return false; - - if (!graph_utils::are_shapes_equal(order, data)) - return false; - - return true; -} - -std::shared_ptr FlatCrop(ov::Output input, size_t offset, size_t size) { - return std::make_shared( - input, // data - Constant::create(ov::element::i64, ov::Shape{2}, {(size_t)0, offset}), // begin sice index - Constant::create(ov::element::i64, ov::Shape{2}, {(size_t)0, offset + size}), // end slice index - Constant::create(ov::element::i64, ov::Shape{2}, {(size_t)1, (size_t)1}), // strides - std::vector{1, 0}, // begin mask - std::vector{1, 0}); // end mask -} - -std::shared_ptr VerifyBiasGetConst(std::shared_ptr conv, std::shared_ptr add) { - auto add_const = std::dynamic_pointer_cast(add->input_value(1).get_node_shared_ptr()); - - // Check if it's really a bias and not just addition - if (add_const) { - auto bias_size = shape_size(add_const->get_shape()); - auto conv_filter_count = conv->get_output_shape(0)[1]; - if (bias_size == conv_filter_count) - return add_const; - } - return nullptr; -} - -std::shared_ptr InsertFQLayer(const std::shared_ptr fq_layer, - std::shared_ptr last_node) { - if (fq_layer != nullptr) { - auto new_fq = fq_layer->clone_with_new_inputs( - {last_node, - Constant::create(ov::element::f32, - ov::Shape{1}, - std::dynamic_pointer_cast(fq_layer->input_value(1).get_node_shared_ptr()) - ->cast_vector()), - Constant::create(ov::element::f32, - ov::Shape{1}, - std::dynamic_pointer_cast(fq_layer->input_value(2).get_node_shared_ptr()) - ->cast_vector()), - Constant::create(ov::element::f32, - ov::Shape{1}, - std::dynamic_pointer_cast(fq_layer->input_value(3).get_node_shared_ptr()) - ->cast_vector()), - Constant::create(ov::element::f32, - ov::Shape{1}, - std::dynamic_pointer_cast(fq_layer->input_value(4).get_node_shared_ptr()) - ->cast_vector())}); - copy_runtime_info(new_fq, fq_layer); - return new_fq; - } - return last_node; -} - -void remove_single_input_node(std::shared_ptr node) { - const ov::Shape input_node_shape = node->get_input_shape(0); - const ov::Shape output_node_shape = node->get_output_shape(0); - - std::shared_ptr node_parent = node->get_input_node_shared_ptr(0); - if (!node_parent) { - THROW_GNA_EXCEPTION << "The removing node has no parrent node"; - } - if (!graph_utils::are_shapes_equal(input_node_shape, output_node_shape)) { - auto reshape_const_node = - std::make_shared(ov::element::i64, ov::Shape{output_node_shape.size()}, output_node_shape); - node_parent = std::make_shared(node_parent, reshape_const_node, false); - } - - ov::replace_output_update_name(node->output(0), node_parent->output(0)); -} - -void swap_output_names(ov::Output output1, ov::Output output2) { - const auto node2_output_names = output2.get_names(); - output2.set_names(output1.get_names()); - output1.set_names(node2_output_names); -} - -void swap_friendly_names(std::shared_ptr node1, std::shared_ptr node2) { - const std::string node2_name = node2->get_friendly_name(); - node2->set_friendly_name(node1->get_friendly_name()); - node1->set_friendly_name(node2_name); -} - -void swap_names(std::shared_ptr node1, std::shared_ptr node2) { - swap_friendly_names(node1, node2); - swap_output_names(node1->output(0), node2->output(0)); -} - -ov::AxisVector reverse_transpose_order(const ov::AxisVector& axis_order) { - ov::AxisVector out(axis_order.size()); - for (size_t i = 0; i < axis_order.size(); i++) { - out.at(axis_order[i]) = i; - } - return out; -} - -ov::NodeVector find_input_transposes(const std::shared_ptr& node) { - ov::NodeVector transposes; - for (size_t input_idx = 0; input_idx < node->get_input_size(); ++input_idx) { - auto input_node = node->get_input_node_shared_ptr(input_idx); - auto transpose_node = ov::as_type_ptr(input_node); - if (transpose_node) - transposes.push_back(transpose_node); - } - - return transposes; -} - -void mark_input_transposes_as_nosinking(std::shared_ptr node) { - for (const auto& input : find_input_transposes(node)) - ov::mark_as_no_sinking_node(input); -} - -TransposeInfo get_first_input_transpose(const std::shared_ptr& node) { - for (size_t input_idx = 0; input_idx < node->get_input_size(); ++input_idx) { - std::shared_ptr input_node = node->get_input_node_shared_ptr(input_idx); - auto transpose_node = as_type_ptr(input_node); - if (!transpose_node) - continue; - auto constant_node = as_type_ptr(transpose_node->input_value(1).get_node_shared_ptr()); - if (!constant_node) - continue; - { - TransposeInfo input_info; - input_info.transpose = transpose_node; - input_info.transpose_const = constant_node; - return input_info; - } - } - - return {}; -} - -TransposeInfo get_first_output_transpose(const std::shared_ptr& node) { - for (size_t i = 0; i < node->get_output_size(); ++i) { - for (const auto& input : node->output(i).get_target_inputs()) { - Node* node = input.get_node(); - if (!dynamic_cast(node)) - continue; - auto transpose_node = as_type_ptr(node->shared_from_this()); - if (!transpose_node) - continue; - auto constant_node = as_type_ptr(transpose_node->input_value(1).get_node_shared_ptr()); - if (!constant_node) - continue; - { - TransposeInfo input_info; - input_info.transpose = transpose_node; - input_info.transpose_const = constant_node; - return input_info; - } - } - } - - return {}; -} - -} // namespace helper -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/src/transformations/utils/transformation_helper.hpp b/src/plugins/intel_gna/src/transformations/utils/transformation_helper.hpp deleted file mode 100644 index 2b9d4cc67d6..00000000000 --- a/src/plugins/intel_gna/src/transformations/utils/transformation_helper.hpp +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "openvino/opsets/opset12.hpp" -#include "ops/gna_convolution.hpp" - -namespace ov { -namespace intel_gna { -namespace pass { -namespace helper { - -struct ConvData { - size_t input_height; - size_t input_width; - size_t input_channel_count; - size_t filter_height; - size_t filter_width; - size_t filter_count; - size_t filter_channel_count; - size_t filter_dilation_height; - size_t filter_dilation_width; - size_t filter_stride_height; - size_t filter_stride_width; - size_t output_height; - size_t output_width; - size_t output_channel_count; - size_t pads_begin_width; - size_t pads_begin_height; - size_t pads_end_width; - size_t pads_end_height; - ngraph::op::PadType padding_type; - ngraph::element::Type element_type; -}; - -/** - * @brief gets all convolution related data into a struct for further processing - * @param conv convolution node to get data of - * @param conv_data convolution data structure to put data into - * @return void - */ -void GetConvData(std::shared_ptr conv, ConvData& conv_data); - -/** - * @brief gets all convolution related data into a struct for further processing - * @param conv GNA custom convolution node to get data of - * @param conv_data convolution data structure to put data into - * @return void - */ -void GetConvData(std::shared_ptr conv, ConvData& conv_data); - -/** - * @brief ngraph matcher predicate fusing existing predicates for consumers count and rank of a layer - * @param expected_count expected consumers count for of node - * @param expected_rank expected node rank - * @return predicate function wrapper - */ -std::function)> consumers_and_rank(const size_t expected_count, - const ngraph::Dimension& expected_rank); - -/** - * @brief checks whether transpose matches a given order - * @param transpose transpose layer - * @param order order of transposition to be compared with - * @return true if the order matches, false otherwise - */ -bool TransposeOrderMatches(std::shared_ptr transpose, std::vector order); - -/** - * @brief performs a crop of a flattened input tensor - * @param input input layer - * @param offset offset to start the crop at* - * @param size size of the crop - * @return pointer to the newly created slice - */ -std::shared_ptr FlatCrop(ngraph::Output input, size_t offset, size_t size); - -/** - * @brief checks whether an add present after convolution is a bias and gets its const input - * @param conv convolution layer preceding potential bias - * @param add potential bias layer passed from ngraph matcher - * @return bias const if the add layer present after convolution is a bias, nullptr otherwise - */ -std::shared_ptr VerifyBiasGetConst(std::shared_ptr conv, std::shared_ptr add); - -/** - * @brief inserts a new fake quantize layer copied from an existing one and connects it to the output of a given layer - * @param fq_layer existing fake quantize layer to be copied - * @param last_node the node to which output the new fake quantize layer will be connected - * @return new fake quantize layer or the last node - */ -std::shared_ptr InsertFQLayer(const std::shared_ptr fq_layer, - std::shared_ptr last_node); - -/** - * @brief removes single node and inserts Reshape if its input and output shapes differ - * @param node the node to be removed - * @return void - */ -void remove_single_input_node(std::shared_ptr node); - -/** - * @brief Swaps @args output tensor names - */ -void swap_output_names(ov::Output, ov::Output); - -/** - * @brief Swaps @args friendly names - */ -void swap_friendly_names(std::shared_ptr, std::shared_ptr); - -/** - * @brief Swaps @args output tensor names and friendly names - */ -void swap_names(std::shared_ptr, std::shared_ptr); - -/** - * @brief Reverses axis order. Final result will be such an order, that together - * with initial order will be {0, 1, 2, ...} - */ -ov::AxisVector reverse_transpose_order(const ov::AxisVector& axis_order); - -/** - * @brief Finds all input node transposes - */ -ov::NodeVector find_input_transposes(const std::shared_ptr& node); - -/** - * @brief Marks all input transposes with flag NoSinking - */ -void mark_input_transposes_as_nosinking(std::shared_ptr node); - -struct TransposeInfo { - std::shared_ptr transpose; - std::shared_ptr transpose_const; - - bool isEmpty() const { - return !transpose || !transpose_const; - } -}; - -/** - * @brief Finds first input node transpose - */ -TransposeInfo get_first_input_transpose(const std::shared_ptr& node); - -/** - * @brief Finds first output node transpose - */ -TransposeInfo get_first_output_transpose(const std::shared_ptr& node); - -} // namespace helper -} // namespace pass -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/tests/CMakeLists.txt b/src/plugins/intel_gna/tests/CMakeLists.txt deleted file mode 100644 index e1c1d1c3917..00000000000 --- a/src/plugins/intel_gna/tests/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (C) 2022 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -enable_testing() - -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - ov_add_compiler_flags(/wd4244) - ov_add_compiler_flags(/wd4267) - ov_add_compiler_flags(/wd4305) - ov_add_compiler_flags(/wd4273) - ov_add_compiler_flags(/wd4661) - ov_add_compiler_flags(/wd4018) - ov_add_compiler_flags(/wd4334) - ov_add_compiler_flags(/wd4250) -else() - ov_add_compiler_flags(-Wno-missing-declarations) - ov_add_compiler_flags(-Wno-odr) - ov_add_compiler_flags(-Wno-all) -endif() - -if(ENABLE_TESTS) - add_subdirectory(deprecated/readers) - add_subdirectory(deprecated/helpers) - - add_subdirectory(unit) - add_subdirectory(deprecated/unit) -endif() - -if(ENABLE_FUNCTIONAL_TESTS) - add_subdirectory(functional) -endif() diff --git a/src/plugins/intel_gna/tests/deprecated/CMakeLists.txt b/src/plugins/intel_gna/tests/deprecated/CMakeLists.txt deleted file mode 100644 index 5a102d9db5f..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -enable_testing() - -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - ov_add_compiler_flags(/wd4244) - ov_add_compiler_flags(/wd4267) - ov_add_compiler_flags(/wd4305) - ov_add_compiler_flags(/wd4273) - ov_add_compiler_flags(/wd4661) - ov_add_compiler_flags(/wd4018) - ov_add_compiler_flags(/wd4334) -endif() - -if(NOT MSVC) - ov_add_compiler_flags(-Wno-missing-declarations) - ov_add_compiler_flags(-Wno-all) - ov_add_compiler_flags(-Wno-unused-variable) - ov_add_compiler_flags(-Wno-unused-function) -endif() - -add_subdirectory(readers) -add_subdirectory(helpers) - -if (ENABLE_FUNCTIONAL_TESTS) - add_subdirectory(functional) -endif() - -if(ENABLE_TESTS) - add_subdirectory(unit) -endif() diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/CMakeLists.txt b/src/plugins/intel_gna/tests/deprecated/helpers/CMakeLists.txt deleted file mode 100644 index 3423cf8f90a..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -set(TARGET_NAME ieTestHelpers) - -file(GLOB HELPERS_SRC - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp -) - -file (GLOB HELPERS_INCLUDES - ${CMAKE_CURRENT_SOURCE_DIR}/*.h - ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp - ) - -function(add_helpers target_name) - add_library(${target_name} STATIC ${HELPERS_SRC}) - - target_include_directories(${target_name} - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" - $ - $ - $ - $ - PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") -endfunction() - -add_helpers(${TARGET_NAME}) - -target_link_libraries(${TARGET_NAME} PUBLIC common_test_utils - PRIVATE inference_engine_legacy) - -add_helpers(${TARGET_NAME}_s USE_STATIC_IE) - -target_link_libraries(${TARGET_NAME}_s PUBLIC common_test_utils_s - PRIVATE inference_engine_legacy_s) diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/cnnlayer_utils.hpp b/src/plugins/intel_gna/tests/deprecated/helpers/cnnlayer_utils.hpp deleted file mode 100644 index c7b190f3d9f..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/cnnlayer_utils.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -namespace CommonTestUtils { - -IE_SUPPRESS_DEPRECATED_START - -inline std::shared_ptr getLayerByName(const InferenceEngine::CNNNetwork& network, - const std::string& layerName) { - InferenceEngine::details::CNNNetworkIterator i(network), end; - while (i != end) { - auto layer = *i; - if (layer->name == layerName) - return layer; - ++i; - } - IE_THROW(NotFound) << "Layer " << layerName << " not found in network"; -} - -IE_SUPPRESS_DEPRECATED_END - -} // namespace CommonTestUtils diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/common_layers_params.cpp b/src/plugins/intel_gna/tests/deprecated/helpers/common_layers_params.cpp deleted file mode 100644 index f0df3368b92..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/common_layers_params.cpp +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include - -#include "common_layers_params.hpp" -#include "common_test_utils/data_utils.hpp" - -namespace CommonTestUtils { - -void getConvOutShape(const std::vector &inShape, - const conv_common_params ¶ms, - std::vector &outShape) { - outShape.resize(inShape.size(), 1lu); - outShape[0] = inShape[0]; - outShape[1] = params.out_c; - for (int i = 0; i < params.kernel.size() && i + 2 < outShape.size(); i++) { - outShape[i + 2] = - (inShape[i + 2] + params.pads_begin[i] + params.pads_end[i] - - (params.kernel[i] - 1lu) * params.dilation[i] - 1lu) / - params.stride[i] + 1lu; - } -} - -std::map convertConvParamToMap(const conv_common_params ¶ms) { - std::map resMap; - - auto propVecToStr = [](const InferenceEngine::PropertyVector &vec) -> std::string { - std::string str = ""; - for (size_t i = 0; i < vec.size(); i++) { - str += std::to_string(vec[i]); - if (i < vec.size() - 1) str += ","; - } - return str; - }; - resMap["dilations"] = propVecToStr(params.dilation); - resMap["kernel"] = propVecToStr(params.kernel); - resMap["strides"] = propVecToStr(params.stride); - resMap["pads_begin"] = propVecToStr(params.pads_begin); - resMap["pads_end"] = propVecToStr(params.pads_end); - resMap["group"] = std::to_string(params.group); - resMap["output"] = std::to_string(params.out_c); - if (!params.auto_pad.empty()) - resMap["auto_pad"] = params.auto_pad; - if (!params.quantization_level.empty()) - resMap["quantization_level"] = params.quantization_level; - - return resMap; -} - -void getPoolOutShape(const std::vector &inShape, - const pool_common_params ¶ms, - std::vector &outShape) { - outShape.resize(inShape.size(), 1lu); - outShape[0] = inShape[0]; - outShape[1] = inShape[1]; - for (int i = 0; i < params.kernel.size() && i + 2 < outShape.size(); i++) { - outShape[i + 2] = - (inShape[i + 2] + params.pads_begin[i] + params.pads_end[i] - params.kernel[i]) / params.stride[i] + - 1lu; - } -} - -std::map convertPoolParamToMap(const pool_common_params ¶ms) { - std::map resMap; - - auto propVecToStr = [](const InferenceEngine::PropertyVector &vec) -> std::string { - std::string str = ""; - for (size_t i = 0; i < vec.size(); i++) { - str += std::to_string(vec[i]); - if (i < vec.size() - 1) str += ","; - } - return str; - }; - resMap["kernel"] = propVecToStr(params.kernel); - resMap["strides"] = propVecToStr(params.stride); - resMap["pads_begin"] = propVecToStr(params.pads_begin); - resMap["pads_end"] = propVecToStr(params.pads_end); - if (!params.auto_pad.empty()) - resMap["auto_pad"] = params.auto_pad; - if (!params.rounding_type.empty()) - resMap["rounding_type"] = params.rounding_type; - - if (params.avg) { - resMap["pool-method"] = "avg"; - resMap["exclude-pad"] = params.exclude_pad ? "true" : "false"; - } else { - resMap["pool-method"] = "max"; - } - - return resMap; -} - -size_t getConvWeightsSize(const std::vector &inShape, - const conv_common_params ¶ms, - const std::string &precision) { - if (!params.with_weights) - return 0lu; - size_t weights_size = 0lu; - if (params.group != 0lu && params.out_c != 0lu && params.kernel.size() != 0lu) { - auto prc = InferenceEngine::Precision::FromStr(precision); - - weights_size = prc.size() * inShape[1] * params.out_c / params.group; - for (size_t i = 0lu; i < params.kernel.size(); i++) { - weights_size *= params.kernel[i]; - } - } - return weights_size; -} - -size_t getConvBiasesSize(const conv_common_params ¶ms, - const std::string &precision) { - if (!params.with_bias) - return 0lu; - auto prc = InferenceEngine::Precision::FromStr(precision); - return prc.size() * params.out_c; -} - -InferenceEngine::Blob::Ptr getWeightsBlob(size_t sizeInBytes, const std::string &precision) { - InferenceEngine::Blob::Ptr weights; - if (precision.empty()) { - /* Just keep U8 blob for weights */ - weights = InferenceEngine::make_shared_blob( - {InferenceEngine::Precision::U8, {sizeInBytes}, InferenceEngine::C}); - } else { - /* Keep blob for weights in original precision */ - if (precision == "U8") { - using dataType = InferenceEngine::PrecisionTrait::value_type; - weights = InferenceEngine::make_shared_blob( - {InferenceEngine::Precision::U8, {sizeInBytes}, InferenceEngine::C}); - } else if (precision == "FP32") { - using dataType = InferenceEngine::PrecisionTrait::value_type; - weights = InferenceEngine::make_shared_blob( - {InferenceEngine::Precision::FP32, {sizeInBytes / sizeof(dataType)}, InferenceEngine::C}); - } else if (precision == "FP16" || precision == "Q78") { - using dataType = InferenceEngine::PrecisionTrait::value_type; - weights = InferenceEngine::make_shared_blob( - {InferenceEngine::Precision::FP16, {sizeInBytes / sizeof(dataType)}, InferenceEngine::C}); - } else { - IE_THROW() << "Precision " << precision << " is not covered by getWeightsBlob()"; - } - } - - weights->allocate(); - ov::test::utils::fill_data(weights->buffer().as(), weights->byteSize() / sizeof(float)); - - return weights; -} - -void get_common_dims(const InferenceEngine::Blob &blob, - int32_t &dimx, - int32_t &dimy, - int32_t &dimz) { - std::vector dims(blob.getTensorDesc().getDims().begin(), blob.getTensorDesc().getDims().end()); - if (dims.size() == 2) { - dimz = 1; - dimy = dims[0]; - dimx = dims[1]; - } else if (dims.size() == 3) { - dimx = dims[2]; - dimy = dims[1]; - dimz = dims[0]; - } else if (dims.size() == 4 && dims[0] == 1) { - dimx = dims[3]; - dimy = dims[2]; - dimz = dims[1]; - } -} - -void get_common_dims(const InferenceEngine::Blob &blob, - int32_t &dimx, - int32_t &dimy, - int32_t &dimz, - int32_t &dimn) { - std::vector dims(blob.getTensorDesc().getDims().begin(), blob.getTensorDesc().getDims().end()); - dimn = 1; - if (dims.size() == 2) { - dimz = 1; - dimy = dims[0]; - dimx = dims[1]; - } else if (dims.size() == 3) { - dimx = dims[2]; - dimy = dims[1]; - dimz = dims[0]; - } else if (dims.size() == 4) { - dimx = dims[3]; - dimy = dims[2]; - dimz = dims[1]; - - if (dims[0] != 1) { - dimn = dims[0]; - } - } -} - -} // namespace CommonTestUtils diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/common_layers_params.hpp b/src/plugins/intel_gna/tests/deprecated/helpers/common_layers_params.hpp deleted file mode 100644 index 715b8aa7799..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/common_layers_params.hpp +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include // to allow putting vector into exception string stream -#include -#include "ie_blob.h" - -namespace CommonTestUtils { - -struct conv_common_params { - InferenceEngine::PropertyVector stride; - InferenceEngine::PropertyVector kernel; - InferenceEngine::PropertyVector pads_begin; - InferenceEngine::PropertyVector pads_end; - InferenceEngine::PropertyVector dilation; - std::string auto_pad; - size_t group; - size_t out_c; - bool with_bias; - bool with_weights; - std::string quantization_level; -}; - -struct pool_common_params { - InferenceEngine::PropertyVector stride; - InferenceEngine::PropertyVector kernel; - InferenceEngine::PropertyVector pads_begin; - InferenceEngine::PropertyVector pads_end; - std::string auto_pad; - bool avg; - bool exclude_pad; - std::string rounding_type; -}; - -struct eltwise_common_params { - std::string operation; - std::vector coeff; -}; - -struct def_conv_common_params : conv_common_params { - explicit def_conv_common_params(conv_common_params convCommonParams) { - this->stride = convCommonParams.stride; - this->kernel = convCommonParams.kernel; - this->pads_begin = convCommonParams.pads_begin; - this->pads_end = convCommonParams.pads_end; - this->dilation = convCommonParams.dilation; - this->auto_pad = convCommonParams.auto_pad; - this->group = convCommonParams.group; - this->out_c = convCommonParams.out_c; - this->with_bias = convCommonParams.with_bias; - } - - size_t deformable_group; -}; - -void getConvOutShape(const std::vector &inShape, - const conv_common_params ¶ms, - std::vector &outShape); - -std::map convertConvParamToMap(const conv_common_params ¶ms); - -void getPoolOutShape(const std::vector &inShape, - const pool_common_params ¶ms, - std::vector &outShape); - -std::map convertPoolParamToMap(const pool_common_params ¶ms); - -size_t getConvWeightsSize(const std::vector &inShape, - const conv_common_params ¶ms, - const std::string &precision); - -size_t getConvBiasesSize(const conv_common_params ¶ms, - const std::string &precision); - -InferenceEngine::Blob::Ptr getWeightsBlob(size_t sizeInBytes, const std::string &precision = ""); - -void get_common_dims(const InferenceEngine::Blob &blob, - int32_t &dimx, - int32_t &dimy, - int32_t &dimz); - -void get_common_dims(const InferenceEngine::Blob &blob, - int32_t &dimx, - int32_t &dimy, - int32_t &dimz, - int32_t &dimn); - - -} // namespace CommonTestUtils diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/ie_core_adapter.cpp b/src/plugins/intel_gna/tests/deprecated/helpers/ie_core_adapter.cpp deleted file mode 100644 index fe4ca91285e..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/ie_core_adapter.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ie_core_adapter.hpp" -#include "description_buffer.hpp" - -using namespace InferenceEngine; - -using IECorePtr = std::shared_ptr; - -IECoreAdapter::IECoreAdapter(IECorePtr ieCore, std::string deviceName) - : m_ieCore(ieCore), m_deviceName(deviceName) {} - -ExecutableNetwork IECoreAdapter::LoadNetwork( - const CNNNetwork & network, - const std::map& config) { - return m_ieCore->LoadNetwork(network, m_deviceName, config); -} - -ExecutableNetwork IECoreAdapter::ImportNetwork( - const std::string& modelFileName, - const std::map& config) { - return m_ieCore->ImportNetwork(modelFileName, m_deviceName, config); -} - -ExecutableNetwork IECoreAdapter::ImportNetwork( - std::istream& networkModel, - const std::map& config) { - return m_ieCore->ImportNetwork(networkModel, m_deviceName, config); -} diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/ie_core_adapter.hpp b/src/plugins/intel_gna/tests/deprecated/helpers/ie_core_adapter.hpp deleted file mode 100644 index d2caff4c734..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/ie_core_adapter.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -class IECoreAdapter { -public: - using Ptr = std::shared_ptr; - - IECoreAdapter( - std::shared_ptr ieCore, std::string deviceName); - - InferenceEngine::ExecutableNetwork LoadNetwork(const InferenceEngine::CNNNetwork & network, - const std::map& config = {}); - - InferenceEngine::ExecutableNetwork ImportNetwork(const std::string& modelFileName, - const std::map& config = {}); - - InferenceEngine::ExecutableNetwork ImportNetwork(std::istream& networkModel, - const std::map& config = {}); - - std::shared_ptr& ieCore() { - return m_ieCore; - } - -private: - std::shared_ptr m_ieCore; - std::string m_deviceName; -}; diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/single_layer_common.cpp b/src/plugins/intel_gna/tests/deprecated/helpers/single_layer_common.cpp deleted file mode 100644 index bf732131aff..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/single_layer_common.cpp +++ /dev/null @@ -1,296 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include -#include "single_layer_common.hpp" -#include - -using namespace InferenceEngine; - -void GenRandomDataCommon(Blob::Ptr blob) { - if (blob->getTensorDesc().getPrecision() == Precision::U8) { - auto * blobRawDataU8 = blob->buffer().as(); - size_t count = blob->size(); - for (size_t i = 0; i < count; i++) { - auto val = static_cast(rand() % 256); - blobRawDataU8[i] = val; - } - } else if (blob->getTensorDesc().getPrecision() == Precision::FP16) { - float scale = 2.0f / static_cast(RAND_MAX); - /* fill by random data in the range (-1, 1)*/ - auto * blobRawDataFp16 = blob->buffer().as(); - size_t count = blob->size(); - for (size_t indx = 0; indx < count; ++indx) { - float val = rand(); - val = val * scale - 1.0f; - blobRawDataFp16[indx] = PrecisionUtils::f32tof16(val); - } - } else if (blob->getTensorDesc().getPrecision() == Precision::FP32) { - float scale = 2.0f / static_cast(RAND_MAX); - /* fill by random data in the range (-1, 1)*/ - auto * blobRawDataFp32 = blob->buffer().as(); - size_t count = blob->size(); - for (size_t i = 0; i < count; i++) { - float val = rand(); - val = val * scale - 1.0f; - blobRawDataFp32[i] = val; - } - } else if (blob->getTensorDesc().getPrecision() == Precision::I32) { - using T = PrecisionTrait::value_type; - auto buffer = blob->buffer().as(); - double tempSum = 0; - int val; - for (size_t i = 0; i < blob->size(); i++) { - if ((tempSum > -RAND_MAX) && (tempSum < RAND_MAX)) - val = rand() % (RAND_MAX - static_cast(tempSum)); - else - val = 0; - buffer[i] = val; - tempSum +=val; - } - } else { - IE_THROW() << blob->getTensorDesc().getPrecision() << " is not supported by GenRandomDataCommon"; - } -} - -BufferWrapper::BufferWrapper(const Blob::Ptr& blob) : BufferWrapper(blob, blob->getTensorDesc().getPrecision()) {} - -BufferWrapper::BufferWrapper(const Blob::Ptr& blob, Precision _precision) : precision(_precision) { - if (precision == Precision::FP16) { - fp16_ptr = blob->buffer().as(); - } else if (precision == Precision::FP32) { - fp32_ptr = blob->buffer().as(); - } else if (precision == Precision::I32) { - i32_ptr = blob->buffer().as(); - } else if (precision == Precision::U8) { - u8_ptr = blob->buffer().as(); - } else { - IE_THROW() << "Unsupported precision for compare: " << precision; - } -} - -float BufferWrapper::operator[](size_t index) { - if (precision == Precision::FP16) { - return PrecisionUtils::f16tof32(fp16_ptr[index]); - } else if (precision == Precision::I32) { - return i32_ptr[index]; - } else if (precision == Precision::U8) { - return u8_ptr[index]; - } - return fp32_ptr[index]; -} - -void BufferWrapper::insert(size_t index, float value) { - if (precision == Precision::FP16) { - fp16_ptr[index] = PrecisionUtils::f32tof16(value); - } else if (precision == Precision::I32) { - i32_ptr[index] = value; - } else if (precision == Precision::U8) { - u8_ptr[index] = value; - } else { - fp32_ptr[index] = value; - } -} - -void CompareCommonExact(const InferenceEngine::Blob::Ptr &actual, - const InferenceEngine::Blob::Ptr &expected) { - ASSERT_EQ(actual == nullptr, expected == nullptr); - if (actual == nullptr && expected == nullptr) { - return; - } - - ASSERT_EQ(actual->getTensorDesc().getPrecision(), expected->getTensorDesc().getPrecision()) - << "actual is " << actual->getTensorDesc().getPrecision() << ", while reference is " << expected->getTensorDesc().getPrecision(); - ASSERT_EQ(actual->size(), expected->size()) << "actual has " << actual->size() << " elements, while reference " << expected->size(); - - auto actualPtr = actual->cbuffer().as(); - auto expectedPtr = expected->cbuffer().as(); - for (std::size_t i = 0; i < actual->byteSize(); ++i) { - ASSERT_EQ(actualPtr[i], expectedPtr[i]) << "first error index = " << i / actual->element_size(); - } -} - -void CompareCommonAbsolute(const Blob::Ptr& actual, const Blob::Ptr& expected, float tolerance) { - ASSERT_NE(actual, nullptr); - ASSERT_NE(expected, nullptr); - - BufferWrapper res_ptr(actual); - BufferWrapper ref_ptr(expected); - float max_abs_error = 0; - size_t actualMaxErrId = 0; - size_t expectedMaxErrId = 0; - std::function absoluteErrorUpdater = [&](size_t actualIdx, size_t expectedIdx) { - auto actual = res_ptr[actualIdx]; - auto expected = ref_ptr[expectedIdx]; - float abs_error = fabsf(actual - expected); - if (abs_error > max_abs_error) { - max_abs_error = abs_error; - actualMaxErrId = actualIdx; - expectedMaxErrId = expectedIdx; - } - }; - CompareCommon(actual, expected, absoluteErrorUpdater); - - ASSERT_NEAR(ref_ptr[expectedMaxErrId], res_ptr[actualMaxErrId], tolerance) - << "expectedMaxErrId = " << expectedMaxErrId - << " actualMaxErrId = " << actualMaxErrId; -} - -void CompareCommonRelative(const Blob::Ptr& actual, const Blob::Ptr& expected, float tolerance) { - ASSERT_NE(actual, nullptr); - ASSERT_NE(expected, nullptr); - - BufferWrapper res_ptr(actual); - BufferWrapper ref_ptr(expected); - float max_rel_error = 0; - size_t actualMaxErrId = 0; - size_t expectedMaxErrId = 0; - std::function relatedErrorUpdater = [&](size_t actualIdx, size_t expectedIdx) { - auto actual = res_ptr[actualIdx]; - auto expected = ref_ptr[expectedIdx]; - float abs_error = fabsf(actual - expected); - float rel_error = expected != 0.0 ? fabsf(abs_error / expected) : abs_error; - if (rel_error > max_rel_error) { - max_rel_error = rel_error; - actualMaxErrId = actualIdx; - expectedMaxErrId = expectedIdx; - } - }; - CompareCommon(actual, expected, relatedErrorUpdater); - - float abs_threshold = fabsf(ref_ptr[expectedMaxErrId]) * tolerance; - ASSERT_NEAR(ref_ptr[expectedMaxErrId], res_ptr[actualMaxErrId], abs_threshold) - << "expectedMaxErrId = " << expectedMaxErrId - << " actualMaxErrId = " << actualMaxErrId; -} - -// Compare: -// - relative if large result -// - absolute if small result -// -// Justification: -// - If result's absolute value if small (close to 0), -// it probably is the difference of similar values, -// so result's leading digits may suffer cancellation. -// Thus, relative error may be large if small result, -// while result is correctly close to zero. -void CompareCommonCombined(const Blob::Ptr& actual, const Blob::Ptr& expected, float tolerance) { - ASSERT_NE(actual, nullptr); - ASSERT_NE(expected, nullptr); - - BufferWrapper res_ptr(actual); - BufferWrapper ref_ptr(expected); - float max_combi_error = 0; - size_t actualMaxErrId = 0; - size_t expectedMaxErrId = 0; - std::function combinedErrorUpdater = [&](size_t actualIdx, size_t expectedIdx) { - auto actual = res_ptr[actualIdx]; - auto expected = ref_ptr[expectedIdx]; - float abs_error = fabsf(actual - expected); - float rel_error = expected != 0.0 ? fabsf(abs_error / expected) : abs_error; - float error = std::max(abs_error, rel_error); - if (max_combi_error < error) { - max_combi_error = error; - actualMaxErrId = actualIdx; - expectedMaxErrId = expectedIdx; - } - }; - CompareCommon(actual, expected, combinedErrorUpdater); - - float abs_threshold = fabsf(ref_ptr[expectedMaxErrId]) * tolerance; - ASSERT_NEAR(ref_ptr[expectedMaxErrId], res_ptr[actualMaxErrId], abs_threshold) - << "expectedMaxErrId = " << expectedMaxErrId - << " actualMaxErrId = " << actualMaxErrId; -} - -void CompareCommonWithNorm(const InferenceEngine::Blob::Ptr& actual, - const InferenceEngine::Blob::Ptr& expected, - float maxDiff) { - ASSERT_NE(actual, nullptr); - ASSERT_NE(expected, nullptr); - const uint16_t *res_ptr = actual->buffer().as(); - size_t res_size = actual->size(); - - const uint16_t *ref_ptr = expected->buffer().as(); - size_t ref_size = expected->size(); - - ASSERT_EQ(res_size, ref_size); - - for (size_t i = 0; i < ref_size; i++) { - float val_res = PrecisionUtils::f16tof32(res_ptr[i]); - float val_ref = PrecisionUtils::f16tof32(ref_ptr[i]); - float norm = std::max(fabs(val_res), fabs(val_ref)); - if (norm < 1.0f) - norm = 1.0f; - ASSERT_NEAR( val_res , val_ref, (maxDiff * norm)); - } -} - -void CompareCommon(const Blob::Ptr& actual, const Blob::Ptr& expected, - const std::function& errorUpdater) { - ASSERT_NE(actual, nullptr); - ASSERT_NE(expected, nullptr); - - Layout res_layout = actual->getTensorDesc().getLayout(); - Layout ref_layout = expected->getTensorDesc().getLayout(); - SizeVector res_dims = actual->getTensorDesc().getDims(); - - size_t res_size = actual->size(); - size_t ref_size = expected->size(); - ASSERT_EQ(res_size, ref_size); - - if (res_layout == NCHW || res_layout == NHWC) { - size_t N = res_dims[0]; - size_t C = res_dims[1]; - size_t H = res_dims[2]; - size_t W = res_dims[3]; - - for (size_t n = 0; n < N; n++) { - for (size_t c = 0; c < C; c++) { - for (size_t h = 0; h < H; h++) { - for (size_t w = 0; w < W; w++) { - size_t actualIdx = res_layout == NCHW ? - w + h * W + c * W * H + n * W * H * C : c + w * C + h * C * W + - n * W * H * C; - size_t expectedIdx = ref_layout == NCHW ? - w + h * W + c * W * H + n * W * H * C : c + w * C + h * C * W + - n * C * W * H; - errorUpdater(actualIdx, expectedIdx); - } - } - } - } - } else { - if (res_layout == NC) { - - size_t N = res_dims[0]; - size_t C = res_dims[1]; - for (size_t n = 0; n < N; n++) { - for (size_t c = 0; c < C; c++) { - size_t actualIdx = c + n * C; - errorUpdater(actualIdx, actualIdx); - } - } - } else { - for (size_t i = 0; i < ref_size; i++) { - errorUpdater(i, i); - } - } - } -} - -void fill_data_common(BufferWrapper& data, size_t size, size_t duty_ratio) { - for (size_t i = 0; i < size; i++) { - if ((i / duty_ratio) % 2 == 1) { - data.insert(i, 0.0); - } else { - data.insert(i, sin((float) i)); - } - } -} diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/single_layer_common.hpp b/src/plugins/intel_gna/tests/deprecated/helpers/single_layer_common.hpp deleted file mode 100644 index 76584605693..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/single_layer_common.hpp +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#if defined(__GNUC__) && (__GNUC__ <= 4) && (__GNUC_MINOR__ < 9) && !defined(__clang__) -# define IE_GCC_4_8 -#endif - -#ifndef IE_GCC_4_8 -# include -# define REPLACE_WITH_STR(SRC, PATTERN, STR) SRC = std::regex_replace(SRC, std::regex(PATTERN), STR) -# define FIND_STR(SRC, PATTERN) std::regex_search(SRC, std::regex(PATTERN)) -#else -# error "Cannot implement regex" -# define REPLACE_WITH_STR(SRC, PATTERN, STR) -# define FIND_STR(SRC, PATTERN) -#endif - -#define REPLACE_WITH_NUM(SRC, PATTERN, NUM) REPLACE_WITH_STR(SRC, PATTERN, to_string_c_locale(NUM)) - -#define REPLACE_WITH_NUM_VECTOR(SRC, PATTERN, NUMS) \ - { std::string result; \ - if (NUMS.size() > 0u) { \ - result += to_string_c_locale(NUMS[0]); \ - for (size_t i = 1u; i < NUMS.size(); i++) { \ - result += "," + to_string_c_locale(NUMS[i]); \ - } \ - } \ - REPLACE_WITH_STR(SRC, PATTERN, result); } - -#define REPLACE_WITH_NUM_VECTOR_REVERSE(SRC, PATTERN, NUMS) \ - { std::string result; \ - auto nums_size = NUMS.size(); \ - if (nums_size > 0u) { \ - result += to_string_c_locale(NUMS[nums_size - 1]); \ - for (size_t i = 2u; i <= nums_size; i++) { \ - result += "," + to_string_c_locale(NUMS[nums_size - i]); \ - } \ - } \ - REPLACE_WITH_STR(SRC, PATTERN, result); } - -#define REMOVE_LINE(SRC, PATTERN) REPLACE_WITH_STR(SRC, PATTERN, "") - -#define PRETTY_PARAM(name, type) \ - class name \ - { \ - public: \ - typedef type param_type; \ - name ( param_type arg = param_type ()) : val_(arg) {} \ - operator param_type () const {return val_;} \ - private: \ - param_type val_; \ - }; \ - static inline void PrintTo(name param, ::std::ostream* os) \ - { \ - *os << #name ": " << ::testing::PrintToString((name::param_type)(param)); \ - } - -template -inline InferenceEngine::CNNNetwork -buildSingleLayerNetworkCommon(const std::string &layerType, - const CommonTestUtils::InOutShapes &inOutShapes, - std::map *params, - const std::string &layerDataName = "data", - const InferenceEngine::Precision &precision = InferenceEngine::Precision::FP32, - size_t weightsSize = 0, - size_t biasesSize = 0, - const InferenceEngine::TBlob::Ptr &weights = nullptr) { - std::string precisionStr = precision.name(); - auto netBuilder = CommonTestUtils::XmlNetBuilder::buildNetworkWithOneInput("Mock", inOutShapes.inDims[0], - precisionStr); - size_t inputsNumber = inOutShapes.inDims.size(); - for (int i = 1; i < inputsNumber; i++) { - netBuilder.addInputLayer(precisionStr, inOutShapes.inDims[i]); - } - netBuilder.addLayer(layerType, precisionStr, params, inOutShapes, weightsSize, biasesSize, layerDataName); - std::string testContent; - if (inputsNumber > 1) { - auto edgeBuilder = netBuilder.havingEdges(); - for (size_t i = 0lu; i < inputsNumber; i++) { - edgeBuilder.connect(i, inputsNumber); - } - testContent = edgeBuilder.finish(); - } else { - testContent = netBuilder.finish(); - } - - InferenceEngine::Core ie; - return ie.ReadNetwork(testContent, weights); -} - -void GenRandomDataCommon(InferenceEngine::Blob::Ptr blob); - -class BufferWrapper { - InferenceEngine::Precision precision; - InferenceEngine::ie_fp16 *fp16_ptr; - float *fp32_ptr; - int32_t *i32_ptr; - uint8_t *u8_ptr; -public: - explicit BufferWrapper(const InferenceEngine::Blob::Ptr &blob); - - BufferWrapper(const InferenceEngine::Blob::Ptr &blob, InferenceEngine::Precision precision); - - float operator[](size_t index); - - void insert(size_t index, float value); -}; - -void CompareCommon(const InferenceEngine::Blob::Ptr &actual, - const InferenceEngine::Blob::Ptr &expected, - const std::function &errorUpdater); - -void CompareCommonExact(const InferenceEngine::Blob::Ptr &actual, - const InferenceEngine::Blob::Ptr &expected); - -void CompareCommonAbsolute(const InferenceEngine::Blob::Ptr &actual, - const InferenceEngine::Blob::Ptr &expected, - float tolerance); - -void CompareCommonRelative(const InferenceEngine::Blob::Ptr &actual, - const InferenceEngine::Blob::Ptr &expected, - float tolerance); - -void CompareCommonCombined(const InferenceEngine::Blob::Ptr &actual, - const InferenceEngine::Blob::Ptr &expected, - float tolerance); - -void CompareCommonWithNorm(const InferenceEngine::Blob::Ptr &actual, - const InferenceEngine::Blob::Ptr &expected, - float maxDiff); - -void fill_data_common(BufferWrapper &data, size_t size, size_t duty_ratio = 10); diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.cpp b/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.cpp deleted file mode 100644 index d82114d26d7..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.cpp +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include - -#include "tests_common.hpp" -#include "openvino/runtime/threading/executor_manager.hpp" - -#ifdef _WIN32 -# ifndef NOMINMAX -# define NOMINMAX -# endif -# ifndef _WINSOCKAPI_ -# define _WINSOCKAPI_ -# endif -# ifndef _WINSOCK2API_ -# define _WINSOCK2API_ -# endif -# include -# include -# include "psapi.h" -#endif - -static size_t parseLine(char* line) { - // This assumes that a digit will be found and the line ends in " Kb". - size_t i = strlen(line); - const char* p = line; - while (*p <'0' || *p > '9') p++; - line[i-3] = '\0'; - i = (size_t)atoi(p); - return i; -} - -static size_t getVmSizeInKB(){ - FILE* file = fopen("/proc/self/status", "r"); - size_t result = 0; - if (file != nullptr) { - char line[128]; - - while (fgets(line, 128, file) != NULL) { - if (strncmp(line, "VmSize:", 7) == 0) { - result = parseLine(line); - break; - } - } - fclose(file); - } - return result; -} - -#ifdef _WIN32 -static size_t getVmSizeInKBWin() { - PROCESS_MEMORY_COUNTERS pmc; - pmc.cb = sizeof(PROCESS_MEMORY_COUNTERS); - GetProcessMemoryInfo(GetCurrentProcess(),&pmc, pmc.cb); - return pmc.WorkingSetSize; -} -#endif - -void TestsCommon::SetUp() { - auto memsize = getVmSizeInKB(); - if (memsize != 0) { - std::cout << "\nMEM_USAGE=" << getVmSizeInKB() << "KB\n"; - } - ov::threading::executor_manager()->clear(); -} - -void TestsCommon::TearDown() { - ov::threading::executor_manager()->clear(); -} - -/** - * @brief Copies a 8-bit RGB image to the blob. - * - * Throws an exception in case of dimensions or input size mismatch - * - * @tparam data_t Type of the target blob - * @param RGB8 8-bit RGB image - * @param RGB8_size Size of the image - * @param blob Target blob to write image to - */ -template -void copyFromRGB8(uint8_t* RGB8, size_t RGB8_size, InferenceEngine::TBlob* blob) { - InferenceEngine::SizeVector dims = blob->getTensorDesc().getDims(); - if (4 != dims.size()) - IE_THROW() << "Cannot write data to input blob! Blob has incorrect dimensions size " << dims.size(); - size_t num_channels = dims[1]; // because RGB - size_t num_images = dims[0]; - size_t w = dims[3]; - size_t h = dims[2]; - size_t nPixels = w * h; - - if (RGB8_size != w * h * num_channels * num_images) - IE_THROW() << "input pixels mismatch, expecting " << w * h * num_channels * num_images - << " bytes, got: " << RGB8_size; - - std::vector dataArray; - for (unsigned int n = 0; n < num_images; n++) { - for (unsigned int i = 0; i < num_channels; i++) { - if (!n && !i && dataArray.empty()) { - dataArray.push_back(blob->data()); - } else { - dataArray.push_back(dataArray.at(n * num_channels + i - 1) + nPixels); - } - } - } - for (size_t n = 0; n < num_images; n++) { - size_t n_num_channels = n * num_channels; - size_t n_num_channels_nPixels = n_num_channels * nPixels; - for (size_t i = 0; i < nPixels; i++) { - size_t i_num_channels = i * num_channels + n_num_channels_nPixels; - for (size_t j = 0; j < num_channels; j++) { - dataArray.at(n_num_channels + j)[i] = RGB8[i_num_channels + j]; - } - } - } -} - -/** - * @brief Splits the RGB channels to either I16 Blob or float blob. - * - * The image buffer is assumed to be packed with no support for strides. - * - * @param imgBufRGB8 Packed 24bit RGB image (3 bytes per pixel: R-G-B) - * @param lengthbytesSize Size in bytes of the RGB image. It is equal to amount of pixels times 3 (number of channels) - * @param input Blob to contain the split image (to 3 channels) - */ -void ConvertImageToInput(unsigned char* imgBufRGB8, size_t lengthbytesSize, InferenceEngine::Blob& input) { - InferenceEngine::TBlob* float_input = dynamic_cast*>(&input); - if (float_input != nullptr) - copyFromRGB8(imgBufRGB8, lengthbytesSize, float_input); - - InferenceEngine::TBlob* short_input = dynamic_cast*>(&input); - if (short_input != nullptr) - copyFromRGB8(imgBufRGB8, lengthbytesSize, short_input); - - InferenceEngine::TBlob* byte_input = dynamic_cast*>(&input); - if (byte_input != nullptr) - copyFromRGB8(imgBufRGB8, lengthbytesSize, byte_input); -} - diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.hpp b/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.hpp deleted file mode 100644 index c9b5cea167f..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.hpp +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -// avoiding clash of the "max" macro with std::max -#ifndef NOMINMAX -#define NOMINMAX -#endif - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "helpers/test_model_repo.hpp" -#include -#include - -#include "stdlib.h" -#include "stdio.h" -#include "string.h" - -#include "common_test_utils/test_constants.hpp" - -template -inline std::string to_string_c_locale(T value) { - std::stringstream val_stream; - val_stream.imbue(std::locale("C")); - val_stream << value; - return val_stream.str(); -} - -class TestsCommon : public ::testing::Test { -protected: - void SetUp() override; - - static std::string make_so_name(const std::string & input) { - return ov::test::utils::pre + input + OV_BUILD_POSTFIX + ov::test::utils::ext; - } - - void TearDown() override; - -public: - inline std::string get_mock_engine_name() { - return make_plugin_name("mock_engine"); - } - - static std::string make_plugin_name(const std::string & input) { - return make_so_name(input); - } - - static void fill_data(InferenceEngine::Blob::Ptr& blob) { - fill_data(blob->buffer().as(), blob->byteSize() / sizeof(float)); - } - - static void fill_data(float *data, size_t size, size_t duty_ratio = 10) { - for (size_t i = 0; i < size; i++) { - if ( ( i / duty_ratio)%2 == 1) { - data[i] = 0.0; - } else { - data[i] = sin((float)i); - } - } - } - - static void fill_data_dbgval(float *data, size_t size, float alpha = 1.0f) { - for (size_t i = 0; i < size; i++) { - data[i] = i * alpha; - } - } - - static void compare( - InferenceEngine::Blob &res, - InferenceEngine::Blob &ref, - float max_diff = 0.01, - const std::string assertDetails = "") { - float *res_ptr = res.buffer().as(); - size_t res_size = res.size(); - - float *ref_ptr = ref.buffer().as(); - size_t ref_size = ref.size(); - - ASSERT_EQ(res_size, ref_size) << assertDetails; - - for (size_t i = 0; i < ref_size; i++) { - ASSERT_NEAR(res_ptr[i], ref_ptr[i], max_diff) << assertDetails; - } - } - - static void compare( - const float* res, - const float* ref, - size_t size, - float max_diff = 0.01f, - const std::string assertDetails = "") { - for (size_t i = 0lu; i < size; i++) { - ASSERT_NEAR(res[i], ref[i], max_diff) << assertDetails << ", index=" << i; - } - } - - template - static void compare(std::vector & a, std::vector & b) { - ASSERT_EQ(a.size(), b.size()); - for (size_t i = 0; i < a.size(); ++i) { - ASSERT_EQ(a[i], b[i]); - } - } - - void replace(std::string& str, const std::string& from, const std::string& to) { - std::string::size_type pos = 0; - - while((pos = str.find(from, pos)) != std::string::npos) { - str.replace(pos, from.length(), to); - pos += to.length(); - } - } - - std::string replace(std::string& str, const std::string& from, const int& to) { - replace(str, from, to_string_c_locale(to)); - return str; - } - - std::string replace(std::string& str, const std::string& from, const size_t& to) { - replace(str, from, to_string_c_locale(to)); - return str; - } - - std::string replace(std::string& str, const std::string& from, const float& to) { - replace(str, from, to_string_c_locale(to)); - return str; - } - // trim from both ends (in place) - static inline std::string &trim(std::string &s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c){ - return !std::isspace(c);})); - s.erase(std::find_if(s.rbegin(), s.rend(), [](int c){ - return !std::isspace(c);}).base(), s.end()); - return s; - } - - template - static inline T div_up(const T a, const U b) { - assert(b); - return (a + b - 1) / b; - } -}; - -// Check bitness -#include -#if UINTPTR_MAX == 0xffffffff - /* 32-bit */ - #define ENVIRONMENT32 -#elif UINTPTR_MAX == 0xffffffffffffffff - /* 64-bit */ - #define ENVIRONMENT64 -#else - # error Unsupported architecture -#endif - -/** - * @brief Splits the RGB channels to either I16 Blob or float blob. - * - * The image buffer is assumed to be packed with no support for strides. - * - * @param imgBufRGB8 Packed 24bit RGB image (3 bytes per pixel: R-G-B) - * @param lengthbytesSize Size in bytes of the RGB image. It is equal to amount of pixels times 3 (number of channels) - * @param input Blob to contain the split image (to 3 channels) - */ -void ConvertImageToInput(unsigned char* imgBufRGB8, size_t lengthbytesSize, InferenceEngine::Blob& input); diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/tests_file_utils.cpp b/src/plugins/intel_gna/tests/deprecated/helpers/tests_file_utils.cpp deleted file mode 100644 index d01b246c371..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/tests_file_utils.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include - -#include - -#include "common_test_utils/file_utils.hpp" - -#ifdef __MACH__ -# include -# include -#endif - -#ifdef _WIN32 -// Copied from linux libc sys/stat.h: -#ifndef S_ISREG -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#endif -#ifndef S_ISDIR -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif -#endif - -using namespace ::testing; -using namespace std; - -void FileUtils::readAllFile(const std::string &file_name, void *buffer, size_t maxSize) { - std::ifstream inputFile; - inputFile.open(file_name, std::ios::binary | std::ios::in); - if (!inputFile.is_open()) OPENVINO_THROW("cannot open file ", file_name); - if (!inputFile.read(static_cast (buffer), maxSize)) { - inputFile.close(); - OPENVINO_THROW("cannot read ", maxSize, " bytes from file ", file_name); - } - - inputFile.close(); -} - -std::string FileUtils::folderOf(const std::string &filepath) { - auto pos = filepath.rfind(ov::test::utils::FileSeparator); - if (pos == std::string::npos) pos = filepath.rfind(ov::test::utils::FileSeparator); - if (pos == std::string::npos) return ""; - return filepath.substr(0, pos); -} - -std::string FileUtils::fileNameNoExt(const std::string &filepath) { - auto pos = filepath.rfind('.'); - if (pos == std::string::npos) return filepath; - return filepath.substr(0, pos); -} - -std::string FileUtils::fileExt(const char *filename) { - return fileExt(std::string(filename)); -} - -std::string FileUtils::fileExt(const std::string &filename) { - auto pos = filename.rfind('.'); - if (pos == std::string::npos) return ""; - return filename.substr(pos + 1); -} - diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/tests_file_utils.hpp b/src/plugins/intel_gna/tests/deprecated/helpers/tests_file_utils.hpp deleted file mode 100644 index 1fd672cec46..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/tests_file_utils.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * \brief TODO: short file description - * \file file_utils.h - */ -#pragma once - -#include - -namespace testing { namespace FileUtils { - /** - * @brief TODO: description - * @param file_name - TODO: param - * @param buffer - TODO: param - * @param maxSize - TODO: param - */ - void readAllFile(const std::string& file_name, void* buffer, size_t maxSize); - - /** - * @brief TODO: description - * @param filepath - TODO: param - * @return TODO: ret obj - */ - std::string folderOf(const std::string &filepath); - - /** - * @brief TODO: description - * @param folder - TODO: param - * @param file - TODO: param - * @return TODO: ret obj - */ - std::string makePath(const std::string& folder, const std::string& file); - - /** - * @brief TODO: description - * @param filepath - TODO: param - * @return TODO: ret obj - */ - std::string fileNameNoExt(const std::string &filepath); - - /** - * @brief TODO: description - * @param filename - TODO: param - * @return TODO: ret obj - */ - std::string fileExt(const char* filename); - - /** - * @brief TODO: description - * @param filename - TODO: param - * @return TODO: ret obj - */ - std::string fileExt(const std::string &filename); -}} - diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/version_printer.cpp b/src/plugins/intel_gna/tests/deprecated/helpers/version_printer.cpp deleted file mode 100644 index 1128dbb9aaa..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/version_printer.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include - -class PrintVersion { -public: - PrintVersion() { - printf("BuildVersion: %s\n", - InferenceEngine::GetInferenceEngineVersion()->buildNumber); - } -}; - -static PrintVersion cons; diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/xml_father.hpp b/src/plugins/intel_gna/tests/deprecated/helpers/xml_father.hpp deleted file mode 100644 index 19723b00ea1..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/xml_father.hpp +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -namespace CommonTestUtils { - -template -inline std::string convert2string(Type &input) { - std::ostringstream convertStream; - convertStream << input; - return convertStream.str(); -} - -#if defined(_MSC_VER) && _MSC_VER > 1800 -inline std::string operator ""_s(const char * str, std::size_t len) { - return std::string(str, str + len); -} - -inline std::string make_content(const std::string & tag, const std::string & content) { - return"<"_s + tag + ">" + content + ""; -} - -inline std::string make_content(const std::string & tag, const std::string & attribute, const std::string & content) { - return attribute.empty() ? make_content(tag, content) : - ("<"_s + tag + attribute + ">" + content + ""); -} - -#else - -inline std::string make_content(const std::string &tag, const std::string &content) { - return std::string("<") + tag + ">" + content + "\n"; -} - -inline std::string make_content(const std::string &tag, const std::string &attribute, const std::string &content) { - return attribute.empty() ? make_content(tag, content) : - (std::string("<") + tag + attribute + ">" + content + "\n"); -} - -#endif - -class ConstCharMaker { - std::string ref; -public: - explicit ConstCharMaker(const std::string &ref) : ref(ref) {} - - operator const char *() { - return ref.c_str(); - } -}; - -template -class Token { - template - friend - class Token; - - T *_f; - mutable std::string _content; - std::string _tag; - std::string _attr; - mutable std::shared_ptr>> lastTag; - -public: - Token(T *f, const std::string &tag) : _f(f), _tag(tag) {} - - T &close() const { - return const_cast(_f->closeToken()); - } - - // direct node content description - without subnodes - template - Token &node(const std::string &name, Args ... content) { - _content += make_content(name, merge({convert2string(content)...})); - return *this; - } - - // combine call to close and creation of new node - template - Token &newnode(const std::string &name, Args ... content) { - return close().node(name, content ...); - } - - - std::string tag() const { - return _tag; - } - - std::string content() const { - return _content; - } - - void add_content(std::string content) { - _content += content; - } - - std::string attr() const { - return _attr; - } - - template - Token &attr(const std::string &attributeType, const Arg &attribute) { - _attr = merge({_attr, attributeType + "=\"" + convert2string(attribute) + "\""}); - return *this; - } - - operator std::string() { - return closeAll().please(); - } - - ConstCharMaker c_str() const { - return ConstCharMaker(closeAll().please()); - } - - Token> &node(const std::string &tag) { - lastTag = std::make_shared>>(this, tag); - return *lastTag; - } - - -private : - auto closeAll() const -> decltype(_f->closeAll()) { - closeToken(); - return _f->closeAll(); - } - - std::string please() { - if (lastTag.get() != nullptr) { - lastTag->close(); - } - - return _content; - } - - const Token &closeToken() const { - if (lastTag) { - _content += make_content(lastTag->tag(), lastTag->attr(), lastTag->content()); - lastTag.reset(); - } - return *this; - } - - std::string merge(std::initializer_list strList) const { - std::stringstream ret; - - for (auto it = strList.begin(); it != strList.end(); it++) { - ret << *it; - if ((it + 1) != strList.end()) { - ret << " "; - } - } - return ret.str(); - } -}; - -class XMLFather { - friend class Token; - - std::list tokens; - std::shared_ptr> lastTag; - std::string _please; - -public: - static XMLFather make_without_schema() { - auto x = XMLFather(); - x.tokens.clear(); - return x; - } - - XMLFather() { - tokens.push_back("\n"); - } - - Token &node(const std::string &tag) { - lastTag = std::make_shared>(this, tag); - return *lastTag; - } - - std::string please() { - if (!_please.empty()) { - return _please; - } - if (lastTag.get() != nullptr) { - lastTag->close(); - } - std::stringstream ss; - for (auto s : tokens) { - ss << s; - } - return _please = ss.str(); - } - - operator std::string() { - return please(); - } - -protected: - XMLFather &closeAll() { - return closeToken(); - } - - XMLFather &closeToken() { - tokens.push_back(make_content(lastTag->tag(), lastTag->attr(), lastTag->content())); - lastTag.reset(); - return *this; - } -}; - -} // namespace CommonTestUtils diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/xml_net_builder.cpp b/src/plugins/intel_gna/tests/deprecated/helpers/xml_net_builder.cpp deleted file mode 100644 index 20bbc93a002..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/xml_net_builder.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include "xml_net_builder.hpp" - -namespace CommonTestUtils { - -size_t IDManager::getNextLayerID() { - return layerID++; -} - -size_t IDManager::getNextPortID() { - return portID++; -} - -void IDManager::reset() { - portID = layerID = 0; -} - -LayerDesc::LayerDesc(std::string type, InOutShapes &shapes, IDManager &id_manager) - : _type(std::move(type)) { - _layerID = id_manager.getNextLayerID(); - auto inDims = shapes.inDims; - auto outDims = shapes.outDims; - for (const auto &inDim : inDims) { - _inPortsID.emplace_back(id_manager.getNextPortID(), inDim); - } - for (const auto &outDim : outDims) { - _outPortsID.emplace_back(id_manager.getNextPortID(), outDim); - } -} - -void LayerDesc::resetPortIDs() { - _currentInPort = _currentOutPort = 0; -} - -LayerDesc::LayerPortData LayerDesc::getNextInData() { - if (_currentInPort == _inPortsID.size()) - IE_THROW() << "Failed to get next input port: reached the last one"; - return _inPortsID[_currentInPort++]; -} - -LayerDesc::LayerPortData LayerDesc::getNextOutData() { - if (_currentOutPort == _outPortsID.size()) - IE_THROW() << "Failed to get next output port: reached the last one"; - return _outPortsID[_currentOutPort++]; -} - -size_t LayerDesc::getLayerID() const { - return _layerID; -} - -size_t LayerDesc::getInputsSize() const { - return _inPortsID.size(); -} - -size_t LayerDesc::getOutputsSize() const { - return _outPortsID.size(); -} - -std::string LayerDesc::getLayerName() const { - return _type + std::to_string(getLayerID()); -} - - -EdgesBuilder &EdgesBuilder::connect(size_t layer1, size_t layer2) { - auto found1 = std::find_if(layersDesc.begin(), layersDesc.end(), [&layer1](const LayerDesc::Ptr &desc) { - return desc->getLayerID() == layer1; - }); - auto found2 = std::find_if(layersDesc.begin(), layersDesc.end(), [&layer2](const LayerDesc::Ptr &desc) { - return desc->getLayerID() == layer2; - }); - if (found1 == layersDesc.end() || found2 == layersDesc.end()) - IE_THROW() << "Failed to find layers with index: " << layer1 << " and " << layer2; - - nodeEdges.node("edge") - .attr("from-layer", (*found1)->getLayerID()) - .attr("from-port", (*found1)->getNextOutData().portID) - .attr("to-layer", (*found2)->getLayerID()) - .attr("to-port", (*found2)->getNextInData().portID).close(); - return *this; -} - -std::string EdgesBuilder::finish() { - auto &exp = nodeEdges.close(); - return exp; -} - -} // namespace CommonTestUtils diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/xml_net_builder.hpp b/src/plugins/intel_gna/tests/deprecated/helpers/xml_net_builder.hpp deleted file mode 100644 index 425f4ef3b60..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/helpers/xml_net_builder.hpp +++ /dev/null @@ -1,567 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - - -#include -#include -#include -#include -#include - -#include "xml_father.hpp" -#include "common_layers_params.hpp" - -namespace CommonTestUtils { - -struct CropData { - size_t axis; - size_t offset; - size_t dim; -}; - -typedef std::vector CropParams; - -struct InOutShapes { - std::vector> inDims; - std::vector> outDims; - - friend std::ostream &operator<<(std::ostream &os, InOutShapes const &inout) { - auto dumpVec = [](const std::vector &vec) -> std::string { - if (vec.empty()) return "[]"; - std::stringstream oss; - oss << "[" << vec[0]; - for (size_t i = 1; i < vec.size(); i++) oss << "," << vec[i]; - oss << "]"; - return oss.str(); - }; - - for (size_t i = 0; i < inout.inDims.size(); i++) { - os << "input" << "[" << i << "]: " << dumpVec(inout.inDims[i]) << ", "; - } - for (size_t i = 0; i < inout.outDims.size(); i++) { - os << "output" << "[" << i << "]: " << dumpVec(inout.outDims[i]) << ", "; - } - return os; - } -}; - -template -struct get_recursion_level; - -template -struct get_recursion_level> : public get_recursion_level { - static const int value = get_recursion_level::value; - typedef Token type; -}; - -template<> -struct get_recursion_level> { - static const int value = 1; - typedef Token type; -}; - - -template::value> -class XMLToken; - -template -struct TokenType { - typedef Token::type> type; -}; - -template<> -struct TokenType<0> { - typedef XMLFather type; -}; - -/** - * @class Singletone that is responsible for generation unique indexes for layers and ports. - */ -class IDManager { -public: - IDManager() = default; - -// IDManager(IDManager const&) = delete; - void operator=(IDManager const &) = delete; - - /** - * @brief Returns new unique number for layer to be used in IR - */ - size_t getNextLayerID(); - - /** - * @brief Returns new unique number for port to be used in IR - */ - size_t getNextPortID(); - - /** - * @brief Reset numbers for layers and ports. It's convenient to always start new network from zero number. - */ - void reset(); - -private: - size_t layerID = 0; - size_t portID = 0; -}; - -/** - * @class Contains basic information about layer that is used on IR creation - */ -class LayerDesc { - /** - * @struct Contains basic information about port in terms of IR - */ - struct LayerPortData { - size_t portID; - std::vector dims; - - /** - * @brief Constructor - * @param _portID - unique port number - * @param _dims - shape of the port - */ - LayerPortData(size_t _portID, std::vector _dims) : portID(_portID), dims(std::move(_dims)) {} - }; - - size_t _currentInPort = 0; - size_t _currentOutPort = 0; - size_t _layerID; - std::vector _inPortsID; - std::vector _outPortsID; - std::string _type; - -public: - using Ptr = std::shared_ptr; - - /** - * @brief Constructor - * @param type - string with type of the layer - * @param shapes - reference to the structure with input and output shapes - */ - explicit LayerDesc(std::string type, InOutShapes &shapes, IDManager &id_manager); - - /** - * @brief Resets current input and output ports to iterate over all input and output ports - */ - void resetPortIDs(); - - /** - * @brief Returns basic information about next input port. It throws exception when current input post is the last. - * @return @LayerPortData - */ - LayerPortData getNextInData(); - - /** - * @brief Returns basic information about next output port. It throws exception when current output port is the last. - * @return @LayerPortData - */ - LayerPortData getNextOutData(); - - /** - * @brief Returns layer number - */ - size_t getLayerID() const; - - /** - * @brief Returns layer number - */ - std::string getLayerName() const; - - /** - * @brief Returns number of inputs - */ - size_t getInputsSize() const; - - /** - * @brief Returns number of outputs - */ - size_t getOutputsSize() const; -}; - - -/** - * @class Builder to add edges between layers in IR - */ -class EdgesBuilder { - Token> &nodeEdges; - std::vector layersDesc; - -public: - /** - * @brief Constructor - * @param _nodeEdges - node with edges to add to - * @param _layersDesc - container with information about layers: id and dimensions of input/output ports, layer id - */ - EdgesBuilder(typename CommonTestUtils::Token> &_nodeEdges, - std::vector _layersDesc) : nodeEdges(_nodeEdges), layersDesc(std::move(_layersDesc)) { - for (const auto &desc : layersDesc) { - desc->resetPortIDs(); - } - } - - /** - * @brief Adds edge between 2 layers with layer1 and layer2 numbers. - * Current output port of layer1 is connected with current input port of layer2 - */ - EdgesBuilder &connect(size_t layer1, size_t layer2); - - /** - * @brief finalizes xml creation and returns its string representation - */ - std::string finish(); -}; - -// BUILDER -template -class XmlNetBuilder { - size_t layersNum = 0lu; - std::vector layersDesc; - std::shared_ptr root; - Token> &xml; - IDManager id_manager; - size_t _offset = 0lu; - - XmlNetBuilder(std::shared_ptr _root, - typename CommonTestUtils::Token> &_xml) : root(_root), xml(_xml) {} - -public: - static XmlNetBuilder buildNetworkWithOneInput( - std::string name = "AlexNet", - std::vector dims = {1, 3, 227, 227}, - std::string precision = "Q78") { - std::shared_ptr root = std::make_shared(); - auto &exp = root->node("net").attr("name", name).attr("precision", precision).attr("version", Version); - - auto &expFinal = exp.attr("batch", 1); - return XmlNetBuilder(root, expFinal.node("layers")).addInputLayer(precision, dims); - } - - static XmlNetBuilder buildBody() { - auto root = std::make_shared(XMLFather::make_without_schema()); - auto &exp = root->node("body"); - return XmlNetBuilder(root, exp.node("layers")); - } - - XmlNetBuilder &havingLayers() { - return *this; - } - - EdgesBuilder havingEdges() { - auto &exp = xml.close(); - return EdgesBuilder(exp.node("edges"), layersDesc); - } - - XmlNetBuilder &cropLayer(CropParams params, const InOutShapes &inout) { - std::map generalParams; - for (CropData crop : params) { - generalParams["axis"] = std::to_string(crop.axis); - generalParams["offset"] = std::to_string(crop.offset); - generalParams["dim"] = std::to_string(crop.dim); - } - return addLayer("Crop", "", &generalParams, inout, 0, 0, "crop-data"); - } - - XmlNetBuilder &convolutionLayer( - const std::string &precision, - const InOutShapes &inout, - const conv_common_params &conv_params = {}, - const std::string &name = "") { - std::map params; - if (Version == 2) { - params = { - {"stride-x", "4"}, - {"stride-y", "4"}, - {"pad-x", "0"}, - {"pad-y", "0"}, - {"kernel-x", "11"}, - {"kernel-y", "11"}, - {"output", "96"} - }; - } else { - params = { - {"group", std::to_string(conv_params.group)}, - {"output", std::to_string(conv_params.out_c)} - }; - std::string kernel = conv_params.kernel.size() > 0lu ? std::to_string(conv_params.kernel[0]) : ""; - for (size_t i = 1lu; i < conv_params.kernel.size(); i++) - kernel += "," + std::to_string(conv_params.kernel[i]); - params["kernel"] = kernel; - std::string strides = conv_params.stride.size() > 0lu ? std::to_string(conv_params.stride[0]) : ""; - for (size_t i = 1lu; i < conv_params.stride.size(); i++) - strides += "," + std::to_string(conv_params.stride[i]); - params["strides"] = strides; - std::string pads_begin = - conv_params.pads_begin.size() > 0lu ? std::to_string(conv_params.pads_begin[0]) : ""; - for (size_t i = 1lu; i < conv_params.pads_begin.size(); i++) - pads_begin += "," + std::to_string(conv_params.pads_begin[i]); - params["pads_begin"] = pads_begin; - std::string pads_end = conv_params.pads_end.size() > 0lu ? std::to_string(conv_params.pads_end[0]) : ""; - for (size_t i = 1lu; i < conv_params.pads_end.size(); i++) - pads_end += "," + std::to_string(conv_params.pads_end[i]); - params["pads_end"] = pads_end; - std::string dilations = conv_params.dilation.size() > 0lu ? std::to_string(conv_params.dilation[0]) : ""; - for (size_t i = 1lu; i < conv_params.dilation.size(); i++) - dilations += "," + std::to_string(conv_params.dilation[i]); - params["dilations"] = dilations; - if (!conv_params.quantization_level.empty()) - params["quantization_level"] = conv_params.quantization_level; - } - int weights_size = getConvWeightsSize(inout.inDims[0], conv_params, precision); - int biases_size = getConvBiasesSize(conv_params, precision); - return addLayer("Convolution", precision, ¶ms, inout, weights_size, biases_size, "convolution_data", "", name); - } - - XmlNetBuilder &poolingLayer( - const std::string &precision, - const InOutShapes &inout, - const pool_common_params &pool_params = {}, - const std::string &name = "") { - std::map params; - if (Version == 2) { - params = { - {"stride-x", "4"}, - {"stride-y", "4"}, - {"pad-x", "0"}, - {"pad-y", "0"}, - {"kernel-x", "11"}, - {"kernel-y", "11"}, - }; - } else { - std::string kernel = pool_params.kernel.size() > 0lu ? std::to_string(pool_params.kernel[0]) : ""; - for (size_t i = 1lu; i < pool_params.kernel.size(); i++) - kernel += "," + std::to_string(pool_params.kernel[i]); - params["kernel"] = kernel; - std::string strides = pool_params.stride.size() > 0lu ? std::to_string(pool_params.stride[0]) : ""; - for (size_t i = 1lu; i < pool_params.stride.size(); i++) - strides += "," + std::to_string(pool_params.stride[i]); - params["strides"] = strides; - std::string pads_begin = - pool_params.pads_begin.size() > 0lu ? std::to_string(pool_params.pads_begin[0]) : ""; - for (size_t i = 1lu; i < pool_params.pads_begin.size(); i++) - pads_begin += "," + std::to_string(pool_params.pads_begin[i]); - params["pads_begin"] = pads_begin; - std::string pads_end = pool_params.pads_end.size() > 0lu ? std::to_string(pool_params.pads_end[0]) : ""; - for (size_t i = 1lu; i < pool_params.pads_end.size(); i++) - pads_end += "," + std::to_string(pool_params.pads_end[i]); - params["pads_end"] = pads_end; - if (!pool_params.auto_pad.empty()) - params["auto_pad"] = pool_params.auto_pad; - if (pool_params.avg) - params["pool-method"] = "avg"; - else - params["pool-method"] = "max"; - if (pool_params.exclude_pad) - params["exclude-pad"] = "true"; - else - params["exclude-pad"] = "false"; - } - return addLayer("Pooling", precision, ¶ms, inout, 0, 0, "pooling_data", "", name); - } - - struct TIPortMap { - int from_l, from_p, to_l, to_p, axis, stride, start, end; - }; - - XmlNetBuilder &TILayer(InOutShapes inout, - std::string body, - std::vector inMap, - std::vector outMap, - std::vector backMap) { - auto builder = XMLFather::make_without_schema(); - // Port map section - auto &ports = builder.node("port_map"); - auto fill_port_map_info = [&](std::string name, TIPortMap m) { - auto &exp = ports.node(name) - .attr("external_port_id", m.from_p) - .attr("internal_layer_id", m.to_l) - .attr("internal_port_id", m.to_p); - if (m.axis != -1) - exp.attr("axis", m.axis).attr("stride", m.stride).attr("start", m.start).attr("end", m.end); - exp.close(); - }; - for (auto &m : inMap) fill_port_map_info("input", m); - for (auto &m : outMap) fill_port_map_info("output", m); - ports.close(); - // BackEdge map section - auto &backedges = builder.node("back_edges"); - for (auto &m : backMap) { - backedges.node("edge") - .attr("from-layer", m.from_l) - .attr("from-port", m.from_p) - .attr("to-layer", m.to_l) - .attr("to-port", m.to_p).close(); - } - backedges.close(); - // Serialize all TI info - std::string content = builder; - content += body; - - return addLayer("TensorIterator", "FP32", nullptr, inout, 0, 0, "data", content); - } - - XmlNetBuilder &addLayer( - const std::string &type, - const std::string &precision, - std::map *params, - InOutShapes inout, - const std::string &name) { - return addLayer(type, precision, params, inout, 0, 0, "data", "", name); - } - - XmlNetBuilder &addLayer( - const std::string &type, - const std::string &precision, - std::map *params, - InOutShapes inout, - int weightsSize, - const std::string &name) { - return addLayer(type, precision, params, inout, weightsSize, 0, "data", "", name); - } - - XmlNetBuilder &addLayer(const std::string &type, - const std::string &precision, - std::map *params, - InOutShapes inout, - int weightsSize = 0, - int biasesSize = 0, - std::string layerDataName = "data", - std::string content = "", - const std::string &name = "") { - layersNum++; - auto layerDesc = std::make_shared(type, inout, id_manager); - layersDesc.push_back(layerDesc); - - auto &layer = xml.node("layer").attr("name", name.empty() ? layerDesc->getLayerName() : name).attr("precision", - precision) - .attr("type", type).attr("id", layerDesc->getLayerID()); - if (params != nullptr) { - auto &data = layer.node(layerDataName); - for (auto &kv : *params) { - data = data.attr(kv.first, kv.second); - } - layer = data.close(); - } - addPorts(layer, layerDesc); - std::string w_blob_name = "weights"; - if (type == "Const") - w_blob_name = "custom"; - if (weightsSize != 0) { - auto &blobs = layer.node("blobs"); - blobs.node(w_blob_name).attr("offset", _offset).attr("size", weightsSize).close(); - _offset += weightsSize; - if (biasesSize != 0) { - blobs.node("biases").attr("offset", _offset).attr("size", biasesSize).close(); - _offset += biasesSize; - } - layer = blobs.close(); - } - if (!content.empty()) - layer.add_content(content); - layer.close(); - return *this; - } - - XmlNetBuilder &addInputLayer(const std::string &precision, - const std::vector &out) { - InOutShapes inout{}; - inout.outDims.push_back(out); - return addLayer("Input", precision, nullptr, inout, 0, 0, "data", ""); - } - - std::string finish(std::vector> *edges) { - auto &exp = xml.close(); - auto &node_edges = exp.node("edges"); - - for (auto &kv : *edges) { - std::string from[] = {kv.first.substr(0, kv.first.find(',')), - kv.first.substr(kv.first.find(',') + 1, kv.first.length())}; - std::string to[] = {kv.second.substr(0, kv.second.find(',')), - kv.second.substr(kv.second.find(',') + 1, kv.second.length())}; - node_edges.node("edge").attr("from-layer", from[0]).attr("from-port", from[1]) - .attr("to-layer", to[0]).attr("to-port", to[1]).close(); - } - -// node_edges.close(); - return exp; - } - - std::string finish(bool addInputPreProcess = true) { - auto &exp = xml.close(); - addEdges(exp); - if (addInputPreProcess) { - addPreProcess(exp); - } - return exp; - } - -private: - template - static void addDims(T &place, std::vector dims) { - for (auto dim : dims) { - place.node("dim", dim); - } - } - - template - void addPorts(T &layer, const LayerDesc::Ptr &layerDesc) { - layerDesc->resetPortIDs(); - size_t numPorts = layerDesc->getInputsSize(); - if (numPorts) { - auto &node = layer.node("input"); - for (size_t i = 0; i < numPorts; i++) { - auto inData = layerDesc->getNextInData(); - addPortInfo(node, inData.portID, inData.dims); - } - node.close(); - } - numPorts = layerDesc->getOutputsSize(); - if (numPorts) { - auto &node = layer.node("output"); - for (size_t i = 0; i < numPorts; i++) { - auto outData = layerDesc->getNextOutData(); - addPortInfo(node, outData.portID, outData.dims); - } - node.close(); - } - } - - template - static void addPortInfo(T &layer, size_t portNum, std::vector dims) { - auto &place = layer.node("port").attr("id", portNum); - addDims(place, dims); - place.close(); - } - - template - void addEdges(T &mainContent) { - auto &edges = mainContent.node("edges"); - for (size_t i = 0lu; i < layersDesc.size(); i++) { - layersDesc[i]->resetPortIDs(); - } - for (size_t i = 0lu; i < layersDesc.size() - 1lu; i++) { - edges.node("edge") - .attr("from-layer", layersDesc[i]->getLayerID()) - .attr("from-port", layersDesc[i]->getNextOutData().portID) - .attr("to-layer", layersDesc[i + 1]->getLayerID()) - .attr("to-port", layersDesc[i + 1]->getNextInData().portID).close(); - } - edges.close(); - } - - template - void addPreProcess(T &mainContent) { - auto &preProcess = mainContent.node("pre-process"); - if (Version >= 2) { - preProcess.attr("reference-layer-name", layersDesc[0]->getLayerName()); - } - preProcess.close(); - } -}; - -typedef XmlNetBuilder<2> V2NetBuilder; -typedef XmlNetBuilder<6> DefaultNetBuilder; - -} // namespace CommonTestUtils diff --git a/src/plugins/intel_gna/tests/deprecated/readers/CMakeLists.txt b/src/plugins/intel_gna/tests/deprecated/readers/CMakeLists.txt deleted file mode 100644 index a1981e4472d..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -if(ENABLE_IR_V7_READER) - add_subdirectory(ir_reader_v7) -endif() diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/CMakeLists.txt b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/CMakeLists.txt deleted file mode 100644 index 2a7937c6671..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/CMakeLists.txt +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -set(TARGET_NAME "inference_engine_ir_v7_reader") - -file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/*.h - ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) - -# Create named folders for the sources within the .vcproj -# Empty name lists them directly under the .vcproj - -source_group("src" FILES ${LIBRARY_SRC}) - -# Create module library - -if(BUILD_SHARED_LIBS) - set(library_type MODULE) -else() - set(library_type STATIC) -endif() - -add_library(${TARGET_NAME} ${library_type} ${LIBRARY_SRC}) - -ov_build_target_faster(${TARGET_NAME} - UNITY -) - -ov_add_vs_version_file(NAME ${TARGET_NAME} - FILEDESCRIPTION "Inference Engine IR v7 reader plugin") - -target_compile_definitions(${TARGET_NAME} PRIVATE IMPLEMENT_INFERENCE_ENGINE_PLUGIN) - -target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/") - -target_link_libraries(${TARGET_NAME} PRIVATE openvino::runtime::dev - inference_engine_legacy openvino::pugixml openvino::itt) - -if(WIN32) - set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_PDB_NAME ${TARGET_NAME}) -endif() - -if(BUILD_SHARED_LIBS) - target_link_libraries(${TARGET_NAME} PRIVATE inference_engine) -endif() - -# must be called after all target_link_libraries -ov_add_api_validator_post_build_step(TARGET ${TARGET_NAME}) - -# code style - -ov_add_clang_format_target(${TARGET_NAME}_clang_format FOR_TARGETS ${TARGET_NAME}) - -# Install rules - -install(TARGETS ${TARGET_NAME} - LIBRARY DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL) - -ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_blob_proxy.hpp b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_blob_proxy.hpp deleted file mode 100644 index 568db2f84af..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_blob_proxy.hpp +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -/** - * @brief A header file for the TBlobProxy class definition - * @file ie_blob_proxy.hpp - */ - -#include -#include - -#include "ie_blob.h" - -namespace InferenceEngine { - -/** - * @class TBlobProxy - * @brief This class enables creation of several blobs based on a single allocation but using different offsets for - * read/write - */ -template -class TBlobProxy : public TBlob { - using base = TBlob; - -public: - /** - * @brief A shared pointer to the TBlobProxy object - */ - using Ptr = std::shared_ptr>; - - /** - * @brief A move constructor - * @param p Precision type - * @param l Layout - * @param blob Source TBlob object to move from. It is deleted after a constructor call, since the ownership is - * transferred to the proxy - * @param offset Offset in memory - * @param dims Dimensions of the given blob - */ - TBlobProxy(Precision p, Layout l, TBlob&& blob, size_t offset, const SizeVector& dims) - : base(TensorDesc(p, dims, l)), - realObject(make_shared_blob(std::move(blob))), - offset(offset * blob.element_size()) { - checkWindow(); - } - - /** - * @brief A move constructor - * @param p Precision type - * @param l Layout - * @param blob Source Blob object to move from. It is deleted after a constructor call, since the ownership is - * transferred to the proxy - * @param offset Offset in memory - * @param dims Dimensions of the given blob - */ - TBlobProxy(Precision p, Layout l, const MemoryBlob::Ptr& blob, size_t offset, const SizeVector& dims) - : base(TensorDesc(p, dims, l)), - realObject(blob), - offset(offset * blob->element_size()) { - checkWindow(); - } - - /** - * A copy constructor - * @param p Precision type - * @param l Layout - * @param blobProxy Source TBlobProxy object to copy from - * @param offset Offset in memory - * @param dims Dimensions of the given blob - */ - TBlobProxy(Precision p, Layout l, const TBlobProxy& blobProxy, size_t offset, const SizeVector& dims) - : TBlob(TensorDesc(p, dims, l)), - realObject(blobProxy.realObject), - offset(offset * sizeof(T)) { - checkWindow(); - } - - /** - * @brief Creates a new empty rvalue LockedMemory instance of type void - * @return LockedMemory instance of type void - */ - LockedMemory buffer() noexcept override { - return {getAllocator().get(), realObject->getHandle(), offset}; - } - - /** - * @brief Creates a new empty rvalue LockedMemory instance of type const void - * @return LockedMemory instance of type const void - */ - LockedMemory cbuffer() const noexcept override { - return {getAllocator().get(), realObject->getHandle(), offset}; - } - - /** - * @brief Creates a LockedMemory instance of the given type - * @return LockedMemory instance of the given type - */ - LockedMemory data() noexcept override { - return {getAllocator().get(), realObject->getHandle(), offset}; - } - - /** - * @brief Creates a readOnly LockedMemory instance of the given type - * @return Read-only LockedMemory instance of the given type - */ - LockedMemory readOnly() const noexcept override { - return {getAllocator().get(), realObject->getHandle(), offset}; - } - -protected: - /** - * @brief Gets an allocator - * @return An allocator instance - */ - const std::shared_ptr& getAllocator() const noexcept override { - return realObject->getAllocator(); - } - - /** - * @brief Checks whether proxy can be created with the requested offset and size parameters - */ - void checkWindow() { - if (realObject->size() * realObject->element_size() < base::size() * base::element_size() + offset) { - IE_THROW() << "cannot create proxy, offsetInBytes=" << offset - << ", sizeInBytes=" << base::size() * base::element_size() - << ", out of original object size=" << realObject->size() * realObject->element_size(); - } - } - - /** - * @brief Allocates TBlobProxy data - * Always throws exception. Not intended to be used - */ - void allocate() noexcept override {} - - /** - * @brief Deallocates TBlobProxy data - * Always throws exception. Not intended to be used - */ - bool deallocate() noexcept override { - return false; - } - -private: - typename MemoryBlob::Ptr realObject; - size_t offset; -}; -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_cnn_net_reader_impl.cpp b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_cnn_net_reader_impl.cpp deleted file mode 100644 index fdee73907d1..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_cnn_net_reader_impl.cpp +++ /dev/null @@ -1,208 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ie_format_parser.h" -#include "ie_ir_itt.hpp" -#include "parsers.h" -#include "xml_parse_utils.h" - -using namespace std; -using namespace InferenceEngine; -using namespace InferenceEngine::details; - -CNNNetReaderImpl::CNNNetReaderImpl(const FormatParserCreator::Ptr& _creator) - : parseSuccess(false), - _version(0), - parserCreator(_creator) {} - -StatusCode CNNNetReaderImpl::SetWeights(const TBlob::Ptr& weights, ResponseDesc* desc) noexcept { - if (!_parser && _version < 10) { - return DescriptionBuffer(desc) << "network must be read first"; - } - - try { - if (_version < 10) { - _parser->SetWeights(weights); - } - } catch (const Exception& iee) { - xmlDoc.reset(); - return DescriptionBuffer(desc) << iee.what(); - } - - xmlDoc.reset(); - return OK; -} - -static size_t GetFileVersion(pugi::xml_node& root) { - return pugixml::utils::GetUIntAttr(root, "version", 0); -} - -StatusCode CNNNetReaderImpl::ReadNetwork(const void* model, size_t size, ResponseDesc* resp) noexcept { - if (network) { - return DescriptionBuffer(NETWORK_NOT_READ, resp) - << "Network has been read already, use new reader instance to read new network."; - } - - xmlDoc = std::make_shared(); - pugi::xml_parse_result res = xmlDoc->load_buffer(model, size); - if (res.status != pugi::status_ok) { - return DescriptionBuffer(resp) << res.description() << " at offset " << res.offset; - } - StatusCode ret = ReadNetwork(); - if (ret != OK) { - return DescriptionBuffer(resp) << "Error reading network: " << description; - } - return OK; -} - -namespace { - -void readAllFile(const std::string& string_file_name, void* buffer, size_t maxSize) { - std::ifstream inputFile; - -#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - std::wstring file_name = ov::util::string_to_wstring(string_file_name.c_str()); -#else - std::string file_name = string_file_name; -#endif - - inputFile.open(file_name.c_str(), std::ios::binary | std::ios::in); - if (!inputFile.is_open()) - IE_THROW() << "cannot open file " << string_file_name; - if (!inputFile.read(reinterpret_cast(buffer), maxSize)) { - inputFile.close(); - IE_THROW() << "cannot read " << maxSize << " bytes from file " << string_file_name; - } - - inputFile.close(); -} - -} // namespace - -StatusCode CNNNetReaderImpl::ReadWeights(const char* filepath, ResponseDesc* resp) noexcept { - OV_ITT_SCOPED_TASK(itt::domains::V7Reader, "CNNNetReaderImpl::ReadWeights"); - int64_t fileSize = FileUtils::fileSize(filepath); - - if (fileSize < 0) - return DescriptionBuffer(resp) << "filesize for: " << filepath << " - " << fileSize - << "<0. Please, check weights file existence."; - - // If IR V10 then there hasn't been loaded network yet - if (network.get() == nullptr && _version < 10) { - return DescriptionBuffer(resp) << "network is empty"; - } - - auto ulFileSize = static_cast(fileSize); - - try { - TBlob::Ptr weightsPtr(new TBlob(TensorDesc(Precision::U8, {ulFileSize}, Layout::C))); - weightsPtr->allocate(); - readAllFile(filepath, weightsPtr->buffer(), ulFileSize); - return SetWeights(weightsPtr, resp); - } catch (const Exception& ex) { - return DescriptionBuffer(resp) << ex.what(); - } -} - -ICNNNetwork* CNNNetReaderImpl::getNetwork(ResponseDesc* resp) noexcept { - OV_ITT_SCOPED_TASK(itt::domains::V7Reader, "CNNNetReaderImpl::getNetwork"); - return network.get(); -} - -StatusCode CNNNetReaderImpl::ReadNetwork(const char* filepath, ResponseDesc* resp) noexcept { - OV_ITT_SCOPED_TASK(itt::domains::V7Reader, "CNNNetReaderImpl::ReadNetwork"); - if (network) { - return DescriptionBuffer(NETWORK_NOT_READ, resp) - << "Network has been read already, use new reader instance to read new network."; - } - - auto parse_result = ParseXml(filepath); - if (!parse_result.error_msg.empty()) { - return DescriptionBuffer(resp) << parse_result.error_msg; - } - xmlDoc = std::move(parse_result.xml); - - StatusCode ret = ReadNetwork(); - if (ret != OK) { - return DescriptionBuffer(resp) << "Error reading network: " << description; - } - return OK; -} - -StatusCode CNNNetReaderImpl::ReadNetwork(const pugi::xml_node& const_root, ResponseDesc* desc) { - try { - pugi::xml_node root = *const_cast(&const_root); - _version = GetFileVersion(root); - if (_version < 2) - IE_THROW() << "deprecated IR version: " << _version; - - if (_version < 10) { - _parser = parserCreator->create(_version); - InferenceEngine::details::CNNNetworkImplPtr local_network = _parser->Parse(root); - name = local_network->getName(); - local_network->validate(static_cast(_version)); - network = local_network; - parseSuccess = true; - } else { - IE_THROW() << "cannot parse future versions: " << _version; - } - } catch (const std::string& err) { - parseSuccess = false; - return DescriptionBuffer(desc) << err; - } catch (const Exception& e) { - description = e.what(); - parseSuccess = false; - return DescriptionBuffer(desc) << e.what(); - } catch (const std::exception& e) { - description = e.what(); - parseSuccess = false; - return DescriptionBuffer(desc) << e.what(); - } catch (...) { - parseSuccess = false; - return DescriptionBuffer(UNEXPECTED, desc) << "Unknown exception thrown"; - } - - return OK; -} - -StatusCode CNNNetReaderImpl::ReadNetwork() { - description.clear(); - - try { - // check which version it is... - pugi::xml_node root = xmlDoc->document_element(); - - ResponseDesc resp; - StatusCode ret = ReadNetwork(root, &resp); - if (ret != OK) - description = resp.msg; - return ret; - } catch (const std::exception& e) { - description = e.what(); - parseSuccess = false; - return GENERAL_ERROR; - } catch (...) { - description = "Unknown exception thrown"; - parseSuccess = false; - return UNEXPECTED; - } - - return OK; -} - -std::shared_ptr V2FormatParserCreator::create(size_t version) { - return std::make_shared(version); -} diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_cnn_net_reader_impl.h b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_cnn_net_reader_impl.h deleted file mode 100644 index 97203f1b757..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_cnn_net_reader_impl.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include "ie_memcpy.h" -#include "parsers.h" - -namespace pugi { -class xml_node; - -class xml_document; -} // namespace pugi - -namespace InferenceEngine { -namespace details { - -struct FormatParserCreator { - using Ptr = std::shared_ptr; - virtual std::shared_ptr create(size_t version) = 0; - virtual ~FormatParserCreator() = default; -}; - -struct V2FormatParserCreator : public FormatParserCreator { - std::shared_ptr create(size_t version) override; -}; - -class CNNNetReaderImpl { -public: - explicit CNNNetReaderImpl(const FormatParserCreator::Ptr& _creator); - - StatusCode ReadNetwork(const char* filepath, ResponseDesc* resp) noexcept; - - StatusCode ReadNetwork(const void* model, size_t size, ResponseDesc* resp) noexcept; - - StatusCode ReadNetwork(const pugi::xml_node& root, ResponseDesc* resp); - - StatusCode SetWeights(const TBlob::Ptr& weights, ResponseDesc* resp) noexcept; - - StatusCode ReadWeights(const char* filepath, ResponseDesc* resp) noexcept; - - ICNNNetwork* getNetwork(ResponseDesc* resp) noexcept; - - CNNNetwork getNetwork() { - IE_SUPPRESS_DEPRECATED_START - return CNNNetwork(network); - IE_SUPPRESS_DEPRECATED_END - } - - StatusCode getName(char* name, size_t len, ResponseDesc* resp) noexcept { - if (len > 0) { - size_t length = std::min(this->name.size(), len - 1); // cut the name if buffer is too small - ie_memcpy(name, len, this->name.c_str(), length); - name[length] = '\0'; // null terminate - } - return OK; - } - -private: - std::shared_ptr _parser; - StatusCode ReadNetwork(); - - std::string description; - std::string name; - std::shared_ptr network; - bool parseSuccess; - size_t _version; - FormatParserCreator::Ptr parserCreator; - - // Stashed xmlDoc that is needed to delayed loading of V10 IR version - std::shared_ptr xmlDoc; -}; - -} // namespace details -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_format_parser.cpp b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_format_parser.cpp deleted file mode 100644 index f515c6c956b..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_format_parser.cpp +++ /dev/null @@ -1,773 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ie_format_parser.h" - -#include -#include -#include -#include - -#include "ie_blob_proxy.hpp" -#include "ie_layer_parsers.h" -#include "ie_layer_validators.hpp" -#include "xml_parse_utils.h" - -using namespace InferenceEngine; -using namespace InferenceEngine::details; -using namespace pugixml::utils; -using namespace std; - -void LayerParseParameters::addOutputPort(const LayerPortData& port) { - outputPorts.insert(std::upper_bound(outputPorts.begin(), - outputPorts.end(), - port, - [=](const LayerParseParameters::LayerPortData& lhs, - const LayerParseParameters::LayerPortData& rhs) { - return lhs.portId < rhs.portId; - }), - port); -} - -void LayerParseParameters::addInputPort(const LayerPortData& port) { - inputPorts.insert(std::upper_bound(inputPorts.begin(), - inputPorts.end(), - port, - [=](const LayerParseParameters::LayerPortData& lhs, - const LayerParseParameters::LayerPortData& rhs) { - return lhs.portId < rhs.portId; - }), - port); -} - -IE_SUPPRESS_DEPRECATED_START - -inline void ParseSegment(LayerParseParameters& prms, const pugi::xml_node& blob) { - uint64_t size = GetUInt64Attr(blob, "size", 0); - uint64_t start = GetUInt64Attr(blob, "offset", 0); - if (!size) - return; - - WeightSegment& segment = prms.blobs[blob.name()]; - segment.start = static_cast(start); - segment.size = static_cast(size); - const std::string& preStr = GetStrAttr(blob, "precision", ""); - if (!preStr.empty()) - segment.precision = Precision::FromStr(preStr); - else - segment.precision = prms.prms.precision; -} - -void FormatParser::ParsePort(LayerParseParameters::LayerPortData& port, pugi::xml_node& node) const { - port.portId = GetIntAttr(node, "id"); - ParseDims(port.dims, node); - const std::string& preStr = GetStrAttr(node, "precision", ""); - if (!preStr.empty()) - port.precision = Precision::FromStr(preStr); -} - -void FormatParser::ParseGenericParams(pugi::xml_node& node, LayerParseParameters& layerParsePrms) const { - layerParsePrms.layerId = GetIntAttr(node, "id"); - layerParsePrms.underIRVersion = _version; - - InferenceEngine::LayerParams& prms = layerParsePrms.prms; - prms.type = pugixml::utils::GetStrAttr(node, "type"); - prms.precision = _defPrecision; - - prms.name = GetStrAttr(node, "name"); - const std::string& preStr = GetStrAttr(node, "precision", ""); - if (!preStr.empty()) - prms.precision = Precision::FromStr(preStr); - - if (prms.precision == Precision::MIXED) { - IE_THROW() << "Layer precision must not be MIXED, at layer name: " << prms.name - << ", offset: " << node.offset_debug(); - } - - auto outNode = node.child("output"); - if (!outNode.empty()) { - FOREACH_CHILD (_cn, outNode, "port") { - LayerParseParameters::LayerPortData port; - port.precision = prms.precision; - ParsePort(port, _cn); - if (prms.type == "Const" || !prms.precision) - prms.precision = port.precision; - layerParsePrms.addOutputPort(port); - } - } - auto inpNode = node.child("input"); - if (!inpNode.empty()) { - FOREACH_CHILD (_cn, inpNode, "port") { - LayerParseParameters::LayerPortData port; - port.precision = prms.precision; - ParsePort(port, _cn); - layerParsePrms.addInputPort(port); - } - } - auto blob = node.child("biases"); - if (!blob.empty()) { - ParseSegment(layerParsePrms, blob); - } - blob = node.child("weights"); - if (!blob.empty()) { - ParseSegment(layerParsePrms, blob); - } - auto blobs = node.child("blobs"); - if (!blobs.empty()) { - for (blob = blobs.first_child(); !blob.empty(); blob = blob.next_sibling()) { - ParseSegment(layerParsePrms, blob); - } - } -} - -IE_SUPPRESS_DEPRECATED_END - -static inline std::string gen_id(int layer_id, int port_id) { - return (std::to_string(layer_id) + '.' + std::to_string(port_id)); -} - -InferenceEngine::CNNLayer::Ptr FormatParser::CreateLayer(pugi::xml_node& node, - LayerParseParameters& layerParsePrms) const { - for (auto& creator : creators) { - if (!creator->shouldCreate(layerParsePrms.prms.type)) - continue; - return creator->CreateLayer(node, layerParsePrms); - } - LayerCreator genericCreator(""); - return genericCreator.CreateLayer(node, layerParsePrms); -} - -void FormatParser::SetLayerInput(CNNNetworkImpl& network, - const std::string& dataId, - CNNLayerPtr& targetLayer, - int inputPort) { - DataPtr& dataPtr = _portsToData[dataId]; - if (!dataPtr) - IE_THROW() << "in Layer " << targetLayer->name - << ": trying to connect an edge to non existing output port: " << dataId; - - getInputTo(dataPtr)[targetLayer->name] = targetLayer; - const LayerParseParameters& parseInfo = layersParseInfo[targetLayer->name]; - if (targetLayer->insData.empty()) { - targetLayer->insData.resize(parseInfo.inputPorts.size()); - } - for (unsigned i = 0; i < parseInfo.inputPorts.size(); i++) { - if (parseInfo.inputPorts[i].portId != inputPort) - continue; - if (parseInfo.inputPorts[i].precision != dataPtr->getPrecision()) { - if (dataPtr->getPrecision() == Precision::UNSPECIFIED) { - dataPtr->setPrecision(parseInfo.inputPorts[i].precision); - } else { - // TODO: Make a correct exception - - /*IE_THROW() << "in Layer " << targetLayer->name - << ": trying to connect an edge to mismatch precision of output port: " - << dataPtr->getName();*/ - } - } - if (!equal(parseInfo.inputPorts[i].dims, dataPtr->getDims())) - IE_THROW() << "in Layer " << targetLayer->name - << ": trying to connect an edge to mismatch dimensions of output port: " << dataPtr->getName() - << " dims input: " << dumpVec(parseInfo.inputPorts[i].dims) - << " dims output: " << dumpVec(dataPtr->getDims()); - targetLayer->insData[i] = dataPtr; - const auto insId = gen_id(parseInfo.layerId, parseInfo.inputPorts[i].portId); - _portsToData[insId] = dataPtr; - return; - } - IE_THROW() << "input port " << inputPort << " does not exist in layer " << targetLayer->name; -} - -FormatParser::FormatParser(size_t version) : _version(version) { - // there should be unique_ptr but it cant be used with initializer lists - creators = {std::make_shared>("Power"), - std::make_shared>("Convolution"), - std::make_shared>("Deconvolution"), - std::make_shared>("DeformableConvolution"), - std::make_shared>("Pooling"), - std::make_shared>("InnerProduct"), - std::make_shared>("FullyConnected"), - std::make_shared>("LRN"), - std::make_shared>("Norm"), - std::make_shared>("Softmax"), - std::make_shared>("LogSoftmax"), - std::make_shared>("GRN"), - std::make_shared>("MVN"), - std::make_shared>("ReLU"), - std::make_shared>("Clamp"), - std::make_shared>("Split"), - std::make_shared>("Slice"), - std::make_shared>("Concat"), - std::make_shared>("Eltwise"), - std::make_shared>("Gemm"), - std::make_shared>("Pad"), - std::make_shared>("Gather"), - std::make_shared>("StridedSlice"), - std::make_shared>("ShuffleChannels"), - std::make_shared>("DepthToSpace"), - std::make_shared>("SpaceToDepth"), - std::make_shared>("SpaceToBatch"), - std::make_shared>("BatchToSpace"), - std::make_shared>("SparseFillEmptyRows"), - std::make_shared>("SparseSegmentMean"), - std::make_shared>("SparseSegmentSqrtN"), - std::make_shared>("SparseSegmentSum"), - std::make_shared>("ExperimentalSparseWeightedSum"), - std::make_shared>("SparseToDense"), - std::make_shared>("Bucketize"), - std::make_shared>("ReverseSequence"), - std::make_shared>("Squeeze"), - std::make_shared>("Unsqueeze"), - std::make_shared>("Range"), - std::make_shared>("Broadcast"), - std::make_shared>("ScaleShift"), - std::make_shared>("PReLU"), - std::make_shared>("Crop"), - std::make_shared>("Reshape"), - std::make_shared>("Flatten"), - std::make_shared>("Tile"), - std::make_shared("Activation"), - std::make_shared>("BatchNormalization"), - std::make_shared("TensorIterator"), - std::make_shared>("LSTMCell"), - std::make_shared>("GRUCell"), - std::make_shared>("RNNCell"), - std::make_shared>("OneHot"), - std::make_shared>("RNNSequence"), - std::make_shared>("GRUSequence"), - std::make_shared>("LSTMSequence"), - std::make_shared>("BinaryConvolution"), - std::make_shared>("Select"), - std::make_shared>("Abs"), - std::make_shared>("Acos"), - std::make_shared>("Acosh"), - std::make_shared>("Asin"), - std::make_shared>("Asinh"), - std::make_shared>("Atan"), - std::make_shared>("Atanh"), - std::make_shared>("Ceil"), - std::make_shared>("Cos"), - std::make_shared>("Cosh"), - std::make_shared>("Erf"), - std::make_shared>("Floor"), - std::make_shared>("HardSigmoid"), - std::make_shared>("Log"), - std::make_shared>("Neg"), - std::make_shared>("Reciprocal"), - std::make_shared>("Selu"), - std::make_shared>("Sign"), - std::make_shared>("Sin"), - std::make_shared>("Sinh"), - std::make_shared>("Softplus"), - std::make_shared>("Softsign"), - std::make_shared>("Tan"), - std::make_shared>("ReduceAnd"), - std::make_shared>("ReduceL1"), - std::make_shared>("ReduceL2"), - std::make_shared>("ReduceLogSum"), - std::make_shared>("ReduceLogSumExp"), - std::make_shared>("ReduceMax"), - std::make_shared>("ReduceMean"), - std::make_shared>("ReduceMin"), - std::make_shared>("ReduceOr"), - std::make_shared>("ReduceProd"), - std::make_shared>("ReduceSum"), - std::make_shared>("ReduceSumSquare"), - std::make_shared>("GatherTree"), - std::make_shared>("TopK"), - std::make_shared>("Unique"), - std::make_shared>("NonMaxSuppression"), - std::make_shared>("ScatterUpdate"), - std::make_shared>("ScatterElementsUpdate"), - std::make_shared>( - "ExperimentalDetectronPriorGridGenerator"), - std::make_shared>( - "ExperimentalDetectronGenerateProposalsSingleImage"), - std::make_shared>("ExperimentalDetectronTopKROIs")}; - creators.emplace_back(_version < 6 ? std::make_shared>("Quantize") - : std::make_shared>("FakeQuantize")); -} - -CNNNetworkImplPtr FormatParser::Parse(pugi::xml_node& root) { - _network.reset(new CNNNetworkImpl()); - _network->setName(GetStrAttr(root, "name", "")); - _defPrecision = Precision::FromStr(GetStrAttr(root, "precision", "UNSPECIFIED")); - // parse the input Data - DataPtr inputData; - // parse the graph layers - auto allLayersNode = root.child("layers"); - std::vector inputLayers; - int nodeCnt = 0; - std::map layerById; - FOREACH_CHILD (node, allLayersNode, "layer") { - LayerParseParameters lprms; - ParseGenericParams(node, lprms); - - CNNLayer::Ptr layer = CreateLayer(node, lprms); - if (!layer) - IE_THROW() << "Don't know how to create Layer type: " << lprms.prms.type; - - layersParseInfo[layer->name] = lprms; - _network->addLayer(layer); - layerById[lprms.layerId] = layer; - - if (equal(layer->type, "input")) { - inputLayers.push_back(layer); - } - - for (size_t i = 0; i < lprms.outputPorts.size(); i++) { - const auto& outPort = lprms.outputPorts[i]; - const auto outId = gen_id(lprms.layerId, outPort.portId); - const std::string outName = - lprms.outputPorts.size() == 1 ? lprms.prms.name : lprms.prms.name + "." + std::to_string(i); - DataPtr& ptr = _network->getData(outName.c_str()); - if (!ptr) { - ptr.reset( - new Data(outName, {outPort.precision, outPort.dims, TensorDesc::getLayoutByDims(outPort.dims)})); - } - _portsToData[outId] = ptr; - - if (getCreatorLayer(ptr).lock()) - IE_THROW() << "two layers set to the same output [" << outName << "], conflict at offset " - << node.offset_debug(); - - getCreatorLayer(ptr) = layer; - layer->outData.push_back(ptr); - } - nodeCnt++; - } - - // connect the edges - pugi::xml_node edges = root.child("edges"); - - FOREACH_CHILD (_ec, edges, "edge") { - int fromLayer = GetIntAttr(_ec, "from-layer"); - int fromPort = GetIntAttr(_ec, "from-port"); - int toLayer = GetIntAttr(_ec, "to-layer"); - int toPort = GetIntAttr(_ec, "to-port"); - - const auto dataId = gen_id(fromLayer, fromPort); - auto targetLayer = layerById[toLayer]; - if (!targetLayer) - IE_THROW() << "Layer ID " << toLayer << " was not found while connecting edge at offset " - << _ec.offset_debug(); - - SetLayerInput(*_network, dataId, targetLayer, toPort); - } - - auto keep_input_info = [&](DataPtr& in_data) { - InputInfo::Ptr info(new InputInfo()); - info->setInputData(in_data); - Precision prc = info->getPrecision(); - - // Convert precision into native format (keep element size) - prc = prc == Precision::Q78 - ? Precision::I16 - : prc == Precision::FP16 ? Precision::FP32 : static_cast(prc); - - info->setPrecision(prc); - _network->setInputInfo(info); - }; - - // Keep all data from InputLayers - for (auto inLayer : inputLayers) { - if (inLayer->outData.size() != 1) - IE_THROW() << "Input layer must have 1 output. " - "See documentation for details."; - keep_input_info(inLayer->outData[0]); - } - - // Keep all data which has no creator layer - for (auto& kvp : _network->allLayers()) { - const CNNLayer::Ptr& layer = kvp.second; - auto pars_info = layersParseInfo[layer->name]; - - if (layer->insData.empty()) - layer->insData.resize(pars_info.inputPorts.size()); - - for (size_t i = 0; i < layer->insData.size(); i++) { - if (!layer->insData[i].lock()) { - std::string data_name = - (layer->insData.size() == 1) ? layer->name : layer->name + "." + std::to_string(i); - - DataPtr data(new Data(data_name, - {pars_info.inputPorts[i].precision, - pars_info.inputPorts[i].dims, - TensorDesc::getLayoutByDims(pars_info.inputPorts[i].dims)})); - - layer->insData[i] = data; - getInputTo(data)[layer->name] = layer; - - const auto insId = gen_id(pars_info.layerId, pars_info.inputPorts[i].portId); - _portsToData[insId] = data; - - keep_input_info(data); - } - } - - /* - * TODO: WA. IR v6 has no precision specification for input data ports. - * So they have default values (generally FP32), which doesn't consists - * with TI port precision. Remove this line after switching onto IR v7 - * and v10. - */ - if (layer->type == "TensorIterator") { - auto ti = dynamic_cast(layer.get()); - if (!ti) - IE_THROW() << "Failed to cast to 'TensorIterator'"; - for (auto& in_map_rule : ti->input_port_map) { - auto exter_data = ti->insData[in_map_rule.from].lock(); - auto inter_data = ti->body.inputs[in_map_rule.to]; - - auto ti_specified_precision = exter_data->getPrecision(); - inter_data->setPrecision(ti_specified_precision); - } - } - } - - if (!_network->allLayers().size()) - IE_THROW() << "Incorrect model! Network doesn't contain layers."; - - size_t inputLayersNum(0); - CaselessEq cmp; - for (const auto& kvp : _network->allLayers()) { - const CNNLayer::Ptr& layer = kvp.second; - if (cmp(layer->type, "Input") || cmp(layer->type, "Const")) - inputLayersNum++; - } - - if (!inputLayersNum && !cmp(root.name(), "body")) - IE_THROW() << "Incorrect model! Network doesn't contain input layers."; - - // check all input ports are occupied - for (const auto& kvp : _network->allLayers()) { - const CNNLayer::Ptr& layer = kvp.second; - const LayerParseParameters& parseInfo = layersParseInfo[layer->name]; - size_t inSize = layer->insData.size(); - if (inSize != parseInfo.inputPorts.size()) - IE_THROW() << "Layer " << layer->name << " does not have any edge connected to it"; - - for (unsigned i = 0; i < inSize; i++) { - if (!layer->insData[i].lock()) { - IE_THROW() << "Layer " << layer->name.c_str() << " input port " << parseInfo.inputPorts[i].portId - << " is not connected to any data"; - } - } - layer->parseParams(); - details::validateLayer(layer.get()); - } - // parse mean image - ParsePreProcess(root); - _network->resolveOutput(); - - // Set default output precision to FP32 (for back-compatibility) - OutputsDataMap outputsInfo; - _network->getOutputsInfo(outputsInfo); - for (auto outputInfo : outputsInfo) { - if (outputInfo.second->getPrecision() == Precision::I64) { - outputInfo.second->setPrecision(Precision::I32); - } else if (outputInfo.second->getPrecision() != Precision::FP32 && - outputInfo.second->getPrecision() != Precision::I32) { - outputInfo.second->setPrecision(Precision::FP32); - } - } - - return _network; -} - -template -inline Blob::Ptr GetTypedBlobFromSegment(const TBlob::Ptr& weights, const WeightSegment& segment) { - if (segment.getEnd() > weights->size()) - IE_THROW() << "segment size(" << segment.getEnd() << ") exceeds given buffer limits(" << weights->size() - << "). Please, validate weights file"; - - size_t noOfElement = segment.size / sizeof(BlobType); - // RanC: TODO: IR does not provide me with weight slayout. - // So far I knew it since I know what layer it is. In generic layers I don't - // so until the IR will have the layout and sizes I will pass it as vector and the plugin will have to - // validate and undertand what he should get... - SizeVector w_dims({noOfElement}); - - typename TBlobProxy::Ptr binBlob( - new TBlobProxy(segment.precision, Layout::C, weights, segment.start, w_dims)); - - /* this validation is not reduntant I have no prior knowledge of the weights anymore... - if (pbpWeights->byteSize() != lprms.weights.size) - IE_THROW() << "bytes size weights for " << pWL->name << " mismatch, expecting " - << pbpWeights->byteSize() << " bytes which are " << pbpWeights->size() << " elements"; - */ - return binBlob; -} - -Blob::Ptr FormatParser::GetBlobFromSegment(const TBlob::Ptr& weights, const WeightSegment& segment) const { - if (segment.precision == Precision::FP32) { - return GetTypedBlobFromSegment(weights, segment); - } else if (segment.precision == Precision::I64) { - return GetTypedBlobFromSegment(weights, segment); - } else if (segment.precision == Precision::I32) { - return GetTypedBlobFromSegment(weights, segment); - } else if (segment.precision == Precision::I16 || segment.precision == Precision::Q78 || - segment.precision == Precision::FP16) { - return GetTypedBlobFromSegment(weights, segment); - } else if (segment.precision == Precision::U8 || segment.precision == Precision::BOOL) { - return GetTypedBlobFromSegment(weights, segment); - } else if (segment.precision == Precision::I8 || segment.precision == Precision::BIN) { - return GetTypedBlobFromSegment(weights, segment); - } else { - IE_THROW() << "precision " << segment.precision << " is not supported..."; - } -} - -void FormatParser::SetWeights(const TBlob::Ptr& weights) { - if (weights == nullptr) - return; - - for (auto& kvp : _network->allLayers()) { - auto fit = layersParseInfo.find(kvp.second->name); - // todo: may check that earlier - while parsing... - if (fit == layersParseInfo.end()) - IE_THROW() << "Internal Error: ParseInfo for " << kvp.second->name << " are missing..."; - auto& lprms = fit->second; - - WeightableLayer* pWL = dynamic_cast(kvp.second.get()); - if (pWL != nullptr) { - if (lprms.blobs.find("weights") != lprms.blobs.end()) { - if (lprms.prms.type == "BinaryConvolution") { - auto segment = lprms.blobs["weights"]; - if (segment.getEnd() > weights->size()) - IE_THROW() << "segment exceeds given buffer limits. Please, validate weights file"; - size_t noOfElement = segment.size; - SizeVector w_dims({noOfElement}); - typename TBlobProxy::Ptr binBlob( - new TBlobProxy(Precision::BIN, Layout::C, weights, segment.start, w_dims)); - - pWL->_weights = binBlob; - } else { - pWL->_weights = GetBlobFromSegment(weights, lprms.blobs["weights"]); - } - pWL->blobs["weights"] = pWL->_weights; - } - if (lprms.blobs.find("biases") != lprms.blobs.end()) { - pWL->_biases = GetBlobFromSegment(weights, lprms.blobs["biases"]); - pWL->blobs["biases"] = pWL->_biases; - } - } - auto pGL = kvp.second.get(); - if (pGL == nullptr) - continue; - for (auto s : lprms.blobs) { - pGL->blobs[s.first] = GetBlobFromSegment(weights, s.second); - if (pGL->type == "Const") { - auto shapes = pGL->outData[0]->getTensorDesc().getDims(); - pGL->blobs[s.first]->getTensorDesc().reshape(shapes, TensorDesc::getLayoutByDims(shapes)); - } - } - - // Some layer can specify additional action to prepare weights - if (fit->second.internalWeightSet) - fit->second.internalWeightSet(weights); - } - for (auto& kvp : _preProcessSegments) { - const std::string& inputName = kvp.first; - auto& segments = kvp.second; - auto inputInfo = _network->getInput(inputName); - if (!inputInfo) - IE_THROW() << "Internal error: missing input name " << inputName; - - auto dims = inputInfo->getTensorDesc().getDims(); - size_t width = 0ul, height = 0ul; - - if (dims.size() == 3) { - height = dims.at(1); - width = dims.at(2); - } else if (dims.size() == 4) { - height = dims.at(2); - width = dims.at(3); - } else if (dims.size() == 5) { - height = dims.at(3); - width = dims.at(4); - } else { - IE_THROW() << inputName << " has unsupported layout " << inputInfo->getTensorDesc().getLayout(); - } - - PreProcessInfo& pp = inputInfo->getPreProcess(); - - for (size_t c = 0; c < segments.size(); c++) { - if (segments[c].size == 0) - continue; - Blob::Ptr blob = GetBlobFromSegment(weights, segments[c]); - blob->getTensorDesc().reshape({height, width}, - Layout::HW); // to fit input image sizes (summing it is an image) - pp.setMeanImageForChannel(blob, c); - } - } -} - -void FormatParser::ParseDims(SizeVector& dims, const pugi::xml_node& parentNode) const { - FOREACH_CHILD (node, parentNode, "dim") { - unsigned int dim = 0; - const pugi::char_t* dimVal = node.child_value(); - stringstream ss(dimVal); - if (!(ss >> dim) || dim == 0) { - IE_THROW() << "dimension (" << dimVal << ") in node " << node.name() - << " must be a positive integer: at offset " << node.offset_debug(); - } - dims.push_back(dim); - } -} - -const DataPtr& FormatParser::GetDataBy(int layer_id, int port_id) const { - const auto id = gen_id(layer_id, port_id); - const auto& found = _portsToData.find(id); - if (found == _portsToData.end()) - IE_THROW() << "No data found for layer_id=" << layer_id << " port_id=" << port_id; - return found->second; -} - -void FormatParser::ParsePreProcess(pugi::xml_node& root) { - /* - - - // in case of constant - // or - // in case of array – ref to the .bin file - - - - */ - - auto ppNode = root.child("pre-process"); - if (ppNode.empty()) { - return; - } - // find out to what input this belongs to - std::string inputName; - InputInfo::Ptr preProcessInput; - - inputName = GetStrAttr(ppNode, "reference-layer-name", ""); - inputName = trim(inputName); - if (inputName.empty()) { - // fallback (old format), look for the picture in the inputs - InputsDataMap inputs; - _network->getInputsInfo(inputs); - - if (inputs.empty()) - IE_THROW() << "network has no input"; - - for (auto i : inputs) { - if (i.second->getTensorDesc().getDims().size() == 4) { - preProcessInput = i.second; - break; - } - } - if (!preProcessInput) { - preProcessInput = inputs.begin()->second; - } - - inputName = preProcessInput->name(); - } else { - preProcessInput = _network->getInput(inputName); - if (!preProcessInput) - IE_THROW() << "pre-process name ref '" << inputName << "' refers to un-existing input"; - } - - // dims vector without batch size - SizeVector inputDims = preProcessInput->getTensorDesc().getDims(); - size_t noOfChannels = 0, width = 0, height = 0; - - if (inputDims.size() < 2) { - IE_THROW() << "network did not define input dimensions properly"; - } else if (inputDims.size() == 2) { // NC - noOfChannels = inputDims[1]; - width = inputDims[1]; - height = inputDims[0]; - } else if (inputDims.size() == 3) { - width = inputDims[2]; - height = inputDims[1]; - noOfChannels = inputDims[0]; - } else if (inputDims.size() == 4) { - width = inputDims[3]; - height = inputDims[2]; - noOfChannels = inputDims[1]; - } else if (inputDims.size() == 5) { - width = inputDims[4]; - height = inputDims[3]; - noOfChannels = inputDims[2]; - } - - PreProcessInfo& pp = preProcessInput->getPreProcess(); - std::vector& segments = _preProcessSegments[inputName]; - - pp.init(noOfChannels); - - segments.resize(noOfChannels); - - auto meanSegmentPrecision = GetPrecisionAttr(ppNode, "mean-precision", Precision::UNSPECIFIED); - - InferenceEngine::PreProcessChannel::Ptr preProcessChannel; - - int lastChanNo = -1; - std::unordered_set idsForMeanValue; - std::unordered_set idsForMeanImage; - - FOREACH_CHILD (chan, ppNode, "channel") { - int chanNo = GetIntAttr(chan, "id", lastChanNo + 1); - if (chanNo >= static_cast(noOfChannels) || chanNo < 0) { - IE_THROW() << "Pre-process channel id invalid: " << chanNo; - } - lastChanNo = chanNo; - preProcessChannel = pp[chanNo]; - WeightSegment& preProcessSegment = segments[chanNo]; - - auto meanNode = chan.child("mean"); - if (!meanNode.empty()) { - if (!meanNode.attribute("value") && (!meanNode.attribute("size"))) { - IE_THROW() << "mean should have at least one of the following attribute: value, size"; - } - if (meanNode.attribute("value")) { - preProcessChannel->meanValue = GetFloatAttr(meanNode, "value"); - idsForMeanValue.insert(chanNo); - } - if (meanNode.attribute("size")) { - idsForMeanImage.insert(chanNo); - preProcessSegment.size = static_cast(GetIntAttr(meanNode, "size")); - preProcessSegment.start = static_cast(GetIntAttr(meanNode, "offset")); - preProcessSegment.precision = meanSegmentPrecision; - if (width * height * meanSegmentPrecision.size() != preProcessSegment.size) { - IE_THROW() << "mean blob size mismatch expected input, got: " << preProcessSegment.size - << " extpecting " << width << " x " << height << " x " << meanSegmentPrecision.size(); - } - if (!meanSegmentPrecision || meanSegmentPrecision == Precision::MIXED) - IE_THROW() << "mean blob defined without specifying precision."; - } - } - auto scaleNode = chan.child("scale"); - if (!scaleNode.empty() && scaleNode.attribute("value")) { - preProcessChannel->stdScale = GetFloatAttr(scaleNode, "value"); - } - } - - if (idsForMeanImage.size() == noOfChannels) { - pp.setVariant(MEAN_IMAGE); - } else if (idsForMeanValue.size() == noOfChannels) { - pp.setVariant(MEAN_VALUE); - } else if ((idsForMeanImage.size() == 0) && (idsForMeanValue.size() == 0)) { - pp.setVariant(NONE); - } else { - std::string validMeanValuesIds = ""; - std::string validMeanImageIds = ""; - for (auto id : idsForMeanValue) { - validMeanValuesIds += std::to_string(id) + " "; - } - for (auto id : idsForMeanImage) { - validMeanImageIds += std::to_string(id) + " "; - } - IE_THROW() << "mean is not provided for all channels\n" - "Provided mean values for : " - << validMeanValuesIds - << "\n" - "Provided mean image for: " - << validMeanImageIds; - } -} diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_format_parser.h b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_format_parser.h deleted file mode 100644 index 980104eca84..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_format_parser.h +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include - -#include "caseless.hpp" -#include "parsers.h" - -namespace InferenceEngine { -namespace details { -struct WeightSegment { - Precision precision; - // offset in bytes of the global weights array - size_t start = 0; - // size in bytes - size_t size = 0; - - inline size_t getEnd() const { - return start + size; - } - - // checks if this segment is in the range of 0 to rangeSize, safer than using getEnd() to avoid int overflow - inline bool inRange(size_t rangeSize) const { - return start < rangeSize && (rangeSize - start) >= size; - } -}; - -struct LayerParseParameters { - struct LayerPortData { - int portId; - Precision precision; - SizeVector dims; - }; - InferenceEngine::LayerParams prms; - int layerId = -1; - std::vector inputPorts; - std::vector outputPorts; - std::map blobs; - - std::function::Ptr& weights)> internalWeightSet; - - size_t underIRVersion = 0; - - void addOutputPort(const LayerPortData& port); - void addInputPort(const LayerPortData& port); -}; - -class BaseCreator { -private: - std::string type_; - -protected: - explicit BaseCreator(const std::string& type) : type_(type) {} - -public: - virtual ~BaseCreator() {} - - virtual CNNLayer::Ptr CreateLayer(pugi::xml_node& node, LayerParseParameters& layerParsePrms) = 0; - - bool shouldCreate(const std::string& nodeType) const { - InferenceEngine::details::CaselessEq comparator; - return comparator(nodeType, type_); - } -}; - -class FormatParser : public IFormatParser { -public: - explicit FormatParser(size_t version); - - CNNNetworkImplPtr Parse(pugi::xml_node& root) override; - - Blob::Ptr GetBlobFromSegment(const TBlob::Ptr& weights, const WeightSegment& weight_segment) const; - void SetWeights(const TBlob::Ptr& weights) override; - void ParseDims(SizeVector& dims, const pugi::xml_node& node) const; - const DataPtr& GetDataBy(int layer_id, int port_id) const; - -protected: - std::map layersParseInfo; - -private: - size_t _version; - Precision _defPrecision = Precision::UNSPECIFIED; - std::vector> creators; - std::map _portsToData; - - CNNNetworkImplPtr _network; - std::map> _preProcessSegments; - void ParsePort(LayerParseParameters::LayerPortData& port, pugi::xml_node& node) const; - void ParseGenericParams(pugi::xml_node& node, LayerParseParameters& layerParsePrms) const; - CNNLayer::Ptr CreateLayer(pugi::xml_node& node, LayerParseParameters& prms) const; - - void SetLayerInput(CNNNetworkImpl& network, const std::string& data, CNNLayerPtr& targetLayer, int inputPort); - - void ParsePreProcess(pugi::xml_node& node); - - // Generate different set of creators depending on required IR version - static std::vector> generateCreators(int version); -}; -} // namespace details -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_itt.hpp b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_itt.hpp deleted file mode 100644 index 5dbe9331fd0..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_itt.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief Defines openvino domains for tracing - * @file itt.hpp - */ - -#pragma once - -#include - -namespace InferenceEngine { -namespace itt { -namespace domains { -OV_ITT_DOMAIN(V7Reader); -} -} // namespace itt -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_parser.cpp b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_parser.cpp deleted file mode 100644 index 70dd9099379..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_parser.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ie_ir_parser.hpp" - -#include "ie_cnn_net_reader_impl.h" -#include "legacy/ie_reader.hpp" - -using namespace InferenceEngine; - -IRParser::IRParser(size_t version) : IRParser(version, {}) {} -IRParser::IRParser(size_t version, const std::vector& exts) { - if (version < 10) { - parser = std::make_shared(); - return; - } else { - IE_THROW() << "Unsupported IR version: " << version; - } -} - -CNNNetwork IRParser::parse(const pugi::xml_node& root, const Blob::CPtr& weights) { - return parser->parse(root, weights); -} - -/** - * Hold original blob in order to avoid situations when original blob is allocated on stack - */ -class WeightsHolderBlob : public TBlob { - Blob::CPtr originBlob; - -public: - explicit WeightsHolderBlob(const Blob::CPtr& weights) - : TBlob(weights->getTensorDesc(), weights->cbuffer().as()), - originBlob(weights) {} -}; - -CNNNetwork CNNParser::parse(const pugi::xml_node& root, const Blob::CPtr& weights) { - details::CNNNetReaderImpl reader(std::make_shared()); - ResponseDesc resp; - StatusCode ret = reader.ReadNetwork(root, &resp); - if (ret != OK) - IE_THROW() << resp.msg; - - TBlob::Ptr weightsPtr; - - if (weights != nullptr) { - weightsPtr = TBlob::Ptr(new WeightsHolderBlob(weights)); - } else { - weightsPtr = std::make_shared>(TensorDesc(Precision::U8, {0}, Layout::C)); - weightsPtr->allocate(); - } - ret = reader.SetWeights(weightsPtr, &resp); - if (ret != OK) - IE_THROW() << resp.msg; - return reader.getNetwork(); -} diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_parser.hpp b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_parser.hpp deleted file mode 100644 index da098990766..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_parser.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace InferenceEngine { - -class IParser { -public: - using Ptr = std::shared_ptr; - virtual ~IParser() = default; - virtual CNNNetwork parse(const pugi::xml_node& root, const Blob::CPtr& weights) = 0; -}; - -class IRParser { -public: - explicit IRParser(size_t version); - IRParser(size_t version, const std::vector& exts); - CNNNetwork parse(const pugi::xml_node& root, const Blob::CPtr& weights); - virtual ~IRParser() = default; - -private: - IParser::Ptr parser; -}; - -class CNNParser : public IParser { -public: - CNNParser() = default; - CNNNetwork parse(const pugi::xml_node& root, const Blob::CPtr& weights) override; -}; - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_reader.cpp b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_reader.cpp deleted file mode 100644 index c67dab31885..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_reader.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "ie_ir_itt.hpp" -#include "ie_ir_parser.hpp" -#include "openvino/runtime/common.hpp" - -using namespace InferenceEngine; - -bool IRReader::supportModel(std::istream& model) const { - OV_ITT_SCOPED_TASK(itt::domains::V7Reader, "IRReader::supportModel"); - auto version = details::get_ir_version(model); - return version > 1 && version <= 7; -} - -CNNNetwork IRReader::read(std::istream& model, const std::vector& exts) const { - return read(model, nullptr, exts); -} - -CNNNetwork IRReader::read(std::istream& model, - const Blob::CPtr& weights, - const std::vector& exts) const { - OV_ITT_SCOPED_TASK(itt::domains::V7Reader, "IRReader::read"); - pugi::xml_document xmlDoc; - pugi::xml_parse_result res = xmlDoc.load(model); - if (res.status != pugi::status_ok) { - IE_THROW() << res.description() << " at offset " << res.offset; - } - pugi::xml_node root = xmlDoc.document_element(); - - auto version = details::get_ir_version(root); - IRParser parser(version, exts); - return CNNNetwork(parser.parse(root, weights)); -} - -INFERENCE_PLUGIN_API(void) InferenceEngine::CreateReader(std::shared_ptr& reader) { - reader = std::make_shared(); -} diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_reader.hpp b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_reader.hpp deleted file mode 100644 index 278873a4816..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_ir_reader.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace pugi { -class xml_node; -class xml_document; -} // namespace pugi - -namespace InferenceEngine { - -/** - * @brief This class is the main interface to build and parse a network from a given IR - */ -class IRReader : public IReader { -public: - /** - * @brief Checks that reader supports format of the model - * @param model stream with model - * @return true if format is supported - */ - bool supportModel(std::istream& model) const override; - /** - * @brief Reads the model to CNNNetwork - * @param model stream with model - * @param exts vector with extensions - * - * @return CNNNetwork - */ - CNNNetwork read(std::istream& model, const std::vector& exts) const override; - /** - * @brief Reads the model to CNNNetwork - * @param model stream with model - * @param weights blob with binary data - * @param exts vector with extensions - * - * @return CNNNetwork - */ - CNNNetwork read(std::istream& model, - const Blob::CPtr& weights, - const std::vector& exts) const override; - - std::vector getDataFileExtensions() const override { - return {"bin"}; - } -}; - -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_parsers.cpp b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_parsers.cpp deleted file mode 100644 index 2c1c842219c..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_parsers.cpp +++ /dev/null @@ -1,281 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ie_layer_parsers.h" - -#include -#include -#include -#include - -#include "ie_cnn_net_reader_impl.h" - -namespace InferenceEngine { - -namespace details { - -IE_SUPPRESS_DEPRECATED_START - -CNNLayer::Ptr ActivationLayerCreator::CreateLayer(pugi::xml_node& node, LayerParseParameters& layerParsePrms) { - pugi::xml_node dn = GetChild(node, {"data", "activation_data"}, false); - if (dn.empty()) { - IE_THROW() << "Activation layer has no data node"; - } - - std::string type; - for (auto ait = dn.attributes_begin(); ait != dn.attributes_end(); ++ait) { - pugi::xml_attribute attr = *ait; - if (CaselessEq()("type", attr.name())) { - if (!type.empty()) { - IE_THROW() << "Activation layer has multiple types"; - } - type = attr.value(); - } - } - - static caseless_map> activationCreators = { - {"relu", std::make_shared>("ReLU")}, - {"relu6", std::make_shared>("ReLU6")}, - {"prelu", std::make_shared>("PReLU")}, - {"clamp", std::make_shared>("Clamp")}, - {"elu", std::make_shared>("ELU")}, - {"sigmoid", std::make_shared>("Sigmoid")}, - {"tanh", std::make_shared>("TanH")}, - {"not", std::make_shared>("LogicalNot")}}; - - CNNLayer::Ptr activation; - - auto activationBuilder = activationCreators.find(type); - if (activationBuilder == activationCreators.end()) { - auto activationCreator = std::make_shared>(type); - if (!activationCreator) - IE_THROW() << "Cannot create activation layer with type " << type; - - activation = activationCreator->CreateLayer(node, layerParsePrms); - activation->type = type; - } else { - activation = activationBuilder->second->CreateLayer(node, layerParsePrms); - activation->type = activationBuilder->first; - } - - activation->params.erase("type"); - - return activation; -} - -/***********************************************************************************/ -/******* Tensor Iterator parser **************************************************/ -/***********************************************************************************/ - -using PortInf = std::pair; -using PortSet = std::set; -using PortMap = std::map; - -static PortSet allRequiredInputs(pugi::xml_node& ti) { - PortSet res; // duplicates are possible - - FOREACH_CHILD (p, ti.child("port_map"), "input") { - int internal_layer_id = GetIntAttr(p, "internal_layer_id"); - int internal_port_id = GetIntAttr(p, "internal_port_id"); - res.emplace(internal_layer_id, internal_port_id); - } - FOREACH_CHILD (ec, ti.child("back_edges"), "edge") { - int to_layer_id = GetIntAttr(ec, "to-layer"); - int to_port_id = GetIntAttr(ec, "to-port"); - res.emplace(to_layer_id, to_port_id); - } - return res; -} - -static PortSet allRequiredOutputs(pugi::xml_node& ti) { - PortSet res; // duplicates are possible - - FOREACH_CHILD (p, ti.child("port_map"), "output") { - int internal_layer_id = GetIntAttr(p, "internal_layer_id"); - int internal_port_id = GetIntAttr(p, "internal_port_id"); - res.emplace(internal_layer_id, internal_port_id); - } - FOREACH_CHILD (edge, ti.child("back_edges"), "edge") { - int to_layer_id = GetIntAttr(edge, "from-layer"); - int to_port_id = GetIntAttr(edge, "from-port"); - res.emplace(to_layer_id, to_port_id); - } - return res; -} - -/***********************************************************************************/ -/******* Body Parser Helper ******************************************************/ -/***********************************************************************************/ -using WBlob = TBlob::Ptr; - -class BodyParser { -public: - BodyParser(pugi::xml_node& net_node, size_t ir_version, Precision prec) - : body(net_node), - parser(FormatParser(ir_version)), - default_precision(prec) {} - - void parse(PortSet in_request, PortSet out_request) { - body.append_attribute("precision").set_value(default_precision.name()); - auto net = parser.Parse(body); - - for (const auto& pi : in_request) - inputs[pi] = parser.GetDataBy(pi.first, pi.second); - for (const auto& pi : out_request) - outputs[pi] = parser.GetDataBy(pi.first, pi.second); - - // Mark data as network output. Just for check - for (const auto& kvp : outputs) { - auto& data = kvp.second; - auto layer = getCreatorLayer(data).lock(); - auto& outs = layer->outData; - auto o_idx = std::find(outs.begin(), outs.end(), data) - outs.begin(); - auto sts = net->addOutput(layer->name, o_idx, nullptr); - IE_ASSERT(sts == OK) << "TI body. Cannot add output port for layer " << layer->name << " port index " - << o_idx; - } - - // Verify that all input/output are in use - InputsDataMap in_info_map; - std::map out_info_map; - net->getInputsInfo(in_info_map); - net->getOutputsInfo(out_info_map); - - IE_ASSERT(in_info_map.size() == inputs.size()) << "TI body. There are unlinked inputs"; - for (auto& it : net->allLayers()) { - auto layer = it.second; - if (layer->type == "Input" || !layer->insData.empty()) - continue; - if (!holder) - holder = std::make_shared("const_holder", Precision::UNSPECIFIED); - getInputTo(holder)[it.first] = layer; - } - } - - DataPtr getHolder() { - return holder; - } - - void setWeights(const WBlob& weights) { - parser.SetWeights(weights); - } - - const PortMap& getInsMap() const { - return inputs; - } - const PortMap& getOutsMap() const { - return outputs; - } - -private: - pugi::xml_node& body; - FormatParser parser; - Precision default_precision; - DataPtr holder; - - PortMap inputs; - PortMap outputs; -}; - -CNNLayer::Ptr TILayerCreator::CreateLayer(pugi::xml_node& node, LayerParseParameters& layerParsePrms) { - std::string ti_name = node.attribute("name").as_string(); - - auto body = node.child("body"); - if (body.empty()) - IE_THROW() << "TensorIterator " << ti_name << " has no body"; - - auto all_inputs = allRequiredInputs(node); - auto all_outputs = allRequiredOutputs(node); - - auto parser = std::make_shared(body, layerParsePrms.underIRVersion, layerParsePrms.prms.precision); - parser->parse(all_inputs, all_outputs); - - auto ins = parser->getInsMap(); - auto outs = parser->getOutsMap(); - - // fill in/outputs and map internal port to index - std::map p2i; - std::vector inputs, outputs; - for (const auto& p : all_inputs) { - IE_ASSERT(ins.find(p) != ins.end()); - p2i[p] = static_cast(inputs.size()); - inputs.push_back(ins[p]); - } - for (const auto& p : all_outputs) { - IE_ASSERT(outs.find(p) != outs.end()); - p2i[p] = static_cast(outputs.size()); - outputs.push_back(outs[p]); - } - - // fill map external port to index - std::map e2i; - { - int in_indx = 0; - FOREACH_CHILD (in, node.child("input"), "port") { - int id = GetIntAttr(in, "id"); - e2i[id] = in_indx++; - } - int out_indx = 0; - FOREACH_CHILD (in, node.child("output"), "port") { - int id = GetIntAttr(in, "id"); - e2i[id] = out_indx++; - } - } - - std::vector in_ports_maping, out_ports_maping, back_edges; - - auto parse_rule = [&](pugi::xml_node& pm) { - int external_port_id = GetIntAttr(pm, "external_port_id"); - int internal_layer_id = GetIntAttr(pm, "internal_layer_id"); - int internal_port_id = GetIntAttr(pm, "internal_port_id"); - - int axis = GetIntAttr(pm, "axis", -1); - int stride = GetIntAttr(pm, "stride", 1); - int part_size = GetIntAttr(pm, "part_size", 1); - int start = GetIntAttr(pm, "start", 0); - int end = GetIntAttr(pm, "end", -1); - - TensorIterator::PortMap res; - res.from = e2i[external_port_id]; - res.to = p2i[{internal_layer_id, internal_port_id}]; - res.axis = axis; - res.stride = stride; - res.part_size = part_size; - res.start = start; - res.end = end; - return res; - }; - - FOREACH_CHILD (pm, node.child("port_map"), "input") { in_ports_maping.push_back(parse_rule(pm)); } - FOREACH_CHILD (pm, node.child("port_map"), "output") { out_ports_maping.push_back(parse_rule(pm)); } - - FOREACH_CHILD (ec, node.child("back_edges"), "edge") { - int from_l = GetIntAttr(ec, "from-layer"); - int from_p = GetIntAttr(ec, "from-port"); - int to_l = GetIntAttr(ec, "to-layer"); - int to_p = GetIntAttr(ec, "to-port"); - - back_edges.push_back({p2i[{from_l, from_p}], p2i[{to_l, to_p}], -1, 1, 0, -1, 1}); - } - - // Hold parser as a shared_ptr into callback - // Will be called outside to set weight blobs - // for internal TI body layers - layerParsePrms.internalWeightSet = [=](const WBlob& w) { - parser->setWeights(w); - }; - - auto res = std::make_shared(layerParsePrms.prms); - res->body.inputs = inputs; - if (auto holder = parser->getHolder()) - res->body.inputs.emplace_back(holder); - res->body.outputs = outputs; - res->input_port_map = in_ports_maping; - res->output_port_map = out_ports_maping; - res->back_edges = back_edges; - return res; -} - -} // namespace details -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_parsers.h b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_parsers.h deleted file mode 100644 index fb9a9f2c069..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_parsers.h +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -#include "ie_format_parser.h" -#include "xml_parse_utils.h" - -inline pugi::xml_node GetChild(const pugi::xml_node& node, std::vector tags, bool failIfMissing = true) { - for (auto tag : tags) { - pugi::xml_node dn = node.child(tag.c_str()); - if (!dn.empty()) - return dn; - } - if (failIfMissing) - IE_THROW() << "missing <" << InferenceEngine::details::dumpVec(tags) - << "> Tags at offset :" << node.offset_debug(); - return pugi::xml_node(); -} - -using namespace pugixml::utils; - -namespace InferenceEngine { -namespace details { -template -class LayerCreator : public BaseCreator { -public: - explicit LayerCreator(const std::string& type) : BaseCreator(type) {} - - CNNLayer::Ptr CreateLayer(pugi::xml_node& node, LayerParseParameters& layerParsePrms) override { - auto res = std::make_shared(layerParsePrms.prms); - - if (res->type == "Quantize") - res->type = "FakeQuantize"; - - if (std::is_same::value) { - layerChild[res->name] = {"fc", "fc_data", "data"}; - } else if (std::is_same::value) { - layerChild[res->name] = {"lrn", "norm", "norm_data", "data"}; - } else if (std::is_same::value) { - layerChild[res->name] = {"crop", "crop-data", "data"}; - } else if (std::is_same::value) { - layerChild[res->name] = {"batch_norm", "batch_norm_data", "data"}; - } else if ((std::is_same::value)) { - layerChild[res->name] = {"elementwise", "elementwise_data", "data"}; - } else { - layerChild[res->name] = {"data", tolower(res->type) + "_data", tolower(res->type)}; - } - - pugi::xml_node dn = GetChild(node, layerChild[res->name], false); - - if (!dn.empty()) { - if (dn.child("crop").empty()) { - for (auto ait = dn.attributes_begin(); ait != dn.attributes_end(); ++ait) { - pugi::xml_attribute attr = *ait; - res->params.emplace(attr.name(), attr.value()); - } - } else { - if (std::is_same::value) { - auto crop_res = std::dynamic_pointer_cast(res); - if (!crop_res) { - IE_THROW() << "Crop layer is nullptr"; - } - std::string axisStr, offsetStr, dimStr; - FOREACH_CHILD (_cn, dn, "crop") { - int axis = GetIntAttr(_cn, "axis", 0); - crop_res->axis.push_back(axis); - axisStr += std::to_string(axis) + ","; - int offset = GetIntAttr(_cn, "offset", 0); - crop_res->offset.push_back(offset); - offsetStr += std::to_string(offset) + ","; - } - if (!axisStr.empty() && !offsetStr.empty() && !dimStr.empty()) { - res->params["axis"] = axisStr.substr(0, axisStr.size() - 1); - res->params["offset"] = offsetStr.substr(0, offsetStr.size() - 1); - } - } - } - } - return res; - } - - std::map> layerChild; -}; - -class ActivationLayerCreator : public BaseCreator { -public: - explicit ActivationLayerCreator(const std::string& type) : BaseCreator(type) {} - CNNLayer::Ptr CreateLayer(pugi::xml_node& node, LayerParseParameters& layerParsePrms) override; -}; - -class TILayerCreator : public BaseCreator { -public: - explicit TILayerCreator(const std::string& type) : BaseCreator(type) {} - CNNLayer::Ptr CreateLayer(pugi::xml_node& node, LayerParseParameters& layerParsePrms) override; -}; -} // namespace details -} // namespace InferenceEngine - -/***********************************************************************************/ -/******* End of Layer Parsers ******************************************************/ -/***********************************************************************************/ diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_validators.cpp b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_validators.cpp deleted file mode 100644 index e09e5e32180..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_validators.cpp +++ /dev/null @@ -1,2403 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ie_layer_validators.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "debug.h" -#include "xml_parse_utils.h" - -void InferenceEngine::details::validateLayer(const CNNLayer* layer) { - try { - LayerValidator::Ptr validator = LayerValidators::getInstance()->getValidator(layer->type); - validator->checkParams(layer); - InOutDims shapes; - getInOutShapes(layer, shapes); - validator->checkShapes(layer, shapes.inDims); - } catch (const Exception& ie_e) { - IE_THROW() << "Error of validate layer: " << layer->name << " with type: " << layer->type << ". " - << ie_e.what(); - } -} - -namespace { - -using namespace InferenceEngine; -using namespace details; -using std::map; -using std::string; -using std::vector; - -template -inline bool one_of(T val, P item) { - return val == item; -} -template -inline bool one_of(T val, P item, Args... item_others) { - return val == item || one_of(val, item_others...); -} - -struct WeightableParams { - std::vector _kernel; - size_t _outputs = 0lu; - size_t _groups = 1lu; - bool _isKernelFromInput = false; - - WeightableParams(size_t outputs, bool isKernelFromInput, size_t groups = 0, const std::vector& kernel = {}) - : _kernel(kernel), - _outputs(outputs), - _groups(groups), - _isKernelFromInput(isKernelFromInput) {} -}; - -void checkWeightable(const std::map& blobs, - const vector& inShapes, - WeightableParams params, - const SizeVector& numDims) { - std::vector expected_num_of_shapes = {1, 2, 3}; - bool shape_was_found = false; - for (const auto& i : expected_num_of_shapes) { - if (inShapes.size() == i) { - shape_was_found = true; - break; - } - } - if (!shape_was_found) - IE_THROW() << "Number of inputs (" << inShapes.size() << ") is not equal to expected ones (1)"; - SizeVector firstInputShape = inShapes[0]; - size_t inputSize = firstInputShape.size(); - - bool isOK = false; - for (auto dim : numDims) { - if (inputSize == dim) { - isOK = true; - break; - } - } - if (!isOK) { - IE_THROW() << "Input shape " << details::dumpVec(firstInputShape) - << " has unexpected size, supported sizes: " << details::dumpVec(numDims); - } - - if (firstInputShape.empty()) - IE_THROW() << "Input shape can't be empty"; - - size_t IC, OC; - std::vector kernel; - IC = firstInputShape[1]; - if (params._isKernelFromInput) { - for (size_t i = 1; i <= inputSize - 2; i++) - kernel.push_back(firstInputShape[inputSize - i]); - } else { - for (auto k : params._kernel) { - kernel.push_back(k); - } - } - OC = params._outputs; - - auto it = blobs.find("weights"); - if (it != blobs.end()) { // TODO: return with fixing shape infer tests: IE_THROW() << "Invalid blobs: no weights"; - auto weights = it->second; - if (weights == nullptr || weights->getTensorDesc().getDims().empty()) - IE_THROW() << "Weights can't be empty"; - - auto weightsSize = details::product(weights->getTensorDesc().getDims()); - size_t expectedWeightsSize = OC * IC; - for (auto k : kernel) { - expectedWeightsSize *= k; - } - if (params._groups) - expectedWeightsSize /= params._groups; - if (expectedWeightsSize != weightsSize) { - std::string ker_str; - for (size_t i = 0; i < params._kernel.size(); i++) { - if (!ker_str.empty()) - ker_str += "x"; - ker_str += std::to_string(kernel[i]); - } - IE_THROW() << "New shapes " << details::dumpVec(firstInputShape) << " make Kernels(" << ker_str - << "), Channels(" << IC << "), Output depth(" << OC << "), Groups(" << params._groups - << ") not matching weights size: " << expectedWeightsSize << " vs " << weightsSize; - } - } - - it = blobs.find("biases"); - if (it != blobs.end()) { - auto biases = it->second; - if (biases == nullptr || biases->getTensorDesc().getDims().empty()) - IE_THROW() << "Biases can't be empty"; - auto biasesSize = details::product(biases->getTensorDesc().getDims()); - if (OC != biasesSize) { - IE_THROW() << "Number of outputs (" << OC << ") don't match biases size: " << biasesSize; - } - } -} - -void checkDeformableConv(const DeformableConvolutionLayer* deformableConvLayer, - const std::map& blobs, - const vector& inShapes) { - std::vector krn; - for (size_t i = 0; i < deformableConvLayer->_kernel.size(); i++) - krn.push_back(deformableConvLayer->_kernel[i]); - checkWeightable(blobs, - {inShapes[0]}, - {deformableConvLayer->_out_depth, false, deformableConvLayer->_group, krn}, - {4}); - - SizeVector transInputShape = inShapes[1]; - - if (transInputShape.empty()) - IE_THROW() << "Trans input shape can't be empty"; - size_t TC = transInputShape[1]; - - if (TC != deformableConvLayer->_deformable_group * 2 * krn[0] * krn[1]) - IE_THROW() << "Failed with invalid shapes: trans input channel dimension is invalid. Actual value is: " << TC - << ". Expected value: " << deformableConvLayer->_deformable_group * 2 * krn[0] * krn[1]; -} - -void checkNumOfInput(const std::vector& inShapes, const vector& expected_num_of_shapes) { - bool shape_was_found = false; - for (const auto& i : expected_num_of_shapes) { - if (inShapes.size() == i) { - shape_was_found = true; - break; - } - } - if (!shape_was_found) { - IE_THROW() << "Number of inputs (" << inShapes.size() - << ") is not equal to expected ones: " << expected_num_of_shapes.size(); - } -} - -LayerValidators* LayerValidators::getInstance() { - static LayerValidators instance; - return &instance; -} - -LayerValidator::Ptr LayerValidators::getValidator(const std::string& type) { - if (_validators.find(type) == _validators.end()) { - return std::make_shared(type); - } - return _validators[type]; -} - -GeneralValidator::GeneralValidator(const std::string& _type) : LayerValidator(_type) {} - -void FullyConnectedValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of FullyConnectedLayer class"; - } - unsigned int _out_num = casted->GetParamAsUInt("out-size"); - (void)_out_num; -} - -void FullyConnectedValidator::checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const vector& inShapes) const { - const auto casted = dynamic_cast(layer); - if (!casted) - IE_THROW() << "Layer is not instance of FullyConnected layer class"; - checkWeightable(blobs, inShapes, {casted->_out_num, true, 1}, {2, 4, 5}); -} - -FullyConnectedValidator::FullyConnectedValidator(const std::string& _type) : LayerValidator(_type) {} - -void FullyConnectedValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1, 2, 3}); -} - -void CropValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of CropLayer class"; - } - if (casted->axis.size() != casted->offset.size()) { - IE_THROW() << "Incorrect format of the Crop layer: number of axis doesn't match number of offset - (" - << casted->axis.size() << " vs. " << casted->offset.size() << ")"; - } -} - -CropValidator::CropValidator(const std::string& _type) : LayerValidator(_type) {} - -void CropValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of CropLayer class"; - } - size_t numInputs = inShapes.size(); - checkNumOfInput(inShapes, {1, 2}); - - auto firstShape = inShapes[0]; - size_t shapeSize = firstShape.size(); - for (size_t i = 0; i < casted->axis.size(); i++) { - int axis = casted->axis[i]; - int offset = casted->offset[i]; - if (static_cast(shapeSize) <= axis) - IE_THROW() << "Crop axis(" << casted->axis[i] - << ") should be less the number of dimensions of first input (" << firstShape.size() << ")"; - if (numInputs == 2) { - if (casted->params.find("crop_begin") != casted->params.end()) { - IE_THROW() << "Incorrect format of the Crop layer: `crop_begin` and `crop_end` attributes are " - "valid for single input only"; - } - auto secondShape = inShapes[1]; - if (static_cast(secondShape.size()) <= axis) - IE_THROW() << "Crop axis(" << axis << ") should be less the number of dimensions of second input (" - << secondShape.size() << ")"; - size_t newSize = secondShape[axis]; - if (firstShape[axis] < static_cast(offset + newSize)) { - IE_THROW() << "Incorrect crop data! Offset(" << offset << ") + result size of output(" << newSize - << ") should be less then input size(" << firstShape[axis] << ") for axis(" << axis << ")"; - } - } else if (!casted->dim.empty()) { - int dim = casted->dim[i]; - if (firstShape[axis] < (static_cast(offset) + dim)) { - IE_THROW() << "Incorrect crop data! Offset(" << offset << ") + result size of output(" << dim - << ") should be less then input size(" << firstShape[axis] << ") for axis(" << axis << ")"; - } - } - } -} - -ConvolutionValidator::ConvolutionValidator(const std::string& _type) : LayerValidator(_type) {} - -void ConvolutionValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of ConvolutionLayer class"; - } - casted->GetParamAsUInt("output"); - - vector kernels = casted->GetParamAsUInts("kernel", {}); - if (kernels.empty()) { - // IR_v == 2 - casted->GetParamAsUInt("kernel-x"); - casted->GetParamAsUInt("kernel-y"); - casted->GetParamAsUInt("stride-x", 1u); - casted->GetParamAsUInt("stride-y", 1u); - casted->GetParamAsUInt("pad-x", 0u); - casted->GetParamAsUInt("pad-y", 0u); - casted->GetParamAsUInt("pad-r", casted->_padding[X_AXIS]); - casted->GetParamAsUInt("pad-b", casted->_padding[Y_AXIS]); - casted->GetParamAsUInt("dilation-x", 1u); - casted->GetParamAsUInt("dilation-y", 1u); - } else { - // IR_v > 2 - vector default_0 = vector(casted->_kernel.size(), 0u); - vector default_1 = vector(casted->_kernel.size(), 1u); - casted->GetParamAsUInts("strides", default_1); - casted->GetParamAsUInts("pads_begin", default_0); - casted->GetParamAsUInts("pads_end", default_0); - casted->GetParamAsUInts("dilations", default_1); - } - casted->GetParamAsString("auto_pad", ""); - casted->GetParamAsUInt("group", 1); -} - -void ConvolutionValidator::checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const vector& inShapes) const { - auto convLayer = dynamic_cast(layer); - if (!convLayer) - IE_THROW() << "Layer is not instance of Convolution layer class"; - - std::vector krn; - for (size_t i = 0; i < convLayer->_kernel.size(); i++) - krn.push_back(convLayer->_kernel[i]); - checkWeightable(blobs, inShapes, {convLayer->_out_depth, false, convLayer->_group, krn}, {4, 5}); -} - -void ConvolutionValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1, 2, 3}); -} - -void DeconvolutionValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of ConvolutionLayer class"; - } - casted->GetParamAsUInt("output"); - - vector kernels = casted->GetParamAsUInts("kernel", {}); - if (kernels.empty()) { - // IR_v == 2 - casted->GetParamAsUInt("kernel-x"); - casted->GetParamAsUInt("kernel-y"); - casted->GetParamAsUInt("stride-x", 1u); - casted->GetParamAsUInt("stride-y", 1u); - casted->GetParamAsUInt("pad-x", 0u); - casted->GetParamAsUInt("pad-y", 0u); - casted->GetParamAsUInt("pad-r", casted->_padding[X_AXIS]); - casted->GetParamAsUInt("pad-b", casted->_padding[Y_AXIS]); - casted->GetParamAsUInt("dilation-x", 1u); - casted->GetParamAsUInt("dilation-y", 1u); - } else { - // IR_v > 2 - vector default_0 = vector(casted->_kernel.size(), 0u); - vector default_1 = vector(casted->_kernel.size(), 1u); - casted->GetParamAsUInts("strides", default_1); - casted->GetParamAsUInts("pads_begin", default_0); - casted->GetParamAsUInts("pads_end", default_0); - casted->GetParamAsUInts("dilations", default_1); - } - casted->GetParamAsString("auto_pad", ""); - casted->GetParamAsUInt("group", 1); -} - -DeconvolutionValidator::DeconvolutionValidator(const std::string& _type) : ConvolutionValidator(_type) {} - -void DeconvolutionValidator::checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const vector& inShapes) const { - auto deconv_layer = dynamic_cast(layer); - if (!deconv_layer) - IE_THROW() << "Layer is not instance of Deconvolution layer class"; - - std::vector krn; - for (size_t i = 0; i < deconv_layer->_kernel.size(); i++) - krn.push_back(deconv_layer->_kernel[i]); - checkWeightable(blobs, inShapes, {deconv_layer->_out_depth, false, deconv_layer->_group, krn}, {4, 5}); -} - -void DeconvolutionValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1, 2, 3}); -} - -void DeformableConvolutionValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of DeformableConvolutionLayer class"; - } - casted->GetParamAsUInt("output"); - - vector kernels = casted->GetParamAsUInts("kernel", {}); - // IR_v > 2 - vector default_0 = vector(casted->_kernel.size(), 0u); - vector default_1 = vector(casted->_kernel.size(), 1u); - casted->GetParamAsUInts("strides", default_1); - casted->GetParamAsUInts("pads_begin", default_0); - casted->GetParamAsUInts("pads_end", default_0); - casted->GetParamAsUInts("dilations", default_1); - casted->GetParamAsString("auto_pad", ""); - casted->GetParamAsUInt("group", 1); - casted->GetParamAsUInt("deformable_group", 1); -} - -DeformableConvolutionValidator::DeformableConvolutionValidator(const std::string& _type) - : ConvolutionValidator(_type) {} - -void DeformableConvolutionValidator::checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const vector& inShapes) const { - auto deformable_conv_layer = dynamic_cast(layer); - if (!deformable_conv_layer) - IE_THROW() << "Layer is not instance of DeformableConvolutionLayer class"; - - checkDeformableConv(deformable_conv_layer, blobs, inShapes); -} - -void DeformableConvolutionValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {2, 3, 4}); -} - -PoolingValidator::PoolingValidator(const std::string& _type) : LayerValidator(_type) {} - -void PoolingValidator::checkParams(const CNNLayer* layer) { - // TODO: check that values belong to the scope of the definition according to spec -} - -void PoolingValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1, 2}); -} - -void BatchNormalizationValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of BatchNormalizationLayer class"; - } - float epsilon = casted->GetParamAsFloat("epsilon"); - if (epsilon < 0) { - IE_THROW() << "The value of BatchNormalization layer epsilon parameter is invalid"; - } -} - -BatchNormalizationValidator::BatchNormalizationValidator(const std::string& _type) : LayerValidator(_type) {} - -void BatchNormalizationValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -void PowerValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -PowerValidator::PowerValidator(const std::string& _type) : LayerValidator(_type) {} - -void PowerValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -void PReLUValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -PReLUValidator::PReLUValidator(const std::string& _type) : LayerValidator(_type) {} - -void PReLUValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -void ScaleShiftValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -ScaleShiftValidator::ScaleShiftValidator(const std::string& _type) : LayerValidator(_type) {} - -void ScaleShiftValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -void TileValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of TileLayer class"; - } - int axis = casted->GetParamAsInt("axis", -1); - int tiles = casted->GetParamAsInt("tiles", -1); - if (axis < 0 && tiles < 0) { - IE_THROW() << "The value of Tile layer parameters is invalid"; - } -} - -TileValidator::TileValidator(const std::string& _type) : LayerValidator(_type) {} - -void TileValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -ReshapeValidator::ReshapeValidator(const std::string& _type) : LayerValidator(_type) {} - -void ReshapeValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) - IE_THROW() << "Layer is not instance of ReshapeLayer class"; - size_t num = 0; - for (int dim : casted->shape) { - if (dim < -1) - IE_THROW() << "Invalid value of Reshape mask (dim attribute):" << dim << ". Supported values: 0, -1, >0"; - if (dim == -1) - num++; - } - if (num > 1) - IE_THROW() << "Invalid Reshape mask (dim attribute): at most one dimension can be `-1`"; -} - -void EltwiseValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of EltwiseLayer class"; - } -} - -void EltwiseValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - if (inShapes.empty()) { - IE_THROW() << "Number of inputs (" << inShapes.size() << ") of Eltwise layer is zero"; - } -} - -EltwiseValidator::EltwiseValidator(const std::string& _type) : LayerValidator(_type) {} - -ClampValidator::ClampValidator(const std::string& _type) : LayerValidator(_type) {} - -void ClampValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -void ReLUValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of ReLULayer class"; - } - if (casted->params.count("negative_slope")) { - float negative_slope = casted->GetParamAsFloat("negative_slope"); - (void)negative_slope; - } -} - -ReLUValidator::ReLUValidator(const std::string& _type) : LayerValidator(_type) {} - -void ReLUValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1, 2}); -} - -void MVNValidator::checkParams(const CNNLayer* layer) {} - -MVNValidator::MVNValidator(const std::string& _type) : LayerValidator(_type) {} - -void MVNValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -void GRNValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -GRNValidator::GRNValidator(const std::string& _type) : LayerValidator(_type) {} - -void GRNValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -void SoftMaxValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of SoftMaxLayer class"; - } - int axis = casted->GetParamAsInt("axis", 1); - if (axis < 0) { - IE_THROW() << "The value of SoftMax layer axis parameter is invalid"; - } -} - -SoftMaxValidator::SoftMaxValidator(const std::string& _type) : LayerValidator(_type) {} - -void SoftMaxValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -void NormValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of NormLayer class"; - } - float _alpha = casted->GetParamAsFloat("alpha"); - float _beta = casted->GetParamAsFloat("beta"); - if (_alpha < 0 && _beta < 0) { - IE_THROW() << "The value of Norm layer alpha or beta parameters is invalid"; - } -} - -NormValidator::NormValidator(const std::string& _type) : LayerValidator(_type) {} - -void NormValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -SplitValidator::SplitValidator(const std::string& _type) : LayerValidator(_type) {} - -void SplitValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); - std::vector out_sizes = layer->GetParamAsInts("out_sizes", {}); - if (out_sizes.empty()) { - IE_THROW() << "Value of out_sizes attribute is empty"; - } -} - -void SplitValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of SplitLayer class"; - } - checkNumOfInput(inShapes, {1}); - std::vector out_sizes = layer->GetParamAsInts("out_sizes", {}); - size_t sum(0); - for (const auto& size : out_sizes) - sum += size; - if (inShapes.empty() || inShapes[0].size() <= casted->_axis) - IE_THROW() << "Layer has incorrect input shapes!"; - if (sum != inShapes[0][casted->_axis]) { - IE_THROW() << "The sum of the dimensions on the axis(" << casted->_axis - << ") is not equal out_sizes: " << details::dumpVec(out_sizes); - } -} - -ConcatValidator::ConcatValidator(const std::string& _type) : LayerValidator(_type) {} - -void ConcatValidator::checkParams(const CNNLayer* layer) {} - -void ConcatValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - if (inShapes.empty()) - IE_THROW() << "Inputs are empty"; - - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Invalid Concat layer."; - } - - auto firstShape = inShapes[0]; - size_t firstShapeSize = firstShape.size(); - size_t axis = casted->_axis; - if (axis >= firstShapeSize) - IE_THROW() << "Concat axis(" << axis << ") should be less the number of current input dimensions (" - << firstShapeSize << ")"; - - for (size_t i = 1; i < inShapes.size(); i++) { - auto shape = inShapes[i]; - if (shape.size() != firstShapeSize) - IE_THROW() << "Invalid inputs for Concat layer: number of dimensions must match: " << firstShapeSize - << " vs " << shape.size(); - bool eq_part1 = std::equal(firstShape.begin(), firstShape.begin() + axis, shape.begin()); - bool eq_part2 = std::equal(firstShape.begin() + axis + 1, firstShape.end(), shape.begin() + axis + 1); - if (!(eq_part1 && eq_part2)) - IE_THROW() << "Invalid inputs for Concat layer: dimensions should match in all " - << "positions except axis (" << axis << ") : [" << dumpVec(firstShape) << "] vs [" - << dumpVec(shape) << "]"; - } -} - -GemmValidator::GemmValidator(const std::string& _type) : LayerValidator(_type) {} - -void GemmValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void GemmValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of GemmLayer class"; - } - - checkNumOfInput(inShapes, {2, 3}); - - auto dims0 = inShapes[0]; - auto dims1 = inShapes[1]; - if (dims0.size() < 2 || dims1.size() < 2) { - IE_THROW() << "Gemm input shapes must have at least 2 dimensions"; - } - - unsigned long xAxis0 = static_cast(dims0.size() - 1); - unsigned long yAxis0 = static_cast(dims0.size() - 2); - - if (casted->transpose_a) - std::swap(xAxis0, yAxis0); - - unsigned long xAxis1 = static_cast(dims1.size() - 1); - unsigned long yAxis1 = static_cast(dims1.size() - 2); - - if (casted->transpose_b) - std::swap(xAxis1, yAxis1); - - if (dims0[xAxis0] != dims1[yAxis1]) - IE_THROW() << "Gemm input0 x dimension must be equal to input1 y dimension (" << dims0[xAxis0] << " vs " - << dims1[yAxis1] << ")"; - - if (inShapes.size() == 3) { - auto dims2 = inShapes[2]; - if (dims2.size() < 2) { - IE_THROW() << "Gemm input shapes must have at least 2 dimensions"; - } - - unsigned long xAxis2 = static_cast(dims2.size() - 1); - unsigned long yAxis2 = static_cast(dims2.size() - 2); - - if (dims2[xAxis2] != dims1[xAxis1]) - IE_THROW() << "Gemm input2 x dimension must be equal to input1 x dimension (" << dims2[xAxis2] << " vs " - << dims1[xAxis1] << ")"; - - if (dims2[yAxis2] != dims0[yAxis0]) - IE_THROW() << "Gemm input2 y dimension must be equal to input0 y dimension (" << dims2[yAxis2] << " vs " - << dims0[yAxis0] << ")"; - } -} - -PadValidator::PadValidator(const std::string& _type) : LayerValidator(_type) {} - -void PadValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void PadValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of PadLayer class"; - } - - checkNumOfInput(inShapes, {1}); - - if (inShapes[0].size() != casted->pads_begin.size()) - IE_THROW() << layer->name << " Dimensions count mismatch in layer " << layer->name - << ". Expected: " << casted->pads_begin.size() << " Got: " << inShapes[0].size(); - - if (inShapes[0].size() != casted->pads_end.size()) - IE_THROW() << layer->name << " Dimensions count mismatch in layer " << layer->name - << ". Expected: " << casted->pads_end.size() << " Got: " << inShapes[0].size(); - - if (casted->pad_mode == PadLayer::Symmetric || casted->pad_mode == PadLayer::Reflect) { - for (size_t i = 0; i < inShapes[0].size(); i++) { - if (inShapes[0][i] < casted->pads_begin[i]) { - IE_THROW() << layer->name << " Pad can't be grater than input shape in symmetric and reflect modes." - << " For dimension " << i << " pad_begin=" << casted->pads_begin[i] - << " in_shape=" << inShapes[0][i]; - } - if (inShapes[0][i] < casted->pads_end[i]) { - IE_THROW() << layer->name << " Pad can't be grater than input shape in symmetric and reflect modes." - << " For dimension " << i << " pad_end=" << casted->pads_end[i] - << " in_shape=" << inShapes[0][i]; - } - } - } -} - -GatherValidator::GatherValidator(const std::string& _type) : LayerValidator(_type) {} - -void GatherValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void GatherValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of GatherLayer class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 2) - IE_THROW() << layer->name << " Gather can take only 2 inputs, but actually it has: " << numInputs; - - if (casted->axis > 0 && static_cast(inShapes[0].size()) < (1 + casted->axis)) - IE_THROW() << layer->name << " Incorrect input dictionary dimensions " << inShapes[0].size() - << " and axis number " << casted->axis; - else if (casted->axis < 0 && (static_cast(inShapes[0].size()) + casted->axis) < 0) - IE_THROW() << layer->name << " Incorrect input dictionary dimensions " << inShapes[0].size() - << " and axis number " << casted->axis; -} - -StridedSliceValidator::StridedSliceValidator(const std::string& _type) : LayerValidator(_type) {} - -void StridedSliceValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void StridedSliceValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of StridedSliceLayer class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs > 4) - IE_THROW() << layer->name << " StridedSlice can take up to 4 inputs, but actually it has: " << numInputs; - - size_t ellipsis_mask_counter = 0; - for (size_t i = 0; i < casted->ellipsis_mask.size(); ++i) { - if (casted->ellipsis_mask[i] == '1') - ellipsis_mask_counter++; - } - if (ellipsis_mask_counter > 1) - IE_THROW() << layer->name << " 'Ellipsis_mask' must be a power of two (only one ellipsis)!"; -} - -ShuffleChannelsValidator::ShuffleChannelsValidator(const std::string& _type) : LayerValidator(_type) {} - -void ShuffleChannelsValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void ShuffleChannelsValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of ShuffleChannels class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 1) - IE_THROW() << layer->name << " ShuffleChannels can take only 1 input, but actually it has: " << numInputs; - - if (casted->axis > 0 && static_cast(inShapes[0].size()) < (1 + casted->axis)) - IE_THROW() << layer->name << "I ncorrect input tensor dimensions " << inShapes[0].size() << " and axis number " - << casted->axis; - else if (casted->axis < 0 && (static_cast(inShapes[0].size()) + casted->axis) < 0) - IE_THROW() << layer->name << " Incorrect input dictionary dimensions " << inShapes[0].size() - << " and axis number " << casted->axis; - - int axis = casted->axis; - if (axis < 0) - axis += static_cast(inShapes[0].size()); - - if (inShapes[0][axis] % casted->group) - IE_THROW() << layer->name << " Group parameter must evenly divide the channel dimension!"; - - size_t dataLength = 1; - for (size_t i = axis + 1; i < inShapes[0].size(); i++) - dataLength *= inShapes[0][i]; - - if (dataLength == 0) - IE_THROW() << layer->name << " Incorrect input parameters dimension!"; -} - -DepthToSpaceValidator::DepthToSpaceValidator(const std::string& _type) : LayerValidator(_type) {} - -void DepthToSpaceValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void DepthToSpaceValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of DepthToSpace class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 1) - IE_THROW() << layer->name << " DepthToSpace can take only 1 input, but actually it has: " << numInputs; - - if (inShapes[0].size() < 3) - IE_THROW() << layer->name << " Incorrect number of input dimensions!"; - - if (casted->block_size == 0) - IE_THROW() << layer->name << " Incorrect block_size parameter is zero!"; - - size_t numSpatialDims = inShapes[0].size() - 2; - if (inShapes[0][1] % static_cast(std::pow(casted->block_size, numSpatialDims))) - IE_THROW() << layer->name << " block_size parameter is incompatible with input tensor Color dimension size!"; -} - -SpaceToDepthValidator::SpaceToDepthValidator(const std::string& _type) : LayerValidator(_type) {} - -void SpaceToDepthValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void SpaceToDepthValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of SpaceToDepth class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 1) - IE_THROW() << layer->name << " SpaceToDepth can take only 1 input, but actually it has: " << numInputs; - - if (inShapes[0].size() < 2) - IE_THROW() << layer->name << " Incorrect number of input dimensions!"; - - if (casted->block_size == 0) - IE_THROW() << layer->name << " Incorrect block_size parameter is zero!"; - - if (inShapes[0][inShapes[0].size() - 1] % casted->block_size) - IE_THROW() << layer->name << " block_size parameter is incompatible with input tensor With dimension size!"; - - if (inShapes[0][inShapes[0].size() - 2] % casted->block_size) - IE_THROW() << layer->name << " block_size parameter is incompatible with input tensor Height dimension size!"; -} - -/*--- SpaceToBatchValidator ---*/ -SpaceToBatchValidator::SpaceToBatchValidator(const std::string& _type) : LayerValidator(_type) {} - -void SpaceToBatchValidator::checkParams(const CNNLayer* layer) { - const auto spaceToBatchLayer = dynamic_cast(layer); - if (!spaceToBatchLayer) - IE_THROW() << "'" << layer->name << "' layer is not instance of SpaceToBatchLayer class"; - LayerValidator::checkParams(layer); - - for (auto& bs : spaceToBatchLayer->_block_shape) { - if (bs == 0lu) - IE_THROW() << "'" << layer->name << "' layer has nullable block shape."; - } -} - -void SpaceToBatchValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto spaceToBatchLayer = dynamic_cast(layer); - if (!spaceToBatchLayer) { - IE_THROW() << "'" << layer->name << "' layer is not instance of SpaceToBatchLayer class"; - } - // TODO: finish -} - -/*--- BatchToSpaceValidator ---*/ -BatchToSpaceValidator::BatchToSpaceValidator(const std::string& _type) : LayerValidator(_type) {} - -void BatchToSpaceValidator::checkParams(const CNNLayer* layer) { - auto batchToSpaceLayer = dynamic_cast(layer); - if (!batchToSpaceLayer) { - IE_THROW() << "'" << layer->name << "' layer is not instance of BatchToSpaceLayer class"; - } - LayerValidator::checkParams(layer); -} - -void BatchToSpaceValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto batchToSpaceLayer = dynamic_cast(layer); - if (!batchToSpaceLayer) { - IE_THROW() << "'" << layer->name << "' layer is not instance of BatchToSpaceLayer class"; - } - // TODO: finish -} - -/*--- SparseFillEmptyRowsValidator ---*/ -SparseFillEmptyRowsValidator::SparseFillEmptyRowsValidator(const std::string& _type) : LayerValidator(_type) {} - -void SparseFillEmptyRowsValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void SparseFillEmptyRowsValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of SparseFillEmptyRows class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 4) - IE_THROW() << layer->name << " SparseFillEmptyRows must have 4 inputs, but actually it has: " << numInputs; - - // Check dimensions of a tensor with input indices - if (inShapes[0].size() != 2) - IE_THROW() << layer->name << " Input indices of SparseFillEmptyRows must be 2-D tensor"; - if (inShapes[0][1] != 2) - IE_THROW() << layer->name << " Input indices must be two-dimensional"; - - // Check dimensions of a tensor with input values - if (inShapes[1].size() != 1) - IE_THROW() << layer->name << " Input values of SparseFillEmptyRows must be 1-D tensor"; - if (inShapes[1][0] != inShapes[0][0]) - IE_THROW() << layer->name << " Number of input indices and values must match"; - - // Check dimensions of a tensor with a dense shape - if (inShapes[2].size() != 1) - IE_THROW() << layer->name << " Dense shape of SparseFillEmptyRows must be 1-D tensor"; - // TODO: check that dense shape value is set - - // Check dimensions of a tensor with default value - if (inShapes[3].size() != 1) - IE_THROW() << layer->name << " Default value of SparseFillEmptyRows must be 1-D tensor"; -} - -SparseSegmentReduceValidator::SparseSegmentReduceValidator(const std::string& _type) : LayerValidator(_type) {} - -void SparseSegmentReduceValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void SparseSegmentReduceValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of SparseSegmentReduce class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 3) - IE_THROW() << layer->name << " SparseSegmentReduce must take three inputs, but actually it has: " << numInputs; - - // check that the second and the third inputs are one-dimensional - if (inShapes[1].size() != 1) { - IE_THROW() << layer->name << " The second input of SparseSegmentReduce must be one-dimensional"; - } - if (inShapes[2].size() != 1) { - IE_THROW() << layer->name << " The third input of SparseSegmentReduce must be one-dimensional"; - } -} - -ExperimentalSparseWeightedReduceValidator::ExperimentalSparseWeightedReduceValidator(const std::string& _type) - : LayerValidator(_type) {} - -void ExperimentalSparseWeightedReduceValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void ExperimentalSparseWeightedReduceValidator::checkShapes(const CNNLayer* layer, - const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of ExperimentalSparseWeightedReduce class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 5 && numInputs != 6) - IE_THROW() << layer->name - << " ExperimentalSparseWeightedReduce must take five or six inputs, but actually it has: " - << numInputs; - - // check shapes of inputs - if (inShapes[0].size() != 2 || inShapes[0][1] != 2) { - IE_THROW() << layer->name - << " The first input with indices of ExperimentalSparseSegmentReduce must be two-dimensional"; - } - if (inShapes[1].size() != 1) { - IE_THROW() << layer->name - << " The second input with values of ExperimentalSparseSegmentReduce must be one-dimensional"; - } - if (inShapes[1][0] != inShapes[0][0]) { - IE_THROW() << layer->name - << " The first dimension value of the first and second inputs of ExperimentalSparseSegmentReduce " - "must be the same"; - } - if (inShapes[2].size() != 1 || inShapes[2][0] != 2) { - IE_THROW() << layer->name - << " The third input with a dense shape of ExperimentalSparseSegmentReduce must be one-dimensional"; - } - if (inShapes[3].size() < 2) { - IE_THROW() << layer->name - << " The fourth input with parameters table of ExperimentalSparseSegmentReduce must have two " - "dimensions at least"; - } - if (inShapes[4].size() != 0) { - IE_THROW() << layer->name - << " The fifth input with a default value of ExperimentalSparseSegmentReduce must be a scalar"; - } - if (numInputs == 6 && (inShapes[5].size() != 1 || inShapes[5][0] != inShapes[1][0])) { - IE_THROW() << layer->name - << " The second and sixth inputs of ExperimentalSparseSegmentReduce must have the same shapes"; - } - - // check precisions of inputs - const size_t INPUT_INDICES_PORT = 0; - const size_t INPUT_VALUES_PORT = 1; - const size_t INPUT_DENSE_SHAPE = 2; - const size_t INPUT_PARAMS_TABLE = 3; - const size_t INPUT_DEFAULT_VALUE = 4; - const size_t INPUT_WEIGHTS = 5; - - Precision input_indices_precision = layer->insData[INPUT_INDICES_PORT].lock()->getTensorDesc().getPrecision(); - if (input_indices_precision != Precision::I32) - IE_THROW() << layer->name << " Incorrect input indices precision. Only I32 are supported!"; - Precision input_values_precision = layer->insData[INPUT_VALUES_PORT].lock()->getTensorDesc().getPrecision(); - if (input_values_precision != Precision::I32) - IE_THROW() << layer->name << " Incorrect input values precision. Only I32 are supported!"; - Precision input_dense_shape_precision = layer->insData[INPUT_DENSE_SHAPE].lock()->getTensorDesc().getPrecision(); - if (input_dense_shape_precision != Precision::I32) - IE_THROW() << layer->name << " Incorrect input dense shape precision. Only I32 are supported!"; - Precision input_params_table_precision = layer->insData[INPUT_PARAMS_TABLE].lock()->getTensorDesc().getPrecision(); - if (input_params_table_precision != Precision::FP32) - IE_THROW() << layer->name << " Incorrect input parameters table precision. Only FP32 are supported!"; - Precision input_default_value_precision = - layer->insData[INPUT_DEFAULT_VALUE].lock()->getTensorDesc().getPrecision(); - if (input_default_value_precision != Precision::I32) - IE_THROW() << layer->name << " Incorrect input default value precision. Only I32 are supported!"; - if (numInputs == 6) { - Precision input_weights_precision = layer->insData[INPUT_WEIGHTS].lock()->getTensorDesc().getPrecision(); - if (input_weights_precision != Precision::FP32) - IE_THROW() << layer->name << " Incorrect input weights precision. Only FP32 are supported!"; - } -} - -SparseToDenseValidator::SparseToDenseValidator(const std::string& _type) : LayerValidator(_type) {} - -void SparseToDenseValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void SparseToDenseValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of SparseToDense class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 3 && numInputs != 4) - IE_THROW() << layer->name - << " SparseToDense must take three or four inputs, but actually it has: " << numInputs; - - // check shapes of inputs - if (inShapes[0].size() != 2) { - IE_THROW() << layer->name << " The first input with indices of SparseToDense must be two-dimensional"; - } - if (inShapes[1].size() != 1 || inShapes[1][0] != inShapes[0][1]) { - IE_THROW() << layer->name << " The second input with a dense shape of SparseToDense must be one-dimensional"; - } - if (inShapes[2].size() != 1 || inShapes[2][0] != inShapes[0][0]) { - IE_THROW() << layer->name << " The third input with values of SparseToDense must be one-dimensional"; - } - if (numInputs == 4 && inShapes[3].size() != 0) { - IE_THROW() << layer->name << " The fourth input with default value of SparseToDense must be a scalar"; - } - - // check precisions of inputs - const size_t INPUT_INDICES_PORT = 0; - const size_t INPUT_DENSE_SHAPE = 1; - const size_t INPUT_VALUES_PORT = 2; - const size_t INPUT_DEFAULT_VALUE = 3; - - Precision input_indices_precision = layer->insData[INPUT_INDICES_PORT].lock()->getTensorDesc().getPrecision(); - if (input_indices_precision != Precision::I32) - IE_THROW() << layer->name << " Incorrect input indices precision. Only I32 are supported!"; - Precision input_dense_shape_precision = layer->insData[INPUT_DENSE_SHAPE].lock()->getTensorDesc().getPrecision(); - if (input_dense_shape_precision != Precision::I32) - IE_THROW() << layer->name << " Incorrect input dense shape precision. Only I32 are supported!"; - Precision input_values_precision = layer->insData[INPUT_VALUES_PORT].lock()->getTensorDesc().getPrecision(); - if (input_values_precision != Precision::I32) - IE_THROW() << layer->name << " Incorrect input values precision. Only I32 are supported!"; - if (numInputs == 4) { - Precision input_default_value_precision = - layer->insData[INPUT_DEFAULT_VALUE].lock()->getTensorDesc().getPrecision(); - if (input_default_value_precision != Precision::I32) - IE_THROW() << layer->name << " Incorrect input default value precision. Only I32 are supported!"; - } -} - -BucketizeValidator::BucketizeValidator(const std::string& _type) : LayerValidator(_type) {} - -void BucketizeValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void BucketizeValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of Bucketize class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 2) - IE_THROW() << layer->name << " Bucketize must take two inputs, but actually it has: " << numInputs; - - // check shapes of inputs - if (inShapes[1].size() != 1) { - IE_THROW() << layer->name << " The second input of Bucketize must be one-dimensional"; - } - - // check precisions of inputs - const size_t INPUT_TENSOR_PORT = 0; - const size_t INPUT_BOUNDARIES_PORT = 1; - - Precision input_tensor_precision = layer->insData[INPUT_TENSOR_PORT].lock()->getTensorDesc().getPrecision(); - if (input_tensor_precision != Precision::I32 && input_tensor_precision != Precision::FP32) - IE_THROW() << layer->name << " Incorrect input tensor precision. Only I32 and FP32 are supported!"; - Precision input_boundaries_precision = layer->insData[INPUT_BOUNDARIES_PORT].lock()->getTensorDesc().getPrecision(); - if (input_boundaries_precision != Precision::FP32) - IE_THROW() << layer->name << " Incorrect input boundaries precision. Only FP32 are supported!"; -} - -ReverseSequenceValidator::ReverseSequenceValidator(const std::string& _type) : LayerValidator(_type) {} - -void ReverseSequenceValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void ReverseSequenceValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of ReverseSequence class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 2) - IE_THROW() << layer->name << " ReverseSequence can take 2 inputs, but actually it has: " << numInputs; - - if (inShapes[1].size() != 1) - IE_THROW() << layer->name << " Incorrect number of 'seq_lengths' input dimensions!"; - - if (casted->seq_axis > 0 && static_cast(inShapes[0].size()) < (1 + casted->seq_axis)) - IE_THROW() << layer->name << "Incorrect input tensor dimensions " << inShapes[0].size() - << " and seq_axis number " << casted->seq_axis; - else if (casted->seq_axis < 0 && (static_cast(inShapes[0].size()) + casted->seq_axis) < 0) - IE_THROW() << layer->name << " Incorrect input dictionary dimensions " << inShapes[0].size() - << " and seq_axis number " << casted->seq_axis; - - if (casted->batch_axis > 0 && static_cast(inShapes[0].size()) < (1 + casted->batch_axis)) - IE_THROW() << layer->name << "Incorrect input tensor dimensions " << inShapes[0].size() - << " and batch_axis number " << casted->batch_axis; - else if (casted->batch_axis < 0 && (static_cast(inShapes[0].size()) + casted->batch_axis) < 0) - IE_THROW() << layer->name << " Incorrect input dictionary dimensions " << inShapes[0].size() - << " and batch_axis number " << casted->batch_axis; - - int batch_axis = casted->batch_axis; - if (batch_axis < 0) - batch_axis += static_cast(inShapes[0].size()); - if (inShapes[1][0] != inShapes[0][batch_axis]) - IE_THROW() << layer->name << " Incorrect 'seq_lengths_dims' parameter dimensions!"; -} - -SqueezeValidator::SqueezeValidator(const std::string& _type) : LayerValidator(_type) {} - -void SqueezeValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void SqueezeValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of Squeeze class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 2) - IE_THROW() << layer->name << " Squeeze can take 2 inputs, but actually it has: " << numInputs; - - if (inShapes[1].size() != 1) - IE_THROW() << layer->name << " Incorrect number of 'indices_to_squeeze' input dimensions!"; -} - -UnsqueezeValidator::UnsqueezeValidator(const std::string& _type) : LayerValidator(_type) {} - -void UnsqueezeValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void UnsqueezeValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of Unsqueeze class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 2) - IE_THROW() << layer->name << " Unsqueeze can take 2 inputs, but actually it has: " << numInputs; - - if (inShapes[1].size() != 1) - IE_THROW() << layer->name << " Incorrect number of 'indices_to_set' input dimensions!"; -} - -RangeValidator::RangeValidator(const std::string& _type) : LayerValidator(_type) {} - -void RangeValidator::checkParams(const CNNLayer* layer) {} - -void RangeValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of Range class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 3) - IE_THROW() << layer->name << " Range can take 3 inputs, but actually it has: " << numInputs; - - if (inShapes[0].size() != 1) - IE_THROW() << layer->name << " Incorrect number of 'start' input dimensions!"; - - if (inShapes[1].size() != 1) - IE_THROW() << layer->name << " Incorrect number of 'limit' input dimensions!"; - - if (inShapes[2].size() != 1) - IE_THROW() << layer->name << " Incorrect number of 'delta' input dimensions!"; -} - -FillValidator::FillValidator(const std::string& _type) : LayerValidator(_type) {} - -void FillValidator::checkParams(const CNNLayer* layer) {} - -void FillValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - size_t numInputs = inShapes.size(); - if (numInputs != 2) - IE_THROW() << layer->name << " Fill can take 2 inputs, but actually it has: " << numInputs; - - if (inShapes[0].size() != 1) - IE_THROW() << layer->name << " Incorrect number of 'fill_dims' input dimensions!"; - - if (inShapes[1].size() != 1) - IE_THROW() << layer->name << " Incorrect number of 'fill_value' input dimensions!"; -} - -BroadcastValidator::BroadcastValidator(const std::string& _type) : LayerValidator(_type) {} - -void BroadcastValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void BroadcastValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of Broadcast class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 2) - IE_THROW() << layer->name << " Broadcast can take 2 inputs, but actually it has: " << numInputs; - - if (inShapes[1].size() != 1) - IE_THROW() << layer->name << " Incorrect number of 'shape' input dimensions!"; -} - -/****************************************/ -/*** RNN specific validators ************/ -/****************************************/ - -RNNBaseValidator::RNNBaseValidator(const std::string& _type, RNNSequenceLayer::CellType CELL) : LayerValidator(_type) { - if (RNNSequenceLayer::LSTM == CELL) { - def_acts = {"sigmoid", "tanh", "tanh"}; - def_alpha = {0, 0, 0}; - def_beta = {0, 0, 0}; - G = 4; - NS = 2; - } else if (RNNSequenceLayer::GRU == CELL) { - def_acts = {"sigmoid", "tanh"}; - def_alpha = {0, 0}; - def_beta = {0, 0}; - G = 3; - NS = 1; - } else if (RNNSequenceLayer::RNN == CELL) { - def_acts = {"tanh"}; - def_alpha = {0}; - def_beta = {0}; - G = 1; - NS = 1; - } else { - IE_ASSERT(false); - } -} - -void RNNBaseValidator::checkParams(const InferenceEngine::CNNLayer* layer) { - auto rnn = dynamic_cast(layer); - if (!rnn) - IE_THROW() << "Layer is not instance of RNNLayer class"; - - if (rnn->clip < 0.0f) - IE_THROW() << "Clip parameter should be positive"; - - for (auto& act : rnn->activations) - if (!one_of(act, "sigmoid", "tanh", "relu")) - IE_THROW() << "Unsupported activation function (" << act << ") for RNN layer."; - - size_t act_num_required = def_acts.size(); - if (rnn->activations.size() != act_num_required) - IE_THROW() << "Expected " << act_num_required << " activations, but provided " << rnn->activations.size(); - - if (rnn->activation_alpha.size() != act_num_required) - IE_THROW() << "Expected " << act_num_required << " activation alpha parameters, " - << "but provided " << rnn->activation_alpha.size(); - if (rnn->activation_beta.size() != act_num_required) - IE_THROW() << "Expected " << act_num_required << " activation beta parameters, " - << "but provided " << rnn->activation_beta.size(); -} - -void RNNBaseValidator::checkCorrespondence(const CNNLayer* layer, - const map& blobs, - const vector& inShapes) const { - auto rnn = dynamic_cast(layer); - if (!rnn) - IE_THROW() << "Layer is not instance of RNNLayer class"; - - if (blobs.size() != 2) - IE_THROW() << "Expected only 2 blobs with trained parameters (weights and biases), " - << "but provided only " << blobs.size(); - if (inShapes.empty()) - IE_THROW() << "No input tensors."; - - size_t D = inShapes[0].back(); - size_t S = rnn->hidden_size; - size_t expectetd_w_size = G * S * (D + S); - size_t expectetd_b_size = G * S; - - if (rnn->cellType == RNNCellBase::GRU_LBR) - expectetd_b_size = (G + 1) * S; - - auto w = blobs.find("weights"); - if (w == blobs.end()) - IE_THROW() << "Weights blob is not provided"; - - if (w->second->size() != expectetd_w_size) - IE_THROW() << "Weights blob has wrang size. Expected " << expectetd_w_size; - - auto b = blobs.find("biases"); - if (b == blobs.end()) - IE_THROW() << "Biases blob is not provided"; - - if (b->second->size() != expectetd_b_size) - IE_THROW() << "Biases blob has wrang size. Expected " << expectetd_b_size; -} - -template -RNNSequenceValidator::RNNSequenceValidator(const std::string& _type) : RNNBaseValidator(_type, CELL) {} - -template -void RNNSequenceValidator::checkParams(const InferenceEngine::CNNLayer* layer) { - RNNBaseValidator::checkParams(layer); - - auto casted = dynamic_cast(layer); - if (!casted) - IE_THROW() << "Layer is not instance of RNNLayer class"; - - if (!one_of(casted->axis, 1u, 0u)) - IE_THROW() << "Unsupported iteration axis for RNNSequense layer. Only 0 or 1 axis are supported."; -} - -template -void RNNSequenceValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto rnn = dynamic_cast(layer); - if (!rnn) - IE_THROW() << "Layer is not instance of RNNSequenceLayer class"; - - if (inShapes.empty()) - IE_THROW() << "No input tensors."; - - if (inShapes[0].size() != 3) - IE_THROW() << "First input data tensor should be 3D"; - - size_t T_axis = rnn->axis; - size_t N_axis = (T_axis + 1) % 2; - size_t N = inShapes[0][N_axis]; - size_t S = rnn->hidden_size; - size_t NS = RNNSequenceValidator::NS; - - SizeVector expected_state_shape{N, S}; - SizeVector expected_seq_l_shape{N}; - - if (inShapes.size() > 1) { // has an initial state blobs - if (inShapes.size() != 1 + NS && inShapes.size() != 2 + NS) - IE_THROW() << "Wrong number of input tensors. Expected 1 (data) or " << 1 + NS << " (data and states) or " - << 2 + NS << " (data, states and seq_length)."; - if (inShapes[1] != expected_state_shape) - IE_THROW() << "Wrong shape of first initial state tensors."; - // << " Expected " << expected_state_shape << " but provided " << inShapes[1]; - - if (NS == 2 && inShapes[2] != expected_state_shape) - IE_THROW() << "Wrong shape of second initial state tensors."; - // << " Expected " << expected_state_shape << " but provided " << inShapes[2]; - if (inShapes.size() == 2 + NS && inShapes[NS + 1] != expected_seq_l_shape) - IE_THROW() << "Wrong shape of last input tensor with sequance length data."; - // << " Expected " << expected_seq_l_shape << " but provided " << inShapes[NS + 1]; - } -} - -template class RNNSequenceValidator; -template class RNNSequenceValidator; -template class RNNSequenceValidator; - -template -RNNCellValidator::RNNCellValidator(const std::string& _type) : RNNBaseValidator(_type, CELL) {} - -template -void RNNCellValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto rnn = dynamic_cast(layer); - if (!rnn) - IE_THROW() << "Layer is not instance of RNNSequenceLayer class"; - - const size_t& NS = RNNCellValidator::NS; - - if (inShapes.size() != NS + 1) - IE_THROW() << "Wrong number of input tensors. Expected " << NS + 1; - - if (inShapes[0].size() != 2) - IE_THROW() << "First input data tensor should be 2D"; - - size_t N = inShapes[0][0]; - size_t S = rnn->hidden_size; - - SizeVector expected_state_shape{N, S}; - - if (inShapes[1] != expected_state_shape) - IE_THROW() << "Wrong shape of first initial state tensors."; - // << " Expected " << expected_state_shape << " but provided " << inShapes[1]; - - if (NS == 2 && inShapes[2] != expected_state_shape) - IE_THROW() << "Wrong shape of second initial state tensors."; - // << " Expected " << expected_state_shape << " but provided " << inShapes[2]; -} - -template class RNNCellValidator; -template class RNNCellValidator; -template class RNNCellValidator; - -void ArgMaxValidator::checkParams(const CNNLayer* layer) { - unsigned int top_k_ = layer->GetParamAsUInt("top_k"); - (void)top_k_; -} - -void ArgMaxValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -ArgMaxValidator::ArgMaxValidator(const std::string& _type) : LayerValidator(_type) {} - -void CTCGreedyDecoderValidator::checkParams(const CNNLayer* layer) { - int flag = layer->GetParamAsInt("ctc_merge_repeated", 0); - if (flag != 0 && flag != 1) { - IE_THROW() << "CTCGreedyDecoder layer parameter ctc_merge_repeated is invalid"; - } -} - -void CTCGreedyDecoderValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1, 2}); -} - -CTCGreedyDecoderValidator::CTCGreedyDecoderValidator(const std::string& _type) : LayerValidator(_type) {} - -void DetectionOutputValidator::checkParams(const CNNLayer* layer) { - unsigned int num_classes = layer->GetParamAsUInt("num_classes"); - if (num_classes == 0) { - IE_THROW() << "num_classes parameter of DetectionOutput layer can't be equal to zero"; - } - float _nms_threshold = layer->GetParamAsFloat("nms_threshold"); - if (_nms_threshold < 0) { - IE_THROW() << "nms_threshold parameter of DetectionOutput layer can't be less then zero"; - } - int _keep_top_k = layer->GetParamAsUInt("keep_top_k", -1); - (void)_keep_top_k; - - if (layer->CheckParamPresence("background_label_id")) { - int _background_label_id = layer->GetParamAsUInt("background_label_id", -1); - (void)_background_label_id; - } - if (layer->CheckParamPresence("top_k")) { - int _top_k = layer->GetParamAsUInt("top_k", -1); - (void)_top_k; - } - if (layer->CheckParamPresence("variance_encoded_in_target")) { - bool _variance_encoded_in_target = static_cast(layer->GetParamAsUInt("variance_encoded_in_target")); - (void)_variance_encoded_in_target; - } - if (layer->CheckParamPresence("num_orient_classes")) { - int _num_orient_classes = layer->GetParamAsUInt("num_orient_classes"); - (void)_num_orient_classes; - } - if (layer->CheckParamPresence("share_location")) { - bool _share_location = static_cast(layer->GetParamAsUInt("share_location")); - (void)_share_location; - } - if (layer->CheckParamPresence("interpolate_orientation")) { - int _interpolate_orientation = layer->GetParamAsInt("interpolate_orientation"); - (void)_interpolate_orientation; - } - if (layer->CheckParamPresence("confidence_threshold")) { - float _confidence_threshold = layer->GetParamAsFloat("confidence_threshold"); - if (_confidence_threshold < 0) { - IE_THROW() << "_nms_threshold parameter of DetectionOutput layer can't be less then zero"; - } - } - if (layer->CheckParamPresence("code_type")) { - std::string _code_type = layer->GetParamAsString("code_type"); - std::vector code_types = {"caffe.PriorBoxParameter.CENTER_SIZE", "caffe.PriorBoxParameter.CORNER"}; - auto it = std::find(code_types.begin(), code_types.end(), _code_type); - if (it == code_types.end()) { - IE_THROW() << "Parameter code_type of DetectionOutput layer "; - } - } -} - -void DetectionOutputValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {3, 5}); -} - -DetectionOutputValidator::DetectionOutputValidator(const std::string& _type) : LayerValidator(_type) {} - -void InterpValidator::checkParams(const CNNLayer* layer) {} - -void InterpValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1, 2}); - auto IS_ZERO = [](float value) { - return std::fabs(value) < std::numeric_limits::epsilon(); - }; - if (inShapes.size() != 2) { - float factor = layer->GetParamAsFloat("factor", 0); - if (factor < 0) - IE_THROW() << "factor parameter of Interp layer can't be less then zero"; - float shrink_factor = layer->GetParamAsFloat("shrink_factor", 0); - if (shrink_factor < 0) - IE_THROW() << "shrink_factor parameter of Interp layer can't be less then zero"; - float zoom_factor = (layer->GetParamAsFloat("zoom_factor", 0)); - if (zoom_factor < 0) - IE_THROW() << "zoom_factor parameter of Interp layer can't be less then zero"; - bool noFactor = IS_ZERO(factor) && IS_ZERO(shrink_factor) && IS_ZERO(zoom_factor); - - auto height = layer->GetParamAsUInt("height", 0); - auto width = layer->GetParamAsUInt("width", 0); - - if (noFactor && (height == 0 || width == 0)) { - IE_THROW() << "Can't reshape without factor, or target resolution. " - << "Supported attributes: factor, shrink_factor, zoom_factor, height, width"; - } - } -} - -InterpValidator::InterpValidator(const std::string& _type) : LayerValidator(_type) {} - -void PermuteValidator::checkParams(const CNNLayer* layer) { - std::vector layerOrder = layer->GetParamAsUInts("order"); -} - -void PermuteValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -PermuteValidator::PermuteValidator(const std::string& _type) : LayerValidator(_type) {} - -void PriorBoxValidator::checkParams(const CNNLayer* layer) { - std::vector min_sizes = layer->GetParamAsUInts("min_size", {}); - std::vector max_sizes = layer->GetParamAsUInts("max_size", {}); - bool flip = static_cast(layer->GetParamAsInt("flip")); - (void)flip; - if (layer->CheckParamPresence("aspect_ratio")) - const std::vector aspect_ratios = layer->GetParamAsUInts("aspect_ratio", {}); - bool clip_ = static_cast(layer->GetParamAsInt("clip")); - (void)clip_; - std::vector variance_ = layer->GetParamAsFloats("variance", {}); - for (float i : variance_) { - if (i < 0) { - IE_THROW() << "The value of PriorBox layer variance parameter is invalid. " - "Positive value is expected"; - } - } - float step_ = layer->GetParamAsFloat("step", 0); - if (step_ < 0) { - IE_THROW() << "The value of PriorBox layer step_ parameter is invalid"; - } - float offset_ = layer->GetParamAsFloat("offset"); - if (offset_ < 0) { - IE_THROW() << "The value of PriorBox layer offset_ parameter is invalid"; - } -} - -void PriorBoxValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {2}); -} - -PriorBoxValidator::PriorBoxValidator(const std::string& _type) : LayerValidator(_type) {} - -void PriorBoxClusteredValidator::checkParams(const CNNLayer* layer) { - std::vector widths = layer->GetParamAsFloats("width", {}); - for (auto i : widths) { - if (i < 0) { - IE_THROW() << "The value of PriorBoxClustered layer width parameter is invalid"; - } - } - std::vector heights = layer->GetParamAsFloats("height", {}); - for (auto i : heights) { - if (i < 0) { - IE_THROW() << "The value of PriorBoxClustered layer heights parameter is invalid"; - } - } - bool flip = static_cast(layer->GetParamAsInt("flip")); - (void)flip; - bool clip_ = static_cast(layer->GetParamAsInt("clip")); - (void)clip_; - float offset_ = layer->GetParamAsFloat("offset"); - if (offset_ < 0) { - IE_THROW() << "The value of PriorBox layer offset_ parameter is invalid"; - } - - std::vector variance_ = layer->GetParamAsFloats("variance", {}); - for (float i : variance_) { - if (i < 0) { - IE_THROW() << "The value of PriorBox layer variance parameter is invalid. " - "Positive value is expected"; - } - } - float step_h_ = layer->GetParamAsFloat("step_h", 0); - if (step_h_ < 0) { - IE_THROW() << "The value of PriorBox layer step_h_ parameter is invalid"; - } - float step_w_ = layer->GetParamAsFloat("step_w", 0); - if (step_w_ < 0) { - IE_THROW() << "The value of PriorBox layer step_w_ parameter is invalid"; - } - float img_h_ = layer->GetParamAsFloat("img_h", 0); - if (img_h_ < 0) { - IE_THROW() << "The value of PriorBox layer img_h_ parameter is invalid"; - } - float img_w_ = layer->GetParamAsFloat("img_w", 0); - if (img_w_ < 0) { - IE_THROW() << "The value of PriorBox layer img_w_ parameter is invalid"; - } -} - -void PriorBoxClusteredValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {2}); -} - -PriorBoxClusteredValidator::PriorBoxClusteredValidator(const std::string& _type) : LayerValidator(_type) {} - -void ProposalValidator::checkParams(const CNNLayer* layer) { - unsigned int post_nms_topn_ = layer->GetParamAsUInt("post_nms_topn"); - (void)post_nms_topn_; - - if (layer->CheckParamPresence("feat_stride")) { - unsigned int feat_stride_ = layer->GetParamAsUInt("feat_stride"); - (void)feat_stride_; - } - if (layer->CheckParamPresence("base_size")) { - unsigned int base_size_ = layer->GetParamAsUInt("base_size"); - (void)base_size_; - } - if (layer->CheckParamPresence("min_size")) { - unsigned int min_size_ = layer->GetParamAsUInt("min_size"); - (void)min_size_; - } - if (layer->CheckParamPresence("pre_nms_topn")) { - unsigned int pre_nms_topn_ = layer->GetParamAsUInt("pre_nms_topn"); - (void)pre_nms_topn_; - } - if (layer->CheckParamPresence("nms_thresh")) { - float nms_thresh_ = layer->GetParamAsFloat("nms_thresh"); - if (nms_thresh_ < 0) { - IE_THROW() << "The value of Proposal layer nms_thresh_ parameter is invalid"; - } - } -} - -void ProposalValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {3}); -} - -ProposalValidator::ProposalValidator(const std::string& _type) : LayerValidator(_type) {} - -void PSROIPoolingValidator::checkParams(const CNNLayer* layer) { - unsigned int output_dim = layer->GetParamAsUInt("output_dim"); - (void)output_dim; - unsigned int group_size = layer->GetParamAsUInt("group_size"); - (void)group_size; - if (layer->CheckParamPresence("spatial_scale")) { - float spatial_scale_ = layer->GetParamAsFloat("spatial_scale"); - if (spatial_scale_ < 0) { - IE_THROW() << "The value of PSROIPooling layer spatial_scale_ parameter is invalid"; - } - } -} - -void PSROIPoolingValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1, 2, 3}); -} - -PSROIPoolingValidator::PSROIPoolingValidator(const std::string& _type) : LayerValidator(_type) {} - -void RegionYoloValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void RegionYoloValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -RegionYoloValidator::RegionYoloValidator(const std::string& _type) : LayerValidator(_type) {} - -void ReorgYoloValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void ReorgYoloValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -ReorgYoloValidator::ReorgYoloValidator(const std::string& _type) : LayerValidator(_type) {} - -void ResampleValidator::checkParams(const CNNLayer* layer) { - if (layer->CheckParamPresence("antialias")) { - auto antialias = static_cast(layer->GetParamAsInt("antialias")); - - if (antialias != 0 && antialias != 1) { - IE_THROW() << "The value of resample layer antialias parameter is invalid"; - } - } - if (layer->CheckParamPresence("type")) { - std::string type = layer->GetParamAsString("type"); - if (type != "caffe.ResampleParameter.NEAREST" && type != "caffe.ResampleParameter.CUBIC" && - type != "caffe.ResampleParameter.LINEAR") { - IE_THROW() << "The value of resample layer type parameter is invalid"; - } - } -} - -void ResampleValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1, 2}); -} - -ResampleValidator::ResampleValidator(const std::string& _type) : LayerValidator(_type) {} - -void ROIPoolingValidator::checkParams(const CNNLayer* layer) { - unsigned int pooled_h = layer->GetParamAsUInt("pooled_h"); - (void)pooled_h; - unsigned int pooled_w = layer->GetParamAsUInt("pooled_w"); - (void)pooled_w; - float spatial_scale = layer->GetParamAsFloat("spatial_scale"); - if (spatial_scale < 0) { - IE_THROW() << "The value of ROIPooling layer spatial_scale parameter is invalid"; - } -} - -void ROIPoolingValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1, 2}); -} - -ROIPoolingValidator::ROIPoolingValidator(const std::string& _type) : LayerValidator(_type) {} - -void SimplerNMSValidator::checkParams(const CNNLayer* layer) { - unsigned int post_nms_topn_ = layer->GetParamAsUInt("post_nms_topn"); - (void)post_nms_topn_; - - if (layer->CheckParamPresence("min_bbox_size")) { - unsigned int min_box_size_ = layer->GetParamAsUInt("min_bbox_size"); - (void)min_box_size_; - } - if (layer->CheckParamPresence("feat_stride")) { - unsigned int feat_stride_ = layer->GetParamAsUInt("feat_stride"); - (void)feat_stride_; - } - if (layer->CheckParamPresence("pre_nms_topn")) { - unsigned int pre_nms_topn_ = layer->GetParamAsUInt("pre_nms_topn"); - (void)pre_nms_topn_; - } - if (layer->CheckParamPresence("iou_threshold")) { - float iou_threshold_ = layer->GetParamAsFloat("iou_threshold"); - if (iou_threshold_ < 0) { - IE_THROW() << "The value of SimplerNMS layer iou_threshold_ parameter is invalid"; - } - } - if (layer->CheckParamPresence("scale")) { - std::vector scale = layer->GetParamAsUInts("scale", {}); - (void)scale; - } - if (layer->CheckParamPresence("cls_threshold")) { - float cls_threshold = layer->GetParamAsFloat("cls_threshold"); - if (cls_threshold < 0) { - IE_THROW() << "The value of SimplerNMS layer cls_threshold parameter is invalid"; - } - } -} - -void SimplerNMSValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {3}); -} - -SimplerNMSValidator::SimplerNMSValidator(const std::string& _type) : LayerValidator(_type) {} - -void SpatialTransformerValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void SpatialTransformerValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {2}); -} - -SpatialTransformerValidator::SpatialTransformerValidator(const std::string& _type) : LayerValidator(_type) {} - -void UpsamplingValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void UpsamplingValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -UpsamplingValidator::UpsamplingValidator(const std::string& _type) : LayerValidator(_type) {} - -void UnpoolingValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void UnpoolingValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -UnpoolingValidator::UnpoolingValidator(const std::string& _type) : LayerValidator(_type) {} - -ActivationValidator::ActivationValidator(const std::string& _type) : LayerValidator(_type) {} - -void ActivationValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void ActivationValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -ConstValidator::ConstValidator(const std::string& _type) : LayerValidator(_type) {} - -void ConstValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void ConstValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {0, 1}); -} - -CopyValidator::CopyValidator(const std::string& _type) : LayerValidator(_type) {} - -void CopyValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void CopyValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -ELUValidator::ELUValidator(const std::string& _type) : LayerValidator(_type) {} - -void ELUValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void ELUValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -InputValidator::InputValidator(const std::string& _type) : LayerValidator(_type) {} - -void InputValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void InputValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {0}); -} - -MemoryValidator::MemoryValidator(const std::string& _type) : LayerValidator(_type) {} - -void MemoryValidator::checkParams(const CNNLayer* layer) { - int size = layer->GetParamAsInt("size"); - if (size != 2) { - IE_THROW() << "The value of Memory layer size parameter is invalid"; - } -} - -void MemoryValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1, 0}); -} - -NormalizeValidator::NormalizeValidator(const std::string& _type) : LayerValidator(_type) {} - -void NormalizeValidator::checkParams(const CNNLayer* layer) { - if (layer->CheckParamPresence("eps")) { - float eps = layer->GetParamAsFloat("eps"); - if (eps < 0) { - IE_THROW() << "The value of Normalize layer eps parameter is invalid"; - } - } -} - -SelectValidator::SelectValidator(const std::string& _type) : LayerValidator(_type) {} - -void SelectValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - enum { CONDITION, THEN, ELSE, numOfInputs }; - - size_t numInputs = inShapes.size(); - if (numOfInputs != numInputs) - IE_THROW() << "Select layer with name '" << layer->name - << "' take 3 inputs, but actually it has: " << numInputs; - - size_t new_rank = inShapes[ELSE].size(); - new_rank = std::max(new_rank, inShapes[THEN].size()); - - if (inShapes[CONDITION].size() > new_rank) - IE_THROW() << "Select layer with name '" << layer->name - << "' has 'Mask' input's rank more than broadcasted 'Then' and 'Else' inputs' ranks"; - - for (size_t i = 0; i < new_rank; i++) { - auto in1 = i < (new_rank - inShapes[THEN].size()) ? 1 : inShapes[THEN][i - (new_rank - inShapes[THEN].size())]; - auto in2 = i < (new_rank - inShapes[ELSE].size()) ? 1 : inShapes[ELSE][i - (new_rank - inShapes[ELSE].size())]; - - size_t tmp = 0; - if (in1 == in2 || in1 == 1 || in2 == 1) - tmp = std::max(in1, in2); - else - IE_THROW() << "Select layer with name '" << layer->name - << "' has incompatible 'Then' and 'Else' inputs' shapes"; - - auto in0 = i < (new_rank - inShapes[CONDITION].size()) - ? 1 - : inShapes[CONDITION][i - (new_rank - inShapes[CONDITION].size())]; - - if (tmp == in0 || in0 == 1) - tmp = std::max(tmp, in0); - else - IE_THROW() << "Select layer with name '" << layer->name - << "' has incompatible 'Mask' input's shapes and broadcasted 'Then' and 'Else' inputs' shapes"; - } -} - -void NormalizeValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -PowerFileValidator::PowerFileValidator(const std::string& _type) : LayerValidator(_type) {} - -void PowerFileValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void PowerFileValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -ReLU6Validator::ReLU6Validator(const std::string& _type) : LayerValidator(_type) {} - -void ReLU6Validator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void ReLU6Validator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -SigmoidValidator::SigmoidValidator(const std::string& _type) : LayerValidator(_type) {} - -void SigmoidValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void SigmoidValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -TanHValidator::TanHValidator(const std::string& _type) : LayerValidator(_type) {} - -void TanHValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -OneHotValidator::OneHotValidator(const std::string& _type) : LayerValidator(_type) {} - -void OneHotValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void OneHotValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -QuantizeValidator::QuantizeValidator(const std::string& _type) : LayerValidator(_type) {} - -void QuantizeValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void QuantizeValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of QuantizeLayer class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 5) - IE_THROW() << "Quantize can take only 5 inputs, but actually it has: " << numInputs; - - auto dims0 = inShapes[0]; - if (dims0.size() < 1) { - IE_THROW() << "Quantize input0 shape must have at least 1 dimension"; - } -} - -BinaryConvolutionValidator::BinaryConvolutionValidator(const std::string& _type) : LayerValidator(_type) {} - -void BinaryConvolutionValidator::checkParams(const CNNLayer* layer) { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << "Layer is not instance of BinaryConvolutionLayer class"; - } -} - -void BinaryConvolutionValidator::checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const vector& inShapes) const { - auto binConvLayer = dynamic_cast(layer); - if (!binConvLayer) - IE_THROW() << "Layer is not instance of BinaryConvolutionLayer class"; -} - -void BinaryConvolutionValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -MathValidator::MathValidator(const std::string& _type) : LayerValidator(_type) {} - -void MathValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {1}); -} - -ReduceValidator::ReduceValidator(const std::string& _type) : LayerValidator(_type) {} - -void ReduceValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void ReduceValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - size_t numInputs = inShapes.size(); - if (numInputs > 2) - IE_THROW() << layer->name << " Reduce can take up to 2 inputs, but actually it has: " << numInputs; -} - -GatherTreeValidator::GatherTreeValidator(const std::string& _type) : LayerValidator(_type) {} - -void GatherTreeValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void GatherTreeValidator::checkShapes(const CNNLayer* layer, const std::vector& inShapes) const { - checkNumOfInput(inShapes, {4}); - if (inShapes[0].size() != 3) - IE_THROW() << layer->name << " step_idx tensor should be 3 dimension " << inShapes[0].size(); - if (inShapes[1].size() != 3) - IE_THROW() << layer->name << " parent_idx tensor should be 3 dimension " << inShapes[1].size(); - if (inShapes[2].size() != 1) - IE_THROW() << layer->name << " max_seq_len vector should be 1 dimension " << inShapes[2].size(); - if (inShapes[3].size() != 1) - IE_THROW() << layer->name << " end_token vector should be 1 dimension " << inShapes[3].size(); - if (inShapes[0] != inShapes[1] || inShapes[0][1] != inShapes[2][0]) { - IE_THROW() << layer->name << " Input tensors dimensions mismatch"; - } -} - -TopKValidator::TopKValidator(const std::string& _type) : LayerValidator(_type) {} - -void TopKValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - size_t numInputs = inShapes.size(); - if (numInputs != 2) - IE_THROW() << layer->name << " TopK can take only 2 inputs, but actually it has: " << numInputs; -} - -UniqueValidator::UniqueValidator(const std::string& _type) : LayerValidator(_type) {} - -void UniqueValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - size_t numInputs = inShapes.size(); - if (numInputs != 1) - IE_THROW() << layer->name << " Unique can take only 1 input, but actually it has: " << numInputs; -} - -NMSValidator::NMSValidator(const std::string& _type) : LayerValidator(_type) {} - -void NMSValidator::checkParams(const CNNLayer* layer) { - LayerValidator::checkParams(layer); -} - -void NMSValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - size_t numInputs = inShapes.size(); - if (numInputs < 2 || numInputs > 6) - IE_THROW() << layer->name << " NonMaxSuppression can take 2 - 6 inputs, but actually it has: " << numInputs; - - if (inShapes[0].size() != 3 || inShapes[0][2] != 4) - IE_THROW() << layer->name << " 'boxes' should be with shape [num_batches, spatial_dimension, 4]"; - - if (inShapes[1].size() != 3) - IE_THROW() << layer->name << " 'scores' should be with shape [num_batches, num_classes, spatial_dimension]"; - - if (inShapes[0][0] != inShapes[1][0]) - IE_THROW() << layer->name << " num_batches is different in 'boxes' and 'scores' tensors"; - - if (inShapes[0][1] != inShapes[1][2]) - IE_THROW() << layer->name << " spatial_dimension is different in 'boxes' and 'scores' tensors"; - - if (numInputs > 2 && inShapes[2].size() && inShapes[2][0] != 1) - IE_THROW() << layer->name << " 'max_output_boxes_per_class' should be scalar"; - - if (numInputs > 3 && inShapes[3].size() && inShapes[3][0] != 1) - IE_THROW() << layer->name << " 'iou_threshold' should be scalar"; - - if (numInputs > 4 && inShapes[4].size() && inShapes[4][0] != 1) - IE_THROW() << layer->name << " 'score_threshold' should be scalar"; -} - -ScatterUpdateValidator::ScatterUpdateValidator(const std::string& _type) : LayerValidator(_type) {} - -void ScatterUpdateValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of ScatterUpdateLayer class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 4) - IE_THROW() << layer->name << " Scatter can take only 4 inputs, but actually it has: " << numInputs; - - static constexpr int DATA = 0; - static constexpr int INDICES = 1; - static constexpr int UPDATES = 2; - static constexpr int AXIS = 3; - - if (inShapes[DATA].size() < 1) - IE_THROW() << layer->name << " 'Data' tensor rank must be >= 1"; - - if (inShapes[INDICES].size() < 1) - IE_THROW() << layer->name << " 'Indices' tensor rank must be >= 1"; - - if (inShapes[UPDATES].size() < 1) - IE_THROW() << layer->name << " 'Updates' tensor rank must be >= 1"; - - if (!(inShapes[AXIS].size() == 0 || (inShapes[AXIS].size() == 1 && inShapes[AXIS][0] == 1))) - IE_THROW() << layer->name << " 'Axis' tensor must be scalar, or 1D array of 1 element"; - - if (inShapes[UPDATES].size() != inShapes[INDICES].size() + inShapes[DATA].size() - 1) - IE_THROW() << layer->name << " Incorrect number of 'indexes' and 'updates' tensors dimension"; - - Precision inIndicesPrecision = layer->insData[INDICES].lock()->getTensorDesc().getPrecision(); - if (inIndicesPrecision != Precision::I32 && inIndicesPrecision != Precision::I64) - IE_THROW() << layer->name << " Incorrect input 'Indices' precision. Only I32 or I64 are supported!"; - - Precision inAxisPrecision = layer->insData[AXIS].lock()->getTensorDesc().getPrecision(); - if (inAxisPrecision != Precision::I32 && inAxisPrecision != Precision::I64) - IE_THROW() << layer->name << " Incorrect input 'Axis' precision. Only I32 or I64 are supported!"; - - if (layer->insData[DATA].lock()->getTensorDesc().getPrecision() != - layer->insData[UPDATES].lock()->getTensorDesc().getPrecision()) - IE_THROW() << layer->name << " Precision should be equal for input tensors 'Data' and 'Updates'"; -} - -ScatterElementsUpdateValidator::ScatterElementsUpdateValidator(const std::string& _type) : LayerValidator(_type) {} - -void ScatterElementsUpdateValidator::checkShapes(const CNNLayer* layer, const vector& inShapes) const { - auto casted = dynamic_cast(layer); - if (!casted) { - IE_THROW() << layer->name << " Layer is not instance of ScatterElementsUpdateLayer class"; - } - - size_t numInputs = inShapes.size(); - if (numInputs != 4) - IE_THROW() << layer->name << " Scatter can take only 4 inputs, but actually it has: " << numInputs; - - static constexpr int DATA = 0; - static constexpr int INDICES = 1; - static constexpr int UPDATES = 2; - static constexpr int AXIS = 3; - - if (inShapes[DATA].size() < 1) - IE_THROW() << layer->name << " 'Data' tensor rank must be >= 1"; - - if (inShapes[INDICES].size() < 1) - IE_THROW() << layer->name << " 'Indices' tensor rank must be >= 1"; - - if (inShapes[UPDATES].size() < 1) - IE_THROW() << layer->name << " 'Updates' tensor rank must be >= 1"; - - if (!(inShapes[AXIS].size() == 0 || (inShapes[AXIS].size() == 1 && inShapes[AXIS][0] == 1))) - IE_THROW() << layer->name << " 'Axis' tensor must be scalar, or 1D array of 1 element"; - - if (inShapes[INDICES].size() != inShapes[DATA].size()) - IE_THROW() << layer->name << " Incorrect number of 'indexes' tensors dimension"; - - if (inShapes[UPDATES].size() != inShapes[DATA].size()) - IE_THROW() << layer->name << " Incorrect number of 'updates' tensors dimension"; - - Precision inIdxPrecision = layer->insData[INDICES].lock()->getTensorDesc().getPrecision(); - if (inIdxPrecision != Precision::I32 && inIdxPrecision != Precision::I64) - IE_THROW() << layer->name << " Incorrect input 'Indices' precision. Only I32 or I64 are supported!"; - - Precision inAxisPrecision = layer->insData[AXIS].lock()->getTensorDesc().getPrecision(); - if (inAxisPrecision != Precision::I32 && inIdxPrecision != Precision::I64) - IE_THROW() << layer->name << " Incorrect input 'Axis' precision. Only I32 or I64 are supported!"; - - if (layer->insData[DATA].lock()->getTensorDesc().getPrecision() != - layer->insData[UPDATES].lock()->getTensorDesc().getPrecision()) - IE_THROW() << layer->name << " Precision should be equal for input tensors 'Data' and 'Updates'"; -} - -#define REG_LAYER_VALIDATOR_FOR_TYPE(__validator, __type) _validators[#__type] = std::make_shared<__validator>(#__type) - -LayerValidators::LayerValidators() : _validators() { - REG_LAYER_VALIDATOR_FOR_TYPE(ActivationValidator, Activation); - REG_LAYER_VALIDATOR_FOR_TYPE(ArgMaxValidator, ArgMax); - REG_LAYER_VALIDATOR_FOR_TYPE(BatchNormalizationValidator, BatchNormalization); - REG_LAYER_VALIDATOR_FOR_TYPE(CTCGreedyDecoderValidator, CTCGreedyDecoder); - REG_LAYER_VALIDATOR_FOR_TYPE(ClampValidator, Clamp); - REG_LAYER_VALIDATOR_FOR_TYPE(ConcatValidator, Concat); - REG_LAYER_VALIDATOR_FOR_TYPE(ConstValidator, Const); - REG_LAYER_VALIDATOR_FOR_TYPE(ConvolutionValidator, Convolution); - REG_LAYER_VALIDATOR_FOR_TYPE(CopyValidator, Copy); - REG_LAYER_VALIDATOR_FOR_TYPE(CropValidator, Crop); - REG_LAYER_VALIDATOR_FOR_TYPE(DeconvolutionValidator, Deconvolution); - REG_LAYER_VALIDATOR_FOR_TYPE(DeformableConvolutionValidator, DeformableConvolution); - REG_LAYER_VALIDATOR_FOR_TYPE(DetectionOutputValidator, DetectionOutput); - REG_LAYER_VALIDATOR_FOR_TYPE(ELUValidator, ELU); - REG_LAYER_VALIDATOR_FOR_TYPE(EltwiseValidator, Eltwise); - REG_LAYER_VALIDATOR_FOR_TYPE(FullyConnectedValidator, InnerProduct); - REG_LAYER_VALIDATOR_FOR_TYPE(FullyConnectedValidator, FullyConnected); - REG_LAYER_VALIDATOR_FOR_TYPE(GRNValidator, GRN); - REG_LAYER_VALIDATOR_FOR_TYPE(InputValidator, Input); - REG_LAYER_VALIDATOR_FOR_TYPE(InterpValidator, Interp); - REG_LAYER_VALIDATOR_FOR_TYPE(MVNValidator, MVN); - REG_LAYER_VALIDATOR_FOR_TYPE(MemoryValidator, Memory); - REG_LAYER_VALIDATOR_FOR_TYPE(NormValidator, Norm); - REG_LAYER_VALIDATOR_FOR_TYPE(NormValidator, LRN); - REG_LAYER_VALIDATOR_FOR_TYPE(NormalizeValidator, Normalize); - REG_LAYER_VALIDATOR_FOR_TYPE(PReLUValidator, PReLU); - REG_LAYER_VALIDATOR_FOR_TYPE(PSROIPoolingValidator, PSROIPooling); - REG_LAYER_VALIDATOR_FOR_TYPE(PermuteValidator, Permute); - REG_LAYER_VALIDATOR_FOR_TYPE(PoolingValidator, Pooling); - REG_LAYER_VALIDATOR_FOR_TYPE(PowerValidator, Power); - REG_LAYER_VALIDATOR_FOR_TYPE(PowerFileValidator, PowerFile); - REG_LAYER_VALIDATOR_FOR_TYPE(PriorBoxClusteredValidator, PriorBoxClustered); - REG_LAYER_VALIDATOR_FOR_TYPE(PriorBoxValidator, PriorBox); - REG_LAYER_VALIDATOR_FOR_TYPE(ProposalValidator, Proposal); - REG_LAYER_VALIDATOR_FOR_TYPE(ROIPoolingValidator, ROIPooling); - REG_LAYER_VALIDATOR_FOR_TYPE(ReLUValidator, ReLU); - REG_LAYER_VALIDATOR_FOR_TYPE(ReLU6Validator, ReLU6); - REG_LAYER_VALIDATOR_FOR_TYPE(RegionYoloValidator, RegionYolo); - REG_LAYER_VALIDATOR_FOR_TYPE(ReorgYoloValidator, ReorgYolo); - REG_LAYER_VALIDATOR_FOR_TYPE(ResampleValidator, Resample); - REG_LAYER_VALIDATOR_FOR_TYPE(ReshapeValidator, Reshape); - REG_LAYER_VALIDATOR_FOR_TYPE(ReshapeValidator, Flatten); - REG_LAYER_VALIDATOR_FOR_TYPE(ScaleShiftValidator, ScaleShift); - REG_LAYER_VALIDATOR_FOR_TYPE(SigmoidValidator, Sigmoid); - REG_LAYER_VALIDATOR_FOR_TYPE(SigmoidValidator, Logistic); - REG_LAYER_VALIDATOR_FOR_TYPE(SimplerNMSValidator, SimplerNMS); - REG_LAYER_VALIDATOR_FOR_TYPE(SoftMaxValidator, SoftMax); - REG_LAYER_VALIDATOR_FOR_TYPE(SpatialTransformerValidator, SpatialTransformer); - REG_LAYER_VALIDATOR_FOR_TYPE(SplitValidator, Split); - REG_LAYER_VALIDATOR_FOR_TYPE(SplitValidator, Slice); - REG_LAYER_VALIDATOR_FOR_TYPE(GemmValidator, Gemm); - REG_LAYER_VALIDATOR_FOR_TYPE(PadValidator, Pad); - REG_LAYER_VALIDATOR_FOR_TYPE(GatherValidator, Gather); - REG_LAYER_VALIDATOR_FOR_TYPE(StridedSliceValidator, StridedSlice); - REG_LAYER_VALIDATOR_FOR_TYPE(ShuffleChannelsValidator, ShuffleChannels); - REG_LAYER_VALIDATOR_FOR_TYPE(DepthToSpaceValidator, DepthToSpace); - REG_LAYER_VALIDATOR_FOR_TYPE(SpaceToDepthValidator, SpaceToDepth); - REG_LAYER_VALIDATOR_FOR_TYPE(SpaceToBatchValidator, SpaceToBatch); - REG_LAYER_VALIDATOR_FOR_TYPE(BatchToSpaceValidator, BatchToSpace); - REG_LAYER_VALIDATOR_FOR_TYPE(SparseFillEmptyRowsValidator, SparseFillEmptyRows); - REG_LAYER_VALIDATOR_FOR_TYPE(SparseSegmentReduceValidator, SparseSegmentMean); - REG_LAYER_VALIDATOR_FOR_TYPE(SparseSegmentReduceValidator, SparseSegmentSqrtN); - REG_LAYER_VALIDATOR_FOR_TYPE(SparseSegmentReduceValidator, SparseSegmentSum); - REG_LAYER_VALIDATOR_FOR_TYPE(ExperimentalSparseWeightedReduceValidator, ExperimentalSparseWeightedReduceLayer); - REG_LAYER_VALIDATOR_FOR_TYPE(ReverseSequenceValidator, ReverseSequence); - REG_LAYER_VALIDATOR_FOR_TYPE(BucketizeValidator, BucketizeLayer); - REG_LAYER_VALIDATOR_FOR_TYPE(SparseToDenseValidator, SparseToDenseLayer); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNCellValidator, RNNCell); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNCellValidator, GRUCell); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNCellValidator, LSTMCell); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNSequenceValidator, RNNSequence); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNSequenceValidator, GRUSequence); - REG_LAYER_VALIDATOR_FOR_TYPE(RNNSequenceValidator, LSTMSequence); - REG_LAYER_VALIDATOR_FOR_TYPE(SelectValidator, Select); - REG_LAYER_VALIDATOR_FOR_TYPE(SqueezeValidator, Squeeze); - REG_LAYER_VALIDATOR_FOR_TYPE(UnsqueezeValidator, Unsqueeze); - REG_LAYER_VALIDATOR_FOR_TYPE(RangeValidator, Range); - REG_LAYER_VALIDATOR_FOR_TYPE(FillValidator, Fill); - REG_LAYER_VALIDATOR_FOR_TYPE(BroadcastValidator, Broadcast); - REG_LAYER_VALIDATOR_FOR_TYPE(TanHValidator, TanH); - REG_LAYER_VALIDATOR_FOR_TYPE(TileValidator, Tile); - REG_LAYER_VALIDATOR_FOR_TYPE(UnpoolingValidator, Unpooling); - REG_LAYER_VALIDATOR_FOR_TYPE(UpsamplingValidator, Upsampling); - REG_LAYER_VALIDATOR_FOR_TYPE(OneHotValidator, OneHot); - REG_LAYER_VALIDATOR_FOR_TYPE(QuantizeValidator, FakeQuantize); - REG_LAYER_VALIDATOR_FOR_TYPE(BinaryConvolutionValidator, BinaryConvolution); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Abs); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Acos); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Acosh); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Asin); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Asinh); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Atan); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Atanh); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Ceil); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Cos); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Cosh); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Erf); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Floor); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, HardSigmoid); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Log); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Neg); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Reciprocal); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Selu); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Sign); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Sin); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Sinh); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Softplus); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Softsign); - REG_LAYER_VALIDATOR_FOR_TYPE(MathValidator, Tan); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceAnd); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceL1); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceL2); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceLogSum); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceLogSumExp); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceMax); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceMean); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceMin); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceOr); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceProd); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceSum); - REG_LAYER_VALIDATOR_FOR_TYPE(ReduceValidator, ReduceSumSquare); - REG_LAYER_VALIDATOR_FOR_TYPE(GatherTreeValidator, GatherTree); - REG_LAYER_VALIDATOR_FOR_TYPE(TopKValidator, TopK); - REG_LAYER_VALIDATOR_FOR_TYPE(UniqueValidator, Unique); - REG_LAYER_VALIDATOR_FOR_TYPE(NMSValidator, NonMaxSuppression); - REG_LAYER_VALIDATOR_FOR_TYPE(ScatterUpdateValidator, ScatterUpdate); - REG_LAYER_VALIDATOR_FOR_TYPE(ScatterElementsUpdateValidator, ScatterElementsUpdate); -} - -} // namespace diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_validators.hpp b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_validators.hpp deleted file mode 100644 index d2320e8bc60..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/ie_layer_validators.hpp +++ /dev/null @@ -1,884 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include - -#include "caseless.hpp" -#include "ie_common.h" - -namespace InferenceEngine { -namespace details { - -void validateLayer(const CNNLayer* layer); - -} // namespace details -} // namespace InferenceEngine - -namespace { - -using InferenceEngine::Blob; -using InferenceEngine::CNNLayer; -using InferenceEngine::RNNSequenceLayer; -using InferenceEngine::SizeVector; - -struct InOutDims { - std::vector> inDims; - std::vector> outDims; -}; - -/** - * @brief Contains methods to validate layer of specific type - */ -class LayerValidator { -public: - using Ptr = std::shared_ptr; - - explicit LayerValidator(const std::string& _type) : _type(_type) {} - virtual ~LayerValidator() = default; - - /** - * @brief Validates layer parameters separately from blobs and shapes - * This is semantic check, like height and width more than kernel sizes, stride > 0, beta > 0, axis is correct and - * etc Throws exception if the check fails - */ - virtual void checkParams(const CNNLayer* layer) {} - - /** - * @brief Checks correspondence of input shapes and layer parameters. - * @note: This function doesn't touch ins and out Data of the layer. - * Throws exception if the check fails - */ - virtual void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const {} - - /** - * @brief Checks correspondence of all parameters in the aggregate, except output shapes. - * @note: This function doesn't touch ins and out Data of the layer. - * Throws exception if the check fails - */ - virtual void checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const std::vector& inShapes) const {} - -protected: - std::string _type; -}; - -/** - * @brief Contains all validators, registered for specific layer type - */ -class LayerValidators { -public: - static LayerValidators* getInstance(); - - LayerValidators(LayerValidators const&) = delete; - - void operator=(LayerValidators const&) = delete; - - LayerValidator::Ptr getValidator(const std::string& type); - -private: - LayerValidators(); - -private: - InferenceEngine::details::caseless_unordered_map _validators; -}; - -inline static void getInOutShapes(const CNNLayer* layer, InOutDims& inOutShapes) { - inOutShapes.inDims.clear(); - inOutShapes.outDims.clear(); - if (layer) { - for (const auto& inData : layer->insData) { - auto locked = inData.lock(); - if (locked) { - inOutShapes.inDims.push_back(locked->getDims()); - } - } - for (const auto& outData : layer->outData) { - if (outData) { - inOutShapes.outDims.push_back(outData->getDims()); - } - } - } -} - -class GeneralValidator : public LayerValidator { -public: - explicit GeneralValidator(const std::string& _type); -}; - -class ConvolutionValidator : public LayerValidator { -public: - void checkParams(const CNNLayer* layer) override; - - explicit ConvolutionValidator(const std::string& _type); - - void checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const std::vector& inShapes) const override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class DeconvolutionValidator : public ConvolutionValidator { -public: - void checkParams(const CNNLayer* layer) override; - - explicit DeconvolutionValidator(const std::string& _type); - - void checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const std::vector& inShapes) const override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class DeformableConvolutionValidator : public ConvolutionValidator { -public: - void checkParams(const CNNLayer* layer) override; - - explicit DeformableConvolutionValidator(const std::string& _type); - - void checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const std::vector& inShapes) const override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class PoolingValidator : public LayerValidator { -public: - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; - - explicit PoolingValidator(const std::string& _type); -}; - -class FullyConnectedValidator : public LayerValidator { -public: - explicit FullyConnectedValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const std::vector& inShapes) const override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class CropValidator : public LayerValidator { -public: - explicit CropValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class TileValidator : public LayerValidator { -public: - explicit TileValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class BatchNormalizationValidator : public LayerValidator { -public: - explicit BatchNormalizationValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class PowerValidator : public LayerValidator { -public: - explicit PowerValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class PReLUValidator : public LayerValidator { -public: - explicit PReLUValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ScaleShiftValidator : public LayerValidator { -public: - explicit ScaleShiftValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ReshapeValidator : public LayerValidator { -public: - explicit ReshapeValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; -}; - -class EltwiseValidator : public LayerValidator { -public: - explicit EltwiseValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ClampValidator : public LayerValidator { -public: - explicit ClampValidator(const std::string& _type); - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ReLUValidator : public LayerValidator { -public: - explicit ReLUValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class MVNValidator : public LayerValidator { -public: - explicit MVNValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class GRNValidator : public LayerValidator { -public: - explicit GRNValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SoftMaxValidator : public LayerValidator { -public: - explicit SoftMaxValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class NormValidator : public LayerValidator { -public: - explicit NormValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SplitValidator : public LayerValidator { -public: - explicit SplitValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ConcatValidator : public LayerValidator { -public: - explicit ConcatValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class GemmValidator : public LayerValidator { -public: - explicit GemmValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class PadValidator : public LayerValidator { -public: - explicit PadValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class GatherValidator : public LayerValidator { -public: - explicit GatherValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class StridedSliceValidator : public LayerValidator { -public: - explicit StridedSliceValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ShuffleChannelsValidator : public LayerValidator { -public: - explicit ShuffleChannelsValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class DepthToSpaceValidator : public LayerValidator { -public: - explicit DepthToSpaceValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SpaceToDepthValidator : public LayerValidator { -public: - explicit SpaceToDepthValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SpaceToBatchValidator : public LayerValidator { -public: - explicit SpaceToBatchValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class BatchToSpaceValidator : public LayerValidator { -public: - explicit BatchToSpaceValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SparseFillEmptyRowsValidator : public LayerValidator { -public: - explicit SparseFillEmptyRowsValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SparseSegmentReduceValidator : public LayerValidator { -public: - explicit SparseSegmentReduceValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ExperimentalSparseWeightedReduceValidator : public LayerValidator { -public: - explicit ExperimentalSparseWeightedReduceValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SparseToDenseValidator : public LayerValidator { -public: - explicit SparseToDenseValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class BucketizeValidator : public LayerValidator { -public: - explicit BucketizeValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ReverseSequenceValidator : public LayerValidator { -public: - explicit ReverseSequenceValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SqueezeValidator : public LayerValidator { -public: - explicit SqueezeValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class UnsqueezeValidator : public LayerValidator { -public: - explicit UnsqueezeValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class RangeValidator : public LayerValidator { -public: - explicit RangeValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class FillValidator : public LayerValidator { -public: - explicit FillValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class BroadcastValidator : public LayerValidator { -public: - explicit BroadcastValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class RNNBaseValidator : public LayerValidator { -public: - RNNBaseValidator(const std::string& _type, RNNSequenceLayer::CellType CELL); - - void checkParams(const CNNLayer* layer) override; - - void checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const std::vector& inShapes) const override; - -protected: - std::vector def_acts; // Default values for cell gate activations - std::vector def_alpha; // Default activation alpha parameter - std::vector def_beta; // Default activation beta parameter - size_t G; // gate number - size_t NS; // state number -}; - -template -class RNNCellValidator : public RNNBaseValidator { -public: - explicit RNNCellValidator(const std::string& _type); - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -template -class RNNSequenceValidator : public RNNBaseValidator { -public: - explicit RNNSequenceValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ArgMaxValidator : public LayerValidator { -public: - explicit ArgMaxValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class CTCGreedyDecoderValidator : public LayerValidator { -public: - explicit CTCGreedyDecoderValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class DetectionOutputValidator : public LayerValidator { -public: - explicit DetectionOutputValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class InterpValidator : public LayerValidator { -public: - explicit InterpValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class PermuteValidator : public LayerValidator { -public: - explicit PermuteValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class PriorBoxValidator : public LayerValidator { -public: - explicit PriorBoxValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class PriorBoxClusteredValidator : public LayerValidator { -public: - explicit PriorBoxClusteredValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ProposalValidator : public LayerValidator { -public: - explicit ProposalValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class PSROIPoolingValidator : public LayerValidator { -public: - explicit PSROIPoolingValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class RegionYoloValidator : public LayerValidator { -public: - explicit RegionYoloValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ReorgYoloValidator : public LayerValidator { -public: - explicit ReorgYoloValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ResampleValidator : public LayerValidator { -public: - explicit ResampleValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ROIPoolingValidator : public LayerValidator { -public: - explicit ROIPoolingValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SimplerNMSValidator : public LayerValidator { -public: - explicit SimplerNMSValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SpatialTransformerValidator : public LayerValidator { -public: - explicit SpatialTransformerValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class OneHotValidator : public LayerValidator { -public: - explicit OneHotValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class UpsamplingValidator : public LayerValidator { -public: - explicit UpsamplingValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ActivationValidator : public LayerValidator { -public: - explicit ActivationValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ConstValidator : public LayerValidator { -public: - explicit ConstValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ELUValidator : public LayerValidator { -public: - explicit ELUValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class InputValidator : public LayerValidator { -public: - explicit InputValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class MemoryValidator : public LayerValidator { -public: - explicit MemoryValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class NormalizeValidator : public LayerValidator { -public: - explicit NormalizeValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class CopyValidator : public LayerValidator { -public: - explicit CopyValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class PowerFileValidator : public LayerValidator { -public: - explicit PowerFileValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ReLU6Validator : public LayerValidator { -public: - explicit ReLU6Validator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SigmoidValidator : public LayerValidator { -public: - explicit SigmoidValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class TanHValidator : public LayerValidator { -public: - explicit TanHValidator(const std::string& _type); - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class UnpoolingValidator : public LayerValidator { -public: - explicit UnpoolingValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class QuantizeValidator : public LayerValidator { -public: - explicit QuantizeValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class BinaryConvolutionValidator : public LayerValidator { -public: - void checkParams(const CNNLayer* layer) override; - - explicit BinaryConvolutionValidator(const std::string& _type); - - void checkCorrespondence(const CNNLayer* layer, - const std::map& blobs, - const std::vector& inShapes) const override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class SelectValidator : public LayerValidator { -public: - explicit SelectValidator(const std::string& _type); - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class MathValidator : public LayerValidator { -public: - explicit MathValidator(const std::string& _type); - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ReduceValidator : public LayerValidator { -public: - explicit ReduceValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class GatherTreeValidator : public LayerValidator { -public: - explicit GatherTreeValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class TopKValidator : public LayerValidator { -public: - explicit TopKValidator(const std::string& _type); - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class UniqueValidator : public LayerValidator { -public: - explicit UniqueValidator(const std::string& _type); - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class NMSValidator : public LayerValidator { -public: - explicit NMSValidator(const std::string& _type); - - void checkParams(const CNNLayer* layer) override; - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ScatterUpdateValidator : public LayerValidator { -public: - explicit ScatterUpdateValidator(const std::string& _type); - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -class ScatterElementsUpdateValidator : public LayerValidator { -public: - explicit ScatterElementsUpdateValidator(const std::string& _type); - - void checkShapes(const CNNLayer* layer, const std::vector& inShapes) const override; -}; - -} // namespace diff --git a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/parsers.h b/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/parsers.h deleted file mode 100644 index 1930b73f0fa..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/readers/ir_reader_v7/parsers.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace pugi { -class xml_node; -} // namespace pugi - -namespace InferenceEngine { -namespace details { -struct IFormatParser { - virtual ~IFormatParser() {} - - virtual CNNNetworkImplPtr Parse(pugi::xml_node& root) = 0; - - virtual void SetWeights(const TBlob::Ptr& weights) = 0; -}; -} // namespace details -} // namespace InferenceEngine diff --git a/src/plugins/intel_gna/tests/deprecated/unit/CMakeLists.txt b/src/plugins/intel_gna/tests/deprecated/unit/CMakeLists.txt deleted file mode 100644 index 035e05de645..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/CMakeLists.txt +++ /dev/null @@ -1,105 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -cmake_policy(SET CMP0054 NEW) - -set(TARGET_NAME InferenceEngineUnitTests) - -ov_disable_deprecated_warnings() - -# collect sources - -file(GLOB - TEST_SRC - inference_engine_tests/*.cpp - ) - -# TODO: fix CVS-71010 and remove BUILD_SHARED_LIBS -if (ENABLE_INTEL_GNA AND BUILD_SHARED_LIBS) - file(GLOB - GNA_TESTS - engines/gna/*cpp - engines/gna/layers/*cpp - engines/gna/graph_tools/*cpp - ) - source_group("gna" FILES ${GNA_TESTS}) - list(APPEND TEST_SRC ${GNA_TESTS}) - list(APPEND TEST_DEPS openvino_intel_gna_plugin_test_static) - - if(SUGGEST_OVERRIDE_SUPPORTED) - set_source_files_properties(engines/gna/graph_tools/graph_copy_tests.cpp - engines/gna/graph_tools/graph_tools_test.cpp - PROPERTIES COMPILE_OPTIONS -Wno-suggest-override) - endif() - - # TODO: fix GNA tests - if(OFF) - set(gna_stub "${CMAKE_CURRENT_SOURCE_DIR}/engines/gna/gna_api_stub.cpp") - list(REMOVE_ITEM TEST_SRC "${gna_stub}") - add_library(libGNAStubs SHARED "${gna_stub}") - - find_package(libGNA NO_MODULE REQUIRED) - - target_include_directories(libGNAStubs PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/engines/gna/") - target_link_libraries(libGNAStubs PUBLIC libGNA::API gmock gtest) - if(UNIX) - set_target_properties(libGNAStubs PROPERTIES CXX_VISIBILITY_PRESET default) - endif() - list(APPEND TEST_DEPS libGNAStubs) - endif() -endif() - -source_group("src" FILES ${TEST_SRC}) -source_group("include" FILES ${TEST_INCLUDE}) - -# create target - -add_executable(${TARGET_NAME} ${TEST_SRC} ${TEST_INCLUDE}) - -target_include_directories(${TARGET_NAME} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}) - -set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_PDB_NAME ${TARGET_NAME}) - -# because IE unit tests use plugin and IE object files compiled with LTO -set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) - -## Mock macros doesn't use "override" specificator -target_compile_options(${TARGET_NAME} PRIVATE $<$: -Wno-error=inconsistent-missing-override >) -target_compile_options(${TARGET_NAME} PRIVATE $<$: -Wno-error=inconsistent-missing-override >) - -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS -IGNORE:4286) -endif() - -target_link_libraries(${TARGET_NAME} PRIVATE - # static libraries - inference_engine_s # need to have this explicitly for USE_STATIC_IE - unit_test_utils - ieTestHelpers_s - ${TEST_DEPS} - - # dynamic libraries - inference_engine_transformations - inference_engine_lp_transformations - ) - -ov_try_use_gold_linker() - -add_test(NAME ${TARGET_NAME} COMMAND ${TARGET_NAME}) -set_property(TEST ${TARGET_NAME} PROPERTY LABELS OV UNIT) - -install(TARGETS ${TARGET_NAME} - RUNTIME DESTINATION tests - COMPONENT tests - EXCLUDE_FROM_ALL) - -if(TARGET libGNAStubs) - install(TARGETS libGNAStubs - RUNTIME DESTINATION tests - COMPONENT tests - EXCLUDE_FROM_ALL) -endif() - -add_dependencies(${TARGET_NAME} mock_engine) diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/I8_quantisation_test.cpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/I8_quantisation_test.cpp deleted file mode 100644 index e7da37e1467..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/I8_quantisation_test.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "frontend/layer_quantizer.hpp" -#include "frontend/model_quantizer.hpp" -#include "gna_matcher.hpp" - -using namespace InferenceEngine; -using namespace ov::intel_gna::limitations; -using namespace ov::intel_gna::frontend; -using namespace GNATestIRs; - -class I8QuantisationTest : public GNATest<> { -protected: - InferenceEngine::CNNLayerPtr quantize(InferenceEngine::CNNLayerPtr lp) { - auto newLayer = InferenceEngine::injectData(lp); - Config gna_config; - gna_config.gnaPrecision = InferenceEngine::Precision::I16; - gna_config.gnaFlags.input_low_precision = false; - LayerQuantizer lq(gna_config); - lq.quantize(*newLayer); - return newLayer; - }; - - InferenceEngine::CNNNetwork quantize_single_input_model(const InferenceEngine::CNNNetwork& model, - float scale_factor) const { - auto scale_factors = std::vector({scale_factor}); - - GnaInputs inputs; - InferenceEngine::InputsDataMap inputs_map = model.getInputsInfo(); - - auto input_layer = getCreatorLayer(inputs_map.begin()->second->getInputData()).lock(); - inputs[input_layer->name].scale_factor = scale_factor; - - Config gna_config; - gna_config.gnaPrecision = InferenceEngine::Precision::I16; - gna_config.gnaFlags.input_low_precision = false; - - auto transformer = ov::intel_gna::TransformationsPipeline(gna_config); - - return ModelQuantizer(transformer).quantize(model, inputs); - } - - void SetUp() override { - Limitations::init(target::DeviceVersion::Default); - } - - void TearDown() override { - Limitations::deinit(); - } -}; - -// TODO: add test for FC weights after quantization -TEST_F(I8QuantisationTest, canQuantizeFCLayer) { - auto fc = std::make_shared(LayerParams{"name", "type", Precision::FP32}); - fc->_out_num = 9; - auto weights = make_shared_blob({Precision::FP32, {1, 1}, Layout::NC}); - fc->_weights = weights; - fc->_biases = make_shared_blob({Precision::FP32, {1, 1}, Layout::NC}); - fc->_weights->allocate(); - fc->_biases->allocate(); - std::shared_ptr outData = - std::make_shared("data", TensorDesc(Precision::FP32, SizeVector({1, 1}), Layout::NC)); - fc->outData.push_back(outData); - fc->insData.push_back(outData); - - // actual quantisation algorithm is involved - for (auto&& w : *weights) { - w = MAX_OUT_MULTIPLIER * MAX_VAL_1B_WEIGHT; - } - - fillWeights(fc->_biases); - - ASSERT_NO_THROW(quantize(fc)); -} - -TEST_F(I8QuantisationTest, canQuantizeActivation) { - auto sigmoid = std::make_shared(LayerParams{"name", "type", Precision::FP32}); - sigmoid->params["value"] = 2; - sigmoid->type = "Activation"; - - ASSERT_NO_THROW(quantize(sigmoid)); -} - -TEST_F(I8QuantisationTest, inputPrecisionIs16Bits) { - auto weights = make_shared_blob({Precision::U8, {440}, C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(Fc2DOutputModel(), weights); - - auto newNet = quantize_single_input_model(network, 1000); - InputsDataMap inputs = newNet.getInputsInfo(); - auto inputLayer = - getCreatorLayer(getInputTo(inputs.begin()->second->getInputData()).begin()->second->insData.front().lock()) - .lock(); - - ASSERT_EQ(inputLayer->precision, Precision::I16); -} - -TEST_F(I8QuantisationTest, FCDimensionIs1) { - auto weights = make_shared_blob({Precision::U8, {440}, C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(FCOnlyModel(), weights); - - ASSERT_NO_THROW(quantize_single_input_model(network, 1000)); -} - -TEST_F(I8QuantisationTest, outputAffinePrecisionIs32Bits) { - auto weights = make_shared_blob({Precision::U8, {440}, C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(Fc2DOutputModel(), weights); - - auto newNet = quantize_single_input_model(network, 1000); - InputsDataMap inputs = newNet.getInputsInfo(); - auto affineDataPtr = getInputTo(inputs.begin()->second->getInputData()).begin()->second->outData.front(); - - ASSERT_EQ(affineDataPtr->getTensorDesc().getPrecision(), Precision::I32); -} - -TEST_F(I8QuantisationTest, fp16tofp32_on_fullyConnected_model) { - auto weights = make_shared_blob({Precision::U8, {220}, Layout::C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(FCOnlyModelFP16(), weights); - - quantize_single_input_model(network, 1000); -} - -TEST_F(I8QuantisationTest, LSTMCell_quantize) { - auto weights = make_shared_blob({Precision::U8, {33664}, C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(LSTMCellOnlyModel(), weights); - - ASSERT_NO_THROW(quantize_single_input_model(network, 1000)); -} - -TEST_F(I8QuantisationTest, LSTMCell_unaligned_quantize) { - auto weights = make_shared_blob({Precision::U8, {3480}, C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(LSTMCellOnlyModelUnaligned(), weights); - - ASSERT_NO_THROW(quantize_single_input_model(network, 1000)); -} - -TEST_F(I8QuantisationTest, TI_quantize) { - auto weights = make_shared_blob({Precision::U8, {249748}, C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(TIModelWithLSTMCell2(), weights); - - ASSERT_NO_THROW(quantize_single_input_model(network, 1000)); -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_api_stub.cpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_api_stub.cpp deleted file mode 100644 index e8e65a0bd63..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_api_stub.cpp +++ /dev/null @@ -1,269 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#define INTEL_GNA_DLLEXPORT 1 - - -#include -#include -#include - -#include "gna_mock_api.hpp" - -static GNACppApi * current = nullptr; - -GNACppApi :: GNACppApi() { - current = this; -} - -GNACppApi :: ~GNACppApi() { - current = nullptr; -} - -#ifdef __cplusplus -extern "C" { // API uses C linkage so that it can be used by C and C++ applications -#endif - -GNA2_API enum Gna2Status Gna2MemoryAlloc( - uint32_t sizeRequested, - uint32_t *sizeGranted, - void **memoryAddress) { - if (sizeGranted != nullptr) { - *sizeGranted = sizeRequested; - } - if (current != nullptr) { - return current->Gna2MemoryAlloc(sizeRequested, sizeGranted, memoryAddress); - } - *memoryAddress = reinterpret_cast(1); - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2MemorySetTag( - void* memory, - uint32_t tag) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2DeviceCreateForExport( - Gna2DeviceVersion targetDeviceVersion, - uint32_t * deviceIndex) { - *deviceIndex = 1; - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2DeviceOpen( - uint32_t deviceIndex) { - if (current != nullptr) { - return current->Gna2DeviceOpen(deviceIndex); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2DeviceSetNumberOfThreads( - uint32_t deviceIndex, - uint32_t numberOfThreads) { - if (current != nullptr) { - return current->Gna2DeviceSetNumberOfThreads(deviceIndex, numberOfThreads); - } - return Gna2StatusSuccess; -} - -GNA2_API Gna2Status Gna2DeviceClose( - uint32_t deviceIndex) { - if (current != nullptr) { - return current->Gna2DeviceClose(deviceIndex); - } - return Gna2StatusSuccess; -} - -GNA2_API Gna2Status Gna2DeviceGetCount( - uint32_t * numberOfDevices) { - if (numberOfDevices != nullptr) { - *numberOfDevices = 1; - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2MemoryFree( - void * memory) { - if (current != nullptr) { - return current->Gna2MemoryFree(memory); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2StatusGetMessage(enum Gna2Status status, - char * messageBuffer, uint32_t messageBufferSize) { - if (current != nullptr) { - return current->Gna2StatusGetMessage(status, messageBuffer, messageBufferSize); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelCreate( - uint32_t deviceIndex, - struct Gna2Model const * model, - uint32_t * modelId) { - if (current != nullptr) { - return current->Gna2ModelCreate(deviceIndex, model, modelId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelRelease( - uint32_t modelId) { - if (current != nullptr) { - return current->Gna2ModelRelease(modelId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelGetLastError( - struct Gna2ModelError* error) { - if (current != nullptr) { - return current->Gna2ModelGetLastError(error); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2RequestConfigCreate( - uint32_t modelId, - uint32_t * requestConfigId) { - if (current != nullptr) { - return current->Gna2RequestConfigCreate(modelId, requestConfigId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2RequestConfigEnableActiveList( - uint32_t requestConfigId, - uint32_t operationIndex, - uint32_t numberOfIndices, - uint32_t const * indices) { - if (current != nullptr) { - return current->Gna2RequestConfigEnableActiveList(requestConfigId, operationIndex, numberOfIndices, indices); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2RequestConfigSetAccelerationMode( - uint32_t requestConfigId, - enum Gna2AccelerationMode accelerationMode) { - if (current != nullptr) { - return current->Gna2RequestConfigSetAccelerationMode(requestConfigId, accelerationMode); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2RequestEnqueue( - uint32_t requestConfigId, - uint32_t * requestId) { - if (current != nullptr) { - return current->Gna2RequestEnqueue(requestConfigId, requestId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2RequestWait( - uint32_t requestId, - uint32_t timeoutMilliseconds) { - if (current != nullptr) { - return current->Gna2RequestWait(requestId, timeoutMilliseconds); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelExportConfigCreate( - Gna2UserAllocator userAllocator, - uint32_t * exportConfigId) { - if (current != nullptr) { - return current->Gna2ModelExportConfigCreate(userAllocator, exportConfigId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelExportConfigRelease( - uint32_t exportConfigId) { - if (current != nullptr) { - return current->Gna2ModelExportConfigRelease(exportConfigId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelExportConfigSetSource( - uint32_t exportConfigId, - uint32_t sourceDeviceIndex, - uint32_t sourceModelId) { - if (current != nullptr) { - return current->Gna2ModelExportConfigSetSource(exportConfigId, sourceDeviceIndex, sourceModelId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelExportConfigSetTarget( - uint32_t exportConfigId, - enum Gna2DeviceVersion targetDeviceVersion) { - if (current != nullptr) { - return current->Gna2ModelExportConfigSetTarget(exportConfigId, targetDeviceVersion); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelExport( - uint32_t exportConfigId, - enum Gna2ModelExportComponent componentType, - void ** exportBuffer, - uint32_t * exportBufferSize) { - if (current != nullptr) { - return current->Gna2ModelExport(exportConfigId, componentType, exportBuffer, exportBufferSize); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2DeviceGetVersion( - uint32_t deviceIndex, - enum Gna2DeviceVersion * deviceVersion) { - if (current != nullptr) { - return current->Gna2DeviceGetVersion(deviceIndex,deviceVersion); - } - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2InstrumentationConfigCreate( - uint32_t numberOfInstrumentationPoints, - enum Gna2InstrumentationPoint* selectedInstrumentationPoints, - uint64_t * results, - uint32_t * instrumentationConfigId) { - if (current != nullptr) { - return current->Gna2InstrumentationConfigCreate(numberOfInstrumentationPoints, selectedInstrumentationPoints, results, instrumentationConfigId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2InstrumentationConfigAssignToRequestConfig( - uint32_t instrumentationConfigId, - uint32_t requestConfigId) { - if (current != nullptr) { - return current->Gna2InstrumentationConfigAssignToRequestConfig(instrumentationConfigId, requestConfigId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2GetLibraryVersion( - char* versionBuffer, - uint32_t versionBufferSize) { - if (current != nullptr) { - return current->Gna2GetLibraryVersion(versionBuffer, versionBufferSize); - } - if (versionBuffer != nullptr && versionBufferSize > 0) { - versionBuffer[0] = '\0'; - return Gna2StatusSuccess; - } - return Gna2StatusNullArgumentNotAllowed; -} - -#ifdef __cplusplus -} -#endif diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_matcher.cpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_matcher.cpp deleted file mode 100644 index 73a2a58c519..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_matcher.cpp +++ /dev/null @@ -1,741 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_matcher.hpp" -#include -#include "backend/gna_types.hpp" -#include -#include "gna_plugin.hpp" -#include "gna_mock_api.hpp" -#include "matchers/precision_matcher.hpp" -#include "matchers/pwl_matcher.hpp" -#include "matchers/copy_matcher.hpp" -#include "matchers/diag_matcher.hpp" -#include "matchers/pwl_quantization_metrics_matcher.hpp" -#include "matchers/conv_matcher.hpp" -#include "matchers/pool_matcher.hpp" -#include "matchers/fill_with_data.hpp" -#include "matchers/weights_matcher.hpp" -#include "gna2_model_helper.hpp" -#include -#include - -#include -#include "gmock/gmock.h" -#include -#include "matchers/input_data_matcher.hpp" -#include -#include -#include - -#include "unit_test_utils/mocks/mock_icnn_network.hpp" -#include - -using namespace std; -using namespace InferenceEngine; -using namespace ::testing; - -#if USE_RANDOM_SEED - static std::random_device rnd_device; - unsigned int const GNATestBase::random_seed = rnd_device(); -#else - unsigned int const GNATestBase::random_seed = 1337; -#endif - -class NullAllocator : public IAllocator { - void * ptr = nullptr; -public: - NullAllocator() { - ptr = new char[1]; - } - ~NullAllocator() { - delete[] static_cast(ptr); - } - void * lock(void * handle, LockOp = LOCK_FOR_WRITE) noexcept override { - return ptr; - } - void unlock(void * handle) noexcept override { - - } - void * alloc(size_t size) noexcept override { - return ptr; - } - bool free(void* handle) noexcept override { - return true; - } -}; - -void expect_enqueue_calls(GNACppApi &mockApi){ - EXPECT_CALL(mockApi, Gna2ModelCreate(_,_,_)).Times(AtLeast(1)).WillRepeatedly(Invoke([]( - uint32_t deviceIndex, - struct Gna2Model const * model, - uint32_t * modelId) { - *modelId = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2RequestConfigCreate(_,_)).Times(AtLeast(1)).WillRepeatedly(Invoke([]( - uint32_t modelId, - uint32_t * requestConfigId) { - *requestConfigId = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2RequestConfigSetAccelerationMode(_,_)).Times(AtLeast(1)).WillRepeatedly(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2InstrumentationConfigAssignToRequestConfig(_,_)).Times(AtLeast(1)).WillRepeatedly(Return(Gna2StatusSuccess)); - - { - ::testing::InSequence enqueue_wait_sequence; - EXPECT_CALL(mockApi, Gna2RequestEnqueue(_,_)).Times(AtLeast(1)).WillRepeatedly(Invoke([]( - uint32_t requestConfigId, - uint32_t * requestId) { - *requestId = 0; - return Gna2StatusSuccess; - })); - EXPECT_CALL(mockApi, Gna2RequestWait(_, _)).Times(AtLeast(1)).WillRepeatedly(Return(Gna2StatusSuccess)); - } -} - -void GNAPropagateMatcher :: match() { - try { - // matching gna propagate forward call. - - size_t inputSize = 10; - size_t outputSize = 10; - InputsDataMap inputsInfo; - OutputsDataMap outputsInfo; - - StrictMock mockApi; - std::vector> data; - - if (_env.config[GNA_CONFIG_KEY(DEVICE_MODE)].compare(GNA_CONFIG_VALUE(SW_FP32)) != 0 && - !_env.matchThrows) { - EXPECT_CALL(mockApi, Gna2MemoryAlloc(_,_,_)) - .WillRepeatedly(Invoke([&data](uint32_t sizeRequested, uint32_t* sizeGranted, void** memoryAddress) { - data.push_back(std::vector(sizeRequested)); - *sizeGranted = sizeRequested; - *memoryAddress = data.back().data(); - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2DeviceGetVersion(_,_)) - .WillOnce(Invoke([](uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion) { - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2DeviceOpen(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2GetLibraryVersion(_,_)) - .Times(AtLeast(0)) - .WillRepeatedly(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2InstrumentationConfigCreate(_,_,_,_)).WillOnce(Return(Gna2StatusSuccess)); - - if (_env.is_setup_of_omp_theads_expected == true) { - EXPECT_CALL(mockApi, Gna2DeviceSetNumberOfThreads(_,_)).WillOnce(Return(Gna2StatusSuccess)); - } - - std::unique_ptr combined(new NNetComponentMatcher()); - - for (auto & matchWhat : _env.whatToMatch) { - switch(matchWhat.type) { - case GnaPluginTestEnvironment::matchPrecision : - combined->add(new NNetPrecisionMatcher(_env.nnet_precision, INTEL_AFFINE)); - break; - case GnaPluginTestEnvironment::matchProcType : - expect_enqueue_calls(mockApi); - break; - case GnaPluginTestEnvironment::matchPwlInserted : - combined->add(new PWLMatcher(_env.matchInserted, matchWhat.matchQuantity, _env.pwlsToMatchWith)); - break; - case GnaPluginTestEnvironment::matchConvInserted: - combined->add(new ConvoluionLayerMatcher(_env.matchInserted, matchWhat.matchQuantity)); - break; - case GnaPluginTestEnvironment::matchMaxPoolingInserted: - combined->add(new PoolingLayerMatcher(_env.matchInserted, matchWhat.matchQuantity, true)); - break; - case GnaPluginTestEnvironment::matchPwlQuantizeMetrics : - combined->add(new PWLQuantizationMetricsMatcher(_env.type, - _env.quantization_presicion_threshold, - _env.quantization_segments_threshold)); - break; - case GnaPluginTestEnvironment::matchCopyInserted : - combined->add(new CopyLayerMatcher(_env.matchInserted, matchWhat.matchQuantity)); - break; - case GnaPluginTestEnvironment::matchDiagonalInserted : - combined->add(new DiagLayerMatcher(_env.matchInserted, matchWhat.matchQuantity)); - break; - case GnaPluginTestEnvironment::saveArgs : - expect_enqueue_calls(mockApi); - break; - case GnaPluginTestEnvironment::matchInputData : - combined->add(new InputDataMatcher(_env.input_processed)); - break; - case GnaPluginTestEnvironment::fillOutputValues : - combined->add(new OutputFiller(_env.fillValue, _env.fillValue)); - break; - case GnaPluginTestEnvironment::matchAffineWeightsTranspose: - HasWeightsTranspozed(combined, _env.transposedData, _env.transposeArgs); - break; - case GnaPluginTestEnvironment::matchAffineWeights: - HasWeightsEq(combined, _env.transposedData); - break; - case GnaPluginTestEnvironment::matchAffineWeightsSize: - HasWeightsSizeEq(combined, _env.matched_weight_size); - break; - case GnaPluginTestEnvironment::saveAffineWeights: - SaveWeights(combined, _env.transposedData, _env.transposedArgsForSaving); - break; - default: - expect_enqueue_calls(mockApi); - break; - } - } - if (combined && !combined->empty()) { - expect_enqueue_calls(mockApi); - } - - EXPECT_CALL(mockApi, Gna2MemoryFree(_)).WillRepeatedly(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2DeviceClose(_)).WillOnce(Return(Gna2StatusSuccess)); - } - - GNAPlugin plugin(_env.config); - - auto loadNetworkFromIR = [&] () -> InferenceEngine::CNNNetwork { - Core core; - auto weights_fake = make_shared_blob(TensorDesc(Precision::U8, - SizeVector({std::numeric_limits::max()/2}), Layout::C)); - weights_fake->allocate(); - - auto net_original = core.ReadNetwork(_env.model, weights_fake); - size_t weightsSize = 0; - std::vector dataBlobs = { - "weights", - "biases", - "custom" - }; - - std::vector tiBodies; - - for (auto layerIt = details::CNNNetworkIterator(net_original), end = details::CNNNetworkIterator(); - layerIt != end; ++layerIt) { - auto layer = *layerIt; - if (layer->type == "TensorIterator") { - auto tiBody = NetPass::TIBodySortTopologically(std::dynamic_pointer_cast(layer)->body); - tiBodies.insert(tiBodies.end(), tiBody.begin(), tiBody.end()); - } - } - std::vector sortedLayers = details::CNNNetSortTopologically(net_original); - sortedLayers.insert(sortedLayers.end(), tiBodies.begin(), tiBodies.end()); - - for (auto &layer : sortedLayers) { - for (auto &blobName : dataBlobs) { - auto weights = layer->blobs[blobName]; - if (weights) { - weightsSize += weights->byteSize(); - } - } - } - - auto weights = make_shared_blob({ Precision::U8, {weightsSize}, Layout::C }); - - weights->allocate(); - if (!_env.weightsFillPattern.empty()) { - fillWeights(weights, _env.weightsFillPattern); - } else { - fillWeights(weights); - } - - auto net = core.ReadNetwork(_env.model, weights); - sortedLayers = details::CNNNetSortTopologically(net); - sortedLayers.insert(sortedLayers.end(), tiBodies.begin(), tiBodies.end()); - - for (auto &pattern : _env.weightsByLayerFillPattern) { - for (auto &layer : sortedLayers) { - if (layer->name == pattern.first) { - auto weightableLayer = dynamic_pointer_cast(layer); - if (!weightableLayer) { - IE_THROW() << "given layer: " << layer->name <<" doesnt have weights"; - } - fillWeights(weightableLayer->_weights, pattern.second); - break; - } - } - } - - return net; - }; - - auto loadCNNNetwork = [&] (CNNNetwork net_original) { - - auto input_dims = net_original.getInputsInfo().begin()->second->getTensorDesc().getDims(); - auto output = net_original.getOutputsInfo(); - // sometimes network might be created without outputs - ex memory output only - auto output_dims = !output.empty() ? output.begin()->second->getTensorDesc().getDims() : input_dims; - - inputSize = details::product(std::begin(input_dims), std::end(input_dims)); - outputSize = details::product(std::begin(output_dims), std::end(output_dims)); - - if (_env.cb) { - _env.cb(net_original); - } - - plugin.LoadNetwork(net_original); - - inputsInfo = net_original.getInputsInfo(); - outputsInfo = net_original.getOutputsInfo(); - }; - - auto loadNetworkFromAOT = [&] () { - std::fstream inputStream(_env.importedModelFileName, std::ios_base::in | std::ios_base::binary); - if (inputStream.fail()) { - THROW_GNA_EXCEPTION << "Cannot open file to import model: " << _env.importedModelFileName; - } - - auto sp = plugin.ImportNetwork(inputStream); - inputsInfo = plugin.GetNetworkInputs(); - outputsInfo = plugin.GetNetworkOutputs(); - }; - - std::map input; - std::map::Ptr> output; - size_t in_N = 1; - size_t out_N = in_N; - size_t in_C; - size_t out_C; - - auto loadNetwork = [&]() { - if (_env.ngraph_model) { - CNNNetwork network; - ASSERT_NO_THROW_IE_EXCEPTION(network = CNNNetwork(_env.ngraph_model)); - ASSERT_NO_FATAL_FAILURE(loadCNNNetwork(network)); -#ifdef GNA_DEBUG - // TODO: crash on activation tests so far on addOutput call - // network.serialize("CNNNetworkFromNgraphModel.xml", "CNNNetworkFromNgraphModel.bin"); -#endif - } - else if (!_env.importedModelFileName.empty()) { - ASSERT_NO_FATAL_FAILURE(loadNetworkFromAOT()); - } else { - CNNNetwork network; - ASSERT_NO_THROW_IE_EXCEPTION(network = loadNetworkFromIR()); - ASSERT_NO_FATAL_FAILURE(loadCNNNetwork(network)); - } - const int channel_idx = 1; - bool haveInputs = !_env.input_init.empty(); - for (auto && info :inputsInfo) { - decltype(_env.input_init)::iterator it; - auto & inputBlob = input[info.first]; - if (haveInputs) { - if (inputsInfo.size() != 1) { - ASSERT_NE(it = _env.input_init.find(info.first), _env.input_init.end()); - } else { - ASSERT_NE(0, _env.input_init.size()); - it = _env.input_init.begin(); - } - in_C = it->second.size(); - ASSERT_EQ(in_C, info.second->getTensorDesc().getDims()[channel_idx]); - } - - inputBlob = make_blob_with_precision({ _env.input_precision, info.second->getTensorDesc().getDims(), - info.second->getLayout() }); - inputBlob->allocate(); - if (haveInputs) { - if (_env.input_precision == Precision::FP32) { - std::copy_n(it->second.cbegin(), in_N * in_C, inputBlob->buffer().as()); - } else if (_env.input_precision == Precision::U8) { - std::copy_n(it->second.cbegin(), in_N * in_C, inputBlob->buffer().as()); - } else { - std::logic_error(std::string("Unsupported input precision: ") + _env.input_precision.name()); - } - } - } - int expectedOutputIdx = 0; - for (auto&& out : outputsInfo) { - - auto& outputBlob = output[out.first]; - auto outsize2 = details::product(out.second->getDims()); - bool matchoutput = _env.matchOutput; - // expectations not set for given output - if (expectedOutputIdx >= _env.expected_output.size()) { - matchoutput = false; - } - out_C = matchoutput ? _env.expected_output[expectedOutputIdx].size() : outsize2; - outputBlob.reset(new TBlob({ Precision::FP32, {out_N, out_C}, Layout::NC })); - outputBlob->allocate(); - expectedOutputIdx++; - } - }; - - loadNetwork(); - - if (!inputsInfo.empty()) { - BlobMap input_blob_map; - BlobMap output_blob_map; - for (auto info : inputsInfo) { - input_blob_map[info.first] = input[info.first]; - } - size_t offset = 0; - for (auto info : outputsInfo) { - size_t current_size = InferenceEngine::details::product(info.second->getTensorDesc().getDims()); - output_blob_map[info.first] = make_shared_blob( - { info.second->getPrecision(), - {1, details::product(info.second->getTensorDesc().getDims())}, NC }, - output[info.first]->data(), current_size * sizeof(float)); - offset += current_size; - } - - plugin.Infer(input_blob_map, output_blob_map); - - } else { - plugin.Infer(*input.begin()->second, *output.begin()->second); - } - - - if (_env.matchOutput) { - - int outputIdx = 0; - for (auto && output_ith : output) { - std::vector actual_output(output_ith.second->size()); - - std::copy_n(output_ith.second->cbuffer().as(), - output_ith.second->size(), - actual_output.begin()); - - for (auto ref = _env.expected_output[outputIdx].begin(); ref != _env.expected_output[outputIdx].end(); - ref++) { - auto idx = std::distance(_env.expected_output[outputIdx].begin(), ref); - ASSERT_FLOAT_EQ(*ref, actual_output[idx]) << "at " << idx << " for " << outputIdx << " output"; - } - outputIdx++; - } - } - - auto perfMap = plugin.GetPerformanceCounts(); - - if(_env.is_profiling_enabled != false) { - ASSERT_NE(perfMap.empty(),true); - } else { - ASSERT_NE(perfMap.empty(),false); - } - - if (_env.matchThrows) { - FAIL() << "Test expected exception"; - } - - } - catch(std::exception &ex) { - if (!_env.matchThrows) { - FAIL() << ex.what(); - } - } - catch(...) { - if (!_env.matchThrows) { - FAIL() << "unknown exception thrown"; - } - } - -} - -void GNAPluginCreationMatcher :: match() { - if (_env.matchThrows) { - ASSERT_ANY_THROW(GNAPlugin(_env.config)); - return; - } - GNAPlugin(_env.config); -} - - -void GNAPluginAOTMatcher :: match() { - // matching gna_propagate forward call. - MockICNNNetwork net; - - size_t weightsSize = 656384; - auto weights = make_shared_blob({ Precision::U8, {weightsSize}, Layout::C }); - weights->allocate(); - fillWeights(weights); - - InferenceEngine::Core core; - InferenceEngine::CNNNetwork network; - ASSERT_NO_THROW_IE_EXCEPTION(network = core.ReadNetwork(_env.model, weights)); - - GNAPlugin plugin(_env.config); - - TBlob input({ Precision::FP32, {1, 10}, Layout::NC }); - input.allocate(); - - - TBlob output({ Precision::FP32, {1, 10}, Layout::NC }); - output.allocate(); - - if (_env.cb) { - _env.cb(network); - } - - GNACppApi mockApi; - std::vector> data; - EXPECT_CALL(mockApi, Gna2MemoryAlloc(_, _, _)).Times(AtLeast(1)).WillRepeatedly(Invoke([&data]( - uint32_t sizeRequested, - uint32_t *sizeGranted, - void **memoryAddress) { - data.push_back(std::vector(sizeRequested)); - *sizeGranted = sizeRequested; - *memoryAddress = data.back().data(); - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2DeviceGetVersion(_,_)).WillOnce(Invoke([]( - uint32_t deviceIndex, - enum Gna2DeviceVersion * deviceVersion) { - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2DeviceOpen(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2GetLibraryVersion(_,_)).Times(AtLeast(0)).WillRepeatedly(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2InstrumentationConfigCreate(_,_,_,_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2ModelCreate(_,_,_)).WillOnce(Invoke([]( - uint32_t deviceIndex, - struct Gna2Model const * model, - uint32_t * modelId) { - *modelId = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2RequestConfigCreate(_,_)).WillOnce(Invoke([]( - uint32_t modelId, - uint32_t * requestConfigId) { - *requestConfigId = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2InstrumentationConfigAssignToRequestConfig(_,_)).Times(AtLeast(1)).WillRepeatedly(Return(Gna2StatusSuccess)); - plugin.LoadNetwork(network); - plugin.Export(_env.exportedModelFileName); -} - - -void GNADumpXNNMatcher::load(std::shared_ptr & plugin) { - - // matching gna DumpXNN forward call. - plugin = std::make_shared(_env.config); - - auto loadNetworkFromIR = [&]() { - MockICNNNetwork net; - - size_t weightsSize = 440 * 3; - auto weights = make_shared_blob({ Precision::U8, {weightsSize}, Layout::C }); - weights->allocate(); - fillWeights(weights); - - InferenceEngine::Core core; - InferenceEngine::CNNNetwork network; - ASSERT_NO_THROW_IE_EXCEPTION(network = core.ReadNetwork(_env.model, weights)); - - if (_env.cb) { - _env.cb(network); - } - - plugin->LoadNetwork(network); - }; - - auto loadNetworkFromAOT = [&]() { - std::fstream inputStream(_env.importedModelFileName, std::ios_base::in | std::ios_base::binary); - if (inputStream.fail()) { - THROW_GNA_EXCEPTION << "Cannot open file to import model: " << _env.importedModelFileName; - } - - plugin->ImportNetwork(inputStream); - }; - - auto loadNetwork = [&]() { - if (!_env.importedModelFileName.empty()) { - loadNetworkFromAOT(); - } else { - loadNetworkFromIR(); - } - }; - - loadNetwork(); -} - -void GNADumpXNNMatcher::match() { - - GNACppApi mockApi; - std::vector data(10000); - - if (!_env.matchThrows) { - EXPECT_CALL(mockApi, Gna2MemoryAlloc(_, _, _)). - WillOnce(DoAll(SetArgPointee<1>(10000), SetArgPointee<2>(&data.front()), Return(Gna2StatusSuccess))); - - EXPECT_CALL(mockApi, Gna2DeviceGetVersion(_,_)).WillOnce(Invoke([]( - uint32_t deviceIndex, - enum Gna2DeviceVersion * deviceVersion) { - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2DeviceOpen(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2GetLibraryVersion(_,_)).Times(AtLeast(0)).WillRepeatedly(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2InstrumentationConfigCreate(_,_,_,_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2ModelCreate(_,_,_)).Times(AtLeast(1)).WillRepeatedly(Invoke([]( - uint32_t deviceIndex, - struct Gna2Model const * model, - uint32_t * modelId) { - *modelId = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2MemoryFree(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2DeviceClose(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2ModelExportConfigCreate(_,_)).WillOnce(DoAll(SetArgPointee<1>(0), Return(Gna2StatusSuccess))); - - EXPECT_CALL(mockApi, Gna2ModelExportConfigSetSource(_,_,_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2ModelExportConfigSetTarget(_,_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2ModelExport(_,_,_,_)).Times(AtLeast(1)).WillRepeatedly(Invoke([] ( - uint32_t exportConfigId, - enum Gna2ModelExportComponent componentType, - void ** exportBuffer, - uint32_t * exportBufferSize) { - *exportBufferSize = 64; - *exportBuffer = gnaUserAllocator(sizeof(Gna2ModelSueCreekHeader)); - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2ModelExportConfigRelease(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2ModelRelease(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2RequestConfigCreate(_,_)).WillOnce(Invoke([]( - uint32_t modelId, - uint32_t * requestConfigId) { - *requestConfigId = 0; - return Gna2StatusSuccess; - })); - - ON_CALL(mockApi, Gna2RequestConfigSetAccelerationMode(_,_)).WillByDefault(Return(Gna2StatusSuccess)); - - ON_CALL(mockApi, Gna2InstrumentationConfigAssignToRequestConfig(_,_)).WillByDefault(Return(Gna2StatusSuccess)); - } - - try { - // matching gna DumpXNN forward call. - auto plugin = std::make_shared(); - load(plugin); - } - catch(std::exception &ex) { - if (!_env.matchThrows) { - FAIL() << ex.what(); - } - } - catch(...) { - if (!_env.matchThrows) { - FAIL() << "unknown exception thrown"; - } - } - -} - -void GNAQueryStateMatcher :: match() { - // TODO : avoid copy pastes - GNACppApi mockApi; - std::vector data(10000); - - std::shared_ptr executer; - auto loadNetworkFromIR = [&]() { - MockICNNNetwork net; - - size_t weightsSize = 440 * 3; - auto weights = make_shared_blob({ Precision::U8, {weightsSize}, Layout::C }); - weights->allocate(); - fillWeights(weights); - - InferenceEngine::Core core; - InferenceEngine::CNNNetwork network; - ASSERT_NO_THROW_IE_EXCEPTION(network = core.ReadNetwork(_env.model, weights)); - - if (_env.cb) { - _env.cb(network); - } - - executer.reset(new GNAExecutableNetwork(network, _env.config)); - }; - - auto loadNetworkFromAOT = [&]() { - executer.reset(new GNAExecutableNetwork(_env.importedModelFileName, _env.config)); - }; - - auto loadNetwork = [&]() { - if (!_env.importedModelFileName.empty()) { - return loadNetworkFromAOT(); - } else { - return loadNetworkFromIR(); - } - }; - - EXPECT_CALL(mockApi, Gna2MemoryAlloc(_, _, _)).Times(AtLeast(1)) - .WillRepeatedly(DoAll(SetArgPointee<1>(10000), SetArgPointee<2>(&data.front()), Return(Gna2StatusSuccess))); - - EXPECT_CALL(mockApi, Gna2DeviceGetVersion(_,_)).WillOnce(Invoke([]( - uint32_t deviceIndex, - enum Gna2DeviceVersion * deviceVersion) { - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2DeviceOpen(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2GetLibraryVersion(_,_)).Times(AtLeast(0)).WillRepeatedly(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2InstrumentationConfigCreate(_,_,_,_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2MemoryFree(_)).Times(AtLeast(1)).WillRepeatedly(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2DeviceClose(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(mockApi, Gna2ModelCreate(_,_,_)).Times(AtLeast(1)).WillRepeatedly(Invoke([]( - uint32_t deviceIndex, - struct Gna2Model const * model, - uint32_t * modelId) { - *modelId = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2RequestConfigCreate(_,_)).Times(AtLeast(1)).WillRepeatedly(Invoke([]( - uint32_t modelId, - uint32_t * requestConfigId) { - *requestConfigId = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(mockApi, Gna2InstrumentationConfigAssignToRequestConfig(_,_)).Times(AtLeast(1)).WillRepeatedly(Return(Gna2StatusSuccess)); -} - - -void fillWeights(InferenceEngine::Blob::Ptr weights, std::vector pattern) { - float * p = weights->buffer().as(); - float * pEnd = p + weights->byteSize() / sizeof(float); - - for(; p!=pEnd ;) { - for (int i = 0; i != (weights->byteSize() / sizeof(float) / 3) + 1; i++) { - for (int j = 0; j != pattern.size() && p != pEnd; j++, p++) { - *p = pattern[j]; - } - } - } -} - diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_matcher.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_matcher.hpp deleted file mode 100644 index b78d3603875..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_matcher.hpp +++ /dev/null @@ -1,692 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "test_irs.hpp" - -#define withConfig(key, value) withGNAConfig(GNA_CONFIG_KEY(key), value) -#define ASSERT_NO_THROW_IE_EXCEPTION(expr) \ -do {\ -try {\ -expr;\ -}catch(std::exception & e) {\ - FAIL() << e.what();\ -}\ -catch(...) {\ - FAIL() << "unknown exception";\ -}}while(false) - -/** - * GNA unit tests environment - */ -class GnaPluginTestEnvironment { - public: - struct NnetPrecision { - InferenceEngine::Precision input_precision; - InferenceEngine::Precision output_precision; - InferenceEngine::Precision weights_precision; - InferenceEngine::Precision biases_precision; - }; - enum MatchWhat { - exactNNetStructure, - matchNone, - matchProcType, - matchPrecision, - matchPwlInserted, - matchConvInserted, - matchMaxPoolingInserted, - matchPwlQuantizeMetrics, - matchCopyInserted, - matchDiagonalInserted, - saveArgs, - matchInputData, - fillOutputValues, - matchAffineWeightsTranspose, - matchAffineWeights, - matchAffineWeightsSize, - saveAffineWeights, - }; - enum { - kUnset = -1, - kAnyNotNull= -2 - }; - struct MatcherData { - MatchWhat type = matchNone; - int matchQuantity = kUnset; - }; - std::vector whatToMatch; - - int numberOfStates = kUnset; - bool matchInserted = true; - NnetPrecision nnet_precision; - float quantization_presicion_threshold = 1.0f; - uint16_t quantization_segments_threshold = UINT16_MAX; - uint32_t type = 0; - std::string model; - std::shared_ptr ngraph_model; - std::string exportedModelFileName; - bool exportNetworkOnly = false; - std::function cb; - std::map config; - bool matchThrows = false; - uint32_t proc_type = static_cast(GNA_SOFTWARE & GNA_HARDWARE); - std::string importedModelFileName; - bool is_profiling_enabled = false; - bool matchOutput = false; - bool is_setup_of_omp_theads_expected = false; - std::vector input_processed; - InferenceEngine::Precision input_precision = InferenceEngine::Precision::FP32; - std::map> input_init; - std::vector> expected_output; - int16_t fillValue = 0; - std::vector weightsFillPattern; - std::map> weightsByLayerFillPattern; - std::pair transposeArgs; - std::pair transposedArgsForSaving; - std::vector* transposedData; - std::vector pwlsToMatchWith; - size_t matched_weight_size = 0; - size_t nCopyLayersToMatch = -1; -}; - -class GNATestBase { - public: - virtual ~GNATestBase() = default; - protected: - - #define USE_RANDOM_SEED 0 - static unsigned int const random_seed; - - template - std::vector generate_random_1d(size_t a, T min, T max) { - static std::default_random_engine generator(random_seed); - std::uniform_real_distribution distribution(min, max); - std::vector v(a); - - for (size_t i = 0; i < a; ++i) { - v[i] = (T)distribution(generator); - } - return v; - } -}; - -template -class GNATestConfigurability : public GNATestBase{ - protected: - bool needNextMatcher = true; - GnaPluginTestEnvironment _env; - GnaPluginTestEnvironment::MatcherData& getMatcher() { - if (needNextMatcher) { - needNextMatcher = false; - _env.whatToMatch.push_back({}); - } - return _env.whatToMatch.back(); - } - public: - GNATestConfigurability(GnaPluginTestEnvironment env) : _env(env) { - } - T & And() { - needNextMatcher = true; - return *dynamic_cast(this); - } - template - T & withGNAConfig(const std::string &keyName, const VType &value) { - std::stringstream ss; - ss << value; - _env.config[keyName] = ss.str(); - return *dynamic_cast(this); - } - T & onCPU() { - _env.config[GNA_CONFIG_KEY(DEVICE_MODE)] = GNA_CONFIG_VALUE(SW_FP32); - return *dynamic_cast(this); - } - T & withGNADeviceMode(std::string value) { - _env.config[GNA_CONFIG_KEY(DEVICE_MODE)] = value; - return *dynamic_cast(this); - } - T & withAcceleratorThreadsNumber(std::string value) { - _env.config[GNA_CONFIG_KEY(LIB_N_THREADS)] = value; - return *dynamic_cast(this); - } - T & throws() { - _env.matchThrows = true; - return *dynamic_cast(this); - } - T & profiling_counters() { - _env.is_profiling_enabled = true; - _env.config[CONFIG_KEY(PERF_COUNT)] = InferenceEngine::PluginConfigParams::YES; - return *dynamic_cast(this); - } -}; - -/** - * @brief matches loadnetwork + infer + call to gna_api propagate - */ -class GNAPropagateMatcher : public GNATestConfigurability { - public: - using base = GNATestConfigurability; - using base::base; - using base::getMatcher; - - ~GNAPropagateMatcher() { - match(); - } - - GNAPropagateMatcher & called() { - // inserting default matcher that matches any propagate_forward call - getMatcher(); - return *this; - } - - GNAPropagateMatcher & returns() { - return *this; - } - - GNAPropagateMatcher & that() { - return *this; - } - - GNAPropagateMatcher & result() { - return *this; - } - - GNAPropagateMatcher & called_with() { - return *this; - } - - GNAPropagateMatcher & called_without() { - _env.matchInserted = false; - return *this; - } - /** - * @brief gna_propagate_forward will fill all output pointers of 16 bits with this value - */ - GNAPropagateMatcher & filledWith(int16_t valueToFill) { - _env.fillValue = valueToFill; - getMatcher().type = GnaPluginTestEnvironment::fillOutputValues; - return *this; - } - - GNAPropagateMatcher & input(const std::string & inputName, const std::vector& inputData) { - _env.input_init[inputName] = inputData; - return *this; - } - - GNAPropagateMatcher & inputScale(const std::string & inputName, float scaleFactor) { - _env.config[std::string(GNA_CONFIG_KEY(SCALE_FACTOR)) + "_" + inputName] = std::to_string(scaleFactor); - return *this; - } - - GNAPropagateMatcher & called_with_input_and_expected_output(const std::vector& input_data, - const std::vector& expect) { - _env.matchOutput = true; - _env.input_init["any_input_name"] = input_data; - _env.expected_output .push_back(expect); - return *this; - } - - GNAPropagateMatcher & called_with_input(std::vector& input_data) { - _env.input_init["any_input_name"] = input_data; - return *this; - } - - GNAPropagateMatcher & equals_to(std::vector& expect) { - _env.matchOutput = true; - _env.expected_output.push_back(expect); - return *this; - } - - GNAPropagateMatcher & once() { - return times(1); - } - - GNAPropagateMatcher & twice() { - return times(2); - } - - GNAPropagateMatcher & times(int n) { - getMatcher().matchQuantity = n; - return *this; - } - - GNAPropagateMatcher & args(std::string args) { - return *this; - } - - GNAPropagateMatcher & exact_nnet_structure(gna_nnet_type_t * pNet) { - - getMatcher().type = GnaPluginTestEnvironment::exactNNetStructure; - original_nnet = pNet; - return *this; - } - - GNAPropagateMatcher & pwl_inserted_into_nnet() { - getMatcher().type = GnaPluginTestEnvironment::matchPwlInserted; - return *this; - } - - GNAPropagateMatcher & pwls_inserted_into_nnet(const std::vector &pwls) { - getMatcher().type = GnaPluginTestEnvironment::matchPwlInserted; - _env.pwlsToMatchWith = pwls; - return *this; - } - - GNAPropagateMatcher & max_pooling_inserted_into_nnet() { - getMatcher().type = GnaPluginTestEnvironment::matchMaxPoolingInserted; - return *this; - } - - GNAPropagateMatcher & succeed() { - return *this; - } - - GNAPropagateMatcher & convolution_inserted_into_nnet() { - getMatcher().type = GnaPluginTestEnvironment::matchConvInserted; - return *this; - } - - - GNAPropagateMatcher & pwl_quantization_activation(uint32_t activation_type) { - getMatcher().type = GnaPluginTestEnvironment::matchPwlQuantizeMetrics; - _env.type = activation_type; - return *this; - } - - GNAPropagateMatcher & pwl_quantization_precision_threshold(float threshold) { - getMatcher().type = GnaPluginTestEnvironment::matchPwlQuantizeMetrics; - _env.quantization_presicion_threshold = threshold; - return *this; - } - - GNAPropagateMatcher & pwl_quantization_segments_threshold(uint16_t threshold) { - getMatcher().type = GnaPluginTestEnvironment::matchPwlQuantizeMetrics; - _env.quantization_segments_threshold = threshold; - return *this; - } - - GNAPropagateMatcher & diagonal_inserted_into_nnet() { - getMatcher().type = GnaPluginTestEnvironment::matchDiagonalInserted; - return *this; - } - - GNAPropagateMatcher &preprocessed_input_data(std::vector input_init, std::vector input_processed, - InferenceEngine::Precision inputPrecision) { - getMatcher().type = GnaPluginTestEnvironment::matchInputData; - _env.input_processed = std::move(input_processed); - _env.input_init["placeholder"] = std::move(input_init); - _env.input_precision = inputPrecision; - return *this; - } - - GNAPropagateMatcher & copy_inserted_into_nnet() { - getMatcher().type = GnaPluginTestEnvironment::matchCopyInserted; - return *this; - } - - GNAPropagateMatcher & affine_weights_transpozed(std::pair &&transpozedArgs) { - getMatcher().type = GnaPluginTestEnvironment::saveAffineWeights; - _env.transposedArgsForSaving = std::move(transpozedArgs); - - return *this; - } - - GNAPropagateMatcher & affine_weights() { - getMatcher().type = GnaPluginTestEnvironment::saveAffineWeights; - return *this; - } - - GNAPropagateMatcher & affine_weights_eq(std::vector & sourceWeights) { - getMatcher().type = GnaPluginTestEnvironment::matchAffineWeights; - _env.transposedData = &sourceWeights; - return *this; - } - - - GNAPropagateMatcher & affine_weights_transposed(std::vector & sourceWeights, std::pair transposeData) { - getMatcher().type = GnaPluginTestEnvironment::matchAffineWeightsTranspose; - _env.transposeArgs = transposeData; - _env.transposedData = &sourceWeights; - return *this; - } - - GNAPropagateMatcher & nnet_input_precision(const InferenceEngine::Precision &precision) { - getMatcher().type = GnaPluginTestEnvironment::matchPrecision; - _env.nnet_precision.input_precision = precision; - return *this; - } - GNAPropagateMatcher & nnet_ouput_precision(const InferenceEngine::Precision &precision) { - getMatcher().type = GnaPluginTestEnvironment::matchPrecision; - _env.nnet_precision.output_precision = precision; - return *this; - } - GNAPropagateMatcher & nnet_weights_precision(const InferenceEngine::Precision &precision) { - getMatcher().type = GnaPluginTestEnvironment::matchPrecision; - _env.nnet_precision.weights_precision = precision; - return *this; - } - GNAPropagateMatcher & nnet_biases_precision(const InferenceEngine::Precision &precision) { - getMatcher().type = GnaPluginTestEnvironment::matchPrecision; - _env.nnet_precision.biases_precision = precision; - return *this; - } - - GNAPropagateMatcher & proc_type(uint32_t proc_type) { - getMatcher().type = GnaPluginTestEnvironment::matchProcType; - _env.proc_type = proc_type; - return * this; - } - - GNAPropagateMatcher & to(gna_nnet_type_t *savedNet) { - this->savedNet = savedNet; - return *this; - } - - GNAPropagateMatcher & to(std::vector & sourceWeights) { - _env.transposedData = &sourceWeights; - return *this; - } - - protected: - void match(); - gna_nnet_type_t * original_nnet = nullptr; - gna_nnet_type_t * savedNet = nullptr; -}; - - -/** - * @brief GNAPlugin matches creation only case - */ -class GNAPluginCreationMatcher : public GNATestConfigurability { - public: - using base = GNATestConfigurability; - using base::base; - - GNAPluginCreationMatcher & gna_plugin() { - return * this; - } - ~GNAPluginCreationMatcher () { - match(); - } - protected: - void match(); -}; - -/** - * @brief GNAPlugin matches creation only case - */ -class GNAPluginAOTMatcher : public GNATestConfigurability { - public: - using base = GNATestConfigurability; - using base::base; - - ~GNAPluginAOTMatcher() { - match(); - } - protected: - void match(); -}; - -/** - * @brief xnn api tests - */ -class GNADumpXNNMatcher : public GNATestConfigurability { - public: - using base = GNATestConfigurability; - using base::base; - - ~GNADumpXNNMatcher() { - if (match_in_dctor) { - match(); - } - } - GNADumpXNNMatcher& called() { - return *this; - } - protected: - - bool match_in_dctor = true; - void load(std::shared_ptr & plugin); - void match(); -}; - -/** - * @brief xnn api tests - */ -class GNAQueryStateMatcher : public GNADumpXNNMatcher { - public: - using base = GNADumpXNNMatcher; - using base::base; - - ~GNAQueryStateMatcher() { - if (match_in_dctor) { - match(); - match_in_dctor = false; - } - } - void isEmpty() { - _env.numberOfStates = 0; - } - void isNotEmpty() { - _env.numberOfStates = GnaPluginTestEnvironment::kAnyNotNull; - } - - protected: - void match(); -}; - -/** - * @brief weights matcher has specific weights matching methods - */ -class GNAWeightsMatcher : public GNAPropagateMatcher { - public: - using base = GNAPropagateMatcher; - using base::base; - - GNAWeightsMatcher & size() { - getMatcher().type = GnaPluginTestEnvironment::matchAffineWeightsSize; - return *this; - } - GNAWeightsMatcher & equals_to(size_t weights_size) { - if (getMatcher().type == GnaPluginTestEnvironment::matchAffineWeightsSize) { - _env.matched_weight_size = weights_size; - } - return *this; - } -}; - - - -/** - * @brief base for test fixture - */ -template -class GNATest : public U, public GNATestConfigurability> { - using base = GNATestConfigurability>; - using base::_env; - class XStorage { - public: - std::vector data; - std::function destroyer; - ~XStorage() { - destroyer(&data.front()); - } - }; - std::list dataUsedInMatchers; - std::list> returnedMatchers; - - public: - template - T & storage () { - dataUsedInMatchers.push_back({std::vector(sizeof(T)), [](void * toDestroy) { - reinterpret_cast(toDestroy)->~T(); - }}); - - auto ptr = reinterpret_cast (&dataUsedInMatchers.back().data.front()); - // sad to say we are not using destructors here so data might leak - new(ptr) T; - - return *ptr; - } - GNATest() : base(GnaPluginTestEnvironment()) {} - GNATest & as() { - return *this; - } - GNATest & model() { - return *this; - } - GNATest & assert_that() { - return *this; - } - GNATest & export_network(std::string modelName) { - _env.model = modelName; - _env.exportNetworkOnly = true; - return *this; - } - GNATest & save_args() { - base::getMatcher().type = GnaPluginTestEnvironment::saveArgs; - return *this; - } - GNATest & save() { - return *this; - } - - GNATest & onInfer1AFModel() { - _env.model = GNATestIRs::Fc2DOutputModel(); - return *this; - } - GNATest & onLoad(std::string _model) { - _env.model = _model; - return *this; - } - GNATest & afterLoadingModel(std::string _model) { - _env.model = _model; - return *this; - } - GNATest & afterLoadingModel(std::shared_ptr ngraph_model) { - _env.ngraph_model = ngraph_model; - return *this; - } - - GNAWeightsMatcher & affine_weights() { - returnedMatchers.push_back(std::make_shared(_env)); - _env = GnaPluginTestEnvironment(); - return dynamic_cast(*returnedMatchers.back()); - } - - GNAQueryStateMatcher & queryState() { - returnedMatchers.push_back(std::make_shared(_env)); - // clearing env; - _env = GnaPluginTestEnvironment(); - return dynamic_cast(*returnedMatchers.back()); - } - - /**importing indicates no infer happened ata all **/ - GNAPropagateMatcher & importingModelFrom(std::string fileName) { - _env.importedModelFileName = fileName; - returnedMatchers.push_back(std::make_shared(_env)); - // clearing env; - _env = GnaPluginTestEnvironment(); - return dynamic_cast(*returnedMatchers.back()); - } - - GNATest & importedFrom(std::string fileName) { - _env.importedModelFileName = fileName; - return *this; - } - - GNATest & onInferModel(std::string _model = "", - std::function _cb = [](InferenceEngine::CNNNetwork & net){}) { - _env.model = _model; - _env.cb = _cb; - return *this; - } - - GNATest & onInferNgraphModel(std::shared_ptr ngraph_model) { - _env.ngraph_model = ngraph_model; - return *this; - } - - GNATest & withWeigthsPattern(std::string layerName, std::vector && initializer) { - _env.weightsByLayerFillPattern[layerName] = std::move(initializer); - return *this; - } - - GNATest & withWeigthsPattern(std::vector && initializer) { - _env.weightsFillPattern = std::move(initializer); - return *this; - } - GNATest & gna() { - _env.config[GNA_CONFIG_KEY(DEVICE_MODE)] = GNA_CONFIG_VALUE(AUTO); - return *this; - } - GNATest & from() { - return *this; - } - GNATest & inNotCompactMode() { - _env.config[GNA_CONFIG_KEY(COMPACT_MODE)] = CONFIG_VALUE(NO); - return *this; - } - GNATest & withUniformPWLAlgo() { - base::_env.config[GNA_CONFIG_KEY(PWL_UNIFORM_DESIGN)] = CONFIG_VALUE(YES); - return *this; - } - GNAPropagateMatcher& propagate_forward() { - returnedMatchers.push_back(std::make_shared(_env)); - //clearing env; - _env = GnaPluginTestEnvironment(); - return dynamic_cast(*returnedMatchers.back()); - } - GNADumpXNNMatcher& dumpXNN() { - returnedMatchers.push_back(std::make_shared(_env)); - //clearing env; - _env = GnaPluginTestEnvironment(); - return dynamic_cast(*returnedMatchers.back()); - } - GNATest & withNanScaleFactor() { - base::_env.config[GNA_CONFIG_KEY(SCALE_FACTOR)] = std::to_string(std::numeric_limits::quiet_NaN()); - return *this; - } - GNATest & withInfScaleFactor() { - base::_env.config[GNA_CONFIG_KEY(SCALE_FACTOR)] = std::to_string(std::numeric_limits::infinity()); - return *this; - } - GNAPluginCreationMatcher creating() { - return _env; - } - - GNAPluginAOTMatcher & to (std::string fileName) { - _env.exportedModelFileName = fileName; - returnedMatchers.push_back(std::make_shared(_env)); - //clearing env; - _env = GnaPluginTestEnvironment(); - return dynamic_cast(*returnedMatchers.back()); - } -}; - -void fillWeights(InferenceEngine::Blob::Ptr weights, std::vector pattern = {1.f}); diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_mock_api.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_mock_api.hpp deleted file mode 100644 index 95566ea79ca..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_mock_api.hpp +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include -#include -#include -#include - -#if defined(_WIN32) || defined(__CYGWIN__) - #ifdef libGNAStubs_EXPORTS - #define GNA_STUBS_EXPORT __declspec(dllexport) - #else - #define GNA_STUBS_EXPORT __declspec(dllimport) - #endif -#else - #define GNA_STUBS_EXPORT -#endif - -class GNACppApi { - - public: - GNA_STUBS_EXPORT GNACppApi(); - GNA_STUBS_EXPORT ~GNACppApi(); - MOCK_METHOD3(Gna2MemoryAlloc, Gna2Status ( - uint32_t sizeRequested, - uint32_t * sizeGranted, - void ** memoryAddress)); - - MOCK_METHOD1(Gna2DeviceOpen, Gna2Status ( - uint32_t deviceIndex)); - - MOCK_METHOD2(Gna2DeviceSetNumberOfThreads, Gna2Status( - uint32_t deviceIndex, - uint32_t numberOfThreads)); - - MOCK_METHOD1(Gna2DeviceClose, Gna2Status ( - uint32_t deviceIndex)); - - MOCK_METHOD1(Gna2DeviceGetCount, Gna2Status ( - uint32_t * numberOfDevices)); - - MOCK_METHOD1(Gna2MemoryFree, Gna2Status ( - void * memory)); - - MOCK_METHOD3(Gna2StatusGetMessage, Gna2Status ( - enum Gna2Status status, - char * messageBuffer, - uint32_t messageBufferSize)); - - MOCK_METHOD3(Gna2ModelCreate, Gna2Status ( - uint32_t deviceIndex, - struct Gna2Model const * model, - uint32_t * modelId)); - - MOCK_METHOD1(Gna2ModelRelease, Gna2Status ( - uint32_t modelId)); - - MOCK_METHOD1(Gna2ModelGetLastError, Gna2Status ( - struct Gna2ModelError* error)); - - MOCK_METHOD2(Gna2RequestConfigCreate, Gna2Status ( - uint32_t modelId, - uint32_t * requestConfigId)); - - MOCK_METHOD4(Gna2RequestConfigEnableActiveList, Gna2Status ( - uint32_t requestConfigId, - uint32_t operationIndex, - uint32_t numberOfIndices, - uint32_t const * indices)); - - MOCK_METHOD2(Gna2RequestConfigEnableHardwareConsistency, Gna2Status ( - uint32_t requestConfigId, - enum Gna2DeviceVersion deviceVersion)); - - MOCK_METHOD2(Gna2RequestConfigSetAccelerationMode, Gna2Status ( - uint32_t requestConfigId, - enum Gna2AccelerationMode accelerationMode)); - - MOCK_METHOD2(Gna2RequestEnqueue, Gna2Status ( - uint32_t requestConfigId, - uint32_t * requestId)); - - MOCK_METHOD2(Gna2RequestWait, Gna2Status ( - uint32_t requestId, - uint32_t timeoutMilliseconds)); - - MOCK_METHOD2(Gna2ModelExportConfigCreate, Gna2Status ( - Gna2UserAllocator userAllocator, - uint32_t * exportConfigId)); - - MOCK_METHOD1(Gna2ModelExportConfigRelease, Gna2Status ( - uint32_t exportConfigId)); - - MOCK_METHOD3(Gna2ModelExportConfigSetSource, Gna2Status ( - uint32_t exportConfigId, - uint32_t sourceDeviceIndex, - uint32_t sourceModelId)); - - MOCK_METHOD2(Gna2ModelExportConfigSetTarget, Gna2Status ( - uint32_t exportConfigId, - enum Gna2DeviceVersion targetDeviceVersion)); - - MOCK_METHOD4(Gna2ModelExport, Gna2Status ( - uint32_t exportConfigId, - enum Gna2ModelExportComponent componentType, - void ** exportBuffer, - uint32_t * exportBufferSize)); - - MOCK_METHOD2(Gna2DeviceGetVersion, Gna2Status ( - uint32_t deviceIndex, - enum Gna2DeviceVersion * deviceVersion)); - - MOCK_METHOD4(Gna2InstrumentationConfigCreate, Gna2Status ( - uint32_t numberOfInstrumentationPoints, - enum Gna2InstrumentationPoint* selectedInstrumentationPoints, - uint64_t * results, - uint32_t * instrumentationConfigId)); - - MOCK_METHOD2(Gna2InstrumentationConfigAssignToRequestConfig, Gna2Status ( - uint32_t instrumentationConfigId, - uint32_t requestConfigId)); - - MOCK_METHOD2(Gna2GetLibraryVersion, Gna2Status( - char* versionBuffer, - uint32_t versionBufferSize)); -}; diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_proc_type_test.cpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_proc_type_test.cpp deleted file mode 100644 index b3010b9cf05..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/gna_proc_type_test.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include "gna_plugin.hpp" -#include "gna_mock_api.hpp" -#include "gna_matcher.hpp" - -#include "unit_test_utils/mocks/mock_icnn_network.hpp" - -using namespace std; -using namespace InferenceEngine; -using namespace ::testing; - -class GNAProcTypeTest : public GNATest<> { - - protected: -}; - -TEST_F(GNAProcTypeTest, defaultProcTypeIsSWEXACT) { - assert_that().onInfer1AFModel().withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna().propagate_forward().called_with().proc_type(GNA_SOFTWARE & GNA_HARDWARE); -} - -TEST_F(GNAProcTypeTest, canPassHWProcTypeToGNA) { - assert_that().withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .onInfer1AFModel().withGNADeviceMode("GNA_HW").gna().propagate_forward().called_with().proc_type(GNA_HARDWARE); -} - -TEST_F(GNAProcTypeTest, canPassSWEXACTProcTypeToGNA) { - assert_that().onInfer1AFModel().withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .withGNADeviceMode("GNA_SW_EXACT").gna(). - propagate_forward().called_with().proc_type(GNA_SOFTWARE & GNA_HARDWARE); -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/graph_tools/graph_copy_tests.cpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/graph_tools/graph_copy_tests.cpp deleted file mode 100644 index 0da43c865db..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/graph_tools/graph_copy_tests.cpp +++ /dev/null @@ -1,322 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include -#include "ie_common.h" -#include -#include "graph_test_base.hpp" -#include -#include - -using namespace testing; -using namespace InferenceEngine; -using namespace std; -using namespace GraphTest; -using namespace ov::intel_gna::frontend; - -class GraphCopyTests : public GraphTestsBase { - -protected: - MockCopier mc; - InferenceEngine::CNNNetwork quantize(const InferenceEngine::CNNNetwork& model, - std::vector scale_factors) const { - GnaInputs inputs; - InferenceEngine::InputsDataMap inputs_map = model.getInputsInfo(); - size_t sf_id = 0; - for (auto&& input_data : inputs_map) { - auto input_layer = getCreatorLayer(input_data.second->getInputData()).lock(); - if (scale_factors.size() <= sf_id) { - THROW_GNA_EXCEPTION << "Scale factors are not set for some of the inputs"; - } - inputs[input_layer->name].scale_factor = scale_factors[sf_id++]; - } - - Config gna_config; - gna_config.gnaPrecision = InferenceEngine::Precision::I16; - gna_config.gnaFlags.input_low_precision = false; - - auto transformer = ov::intel_gna::TransformationsPipeline(gna_config); - - return ModelQuantizer(transformer) - .quantize( - model, - inputs); - } - - void SetUp() override { - GraphTestsBase::_batchSize = 12; - GraphTestsBase::SetUp(); - CONNECT(1, 2); - CONNECT(3, 4); - CONNECT(4, 2); - CONNECT(3, 5); - CONNECT(5, 2); - - EXPECT_CALL(*mockNet, getInputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](InputsDataMap &maps) { - prepareInputs(maps, 12); - }))); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap &maps) { - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getBatchSize()).WillRepeatedly(Return(12)); - EXPECT_CALL(*mockNet, getName()).WillRepeatedly(ReturnRefOfCopy(std::string("nm"))); - - EXPECT_CALL(mc, copyLayer(_)).WillRepeatedly(Invoke([](CNNLayerPtr ptr) { - return ptr; - })); - } -}; - -TEST_F(GraphCopyTests, canPreserveBatchWhenCopyNetwork) { - auto clone = CNNNetCopy(CNNNetwork(mockNet), mc); - auto icnnnet = static_cast(clone); - - //network was copied not just assigned - ASSERT_NE(icnnnet.get(), mockNet.get()); - - ASSERT_EQ(clone.getBatchSize(), 12); -} - - -TEST_F(GraphCopyTests, canPreserveInputs) { - auto clone = CNNNetCopy(CNNNetwork(mockNet), mc); - - InputsDataMap inputs = clone.getInputsInfo(), inputsTarget; - InputsDataMap heads, headsTarget; - - mockNet->getInputsInfo(inputsTarget); - ASSERT_INPUTS_INFO_EQ(inputs, inputsTarget); -} - -TEST_F(GraphCopyTests, canPreserveOutputs) { - auto clone = CNNNetCopy(CNNNetwork(mockNet), mc); - - OutputsDataMap outTarget = clone.getOutputsInfo(), outSource; - mockNet->getOutputsInfo(outSource); - - ASSERT_OUTPUTS_INFO_EQ(outSource, outTarget); -} - -TEST_F(GraphCopyTests, canPreserveAttributes) { - auto clone = CNNNetCopy(CNNNetwork(mockNet), mc); - ADD_ATTR(1, "id", "r-1-2-3"); - ADD_ATTR(2, "id", "r-1-2-3"); - auto idMemOutput = CommonTestUtils::getLayerByName(clone, "1")->GetParamAsString("id"); - auto idMemInput = CommonTestUtils::getLayerByName(clone, "2")->GetParamAsString("id"); - - ASSERT_STREQ(idMemInput.c_str(), idMemOutput.c_str()); - ASSERT_STREQ(idMemInput.c_str(), "r-1-2-3"); -} - -TEST_F(GraphCopyTests, canQuantizeTopology) { - auto clone = quantize(CNNNetwork(mockNet), std::vector({1.0f, 1.0f})); - - CNNNetBFS(CommonTestUtils::getLayerByName(clone, "1"), [&](CNNLayerPtr layer) { - auto params = getInjectedData(layer); - ASSERT_NE(params, nullptr); - }); - - CNNNetBFS(CommonTestUtils::getLayerByName(clone, "3"), [&](CNNLayerPtr layer) { - auto params = getInjectedData(layer); - ASSERT_NE(params, nullptr); - }); -} - -TEST(CNNSpecificGraphCopyTests, copyNetworkWithClampLayer) { - //define minimal network with Clamp layer - const std::string SINGLE_LAYER_MODEL = R"V0G0N( - - - - - - 1 - 3 - 224 - 224 - - - - - - - - 1 - 3 - 224 - 224 - - - - - 1 - 3 - 224 - 224 - - - - - - - - - )V0G0N"; - - InferenceEngine::Core core; - InferenceEngine::CNNNetwork network; - ASSERT_NO_THROW(network = core.ReadNetwork(SINGLE_LAYER_MODEL, InferenceEngine::Blob::CPtr())); - - //copy the network - struct EmptyStruct {}; - auto visitor = [&](CNNLayerPtr lp) { return injectData(lp); }; - auto copied_net_ptr = CNNNetCopy(network, visitor); - auto copied_net = CNNNetwork(copied_net_ptr); - - //check that Clamp layer was properly copied - auto layer = std::dynamic_pointer_cast(CommonTestUtils::getLayerByName(copied_net, "ClampLayer")); - ASSERT_NE(layer, nullptr) << "Could not perform dynamic cast from base pointer to Clamp layer pointer. " - "Net copy could be incorrect."; -} - -TEST(CNNSpecificGraphCopyTests, copyPreprocess) { - //define minimal network with Clamp layer - const std::string SINGLE_LAYER_MODEL = R"V0G0N( - - - - - - 1 - 3 - 224 - 224 - - - - - - - - 1 - 3 - 224 - 224 - - - - - 1 - 3 - 224 - 224 - - - - - - - - - - - - - - - - - - - - )V0G0N"; - - InferenceEngine::Core core; - InferenceEngine::CNNNetwork network; - - ASSERT_NO_THROW(network = core.ReadNetwork(SINGLE_LAYER_MODEL, InferenceEngine::Blob::CPtr())); - - //copy the network - struct EmptyStruct {}; - auto visitor = [&](CNNLayerPtr lp) { return injectData(lp); }; - auto copied_net_ptr = CNNNetCopy(network, visitor); - auto copied_net = CNNNetwork(copied_net_ptr); - - //check that pre process Info existed in copied network - auto &pp = copied_net.getInputsInfo().begin()->second->getPreProcess(); - ASSERT_EQ(MEAN_VALUE, pp.getMeanVariant()); - ASSERT_EQ(3, pp.getNumberOfChannels()); - - - ASSERT_FLOAT_EQ(pp[0]->meanValue, 104); - ASSERT_FLOAT_EQ(pp[1]->meanValue, 116); - ASSERT_FLOAT_EQ(pp[2]->meanValue, 122); -} - -TEST(CNNSpecificGraphCopyTests, copyNetworkWithDeconvolution) { - //define minimal network with deconvolution layer - const std::string SINGLE_LAYER_MODEL = R"V0G0N( - - - - - - 1 - 384 - 4 - 2 - - - - - - - - 1 - 384 - 4 - 2 - - - - - 1 - 384 - 8 - 4 - - - - - - - - - - )V0G0N"; - - InferenceEngine::Core core; - InferenceEngine::CNNNetwork network; - auto blob = make_shared_blob(TensorDesc(Precision::U8, {12288}, Layout::C)); - blob->allocate(); - ASSERT_NO_THROW(network = core.ReadNetwork(SINGLE_LAYER_MODEL, blob)); - - // copy the network - struct EmptyStruct {}; - auto visitor = [&](CNNLayerPtr lp) { return injectData(lp); }; - auto copied_net_ptr = CNNNetCopy(network, visitor); - auto copied_net = CNNNetwork(copied_net_ptr); - - // check that Clamp layer was properly copied - auto layer = std::dynamic_pointer_cast(CommonTestUtils::getLayerByName(copied_net, "upsample_merged")); - ASSERT_NE(layer, nullptr) << "Could not perform dynamic cast from base pointer to Deconvolution layer pointer. " - "Net copy could be incorrect."; -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/graph_tools/graph_test_base.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/graph_tools/graph_test_base.hpp deleted file mode 100644 index f49aa4c50d8..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/graph_tools/graph_test_base.hpp +++ /dev/null @@ -1,321 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include "cpp/ie_cnn_network.h" -#include - -#include "unit_test_utils/mocks/mock_icnn_network.hpp" -#include "common_test_utils/common_utils.hpp" -#include "cnnlayer_utils.hpp" - -namespace GraphTest { - -using namespace InferenceEngine; -using namespace std; - -/** - * @class all layers are input without connection. - * Input layers are defined by absence of ins data. - */ -class GraphTestsBase : public ::testing::Test { -protected: - MOCK_METHOD2(visited, void(size_t, int)); - MOCK_METHOD2(visited2, void(size_t, int)); - - std::vector layers; - std::vector> datas; - - std::shared_ptr mockNet; - InferenceEngine::CNNNetwork wrap; - - /** - * layers that are used as lhs in oriented connect operations - */ - std::unordered_set lhsLayers; - std::unordered_set rhsLayers; - - virtual void prepareInputs(InputsDataMap &inputsMap, int batchSize = 1) { - auto prepareInputsInternal = [&inputsMap, &batchSize](std::unordered_set & layersSet) { - for (auto layer = layersSet.begin(); layer != layersSet.end(); layer++) { - if ((*layer)->insData.empty()) { - auto info = make_shared(); - auto data = make_shared((*layer)->name, Precision::FP32, Layout::NC); - SizeVector dims = data->getDims(); - dims.push_back(batchSize); - dims.push_back(batchSize); - data->setDims(dims); - for (auto output : (*layer)->outData) { - getInputTo(data) = getInputTo(output); - } - getCreatorLayer(data) = (*layer); - info->setInputData(data); - inputsMap[(*layer)->name] = info; - } - } - }; - prepareInputsInternal(lhsLayers); - prepareInputsInternal(rhsLayers); - } - - CNNLayerPtr layerByName(std::string name) { - auto sorted = InferenceEngine::details::CNNNetSortTopologically( - InferenceEngine::CNNNetwork(mockNet)); - - auto i = std::find_if(sorted.begin(), sorted.end(), [&](CNNLayerPtr l){ - return l->name == name; - }); - if (i != sorted.end()) { - return *i; - } - return nullptr; - } - - - #define ASSERT_N_CONNECTIONS(a, b, n) \ - ASSERT_EQ(countForwardConnections(#a, #b), n);\ - ASSERT_EQ(countBackwardConnections(#a, #b), n) - - #define ASSERT_MN_CONNECTIONS(a, b, m, n) \ - ASSERT_EQ(countForwardConnections(#a, #b), m);\ - ASSERT_EQ(countBackwardConnections(#a, #b), n) - - #define ASSERT_CONNECTION(a, b) \ - ASSERT_N_CONNECTIONS(a,b,1) - - #define ASSERT_PORT_CONNECTION(a, from_port, b, to_port) \ - ASSERT_EQ(countForwardConnections(#a, #b, from_port), 1);\ - ASSERT_EQ(countBackwardConnections(#a, #b, to_port), 1) - - #define ASSERT_2_CONNECTIONS(a, b) \ - ASSERT_N_CONNECTIONS(a,b,2) - - #define ASSERT_3_CONNECTIONS(a, b) \ - ASSERT_N_CONNECTIONS(a,b,3) - - /** - * @brief check connection without direction - */ - #define ASSERT_NO_CONNECTION(a, b) \ - ASSERT_EQ(countConnections(#a, #b), 0);\ - ASSERT_EQ(countConnections(#b, #a), 0) - - void ASSERT_DIMS(int x, const SizeVector & dims) { - - ASSERT_EQ(datas[x].front()->getDims().size(), dims.size()); - for(size_t i = 0; i != dims.size(); i++) { - ASSERT_EQ(datas[x].front()->getDims()[i], dims[i]); - } - } - - int countForwardConnections(std::string a, std::string b, int from_port_id=-1) { - long int nForward = 0; - CNNLayerPtr layerExist; - try { - layerExist = CommonTestUtils::getLayerByName(wrap, a.c_str()); - if (!layerExist) { - return 0; - } - } catch(...) { - return 0; - } - - for (auto && outData : layerExist->outData) { - if (from_port_id != -1) { - if (from_port_id > 0) { - from_port_id--; - continue; - } - } - auto &inputMap = getInputTo(outData); - nForward += - std::count_if(inputMap.begin(), inputMap.end(), [&](std::map::value_type &vt) { - return vt.second->name == b; - }); - } - - return nForward; - } - - int countBackwardConnections(std::string a, std::string b, int from_port_id=-1) { - CNNLayerPtr layerExist; - try { - layerExist = CommonTestUtils::getLayerByName(wrap, b.c_str()); - if (!layerExist) { - return 0; - } - } catch(...) { - return 0; - } - - auto countRef = [&](DataWeakPtr wp) { - return getCreatorLayer(wp.lock()).lock()->name == a; - }; - - if (from_port_id == -1) { - auto prevData = layerExist->insData; - - return std::count_if(prevData.begin(), prevData.end(), countRef); - } else { - return countRef(layerExist->insData[from_port_id]); - } - } - - int countConnections(std::string a, std::string b) { - return countForwardConnections(a, b) + countBackwardConnections(a, b); - } - - int numCreated = 0; - CNNLayerPtr createGenericLayer (std::string name) { - auto newData = std::make_shared(name, TensorDesc(Precision::FP32, SizeVector({ 1, 1 }), Layout::NC)); - - CNNLayerPtr newLayer = make_shared(LayerParams({name, "Generic_" + std::to_string(numCreated++), Precision::FP32})); - getCreatorLayer(newData) = newLayer; - newLayer->outData.push_back(newData); - - return newLayer; - } - - void prepareSomeInputs(InputsDataMap &inputsMap, std::initializer_list inputLayers, int batchSize = 1) { - for (auto layer = lhsLayers.begin(); layer != lhsLayers.end(); layer++) { - if ((*layer)->insData.empty()) { - auto isMarked = std::find_if(begin(inputLayers), end(inputLayers), [&](int value) { - return std::to_string(value) ==(*layer)->name; - }); - if (isMarked == end(inputLayers)) - continue; - auto info = make_shared(); - auto data = make_shared((*layer)->name, TensorDesc(Precision::FP32, Layout::NC)); - SizeVector dims = data->getDims(); - dims.push_back(batchSize); - dims.push_back(batchSize); - data->setDims(dims); - for (auto output : (*layer)->outData) { - getInputTo(data) = getInputTo(output); - } - info->setInputData(data); - inputsMap[(*layer)->name] = info; - } - } - } - - /** - * @brief output layers considered only leafs here - * @param outputMap - */ - void prepareOutputs(OutputsDataMap & outputMap) { - for (auto layer = rhsLayers.begin(); layer != rhsLayers.end(); layer++) { - bool notLast = false; - for (auto && outData : (*layer)->outData) { - if (!getInputTo(outData).empty()) { - notLast = true; - break; - } - } - if (notLast) continue; - for (auto && outData : (*layer)->outData) { - outputMap[outData->getName()] = outData; - } - } - } - /** - * @brief creates 10 independent layers without connections. - * Data corresponding to each layer sets up in outData - * Likewise creator layer sets up for data in getCreatorLayer - */ - int _batchSize = 1; - void SetUp() override { - mockNet = std::make_shared(); - wrap = InferenceEngine::CNNNetwork(std::dynamic_pointer_cast(mockNet)); - - datas.resize(10); - for (int i = 0; i < 10; i++) { - layers.push_back(make_shared(LayerParams({std::to_string(i)}, "", Precision::UNSPECIFIED))); - datas[i].push_back(make_shared(std::to_string(i), Precision::FP32, Layout::NC)); - getCreatorLayer(datas[i].back()) = layers[i]; - - SizeVector dims = datas[i].back()->getDims(); - dims.push_back(_batchSize); - dims.push_back(_batchSize); - datas[i].back()->setDims(dims); - - layers.back()->outData.push_back(datas[i].back()); - } - } - - void TearDown() override { - // Reset shared_pointer circular dependencies to mitigate memory leaks. - for (auto& items : datas) { - for (auto& data : items) { - for (auto& input : getInputTo(data)) { - input.second.reset(); - } - } - } - } - - int ID(const CNNLayerPtr &ptr) { - for (int i = 0; i < layers.size(); i++) { - if (layers[i].get() == ptr.get()) - return i; - } - return -1; - } - - void ADD_ATTR(int layer, std::string attr, std::string value) { - layers[layer]->params[attr] = value; - } - /** - * @brief add edges between layers x and y, creating connected graph - * @param x output layer index - * @param y input layer index - */ - void CONNECT(int x, int y) { - getInputTo(datas[x].front())[std::to_string(y)] = layers[y]; - layers[y]->insData.push_back(datas[x].front()); - lhsLayers.insert(layers[x]); - rhsLayers.insert(layers[y]); - } - - void CONNECT_FROM_PORT(int x, int port, int y) { - if (datas[x].size() <= port) { - datas[x].push_back(make_shared(std::string("split_") + std::to_string(datas[x].size()), Precision::FP32, Layout::NC)); - getCreatorLayer(datas[x].back()) = layers[x]; - - SizeVector dims = datas[x].back()->getDims(); - dims.push_back(_batchSize); - dims.push_back(_batchSize); - datas[x].back()->setDims(dims); - layers[x]->outData.push_back(datas[x].back()); - } - getInputTo(datas[x][port])[std::to_string(y)] = layers[y]; - layers[y]->insData.push_back(datas[x][port]); - lhsLayers.insert(layers[x]); - rhsLayers.insert(layers[y]); - } - - void SET_DIMS(int x, const SizeVector & dims) { - datas[x].front()->setDims(dims); - } - - void SET_TYPE(int x, std::string name) { - layers[x]->type = name; - } -}; - -class MockCopier { - public: - CNNLayerPtr operator()(CNNLayerPtr layer) const { - return copyLayer(layer); - } - MOCK_CONST_METHOD1(copyLayer, CNNLayerPtr(CNNLayerPtr)); -}; - -} - -MATCHER_P2(IsBetween, a, b, std::string(negation ? "isn't" : "is") + " between " + ::testing::PrintToString(a) + " and " + ::testing::PrintToString(b)) { return a <= arg && arg <= b; } diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/graph_tools/graph_tools_test.cpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/graph_tools/graph_tools_test.cpp deleted file mode 100644 index 3297c0bddc2..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/graph_tools/graph_tools_test.cpp +++ /dev/null @@ -1,968 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include "graph_test_base.hpp" -#include -#include -#include -#include "ie_common.h" -#include -#include -#include -#include - -using namespace testing; -using namespace InferenceEngine; -using namespace std; -using namespace GraphTest; - -class GraphToolsTest : public GraphTestsBase { - -}; - -TEST_F(GraphToolsTest, canRunSimpleDFS) { - - CONNECT(0, 1); - CONNECT(0, 2); - CONNECT(1, 3); - CONNECT(2, 3); - - EXPECT_CALL(*this, visited(0 ,0)).Times(1); - EXPECT_CALL(*this, visited(1, IsBetween(1,3))).Times(1); - EXPECT_CALL(*this, visited(2, IsBetween(1,3))).Times(1); - EXPECT_CALL(*this, visited(3, 2)).Times(1); - - int idx = 0; - CNNNetDFS(layers[0], [&] (const CNNLayerPtr & layer) { - visited(ID(layer), idx++); - }); -} - - -TEST_F(GraphToolsTest, canRunCycleDFS) { - - CONNECT(0, 1); - CONNECT(1, 2); - CONNECT(2, 0); - - EXPECT_CALL(*this, visited(0 ,0)).Times(1); - EXPECT_CALL(*this, visited(1, 1)).Times(1); - EXPECT_CALL(*this, visited(2, 2)).Times(1); - - int idx = 0; - CNNNetDFS(layers[0], [&] (const CNNLayerPtr & layer) { - visited(ID(layer), idx++); - }); -} - - -TEST_F(GraphToolsTest, canRunBFS) { - - CONNECT(0, 1); - CONNECT(0, 2); - CONNECT(0, 3); - CONNECT(1, 4); - - EXPECT_CALL(*this, visited(0 ,0)).Times(1); - EXPECT_CALL(*this, visited(1, IsBetween(1,3))).Times(1); - EXPECT_CALL(*this, visited(2, IsBetween(1,3))).Times(1); - EXPECT_CALL(*this, visited(3, IsBetween(1,3))).Times(1); - EXPECT_CALL(*this, visited(4, 4)).Times(1); - - int idx = 0; - CNNNetBFS(layers[0], [&] (const InferenceEngine::CNNLayerPtr & layer) { - visited(ID(layer), idx++); - }); -} - -/** - * Generic BFS algorithm traverser - with limiting depth - * @param layer - starting layer - * @param visit - callback to be called upon visiting - */ -template -inline void CNNNetNBFS(const InferenceEngine::CNNLayerPtr& layer, int maxDept, const T& visit) { - if (!layer) { - return; - } - details::BFS(layer, visit, maxDept + 1); -} - -TEST_F(GraphToolsTest, canRunNBFS) { - - CONNECT(0, 1); - CONNECT(0, 2); - CONNECT(0, 3); - CONNECT(1, 4); - - EXPECT_CALL(*this, visited(0 ,0)).Times(1); - EXPECT_CALL(*this, visited(1, IsBetween(1,3))).Times(1); - EXPECT_CALL(*this, visited(2, IsBetween(1,3))).Times(1); - EXPECT_CALL(*this, visited(3, IsBetween(1,3))).Times(1); - - int idx = 0; - CNNNetNBFS(layers[0], 1, [&] (const InferenceEngine::CNNLayerPtr & layer) { - visited(ID(layer), idx++); - }); -} - -TEST_F(GraphToolsTest, canSortTopologically) { - - CONNECT(0, 1); - CONNECT(2, 1); - CONNECT(1, 4); - - EXPECT_CALL(*mockNet, getInputsInfo(_)).WillOnce(WithArg<0>(Invoke([&](InputsDataMap & maps){ - prepareInputs(maps); - }))); - auto sorted = details::CNNNetSortTopologically(CNNNetwork(mockNet)); - - EXPECT_EQ(sorted.size(), 4); - - // first element can be 0 or 2 depending on implementation - EXPECT_TRUE( - sorted[0]->name=="0" && sorted[1]->name=="2" || - sorted[0]->name=="2" && sorted[1]->name=="0"); - - EXPECT_STREQ(sorted[2]->name.c_str(), "1"); - EXPECT_STREQ(sorted[3]->name.c_str(), "4"); -} - -TEST_F(GraphToolsTest, canDetectLoopsWhileSortTing) { - - // 1->2->3-> 4->5->6->7-> 8 - // ^ |^ | ^| - // | |└--------┘ || - // | └------------┘| - // └----------------┘ - - CONNECT(1, 2); - CONNECT(2, 3); - CONNECT(3, 4); - CONNECT(4, 5); - CONNECT(5, 6); - CONNECT(6, 7); - CONNECT(7, 8); - CONNECT(7, 4); - CONNECT(4, 8); - CONNECT(8, 3); - - EXPECT_CALL(*mockNet, getInputsInfo(_)).WillOnce(WithArg<0>(Invoke([&](InputsDataMap & maps){ - prepareInputs(maps); - }))); - ASSERT_ANY_THROW(details::CNNNetSortTopologically(CNNNetwork(mockNet))); -} - - -TEST_F(GraphToolsTest, canSortIfInputsPointsToLayerWithMultiInputs) { - - CONNECT(1, 2); - CONNECT(3, 4); - CONNECT(4, 2); - CONNECT(3, 5); - CONNECT(5, 2); - - EXPECT_CALL(*mockNet, getInputsInfo(_)).WillOnce(WithArg<0>(Invoke([&](InputsDataMap & maps){ - prepareInputs(maps); - }))); - - auto sorted = details::CNNNetSortTopologically(CNNNetwork(mockNet)); - - vector> expected = { - {"1", "3", "4", "5", "2"}, - {"3", "4", "5", "1", "2"}, - {"3", "5", "4", "1", "2"}, - {"1", "3", "5", "4", "2"}, - }; - - bool bFailed = true; - for (auto ex: expected) { - bFailed = false; - for (auto i = 0; i < ex.size(); i++) { - if (sorted[i]->name != ex[i]) { - bFailed = true; - break; - } - } - if (!bFailed) break; - } - std::stringstream actual; - for (auto x : sorted) { - actual << x->name << " "; - } - - EXPECT_FALSE(bFailed) << actual.str() << "doesn't match: one of expected" ; -} - -TEST_F(GraphToolsTest, canGetAllMemoryInputsLayersFromStandardInputs) { - - - // 1->4--┐ - // | - // 2->5->6 - // | - // 3->7 - - CONNECT(1, 4); - CONNECT(2, 5); - CONNECT(3, 7); - CONNECT(4, 5); - CONNECT(5, 6); - CONNECT(5, 7); - - - EXPECT_CALL(*mockNet, getInputsInfo(_)).WillOnce(WithArg<0>(Invoke([&](InputsDataMap & maps){ - prepareSomeInputs(maps, {1}); - }))); - auto allInputLayers = CNNNetGetAllInputLayers(CNNNetwork(mockNet)); - ASSERT_EQ(3, allInputLayers.size()); - auto element = allInputLayers.begin(); - ASSERT_STREQ("1", element->get()->name.c_str()); - element++; - ASSERT_STREQ("2", element->get()->name.c_str()); - element++; - ASSERT_STREQ("3", element->get()->name.c_str()); -} - -TEST_F(GraphToolsTest, canGetSingleInputLayer) { - // 1->2 - CONNECT(1, 2); - - EXPECT_CALL(*mockNet, getInputsInfo(_)).WillOnce(WithArg<0>(Invoke([&](InputsDataMap & maps){ - prepareSomeInputs(maps, {1}); - }))); - auto allInputLayers = CNNNetGetAllInputLayers(CNNNetwork(mockNet)); - ASSERT_EQ(1, allInputLayers.size()); -} - -TEST_F(GraphToolsTest, canIterateOverCNNNetwork) { - CONNECT(1, 2); - CONNECT(1, 3); - CONNECT(2, 6); - CONNECT(3, 6); - CONNECT(3, 4); - CONNECT(3, 5); - CONNECT(4, 5); - CONNECT(4, 7); - CONNECT(6, 7); - CONNECT(7, 8); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - std::vector resultedOrder; - details::CNNNetworkIterator l(wrap), end; - for ( ; l != end; ++l) { - resultedOrder.push_back(*l); - } - - ASSERT_EQ(resultedOrder.size(), 8); - ASSERT_STREQ(resultedOrder[0]->name.c_str(), "1"); - ASSERT_STREQ(resultedOrder[1]->name.c_str(), "3"); - ASSERT_STREQ(resultedOrder[2]->name.c_str(), "4"); - ASSERT_STREQ(resultedOrder[3]->name.c_str(), "2"); - ASSERT_STREQ(resultedOrder[4]->name.c_str(), "6"); - ASSERT_STREQ(resultedOrder[5]->name.c_str(), "7"); - ASSERT_STREQ(resultedOrder[6]->name.c_str(), "8"); - ASSERT_STREQ(resultedOrder[7]->name.c_str(), "5"); -} - -TEST_F(GraphToolsTest, DISABLED_canIterateOverCNNNetworkWithCycle) { - CONNECT(1, 2); - CONNECT(2, 3); - CONNECT(3, 4); - CONNECT(4, 2); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - std::vector resultedOrder; - details::CNNNetworkIterator l(wrap), end; - for (; l != end; ++l) { - resultedOrder.push_back(*l); - } - - ASSERT_EQ(resultedOrder.size(), 4); - ASSERT_STREQ(resultedOrder[0]->name.c_str(), "2"); - ASSERT_STREQ(resultedOrder[1]->name.c_str(), "3"); - ASSERT_STREQ(resultedOrder[2]->name.c_str(), "1"); - ASSERT_STREQ(resultedOrder[3]->name.c_str(), "4"); -} - -TEST_F(GraphToolsTest, canCompareCNNNetworkIterators) { - CONNECT(1, 2); - CONNECT(1, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - details::CNNNetworkIterator i(wrap); - auto i2 = i; - i2++; - - ASSERT_NE(i, i2); - i++; - ASSERT_EQ(i, i2); -} - -TEST_F(GraphToolsTest, DISABLED_canIterateOverEmptyNetwork) { - CONNECT(1, 2); - CONNECT(2, 1); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - details::CNNNetworkIterator beg(wrap), end; - ASSERT_TRUE(beg == end); -} - -TEST_F(GraphToolsTest, CNNNetSwapLayersThrowsForNullPointers) { - CNNLayerPtr nullLayer; - ASSERT_ANY_THROW(CNNNetSwapLayers(nullLayer, nullLayer)); -} - -TEST_F(GraphToolsTest, CNNNetSwapLayersSwapWithItself) { - CONNECT(1, 2); - CONNECT(2, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "2"); - - ASSERT_NO_THROW(CNNNetSwapLayers(l, l)); - - ASSERT_CONNECTION(1, 2); - ASSERT_CONNECTION(2, 3); -} - -TEST_F(GraphToolsTest, DISABLED_CNNNetSwapLayersSimpleCase_1) { - CONNECT(1, 2); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_, _, _)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "1"); - auto r = CommonTestUtils::getLayerByName(wrap, "2"); - - ASSERT_NO_THROW(CNNNetSwapLayers(l, r)); - - ASSERT_CONNECTION(2, 1); -} - -TEST_F(GraphToolsTest, CNNNetSwapLayersSimpleCase_2) { - CONNECT(1, 2); - CONNECT(2, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_, _, _)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "2"); - auto r = CommonTestUtils::getLayerByName(wrap, "3"); - - ASSERT_NO_THROW(CNNNetSwapLayers(l, r)); - - ASSERT_CONNECTION(1, 3); - ASSERT_CONNECTION(3, 2); -} - -TEST_F(GraphToolsTest, CNNNetSwapLayersSimpleCase_3) { - CONNECT(1, 2); - CONNECT(2, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_, _, _)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "1"); - auto r = CommonTestUtils::getLayerByName(wrap, "2"); - - ASSERT_NO_THROW(CNNNetSwapLayers(l, r)); - - ASSERT_CONNECTION(2, 1); - ASSERT_CONNECTION(1, 3); -} - -TEST_F(GraphToolsTest, CNNNetSwapLayersDoesSwapDims) { - CONNECT(1, 2); - CONNECT(2, 3); - - SET_DIMS(1, {10, 1}); - SET_DIMS(2, {20, 1}); - SET_DIMS(3, {30, 1}); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_, _, _)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "1"); - auto r = CommonTestUtils::getLayerByName(wrap, "2"); - - ASSERT_NO_THROW(CNNNetSwapLayers(l, r)); - - ASSERT_CONNECTION(2, 1); - ASSERT_CONNECTION(1, 3); - - ASSERT_DIMS(1, {20, 1}); - ASSERT_DIMS(2, {20, 1}); -} - -TEST_F(GraphToolsTest, CNNNetSwapLayersSimpleCase_4) { - CONNECT(1, 2); - CONNECT(2, 3); - CONNECT(3, 4); - CONNECT(4, 5); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_, _, _)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "2"); - auto r = CommonTestUtils::getLayerByName(wrap, "4"); - - ASSERT_NO_THROW(CNNNetSwapLayers(l, r)); - - ASSERT_CONNECTION(1, 4); - ASSERT_CONNECTION(4, 3); - ASSERT_CONNECTION(3, 2); - ASSERT_CONNECTION(2, 5); -} - -TEST_F(GraphToolsTest, CNNNetSwapLayersSplit) { - CONNECT(1, 2); - CONNECT(1, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_, _, _)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "2"); - auto r = CommonTestUtils::getLayerByName(wrap, "3"); - - ASSERT_NO_THROW(CNNNetSwapLayers(l, r)); - - ASSERT_CONNECTION(1, 2); - ASSERT_CONNECTION(1, 3); -} -TEST_F(GraphToolsTest, DISABLED_CNNNetSwapLayersSplit_2) { - CONNECT(1, 2); - CONNECT(1, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_, _, _)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "1"); - auto r = CommonTestUtils::getLayerByName(wrap, "2"); - - ASSERT_NO_THROW(CNNNetSwapLayers(l, r)); - - ASSERT_CONNECTION(2, 1); - ASSERT_CONNECTION(2, 3); -} - -TEST_F(GraphToolsTest, CNNNetSwapLayersSplit_3) { - CONNECT(1, 2); - CONNECT(1, 6); - CONNECT(2, 3); - CONNECT(2, 4); - CONNECT(2, 5); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_, _, _)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "1"); - auto r = CommonTestUtils::getLayerByName(wrap, "2"); - - ASSERT_NO_THROW(CNNNetSwapLayers(l, r)); - - ASSERT_CONNECTION(2, 1); - ASSERT_CONNECTION(2, 6); - ASSERT_CONNECTION(1, 3); - ASSERT_CONNECTION(1, 4); - ASSERT_CONNECTION(1, 5); -} - -TEST_F(GraphToolsTest, CNNNetSwapLayersSplit_4) { - CONNECT(1, 2); - CONNECT(2, 3); - CONNECT(1, 3); - CONNECT(4, 2); - CONNECT(4, 1); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_, _, _)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "1"); - auto r = CommonTestUtils::getLayerByName(wrap, "2"); - - ASSERT_NO_THROW(CNNNetSwapLayers(l, r)); - - ASSERT_CONNECTION(4, 2); - ASSERT_CONNECTION(4, 1); - ASSERT_CONNECTION(2, 1); - ASSERT_CONNECTION(2, 3); - ASSERT_CONNECTION(1, 3); -} - -TEST_F(GraphToolsTest, CNNNetworkInsertLayerThrowsForNullPointers) { - CNNLayerPtr nullLayer; - ASSERT_ANY_THROW(CNNNetworkInsertLayer(nullLayer, nullLayer, nullLayer)); -} - -TEST_F(GraphToolsTest, CanNotInsertLayerIntoNonAdjiacendLayers) { - CONNECT(1, 2); - CONNECT(2, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "1"); - auto r = CommonTestUtils::getLayerByName(wrap, "3"); - - ASSERT_ANY_THROW(CNNNetworkInsertLayer(l, r, createGenericLayer("3"))); -} - -TEST_F(GraphToolsTest, CNNNetworkInsertLayerSimpleCase) { - CONNECT(1, 2); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "1"); - auto r = CommonTestUtils::getLayerByName(wrap, "2"); - - CNNNetworkInsertLayer(l, r, createGenericLayer("3")); - - ASSERT_CONNECTION(3, 2); - ASSERT_CONNECTION(1, 3); -} - -TEST_F(GraphToolsTest, CNNNetworkInsertLayerSimpleCaseWithMultipleOutputs) { - CONNECT(1, 2); - CONNECT(1, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "1"); - auto r = CommonTestUtils::getLayerByName(wrap, "3"); - - CNNNetworkInsertLayer(l, r, createGenericLayer("4")); - - ASSERT_CONNECTION(4, 3); - ASSERT_CONNECTION(1, 4); - ASSERT_CONNECTION(1, 2); -} - - -TEST_F(GraphToolsTest, CNNNetworkInsertLayerSimpleCaseWithMultipleInputs) { - CONNECT(1, 2); - CONNECT(3, 2); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "3"); - auto r = CommonTestUtils::getLayerByName(wrap, "2"); - - CNNNetworkInsertLayer(l, r, createGenericLayer("4")); - - ASSERT_CONNECTION(4, 2); - ASSERT_CONNECTION(3, 4); - ASSERT_CONNECTION(1, 2); -} - -TEST_F(GraphToolsTest, CNNNetworkInsertLayerSplitAndConcat) { - CONNECT_FROM_PORT(1, 0, 2); - CONNECT_FROM_PORT(1, 1, 2); - CONNECT_FROM_PORT(1, 2, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0,1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "1"); - auto r = CommonTestUtils::getLayerByName(wrap, "2"); - auto r2 = CommonTestUtils::getLayerByName(wrap, "3"); - - CNNNetworkInsertLayer(l, r, createGenericLayer("4"), 1); - CNNNetworkInsertLayer(l, r2, createGenericLayer("5"), 2); - - ASSERT_PORT_CONNECTION(1, 0, 2, 0); - ASSERT_PORT_CONNECTION(1, 1, 4, 0); - ASSERT_PORT_CONNECTION(4, 0, 2, 1); - ASSERT_PORT_CONNECTION(1, 2, 5, 0); - ASSERT_CONNECTION(5, 3); -} - - -TEST_F(GraphToolsTest, DISABLED_CNNNetworkInsertAfterLastLayer) { - CONNECT(1, 2); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - auto l = CommonTestUtils::getLayerByName(wrap, "2"); - - CNNNetworkInsertLayer(l, nullptr, createGenericLayer("3")); - - ASSERT_CONNECTION(1, 2); - ASSERT_CONNECTION(2, 3); -} - -TEST_F(GraphToolsTest, CNNNetworkInsertAfterAll) { - CONNECT(1, 2); - CONNECT(1, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - CNNNetworkInsertLayer(CommonTestUtils::getLayerByName(wrap, "1"), nullptr, createGenericLayer("5")); - - ASSERT_CONNECTION(1, 5); - ASSERT_CONNECTION(5, 2); - ASSERT_CONNECTION(5, 3); -} - -TEST_F(GraphToolsTest, CNNNetworkInsertAllAfterSplit) { - - CONNECT_FROM_PORT(1, 0, 2); - CONNECT_FROM_PORT(1, 1, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - CNNNetworkInsertLayer(CommonTestUtils::getLayerByName(wrap, "1"), nullptr, createGenericLayer("5")); - - ASSERT_CONNECTION(1, 5); - ASSERT_CONNECTION(5, 2); - ASSERT_CONNECTION(1, 3); -} - -TEST_F(GraphToolsTest, CNNNetworkInsert1AfterSplitBeforeEltwise) { - - CONNECT_FROM_PORT(1, 0, 3); - CONNECT_FROM_PORT(1, 1, 4); - CONNECT(2, 4); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - CNNNetworkInsertLayer(CommonTestUtils::getLayerByName(wrap, "1"), CommonTestUtils::getLayerByName(wrap, "4"), createGenericLayer("5")); - - ASSERT_CONNECTION(1, 3); - ASSERT_CONNECTION(1, 5); - ASSERT_CONNECTION(5, 4); - ASSERT_CONNECTION(2, 4); -} - -TEST_F(GraphToolsTest, CNNNetworkInsert1AfterSplit) { - - CONNECT_FROM_PORT(1, 0, 2); - CONNECT_FROM_PORT(1, 1, 3); - CONNECT_FROM_PORT(1, 2, 4); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - CNNNetworkInsertLayer(CommonTestUtils::getLayerByName(wrap, "1"), CommonTestUtils::getLayerByName(wrap, "4"), createGenericLayer("5")); - - ASSERT_CONNECTION(1, 2); - ASSERT_CONNECTION(1, 3); - ASSERT_CONNECTION(1, 5); - ASSERT_CONNECTION(5, 4); -} - - -TEST_F(GraphToolsTest, CNNNetworkInsertAfter2ConnectionsToEltwise) { - // multiple 1->2 connections like square operation using eltwise mull with itself - CONNECT(1, 2); - CONNECT(1, 2); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - CNNNetworkInsertLayer(CommonTestUtils::getLayerByName(wrap, "1"), CommonTestUtils::getLayerByName(wrap, "2"), createGenericLayer("5")); - - ASSERT_CONNECTION(1, 5); - ASSERT_MN_CONNECTIONS(5, 2, 1, 2); -} - - -TEST_F(GraphToolsTest, CNNNetworkRemoveNullPointerLayer) { - - CONNECT_FROM_PORT(1, 0, 2); - CONNECT_FROM_PORT(1, 1, 3); - CONNECT_FROM_PORT(1, 2, 4); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - ASSERT_ANY_THROW(CNNNetworkRemoveLayer(nullptr)); -} - -TEST_F(GraphToolsTest, CNNNetworkRemoveInputOrOutputLayer) { - - CONNECT_FROM_PORT(1, 0, 2); - CONNECT_FROM_PORT(2, 0, 3); - CONNECT_FROM_PORT(1, 0, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - ASSERT_ANY_THROW(CNNNetworkRemoveLayer(CommonTestUtils::getLayerByName(wrap, "1"))); - ASSERT_ANY_THROW(CNNNetworkRemoveLayer(CommonTestUtils::getLayerByName(wrap, "3"))); -} - -TEST_F(GraphToolsTest, CNNNetworkRemoveLayerThaHas2Outputs) { - - CONNECT_FROM_PORT(1, 0, 2); - CONNECT_FROM_PORT(2, 0, 3); - CONNECT_FROM_PORT(2, 0, 4); - CONNECT_FROM_PORT(1, 0, 3); - CONNECT_FROM_PORT(5, 0, 4); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - CNNNetworkRemoveLayer(CommonTestUtils::getLayerByName(wrap, "2")); - - ASSERT_2_CONNECTIONS(1, 3); - ASSERT_CONNECTION(1, 4); - ASSERT_CONNECTION(5, 4); - - // means all remained references removed - ASSERT_NO_CONNECTION(1, 2); - ASSERT_NO_CONNECTION(2, 2); - ASSERT_NO_CONNECTION(3, 2); - ASSERT_NO_CONNECTION(4, 2); -} - -TEST_F(GraphToolsTest, CNNNetworkRemoveLayerSplit) { - - CONNECT_FROM_PORT(1, 0, 2); - CONNECT_FROM_PORT(1, 1, 3); - CONNECT_FROM_PORT(2, 0, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - CNNNetworkRemoveLayer(CommonTestUtils::getLayerByName(wrap, "2")); - - ASSERT_2_CONNECTIONS(1, 3); - // means all remained references removed - ASSERT_NO_CONNECTION(1, 2); - ASSERT_NO_CONNECTION(2, 2); - ASSERT_NO_CONNECTION(3, 2); -} - -TEST_F(GraphToolsTest, CNNNetworkRemoveLayerSplit2) { - - CONNECT_FROM_PORT(1, 0, 2); - CONNECT_FROM_PORT(1, 0, 3); - CONNECT_FROM_PORT(1, 0, 4); - CONNECT_FROM_PORT(1, 1, 4); - CONNECT_FROM_PORT(1, 2, 5); - - CONNECT_FROM_PORT(2, 0, 3); - CONNECT_FROM_PORT(2, 0, 4); - CONNECT_FROM_PORT(2, 0, 5); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - CNNNetworkRemoveLayer(CommonTestUtils::getLayerByName(wrap, "2")); - - ASSERT_2_CONNECTIONS(1, 3); - ASSERT_3_CONNECTIONS(1, 4); - ASSERT_2_CONNECTIONS(1, 5); - - // means all remained references removed - ASSERT_NO_CONNECTION(1, 2); - ASSERT_NO_CONNECTION(2, 2); - ASSERT_NO_CONNECTION(3, 2); - ASSERT_NO_CONNECTION(4, 2); - ASSERT_NO_CONNECTION(5, 2); -} - -TEST_F(GraphToolsTest, CNNNetworkRemoveSimpleLayer) { - - CONNECT_FROM_PORT(1, 0, 2); - CONNECT_FROM_PORT(2, 0, 3); - - EXPECT_CALL(*mockNet, getOutputsInfo(_)).WillRepeatedly(WithArg<0>(Invoke([&](OutputsDataMap & maps){ - prepareOutputs(maps); - }))); - - EXPECT_CALL(*mockNet, getLayerByName(_,_,_)).WillRepeatedly(WithArgs<0, 1>(Invoke([&](const char* name, InferenceEngine::CNNLayerPtr& l){ - l = layerByName(name); - return l== nullptr ? GENERAL_ERROR : OK; - }))); - - CNNNetworkRemoveLayer(CommonTestUtils::getLayerByName(wrap, "2")); - - ASSERT_CONNECTION(1, 3); - - // means all remained references removed - ASSERT_NO_CONNECTION(1, 2); - ASSERT_NO_CONNECTION(2, 2); - ASSERT_NO_CONNECTION(3, 2); -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/i16_quantisation_test.cpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/i16_quantisation_test.cpp deleted file mode 100644 index 252952a44b2..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/i16_quantisation_test.cpp +++ /dev/null @@ -1,716 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "backend/gna_types.hpp" -#include "frontend/layer_quantizer.hpp" -#include "frontend/model_quantizer.hpp" -#include "gna_matcher.hpp" -#include "ov_models/builders.hpp" -#include "openvino/opsets/opset8.hpp" - -using namespace InferenceEngine; -using namespace ov::intel_gna::limitations; -using namespace ov::intel_gna::frontend; -using namespace GNATestIRs; - -class I16QuantisationTest : public GNATest<> { -protected: - InferenceEngine::CNNLayerPtr quantize(InferenceEngine::CNNLayerPtr lp) { - auto newLayer = InferenceEngine::injectData(lp); - Config gna_config; - gna_config.gnaPrecision = InferenceEngine::Precision::I16; - gna_config.gnaFlags.input_low_precision = false; - LayerQuantizer lq(gna_config); - lq.quantize(*newLayer); - return newLayer; - }; - - InferenceEngine::CNNNetwork quantize_single_input_model(const InferenceEngine::CNNNetwork& model, - float scale_factor) const { - auto scale_factors = std::vector({scale_factor}); - - GnaInputs inputs; - InferenceEngine::InputsDataMap inputs_map = model.getInputsInfo(); - - auto input_layer = getCreatorLayer(inputs_map.begin()->second->getInputData()).lock(); - inputs[input_layer->name].scale_factor = scale_factor; - - Config gna_config; - gna_config.gnaPrecision = InferenceEngine::Precision::I16; - gna_config.gnaFlags.input_low_precision = false; - - auto transformer = ov::intel_gna::TransformationsPipeline(gna_config); - - return ModelQuantizer(transformer).quantize(model, inputs); - } - - void SetUp() override { - Limitations::init(target::DeviceVersion::Default); - } - - void TearDown() override { - Limitations::deinit(); - } -}; - -template -T setWeights(T blob) { - blob->allocate(); - // actual quantisation algorithm is involved - we need to provide weights that will be quantized with scale factor - // of 1 - for (auto&& w : *blob) { - w = MAX_VAL_2B_WEIGHT; - } - return blob; -} - -template <> -TBlob::Ptr setWeights(TBlob::Ptr blob) { - blob->allocate(); - auto buf = blob->buffer(); - auto ptr = buf.as(); - - for (int i = 0; i != blob->byteSize() / 4; i++) { - ptr[i] = MAX_VAL_2B_WEIGHT; - } - return blob; -} - -// TODO: add test for FC weights after quantization -TEST_F(I16QuantisationTest, canQuantizeFCLayer) { - auto fc = std::make_shared(LayerParams{"name", "type", Precision::FP32}); - fc->_out_num = 9; - fc->_weights = setWeights(make_shared_blob({Precision::FP32, {1, 1}, Layout::NC})); - fillWeights(fc->_weights); - fc->_biases = make_shared_blob({Precision::FP32, {1, 1}, Layout::NC}); - fc->_biases->allocate(); - fillWeights(fc->_biases); - - std::shared_ptr outData = - std::make_shared("data", TensorDesc(Precision::FP32, SizeVector({1, 1}), Layout::NC)); - fc->outData.push_back(outData); - fc->insData.push_back(outData); - - ASSERT_NO_THROW(quantize(fc)); -} - -TEST_F(I16QuantisationTest, canQuantizeActivation) { - auto sigmoid = std::make_shared(LayerParams{"name", "type", Precision::FP32}); - sigmoid->params["value"] = 2; - sigmoid->type = "Activation"; - - ASSERT_NO_THROW(quantize(sigmoid)); -} - -TEST_F(I16QuantisationTest, outputAffinePrecisionIs32Bits) { - auto weights = make_shared_blob({Precision::U8, {440}, C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(Fc2DOutputModel(), weights); - - auto newNet = quantize_single_input_model(network, 1000); - InputsDataMap inputs = newNet.getInputsInfo(); - auto affineDataPtr = getInputTo(inputs.begin()->second->getInputData()).begin()->second->outData.front(); - - ASSERT_EQ(affineDataPtr->getTensorDesc().getPrecision(), Precision::I32); -} - -TEST_F(I16QuantisationTest, canQuantizeLstmLikeTopology) { - auto weights = setWeights(make_shared_blob({Precision::U8, {440}, C})); - // std::fill_n(weights->buffer().as(), weights->byteSize()/sizeof(float), 0); - - Core ie; - auto network = ie.ReadNetwork(affineToMemoryModel(), weights); - - ASSERT_NO_THROW(quantize_single_input_model(network, 1000)); -} - -TEST_F(I16QuantisationTest, DISABLED_outputScaleFactorForAffineIsCorrect) { - const float inputScaleFactorTest = 1000; - const float weightValueTest = 100; - - auto weights = make_shared_blob({Precision::U8, {440}, C}); - weights->allocate(); - fillWeights(weights, {weightValueTest}); - - Core ie; - auto network = ie.ReadNetwork(Fc2DOutputModel(), weights); - - auto newNet = quantize_single_input_model(network, inputScaleFactorTest); - InputsDataMap inputs = newNet.getInputsInfo(); - auto affineLayerPtr = getInputTo(inputs.begin()->second->getInputData()).begin()->second; - - auto quantParams = getInjectedData(affineLayerPtr); - - ASSERT_FLOAT_EQ(quantParams->_dst_quant.GetScale(), MAX_VAL_2B_WEIGHT / weightValueTest * inputScaleFactorTest); - ASSERT_FLOAT_EQ(quantParams->_weights_quant.GetScale(), MAX_VAL_2B_WEIGHT / weightValueTest); -} - -TEST_F(I16QuantisationTest, OnlyAffine_NoActivationInsertion) { - assert_that() - .onInferModel(Fc2DOutputModel()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_without() - .pwl_inserted_into_nnet(); -} - -TEST_F(I16QuantisationTest, OnlyAffine_NoActivationInsertion_ProfilingEnabled) { - assert_that() - .onInferModel(Fc2DOutputModel()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_without() - .pwl_inserted_into_nnet() - .profiling_counters(); -} - -TEST_F(I16QuantisationTest, OnlyAffineWithNanScaleFactorFails) { - gna().onInferModel(Fc2DOutputModel()).withNanScaleFactor().propagate_forward().throws(); -} - -TEST_F(I16QuantisationTest, OnlyAffineWithInfScaleFactorFails) { - gna().onInferModel(Fc2DOutputModel()).withInfScaleFactor().propagate_forward().throws(); -} - -TEST_F(I16QuantisationTest, AffineToMemoryWillResultInActivationInsertion) { - assert_that() - .onInferModel(affineToMemoryModel()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .pwl_inserted_into_nnet(); -} - -TEST_F(I16QuantisationTest, EltwiseToMemoryWithNoOutputActivationInsertion) { - assert_that() - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .onInferModel(eltwiseToMemoryModelNoOutput(), - [](CNNNetwork& net) { - net.addOutput("Eltwise_8"); - }) - .gna() - .propagate_forward() - .called_with() - .pwl_inserted_into_nnet(); -} - -TEST_F(I16QuantisationTest, EltwiseToMemory_ActivationInsertion) { - assert_that() - .onInferModel(eltwiseToMemoryModel()) - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .inNotCompactMode() - .gna() - .propagate_forward() - .called_with() - .pwl_inserted_into_nnet(); -} - -TEST_F(I16QuantisationTest, SplitFollowedByActivation_DummyDiagonalAffineInsertion) { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 20}); - const auto axis_node = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{}, {1}); - auto split = std::make_shared(input_params, axis_node, 2); - auto tanh = std::make_shared(split->outputs()[0]); - auto add = std::make_shared(split->outputs()[1], tanh); - auto result = std::make_shared(add); - auto function = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - assert_that() - .onInferNgraphModel(function) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .diagonal_inserted_into_nnet(); -} - -TEST_F(I16QuantisationTest, SliceFollowedBy2FCsAnd2Eltwises_AlignedFilterInsertion) { - assert_that() - .onInferModel(twoFCWithPaddingAfterSliceModel()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .diagonal_inserted_into_nnet(); -} - -// ToDo requires implementation of aligning filter for concat inputs and improvement of -// qunatization/scaling algorithm for concat -TEST_F(I16QuantisationTest, DISABLED_DoubleConcatPropageteForwardWithSuccess_AlignedFilterInsertion) { - assert_that() - .onInferModel(doubleConcatModel()) - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .inNotCompactMode() - .gna() - .propagate_forward() - .called_with() - .diagonal_inserted_into_nnet(); -} - -TEST_F(I16QuantisationTest, EltwiseSumm_onlyOneIdentityInsertion) { - assert_that() - .onInferModel(eltwiseSummModel()) - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .inNotCompactMode() - .gna() - .propagate_forward() - .called_with() - .pwl_inserted_into_nnet() - .once(); -} - -TEST_F(I16QuantisationTest, EltwiseMull_willInsertTwoIdentities) { - assert_that() - .onInferModel(eltwiseMulModel()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .pwl_inserted_into_nnet() - .twice(); -} - -TEST_F(I16QuantisationTest, multiple_inputs_supported) { - std::string configKey = GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_"); - assert_that() - .onInferModel(two_inputs_to_affine()) - .inNotCompactMode() - .withGNAConfig(configKey + std::to_string(0), 1.0f) - .withGNAConfig(configKey + std::to_string(1), 2.0f) - .gna() - .propagate_forward() - .called_with() - .pwl_inserted_into_nnet() - .once(); -} - -TEST_F(I16QuantisationTest, DISABLED_multiple_inputs_into_concat_supported) { - assert_that() - .onInferModel(two_inputs_to_concat()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .pwl_inserted_into_nnet() - .once(); -} - -TEST_F(I16QuantisationTest, ScaleShift_Affine_WillResultInIdentityInsertion) { - assert_that() - .onInferModel(scaleShiftAffineModel()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .pwl_inserted_into_nnet() - .once(); -} - -TEST_F(I16QuantisationTest, ClampFollowedByTanh_ResultInDiagonalInsertion) { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 10}); - auto clamp = std::make_shared(input_params, -50, 50); - auto tanh = std::make_shared(clamp); - auto result = std::make_shared(tanh); - auto function = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - assert_that() - .onInferNgraphModel(function) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .diagonal_inserted_into_nnet() - .twice(); -} - -TEST_F(I16QuantisationTest, EltwiseWithMemoryAndActivationInput_ResultInTwoDiagonalsInsertion) { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 10}); - const auto constant = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{10, 10}, {1}); - auto matmul = std::make_shared(input_params, constant); - auto mem_i = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 10}, 0); - auto mem_r = std::make_shared(mem_i, "r_27-28"); - auto tanh = std::make_shared(matmul); - auto add = std::make_shared(tanh, mem_r); - tanh->add_control_dependency(mem_r); - auto mem_w = std::make_shared(tanh, "r_27-28"); - auto result = std::make_shared(add); - mem_w->add_control_dependency(mem_r); - result->add_control_dependency(mem_w); - auto function = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - assert_that() - .onInferNgraphModel(function) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .diagonal_inserted_into_nnet() - .twice(); -} - -TEST_F(I16QuantisationTest, AffineWith2AffineOutputs_ResultInOnlyOneIdentityInsertion) { - // one Identity activation from first FC, and one Identity activation for eltwise - assert_that() - .onInferModel(AffineWith2AffineOutputsModel()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .pwl_inserted_into_nnet() - .twice(); -} - -TEST_F(I16QuantisationTest, ScaleShiftWithBroadcast_ResultInDiagonalInsertion) { - auto& affineWeights = storage>(); - - affineWeights = { - 2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 2048, 4096, 6144, 8192, 10240, 12288, - 14336, 16384, 2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 2048, 4096, 6144, 8192, - 10240, 12288, 14336, 16384, 2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, - }; - - assert_that() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .onInferModel(ScaleShift3DModel()) - .withWeigthsPattern({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}) - .inNotCompactMode() - .gna() - .propagate_forward() - .called_with() - .called_with() - .affine_weights_eq(affineWeights); -} - -TEST_F(I16QuantisationTest, MemoryAfterConcat_ResultInCopyInsertion) { - assert_that() - .onInferModel(MemoryAfterConcatModel()) - .inNotCompactMode() - .gna() - .propagate_forward() - .called_with() - .copy_inserted_into_nnet(); -} - -TEST_F(I16QuantisationTest, MemoryAndConcatAfterOneNode_ResultInCopyInsertion) { - assert_that() - .onInferModel(MemoryAndConcatAfterOneNode()) - .inNotCompactMode() - .gna() - .propagate_forward() - .called_with() - .copy_inserted_into_nnet(); -} - -TEST_F(I16QuantisationTest, DISABLED_permutationOfWeightsBetweenConvAndAffine) { - auto& affineWeights = storage>(); - - // least likely that width and height both are multiple of 7 - auto weigthsPattern = {1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f}; - - // here weights are transpozed - save() - .onInferModel(affineAfterConvNoPermute()) - .withWeigthsPattern(weigthsPattern) - .inNotCompactMode() - .from() - .propagate_forward() - .affine_weights_transpozed({128, 61}) - .to(affineWeights); - - // here weights shouldn't be transposed - assert_that() - .onInferModel(affineAfterConvWithPermute()) - .withWeigthsPattern(weigthsPattern) - .inNotCompactMode() - .gna() - .propagate_forward() - .called_with() - .affine_weights_eq(affineWeights); -} - -TEST_F(I16QuantisationTest, DISABLED_noPermutationOfWeightsBetweenConvAndAffineIfPermuteLayerWithCorrectArgs) { - auto& affineWeights = storage>(); - - // least likely that width and height both are multiple of 7 - auto weigthsPattern = {1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f}; - - save() - .onInferModel(affineAfterConvWithPermute()) - .withWeigthsPattern(weigthsPattern) - .inNotCompactMode() - .from() - .propagate_forward() - .affine_weights() - .to(affineWeights); - - assert_that() - .onInferModel(affineAfterConvNoPermute()) - .withWeigthsPattern(weigthsPattern) - .inNotCompactMode() - .gna() - .propagate_forward() - .called_with() - .affine_weights_transposed(affineWeights, {128, 61}); -} - -TEST_F(I16QuantisationTest, fp16tofp32_on_fullyConnected_model) { - auto weights = make_shared_blob({Precision::U8, {220}, Layout::C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(FCOnlyModelFP16(), weights); - - quantize_single_input_model(network, 1000); -} - -TEST_F(I16QuantisationTest, - MultipleActivationsAfterAffineWithIdentityActivation_MultipleDiagonalLayersWithActivaitons) { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 10}); - const auto constant = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{10, 10}, {1}); - auto matmul1 = std::make_shared(input_params, constant); - auto matmul2 = std::make_shared(input_params, constant); - auto add = std::make_shared(matmul2, matmul1); - auto sigmoid = std::make_shared(matmul2); - auto relu = std::make_shared(matmul2); - auto mul = std::make_shared(sigmoid, relu); - auto add2 = std::make_shared(add, mul); - auto result = std::make_shared(add); - auto function = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - // identiy came from automatic insertion due to - assert_that() - .onInferNgraphModel(function) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .pwls_inserted_into_nnet({kActSigmoid, kActRelu, kActIdentity, kActIdentity}); -} - -TEST_F(I16QuantisationTest, MultipleActivationsAfterAffine_ResultInMultipleDiagonalLayersWithActivaitons) { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 10}); - const auto constant = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{10, 10}, {1}); - auto matmul = std::make_shared(input_params, constant); - auto sigmoid = std::make_shared(matmul); - auto relu = std::make_shared(matmul); - auto mul = std::make_shared(sigmoid, relu); - auto result = std::make_shared(mul); - auto function = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - // extra identity inserted for affine - assert_that() - .onInferNgraphModel(function) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - // 1 diag for second activation, 1 for eltwise - .pwls_inserted_into_nnet({kActRelu, kActSigmoid}) - .diagonal_inserted_into_nnet() - .times(3); -} - -// TODO: build a regression test on top of it using real quantisation accuracy checking -TEST_F(I16QuantisationTest, ConcatWithConstInputPropagatedForward) { - assert_that() - .onInferModel(concatModelWithConstLayer()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .pwls_inserted_into_nnet({kActIdentity}); -} - -TEST_F(I16QuantisationTest, LSTMCell_quantize) { - auto weights = make_shared_blob({Precision::U8, {33664}, C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(LSTMCellOnlyModel(), weights); - - ASSERT_NO_THROW(quantize_single_input_model(network, 1000)); -} - -TEST_F(I16QuantisationTest, LSTMCell_unaligned_quantize) { - auto weights = make_shared_blob({Precision::U8, {3480}, C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(LSTMCellOnlyModelUnaligned(), weights); - - ASSERT_NO_THROW(quantize_single_input_model(network, 1000)); -} - -TEST_F(I16QuantisationTest, EltwisetWithConstInputPropagatedForward) { - assert_that() - .onInferModel(eltwiseSumModelWithConstLayer()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .diagonal_inserted_into_nnet(); -} - -TEST_F(I16QuantisationTest, PowerWithScaleFactorPropagateForward) { - assert_that() - .onInferModel(PowerWithScaleFactor1()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .pwls_inserted_into_nnet({kActIdentity}) - .And() - .diagonal_inserted_into_nnet(); -} - -TEST_F(I16QuantisationTest, ConcatWithDifferentInputScaleFactorsPropagateForward) { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 20}); - const auto axis_node = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{}, {1}); - auto split = std::make_shared(input_params, axis_node, 2); - auto sigmoid = std::make_shared(split->outputs()[0]); - auto tanh = std::make_shared(split->outputs()[1]); - auto concat = std::make_shared(ngraph::OutputVector{sigmoid, tanh}, 1); - auto result = std::make_shared(concat); - auto function = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - assert_that() - .onInferNgraphModel(function) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called_with() - .pwls_inserted_into_nnet({kActIdentity}); -} - -TEST_F(I16QuantisationTest, TI_quantize) { - auto weights = make_shared_blob({Precision::U8, {249748}, C}); - weights->allocate(); - fillWeights(weights); - - Core ie; - auto network = ie.ReadNetwork(TIModelWithLSTMCell2(), weights); - - ASSERT_NO_THROW(quantize_single_input_model(network, 1000)); -} - -TEST_F(I16QuantisationTest, TI_PropagateForward) { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 10}); - auto mul = std::make_shared( - input_params, - std::make_shared(ngraph::element::f32, ngraph::Shape{1, 10})); - auto add = std::make_shared( - mul, - std::make_shared(ngraph::element::f32, ngraph::Shape{1, 10})); - auto reshape = std::make_shared( - add, - std::make_shared(ngraph::element::i64, ngraph::Shape{3}, std::vector{1, 1, 10}), - false); - - auto reshape_shape = reshape->output(0).get_shape(); - const size_t batch_size = 1; - const size_t hiddenSize = 10; - - auto H_init = ngraph::builder::makeConstant(ngraph::element::f32, {batch_size, hiddenSize}, {}, true); - auto C_init = ngraph::builder::makeConstant(ngraph::element::f32, {batch_size, hiddenSize}, {}, true); - - auto H_t = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, hiddenSize}); - auto C_t = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, hiddenSize}); - - // Body - auto X = std::make_shared(ngraph::element::f32, - ngraph::Shape{batch_size, 1, reshape_shape[2]}); - auto weightsNode = - ngraph::builder::makeConstant(ngraph::element::f32, {4 * hiddenSize, reshape_shape[2]}, {}, true); - auto reccurrenceWeightsNode = - ngraph::builder::makeConstant(ngraph::element::f32, {4 * hiddenSize, hiddenSize}, {}, true); - - // lstm - auto constantX = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {batch_size, reshape_shape[2]}); - auto lstm1 = - std::make_shared(std::make_shared(X, constantX, false), - H_t, - C_t, - weightsNode, - reccurrenceWeightsNode, - hiddenSize); - - auto H_o = lstm1->output(0); - auto C_o = lstm1->output(1); - - auto body = - std::make_shared(ngraph::OutputVector{H_o, C_o}, ngraph::ParameterVector{X, H_t, C_t}); - - auto tensor_iterator = std::make_shared(); - tensor_iterator->set_body(body); - - tensor_iterator->set_sliced_input(X, reshape, 0, 1, 1, -1, 1); - tensor_iterator->set_merged_input(H_t, H_init, H_o); - tensor_iterator->set_merged_input(C_t, C_init, C_o); - - auto out0 = tensor_iterator->get_iter_value(H_o, -1); - - const size_t output_size = 12; - auto fc = ngraph::builder::makeFullyConnected(out0, - ngraph::element::f32, - output_size, - true, - {hiddenSize, output_size}, - {1}, - {1}); - auto result = std::make_shared(fc); - auto function = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - assert_that() - .onInferNgraphModel(function) - .withWeigthsPattern({0.1f}) - .inNotCompactMode() - .gna() - .propagate_forward() - .called_with() - .pwls_inserted_into_nnet({kActIdentity}); -} - -TEST_F(I16QuantisationTest, SplitToConcatWith2Inputs1360NotAlignedNoFC) { - assert_that() - .onInferModel(SplitToConcatWith2Inputs1360NotAlignedNoFC()) - .inNotCompactMode() - .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f) - .gna() - .propagate_forward() - .called(); -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/conv_matcher.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/conv_matcher.hpp deleted file mode 100644 index f489a63ca03..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/conv_matcher.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "nnet_base_matcher.hpp" - -class ConvoluionLayerMatcher : public ::testing::MatcherInterface { - bool matchInserted; - int matchQuantity; - public: - ConvoluionLayerMatcher(bool matchInserted, int matchQuantity) : matchInserted(matchInserted), matchQuantity(matchQuantity) {} - bool MatchAndExplain(const gna_nnet_type_t *foo, ::testing::MatchResultListener *listener) const override { - if (foo == nullptr) - return false; - for(int i = 0; i < foo->nLayers; i++) { - if (foo->pLayers[i].nLayerKind != INTEL_CONVOLUTIONAL) - continue; - - return matchInserted; - } - return !matchInserted; - }; - void DescribeTo(::std::ostream *os) const override { - *os << "should "<< (matchInserted ? "" : "not ") << "have Convolution primitive as part of nnet structure"; - } -}; - - - diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/copy_matcher.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/copy_matcher.hpp deleted file mode 100644 index 7fb0d16877e..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/copy_matcher.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "nnet_base_matcher.hpp" -#include "backend/gna_types.hpp" - -class CopyLayerMatcher : public ::testing::MatcherInterface { - bool matchInserted; - const int matchQuantity; - mutable int actualNumberOfCopyLayers; - public: - CopyLayerMatcher(bool matchInserted, int matchQuantity) : matchInserted(matchInserted), matchQuantity(matchQuantity) {} - bool MatchAndExplain(const gna_nnet_type_t *foo, ::testing::MatchResultListener *listener) const override { - if (foo == nullptr) - return false; - actualNumberOfCopyLayers = 0; - - for(int i = 0; i < foo->nLayers; i++) { - if (foo->pLayers[i].nLayerKind != INTEL_COPY) continue; - - if (!matchInserted) { - return false; - } - actualNumberOfCopyLayers ++; - } - if (matchQuantity == -1) { - if (actualNumberOfCopyLayers > 0) { - return true; - } - return false; - } - if (actualNumberOfCopyLayers != matchQuantity) { - return false; - } - return true; - }; - void DescribeTo(::std::ostream *os) const override { - *os << "should "<< (matchInserted ? "" : "not ") << "have " << (matchInserted ? std::to_string(matchQuantity) : "" ) - << " Copy primitives as part of nnet structure" << (matchInserted ? std::string(" but was only: ") + std::to_string(actualNumberOfCopyLayers) + " copy layers" : "" ); - } -}; - -inline ::testing::Matcher HasCopyLayer(bool matchInserted = false, int matchQuantity = -1) { - std::unique_ptr c (new NNetComponentMatcher()); - c->add(new CopyLayerMatcher(matchInserted, matchQuantity)); - return ::testing::MakeMatcher(c.release()); -} - - diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/diag_matcher.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/diag_matcher.hpp deleted file mode 100644 index 5ff5621621d..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/diag_matcher.hpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "nnet_base_matcher.hpp" -#include "frontend/quantization.hpp" - -class DiagLayerMatcher : public ::testing::MatcherInterface { - bool matchInserted; - int matchQuantity; - mutable int actualQuantity; -public: - DiagLayerMatcher(bool matchInserted, int matchQuantity) : matchInserted(matchInserted), matchQuantity(matchQuantity) {} - bool MatchAndExplain(const gna_nnet_type_t *foo, ::testing::MatchResultListener *listener) const override { - if (foo == nullptr) - return false; - actualQuantity = 0; - for(int i = 0; i < foo->nLayers; i++) { - if (foo->pLayers[i].nLayerKind != INTEL_AFFINE_DIAGONAL) continue; - // diagonal layer has to have 1 for weights and 0 for biases - - auto diag = (gna_affine_func_t*)foo->pLayers[i].pLayerStruct; - bool bWeightsOK = true; - - int beforePadding = 0; - for (int j =0; j < foo->pLayers[i].nOutputRows; j++) { - auto weights = (int16_t*)diag->pWeights; - auto biases = (int32_t*)diag->pBiases; - // identity matrix transformed to 16384 values - if (weights[j] != MAX_VAL_2B_WEIGHT || biases[j] != 0) { - beforePadding = j; - break; - } - } - - for (int j = beforePadding; j < foo->pLayers[i].nOutputRows; j++) { - auto weights = (int16_t*)diag->pWeights; - auto biases = (int32_t*)diag->pBiases; - // identity matrix transformed to 16384 values - if (weights[j] != 0 || biases[j] != 0) { - bWeightsOK = false; - break; - } - } - - // if all weights are zero, or zero value doesn't look like padding - if (!bWeightsOK && beforePadding == -1) continue; - actualQuantity ++; - } - // means any quantity > 0 - if (matchQuantity == -1) { - if (actualQuantity > 0) - return matchInserted; - else - return !matchInserted; - } - if (actualQuantity == matchQuantity) - return matchInserted; - else - return !matchInserted; - - }; - void DescribeTo(::std::ostream *os) const override { - *os << "should "<< (matchInserted ? "" : "not ") << "have " - << (matchQuantity == -1 ? "any" : std::to_string(matchQuantity)) - << " Identity Diagonal Primitive primitive as part of nnet structure, but was " << actualQuantity; - } -}; - -inline ::testing::Matcher HasDiagonalLayer(bool matchInserted = false, int matchQuantity = -1) { - std::unique_ptr c (new NNetComponentMatcher()); - c->add(new DiagLayerMatcher(matchInserted, matchQuantity)); - return ::testing::MakeMatcher(c.release()); -} - - diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/fill_with_data.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/fill_with_data.hpp deleted file mode 100644 index 622a8d68297..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/fill_with_data.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "backend/gna_types.hpp" - -class OutputFiller : public ::testing::MatcherInterface { - mutable std::stringstream reason; - int32_t fill32BValue; - int16_t fill16BValue; - - public: - OutputFiller(int32_t fill32BValue, int16_t fill16BValue) : fill32BValue(fill32BValue), fill16BValue(fill16BValue) {} - - - bool MatchAndExplain(const gna_nnet_type_t* foo, ::testing::MatchResultListener* listener) const override { - if (foo == nullptr) - return false; - reason.str(""); - // checking pointers are set - for (int i=0; i < foo->nLayers; i++) { - if (nullptr == foo->pLayers[i].pInputs || - nullptr == foo->pLayers[i].pOutputs) { - reason << "input/output pointers in pLayers[" << i << "] shouldn't be null NULL"; - return false; - } - auto nElements = foo->pLayers[i].nOutputColumns * foo->pLayers[i].nOutputRows; - if (foo->pLayers[i].nBytesPerOutput == 2) { - std::fill_n((int16_t *) foo->pLayers[i].pOutputs, nElements, fill16BValue); - } else if (foo->pLayers[i].nBytesPerOutput == 4) { - std::fill_n((int32_t *) foo->pLayers[i].pOutputs, nElements, fill32BValue); - } else { - reason << "output bitness of layer [" << i << "] shouldn't be 16 or 32, but was " << foo->pLayers[i].nBytesPerOutput; - return false; - } - } - return true; - } - - void DescribeTo(::std::ostream *os) const override { - *os << "Not a Matcher but a fake, but error happened anyway: " << reason.str(); - } - -}; - diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/input_data_matcher.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/input_data_matcher.hpp deleted file mode 100644 index 72cf36285ad..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/input_data_matcher.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#pragma once - -#include -#include "backend/gna_types.hpp" -#include "nnet_base_matcher.hpp" - -class InputDataMatcher : public ::testing::MatcherInterface { - std::vector refInput; -public: - - explicit InputDataMatcher(const std::vector &_refInput) : refInput(_refInput) {} - - bool MatchAndExplain(const gna_nnet_type_t *foo, ::testing::MatchResultListener *listener) const override { - if (foo->pLayers == nullptr) { - *listener << "Address of the first layer descriptor is NULL"; - return false; - } - auto firstLayer = foo->pLayers[0]; - auto actualInput = firstLayer.pInputs; - if (!actualInput) { - *listener << "Input of the first layer is NULL"; - return false; - } - - auto *actualInputI16 = reinterpret_cast(actualInput); - for (int i = 0; i < refInput.size(); i++) { - if (actualInputI16[i] != refInput[i]) { - *listener << "Actual and reference value of input doesn't match: " << actualInputI16[i] << " vs " - << refInput[i]; - } - } - return true; - } - - void DescribeTo(::std::ostream *os) const override {} -}; diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/nnet_base_matcher.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/nnet_base_matcher.hpp deleted file mode 100644 index c95b860a48a..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/nnet_base_matcher.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "backend/gna_types.hpp" -#include "gna_lib_ver_selector.hpp" - -class NNetComponentMatcher : public ::testing::MatcherInterface { - std::vector>> matchers; - mutable int failIdx = -1; - mutable std::stringstream reason; - int bitness; - public: - NNetComponentMatcher(int bitness = 16) : bitness(bitness) {} - NNetComponentMatcher& add(::testing::MatcherInterface * p) { - matchers.push_back(std::shared_ptr<::testing::MatcherInterface>(p)); - return *this; - } - bool empty() const { - return matchers.empty(); - } - bool MatchAndExplain(const gna_nnet_type_t* foo, ::testing::MatchResultListener* listener) const override { - if (foo == nullptr) - return false; - reason.str(""); - // checking pointers are set - for (int i=0; i < foo->nLayers; i++) { - if (nullptr == foo->pLayers[i].pInputs || - nullptr == foo->pLayers[i].pOutputs) { - reason << "input/output pointers in pLayers[" << i << "] shouldn't be null NULL"; - return false; - } - if (foo->pLayers[i].nBytesPerInput * 8 != bitness) { - reason << "numberOfBytes per input in pLayers[" << i << "] should be " << (bitness/8) << ", but was " - << foo->pLayers[i].nBytesPerInput; - return false; - } - - if (foo->pLayers[i].nBytesPerOutput * 8 != bitness) { - // if this output is a output to a bias this is fine - // also if this output is defacto network output - other words this whouldnt use in inputs, - for (int j=0; j < foo->nLayers; j++) { - // bad - if (foo->pLayers[j].pInputs == foo->pLayers[i].pOutputs) { - reason << "numberOfBytes per output int pLayers[" << i << "] should be " << (bitness/8) << ", but was " - << foo->pLayers[i].nBytesPerOutput << " cannot use this output as inputs for layer :" << j; - return false; - } - if (foo->pLayers[j].nLayerKind == INTEL_AFFINE || - foo->pLayers[j].nLayerKind == INTEL_AFFINE_DIAGONAL) { - auto pAffine = reinterpret_cast(foo->pLayers[j].pLayerStruct); - - if (pAffine->pWeights == foo->pLayers[i].pOutputs) { - reason << "numberOfBytes per output int pLayers[" << i << "] should be " << (bitness/8) << ", but was " - << foo->pLayers[i].nBytesPerOutput << " cannot use this output as weights for affine layer :" << j; - return false; - } - } - } - } - } - - int i = 0; - for (auto && matcher : matchers) { - bool res = matcher->MatchAndExplain(foo, listener); - if (!res) { - failIdx = i; - return false; - } - i++; - } - return true; - } - - void DescribeTo(::std::ostream* os) const override { - - if (failIdx != -1) { - matchers[failIdx]->DescribeTo(os); - return; - } - - *os << reason.str(); - } - -}; - diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/pool_matcher.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/pool_matcher.hpp deleted file mode 100644 index d871a556ebb..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/pool_matcher.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "nnet_base_matcher.hpp" - -class PoolingLayerMatcher : public ::testing::MatcherInterface { - bool matchInserted; - int matchQuantity; - bool bMaxPool; - public: - PoolingLayerMatcher(bool matchInserted, int matchQuantity, bool bMaxPool) - : matchInserted(matchInserted), matchQuantity(matchQuantity), bMaxPool(bMaxPool) {} - bool MatchAndExplain(const gna_nnet_type_t *foo, ::testing::MatchResultListener *listener) const override { - if (foo == nullptr) - return false; - for(int i = 0; i < foo->nLayers; i++) { - if (foo->pLayers[i].nLayerKind != INTEL_CONVOLUTIONAL) continue; - - auto conv = (gna_convolutional_layer_t*)foo->pLayers[i].pLayerStruct; - if (conv->poolType != INTEL_MAX_POOLING) continue; - - return matchInserted; - } - return !matchInserted; - }; - void DescribeTo(::std::ostream *os) const override { - *os << "should "<< (matchInserted ? "" : "not ") << "have MaxPooling primitive as part of nnet structure"; - } -}; - - - diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/precision_matcher.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/precision_matcher.hpp deleted file mode 100644 index deb91247953..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/precision_matcher.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include "nnet_base_matcher.hpp" -#include "backend/gna_types.hpp" -#include "gna_lib_ver_selector.hpp" - -class NNetPrecisionMatcher : public ::testing::MatcherInterface { - GnaPluginTestEnvironment::NnetPrecision nnetPrecision; - intel_layer_kind_t layerKind = (intel_layer_kind_t)-1; - public: - explicit NNetPrecisionMatcher(GnaPluginTestEnvironment::NnetPrecision nnetPrecision, - intel_layer_kind_t layerKind = (intel_layer_kind_t)-1) : nnetPrecision(nnetPrecision), layerKind(layerKind) {} - bool MatchAndExplain(const gna_nnet_type_t* foo, ::testing::MatchResultListener* listener) const override { - - auto ioPrecision = (foo->pLayers->nBytesPerInput == nnetPrecision.input_precision.size()) && - (foo->pLayers->nBytesPerOutput== nnetPrecision.output_precision.size()); - if (!ioPrecision) { - return false; - } - if (layerKind != (intel_layer_kind_t)-1) { - if (foo->pLayers->nLayerKind != layerKind) { - return false; - } - switch (layerKind) { - case INTEL_AFFINE : { - auto affine = (gna_affine_layer_t *) (foo->pLayers->pLayerStruct); - - return affine->affine.nBytesPerBias == nnetPrecision.biases_precision.size() && - affine->affine.nBytesPerWeight == nnetPrecision.weights_precision.size(); - } - default : - return false; - } - - } - return true; - } - - void DescribeTo(::std::ostream* os) const override { - *os << "intel_nnet_layer_t nBytesPerInput equals " << nnetPrecision.input_precision.size() << std::endl; - *os << "intel_nnet_layer_t nBytesPerOutput equals " << nnetPrecision.output_precision.size() << std::endl; - *os << "intel_nnet_layer_t nBytesPerWeights equals " << nnetPrecision.weights_precision.size() << std::endl; - *os << "intel_nnet_layer_t nBytesPerBises equals " << nnetPrecision.biases_precision.size() << std::endl; - *os << "foo->pLayers->nLayerKind INTEL_AFFINE" ; - } -}; - -inline ::testing::Matcher BitnessOfNNetEq(GnaPluginTestEnvironment::NnetPrecision nnetPrecision, - intel_layer_kind_t component) { - std::unique_ptr c (new NNetComponentMatcher()); - c->add(new NNetPrecisionMatcher(nnetPrecision, component)); - return ::testing::MakeMatcher(c.release()); -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/pwl_matcher.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/pwl_matcher.hpp deleted file mode 100644 index 2932e79cc5b..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/pwl_matcher.hpp +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include -#include "nnet_base_matcher.hpp" - -#include "gna_lib_ver_selector.hpp" - -extern void PwlApply16(intel_dnn_component_t *component, uint32_t num_subset_size); - -class PWLMatcher : public ::testing::MatcherInterface { - bool matchInserted; - int matchQuantity; - mutable int timesInserted = 0; - mutable std::vector activationsToLookFor; - mutable std::string notFoundLayer; - - template - using HashType = typename std::conditional::value, std::hash::type>, std::hash>::type; - - public: - PWLMatcher(bool inserted, int matchQuantity, const std::vector & particularActivations) - : matchInserted(inserted), matchQuantity(matchQuantity), activationsToLookFor(particularActivations) { - } - - bool MatchAndExplain(const gna_nnet_type_t *foo, ::testing::MatchResultListener *listener) const override { - if (foo == nullptr) - return false; - timesInserted = 0; - std::unordered_map> foundActivations; - - for(int i = 0; i < foo->nLayers; i++) { - if (foo->pLayers[i].nLayerKind != INTEL_AFFINE && - foo->pLayers[i].nLayerKind != INTEL_AFFINE_DIAGONAL && - foo->pLayers[i].nLayerKind != INTEL_CONVOLUTIONAL) continue; - auto affine = reinterpret_cast(foo->pLayers[i].pLayerStruct); - if (affine == nullptr) continue; - - bool hasPwl = affine->pwl.nSegments != 0 && affine->pwl.pSegments != nullptr; - - if (hasPwl) { - if (matchQuantity == -1) { - if (activationsToLookFor.empty()) - return matchInserted; - // detection of particular activation type - foundActivations[detectPwlType(foo->pLayers + i)]++; - } else { - timesInserted++; - } - } - } - if (!activationsToLookFor.empty()) { - for (auto & activation : activationsToLookFor) { - if (!foundActivations.count(activation)) { - notFoundLayer = intel_dnn_activation_name[activation]; - return false; - } - if (!--foundActivations[activation]) { - foundActivations.erase(activation); - } - } - return true; - } - if (matchInserted) { - if (matchQuantity != -1) { - return timesInserted == matchQuantity; - } - return timesInserted != 0; - } - - return timesInserted == 0; - }; - - DnnActivationType detectPwlType(gna_nnet_layer_t *layer) const { - intel_dnn_component_t comp{}; - comp.ptr_outputs = layer->pOutputs; - comp.num_columns_in = layer->nInputColumns; - comp.num_rows_in = layer->nInputRows; - - if (layer->nLayerKind == INTEL_AFFINE || - layer->nLayerKind == INTEL_AFFINE_DIAGONAL) { - auto pAffineLayer = reinterpret_cast(layer->pLayerStruct); - comp.op.pwl.num_segments = pAffineLayer->pwl.nSegments; - comp.op.pwl.ptr_segments = pAffineLayer->pwl.pSegments; - } else if (layer->nLayerKind == INTEL_CONVOLUTIONAL) { - auto pConvolutionalLayer = reinterpret_cast(layer->pLayerStruct); - comp.op.pwl.num_segments = pConvolutionalLayer->pwl.nSegments; - comp.op.pwl.ptr_segments = pConvolutionalLayer->pwl.pSegments; - } else { - return kActNone; - } - - int16_t prevSlope = 0; - int slopeChangedTimes = 0; - for (int i = 0; i != comp.op.pwl.num_segments; i++) { - if (!i || prevSlope != comp.op.pwl.ptr_segments[i].slope) { - slopeChangedTimes++; - prevSlope = comp.op.pwl.ptr_segments[i].slope; - } - } - - switch (slopeChangedTimes) { - case 3 : - if (comp.op.pwl.num_segments == 4) { - // ReLU has y=0 segment while identity doesn't have - // 2 segments are added: one at the begining and one at the end, due to saturation errata - return kActRelu; - } else { - return kActIdentity; - } - default: - // currently cannot determine between sigmoid or tanh etc - if (slopeChangedTimes > 3) { - return kActSigmoid; - } - return kActNone; - } - } - - void DescribeTo(::std::ostream *os) const override { - if (!matchInserted ) { - *os << "should not have PWL layer as part of nnet structure, but was found " << timesInserted <<" times" ; - } else { - if (matchQuantity == -1) { - *os << "should have PWL layer " << notFoundLayer << " as part of nnet structure, but it was not found " ; - } else { - *os << "should have PWL layer as part of nnet structure, for " << matchQuantity <<" times, but was for " << timesInserted ; - } - } - } -}; diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/pwl_quantization_metrics_matcher.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/pwl_quantization_metrics_matcher.hpp deleted file mode 100644 index 59933218a57..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/pwl_quantization_metrics_matcher.hpp +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include - -#include -#include - -#include "nnet_base_matcher.hpp" - -class PWLQuantizationMetricsMatcher : public ::testing::MatcherInterface { - const float rmse_threshold; - const uint32_t activation_type; - const uint16_t segment_threshold; - public: - PWLQuantizationMetricsMatcher(uint32_t type, float precision_threshold, uint16_t segments) : - activation_type(type), - rmse_threshold(precision_threshold), - segment_threshold(segments) {} - - bool MatchAndExplain(const gna_nnet_type_t *nnet, ::testing::MatchResultListener *listener) const override { - float rmse = 0.f; - const float test_arg_scale_factor = 16384; - - if (nnet == nullptr) - return false; - - for(int i = 0; i < nnet->nLayers; ++i) { - if (nnet->pLayers[i].nLayerKind != INTEL_AFFINE && - nnet->pLayers[i].nLayerKind != INTEL_AFFINE_DIAGONAL && - nnet->pLayers[i].nLayerKind != INTEL_CONVOLUTIONAL) continue; - - auto affine = reinterpret_cast(nnet->pLayers[i].pLayerStruct); - - if (affine == nullptr || - affine->pwl.nSegments == 0 || - affine->pwl.pSegments == nullptr) continue; - - if (affine->pwl.nSegments > segment_threshold) { - return false; - } - - int32_t domain = 0; - std::function activation_func = nullptr; - switch (activation_type) { - case kActSigmoid: - domain = 10000; - activation_func = [](float x)-> float { - float exp_value; - exp_value = - exp(static_cast(-(x))); - return 1 / (1 + exp_value);}; - break; - case kActTanh: - domain = 5000; - activation_func = [](float x)-> float {return tanh(x);}; - break; - case kActIdentity: - domain = 1000; - activation_func = [](float x)-> float {return x;}; - break; - case kActRelu: - domain = 1000; - activation_func = [](float x)-> float {return relu(x);}; - break; - case kActLeakyRelu: - domain = 1000; - activation_func = [](float x)-> float {return leaky_relu(x);}; - break; - case kActKaldiLstmClipping: - domain = 16000; - activation_func = [](float x)-> float { - return clipping(x, - KALDI_LSTM_CLIP_LOWER, - KALDI_LSTM_CLIP_UPPER);}; - break; - default: - domain = 50000; - activation_func = [](float x)-> float {return 0;}; - } - - std::vector y_diviation(2*domain); - std::vector segments_vector(affine->pwl.nSegments); - std::iota(segments_vector.begin(), segments_vector.begin()+affine->pwl.nSegments, - affine->pwl.pSegments); - - auto current_segment = segments_vector.begin(); - auto diviation_itr = y_diviation.begin(); - - for(int i=-domain; i static_cast((*current_segment)->xBase & XBASEMASK) / test_arg_scale_factor) { - ++current_segment; - } - auto prev_segment = std::prev(current_segment,1); - value = activation_func(arg); - - float base_arg = static_cast((*prev_segment)->xBase & XBASEMASK) / test_arg_scale_factor; - float base_value = static_cast((*prev_segment)->yBase) / ACTIVATION_SCALE_FACTOR; - - uint32_t slope_scale_index = (*prev_segment)->xBase & ~XBASEMASK; - - uint64_t slope_scale = static_cast(1) << (8 * (1 + slope_scale_index)); - float slope = - test_arg_scale_factor*(static_cast((*prev_segment)->slope ) / (slope_scale*ACTIVATION_SCALE_FACTOR)); - - float quant_value = (arg - base_arg)*slope + base_value; - - *diviation_itr = std::pow(std::abs(value-quant_value),2); - ++diviation_itr; - } - - // sort ascending to do not lost precision - std::sort(y_diviation.begin(),y_diviation.end()); - double sum = std::accumulate(y_diviation.begin(), y_diviation.end(), 0.0); - rmse = std::sqrt(sum/static_cast(y_diviation.size())); - } - - return rmse_threshold > rmse; - }; - void DescribeTo(::std::ostream *os) const override { - *os << "Has the activation layer type " << activation_type <<" rmse less that threshold "<< rmse_threshold - << " or segments count less that threshold " << segment_threshold - << " ?"; - } -}; - -inline ::testing::Matcher PrecisionOfQuantizedPwlMetrics(uint32_t type, - float threshold, - uint16_t segments) { - std::unique_ptr c (new NNetComponentMatcher()); - c->add(new PWLQuantizationMetricsMatcher(type, threshold, segments)); - return ::testing::MakeMatcher(c.release()); -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/weights_matcher.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/weights_matcher.hpp deleted file mode 100644 index f4f5f3ddd15..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/matchers/weights_matcher.hpp +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include "nnet_base_matcher.hpp" - -using TranspozedData = std::tuple*, int, int>; - -class TranspozeIterator { - std::pair dims; - int _offset = 0; - int _row = 0; - int _col = 0; - int _outputRow = 0; - public : - TranspozeIterator(const std::pair & dims) : dims(std::move(dims)) { - } - TranspozeIterator(const TranspozedData & data) : TranspozeIterator({std::get<1>(data), std::get<2>(data)}) { - } - - TranspozeIterator operator ++ (int) { - TranspozeIterator c(*this); - this->operator++(); - return c; - } - - void reset() { - _offset = 0; - _row = 0; - _col = 0; - _outputRow = 0; - } - - // prefix form - TranspozeIterator& operator ++ () { - if (dims.first == 0 || dims.second == 0) { - _offset ++; - } else { - // step over whole row length - _row++; - // once number of rows hit max value - if (_row == dims.second) { - // increment offset within row - _col++; - // restart from first row - _row = 0; - // restart from next output channel - if (_col == dims.first) { - _outputRow++; - _col = 0; - } - } - _offset = _col + _row * dims.first + _outputRow * dims.first * dims.second; - } - return *this; - } - // getting index - operator int() { - return _offset; - } - int row() const noexcept { - return _row; - } - int col() const noexcept { - return _col; - } - int outputRow() const noexcept{ - return _outputRow; - } -}; - -class WeightsMatcher : public ::testing::MatcherInterface { - enum HowMatch{ - eNone, - eEq, - eTranspozed - } eMatchKind; - TranspozedData transpozedData; - - mutable std::stringstream error; - mutable TranspozeIterator iterator; - mutable int actual; - public: - explicit WeightsMatcher(const TranspozedData & data) : - eMatchKind(eTranspozed), - transpozedData(data), - iterator(data) { - if (0 == std::get<1>(transpozedData) || 0 == std::get<2>(transpozedData)) { - eMatchKind = eEq; - } - } - bool MatchAndExplain(const gna_nnet_type_t *foo, ::testing::MatchResultListener *listener) const override { - if (foo == nullptr) - return false; - iterator.reset(); - - for (uint32_t i = 0; i < foo->nLayers; i++) { - if (foo->pLayers[i].nLayerKind != INTEL_AFFINE && - foo->pLayers[i].nLayerKind != INTEL_AFFINE_DIAGONAL) continue; - - auto affine = (gna_affine_func_t*)foo->pLayers[i].pLayerStruct; - - auto affineWeightsSize = foo->pLayers[i].nOutputRows * - (foo->pLayers[i].nLayerKind == INTEL_AFFINE_DIAGONAL ? 1 : foo->pLayers[i].nInputRows); - - if (affineWeightsSize != std::get<0>(transpozedData)->size()) { - error << "gna-xnn layer(" << i << ") weights size mismatch: expected " - << std::get<0>(transpozedData)->size() << ", but was: " << affineWeightsSize; - break; - } - - auto pWeights = reinterpret_cast(affine->pWeights); - - for (int i = 0; i != affineWeightsSize; i++, iterator++) { - auto savedVal = (&std::get<0>(transpozedData)->front())[iterator]; - if (pWeights[i] != savedVal) { - actual = pWeights[i]; - return false; - } - } - return true; - } - return false; - }; - void DescribeTo(::std::ostream *os) const override { - *os << error.str() << std::endl; - if (eMatchKind == eEq) { - *os << "weights of affine layers are not equal, error at: "; - } else { - *os << "weights of affine layers are not transpozed, error at: "; - } - *os << (int)iterator << ", actual=" << actual<<", expected=" << (&std::get<0>(transpozedData)->front())[iterator]; - } -}; - -class WeightsSizeMatcher : public ::testing::MatcherInterface { - enum HowMatch{ - eNone, - eEqAffine, - } eMatchKind; - - mutable std::stringstream error; - mutable int actual; - size_t expected_weights_size; - public: - explicit WeightsSizeMatcher(const size_t data_len) : - eMatchKind(eEqAffine), - expected_weights_size(data_len){ - } - bool MatchAndExplain(const gna_nnet_type_t *foo, ::testing::MatchResultListener *listener) const override { - if (foo == nullptr) - return false; - - size_t sizeTotal = 0; - std::stringstream ss; - for(uint32_t i = 0; i < foo->nLayers; i++) { - if (foo->pLayers[i].nLayerKind != INTEL_AFFINE && eMatchKind == eEqAffine) continue; - - auto affineWeightsSize = foo->pLayers[i].nOutputRows * - (foo->pLayers[i].nLayerKind == INTEL_AFFINE_DIAGONAL ? 1 : foo->pLayers[i].nInputRows); - - sizeTotal += affineWeightsSize; - ss << "[" << i << "]: " << affineWeightsSize << ", "; - - } - - if (eMatchKind == eEqAffine && sizeTotal != expected_weights_size) { - error << "gna-affine layers " << ss.str() << " have diff total weights size : " << sizeTotal - << ", while expected to have: " << expected_weights_size << "\n"; - return false; - } - return true; - }; - void DescribeTo(::std::ostream *os) const override { - *os << error.str() << std::endl; - } -}; - - -class WeightsSaver: public ::testing::MatcherInterface { - mutable TranspozeIterator iterator; - std::vector* weights; - public: - explicit WeightsSaver(TranspozedData data) : - weights(std::get<0>(data)), iterator(data) { - } - bool MatchAndExplain(const gna_nnet_type_t *foo, ::testing::MatchResultListener *listener) const override { - if (foo == nullptr) - return false; - for (uint32_t i = 0; i < foo->nLayers; i++) { - if (foo->pLayers[i].nLayerKind != INTEL_AFFINE) continue; - - auto affine = (gna_affine_func_t*)foo->pLayers[i].pLayerStruct; - - auto affineWeightsSize = foo->pLayers[i].nOutputRows * foo->pLayers[i].nInputRows; - auto pWeights = reinterpret_cast(affine->pWeights); - weights->resize(affineWeightsSize); - - for (int i=0; i != affineWeightsSize; i++, ++iterator) { - (*weights)[i] = pWeights[iterator]; - } - - return true; - } - return false; - }; - void DescribeTo(::std::ostream *os) const override { - *os << "affine layer not found"; - } -}; - - -void HasWeightsTranspozed(std::unique_ptr& components, std::vector* data, std::pair dims) { - components->add(new WeightsMatcher(make_tuple(data, dims.first, dims.second))); -} - -void HasWeightsEq(std::unique_ptr& components, std::vector* data) { - components->add(new WeightsMatcher(make_tuple(data, 0, 0))); -} - -void SaveWeights(std::unique_ptr& components, std::vector* data, std::pair dims) { - components->add(new WeightsSaver(make_tuple(data, dims.first, dims.second))); -} - -void HasWeightsSizeEq(std::unique_ptr& components, size_t weights_size) { - components->add(new WeightsSizeMatcher(weights_size)); -} - diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/test_irs.cpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/test_irs.cpp deleted file mode 100644 index 3596dfe004c..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/test_irs.cpp +++ /dev/null @@ -1,5872 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include "test_irs.hpp" - -namespace GNATestIRs { - -std::string FCOnlyModel() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - - - - - - - 1 - 10 - - - - - 10 - - - - - - - - -)V0G0N"; -} - -std::string Fc2DOutputModel() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - -)V0G0N"; -} - -std::string affineToMemoryModel() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - - - - - - - - -)V0G0N"; -} - - -std::string MemoryAndConcatAfterOneNode() { - return R"V0G0N( - - - - - - 1 - 32 - - - - - - - - - 1 - 32 - - - - - 1 - 32 - - - - - - - - - 1 - 32 - - - - - - - - - 1 - 32 - - - - - 1 - 32 - - - - - - - - - 1 - 32 - - - - - - - - - 1 - 32 - - - - 1 - 32 - - - - - 1 - 64 - - - - - - - - - - - - - -)V0G0N"; -} - -std::string MemoryAfterConcatModel() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 10 - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - 1 - 10 - - - - 1 - 10 - - - - - 1 - 20 - - - - - - - - - 1 - 20 - - - - - - 1 - 20 - - - - - - - - - 1 - 20 - - - - - - 1 - 20 - - - - - - - - - - 1 - 20 - - - - - - - - - - - - - - - -)V0G0N"; -} - -std::string eltwiseToMemoryModelNoOutput() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - - - 1 - 10 - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - - - - - - - -)V0G0N"; -} -std::string eltwiseToMemoryModel() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - 1 - 10 - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - 1 - 10 - - - - - - - - - - - - - -)V0G0N"; -} - -std::string FCWithPaddingAfterSplitModel() { - return R"V0G0N( - - - - - - 1 - 20 - - - - - - - - - 1 - 20 - - - - - - 1 - 10 - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - )V0G0N"; -} - -std::string twoFCWithPaddingAfterSliceModel() { - return R"V0G0N( - - - - - - 1 - 20 - - - - - - - - - 1 - 20 - - - - - - 1 - 8 - - - - 1 - 12 - - - - - - - - - - 1 - 12 - - - - - 1 - 8 - - - - - - - - - - 1 - 12 - - - - - 1 - 8 - - - - - - - - 1 - 8 - - - 1 - 8 - - - - - 1 - 8 - - - - - - - - 1 - 8 - - - 1 - 8 - - - - - 1 - 8 - - - - - - - - - - - - - - - )V0G0N"; -} - -std::string FCWithPaddingAfterSliceModel() { - return R"V0G0N( - - - - - - 1 - 20 - - - - - - - - - 1 - 20 - - - - - - 1 - 8 - - - - 1 - 12 - - - - - - - - - - 1 - 12 - - - - - 1 - 8 - - - - - - - - 1 - 8 - - - 1 - 8 - - - - - 1 - 8 - - - - - - - - - - - - )V0G0N"; -} - -std::string SliceModelWithAlignedOutputs() { - return R"V0G0N( - - - - - - 1 - 20 - - - - - - - - - 1 - 20 - - - - - - 1 - 16 - - - - 1 - 4 - - - - - - - - - - 1 - 16 - - - - - 1 - 4 - - - - - - - - 1 - 4 - - - 1 - 4 - - - - - 1 - 4 - - - - - - - - - - - - )V0G0N"; -} - -std::string eltwiseSummModel() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - )V0G0N"; -} - - -std::string eltwiseMulModel() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - )V0G0N"; -} - -std::string scaleShiftAffineModel() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - 1 - 10 - - - - - - 1 - 10 - - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - -)V0G0N"; - -} - -std::string AffineWith2AffineOutputsModel() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - 1 - 10 - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - - - )V0G0N"; - -} - -std::string TFLeakyReluModel() { - return R"V0G0N( - - - - - - - 1 - 128 - 1 - 126 - - - - - - - - 1 - 128 - 1 - 126 - - - - - 1 - 128 - 1 - 122 - - - - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - 1 - 128 - 1 - 122 - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - - - - - - - - - )V0G0N"; -} - -std::string maxpoolAfterRelu() { - return R"V0G0N( - - - - - - - 1 - 128 - 1 - 126 - - - - - - - - 1 - 128 - 1 - 126 - - - - - 1 - 128 - 1 - 122 - - - - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - 1 - 128 - 1 - 122 - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 118 - - - - - - - - - - - 1 - 128 - 1 - 118 - - - - - 1 - 128 - 1 - 118 - - - - - - - - 1 - 128 - 1 - 118 - - - - - 1 - 128 - 1 - 118 - - - - - - - 1 - 128 - 1 - 118 - - - - - 1 - 128 - 1 - 118 - - - - - - - - 1 - 128 - 1 - 118 - - - - - 1 - 128 - 1 - 118 - - - - - - - - 1 - 128 - 1 - 118 - - - - - 1 - 128 - 1 - 118 - - - - - - - - 1 - 128 - 1 - 118 - - - 1 - 128 - 1 - 118 - - - - - 1 - 128 - 1 - 118 - - - - - - - - 1 - 128 - 1 - 118 - - - - - 1 - 128 - 1 - 59 - - - - - - - - - - - - - - - - - - - - - - - - - - )V0G0N"; -} - -std::string doubleConcatModel() { - return R"V0G0N( - - - - - - 1 - 40 - - - - - - - - - 1 - 40 - - - - - - 1 - 20 - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 20 - - - - - - - - - 1 - 20 - - - - - - 1 - 10 - - - - 1 - 10 - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - 1 - 20 - - - - - 1 - 40 - - - - - - - - - - 1 - 40 - - - - - 1 - 40 - - - - - - - - - - - - - - - - - - )V0G0N"; -} - - -std::string cropWithoutOffsetModel() { - return R"V0G0N( - - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - )V0G0N"; -} - -std::string cropWithAlignedOffsetModel() { - return R"V0G0N( - - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - )V0G0N"; -} - -std::string cropWithOffsetModel() { - return R"V0G0N( - - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - )V0G0N"; -} - -std::string cropWithOffsetAndSecondDimModel() { - return R"V0G0N( - - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - -)V0G0N"; -} - - -std::string cropWithMaxOffsetModel() { - return R"V0G0N( - - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - )V0G0N"; -} - -std::string cropWithOffsetExtendedModel() { - return R"V0G0N( - - - - - - 1 - 20 - - - - - - - - - - 1 - 20 - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - )V0G0N"; -} - -std::string copyModel() { - return R"V0G0N( - - - - - - 1 - 20 - - - - - - - - - - 1 - 20 - - - - - 1 - 20 - - - - - - - 1 - 20 - - - - - 1 - 20 - - - - - - - - - 1 - 20 - - - 1 - 20 - - - - - 1 - 20 - - - - - - - - - - - - )V0G0N"; -} - -std::string two_inputs_to_concat() { - return R"V0G0N( - - - - - - - 1 - 600 - - - - - - - 1 - 600 - - - - - - - - 1 - 600 - - - - - 1 - 600 - - - - - 1 - 1200 - - - - - - - - 1 - 600 - - - - - 1 - 600 - - - - - - - - - - - )V0G0N"; - -} - -std::string two_inputs_to_affine() { - return R"V0G0N( - - - - - - - 1 - 10 - - - - - - - 1 - 10 - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - )V0G0N"; - -} - - -std::string affineAfterConvNoPermute() { - return R"V0G0N( - - - - - - - 1 - 128 - 1 - 126 - - - - - - - - 1 - 128 - 1 - 126 - - - - - 1 - 128 - 1 - 122 - - - - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 61 - - - - - - - - - 1 - 128 - 1 - 61 - - - - - 1 - 7808 - - - - - - - - - - - - - - 1 - 7808 - - - - - 1 - 10 - - - - - - - - - - - - - - )V0G0N"; -} - -std::string affineAfterConvWithPermute() { - return R"V0G0N( - - - - - - - 1 - 128 - 1 - 126 - - - - - - - - 1 - 128 - 1 - 126 - - - - - 1 - 128 - 1 - 122 - - - - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 122 - - - - - - - - 1 - 128 - 1 - 122 - - - - - 1 - 128 - 1 - 61 - - - - - - - - - 1 - 128 - 1 - 61 - - - - - 1 - 61 - 1 - 128 - - - - - - - - - 1 - 61 - 1 - 128 - - - - - 1 - 7808 - - - - - - - - - - - - - - 1 - 7808 - - - - - 1 - 10 - - - - - - - - - - - - - - - )V0G0N"; -} - - - -std::string ScaleShift3DModel() { - return R"V0G0N( - - - - - - - 1 - 40 - - - - - - - - 1 - 40 - - - - - 1 - 5 - 8 - - - - - - - 1 - 5 - 8 - - - - - 1 - 5 - 8 - - - - - - - - - - - - - - - )V0G0N"; -} - -std::string FCOnlyModelFP16() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - )V0G0N"; -} - -std::string concatModelWithConstLayer() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - 1 - 10 - - - - - - - - - - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 20 - - - - - - - - - - 1 - 20 - - - - - 1 - 20 - - - - - - - - - - - - )V0G0N"; -} - -std::string LSTMCellOnlyModel() { - return R"V0G0N( - - - - - - - 1 - 96 - - - - - - - - 1 - 96 - - - - - 1 - 96 - - - - - - - - - 1 - 96 - - - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - - - - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - - - 1 - 32 - - - 1 - 32 - - - - - - - - - - - - 1 - 32 - - - 1 - 32 - - - - - 1 - 32 - - - - - - - - - - - - - - - )V0G0N"; -}; - - - -std::string TIModelWithLSTMCell1() { - return R"V0G0N( - - - - - - - 1 - 10 - - - - - - - - 1 - 10 - - - - - - 1 - 10 - - - - - - - - 3 - - - - - - - - - - 1 - 10 - - - 3 - - - - - 1 - 1 - 10 - - - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - - - - - - 1 - 1 - 10 - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 10 - - - 1 - 10 - - - - - - - - - - - - - - - - - - - - 1 - 1 - 10 - - - - - 1 - 10 - - - - - - - - 1 - 10 - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 10 - - - 1 - 10 - - - - - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 12 - - - - - - - - - - - - - - - - - - - )V0G0N"; -} - -std::string TIModelWithLSTMCell1WithoutScaleShift() { - return R"V0G0N( - - - - - - - 1 - 10 - - - - - - - 3 - - - - - - - - - - 1 - 10 - - - 3 - - - - - 1 - 1 - 10 - - - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - - - - - - 1 - 1 - 10 - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 10 - - - 1 - 10 - - - - - - - - - - - - - - - - - - - - 1 - 1 - 10 - - - - - 1 - 10 - - - - - - - - 1 - 10 - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 10 - - - 1 - 10 - - - - - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 12 - - - - - - - - - - - - - - - - - - )V0G0N"; - } - - std::string TIModelWithLSTMCell1Aligned() { - return R"V0G0N( - - - - - - - 1 - 32 - - - - - - - - 1 - 32 - - - - - - 1 - 32 - - - - - - - - 3 - - - - - - - - - - 1 - 32 - - - 3 - - - - - 1 - 1 - 32 - - - - - - - 1 - 32 - - - - - - - - - - 1 - 32 - - - - - - - - - - 1 - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - - - 1 - 32 - - - 1 - 32 - - - - - - - - - - - - - - - - - - - - 1 - 1 - 32 - - - - - 1 - 32 - - - - - - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - - - 1 - 32 - - - 1 - 32 - - - - - - - - - - - - - - - - - - 1 - 32 - - - - - 1 - 12 - - - - - - - - - - - - - - - - - - - )V0G0N"; -} - - std::string TIModelWithLSTMCell3Aligned() { - return R"V0G0N( - - - - - - - 1 - 96 - - - - - - - 3 - - - - - - - - - - 1 - 96 - - - 3 - - - - - 1 - 3 - 32 - - - - - - - 1 - 32 - - - - - - - - - - 1 - 32 - - - - - - - - - - 1 - 3 - 32 - - - 1 - 32 - - - 1 - 32 - - - - - 1 - 32 - - - 1 - 32 - - - - - - - - - - - - - - - - - - - - 1 - 1 - 32 - - - - - 1 - 32 - - - - - - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - - - 1 - 32 - - - 1 - 32 - - - - - - - - - - - - - - - - - - 1 - 32 - - - - - 1 - 12 - - - - - - - - - - - - - - - - - - )V0G0N"; - }; - -std::string TIModelWithLSTMCell2() { - return R"V0G0N( - - - - - - - 1 - 20 - - - - - - - 3 - - - - - - - - - - 1 - 20 - - - 3 - - - - - 1 - 2 - 10 - - - - - - - 1 - 10 - - - - - - - - - - 1 - 10 - - - - - - - - - - 1 - 2 - 10 - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 10 - - - 1 - 10 - - - - - - - - - - - - - - - - - - - - 1 - 1 - 10 - - - - - 1 - 10 - - - - - - - - 1 - 10 - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 10 - - - 1 - 10 - - - - - - - - - - - - - - - - - - 1 - 10 - - - - - 1 - 12 - - - - - - - - - - - - - - - - - - )V0G0N"; -}; - -std::string InputSplitConcatModel() { - return R"V0G0N( - - - - - - - 1 - 64 - - - - - - - - 1 - 64 - - - - - - 1 - 64 - - - - - - - - 1 - 64 - - - - - 1 - 32 - - - 1 - 32 - - - - - - - 1 - 32 - - - 1 - 32 - - - - - 1 - 64 - - - - - - - - 1 - 64 - - - - - 1 - 10 - - - - - - - - - - - - - - - - )V0G0N"; -} - -std::string InputSplitConcatModelUnaligned() { - return R"V0G0N( - - - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 10 - - - 1 - 10 - - - - - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 10 - - - - - - - - - - - - - - - - )V0G0N"; -} - -std::string InputSplitConcatReshapeModelUnaligned() { - return R"V0G0N( - - - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 10 - - - 1 - 10 - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 20 - - - - - - - - 1 - 20 - - - - - 1 - 10 - - - - - - - - - - - - - - - - - )V0G0N"; -} - -std::string eltwiseSumModelWithConstLayer() { - return R"V0G0N( - - - - - - 1 - 10 - - - - - - - 1 - 10 - - - - - - - - - - - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - )V0G0N"; -} - -std::string LSTMCellOnlyModelUnaligned() { - return R"V0G0N( - - - - - - - 1 - 30 - - - - - - - - 1 - 30 - - - - - 1 - 30 - - - - - - - - - 1 - 30 - - - - - 1 - 10 - - - 1 - 10 - - - 1 - 10 - - - - - - - - 1 - 10 - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 10 - - - 1 - 10 - - - - - - - - - - - - 1 - 10 - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - - - -)V0G0N"; -}; - -std::string twoCropsModel() { - return R"V0G0N( - - - - - - 1 - 48 - - - - - - - - - 1 - 48 - - - - - 1 - 48 - - - - - - - - - 1 - 48 - - - - - 1 - 16 - - - - - - - - 1 - 48 - - - - - 1 - 16 - - - - - - - - - 1 - 16 - - - 1 - 16 - - - - - 1 - 32 - - - - - - - - 1 - 32 - - - - - 1 - 32 - - - - - - - - - - - - - - )V0G0N"; -} - -std::string threeCropsModel() { - return R"V0G0N( - - - - - - 1 - 40 - - - - - - - - - 1 - 40 - - - - - 1 - 40 - - - - - - - - - 1 - 40 - - - - - 1 - 8 - - - - - - - - 1 - 40 - - - - - 1 - 8 - - - - - - - - - 1 - 40 - - - - - 1 - 8 - - - - - - - - - 1 - 8 - - - 1 - 16 - - - - - 1 - 24 - - - - - - - - 1 - 8 - - - 1 - 8 - - - - - 1 - 16 - - - - - - - - 1 - 24 - - - - - 1 - 24 - - - - - - - - - - - - - - - - - - - )V0G0N"; -} - - -std::string threeCropsWithReshapeModel() { - return R"V0G0N( - - - - - - 1 - 40 - - - - - - - - - 1 - 40 - - - - - 1 - 40 - - - - - - - - - 1 - 40 - - - - - 1 - 8 - - - - - - - - 1 - 40 - - - - - 1 - 8 - - - - - - - - - 1 - 40 - - - - - 1 - 8 - - - - - - - - - 1 - 8 - - - - - 1 - 8 - - - - - - - - - 1 - 8 - - - - - 1 - 8 - - - - - - - - - 1 - 8 - - - - - 1 - 8 - - - - - - - - - 1 - 8 - - - 1 - 16 - - - - - 1 - 24 - - - - - - - - 1 - 8 - - - 1 - 8 - - - - - 1 - 16 - - - - - - - - 1 - 24 - - - - - 1 - 24 - - - - - - - - - - - - - - - - - - - - - - - - )V0G0N"; -} - -std::string PowerWithScaleFactor1() { - return R"V0G0N( - - - - - - - 1 - 10 - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - 1 - 10 - - - - - 1 - 12 - - - - - - - - - - - - - - )V0G0N"; -} - -std::string SplitToConcatThroughScaleShift() { - return R"V0G0N( - - - - - - - 1 - 30 - - - - - - - - 1 - 30 - - - - - 1 - 20 - - - 1 - 10 - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - 1 - 20 - - - 1 - 10 - - - - - 1 - 30 - - - - - - - - 1 - 30 - - - - - 1 - 20 - - - - - - - - - - - 1 - 20 - - - - - 1 - 20 - - - - - - - - - - - - 1 - 20 - - - 1 - 20 - - - - - 1 - 40 - - - - - - - - - - - - - - - - )V0G0N"; - } - -std::string TwoOutputs() { -return R"V0G0N( - - - - - - - 1 - 10 - - - - - - - - 1 - 10 - - - - - 1 - 20 - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - - - )V0G0N"; -} - -std::string TwoOutputsDiffPrecision() { - return R"V0G0N( - - - - - - - 1 - 10 - - - - - - - - 1 - 10 - - - - - 1 - 20 - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - - 1 - 10 - - - - - 1 - 10 - - - - - - - - - - - )V0G0N"; -} - - std::string SplitToConcatWith2Inputs1360NotAlignedNoFC () { - return R"V0G0N( - - - - - - - 1 - 1360 - - - - - - - - 1 - 1360 - - - - - 1 - 880 - - - 1 - 480 - - - - - - - - 1 - 880 - - - 1 - 480 - - - - - 1 - 1360 - - - - - - - - - - - - - )V0G0N"; - } - - std::string SplitToConcatWith2By64InputsAlignedNoFC () { - return R"V0G0N( - - - - - - - 1 - 128 - - - - - - - - 1 - 128 - - - - - 1 - 64 - - - 1 - 64 - - - - - - - - 1 - 64 - - - 1 - 64 - - - - - 1 - 128 - - - - - - - - - - - - - )V0G0N"; - } - - std::string SplitToConcatWith2InputsAlignedNoFC () { - return R"V0G0N( - - - - - - - 1 - 64 - - - - - - - - 1 - 64 - - - - - 1 - 32 - - - 1 - 32 - - - - - - - - 1 - 32 - - - 1 - 32 - - - - - 1 - 64 - - - - - - - - - - - - )V0G0N"; - } - - std::string SplitToConcatWith3InputsAlignedNoFC () { - return R"V0G0N( - - - - - - - 1 - 96 - - - - - - - - 1 - 96 - - - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - - - - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - - - 1 - 96 - - - - - - - - - - - - - - )V0G0N"; - } - - std::string SplitToConcatWith10InputsAlignedNoFC () { - return R"V0G0N( - - - - - - - 1 - 320 - - - - - - - - 1 - 320 - - - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - - - - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - 1 - 32 - - - - - 1 - 320 - - - - - - - - - - - - - - - - - - - - )V0G0N"; - } - - std::string ReshapeConvolutionLessThan48Filters() { - return R"V0G0N( - - - - - - - 1 - 800 - - - - - - - - 1 - 800 - - - - - 1 - 4 - 1 - 200 - - - - - - - - 1 - 4 - 1 - 200 - - - - - 1 - 16 - 1 - 100 - - - - - - - - - - - 1 - 16 - 1 - 100 - - - - - 1 - 1600 - - - - - - - 1 - 1600 - - - - - 1 - 1600 - - - - - - - - - - - - )V0G0N"; - } - -} // namespace GNATestIRs diff --git a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/test_irs.hpp b/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/test_irs.hpp deleted file mode 100644 index 32644be37ed..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/engines/gna/test_irs.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace GNATestIRs { - -std::string FCOnlyModel() ; -std::string Fc2DOutputModel(); -std::string affineToMemoryModel(); -std::string MemoryAfterConcatModel(); -std::string MemoryAndConcatAfterOneNode(); -std::string eltwiseToMemoryModel(); -std::string eltwiseToMemoryModelNoOutput(); -std::string FCWithPaddingAfterSplitModel(); -/// @eltwise layer mode -std::string SliceModelWithAlignedOutputs(); -std::string FCWithPaddingAfterSliceModel(); -std::string twoFCWithPaddingAfterSliceModel(); -std::string eltwiseSummModel(); -std::string eltwiseMulModel(); -std::string doubleConcatModel(); -std::string scaleShiftAffineModel(); -std::string AffineWith2AffineOutputsModel(); -std::string maxpoolAfterRelu(); -std::string TFLeakyReluModel(); -std::string cropWithoutOffsetModel(); -std::string cropWithAlignedOffsetModel(); -std::string cropWithOffsetModel(); -std::string cropWithOffsetAndSecondDimModel(); -std::string cropWithMaxOffsetModel(); -std::string cropWithOffsetExtendedModel(); -std::string twoCropsModel(); -std::string threeCropsModel(); -std::string threeCropsWithReshapeModel(); -std::string copyModel(); -std::string two_inputs_to_affine(); -std::string two_inputs_to_concat(); -std::string affineAfterConvNoPermute(); -std::string affineAfterConvWithPermute(); -std::string ScaleShift3DModel(); -std::string FCOnlyModelFP16(); -std::string concatModelWithConstLayer(); -std::string LSTMCellOnlyModel(); -std::string eltwiseSumModelWithConstLayer(); -std::string TIModelWithLSTMCell1(); -std::string TIModelWithLSTMCell1Aligned(); -std::string TIModelWithLSTMCell2(); -std::string TIModelWithLSTMCell3Aligned(); -std::string InputSplitConcatModel(); -std::string InputSplitConcatModelUnaligned(); -std::string InputSplitConcatReshapeModelUnaligned(); -std::string LSTMCellOnlyModelUnaligned(); -std::string TIModelWithLSTMCell1WithoutScaleShift(); -std::string SplitToConcatThroughScaleShift(); -std::string PowerWithScaleFactor1(); -std::string TwoOutputs(); -std::string TwoOutputsDiffPrecision(); -std::string SplitToConcatWith2InputsAlignedNoFC(); -std::string SplitToConcatWith2Inputs1360NotAlignedNoFC(); -std::string SplitToConcatWith3InputsAlignedNoFC(); -std::string SplitToConcatWith10InputsAlignedNoFC(); -std::string SplitToConcatWith2By64InputsAlignedNoFC(); -std::string ReshapeConvolutionLessThan48Filters(); - -} // namespace GNATestIRs diff --git a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/cnn_ngraph_impl_tests.cpp b/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/cnn_ngraph_impl_tests.cpp deleted file mode 100644 index 253036bfaf5..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/cnn_ngraph_impl_tests.cpp +++ /dev/null @@ -1,2032 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cnn_network_ngraph_impl.hpp" -#include "cnnlayer_utils.hpp" -#include "common_test_utils/common_utils.hpp" -#include "common_test_utils/file_utils.hpp" -#include "ie_precision.hpp" -#include "transformations/rt_info/primitives_priority_attribute.hpp" - -using namespace testing; -using namespace InferenceEngine; - -TEST(CNNNGraphImplTests, TestReshapeWithSameShape) { - std::shared_ptr f; - { - auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1000, 4}); - input->set_friendly_name("input"); - auto shape = ov::op::v0::Constant::create(ngraph::element::i64, {2}, {1, 4000}); - auto reshape = std::make_shared(input, shape, true); - f = std::make_shared(ngraph::OutputVector{reshape}, ngraph::ParameterVector{input}); - } - - auto net = InferenceEngine::CNNNetwork(f); - ASSERT_NO_THROW(net.reshape({{"input", SizeVector({1, 4000})}})); -} - -TEST(CNNNGraphImplTests, TestTwoResultsFromOneTensor) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - auto result1 = std::make_shared(relu); - auto result2 = std::make_shared(relu); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result1, result2}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - ASSERT_NO_THROW(auto convertedNet = std::make_shared(cnnNet)); -} - -TEST(CNNNGraphImplTests, TestInvalidReshape) { - std::shared_ptr f; - { - auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1000, 4}); - input->set_friendly_name("input"); - auto shape = ov::op::v0::Constant::create(ngraph::element::i64, {2}, {1, 4000}); - auto reshape = std::make_shared(input, shape, true); - f = std::make_shared(ngraph::OutputVector{reshape}, ngraph::ParameterVector{input}); - } - - auto net = InferenceEngine::CNNNetwork(f); - ASSERT_ANY_THROW(net.reshape({{"input", SizeVector({4})}})); - - auto param = *net.getFunction()->get_parameters().begin(); - ASSERT_EQ(param->get_output_shape(0), ngraph::Shape({1, 1000, 4})); - - ASSERT_NO_THROW(net.reshape({{"input", SizeVector({1, 1000, 4})}})); -} - -TEST(CNNNGraphImplTests, TestNMS5OutputNames) { - std::shared_ptr f; - { - auto boxes = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1000, 4}); - auto scores = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1000}); - auto max_output_boxes_per_class = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{}, {10}); - auto iou_threshold = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.75}); - auto score_threshold = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.7}); - auto nms = std::make_shared( - boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - ov::opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true); - nms->set_friendly_name("nms"); - f = std::make_shared(ngraph::OutputVector{nms->output(0), nms->output(1), nms->output(2)}, - ngraph::ParameterVector{boxes, scores}); - } - - InferenceEngine::CNNNetwork cnnNet(f); - auto outputs_info = cnnNet.getOutputsInfo(); - ASSERT_EQ(outputs_info.size(), 3); - ASSERT_EQ(outputs_info.count("nms.0"), 1); - ASSERT_EQ(outputs_info.count("nms.1"), 1); - ASSERT_EQ(outputs_info.count("nms.2"), 1); -} - -IE_SUPPRESS_DEPRECATED_START - -TEST(CNNNGraphImplTests, TestConvertWithRemoveLastLayerNetwork) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::i32); - auto param = std::make_shared(type, shape); - param->set_friendly_name("param"); - auto relu = std::make_shared(param); - relu->set_friendly_name("relu"); - auto convert = std::make_shared(relu, ngraph::element::Type_t::i64); - convert->set_friendly_name("convert"); - auto result = std::make_shared(convert); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - auto convertedNet = InferenceEngine::CNNNetwork(std::make_shared(cnnNet)); - // Remove convert layer - InferenceEngine::NetPass::ConvertPrecision(convertedNet, Precision::I64, Precision::I32); - ASSERT_NO_THROW(cloneNet(convertedNet)); -} - -TEST(CNNNGraphImplTests, TestResultWithNotEqualName) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - relu->set_friendly_name("test_layer_name"); - auto result = std::make_shared(relu); - result->set_friendly_name("test_layer_name"); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - ASSERT_NO_THROW(auto convertedNet = std::make_shared(cnnNet)); -} - -TEST(CNNNGraphImplTests, TestGetOutputAfterConvertNetwork) { - const std::string testLayerName = "testReLU"; - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - relu->set_friendly_name(testLayerName); - auto relu2 = std::make_shared(relu); - relu2->set_friendly_name("relu2"); - auto result = std::make_shared(relu2); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - // convert to old representation - InferenceEngine::CNNNetwork convertedNetwork(std::make_shared(cnnNet)); - convertedNetwork.addOutput(testLayerName); - - InferenceEngine::OutputsDataMap outs = cnnNet.getOutputsInfo(); - InferenceEngine::OutputsDataMap convertedOuts = convertedNetwork.getOutputsInfo(); - ASSERT_EQ(1, outs.size()); - ASSERT_EQ(2, convertedOuts.size()); -} - -TEST(CNNNGraphImplTests, TestSetCurrentBatch) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - auto result = std::make_shared(relu); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::details::CNNNetworkNGraphImpl cnnNet(ngraph); - ASSERT_EQ(1, cnnNet.getBatchSize()); - ASSERT_EQ(OK, cnnNet.setBatchSize(1, nullptr)); - ASSERT_EQ(1, cnnNet.getBatchSize()); - ASSERT_NE(nullptr, cnnNet.getFunction()); -} - -TEST(CNNNGraphImplTests, TestSetBatch) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - auto result = std::make_shared(relu); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::details::CNNNetworkNGraphImpl cnnNet(ngraph); - ASSERT_EQ(1, cnnNet.getBatchSize()); - ASSERT_EQ(OK, cnnNet.setBatchSize(2, nullptr)); // must not trigger conversion - ASSERT_EQ(2, cnnNet.getBatchSize()); - ASSERT_NE(nullptr, cnnNet.getFunction()); -} - -TEST(CNNNGraphImplTests, TestGetBatchScalar) { - std::shared_ptr ngraph; - { - ngraph::Shape shape({}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - auto result = std::make_shared(relu); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::details::CNNNetworkNGraphImpl cnnNet(ngraph); - ASSERT_EQ(1, cnnNet.getBatchSize()); -} - -TEST(CNNNGraphImplTests, TestSetBatchScalar) { - std::shared_ptr ngraph; - { - ngraph::Shape shape({}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - auto result = std::make_shared(relu); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::details::CNNNetworkNGraphImpl cnnNet(ngraph); - ASSERT_EQ(1, cnnNet.getBatchSize()); - ASSERT_EQ(PARAMETER_MISMATCH, cnnNet.setBatchSize(2, nullptr)); // must not trigger conversion -} - -TEST(CNNNGraphImplTests, TestGetBatchDynamic) { - std::shared_ptr ngraph; - { - auto param = std::make_shared(ngraph::element::Type_t::f32, - ngraph::PartialShape{5, ngraph::Dimension::dynamic()}); - auto relu = std::make_shared(param); - auto result = std::make_shared(relu); - ngraph = std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{param}); - } - - InferenceEngine::details::CNNNetworkNGraphImpl cnnNet(ngraph); - ASSERT_TRUE(cnnNet.getFunction()->get_parameters()[0]->get_partial_shape().is_dynamic()); - ASSERT_EQ(5, cnnNet.getBatchSize()); -} - -TEST(CNNNGraphImplTests, TestSetBatchDynamic) { - std::shared_ptr ngraph; - { - auto param = - std::make_shared(ngraph::element::Type_t::f32, ngraph::PartialShape::dynamic()); - auto relu = std::make_shared(param); - auto result = std::make_shared(relu); - ngraph = std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{param}); - } - - InferenceEngine::details::CNNNetworkNGraphImpl cnnNet(ngraph); - ASSERT_EQ(1, cnnNet.getBatchSize()); - ASSERT_EQ(PARAMETER_MISMATCH, cnnNet.setBatchSize(2, nullptr)); // must not trigger conversion -} - -TEST(CNNNGraphImplTests, TestDoesChangePrecisionsWithNewAPI) { - std::shared_ptr ngraph; - { - auto param = - std::make_shared(ngraph::element::Type_t::f16, ngraph::PartialShape::dynamic()); - auto relu = std::make_shared(param); - auto result = std::make_shared(relu); - ngraph = std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{param}); - } - - // new OpenVINO 2.0 - { - auto ngraphImpl = std::make_shared( - ngraph, - std::vector{}, - true); - InferenceEngine::CNNNetwork cnnNet(ngraphImpl); - ASSERT_EQ(InferenceEngine::Precision::FP16, - cnnNet.getInputsInfo().begin()->second->getTensorDesc().getPrecision()); - ASSERT_EQ(InferenceEngine::Precision::FP16, - cnnNet.getOutputsInfo().begin()->second->getTensorDesc().getPrecision()); - } - - // current API - { - auto ngraphImpl = std::make_shared(ngraph); - InferenceEngine::CNNNetwork cnnNet(ngraphImpl); - ASSERT_EQ(InferenceEngine::Precision::FP32, - cnnNet.getInputsInfo().begin()->second->getTensorDesc().getPrecision()); - ASSERT_EQ(InferenceEngine::Precision::FP32, - cnnNet.getOutputsInfo().begin()->second->getTensorDesc().getPrecision()); - } -} - -TEST(CNNNGraphImplTests, TestSaveAffinity) { - const std::string testAffinity = "testAffinity"; - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - auto& rtInfo = relu->get_rt_info(); - rtInfo["affinity"] = testAffinity; - relu->set_friendly_name("testReLU"); - auto result = std::make_shared(relu); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - auto convertedNetwork = std::make_shared(cnnNet); - auto cnnLayer = CommonTestUtils::getLayerByName(InferenceEngine::CNNNetwork(convertedNetwork), "testReLU"); - ASSERT_NE(nullptr, cnnLayer); - ASSERT_EQ(cnnLayer->affinity, testAffinity); -} - -TEST(CNNNGraphImplTests, TestAddOutput) { - const std::string testLayerName = "testReLU"; - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - relu->set_friendly_name(testLayerName); - auto relu2 = std::make_shared(relu); - relu2->set_friendly_name("relu2"); - auto result = std::make_shared(relu2); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - ASSERT_NE(nullptr, cnnNet.getFunction()); - ASSERT_EQ(4, cnnNet.layerCount()); - - cnnNet.addOutput(testLayerName); - ASSERT_NE(nullptr, cnnNet.getFunction()); - ASSERT_EQ(5, cnnNet.layerCount()); - auto outputs = cnnNet.getOutputsInfo(); - ASSERT_EQ(2, outputs.size()); - ASSERT_TRUE(outputs.find("relu2") != outputs.end()); - ASSERT_TRUE(outputs.find(testLayerName) != outputs.end()); -} - -TEST(CNNNGraphImplTests, TestAddOutputWithPort) { - const std::string testLayerName = "testReLU"; - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - relu->set_friendly_name(testLayerName); - auto relu2 = std::make_shared(relu); - relu2->set_friendly_name("relu2"); - auto result = std::make_shared(relu2); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - ASSERT_NE(nullptr, cnnNet.getFunction()); - ASSERT_EQ(4, cnnNet.layerCount()); - - cnnNet.addOutput(testLayerName, 0); - ASSERT_NE(nullptr, cnnNet.getFunction()); - ASSERT_EQ(5, cnnNet.layerCount()); - - EXPECT_THROW(cnnNet.addOutput(testLayerName, 1), OutOfBounds); - ASSERT_NE(nullptr, cnnNet.getFunction()); - ASSERT_EQ(5, cnnNet.layerCount()); - - auto outputs = cnnNet.getOutputsInfo(); - ASSERT_EQ(2, outputs.size()); - ASSERT_TRUE(outputs.find("relu2") != outputs.end()); - ASSERT_TRUE(outputs.find(testLayerName) != outputs.end()); -} - -TEST(CNNNGraphImplTests, TestAddOutputTwoTimes) { - const std::string testLayerName = "testReLU"; - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - relu->set_friendly_name(testLayerName); - auto relu2 = std::make_shared(relu); - relu2->set_friendly_name("relu2"); - auto result = std::make_shared(relu2); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - ASSERT_NE(nullptr, cnnNet.getFunction()); - ASSERT_EQ(4, cnnNet.layerCount()); - - cnnNet.addOutput(testLayerName); - ASSERT_NE(nullptr, cnnNet.getFunction()); - ASSERT_EQ(5, cnnNet.layerCount()); - cnnNet.addOutput(testLayerName); - ASSERT_NE(nullptr, cnnNet.getFunction()); - ASSERT_EQ(5, cnnNet.layerCount()); - auto outputs = cnnNet.getOutputsInfo(); - ASSERT_EQ(2, outputs.size()); - ASSERT_TRUE(outputs.find("relu2") != outputs.end()); - ASSERT_TRUE(outputs.find(testLayerName) != outputs.end()); -} - -TEST(CNNNGraphImplTests, TestAddOutputFromConvertedNetwork) { - const std::string testLayerName = "testReLU"; - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - relu->set_friendly_name(testLayerName); - auto relu2 = std::make_shared(relu); - relu2->set_friendly_name("relu2"); - auto result = std::make_shared(relu2); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - ASSERT_NE(nullptr, cnnNet.getFunction()); - ASSERT_EQ(4, cnnNet.layerCount()); - - cnnNet.addOutput(testLayerName); - ASSERT_NE(nullptr, cnnNet.getFunction()); - ASSERT_EQ(5, cnnNet.layerCount()); - // convert to old representation - InferenceEngine::CNNNetwork convertedNetwork(std::make_shared(cnnNet)); - auto outputs = convertedNetwork.getOutputsInfo(); - ASSERT_EQ(2, outputs.size()); - ASSERT_TRUE(outputs.find("relu2") != outputs.end()); - ASSERT_TRUE(outputs.find(testLayerName) != outputs.end()); -} - -TEST(CNNNGraphImplTests, ConstantAsInternalAndExternalLayer) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto constant = ngraph::op::Constant::create(ngraph::element::Type_t::f32, {1}, {2}); - auto prelu = std::make_shared(param, constant); - auto add = std::make_shared(prelu, constant); - auto result = std::make_shared(add); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - auto convertedNetwork = std::make_shared(cnnNet); - ASSERT_EQ(4, convertedNetwork->layerCount()); -} - -TEST(CNNNGraphImplTests, SaveInputInfoAfterConversion) { - std::string name = "param"; - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - param->set_friendly_name(name); - auto constant = ngraph::op::Constant::create(ngraph::element::Type_t::f32, {1}, {2}); - auto prelu = std::make_shared(param, constant); - auto add = std::make_shared(prelu, constant); - auto result = std::make_shared(add); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - auto inputInfo = cnnNet.getInputsInfo()[name]; - ASSERT_EQ(inputInfo->getPreProcess().getResizeAlgorithm(), ResizeAlgorithm::NO_RESIZE); - inputInfo->getPreProcess().setResizeAlgorithm(ResizeAlgorithm::RESIZE_AREA); - ASSERT_EQ(inputInfo->getPreProcess().getResizeAlgorithm(), ResizeAlgorithm::RESIZE_AREA); - - auto cnnNetImpl = std::make_shared(cnnNet); - inputInfo = cnnNetImpl->getInput(name); - ASSERT_EQ(inputInfo->getPreProcess().getResizeAlgorithm(), ResizeAlgorithm::RESIZE_AREA); -} - -TEST(CNNNGraphImplTests, SavePrimitivesPriority) { - std::string model = R"V0G0N( - - - - - - - 1 - 3 - 22 - 22 - - - - - - - 1 - 3 - 22 - 22 - - - - - 1 - 3 - 22 - 22 - - - - - - - 1 - 3 - 22 - 22 - - - - - - - - - -)V0G0N"; - const Core ie; - Blob::Ptr weights; - - auto network = ie.ReadNetwork(model, weights); - auto inputInfo = network.getInputsInfo(); - auto convertedNetwork = std::make_shared(network); - auto cnnLayer = getCreatorLayer(inputInfo.begin()->second->getInputData()).lock(); - ASSERT_NE(nullptr, cnnLayer); - ASSERT_NE(cnnLayer->params.find("PrimitivesPriority"), cnnLayer->params.end()); - ASSERT_EQ("cpu:avx2", cnnLayer->params["PrimitivesPriority"]); -} - -TEST(CNNNGraphImplTests, ReadFromCNNNetReader) { - std::string model = R"V0G0N( - - - - - - - 1 - 3 - 22 - 22 - - - - - - - 1 - 3 - 22 - 22 - - - - - 1 - 3 - 22 - 22 - - - - - - - 1 - 3 - 22 - 22 - - - - - - - - - -)V0G0N"; - InferenceEngine::Core core; - CNNNetwork network = core.ReadNetwork(model, InferenceEngine::Blob::CPtr()); - ASSERT_EQ(3, network.layerCount()); -} - -TEST(CNNNGraphImplTests, ReadMeanImageFromCNNNetReader) { - std::string model = R"V0G0N( - - - - - - - - - - - - - - - - - - 1 - 3 - 22 - 22 - - - - - - - 1 - 3 - 22 - 22 - - - - - 1 - 3 - 22 - 22 - - - - - - - 1 - 3 - 22 - 22 - - - - - - - - - -)V0G0N"; - InferenceEngine::Core core; - size_t hwSize = 22 * 22; - size_t dataSize = hwSize * 3; - Blob::Ptr weights = make_shared_blob(TensorDesc(Precision::FP32, {dataSize}, Layout::C)); - weights->allocate(); - { - auto lockData = weights->buffer(); - float* dataPtr = lockData.as(); - - for (size_t i = 0; i < dataSize; ++i) { - dataPtr[i] = 1; - } - } - CNNNetwork network = core.ReadNetwork(model, weights); - auto f = network.getFunction(); - - std::shared_ptr f_ref; - auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 22, 22}); - { - auto mean_image = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 22, 22}, {1}); - auto sub = std::make_shared(data, mean_image); - auto relu = std::make_shared(sub); - f_ref = std::make_shared(ngraph::NodeVector{relu}, ngraph::ParameterVector{data}); - } - - const auto fc = FunctionsComparator::with_default() - .enable(FunctionsComparator::ATTRIBUTES) - .enable(FunctionsComparator::CONST_VALUES); - const auto res = fc.compare(f, f_ref); - EXPECT_TRUE(res.valid) << res.message; -} - -TEST(CNNNGraphImplTests, ReadMeanValueFromCNNNetReader) { - std::string model = R"V0G0N( - - - - - - - - - - - - - - - - - - 1 - 3 - 22 - 22 - - - - - - - 1 - 3 - 22 - 22 - - - - - 1 - 3 - 22 - 22 - - - - - - - 1 - 3 - 22 - 22 - - - - - - - - - -)V0G0N"; - InferenceEngine::Core core; - Blob::Ptr weights{nullptr}; - CNNNetwork network = core.ReadNetwork(model, weights); - auto f = network.getFunction(); - - std::shared_ptr f_ref; - { - auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 22, 22}); - auto mean_image = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 1, 1}, {1.1, 2.2, 3.3}); - auto sub = std::make_shared(data, mean_image); - auto relu = std::make_shared(sub); - f_ref = std::make_shared(ngraph::NodeVector{relu}, ngraph::ParameterVector{data}); - } - - const auto fc = FunctionsComparator::with_default() - .enable(FunctionsComparator::ATTRIBUTES) - .enable(FunctionsComparator::CONST_VALUES); - const auto res = fc.compare(f, f_ref); - EXPECT_TRUE(res.valid) << res.message; -} - -TEST(CNNNGraphImplTests, CanChangeInputPrecision) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 16, 16}); - ngraph::element::Type type(ngraph::element::Type_t::f16); - auto param = std::make_shared(type, shape); - param->set_friendly_name("input"); - auto relu = std::make_shared(param); - relu->set_friendly_name("output"); - auto result = std::make_shared(relu); - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - { - SCOPED_TRACE("After ctor"); - - const auto inputsInfo = cnnNet.getInputsInfo(); - - ASSERT_EQ(inputsInfo.at("input")->getPrecision(), Precision::FP32) << "FP32 is default presision"; - } - { - SCOPED_TRACE("Manually set input precision"); - - const auto inputsInfo = cnnNet.getInputsInfo(); - - inputsInfo.at("input")->setPrecision(Precision::FP16); - } - InferenceEngine::CNNNetwork convertedNetwork; - { - SCOPED_TRACE("Convert to old format"); - - // convert to old representation - convertedNetwork = - InferenceEngine::CNNNetwork(std::make_shared(cnnNet)); - } - { - SCOPED_TRACE("After conversion"); - - const auto inputsInfo = convertedNetwork.getInputsInfo(); - - ASSERT_EQ(inputsInfo.at("input")->getPrecision(), Precision::FP16) - << "Manually set presision should be left unchanged"; - } -} - -TEST(CNNNGraphImplTests, CanChangeInputLayout) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 16, 16}); - ngraph::element::Type type(ngraph::element::Type_t::f16); - auto param = std::make_shared(type, shape); - param->set_friendly_name("input"); - auto relu = std::make_shared(param); - relu->set_friendly_name("output"); - auto result = std::make_shared(relu); - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - { - SCOPED_TRACE("After ctor"); - - const auto inputsInfo = cnnNet.getInputsInfo(); - - ASSERT_EQ(inputsInfo.at("input")->getLayout(), Layout::NCHW) << "NCHW is default layout"; - } - { - SCOPED_TRACE("Manually set input layout"); - - const auto inputsInfo = cnnNet.getInputsInfo(); - - inputsInfo.at("input")->setLayout(Layout::NHWC); - } - InferenceEngine::CNNNetwork convertedNetwork; - { - SCOPED_TRACE("Convert to old format"); - - // convert to old representation - convertedNetwork = - InferenceEngine::CNNNetwork(std::make_shared(cnnNet)); - } - { - SCOPED_TRACE("After conversion"); - - const auto inputsInfo = convertedNetwork.getInputsInfo(); - - ASSERT_EQ(inputsInfo.at("input")->getLayout(), Layout::NHWC) << "Manually set layout should be left unchanged"; - } -} - -TEST(CNNNGraphImplTests, CanChangeOutputPrecision) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 16, 16}); - ngraph::element::Type type(ngraph::element::Type_t::f16); - auto param = std::make_shared(type, shape); - param->set_friendly_name("input"); - auto relu = std::make_shared(param); - relu->set_friendly_name("output"); - auto result = std::make_shared(relu); - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - { - SCOPED_TRACE("After ctor"); - - const auto outputsInfo = cnnNet.getOutputsInfo(); - - ASSERT_EQ(outputsInfo.at("output")->getPrecision(), Precision::FP32) << "FP32 is default presision"; - } - { - SCOPED_TRACE("Manually set output precision"); - - const auto outputsInfo = cnnNet.getOutputsInfo(); - - outputsInfo.at("output")->setPrecision(Precision::FP16); - } - InferenceEngine::CNNNetwork convertedNetwork; - { - SCOPED_TRACE("Convert to old format"); - - // convert to old representation - convertedNetwork = - InferenceEngine::CNNNetwork(std::make_shared(cnnNet)); - } - { - SCOPED_TRACE("After conversion"); - - const auto outputsInfo = convertedNetwork.getOutputsInfo(); - - ASSERT_EQ(outputsInfo.at("output")->getPrecision(), Precision::FP16) - << "Manually set presision should be left unchanged"; - } -} - -TEST(CNNNGraphImplTests, CanChangeOutputLayout) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 16, 16}); - ngraph::element::Type type(ngraph::element::Type_t::f16); - auto param = std::make_shared(type, shape); - param->set_friendly_name("input"); - auto relu = std::make_shared(param); - relu->set_friendly_name("output"); - auto result = std::make_shared(relu); - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - ngraph = std::make_shared(results, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - { - SCOPED_TRACE("After ctor"); - - const auto outputsInfo = cnnNet.getOutputsInfo(); - - ASSERT_EQ(outputsInfo.at("output")->getLayout(), Layout::NCHW) << "NCHW is default layout"; - } - { - SCOPED_TRACE("Manually set output layout"); - - const auto outputsInfo = cnnNet.getOutputsInfo(); - - outputsInfo.at("output")->setLayout(Layout::NHWC); - } - InferenceEngine::CNNNetwork convertedNetwork; - { - SCOPED_TRACE("Convert to old format"); - - // convert to old representation - convertedNetwork = - InferenceEngine::CNNNetwork(std::make_shared(cnnNet)); - } - { - SCOPED_TRACE("After conversion"); - - const auto outputsInfo = convertedNetwork.getOutputsInfo(); - - ASSERT_EQ(outputsInfo.at("output")->getLayout(), Layout::NHWC) - << "Manually set layout should be left unchanged"; - } -} - -TEST(CNNNGraphImplTests, TestCheckStats) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - auto result = std::make_shared(relu); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - InferenceEngine::details::CNNNetworkNGraphImpl cnnNet(ngraph); -} - -TEST(CNNNGraphImplTests, CanSetBatchReadValue) { - std::shared_ptr ngraph; - { - auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 2}); - auto constant = std::make_shared(ngraph::element::f32, - ngraph::Shape{1, 2}, - std::vector{1, 2}); - - auto read_value = std::make_shared(constant, "variable_id"); - auto assign = std::make_shared(read_value, "variable_id"); - assign->add_control_dependency(read_value); - auto add = std::make_shared(input, read_value); - auto result = std::make_shared(add); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - - ngraph = std::make_shared(results, sinks, params); - } - - InferenceEngine::CNNNetwork cnnNet(ngraph); - auto convertedNet = std::make_shared(cnnNet); - auto status = convertedNet->setBatchSize(4, nullptr); - EXPECT_EQ(status, StatusCode::OK); -} - -TEST(CNNNGraphImplTests, addSameOutput) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - auto shapeof = std::make_shared(param); - auto reshape = std::make_shared(relu, shapeof, true); - reshape->set_friendly_name("reshape"); - auto result = std::make_shared(reshape); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - CNNNetwork cnnNetwork(ngraph); - cnnNetwork.addOutput("reshape"); - auto outputs = cnnNetwork.getOutputsInfo(); - - ASSERT_EQ(outputs.size(), 1); - ASSERT_EQ(outputs.count("reshape"), 1); - ASSERT_EQ(outputs["reshape"]->getLayout(), InferenceEngine::Layout::NCHW); -} - -TEST(CNNNGraphImplTests, addOutput) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - auto relu = std::make_shared(param); - auto shapeof = std::make_shared(param); - auto reshape = std::make_shared(relu, shapeof, true); - reshape->set_friendly_name("reshape"); - auto relu2 = std::make_shared(reshape); - auto result = std::make_shared(relu2); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - CNNNetwork cnnNetwork(ngraph); - cnnNetwork.addOutput("reshape"); - auto outputs = cnnNetwork.getOutputsInfo(); - - ASSERT_EQ(outputs.size(), 2); - ASSERT_EQ(outputs.count("reshape"), 1); - ASSERT_EQ(outputs["reshape"]->getLayout(), InferenceEngine::Layout::NCHW); -} - -TEST(CNNNGraphImplTests, addOutputForParameter) { - std::shared_ptr ngraph; - { - ngraph::PartialShape shape({1, 3, 22, 22}); - ngraph::element::Type type(ngraph::element::Type_t::f32); - auto param = std::make_shared(type, shape); - param->set_friendly_name("param"); - auto relu = std::make_shared(param); - auto result = std::make_shared(relu); - - ngraph::ParameterVector params = {param}; - ngraph::ResultVector results = {result}; - - ngraph = std::make_shared(results, params); - } - - CNNNetwork cnnNetwork(ngraph); - cnnNetwork.addOutput("param"); - { - auto output_info = cnnNetwork.getOutputsInfo(); - ASSERT_EQ(output_info.count("param"), 1); - ASSERT_EQ(output_info["param"]->getTensorDesc().getDims(), SizeVector({1, 3, 22, 22})); - } - - cnnNetwork.reshape({{"param", SizeVector({1, 3, 32, 64})}}); - cnnNetwork.addOutput("param"); - { - auto output_info = cnnNetwork.getOutputsInfo(); - ASSERT_EQ(output_info.count("param"), 1); - ASSERT_EQ(output_info["param"]->getTensorDesc().getDims(), SizeVector({1, 3, 32, 64})); - } -} - -TEST(CNNNGraphImplTests, AddOutputToExperimentalOpOpset6) { - std::string model = R"V0G0N( - - - - - - - 1000 - 4 - - - - - - - - 1 - 256 - 200 - 336 - - - - - - - - 1 - 256 - 100 - 168 - - - - - - - - 1 - 256 - 50 - 84 - - - - - - - - 1 - 256 - 25 - 42 - - - - - - - - 1000 - 4 - - - 1 - 256 - 200 - 336 - - - 1 - 256 - 100 - 168 - - - 1 - 256 - 50 - 84 - - - 1 - 256 - 25 - 42 - - - - - 1000 - 256 - 7 - 7 - - - - - - - 1000 - 256 - 7 - 7 - - - - - 1000 - 256 - 7 - 7 - - - - - - - 1000 - 256 - 7 - 7 - - - - - - - - - - - - - - -)V0G0N"; - InferenceEngine::Core core; - CNNNetwork network = core.ReadNetwork(model, InferenceEngine::Blob::CPtr()); - network.addOutput("exp"); - auto outputs = network.getOutputsInfo(); - ASSERT_NE(outputs.find("exp.0"), outputs.end()); -} - -TEST(CNNNGraphImplTests, AddOutputToExperimentalOp) { - std::string model = R"V0G0N( - - - - - - - 1000 - 4 - - - - - - - - 1 - 256 - 200 - 336 - - - - - - - - 1 - 256 - 100 - 168 - - - - - - - - 1 - 256 - 50 - 84 - - - - - - - - 1 - 256 - 25 - 42 - - - - - - - - 1000 - 4 - - - 1 - 256 - 200 - 336 - - - 1 - 256 - 100 - 168 - - - 1 - 256 - 50 - 84 - - - 1 - 256 - 25 - 42 - - - - - 1000 - 256 - 7 - 7 - - - - - - - 1000 - 256 - 7 - 7 - - - - - 1000 - 256 - 7 - 7 - - - - - - - 1000 - 256 - 7 - 7 - - - - - - - - - - - - - - -)V0G0N"; - InferenceEngine::Core core; - CNNNetwork network = core.ReadNetwork(model, InferenceEngine::Blob::CPtr()); - network.addOutput("exp"); - auto outputs = network.getOutputsInfo(); - ASSERT_NE(outputs.find("exp.0"), outputs.end()); -} - -TEST(CNNNGraphImplTests, SaveOriginalResultNameForMultiOutputOp) { - std::string model = R"V0G0N( - - - - - - - 1000 - 4 - - - - - - - - 1 - 256 - 200 - 336 - - - - - - - - 1 - 256 - 100 - 168 - - - - - - - - 1 - 256 - 50 - 84 - - - - - - - - 1 - 256 - 25 - 42 - - - - - - - - 1000 - 4 - - - 1 - 256 - 200 - 336 - - - 1 - 256 - 100 - 168 - - - 1 - 256 - 50 - 84 - - - 1 - 256 - 25 - 42 - - - - - 1000 - 256 - 7 - 7 - - - - - - - - 1 - 1 - 1 - 1 - - - - - - - 1000 - 256 - 7 - 7 - - - 1 - 1 - 1 - 1 - - - - - 1000 - 256 - 7 - 7 - - - - - - - 1000 - 256 - 7 - 7 - - - - - - - - - - - - - - - -)V0G0N"; - - InferenceEngine::Core core; - Blob::Ptr data = make_shared_blob(TensorDesc(Precision::FP32, {4}, Layout::C)); - data->allocate(); - { - auto lockData = data->buffer(); - float* dataPtr = lockData.as(); - - for (size_t i = 0; i < 4; ++i) { - dataPtr[i] = 0; - } - } - CNNNetwork network = core.ReadNetwork(model, data); - { - auto outputs = network.getOutputsInfo(); - ASSERT_NE(outputs.find("text_features"), outputs.end()); - } - - auto nGraphFunc = network.getFunction(); - - ngraph::pass::Manager manager; - manager.register_pass(); - manager.run_passes(nGraphFunc); - - auto clonedNetwork = InferenceEngine::details::convertFunctionToICNNNetwork(nGraphFunc, network); - { - OutputsDataMap outputs; - clonedNetwork->getOutputsInfo(outputs); - ASSERT_NE(outputs.find("text_features"), outputs.end()); - } -} - -TEST(CNNNGraphImplTests, SaveOriginalResultNameForMultiOutputOpOpset6) { - std::string model = R"V0G0N( - - - - - - - 1000 - 4 - - - - - - - - 1 - 256 - 200 - 336 - - - - - - - - 1 - 256 - 100 - 168 - - - - - - - - 1 - 256 - 50 - 84 - - - - - - - - 1 - 256 - 25 - 42 - - - - - - - - 1000 - 4 - - - 1 - 256 - 200 - 336 - - - 1 - 256 - 100 - 168 - - - 1 - 256 - 50 - 84 - - - 1 - 256 - 25 - 42 - - - - - 1000 - 256 - 7 - 7 - - - - - - - - 1 - 1 - 1 - 1 - - - - - - - 1000 - 256 - 7 - 7 - - - 1 - 1 - 1 - 1 - - - - - 1000 - 256 - 7 - 7 - - - - - - - 1000 - 256 - 7 - 7 - - - - - - - - - - - - - - - -)V0G0N"; - - InferenceEngine::Core core; - Blob::Ptr data = make_shared_blob(TensorDesc(Precision::FP32, {4}, Layout::C)); - data->allocate(); - { - auto lockData = data->buffer(); - float* dataPtr = lockData.as(); - - for (size_t i = 0; i < 4; ++i) { - dataPtr[i] = 0; - } - } - CNNNetwork network = core.ReadNetwork(model, data); - { - auto outputs = network.getOutputsInfo(); - ASSERT_NE(outputs.find("text_features"), outputs.end()); - } - - auto nGraphFunc = network.getFunction(); - - ngraph::pass::Manager manager; - - manager.register_pass(); - - manager.run_passes(nGraphFunc); - - auto clonedNetwork = InferenceEngine::details::convertFunctionToICNNNetwork(nGraphFunc, network); - { - OutputsDataMap outputs; - clonedNetwork->getOutputsInfo(outputs); - ASSERT_NE(outputs.find("text_features"), outputs.end()); - } -} - -TEST(CNNNGraphImplTests, CheckUniqueNames) { - std::shared_ptr f; - { - auto boxes = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1000, 4}); - boxes->set_friendly_name("boxes"); - auto scores = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1000}); - scores->set_friendly_name("scores"); - auto max_output_boxes_per_class = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{}, {10}); - auto iou_threshold = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.75}); - auto score_threshold = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.7}); - auto nms = std::make_shared( - boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - ov::opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true); - - auto result1 = std::make_shared(nms->output(0)); - result1->set_friendly_name("result1"); - auto result2 = std::make_shared(nms->output(1)); - result2->set_friendly_name("result2"); - auto result3 = std::make_shared(nms->output(2)); - result3->set_friendly_name("result3"); - nms->set_friendly_name("nms"); - f = std::make_shared(ngraph::ResultVector{result1, result2, result3}, - ngraph::ParameterVector{boxes, scores}); - } - - ASSERT_NO_THROW(InferenceEngine::CNNNetwork{f}); -} - -TEST(CNNNGraphImplTests, CheckNonUniqueParameterName) { - std::shared_ptr f; - { - auto boxes = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1000, 4}); - boxes->set_friendly_name("boxes"); - auto scores = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1000}); - scores->set_friendly_name("boxes"); - auto max_output_boxes_per_class = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{}, {10}); - auto iou_threshold = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.75}); - auto score_threshold = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.7}); - auto nms = std::make_shared( - boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - ov::opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true); - - auto result1 = std::make_shared(nms->output(0)); - result1->set_friendly_name("result1"); - auto result2 = std::make_shared(nms->output(1)); - result2->set_friendly_name("result2"); - auto result3 = std::make_shared(nms->output(2)); - result3->set_friendly_name("result3"); - nms->set_friendly_name("nms"); - f = std::make_shared(ngraph::ResultVector{result1, result2, result3}, - ngraph::ParameterVector{boxes, scores}); - } - - ASSERT_THROW(InferenceEngine::CNNNetwork{f}, InferenceEngine::Exception); -} - -TEST(CNNNGraphImplTests, CheckNonUniqueResultName) { - std::shared_ptr f; - { - auto boxes = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1000, 4}); - boxes->set_friendly_name("nms.1"); - auto scores = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1000}); - scores->set_friendly_name("scores"); - auto max_output_boxes_per_class = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{}, {10}); - auto iou_threshold = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.75}); - auto score_threshold = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.7}); - auto nms = std::make_shared( - boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - ov::opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true); - - auto result1 = std::make_shared(nms->output(0)); - result1->set_friendly_name("result1"); - auto result2 = std::make_shared(nms->output(1)); - result2->set_friendly_name("result2"); - auto result3 = std::make_shared(nms->output(2)); - result3->set_friendly_name("result3"); - nms->set_friendly_name("nms"); - f = std::make_shared(ngraph::ResultVector{result1, result2, result3}, - ngraph::ParameterVector{boxes, scores}); - } - - ASSERT_THROW(InferenceEngine::CNNNetwork{f}, InferenceEngine::Exception); -} - -TEST(CNNNGraphImplTests, CheckNonUniqueNewResultName) { - std::shared_ptr f; - { - auto boxes = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1000, 4}); - boxes->set_friendly_name("nms.1"); - auto scores = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1000}); - scores->set_friendly_name("scores"); - auto max_output_boxes_per_class = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{}, {10}); - auto iou_threshold = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.75}); - auto score_threshold = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.7}); - auto nms = std::make_shared( - boxes, - scores, - max_output_boxes_per_class, - iou_threshold, - score_threshold, - ov::opset5::NonMaxSuppression::BoxEncodingType::CORNER, - true); - - auto result1 = std::make_shared(nms->output(0)); - result1->set_friendly_name("result1"); - auto result3 = std::make_shared(nms->output(2)); - result3->set_friendly_name("result3"); - nms->set_friendly_name("nms"); - f = std::make_shared(ngraph::ResultVector{result1, result3}, - ngraph::ParameterVector{boxes, scores}); - } - - CNNNetwork cnnNet; - ASSERT_NO_THROW(cnnNet = InferenceEngine::CNNNetwork{f}); - ASSERT_THROW(cnnNet.addOutput("nms", 1), InferenceEngine::Exception); -} - -TEST(CNNNGraphImplTests, RemoveLoopDanglingParametersIfConcatEmptyTensor) { - CNNNetwork network; - - auto trip_count = std::make_shared(ov::element::i64, ov::Shape{}, 10); - auto condition = std::make_shared(ov::element::boolean, ov::Shape{}, true); - - auto a = std::make_shared(ov::element::f32, ov::Shape{2, 2}); - auto ai = std::make_shared(ov::element::f32, ov::Shape{2, 2}); - auto b = std::make_shared(ov::element::f32, ov::Shape{2}); - auto b_broadcast = - std::make_shared(b, ov::op::v0::Constant::create(ngraph::element::i64, {2}, {0, 2})); - auto bi = std::make_shared(ov::element::f32, ov::Shape{0, 2}); - { - auto concat = std::make_shared(ov::NodeVector{ai, bi}, 0); - auto body = std::make_shared(ov::OutputVector{condition, concat}, ov::ParameterVector{ai, bi}); - auto loop = std::make_shared(trip_count, condition); - loop->set_special_body_ports({-1, 0}); - loop->set_function(body); - loop->set_invariant_input(ai, a); - loop->set_invariant_input(bi, b_broadcast); - - auto loop_res = std::make_shared(loop->get_iter_value(concat)); - auto model = std::make_shared(ov::OutputVector{loop_res}, ov::ParameterVector{a, b}); - - network = CNNNetwork(model); - } - { - auto concat = std::make_shared(ov::NodeVector{ai}, 0); - auto body = std::make_shared(ov::OutputVector{condition, concat}, ov::ParameterVector{ai}); - auto loop = std::make_shared(trip_count, condition); - loop->set_special_body_ports({-1, 0}); - loop->set_function(body); - loop->set_invariant_input(ai, a); - - auto loop_res = std::make_shared(loop->get_iter_value(concat)); - auto model_ref = std::make_shared(ov::OutputVector{loop_res}, ov::ParameterVector{a, b}); - - const auto fc = FunctionsComparator::with_default() - .enable(FunctionsComparator::ATTRIBUTES) - .enable(FunctionsComparator::CONST_VALUES); - const auto res = fc.compare(network.getFunction(), model_ref); - EXPECT_TRUE(res.valid) << res.message; - } -} - -IE_SUPPRESS_DEPRECATED_END diff --git a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/get_num_iterations_test.cpp b/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/get_num_iterations_test.cpp deleted file mode 100644 index 4fc14a848bb..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/get_num_iterations_test.cpp +++ /dev/null @@ -1,478 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include "single_layer_common.hpp" - -namespace { - -using InferenceEngine::details::operator<<; - -struct From { - explicit From(int new_value) : value(new_value) {} - int value; -}; - -struct Axis { - explicit Axis(int new_value) : value(new_value) {} - int value; -}; - -struct Start { - explicit Start(int new_value) : value(new_value) {} - int value; -}; - -struct Stride { - explicit Stride(int new_value) : value(new_value) {} - int value; -}; - -struct End { - explicit End(int new_value) : value(new_value) {} - int value; -}; - -class PortMap : public InferenceEngine::TensorIterator::PortMap { -public: - PortMap() = default; - PortMap(From new_from, Axis new_axis, Start new_start, Stride new_stride, End new_end) : InferenceEngine::TensorIterator::PortMap() { - from = new_from.value; - to = -1; - axis = new_axis.value; - - start = new_start.value; - stride = new_stride.value; - end = new_end.value; - - part_size = -1; - } - - friend std::ostream& operator<<(std::ostream& stream, const PortMap& object) { - stream << "{"; - stream << "from:" << object.from; - stream << ", axis: " << object.axis; - stream << ", start: " << object.start; - stream << ", stride: " << object.stride; - stream << ", end: " << object.end; - stream << "}"; - return stream;; - } -}; - -struct NegativeTestParams { - std::vector inputsDimensions; - std::vector inputRules; - - std::vector outputsDimensions; - std::vector outputRules; - - friend std::ostream& operator<<(std::ostream& stream, const NegativeTestParams& object) { - stream << "{"; - stream << "inputs: " << object.inputsDimensions; - stream << ", inputRules: " << object.inputRules; - stream << ", outputs: " << object.outputsDimensions; - stream << ", outputRules: " << object.outputRules; - stream << "}"; - return stream; - } -}; - -class GetNumIterationsTests : public testing::Test { -public: - void SetUp() override { - tensorIterator = std::make_shared( - InferenceEngine::LayerParams{"TI", "TensorIterator", InferenceEngine::Precision::UNSPECIFIED}); - } - - void TearDown() override { - tensorIterator.reset(); - } - - void BuildTensorIterator( - const std::vector& inputsDimensions, - const std::vector& inputRules, - const std::vector& outputsDimensions, - const std::vector& outputRules) { - std::transform(inputsDimensions.begin(), inputsDimensions.end(), std::back_inserter(inputsHandle), createData); - std::transform(outputsDimensions.begin(), outputsDimensions.end(), std::back_inserter(tensorIterator->outData), createData); - tensorIterator->insData = getInputs(); - - tensorIterator->input_port_map = getRules(inputRules); - tensorIterator->output_port_map = getRules(outputRules); - } - - int Run() const { - return getNumIteration(*tensorIterator); - } -private: - static InferenceEngine::DataPtr createData(const InferenceEngine::SizeVector& dimensions) { - const auto tensorDescriptor = InferenceEngine::TensorDesc{InferenceEngine::Precision::UNSPECIFIED, dimensions, InferenceEngine::Layout::ANY}; - return std::make_shared("", tensorDescriptor); - } - - std::vector getInputs() const { - std::vector inputs; - std::transform(inputsHandle.begin(), inputsHandle.end(), std::back_inserter(inputs), - [](const InferenceEngine::DataPtr& data) -> InferenceEngine::DataWeakPtr { return data; }); - return inputs; - } - - static std::vector getRules(const std::vector& testParam) { - std::vector rules; - std::transform(testParam.begin(), testParam.end(), std::back_inserter(rules), - [](const PortMap& rule) -> InferenceEngine::TensorIterator::PortMap { return rule; }); - return rules; - } - - std::shared_ptr tensorIterator; - std::vector inputsHandle; -}; - -class GetNumIterationsNegativeTests : public GetNumIterationsTests, public testing::WithParamInterface { -public: - void SetUp() override { - GetNumIterationsTests::SetUp(); - - const auto& parameters = GetParam(); - BuildTensorIterator(parameters.inputsDimensions, parameters.inputRules, parameters.outputsDimensions, parameters.outputRules); - } -}; - -using GetNumIterationsInvalidAxisTests = GetNumIterationsNegativeTests; -TEST_P(GetNumIterationsInvalidAxisTests, InvalidAxisThrowsAnException) { - ASSERT_ANY_THROW(Run()); -} -INSTANTIATE_TEST_SUITE_P(NumIterationsTest, GetNumIterationsInvalidAxisTests, testing::Values( - NegativeTestParams{{{1}}, {{From{0}, Axis{-2}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1}}, {{From{0}, Axis{10}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1}, {1, 2}}, {{From{0}, Axis{-2}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1}, {1, 2}}, {{From{0}, Axis{10}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1}, {1, 2}}, {{From{0}, Axis{1}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1, 2}, {1}}, {{From{1}, Axis{-2}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1, 2}, {1}}, {{From{1}, Axis{10}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1, 2}, {1}}, {{From{1}, Axis{1}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1}, {1}}, {{From{0}, Axis{-2}, Start{0}, Stride{1}, End{1}}, {From{1}, Axis{-2}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1}, {1}}, {{From{0}, Axis{10}, Start{0}, Stride{1}, End{1}}, {From{1}, Axis{10}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1}, {1}}, {{From{0}, Axis{1}, Start{0}, Stride{1}, End{1}}, {From{1}, Axis{1}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - - NegativeTestParams{{}, {}, {{1}}, {{From{0}, Axis{-2}, Start{0}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1}}, {{From{0}, Axis{10}, Start{0}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1}, {1, 2}}, {{From{0}, Axis{-2}, Start{0}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1}, {1, 2}}, {{From{0}, Axis{10}, Start{0}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1}, {1, 2}}, {{From{0}, Axis{1}, Start{0}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1, 2}, {1}}, {{From{1}, Axis{-2}, Start{0}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1, 2}, {1}}, {{From{1}, Axis{10}, Start{0}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1, 2}, {1}}, {{From{1}, Axis{1}, Start{0}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1}, {1}}, {{From{0}, Axis{-2}, Start{0}, Stride{1}, End{1}}, {From{1}, Axis{-2}, Start{0}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1}, {1}}, {{From{0}, Axis{10}, Start{0}, Stride{1}, End{1}}, {From{1}, Axis{10}, Start{0}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1}, {1}}, {{From{0}, Axis{1}, Start{0}, Stride{1}, End{1}}, {From{1}, Axis{1}, Start{0}, Stride{1}, End{1}}}} -)); - -using GetNumIterationsInvalidStartTests = GetNumIterationsNegativeTests; -TEST_P(GetNumIterationsInvalidStartTests, InvalidStartThrowsAnException) { - ASSERT_ANY_THROW(Run()); -} -INSTANTIATE_TEST_SUITE_P(NumIterationsTest, GetNumIterationsInvalidStartTests, testing::Values( - NegativeTestParams{{{1}}, {{From{0}, Axis{0}, Start{2}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1}, {1, 2}}, {{From{0}, Axis{0}, Start{2}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1}, {1, 2}}, {{From{1}, Axis{0}, Start{2}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1}, {1, 2}}, {{From{1}, Axis{1}, Start{2}, Stride{1}, End{1}}}, {}, {}}, - - NegativeTestParams{{}, {}, {{1}}, {{From{0}, Axis{0}, Start{2}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1}, {1, 2}}, {{From{0}, Axis{0}, Start{2}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1}, {1, 2}}, {{From{1}, Axis{0}, Start{2}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1}, {1, 2}}, {{From{1}, Axis{1}, Start{2}, Stride{1}, End{1}}}} -)); - -using GetNumIterationsInvalidEndTests = GetNumIterationsNegativeTests; -TEST_P(GetNumIterationsInvalidEndTests, InvalidEndThrowsAnException) { - ASSERT_ANY_THROW(Run()); -} -INSTANTIATE_TEST_SUITE_P(NumIterationsTest, GetNumIterationsInvalidEndTests, testing::Values( - NegativeTestParams{{}, {}, {{1}}, {{From{0}, Axis{0}, Start{0}, Stride{1}, End{2}}}}, - NegativeTestParams{{}, {}, {{1}, {1, 2}}, {{From{0}, Axis{0}, Start{0}, Stride{1}, End{2}}}}, - NegativeTestParams{{}, {}, {{1}, {1, 2}}, {{From{1}, Axis{0}, Start{0}, Stride{1}, End{2}}}} -)); - -using GetNumIterationsInvalidStrideTests = GetNumIterationsNegativeTests; -TEST_P(GetNumIterationsInvalidStrideTests, InvalidStrideThrowsAnException) { - ASSERT_ANY_THROW(Run()); -} -INSTANTIATE_TEST_SUITE_P(NumIterationsTest, GetNumIterationsInvalidStrideTests, testing::Values( - NegativeTestParams{{{1}}, {{From{0}, Axis{0}, Start{0}, Stride{0}, End{1}}}, {}, {}}, - NegativeTestParams{{}, {}, {{1}}, {{From{0}, Axis{0}, Start{0}, Stride{0}, End{1}}}} -)); - -using GetNumIterationsInvalidFromTests = GetNumIterationsNegativeTests; -TEST_P(GetNumIterationsInvalidFromTests, InvalidFromThrowsAnException) { - ASSERT_ANY_THROW(Run()); -} -INSTANTIATE_TEST_SUITE_P(NumIterationsTest, GetNumIterationsInvalidFromTests, testing::Values( - NegativeTestParams{{{1}}, {{From{-1}, Axis{0}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - NegativeTestParams{{{1}}, {{From{1}, Axis{0}, Start{0}, Stride{1}, End{1}}}, {}, {}}, - - NegativeTestParams{{}, {}, {{1}}, {{From{-1}, Axis{0}, Start{0}, Stride{1}, End{1}}}}, - NegativeTestParams{{}, {}, {{1}}, {{From{1}, Axis{0}, Start{0}, Stride{1}, End{1}}}} -)); - -using GetNumIterationsInvalidDirectionTests = GetNumIterationsNegativeTests; -TEST_P(GetNumIterationsInvalidDirectionTests, InvalidDirectionThrowsAnException) { - ASSERT_ANY_THROW(Run()); -} -INSTANTIATE_TEST_SUITE_P(NumIterationsTest, GetNumIterationsInvalidDirectionTests, testing::Values( - NegativeTestParams{{{10}}, {{From{0}, Axis{0}, Start{8}, Stride{1}, End{2}}}, {}, {}}, - NegativeTestParams{{{10}}, {{From{0}, Axis{0}, Start{2}, Stride{-1}, End{8}}}, {}, {}}, - - NegativeTestParams{{}, {}, {{10}}, {{From{0}, Axis{0}, Start{8}, Stride{1}, End{2}}}}, - NegativeTestParams{{}, {}, {{10}}, {{From{0}, Axis{0}, Start{2}, Stride{-1}, End{8}}}} -)); - -using GetNumIterationsInvalidStepTests = GetNumIterationsNegativeTests; -TEST_P(GetNumIterationsInvalidStepTests, InvalidStepThrowsAnException) { - ASSERT_ANY_THROW(Run()); -} -INSTANTIATE_TEST_SUITE_P(NumIterationsTest, GetNumIterationsInvalidStepTests, testing::Values( - NegativeTestParams{{{10}}, {{From{0}, Axis{0}, Start{2}, Stride{3}, End{6}}}, {}, {}}, - NegativeTestParams{{{10}}, {{From{0}, Axis{0}, Start{2}, Stride{8}, End{6}}}, {}, {}}, - NegativeTestParams{{{10}}, {{From{0}, Axis{0}, Start{6}, Stride{-3}, End{2}}}, {}, {}}, - NegativeTestParams{{{10}}, {{From{0}, Axis{0}, Start{6}, Stride{-8}, End{2}}}, {}, {}}, - - NegativeTestParams{{}, {}, {{10}}, {{From{0}, Axis{0}, Start{2}, Stride{3}, End{6}}}}, - NegativeTestParams{{}, {}, {{10}}, {{From{0}, Axis{0}, Start{2}, Stride{8}, End{6}}}}, - NegativeTestParams{{}, {}, {{10}}, {{From{0}, Axis{0}, Start{6}, Stride{-3}, End{2}}}}, - NegativeTestParams{{}, {}, {{10}}, {{From{0}, Axis{0}, Start{6}, Stride{-8}, End{2}}}} -)); - -using GetNumIterationsInvalidIterationNumbersTests = GetNumIterationsNegativeTests; -TEST_P(GetNumIterationsInvalidIterationNumbersTests, InvalidInterationNumbersThrowAnException) { - ASSERT_ANY_THROW(Run()); -} -INSTANTIATE_TEST_SUITE_P(NumIterationsTest, GetNumIterationsInvalidIterationNumbersTests, testing::Values( - NegativeTestParams{ - { - {1, 3, 24, 24}, - {1, 3, 24, 24} - }, - { - {From{0}, Axis{2}, Start{0}, Stride{1}, End{-1}}, - {From{1}, Axis{2}, Start{0}, Stride{2}, End{-1}} - }, {}, {} - }, - NegativeTestParams{ - { - {1, 3, 24, 24}, - {1, 3, 24, 24}, - {1, 3, 48, 10} - }, - { - {From{0}, Axis{2}, Start{0}, Stride{1}, End{-1}}, - {From{1}, Axis{2}, Start{0}, Stride{2}, End{-1}}, - {From{2}, Axis{3}, Start{0}, Stride{2}, End{-1}} - }, {}, {} - }, - NegativeTestParams{ - { - {1, 3, 24, 24}, - {1, 3, 48, 24}, - {1, 3, 48, 10} - }, - { - {From{0}, Axis{2}, Start{0}, Stride{1}, End{-1}}, - {From{1}, Axis{2}, Start{0}, Stride{2}, End{-1}}, - {From{2}, Axis{3}, Start{0}, Stride{2}, End{-1}} - }, {}, {} - }, - NegativeTestParams{ - { - {1, 3, 24, 24}, - {1, 3, 24, 24} - }, - { - {From{0}, Axis{2}, Start{0}, Stride{24}, End{-1}}, - {From{1}, Axis{2}, Start{0}, Stride{12}, End{-1}} - }, {}, {} - }, - - NegativeTestParams{ - {}, {}, - { - {1, 3, 24, 24}, - {1, 3, 24, 24}}, - { - {From{0}, Axis{2}, Start{0}, Stride{1}, End{-1}}, - {From{1}, Axis{2}, Start{0}, Stride{2}, End{-1}} - } - }, - NegativeTestParams{ - {}, {}, - { - {1, 3, 24, 24}, - {1, 3, 24, 24}, - {1, 3, 48, 10} - }, - { - {From{0}, Axis{2}, Start{0}, Stride{1}, End{-1}}, - {From{1}, Axis{2}, Start{0}, Stride{2}, End{-1}}, - {From{2}, Axis{3}, Start{0}, Stride{2}, End{-1}} - } - }, - NegativeTestParams{ - {}, {}, - { - {1, 3, 24, 24}, - {1, 3, 48, 24}, - {1, 3, 48, 10} - }, - { - {From{0}, Axis{2}, Start{0}, Stride{1}, End{-1}}, - {From{1}, Axis{2}, Start{0}, Stride{2}, End{-1}}, - {From{2}, Axis{3}, Start{0}, Stride{2}, End{-1}} - } - }, - NegativeTestParams{ - {}, {}, - { - {1, 3, 24, 24}, - {1, 3, 24, 24} - }, - { - {From{0}, Axis{2}, Start{0}, Stride{24}, End{-1}}, - {From{1}, Axis{2}, Start{0}, Stride{12}, End{-1}} - }, - }, - NegativeTestParams{ - { - {1, 3, 24, 24} - }, - { - {From{0}, Axis{2}, Start{0}, Stride{1}, End{-1}} - }, - { - {1, 3, 24, 24} - }, - { - {From{0}, Axis{2}, Start{0}, Stride{2}, End{-1}} - } - }, - NegativeTestParams{ - { - {1, 3, 24, 24}, - {1, 3, 10, 48} - }, - { - {From{0}, Axis{2}, Start{0}, Stride{ 1}, End{-1}}, - {From{1}, Axis{3}, Start{-1}, Stride{-2}, End{0}}, - }, - { - {1, 3, 48, 24}, - {1, 3, 24, 48} - }, - { - {From{0}, Axis{2}, Start{0}, Stride{1}, End{-1}}, - {From{1}, Axis{3}, Start{0}, Stride{1}, End{-1}}, - } - } -)); - -struct PositiveTestParams { - std::vector inputsDimensions; - std::vector inputRules; - - std::vector outputsDimensions; - std::vector outputRules; - int reference; - - friend std::ostream& operator<<(std::ostream& stream, const PositiveTestParams& object) { - stream << "{"; - stream << "inputs: " << object.inputsDimensions; - stream << ", inputRules: " << object.inputRules; - stream << ", outputs: " << object.outputsDimensions; - stream << ", outputRules: " << object.outputRules; - stream << ", reference: " << object.reference; - stream << "}"; - return stream; - } -}; - -class GetNumIterationsPositiveTests : public GetNumIterationsTests, public testing::WithParamInterface { -public: - void SetUp() override { - GetNumIterationsTests::SetUp(); - - const auto& parameters = GetParam(); - BuildTensorIterator(parameters.inputsDimensions, parameters.inputRules, parameters.outputsDimensions, parameters.outputRules); - reference = parameters.reference; - } - - void Check() const { - ASSERT_EQ(GetNumIterationsTests::Run(), reference); - } -private: - int reference = -1; -}; - -TEST_P(GetNumIterationsPositiveTests, CanGetNumIterations) { - Check(); -} -std::vector g_positiveTestParameters = { - {{{1}}, {{From{0}, Axis{0}, Start{ 0}, Stride{ 1}, End{ 1}}}, {}, {}, 1}, - {{{1}}, {{From{0}, Axis{0}, Start{ 0}, Stride{ 1}, End{-1}}}, {}, {}, 1}, - {{{1}}, {{From{0}, Axis{0}, Start{-2}, Stride{ 1}, End{ 1}}}, {}, {}, 1}, - {{{1}}, {{From{0}, Axis{0}, Start{-2}, Stride{ 1}, End{-1}}}, {}, {}, 1}, - {{{1}}, {{From{0}, Axis{0}, Start{ 1}, Stride{-1}, End{ 0}}}, {}, {}, 1}, - {{{1}}, {{From{0}, Axis{0}, Start{-1}, Stride{-1}, End{ 0}}}, {}, {}, 1}, - {{{1}}, {{From{0}, Axis{0}, Start{ 1}, Stride{-1}, End{-2}}}, {}, {}, 1}, - {{{1}}, {{From{0}, Axis{0}, Start{-1}, Stride{-1}, End{-2}}}, {}, {}, 1}, - {{{7}}, {{From{0}, Axis{0}, Start{ 0}, Stride{ 7}, End{ 7}}}, {}, {}, 1}, - {{{7}}, {{From{0}, Axis{0}, Start{-1}, Stride{-7}, End{ 0}}}, {}, {}, 1}, - {{{1, 1}}, {{From{0}, Axis{1}, Start{ 0}, Stride{ 1}, End{ 1}}}, {}, {}, 1}, - {{{1, 1}}, {{From{0}, Axis{1}, Start{ 0}, Stride{ 1}, End{-1}}}, {}, {}, 1}, - {{{1, 1}}, {{From{0}, Axis{1}, Start{-2}, Stride{ 1}, End{ 1}}}, {}, {}, 1}, - {{{1, 1}}, {{From{0}, Axis{1}, Start{-2}, Stride{ 1}, End{-1}}}, {}, {}, 1}, - {{{1, 1}}, {{From{0}, Axis{1}, Start{ 1}, Stride{-1}, End{ 0}}}, {}, {}, 1}, - {{{1, 1}}, {{From{0}, Axis{1}, Start{-1}, Stride{-1}, End{ 0}}}, {}, {}, 1}, - {{{1, 1}}, {{From{0}, Axis{1}, Start{ 1}, Stride{-1}, End{-2}}}, {}, {}, 1}, - {{{1, 1}}, {{From{0}, Axis{1}, Start{-1}, Stride{-1}, End{-2}}}, {}, {}, 1}, - {{{1, 7}}, {{From{0}, Axis{1}, Start{ 0}, Stride{ 7}, End{ 7}}}, {}, {}, 1}, - {{{1, 7}}, {{From{0}, Axis{1}, Start{-1}, Stride{-7}, End{ 0}}}, {}, {}, 1}, - {{{13}}, {{From{0}, Axis{0}, Start{ 3}, Stride{ 1}, End{ 13}}}, {}, {}, 10}, - {{{13}}, {{From{0}, Axis{0}, Start{-11}, Stride{ 1}, End{ 13}}}, {}, {}, 10}, - {{{13}}, {{From{0}, Axis{0}, Start{ 3}, Stride{ 2}, End{ 13}}}, {}, {}, 5}, - {{{13}}, {{From{0}, Axis{0}, Start{-11}, Stride{ 2}, End{ 13}}}, {}, {}, 5}, - {{{13}}, {{From{0}, Axis{0}, Start{ 0}, Stride{ 1}, End{ 10}}}, {}, {}, 10}, - {{{13}}, {{From{0}, Axis{0}, Start{ 0}, Stride{ 1}, End{ -4}}}, {}, {}, 10}, - {{{13}}, {{From{0}, Axis{0}, Start{ 0}, Stride{ 2}, End{ 10}}}, {}, {}, 5}, - {{{13}}, {{From{0}, Axis{0}, Start{ 0}, Stride{ 2}, End{ -4}}}, {}, {}, 5}, - {{{13}}, {{From{0}, Axis{0}, Start{ 3}, Stride{ 1}, End{ 10}}}, {}, {}, 7}, - {{{13}}, {{From{0}, Axis{0}, Start{-11}, Stride{ 1}, End{ -4}}}, {}, {}, 7}, - {{{13}}, {{From{0}, Axis{0}, Start{ 3}, Stride{ 2}, End{ 9}}}, {}, {}, 3}, - {{{13}}, {{From{0}, Axis{0}, Start{-11}, Stride{ 2}, End{ -5}}}, {}, {}, 3}, - {{{13}}, {{From{0}, Axis{0}, Start{ 3}, Stride{ 1}, End{ -4}}}, {}, {}, 7}, - {{{13}}, {{From{0}, Axis{0}, Start{ 3}, Stride{ 2}, End{ -5}}}, {}, {}, 3}, - {{{13}}, {{From{0}, Axis{0}, Start{-11}, Stride{ 1}, End{ 10}}}, {}, {}, 7}, - {{{13}}, {{From{0}, Axis{0}, Start{-11}, Stride{ 2}, End{ 9}}}, {}, {}, 3}, - {{{13}}, {{From{0}, Axis{0}, Start{ 13}, Stride{-1}, End{ 3}}}, {}, {}, 10}, - {{{13}}, {{From{0}, Axis{0}, Start{ 13}, Stride{-1}, End{-11}}}, {}, {}, 10}, - {{{13}}, {{From{0}, Axis{0}, Start{ 13}, Stride{-2}, End{ 3}}}, {}, {}, 5}, - {{{13}}, {{From{0}, Axis{0}, Start{ 13}, Stride{-2}, End{-11}}}, {}, {}, 5}, - {{{13}}, {{From{0}, Axis{0}, Start{ 10}, Stride{-1}, End{ 0}}}, {}, {}, 10}, - {{{13}}, {{From{0}, Axis{0}, Start{ -4}, Stride{-1}, End{ 0}}}, {}, {}, 10}, - {{{13}}, {{From{0}, Axis{0}, Start{ 10}, Stride{-2}, End{ 0}}}, {}, {}, 5}, - {{{13}}, {{From{0}, Axis{0}, Start{ -4}, Stride{-2}, End{ 0}}}, {}, {}, 5}, - {{{13}}, {{From{0}, Axis{0}, Start{ 10}, Stride{-1}, End{ 3}}}, {}, {}, 7}, - {{{13}}, {{From{0}, Axis{0}, Start{ -4}, Stride{-1}, End{-11}}}, {}, {}, 7}, - {{{13}}, {{From{0}, Axis{0}, Start{ 9}, Stride{-2}, End{ 3}}}, {}, {}, 3}, - {{{13}}, {{From{0}, Axis{0}, Start{ -5}, Stride{-2}, End{-11}}}, {}, {}, 3}, - {{{13}}, {{From{0}, Axis{0}, Start{ -4}, Stride{-1}, End{ 3}}}, {}, {}, 7}, - {{{13}}, {{From{0}, Axis{0}, Start{ -5}, Stride{-2}, End{ 3}}}, {}, {}, 3}, - {{{13}}, {{From{0}, Axis{0}, Start{ 10}, Stride{-1}, End{-11}}}, {}, {}, 7}, - {{{13}}, {{From{0}, Axis{0}, Start{ 9}, Stride{-2}, End{-11}}}, {}, {}, 3} -}; -INSTANTIATE_TEST_SUITE_P(NumIterationsTest, GetNumIterationsPositiveTests, testing::ValuesIn(g_positiveTestParameters)); - -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/layer_transform_test.cpp b/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/layer_transform_test.cpp deleted file mode 100644 index ea8a30c95bd..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/layer_transform_test.cpp +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include - -#include "unit_test_utils/mocks/mock_icnn_network.hpp" - -using namespace std; -using namespace InferenceEngine; -using namespace ::testing; - -class LayerTransformTest : public ::testing::Test { - protected: - struct TransformMocker { - MOCK_CONST_METHOD0(mockTransform, bool()); - template - bool operator () (T ) const { - return mockTransform(); - } - }; - TransformMocker tmock; - void SetUp() override { - } -}; - -TEST_F(LayerTransformTest, canInjectIntoConvolutionLayer) { - - ConvolutionLayer lc(LayerParams{"name", "type", Precision::FP32}); - - lc._kernel.clear(); - lc._kernel.insert(X_AXIS, 23); - lc._kernel.insert(Y_AXIS, 24); - - auto layerWithData = injectData(lc); - dynamic_cast*>(layerWithData.get())->injected = 5; - - ASSERT_EQ(dynamic_cast(layerWithData.get())->_kernel[X_AXIS], 23); - ASSERT_EQ(dynamic_cast(layerWithData.get())->_kernel[Y_AXIS], 24); -} - -TEST_F(LayerTransformTest, canInjectValue) { - - ConvolutionLayer lc(LayerParams{"name", "type", Precision::FP32}); - - lc._kernel.clear(); - lc._kernel.insert(X_AXIS, 23); - lc._kernel.insert(Y_AXIS, 24); - - auto layerWithData = injectData(lc, 6); - ASSERT_EQ((dynamic_cast*>(layerWithData.get())->injected), 6); - - ASSERT_EQ(dynamic_cast(layerWithData.get())->_kernel[X_AXIS], 23); - ASSERT_EQ(dynamic_cast(layerWithData.get())->_kernel[Y_AXIS], 24); -} - -TEST_F(LayerTransformTest, canAccessInjectedValue) { - - ConvolutionLayer lc(LayerParams{"name", "type", Precision::FP32}); - - lc._kernel.clear(); - lc._kernel.insert(X_AXIS, 23); - lc._kernel.insert(Y_AXIS, 24); - - auto layerWithData = injectData(lc, 7); - auto injectedData = getInjectedData(layerWithData); - - ASSERT_NE(injectedData, nullptr); - ASSERT_EQ(*injectedData, 7); - - ASSERT_EQ(dynamic_cast(layerWithData.get())->_kernel[X_AXIS], 23); - ASSERT_EQ(dynamic_cast(layerWithData.get())->_kernel[Y_AXIS], 24); -} - -TEST_F(LayerTransformTest, returnNullIfNotInjected) { - - ConvolutionLayer lc(LayerParams{"name", "type", Precision::FP32}); - - lc._kernel.clear(); - lc._kernel.insert(X_AXIS, 23); - lc._kernel.insert(Y_AXIS, 24); - - auto layerWithData = injectData(lc, 7); - - ASSERT_EQ(getInjectedData(layerWithData), nullptr); - - ASSERT_EQ(dynamic_cast(layerWithData.get())->_kernel[X_AXIS], 23); - ASSERT_EQ(dynamic_cast(layerWithData.get())->_kernel[Y_AXIS], 24); -} - -struct SomeData { - int ivalue; - std::string name; - float value; -}; - -TEST_F(LayerTransformTest, canInjectStruct) { - - FullyConnectedLayer fc(LayerParams{"name", "type", Precision::FP32}); - fc._out_num = 9; - - auto layerWithData = injectData(fc, SomeData({11, "myname", 12.f})); - - auto some = getInjectedData(layerWithData); - - ASSERT_NE(some, nullptr); - ASSERT_STREQ(some->name.c_str(), "myname"); - ASSERT_EQ(some->ivalue, 11); - ASSERT_FLOAT_EQ(some->value, 12.f); - ASSERT_EQ(dynamic_cast(layerWithData.get())->_out_num, 9); - -} -// out data array items is fully copied, not just references to them -TEST_F(LayerTransformTest, injectioWillCopyOutData) { - - auto fc = std::make_shared(LayerParams{"name", "type", Precision::FP32}); - ASSERT_NE(fc, nullptr); - fc->_out_num = 9; - - auto data = std::make_shared("N1", Precision::FP32); - getCreatorLayer(data) = fc; - fc->outData.push_back(data); - - auto layerWithData = injectData(fc, SomeData({11, "myname", 12.f})); - - ASSERT_EQ(getCreatorLayer(data).lock(), getCreatorLayer(layerWithData->outData[0]).lock()); - ASSERT_NE(data.get(), layerWithData->outData[0].get()); -} - -TEST_F(LayerTransformTest, injectioWillCopyInputData) { - - auto fc = std::make_shared(LayerParams{"name", "type", Precision::FP32}); - ASSERT_NE(fc, nullptr); - fc->_out_num = 9; - - auto data = std::make_shared("N1", Precision::FP32); - getCreatorLayer(data) = fc; - fc->insData.push_back(data); - - auto layerWithData = injectData(fc, SomeData({11, "myname", 12.f})); - - ASSERT_EQ(data.get(), layerWithData->insData[0].lock().get()); -} - -TEST_F(LayerTransformTest, transformWillOnlyTransformOnce) { - - auto fc = std::make_shared(LayerParams{"name", "type", Precision::FP32}); - ASSERT_NE(fc, nullptr); - fc->_out_num = 9; - - EXPECT_CALL(tmock, mockTransform()).WillOnce(Return(true)); - - // CNNLayer might be selected in case of overloads - transformLayer(fc, tmock); -} - -TEST_F(LayerTransformTest, transformCanGoToParentIfChildTransformNotImplemented) { - - auto fc = std::make_shared(LayerParams{"name", "type", Precision::FP32}); - ASSERT_NE(fc, nullptr); - fc->_out_num = 9; - - Sequence s1; - EXPECT_CALL(tmock, mockTransform()).InSequence(s1).WillOnce(Return(false)); - EXPECT_CALL(tmock, mockTransform()).InSequence(s1).WillOnce(Return(false)); - EXPECT_CALL(tmock, mockTransform()).InSequence(s1).WillOnce(Return(true)); - - // CNNLayer might be selected in case of overloads - transformLayer(fc, tmock); -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/layers_test.cpp b/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/layers_test.cpp deleted file mode 100644 index 5bdc715730b..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/layers_test.cpp +++ /dev/null @@ -1,580 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include "ie_precision.hpp" -#include - -using namespace std; -using InferenceEngine::X_AXIS; -using InferenceEngine::Y_AXIS; -using namespace InferenceEngine; - -const std::string defaultLayerName = "layer"; -const std::string defaultLayerType = "unknown"; -InferenceEngine::Precision defaultPrecision{InferenceEngine::Precision::FP32}; - - -class LayersTests : public ::testing::Test { -public: - static InferenceEngine::LayerParams getParamsForLayer(std::string name, std::string type, - InferenceEngine::Precision precision) { - InferenceEngine::LayerParams params = {}; - params.name = name; - params.type = type; - params.precision = precision; - return params; - } - - static InferenceEngine::LayerParams getDefaultParamsForLayer() { - return getParamsForLayer(defaultLayerName, defaultLayerType, defaultPrecision); - } - - template - bool checkCreateLayer() { - T layer(getDefaultParamsForLayer()); - return layer.name == defaultLayerName; - } -}; - -TEST_F(LayersTests, canCreateLayersWithDefaultParams) { - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - ASSERT_TRUE(checkCreateLayer()); - -} - -TEST_F(LayersTests, throwsOnExpiredDataPtr) { - InferenceEngine::CNNLayer layer(getDefaultParamsForLayer()); - InferenceEngine::DataPtr dataPtr( - new InferenceEngine::Data("data", TensorDesc(InferenceEngine::Precision::FP32, InferenceEngine::NCHW))); - layer.insData.resize(1); - layer.insData[0] = dataPtr; - dataPtr.reset(); - ASSERT_THROW(layer.input(), InferenceEngine::Exception); -} - -template -void ASSERT_CNN_LAYER_DEFAULT(T& l) { - ASSERT_STREQ(l.params["some"].c_str(), "some"); -} - -template<> -void ASSERT_CNN_LAYER_DEFAULT(ConvolutionLayer& l) { - ASSERT_EQ(l._kernel[X_AXIS], 1); - ASSERT_EQ(l._kernel_x, 1); - ASSERT_EQ(l._out_depth, 3); - ASSERT_EQ(l._group, 4); - ASSERT_EQ(l._pads_end[X_AXIS], 5); - ASSERT_EQ(l._stride[X_AXIS], 6); - ASSERT_EQ(l._stride_x, 6); - ASSERT_EQ(l._dilation[X_AXIS], 7); - ASSERT_EQ(l._dilation_x, 7); - ASSERT_NO_FATAL_FAILURE(ASSERT_CNN_LAYER_DEFAULT(static_cast(l))); -} - -template<> -void ASSERT_CNN_LAYER_DEFAULT(DeconvolutionLayer& l) { - ASSERT_NO_FATAL_FAILURE(ASSERT_CNN_LAYER_DEFAULT(static_cast(l))); -} - -template<> -void ASSERT_CNN_LAYER_DEFAULT(PoolingLayer& l) { - ASSERT_NO_FATAL_FAILURE(ASSERT_CNN_LAYER_DEFAULT(static_cast(l))); -} - -template -void checkCopyLayerWithKernel(T& layer_1) { - T layer_2(LayersTests::getDefaultParamsForLayer()); - - layer_2 = layer_1; - ASSERT_NO_FATAL_FAILURE(ASSERT_CNN_LAYER_DEFAULT(layer_2)); - - T layer_3(layer_1); - ASSERT_NO_FATAL_FAILURE(ASSERT_CNN_LAYER_DEFAULT(layer_3)); - - T layer_4(LayersTests::getDefaultParamsForLayer()); - //use copy to temporary object then move it using asignment operator - { - T layerx(layer_1); - layer_4 = std::move(layerx); - } - - ASSERT_NO_FATAL_FAILURE(ASSERT_CNN_LAYER_DEFAULT(layer_4)); - - //use copy to temporary object then move it using move ctor - T layerx(layer_1); - T layer_5 = std::move(layerx); - ASSERT_NO_FATAL_FAILURE(ASSERT_CNN_LAYER_DEFAULT(layer_5)); - - - layer_1._kernel[X_AXIS] = 4; - ASSERT_EQ(layer_1._kernel_x, 4); - layer_1._kernel_x = 40; - ASSERT_EQ(layer_1._kernel[X_AXIS], 40); - - ASSERT_NO_FATAL_FAILURE(ASSERT_CNN_LAYER_DEFAULT(layer_2)); - ASSERT_NO_FATAL_FAILURE(ASSERT_CNN_LAYER_DEFAULT(layer_3)); - ASSERT_NO_FATAL_FAILURE(ASSERT_CNN_LAYER_DEFAULT(layer_4)); - ASSERT_NO_FATAL_FAILURE(ASSERT_CNN_LAYER_DEFAULT(layer_5)); -} - - -TEST_F(LayersTests, copyConvolution) { - ConvolutionLayer layer_1(getDefaultParamsForLayer()); - layer_1._kernel.insert(X_AXIS, 1); - layer_1._padding.insert(X_AXIS, 2); - layer_1._out_depth = 3; - layer_1._group = 4; - layer_1._pads_end.insert(X_AXIS, 5); - layer_1._stride.insert(X_AXIS, 6); - layer_1._dilation.insert(X_AXIS, 7); - layer_1.params["some"] = "some"; - checkCopyLayerWithKernel(layer_1); -} - -TEST_F(LayersTests, copyDeconvolution) { - ConvolutionLayer layer_1(getDefaultParamsForLayer()); - layer_1._kernel.insert(X_AXIS, 1); - layer_1._padding.insert(X_AXIS, 2); - layer_1._out_depth = 3; - layer_1._group = 4; - layer_1._pads_end.insert(X_AXIS, 5); - layer_1._stride.insert(X_AXIS, 6); - layer_1._dilation.insert(X_AXIS, 7); - layer_1.params["some"] = "some"; - checkCopyLayerWithKernel(layer_1); -} - -TEST_F(LayersTests, copyPooling) { - PoolingLayer layer_1(getDefaultParamsForLayer()); - layer_1._kernel.insert(X_AXIS, 1); - layer_1._padding.insert(X_AXIS, 2); - layer_1._type = PoolingLayer::MAX; - layer_1._exclude_pad = true; - layer_1._pads_end.insert(X_AXIS, 5); - layer_1._stride.insert(X_AXIS, 6); - layer_1.params["some"] = "some"; - checkCopyLayerWithKernel(layer_1); -} - -TEST_F(LayersTests, canNotInserOutOfBounds) { - - PoolingLayer layer_1(getDefaultParamsForLayer()); - ASSERT_ANY_THROW(layer_1._kernel.insert(MAX_DIMS_NUMBER, 5)); - ASSERT_ANY_THROW(layer_1._kernel.insert(-1, 5)); -} - -TEST_F(LayersTests, canInsertIntoExistedAxis) { - PoolingLayer layer_1(getDefaultParamsForLayer()); - layer_1._kernel.insert(Z_AXIS, 5); - ASSERT_EQ(layer_1._kernel[Z_AXIS], 5); - // for backward compatibility with IRv2 initial size is 2 - ASSERT_EQ(layer_1._kernel.size(), 3); - - layer_1._kernel.insert(Z_AXIS, 6); - ASSERT_EQ(layer_1._kernel[Z_AXIS], 6); - ASSERT_EQ(layer_1._kernel.size(), 3); - - layer_1._kernel.insert(Z_AXIS, 0); - ASSERT_EQ(layer_1._kernel[Z_AXIS], 0); - ASSERT_EQ(layer_1._kernel.size(), 3); - - layer_1._kernel.insert(Z_AXIS, 6); - ASSERT_EQ(layer_1._kernel[Z_AXIS], 6); - ASSERT_EQ(layer_1._kernel.size(), 3); -} - -TEST_F(LayersTests, canRemoveProperty) { - PoolingLayer layer_1(getDefaultParamsForLayer()); - layer_1._kernel.insert(Z_AXIS, 5); - layer_1._kernel.remove(X_AXIS); - layer_1._kernel.remove(Y_AXIS); - ASSERT_EQ(layer_1._kernel.size(), 1); - layer_1._kernel.remove(Z_AXIS); - ASSERT_EQ(layer_1._kernel.size(), 0); -} - -TEST_F(LayersTests, cannotRemovePropertyOutOfRange) { - - PoolingLayer layer_1(getDefaultParamsForLayer()); - layer_1._kernel.insert(Z_AXIS, 5); - ASSERT_NO_THROW(layer_1._kernel.remove(MAX_DIMS_NUMBER + 1000000)); - ASSERT_NO_THROW(layer_1._kernel.remove(-1)); - ASSERT_EQ(layer_1._kernel.size(), 3); -} - -TEST_F(LayersTests, convIRv2BackwardCompatibility) { - ConvolutionLayer conv(getDefaultParamsForLayer()); - ASSERT_NO_THROW(conv._kernel[X_AXIS]); - ASSERT_NO_THROW(conv._kernel[Y_AXIS]); - ASSERT_NO_THROW(conv._padding[X_AXIS]); - ASSERT_NO_THROW(conv._padding[Y_AXIS]); - ASSERT_NO_THROW(conv._stride[X_AXIS]); - ASSERT_NO_THROW(conv._stride[Y_AXIS]); - ASSERT_NO_THROW(conv._dilation[X_AXIS]); - ASSERT_NO_THROW(conv._dilation[Y_AXIS]); - - conv._kernel_x = 9u; - ASSERT_EQ(conv._kernel[X_AXIS], 9u); - conv._kernel_y = 2u; - ASSERT_EQ(conv._kernel[Y_AXIS], 2u); - conv._padding_x = 3u; - ASSERT_EQ(conv._padding[X_AXIS], 3u); - conv._padding_y = 4u; - ASSERT_EQ(conv._padding[Y_AXIS], 4u); - conv._stride_x = 5u; - ASSERT_EQ(conv._stride[X_AXIS], 5u); - conv._stride_y = 6u; - ASSERT_EQ(conv._stride[Y_AXIS], 6u); - conv._dilation_x = 7u; - ASSERT_EQ(conv._dilation[X_AXIS], 7u); - conv._dilation_y = 8u; - ASSERT_EQ(conv._dilation[Y_AXIS], 8u); - - conv._kernel[X_AXIS] = 8u; - ASSERT_EQ(conv._kernel_x, 8u); - conv._kernel[Y_AXIS] = 7u; - ASSERT_EQ(conv._kernel_y, 7u); - conv._padding[X_AXIS] = 6u; - ASSERT_EQ(conv._padding_x, 6u); - conv._padding[Y_AXIS] = 5u; - ASSERT_EQ(conv._padding_y, 5u); - conv._stride[X_AXIS] = 4u; - ASSERT_EQ(conv._stride_x, 4u); - conv._stride[Y_AXIS] = 3u; - ASSERT_EQ(conv._stride_y, 3u); - conv._dilation[X_AXIS] = 2u; - ASSERT_EQ(conv._dilation_x, 2u); - conv._dilation[Y_AXIS] = 9u; - ASSERT_EQ(conv._dilation_y, 9u); -} - -TEST_F(LayersTests, deconvIRv2BackwardCompatibility) { - DeconvolutionLayer deconv(getDefaultParamsForLayer()); - ASSERT_NO_THROW(deconv._kernel[X_AXIS]); - ASSERT_NO_THROW(deconv._kernel[Y_AXIS]); - ASSERT_NO_THROW(deconv._padding[X_AXIS]); - ASSERT_NO_THROW(deconv._padding[Y_AXIS]); - ASSERT_NO_THROW(deconv._stride[X_AXIS]); - ASSERT_NO_THROW(deconv._stride[Y_AXIS]); - ASSERT_NO_THROW(deconv._dilation[X_AXIS]); - ASSERT_NO_THROW(deconv._dilation[Y_AXIS]); - - deconv._kernel_x = 9u; - ASSERT_EQ(deconv._kernel[X_AXIS], 9u); - deconv._kernel_y = 2u; - ASSERT_EQ(deconv._kernel[Y_AXIS], 2u); - deconv._padding_x = 3u; - ASSERT_EQ(deconv._padding[X_AXIS], 3u); - deconv._padding_y = 4u; - ASSERT_EQ(deconv._padding[Y_AXIS], 4u); - deconv._stride_x = 5u; - ASSERT_EQ(deconv._stride[X_AXIS], 5u); - deconv._stride_y = 6u; - ASSERT_EQ(deconv._stride[Y_AXIS], 6u); - deconv._dilation_x = 7u; - ASSERT_EQ(deconv._dilation[X_AXIS], 7u); - deconv._dilation_y = 8u; - ASSERT_EQ(deconv._dilation[Y_AXIS], 8u); - - deconv._kernel[X_AXIS] = 8u; - ASSERT_EQ(deconv._kernel_x, 8u); - deconv._kernel[Y_AXIS] = 7u; - ASSERT_EQ(deconv._kernel_y, 7u); - deconv._padding[X_AXIS] = 6u; - ASSERT_EQ(deconv._padding_x, 6u); - deconv._padding[Y_AXIS] = 5u; - ASSERT_EQ(deconv._padding_y, 5u); - deconv._stride[X_AXIS] = 4u; - ASSERT_EQ(deconv._stride_x, 4u); - deconv._stride[Y_AXIS] = 3u; - ASSERT_EQ(deconv._stride_y, 3u); - deconv._dilation[X_AXIS] = 2u; - ASSERT_EQ(deconv._dilation_x, 2u); - deconv._dilation[Y_AXIS] = 9u; - ASSERT_EQ(deconv._dilation_y, 9u); -} - -TEST_F(LayersTests, poolIRv2BackwardCompatibility) { - PoolingLayer pool(getDefaultParamsForLayer()); - ASSERT_NO_THROW(pool._kernel[X_AXIS]); - ASSERT_NO_THROW(pool._kernel[Y_AXIS]); - ASSERT_NO_THROW(pool._padding[X_AXIS]); - ASSERT_NO_THROW(pool._padding[Y_AXIS]); - ASSERT_NO_THROW(pool._stride[X_AXIS]); - ASSERT_NO_THROW(pool._stride[Y_AXIS]); - - pool._kernel_x = 9u; - ASSERT_EQ(pool._kernel[X_AXIS], 9u); - pool._kernel_y = 2u; - ASSERT_EQ(pool._kernel[Y_AXIS], 2u); - pool._padding_x = 3u; - ASSERT_EQ(pool._padding[X_AXIS], 3u); - pool._padding_y = 4u; - ASSERT_EQ(pool._padding[Y_AXIS], 4u); - pool._stride_x = 5u; - ASSERT_EQ(pool._stride[X_AXIS], 5u); - pool._stride_y = 6u; - ASSERT_EQ(pool._stride[Y_AXIS], 6u); - - pool._kernel[X_AXIS] = 8u; - ASSERT_EQ(pool._kernel_x, 8u); - pool._kernel[Y_AXIS] = 7u; - ASSERT_EQ(pool._kernel_y, 7u); - pool._padding[X_AXIS] = 6u; - ASSERT_EQ(pool._padding_x, 6u); - pool._padding[Y_AXIS] = 5u; - ASSERT_EQ(pool._padding_y, 5u); - pool._stride[X_AXIS] = 4u; - ASSERT_EQ(pool._stride_x, 4u); - pool._stride[Y_AXIS] = 3u; - ASSERT_EQ(pool._stride_y, 3u); -} - -TEST_F(LayersTests, canGetPadBeginForConvolution) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - PropertyVector ref{{1, 2}}; - layer._padding = ref; - - auto allPads = getPaddings(layer); - - ASSERT_EQ(allPads.begin, ref); -} - -TEST_F(LayersTests, canGetPadEndForConvolution) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - PropertyVector ref{{1, 2}}; - layer._pads_end = ref; - - auto allPads = getPaddings(layer); - - ASSERT_EQ(allPads.end, ref); -} - -TEST_F(LayersTests, canGetPad3DBeginForConvolution) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - PropertyVector ref; - ref.insert(X_AXIS, 1); - ref.insert(Y_AXIS, 2); - ref.insert(Z_AXIS, 3); - layer._padding = ref; - - auto allPads = getPaddings(layer); - - ASSERT_EQ(allPads.begin, ref); -} - -TEST_F(LayersTests, canGetPad3DEndForConvolution) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - PropertyVector ref; - ref.insert(X_AXIS, 1); - ref.insert(Y_AXIS, 2); - ref.insert(Z_AXIS, 3); - layer._pads_end = ref; - - auto allPads = getPaddings(layer); - - ASSERT_EQ(allPads.end, ref); -} - -TEST_F(LayersTests, returnDefaultPadForEmptyConvolution) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - auto allPads = getPaddings(layer); - PropertyVector ref_begin(2, 0u); - PropertyVector ref_end; - ASSERT_EQ(allPads.begin, ref_begin); - ASSERT_EQ(allPads.end, ref_end); -} - -TEST_F(LayersTests, returnEmptyPadForValidPadConvolution) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "valid"; - auto allPads = getPaddings(layer); - PropertyVector ref(2,0u); - ASSERT_EQ(allPads.begin, ref); - ASSERT_EQ(allPads.end, ref); - - PropertyVector ref3D(2,0u); - layer._kernel.insert(Z_AXIS, 0u); - ASSERT_EQ(allPads.begin, ref3D); - ASSERT_EQ(allPads.end, ref3D); -} - -TEST_F(LayersTests, throwOnSamePadForEmptyConvolution) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "same_upper"; - ASSERT_THROW(getPaddings(layer), Exception); -} - -TEST_F(LayersTests, throwOnInvalidDimsSamePadForConvolution) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "same_upper"; - auto emptyData = std::make_shared("", TensorDesc(Precision::UNSPECIFIED, Layout::ANY)); - layer.insData.push_back(emptyData); - ASSERT_THROW(getPaddings(layer), Exception); -} - -TEST_F(LayersTests, throwOn2DSamePadForConvolution) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "same_upper"; - auto notEmptyData = std::make_shared("", TensorDesc(Precision::UNSPECIFIED, SizeVector{ 1, 1 }, Layout::NC)); - layer.insData.push_back(notEmptyData); - ASSERT_THROW(getPaddings(layer), Exception); -} - -TEST_F(LayersTests, throwWithNotEnoughParamsSamePadForConvolution) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "same_upper"; - auto notEmptyData = std::make_shared("", TensorDesc(Precision::UNSPECIFIED, SizeVector{ 4, 3, 2, 1 }, Layout::ANY)); - layer.insData.push_back(notEmptyData); - ASSERT_NO_THROW(getPaddings(layer)); - - auto notEmptyData3D = std::make_shared("", TensorDesc(Precision::UNSPECIFIED, SizeVector{ 5, 4, 3, 2, 1 }, Layout::NCDHW)); - layer._kernel.insert(Z_AXIS, 0u); - layer.insData[0] = notEmptyData3D; - ASSERT_NO_THROW(getPaddings(layer)); -} - -// parameters are from real model, like Mobilenet-SSD -TEST_F(LayersTests, canGetSamePadForConvolutionEvenInput) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "same_upper"; - TensorDesc tensorDesc(Precision::UNSPECIFIED, SizeVector{1, 144, 160, 160}, Layout::NCHW); - auto notEmptyData = std::make_shared("", tensorDesc); - layer.insData.push_back(notEmptyData); - layer._dilation = PropertyVector{{1, 1}}; - layer._kernel = PropertyVector{{3, 3}}; - layer._stride = PropertyVector{{2, 2}}; - - auto pad = getPaddings(layer); - - ASSERT_EQ(pad.begin, PropertyVector(2, 0)); - ASSERT_EQ(pad.end, PropertyVector(2, 1)); -} - -// parameters are from real model, like V-Net -TEST_F(LayersTests, canGetSamePadForConvolutionEvenInput3D) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "same_upper"; - TensorDesc tensorDesc(Precision::UNSPECIFIED, SizeVector{1, 6, 190, 190, 20}, Layout::NCDHW); - auto notEmptyData = std::make_shared("", tensorDesc); - layer.insData.push_back(notEmptyData); - layer._dilation.insert(X_AXIS, 1u); - layer._dilation.insert(Y_AXIS, 1u); - layer._dilation.insert(Z_AXIS, 1u); - layer._kernel.insert(X_AXIS, 5u); - layer._kernel.insert(Y_AXIS, 5u); - layer._kernel.insert(Z_AXIS, 5u); - layer._stride.insert(X_AXIS, 1u); - layer._stride.insert(Y_AXIS, 1u); - layer._stride.insert(Z_AXIS, 1u); - - auto pad = getPaddings(layer); - - ASSERT_EQ(pad.begin, PropertyVector(3, 2u)); - ASSERT_EQ(pad.end, PropertyVector(3, 2u)); -} - -// parameters are from real model, like Mobilenet-SSD -TEST_F(LayersTests, canGetSamePadForConvolutionOddInput) { - ConvolutionLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "same_upper"; - TensorDesc tensorDesc(Precision::UNSPECIFIED, SizeVector{1, 144, 75, 75}, Layout::NCHW); - auto notEmptyData = std::make_shared("", tensorDesc); - layer.insData.push_back(notEmptyData); - layer._dilation = PropertyVector{{1, 1}}; - layer._kernel = PropertyVector{{3, 3}}; - layer._stride = PropertyVector{{2, 2}}; - PropertyVector ref(2, 1); - - auto pad = getPaddings(layer); - - ASSERT_EQ(pad.begin, ref); - ASSERT_EQ(pad.end, ref); -} - -TEST_F(LayersTests, canGetSamePadForDeConvolutionEvenInput) { - DeconvolutionLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "same_upper"; - TensorDesc tensorDesc(Precision::UNSPECIFIED, SizeVector{1, 144, 160, 160}, Layout::NCHW); - auto notEmptyData = std::make_shared("", tensorDesc); - layer.insData.push_back(notEmptyData); - layer._dilation = PropertyVector{{1, 1}}; - layer._kernel = PropertyVector{{3, 3}}; - layer._stride = PropertyVector{{2, 2}}; - - auto pad = getPaddings(layer); - - ASSERT_EQ(pad.begin, PropertyVector(2, 0)); - ASSERT_EQ(pad.end, PropertyVector(2, 1)); -} - -TEST_F(LayersTests, canGetSamePadForDeConvolutionOddInput) { - DeconvolutionLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "same_upper"; - TensorDesc tensorDesc(Precision::UNSPECIFIED, SizeVector{1, 144, 75, 75}, Layout::NCHW); - auto notEmptyData = std::make_shared("", tensorDesc); - layer.insData.push_back(notEmptyData); - layer._dilation = PropertyVector{{1, 1}}; - layer._kernel = PropertyVector{{3, 3}}; - layer._stride = PropertyVector{{2, 2}}; - PropertyVector ref(2, 1); - - auto pad = getPaddings(layer); - - ASSERT_EQ(pad.begin, ref); - ASSERT_EQ(pad.end, ref); -} - -TEST_F(LayersTests, canGetSamePadForPoolingEvenInput) { - PoolingLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "same_upper"; - TensorDesc tensorDesc(Precision::UNSPECIFIED, SizeVector{1, 144, 160, 160}, Layout::NCHW); - auto notEmptyData = std::make_shared("", tensorDesc); - layer.insData.push_back(notEmptyData); - layer._kernel = PropertyVector{{3, 3}}; - layer._stride = PropertyVector{{2, 2}}; - - auto pad = getPaddings(layer); - - ASSERT_EQ(pad.begin, PropertyVector(2, 0)); - ASSERT_EQ(pad.end, PropertyVector(2, 1)); -} - -TEST_F(LayersTests, canGetSamePadForPoolingOddInput) { - PoolingLayer layer(getDefaultParamsForLayer()); - layer.params["auto_pad"] = "same_upper"; - TensorDesc tensorDesc(Precision::UNSPECIFIED, SizeVector{1, 144, 75, 75}, Layout::NCHW); - auto notEmptyData = std::make_shared("", tensorDesc); - layer.insData.push_back(notEmptyData); - layer._kernel = PropertyVector{{3, 3}}; - layer._stride = PropertyVector{{2, 2}}; - PropertyVector ref(2, 1); - - auto pad = getPaddings(layer); - - ASSERT_EQ(pad.begin, ref); - ASSERT_EQ(pad.end, ref); -} - - -TEST_F(LayersTests, cannotGetPadForUnsupportedLayer) { - FullyConnectedLayer layer(getDefaultParamsForLayer()); - ASSERT_ANY_THROW(getPaddingsImpl(layer)); -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_const_infer_test.cpp b/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_const_infer_test.cpp deleted file mode 100644 index 4a73e6b0607..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_const_infer_test.cpp +++ /dev/null @@ -1,984 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include "blob_factory.hpp" -#include "debug.h" -#include "util_test.hpp" -#include "util_const_infer_test.hpp" -#include -#include -#include "common_test_utils/common_utils.hpp" -#include "cnnlayer_utils.hpp" - -namespace IE = InferenceEngine; - -void RemoveLayerTests::SetUp() { - net = getNetwork(); - originalLayersNum = net->allLayers().size(); - testTransformator.reset(new ConstTransformatorTest(net.get())); -} - -// -// I1-d1-L1-d4 I4 -// / \ \ \ -// | d7 \ d10 -// | | \ / -// I2-d2-L2-d5-L4-d6-L5-d9-L10 -// / / -// / ____d8___/ -// / / -// I3-d3-L3 -// -IE::details::CNNNetworkImplPtr RemoveLayerTests::getNetwork() { - return netBuilder - .data("data1", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 3 }, IE::Layout::CHW)) - .data("data2", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 3 }, IE::Layout::CHW)) - .data("data3", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 3 }, IE::Layout::CHW)) - .data("data4", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 3 }, IE::Layout::CHW)) - .data("data5", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 3 }, IE::Layout::CHW)) - .data("data6", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 3 }, IE::Layout::CHW)) - .data("data7", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 3 }, IE::Layout::CHW)) - .data("data8", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 3 }, IE::Layout::CHW)) - .data("data9", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 3 }, IE::Layout::CHW)) - .data("data10", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 3 }, IE::Layout::CHW)) - .data("data11", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 3 }, IE::Layout::CHW)) - .layer(IE::LayerParams{"input1", "input", IE::Precision::FP32}) - .layer(IE::LayerParams{"input2", "Input", IE::Precision::FP32}) - .layer(IE::LayerParams{"input3", "input", IE::Precision::FP32}) - .layer(IE::LayerParams{"input4", "input", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer1", "dummy", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer2", "dummy", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer3", "dummy", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer4", "dummy", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer5", "dummy", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer6", "dummy", IE::Precision::FP32}) - .linkToData("input1", "data1") - .linkToData("input2", "data2") - .linkToData("input3", "data3") - .linkToData("input4", "data10") - - .linkDataTo("data1", "layer1") - .linkDataTo("data2", "layer2") - .linkDataTo("data2", "layer1") - .linkDataTo("data3", "layer3") - .linkDataTo("data3", "layer2") - .linkDataTo("data10", "layer6") - - .linkToData("layer1", "data4") - .linkToData("layer1", "data7") - .linkToData("layer2", "data5") - .linkToData("layer3", "data8") - - .linkDataTo("data4", "layer4") - .linkDataTo("data5", "layer4") - .linkDataTo("data8", "layer5") - .linkDataTo("data7", "layer2") - - .linkToData("layer4", "data6") - - .linkDataTo("data6", "layer5") - - .linkToData("layer5", "data9") - - .linkDataTo("data9", "layer6") - - .linkToData("layer6", "data11") - - .addInput("data1") - .addInput("data2") - .addInput("data3") - .finalize(); -} - -IE::CNNLayerPtr RemoveLayerTests::getLayer(const std::string& name) { - const auto& layers = netBuilder.getLayersMap(); - auto it = layers.find(name); - if (it == layers.end()) throw std::logic_error("Failed to find layer: " + name); - return it->second; -} - -IE::DataPtr RemoveLayerTests::getData(const std::string& name) { - const auto& datas = netBuilder.getDataMap(); - auto it = datas.find(name); - if (it == datas.end()) throw std::logic_error("Failed to find data: " + name); - return it->second; -} - -IE::BlobMap RemoveLayerTests::fillConstData(const std::vector& constLayers) { - IE::BlobMap constData; - for (const auto& name:constLayers) { - auto layer = getLayer(name); - for (const auto& outData:layer->outData) { - IE::TensorDesc desc = outData->getTensorDesc(); - IE::Blob::Ptr blob = make_blob_with_precision(desc); - blob->allocate(); - auto* buffer = blob->buffer().as(); - size_t buffer_length = blob->byteSize() / sizeof(float); - for (int i = 0; i < buffer_length; i++) { - buffer[i] = i + 1; - } - constData[outData->getName()] = blob; - } - } - return constData; -} - -IE::BlobMap RemoveLayerTests::initConstLayers(const std::vector& constLayers) { - for (const auto& name : constLayers) { - getLayer(name)->type = "Const"; - } - IE::BlobMap customBlobs = fillConstData(constLayers); - for (const auto& layerName: constLayers) { - auto layer = getLayer(layerName); - layer->type = "Const"; - layer->blobs["custom"] = customBlobs[layer->outData[0]->getName()]; - } - return customBlobs; -} - -IE::BlobMap RemoveLayerTests::fillConstDataDiffPrec (const std::vector& constLayers) { - IE::BlobMap constData; - for (const auto& name:constLayers) { - auto layer = getLayer(name); - for (const auto& outData:layer->outData) { - IE::TensorDesc desc = outData->getTensorDesc(); - IE::Blob::Ptr blob = make_blob_with_precision(desc); - blob->allocate(); - switch(layer->precision) { - case IE::Precision::U8: { - auto *buffer = blob->buffer().as(); - for (int i = 0; i < blob->size(); i++) { - buffer[i] = i + 2; - } - break; - } - case IE::Precision::I32: { - auto *buffer = blob->buffer().as(); - for (int i = 0; i < blob->size(); i++) { - buffer[i] = i + 2; - } - break; - } - case IE::Precision::U32: { - auto *buffer = blob->buffer().as(); - for (int i = 0; i < blob->size(); i++) { - buffer[i] = i + 2; - } - break; - } - case IE::Precision::I64: { - auto *buffer = blob->buffer().as(); - for (int i = 0; i < blob->size(); i++) { - buffer[i] = i + 2; - } - break; - } - case IE::Precision::U64: { - auto *buffer = blob->buffer().as(); - for (int i = 0; i < blob->size(); i++) { - buffer[i] = i + 2; - } - break; - } - case IE::Precision::FP16: { - auto *buffer = blob->buffer().as(); - float j = 0; - for (int i = 0; i < blob->size(); i++) { - buffer[i] = j + (float)2; - buffer[i] = IE::PrecisionUtils::f32tof16(buffer[i]); - j++; - } - break; - } - case IE::Precision::FP32: { - auto *buffer = blob->buffer().as(); - for (int i = 0; i < blob->size(); i++) { - buffer[i] = i + 2; - } - break; - } - default: - IE_THROW() << "Not supported data type"; - } - constData[outData->getName()] = blob; - } - } - return constData; -} - -IE::BlobMap RemoveLayerTests::initConstLayersDiffPrec(const std::vector &constLayers) { - for (const auto& name : constLayers) { - getLayer(name)->type = "Const"; - } - IE::BlobMap customBlobs = fillConstDataDiffPrec(constLayers); - for (const auto& layerName: constLayers) { - auto layer = getLayer(layerName); - layer->type = "Const"; - layer->blobs["custom"] = customBlobs[layer->outData[0]->getName()]; - } - return customBlobs; -} - -TEST_F(RemoveLayerTests, canTrimL2) { - auto layer1 = getLayer("layer1"); - auto layer4 = getLayer("layer4"); - auto data2 = getData("data2"); - auto data3 = getData("data3"); - auto data7 = getData("data7"); - auto data5 = getData("data5"); - std::vector constLayers = {"layer2"}; - std::vector refNewLayers = {constLayers[0] + "__data5__Const"}; - auto constData = fillConstData(constLayers); - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - - auto newLayers = testTransformator->foldConstSubgraphsInternal({{constLayers[0], false}}, constData, sortedLayers); - - std::vector newLayer_names; - for (const auto& layer : newLayers) newLayer_names.push_back(layer->name); - - ASSERT_EQ(newLayer_names, refNewLayers); - IE::CNNNetwork cnnNetwork(net); - ASSERT_THROW(CommonTestUtils::getLayerByName(cnnNetwork, "layer2"), IE::NotFound); - auto newLayer = CommonTestUtils::getLayerByName(cnnNetwork, refNewLayers[0].c_str()); - ASSERT_EQ(newLayer->type, "Const"); - ASSERT_EQ(constData["data5"], newLayer->blobs.at("custom")); - ASSERT_EQ(nullptr, net->getData("data7")); - net->removeData("data7"); - ASSERT_EQ(net->allLayers().size(), originalLayersNum); - ASSERT_EQ(getInputTo(data2).size(), 1); - ASSERT_EQ(getInputTo(data2).find("layer1")->second, layer1); - ASSERT_EQ(getCreatorLayer(data5).lock(), newLayer); - ASSERT_EQ(layer4->insData.size(), 2); - ASSERT_EQ(layer4->insData[1].lock(), data5); - ASSERT_EQ(layer1->insData.size(), 2); - ASSERT_EQ(layer1->insData[0].lock(), getData("data1")); - ASSERT_EQ(layer1->insData[1].lock(), data2); - ASSERT_EQ(layer1->outData.size(), 1); - ASSERT_EQ(layer1->outData[0], getData("data4")); - ASSERT_EQ(newLayer->outData.size(), 1); - ASSERT_EQ(newLayer->outData[0], data5); - ASSERT_EQ(getInputTo(data3).size(), 1); - ASSERT_EQ(getInputTo(data3).find("layer3")->second, getLayer("layer3")); -} - -TEST_F(RemoveLayerTests, canTrimI1andL1) { - auto layer4 = getLayer("layer4"); - auto layer2 = getLayer("layer2"); - auto data2 = getData("data2"); - std::vector constLayers = {"input1", "layer1"}; - std::map mapConstLayers; - for (const auto& it : constLayers) { - mapConstLayers[it] = false; - } - std::vector refNewLayers = {(constLayers[1] + "__data4__Const"), (constLayers[1] + "__data7__Const")}; - - auto constData = fillConstData(constLayers); - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - auto newLayers = testTransformator->foldConstSubgraphsInternal(mapConstLayers, constData, sortedLayers); - - std::vector newLayer_names; - for (auto layer : newLayers) newLayer_names.push_back(layer->name); - - ASSERT_EQ(newLayer_names, refNewLayers); - IE::CNNLayerPtr layer; - ASSERT_EQ(IE::NOT_FOUND, net->getLayerByName("input1", layer, nullptr)); - ASSERT_EQ(nullptr, layer); - ASSERT_EQ(IE::NOT_FOUND, net->getLayerByName("layer1", layer, nullptr)); - ASSERT_EQ(nullptr, layer); - IE::CNNNetwork cnnNetwork(net); - auto newLayerD4 = CommonTestUtils::getLayerByName(cnnNetwork, refNewLayers[0]); - auto newLayerD7 = CommonTestUtils::getLayerByName(cnnNetwork, refNewLayers[1]); - auto newData4 = net->getData("data4__layer4"); - auto newData7 = net->getData("data7__layer2"); - ASSERT_EQ(newLayerD4->type, "Const"); - ASSERT_EQ(newLayerD7->type, "Const"); - ASSERT_EQ(constData["data4"], newLayerD4->blobs.at("custom")); - ASSERT_EQ(constData["data7"], newLayerD7->blobs.at("custom")); - ASSERT_EQ(nullptr, net->getData("data1")); - net->removeData("data1"); - ASSERT_EQ(net->allLayers().size(), originalLayersNum); - ASSERT_EQ(getInputTo(data2).size(), 1); - ASSERT_EQ(getInputTo(data2).find("layer2")->second, layer2); - ASSERT_EQ(getCreatorLayer(newData4).lock(), newLayerD4); - ASSERT_EQ(getCreatorLayer(newData7).lock(), newLayerD7); - ASSERT_EQ(newLayerD4->outData.size(), 1); - ASSERT_EQ(newLayerD7->outData.size(), 1); - ASSERT_EQ(newLayerD4->outData[0], newData4); - ASSERT_EQ(newLayerD7->outData[0], newData7); - ASSERT_EQ(layer4->insData.size(), 2); - ASSERT_EQ(layer4->insData[0].lock(), newData4); - ASSERT_EQ(layer4->insData[1].lock(), getData("data5")); - ASSERT_EQ(layer2->insData.size(), 3); - ASSERT_EQ(layer2->insData[0].lock(), data2); - ASSERT_EQ(layer2->insData[1].lock(), getData("data3")); - ASSERT_EQ(layer2->insData[2].lock(), newData7); -} - -TEST_F(RemoveLayerTests, canFindConstLayers) { - getLayer("input1")->type = "Const"; - getLayer("layer2")->type = "Shape"; - - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - auto constLayers = testTransformator->getConstLayers(sortedLayers); - - ASSERT_EQ(constLayers.size(), 2); - ASSERT_FALSE(constLayers.at("input1")); - ASSERT_FALSE(constLayers.at("layer2")); -} - -TEST_F(RemoveLayerTests, canFindConstLayers2) { - getLayer("input3")->type = "Const"; - getLayer("input2")->type = "Const"; - getLayer("layer2")->type = "Shape"; - - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - auto constLayers = testTransformator->getConstLayers(sortedLayers); - - ASSERT_EQ(constLayers.size(), 4); - ASSERT_FALSE(constLayers.at("input3")); - ASSERT_FALSE(constLayers.at("layer2")); - ASSERT_FALSE(constLayers.at("layer3")); - ASSERT_FALSE(constLayers.at("input2")); -} - -TEST_F(RemoveLayerTests, canFindConstLayers3) { - getLayer("input3")->type = "Const"; - getLayer("layer2")->type = "Shape"; - getLayer("layer1")->type = "Shape"; - getLayer("layer4")->type = "Reshape"; - - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - auto constLayers = testTransformator->getConstLayers(sortedLayers); - - ASSERT_EQ(constLayers.size(), 6); - ASSERT_FALSE(constLayers.at("input3")); - ASSERT_FALSE(constLayers.at("layer1")); - ASSERT_TRUE(constLayers.at("layer2")); - ASSERT_FALSE(constLayers.at("layer3")); - ASSERT_FALSE(constLayers.at("layer4")); - ASSERT_FALSE(constLayers.at("layer5")); -} - -TEST_F(RemoveLayerTests, canFindShapeConstLayers) { - getLayer("input3")->type = "Const"; - getLayer("layer2")->type = "Shape"; - getLayer("layer1")->type = "Shape"; - getLayer("layer6")->type = "Interp"; - - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - auto constLayers = testTransformator->getConstLayers(sortedLayers); - - ASSERT_EQ(constLayers.size(), 6); - ASSERT_TRUE(constLayers.at("input3")); - ASSERT_TRUE(constLayers.at("layer1")); - ASSERT_TRUE(constLayers.at("layer2")); - ASSERT_TRUE(constLayers.at("layer3")); - ASSERT_TRUE(constLayers.at("layer4")); - ASSERT_TRUE(constLayers.at("layer5")); -} - -TEST_F(RemoveLayerTests, canFindShapeConstLayers2) { - getLayer("input3")->type = "Const"; - getLayer("input2")->type = "Const"; - getLayer("layer2")->type = "Shape"; - getLayer("layer1")->type = "Resample"; - - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - auto constLayers = testTransformator->getConstLayers(sortedLayers); - - ASSERT_EQ(constLayers.size(), 4); - ASSERT_FALSE(constLayers.at("input3")); - ASSERT_FALSE(constLayers.at("layer2")); - ASSERT_FALSE(constLayers.at("layer3")); - ASSERT_FALSE(constLayers.at("input2")); -} - -TEST_F(RemoveLayerTests, canTrimShapeInput) { - std::vector constLayers = {"input3", "layer3", "input2"}; - for (const auto& name : constLayers) { - getLayer(name)->type = "Const"; - } - getLayer("layer2")->type = "Shape"; - getLayer("layer1")->type = "Interp"; - getLayer("layer4")->type = "Reshape"; - getLayer("layer5")->type = "Reshape"; - auto layer1 = getLayer("layer1"); - auto layer4 = getLayer("layer4"); - auto layer5 = getLayer("layer5"); - - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - auto mapConstLayers = testTransformator->getConstLayers(sortedLayers); - auto newLayers = testTransformator->foldConstSubgraphsInternal(mapConstLayers, {}, sortedLayers); - testTransformator->trimShapeInputs(newLayers, sortedLayers); - - ASSERT_EQ(nullptr, net->getData("data5")); - ASSERT_EQ(nullptr, net->getData("data2")); - net->removeData("data5"); - net->removeData("data2"); - ASSERT_EQ(net->allLayers().size(), originalLayersNum - 3); - ASSERT_EQ(layer1->insData.size(), 1); - ASSERT_EQ(layer1->insData[0].lock(), getData("data1")); - ASSERT_EQ(layer4->insData.size(), 1); - ASSERT_EQ(layer4->insData[0].lock(), getData("data4")); - ASSERT_EQ(layer5->insData.size(), 2); - ASSERT_EQ(layer5->insData[0].lock(), getData("data8")); - ASSERT_EQ(layer5->insData[1].lock(), getData("data6")); -} - -TEST_F(RemoveLayerTests, canTrimShapeInput2) { - std::vector constLayer_names = {"input3", "input2"}; - for (const auto& name : constLayer_names) { - getLayer(name)->type = "Const"; - } - auto layer1 = getLayer("layer1"); - auto layer2 = getLayer("layer2"); - layer1->type = "Resample"; - layer2->type = "StridedSlice"; - - std::vector constLayers; - for (auto &const_input_name : constLayer_names) - constLayers.push_back(getLayer(const_input_name)); - - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - testTransformator->trimShapeInputs(constLayers, sortedLayers); - - auto data6 = net->getData("data6"); - auto data2 = net->getData("data2"); - ASSERT_EQ(getInputTo(data2).size(), 1); - ASSERT_EQ(getInputTo(data2).at(layer2->name), layer2); - ASSERT_EQ(net->allLayers().size(), originalLayersNum); - ASSERT_EQ(layer1->insData.size(), 1); - ASSERT_EQ(layer1->insData[0].lock(), getData("data1")); - ASSERT_EQ(layer2->insData.size(), 3); - ASSERT_EQ(layer2->insData[0].lock(), getData("data2")); - ASSERT_EQ(layer2->insData[1].lock(), getData("data3")); - ASSERT_EQ(layer2->insData[2].lock(), getData("data7")); -} - -TEST_F(RemoveLayerTests, notTrimFirstConstInput) { - std::vector testLayers = {"Interp", "Reshape", "Pad", "Gather", "Resample"}; - auto constLayer = getLayer("input4"); - constLayer->type = "Const"; - auto layer6 = getLayer("layer6"); - auto data10 = getData("data10"); - for (const auto& name: testLayers) { - layer6->type = name; - - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - testTransformator->trimShapeInputs({constLayer}, sortedLayers); - - ASSERT_EQ(net->allLayers().size(), originalLayersNum); - IE::CNNNetwork cnnNetwork(net); - auto input4 = CommonTestUtils::getLayerByName(cnnNetwork, constLayer->name.c_str()); - ASSERT_EQ(getInputTo(data10).size(), 1); - ASSERT_EQ(getCreatorLayer(data10).lock(), input4); - ASSERT_EQ(layer6->insData.size(), 2); - ASSERT_EQ(layer6->insData[0].lock(), data10); - ASSERT_EQ(layer6->insData[1].lock(), getData("data9")); - } -} - -TEST_F(RemoveLayerTests, canSaveConstForEltWise) { - auto input2 = getLayer("input2"); - auto layer1 = getLayer("layer1"); - auto data2 = getData("data2"); - input2->type = "Const"; - layer1->type = "Eltwise"; - - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - testTransformator->trimShapeInputs({input2}, sortedLayers); - - IE::CNNNetwork cnnNetwork(net); - ASSERT_NO_THROW(input2 = CommonTestUtils::getLayerByName(cnnNetwork, input2->name.c_str())); - ASSERT_EQ(net->allLayers().size(), 10); - ASSERT_EQ(layer1->insData.size(), 2); - ASSERT_EQ(layer1->insData[1].lock(), data2); - ASSERT_EQ(getInputTo(data2).size(), 2); - ASSERT_EQ(getInputTo(data2).at(layer1->name), layer1); - ASSERT_EQ(getCreatorLayer(data2).lock(), input2); -} - -TEST_F(RemoveLayerTests, canSaveDataWithMultipleInputTo) { - auto input3 = getLayer("input3"); - auto layer2 = getLayer("layer2"); - auto layer3 = getLayer("layer3"); - auto data3 = getData("data3"); - input3->type = "Const"; - layer2->type = "Reshape"; - - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - testTransformator->trimShapeInputs({input3}, sortedLayers); - - IE::CNNNetwork cnnNetwork(net); - ASSERT_NO_THROW(input3 = CommonTestUtils::getLayerByName(cnnNetwork, input3->name.c_str())); - ASSERT_EQ(net->allLayers().size(), originalLayersNum); - ASSERT_EQ(layer2->insData.size(), 2); - ASSERT_EQ(layer2->insData[0].lock(), getData("data2")); - ASSERT_EQ(layer2->insData[1].lock(), getData("data7")); - ASSERT_EQ(getInputTo(data3).size(), 1); - ASSERT_EQ(getInputTo(data3).at(layer3->name), layer3); - ASSERT_EQ(getCreatorLayer(data3).lock(), input3); - ASSERT_EQ(layer3->insData.size(), 1); - ASSERT_EQ(layer3->insData[0].lock(), data3); -} - -TEST_F(RemoveLayerTests, canFoldConstSubgraphToConst) { - std::vector constLayers = {"input1", "input2", "input3"}; - std::vector refNewLayers = {"layer5__data9__Const"}; - for (const auto& name : constLayers) { - getLayer(name)->type = "Const"; - } - getLayer("layer2")->type = "Shape"; - - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - auto mapConstLayers = testTransformator->getConstLayers(sortedLayers); - auto newLayers = testTransformator->foldConstSubgraphsInternal(mapConstLayers, {}, sortedLayers); - - std::vector newLayer_names; - for (auto layer : newLayers) newLayer_names.push_back(layer->name); - - ASSERT_EQ(net->allLayers().size(), originalLayersNum - 7); - ASSERT_EQ(newLayer_names, refNewLayers); - IE::CNNNetwork cnnNetwork(net); - auto newLayer = CommonTestUtils::getLayerByName(cnnNetwork, refNewLayers[0].c_str()); - ASSERT_EQ(newLayer->type, "Const"); - ASSERT_EQ(newLayer->outData[0], getData("data9")); -} - -TEST_F(RemoveLayerTests, canGetConstData) { - std::vector constLayers = {"input2", "input3", "layer3"}; - IE::BlobMap refBlobs = initConstLayers(constLayers); - std::map mapConstLayers; - for (const auto& it : constLayers) { - mapConstLayers[it] = false; - } - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - - auto actBlobs = testTransformator->getConstData(mapConstLayers, sortedLayers); - - ASSERT_EQ(actBlobs.size(), refBlobs.size()); - for (const auto& it: refBlobs) { - ASSERT_EQ(it.second, actBlobs[it.first]); - } -} - -TEST_F(RemoveLayerTests, canGetConstDataForUnknownImpl) { - initConstLayers({"input1", "input2", "input3"}); - { - getLayer("layer1")->type = "UNKNOWN"; - getLayer("layer2")->type = "UNKNOWN"; - getLayer("layer3")->type = "Shape"; - getLayer("layer4")->type = "UNKNOWN"; - getLayer("layer5")->type = "Mul"; - getLayer("layer6")->type = "Reshape"; - } - auto sortedLayers = IE::details::CNNNetSortTopologically(IE::CNNNetwork(net)); - IE::SizeVector refShape = {1, 1, 3}; - - auto mapConstLayers = testTransformator->getConstLayers(sortedLayers); - auto actBlobs = testTransformator->getConstData(mapConstLayers, sortedLayers); - - ASSERT_EQ(getData("data9")->getTensorDesc().getDims(), refShape); -} - -TEST_F(RemoveLayerTests, canSkipConstCalculation) { - IE::BlobMap refBlobs = initConstLayers({"input1", "input2", "input3"}); - getLayer("layer6")->type = "Reshape"; - - IE::ConstTransformer transformator(net.get()); - transformator.foldConstSubgraphs(); - - IE::CNNNetwork cnnNetwork(net); - ASSERT_EQ(net->allLayers().size(), originalLayersNum - 8); -} - -TEST_F(RemoveLayerTests, canFoldConstWithUnknownImplForShapeDefiningLayers) { - IE::BlobMap refBlobs = initConstLayers({"input1", "input2", "input3"}); - { - getLayer("layer1")->type = "UNKNOWN"; - getLayer("layer2")->type = "UNKNOWN"; - getLayer("layer3")->type = "Shape"; - getLayer("layer4")->type = "Reshape"; - getLayer("layer5")->type = "Mul"; - getLayer("layer6")->type = "Reshape"; - } - - IE::ConstTransformer transformator(net.get()); - transformator.foldConstSubgraphs(); - - IE::CNNNetwork cnnNetwork(net); - ASSERT_EQ(net->allLayers().size(), originalLayersNum - 8); - ASSERT_EQ(getLayer("layer6")->insData.size(), 1); -} - -TEST_F(RemoveLayerTests, throwErrorOnFoldWithUnknownImplForNotShapeDefiningLayers) { - IE::BlobMap refBlobs = initConstLayers({"input1", "input2", "input3"}); - { - getLayer("layer1")->type = "UNKNOWN"; - getLayer("layer2")->type = "Shape"; - getLayer("layer3")->type = "Shape"; - getLayer("layer4")->type = "Mul"; - getLayer("layer5")->type = "Mul"; - getLayer("layer6")->type = "Gather"; - } - - IE::ConstTransformer transformator(net.get()); - ASSERT_THROW(transformator.foldConstSubgraphs(), IE::Exception); -} - -TEST_F(RemoveLayerTests, canFullTrim) { - IE::BlobMap refBlobs = initConstLayers({"input1", "input2", "input3"}); - auto layer6 = getLayer("layer6"); - { // TODO: method for marking layers - getLayer("layer1")->type = "Mul"; - getLayer("layer2")->type = "Shape"; - getLayer("layer3")->type = "Power"; - getLayer("layer3")->params = {{"power", "1"}, - {"scale", "2"}, - {"shift", "-4"}}; - getLayer("layer4")->type = "Mul"; - getLayer("layer5")->type = "Mul"; - layer6->type = "Reshape"; - } - - IE::ConstTransformer transformator(net.get()); - transformator.fullTrim(); - - IE::CNNNetwork cnnNetwork(net); - std::string newName = "layer5__data9__Const"; - ASSERT_THROW(CommonTestUtils::getLayerByName(cnnNetwork, newName.c_str()), IE::NotFound); - ASSERT_EQ(net->allLayers().size(), 2); - ASSERT_EQ(layer6->insData.size(), 1); - ASSERT_EQ(layer6->insData[0].lock(), getData("data10")); -} - -TEST_F(RemoveLayerTests, canFullTrimAndSaveNeededData) { - IE::BlobMap refBlobs = initConstLayers({"input1", "input2", "input3", "layer3"}); - auto layer6 = getLayer("layer6"); - { - getLayer("layer1")->type = "Mul"; - getLayer("layer2")->type = "Shape"; - getLayer("layer3")->type = "Const"; // this is the Const layer we need to keep - getLayer("layer4")->type = "Mul"; - getLayer("layer5")->type = "Mul"; - layer6->type = "Reshape"; - } - net.get()->addOutput("data8"); - IE::ConstTransformer transformator(net.get()); - transformator.fullTrim(); - - IE::CNNNetwork cnnNetwork(net); - std::string newName = "layer5__data9__Const"; - ASSERT_THROW(CommonTestUtils::getLayerByName(cnnNetwork, newName.c_str()), IE::NotFound); - ASSERT_EQ(net->allLayers().size(), 3); - ASSERT_NE(net->allLayers().find("layer3")->second, nullptr); -} - -TEST_F(AdvancedShapeInferTests, canFullTrimConstToReshape) { - // - // I2-d2 - // \ - // I1-d1-Reshape-d3-L2-d4 - // - net = netBuilder - .data("data1", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{3, 1, 1}, IE::Layout::CHW)) - .data("data2", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{3}, IE::Layout::C)) - .data("data3", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1, 1, 1}, IE::Layout::CHW)) - .data("data4", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1, 1, 1}, IE::Layout::CHW)) - .layer(IE::LayerParams{"input1", "Input", IE::Precision::I32}) - .layer(IE::LayerParams{"input2", "Input", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer1", "Reshape", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer2", "dummy", IE::Precision::FP32}) - .linkToData("input1", "data1") - .linkToData("input2", "data2") - .linkDataTo("data1", "layer1") - .linkDataTo("data2", "layer1") - .linkToData("layer1", "data3") - .linkDataTo("data3", "layer2") - .linkToData("layer2", "data4") - .addInput("data1") - .addInput("data2") - .finalize(); - - IE::BlobMap refBlobs = initConstLayers({"input2"}); - auto layer1 = getLayer("layer1"); - - IE::ConstTransformer transformator(net.get()); - transformator.fullTrim(); - - IE::CNNNetwork cnnNetwork(net); - ASSERT_EQ(net->allLayers().size(), 3); - ASSERT_EQ(layer1->insData.size(), 1); - ASSERT_EQ(layer1->insData[0].lock(), getData("data1")); -} - -TEST_F(AdvancedShapeInferTests, canFullTrimConstToMVN) { - // - // I2-d2 - // \ - // I1-d1-Reshape-d3-L2-d4 - // - net = netBuilder - .data("data1", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{3, 1, 1}, IE::Layout::CHW)) - .data("data2", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{3}, IE::Layout::C)) - .data("data3", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1, 1, 1}, IE::Layout::CHW)) - .data("data4", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1, 1, 1}, IE::Layout::CHW)) - .layer(IE::LayerParams{"input1", "Const", IE::Precision::I32}) - .layer(IE::LayerParams{"input2", "Const", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer1", "MVN", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer2", "dummy", IE::Precision::FP32}) - .linkToData("input1", "data1") - .linkToData("input2", "data2") - .linkDataTo("data1", "layer1") - .linkDataTo("data2", "layer1") - .linkToData("layer1", "data3") - .linkDataTo("data3", "layer2") - .linkToData("layer2", "data4") - .addInput("data1") - .addInput("data2") - .finalize(); - - IE::BlobMap refBlobs = initConstLayers({"input1", "input2"}); - auto layer1 = getLayer("layer1"); - - IE::ConstTransformer transformator(net.get()); - ASSERT_NO_THROW(transformator.fullTrim()); -} - -TEST_F(AdvancedShapeInferTests, canReshape) { - // - // I2-d2-Shape - // \ - // d3 - // \ - // I1-d1-Reshape-d4 - // - net = netBuilder - .data("data1", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{3, 1, 1}, IE::Layout::CHW)) - .data("data2", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1, 1, 1}, IE::Layout::CHW)) - .data("data3", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1}, IE::Layout::C)) - .data("data4", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1, 1, 1}, IE::Layout::CHW)) - .layer(IE::LayerParams{"input1", "input", IE::Precision::FP32}) - .layer(IE::LayerParams{"input2", "Input", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer1", "Reshape", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer2", "Shape", IE::Precision::FP32}) - .linkToData("input1", "data1") - .linkToData("input2", "data2") - .linkDataTo("data1", "layer1") - .linkDataTo("data2", "layer2") - .linkToData("layer2", "data3") - .linkDataTo("data3", "layer1") - .linkToData("layer1", "data4") - .addInput("data1") - .addInput("data2") - .finalize(); - originalLayersNum = net->allLayers().size(); - IE::CNNNetwork cnnNetwork(net); - IE::SizeVector newShape = {1, 1, 1}; - std::map inputShapes = {{"data2", newShape}}; - cnnNetwork.reshape(inputShapes); - - ASSERT_NO_THROW(CommonTestUtils::getLayerByName(cnnNetwork, "layer2")); - ASSERT_EQ(getData("data3")->getTensorDesc().getDims(), IE::SizeVector{1}); - ASSERT_EQ(net->allLayers().size(), originalLayersNum); - - IE::ConstTransformer transformator(net.get()); - transformator.fullTrim(); - - ASSERT_THROW(CommonTestUtils::getLayerByName(cnnNetwork, "layer2"), IE::NotFound); - ASSERT_EQ(getData("data4")->getTensorDesc().getDims(), newShape); - ASSERT_EQ(net->allLayers().size(), originalLayersNum - 1); -} - -TEST_F(AdvancedShapeInferTests, canReshape2) { - // - // I3-d3-Shape(L3)-d5 - // \ - // I2-d2-Shape(L2)-d4-Power(L4)-d6-Mul(L5)-d7 - // \ - // I1-d1-Reshape(L1)-d8 - // - net = netBuilder - .data("data1", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1}, IE::Layout::C)) - .data("data2", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1, 1, 1}, IE::Layout::CHW)) - .data("data3", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1, 1, 1}, IE::Layout::CHW)) - .data("data4", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1}, IE::Layout::C)) - .data("data5", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1}, IE::Layout::C)) - .data("data6", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1}, IE::Layout::C)) - .data("data7", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1}, IE::Layout::C)) - .data("data8", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1, 1, 1}, IE::Layout::CHW)) - .layer(IE::LayerParams{"input1", "input", IE::Precision::FP32}) - .layer(IE::LayerParams{"input2", "Input", IE::Precision::FP32}) - .layer(IE::LayerParams{"input3", "Input", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer1", "Reshape", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer2", "Shape", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer3", "Shape", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer4", "Power", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer5", "Mul", IE::Precision::FP32}) - .linkToData("input1", "data1") - .linkToData("input2", "data2") - .linkToData("input3", "data3") - - .linkDataTo("data1", "layer1") - .linkDataTo("data2", "layer2") - .linkDataTo("data3", "layer3") - - .linkToData("layer2", "data4") - .linkToData("layer3", "data5") - - .linkDataTo("data4", "layer4") - - .linkToData("layer4", "data6") - - .linkDataTo("data5", "layer5") - .linkDataTo("data6", "layer5") - - .linkToData("layer5", "data7") - - .linkDataTo("data7", "layer1") - - .linkToData("layer1", "data8") - - .addInput("data1") - .addInput("data2") - .addInput("data3") - .finalize(); - originalLayersNum = net->allLayers().size(); - IE::CNNNetwork cnnNetwork(net); - IE::SizeVector newShape = {1, 1, 1}; - std::map inputShapes = {{"data1", {1}}, - {"data2", {1, 1, 1}}, - {"data3", {1, 1, 1}}}; - getLayer("layer4")->params = {{"power", "1"}, - {"scale", "2"}, - {"shift", "1"}}; - - cnnNetwork.reshape(inputShapes); - - ASSERT_EQ(getData("data7")->getTensorDesc().getDims(), IE::SizeVector{1}); - ASSERT_EQ(net->allLayers().size(), originalLayersNum); - - IE::ConstTransformer transformator(net.get()); - transformator.fullTrim(); - - ASSERT_EQ(net->allLayers().size(), originalLayersNum - 4); - ASSERT_EQ(getData("data8")->getTensorDesc().getDims(), newShape); -} - -TEST_F(AdvancedShapeInferTests, canReshapeConst) { - // - // Const-d2 - // \ - // I1-d1-Reshape(L1)-d3 - // - net = netBuilder - .data("data1", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1 }, IE::Layout::C)) - .data("data2", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 3 }, IE::Layout::C)) - .data("data3", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{ 1, 1, 1 }, IE::Layout::CHW)) - .layer(IE::LayerParams{"input1", "input", IE::Precision::FP32}) - .layer(IE::LayerParams{"const1", "dummy", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer1", "Reshape", IE::Precision::FP32}) - .linkToData("input1", "data1") - .linkToData("const1", "data2") - .linkDataTo("data1", "layer1") - .linkDataTo("data2", "layer1") - .linkToData("layer1", "data3") - .addInput("data1") - .finalize(); - originalLayersNum = net->allLayers().size(); - IE::CNNNetwork cnnNetwork(net); - initConstLayers({"const1"}); - IE::SizeVector newOutShape = {1, 1, 1}; - IE::SizeVector newInShape = {IE::details::product(newOutShape)}; - - std::map inputShapes = {{"data1", newInShape}}; - - cnnNetwork.reshape(inputShapes); - - ASSERT_EQ(net->allLayers().size(), originalLayersNum); - - IE::ConstTransformer transformator(net.get()); - transformator.fullTrim(); - - ASSERT_EQ(net->allLayers().size(), originalLayersNum - 1); - ASSERT_EQ(getData("data1")->getTensorDesc().getDims(), newInShape); - ASSERT_EQ(getData("data3")->getTensorDesc().getDims(), newOutShape); -} - -TEST_F(AdvancedShapeInferTests, canReshapeCHWConst) { - // - // Const-d1-Tile-d2 - // - net = netBuilder - .data("data1", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1, 1, 3}, IE::Layout::CHW)) - .data("data2", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1, 1, 1}, IE::Layout::CHW)) - .layer(IE::LayerParams{"const", "dummy", IE::Precision::FP32}) - .layer(IE::LayerParams{"tile", "Tile", IE::Precision::FP32}) - .linkToData("const", "data1") - .linkDataTo("data1", "tile") - .linkToData("tile", "data2") - .addInput("data1") - .finalize(); - getLayer("tile")->params = {{"axis", "0"}, - {"tiles", "2"}}; - originalLayersNum = net->allLayers().size(); - IE::CNNNetwork cnnNetwork(net); - initConstLayers({"const"}); - - cnnNetwork.reshape({}); - - IE::SizeVector expectedDims = {1, 1, 1}; - ASSERT_EQ(getData("data2")->getTensorDesc().getDims(), expectedDims); -} - -TEST_F(AdvancedShapeInferTests, canReshapeWithScalar) { - // - // Scalar-d2 - // \ - // I1-d1-Reshape(L1)-d3 - // - net = netBuilder - .data("data1", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1}, IE::Layout::C)) - .data("data2", IE::TensorDesc(IE::Precision::FP32, IE::Layout::SCALAR)) - .data("data3", IE::TensorDesc(IE::Precision::FP32, IE::SizeVector{1}, IE::Layout::C)) - .layer(IE::LayerParams{"input1", "input", IE::Precision::FP32}) - .layer(IE::LayerParams{"scalar", "dummy", IE::Precision::FP32}) - .layer(IE::LayerParams{"layer1", "Reshape", IE::Precision::FP32}) - .linkToData("input1", "data1") - .linkToData("scalar", "data2") - .linkDataTo("data1", "layer1") - .linkDataTo("data2", "layer1") - .linkToData("layer1", "data3") - .addInput("data1") - .finalize(); - originalLayersNum = net->allLayers().size(); - IE::CNNNetwork cnnNetwork(net); - initConstLayers({"scalar"}); - IE::SizeVector newOutShape = {1}; - IE::SizeVector newInShape = {IE::details::product(newOutShape)}; - - std::map inputShapes = {{"data1", newInShape}}; - - cnnNetwork.reshape(inputShapes); - - ASSERT_EQ(net->allLayers().size(), originalLayersNum); - - IE::ConstTransformer transformator(net.get()); - transformator.fullTrim(); - - ASSERT_EQ(net->allLayers().size(), originalLayersNum - 1); - ASSERT_EQ(getData("data1")->getTensorDesc().getDims(), newInShape); - ASSERT_EQ(getData("data3")->getTensorDesc().getDims(), newOutShape); -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_const_infer_test.hpp b/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_const_infer_test.hpp deleted file mode 100644 index cda98702745..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_const_infer_test.hpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include "blob_factory.hpp" -#include "debug.h" -#include "util_test.hpp" - -namespace IE = InferenceEngine; - -class ConstTransformatorTest : public IE::ConstTransformer { -public: - explicit ConstTransformatorTest(IE::details::CNNNetworkImpl* network) : IE::ConstTransformer(network) {} - - const std::map - getConstLayers(const std::vector& sortedLayers) override { - return ConstTransformer::getConstLayers(sortedLayers); - } - - const InferenceEngine::BlobMap getConstData(const std::map& constLayers, - const std::vector& sortedLayers) override { - return ConstTransformer::getConstData(constLayers, sortedLayers); - } - - std::vector - foldConstSubgraphsInternal(const std::map& constLayers, const IE::BlobMap& constData, - const std::vector& sortedLayers) override { - auto layers = ConstTransformer::foldConstSubgraphsInternal(constLayers, constData, sortedLayers); - ConstTransformer::cleanup(); - return layers; - } - - void trimShapeInputs(const std::vector& constLayers, - std::vector& allLayers) override { - ConstTransformer::trimShapeInputs(constLayers, allLayers); - } - -}; - -class RemoveLayerTests : public testing::Test { -protected: - void SetUp() override; - - // - // I1-d1-L1-d4 I4 - // / \ \ \ - // | d7 \ d10 - // | | \ / - // I2-d2-L2-d5-L4-d6-L5-d9-L10 - // / / - // / ____d8___/ - // / / - // I3-d3-L3 - // - IE::details::CNNNetworkImplPtr getNetwork(); - - IE::CNNLayerPtr getLayer(const std::string& name); - - IE::DataPtr getData(const std::string& name); - - IE::BlobMap fillConstData(const std::vector& constLayers); - - IE::BlobMap initConstLayers(const std::vector& constLayers); - - IE::BlobMap fillConstDataDiffPrec(const std::vector& constLayers); - - IE::BlobMap initConstLayersDiffPrec(const std::vector& constLayers); - - NetBuilder netBuilder; - IE::details::CNNNetworkImplPtr net; - size_t originalLayersNum; - std::unique_ptr testTransformator; -}; - -class AdvancedShapeInferTests : public RemoveLayerTests { -protected: - void SetUp() override {}; -}; diff --git a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_test.cpp b/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_test.cpp deleted file mode 100644 index e8326c8d78a..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_test.cpp +++ /dev/null @@ -1,464 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include - -#include -#include -#include -#include "util_test.hpp" -#include - -namespace { -bool checkLayers(const std::vector& layers, std::initializer_list layersToCheck) { - if (layers.size() != layersToCheck.size()) { - return false; - } - for (auto&& layerToCheck: layersToCheck) { - bool found = false; - for (auto&& layer: layers) { - if (layerToCheck == layer->name) { - found = true; - break; - } - } - if (!found) { - return false; - } - } - return true; -} -} - -TEST(UtilTests, contains) { - std::unordered_set temp_set; - temp_set.insert(42); - EXPECT_TRUE(contains(temp_set, 42)); - EXPECT_FALSE(contains(temp_set, 5)); -} - -namespace { -template -bool checkLayerCloning() { - T srcLayer(IE::LayerParams{"layer","dummy",IE::Precision::FP32}); - auto cloned = IE::clonelayer(srcLayer); - return nullptr != std::dynamic_pointer_cast(cloned); -} -} - -TEST(UtilTests, cloneLayers) { - { - IE::CNNLayer srclayer(IE::LayerParams{"layer","dummy",IE::Precision::FP32}); - auto data1 = std::make_shared("data1",IE::Precision::FP32); - auto data2 = std::make_shared("data1",IE::Precision::FP32); - srclayer.insData.push_back(data1); - srclayer.outData.push_back(data2); - int dummy = 123; - srclayer.userValue.v_ptr = &dummy; - srclayer.params["foo"] = "1"; - srclayer.params["bar"] = "2"; - auto blob = IE::make_shared_blob(IE::TensorDesc(IE::Precision::FP32, IE::NCHW)); - srclayer.blobs["baz"] = blob; - auto cloned = IE::clonelayer(srclayer); - ASSERT_NE(nullptr, cloned); - EXPECT_EQ(srclayer.name, cloned->name); - EXPECT_EQ(srclayer.type, cloned->type); - EXPECT_EQ(srclayer.precision, cloned->precision); - EXPECT_EQ(srclayer.userValue.v_ptr, cloned->userValue.v_ptr); - EXPECT_EQ(srclayer.params, cloned->params); - EXPECT_EQ(srclayer.blobs, cloned->blobs); - EXPECT_EQ(0, cloned->insData.size()); - EXPECT_EQ(0, cloned->outData.size()); - } - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); - EXPECT_TRUE(checkLayerCloning()); -} - -namespace { -IE::CNNLayerPtr getLayer(const IE::details::CNNNetworkImplPtr n, - const char* name) { - if (InferenceEngine::details::contains(n->allLayers(), name)) { - return n->allLayers().find(name)->second; - } - return nullptr; -}; -} // namespace - -TEST(UtilTests, cloneNet) { - // - // I O - // \ / - // I-L1->L2->L3->L4->L5->O - // \ / - // L6 -> L7 - // - auto net = NetBuilder() - // input is 4d to allow setting of batch, otherwise, CHW notation doesnt have batches - .data("data1", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1,1 }, IE::Layout::NCHW)) - .data("data2", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data3", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data4", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data5", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data6", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data7", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data8", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data9", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data10", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data11", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .layer(IE::LayerParams{"layer1","dummy",IE::Precision::Q78}) - .layer(IE::LayerParams{"layer2","dummy",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"layer3","dummy",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"layer4","dummy",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"layer5","dummy",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"layer6","dummy",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"layer7","dummy",IE::Precision::UNSPECIFIED}) - .linkData("data1","data2","layer1") - .linkData("data2","data3","layer2") - .linkData("data3","data4","layer3") - .linkData("data4","data5","layer4") - .linkData("data5","data6","layer5") - - .linkLayers("layer2", "layer6", "data7") - .linkLayers("layer6", "layer7", "data8") - .linkLayers("layer7", "layer4", "data9") - - .linkDataTo("data10","layer2") - .linkToData("layer3","data11") - - .finalize(); - - net->setName("net"); - - { - IE::InputsDataMap inputs; - net->getInputsInfo(inputs); - for (auto &&it : inputs) { - it.second->getPreProcess().init(1); - it.second->getPreProcess().setMeanImage(IE::make_shared_blob({ IE::Precision::FP32, {1,1,1}, IE::Layout::CHW })); - it.second->getPreProcess().setResizeAlgorithm(IE::ResizeAlgorithm::RESIZE_BILINEAR); - } - } - - { - auto layer = getLayer(net, "layer1"); - auto cloned = IE::cloneNet({layer}); - EXPECT_EQ(2, cloned->layerCount()); - auto clonedLayer = getLayer(cloned, "layer1"); - ASSERT_NE(nullptr, clonedLayer); - EXPECT_EQ(layer->type, clonedLayer->type); - - IE::InputsDataMap inputs; - IE::OutputsDataMap outputs; - cloned->getInputsInfo(inputs); - cloned->getOutputsInfo(outputs); - ASSERT_EQ(1, inputs.size()); - ASSERT_EQ(1, outputs.size()); - EXPECT_TRUE(contains(inputs,"data1")); - EXPECT_TRUE(contains(outputs,"data2")); - } - { - auto layer1 = getLayer(net, "layer1"); - auto layer2 = getLayer(net, "layer2"); - auto cloned = IE::cloneNet({layer1,layer2}); - EXPECT_EQ(4, cloned->layerCount()); - auto clonedLayer1 = getLayer(cloned, "layer1"); - auto clonedLayer2 = getLayer(cloned, "layer2"); - ASSERT_NE(nullptr, clonedLayer1); - ASSERT_NE(nullptr, clonedLayer2); - - IE::InputsDataMap inputs; - IE::OutputsDataMap outputs; - cloned->getInputsInfo(inputs); - cloned->getOutputsInfo(outputs); - ASSERT_EQ(2, inputs.size()); - ASSERT_EQ(2, outputs.size()); - EXPECT_TRUE(contains(inputs,"data1")); - EXPECT_TRUE(contains(inputs,"data10")); - EXPECT_TRUE(contains(outputs,"data3")); - EXPECT_TRUE(contains(outputs,"data7")); - } - { - auto layer4 = getLayer(net, "layer4"); - auto layer5 = getLayer(net, "layer5"); - auto cloned = IE::cloneNet({layer4,layer5}); - EXPECT_EQ(4, cloned->layerCount()); - auto clonedLayer4 = getLayer(cloned, "layer4"); - auto clonedLayer5 = getLayer(cloned, "layer5"); - ASSERT_NE(nullptr, clonedLayer4); - ASSERT_NE(nullptr, clonedLayer5); - - ASSERT_EQ(2, clonedLayer4->insData.size()); - ASSERT_EQ(1, clonedLayer4->outData.size()); - - EXPECT_EQ("data4", clonedLayer4->insData[0].lock()->getName()); - EXPECT_EQ("data9", clonedLayer4->insData[1].lock()->getName()); - EXPECT_EQ("data5", clonedLayer4->outData[0]->getName()); - - ASSERT_EQ(1, clonedLayer5->insData.size()); - ASSERT_EQ(1, clonedLayer5->outData.size()); - - EXPECT_EQ("data5", clonedLayer5->insData[0].lock()->getName()); - EXPECT_EQ("data6", clonedLayer5->outData[0]->getName()); - - IE::InputsDataMap inputs; - IE::OutputsDataMap outputs; - cloned->getInputsInfo(inputs); - cloned->getOutputsInfo(outputs); - ASSERT_EQ(2, inputs.size()); - ASSERT_EQ(1, outputs.size()); - EXPECT_TRUE(contains(inputs,"data4")); - EXPECT_TRUE(contains(inputs,"data9")); - EXPECT_TRUE(contains(outputs,"data6")); - } - { - auto layer3 = getLayer(net, "layer3"); - auto cloned = IE::cloneNet({layer3}); - EXPECT_EQ(2, cloned->layerCount()); - auto clonedLayer3 = getLayer(cloned, "layer3"); - ASSERT_NE(nullptr, clonedLayer3); - - ASSERT_EQ(1, clonedLayer3->insData.size()); - ASSERT_EQ(2, clonedLayer3->outData.size()); - - EXPECT_EQ("data3", clonedLayer3->insData[0].lock()->getName()); - EXPECT_EQ("data4", clonedLayer3->outData[0]->getName()); - EXPECT_EQ("data11", clonedLayer3->outData[1]->getName()); - - IE::InputsDataMap inputs; - IE::OutputsDataMap outputs; - cloned->getInputsInfo(inputs); - cloned->getOutputsInfo(outputs); - ASSERT_EQ(1, inputs.size()); - ASSERT_EQ(2, outputs.size()); - EXPECT_TRUE(contains(inputs,"data3")); - EXPECT_TRUE(contains(outputs,"data4")); - EXPECT_TRUE(contains(outputs,"data11")); - } - { - auto layer1 = getLayer(net, "layer1"); - auto layer2 = getLayer(net, "layer2"); - auto layer3 = getLayer(net, "layer3"); - auto layer4 = getLayer(net, "layer4"); - auto layer5 = getLayer(net, "layer5"); - auto layer6 = getLayer(net, "layer6"); - auto layer7 = getLayer(net, "layer7"); - auto cloned = IE::cloneNet({layer1,layer2,layer3,layer4,layer5,layer6,layer7}); - EXPECT_EQ(9, cloned->layerCount()); - auto clonedLayer1 = getLayer(cloned, "layer1"); - auto clonedLayer2 = getLayer(cloned, "layer2"); - auto clonedLayer3 = getLayer(cloned, "layer3"); - auto clonedLayer4 = getLayer(cloned, "layer4"); - auto clonedLayer5 = getLayer(cloned, "layer5"); - auto clonedLayer6 = getLayer(cloned, "layer6"); - auto clonedLayer7 = getLayer(cloned, "layer7"); - ASSERT_NE(nullptr, clonedLayer1); - ASSERT_NE(nullptr, clonedLayer2); - ASSERT_NE(nullptr, clonedLayer3); - ASSERT_NE(nullptr, clonedLayer4); - ASSERT_NE(nullptr, clonedLayer5); - ASSERT_NE(nullptr, clonedLayer6); - ASSERT_NE(nullptr, clonedLayer7); - - ASSERT_EQ(1, clonedLayer1->insData.size()); - ASSERT_EQ(1, clonedLayer1->outData.size()); - EXPECT_EQ("data1", clonedLayer1->insData[0].lock()->getName()); - EXPECT_EQ("data2", clonedLayer1->outData[0]->getName()); - - ASSERT_EQ(2, clonedLayer2->insData.size()); - ASSERT_EQ(2, clonedLayer2->outData.size()); - EXPECT_EQ("data2", clonedLayer2->insData[0].lock()->getName()); - EXPECT_EQ("data10", clonedLayer2->insData[1].lock()->getName()); - EXPECT_EQ("data3", clonedLayer2->outData[0]->getName()); - EXPECT_EQ("data7", clonedLayer2->outData[1]->getName()); - - ASSERT_EQ(1, clonedLayer3->insData.size()); - ASSERT_EQ(2, clonedLayer3->outData.size()); - EXPECT_EQ("data3", clonedLayer3->insData[0].lock()->getName()); - EXPECT_EQ("data4", clonedLayer3->outData[0]->getName()); - EXPECT_EQ("data11", clonedLayer3->outData[1]->getName()); - - ASSERT_EQ(2, clonedLayer4->insData.size()); - ASSERT_EQ(1, clonedLayer4->outData.size()); - EXPECT_EQ("data4", clonedLayer4->insData[0].lock()->getName()); - EXPECT_EQ("data9", clonedLayer4->insData[1].lock()->getName()); - EXPECT_EQ("data5", clonedLayer4->outData[0]->getName()); - - ASSERT_EQ(1, clonedLayer5->insData.size()); - ASSERT_EQ(1, clonedLayer5->outData.size()); - EXPECT_EQ("data5", clonedLayer5->insData[0].lock()->getName()); - EXPECT_EQ("data6", clonedLayer5->outData[0]->getName()); - - ASSERT_EQ(1, clonedLayer6->insData.size()); - ASSERT_EQ(1, clonedLayer6->outData.size()); - EXPECT_EQ("data7", clonedLayer6->insData[0].lock()->getName()); - EXPECT_EQ("data8", clonedLayer6->outData[0]->getName()); - - ASSERT_EQ(1, clonedLayer7->insData.size()); - ASSERT_EQ(1, clonedLayer7->outData.size()); - EXPECT_EQ("data8", clonedLayer7->insData[0].lock()->getName()); - EXPECT_EQ("data9", clonedLayer7->outData[0]->getName()); - - IE::InputsDataMap inputs; - IE::OutputsDataMap outputs; - cloned->getInputsInfo(inputs); - cloned->getOutputsInfo(outputs); - ASSERT_EQ(2, inputs.size()); - ASSERT_EQ(2, outputs.size()); - EXPECT_TRUE(contains(inputs,"data1")); - EXPECT_TRUE(contains(inputs,"data10")); - EXPECT_TRUE(contains(outputs,"data11")); - EXPECT_TRUE(contains(outputs,"data6")); - } - { - auto cloned = IE::cloneNet(IE::CNNNetwork(net)); - auto layer1 = getLayer(cloned, "layer1"); - auto layer2 = getLayer(cloned, "layer2"); - EXPECT_TRUE(IE::Precision::Q78 == layer1->precision); - EXPECT_TRUE(IE::Precision::UNSPECIFIED == layer2->precision); - } - { - auto cloned = IE::cloneNet(IE::CNNNetwork(net)); - EXPECT_EQ("net", cloned->getName()); - } - { - auto cloned = IE::cloneNet(IE::CNNNetwork(net)); - IE::InputsDataMap clonedInputs; - cloned->getInputsInfo(clonedInputs); - for (auto &&clonedInput : clonedInputs) { - EXPECT_EQ(1, clonedInput.second->getPreProcess().getNumberOfChannels()); - EXPECT_TRUE(IE::MeanVariant::MEAN_IMAGE == clonedInput.second->getPreProcess().getMeanVariant()); - EXPECT_TRUE(IE::ResizeAlgorithm::RESIZE_BILINEAR == clonedInput.second->getPreProcess().getResizeAlgorithm()); - } - } -} - -TEST(UtilTests, cloneNet_input) { - // - // I1-d1-L1 - // - // I2-d2 - // \ - // L2 - // / - // I3-d3 - // \ - // L3 - // - auto net = NetBuilder() - .data("data1", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data2", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data3", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .layer(IE::LayerParams{"input1","input",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"input2","Input",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"input3","input",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"layer1","dummy",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"layer2","dummy",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"layer3","dummy",IE::Precision::UNSPECIFIED}) - - .linkToData("input1", "data1") - .linkToData("input2", "data2") - .linkToData("input3", "data3") - - .linkDataTo("data1", "layer1") - .linkDataTo("data2", "layer2") - .linkDataTo("data3", "layer2") - .linkDataTo("data3", "layer3") - - .finalize(); - - getLayer(net, "input1")->params["custom_param1"] = "custom_val1"; - getLayer(net, "input2")->params["custom_param2"] = "custom_val2"; - getLayer(net, "input3")->params["custom_param3"] = "custom_val3"; - - auto cloned = IE::cloneNet({getLayer(net, "layer1"), - getLayer(net, "layer2"), - getLayer(net, "layer3")}); - - ASSERT_EQ(6, cloned->layerCount()); - ASSERT_NE(nullptr, getLayer(cloned, "input1")); - ASSERT_NE(nullptr, getLayer(cloned, "input2")); - ASSERT_NE(nullptr, getLayer(cloned, "input3")); - ASSERT_EQ("input", getLayer(cloned, "input1")->type); - ASSERT_EQ("Input", getLayer(cloned, "input2")->type); - ASSERT_EQ("input", getLayer(cloned, "input3")->type); - ASSERT_EQ("custom_val1", getLayer(cloned, "input1")->params["custom_param1"]); - ASSERT_EQ("custom_val2", getLayer(cloned, "input2")->params["custom_param2"]); - ASSERT_EQ("custom_val3", getLayer(cloned, "input3")->params["custom_param3"]); -} - -TEST(UtilTests, cloneNet_const) { - // - // C1-d1-L1 - // - // C2-d2 - // \ - // L2 - // / - // C3-d3 - // \ - // L3 - // - auto net = NetBuilder() - .data("data1", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data2", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .data("data3", IE::TensorDesc(IE::Precision::UNSPECIFIED, IE::SizeVector{ 1,1,1 }, IE::Layout::CHW)) - .layer(IE::LayerParams{"input1","const",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"input2","Const",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"input3","const",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"layer1","dummy",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"layer2","dummy",IE::Precision::UNSPECIFIED}) - .layer(IE::LayerParams{"layer3","dummy",IE::Precision::UNSPECIFIED}) - - .linkToData("input1", "data1") - .linkToData("input2", "data2") - .linkToData("input3", "data3") - - .linkDataTo("data1", "layer1") - .linkDataTo("data2", "layer2") - .linkDataTo("data3", "layer2") - .linkDataTo("data3", "layer3") - - .finalize(); - - getLayer(net, "input1")->params["custom_param1"] = "custom_val1"; - getLayer(net, "input2")->params["custom_param2"] = "custom_val2"; - getLayer(net, "input3")->params["custom_param3"] = "custom_val3"; - - auto cloned = IE::cloneNet({getLayer(net, "layer1"), - getLayer(net, "layer2"), - getLayer(net, "layer3")}); - - ASSERT_EQ(6, cloned->layerCount()); - ASSERT_NE(nullptr, getLayer(cloned, "input1")); - ASSERT_NE(nullptr, getLayer(cloned, "input2")); - ASSERT_NE(nullptr, getLayer(cloned, "input3")); - ASSERT_EQ("const", getLayer(cloned, "input1")->type); - ASSERT_EQ("Const", getLayer(cloned, "input2")->type); - ASSERT_EQ("const", getLayer(cloned, "input3")->type); - ASSERT_EQ("custom_val1", getLayer(cloned, "input1")->params["custom_param1"]); - ASSERT_EQ("custom_val2", getLayer(cloned, "input2")->params["custom_param2"]); - ASSERT_EQ("custom_val3", getLayer(cloned, "input3")->params["custom_param3"]); -} diff --git a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_test.hpp b/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_test.hpp deleted file mode 100644 index 13d81f577a1..00000000000 --- a/src/plugins/intel_gna/tests/deprecated/unit/inference_engine_tests/util_test.hpp +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include -#include -#include -#include - -namespace IE = InferenceEngine; -using IE::details::contains; - -class NetBuilder { - using LayersMap = std::unordered_map; - using DataMap = std::unordered_map; - using InputsSet = std::unordered_set; - LayersMap _layers; - DataMap _data; - InputsSet _inputs; -public: - NetBuilder() = default; - - NetBuilder(const NetBuilder&) = delete; - - template - NetBuilder& data(Args&& ... args) { - auto newData = std::make_shared(std::forward(args)...); - assert(!contains(_data, newData->getName())); - _data[newData->getName()] = newData; - return *this; - } - - template - NetBuilder& layer(Args&& ... args) { - auto newLayer = std::make_shared(std::forward(args)...); - assert(!contains(_layers, newLayer->name)); - _layers[newLayer->name] = std::static_pointer_cast(newLayer); - return *this; - } - - const LayersMap& getLayersMap() const { - return _layers; - } - - const DataMap& getDataMap() const { - return _data; - } - - NetBuilder& linkDataTo(const std::string& dataName, - const std::string& nextlayerName) { - assert(contains(_layers, nextlayerName)); - assert(contains(_data, dataName)); - - auto nextlayer = _layers[nextlayerName]; - auto data = _data[dataName]; - - nextlayer->insData.push_back(data); - getInputTo(data).insert({nextlayerName, nextlayer}); - return *this; - } - - NetBuilder& linkToData(const std::string& prevlayerName, - const std::string& dataName) { - assert(contains(_layers, prevlayerName)); - assert(contains(_data, dataName)); - - auto prevlayer = _layers[prevlayerName]; - auto data = _data[dataName]; - assert(nullptr == getCreatorLayer(data).lock()); - - prevlayer->outData.push_back(data); - getCreatorLayer(data) = prevlayer; - return *this; - } - - NetBuilder& linkLayers(const std::string& prevlayerName, - const std::string& nextlayerName, - const std::string& dataName) { - linkToData(prevlayerName, dataName); - linkDataTo(dataName, nextlayerName); - return *this; - } - - NetBuilder& linkData(const std::string& prevDataName, - const std::string& nextDataName, - const std::string& layerName) { - linkDataTo(prevDataName, layerName); - linkToData(layerName, nextDataName); - return *this; - } - - template - NetBuilder& addInput(const std::string& dataName, Args&& ... args) { - assert(!dataName.empty()); - assert(contains(_data, dataName)); - auto input = std::make_shared( - std::forward(args)...); - input->setInputData(_data[dataName]); - _inputs.insert(std::move(input)); - return *this; - } - - IE::details::CNNNetworkImplPtr finalize() { - auto net = std::make_shared(); - - for (auto&& it: _data) { - auto& data = it.second; - net->getData(it.first) = data; - if (nullptr == getCreatorLayer(data).lock()) { - auto input = std::make_shared(); - input->setInputData(data); - net->setInputInfo(input); - } - } - for (auto&& it: _layers) { - net->addLayer(it.second); - } - for (auto& i : _inputs) { - net->setInputInfo(std::move(i)); - } - - net->resolveOutput(); - - return net; - } -}; diff --git a/src/plugins/intel_gna/tests/functional/CMakeLists.txt b/src/plugins/intel_gna/tests/functional/CMakeLists.txt deleted file mode 100644 index c1d1c74c46d..00000000000 --- a/src/plugins/intel_gna/tests/functional/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - ov_add_compiler_flags(-Wno-literal-conversion) -endif() - -set(TARGET_NAME ov_gna_func_tests) - -ov_add_test_target( - NAME ${TARGET_NAME} - ROOT ${CMAKE_CURRENT_SOURCE_DIR} - INCLUDES - ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDENCIES - openvino_intel_gna_plugin - LINK_LIBRARIES - funcSharedTests - ADD_CLANG_FORMAT - LABELS - OV GNA -) - -target_compile_definitions(${TARGET_NAME} - PUBLIC ${ARGV} - GNA_DATA_PATH=\"${CMAKE_CURRENT_SOURCE_DIR}/data\") diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/backward_compatibility.cpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/backward_compatibility.cpp deleted file mode 100644 index 87cc38e55bf..00000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/backward_compatibility/backward_compatibility.cpp +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include - -#include -#include -#include - -#include "helpers/test_model_repo.hpp" -#include "openvino/core/model.hpp" -#include "openvino/core/shape.hpp" -#include "openvino/core/type.hpp" -#include "openvino/opsets/opset10.hpp" -#include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -using namespace ov::opset10; - -typedef std::tuple, // Export Configuration - std::map // Import Configuration - > - exportImportNetworkParams; - -class BackwardCompatibility : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { -public: - static std::string get_test_case_name(testing::TestParamInfo obj) { - ov::element::Type input_prc; - std::string target_device; - std::map conf_export; - std::map conf_import; - std::string name_export_model; - std::tie(input_prc, target_device, name_export_model, conf_export, conf_import) = obj.param; - - std::ostringstream result; - result << "input_prc=" << input_prc << "_"; - result << "target_device=" << target_device << "_"; - result << "name_export_model=" << name_export_model << "_"; - for (auto const& conf_item : conf_export) { - result << "_exportConfigItem=" << conf_item.first << "_" << conf_item.second; - } - for (auto const& conf_item : conf_import) { - result << "_importConfigItem=" << conf_item.first << "_" << conf_item.second; - } - return result.str(); - } - - void Run() override { - SKIP_IF_CURRENT_TEST_IS_DISABLED() - functionRefs = ngraph::clone_function(*function); - // load export configuration and save outputs - configuration.insert(m_conf_export.begin(), m_conf_export.end()); - LoadNetwork(); - GenerateInputs(); - Infer(); - auto outputs = GetOutputs(); - - auto output_refs = CalculateRefs(); - Compare(output_refs, outputs); - - for (auto const& config_item : m_conf_import) { - configuration[config_item.first] = config_item.second; - } - - const auto compiled_network = executableNetwork; - auto model = TestDataHelpers::get_data_path() + "/exported_models/" + m_export_model_name; - - const auto imported_network = core->ImportNetwork(model, targetDevice, configuration); - - GenerateInputs(); - Infer(); - - ASSERT_EQ(imported_network.GetInputsInfo().size(), compiled_network.GetInputsInfo().size()); - ASSERT_EQ(imported_network.GetOutputsInfo().size(), compiled_network.GetOutputsInfo().size()); - - for (const auto& next_output : imported_network.GetOutputsInfo()) { - ASSERT_NO_THROW(compiled_network.GetOutputsInfo()[next_output.first]); - } - auto outputs_imported = GetOutputs(); - - ASSERT_EQ(outputs.size(), outputs_imported.size()); - - for (size_t i = 0; i < outputs.size(); i++) { - Compare(outputs[i], outputs_imported[i]); - } - } - -protected: - void SetUp() override { - ov::element::Type prc = ov::element::undefined; - std::tie(prc, targetDevice, m_export_model_name, m_conf_export, m_conf_import) = this->GetParam(); - ov::Shape input_shape{1, 80}; - ov::Shape conv_shape{1, 2, 1, 40}; - ov::Shape split_shape = {input_shape[0], 2 * input_shape[1]}; - ov::ParameterVector inputs = {std::make_shared(prc, split_shape), - std::make_shared(prc, input_shape)}; - - // split layer to split inputs and transpose the part connected to convolution only - auto axis_const = std::make_shared(ov::element::i32, ov::Shape{}, std::vector{1}); - auto split = std::make_shared(inputs[0], axis_const, 2); - - std::vector reshape_pattern{1, 2, 1, -1}; - auto reshape_const = - std::make_shared(ov::element::i32, ov::Shape{reshape_pattern.size()}, reshape_pattern); - - auto split_0_reshape = std::make_shared(split->output(0), reshape_const, true); - auto split_1_reshape = std::make_shared(split->output(1), reshape_const, true); - auto input_1_reshape = std::make_shared(inputs[1], reshape_const, true); - - auto add = std::make_shared(split_0_reshape, input_1_reshape); - auto relu_1 = std::make_shared(add); - - // Convolution to test nchw->nhwc - size_t num_out_channels = 8; - size_t kernel_size = 8; - std::vector filter_weights = - ov::test::utils::generate_float_numbers(num_out_channels * reshape_pattern[1] * kernel_size, -0.1f, 0.1f); - auto conv = ngraph::builder::makeConvolution(relu_1, - prc, - {1, kernel_size}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ngraph::op::PadType::VALID, - num_out_channels, - true, - filter_weights); - - auto relu_2 = std::make_shared(conv); - - // Memory layers - ov::op::util::VariableInfo vi{}; - vi.data_shape = ov::PartialShape(conv_shape); - vi.variable_id = "test_variable"; - vi.data_type = prc; - const auto var = std::make_shared(vi); - std::vector initial_state = - ov::test::utils::generate_float_numbers(ov::shape_size(conv_shape), -3.f, 3.f); - auto initial_state_node = std::make_shared(prc, conv_shape, initial_state); - auto read = std::make_shared(initial_state_node, var); - auto mul = std::make_shared(split_1_reshape, read); - auto assign = std::make_shared(mul, var); - auto relu_3 = std::make_shared(mul); - - ov::SinkVector sinks = {assign}; - ov::ResultVector results; - results.emplace_back(std::make_shared(relu_2)); - results.emplace_back(std::make_shared(relu_3)); - - function = std::make_shared(results, sinks, inputs, "universal_export_model"); - } - - std::map m_conf_export; - std::map m_conf_import; - std::string m_export_model_name; -}; - -class BackwardCompatibilityLegacy : public BackwardCompatibility { -protected: - void SetUp() override { - ov::element::Type prc = ov::element::undefined; - std::tie(prc, targetDevice, m_export_model_name, m_conf_export, m_conf_import) = this->GetParam(); - ov::Shape input_shape{1, 336}; - - auto param = std::make_shared(prc, input_shape); - auto const_eltwise = std::make_shared(prc, input_shape, std::vector{-1}); - auto mul = std::make_shared(param, const_eltwise); - - ov::ResultVector results{std::make_shared(mul)}; - - function = std::make_shared(results, ov::ParameterVector{param}, "ExportBackwordCompatibility"); - } -}; - -TEST_P(BackwardCompatibility, BackwardCompatibility) { - Run(); -} - -TEST_P(BackwardCompatibilityLegacy, BackwardCompatibility) { - Run(); -} - -const std::vector input_precisions = {ov::element::f32, ov::element::f16}; - -const std::vector> export_configs_legacy = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}}}; - -const std::vector> import_configs_legacy = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}}, -}; - -const std::vector> export_configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}, {"GNA_SCALE_FACTOR_1", "327.67"}}}; - -const std::vector> import_configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}, {"GNA_SCALE_FACTOR_1", "327.67"}}}; - -const std::vector export_models_legacy = {"export2dot1.blob", - "export2dot2.blob", - "export2dot3.blob", - "export2dot4.blob", - "export2dot5.blob"}; - -const std::vector export_models = {"export2dot6.blob", "export2dot7.blob", "export2dot8.blob"}; - -// Those tests should not be run in CI due to dependency on model blobs -INSTANTIATE_TEST_SUITE_P(OldVersion, - BackwardCompatibilityLegacy, - ::testing::Combine(::testing::ValuesIn(input_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(export_models_legacy), - ::testing::ValuesIn(export_configs_legacy), - ::testing::ValuesIn(import_configs_legacy)), - BackwardCompatibilityLegacy::get_test_case_name); - -INSTANTIATE_TEST_SUITE_P(OldVersion, - BackwardCompatibility, - ::testing::Combine(::testing::ValuesIn(input_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(export_models), - ::testing::ValuesIn(export_configs), - ::testing::ValuesIn(import_configs)), - BackwardCompatibility::get_test_case_name); 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 deleted file mode 100644 index b2564728153..00000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/base/import_export_base.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "import_export_base.hpp" - -#include - -namespace FuncTestUtils { - -std::string ImportNetworkTestBase::getTestCaseName(testing::TestParamInfo obj) { - std::vector inputShape; - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map exportConfiguration; - std::map importConfiguration; - std::string appHeader; - std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, appHeader) = obj.param; - - std::ostringstream result; - result << "IS=" << ov::test::utils::vec2str(inputShape) << "_"; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : exportConfiguration) { - result << "_exportConfigItem=" << configItem.first << "_" << configItem.second; - } - for (auto const& configItem : importConfiguration) { - result << "_importConfigItem=" << configItem.first << "_" << configItem.second; - } - result << "_appHeader=" << appHeader; - return result.str(); -} - -void ImportNetworkTestBase::exportImportNetwork() { - std::stringstream strm; - strm.write(applicationHeader.c_str(), applicationHeader.size()); - executableNetwork.Export(strm); - - strm.seekg(0, strm.beg); - std::string appHeader(applicationHeader.size(), ' '); - strm.read(&appHeader[0], applicationHeader.size()); - ASSERT_EQ(appHeader, applicationHeader); - executableNetwork = core->ImportNetwork(strm, targetDevice, configuration); -} - -void ImportNetworkTestBase::Run() { - functionRefs = ngraph::clone_function(*function); - TestRun(false); -} - -void ImportNetworkTestBase::TestRun(bool isModelChanged) { - SKIP_IF_CURRENT_TEST_IS_DISABLED() - functionRefs = ngraph::clone_function(*function); - // load export configuration and save outputs - configuration.insert(exportConfiguration.begin(), exportConfiguration.end()); - LoadNetwork(); - GenerateInputs(); - Infer(); - auto actualOutputs = GetOutputs(); - - auto referenceOutputs = CalculateRefs(); - Compare(referenceOutputs, actualOutputs); - - for (auto const& configItem : importConfiguration) { - configuration[configItem.first] = configItem.second; - } - - // for import with different scale factor need to use import configuration to get refference outputs. - if (isModelChanged) { - LoadNetwork(); - GenerateInputs(); - Infer(); - actualOutputs = GetOutputs(); - } - - const auto compiledExecNetwork = executableNetwork; - exportImportNetwork(); - const auto importedExecNetwork = executableNetwork; - - GenerateInputs(); - Infer(); - - ASSERT_EQ(importedExecNetwork.GetInputsInfo().size(), compiledExecNetwork.GetInputsInfo().size()); - ASSERT_EQ(importedExecNetwork.GetOutputsInfo().size(), compiledExecNetwork.GetOutputsInfo().size()); - - for (const auto& next_input : importedExecNetwork.GetInputsInfo()) { - ASSERT_NO_THROW(compiledExecNetwork.GetInputsInfo()[next_input.first]); - Compare(next_input.second->getTensorDesc(), - compiledExecNetwork.GetInputsInfo()[next_input.first]->getTensorDesc()); - } - for (const auto& next_output : importedExecNetwork.GetOutputsInfo()) { - ASSERT_NO_THROW(compiledExecNetwork.GetOutputsInfo()[next_output.first]); - } - auto importedOutputs = GetOutputs(); - - ASSERT_EQ(actualOutputs.size(), importedOutputs.size()); - - for (size_t i = 0; i < actualOutputs.size(); i++) { - Compare(actualOutputs[i]->getTensorDesc(), importedOutputs[i]->getTensorDesc()); - Compare(actualOutputs[i], importedOutputs[i]); - } -} - -} // namespace FuncTestUtils diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/base/import_export_base.hpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/base/import_export_base.hpp deleted file mode 100644 index c4c200c330f..00000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/base/import_export_base.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Input Shape - InferenceEngine::Precision, // Network Precision - std::string, // Target Device - std::map, // Export Configuration - std::map, // Import Configuration - std::string // Application Header - > - exportImportNetworkParams; - -namespace FuncTestUtils { - -class ImportNetworkTestBase : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj); - void Run() override; - void TestRun(bool isModelChanged); - -protected: - std::map exportConfiguration; - std::map importConfiguration; - std::string applicationHeader; - -private: - virtual void exportImportNetwork(); -}; - -} // namespace FuncTestUtils diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_act_conv_act.cpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_act_conv_act.cpp deleted file mode 100644 index 19db46d5a64..00000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_act_conv_act.cpp +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include "functional_test_utils/blob_utils.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Input shape - InferenceEngine::Precision, // Network Precision - std::string, // Target Device - std::map, // Export Configuration - std::map // Import Configuration - > - exportImportNetworkParams; - -namespace LayerTestsDefinitions { - -class ImportActConvActTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - std::vector inputShape; - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map exportConfiguration; - std::map importConfiguration; - std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : exportConfiguration) { - result << "_exportConfigItem=" << configItem.first << "_" << configItem.second; - } - for (auto const& configItem : importConfiguration) { - result << "_importConfigItem=" << configItem.first << "_" << configItem.second; - } - result << ov::test::utils::vec2str(inputShape); - return result.str(); - } - - void Run() override { - SKIP_IF_CURRENT_TEST_IS_DISABLED() - functionRefs = ngraph::clone_function(*function); - - configuration.insert(exportConfiguration.begin(), exportConfiguration.end()); - LoadNetwork(); - GenerateInputs(); - Infer(); - - executableNetwork.Export("exported_model.blob"); - for (auto const& configItem : importConfiguration) { - configuration[configItem.first] = configItem.second; - } - std::fstream inputStream("exported_model.blob", std::ios_base::in | std::ios_base::binary); - if (inputStream.fail()) { - FAIL() << "Cannot open file to import model: exported_model.blob"; - } - - auto importedNetwork = core->ImportNetwork(inputStream, targetDevice, configuration); - - // Generate inputs - std::vector inputs; - auto inputsInfo = importedNetwork.GetInputsInfo(); - auto functionParams = function->get_parameters(); - for (int i = 0; i < functionParams.size(); ++i) { - const auto& param = functionParams[i]; - const auto infoIt = inputsInfo.find(param->get_friendly_name()); - GTEST_ASSERT_NE(infoIt, inputsInfo.cend()); - - const auto& info = infoIt->second; - auto blob = GenerateInput(*info); - inputs.push_back(blob); - } - - // Infer imported network - InferenceEngine::InferRequest importInfer = importedNetwork.CreateInferRequest(); - inputsInfo = importedNetwork.GetInputsInfo(); - functionParams = function->get_parameters(); - for (int i = 0; i < functionParams.size(); ++i) { - const auto& param = functionParams[i]; - const auto infoIt = inputsInfo.find(param->get_friendly_name()); - GTEST_ASSERT_NE(infoIt, inputsInfo.cend()); - - const auto& info = infoIt->second; - auto blob = inputs[i]; - importInfer.SetBlob(info->name(), blob); - } - importInfer.Infer(); - - // Validate - auto expectedOutputs = CalculateRefs(); - auto actualOutputs = std::vector{}; - for (const auto& output : importedNetwork.GetOutputsInfo()) { - const auto& name = output.first; - actualOutputs.push_back(importInfer.GetBlob(name)); - } - IE_ASSERT(actualOutputs.size() == expectedOutputs.size()) - << "nGraph interpreter has " << expectedOutputs.size() << " outputs, while IE " << actualOutputs.size(); - Compare(expectedOutputs, actualOutputs); - } - -protected: - void SetUp() override { - std::vector inputShape; - InferenceEngine::Precision netPrecision; - std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto relu1 = std::make_shared(params[0]); - - size_t num_out_channels = 8; - size_t kernel_size = 8; - std::vector filter_weights = - ov::test::utils::generate_float_numbers(num_out_channels * inputShape[1] * kernel_size, -0.2f, 0.2f); - auto conv = ngraph::builder::makeConvolution(relu1, - ngPrc, - {1, kernel_size}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ngraph::op::PadType::VALID, - num_out_channels, - true, - filter_weights); - - auto relu2 = std::make_shared(conv); - ngraph::ResultVector results{std::make_shared(relu2)}; - function = std::make_shared(results, params, "ExportImportNetwork"); - } - -private: - std::map exportConfiguration; - std::map importConfiguration; -}; - -TEST_P(ImportActConvActTest, CompareWithRefImpl) { - Run(); -}; - -const std::vector> inputShape = {{1, 1, 1, 240}, {1, 1, 1, 160}, {1, 2, 1, 80}}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> exportConfigs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -const std::vector> importConfigs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_ImportActConvAct, - ImportActConvActTest, - ::testing::Combine(::testing::ValuesIn(inputShape), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(exportConfigs), - ::testing::ValuesIn(importConfigs)), - ImportActConvActTest::getTestCaseName); - -} // namespace LayerTestsDefinitions 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 deleted file mode 100644 index e2b5c188eaa..00000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_batch_size.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include "base/import_export_base.hpp" -#include "ov_models/builders.hpp" - -namespace LayerTestsDefinitions { - -class ImportBatchTest : public FuncTestUtils::ImportNetworkTestBase { -protected: - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), 0.2f, -0.1f); - } - - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::string _; - std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, _) = - this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - - auto mul_const_1 = ngraph::builder::makeConstant( - ngPrc, - {inputShape[1], 2048}, - ov::test::utils::generate_float_numbers(2048 * inputShape[1], -0.1f, 0.1f), - false); - - auto matmul_1 = std::make_shared(params[0], mul_const_1); - auto sigmoid_1 = std::make_shared(matmul_1); - - auto mul_const_2 = - ngraph::builder::makeConstant(ngPrc, - {2048, 3425}, - ov::test::utils::generate_float_numbers(2048 * 3425, -0.1f, 0.1f), - false); - - auto matmul_2 = std::make_shared(sigmoid_1, mul_const_2); - - function = std::make_shared(matmul_2, params, "ExportImportNetwork"); - } -}; - -TEST_P(ImportBatchTest, CompareWithRefImpl) { - Run(); -}; - -const std::vector> inputShapes = {{1, 440}, {2, 440}, {4, 128}}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> exportConfigs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}}}; - -const std::vector> importConfigs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -const std::vector appHeader = {""}; - -INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkBatchCase, - ImportBatchTest, - ::testing::Combine(::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(exportConfigs), - ::testing::ValuesIn(importConfigs), - ::testing::ValuesIn(appHeader)), - ImportBatchTest::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_memory_layer.cpp b/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_memory_layer.cpp deleted file mode 100644 index 5042883e351..00000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_memory_layer.cpp +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include "functional_test_utils/blob_utils.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Export Configuration - std::map, // Import Configuration - std::pair // With reset - > - exportImportNetworkParams; - -namespace LayerTestsDefinitions { - -class ImportMemoryTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map exportConfiguration; - std::map importConfiguration; - std::pair withReset; - std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, withReset) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : exportConfiguration) { - result << "_exportConfigItem=" << configItem.first << "_" << configItem.second; - } - for (auto const& configItem : importConfiguration) { - result << "_importConfigItem=" << configItem.first << "_" << configItem.second; - } - result << "_resetBefore=" << withReset.first; - result << "_resetAfter=" << withReset.second; - return result.str(); - } - - void Run() override { - SKIP_IF_CURRENT_TEST_IS_DISABLED() - - configuration.insert(exportConfiguration.begin(), exportConfiguration.end()); - LoadNetwork(); - GenerateInputs(); - Infer(); - if (withReset.first) { - for (auto& query_state : inferRequest.QueryState()) { - query_state.Reset(); - } - } - executableNetwork.Export("exported_model.blob"); - for (auto const& configItem : importConfiguration) { - configuration[configItem.first] = configItem.second; - } - std::fstream inputStream("exported_model.blob", std::ios_base::in | std::ios_base::binary); - if (inputStream.fail()) { - FAIL() << "Cannot open file to import model: exported_model.blob"; - } - auto importedNetwork = core->ImportNetwork(inputStream, targetDevice, configuration); - std::vector queryToState; - InferenceEngine::InferRequest importInfer = importedNetwork.CreateInferRequest(); - - for (auto& query_state : importInfer.QueryState()) { - queryToState.push_back(query_state.GetName()); - } - if (withReset.first) { - CheckQueryStates(&inferRequest); - } - for (const auto& next_memory : importInfer.QueryState()) { - ASSERT_TRUE(std::find(queryToState.begin(), queryToState.end(), next_memory.GetName()) != - queryToState.end()) - << "State " << next_memory.GetName() << " expected to be in memory states but it is not!"; - } - importInfer.Infer(); - if (withReset.second) { - for (auto& query_state : importInfer.QueryState()) { - query_state.Reset(); - } - CheckQueryStates(&importInfer); - } - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, withReset) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape{1, 336})}; - auto mem_c = ngraph::builder::makeConstant(ngPrc, {1, 336}, std::vector{1}); - auto mem_r = std::make_shared(mem_c, "id"); - - auto mul = std::make_shared(params[0], mem_r); - auto mem_w = std::make_shared(mul, "id"); - - auto relu = std::make_shared(mul); - mem_w->add_control_dependency(mem_r); - relu->add_control_dependency(mem_w); - ngraph::ResultVector results{std::make_shared(relu)}; - function = std::make_shared(results, params, "ExportImportNetwork"); - } - - void CheckQueryStates(InferenceEngine::InferRequest* inferRequest) { - for (auto& query_state : inferRequest->QueryState()) { - auto state = query_state.GetState(); - auto state_data = state->cbuffer().as(); - for (int i = 0; i < state->size(); i++) { - EXPECT_NEAR(0, state_data[i], 1e-5); - } - } - } - -private: - std::pair withReset; - std::map exportConfiguration; - std::map importConfiguration; -}; - -TEST_P(ImportMemoryTest, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> exportConfigs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}}}; - -const std::vector> importConfigs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "32767"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}}, -}; - -const std::vector> withReset = { - {false, false}, - {true, false}, // Reset before export - {false, true} // Reset after export -}; - -INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkMemoryCase, - ImportMemoryTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(exportConfigs), - ::testing::ValuesIn(importConfigs), - ::testing::ValuesIn(withReset)), - ImportMemoryTest::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 deleted file mode 100644 index b8d7c4f11a2..00000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_export_multi_inputs.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "base/import_export_base.hpp" -#include "common_test_utils/node_builders/eltwise.hpp" -#include "ov_models/builders.hpp" - -namespace LayerTestsDefinitions { - -class ImportMultiInput : public FuncTestUtils::ImportNetworkTestBase { -protected: - void SetUp() override { - std::vector inputShape; - InferenceEngine::Precision netPrecision; - std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = - this->GetParam(); - - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector input{std::make_shared(ngPrc, ov::Shape(inputShape)), - std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto mul1 = ov::test::utils::make_eltwise(input[0], input[1], ngraph::helpers::EltwiseTypes::ADD); - auto result = std::make_shared(mul1); - - function = std::make_shared(ngraph::ResultVector{result}, input, "multiple_input"); - } -}; - -class ImportMultiInputChanged : public ImportMultiInput {}; -class ImportMultiInputUnchanged : public ImportMultiInput {}; - -TEST_P(ImportMultiInputUnchanged, CompareWithRefImpl) { - TestRun(false); -}; - -TEST_P(ImportMultiInputChanged, CompareWithRefImpl) { - TestRun(true); -}; - -const std::vector> inputShape = {{1, 10}}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32}; - -const std::vector> exportConfigs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}, {"GNA_SCALE_FACTOR_1", "327.67"}}}; - -const std::vector> importConfigsChanged = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "32767"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_1", "32767"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "32767"}, {"GNA_SCALE_FACTOR_1", "32767"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_SCALE_FACTOR_1", "32767"}}}; - -const std::vector> importConfigsUnchanged = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}, {"GNA_SCALE_FACTOR_1", "327.67"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_1", "327.67"}}, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, - ImportMultiInputUnchanged, - ::testing::Combine(::testing::ValuesIn(inputShape), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(exportConfigs), - ::testing::ValuesIn(importConfigsUnchanged), - ::testing::Values("")), - ImportMultiInputUnchanged::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, - ImportMultiInputChanged, - ::testing::Combine(::testing::ValuesIn(inputShape), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(exportConfigs), - ::testing::ValuesIn(importConfigsChanged), - ::testing::Values("")), - ImportMultiInputChanged::getTestCaseName); - -} // namespace LayerTestsDefinitions 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 deleted file mode 100644 index da9ee1d225a..00000000000 --- a/src/plugins/intel_gna/tests/functional/Import_export_tests/import_reshape_permute_conv.cpp +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "base/import_export_base.hpp" -#include "ov_models/builders.hpp" - -namespace LayerTestsDefinitions { - -class ImportReshapePermuteConv : public FuncTestUtils::ImportNetworkTestBase { -protected: - void SetUp() override { - std::vector inputShape; - InferenceEngine::Precision netPrecision; - std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = - this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - - std::vector outFormShapes1 = {1, 1, 168, 2}; - auto pattern1 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{4}, outFormShapes1); - auto reshape1 = std::make_shared(params[0], pattern1, false); - - auto permute1 = std::make_shared( - reshape1, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 3, 1, 2})); - - auto conv1 = ngraph::builder::makeConvolution(permute1, - ngPrc, - {1, 8}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ngraph::op::PadType::VALID, - 12); - - auto permute2 = std::make_shared( - conv1, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 2, 3, 1})); - - std::vector outFormShapes2 = {1, 1932}; - auto pattern2 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{2}, outFormShapes2); - auto reshape2 = std::make_shared(permute2, pattern2, false); - - ngraph::ResultVector results{std::make_shared(reshape2)}; - function = std::make_shared(results, params, "ExportImportNetwork"); - }; -}; - -TEST_P(ImportReshapePermuteConv, CompareWithRefImpl) { - Run(); -}; - -} // namespace LayerTestsDefinitions - -using namespace LayerTestsDefinitions; - -namespace { - -class ImportExportGNAModelUnchanged : public ImportReshapePermuteConv { -private: - void exportImportNetwork() override { - { - std::fstream outStream(fileName, std::ios_base::out | std::ios_base::binary); - outStream.write(applicationHeader.c_str(), applicationHeader.size()); - executableNetwork.Export(outStream); - } - { - std::string appHeader(applicationHeader.size(), ' '); - std::fstream inputStream(fileName, std::ios_base::in | std::ios_base::binary); - if (inputStream.fail()) { - FAIL() << "Cannot open file to import model: " << fileName; - } - inputStream.read(&appHeader[0], applicationHeader.size()); - ASSERT_EQ(appHeader, applicationHeader); - executableNetwork = core->ImportNetwork(inputStream, targetDevice, configuration); - } - } - -protected: - void TearDown() override { - if (remove(fileName.c_str()) != 0) { - FAIL() << "Error: could not delete file " << fileName; - } - } - -private: - std::string fileName = "exported_model.blob"; -}; - -class ImportExportGNAModelChanged : public ImportExportGNAModelUnchanged {}; - -TEST_P(ImportExportGNAModelUnchanged, ReshapePermuteConv) { - TestRun(false); -}; - -TEST_P(ImportExportGNAModelChanged, ReshapePermuteConv) { - TestRun(true); -}; - -const std::vector> inputShapes = {{1, 336}}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> exportConfigs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}}}; - -const std::vector> importConfigsChanged = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "32767"}}}; - -const std::vector> importConfigsUnchanged = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -const std::vector appHeaders = {"", "APPLICATION_HEADER"}; - -INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, - ImportExportGNAModelUnchanged, - ::testing::Combine(::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(exportConfigs), - ::testing::ValuesIn(importConfigsUnchanged), - ::testing::ValuesIn(appHeaders)), - ImportExportGNAModelUnchanged::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, - ImportExportGNAModelChanged, - ::testing::Combine(::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(exportConfigs), - ::testing::ValuesIn(importConfigsChanged), - ::testing::ValuesIn(appHeaders)), - ImportExportGNAModelChanged::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot1.blob b/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot1.blob deleted file mode 100644 index f468203d718..00000000000 Binary files a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot1.blob and /dev/null differ diff --git a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot2.blob b/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot2.blob deleted file mode 100644 index 9e892d794ee..00000000000 Binary files a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot2.blob and /dev/null differ diff --git a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot3.blob b/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot3.blob deleted file mode 100644 index 780b152dae8..00000000000 Binary files a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot3.blob and /dev/null differ diff --git a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot4.blob b/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot4.blob deleted file mode 100644 index 3159a652f83..00000000000 Binary files a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot4.blob and /dev/null differ diff --git a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot5.blob b/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot5.blob deleted file mode 100644 index 427b8c020ed..00000000000 Binary files a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot5.blob and /dev/null differ diff --git a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot6.blob b/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot6.blob deleted file mode 100644 index 22a6b400a74..00000000000 Binary files a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot6.blob and /dev/null differ diff --git a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot7.blob b/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot7.blob deleted file mode 100644 index 720bc8b78b3..00000000000 Binary files a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot7.blob and /dev/null differ diff --git a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot8.blob b/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot8.blob deleted file mode 100644 index 571f5ad83fc..00000000000 Binary files a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot8.blob and /dev/null differ diff --git a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot9.blob b/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot9.blob deleted file mode 100644 index 48870871e2b..00000000000 Binary files a/src/plugins/intel_gna/tests/functional/data/exported_models/export2dot9.blob and /dev/null differ diff --git a/src/plugins/intel_gna/tests/functional/helpers/test_model_repo.cpp b/src/plugins/intel_gna/tests/functional/helpers/test_model_repo.cpp deleted file mode 100644 index 8f133d806fe..00000000000 --- a/src/plugins/intel_gna/tests/functional/helpers/test_model_repo.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "test_model_repo.hpp" - -std::string TestDataHelpers::get_data_path() { - if (const auto env_var = std::getenv("GNA_DATA_PATH")) { - return env_var; - } - -#ifdef GNA_DATA_PATH - return GNA_DATA_PATH; -#else - return nullptr; -#endif -} diff --git a/src/plugins/intel_gna/tests/functional/helpers/test_model_repo.hpp b/src/plugins/intel_gna/tests/functional/helpers/test_model_repo.hpp deleted file mode 100644 index fcbfb6e1c7b..00000000000 --- a/src/plugins/intel_gna/tests/functional/helpers/test_model_repo.hpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include - -namespace TestDataHelpers { - -std::string get_data_path(); - -} // namespace TestDataHelpers diff --git a/src/plugins/intel_gna/tests/functional/limitations/layers_limit.cpp b/src/plugins/intel_gna/tests/functional/limitations/layers_limit.cpp deleted file mode 100644 index 9c54ae4f64c..00000000000 --- a/src/plugins/intel_gna/tests/functional/limitations/layers_limit.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "common_test_utils/common_utils.hpp" -#include "openvino/opsets/opset8.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -using namespace InferenceEngine; -using namespace ov::opset8; - -namespace LayerTestsDefinitions { - -using GNALayersLimitTestParams = std::tuple, // common config - std::map, // Configuration - size_t>; // number of layers - -class GNALayersLimitTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - std::string target_device; - std::map common_conf, conf; - size_t layers_number; - - std::tie(target_device, common_conf, conf, layers_number) = obj.param; - - std::ostringstream result; - result << "layerNumber=" << layers_number; - result << "_trgDev=" << target_device; - for (auto const& conf_i : conf) { - result << "_configItem=" << conf_i.first.c_str() << "_" << conf_i.second.c_str(); - } - return result.str(); - } - -protected: - void SetUp() override { - ov::element::Type net_type = ov::element::f32; - const size_t branch_count = 64; - std::vector> shapes(branch_count, {1, 2}); - - std::map common_conf, conf; - size_t layers_number; - std::tie(targetDevice, common_conf, conf, layers_number) = this->GetParam(); - - configuration.insert(common_conf.begin(), common_conf.end()); - configuration.insert(conf.begin(), conf.end()); - - ov::ParameterVector params; - for (auto&& shape : shapes) { - params.push_back(std::make_shared(net_type, ov::Shape(shape))); - } - auto add_const = ngraph::builder::makeConstant(net_type, ov::Shape{1}, std::vector{0.01f}); - ov::ResultVector results; - - std::vector>> branches; - - for (size_t i = 0; i < branch_count; ++i) { - configuration.insert({"GNA_SCALE_FACTOR_" + std::to_string(i), "1"}); - std::vector> add_nodes; - add_nodes.push_back(std::make_shared(add_const, params[i])); - - for (size_t j = 0; j < (layers_number - branch_count) / branch_count; ++j) { - add_nodes.push_back(std::make_shared(add_nodes.back(), params[i])); - } - branches.push_back(add_nodes); - results.push_back(std::make_shared(add_nodes.back())); - } - function = std::make_shared(results, params, "layers_limit"); - }; -}; - -class GNALayersLimit20Test : public GNALayersLimitTest {}; -class GNALayersLimit3XTest : public GNALayersLimitTest {}; - -TEST_P(GNALayersLimit20Test, CompareWithRefs) { - Run(); -} - -TEST_P(GNALayersLimit3XTest, CompareWithRefs) { - Run(); -} - -std::map common_config{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_COMPACT_MODE", "NO"}}; - -std::vector> configs_20{{{"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}, - {{"GNA_COMPILE_TARGET", "GNA_TARGET_2_0"}}}; - -std::vector> configs_3X{{{"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_COMPILE_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}, - {{"GNA_COMPILE_TARGET", "GNA_TARGET_3_5"}}}; - -// for GNA v2.0 limit is 4096 -std::vector layer_limits_20{64, 4096, 4160}; -// for GNA >= v3.0 limit is 8192 -std::vector layer_limits_3X{64, 8192, 8200}; - -INSTANTIATE_TEST_SUITE_P(smoke_GNALimits, - GNALayersLimit20Test, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(common_config), - ::testing::ValuesIn(configs_20), - ::testing::ValuesIn(layer_limits_20)), - GNALayersLimitTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_GNALimits, - GNALayersLimit3XTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(common_config), - ::testing::ValuesIn(configs_3X), - ::testing::ValuesIn(layer_limits_3X)), - GNALayersLimitTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/4d_eltwise.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/4d_eltwise.cpp deleted file mode 100644 index c8f2c3bbb77..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/4d_eltwise.cpp +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "common_test_utils/node_builders/eltwise.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - ngraph::helpers::EltwiseTypes // Type of eltwise - > - eltwiseParams; - -namespace LayerTestsDefinitions { - -class Eltwise4dBroadcast : public testing::WithParamInterface, public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - ngraph::helpers::EltwiseTypes eltwiseType; - std::tie(netPrecision, targetDevice, configuration, eltwiseType) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_eltwiseType=" << eltwiseType; - return result.str(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - ngraph::helpers::EltwiseTypes eltwiseType; - std::tie(netPrecision, targetDevice, configuration, eltwiseType) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - outPrc = InferenceEngine::Precision::FP32; - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape{1, 72})}; - - std::vector outFormShapes1 = {1, 1, 6, 12}; - auto pattern1 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{4}, outFormShapes1); - auto reshape1 = std::make_shared(params[0], pattern1, false); - - auto constant1 = ngraph::builder::makeConstant(ngPrc, {1, 1, 1, 12}, {}, true); - auto eltwise = ov::test::utils::make_eltwise(reshape1, constant1, eltwiseType); - - std::vector outFormShapes2 = {1, 72}; - auto pattern2 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{2}, outFormShapes2); - auto reshape2 = std::make_shared(eltwise, pattern2, false); - - ngraph::ResultVector results{std::make_shared(reshape2)}; - function = std::make_shared(results, params, "Eltwise4dBroadcast"); - } -}; - -class Eltwise4dMultipleInput : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - ngraph::helpers::EltwiseTypes eltwiseType; - std::tie(netPrecision, targetDevice, configuration, eltwiseType) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_eltwiseType=" << eltwiseType; - return result.str(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - ngraph::helpers::EltwiseTypes eltwiseType; - std::tie(netPrecision, targetDevice, configuration, eltwiseType) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - outPrc = InferenceEngine::Precision::FP32; - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape{1, 72}), - std::make_shared(ngPrc, ov::Shape{1, 72})}; - std::vector outFormShapes1 = {1, 1, 6, 12}; - auto pattern1 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{4}, outFormShapes1); - auto reshape1 = std::make_shared(params[0], pattern1, false); - - auto reshape2 = std::make_shared(params[1], pattern1, false); - - auto eltwise = ov::test::utils::make_eltwise(reshape1, reshape2, eltwiseType); - - std::vector outFormShapes2 = {1, 72}; - auto pattern2 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{2}, outFormShapes2); - auto reshape3 = std::make_shared(eltwise, pattern2, false); - - ngraph::ResultVector results{std::make_shared(reshape3)}; - function = std::make_shared(results, params, "Eltwise4dMultipleInput"); - } -}; - -TEST_P(Eltwise4dBroadcast, CompareWithRefImpl) { - Run(); -}; - -TEST_P(Eltwise4dMultipleInput, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1638.4"}}}; - -const std::vector> configsMultiple = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1638.4"}, {"GNA_SCALE_FACTOR_1", "1638.4"}}}; - -const std::vector eltwiseOpTypes = {ngraph::helpers::EltwiseTypes::MULTIPLY, - ngraph::helpers::EltwiseTypes::SUBTRACT, - ngraph::helpers::EltwiseTypes::ADD}; - -INSTANTIATE_TEST_SUITE_P(smoke_Eltwise4d, - Eltwise4dBroadcast, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(eltwiseOpTypes)), - Eltwise4dBroadcast::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Eltwise4d, - Eltwise4dMultipleInput, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configsMultiple), - ::testing::ValuesIn(eltwiseOpTypes)), - Eltwise4dMultipleInput::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/act_maxpool_reordering.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/act_maxpool_reordering.cpp deleted file mode 100644 index 2c95884493e..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/act_maxpool_reordering.cpp +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -static std::map activationNames = { - {ngraph::helpers::ActivationTypes::Sigmoid, "Sigmoid"}, - {ngraph::helpers::ActivationTypes::Tanh, "Tanh"}, - {ngraph::helpers::ActivationTypes::Relu, "Relu"}, - {ngraph::helpers::ActivationTypes::LeakyRelu, "LeakyRelu"}, - {ngraph::helpers::ActivationTypes::Exp, "Exp"}, - {ngraph::helpers::ActivationTypes::Log, "Log"}, - {ngraph::helpers::ActivationTypes::Sign, "Sign"}, - {ngraph::helpers::ActivationTypes::Abs, "Abs"}, - {ngraph::helpers::ActivationTypes::Clamp, "Clamp"}}; - -typedef std::tuple, // Configuration - std::vector, // Input Shape - bool, // add biases - ngraph::helpers::ActivationTypes // Activation type - > - actMaxpoolReorderingParams; - -namespace LayerTestsDefinitions { - -class ActMaxpoolReordering : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - bool addBiases; - ngraph::helpers::ActivationTypes actType; - std::tie(netPrecision, targetDevice, configuration, inputShape, addBiases, actType) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(inputShape); - result << "_bias=" << addBiases; - result << "_actType=" << activationNames[actType]; - - return result.str(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector inputShape; - bool addBiases; - ngraph::helpers::ActivationTypes actType; - std::tie(netPrecision, targetDevice, configuration, inputShape, addBiases, actType) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector inputVector{std::make_shared(ngPrc, ov::Shape(inputShape))}; - - size_t num_out_channels = 12; - size_t kernal_size = 8; - auto conv = ngraph::builder::makeConvolution(inputVector[0], - ngPrc, - {1, kernal_size}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ngraph::op::PadType::VALID, - num_out_channels, - addBiases); - - auto activation = ngraph::builder::makeActivation(conv, ngPrc, actType); - - OPENVINO_SUPPRESS_DEPRECATED_START - auto maxpool = ngraph::builder::makePooling(activation, - {1, 2}, - {0, 0}, - {0, 0}, - {1, 2}, - ngraph::op::RoundingType::FLOOR, - ngraph::op::PadType::VALID, - false, - ngraph::helpers::PoolingTypes::MAX); - OPENVINO_SUPPRESS_DEPRECATED_END - - ngraph::ResultVector results{std::make_shared(maxpool)}; - function = std::make_shared(results, inputVector, "ActMaxpoolReordering"); - } -}; - -TEST_P(ActMaxpoolReordering, CompareWithRefImpl) { - LoadNetwork(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{ - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, -}}; - -const std::vector> gnaPwlUniformDesignConfigs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_PWL_UNIFORM_DESIGN", "YES"}}}; - -const std::vector> inputShape = { - {1, 1, 1, 1024}, - {1, 8, 1, 168}, -}; - -const std::vector addBiases = {false, true}; - -const std::vector activationTypes = {ngraph::helpers::ActivationTypes::Sigmoid, - ngraph::helpers::ActivationTypes::Tanh, - ngraph::helpers::ActivationTypes::Relu, - ngraph::helpers::ActivationTypes::Exp, - ngraph::helpers::ActivationTypes::Log, - ngraph::helpers::ActivationTypes::Sign, - ngraph::helpers::ActivationTypes::Abs}; - -const std::vector gnaPwlUniformDesignActivationTypes = { - ngraph::helpers::ActivationTypes::Sigmoid, - ngraph::helpers::ActivationTypes::Tanh}; - -INSTANTIATE_TEST_SUITE_P(smoke_act_maxpool_reordering, - ActMaxpoolReordering, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShape), - ::testing::ValuesIn(addBiases), - ::testing::ValuesIn(activationTypes)), - ActMaxpoolReordering::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(gna_pwl_uniform_design_smoke_act_maxpool_reordering, - ActMaxpoolReordering, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(gnaPwlUniformDesignConfigs), - ::testing::ValuesIn(inputShape), - ::testing::ValuesIn(addBiases), - ::testing::ValuesIn(gnaPwlUniformDesignActivationTypes)), - ActMaxpoolReordering::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/broadcast_const_with_fq.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/broadcast_const_with_fq.cpp deleted file mode 100644 index 46fb55bf594..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/broadcast_const_with_fq.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -// -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -using BroadcastConstWithFqParamsTuple = typename std::tuple, // Input shapes for Params Layer - std::vector, // Input shapes for Constant Layer - size_t, // Quantization level - std::map, // Configuration - std::string>; // Device name - -namespace LayerTestsDefinitions { - -class BroadcastConstWithFq : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::vector inputShape1; - std::vector inputShape2; - size_t level{0}; - std::map configuration; - std::string targetDevice; - std::tie(netPrecision, inputShape1, inputShape2, level, configuration, targetDevice) = obj.param; - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "configItem=" << configItem.first << "_" << configItem.second << "_"; - } - result << "inputShape1=" << ov::test::utils::vec2str(inputShape1) << "_"; - result << "inputShape2=" << ov::test::utils::vec2str(inputShape2) << "_"; - result << "level=" << level; - return result.str(); - } - -protected: - void SetUp() override { - size_t level{0}; - InferenceEngine::Precision netPrecision; - std::vector inputShape1; - std::vector inputShape2; - std::tie(netPrecision, inputShape1, inputShape2, level, configuration, targetDevice) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape1))}; - auto fakeQuantize1 = - ngraph::builder::makeFakeQuantize(params[0], ngPrc, level, {}, {-0.5}, {0.5}, {-0.5}, {0.5}); - auto constant = ngraph::builder::makeConstant(ngPrc, inputShape2, {}, true); - auto fakeQuantize2 = - ngraph::builder::makeFakeQuantize(constant, ngPrc, level, {}, {-0.5}, {0.5}, {-0.5}, {0.5}); - auto add = std::make_shared(fakeQuantize1, fakeQuantize2); - ngraph::ResultVector results{std::make_shared(add)}; - function = std::make_shared(results, params, "BroadcastConstWithFq"); - } -}; - -TEST_P(BroadcastConstWithFq, CompareWithRefImpl) { - Run(); -}; - -std::vector> inputShapes1 = {{1, 1, 21, 160}}; -std::vector> inputShapes2 = {{1, 1, 1, 160}}; -const std::vector level = {65535}; -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_broadcast_const_with_fq, - BroadcastConstWithFq, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(inputShapes1), - ::testing::ValuesIn(inputShapes2), - ::testing::ValuesIn(level), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - BroadcastConstWithFq::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/broadcast_tile_issue.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/broadcast_tile_issue.cpp deleted file mode 100644 index eefee2c2548..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/broadcast_tile_issue.cpp +++ /dev/null @@ -1,424 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include - -#include "shared_test_classes/base/layer_test_utils.hpp" -using namespace ov::opset9; -using namespace ov::element; -using namespace ov; - -namespace { -struct FunctionConfig { - std::vector input_shape; - std::vector extra_arg; // Broadcast target_shape, Tile repeats - Type ngraph_precision; - bool use_axes_mapping; // used only by Broadcast -}; - -struct ModelWithExpect { - std::shared_ptr function; - std::vector input_friendly_names; - std::vector ouput_friendly_names; -}; - -// Declarations Broadcast and Tile layer creators used to build test model -class LayerForEliminationCreator { -public: - LayerForEliminationCreator(std::string&& layer_name, std::string&& extra_arg_name, bool contains_non_functional); - virtual ~LayerForEliminationCreator() = default; - - virtual std::shared_ptr CreateLayer(const Output& input, const FunctionConfig& config) const = 0; - - bool IsContainingNonFunctional() const; - virtual std::string GenerateLayerName(const FunctionConfig& config) const; - -private: - bool _contains_non_functional; - std::string _layer_name; - std::string _extra_arg_name; -}; - -class BroadcastCreator : public LayerForEliminationCreator { -public: - BroadcastCreator(bool contains_non_functional = false); - - std::shared_ptr CreateLayer(const Output& input, const FunctionConfig& config) const override; - std::string GenerateLayerName(const FunctionConfig& config) const override; -}; - -class TileCreator : public LayerForEliminationCreator { -public: - TileCreator(bool contains_non_functional = false); - std::shared_ptr CreateLayer(const Output& input, const FunctionConfig& config) const override; -}; - -// Full model creators -class ModelExpectCreator { -public: - ModelExpectCreator(std::shared_ptr&& layer_creator, std::string&& function_name); - virtual ~ModelExpectCreator() = default; - - virtual std::string GenerateFunctionName(const FunctionConfig& config) const; - virtual ModelWithExpect CreateFunctionWithExpects(const FunctionConfig& config) const = 0; - -protected: - std::shared_ptr CreateLayer(const Output& input, const FunctionConfig& config) const; - -private: - std::shared_ptr _layer_creator; - std::string _function_name; -}; - -class LayerAfterActivationCreator : public ModelExpectCreator { -public: - LayerAfterActivationCreator(std::shared_ptr&& layer_creator); - - ModelWithExpect CreateFunctionWithExpects(const FunctionConfig& config) const override; -}; - -class LayerBeforeActivationCreator : public ModelExpectCreator { -public: - LayerBeforeActivationCreator(std::shared_ptr&& layer_creator); - - ModelWithExpect CreateFunctionWithExpects(const FunctionConfig& config) const override; -}; - -class LayerTwoOutputsFunctionCreator : public ModelExpectCreator { -public: - LayerTwoOutputsFunctionCreator(std::shared_ptr&& layer_creator); - - ModelWithExpect CreateFunctionWithExpects(const FunctionConfig& config) const override; -}; - -using TestConfig = std::tuple, // variant of fuction - std::pair, std::vector>, // - InferenceEngine::Precision, // net precision - bool // axes mapping - >; - -// Test class -class BroadcastTileIssue : public ::testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj); - -protected: - void SetUp() override; - void Validate() override; - static const char* s_target_device_name; - ModelWithExpect _function_with_expects; -}; - -// Implementations -LayerForEliminationCreator::LayerForEliminationCreator(std::string&& layer_name, - std::string&& extra_arg_name, - bool contains_non_functional) - : _layer_name(layer_name), - _contains_non_functional(contains_non_functional), - _extra_arg_name(std::move(extra_arg_name)) {} - -bool LayerForEliminationCreator::IsContainingNonFunctional() const { - return _contains_non_functional; -} - -std::string LayerForEliminationCreator::GenerateLayerName(const FunctionConfig& config) const { - std::stringstream name; - name << _layer_name; - if (_contains_non_functional) { - name << "_with_non_functional"; - } - name << "_" << _extra_arg_name << "=" << ov::test::utils::vec2str(config.extra_arg); - return name.str(); -} - -BroadcastCreator::BroadcastCreator(bool contains_non_functional) - : LayerForEliminationCreator("Broadcast", "AxesMapping", contains_non_functional) {} - -std::shared_ptr BroadcastCreator::CreateLayer(const Output& input, const FunctionConfig& config) const { - Output broadcast_input = input; - auto input_shape = config.input_shape; - auto targtet_shape = config.extra_arg; - - if (IsContainingNonFunctional()) { - auto shape_pattern = Constant::create(i32, Shape{input_shape.size()}, input_shape); - broadcast_input = std::make_shared(input, shape_pattern, false); - } - - auto target_shape_const = Constant::create(i32, Shape{targtet_shape.size()}, targtet_shape); - - if (config.use_axes_mapping) { - std::vector axes; - for (int i = 1; i <= input_shape.size(); ++i) { - axes.push_back(i); - } - auto axes_mapping = Constant::create(i32, Shape{axes.size()}, axes); - - return std::make_shared(broadcast_input, target_shape_const, axes_mapping); - } - - return std::make_shared(broadcast_input, target_shape_const); -} - -std::string BroadcastCreator::GenerateLayerName(const FunctionConfig& config) const { - std::stringstream name; - name << LayerForEliminationCreator::GenerateLayerName(config) << "_"; - name << "UseAxesMapping=" << (config.use_axes_mapping ? "ON" : "OFF"); - return name.str(); -} - -TileCreator::TileCreator(bool contains_non_functional) - : LayerForEliminationCreator("Tile", "Repeats", contains_non_functional) {} - -std::shared_ptr TileCreator::CreateLayer(const Output& input, const FunctionConfig& config) const { - Output tile_input = input; - auto input_shape = config.input_shape; - - auto repeats = config.extra_arg; - auto repeats_const = Constant::create(i32, Shape{repeats.size()}, repeats); - - if (IsContainingNonFunctional()) { - auto shape_pattern = Constant::create(i32, Shape{input_shape.size()}, input_shape); - tile_input = std::make_shared(input, shape_pattern, false); - } - - return std::make_shared(input, repeats_const); -} - -std::shared_ptr ModelExpectCreator::CreateLayer(const Output& input, const FunctionConfig& config) const { - return _layer_creator->CreateLayer(input, config); -} - -ModelExpectCreator::ModelExpectCreator(std::shared_ptr&& layer_creator, - std::string&& function_name) - : _layer_creator(std::move(layer_creator)), - _function_name(std::move(function_name)) {} - -std::string ModelExpectCreator::GenerateFunctionName(const FunctionConfig& config) const { - std::stringstream name; - name << _function_name << "_"; - name << _layer_creator->GenerateLayerName(config); - return name.str(); -} - -LayerAfterActivationCreator::LayerAfterActivationCreator(std::shared_ptr&& layer_creator) - : ModelExpectCreator(std::move(layer_creator), "AfterActivation") {} - -ModelWithExpect LayerAfterActivationCreator::CreateFunctionWithExpects(const FunctionConfig& config) const { - const std::string input_friendly_name = "input_1"; - const auto& input_shape = config.input_shape; - - auto input_param = std::make_shared(config.ngraph_precision, Shape{input_shape}); - input_param->set_friendly_name(input_friendly_name); - - auto length = std::accumulate(input_shape.begin(), input_shape.end(), (size_t)1, std::multiplies()); - std::vector vector_data(length, 1.0); - auto constant = std::make_shared(config.ngraph_precision, Shape{input_shape}, vector_data); - auto add = std::make_shared(input_param, constant); - auto activation = std::make_shared(add); - - auto layer = CreateLayer(activation, config); - - const std::string output_friendly_name = "ouput_1"; - layer->set_friendly_name(output_friendly_name); - auto result = std::make_shared(layer); - - auto model = - std::make_shared(ResultVector{result}, ParameterVector{input_param}, GenerateFunctionName(config)); - return {model, {input_friendly_name}, {output_friendly_name}}; -} - -LayerBeforeActivationCreator::LayerBeforeActivationCreator(std::shared_ptr&& layer_creator) - : ModelExpectCreator(std::move(layer_creator), "LayerBeforeActivation") {} - -ModelWithExpect LayerBeforeActivationCreator::CreateFunctionWithExpects(const FunctionConfig& config) const { - const std::string input_friendly_name = "input_1"; - const auto& input_shape = config.input_shape; - auto input_param = std::make_shared(config.ngraph_precision, Shape{input_shape}); - input_param->set_friendly_name(input_friendly_name); - - auto layer = CreateLayer(input_param, config); - - auto activation = std::make_shared(layer); - const std::string output_friendly_name = "ouput_1"; - activation->set_friendly_name(output_friendly_name); - auto result = std::make_shared(activation); - - auto model = - std::make_shared(ResultVector{result}, ParameterVector{input_param}, GenerateFunctionName(config)); - return {model, {input_friendly_name}, {output_friendly_name}}; -} - -LayerTwoOutputsFunctionCreator::LayerTwoOutputsFunctionCreator( - std::shared_ptr&& layer_creator) - : ModelExpectCreator(std::move(layer_creator), "LayerTwoOutputsFunction") {} - -ModelWithExpect LayerTwoOutputsFunctionCreator::CreateFunctionWithExpects(const FunctionConfig& config) const { - const std::string input_friendly_name = "input_1"; - const auto& input_shape = config.input_shape; - auto input_param = std::make_shared(config.ngraph_precision, Shape{input_shape}); - input_param->set_friendly_name(input_friendly_name); - - auto layer = CreateLayer(input_param, config); - - const std::string output_friendly_name_1 = "ouput_1"; - layer->set_friendly_name(output_friendly_name_1); - auto result_1 = std::make_shared(layer); - auto length = std::accumulate(input_shape.begin(), input_shape.end(), (size_t)1, std::multiplies()); - std::vector vector_data(length, 1.0); - auto constant = std::make_shared(config.ngraph_precision, Shape{input_shape}, vector_data); - auto add = std::make_shared(input_param, constant); - auto activation = std::make_shared(add); - const std::string output_friendly_name_2 = "ouput_2"; - activation->set_friendly_name(output_friendly_name_2); - auto result_2 = std::make_shared(activation); - - ResultVector results = {result_1, result_2}; - auto model = std::make_shared(results, ParameterVector{input_param}, GenerateFunctionName(config)); - return {model, {input_friendly_name}, {output_friendly_name_1, output_friendly_name_2}}; -} - -const char* BroadcastTileIssue::s_target_device_name = ov::test::utils::DEVICE_GNA; - -std::string BroadcastTileIssue::getTestCaseName(const testing::TestParamInfo& obj) { - std::shared_ptr function_creator; - InferenceEngine::Precision net_precision; - std::pair, std::vector> shapes; - bool axes_mapping; - std::tie(function_creator, shapes, net_precision, axes_mapping) = obj.param; - - auto precision = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(net_precision); - FunctionConfig func_config = {shapes.first, shapes.second, precision, axes_mapping}; - - std::stringstream test_name; - - test_name << "IS=" << ov::test::utils::vec2str(shapes.first) << "_"; - test_name << "netPRC=" << precision.get_type_name() << "_"; - test_name << "targetDevice=" << s_target_device_name << "_"; - test_name << "FunctionVariant=" << function_creator->GenerateFunctionName(func_config) << "_"; - return test_name.str(); -} - -void BroadcastTileIssue::SetUp() { - targetDevice = s_target_device_name; - - std::shared_ptr function_creator; - std::pair, std::vector> shapes; - bool axes_mapping; - InferenceEngine::Precision net_precision; - - std::tie(function_creator, shapes, net_precision, axes_mapping) = GetParam(); - std::vector input_shape = shapes.first; - std::vector extra_arg = shapes.second; - - auto ngraph_precision = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(net_precision); - - FunctionConfig func_config = {input_shape, extra_arg, ngraph_precision, axes_mapping}; - - _function_with_expects = function_creator->CreateFunctionWithExpects(func_config); - function = _function_with_expects.function; -} - -void BroadcastTileIssue::Validate() { - LayerTestsCommon::Validate(); - auto inputs = executableNetwork.GetInputsInfo(); - ASSERT_EQ(_function_with_expects.input_friendly_names.size(), inputs.size()); - for (const auto& name : _function_with_expects.input_friendly_names) { - ASSERT_TRUE(inputs.end() != inputs.find(name)); - } - - auto outputs = executableNetwork.GetOutputsInfo(); - ASSERT_EQ(_function_with_expects.ouput_friendly_names.size(), outputs.size()); - for (const auto& name : _function_with_expects.ouput_friendly_names) { - ASSERT_TRUE(outputs.end() != outputs.find(name)); - } -} - -} // namespace - -TEST_P(BroadcastTileIssue, CompareWithRefs) { - Run(); -} - -static const std::pair, std::vector> broadcast_shape_the_same = {{1, 1, 590}, {1, 1, 590}}; -static const std::pair, std::vector> broadcast_shape_output_higher_rank = {{1, 1, 590}, - {1, 1, 1, 590}}; - -static const std::pair, std::vector> tile_shape_the_same = {{1, 1, 590}, {1, 1, 1}}; - -static const InferenceEngine::Precision precision = InferenceEngine::Precision::FP32; - -std::vector configs = { - {std::make_shared(std::make_shared()), - broadcast_shape_the_same, - precision, - false}, - {std::make_shared(std::make_shared(true)), - broadcast_shape_the_same, - precision, - false}, - {std::make_shared(std::make_shared()), - broadcast_shape_the_same, - precision, - false}, - {std::make_shared(std::make_shared(true)), - broadcast_shape_the_same, - precision, - false}, - {std::make_shared(std::make_shared()), - broadcast_shape_output_higher_rank, - precision, - false}, - {std::make_shared(std::make_shared()), - broadcast_shape_output_higher_rank, - precision, - true}, - {std::make_shared(std::make_shared()), - broadcast_shape_the_same, - precision, - false}, - {std::make_shared(std::make_shared(true)), - broadcast_shape_the_same, - precision, - false}, - {std::make_shared(std::make_shared()), - broadcast_shape_output_higher_rank, - precision, - false}, - {std::make_shared(std::make_shared()), - broadcast_shape_output_higher_rank, - precision, - true}, - {std::make_shared(std::make_shared()), - tile_shape_the_same, - precision, - false}, - {std::make_shared(std::make_shared(true)), - tile_shape_the_same, - precision, - false}, - {std::make_shared(std::make_shared()), - tile_shape_the_same, - precision, - false}, - {std::make_shared(std::make_shared(true)), - tile_shape_the_same, - precision, - false}, - {std::make_shared(std::make_shared()), - tile_shape_the_same, - precision, - false}, - {std::make_shared(std::make_shared(true)), - tile_shape_the_same, - precision, - false}, -}; - -INSTANTIATE_TEST_SUITE_P(broadcast_tile_issue, - BroadcastTileIssue, - ::testing::ValuesIn(configs), - BroadcastTileIssue::getTestCaseName); diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/concat_memory_param.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/concat_memory_param.cpp deleted file mode 100644 index 0f182484e33..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/concat_memory_param.cpp +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset9.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector // shape to split - > - concat_memory_test_params; - -namespace LayerTestsDefinitions { - -class ConcatMemoryTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision net_prc; - std::string targetDevice; - std::map configuration; - std::vector input_shape; - std::tie(net_prc, targetDevice, configuration, input_shape) = obj.param; - - std::ostringstream result; - result << "net_prc=" << net_prc.name() << "_"; - result << "device=" << targetDevice << "_"; - for (auto const& config_item : configuration) { - result << "_config_item=" << config_item.first << "_" << config_item.second; - } - result << "_input_shape=" << ov::test::utils::vec2str(input_shape); - return result.str(); - } - -protected: - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* raw_blob_data_ptr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -2.f, 2.f); - for (size_t i = 0; i < blob->size(); i++) { - raw_blob_data_ptr[i] = values[i]; - } - return blob; - } - - void SetUp() override { - InferenceEngine::Precision net_prc; - std::vector input_shape; - std::tie(net_prc, targetDevice, configuration, input_shape) = this->GetParam(); - - auto ng_prc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(net_prc); - - size_t in_total_dims_size = ov::shape_size(input_shape); - ov::ParameterVector params{std::make_shared(ng_prc, ov::Shape{1, in_total_dims_size})}; - auto reshape_pattern = - std::make_shared(ov::element::Type_t::i64, ov::Shape{2}, input_shape); - auto reshape = std::make_shared(params[0], reshape_pattern, false); - - ov::op::util::VariableInfo vi{}; - vi.data_shape = ov::PartialShape(input_shape); - vi.variable_id = "test_variable"; - vi.data_type = ov::element::Type_t::f32; - const auto var = std::make_shared(vi); - std::vector initial_state = ov::test::utils::generate_float_numbers(in_total_dims_size, -3.f, 3.f); - auto initial_state_node = ngraph::builder::makeConstant(ov::element::Type_t::f32, input_shape, initial_state); - auto readValue = std::make_shared(initial_state_node, var); - - const int axis = 1; - ov::OutputVector to_concat{readValue, reshape}; - auto concat = std::make_shared(to_concat, axis); - - const auto concat_shape = concat->get_output_shape(0); - const auto concat_shape_size = ov::shape_size(concat_shape); - - auto etlwise_data = ov::test::utils::generate_float_numbers(concat_shape_size, -1.f, 1.f); - auto etlwise_node = ngraph::builder::makeConstant(ov::element::Type_t::f32, concat_shape, etlwise_data); - auto etlwise_result_node = std::make_shared(concat, etlwise_node); - - ov::ResultVector results{std::make_shared(etlwise_result_node)}; - auto split_axis_op = - std::make_shared(ov::element::Type_t::i64, ov::Shape{}, std::vector{axis}); - auto split_node = std::make_shared(concat, split_axis_op, 2); - - auto assign_node = std::make_shared(split_node->output(1), var); - ngraph::SinkVector sinks{assign_node}; - function = std::make_shared(results, sinks, params); - } -}; - -TEST_P(ConcatMemoryTest, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, -}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -const std::vector> shapes{ - {1, 64}, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_memory, - ConcatMemoryTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(shapes)), - ConcatMemoryTest::getTestCaseName); - -} // namespace LayerTestsDefinitions \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/concat_restrictions.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/concat_restrictions.cpp deleted file mode 100644 index f261b5a5e9c..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/concat_restrictions.cpp +++ /dev/null @@ -1,787 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -// -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset11.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -/* ============= Concat Layer Restrictions Tests ============= */ - -using ConcatRestrictionsParamsTuple = typename std::tuple, // Configuration - std::string>; // Device name - -namespace ConcatTestsDefinitions { - -using namespace InferenceEngine; -using namespace ngraph::builder; -using namespace ov; -using namespace ov::element; -using namespace ov::opset11; -using namespace std; - -shared_ptr create_fq_node(const Type& type, - const shared_ptr& node, - float fqMin, - float fqMax, - size_t levels) { - auto fqInpMin = makeConstant(type, {1}, {fqMin}); - auto fqInpMax = makeConstant(type, {1}, {fqMax}); - auto fqOutMin = makeConstant(type, {1}, {fqMin}); - auto fqOutMax = makeConstant(type, {1}, {fqMax}); - return make_shared(node, fqInpMin, fqInpMax, fqOutMin, fqOutMax, levels); -} - -struct ReLUConcatAxis { - static const char* getName() { - return "ReLUConcatAxis"; - } - static std::shared_ptr createTopology(const InferenceEngine::SizeVector& inputShape, - const unsigned int& axis, - const InferenceEngine::Precision& netPrecision) { - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::OutputVector concatInputs; - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto relu = ngraph::builder::makeActivation(params[0], ngPrc, ngraph::helpers::ActivationTypes::Relu); - concatInputs.push_back(relu); - size_t totalSize = ov::shape_size(inputShape); - auto constValues = ov::test::utils::generate_float_numbers(totalSize, -0.1f, 0.1f); - auto constNode = ngraph::builder::makeConstant(ngPrc, {inputShape}, constValues); - concatInputs.push_back(constNode); - auto concat = std::make_shared(concatInputs, axis); - - ov::ResultVector results{std::make_shared(concat)}; - return std::make_shared(results, params, getName()); - } - static const char* getMatch() { - return "Unsupported concatenation axis"; - } -}; - -struct MatmulConcatAxis { - static const char* getName() { - return "MatmulConcatAxis"; - } - static std::shared_ptr createTopology(const InferenceEngine::SizeVector& inputShape, - const unsigned int& axis, - const InferenceEngine::Precision& netPrecision) { - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::OutputVector concatInputs; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - ov::Shape mulConstShape; - - switch (inputShape.size()) { - default: - case 2: - mulConstShape = {inputShape[1], inputShape[1]}; - break; - case 3: - mulConstShape = {inputShape[0], inputShape[2], inputShape[2]}; - break; - case 4: - mulConstShape = {inputShape[0], inputShape[1], inputShape[3], inputShape[3]}; - break; - } - - size_t mulConstSize = ov::shape_size(mulConstShape); - std::vector weights1(mulConstSize); - std::vector weights2(mulConstSize); - std::iota(weights1.begin(), weights1.end(), 0.0f); - std::iota(weights2.begin(), weights2.end(), 0.0f); - auto constMul1 = ngraph::builder::makeConstant(ngPrc, mulConstShape, weights1); - auto constMul2 = ngraph::builder::makeConstant(ngPrc, mulConstShape, weights2); - auto matmul1 = std::make_shared(params[0], constMul1, false, true); - concatInputs.push_back(matmul1); - auto matmul2 = std::make_shared(params[0], constMul2, false, true); - concatInputs.push_back(matmul2); - auto concat = std::make_shared(concatInputs, axis); - - ov::ResultVector results{std::make_shared(concat)}; - return std::make_shared(results, params, getName()); - } - static const char* getMatch() { - return "Unsupported concatenation axis"; - } -}; - -struct ConvNCHWConcatAxis { - static const char* getName() { - return "ConvNCHWConcatAxis"; - } - static std::shared_ptr createTopology(const InferenceEngine::SizeVector& inputShape, - const unsigned int& axis, - const InferenceEngine::Precision& netPrecision) { - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::OutputVector concatInputs; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - - size_t numOutChannels = 8; - size_t kernelSize = 1; - std::vector filterWeights = - ov::test::utils::generate_float_numbers(numOutChannels * inputShape[1] * kernelSize, -0.2f, 0.2f); - auto conv = ngraph::builder::makeConvolution(params[0], - ngPrc, - {1, kernelSize}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ov::op::PadType::VALID, - numOutChannels, - true, - filterWeights); - - concatInputs.push_back(conv); - size_t totalSize = ov::shape_size(inputShape); - auto constValues = ov::test::utils::generate_float_numbers(totalSize, -0.0001f, 0.0001f); - auto constNode = ngraph::builder::makeConstant(ngPrc, {inputShape}, constValues); - concatInputs.push_back(constNode); - auto concat = std::make_shared(concatInputs, axis); - - ov::ResultVector results{std::make_shared(concat)}; - return std::make_shared(results, params, getName()); - } - static const char* getMatch() { - return "for input dimensions"; - } -}; - -struct ConvNHWCConcatAxis { - static const char* getName() { - return "ConvNHWCConcatAxis"; - } - static std::shared_ptr createTopology(const InferenceEngine::SizeVector& inputShape, - const unsigned int& axis, - const InferenceEngine::Precision& netPrecision) { - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::OutputVector concatInputs; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - - auto transposeInOrder = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 3, 1, 2}); - auto transposeIn = std::make_shared(params[0], transposeInOrder); - size_t numOutChannels = 8; - size_t kernelSize = 1; - std::vector filterWeights = - ov::test::utils::generate_float_numbers(numOutChannels * inputShape[3] * kernelSize, -0.2f, 0.2f); - auto conv = ngraph::builder::makeConvolution(transposeIn, - ngPrc, - {1, kernelSize}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ov::op::PadType::VALID, - numOutChannels, - true, - filterWeights); - auto transposeOutOrder = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 3, 1}); - auto transposeOut = std::make_shared(conv, transposeOutOrder); - - concatInputs.push_back(transposeOut); - size_t totalSize = ov::shape_size(inputShape); - auto constValues = ov::test::utils::generate_float_numbers(totalSize, -0.0001f, 0.0001f); - auto constNode = ngraph::builder::makeConstant(ngPrc, {inputShape}, constValues); - concatInputs.push_back(constNode); - auto concat = std::make_shared(concatInputs, axis); - - ov::ResultVector results{std::make_shared(concat)}; - return std::make_shared(results, params, getName()); - } - static const char* getMatch() { - return "Unsupported concatenation axis"; - } -}; - -struct ConvConcatNHWCAxis { - static const char* getName() { - return "ConvConcatNHWCAxis"; - } - static std::shared_ptr createTopology(const InferenceEngine::SizeVector& inputShape, - const unsigned int& axis, - const InferenceEngine::Precision& netPrecision) { - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::OutputVector concatInputs; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - - auto transposeInOrder = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 3, 1, 2}); - auto transposeIn1 = std::make_shared(params[0], transposeInOrder); - auto transposeIn2 = std::make_shared(params[0], transposeInOrder); - size_t numOutChannels = 8; - size_t kernelSize = 1; - std::vector filterWeights1 = - ov::test::utils::generate_float_numbers(numOutChannels * inputShape[3] * kernelSize, -0.1f, 2.2f); - std::vector filterWeights2 = - ov::test::utils::generate_float_numbers(numOutChannels * inputShape[3] * kernelSize, -1.2f, 0.5f); - auto conv1 = ngraph::builder::makeConvolution(transposeIn1, - ngPrc, - {1, kernelSize}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ov::op::PadType::VALID, - numOutChannels, - true, - filterWeights1); - auto conv2 = ngraph::builder::makeConvolution(transposeIn2, - ngPrc, - {1, kernelSize}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ov::op::PadType::VALID, - numOutChannels, - true, - filterWeights2); - - concatInputs.push_back(conv1); - concatInputs.push_back(conv2); - auto concat = std::make_shared(concatInputs, axis); - - auto transposeOutOrder = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 3, 1}); - auto transposeOut = std::make_shared(concat, transposeOutOrder); - - ov::ResultVector results{std::make_shared(transposeOut)}; - return std::make_shared(results, params, getName()); - } - static const char* getMatch() { - return "Unsupported concatenation axis"; - } -}; - -struct ConvConcatConcatNHWCAxis { - static const char* getName() { - return "ConvConcatConcatNHWCAxis"; - } - static std::shared_ptr createTopology(const InferenceEngine::SizeVector& inputShape, - const unsigned int& axis, - const InferenceEngine::Precision& netPrecision) { - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::OutputVector concat1Inputs, concat2Inputs; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - - auto transposeInOrder = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 3, 1, 2}); - auto transposeIn1 = std::make_shared(params[0], transposeInOrder); - auto transposeIn2 = std::make_shared(params[0], transposeInOrder); - size_t numOutChannels = 64; - size_t kernelSize = 1; - std::vector filterWeights1 = - ov::test::utils::generate_float_numbers(numOutChannels * inputShape[3] * kernelSize, -0.1f, 2.2f); - std::vector filterWeights2 = - ov::test::utils::generate_float_numbers(numOutChannels * inputShape[3] * kernelSize, -1.2f, 0.5f); - auto conv1 = ngraph::builder::makeConvolution(transposeIn1, - ngPrc, - {1, kernelSize}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ov::op::PadType::VALID, - numOutChannels, - true, - filterWeights1); - auto conv2 = ngraph::builder::makeConvolution(transposeIn2, - ngPrc, - {1, kernelSize}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ov::op::PadType::VALID, - numOutChannels, - true, - filterWeights2); - - auto transposeOutOrder = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 3, 1}); - auto transposeOut1 = std::make_shared(conv1, transposeOutOrder); - auto transposeOut2 = std::make_shared(conv2, transposeOutOrder); - - concat1Inputs.push_back(transposeOut1); - concat1Inputs.push_back(transposeOut2); - auto concat1 = std::make_shared(concat1Inputs, 2); - auto squeeze = std::make_shared( - concat1, - ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {0, 1})); - - size_t totalSize = ov::shape_size(squeeze->get_shape()); - auto constValues = ov::test::utils::generate_float_numbers(totalSize, -0.0001f, 0.0001f); - auto constNode = ngraph::builder::makeConstant(ngPrc, {squeeze->get_shape()}, constValues); - - concat2Inputs.push_back(squeeze); - concat2Inputs.push_back(constNode); - auto concat2 = std::make_shared(concat2Inputs, axis); - auto reshape = std::make_shared( - concat2, - ov::op::v0::Constant::create(ov::element::i64, - ov::Shape{2}, - ov::Shape{1, shape_size(concat2->get_shape())}), - false); - - ov::ResultVector results{std::make_shared(reshape)}; - return std::make_shared(results, params, getName()); - } - static const char* getMatch() { - return "Unsupported concatenation axis"; - } -}; - -// This test performs checks on the following network: -// Param1 -// | -// Reshape Param2 -// | | -// Convolution FQ -// | | -// ReLU Reshape -// | | -// FQ Transpose -// | | -// Reshape Reshape -// | | -// Transpose Transpose -// \ / -// Concat -// | -// Reshape -// | -// Result -// -// We want to ensure this Concat topology will not be detected as unsupported one. - -struct TransposeTransposeConcat { - static const char* getName() { - return "TransposeTransposeConcat"; - } - - static std::shared_ptr createTopology(const SizeVector& input_shapes, - const unsigned int& axis, - const Precision& net_precision) { - const float fq1 = 5.5, fq2 = 10.0; - const size_t levels = 65536; - const vector invert = {1, 0}; - const vector kernel_shape = {1, 3}; - const size_t input_channels = 8; - const size_t output_channels = 64; - - IE_ASSERT(input_shapes[0] % input_channels == 0); - IE_ASSERT(input_shapes[1] % input_shapes[0] == 0); - - vector concat_input_shape = {input_shapes[1] / input_shapes[0], input_shapes[0]}; - vector conv_input_shape = {1, input_channels, 1, input_shapes[0] / input_channels}; - - auto ng_prc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(net_precision); - ov::ParameterVector inputs{std::make_shared(ng_prc, ov::Shape{1, input_shapes[0]}), - std::make_shared(ng_prc, ov::Shape{1, input_shapes[1]})}; - // 1st concat input - auto reshape_l1_const = make_shared(i64, Shape{conv_input_shape.size()}, conv_input_shape); - auto reshape_l1 = make_shared(inputs[0], reshape_l1_const, false); - - auto conv_l1_weights = makeConstant(ng_prc, - {output_channels, input_channels, kernel_shape[0], kernel_shape[1]}, - {}, - true, - 1.0f, - -1.0f); - auto conv_l1_weights_fq = create_fq_node(ng_prc, conv_l1_weights, -fq1, fq1, levels); - auto conv_l1 = make_shared(reshape_l1, - conv_l1_weights_fq, - vector{1, 1}, - vector{0, 0}, - vector{0, 0}, - vector{1, 1}, - ov::op::PadType::VALID); - auto relu_l1 = make_shared(conv_l1); - auto fq_l1 = create_fq_node(ng_prc, relu_l1, -fq1, fq1, levels); - auto reshape_l2_const = make_shared(i64, Shape{concat_input_shape.size()}, concat_input_shape); - auto reshape_l2 = make_shared(fq_l1, reshape_l2_const, false); - auto transpose_l1_const = Constant::create(i64, Shape{invert.size()}, invert); - auto transpose_l1 = make_shared(reshape_l2, transpose_l1_const); - - // 2nd concat input - auto fq_r1 = create_fq_node(ng_prc, inputs[1], -fq2, fq2, levels); - auto reshape_r1_const = make_shared(i64, Shape{2}, concat_input_shape); - auto reshape_r1 = make_shared(fq_r1, reshape_r1_const, false); - auto transpose_r1_const = Constant::create(i64, Shape{invert.size()}, invert); - auto transpose_r1 = make_shared(reshape_r1, transpose_r1_const); - auto reshape_r3_const = make_shared(i64, Shape{concat_input_shape.size()}, concat_input_shape); - auto reshape_r3 = make_shared(transpose_r1, reshape_r3_const, false); - auto transpose_r2_const = Constant::create(i64, Shape{invert.size()}, invert); - auto transpose_r2 = make_shared(reshape_r3, transpose_r2_const); - - // Concat - auto concat = std::make_shared(ov::NodeVector{transpose_l1, transpose_r2}, 0); - - auto width_after_conv = (conv_input_shape[3] - kernel_shape[1]) + 1; - auto reshape_const = - make_shared(i64, Shape{2}, vector{1, 2 * output_channels * width_after_conv}); - auto reshape = make_shared(concat, reshape_const, false); - - ResultVector result{make_shared(reshape)}; - auto model = make_shared(result, inputs, getName()); - return model; - } -}; - -template -class ConcatRestrictions : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::SizeVector inputShape; - unsigned int concatAxis; - InferenceEngine::Precision netPrecision; - std::map configuration; - std::string targetDevice; - std::tie(inputShape, concatAxis, netPrecision, configuration, targetDevice) = obj.param; - std::ostringstream result; - result << T::getName() << "_"; - result << "inputShape=" << ov::test::utils::vec2str(inputShape) << "_"; - result << "concatAxis=" << concatAxis << "_"; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "configItem=" << configItem.first << "_" << configItem.second << "_"; - } - return result.str(); - } - static const char* getMatch() { - return T::getMatch(); - } - - Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.2f, 0.2f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - -protected: - void SetUp() override { - InferenceEngine::SizeVector inputShape; - unsigned int concatAxis; - InferenceEngine::Precision netPrecision; - std::tie(inputShape, concatAxis, netPrecision, configuration, targetDevice) = this->GetParam(); - function = T::createTopology(inputShape, concatAxis, netPrecision); - } -}; - -using ReLUConcatRestrictionsNeg = ConcatRestrictions; -using ReLUConcatRestrictionsPos = ConcatRestrictions; -using MatMulConcatRestrictionsNeg = ConcatRestrictions; -using MatMulConcatRestrictionsPos = ConcatRestrictions; -using ConvNCHWConcatRestrictionsNeg = ConcatRestrictions; -using ConvNCHWConcatRestrictionsPos = ConcatRestrictions; -using ConvNHWCConcatRestrictionsNeg = ConcatRestrictions; -using ConvNHWCConcatRestrictionsPos = ConcatRestrictions; -using ConvConcatNHWCRestrictionsNeg = ConcatRestrictions; -using ConvConcatNHWCRestrictionsPos = ConcatRestrictions; -using ConvConcatConcatNHWCRestrictionsNeg = ConcatRestrictions; -using ConvConcatConcatNHWCRestrictionsPos = ConcatRestrictions; -using TransposeTransposeConcatPos = ConcatRestrictions; - -// TODO: those tests are left for future when GNA plugin handles const tranposition required for concats with -// interleaved layers -// TEST_P(ReLUConcatRestrictionsNeg, CompareWithRefImpl) { -// ExpectLoadNetworkToThrow(getMatch()); -// }; -// -// TEST_P(ReLUConcatRestrictionsPos, CompareWithRefImpl) { -// Run(); -//}; - -TEST_P(MatMulConcatRestrictionsNeg, CompareWithRefImpl) { - ExpectLoadNetworkToThrow(getMatch()); -}; - -TEST_P(MatMulConcatRestrictionsPos, CompareWithRefImpl) { - Run(); -}; - -TEST_P(ConvNCHWConcatRestrictionsNeg, CompareWithRefImpl) { - ExpectLoadNetworkToThrow(getMatch()); -}; - -TEST_P(ConvNCHWConcatRestrictionsPos, CompareWithRefImpl) { - Run(); -}; - -TEST_P(ConvNHWCConcatRestrictionsNeg, CompareWithRefImpl) { - ExpectLoadNetworkToThrow(getMatch()); -}; - -TEST_P(ConvNHWCConcatRestrictionsPos, CompareWithRefImpl) { - Run(); -}; - -TEST_P(ConvConcatNHWCRestrictionsNeg, CompareWithRefImpl) { - ExpectLoadNetworkToThrow(getMatch()); -}; - -TEST_P(ConvConcatNHWCRestrictionsPos, CompareWithRefImpl) { - Run(); -}; - -TEST_P(ConvConcatConcatNHWCRestrictionsNeg, CompareWithRefImpl) { - ExpectLoadNetworkToThrow(getMatch()); -}; - -TEST_P(ConvConcatConcatNHWCRestrictionsPos, CompareWithRefImpl) { - Run(); -}; - -TEST_P(TransposeTransposeConcatPos, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32}; -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -// Negative 4D MatMul cases -const std::vector> inputShapesMatMul4D_neg = {{1, 2, 4, 8}}; -const std::vector concatAxisMatMul4D_neg = {2, 3}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions_matmul_4d, - MatMulConcatRestrictionsNeg, - ::testing::Combine(::testing::ValuesIn(inputShapesMatMul4D_neg), - ::testing::ValuesIn(concatAxisMatMul4D_neg), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - MatMulConcatRestrictionsNeg::getTestCaseName); - -// Positive 4D MatMul cases - TODO: this test fails with 4D Gemm computation errors -// const std::vector> inputShapesMatMul4D_pos = {{1, 2, 4, 8}}; -// const std::vector concatAxisMatMul4D_pos = {0, 1}; -// -// INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions_matmul_4d, MatMulConcatRestrictionsPos, -// ::testing::Combine( -// ::testing::ValuesIn(inputShapesMatMul4D_pos), -// ::testing::ValuesIn(concatAxisMatMul4D_pos), -// ::testing::ValuesIn(netPrecisions), -// ::testing::ValuesIn(configs), -// ::testing::Values(ov::test::utils::DEVICE_GNA)), -// MatMulConcatRestrictionsPos::getTestCaseName); - -// Negative 3D MatMul cases -const std::vector> inputShapesMatMul3D_neg = {{2, 4, 8}}; -const std::vector concatAxisMatMul3D_neg = {0, 2}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions_matmul_3d, - MatMulConcatRestrictionsNeg, - ::testing::Combine(::testing::ValuesIn(inputShapesMatMul3D_neg), - ::testing::ValuesIn(concatAxisMatMul3D_neg), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - MatMulConcatRestrictionsNeg::getTestCaseName); - -// Positive 3D MatMul cases - TODO: this test fails with 3D Gemm computation errors -// const std::vector> inputShapesMatMul3D_pos = {{2, 4, 8}}; -// const std::vector concatAxisMatMul3D_pos = {1}; -// -// INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions_matmul_3d, MatMulConcatRestrictionsPos, -// ::testing::Combine( -// ::testing::ValuesIn(inputShapesMatMul3D_pos), -// ::testing::ValuesIn(concatAxisMatMul3D_pos), -// ::testing::ValuesIn(netPrecisions), -// ::testing::ValuesIn(configs), -// ::testing::Values(ov::test::utils::DEVICE_GNA)), -// MatMulConcatRestrictionsPos::getTestCaseName); - -// Negative 2D MatMul cases -const std::vector> inputShapesMatMul2D_neg = {{8, 64}}; -const std::vector concatAxisMatMul2D_neg = {0}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions_matmul_2d, - MatMulConcatRestrictionsNeg, - ::testing::Combine(::testing::ValuesIn(inputShapesMatMul2D_neg), - ::testing::ValuesIn(concatAxisMatMul2D_neg), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - MatMulConcatRestrictionsNeg::getTestCaseName); - -// Positive 2D MatMul cases -const std::vector> inputShapesMatMul2D_pos = {{8, 64}}; -const std::vector concatAxisMatMul2D_pos = {1}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions_matmul_2d, - MatMulConcatRestrictionsPos, - ::testing::Combine(::testing::ValuesIn(inputShapesMatMul2D_pos), - ::testing::ValuesIn(concatAxisMatMul2D_pos), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - MatMulConcatRestrictionsPos::getTestCaseName); - -// Negative ReLU cases -const std::vector> inputShapesReLU_neg = {{64, 128}}; -const std::vector concatAxisReLU_neg = {0}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions_relu, - ReLUConcatRestrictionsNeg, - ::testing::Combine(::testing::ValuesIn(inputShapesReLU_neg), - ::testing::ValuesIn(concatAxisReLU_neg), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ReLUConcatRestrictionsNeg::getTestCaseName); - -// Positive ReLU cases -const std::vector> inputShapesReLU_pos = {{64, 128}}; -const std::vector concatAxisReLU_pos = {1}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions_relu, - ReLUConcatRestrictionsPos, - ::testing::Combine(::testing::ValuesIn(inputShapesReLU_pos), - ::testing::ValuesIn(concatAxisReLU_pos), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ReLUConcatRestrictionsPos::getTestCaseName); - -// Negative cases NCHW -const std::vector> inputShapesConvNCHW_neg = {{1, 8, 16, 32}}; -const std::vector concatAxisConvNCHW_neg = {3}; // Axis 1 should be negative as well, - // but is handled by the plugin in this case - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions, - ConvNCHWConcatRestrictionsNeg, - ::testing::Combine(::testing::ValuesIn(inputShapesConvNCHW_neg), - ::testing::ValuesIn(concatAxisConvNCHW_neg), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ConvNCHWConcatRestrictionsNeg::getTestCaseName); - -// Positive cases NCHW -const std::vector> inputShapesConvNCHW_pos = {{1, 8, 1, 64}}; -const std::vector concatAxisConvNCHW_pos = {2, 3}; // TODO: incorrect output buffer calculation - // when 0 axis is used - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions, - ConvNCHWConcatRestrictionsPos, - ::testing::Combine(::testing::ValuesIn(inputShapesConvNCHW_pos), - ::testing::ValuesIn(concatAxisConvNCHW_pos), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ConvNCHWConcatRestrictionsPos::getTestCaseName); - -// Negative cases NHWC -const std::vector> inputShapesNHWC_neg = {{1, 2, 16, 8}}; -const std::vector concatAxisNHWC_neg = {2, 3}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions, - ConvNHWCConcatRestrictionsNeg, - ::testing::Combine(::testing::ValuesIn(inputShapesNHWC_neg), - ::testing::ValuesIn(concatAxisNHWC_neg), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ConvNHWCConcatRestrictionsNeg::getTestCaseName); - -// Positive cases NHWC -const std::vector> inputShapesNHWC_pos = {{1, 1, 16, 8}}; -const std::vector concatAxisNHWC_pos = {1, 2}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions, - ConvNHWCConcatRestrictionsPos, - ::testing::Combine(::testing::ValuesIn(inputShapesNHWC_pos), - ::testing::ValuesIn(concatAxisNHWC_pos), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ConvNHWCConcatRestrictionsPos::getTestCaseName); - -// Negative cases NHWC with concat inside transposes - TODO: this test fails, because the transposes are not removed -// const std::vector> inputShapesConcatNHWC_neg = {{1, 1, 16, 8}}; -// const std::vector concatAxisConcatNHWC_neg = {1}; -// -// INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions, ConvConcatNHWCRestrictionsNeg, -// ::testing::Combine( -// ::testing::ValuesIn(inputShapesConcatNHWC_neg), -// ::testing::ValuesIn(concatAxisConcatNHWC_neg), -// ::testing::ValuesIn(netPrecisions), -// ::testing::ValuesIn(configs), -// ::testing::Values(ov::test::utils::DEVICE_GNA)), -// ConvConcatNHWCRestrictionsNeg::getTestCaseName); - -// Positive cases NHWC with concat inside transposes -const std::vector> inputShapesConcatNHWC_pos = {{1, 1, 16, 8}}; -const std::vector concatAxisConcatNHWC_pos = {2, 3}; // TODO: 0 fails with unsupported permute, - // because the transposes are not removed - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions, - ConvConcatNHWCRestrictionsPos, - ::testing::Combine(::testing::ValuesIn(inputShapesConcatNHWC_pos), - ::testing::ValuesIn(concatAxisConcatNHWC_pos), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ConvConcatNHWCRestrictionsPos::getTestCaseName); - -// Negative cases NHWC with two consecutive concats -const std::vector> inputShapesConcatConcatNHWC = {{1, 1, 16, 8}}; -const std::vector concatAxisConcatConcatNHWC_neg = {1}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions, - ConvConcatConcatNHWCRestrictionsNeg, - ::testing::Combine(::testing::ValuesIn(inputShapesConcatConcatNHWC), - ::testing::ValuesIn(concatAxisConcatConcatNHWC_neg), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ConvConcatConcatNHWCRestrictionsNeg::getTestCaseName); - -// Positive cases NHWC with two consecutive concats -const std::vector concatAxisConcatConcatNHWC_pos = {0}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions, - ConvConcatConcatNHWCRestrictionsPos, - ::testing::Combine(::testing::ValuesIn(inputShapesConcatConcatNHWC), - ::testing::ValuesIn(concatAxisConcatConcatNHWC_pos), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ConvConcatConcatNHWCRestrictionsPos::getTestCaseName); - -const vector ttc_input_shapes = {{64, 384}}; -const vector> ttc_configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}, -}; -const vector ttc_axis = {0}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_restrictions, - TransposeTransposeConcatPos, - ::testing::Combine(::testing::ValuesIn(ttc_input_shapes), - ::testing::ValuesIn(ttc_axis), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(ttc_configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - TransposeTransposeConcatPos::getTestCaseName); - -} // namespace ConcatTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/concat_transpose.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/concat_transpose.cpp deleted file mode 100644 index 801b8c52452..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/concat_transpose.cpp +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "openvino/opsets/opset12.hpp" -#include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "shared_test_classes/base/ov_subgraph.hpp" - -using namespace ov::opset12; -using namespace ov::test; - -namespace TransposesConcatTests { - -typedef std::tuple, // Configuration - std::map // Additional Configuration - > - TransposesConcatTestParamsSet; - -class TransposesConcatTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest { -public: - static std::string get_test_case_name(const testing::TestParamInfo& obj) { - ov::element::Type net_type, in_type, out_type; - std::string target_device; - std::map conf, conf_ext; - - std::tie(net_type, target_device, conf, conf_ext) = obj.param; - for (auto& conf_item : conf_ext) { - conf[conf_item.first] = conf_item.second; - } - - std::ostringstream result; - result << "netPRC=" << net_type << "_"; - result << "trgDev=" << target_device; - for (auto const& conf_i : conf) { - result << "_configItem=" << conf_i.first.c_str() << "_" << conf_i.second.c_str(); - } - return result.str(); - } - -protected: - void SetUp() override { - abs_threshold = std::numeric_limits::max(); - rel_threshold = std::numeric_limits::max(); - std::map conf, conf_ext; - std::tie(m_net_type, targetDevice, conf, conf_ext) = this->GetParam(); - - std::vector input_shapes = static_shapes_to_test_representation({{10, 1}}); - configuration.insert(conf.begin(), conf.end()); - for (auto& conf_item : conf_ext) { - configuration[conf_item.first] = conf_item.second; - } - init_input_shapes(input_shapes); - } - - void init_test_model() { - std::vector> input_shapes = {{10, 1}}; - - ov::ParameterVector params; - for (auto&& shape : input_shapes) { - params.push_back(std::make_shared(m_net_type, ov::Shape(shape))); - } - std::vector shape_1 = {10, 128}; - std::vector shape_2 = {10, 192}; - std::vector shape_3 = {10, 256}; - - std::shared_ptr input_node = params[0]; - - std::vector mulConstWeights(1 * 576); - std::iota(mulConstWeights.begin(), mulConstWeights.end(), 0.1f); - auto constMul1 = ngraph::builder::makeConstant(m_net_type, ov::Shape{1, 576}, mulConstWeights); - auto matmul1 = std::make_shared(input_node, constMul1, false, false); - - auto split_axis = std::make_shared(ov::element::u8, ov::Shape{1}, std::vector{1}); - auto split_slices = - std::make_shared(ov::element::u32, ov::Shape{3}, std::vector{128, 192, 256}); - auto split_node = std::make_shared(matmul1, split_axis, split_slices); - - std::vector transpose_order = {1, 0}; - auto transpose_const_1 = - std::make_shared(ov::element::u8, ov::Shape{transpose_order.size()}, transpose_order); - auto transpose_const_2 = - std::make_shared(ov::element::u8, ov::Shape{transpose_order.size()}, transpose_order); - auto transpose_const_3 = - std::make_shared(ov::element::u8, ov::Shape{transpose_order.size()}, transpose_order); - - auto transpose_node_1 = std::make_shared(split_node->output(0), transpose_const_1); - auto transpose_node_2 = std::make_shared(split_node->output(1), transpose_const_2); - auto transpose_node_3 = std::make_shared(split_node->output(2), transpose_const_3); - - const int axis = 0; - auto concat_node = - std::make_shared(ov::OutputVector{transpose_node_1, transpose_node_2, transpose_node_3}, axis); - - std::vector reshape_pattern = {1, 2, 5, 576}; - auto reshape_const = - std::make_shared(ov::element::u16, ov::Shape{reshape_pattern.size()}, reshape_pattern); - auto reshape_node = std::make_shared(concat_node, reshape_const, false); - - ov::ResultVector results{std::make_shared(reshape_node)}; - function = std::make_shared(results, params, "concat"); - } - - ov::element::Type m_net_type; - std::vector m_input_shape; -}; - -TEST_P(TransposesConcatTest, CompareWithRefs) { - init_test_model(); - run(); -} - -std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -std::vector> target_configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_1_0"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}}; - -const ov::element::TypeVector input_precisions = {ov::element::f32}; - -INSTANTIATE_TEST_SUITE_P(smoke_transposes_concat, - TransposesConcatTest, - ::testing::Combine(::testing::ValuesIn(input_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(target_configs)), - TransposesConcatTest::get_test_case_name); - -} // namespace TransposesConcatTests diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/conv_with_padding.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/conv_with_padding.cpp deleted file mode 100644 index fc77b4ab6f0..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/conv_with_padding.cpp +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "../shared_tests_instances/skip_tests_check.hpp" -#include "common_test_utils/type_prop.hpp" -#include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector, // Input Shape - std::vector, // Filter Shape - std::vector // Padding Size - > - ConvWithPaddingParams; - -namespace LayerTestsDefinitions { - -class ConvWithPadding : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon, - public GnaLayerTestCheck { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision precision; - std::string targetDevice; - std::map configuration; - std::vector input_shape; - std::vector filter_shape; - std::vector padding_size; - - std::tie(precision, targetDevice, configuration, input_shape, filter_shape, padding_size) = obj.param; - - std::ostringstream result; - result << "netPRC=" << precision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(input_shape) << "_"; - result << "_filterShape=" << ov::test::utils::vec2str(filter_shape) << "_"; - result << "_paddingSize=" << ov::test::utils::vec2str(padding_size); - - return result.str(); - } - -protected: - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.01f, 0.01f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - - void SetUp() override { - InferenceEngine::Precision precision; - std::vector input_shape; - std::vector filter_shape; - std::vector padding_size; - - std::tie(precision, targetDevice, configuration, input_shape, filter_shape, padding_size) = this->GetParam(); - - GnaLayerTestCheck::SetUp(targetDevice); - - auto ng_precision = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(precision); - auto input = std::make_shared(ng_precision, ngraph::Shape{input_shape}); - auto filter = ngraph::builder::makeConstant(ng_precision, filter_shape, {1.f}); - auto conv = std::make_shared(input, - filter, - ov::Strides{1, 1}, - padding_size, - padding_size, - ov::Strides{}); - - auto res = std::make_shared(conv); - function = std::make_shared(ngraph::ResultVector{res}, ngraph::ParameterVector{input}); - } -}; - -using ConvWithPaddingTestPos = ConvWithPadding; -using ConvWithPaddingTestNeg = ConvWithPadding; - -TEST_P(ConvWithPaddingTestPos, CompareWithRefImpl) { - Run(); -}; - -TEST_P(ConvWithPaddingTestNeg, CompareWithRefImpl) { - std::string what; - try { - LoadNetwork(); - } catch (const std::runtime_error& re) { - what.assign(re.what()); - } catch (const std::exception& e) { - what.assign(e.what()); - } catch (...) { - what.assign("Unknown failure occurred."); - } - EXPECT_HAS_SUBSTRING(what, std::string("Unsupported convolution input padding")); -}; - -const InferenceEngine::Precision net_precisions{InferenceEngine::Precision::FP32}; - -const std::vector> configs_gna_3_0_to_3_5 = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}}; - -const std::vector> configs_gna_3_0 = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}}; - -const std::vector> configs_gna_3_5 = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}}; - -const std::vector input2D = {1, 8, 16, 16}; -const std::vector filter2D = {8, 8, 2, 2}; -const std::vector> inputs2D_gna_3_5 = {{1, 1, 4, 16}, {1, 1, 16, 16}}; -const std::vector> inputs1D_gna_3_5 = {{1, 1, 1, 16}}; -const std::vector> filters1D_gna_3_5 = {{1, 1, 1, 2}, {1, 1, 1, 16}}; -const std::vector> filters2D_mappable_to_1D_gna_3_5 = {{1, 1, 2, 16}}; -const std::vector no_padding = {0, 0}; -const std::vector padding1D = {0, 1}; -const std::vector padding2D = {1, 1}; - -INSTANTIATE_TEST_SUITE_P(smoke_conv_without_padding, - ConvWithPaddingTestPos, - ::testing::Combine(::testing::Values(net_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs_gna_3_0_to_3_5), - ::testing::Values(input2D), - ::testing::Values(filter2D), - ::testing::Values(no_padding)), - ConvWithPaddingTestPos::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_conv_with_padding_input1D_filter1D_gna_3_5, - ConvWithPaddingTestPos, - ::testing::Combine(::testing::Values(net_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs_gna_3_5), - ::testing::ValuesIn(inputs1D_gna_3_5), - ::testing::ValuesIn(filters1D_gna_3_5), - ::testing::Values(padding1D)), - ConvWithPaddingTestPos::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_conv_with_padding_input2D_filter1D_gna_3_5, - ConvWithPaddingTestPos, - ::testing::Combine(::testing::Values(net_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs_gna_3_5), - ::testing::ValuesIn(inputs2D_gna_3_5), - ::testing::ValuesIn(filters1D_gna_3_5), - ::testing::Values(padding1D)), - ConvWithPaddingTestPos::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_conv_with_padding_2D_mappable_to_1D_gna_3_5, - ConvWithPaddingTestPos, - ::testing::Combine(::testing::Values(net_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs_gna_3_5), - ::testing::ValuesIn(inputs2D_gna_3_5), - ::testing::ValuesIn(filters2D_mappable_to_1D_gna_3_5), - ::testing::Values(padding1D)), - ConvWithPaddingTestPos::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_conv_with_padding_2D_gna_3_5, - ConvWithPaddingTestPos, - ::testing::Combine(::testing::Values(net_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs_gna_3_5), - ::testing::Values(input2D), - ::testing::Values(filter2D), - ::testing::Values(padding2D)), - ConvWithPaddingTestPos::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_expect_exception_for_conv_with_padding_when_gna_3_0, - ConvWithPaddingTestNeg, - ::testing::Combine(::testing::Values(net_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs_gna_3_0), - ::testing::Values(input2D), - ::testing::Values(filter2D), - ::testing::Values(padding2D)), - ConvWithPaddingTestNeg::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/convert_dwsc_to_scaleshifts.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/convert_dwsc_to_scaleshifts.cpp deleted file mode 100644 index fb7843e0470..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/convert_dwsc_to_scaleshifts.cpp +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/test_common.hpp" -#include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ngraph; -using namespace ov::opset1; - -namespace LayerTestsDefinitions { - -enum class modelType { - TranspDWSCTransp = 0, /* Transpose(NHWC->NCHW) => DWSC (Group Convolution) => Transpose(NCHW->NHWC) */ - TranspDWSCBiasTransp, /* Transpose(NHWC->NCHW) => DWSC => Broadcasted Add (Bias) => Transpose(NCHW->NHWC) */ -}; - -typedef std::tuple, // Pad begin - std::vector, // Pad end - InferenceEngine::SizeVector, // Dilation - op::PadType, // Padding type - size_t, // Num out channels - size_t, // Num groups - InferenceEngine::SizeVector // Bias - > - DWSCParams; - -typedef std::tuple, // Configuration - InferenceEngine::SizeVector, // Input shapes - modelType // Test model - > - DWSCToScaleShiftsParams; - -class DWSCToScaleShiftsTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - DWSCParams params; - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - InferenceEngine::SizeVector inputShape; - modelType model; - std::tie(params, netPrecision, targetDevice, configuration, inputShape, model) = obj.param; - op::PadType padType; - InferenceEngine::SizeVector filter, stride, dilation, bias; - std::vector padBegin, padEnd; - size_t numOutChannels, numGroups; - std::tie(filter, stride, padBegin, padEnd, dilation, padType, numOutChannels, numGroups, bias) = params; - - std::ostringstream result; - result << "M=" << static_cast(model) << "_"; - result << "IS=" << ov::test::utils::vec2str(inputShape) << "_"; - result << "K" << ov::test::utils::vec2str(filter) << "_"; - result << "S" << ov::test::utils::vec2str(stride) << "_"; - result << "PB" << ov::test::utils::vec2str(padBegin) << "_"; - result << "PE" << ov::test::utils::vec2str(padEnd) << "_"; - result << "D=" << ov::test::utils::vec2str(dilation) << "_"; - result << "O=" << numOutChannels << "_"; - result << "AP=" << padType << "_"; - result << "B=" << ov::test::utils::vec2str(bias) << "_"; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - return result.str(); - } - -protected: - void SetUp() override { - threshold = 0.05f; - DWSCParams params; - InferenceEngine::Precision netPrecision; - std::vector inputShape; - modelType model; - std::tie(params, netPrecision, targetDevice, configuration, inputShape, model) = this->GetParam(); - op::PadType padType; - InferenceEngine::SizeVector filter, stride, dilation, bias; - std::vector padBegin, padEnd; - size_t numOutChannels, numGroups; - std::tie(filter, stride, padBegin, padEnd, dilation, padType, numOutChannels, numGroups, bias) = params; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector input{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto transposeInOrder = Constant::create(element::i64, Shape{4}, {0, 3, 1, 2}); - auto transposeIn = std::make_shared(input[0], transposeInOrder); - auto filterSize = std::accumulate(std::begin(filter), std::end(filter), 1ull, std::multiplies()); - auto filterWeights = - ov::test::utils::generate_float_numbers(numOutChannels * (inputShape[3] / numGroups) * filterSize, - -0.5f, - 0.5f); - auto dwsc = builder::makeGroupConvolution(transposeIn, - ngPrc, - filter, - stride, - padBegin, - padEnd, - dilation, - padType, - numOutChannels, - numGroups, - false, - filterWeights); - auto transposeOutOrder = Constant::create(element::i64, Shape{4}, {0, 2, 3, 1}); - auto lastOp = std::make_shared(dwsc, transposeOutOrder); - - if (model == modelType::TranspDWSCBiasTransp) { - Shape biasShape{bias}; - auto biasWeights = ov::test::utils::generate_float_numbers(shape_size(biasShape), -1.0f, 1.0f); - auto biasConst = std::make_shared(ngPrc, biasShape, biasWeights); - auto bias = std::make_shared(dwsc, biasConst); - lastOp = std::make_shared(bias, transposeOutOrder); - } - - auto result = std::make_shared(lastOp); - function = std::make_shared(ResultVector{result}, ParameterVector{input}); - } -}; - -TEST_P(DWSCToScaleShiftsTest, CompareWithRefs) { - Run(); -} - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_PWL_UNIFORM_DESIGN", "NO"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_PWL_UNIFORM_DESIGN", "YES"}}}; - -const std::vector padTypes = {op::PadType::VALID, - op::PadType::EXPLICIT, - op::PadType::SAME_LOWER, - op::PadType::SAME_UPPER}; - -const std::vector models = {modelType::TranspDWSCTransp, modelType::TranspDWSCBiasTransp}; - -const std::vector> inputNHWC = {{1, 1, 5, 32}}; -const std::vector> filters = {{1, 3}}; -const std::vector> strides = {{1, 1}, {1, 2}}; -const std::vector> padBegins = {{0, 1}, {0, 2}}; -const std::vector> padEnds = {{0, 1}}; -const std::vector> dilations = {{1, 1}}; -const std::vector numOutChannels = {32}; -const std::vector numGroups = {32}; -const std::vector> biases = {{1, 32, 1, 1}}; - -const auto convParams = ::testing::Combine(::testing::ValuesIn(filters), - ::testing::ValuesIn(strides), - ::testing::ValuesIn(padBegins), - ::testing::ValuesIn(padEnds), - ::testing::ValuesIn(dilations), - ::testing::ValuesIn(padTypes), - ::testing::ValuesIn(numOutChannels), - ::testing::ValuesIn(numGroups), - ::testing::ValuesIn(biases)); - -INSTANTIATE_TEST_SUITE_P(smoke_DWSCToScaleShifts, - DWSCToScaleShiftsTest, - ::testing::Combine(convParams, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputNHWC), - ::testing::ValuesIn(models)), - DWSCToScaleShiftsTest::getTestCaseName); - -/* ============= Strides & Dilations Combination ============= */ - -const std::vector padTypesSD = { - op::PadType::VALID, -}; - -const std::vector> inputNHWCSD = {{1, 1, 8, 32}}; -const std::vector> dilationsSD = {{1, 1}, {1, 2}}; - -const auto convParamsSD = ::testing::Combine(::testing::ValuesIn(filters), - ::testing::ValuesIn(strides), - ::testing::ValuesIn(padBegins), - ::testing::ValuesIn(padEnds), - ::testing::ValuesIn(dilationsSD), - ::testing::ValuesIn(padTypesSD), - ::testing::ValuesIn(numOutChannels), - ::testing::ValuesIn(numGroups), - ::testing::ValuesIn(biases)); - -INSTANTIATE_TEST_SUITE_P(smoke_DWSCToScaleShiftsStridesDilations, - DWSCToScaleShiftsTest, - ::testing::Combine(convParamsSD, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputNHWCSD), - ::testing::ValuesIn(models)), - DWSCToScaleShiftsTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/convert_matmul_to_fullyconnected.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/convert_matmul_to_fullyconnected.cpp deleted file mode 100644 index 08c81e80862..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/convert_matmul_to_fullyconnected.cpp +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "functional_test_utils/blob_utils.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple>, // Input shape - InferenceEngine::Precision, // Network Precision - std::string, // Target Device - std::map // Configuration - > - ConvertMatmulToFcPassParams; - -namespace LayerTestsDefinitions { -class ConvertMatmulToFcPass : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector> inputShape; - std::tie(inputShape, netPrecision, targetDevice, configuration) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_IS=" << ov::test::utils::vec2str(inputShape[1]) << "_"; - result << "_CS=" << ov::test::utils::vec2str(inputShape[0]) << "_"; - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.2f, 0.2f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector> inputShape; - std::tie(inputShape, netPrecision, targetDevice, configuration) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape[1]))}; - std::vector weights = - ov::test::utils::generate_float_numbers(inputShape[0][0] * inputShape[0][1], -0.2f, 0.2f); - auto const_mult2 = ngraph::builder::makeConstant(ngPrc, inputShape[0], weights); - - auto const_eltwise = ngraph::builder::makeConstant(ngPrc, {inputShape[0][0], inputShape[1][1]}, {1.0f}); - auto matmul = std::make_shared(const_mult2, params[0], false, false); - - auto eltwise = std::make_shared(matmul, const_eltwise); - function = std::make_shared(eltwise, params, "ConvertMatmulToFC"); - } -}; - -class ConvertMatmulToFcWithTransposesPass : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector> inputShape; - std::tie(inputShape, netPrecision, targetDevice, configuration) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_IS=" << ov::test::utils::vec2str(inputShape[1]) << "_"; - result << "_CS=" << ov::test::utils::vec2str(inputShape[0]) << "_"; - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.1f, 0.1f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector> inputShape; - std::tie(inputShape, netPrecision, targetDevice, configuration) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{ - std::make_shared(ngPrc, ov::Shape({1, inputShape[1][0] * inputShape[1][1]}))}; - auto reshape1 = std::make_shared( - params[0], - ngraph::builder::makeConstant(ngraph::element::i64, {inputShape[1].size()}, inputShape[1]), - false); - auto transpose1 = std::make_shared( - reshape1, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, std::vector{1, 0})); - - std::vector weights = - ov::test::utils::generate_float_numbers(inputShape[0][0] * inputShape[0][1], -0.1f, 0.1f); - auto const_mult2 = ngraph::builder::makeConstant(ngPrc, inputShape[0], weights); - auto matmul = std::make_shared(const_mult2, transpose1, false, false); - auto relu = std::make_shared(matmul); - - auto transpose2 = std::make_shared( - relu, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, std::vector{1, 0})); - auto transpose_output_shape = transpose2->get_output_shape(0); - ngraph::Shape output_shape = {1, transpose_output_shape[0] * transpose_output_shape[1]}; - auto reshape2 = std::make_shared( - transpose2, - ngraph::builder::makeConstant(ngraph::element::i64, {output_shape.size()}, output_shape), - false); - - function = std::make_shared(reshape2, params, "ConvertMatmulToFCWithTransposes"); - } -}; - -TEST_P(ConvertMatmulToFcPass, CompareWithRefImpl) { - Run(); -} - -TEST_P(ConvertMatmulToFcWithTransposesPass, CompareWithRefImpl) { - Run(); -} - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}, {"GNA_COMPACT_MODE", "NO"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_COMPACT_MODE", "NO"}}}; - -const std::vector>> input_shapes = {{{1, 8}, {8, 1}}, - {{128, 8}, {8, 1}}, - {{8, 8}, {8, 8}}, - {{1, 16}, {16, 8}}, - {{6, 16}, {16, 8}}}; - -const std::vector>> input_shapes_transposes = {{{1, 8}, {1, 8}}, - {{128, 8}, {1, 8}}, - {{8, 8}, {8, 8}}, - {{1, 16}, {8, 16}}, - {{6, 16}, {1, 16}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_convert_matmul_to_fc, - ConvertMatmulToFcPass, - ::testing::Combine(::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvertMatmulToFcPass::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_convert_matmul_to_fc, - ConvertMatmulToFcWithTransposesPass, - ::testing::Combine(::testing::ValuesIn(input_shapes_transposes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvertMatmulToFcWithTransposesPass::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/convert_matmul_to_pointwise_conv.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/convert_matmul_to_pointwise_conv.cpp deleted file mode 100644 index 868017f0bc5..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/convert_matmul_to_pointwise_conv.cpp +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "common_test_utils/node_builders/eltwise.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset7.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector // Input Shape - > - convertMatmulToPointwiseConvParams; - -typedef std::tuple, // Configuration - std::vector, // Input Shape - std::pair // Input Min and Max - > - ConvertMatmulToPointwiseConvWithFqNegParams; - -namespace LayerTestsDefinitions { - -class ConvertMatmulToPointwiseConv : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(inputShape); - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.2f, 0.2f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - - size_t batch = inputShape[inputShape.size() - 2]; - size_t elemNum = inputShape[inputShape.size() - 1]; - std::vector weights = ov::test::utils::generate_float_numbers(elemNum * elemNum, -0.1f, 0.1f); - auto weightsNode = std::make_shared(ngPrc, ngraph::Shape{elemNum, elemNum}, weights); - auto matmul = std::make_shared(params[0], weightsNode, false, true); - - auto bias = ngraph::builder::makeConstant(ngPrc, std::vector{1, batch, 1}, std::vector{1.0f}); - auto add = ov::test::utils::make_eltwise(matmul, bias, ngraph::helpers::EltwiseTypes::ADD); - - auto pattern = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{inputShape.size()}, - inputShape); - auto reshape = std::make_shared(matmul, pattern, false); - auto relu = std::make_shared(reshape); - - ngraph::ResultVector results{std::make_shared(relu)}; - function = std::make_shared(results, params, "ConvertMatmulToPointwiseConv"); - } -}; - -class ConvertMatmulToPointwiseConvWithFqNeg - : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { - float inputDataMin = -10.0f; - float inputDataMax = 10.0f; - float inputDataResolution = 1.0f; - -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::pair inputMinMax; - std::tie(netPrecision, targetDevice, configuration, inputShape, inputMinMax) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(inputShape); - result << "_inputMinMax=(" << inputMinMax.first << ".." << inputMinMax.second << ")"; - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), - inputDataMax - inputDataMin, - inputDataMin, - 1 / inputDataResolution); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::pair inputMinMax; - std::tie(netPrecision, targetDevice, configuration, inputShape, inputMinMax) = this->GetParam(); - std::tie(inputDataMin, inputDataMax) = inputMinMax; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - - auto inputLowNode = - ngraph::builder::makeConstant(ngPrc, std::vector{1}, std::vector{inputDataMin}); - auto inputHighNode = - ngraph::builder::makeConstant(ngPrc, std::vector{1}, std::vector{inputDataMax}); - auto inputFQ = std::make_shared(params[0], - inputLowNode, - inputHighNode, - inputLowNode, - inputHighNode, - UINT16_MAX); - - size_t elemNum = inputShape[inputShape.size() - 1]; - - const float weightsMin = -0.2f; - const float weightsMax = 0.2f; - std::vector weights = ov::test::utils::generate_float_numbers(elemNum * elemNum, weightsMin, weightsMax); - auto weightsNode = std::make_shared(ngPrc, ngraph::Shape{elemNum, elemNum}, weights); - auto weightsLowNode = - ngraph::builder::makeConstant(ngPrc, std::vector{1}, std::vector{weightsMin}); - auto weightsHighNode = - ngraph::builder::makeConstant(ngPrc, std::vector{1}, std::vector{weightsMax}); - auto weightsFQNode = std::make_shared(weightsNode, - weightsLowNode, - weightsHighNode, - weightsLowNode, - weightsHighNode, - UINT16_MAX); - auto matmul = std::make_shared(inputFQ, weightsFQNode, false, true); - - auto bias = ngraph::builder::makeConstant(ngPrc, std::vector{1, 1, 1}, std::vector{1.0f}); - auto add = ov::test::utils::make_eltwise(matmul, bias, ngraph::helpers::EltwiseTypes::ADD); - - auto outputLowNode = ngraph::builder::makeConstant(ngPrc, - std::vector{1}, - std::vector{-inputDataMax * weightsMax * elemNum}); - auto outputHighNode = ngraph::builder::makeConstant(ngPrc, - std::vector{1}, - std::vector{inputDataMax * weightsMax * elemNum}); - auto outputFQ = std::make_shared(add, - outputLowNode, - outputHighNode, - outputLowNode, - outputHighNode, - UINT16_MAX); - - auto pattern = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{inputShape.size()}, - inputShape); - auto reshape = std::make_shared(outputFQ, pattern, false); - - auto relu = std::make_shared(reshape); - - ngraph::ResultVector results{std::make_shared(relu)}; - function = std::make_shared(results, params, "ConvertMatmulToPointwiseConv"); - } -}; - -TEST_P(ConvertMatmulToPointwiseConv, CompareWithRefImpl) { - Run(); -}; - -TEST_P(ConvertMatmulToPointwiseConvWithFqNeg, CompareWithRefImpl) { - std::stringstream what; - std::streambuf* sbuf = std::cout.rdbuf(); - std::streambuf* ebuf = std::cerr.rdbuf(); - std::cout.rdbuf(what.rdbuf()); - std::cerr.rdbuf(what.rdbuf()); - LoadNetwork(); - const auto expected = "Potential overload correction issue at layer "; - EXPECT_THAT(what.str(), ::testing::HasSubstr(expected)); - std::cout.rdbuf(sbuf); - std::cerr.rdbuf(ebuf); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -const std::vector> configs_neg = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"LOG_LEVEL", "LOG_WARNING"}}}; - -const std::vector> inputShape = {{1, 64, 64}, {1, 256, 128}, {1, 512, 128}}; - -const std::vector> fqStats = {{-0.5, 0.5}}; - -INSTANTIATE_TEST_SUITE_P(smoke_ConvertMatmulToPointwiseConvTest, - ConvertMatmulToPointwiseConv, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShape)), - ConvertMatmulToPointwiseConv::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_ConvertMatmulToPointwiseConvTest, - ConvertMatmulToPointwiseConvWithFqNeg, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs_neg), - ::testing::ValuesIn(inputShape), - ::testing::ValuesIn(fqStats)), - ConvertMatmulToPointwiseConvWithFqNeg::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/convert_padded_to_valid_conv.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/convert_padded_to_valid_conv.cpp deleted file mode 100644 index 905ac67d98a..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/convert_padded_to_valid_conv.cpp +++ /dev/null @@ -1,324 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include "../shared_tests_instances/skip_tests_check.hpp" -#include "common_test_utils/test_common.hpp" -#include "ngraph/opsets/opset7.hpp" -#include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ngraph; -using namespace ngraph::opset7; - -namespace LayerTestsDefinitions { - -enum class modelType { - TranspConvTransp = 0, /* Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) */ - TranspConvBcastAddTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => Transpose(NCHW->NHWC) */ - TranspConvActTransp, /* Transpose(NHWC->NCHW) => Conv => Activation Function => Transpose(NCHW->NHWC) */ - TranspConvBcastAddMaxPoolTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => MaxPooling => - Transpose(NCHW->NHWC) (2D Max Pool case) */ - TranspConvBcastAddActTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => Activation Function => - Transpose(NCHW->NHWC) */ - TranspConvBcastAddMaxPoolActTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => MaxPool => - Activation Function => Transpose(NCHW->NHWC) */ - TranspConvTranspBcastAdd, /* Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) => Bias */ - TranspConvTranspBcastAddAct /* Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) => Bias => Activation Function - */ -}; - -typedef std::tuple, // Pad begin - std::vector, // Pad end - InferenceEngine::SizeVector, // Dilation - size_t, // Num out channels - op::PadType // Padding type - > - convSpecificParams; - -typedef std::tuple - miscSpecificParams; - -typedef std::tuple, // Configuration - InferenceEngine::SizeVector, // Input shapes - modelType // Test model - > - paddedToValidParams; - -class PaddedToValidConvTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - convSpecificParams convParams; - miscSpecificParams miscParams; - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - InferenceEngine::SizeVector inputShape; - modelType model; - std::tie(convParams, miscParams, netPrecision, targetDevice, configuration, inputShape, model) = obj.param; - op::PadType padType; - InferenceEngine::SizeVector kernel, stride, dilation, bias, transpBias, maxpoolPool, maxpoolStride; - std::vector padBegin, padEnd; - size_t numOutChannels; - std::tie(kernel, stride, padBegin, padEnd, dilation, numOutChannels, padType) = convParams; - std::tie(bias, transpBias, maxpoolPool, maxpoolStride) = miscParams; - - std::ostringstream result; - result << "M=" << static_cast(model) << "_"; - result << "IS=" << ov::test::utils::vec2str(inputShape) << "_"; - result << "K" << ov::test::utils::vec2str(kernel) << "_"; - result << "S" << ov::test::utils::vec2str(stride) << "_"; - result << "PB" << ov::test::utils::vec2str(padBegin) << "_"; - result << "PE" << ov::test::utils::vec2str(padEnd) << "_"; - result << "D=" << ov::test::utils::vec2str(dilation) << "_"; - result << "O=" << numOutChannels << "_"; - result << "AP=" << padType << "_"; - result << "B=" << ov::test::utils::vec2str(bias) << "_"; - result << "B=" << ov::test::utils::vec2str(transpBias) << "_"; - result << "MPP=" << ov::test::utils::vec2str(maxpoolPool) << "_"; - result << "MPS=" << ov::test::utils::vec2str(maxpoolStride) << "_"; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - return result.str(); - } - -protected: - GnaLayerTestCheck gnaVersionCheck; - - void SetUp() override { - threshold = 0.015f; - convSpecificParams convParams; - miscSpecificParams miscParams; - InferenceEngine::Precision netPrecision; - std::vector inputShape; - modelType model; - std::tie(convParams, miscParams, netPrecision, targetDevice, configuration, inputShape, model) = - this->GetParam(); - op::PadType padType; - InferenceEngine::SizeVector kernel, stride, dilation, bias, transpBias, maxpoolPool, maxpoolStride; - std::vector padBegin, padEnd; - size_t numOutChannels; - std::tie(kernel, stride, padBegin, padEnd, dilation, numOutChannels, padType) = convParams; - std::tie(bias, transpBias, maxpoolPool, maxpoolStride) = miscParams; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - Shape biasShape{bias}; - Shape transpBiasShape{transpBias}; - Shape maxpoolShape{maxpoolPool}; - Strides maxpoolStrides{maxpoolStride}; - - ov::ParameterVector input{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto transposeInOrder = op::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2}); - auto transposeIn = std::make_shared(input[0], transposeInOrder); - auto filterSize = std::accumulate(std::begin(kernel), std::end(kernel), 1ull, std::multiplies()); - auto filterWeights = - ov::test::utils::generate_float_numbers(numOutChannels * inputShape[3] * filterSize, -0.05f, 0.05f); - auto conv = builder::makeConvolution(transposeIn, - ngPrc, - kernel, - stride, - padBegin, - padEnd, - dilation, - padType, - numOutChannels, - false, - filterWeights); - auto transposeOutOrder = op::Constant::create(element::i64, Shape{4}, {0, 2, 3, 1}); - auto biasWeights = ov::test::utils::generate_float_numbers(shape_size(biasShape), -1.5f, 1.5f); - Output biasConst = std::make_shared(ngPrc, biasShape, biasWeights); - Output lastOp = std::make_shared(conv, transposeOutOrder); - - switch (model) { - case modelType::TranspConvBcastAddTransp: { - auto bias = std::make_shared(conv, biasConst); - lastOp = std::make_shared(bias, transposeOutOrder); - } break; - - case modelType::TranspConvActTransp: { - auto activation = std::make_shared(conv); - lastOp = std::make_shared(activation, transposeOutOrder); - } break; - - case modelType::TranspConvBcastAddMaxPoolTransp: { - auto bcastAdd = std::make_shared(conv, biasConst); - auto maxpool = std::make_shared(bcastAdd, - maxpoolStrides, - Shape{0, 0}, - Shape{0, 0}, - maxpoolShape, - op::RoundingType::FLOOR, - op::PadType::VALID); - auto transpose = std::make_shared(maxpool, transposeOutOrder); - auto lastOp = std::make_shared(transpose); - } break; - - case modelType::TranspConvBcastAddActTransp: { - auto bcastAdd = std::make_shared(conv, biasConst); - auto activation = std::make_shared(bcastAdd); - lastOp = std::make_shared(activation, transposeOutOrder); - } break; - - case modelType::TranspConvBcastAddMaxPoolActTransp: { - auto bcastAdd = std::make_shared(conv, biasConst); - auto maxpool = std::make_shared(bcastAdd, - maxpoolStrides, - Shape{0, 0}, - Shape{0, 0}, - maxpoolShape, - op::RoundingType::FLOOR, - op::PadType::VALID); - auto activation = std::make_shared(maxpool); - lastOp = std::make_shared(activation, transposeOutOrder); - } break; - - case modelType::TranspConvTranspBcastAdd: { - biasConst = std::make_shared(ngPrc, transpBiasShape); - lastOp = std::make_shared(lastOp, biasConst); - } break; - - case modelType::TranspConvTranspBcastAddAct: { - biasConst = builder::makeConstant(ngPrc, transpBiasShape, biasWeights, true); - auto bcastAdd = std::make_shared(lastOp, biasConst); - lastOp = std::make_shared(bcastAdd); - } break; - - case modelType::TranspConvTransp: - default: - break; - } - - auto result = std::make_shared(lastOp); - function = std::make_shared(ResultVector{result}, ParameterVector{input}); - gnaVersionCheck.SetUp(targetDevice); - } -}; - -TEST_P(PaddedToValidConvTest, CompareWithRefs) { - Run(); -} - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs1D = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_EXEC_TARGET", "GNA_TARGET_1_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}}; - -const std::vector> configs2D = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}}; - -const std::vector padTypes = {op::PadType::VALID, - op::PadType::EXPLICIT, - op::PadType::SAME_LOWER, - op::PadType::SAME_UPPER}; - -const std::vector models = {modelType::TranspConvTransp, - modelType::TranspConvBcastAddTransp, - modelType::TranspConvActTransp, - modelType::TranspConvBcastAddActTransp, - modelType::TranspConvTranspBcastAdd, - modelType::TranspConvTranspBcastAddAct, - modelType::TranspConvBcastAddMaxPoolTransp, - modelType::TranspConvBcastAddMaxPoolActTransp}; - -const std::vector> input1DNHWC = {{1, 1, 16, 8}}; -const std::vector> kernels1D = {{1, 2}, {1, 3}, {1, 4}}; -const std::vector> strides1D = {{1, 1}}; -const std::vector> padBegins1D = {{0, 2}}; -const std::vector> padEnds1D = {{0, 3}}; -const std::vector> dilations1D = {{1, 1}}; -const std::vector numOutChannels1D = {4}; -const std::vector> biases1D = {{1, 4, 1, 1}}; -const std::vector> transpBiases1D = {{1, 1, 1, 4}}; -const std::vector> maxpool1DPools = {{1, 2}}; -const std::vector> maxpool1DStrides = {{1, 1}}; - -const std::vector> input2DNHWC = {{1, 16, 16, 32}}; -const std::vector> kernels2D = {{2, 2}, {4, 1}}; -const std::vector> strides2D = {{1, 1}, {2, 1}}; -const std::vector> padBegins2D = {{1, 2}}; -const std::vector> padEnds2D = {{3, 1}}; -const std::vector> dilations2D = {{1, 1}}; -const std::vector numOutChannels2D = {8}; -const std::vector> biases2D = {{1, 8, 1, 1}}; -const std::vector> transpBiases2D = {{1, 1, 1, 8}}; -const std::vector> maxpool2DPools = {{2, 2}}; -const std::vector> maxpool2DStrides = {{2, 1}}; - -const auto conv1DParams = ::testing::Combine(::testing::ValuesIn(kernels1D), - ::testing::ValuesIn(strides1D), - ::testing::ValuesIn(padBegins1D), - ::testing::ValuesIn(padEnds1D), - ::testing::ValuesIn(dilations1D), - ::testing::ValuesIn(numOutChannels1D), - ::testing::ValuesIn(padTypes)); - -const auto misc1DParams = ::testing::Combine(::testing::ValuesIn(biases1D), - ::testing::ValuesIn(transpBiases1D), - ::testing::ValuesIn(maxpool1DPools), - ::testing::ValuesIn(maxpool1DStrides)); - -const auto conv2DParams = ::testing::Combine(::testing::ValuesIn(kernels2D), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutChannels2D), - ::testing::ValuesIn(padTypes)); - -const auto misc2DParams = ::testing::Combine(::testing::ValuesIn(biases2D), - ::testing::ValuesIn(transpBiases2D), - ::testing::ValuesIn(maxpool2DPools), - ::testing::ValuesIn(maxpool2DStrides)); - -INSTANTIATE_TEST_SUITE_P(smoke_1DPaddedToValid, - PaddedToValidConvTest, - ::testing::Combine(conv1DParams, - misc1DParams, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs1D), - ::testing::ValuesIn(input1DNHWC), - ::testing::ValuesIn(models)), - PaddedToValidConvTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_2DPaddedToValid, - PaddedToValidConvTest, - ::testing::Combine(conv2DParams, - misc2DParams, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs2D), - ::testing::ValuesIn(input2DNHWC), - ::testing::ValuesIn(models)), - PaddedToValidConvTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/convolution_align_filter.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/convolution_align_filter.cpp deleted file mode 100644 index 0e23c8954d4..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/convolution_align_filter.cpp +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset8.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector // shape to split - > - convAlignFilterParams; - -namespace LayerTestsDefinitions { - -class ConvolutionAlignFilterTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector splitInputShape; - std::tie(netPrecision, targetDevice, configuration, splitInputShape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_SIS=" << ov::test::utils::vec2str(splitInputShape); - return result.str(); - } - -protected: - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.2f, 0.2f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector splitInputShape; - std::tie(netPrecision, targetDevice, configuration, splitInputShape) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - size_t in_total_dims_size = - std::accumulate(std::begin(splitInputShape), std::end(splitInputShape), 1, std::multiplies()); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape{1, in_total_dims_size})}; - auto pattern1 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{2}, splitInputShape); - auto reshape1 = std::make_shared(params[0], pattern1, false); - OPENVINO_SUPPRESS_DEPRECATED_START - auto split = ngraph::builder::makeSplit(reshape1, ngPrc, 2, 0); - OPENVINO_SUPPRESS_DEPRECATED_END - - auto relu1 = std::make_shared(split->output(0)); - auto relu2 = std::make_shared(split->output(1)); - - auto concat = std::make_shared(ngraph::OutputVector{relu1, relu2}, 0); - auto pattern2 = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{2}, - ngraph::Shape{1, in_total_dims_size}); - auto reshape2 = std::make_shared(concat, pattern2, false); - - ngraph::ResultVector results{std::make_shared(reshape2)}; - function = std::make_shared(results, params, "ConvAlignFilter"); - functionRefs = ngraph::clone_function(*function); - } -}; - -TEST_P(ConvolutionAlignFilterTest, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -const std::vector> shapes{{16, 24}, {8, 32}}; - -INSTANTIATE_TEST_SUITE_P(smoke_conv_align_filter, - ConvolutionAlignFilterTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(shapes)), - ConvolutionAlignFilterTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/convolution_crop_axis_h.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/convolution_crop_axis_h.cpp deleted file mode 100644 index 936b7a9af9f..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/convolution_crop_axis_h.cpp +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector // input shape - > - cccmParams; - -namespace LayerTestsDefinitions { - -class CropAfterConvolutionTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector cropInputShape; - std::tie(netPrecision, targetDevice, configuration, cropInputShape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_CIS=" << ov::test::utils::vec2str(cropInputShape); - return result.str(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = this->GetParam(); - - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - auto reshape_pattern_size = ngraph::Shape{inputShape.size()}; - auto reshape_pattern = ngraph::builder::makeConstant(ov::element::i64, reshape_pattern_size, inputShape); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto input_reshape = std::make_shared(params[0], reshape_pattern, false); - - const std::vector filterSize{1, 1}; - const std::vector strides{1, 1}; - const std::vector padsBegin{0, 0}; - const std::vector padsEnd{0, 0}; - const std::vector dilations{1, 1}; - const auto pad_type = ngraph::op::PadType::EXPLICIT; - const size_t numOutChannels = 8; - constexpr auto c_index_in_nchw = 1; - constexpr auto h_index_in_nchw = 2; - const auto weights_size = ngraph::shape_size(filterSize) * numOutChannels * inputShape[c_index_in_nchw]; - auto weights_values = ov::test::utils::generate_float_numbers(weights_size, -0.2f, 0.2f); - const auto weights2_size = ngraph::shape_size(filterSize) * numOutChannels * numOutChannels; - auto weights2_values = ov::test::utils::generate_float_numbers(weights2_size, -0.2f, 0.2f); - - auto convolution_node = ngraph::builder::makeConvolution(input_reshape, - ngPrc, - filterSize, - strides, - padsBegin, - padsEnd, - dilations, - pad_type, - numOutChannels, - false, - weights_values); - - const std::vector crop_begin{4}; - const std::vector crop_end{20}; - const std::vector crop_stride{1}; - const std::vector axes{h_index_in_nchw}; - OPENVINO_SUPPRESS_DEPRECATED_START - auto split_node = ngraph::builder::makeSlice(convolution_node, crop_begin, crop_end, crop_stride, axes, ngPrc); - OPENVINO_SUPPRESS_DEPRECATED_END - - auto convolution_node2 = ngraph::builder::makeConvolution(split_node, - ngPrc, - filterSize, - strides, - padsBegin, - padsEnd, - dilations, - pad_type, - numOutChannels, - false, - weights2_values); - ngraph::ResultVector results{std::make_shared(convolution_node2)}; - function = std::make_shared(results, params, "CropAfterConvolutionTest"); - } -}; - -TEST_P(CropAfterConvolutionTest, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32, -}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -const std::vector> input_shapes{ - {1, 8, 32, 16}, - {1, 16, 32, 16}, - {1, 8, 128, 32}, - {1, 16, 32, 32}, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_crop_after_conv, - CropAfterConvolutionTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(input_shapes)), - CropAfterConvolutionTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/decompose_2d_conv.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/decompose_2d_conv.cpp deleted file mode 100644 index bff69b08bcc..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/decompose_2d_conv.cpp +++ /dev/null @@ -1,392 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include "../shared_tests_instances/skip_tests_check.hpp" -#include "common_test_utils/test_common.hpp" -#include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ngraph; -using namespace ov::opset1; - -namespace LayerTestsDefinitions { - -enum class modelType { - TranspConvTransp = 0, /* Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) */ - TranspConvBcastAddTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => Transpose(NCHW->NHWC) */ - TranspConvActTransp, /* Transpose(NHWC->NCHW) => Conv => Activation Function => Transpose(NCHW->NHWC) */ - TranspConvBcastAddMaxPoolTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => MaxPooling => - Transpose(NCHW->NHWC) (2D Max Pool case) */ - TranspConvBcastAddActTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => Activation Function => - Transpose(NCHW->NHWC) */ - TranspConvBcastAddMaxPoolActTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => MaxPool => - Activation Function => Transpose(NCHW->NHWC) */ - TranspConvTranspBcastAdd, /* Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) => Bias */ - TranspConvTranspBcastAddAct /* Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) => Bias => AF */ -}; - -typedef std::tuple, // Pad begin - std::vector, // Pad end - InferenceEngine::SizeVector, // Dilation - size_t, // Num out channels - op::PadType // Padding type - > - convSpecificParams; - -typedef std::tuple - miscSpecificParams; - -typedef std::tuple, // Configuration - InferenceEngine::SizeVector, // Input shapes - modelType // Test model - > - decompose2DConvParams; - -class Decompose2DConvTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - convSpecificParams convParams; - miscSpecificParams miscParams; - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - InferenceEngine::SizeVector inputShape; - modelType model; - std::tie(convParams, miscParams, netPrecision, targetDevice, configuration, inputShape, model) = obj.param; - op::PadType padType; - InferenceEngine::SizeVector kernel, stride, dilation, bias, transpBias, maxpoolPool, maxpoolStride; - std::vector padBegin, padEnd; - size_t numOutChannels; - std::tie(kernel, stride, padBegin, padEnd, dilation, numOutChannels, padType) = convParams; - std::tie(bias, transpBias, maxpoolPool, maxpoolStride) = miscParams; - - std::ostringstream result; - result << "M=" << static_cast(model) << "_"; - result << "IS=" << ov::test::utils::vec2str(inputShape) << "_"; - result << "K" << ov::test::utils::vec2str(kernel) << "_"; - result << "S" << ov::test::utils::vec2str(stride) << "_"; - result << "PB" << ov::test::utils::vec2str(padBegin) << "_"; - result << "PE" << ov::test::utils::vec2str(padEnd) << "_"; - result << "D=" << ov::test::utils::vec2str(dilation) << "_"; - result << "O=" << numOutChannels << "_"; - result << "AP=" << padType << "_"; - result << "B=" << ov::test::utils::vec2str(bias) << "_"; - result << "B=" << ov::test::utils::vec2str(transpBias) << "_"; - result << "MPP=" << ov::test::utils::vec2str(maxpoolPool) << "_"; - result << "MPS=" << ov::test::utils::vec2str(maxpoolStride) << "_"; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - return result.str(); - } - -protected: - GnaLayerTestCheck gnaVersionCheck; - - void SetUp() override { - threshold = 0.015f; - convSpecificParams convParams; - miscSpecificParams miscParams; - InferenceEngine::Precision netPrecision; - std::vector inputShape; - modelType model; - std::tie(convParams, miscParams, netPrecision, targetDevice, configuration, inputShape, model) = - this->GetParam(); - op::PadType padType; - InferenceEngine::SizeVector kernel, stride, dilation, bias, transpBias, maxpoolPool, maxpoolStride; - std::vector padBegin, padEnd; - size_t numOutChannels; - std::tie(kernel, stride, padBegin, padEnd, dilation, numOutChannels, padType) = convParams; - std::tie(bias, transpBias, maxpoolPool, maxpoolStride) = miscParams; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - Shape biasShape{bias}; - Shape transpBiasShape{transpBias}; - Shape maxpoolShape{maxpoolPool}; - Strides maxpoolStrides{maxpoolStride}; - - ov::ParameterVector input{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto transposeInOrder = ov::op::v0::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2}); - auto transposeIn = std::make_shared(input[0], transposeInOrder); - auto filterSize = std::accumulate(std::begin(kernel), std::end(kernel), 1ull, std::multiplies()); - auto filterWeights = - ov::test::utils::generate_float_numbers(numOutChannels * inputShape[3] * filterSize, -0.03f, 0.03f); - auto conv = builder::makeConvolution(transposeIn, - ngPrc, - kernel, - stride, - padBegin, - padEnd, - dilation, - padType, - numOutChannels, - false, - filterWeights); - auto transposeOutOrder = ov::op::v0::Constant::create(element::i64, Shape{4}, {0, 2, 3, 1}); - auto biasWeights = ov::test::utils::generate_float_numbers(shape_size(biasShape), -1.5f, 1.5f); - Output biasConst = std::make_shared(ngPrc, biasShape, biasWeights); - Output lastOp = std::make_shared(conv, transposeOutOrder); - - switch (model) { - case modelType::TranspConvBcastAddTransp: { - auto bias = std::make_shared(conv, biasConst); - lastOp = std::make_shared(bias, transposeOutOrder); - } break; - - case modelType::TranspConvActTransp: { - auto activation = std::make_shared(conv); - lastOp = std::make_shared(activation, transposeOutOrder); - } break; - - case modelType::TranspConvBcastAddMaxPoolTransp: { - auto bcastAdd = std::make_shared(conv, biasConst); - auto maxpool = std::make_shared(bcastAdd, - maxpoolStrides, - Shape{0, 0}, - Shape{0, 0}, - maxpoolShape, - op::RoundingType::FLOOR, - op::PadType::VALID); - auto transpose = std::make_shared(maxpool, transposeOutOrder); - lastOp = std::make_shared(transpose); - } break; - - case modelType::TranspConvBcastAddActTransp: { - auto bcastAdd = std::make_shared(conv, biasConst); - auto activation = std::make_shared(bcastAdd); - lastOp = std::make_shared(activation, transposeOutOrder); - } break; - - case modelType::TranspConvBcastAddMaxPoolActTransp: { - auto bcastAdd = std::make_shared(conv, biasConst); - auto max_pool = std::make_shared(bcastAdd, - Strides{1, 1}, - Shape{0, 0}, - Shape{0, 0}, - maxpoolShape, - op::RoundingType::FLOOR, - op::PadType::VALID); - auto activation = std::make_shared(max_pool); - lastOp = std::make_shared(activation, transposeOutOrder); - } break; - - case modelType::TranspConvTranspBcastAdd: { - biasConst = std::make_shared(ngPrc, transpBiasShape); - lastOp = std::make_shared(lastOp, biasConst); - } break; - - case modelType::TranspConvTranspBcastAddAct: { - biasConst = builder::makeConstant(ngPrc, transpBiasShape, biasWeights, true); - auto bcastAdd = std::make_shared(lastOp, biasConst); - lastOp = std::make_shared(bcastAdd); - } break; - - case modelType::TranspConvTransp: - default: - break; - } - - auto result = std::make_shared(lastOp); - function = std::make_shared(ResultVector{result}, ParameterVector{input}); - gnaVersionCheck.SetUp(targetDevice); - } -}; - -TEST_P(Decompose2DConvTest, CompareWithRefs) { - Run(); -} - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}}; - -const std::vector> configsExec3XCompile20 = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_SCALE_FACTOR_0", "1"}, - {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}, - {"GNA_COMPILE_TARGET", "GNA_TARGET_2_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_SCALE_FACTOR_0", "1"}, - {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}, - {"GNA_COMPILE_TARGET", "GNA_TARGET_2_0"}}}; - -const std::vector padTypes = {op::PadType::VALID, - op::PadType::EXPLICIT, - op::PadType::SAME_LOWER, - op::PadType::SAME_UPPER}; - -const std::vector models = {modelType::TranspConvTransp, - modelType::TranspConvBcastAddTransp, - modelType::TranspConvActTransp, - modelType::TranspConvBcastAddActTransp, - modelType::TranspConvTranspBcastAdd, - modelType::TranspConvTranspBcastAddAct, - modelType::TranspConvBcastAddMaxPoolTransp, - modelType::TranspConvBcastAddMaxPoolActTransp}; - -const std::vector modelsWithPool = {modelType::TranspConvBcastAddMaxPoolTransp, - modelType::TranspConvBcastAddMaxPoolActTransp}; - -const std::vector> input2DNHWC = {{1, 4, 4, 32}}; -const std::vector> kernels2D = {{1, 2}, {2, 1}, {2, 2}}; -const std::vector> strides2D = {{1, 1}}; -const std::vector> padBegins2D = {{1, 1}}; -const std::vector> padEnds2D = {{3, 1}}; -const std::vector> dilations2D = {{1, 1}, {1, 2}, {2, 1}, {2, 2}}; -const std::vector numOutChannels2D = {4}; -const std::vector> biases2D = {{1, 4, 1, 1}}; -const std::vector> transpBiases2D = {{1, 1, 1, 4}}; -const std::vector> maxpool1DPools = {{1, 2}}; -const std::vector> maxpool1DStrides = {{1, 1}}; - -const auto conv2DParams = ::testing::Combine(::testing::ValuesIn(kernels2D), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutChannels2D), - ::testing::ValuesIn(padTypes)); - -const auto miscParams = ::testing::Combine(::testing::ValuesIn(biases2D), - ::testing::ValuesIn(transpBiases2D), - ::testing::ValuesIn(maxpool1DPools), - ::testing::ValuesIn(maxpool1DStrides)); - -INSTANTIATE_TEST_SUITE_P(smoke_Decompose2DConv, - Decompose2DConvTest, - ::testing::Combine(conv2DParams, - miscParams, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(input2DNHWC), - ::testing::ValuesIn(models)), - Decompose2DConvTest::getTestCaseName); - -// These tests flow compile the model for GNA 2.0 -// and load by GNA Library for GNA 3.0 execution target -// They assure that the W/A for pooling output differences btw GNA 2.0 / 3.0 is properly working -INSTANTIATE_TEST_CASE_P(smoke_Decompose2DConv_Exec3XCompile20, - Decompose2DConvTest, - ::testing::Combine(conv2DParams, - miscParams, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configsExec3XCompile20), - ::testing::ValuesIn(input2DNHWC), - ::testing::ValuesIn(modelsWithPool)), - Decompose2DConvTest::getTestCaseName); - -/* ============= Strides & Dilations Combination ============= */ - -const std::vector> configsStrides = { - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}}; - -const std::vector padTypesStrides = { - op::PadType::VALID, -}; - -const std::vector modelsStrides = { - modelType::TranspConvTransp, -}; - -const std::vector> input2DNHWCStrides = {{1, 8, 8, 32}}; -const std::vector> kernels2DStrides = {{1, 2}, {2, 1}, {2, 2}}; -const std::vector> strides2DStrides = {{1, 1}, {2, 1}, {1, 2}, {2, 2}}; -const std::vector> dilations2DStrides = {{1, 1}, {1, 2}, {2, 1}, {2, 2}}; - -const auto conv2DParamsStrides = ::testing::Combine(::testing::ValuesIn(kernels2DStrides), - ::testing::ValuesIn(strides2DStrides), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2DStrides), - ::testing::ValuesIn(numOutChannels2D), - ::testing::ValuesIn(padTypesStrides)); - -INSTANTIATE_TEST_SUITE_P(smoke_Decompose2DConvStridesDilations, - Decompose2DConvTest, - ::testing::Combine(conv2DParamsStrides, - miscParams, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configsStrides), - ::testing::ValuesIn(input2DNHWCStrides), - ::testing::ValuesIn(modelsStrides)), - Decompose2DConvTest::getTestCaseName); - -/* ============= GNA 3.0 Supported Convolutions Combination ============= */ - -const std::vector> configsGNA3X = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}}; - -const std::vector padTypesGNA3X = { - op::PadType::VALID, -}; - -const std::vector modelsGNA3X = { - modelType::TranspConvBcastAddMaxPoolTransp, -}; - -const std::vector> input2DNHWCGNA3X = {{1, 16, 16, 32}}; -const std::vector> kernels2DGNA3X = {{1, 2}, {1, 4}}; -const std::vector> strides2DGNA3X = {{1, 1}}; -const std::vector> dilations2DGNA3X = {{1, 1}, {1, 2}}; -const std::vector numOutChannels2DGNA3X = {8}; -const std::vector> biases2DGNA3X = {{1, 8, 1, 1}}; -const std::vector> transpBiases2DGNA3X = {{1, 1, 1, 8}}; -const std::vector> maxpool2DPoolsGNA3X = {{1, 1}, {1, 2}}; -const std::vector> maxpoo2DStridesGNA3X = {{1, 1}}; - -const auto conv2DParamsGNA3X = ::testing::Combine(::testing::ValuesIn(kernels2DGNA3X), - ::testing::ValuesIn(strides2DGNA3X), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2DGNA3X), - ::testing::ValuesIn(numOutChannels2DGNA3X), - ::testing::ValuesIn(padTypesGNA3X)); - -const auto miscParamsGNA3X = ::testing::Combine(::testing::ValuesIn(biases2DGNA3X), - ::testing::ValuesIn(transpBiases2DGNA3X), - ::testing::ValuesIn(maxpool2DPoolsGNA3X), - ::testing::ValuesIn(maxpoo2DStridesGNA3X)); - -INSTANTIATE_TEST_SUITE_P(smoke_Decompose2DConvGNA3X, - Decompose2DConvTest, - ::testing::Combine(conv2DParamsGNA3X, - miscParamsGNA3X, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configsGNA3X), - ::testing::ValuesIn(input2DNHWCGNA3X), - ::testing::ValuesIn(modelsGNA3X)), - Decompose2DConvTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/decompose_mvn.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/decompose_mvn.cpp deleted file mode 100644 index 7ad1d05ea4c..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/decompose_mvn.cpp +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/test_common.hpp" -#include "ngraph/opsets/opset2.hpp" -#include "ngraph/opsets/opset8.hpp" -#include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ngraph; -using namespace opset8; - -namespace LayerTestsDefinitions { - -typedef std::tuple - mvnSpecificParams; - -typedef std::tuple, // Configuration - InferenceEngine::SizeVector // Input shapes - > - decomposeMVNParams; - -class DecomposeMVNTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - mvnSpecificParams mvnParams; - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - InferenceEngine::SizeVector inputShape; - std::tie(mvnParams, netPrecision, targetDevice, configuration, inputShape) = obj.param; - float eps; - op::MVNEpsMode epsMode; - bool normalizeVariance, acrossChannels, mvnVersion6; - std::tie(normalizeVariance, eps, epsMode, acrossChannels, mvnVersion6) = mvnParams; - - std::ostringstream result; - result << "IS=" << ov::test::utils::vec2str(inputShape) << "_"; - result << "NV=" << normalizeVariance << "_"; - result << "eps=" << eps << "_"; - result << "mode=" << static_cast(epsMode) << "_"; - result << "AC=" << acrossChannels << "_"; - result << "version=" << mvnVersion6 << "_"; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - return result.str(); - } - -protected: - void SetUp() override { - threshold = 0.2f; - mvnSpecificParams mvnParams; - InferenceEngine::Precision netPrecision; - InferenceEngine::SizeVector inputShape; - std::tie(mvnParams, netPrecision, targetDevice, configuration, inputShape) = this->GetParam(); - float eps; - op::MVNEpsMode epsMode; - bool normalizeVariance, acrossChannels, mvnVersion6; - std::tie(normalizeVariance, eps, epsMode, acrossChannels, mvnVersion6) = mvnParams; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector input{std::make_shared(ngPrc, ov::Shape(inputShape))}; - InferenceEngine::SizeVector axes(inputShape.size() - 2); - std::iota(axes.begin(), axes.end(), 2); - std::shared_ptr mvn; - - if (mvnVersion6) { - const auto axesConst = std::make_shared(element::i64, Shape{axes.size()}, axes); - mvn = std::make_shared(input[0], axesConst, normalizeVariance, eps, epsMode); - } else { - mvn = std::make_shared(input[0], acrossChannels, normalizeVariance); - } - - auto result = std::make_shared(mvn); - function = std::make_shared(ResultVector{result}, ParameterVector{input}); - } -}; - -TEST_P(DecomposeMVNTest, CompareWithRefs) { - Run(); -} - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}, {"GNA_SCALE_FACTOR_0", "1"}}}; - -const std::vector> inputs = {{1, 1, 5, 300}, {1, 6, 256}}; -const std::vector normalizeVariance = {true}; -const std::vector eps = {1.0e-09f}; -const std::vector epsMode = {op::MVNEpsMode::INSIDE_SQRT}; -const std::vector accrossChannels = {false}; - -const auto mvnParams_v6 = ::testing::Combine(::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(eps), - ::testing::ValuesIn(epsMode), - ::testing::Values(false), - ::testing::Values(true)); - -const auto mvnParams_v1 = ::testing::Combine(::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(eps), - ::testing::ValuesIn(epsMode), - ::testing::ValuesIn(accrossChannels), - ::testing::Values(false)); - -INSTANTIATE_TEST_SUITE_P(smoke_DecomposeMVN_v6, - DecomposeMVNTest, - ::testing::Combine(mvnParams_v6, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputs)), - DecomposeMVNTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_DecomposeMVN_v1, - DecomposeMVNTest, - ::testing::Combine(mvnParams_v1, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputs)), - DecomposeMVNTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/diagonal_insertion_test.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/diagonal_insertion_test.cpp deleted file mode 100644 index cc2b903ceb2..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/diagonal_insertion_test.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -namespace DiagonalInsertionTestNs { - -using namespace ngraph; -using namespace ngraph::builder; -using namespace ngraph::element; -using namespace ngraph::op; -using namespace std; - -using DiagonalInsertionTestParams = tuple, // Configuration - vector> // FakeQuantize min/max params - >; - -constexpr uint16_t fq_levels = numeric_limits::max(); - -// This class performs tests on the following network: -// Params -// Const | -// | FakeQuantize -// FakeQuantize | -// | Reshape -// \ / -// MatMul -// | -// Const Reshape -// | / -// FakeQuantize / -// \ / -// Add -// | -// FakeQuantize -// | -// ReLU -// | -// Result -// The above network should cause the FuseFullyConnectedWithEltwisePass to be fired -// The final network should have only one functional layer - FullyConnected - -class DiagonalInsertionTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { - const int32_t seed = 7235346; - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - return FuncTestUtils::createAndFillBlobFloatNormalDistribution(info.getTensorDesc(), 0.0f, 0.2f, seed); - } - - ParameterVector CreateInputVector(const Type& type, const vector& shapes) { - return ov::ParameterVector{std::make_shared(type, ov::Shape(shapes))}; - } - - shared_ptr CreateFQNode(const Type& type, - const shared_ptr& node, - float fq_min, - float fq_max, - std::size_t levels) { - // - auto fq_inp_min = makeConstant(type, {1}, {fq_min}); - auto fq_inp_max = makeConstant(type, {1}, {fq_max}); - auto fq_out_min = makeConstant(type, {1}, {fq_min}); - auto fq_out_max = makeConstant(type, {1}, {fq_max}); - return make_shared(node, fq_inp_min, fq_inp_max, fq_out_min, fq_out_max, levels); - } - - std::shared_ptr CreateReshapeNode(element::Type in_type, - shared_ptr input_node, - std::vector target_shape_vect) { - // - const auto target_shape_const = - ov::op::v0::Constant::create(in_type, Shape{target_shape_vect.size()}, target_shape_vect); - return std::make_shared(input_node, target_shape_const, false); - } - - bool IsDebugEnabled(map& configuration) { - return configuration.find("LOG_LEVEL") != configuration.end() && configuration["LOG_LEVEL"] == "LOG_DEBUG"; - } - -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - map configuration; - vector> fq_min_max; - - tie(configuration, fq_min_max) = obj.param; - - ostringstream result; - for (auto const& config_item : configuration) { - result << "_configItem=" << config_item.first << ":" << config_item.second; - } - for (auto const& fq : fq_min_max) { - result << "_fqMin=" << fq[0] << "_fqMax=" << fq[1]; - } - - return result.str(); - } - -protected: - void SetUp() override { - // Loosen threshold because of precision decrease during test - threshold = 0.1; - targetDevice = ov::test::utils::DEVICE_GNA; - - const size_t height = 512; - const size_t width = 1024; - const auto precision = ::ngraph::element::Type_t::f32; - const vector input_shape = {width}; - - // Receive test params - vector> fq_min_max; - tie(configuration, fq_min_max) = this->GetParam(); - - // Create network - - ov::ParameterVector input_vect{std::make_shared(precision, ov::Shape(input_shape))}; - auto input_fq = CreateFQNode(precision, input_vect[0], fq_min_max[0][0], fq_min_max[0][1], fq_levels); - - auto reshape = CreateReshapeNode(ngraph::element::Type_t::i32, input_fq, {width, 1}); - - auto mm_const = makeConstant(precision, {height, width}, {}, true); - auto mm_const_fq = CreateFQNode(precision, mm_const, fq_min_max[1][0], fq_min_max[1][1], fq_levels); - - auto matmul = std::make_shared(mm_const_fq, reshape); - auto matmul_fq = CreateFQNode(precision, matmul, fq_min_max[2][0], fq_min_max[2][1], fq_levels); - auto add_mm_reshape = CreateReshapeNode(ngraph::element::Type_t::i32, matmul, {height}); - - auto add_const = makeConstant(precision, {height}, {}, true); - auto add_const_fq = CreateFQNode(precision, add_const, fq_min_max[3][0], fq_min_max[3][1], fq_levels); - - auto add = make_shared(add_const_fq, add_mm_reshape); - auto add_fq = CreateFQNode(precision, add, fq_min_max[4][0], fq_min_max[4][1], fq_levels); - - auto relu = make_shared(add_fq); - - function = make_shared(relu, input_vect, "DiagonalInsertion"); - } -}; - -TEST_P(DiagonalInsertionTest, CompareWithRefs) { - Run(); -}; - -const vector> configs = { - { - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_PRECISION", "I16"}, - {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}, - }, -}; - -vector> fq_mm1 = {{-19.38653564453125, 19.38653564453125}, - {-4.872922897338867, 4.872922897338867}, - {-633.115478515625, 633.115478515625}, - {-3.2157254219055176, 3.2157254219055176}, - {-633.0288696289062, 633.0288696289062}}; - -vector> fq_mm2 = {{-1.38653564453125, 1.38653564453125}, - {-0.872922897338867, 0.872922897338867}, - {-63.115478515625, 63.115478515625}, - {-0.2157254219055176, 0.2157254219055176}, - {-63.0288696289062, 63.0288696289062}}; - -vector> fq_mm3 = {{-0.1938653564453125, 0.1938653564453125}, - {-0.04872922897338867, 0.04872922897338867}, - {-6.33115478515625, 6.33115478515625}, - {-0.032157254219055176, 0.032157254219055176}, - {-6.330288696289062, 6.330288696289062}}; - -vector> fq_mm4 = {{-4.38653564453125, 4.38653564453125}, - {-48.72922897338867, 48.72922897338867}, - {-3.115478515625, 3.115478515625}, - {-32.157254219055176, 32.157254219055176}, - {-30.0288696289062, 30.0288696289062}}; - -vector> fq_mm5 = {{-390.38653564453125, 390.38653564453125}, - {-400.872922897338867, 400.872922897338867}, - {-633.115478515625, 633.115478515625}, - {-399.2157254219055176, 399.2157254219055176}, - {-633.0288696289062, 633.0288696289062}}; - -vector>> fq_min_max = {fq_mm1, fq_mm2, fq_mm3, fq_mm4, fq_mm5}; - -INSTANTIATE_TEST_SUITE_P(smoke_DiagonalInsertion, - DiagonalInsertionTest, - ::testing::Combine(::testing::ValuesIn(configs), ::testing::ValuesIn(fq_min_max)), - DiagonalInsertionTest::getTestCaseName); - -} // namespace DiagonalInsertionTestNs diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/eltwise_split_over_channels_pass.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/eltwise_split_over_channels_pass.cpp deleted file mode 100644 index 8e95ef885f0..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/eltwise_split_over_channels_pass.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/node_builders/eltwise.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector // Input Shape - > - EltwiseSplitOverChannelsPassParams; - -namespace LayerTestsDefinitions { - -class EltwiseSplitOverChannelsPassTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(inputShape); - return result.str(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto const_mult2 = ngraph::builder::makeConstant(ngPrc, inputShape, {-1.0f}); - - auto mul = ov::test::utils::make_eltwise(params[0], const_mult2, ngraph::helpers::EltwiseTypes::MULTIPLY); - function = std::make_shared(mul, params, "EltwiseSplitOverChannelsPassTest"); - } -}; - -TEST_P(EltwiseSplitOverChannelsPassTest, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_COMPACT_MODE", "NO"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_COMPACT_MODE", "YES"}}, - { - {"GNA_DEVICE_MODE", "GNA_SW_FP32"}, - }}; - -const std::vector> inputShape = {{1, 67000}, {1, 500000}, {1, 936, 513}, {1, 64, 64, 64}}; - -INSTANTIATE_TEST_SUITE_P(smoke_EltwiseSplitOverChennels, - EltwiseSplitOverChannelsPassTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShape)), - EltwiseSplitOverChannelsPassTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/fq_activation.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/fq_activation.cpp deleted file mode 100644 index 5527be1a36d..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/fq_activation.cpp +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector, // Input Shape - std::pair, // Input Min and Max - std::pair // Levels for input and output FQs - > - fqActivationParams; - -namespace LayerTestsDefinitions { - -class FQActivation : public testing::WithParamInterface, public LayerTestsUtils::LayerTestsCommon { - float inputDataMin = 0.0f; - float inputDataMax = 0.0f; - float inputDataResolution = 1.0f; - -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::pair inputMinMax; - std::pair levels; - std::tie(netPrecision, targetDevice, configuration, inputShape, inputMinMax, levels) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(inputShape); - result << "_inputMinMax=(" << inputMinMax.first << ".." << inputMinMax.second << ")"; - result << "_levels=" << levels.first << "," << levels.second; - - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), - inputDataMax - inputDataMin, - inputDataMin, - 1 / inputDataResolution); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - - std::vector inputShape; - std::pair inputMinMax; - std::pair levels; - std::tie(netPrecision, targetDevice, configuration, inputShape, inputMinMax, levels) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - std::tie(inputDataMin, inputDataMax) = inputMinMax; - auto inputLowNode = ngraph::builder::makeConstant(ngPrc, {1}, {inputMinMax.first}); - auto inputHighNode = ngraph::builder::makeConstant(ngPrc, {1}, {inputMinMax.second}); - - ov::ParameterVector inputVector{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto inputFQNode = std::make_shared(inputVector[0], - inputLowNode, - inputHighNode, - inputLowNode, - inputHighNode, - levels.first); - - auto relu = - ngraph::builder::makeActivation(inputFQNode, ngraph::element::f32, ngraph::helpers::ActivationTypes::Relu); - auto reluFQNode = std::make_shared(relu, - inputLowNode, - inputHighNode, - inputLowNode, - inputHighNode, - levels.second); - - ngraph::ResultVector results{std::make_shared(reluFQNode)}; - function = std::make_shared(results, inputVector, "FQActivation"); - } -}; - -TEST_P(FQActivation, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{ - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, -}}; - -const std::vector> inputShape = { - {1, 1024}, -}; - -const std::vector> inputMinMax = { - {-0.5, 0.5}, - {-2, 2}, - {-8, 8}, - {-16, 16}, - {-50, 50}, - {-100, 100}, -}; - -const std::vector> levels = { - {std::numeric_limits::max(), std::numeric_limits::max()}, - {std::numeric_limits::max(), std::numeric_limits::max()}}; - -INSTANTIATE_TEST_SUITE_P(smoke_fq_activation, - FQActivation, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShape), - ::testing::ValuesIn(inputMinMax), - ::testing::ValuesIn(levels)), - FQActivation::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/fq_fusion_with_multiple_weights.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/fq_fusion_with_multiple_weights.cpp deleted file mode 100644 index 63be0f64a73..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/fq_fusion_with_multiple_weights.cpp +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset7.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector, // Input Shape - std::pair, // Min, max values of weights - size_t // Levels - > - fqFusionWithMultipleWeightsParams; - -namespace LayerTestsDefinitions { - -class FQFusionWithMultipleWeights : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::pair weightsMinMax; - size_t levels; - std::tie(netPrecision, targetDevice, configuration, inputShape, weightsMinMax, levels) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(inputShape); - result << "_weightstMinMax=(" << weightsMinMax.first << ".." << weightsMinMax.second << ")"; - result << "_levels=" << levels; - - return result.str(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - - std::vector inputShape; - std::pair weightsMinMax; - size_t levels; - std::tie(netPrecision, targetDevice, configuration, inputShape, weightsMinMax, levels) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape)), - std::make_shared(ngPrc, ov::Shape(inputShape))}; - - const size_t outChannels = 8; - const size_t kernelSize = 8; - auto weights = ngraph::builder::makeConstant( - ngPrc, - {outChannels, inputShape[1], 1, kernelSize}, - ov::test::utils::generate_float_numbers(outChannels * inputShape[1] * kernelSize, - weightsMinMax.first, - weightsMinMax.second)); - auto weightsLowNode = ngraph::builder::makeConstant(ngPrc, {1}, {weightsMinMax.first * 2}); - auto weightsHighNode = ngraph::builder::makeConstant(ngPrc, {1}, {weightsMinMax.second * 2}); - auto weightsFQ = std::make_shared(weights, - weightsLowNode, - weightsHighNode, - weightsLowNode, - weightsHighNode, - levels); - - auto conv1 = std::make_shared(params[0], - weightsFQ, - std::vector{1, 1}, - std::vector{0, 0}, - std::vector{0, 0}, - std::vector{1, 1}, - ngraph::op::PadType::VALID); - auto add1 = std::make_shared( - conv1, - ngraph::builder::makeConstant(ngPrc, {}, std::vector{0.0f})); - auto conv2 = std::make_shared(params[1], - weightsFQ, - std::vector{1, 1}, - std::vector{0, 0}, - std::vector{0, 0}, - std::vector{1, 1}, - ngraph::op::PadType::VALID); - auto add2 = std::make_shared( - conv2, - ngraph::builder::makeConstant(ngPrc, {}, std::vector{0.0f})); - - auto outLowNode = - ngraph::builder::makeConstant(ngPrc, {1}, {-weightsMinMax.second * kernelSize * 10.0f}); - auto outHighNode = - ngraph::builder::makeConstant(ngPrc, {1}, {weightsMinMax.second * kernelSize * 10.0f}); - auto fq1 = - std::make_shared(add1, outLowNode, outHighNode, outLowNode, outHighNode, levels); - auto fq2 = - std::make_shared(add2, outLowNode, outHighNode, outLowNode, outHighNode, levels); - - auto add3 = std::make_shared(fq1, fq2); - - ngraph::ResultVector results{std::make_shared(add3)}; - function = std::make_shared(results, params, "FQFusionWithMultipleWeights"); - } -}; - -TEST_P(FQFusionWithMultipleWeights, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{ - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, -}}; - -const std::vector> inputShape = {{1, 8, 1, 128}}; - -const std::vector> weightsMinMax = {{-0.2, 0.2}}; - -const std::vector levels = { - 65535, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_fq_fusion, - FQFusionWithMultipleWeights, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShape), - ::testing::ValuesIn(weightsMinMax), - ::testing::ValuesIn(levels)), - FQFusionWithMultipleWeights::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/fq_fusion_with_sigmoid.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/fq_fusion_with_sigmoid.cpp deleted file mode 100644 index bce4e9af164..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/fq_fusion_with_sigmoid.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common_test_utils/node_builders/eltwise.hpp" -#include "common_test_utils/test_constants.hpp" -#include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -namespace LayerTestsDefinitions { - -typedef std::tuple, // min, max - size_t, // Input size - std::map // Configuration - > - fqFusionWithSigmoidParams; - -class FqFusionWithSigmoidTest : public LayerTestsUtils::LayerTestsCommon, - public testing::WithParamInterface { -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::map config; - size_t levelFq; - std::pair minMaxFq; - size_t inputSize; - std::tie(targetDevice, netPrecision, levelFq, minMaxFq, inputSize, config) = this->GetParam(); - configuration.insert(config.begin(), config.end()); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector input{std::make_shared(ngPrc, ov::Shape{1, inputSize})}; - auto constant = ngraph::builder::makeConstant(ngPrc, {1, inputSize}, std::vector{1}); - auto mul1 = ov::test::utils::make_eltwise(input[0], constant, ngraph::helpers::EltwiseTypes::ADD); - auto sigmoid1 = std::make_shared(mul1); - auto mul2 = ov::test::utils::make_eltwise(input[0], sigmoid1, ngraph::helpers::EltwiseTypes::MULTIPLY); - auto fake3 = ngraph::builder::makeFakeQuantize(sigmoid1, - ngPrc, - levelFq, - {1}, - {minMaxFq.first}, - {minMaxFq.second}, - {minMaxFq.first}, - {minMaxFq.second}); - auto mul3 = ov::test::utils::make_eltwise(mul2, fake3, ngraph::helpers::EltwiseTypes::ADD); - auto result = std::make_shared(mul3); - function = std::make_shared(ngraph::ResultVector{result}, input, "fq_fusion_with_sigmoid"); - } - -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - std::string targetDevice; - InferenceEngine::Precision netPrecision; - size_t levelFq; - std::pair minMaxFq; - size_t inputSize; - std::map config; - std::tie(targetDevice, netPrecision, levelFq, minMaxFq, inputSize, config) = obj.param; - std::ostringstream result; - result << "netPrecision=" << netPrecision.name() << "_"; - result << "IS=" << inputSize << "_"; - result << "targetDevice=" << targetDevice << "_"; - result << "levelFq=" << levelFq << "_"; - result << "(minFq,maxFq)=" << std::to_string(minMaxFq.first) << "_" << std::to_string(minMaxFq.first) << "_"; - result << "inputSize=" << std::to_string(inputSize); - return result.str(); - } -}; // class FqFusionWithSigmoidTest - -TEST_P(FqFusionWithSigmoidTest, CompareWithRefs) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -std::vector levelFq = {65535}; - -std::vector> minMaxFq = {{-1, 1}, {-5, 5}}; - -std::vector input = { - 64, -}; - -std::map additional_config = { - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_fq_fusion_with_sigmoid, - FqFusionWithSigmoidTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(levelFq), - ::testing::ValuesIn(minMaxFq), - ::testing::ValuesIn(input), - ::testing::Values(additional_config)), - FqFusionWithSigmoidTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/fq_maxpool_reordering.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/fq_maxpool_reordering.cpp deleted file mode 100644 index 1af3289e173..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/fq_maxpool_reordering.cpp +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector, // Input Shape - std::pair, // Input Min and Max (before conv) - std::pair, // Input Min and Max (after conv) - size_t, // Levels - bool // Reshape between FQ and Pooling - > - fqMaxpoolReorderingParams; - -namespace LayerTestsDefinitions { - -class FQMaxpoolReordering : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { - float inputDataMin1 = 0.0f; - float inputDataMax1 = 0.0f; - float inputDataMin2 = 0.0f; - float inputDataMax2 = 0.0f; - float inputDataResolution = 1.0f; - -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::pair inputMinMax1; - std::pair inputMinMax2; - size_t levels = 0; - bool reshape = false; - std::tie(netPrecision, targetDevice, configuration, inputShape, inputMinMax1, inputMinMax2, levels, reshape) = - obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(inputShape); - result << "_inputMinMax1=(" << inputMinMax1.first << ".." << inputMinMax1.second << ")"; - result << "_inputMinMax2=(" << inputMinMax2.first << ".." << inputMinMax2.second << ")"; - result << "_levels=" << levels; - result << "_reshape=" << reshape; - - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), - inputDataMax1 - inputDataMin1, - inputDataMin1, - 1 / inputDataResolution); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - - std::vector inputShape; - std::pair inputMinMax1; - std::pair inputMinMax2; - size_t levels = 0; - bool reshape = false; - std::tie(netPrecision, targetDevice, configuration, inputShape, inputMinMax1, inputMinMax2, levels, reshape) = - this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - std::tie(inputDataMin1, inputDataMax1) = inputMinMax1; - std::tie(inputDataMin2, inputDataMax2) = inputMinMax2; - auto inputLowNode1 = ngraph::builder::makeConstant(ngPrc, {1}, {inputDataMin1}); - auto inputHighNode1 = ngraph::builder::makeConstant(ngPrc, {1}, {inputDataMax1}); - auto inputLowNode2 = ngraph::builder::makeConstant(ngPrc, {1}, {inputDataMin2}); - auto inputHighNode2 = ngraph::builder::makeConstant(ngPrc, {1}, {inputDataMax2}); - - ov::ParameterVector inputVector{std::make_shared(ngPrc, ov::Shape(inputShape))}; - - auto inputFQ = std::make_shared(inputVector[0], - inputLowNode1, - inputHighNode1, - inputLowNode1, - inputHighNode1, - levels); - - auto filterWeightsNode = ngraph::builder::makeConstant(ngPrc, {8, inputShape[1], 1, 8}, {1.0f}); - auto convLowNode = ngraph::builder::makeConstant(ngraph::element::f32, - std::vector{1}, - std::vector{inputDataMin1 * 35}); - auto convHighNode = ngraph::builder::makeConstant(ngraph::element::f32, - std::vector{1}, - std::vector{inputDataMax1 * 35}); - auto convWeightsFQNode = std::make_shared(filterWeightsNode, - convLowNode, - convHighNode, - convLowNode, - convHighNode, - levels); - auto convWeightsFQ = std::dynamic_pointer_cast(convWeightsFQNode); - - auto conv = std::make_shared(inputFQ, - convWeightsFQ, - std::vector{1, 1}, - std::vector{0, 0}, - std::vector{0, 0}, - std::vector{1, 1}, - ngraph::op::PadType::VALID); - auto biasesWeightsNode = ngraph::builder::makeConstant(ngPrc, {}, std::vector{0.0f}); - auto add = std::make_shared(conv, biasesWeightsNode); - - auto convFQNode = std::make_shared(add, - inputLowNode2, - inputHighNode2, - inputLowNode2, - inputHighNode2, - levels); - - std::shared_ptr node_before_pooling = convFQNode; - if (reshape) { - const auto& shape = conv->get_output_shape(0); - size_t total = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies()); - auto reshapeConst1 = - ngraph::builder::makeConstant(ngraph::element::i64, std::vector{2}, ngraph::Shape{1, total}); - auto reshapeNode1 = std::make_shared(convFQNode, reshapeConst1, false); - auto reshapeConst2 = ngraph::builder::makeConstant(ngraph::element::i64, std::vector{4}, shape); - auto reshapeNode2 = std::make_shared(reshapeNode1, reshapeConst2, false); - node_before_pooling = reshapeNode2; - } - - OPENVINO_SUPPRESS_DEPRECATED_START - auto maxpool = ngraph::builder::makePooling(node_before_pooling, - {1, 2}, - {0, 0}, - {0, 0}, - {1, 2}, - ngraph::op::RoundingType::FLOOR, - ngraph::op::PadType::VALID, - false, - ngraph::helpers::PoolingTypes::MAX); - OPENVINO_SUPPRESS_DEPRECATED_END - - ngraph::ResultVector results{std::make_shared(maxpool)}; - function = std::make_shared(results, inputVector, "FQMaxPoolReorder"); - } -}; - -TEST_P(FQMaxpoolReordering, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{ - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, -}}; - -const std::vector> inputShape = {{1, 1, 1, 1024}, {1, 8, 1, 168}}; - -const std::vector> inputMinMax = {{-0.5, 0.5}, {-2, 2}, {-8, 8}, {-5, 5}, {-17.5, 17.5}}; - -const std::vector levels = {65535}; - -INSTANTIATE_TEST_SUITE_P(smoke_fq_maxpool_reordering, - FQMaxpoolReordering, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShape), - ::testing::ValuesIn(inputMinMax), - ::testing::ValuesIn(inputMinMax), - ::testing::ValuesIn(levels), - ::testing::ValuesIn(std::vector{true, false})), - FQMaxpoolReordering::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/fq_outputs_activation_.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/fq_outputs_activation_.cpp deleted file mode 100644 index ea646f5e3de..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/fq_outputs_activation_.cpp +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector, // Input Shape - std::pair, // Input Min and Max - size_t, // Levels - size_t // Outputs - > - fqOutputsActivationParams; - -namespace LayerTestsDefinitions { - -class FQOutputsActivation : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { - float inputDataMin = 0.0f; - float inputDataMax = 0.0f; - float inputDataResolution = 1.0f; - -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::pair inputMinMax; - size_t levels = 0; - size_t outputCount = 1; - std::tie(netPrecision, targetDevice, configuration, inputShape, inputMinMax, levels, outputCount) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(inputShape); - result << "_inputMinMax=(" << inputMinMax.first << ".." << inputMinMax.second << ")"; - result << "_levels=" << levels; - result << "_outputs=" << outputCount; - - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), - inputDataMax - inputDataMin, - inputDataMin, - 1 / inputDataResolution); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::pair inputMinMax; - size_t levels = 0; - size_t outputCount = 1; - std::tie(netPrecision, targetDevice, configuration, inputShape, inputMinMax, levels, outputCount) = - this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - auto inputLowNode = ngraph::builder::makeConstant(ngPrc, {1}, {inputMinMax.first}); - auto inputHighNode = ngraph::builder::makeConstant(ngPrc, {1}, {inputMinMax.second}); - ov::ParameterVector inputVector{std::make_shared(ngPrc, ov::Shape(inputShape))}; - OPENVINO_SUPPRESS_DEPRECATED_START - auto split = ngraph::builder::makeSplit(inputVector[0], ngPrc, outputCount, 1); - OPENVINO_SUPPRESS_DEPRECATED_END - - ngraph::ResultVector results; - for (size_t i = 0; i < outputCount; ++i) { - auto relu = ngraph::builder::makeActivation(split->output(i), - ngraph::element::f32, - ngraph::helpers::ActivationTypes::Sigmoid); - auto reluFQNode = std::make_shared(relu, - inputLowNode, - inputHighNode, - inputLowNode, - inputHighNode, - levels); - results.push_back(std::make_shared(reluFQNode)); - } - function = std::make_shared(results, inputVector, "FQOutputsActivation"); - } -}; - -TEST_P(FQOutputsActivation, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{ - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, -}}; - -const std::vector> inputShape = { - {1, 2048}, -}; - -const std::vector> inputMinMax = { - {-0.5, 0.5}, - {-16, 16}, - {-100, 100}, -}; - -const std::vector levels = { - 65535, -}; - -const std::vector outputCount = {1, 2, 4}; - -INSTANTIATE_TEST_SUITE_P(smoke_fq_activation, - FQOutputsActivation, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShape), - ::testing::ValuesIn(inputMinMax), - ::testing::ValuesIn(levels), - ::testing::ValuesIn(outputCount)), - FQOutputsActivation::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/fq_with_multiple_out_connections.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/fq_with_multiple_out_connections.cpp deleted file mode 100644 index 752b78acffd..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/fq_with_multiple_out_connections.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset8.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple // Configuration - > - fqWithMultipleOutConnectionsParams; - -namespace LayerTestsDefinitions { - -class FQWithMultipleOutConnections : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::tie(netPrecision, targetDevice, configuration) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - - return result.str(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - - std::tie(netPrecision, targetDevice, configuration) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - const ngraph::Shape shape = {1, 128}; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(shape))}; - - auto pattern1 = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{3}, - ngraph::Shape{1, 2, 64}); - auto reshape1 = std::make_shared(params[0], pattern1, false); - - auto relu1 = std::make_shared(reshape1); - - auto lowNode = ngraph::builder::makeConstant(ngPrc, {1}, {-10.0f}); - auto highNode = ngraph::builder::makeConstant(ngPrc, {1}, {10.0f}); - auto fq = std::make_shared(relu1, - lowNode, - highNode, - lowNode, - highNode, - std::numeric_limits::max()); - - auto pattern2 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{shape.size()}, shape); - auto reshape2 = std::make_shared(fq, pattern2, false); - - auto relu2 = std::make_shared(fq); - auto reshape3 = std::make_shared(relu2, pattern2, false); - - ngraph::ResultVector results{std::make_shared(reshape2), - std::make_shared(reshape3)}; - function = std::make_shared(results, params, "FQFusionWithMultipleWeights"); - } -}; - -TEST_P(FQWithMultipleOutConnections, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{ - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - }, - { - {"GNA_DEVICE_MODE", "GNA_SW_FP32"}, - }}; - -INSTANTIATE_TEST_SUITE_P(smoke_fq_fusion, - FQWithMultipleOutConnections, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - FQWithMultipleOutConnections::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/insert_copy_layer_before_self_concat.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/insert_copy_layer_before_self_concat.cpp deleted file mode 100644 index b7162a36c35..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/insert_copy_layer_before_self_concat.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -using concatParamsTuple = typename std::tuple< - // TODO: according to specification axis have to be int, negative values are allowed - size_t, // Concat axis - std::vector, // Input shapes - size_t, // Concat inputs number - size_t, // Concats nymber - InferenceEngine::Precision, // Network precision - InferenceEngine::Precision, // Input precision - InferenceEngine::Precision, // Output precision - InferenceEngine::Layout, // Input layout - InferenceEngine::Layout, // Output layout - std::string>; // Device name - -namespace LayerTestsDefinitions { - -class InsertCopyBeforeSelfConcatTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - int axis; - std::vector inputShape; - size_t inputsNum, concatsNum; - InferenceEngine::Precision netPrecision; - InferenceEngine::Precision inPrc, outPrc; - InferenceEngine::Layout inLayout, outLayout; - std::string targetName; - std::tie(axis, - inputShape, - inputsNum, - concatsNum, - netPrecision, - inPrc, - outPrc, - inLayout, - outLayout, - targetName) = obj.param; - std::ostringstream result; - result << "IS=" << ov::test::utils::vec2str(inputShape) << "_"; - result << "IN=" << inputsNum << "_"; - result << "CN=" << concatsNum << "_"; - result << "axis=" << axis << "_"; - result << "netPRC=" << netPrecision.name() << "_"; - result << "inPRC=" << inPrc.name() << "_"; - result << "outPRC=" << outPrc.name() << "_"; - result << "inL=" << inLayout << "_"; - result << "outL=" << outLayout << "_"; - result << "trgDev=" << targetName; - return result.str(); - } - -protected: - void SetUp() override { - int axis; - std::vector inputShape; - size_t inputsNum, concatsNum; - InferenceEngine::Precision netPrecision; - std::tie(axis, - inputShape, - inputsNum, - concatsNum, - netPrecision, - inPrc, - outPrc, - inLayout, - outLayout, - targetDevice) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - ngraph::OutputVector concatInputs; - for (int i = 0; i < inputsNum; ++i) { - concatInputs.push_back(params[0]); - } - ngraph::ResultVector results; - for (int i = 0; i < concatsNum; ++i) { - auto concat = std::make_shared(concatInputs, axis); - auto relu = std::make_shared(concat); - results.push_back(std::make_shared(relu)); - } - function = std::make_shared(results, params, "InsertCopyBeforeSelfConcat"); - } -}; - -TEST_P(InsertCopyBeforeSelfConcatTest, CompareWithRefs) { - Run(); -}; - -std::vector axes = {1}; - -std::vector> inShapes = {{1, 32}, {1, 128}, {8, 64}, {1, 16}}; - -std::vector inputsNum = {2, 3, 5}; - -std::vector concatsNum = {1, 2, 3, 4}; - -std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -INSTANTIATE_TEST_SUITE_P(smoke_InsertCopy, - InsertCopyBeforeSelfConcatTest, - ::testing::Combine(::testing::ValuesIn(axes), - ::testing::ValuesIn(inShapes), - ::testing::ValuesIn(inputsNum), - ::testing::ValuesIn(concatsNum), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - InsertCopyBeforeSelfConcatTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/insert_transpose_before_matmul.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/insert_transpose_before_matmul.cpp deleted file mode 100644 index 482161a7288..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/insert_transpose_before_matmul.cpp +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - size_t, // Input Shape - bool // first input is const - > - insertTransposeBeforeMatmulParams; - -namespace LayerTestsDefinitions { - -class InsertTransposeBeforeMatmul : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - size_t inputShape; - bool firstInConst; - std::tie(netPrecision, targetDevice, configuration, inputShape, firstInConst) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << inputShape; - result << "_firstInConst=" << firstInConst; - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.2f, 0.2f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - size_t inputShape; - bool firstInConst; - std::tie(netPrecision, targetDevice, configuration, inputShape, firstInConst) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape{1, inputShape})}; - - auto matmul_in_shape = firstInConst ? ngraph::Shape{inputShape / 8, 8} : ngraph::Shape{8, inputShape / 8}; - auto pattern = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{2}, matmul_in_shape); - auto reshape = std::make_shared(params[0], pattern, false); - - std::shared_ptr weights_node; - if (firstInConst) { - std::vector weights = ov::test::utils::generate_float_numbers(matmul_in_shape[0], -0.2f, 0.2f); - weights_node = std::make_shared(ngPrc, ngraph::Shape{1, matmul_in_shape[0]}, weights); - } else { - std::vector weights = ov::test::utils::generate_float_numbers(matmul_in_shape[1], -0.2f, 0.2f); - weights_node = std::make_shared(ngPrc, ngraph::Shape{matmul_in_shape[1], 1}, weights); - } - - auto matmul = firstInConst ? std::make_shared(weights_node, reshape, false, false) - : std::make_shared(reshape, weights_node, false, false); - - ngraph::ResultVector results{std::make_shared(matmul)}; - function = std::make_shared(results, params, "InsertTransposeBeforeMatmul"); - } -}; - -TEST_P(InsertTransposeBeforeMatmul, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -const std::vector inputShape = {64, 128, 192}; - -const std::vector firstInputConst = {false, true}; - -INSTANTIATE_TEST_SUITE_P(smoke_InsertTransposeBeforeMatmulTest, - InsertTransposeBeforeMatmul, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShape), - ::testing::ValuesIn(firstInputConst)), - InsertTransposeBeforeMatmul::getTestCaseName); - -/* Case with two inputs with concat instead of reshape */ - -class InsertTransposeBeforeConcatConcat : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - size_t inputShape; - bool firstInConst; - std::tie(netPrecision, targetDevice, configuration, inputShape, firstInConst) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << inputShape; - result << "_firstInConst=" << firstInConst; - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.2f, 0.2f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - size_t inputShape; - bool firstInConst; - std::tie(netPrecision, targetDevice, configuration, inputShape, firstInConst) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape{1, inputShape})}; - auto matmul_in_shape = ngraph::Shape{inputShape / 8, 8}; - auto pattern = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{2}, matmul_in_shape); - auto reshape = std::make_shared(params[0], pattern, false); - - std::vector data = - ov::test::utils::generate_float_numbers(ngraph::shape_size(matmul_in_shape), -0.2f, 0.2f); - auto concat_const = std::make_shared(ngPrc, matmul_in_shape, data); - ngraph::OutputVector concat_chunks{reshape, concat_const}; - auto concat = std::make_shared(concat_chunks, 0); - - std::shared_ptr weights_node; - std::vector weights = ov::test::utils::generate_float_numbers(matmul_in_shape[0] * 2, -0.2f, 0.2f); - weights_node = std::make_shared(ngPrc, ngraph::Shape{1, matmul_in_shape[0] * 2}, weights); - - auto matmul = firstInConst ? std::make_shared(weights_node, concat, false, false) - : std::make_shared(concat, weights_node, false, false); - - ngraph::ResultVector results{std::make_shared(matmul)}; - function = std::make_shared(results, params, "InsertTransposeBeforeConcatConcat"); - } -}; - -TEST_P(InsertTransposeBeforeConcatConcat, CompareWithRefImpl) { - Run(); -}; - -const std::vector concatInputShape = {64, 96, 128}; - -const std::vector firstInputConstConcat = {true}; - -INSTANTIATE_TEST_SUITE_P(smoke_InsertTransposeBeforeMatmulConcat, - InsertTransposeBeforeConcatConcat, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(concatInputShape), - ::testing::ValuesIn(firstInputConstConcat)), - InsertTransposeBeforeConcatConcat::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/insert_transpose_between_convs.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/insert_transpose_between_convs.cpp deleted file mode 100644 index 7f79573fb08..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/insert_transpose_between_convs.cpp +++ /dev/null @@ -1,264 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector // Input Shape - > - insertTransposeBetweenConvsParams; - -namespace LayerTestsDefinitions { - -class InsertTransposeBetweenConvs : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(inputShape); - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.2f, 0.2f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ngraph::Shape inputShape_2d = {inputShape[0], inputShape[1] * inputShape[2] * inputShape[3]}; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape_2d))}; - - auto pattern1 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{4}, inputShape); - auto reshape1 = std::make_shared(params[0], pattern1, false); - - size_t num_out_channels = 8; - size_t kernal_size = 8; - size_t stride_size = 8; - std::vector filter_weights_1 = - ov::test::utils::generate_float_numbers(num_out_channels * inputShape[1] * kernal_size, -0.2f, 0.2f); - auto conv1 = ngraph::builder::makeConvolution(reshape1, - ngPrc, - {1, kernal_size}, - {1, stride_size}, - {0, 0}, - {0, 0}, - {1, 1}, - ngraph::op::PadType::VALID, - num_out_channels, - false, - filter_weights_1); - size_t out_width = ((inputShape[3] - kernal_size) / stride_size + 1); - size_t out_height = ((inputShape[2] - 1) + 1); - - ngraph::Shape pattern2_shape = {1, 1, 1, num_out_channels * out_height * out_width}; - auto pattern2 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{4}, pattern2_shape); - auto reshape2 = std::make_shared(conv1, pattern2, false); - - std::vector filter_weights_2 = - ov::test::utils::generate_float_numbers(num_out_channels * kernal_size, -0.2f, 0.2f); - auto conv2 = ngraph::builder::makeConvolution(reshape2, - ngPrc, - {1, kernal_size}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ngraph::op::PadType::VALID, - num_out_channels, - false, - filter_weights_2); - out_width = ((pattern2_shape[3] - kernal_size) + 1); - out_height = ((pattern2_shape[2] - 1) + 1); - - ngraph::Shape pattern3_shape = {1, num_out_channels * out_height * out_width}; - auto pattern3 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{2}, pattern3_shape); - auto reshape3 = std::make_shared(conv2, pattern3, false); - - ngraph::ResultVector results{std::make_shared(reshape3)}; - function = std::make_shared(results, params, "InsertTransposeBetweenConvs"); - } -}; - -class InsertTransposeBetweenConvsWithPool : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(inputShape); - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.2f, 0.2f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ngraph::Shape inputShape_2d = {inputShape[0], inputShape[1] * inputShape[2] * inputShape[3]}; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape_2d))}; - - auto pattern1 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{4}, inputShape); - auto reshape1 = std::make_shared(params[0], pattern1, false); - - size_t num_out_channels = 8; - size_t kernal_size = 8; - size_t stride_size = 8; - std::vector filter_weights_1 = - ov::test::utils::generate_float_numbers(num_out_channels * inputShape[1] * kernal_size, -0.2f, 0.2f); - auto conv1 = ngraph::builder::makeConvolution(reshape1, - ngPrc, - {1, kernal_size}, - {1, stride_size}, - {0, 0}, - {0, 0}, - {1, 1}, - ngraph::op::PadType::VALID, - num_out_channels, - false, - filter_weights_1); - size_t out_width = ((inputShape[3] - kernal_size) / stride_size + 1); - size_t out_height = ((inputShape[2] - 1) + 1); - OPENVINO_SUPPRESS_DEPRECATED_START - auto pool = ngraph::builder::makePooling(conv1, - {1, 2}, - {0, 0}, - {0, 0}, - {1, 2}, - ngraph::op::RoundingType::FLOOR, - ngraph::op::PadType::VALID, - false, - ngraph::helpers::PoolingTypes::MAX); - OPENVINO_SUPPRESS_DEPRECATED_END - out_width /= 2; - - ngraph::Shape pattern2_shape = {1, 1, 1, num_out_channels * out_height * out_width}; - auto pattern2 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{4}, pattern2_shape); - auto reshape2 = std::make_shared(pool, pattern2, false); - - std::vector filter_weights_2 = - ov::test::utils::generate_float_numbers(num_out_channels * kernal_size, -0.2f, 0.2f); - auto conv2 = ngraph::builder::makeConvolution(reshape2, - ngPrc, - {1, kernal_size}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ngraph::op::PadType::VALID, - num_out_channels, - false, - filter_weights_2); - out_width = ((pattern2_shape[3] - kernal_size) + 1); - out_height = ((pattern2_shape[2] - 1) + 1); - - ngraph::Shape pattern3_shape = {1, num_out_channels * out_height * out_width}; - auto pattern3 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{2}, pattern3_shape); - auto reshape3 = std::make_shared(conv2, pattern3, false); - - ngraph::ResultVector results{std::make_shared(reshape3)}; - function = std::make_shared(results, params, "InsertTransposeBetweenConvs"); - } -}; - -TEST_P(InsertTransposeBetweenConvs, CompareWithRefImpl) { - Run(); -}; - -TEST_P(InsertTransposeBetweenConvsWithPool, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -const std::vector> inputShape = {{1, 1, 1, 32}, {1, 8, 1, 64}, {1, 4, 1, 128}}; - -INSTANTIATE_TEST_SUITE_P(smoke_InsertTransposeBetweenConvsTest, - InsertTransposeBetweenConvs, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShape)), - InsertTransposeBetweenConvs::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_InsertTransposeBetweenConvsWithPoolTest, - InsertTransposeBetweenConvsWithPool, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShape)), - InsertTransposeBetweenConvsWithPool::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/layers_restrictions.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/layers_restrictions.cpp deleted file mode 100644 index 47216d5bcc2..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/layers_restrictions.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -// -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -using LayersRestrictionsParamsTuple = typename std::tuple, // Configuration - std::string>; // Device name - -namespace LayerTestsDefinitions { - -struct FullyConnectedBatchSizeMoreThan8 { - static const char* getName() { - return "FullyConnectedBatchSizeMoreThan8"; - } - static std::shared_ptr createTopology(const InferenceEngine::Precision& netPrecision) { - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - std::vector inputShape = {9, 1}; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto weights = ov::test::utils::generate_float_numbers(inputShape[1] * inputShape[1], -0.0001f, 0.0001f); - auto fullyConnected = ngraph::builder::makeFullyConnected(params[0], ngPrc, inputShape[1], false, {}, weights); - ngraph::ResultVector results{std::make_shared(fullyConnected)}; - return std::make_shared(results, params, getName()); - } - static const char* getMatch() { - return "and batch size(9) not supported"; - } -}; - -struct FullyConnectedBatchSizeLessThanOrEqual8 { - static const char* getName() { - return "FullyConnectedBatchSizeLessThanOrEqual8"; - } - static std::shared_ptr createTopology(const InferenceEngine::Precision& netPrecision) { - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - std::vector inputShape = {7, 1}; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto weights = ov::test::utils::generate_float_numbers(inputShape[1] * inputShape[1], -0.0001f, 0.0001f); - auto fullyConnected = ngraph::builder::makeFullyConnected(params[0], ngPrc, inputShape[1], false, {}, weights); - ngraph::ResultVector results{std::make_shared(fullyConnected)}; - return std::make_shared(results, params, getName()); - } -}; - -template -class LayersRestrictions : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::map configuration; - std::string targetDevice; - std::tie(netPrecision, configuration, targetDevice) = obj.param; - std::ostringstream result; - result << T::getName() << "_"; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "configItem=" << configItem.first << "_" << configItem.second << "_"; - } - return result.str(); - } - static const char* getMatch() { - return T::getMatch(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::tie(netPrecision, configuration, targetDevice) = this->GetParam(); - function = T::createTopology(netPrecision); - } -}; - -using LayersRestrictionsFullyConnectedBatchSizeMoreThan8 = LayersRestrictions; -using LayersRestrictionsFullyConnectedBatchSizeLessThanOrEqual8 = - LayersRestrictions; - -TEST_P(LayersRestrictionsFullyConnectedBatchSizeMoreThan8, CompareWithRefImpl) { - std::string what; - try { - LoadNetwork(); - } catch (const std::exception& e) { - what.assign(e.what()); - } - EXPECT_TRUE(what.find(getMatch()) != std::string::npos); -} - -TEST_P(LayersRestrictionsFullyConnectedBatchSizeLessThanOrEqual8, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32}; -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_layers_restrictions, - LayersRestrictionsFullyConnectedBatchSizeMoreThan8, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - LayersRestrictionsFullyConnectedBatchSizeMoreThan8::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_layers_restrictions, - LayersRestrictionsFullyConnectedBatchSizeLessThanOrEqual8, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(configs), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - LayersRestrictionsFullyConnectedBatchSizeLessThanOrEqual8::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/pass_tests/remove_permutations_NHWC_to_NCHW_pass.cpp b/src/plugins/intel_gna/tests/functional/pass_tests/remove_permutations_NHWC_to_NCHW_pass.cpp deleted file mode 100644 index 0ada71e6069..00000000000 --- a/src/plugins/intel_gna/tests/functional/pass_tests/remove_permutations_NHWC_to_NCHW_pass.cpp +++ /dev/null @@ -1,727 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "transformations/common_optimizations/transpose_to_reshape.hpp" - -typedef std::tuple, // Configuration - std::vector // Input shape - > - removePermutationsPassParams; - -typedef std::tuple, // Configuration - std::vector, // Input shape - bool, // additional bool parameter - bool // transpose to reshape - > - removePermutationsAddParamPassParams; - -typedef std::tuple, // Configuration - std::vector, // Input shape - size_t // Splits number - > - removeSharedPermutationPassParams; - -namespace LayerTestsDefinitions { - -std::vector GetKernelShape(std::vector input_shape, size_t kernel_size, bool output_1d = false) { - if (input_shape.size() == 3) { - return output_1d ? std::vector{input_shape.back()} : std::vector{kernel_size}; - } - - if (output_1d) { - return std::vector{input_shape[1], input_shape[2]}; - } - - return (input_shape[1] == 1 ? std::vector{1, kernel_size} - : (input_shape[2] == 1 ? std::vector{kernel_size, 1} - : std::vector{kernel_size, kernel_size})); -} - -std::shared_ptr CreateTranspose(std::shared_ptr input, - size_t shape_size, - bool before_conv) { - std::vector permute_order; - if (before_conv) { - permute_order = shape_size == 4 ? std::vector{0, 3, 1, 2} : std::vector{0, 2, 1}; - } else { - permute_order = shape_size == 4 ? std::vector{0, 2, 3, 1} : std::vector{0, 2, 1}; - } - return std::make_shared( - input, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{shape_size}, permute_order)); -} - -ngraph::Shape GetLayerTransposedOutputShape(std::shared_ptr layer) { - auto out_shape = layer->get_output_shape(0); - auto perm = out_shape.size() == 4 ? std::vector{0, 2, 3, 1} : std::vector{0, 2, 1}; - std::vector nhwc_out_shape; - std::transform(std::begin(perm), std::end(perm), std::back_inserter(nhwc_out_shape), [out_shape](int i) { - return out_shape[i]; - }); - return nhwc_out_shape; -} - -std::shared_ptr CreateConvolution(const ngraph::Output& input, - const ov::element::Type& ngPrc, - const std::vector& input_shape, - bool output1D = false, - bool withPool = false, - bool withActivation = false) { - const size_t num_out_channels = 12; - auto kernel_shape = GetKernelShape(input_shape, 8, output1D); - size_t filter_total_size = - num_out_channels * input_shape.back() * - std::accumulate(std::begin(kernel_shape), std::end(kernel_shape), 1, std::multiplies()); - const std::vector filter_weights = ov::test::utils::generate_float_numbers(filter_total_size, -0.01f, 0.01f); - const auto shape_size = input_shape.size(); - auto conv = ngraph::builder::makeConvolution(input, - ngPrc, - kernel_shape, - std::vector(shape_size - 2, 1), - std::vector(shape_size - 2, 0l), - std::vector(shape_size - 2, 0l), - std::vector(shape_size - 2, 1), - ngraph::op::PadType::VALID, - num_out_channels, - false, - filter_weights); - - if (!withPool) { - return conv; - } - - auto pool_kernal_shape = GetKernelShape(GetLayerTransposedOutputShape(conv), 2, false); - OPENVINO_SUPPRESS_DEPRECATED_START - auto pool = ngraph::builder::makePooling(conv, - pool_kernal_shape, - std::vector(shape_size - 2, 0), - std::vector(shape_size - 2, 0), - pool_kernal_shape, - ngraph::op::RoundingType::FLOOR, - ngraph::op::PadType::VALID, - false, - ngraph::helpers::PoolingTypes::MAX); - OPENVINO_SUPPRESS_DEPRECATED_END - return withActivation ? std::make_shared(pool) : pool; -} - -class RemovePermutationsNHWCToNCHWPassTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - bool output1D; - bool transpose_to_reshape; - std::tie(netPrecision, targetDevice, configuration, inputShape, output1D, transpose_to_reshape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_IS=" << ov::test::utils::vec2str(inputShape); - result << "_1d_out=" << output1D; - result << "_transpose2reshape=" << transpose_to_reshape; - return result.str(); - } - -protected: - void SetUp() override { - // Reshape - // | - // Permute (order: [0, 3, 1, 2]) - // | - // Convolution - // | - // Permute (order: [0, 2, 3, 1]) - // | - // Reshape - InferenceEngine::Precision netPrecision; - std::vector inputShape; - bool output1D; - bool transpose_to_reshape; - std::tie(netPrecision, targetDevice, configuration, inputShape, output1D, transpose_to_reshape) = - this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - size_t shape_size = inputShape.size(); - ASSERT_GT(shape_size, 2); - ASSERT_LT(shape_size, 5); - size_t in_total_dims_size = - std::accumulate(std::begin(inputShape), std::end(inputShape), 1, std::multiplies()); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape{1, in_total_dims_size})}; - - auto pattern1 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{shape_size}, inputShape); - auto reshape1 = std::make_shared(params[0], pattern1, false); - - auto permute1 = CreateTranspose(reshape1, shape_size, true); - auto conv = CreateConvolution(permute1, ngPrc, inputShape, output1D); - auto permute2 = CreateTranspose(conv, shape_size, false); - - auto conv_out_size = std::accumulate(std::begin(conv->get_output_shape(0)), - std::end(conv->get_output_shape(0)), - size_t(1), - std::multiplies()); - auto pattern2 = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{2}, - ngraph::Shape{1, conv_out_size}); - auto reshape2 = std::make_shared(permute2, pattern2, false); - - ngraph::ResultVector results{std::make_shared(reshape2)}; - function = std::make_shared(results, params, "RemovePermutationsTest"); - if (transpose_to_reshape) { - ngraph::pass::Manager manager; - manager.register_pass(); - manager.run_passes(function); - } - } -}; - -class RemovePermutationsNHWCToNCHWPassNoReshapesTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_IS=" << ov::test::utils::vec2str(inputShape); - return result.str(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - size_t shape_size = inputShape.size(); - ASSERT_GT(shape_size, 2); - ASSERT_LT(shape_size, 5); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto permute1 = CreateTranspose(params[0], shape_size, true); - auto conv = CreateConvolution(permute1, ngPrc, inputShape); - auto permute2 = CreateTranspose(conv, shape_size, false); - - ngraph::ResultVector results{std::make_shared(permute2)}; - - function = std::make_shared(results, params, "RemovePermutationPassNoReshapes"); - } -}; - -class RemovePermutationsWithPoolAndActTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - bool withActivation; - bool transpose_to_reshape; - std::tie(netPrecision, targetDevice, configuration, inputShape, withActivation, transpose_to_reshape) = - obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_IS=" << ov::test::utils::vec2str(inputShape); - result << "_withActivation=" << withActivation; - result << "_transpose2reshape=" << transpose_to_reshape; - return result.str(); - } - -protected: - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.2f, 0.2f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - - void SetUp() override { - // Reshape - // | - // Permute (order: [0, 3, 1, 2]) - // | - // Convolution - // | - // Pooling - // | - // Relu - // | - // Permute (order: [0, 2, 3, 1]) - // | - // Reshape - InferenceEngine::Precision netPrecision; - std::vector inputShape; - bool withActivation; - bool transpose_to_reshape; - std::tie(netPrecision, targetDevice, configuration, inputShape, withActivation, transpose_to_reshape) = - this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - size_t shape_size = inputShape.size(); - ASSERT_GT(shape_size, 2); - ASSERT_LT(shape_size, 5); - - size_t in_total_dims_size = - std::accumulate(std::begin(inputShape), std::end(inputShape), 1, std::multiplies()); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape{1, in_total_dims_size})}; - - auto pattern1 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{shape_size}, inputShape); - auto reshape1 = std::make_shared(params[0], pattern1, false); - - auto permute1 = CreateTranspose(reshape1, shape_size, true); - auto conv = CreateConvolution(permute1, ngPrc, inputShape, false, true, true); - auto permute2 = CreateTranspose(conv, shape_size, false); - - auto conv_out_size = std::accumulate(std::begin(conv->get_output_shape(0)), - std::end(conv->get_output_shape(0)), - size_t(1), - std::multiplies()); - auto pattern2 = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{2}, - ngraph::Shape{1, conv_out_size}); - auto reshape2 = std::make_shared(permute2, pattern2, false); - - ngraph::ResultVector results{std::make_shared(reshape2)}; - function = std::make_shared(results, params, "RemovePermutationsWithPoolAndActTest"); - - if (transpose_to_reshape) { - ngraph::pass::Manager manager; - manager.register_pass(); - manager.run_passes(function); - } - } -}; - -class RemovePermutationsWithTwoConvTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_IS=" << ov::test::utils::vec2str(inputShape); - return result.str(); - } - -protected: - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), 0.0f, 0.5f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - - void SetUp() override { - // Reshape - // | - // Permute (order: [0, 3, 1, 2]) - // | - // Convolution - // | - // Convolution - // | - // Permute (order: [0, 2, 3, 1]) - // | - // Reshape - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - size_t shape_size = inputShape.size(); - ASSERT_GT(shape_size, 2); - ASSERT_LT(shape_size, 5); - - size_t in_total_dims_size = - std::accumulate(std::begin(inputShape), std::end(inputShape), 1, std::multiplies()); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape{1, in_total_dims_size})}; - - auto pattern1 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{shape_size}, inputShape); - auto reshape1 = std::make_shared(params[0], pattern1, false); - - auto permute1 = CreateTranspose(reshape1, shape_size, true); - auto conv1 = CreateConvolution(permute1, ngPrc, inputShape); - auto conv2 = CreateConvolution(conv1, ngPrc, GetLayerTransposedOutputShape(conv1)); - auto permute2 = CreateTranspose(conv2, shape_size, false); - - auto conv_out_size = std::accumulate(std::begin(conv2->get_output_shape(0)), - std::end(conv2->get_output_shape(0)), - size_t(1), - std::multiplies()); - auto pattern2 = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{2}, - ngraph::Shape{1, conv_out_size}); - auto reshape2 = std::make_shared(permute2, pattern2, false); - - ngraph::ResultVector results{std::make_shared(reshape2)}; - function = std::make_shared(results, params, "RemovePermutationPass"); - } -}; - -class RemovePermutationsWithEltwiseTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_IS=" << ov::test::utils::vec2str(inputShape); - return result.str(); - } - -protected: - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.2f, 0.2f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - - void SetUp() override { - // Reshape Reshape - // | | - // Permute (order: [0, 3, 1, 2]) Permute (order: [0, 3, 1, 2]) - // | | - // Convolution Convolution - // |______________________________________| - // | - // Add - // | - // Permute (order: [0, 2, 3, 1]) - // | - // Reshape - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - size_t shape_size = inputShape.size(); - ASSERT_GT(shape_size, 2); - ASSERT_LT(shape_size, 5); - - size_t in_total_dims_size = - std::accumulate(std::begin(inputShape), std::end(inputShape), 1, std::multiplies()); - ov::ParameterVector params{ - std::make_shared(ngPrc, ov::Shape{1, 2 * in_total_dims_size})}; - auto split_axis_op = - std::make_shared(ov::element::Type_t::i64, ov::Shape{}, std::vector{1}); - auto split = std::make_shared(params[0], split_axis_op, 2); - - auto pattern1 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{shape_size}, inputShape); - auto reshape1 = std::make_shared(split->output(0), pattern1, false); - - auto permute1 = CreateTranspose(reshape1, shape_size, true); - auto conv1 = CreateConvolution(permute1, ngPrc, inputShape); - - auto pattern2 = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{shape_size}, inputShape); - auto reshape2 = std::make_shared(split->output(1), pattern2, false); - - auto permute2 = CreateTranspose(reshape2, shape_size, true); - auto conv2 = CreateConvolution(permute2, ngPrc, inputShape); - - auto add = std::make_shared(conv1, conv2); - auto permute3 = CreateTranspose(add, add->get_output_shape(0).size(), false); - - auto conv_out_size = std::accumulate(std::begin(add->get_output_shape(0)), - std::end(add->get_output_shape(0)), - size_t(1), - std::multiplies()); - auto pattern3 = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{2}, - ngraph::Shape{1, conv_out_size}); - auto reshape3 = std::make_shared(permute3, pattern3, false); - - ngraph::ResultVector results{std::make_shared(reshape3)}; - function = std::make_shared(results, params, "RemovePermutationPass"); - } -}; - -class RemoveSharedPermutationTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - size_t splits_num; - std::tie(netPrecision, targetDevice, configuration, inputShape, splits_num) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_IS=" << ov::test::utils::vec2str(inputShape); - result << "_splits=" << splits_num; - return result.str(); - } - -protected: - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.2f, 0.2f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - - void SetUp() override { - // Reshape - // | - // Permute (order: [0, 3, 1, 2]) - // | - // ______________Split____________________ - // | | - // Convolution Convolution - // | | - // Permute (order: [0, 2, 3, 1]) Permute (order: [0, 2, 3, 1]) - // | | - // Reshape Reshape - // |______________________________________| - // Concat - InferenceEngine::Precision netPrecision; - std::vector inputShape; - size_t splits_num; - std::tie(netPrecision, targetDevice, configuration, inputShape, splits_num) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - size_t shape_size = inputShape.size(); - ASSERT_GT(shape_size, 2); - ASSERT_LT(shape_size, 5); - - size_t in_total_dims_size = - std::accumulate(std::begin(inputShape), std::end(inputShape), 1, std::multiplies()); - ov::ParameterVector params{ - std::make_shared(ngPrc, ov::Shape{1, splits_num * in_total_dims_size})}; - - auto multipleInputShape = inputShape; - size_t mul_dim = inputShape.size() == 4 && inputShape[1] > 1 ? 1 : (inputShape.size() - 2); - multipleInputShape[mul_dim] *= splits_num; - auto pattern = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{multipleInputShape.size()}, - multipleInputShape); - auto reshape = std::make_shared(params[0], pattern, false); - auto permute = CreateTranspose(reshape, shape_size, true); - OPENVINO_SUPPRESS_DEPRECATED_START - auto split = ngraph::builder::makeSplit( - permute, - ngPrc, - splits_num, - inputShape.size() == 4 && inputShape[1] > 1 ? inputShape.size() - 2 : inputShape.size() - 1); - OPENVINO_SUPPRESS_DEPRECATED_END - - auto conv1 = CreateConvolution(split->output(0), ngPrc, inputShape); - auto permute1 = CreateTranspose(conv1, conv1->get_output_shape(0).size(), false); - auto conv1_out_size = std::accumulate(std::begin(conv1->get_output_shape(0)), - std::end(conv1->get_output_shape(0)), - size_t(1), - std::multiplies()); - auto pattern1 = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{2}, - ngraph::Shape{1, conv1_out_size}); - auto reshape1 = std::make_shared(permute1, pattern1, false); - - auto conv2 = CreateConvolution(split->output(1), ngPrc, inputShape); - auto permute2 = CreateTranspose(conv2, conv2->get_output_shape(0).size(), false); - auto conv2_out_size = std::accumulate(std::begin(conv2->get_output_shape(0)), - std::end(conv2->get_output_shape(0)), - size_t(1), - std::multiplies()); - auto pattern2 = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{2}, - ngraph::Shape{1, conv2_out_size}); - auto reshape2 = std::make_shared(permute2, pattern2, false); - - auto concat = std::make_shared(ov::NodeVector{reshape1, reshape2}, 1); - - ngraph::ResultVector results{std::make_shared(concat)}; - function = std::make_shared(results, params, "RemoveSharedPermutationTest"); - } -}; - -TEST_P(RemovePermutationsNHWCToNCHWPassTest, CompareWithRefImpl) { - Run(); -}; - -TEST_P(RemovePermutationsNHWCToNCHWPassNoReshapesTest, CompareWithRefImpl) { - Run(); -}; - -TEST_P(RemovePermutationsWithPoolAndActTest, CompareWithRefImpl) { - Run(); -}; - -TEST_P(RemovePermutationsWithTwoConvTest, CompareWithRefImpl) { - Run(); -}; - -TEST_P(RemovePermutationsWithEltwiseTest, CompareWithRefImpl) { - Run(); -}; - -TEST_P(RemoveSharedPermutationTest, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "327.67"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -const std::vector> inputShapes{ - {1, 1, 168, 1}, {1, 1, 168, 2}, {1, 1, 168, 4}, {1, 1, 32, 1}, {1, 1, 32, 2}, {1, 1, 32, 8}, - {1, 1, 32, 9}, {1, 168, 1, 1}, {1, 168, 1, 2}, {1, 168, 1, 4}, {1, 32, 1, 1}, {1, 32, 1, 2}, - {1, 32, 1, 8}, {1, 32, 1, 9}, {1, 16, 8, 1}, {1, 168, 1}, {1, 168, 2}, {1, 168, 4}, - {1, 32, 1}, {1, 32, 2}, {1, 32, 8}, {1, 32, 9}}; - -const std::vector> inputShapesSplit{ - {1, 1, 160, 1}, {1, 1, 160, 2}, {1, 1, 168, 4}, {1, 1, 32, 1}, {1, 1, 32, 2}, {1, 1, 32, 8}, - {1, 1, 32, 9}, {1, 160, 1, 1}, {1, 160, 1, 2}, {1, 168, 1, 4}, {1, 32, 1, 1}, {1, 32, 1, 2}, - {1, 32, 1, 8}, {1, 32, 1, 9}, {1, 16, 8, 1}, {1, 168, 1}, {1, 168, 2}, {1, 168, 4}, - {1, 32, 1}, {1, 32, 2}, {1, 32, 8}, {1, 32, 9}}; - -const std::vector splitsNum = {2, 4, 8}; - -INSTANTIATE_TEST_SUITE_P( - smoke_PermutationPass, - RemovePermutationsNHWCToNCHWPassTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(std::vector{false, true}), // with 1d output of convolution - ::testing::ValuesIn(std::vector{false, true})), // transpose to reshape - RemovePermutationsNHWCToNCHWPassTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_PermutationPass, - RemovePermutationsNHWCToNCHWPassNoReshapesTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShapes)), - RemovePermutationsNHWCToNCHWPassNoReshapesTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_PermutationPass, - RemovePermutationsWithPoolAndActTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(std::vector{false, true}), // with activation - ::testing::ValuesIn(std::vector{false, - true})), // transpose to reshape - RemovePermutationsWithPoolAndActTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_PermutationPass, - RemovePermutationsWithTwoConvTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShapes)), - RemovePermutationsWithTwoConvTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_PermutationPass, - RemovePermutationsWithEltwiseTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShapes)), - RemovePermutationsWithEltwiseTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_PermutationPass, - RemoveSharedPermutationTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShapesSplit), - ::testing::ValuesIn(splitsNum)), - RemoveSharedPermutationTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/preprocess_tests/gather_transpose_cpu.cpp b/src/plugins/intel_gna/tests/functional/preprocess_tests/gather_transpose_cpu.cpp deleted file mode 100644 index 2a472d4a6ef..00000000000 --- a/src/plugins/intel_gna/tests/functional/preprocess_tests/gather_transpose_cpu.cpp +++ /dev/null @@ -1,235 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "openvino/opsets/opset10.hpp" -#include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "shared_test_classes/base/ov_subgraph.hpp" - -using namespace ov::opset10; -using namespace ov::test; - -enum PrePostLayer { NONE, GATHER, TRANSPOSE }; - -namespace std { -inline std::ostream& operator<<(std::ostream& os, PrePostLayer layer_type) { - switch (layer_type) { - case PrePostLayer::GATHER: - os << "GATHER"; - break; - case PrePostLayer::TRANSPOSE: - os << "TRANSPOSE"; - break; - default: - os << "NONE"; - break; - } - return os; -} -} // namespace std - -namespace LayerTestsDefinitions { - -namespace { - -inline std::vector make_indexes(size_t size) { - std::vector indexes(size); - std::iota(indexes.begin(), indexes.end(), 0); - std::reverse(indexes.begin(), indexes.end()); - return indexes; -} - -inline std::vector make_transpose_order(const std::vector& input_shape) { - std::vector transpose_order; - switch (input_shape.size()) { - case 2: - transpose_order = {1, 0}; - break; - case 3: - transpose_order = {0, 2, 1}; - break; - case 4: - transpose_order = {0, 2, 3, 1}; - break; - default: - break; - } - - return transpose_order; -} - -} // namespace - -typedef std::tuple, // Input shape - ov::element::Type, // Net precision - std::string, // Device name - std::map, // Configuration - std::map, // Additional Configuration - PrePostLayer, // Pre-processing layer - PrePostLayer // Post-processing layer - > - preprocessTestParamsSet; - -class PrePostProcessBaseTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest { -public: - static std::string get_test_case_name(const testing::TestParamInfo& obj) { - std::vector input_shape; - ov::element::Type net_type, in_type, out_type; - std::string target_device; - std::map conf, conf_ext; - PrePostLayer pre_layer, post_layer; - - std::tie(input_shape, net_type, target_device, conf, conf_ext, pre_layer, post_layer) = obj.param; - for (auto& conf_item : conf_ext) { - conf[conf_item.first] = conf_item.second; - } - - std::ostringstream result; - result << "Shape=" << ov::test::utils::vec2str(input_shape) << "_"; - result << "netPRC=" << net_type << "_"; - result << "trgDev=" << target_device; - for (auto const& conf_i : conf) { - result << "_configItem=" << conf_i.first.c_str() << "_" << conf_i.second.c_str(); - } - result << "_pre_layer=" << pre_layer; - result << "_post_layer=" << post_layer; - return result.str(); - } - -protected: - void SetUp() override { - abs_threshold = std::numeric_limits::max(); - rel_threshold = std::numeric_limits::max(); - std::map conf, conf_ext; - std::tie(m_input_shape, m_net_type, targetDevice, conf, conf_ext, m_pre_layer, m_post_layer) = this->GetParam(); - - std::vector input_shapes = static_shapes_to_test_representation({m_input_shape, m_input_shape}); - configuration.insert(conf.begin(), conf.end()); - for (auto& conf_item : conf_ext) { - configuration[conf_item.first] = conf_item.second; - } - init_input_shapes(input_shapes); - } - - void init_test_model() { - ov::ParameterVector params{std::make_shared(m_net_type, ov::Shape(m_input_shape))}; - const size_t input_shape_size = ov::shape_size(params[0]->get_shape()); - - std::shared_ptr pre_node = params[0]; - switch (m_pre_layer) { - case PrePostLayer::GATHER: - pre_node = make_gather_node(pre_node); - break; - case PrePostLayer::TRANSPOSE: - pre_node = make_transpose_node(pre_node); - break; - default: - break; - } - - auto mul_input_const = Constant::create(m_net_type, - pre_node->get_shape(), - ov::test::utils::generate_float_numbers(input_shape_size, -0.2f, 0.2f)); - auto matmul_node = std::make_shared(pre_node, mul_input_const); - - auto add_input_const = Constant::create(m_net_type, - pre_node->get_shape(), - ov::test::utils::generate_float_numbers(input_shape_size, -0.2f, 0.2f)); - auto add_node = std::make_shared(matmul_node, add_input_const); - - std::shared_ptr post_node = add_node; - switch (m_post_layer) { - case PrePostLayer::GATHER: - pre_node = make_gather_node(post_node); - break; - case PrePostLayer::TRANSPOSE: - pre_node = make_transpose_node(post_node); - break; - default: - break; - } - - ov::ResultVector results{std::make_shared(post_node)}; - function = std::make_shared(results, params, "concat"); - } - - std::shared_ptr make_gather_node(std::shared_ptr node) { - const std::vector indexes = make_indexes(ov::shape_size(m_input_shape)); - auto gather_indexes = Constant::create(ov::element::i64, ov::Shape{indexes.size()}, indexes); - const size_t gather_axis = m_input_shape.size() - 1; - auto gather_axis_const = Constant::create(ov::element::i64, ov::Shape{}, {gather_axis}); - auto gather_node = std::make_shared(node, gather_indexes, gather_axis_const); - - return gather_node; - } - - std::shared_ptr make_transpose_node(std::shared_ptr node) { - std::vector transpose_order = make_transpose_order(m_input_shape); - ov::Shape transpose_shape; - for (size_t i : transpose_order) { - transpose_shape.push_back(m_input_shape[i]); - } - - auto transpose_const = - std::make_shared(ov::element::i8, ov::Shape{transpose_order.size()}, transpose_order); - auto transpose_node = std::make_shared(node, transpose_const); - - return transpose_node; - } - - ov::element::Type m_net_type; - std::vector m_input_shape; - PrePostLayer m_pre_layer = PrePostLayer::NONE; - PrePostLayer m_post_layer = PrePostLayer::NONE; -}; - -TEST_P(PrePostProcessBaseTest, CompareWithRefs) { - init_test_model(); - run(); -} - -std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -std::vector> target_configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_1_0"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}}; - -const std::vector> input_shapes_transpose = {{2, 64}, {1, 2, 64}, {1, 2, 4, 16}}; - -const std::vector> input_shapes_gather = {{1, 128}}; - -const ov::element::TypeVector input_precisions = {ov::element::f32}; - -INSTANTIATE_TEST_SUITE_P(smoke_preprocess_gather, - PrePostProcessBaseTest, - ::testing::Combine(::testing::ValuesIn(input_shapes_gather), - ::testing::ValuesIn(input_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(target_configs), - ::testing::ValuesIn({PrePostLayer::NONE, PrePostLayer::GATHER}), - ::testing::ValuesIn({PrePostLayer::NONE, PrePostLayer::GATHER})), - PrePostProcessBaseTest::get_test_case_name); - -INSTANTIATE_TEST_SUITE_P(smoke_preprocess_transpose, - PrePostProcessBaseTest, - ::testing::Combine(::testing::ValuesIn(input_shapes_transpose), - ::testing::ValuesIn(input_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(target_configs), - ::testing::ValuesIn({PrePostLayer::NONE, PrePostLayer::TRANSPOSE}), - ::testing::ValuesIn({PrePostLayer::NONE, PrePostLayer::TRANSPOSE})), - PrePostProcessBaseTest::get_test_case_name); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/preprocess_tests/gather_transpose_merge.cpp b/src/plugins/intel_gna/tests/functional/preprocess_tests/gather_transpose_merge.cpp deleted file mode 100644 index 746c5cafa64..00000000000 --- a/src/plugins/intel_gna/tests/functional/preprocess_tests/gather_transpose_merge.cpp +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset10.hpp" -#include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "shared_test_classes/base/ov_subgraph.hpp" - -using namespace ov::opset10; -using namespace ov::test; - -namespace gather_transpose_merge_test { - -namespace { - -inline std::vector make_indexes(size_t size) { - std::vector indexes(size); - std::iota(indexes.begin(), indexes.end(), 0); - std::reverse(indexes.begin(), indexes.end()); - return indexes; -} - -inline std::vector make_transpose_order(const std::vector& input_shape) { - std::vector transpose_order; - switch (input_shape.size()) { - case 2: - transpose_order = {1, 0}; - break; - case 3: - transpose_order = {0, 2, 1}; - break; - case 4: - transpose_order = {0, 2, 3, 1}; - break; - default: - break; - } - - return transpose_order; -} - -} // namespace - -typedef std::tuple, // Input shape - ov::element::Type, // Net precision - std::string, // Device name - std::map, // Configuration - std::map // Additional Configuration - > - GatherTransposeMergeTestParams; - -class GatherTransposeMergeTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest { -public: - static std::string get_test_case_name(const testing::TestParamInfo& obj) { - std::vector input_shape; - ov::element::Type net_type, in_type, out_type; - std::string target_device; - std::map conf, conf_ext; - - std::tie(input_shape, net_type, target_device, conf, conf_ext) = obj.param; - for (auto& conf_item : conf_ext) { - conf[conf_item.first] = conf_item.second; - } - - std::ostringstream result; - result << "Shape=" << ov::test::utils::vec2str(input_shape) << "_"; - result << "netPRC=" << net_type << "_"; - result << "trgDev=" << target_device; - for (auto const& conf_i : conf) { - result << "_configItem=" << conf_i.first.c_str() << "_" << conf_i.second.c_str(); - } - return result.str(); - } - -protected: - void SetUp() override { - abs_threshold = std::numeric_limits::max(); - rel_threshold = std::numeric_limits::max(); - std::map conf, conf_ext; - std::tie(m_input_shape, m_net_type, targetDevice, conf, conf_ext) = this->GetParam(); - - std::vector input_shapes = static_shapes_to_test_representation({m_input_shape, m_input_shape}); - configuration.insert(conf.begin(), conf.end()); - for (auto& conf_item : conf_ext) { - configuration[conf_item.first] = conf_item.second; - } - init_input_shapes(input_shapes); - } - - void init_test_model(); - - ov::element::Type m_net_type; - std::vector m_input_shape; -}; - -class TransposeGatherTest : public GatherTransposeMergeTest { -protected: - void init_test_model() { - ov::ParameterVector params{std::make_shared(m_net_type, ov::Shape(m_input_shape))}; - const size_t input_shape_size = ov::shape_size(params[0]->get_shape()); - - std::vector transpose_order = make_transpose_order(m_input_shape); - auto transpose_const = - std::make_shared(ov::element::i8, ov::Shape{transpose_order.size()}, transpose_order); - auto transpose_node = std::make_shared(params[0], transpose_const); - - std::vector shape_in = {1, -1}; - auto reshape_in_const = std::make_shared(ov::element::i64, ov::Shape{shape_in.size()}, shape_in); - auto reshape_in_node = std::make_shared(transpose_node, reshape_in_const, false); - - const std::vector gather_ids = make_indexes(ov::shape_size(m_input_shape)); - auto gather_const_ids = Constant::create(ov::element::i64, ov::Shape{gather_ids.size()}, gather_ids); - const size_t gather_axis = 1; - auto gather_const_axis = Constant::create(ov::element::i64, ov::Shape{}, {gather_axis}); - auto gather_node = std::make_shared(reshape_in_node, gather_const_ids, gather_const_axis); - - ov::Shape shape_out = transpose_node->get_output_shape(0); - auto reshape_out_const = std::make_shared(ov::element::i64, ov::Shape{shape_out.size()}, shape_out); - auto reshape_out_node = std::make_shared(gather_node, reshape_out_const, false); - - ov::ResultVector results{std::make_shared(reshape_out_node)}; - function = std::make_shared(results, params, "gather_transpose_merge_test"); - } -}; - -class GatherTransposeTest : public GatherTransposeMergeTest { -protected: - void init_test_model() { - ov::ParameterVector params{std::make_shared(m_net_type, ov::Shape(m_input_shape))}; - const size_t input_shape_size = ov::shape_size(params[0]->get_shape()); - - std::vector shape_in = {1, -1}; - auto reshape_in_const = std::make_shared(ov::element::i64, ov::Shape{shape_in.size()}, shape_in); - auto reshape_in_node = std::make_shared(params[0], reshape_in_const, false); - - const std::vector gather_ids = make_indexes(ov::shape_size(m_input_shape)); - auto gather_const_ids = Constant::create(ov::element::i64, ov::Shape{gather_ids.size()}, gather_ids); - const size_t gather_axis = 1; - auto gather_const_axis = Constant::create(ov::element::i64, ov::Shape{}, {gather_axis}); - auto gather_node = std::make_shared(reshape_in_node, gather_const_ids, gather_const_axis); - - ov::Shape shape_middle = m_input_shape; - auto reshape_middle_const = - std::make_shared(ov::element::i64, ov::Shape{shape_middle.size()}, shape_middle); - auto reshape_middle_node = std::make_shared(gather_node, reshape_middle_const, false); - - std::vector transpose_order = make_transpose_order(m_input_shape); - auto transpose_const = - std::make_shared(ov::element::i8, ov::Shape{transpose_order.size()}, transpose_order); - auto transpose_node = std::make_shared(reshape_middle_node, transpose_const); - - ov::ResultVector results{std::make_shared(transpose_node)}; - function = std::make_shared(results, params, "gather_transpose_merge_test"); - } -}; - -TEST_P(TransposeGatherTest, CompareWithRefs) { - init_test_model(); - run(); -} - -TEST_P(GatherTransposeTest, CompareWithRefs) { - init_test_model(); - run(); -} - -std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -std::vector> target_configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}}; - -const std::vector> input_shapes = {{16, 64}, {1, 16, 64}, {1, 8, 16, 64}}; - -const ov::element::TypeVector input_precisions = {ov::element::f32}; - -INSTANTIATE_TEST_SUITE_P(smoke_merge_transpose_gather, - TransposeGatherTest, - ::testing::Combine(::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(input_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(target_configs)), - TransposeGatherTest::get_test_case_name); - -INSTANTIATE_TEST_SUITE_P(smoke_merge_transpose_gather, - GatherTransposeTest, - ::testing::Combine(::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(input_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(target_configs)), - GatherTransposeTest::get_test_case_name); - -} // namespace gather_transpose_merge_test diff --git a/src/plugins/intel_gna/tests/functional/preprocess_tests/precision_convert.cpp b/src/plugins/intel_gna/tests/functional/preprocess_tests/precision_convert.cpp deleted file mode 100644 index eb224e20c78..00000000000 --- a/src/plugins/intel_gna/tests/functional/preprocess_tests/precision_convert.cpp +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "common_test_utils/common_utils.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/ov_subgraph.hpp" - -using namespace InferenceEngine; -using namespace ov::test; - -namespace LayerTestsDefinitions { - -typedef std::tuple // Configuration - > - preprocessTestParamsSet; - -class PreprocessGNATest : public testing::WithParamInterface, virtual public SubgraphBaseTest { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - ov::element::Type net_type, in_type, out_type; - std::string target_device; - std::map conf; - - std::tie(net_type, in_type, out_type, target_device, conf) = obj.param; - - std::ostringstream result; - result << "netPRC=" << net_type << "_"; - result << "inPRC=" << in_type << "_"; - result << "outPRC=" << out_type << "_"; - result << "trgDev=" << target_device; - for (auto const& conf_i : conf) { - result << "_configItem=" << conf_i.first.c_str() << "_" << conf_i.second.c_str(); - } - return result.str(); - } - -protected: - void SetUp() override { - ov::element::Type net_type; - std::vector input_shapes = static_shapes_to_test_representation({{8, 2}, {8, 2}}); - std::map conf; - abs_threshold = std::numeric_limits::max(); - rel_threshold = std::numeric_limits::max(); - - std::tie(net_type, inType, outType, targetDevice, conf) = this->GetParam(); - - configuration.insert(conf.begin(), conf.end()); - - init_input_shapes({input_shapes}); - - ov::ParameterVector params; - ov::OutputVector paramsOuts; - for (auto&& shape : inputDynamicShapes) { - auto param = std::make_shared(net_type, shape); - params.push_back(param); - paramsOuts.push_back(param); - } - auto concat = std::make_shared(paramsOuts, 1); - ngraph::ResultVector results{std::make_shared(concat)}; - function = std::make_shared(results, params, "concat"); - } -}; - -class PreprocessGNAUnsupportedTest : public PreprocessGNATest { -public: - PreprocessGNAUnsupportedTest(std::string error_str) : exp_error_str_(error_str) {} - void run() override { - try { - PreprocessGNATest::compile_model(); - FAIL() << "GNA's unsupported layers were not detected during LoadNetwork()"; - } catch (std::runtime_error& e) { - const std::string errorMsg = e.what(); - const auto expectedMsg = exp_error_str_; - ASSERT_STR_CONTAINS(errorMsg, expectedMsg); - EXPECT_TRUE(errorMsg.find(expectedMsg) != std::string::npos) - << "Wrong error message, actual error message: " << errorMsg << ", expected: " << expectedMsg; - } - } - -private: - std::string exp_error_str_; -}; - -class PreprocessGNAUnsupportedInputsTest : public PreprocessGNAUnsupportedTest { -public: - PreprocessGNAUnsupportedInputsTest() - : PreprocessGNAUnsupportedTest("The plugin does not support input precision") {} -}; - -class PreprocessGNAUnsupportedOutputsTest : public PreprocessGNAUnsupportedTest { -public: - PreprocessGNAUnsupportedOutputsTest() : PreprocessGNAUnsupportedTest("The plugin does not support layer") {} -}; - -TEST_P(PreprocessGNATest, CompareWithRefs) { - run(); -} - -TEST_P(PreprocessGNAUnsupportedInputsTest, CompareWithRefs) { - run(); -} - -TEST_P(PreprocessGNAUnsupportedOutputsTest, CompareWithRefs) { - run(); -} - -std::map config = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1"}, {"GNA_SCALE_FACTOR_1", "1"}}}; - -ov::element::TypeVector inputTypesUnsupported = {ov::element::i32}; - -ov::element::TypeVector outputTypesUnsupported = { - ov::element::u8, - ov::element::i16, -}; - -ov::element::TypeVector outputTypesSupported = {ov::element::i32, ov::element::f32}; - -ov::element::TypeVector netTypes = {ov::element::f16, ov::element::f32}; - -INSTANTIATE_TEST_SUITE_P(smoke_Preprocess, - PreprocessGNATest, - ::testing::Combine(::testing::ValuesIn(netTypes), - ::testing::Values(ov::element::f32), - ::testing::ValuesIn(outputTypesSupported), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(config)), - PreprocessGNATest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Preprocess, - PreprocessGNAUnsupportedInputsTest, - ::testing::Combine(::testing::ValuesIn(netTypes), - ::testing::ValuesIn(inputTypesUnsupported), - ::testing::Values(ov::element::f32), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(config)), - PreprocessGNATest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Preprocess, - PreprocessGNAUnsupportedOutputsTest, - ::testing::Combine(::testing::ValuesIn(netTypes), - ::testing::Values(ov::element::f32), - ::testing::ValuesIn(outputTypesUnsupported), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(config)), - PreprocessGNATest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/scale_factors_tests/add_overload_correction.cpp b/src/plugins/intel_gna/tests/functional/scale_factors_tests/add_overload_correction.cpp deleted file mode 100644 index 1642b372fcf..00000000000 --- a/src/plugins/intel_gna/tests/functional/scale_factors_tests/add_overload_correction.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset8.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector> - addOverloadCorrectionParams; - -namespace LayerTestsDefinitions { - -class AddOverloadCorrectionTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, inputShape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_IS=" << ov::test::utils::vec2str(inputShape); - - return result.str(); - } - -protected: - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - // generate values with different dynamic ranges for different inputs to produce integer overload after Add - const float valueLimit = (info.name() == "input1") ? 10.0 : 1.0; - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -valueLimit, valueLimit); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::vector inputShape; - - std::tie(netPrecision, targetDevice, configuration, inputShape) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape)), - std::make_shared(ngPrc, ov::Shape(inputShape))}; - params[0]->set_friendly_name("input1"); - params[1]->set_friendly_name("input2"); - - auto lowNodeIn = ngraph::builder::makeConstant(ngPrc, {1}, {-10.0f}); - auto highNodeIn = ngraph::builder::makeConstant(ngPrc, {1}, {10.0f}); - auto fqIn = std::make_shared(params[0], - lowNodeIn, - highNodeIn, - lowNodeIn, - highNodeIn, - levels16); - - auto constant = - ngraph::builder::makeConstant(ngPrc, - inputShape, - ov::test::utils::generate_float_numbers(inputShape[1], -1.0f, 1.0f)); - auto mul = std::make_shared(params[1], constant); - auto lowNodeMul = ngraph::builder::makeConstant(ngPrc, {1}, {-1.0f}); - auto highNodeMul = ngraph::builder::makeConstant(ngPrc, {1}, {1.0f}); - auto fqMul = - std::make_shared(mul, lowNodeMul, highNodeMul, lowNodeMul, highNodeMul, levels16); - - auto add = std::make_shared(fqIn, fqMul); - - auto lowNodeOut = ngraph::builder::makeConstant(ngPrc, {1}, {-11.0f}); - auto highNodeOut = ngraph::builder::makeConstant(ngPrc, {1}, {11.0f}); - auto fqOut = - std::make_shared(add, lowNodeOut, highNodeOut, lowNodeOut, highNodeOut, levels16); - - ngraph::ResultVector results{std::make_shared(fqOut)}; - function = std::make_shared(results, params, "AddOverloadCorrection"); - } - - const size_t levels16 = std::numeric_limits::max(); -}; - -TEST_P(AddOverloadCorrectionTest, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -const std::vector> inputShapes = {{1, 128}}; - -INSTANTIATE_TEST_SUITE_P(smoke_base, - AddOverloadCorrectionTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShapes)), - AddOverloadCorrectionTest::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/scale_factors_tests/const_input_add.cpp b/src/plugins/intel_gna/tests/functional/scale_factors_tests/const_input_add.cpp deleted file mode 100644 index 8766fab37d5..00000000000 --- a/src/plugins/intel_gna/tests/functional/scale_factors_tests/const_input_add.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "common_test_utils/node_builders/eltwise.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::pair, // Input min/max values - std::pair // Constant min/max values - > - constInputAddParams; - -namespace LayerTestsDefinitions { - -class ConstInputAddTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::pair inputRange; - std::pair constRange; - std::tie(netPrecision, targetDevice, configuration, inputRange, constRange) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_IR=" << inputRange.first << "," << inputRange.second << "_"; - result << "IR=" << constRange.first << "," << constRange.second; - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), - inputMax - inputMin, - inputMin, - (inputMax - inputMin) / 10); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::pair inputRange; - std::pair constRange; - std::tie(netPrecision, targetDevice, configuration, inputRange, constRange) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - std::tie(inputMin, inputMax) = inputRange; - - ngraph::Shape shape = {1, 72}; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(shape))}; - - auto constant = - ngraph::builder::makeConstant(ngPrc, shape, {}, true, constRange.second, constRange.first); - auto eltwise = ov::test::utils::make_eltwise(constant, params[0], ngraph::helpers::EltwiseTypes::ADD); - - ngraph::ResultVector results{std::make_shared(eltwise)}; - function = std::make_shared(results, params, "InputConstAdd"); - } - -private: - float inputMin = 0.0; - float inputMax = 0.0; -}; - -TEST_P(ConstInputAddTest, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -const std::vector> inputRange = {{-10, 10}, {-100, 100}}; - -const std::vector> constRange = {{-10, 10}, {-0.1, 0.1}, {-1.0e-5, 1.0e-5}}; - -INSTANTIATE_TEST_SUITE_P(smoke_const_input_add, - ConstInputAddTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputRange), - ::testing::ValuesIn(constRange)), - ConstInputAddTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/scale_factors_tests/eltwise_act_fq.cpp b/src/plugins/intel_gna/tests/functional/scale_factors_tests/eltwise_act_fq.cpp deleted file mode 100644 index 0106d80fec5..00000000000 --- a/src/plugins/intel_gna/tests/functional/scale_factors_tests/eltwise_act_fq.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset8.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -static std::map activationNames = { - {ngraph::helpers::ActivationTypes::Sigmoid, "Sigmoid"}, - {ngraph::helpers::ActivationTypes::Tanh, "Tanh"}, - {ngraph::helpers::ActivationTypes::Relu, "Relu"}, - {ngraph::helpers::ActivationTypes::Exp, "Exp"}, - {ngraph::helpers::ActivationTypes::Log, "Log"}, - {ngraph::helpers::ActivationTypes::Sign, "Sign"}, - {ngraph::helpers::ActivationTypes::Abs, "Abs"}}; - -typedef std::tuple, // Configuration - std::pair, // Input values - ngraph::helpers::ActivationTypes // Activation type - > - eltwiseActFqParams; - -namespace LayerTestsDefinitions { - -class EltwiseActFqTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::pair inputValues; - ngraph::helpers::ActivationTypes act; - std::tie(netPrecision, targetDevice, configuration, inputValues, act) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_range=(" << inputValues.first << ", " << inputValues.second << ")"; - result << "_act=" << activationNames[act]; - - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), inputDataMin, inputDataMax); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::pair inputValues; - ngraph::helpers::ActivationTypes act; - - std::tie(netPrecision, targetDevice, configuration, inputValues, act) = this->GetParam(); - std::tie(inputDataMin, inputDataMax) = inputValues; - if (act == ngraph::helpers::ActivationTypes::Log) { - // clamp not positive values - inputDataMin = 1.0e-3; - // get error threshold value from PWL error - threshold = std::stof(configuration["GNA_PWL_MAX_ERROR_PERCENT"]); - } - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - const ngraph::Shape shape = {1, 128}; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(shape))}; - - auto lowNodeIn = ngraph::builder::makeConstant(ngPrc, {1}, {100 * -inputDataMax}); - auto highNodeIn = ngraph::builder::makeConstant(ngPrc, {1}, {100 * inputDataMax}); - auto fqIn = std::make_shared(params[0], - lowNodeIn, - highNodeIn, - lowNodeIn, - highNodeIn, - levels16); - - auto constant = ngraph::builder::makeConstant( - ngPrc, - shape, - ov::test::utils::generate_float_numbers(shape[1], inputDataMin, inputDataMax)); - auto add = std::make_shared(fqIn, constant); - - auto lowNode = ngraph::builder::makeConstant(ngPrc, {1}, {2 * inputDataMin}); - auto highNode = ngraph::builder::makeConstant(ngPrc, {1}, {2 * inputDataMax}); - auto fq = std::make_shared(add, lowNode, highNode, lowNode, highNode, levels32); - - auto tanh = ngraph::builder::makeActivation(fq, ngPrc, act); - - auto lowNodeOut = ngraph::builder::makeConstant(ngPrc, {1}, {std::tanh(2 * inputDataMin)}); - auto highNodeOut = ngraph::builder::makeConstant(ngPrc, {1}, {std::tanh(2 * inputDataMax)}); - auto fqOut = std::make_shared(tanh, - lowNodeOut, - highNodeOut, - lowNodeOut, - highNodeOut, - levels16); - - ngraph::ResultVector results{std::make_shared(fqOut)}; - function = std::make_shared(results, params, "TanhFq"); - } - - float inputDataMax = 1.0; - float inputDataMin = -1.0; - const size_t levels16 = std::numeric_limits::max(); - const size_t levels32 = std::numeric_limits::max(); - // to reproduce the problem with quite big distance between min int and min value from stats - const size_t sf_reducer = 100; -}; - -TEST_P(EltwiseActFqTest, CompareWithRefImpl) { - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_PWL_MAX_ERROR_PERCENT", "0.025"}}}; - -const std::vector> inputValues = {{-10.0, 10.0}, {-5.0, 5.0}, {-1.0, 1.0}, {-0.04, 0.04}}; - -const std::vector activationTypes = {ngraph::helpers::ActivationTypes::Sigmoid, - ngraph::helpers::ActivationTypes::Tanh, - ngraph::helpers::ActivationTypes::Relu, - ngraph::helpers::ActivationTypes::Exp, - ngraph::helpers::ActivationTypes::Log, - ngraph::helpers::ActivationTypes::Sign, - ngraph::helpers::ActivationTypes::Abs}; - -INSTANTIATE_TEST_SUITE_P(smoke_base, - EltwiseActFqTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputValues), - ::testing::ValuesIn(activationTypes)), - EltwiseActFqTest::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/scale_factors_tests/matmul_overload_correction.cpp b/src/plugins/intel_gna/tests/functional/scale_factors_tests/matmul_overload_correction.cpp deleted file mode 100644 index afb739876c7..00000000000 --- a/src/plugins/intel_gna/tests/functional/scale_factors_tests/matmul_overload_correction.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset8.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::vector, // Input shape - bool, // Constant second input - bool // Swap inputs - > - matmulOverloadCorrectionParams; - -namespace LayerTestsDefinitions { - -class MatMulOverloadCorrectionNegTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::vector inputShape; - bool isSecondInputConst, swapInputs; - std::tie(netPrecision, targetDevice, configuration, inputShape, isSecondInputConst, swapInputs) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_IS=" << ov::test::utils::vec2str(inputShape); - result << "_secondInput=" << (isSecondInputConst ? "const" : "param"); - result << "_swapInputs=" << swapInputs; - - return result.str(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - bool isSecondInputConst, swapInputs; - std::vector inputShape; - - std::tie(netPrecision, targetDevice, configuration, inputShape, isSecondInputConst, swapInputs) = - this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - const ngraph::Shape shape1 = inputShape; - const ngraph::Shape shape2 = {1, inputShape[1] * inputShape[1]}; - const float maxInputValue = 10.0f; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(shape1))}; - auto relu = std::make_shared(params[0]); - - std::shared_ptr input2; - if (isSecondInputConst) { - input2 = ngraph::builder::makeConstant( - ngPrc, - ngraph::Shape{shape1[1], shape1[1]}, - ov::test::utils::generate_float_numbers(shape2[1], 0.0f, maxInputValue)); - } else { - input2 = std::make_shared(ngPrc, shape2); - params.push_back(std::dynamic_pointer_cast(input2)); - } - - auto lowNodeIn1 = ngraph::builder::makeConstant(ngPrc, {1}, {-maxInputValue}); - auto highNodeIn1 = ngraph::builder::makeConstant(ngPrc, {1}, {maxInputValue}); - auto fqIn1 = std::make_shared(relu, - lowNodeIn1, - highNodeIn1, - lowNodeIn1, - highNodeIn1, - levels16); - - auto lowNodeIn2 = ngraph::builder::makeConstant(ngPrc, {1}, {-maxInputValue}); - auto highNodeIn2 = ngraph::builder::makeConstant(ngPrc, {1}, {maxInputValue}); - auto fqIn2 = std::make_shared(input2, - lowNodeIn2, - highNodeIn2, - lowNodeIn2, - highNodeIn2, - levels16); - - std::shared_ptr matmul_input2 = fqIn2; - if (!isSecondInputConst) { - auto pattern = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{2}, - ngraph::Shape{shape1[1], shape1[1]}); - matmul_input2 = std::make_shared(fqIn2, pattern, false); - } - - auto matmul = swapInputs ? std::make_shared(matmul_input2, fqIn1, false, true) - : std::make_shared(fqIn1, matmul_input2, false, true); - - auto lowNodeOut = - ngraph::builder::makeConstant(ngPrc, {1}, {-maxInputValue * maxInputValue * inputShape[1] / 10}); - auto highNodeOut = - ngraph::builder::makeConstant(ngPrc, {1}, {maxInputValue * maxInputValue * inputShape[1] / 10}); - auto fqOut = std::make_shared(matmul, - lowNodeOut, - highNodeOut, - lowNodeOut, - highNodeOut, - levels32); - - ngraph::ResultVector results{std::make_shared(fqOut)}; - function = std::make_shared(results, params, "MatMulOverloadCorrection"); - } - - const size_t levels16 = std::numeric_limits::max(); - const size_t levels32 = std::numeric_limits::max(); -}; - -TEST_P(MatMulOverloadCorrectionNegTest, CompareWithRefImpl) { - std::stringstream what; - std::streambuf* sbuf = std::cout.rdbuf(); - std::streambuf* ebuf = std::cerr.rdbuf(); - std::cout.rdbuf(what.rdbuf()); - std::cerr.rdbuf(what.rdbuf()); - LoadNetwork(); - const auto expected = "Potential overload correction issue at layer "; - EXPECT_THAT(what.str(), ::testing::HasSubstr(expected)); - std::cout.rdbuf(sbuf); - std::cerr.rdbuf(ebuf); - Run(); -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"LOG_LEVEL", "LOG_WARNING"}}}; - -const std::vector> inputShapes = {{1, 128}, {1, 256}}; - -INSTANTIATE_TEST_SUITE_P(smoke_base, - MatMulOverloadCorrectionNegTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn({true}), - ::testing::ValuesIn({true, false})), - MatMulOverloadCorrectionNegTest::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/scale_factors_tests/perchannel_quant_test.cpp b/src/plugins/intel_gna/tests/functional/scale_factors_tests/perchannel_quant_test.cpp deleted file mode 100644 index 5fd0cd60a7e..00000000000 --- a/src/plugins/intel_gna/tests/functional/scale_factors_tests/perchannel_quant_test.cpp +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset8.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -typedef std::tuple, // Configuration - std::pair, // Weights values - std::vector // Input shapes - > - matmulParams; - -namespace LayerTestsDefinitions { - -class PerchannelQuantTest : public testing::WithParamInterface, public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::pair weightsValues; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, weightsValues, inputShape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_range=(" << weightsValues.first << ", " << weightsValues.second << ")"; - result << "_IS=(" << ov::test::utils::vec2str(inputShape) << ")"; - - return result.str(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::pair weightsValues; - std::vector inputShape; - std::tie(netPrecision, targetDevice, configuration, weightsValues, inputShape) = this->GetParam(); - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - const ngraph::Shape constShape = {inputShape.back(), inputShape.back()}; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - - std::vector weights; - std::vector weightsMin, weightsMax; - for (int i = 0; i < constShape.front(); ++i) { - // multiplier to increase weights ranges difference between different channels - float mul = (i % 2 ? 1.0 : 0.001); - float rowMin = weightsValues.first * mul; - float rowMax = weightsValues.second * mul; - auto rowWeights = ov::test::utils::generate_float_numbers(constShape.back(), rowMin, rowMax); - weights.insert(std::end(weights), std::begin(rowWeights), std::end(rowWeights)); - weightsMin.push_back(rowMin); - weightsMax.push_back(rowMax); - } - - auto constant = ngraph::builder::makeConstant(ngPrc, constShape, weights); - auto wLowNode = ngraph::builder::makeConstant(ngPrc, {constShape.front()}, {weightsMin}); - auto wHighNode = ngraph::builder::makeConstant(ngPrc, {constShape.front()}, {weightsMax}); - auto wFq = std::make_shared(constant, - wLowNode, - wHighNode, - wLowNode, - wHighNode, - std::numeric_limits::max() - 1); - auto matmul = std::make_shared(params[0], wFq, false, true); - - ngraph::ResultVector results{std::make_shared(matmul)}; - function = std::make_shared(results, params, "PerchannelQuantTest"); - } -}; - -TEST_P(PerchannelQuantTest, CompareWithRefImpl) { - LoadNetwork(); - GenerateInputs(); - Infer(); - auto results = GetOutputs(); - size_t size = results.front()->size(); - auto memory = InferenceEngine::as(results.front()); - IE_ASSERT(memory); - const auto lockedMemory = memory->wmap(); - const auto actualBuffer = lockedMemory.as(); - - // check that outputs haven't been zero out by a channel multilplier - for (size_t i = 0; i < size; ++i) { - if (actualBuffer[i] == 0.0) { - IE_THROW() << "Unexpected 0 output value"; - } - } -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -const std::vector> weightsValues = {{-0.1, 0.1}, {-1.0, 1.0}, {-10.0, 10.0}}; - -const std::vector> inputShapes = {{1, 128}, {1, 38}, {1, 8}}; - -INSTANTIATE_TEST_SUITE_P(smoke_base, - PerchannelQuantTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(weightsValues), - ::testing::ValuesIn(inputShapes)), - PerchannelQuantTest::getTestCaseName); -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/scale_factors_tests/test_fq_scale_factors.cpp b/src/plugins/intel_gna/tests/functional/scale_factors_tests/test_fq_scale_factors.cpp deleted file mode 100644 index 92897c230ca..00000000000 --- a/src/plugins/intel_gna/tests/functional/scale_factors_tests/test_fq_scale_factors.cpp +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset10.hpp" -#include "openvino/opsets/opset8.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -using namespace ov::opset10; - -enum NonFunctionalLayer { RESHAPE, SQUEEZE, UNSQUEEZE, TRANSPOSE, GATHER, NONE }; - -namespace std { -inline std::ostream& operator<<(std::ostream& os, NonFunctionalLayer layer_type) { - switch (layer_type) { - case NonFunctionalLayer::RESHAPE: - os << "RESHAPE"; - break; - case NonFunctionalLayer::SQUEEZE: - os << "SQUEEZE"; - break; - case NonFunctionalLayer::UNSQUEEZE: - os << "UNSQUEEZE"; - break; - case NonFunctionalLayer::TRANSPOSE: - os << "TRANSPOSE"; - break; - case NonFunctionalLayer::GATHER: - os << "GATHER"; - break; - default: - os << "NONE"; - break; - } - return os; -} -} // namespace std - -typedef std::tuple, // Configuration - std::pair, // Input values - NonFunctionalLayer // Layer between Input and FQ - > - fqScaleFactorParams; - -namespace LayerTestsDefinitions { - -class TestFQScaleFactorsTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map configuration; - std::pair inputValues; - NonFunctionalLayer non_func_layer; - std::tie(netPrecision, targetDevice, configuration, inputValues, non_func_layer) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_range=(" << inputValues.first << ", " << inputValues.second << ")"; - result << "layer=" << non_func_layer; - - return result.str(); - } - -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::pair inputValues; - - std::tie(netPrecision, targetDevice, configuration, inputValues, m_non_func_layer) = this->GetParam(); - std::tie(inputDataMin, inputDataMax) = inputValues; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - - const ngraph::Shape shape = {1, 1, 128}; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(shape))}; - std::shared_ptr test_node = params[0]; - switch (m_non_func_layer) { - case NonFunctionalLayer::RESHAPE: - test_node = AddReshapeNode(test_node); - break; - case NonFunctionalLayer::SQUEEZE: - test_node = AddSqueezeNode(test_node); - break; - case NonFunctionalLayer::UNSQUEEZE: - test_node = AddUnSqueezeNode(test_node); - break; - case NonFunctionalLayer::TRANSPOSE: - test_node = AddTransposeNode(test_node); - break; - case NonFunctionalLayer::GATHER: - test_node = AddGatherNode(test_node, shape); - break; - default: - break; - } - - auto lowNodeIn = ngraph::builder::makeConstant(ngPrc, {1}, {inputDataMin}); - auto highNodeIn = ngraph::builder::makeConstant(ngPrc, {1}, {inputDataMax}); - auto fqIn = - std::make_shared(test_node, lowNodeIn, highNodeIn, lowNodeIn, highNodeIn, levels); - - auto mul = std::make_shared(fqIn, test_node); - - auto lowNodeOut = ngraph::builder::makeConstant(ngPrc, {1}, {-inputDataMin * inputDataMin}); - auto highNodeOut = ngraph::builder::makeConstant(ngPrc, {1}, {inputDataMax * inputDataMax}); - auto fqOut = - std::make_shared(mul, lowNodeOut, highNodeOut, lowNodeOut, highNodeOut, levels); - - ngraph::ResultVector results{std::make_shared(fqOut)}; - function = std::make_shared(results, params, "FQWithSmallScaleFactor"); - functionRefs = ngraph::clone_function(*function); - } - - std::shared_ptr AddReshapeNode(std::shared_ptr node) { - const ov::Shape reshape_pattern = {1, 128}; - auto reshape_const = - std::make_shared(ov::element::i32, ov::Shape{reshape_pattern.size()}, reshape_pattern); - auto reshape = std::make_shared(node, reshape_const, false); - return reshape; - } - - std::shared_ptr AddSqueezeNode(std::shared_ptr node) { - const ov::Shape sq_dims = {0, 1}; - auto sq_axes = std::make_shared(ov::element::i32, ov::Shape{sq_dims.size()}, sq_dims); - auto sq_node = std::make_shared(node, sq_axes); - return sq_node; - } - - std::shared_ptr AddUnSqueezeNode(std::shared_ptr node) { - const ov::Shape unsq_dims = {0}; - auto unsq_axes = std::make_shared(ov::element::i32, ov::Shape{unsq_dims.size()}, unsq_dims); - auto unsq_node = std::make_shared(node, unsq_axes); - return unsq_node; - } - - std::shared_ptr AddTransposeNode(std::shared_ptr node) { - const ov::Shape transpose_axes = {0, 2, 1}; - auto transpose_const = - std::make_shared(ov::element::i32, ov::Shape{transpose_axes.size()}, transpose_axes); - auto transpose = std::make_shared(node, transpose_const); - return transpose; - } - - std::shared_ptr AddGatherNode(std::shared_ptr node, ov::Shape shape) { - ov::Shape gather_indices(shape.size()); - std::iota(gather_indices.begin(), gather_indices.end(), 0); - - auto gather_const = - std::make_shared(ov::element::i32, ov::Shape{gather_indices.size()}, gather_indices); - auto gather_axis_const = Constant::create(ov::element::i64, ov::Shape{}, {shape.size() - 1}); - auto gather = std::make_shared(node, gather_const, gather_axis_const); - return gather; - } - - NonFunctionalLayer m_non_func_layer = NonFunctionalLayer::NONE; - float inputDataMax = 1.0; - float inputDataMin = -1.0; - size_t levels = std::numeric_limits::max(); -}; - -TEST_P(TestFQScaleFactorsTest, CompareWithRefImpl) { - LoadNetwork(); - GenerateInputs(); - Infer(); - auto refs = CalculateRefs(); - auto results = GetOutputs(); - const auto expected = reinterpret_cast(refs.front().second.data()); - size_t size = results.front()->size(); - auto memory = InferenceEngine::as(results.front()); - IE_ASSERT(memory); - const auto lockedMemory = memory->wmap(); - const auto actualBuffer = lockedMemory.as(); - - /* the absolute threshold is calculated as 1.25 * (1 / last_fq_out_scale_factor) = 1.25 * (2 * maxValue) / (levels - - 1), the most of accuracy degradation in this model is introduced by the output scale factor of FakeQuantize, 1 / sf - is a part of the value which can be represented by one level, so we can't get more accurate resolution than this - part, maxValue = inputDataMax * inputDataMax since this model multiplies input values with itself, - 1.25 is a reserve factor to cover other errors in this model */ - abs_threshold = 2.5 * inputDataMax * inputDataMax / (levels - 1); - - for (size_t i = 0; i < size; ++i) { - const auto& ref = expected[i]; - const auto& res = actualBuffer[i]; - if (ov::test::utils::ie_abs(res - ref) > abs_threshold) { - IE_THROW() << "Absolute comparison of values expected: " << ref << " and actual: " << res << " at index " - << i << " with absolute threshold " << abs_threshold << " failed"; - } - } -}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{ - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, -}}; - -// Need to enable Gather when it is supported by the plugin -const std::vector non_func_layers = {NONE, RESHAPE, SQUEEZE, UNSQUEEZE, TRANSPOSE}; - -const std::vector> inputValues = {{-188.0, 188.0}, {-90.0, 90.0}, {-20.0, 20.0}, {-10.0, 10.0}}; - -INSTANTIATE_TEST_SUITE_P(smoke_base, - TestFQScaleFactorsTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputValues), - ::testing::ValuesIn(non_func_layers)), - TestFQScaleFactorsTest::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/scale_factors_tests/weighable_layer_without_fq.cpp b/src/plugins/intel_gna/tests/functional/scale_factors_tests/weighable_layer_without_fq.cpp deleted file mode 100644 index ef2b2da8d29..00000000000 --- a/src/plugins/intel_gna/tests/functional/scale_factors_tests/weighable_layer_without_fq.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include - -#include "openvino/opsets/opset8.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -namespace SubgraphTestsDefinitions { - -typedef std::tuple, // Input shape; - std::vector, // Constant shape; - LayerTestsUtils::TargetDevice, // Device name - std::map // Additional backend configuration and alis name to it - > - WeighableLayerWithoutFqParamsSet; - -/* - * This test emulates cases in which the ConcatAlignFilter layer is created and the model has FakeQuantize layers. - */ -class WeighableLayerWithoutFqTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - std::map config; - std::vector inputShape; - std::vector constantShape; - std::tie(netPrecision, constantShape, inputShape, targetDevice, config) = obj.param; - - std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; - result << "trgDev=" << targetDevice; - for (auto const& configItem : config) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - return result.str(); - } - -protected: - void SetUp() override { - std::map config; - InferenceEngine::Precision netPrecision; - std::vector inputShape; - std::vector constantShape; - std::tie(netPrecision, constantShape, inputShape, targetDevice, config) = this->GetParam(); - configuration.insert(config.begin(), config.end()); - - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto relu = std::make_shared(params[0]); - auto fq1 = - std::make_shared(relu, - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-10.}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {10.}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-10.}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {10.}), - static_cast(std::numeric_limits::max()) + 1); - auto constant = ngraph::builder::makeConstant(ngPrc, constantShape, std::vector{}, true); - auto fq2 = - std::make_shared(constant, - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-10}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {10.}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-10.}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {10.}), - static_cast(std::numeric_limits::max()) + 1); - auto concat = std::make_shared(ov::NodeVector{fq1, fq2}, 1); - function = std::make_shared(concat, params, "WeighableLayerWithoutFq"); - } -}; // class WeighableLayerWithoutFqTest - -TEST_P(WeighableLayerWithoutFqTest, CompareWithRefs) { - Run(); -} - -namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -const std::vector> inputShapes = {{{1, 5}}}; - -const std::vector> constantShapes = {{{1, 16}}}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_WeighableLayerWithoutFqTest, - WeighableLayerWithoutFqTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(constantShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - WeighableLayerWithoutFqTest::getTestCaseName); -} // namespace -} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/executable_network/exec_net_base.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/executable_network/exec_net_base.cpp deleted file mode 100644 index 0d4802ee5ce..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/executable_network/exec_net_base.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/executable_network/exec_network_base.hpp" - -using namespace BehaviorTestsDefinitions; -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = { - {}, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - ExecutableNetworkBaseTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ExecutableNetworkBaseTest::getTestCaseName); - -const std::vector setPRC = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::U8, - InferenceEngine::Precision::I16}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - ExecNetSetPrecision, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ExecNetSetPrecision::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/executable_network/get_metric.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/executable_network/get_metric.cpp deleted file mode 100644 index 5b169831397..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/executable_network/get_metric.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/executable_network/get_metric.hpp" - -#include - -using namespace BehaviorTestsDefinitions; - -namespace { -// -// Executable Network GetMetric -// - -// TODO: Convolution with 3D input is not supported on GNA -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassExecutableNetworkGetMetricTest, - IEClassExecutableNetworkGetMetricTest_SUPPORTED_CONFIG_KEYS, - ::testing::Values("GNA" /*, "MULTI:GNA", "HETERO:GNA" */)); - -// TODO: Convolution with 3D input is not supported on GNA -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassExecutableNetworkGetMetricTest, - IEClassExecutableNetworkGetMetricTest_SUPPORTED_METRICS, - ::testing::Values("GNA" /*, "MULTI:GNA", "HETERO:GNA" */)); - -// TODO: this metric is not supported by the plugin -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassExecutableNetworkGetMetricTest, - IEClassExecutableNetworkGetMetricTest_NETWORK_NAME, - ::testing::Values("GNA", /* "MULTI:GNA", */ "HETERO:GNA")); - -// TODO: Convolution with 3D input is not supported on GNA -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassExecutableNetworkGetMetricTest, - IEClassExecutableNetworkGetMetricTest_OPTIMAL_NUMBER_OF_INFER_REQUESTS, - ::testing::Values("GNA" /*, "MULTI:GNA", "HETERO:GNA" */)); - -// TODO: Convolution with 3D input is not supported on GNA -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassExecutableNetworkGetMetricTest, - IEClassExecutableNetworkGetMetricTest_ThrowsUnsupported, - ::testing::Values("GNA", /* "MULTI:GNA", */ "HETERO:GNA")); - -// -// Executable Network GetConfig / SetConfig -// - -// TODO: Convolution with 3D input is not supported on GNA -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassExecutableNetworkGetConfigTest, - IEClassExecutableNetworkGetConfigTest, - ::testing::Values("GNA")); - -// TODO: Convolution with 3D input is not supported on GNA -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassExecutableNetworkSetConfigTest, - IEClassExecutableNetworkSetConfigTest, - ::testing::Values("GNA")); - -IE_SUPPRESS_DEPRECATED_START -// TODO: Convolution with 3D input is not supported on GNA -INSTANTIATE_TEST_SUITE_P( - DISABLED_smoke_IEClassExecutableNetworkSupportedConfigTest, - IEClassExecutableNetworkSupportedConfigTest, - ::testing::Combine( - ::testing::Values("GNA"), - ::testing::Values(std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_HW), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_SW), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_SW_EXACT), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_AUTO)))); -IE_SUPPRESS_DEPRECATED_END - -// TODO: Convolution with 3D input is not supported on GNA -INSTANTIATE_TEST_SUITE_P( - DISABLED_smoke_IEClassExecutableNetworkUnsupportedConfigTest, - IEClassExecutableNetworkUnsupportedConfigTest, - ::testing::Combine(::testing::Values("GNA"), - ::testing::Values(std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), - InferenceEngine::GNAConfigParams::GNA_SW_FP32), - std::make_pair(GNA_CONFIG_KEY(SCALE_FACTOR), "5"), - std::make_pair(CONFIG_KEY(EXCLUSIVE_ASYNC_REQUESTS), CONFIG_VALUE(YES)), - std::make_pair(GNA_CONFIG_KEY(COMPACT_MODE), CONFIG_VALUE(NO))))); - -using IEClassExecutableNetworkSetConfigFromFp32Test = IEClassExecutableNetworkGetMetricTestForSpecificConfig; - -TEST_P(IEClassExecutableNetworkSetConfigFromFp32Test, SetConfigFromFp32Throws) { - InferenceEngine::Core ie; - - std::map initialConfig; - initialConfig[GNA_CONFIG_KEY(DEVICE_MODE)] = InferenceEngine::GNAConfigParams::GNA_SW_FP32; - InferenceEngine::ExecutableNetwork exeNetwork = ie.LoadNetwork(simpleCnnNetwork, target_device, initialConfig); - - ASSERT_THROW(exeNetwork.SetConfig({{configKey, configValue}}), InferenceEngine::Exception); -} - -IE_SUPPRESS_DEPRECATED_START -// TODO: Convolution with 3D input is not supported on GNA -INSTANTIATE_TEST_SUITE_P( - DISABLED_smoke_IEClassExecutableNetworkSetConfigFromFp32Test, - IEClassExecutableNetworkSetConfigFromFp32Test, - ::testing::Combine( - ::testing::Values("GNA"), - ::testing::Values(std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_HW), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_SW), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_SW_EXACT), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_SW_FP32), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_AUTO)))); -IE_SUPPRESS_DEPRECATED_END - -// -// Hetero Executable Network GetMetric -// - -// TODO: verify hetero interop -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassHeteroExecutableNetworlGetMetricTest, - IEClassHeteroExecutableNetworkGetMetricTest_SUPPORTED_CONFIG_KEYS, - ::testing::Values("GNA")); - -// TODO: verify hetero interop -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassHeteroExecutableNetworlGetMetricTest, - IEClassHeteroExecutableNetworkGetMetricTest_SUPPORTED_METRICS, - ::testing::Values("GNA")); - -// TODO: verify hetero interop -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassHeteroExecutableNetworlGetMetricTest, - IEClassHeteroExecutableNetworkGetMetricTest_NETWORK_NAME, - ::testing::Values("GNA")); - -INSTANTIATE_TEST_SUITE_P(smoke_IEClassHeteroExecutableNetworlGetMetricTest, - IEClassHeteroExecutableNetworkGetMetricTest_TARGET_FALLBACK, - ::testing::Values("GNA")); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/callback.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/callback.cpp deleted file mode 100644 index 3eecd3ee55f..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/callback.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/infer_request/callback.hpp" - -using namespace BehaviorTestsDefinitions; -namespace { -const std::vector> configs = { - {}, -}; - -const std::vector> multiConfigs = { - {{MULTI_CONFIG_KEY(DEVICE_PRIORITIES), ov::test::utils::DEVICE_GNA}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - InferRequestCallbackTests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - InferRequestCallbackTests::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Multi_BehaviorTests, - InferRequestCallbackTests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_MULTI), - ::testing::ValuesIn(multiConfigs)), - InferRequestCallbackTests::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/config.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/config.cpp deleted file mode 100644 index 74452979d91..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/config.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/infer_request/config.hpp" - -#include "gna/gna_config.hpp" - -using namespace BehaviorTestsDefinitions; -namespace { -const std::vector> configs = {{}}; - -IE_SUPPRESS_DEPRECATED_START -const std::vector> Inconfigs = { - {{InferenceEngine::GNAConfigParams::KEY_GNA_SCALE_FACTOR, "1.0"}}, - {{InferenceEngine::GNAConfigParams::KEY_GNA_PRECISION, "I8"}}, - {{InferenceEngine::GNAConfigParams::KEY_GNA_FIRMWARE_MODEL_IMAGE, "gfile"}, - {InferenceEngine::GNAConfigParams::KEY_GNA_EXEC_TARGET, InferenceEngine::GNAConfigParams::GNA_TARGET_2_0}, - {InferenceEngine::GNAConfigParams::KEY_GNA_COMPILE_TARGET, InferenceEngine::GNAConfigParams::GNA_TARGET_2_0}}, - {{InferenceEngine::GNAConfigParams::KEY_GNA_DEVICE_MODE, InferenceEngine::GNAConfigParams::GNA_AUTO}}, - {{InferenceEngine::GNAConfigParams::KEY_GNA_DEVICE_MODE, InferenceEngine::GNAConfigParams::GNA_SW_FP32}}, - {{InferenceEngine::GNAConfigParams::KEY_GNA_DEVICE_MODE, InferenceEngine::GNAConfigParams::GNA_SW}}, - {{InferenceEngine::GNAConfigParams::KEY_GNA_DEVICE_MODE, InferenceEngine::GNAConfigParams::GNA_SW_EXACT}}, - {{InferenceEngine::GNAConfigParams::KEY_GNA_COMPACT_MODE, InferenceEngine::PluginConfigParams::NO}}}; -IE_SUPPRESS_DEPRECATED_END - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - InferRequestConfigTest, - ::testing::Combine(::testing::Values(0u), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - InferRequestConfigTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/io_blob.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/io_blob.cpp deleted file mode 100644 index fb609226211..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/io_blob.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/infer_request/io_blob.hpp" - -using namespace BehaviorTestsDefinitions; -namespace { -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - InferRequestIOBBlobTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(std::map({}))), - InferRequestIOBBlobTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/memory_states.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/memory_states.cpp deleted file mode 100644 index 43d7c2eca86..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/memory_states.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/infer_request/memory_states.hpp" - -#include - -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" - -using namespace BehaviorTestsDefinitions; - -namespace { -std::vector memoryStateTestCases = {memoryStateParams(InferRequestVariableStateTest::getNetwork(), - {"c_1-3", "r_1-3"}, - ov::test::utils::DEVICE_GNA, - {})}; - -INSTANTIATE_TEST_SUITE_P(smoke_VariableStateBasic, - InferRequestVariableStateTest, - ::testing::ValuesIn(memoryStateTestCases), - InferRequestVariableStateTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/multitheading.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/multitheading.cpp deleted file mode 100644 index b55a4384ef7..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/multitheading.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/infer_request/multithreading.hpp" - -using namespace BehaviorTestsDefinitions; -namespace { -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - InferRequestMultithreadingTests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(std::map({}))), - InferRequestMultithreadingTests::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/wait.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/wait.cpp deleted file mode 100644 index 399f9e1dc3e..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/infer_request/wait.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/infer_request/wait.hpp" - -using namespace BehaviorTestsDefinitions; -namespace { -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - InferRequestWaitTests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(std::map({}))), - InferRequestWaitTests::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_executable_network/exec_graph_info.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_executable_network/exec_graph_info.cpp deleted file mode 100644 index ac913c3073e..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_executable_network/exec_graph_info.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include - -#include "behavior/compiled_model/import_export.hpp" -#include "ie_plugin_config.hpp" - -using namespace ov::test::behavior; -namespace { -const std::vector netPrecisions = {ov::element::i16, ov::element::u8, ov::element::f32}; -const std::vector configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVCompiledGraphImportExportTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - OVCompiledGraphImportExportTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_executable_network/exec_net_base.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_executable_network/exec_net_base.cpp deleted file mode 100644 index 0028963b91f..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_executable_network/exec_net_base.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/compiled_model/compiled_model_base.hpp" - -using namespace ov::test::behavior; -namespace { -const std::vector configs = { - {}, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVCompiledModelBaseTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - OVCompiledModelBaseTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVCompiledModelBaseTestOptional, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - OVCompiledModelBaseTestOptional::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_executable_network/get_metric.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_executable_network/get_metric.cpp deleted file mode 100644 index a84648cf4a8..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_executable_network/get_metric.cpp +++ /dev/null @@ -1,252 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "behavior/compiled_model/properties.hpp" -#include "openvino/runtime/intel_gna/properties.hpp" - -using namespace ov::test::behavior; - -namespace { -// -// Executable Network GetMetric -// -class OVClassNetworkTestGNA : public ::testing::Test { -public: - std::shared_ptr gnaSimpleNetwork; - - void SetUp() override { - SKIP_IF_CURRENT_TEST_IS_DISABLED(); - - auto param0 = std::make_shared(ngraph::element::Type_t::f32, ngraph::Shape(1, 1024)); - auto reshape = - std::make_shared(param0, - std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{4}, - ngraph::Shape{1, 1, 1, 1024}), - false); - param0->set_friendly_name("input"); - auto conv1 = ngraph::builder::makeConvolution(reshape, - ngraph::element::Type_t::f32, - {1, 7}, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ngraph::op::PadType::EXPLICIT, - 4); - auto result = std::make_shared(conv1); - gnaSimpleNetwork = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{param0}); - gnaSimpleNetwork->set_friendly_name("GnaSingleConv"); - } -}; - -class OVClassBaseTestGNAP : public OVClassNetworkTestGNA, public ::testing::WithParamInterface { -public: - std::string deviceName; - - void SetUp() override { - SKIP_IF_CURRENT_TEST_IS_DISABLED(); - OVClassNetworkTestGNA::SetUp(); - deviceName = GetParam(); - } -}; - -class OVClassCompiledModelGetPropertyTestForSpecificConfigGNA - : public OVClassNetworkTestGNA, - public ::testing::WithParamInterface>> { -protected: - std::string deviceName; - std::string configKey; - ov::Any configValue; - -public: - void SetUp() override { - SKIP_IF_CURRENT_TEST_IS_DISABLED(); - OVClassNetworkTestGNA::SetUp(); - deviceName = std::get<0>(GetParam()); - std::tie(configKey, configValue) = std::get<1>(GetParam()); - } -}; - -using OVGNAClassExecutableNetworkGetMetricTest_SUPPORTED_CONFIG_KEYS = OVClassBaseTestGNAP; -using OVGNAClassExecutableNetworkGetMetricTest_SUPPORTED_METRICS = OVClassBaseTestGNAP; -using OVGNAClassExecutableNetworkGetMetricTest_NETWORK_NAME = OVClassBaseTestGNAP; -using OVGNAClassExecutableNetworkGetMetricTest_OPTIMAL_NUMBER_OF_INFER_REQUESTS = OVClassBaseTestGNAP; -using OVGNAClassExecutableNetworkGetMetricTest_ThrowsUnsupported = OVClassBaseTestGNAP; - -INSTANTIATE_TEST_SUITE_P(smoke_OVClassCompiledModelGetPropertyTest, - OVGNAClassExecutableNetworkGetMetricTest_SUPPORTED_CONFIG_KEYS, - ::testing::Values("GNA" /*, "MULTI:GNA"*/, "HETERO:GNA")); - -INSTANTIATE_TEST_SUITE_P(smoke_OVClassCompiledModelGetPropertyTest, - OVGNAClassExecutableNetworkGetMetricTest_SUPPORTED_METRICS, - ::testing::Values("GNA" /*, "MULTI:GNA"*/, "HETERO:GNA")); - -INSTANTIATE_TEST_SUITE_P(smoke_OVClassCompiledModelGetPropertyTest, - OVGNAClassExecutableNetworkGetMetricTest_NETWORK_NAME, - ::testing::Values("GNA" /*, "MULTI:GNA"*/, "HETERO:GNA")); - -INSTANTIATE_TEST_SUITE_P(smoke_OVClassCompiledModelGetPropertyTest, - OVGNAClassExecutableNetworkGetMetricTest_OPTIMAL_NUMBER_OF_INFER_REQUESTS, - ::testing::Values("GNA" /*, "MULTI:GNA"*/, "HETERO:GNA")); - -INSTANTIATE_TEST_SUITE_P(smoke_OVClassCompiledModelGetPropertyTest, - OVGNAClassExecutableNetworkGetMetricTest_ThrowsUnsupported, - ::testing::Values("GNA" /*, "MULTI:GNA"*/, "HETERO:GNA")); - -// -// Executable Network GetConfig / SetConfig -// - -using OVGNAClassExecutableNetworkGetConfigTest = OVClassBaseTestGNAP; -using OVGNAClassExecutableNetworkSetConfigTest = OVClassBaseTestGNAP; - -INSTANTIATE_TEST_SUITE_P(moke_OVClassCompiledModelGetConfigTest, - OVGNAClassExecutableNetworkGetConfigTest, - ::testing::Values("GNA")); - -INSTANTIATE_TEST_SUITE_P(smoke_OVClassCompiledModelGetIncorrectPropertyTest, - OVClassCompiledModelGetIncorrectPropertyTest, - ::testing::Values("GNA")); - -INSTANTIATE_TEST_SUITE_P(smoke_OVClassCompiledModelGetConfigTest, - OVClassCompiledModelGetConfigTest, - ::testing::Values("GNA")); - -INSTANTIATE_TEST_SUITE_P(smoke_OVClassCompiledModelSetIncorrectConfigTest, - OVGNAClassExecutableNetworkSetConfigTest, - ::testing::Values("GNA")); - -using OVGNAClassExecutableNetworkSupportedConfigTest = OVClassCompiledModelGetPropertyTestForSpecificConfigGNA; -using OVGNAClassExecutableNetworkUnsupportedConfigTest = OVClassCompiledModelGetPropertyTestForSpecificConfigGNA; - -IE_SUPPRESS_DEPRECATED_START -INSTANTIATE_TEST_SUITE_P( - smoke_OVClassExecutableNetworkSupportedConfigTest, - OVGNAClassExecutableNetworkSupportedConfigTest, - ::testing::Combine( - ::testing::Values("GNA"), - ::testing::Values(std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_HW), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_SW), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_SW_EXACT), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_AUTO)))); -IE_SUPPRESS_DEPRECATED_END - -INSTANTIATE_TEST_SUITE_P( - smoke_OVClassExecutableNetworkUnsupportedConfigTest, - OVGNAClassExecutableNetworkUnsupportedConfigTest, - ::testing::Combine(::testing::Values("GNA"), - ::testing::Values(std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), - InferenceEngine::GNAConfigParams::GNA_SW_FP32), - std::make_pair(GNA_CONFIG_KEY(SCALE_FACTOR), "5"), - std::make_pair(CONFIG_KEY(EXCLUSIVE_ASYNC_REQUESTS), CONFIG_VALUE(YES)), - std::make_pair(GNA_CONFIG_KEY(COMPACT_MODE), CONFIG_VALUE(NO))))); - -using OVClassExecutableNetworkSetConfigFromFp32Test = OVClassCompiledModelGetPropertyTestForSpecificConfigGNA; -using OVClassExecutableNetworkSetConfigROProperties = OVClassCompiledModelGetPropertyTestForSpecificConfigGNA; - -TEST_P(OVClassExecutableNetworkSetConfigFromFp32Test, SetConfigFromFp32Throws) { - ov::Core ie; - - ov::AnyMap initialConfig; - - ov::CompiledModel exeNetwork = - ie.compile_model(gnaSimpleNetwork, - deviceName, - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_FP32)); - - ASSERT_THROW(exeNetwork.set_property({{configKey, configValue}}), ov::Exception); -} - -INSTANTIATE_TEST_SUITE_P( - smoke_OVClassExecutableNetworkSetConfigFromFp32Test, - OVClassExecutableNetworkSetConfigFromFp32Test, - ::testing::Combine( - ::testing::Values("GNA"), - ::testing::Values(std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_HW), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), - InferenceEngine::GNAConfigParams::GNA_HW_WITH_SW_FBACK), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_SW_EXACT), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_SW_FP32), - std::make_pair(GNA_CONFIG_KEY(DEVICE_MODE), InferenceEngine::GNAConfigParams::GNA_AUTO), - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::HW), - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::HW_WITH_SW_FBACK), - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_EXACT), - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_FP32), - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::AUTO)))); - -TEST_P(OVClassExecutableNetworkSetConfigROProperties, SetConfigROPropertiesThrows) { - ov::Core ie; - std::vector properties; - - ov::CompiledModel exeNetwork = ie.compile_model(gnaSimpleNetwork, deviceName); - - ASSERT_NO_THROW(properties = exeNetwork.get_property(ov::supported_properties)); - - auto it = find(properties.begin(), properties.end(), configKey); - ASSERT_TRUE(it != properties.end()); - ASSERT_FALSE(it->is_mutable()); - - ASSERT_THROW(exeNetwork.set_property({{configKey, configValue}}), ov::Exception); -} - -INSTANTIATE_TEST_SUITE_P( - smoke_OVClassExecutableNetworkSetConfigROProperties, - OVClassExecutableNetworkSetConfigROProperties, - ::testing::Combine( - ::testing::Values("GNA"), - ::testing::Values(ov::intel_gna::scale_factors_per_input(std::map{{"0", 1.0f}}), - ov::hint::inference_precision(ngraph::element::i8), - ov::hint::num_requests(2), - ov::intel_gna::pwl_design_algorithm(ov::intel_gna::PWLDesignAlgorithm::UNIFORM_DISTRIBUTION), - ov::intel_gna::pwl_max_error_percent(0.2), - ov::intel_gna::firmware_model_image_path(""), - ov::intel_gna::compile_target(ov::intel_gna::HWGeneration::GNA_3_0), - ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::GNA_3_0)))); - -using OVClassExecutableNetworkDevicePropertiesTest = OVClassCompiledModelGetPropertyTestForSpecificConfigGNA; -TEST_P(OVClassExecutableNetworkDevicePropertiesTest, DevicePropertiesNoThrow) { - ov::Core ie; - ASSERT_NO_THROW(auto compiled_model = - ie.compile_model(gnaSimpleNetwork, - deviceName, - ov::device::properties("GNA", ov::AnyMap{{configKey, configValue}}))); -} - -INSTANTIATE_TEST_SUITE_P( - smoke_OVClassExecutableNetworkDevicePropertiesTest, - OVClassExecutableNetworkDevicePropertiesTest, - ::testing::Combine( - ::testing::Values("HETERO:GNA"), - ::testing::Values(ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::HW), - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::HW_WITH_SW_FBACK), - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_EXACT), - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_FP32), - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::AUTO), - ov::intel_gna::scale_factors_per_input(std::map{{"input", 1.0f}}), - ov::hint::inference_precision(ov::element::i8), - ov::hint::inference_precision(ov::element::i16), - ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY), - ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT), - ov::hint::num_requests(1), - ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::GNA_2_0), - ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::GNA_3_0), - ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::UNDEFINED), - ov::intel_gna::compile_target(ov::intel_gna::HWGeneration::GNA_2_0), - ov::intel_gna::compile_target(ov::intel_gna::HWGeneration::GNA_3_0), - ov::intel_gna::compile_target(ov::intel_gna::HWGeneration::UNDEFINED), - ov::intel_gna::pwl_design_algorithm(ov::intel_gna::PWLDesignAlgorithm::RECURSIVE_DESCENT), - ov::intel_gna::pwl_design_algorithm(ov::intel_gna::PWLDesignAlgorithm::UNIFORM_DISTRIBUTION), - ov::intel_gna::pwl_max_error_percent(0.05), - ov::log::level(ov::log::Level::NO)))); - -// IE Class Load network - -INSTANTIATE_TEST_SUITE_P(smoke_OVCompiledModelIncorrectDevice, - OVCompiledModelIncorrectDevice, - ::testing::Values("GNA")); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/callback.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/callback.cpp deleted file mode 100644 index 6578c1c4c47..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/callback.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/ov_infer_request/callback.hpp" - -using namespace ov::test::behavior; - -namespace { -const std::vector configs = { - {}, -}; - -const std::vector multiConfigs = {{ov::device::priorities(ov::test::utils::DEVICE_GNA)}}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVInferRequestCallbackTests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - OVInferRequestCallbackTests::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Multi_BehaviorTests, - OVInferRequestCallbackTests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_MULTI), - ::testing::ValuesIn(multiConfigs)), - OVInferRequestCallbackTests::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/cancellation.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/cancellation.cpp deleted file mode 100644 index 3dc74ed007b..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/cancellation.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/ov_infer_request/cancellation.hpp" - -using namespace ov::test::behavior; - -namespace { -const std::vector configs = { - {}, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVInferRequestCancellationTests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - OVInferRequestCancellationTests::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/infer_request_dynamic.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/infer_request_dynamic.cpp deleted file mode 100644 index da69df5a58f..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/infer_request_dynamic.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/ov_infer_request/infer_request_dynamic.hpp" - -#include - -#include "common_test_utils/subgraph_builders/split_conv_concat.hpp" - -using namespace ov::test::behavior; - -namespace { -const std::vector configs = {{}}; - -INSTANTIATE_TEST_SUITE_P( - smoke_BehaviorTests, - OVInferRequestDynamicTests, - ::testing::Combine(::testing::Values(ov::test::utils::make_split_conv_concat()), - ::testing::Values(std::vector, std::vector>>{ - {{1, 4, 20, 20}, {1, 10, 18, 18}}, - {{2, 4, 20, 20}, {2, 10, 18, 18}}}), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - OVInferRequestDynamicTests::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/inference_chaining.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/inference_chaining.cpp deleted file mode 100644 index 9d1442ed3ea..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/inference_chaining.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/ov_infer_request/inference_chaining.hpp" - -#include "common_test_utils/test_constants.hpp" - -using namespace ov::test::behavior; -namespace { - -// GNA_SW_EXACT mode excluded from the tests because without quantization we got the bad accuracy for this test -const std::vector device_modes{{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVInferenceChaining, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(device_modes)), - OVInferenceChaining::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVInferenceChainingStatic, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(device_modes)), - OVInferenceChainingStatic::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/io_tensor.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/io_tensor.cpp deleted file mode 100644 index 9975905a30b..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/io_tensor.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/ov_infer_request/io_tensor.hpp" - -#include - -using namespace ov::test::behavior; - -namespace { -const std::vector configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}, {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -std::vector prcs = { - ov::element::boolean, - ov::element::bf16, - ov::element::f16, - ov::element::f32, - ov::element::f64, - ov::element::i4, - ov::element::i8, - ov::element::i16, - ov::element::i32, - ov::element::i64, - ov::element::u1, - ov::element::u4, - ov::element::u8, - ov::element::u16, - ov::element::u32, - ov::element::u64, -}; - -std::vector supported_input_prcs = {ov::element::f32, ov::element::i16, ov::element::u8}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVInferRequestIOTensorTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - OVInferRequestIOTensorTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVInferRequestIOTensorSetPrecisionTest, - ::testing::Combine(::testing::ValuesIn(prcs), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - OVInferRequestIOTensorSetPrecisionTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVInferRequestCheckTensorPrecision, - ::testing::Combine(::testing::ValuesIn(supported_input_prcs), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - OVInferRequestCheckTensorPrecision::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/multithreading.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/multithreading.cpp deleted file mode 100644 index 3eefcf3d142..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/multithreading.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/ov_infer_request/multithreading.hpp" - -using namespace ov::test::behavior; -namespace { - -OPENVINO_SUPPRESS_DEPRECATED_START - -const std::vector configs = {{{GNA_CONFIG_KEY(LIB_N_THREADS), "3"}}}; - -OPENVINO_SUPPRESS_DEPRECATED_END - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVInferRequestMultithreadingTests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - OVInferRequestMultithreadingTests::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/wait.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/wait.cpp deleted file mode 100644 index dbee483584c..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_infer_request/wait.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/ov_infer_request/wait.hpp" - -using namespace ov::test::behavior; -namespace { -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVInferRequestWaitTests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(ov::AnyMap({}))), - OVInferRequestWaitTests::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp deleted file mode 100644 index 5b80420b3c5..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/ov_plugin/caching_tests.hpp" - -using namespace ov::test::behavior; - -namespace { -static const std::vector precisionsGNA = { - ngraph::element::f32, - // integer weights are not supported by GNA so far - // ngraph::element::u8, - // ngraph::element::i16, -}; - -static const std::vector batchSizesGNA = {1, 2}; - -INSTANTIATE_TEST_SUITE_P(smoke_CachingSupportCase_GNA, - CompileModelCacheTestBase, - ::testing::Combine(::testing::ValuesIn(CompileModelCacheTestBase::getStandardFunctions()), - ::testing::ValuesIn(precisionsGNA), - ::testing::ValuesIn(batchSizesGNA), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(ov::AnyMap{})), - CompileModelCacheTestBase::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/core_integration.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/core_integration.cpp deleted file mode 100644 index 6a5e19ec24d..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/core_integration.cpp +++ /dev/null @@ -1,381 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "behavior/ov_plugin/core_integration.hpp" - -#include "behavior/compiled_model/properties.hpp" -#include "behavior/ov_plugin/core_integration_sw.hpp" -#include "behavior/ov_plugin/properties_tests.hpp" -#include "behavior/ov_plugin/query_model.hpp" -#include "gna/gna_config.hpp" -#include "openvino/runtime/intel_gna/properties.hpp" - -using namespace ov::test::behavior; - -namespace { - -// -// IE Class Common tests with -// - -INSTANTIATE_TEST_SUITE_P(nightly_OVBasicPropertiesTestsP, - OVBasicPropertiesTestsP, - ::testing::Values(std::make_pair("openvino_intel_gna_plugin", "GNA"))); - -// TODO -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_OVClassModelTestP, OVClassModelTestP, ::testing::Values("GNA")); -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_OVClassModelOptionalTestP, OVClassModelOptionalTestP, ::testing::Values("GNA")); - -// -// IE Class GetMetric -// - -INSTANTIATE_TEST_SUITE_P(smoke_MultiHeteroOVGetMetricPropsTest, - OVGetMetricPropsTest, - ::testing::Values("MULTI", "HETERO")); - -INSTANTIATE_TEST_SUITE_P(nightly_OVGetMetricPropsTest, OVGetMetricPropsTest, ::testing::Values("GNA")); - -INSTANTIATE_TEST_SUITE_P( - smoke_MultiHeteroOVCheckGetSupportedROMetricsPropsTests, - OVCheckGetSupportedROMetricsPropsTests, - ::testing::Combine(::testing::Values("MULTI", "HETERO"), - ::testing::ValuesIn(OVCheckGetSupportedROMetricsPropsTests::configureProperties( - {ov::device::full_name.name()}))), - OVCheckGetSupportedROMetricsPropsTests::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P( - smoke_OVCheckGetSupportedROMetricsPropsTests, - OVCheckGetSupportedROMetricsPropsTests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(OVCheckGetSupportedROMetricsPropsTests::configureProperties( - {ov::device::full_name.name()}))), - OVCheckGetSupportedROMetricsPropsTests::getTestCaseName); - -const std::vector>> GetMetricTest_ExecutionDevice_GNA = { - {"GNA", std::make_pair(ov::AnyMap{}, "GNA")}}; - -INSTANTIATE_TEST_SUITE_P(nightly_OVClassCompiledModelGetPropertyTest, - OVClassCompiledModelGetPropertyTest_EXEC_DEVICES, - ::testing::ValuesIn(GetMetricTest_ExecutionDevice_GNA)); - -INSTANTIATE_TEST_SUITE_P(nightly_OVGetAvailableDevicesPropsTest, - OVGetAvailableDevicesPropsTest, - ::testing::Values("GNA")); - -// -// IE Class GetConfig -// - -INSTANTIATE_TEST_SUITE_P(nightly_OVPropertiesDefaultSupportedTests, - OVPropertiesDefaultSupportedTests, - ::testing::Values("GNA")); - -TEST(OVClassBasicPropsTest, smoke_SetConfigAfterCreatedScaleFactors) { - ov::Core core; - float sf1, sf2; - OV_ASSERT_NO_THROW(core.set_property({{"GNA_SCALE_FACTOR_0", "1634.0"}, {"GNA_SCALE_FACTOR_1", "2000.0"}})); - OV_ASSERT_NO_THROW(sf1 = std::stof(core.get_property("GNA", "GNA_SCALE_FACTOR_0").as())); - OV_ASSERT_NO_THROW(sf2 = std::stof(core.get_property("GNA", "GNA_SCALE_FACTOR_1").as())); - ASSERT_FLOAT_EQ(1634.0, sf1); - ASSERT_FLOAT_EQ(2000.0, sf2); - - ASSERT_THROW(core.set_property("GNA", - {ov::intel_gna::scale_factors_per_input( - std::map{{"input_0", 1634.0f}, {"input_1", 2000.0f}}), - {"GNA_SCALE_FACTOR_0", "1634.0"}, - {"GNA_SCALE_FACTOR_1", "2000.0"}}), - ov::Exception); -} - -TEST(OVClassBasicPropsTest, smoke_SetConfigAfterCreatedScaleFactorsPerInput) { - ov::Core core; - std::map scale_factors_per_input; - - OV_ASSERT_NO_THROW( - core.set_property("GNA", - ov::intel_gna::scale_factors_per_input( - std::map{{"input_0", 1634.0f}, {"input_1", 2000.0f}}))); - OV_ASSERT_NO_THROW(scale_factors_per_input = core.get_property("GNA", ov::intel_gna::scale_factors_per_input)); - ASSERT_EQ(2, scale_factors_per_input.size()); - ASSERT_FLOAT_EQ(1634.0f, scale_factors_per_input["input_0"]); - ASSERT_FLOAT_EQ(2000.0f, scale_factors_per_input["input_1"]); - - OV_ASSERT_NO_THROW( - core.set_property("GNA", ov::intel_gna::scale_factors_per_input(std::map{{"0", 1.0f}}))); - OV_ASSERT_NO_THROW(scale_factors_per_input = core.get_property("GNA", ov::intel_gna::scale_factors_per_input)); - ASSERT_EQ(1, scale_factors_per_input.size()); - ASSERT_FLOAT_EQ(1.0f, scale_factors_per_input["0"]); -} - -TEST(OVClassBasicPropsTest, smoke_SetConfigAfterCreatedPrecisionHint) { - ov::Core core; - ov::element::Type precision; - - OV_ASSERT_NO_THROW(precision = core.get_property("GNA", ov::hint::inference_precision)); - ASSERT_EQ(ov::element::undefined, precision); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::hint::inference_precision(ov::element::i8))); - OV_ASSERT_NO_THROW(precision = core.get_property("GNA", ov::hint::inference_precision)); - ASSERT_EQ(ov::element::i8, precision); - - OPENVINO_SUPPRESS_DEPRECATED_START - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::hint::inference_precision(ov::element::i8))); - OV_ASSERT_NO_THROW(precision = core.get_property("GNA", ov::hint::inference_precision)); - OPENVINO_SUPPRESS_DEPRECATED_END - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::hint::inference_precision(ov::element::i16))); - OV_ASSERT_NO_THROW(precision = core.get_property("GNA", ov::hint::inference_precision)); - ASSERT_EQ(ov::element::i16, precision); - - OV_ASSERT_NO_THROW(core.set_property("GNA", {{ov::hint::inference_precision.name(), "I8"}})); - OV_ASSERT_NO_THROW(precision = core.get_property("GNA", ov::hint::inference_precision)); - ASSERT_EQ(ov::element::i8, precision); - - OV_ASSERT_NO_THROW(core.set_property("GNA", {{ov::hint::inference_precision.name(), "I16"}})); - OV_ASSERT_NO_THROW(precision = core.get_property("GNA", ov::hint::inference_precision)); - ASSERT_EQ(ov::element::i16, precision); - - OV_ASSERT_NO_THROW( - core.set_property("GNA", {ov::hint::inference_precision(ov::element::i8), {GNA_CONFIG_KEY(PRECISION), "I16"}})); - ASSERT_THROW(core.set_property("GNA", ov::hint::inference_precision(ov::element::i32)), ov::Exception); - ASSERT_THROW(core.set_property("GNA", ov::hint::inference_precision(ov::element::undefined)), ov::Exception); - ASSERT_THROW(core.set_property("GNA", {{ov::hint::inference_precision.name(), "ABC"}}), ov::Exception); -} - -TEST(OVClassBasicPropsTest, smoke_SetConfigAfterCreatedPerformanceHint) { - ov::Core core; - ov::hint::PerformanceMode mode; - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY))); - OV_ASSERT_NO_THROW(mode = core.get_property("GNA", ov::hint::performance_mode)); - ASSERT_EQ(ov::hint::PerformanceMode::LATENCY, mode); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT))); - OV_ASSERT_NO_THROW(mode = core.get_property("GNA", ov::hint::performance_mode)); - ASSERT_EQ(ov::hint::PerformanceMode::THROUGHPUT, mode); - - ASSERT_THROW(core.set_property("GNA", {{ov::hint::performance_mode.name(), "ABC"}}), ov::Exception); -} - -TEST(OVClassBasicPropsTest, smoke_SetConfigAfterCreatedNumRequests) { - ov::Core core; - uint32_t num_requests; - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::hint::num_requests(8))); - OV_ASSERT_NO_THROW(num_requests = core.get_property("GNA", ov::hint::num_requests)); - ASSERT_EQ(8, num_requests); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::hint::num_requests(1))); - OV_ASSERT_NO_THROW(num_requests = core.get_property("GNA", ov::hint::num_requests)); - ASSERT_EQ(1, num_requests); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::hint::num_requests(1000))); - OV_ASSERT_NO_THROW(num_requests = core.get_property("GNA", ov::hint::num_requests)); - ASSERT_EQ(127, num_requests); // maximum value - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::hint::num_requests(0))); - OV_ASSERT_NO_THROW(num_requests = core.get_property("GNA", ov::hint::num_requests)); - ASSERT_EQ(1, num_requests); // minimum value - - OPENVINO_SUPPRESS_DEPRECATED_START - OV_ASSERT_NO_THROW(core.set_property("GNA", {ov::hint::num_requests(8), {GNA_CONFIG_KEY(LIB_N_THREADS), "8"}})); - ASSERT_THROW(core.set_property("GNA", {ov::hint::num_requests(4), {GNA_CONFIG_KEY(LIB_N_THREADS), "8"}}), - ov::Exception); - OPENVINO_SUPPRESS_DEPRECATED_END - ASSERT_THROW(core.set_property("GNA", {{ov::hint::num_requests.name(), "ABC"}}), ov::Exception); -} - -TEST(OVClassBasicPropsTest, smoke_SetConfigAfterCreatedExecutionMode) { - ov::Core core; - auto execution_mode = ov::intel_gna::ExecutionMode::AUTO; - - OV_ASSERT_NO_THROW(execution_mode = core.get_property("GNA", ov::intel_gna::execution_mode)); - ASSERT_EQ(ov::intel_gna::ExecutionMode::SW_EXACT, execution_mode); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_FP32))); - OV_ASSERT_NO_THROW(execution_mode = core.get_property("GNA", ov::intel_gna::execution_mode)); - ASSERT_EQ(ov::intel_gna::ExecutionMode::SW_FP32, execution_mode); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_EXACT))); - OV_ASSERT_NO_THROW(execution_mode = core.get_property("GNA", ov::intel_gna::execution_mode)); - ASSERT_EQ(ov::intel_gna::ExecutionMode::SW_EXACT, execution_mode); - - OV_ASSERT_NO_THROW( - core.set_property("GNA", ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::HW_WITH_SW_FBACK))); - OV_ASSERT_NO_THROW(execution_mode = core.get_property("GNA", ov::intel_gna::execution_mode)); - ASSERT_EQ(ov::intel_gna::ExecutionMode::HW_WITH_SW_FBACK, execution_mode); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::HW))); - OV_ASSERT_NO_THROW(execution_mode = core.get_property("GNA", ov::intel_gna::execution_mode)); - ASSERT_EQ(ov::intel_gna::ExecutionMode::HW, execution_mode); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::AUTO))); - OV_ASSERT_NO_THROW(execution_mode = core.get_property("GNA", ov::intel_gna::execution_mode)); - ASSERT_EQ(ov::intel_gna::ExecutionMode::AUTO, execution_mode); - - ASSERT_THROW(core.set_property("GNA", {{ov::intel_gna::execution_mode.name(), "ABC"}}), ov::Exception); - OV_ASSERT_NO_THROW(execution_mode = core.get_property("GNA", ov::intel_gna::execution_mode)); - ASSERT_EQ(ov::intel_gna::ExecutionMode::AUTO, execution_mode); -} - -TEST(OVClassBasicPropsTest, smoke_SetConfigAfterCreatedTargetDevice) { - ov::Core core; - auto execution_target = ov::intel_gna::HWGeneration::UNDEFINED; - auto compile_target = ov::intel_gna::HWGeneration::UNDEFINED; - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::GNA_2_0))); - OV_ASSERT_NO_THROW(execution_target = core.get_property("GNA", ov::intel_gna::execution_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::GNA_2_0, execution_target); - OV_ASSERT_NO_THROW(compile_target = core.get_property("GNA", ov::intel_gna::compile_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::GNA_2_0, compile_target); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::GNA_3_0))); - OV_ASSERT_NO_THROW(execution_target = core.get_property("GNA", ov::intel_gna::execution_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::GNA_3_0, execution_target); - OV_ASSERT_NO_THROW(compile_target = core.get_property("GNA", ov::intel_gna::compile_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::GNA_2_0, compile_target); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::GNA_3_5))); - OV_ASSERT_NO_THROW(execution_target = core.get_property("GNA", ov::intel_gna::execution_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::GNA_3_5, execution_target); - OV_ASSERT_NO_THROW(compile_target = core.get_property("GNA", ov::intel_gna::compile_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::GNA_2_0, compile_target); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::compile_target(ov::intel_gna::HWGeneration::GNA_3_0))); - OV_ASSERT_NO_THROW(execution_target = core.get_property("GNA", ov::intel_gna::execution_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::GNA_3_5, execution_target); - OV_ASSERT_NO_THROW(compile_target = core.get_property("GNA", ov::intel_gna::compile_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::GNA_3_0, compile_target); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::compile_target(ov::intel_gna::HWGeneration::GNA_3_5))); - OV_ASSERT_NO_THROW(execution_target = core.get_property("GNA", ov::intel_gna::execution_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::GNA_3_5, execution_target); - OV_ASSERT_NO_THROW(compile_target = core.get_property("GNA", ov::intel_gna::compile_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::GNA_3_5, compile_target); - - OV_ASSERT_NO_THROW( - core.set_property("GNA", ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::UNDEFINED))); - OV_ASSERT_NO_THROW(execution_target = core.get_property("GNA", ov::intel_gna::execution_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::UNDEFINED, execution_target); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::compile_target(ov::intel_gna::HWGeneration::UNDEFINED))); - OV_ASSERT_NO_THROW(compile_target = core.get_property("GNA", ov::intel_gna::execution_target)); - ASSERT_EQ(ov::intel_gna::HWGeneration::UNDEFINED, compile_target); - - ASSERT_THROW(core.set_property("GNA", - {ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::GNA_2_0), - {GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_3_0"}}), - ov::Exception); - ASSERT_THROW(core.set_property("GNA", - {ov::intel_gna::compile_target(ov::intel_gna::HWGeneration::GNA_2_0), - {GNA_CONFIG_KEY(COMPILE_TARGET), "GNA_TARGET_3_0"}}), - ov::Exception); - - ASSERT_THROW(core.set_property("GNA", - {ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::GNA_2_0), - {GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_3_5"}}), - ov::Exception); - ASSERT_THROW(core.set_property("GNA", - {ov::intel_gna::compile_target(ov::intel_gna::HWGeneration::GNA_2_0), - {GNA_CONFIG_KEY(COMPILE_TARGET), "GNA_TARGET_3_5"}}), - ov::Exception); - - ASSERT_THROW(core.set_property("GNA", {{ov::intel_gna::execution_target.name(), "ABC"}}), ov::Exception); - ASSERT_THROW(core.set_property("GNA", {{ov::intel_gna::compile_target.name(), "ABC"}}), ov::Exception); -} - -TEST(OVClassBasicPropsTest, smoke_SetConfigAfterCreatedPwlAlgorithm) { - ov::Core core; - auto pwl_algo = ov::intel_gna::PWLDesignAlgorithm::UNDEFINED; - float pwl_max_error = 0.0f; - - OV_ASSERT_NO_THROW( - core.set_property("GNA", - ov::intel_gna::pwl_design_algorithm(ov::intel_gna::PWLDesignAlgorithm::RECURSIVE_DESCENT))); - OV_ASSERT_NO_THROW(pwl_algo = core.get_property("GNA", ov::intel_gna::pwl_design_algorithm)); - ASSERT_EQ(ov::intel_gna::PWLDesignAlgorithm::RECURSIVE_DESCENT, pwl_algo); - - OV_ASSERT_NO_THROW(core.set_property( - "GNA", - ov::intel_gna::pwl_design_algorithm(ov::intel_gna::PWLDesignAlgorithm::UNIFORM_DISTRIBUTION))); - OV_ASSERT_NO_THROW(pwl_algo = core.get_property("GNA", ov::intel_gna::pwl_design_algorithm)); - ASSERT_EQ(ov::intel_gna::PWLDesignAlgorithm::UNIFORM_DISTRIBUTION, pwl_algo); - - ASSERT_THROW(core.set_property("GNA", {{ov::intel_gna::pwl_design_algorithm.name(), "ABC"}}), ov::Exception); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::pwl_max_error_percent(0.05))); - OV_ASSERT_NO_THROW(pwl_max_error = core.get_property("GNA", ov::intel_gna::pwl_max_error_percent)); - ASSERT_FLOAT_EQ(0.05, pwl_max_error); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::pwl_max_error_percent(100.0f))); - OV_ASSERT_NO_THROW(pwl_max_error = core.get_property("GNA", ov::intel_gna::pwl_max_error_percent)); - ASSERT_FLOAT_EQ(100.0f, pwl_max_error); - - OPENVINO_SUPPRESS_DEPRECATED_START - ASSERT_THROW( - core.set_property("GNA", - {ov::intel_gna::pwl_design_algorithm(ov::intel_gna::PWLDesignAlgorithm::RECURSIVE_DESCENT), - {GNA_CONFIG_KEY(PWL_UNIFORM_DESIGN), InferenceEngine::PluginConfigParams::YES}}), - ov::Exception); - OPENVINO_SUPPRESS_DEPRECATED_END - ASSERT_THROW(core.set_property("GNA", ov::intel_gna::pwl_max_error_percent(-1.0f)), ov::Exception); - ASSERT_THROW(core.set_property("GNA", ov::intel_gna::pwl_max_error_percent(146.0f)), ov::Exception); -} - -TEST(OVClassBasicPropsTest, smoke_SetConfigAfterCreatedLogLevel) { - ov::Core core; - auto level = ov::log::Level::NO; - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::INFO))); - OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); - ASSERT_EQ(ov::log::Level::INFO, level); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::ERR))); - OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); - ASSERT_EQ(ov::log::Level::ERR, level); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::WARNING))); - OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); - ASSERT_EQ(ov::log::Level::WARNING, level); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::DEBUG))); - OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); - ASSERT_EQ(ov::log::Level::DEBUG, level); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::TRACE))); - OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); - ASSERT_EQ(ov::log::Level::TRACE, level); - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::log::level(ov::log::Level::NO))); - OV_ASSERT_NO_THROW(level = core.get_property("GNA", ov::log::level)); - ASSERT_EQ(ov::log::Level::NO, level); - - ASSERT_THROW(core.set_property("GNA", {{ov::log::level.name(), "NO"}}), ov::Exception); -} - -TEST(OVClassBasicPropsTest, smoke_SetConfigAfterCreatedFwModelPathNegative) { - ov::Core core; - std::string path = ""; - - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::GNA_3_5))); - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::firmware_model_image_path("model.bin"))); - ASSERT_THROW(path = core.get_property("GNA", ov::intel_gna::firmware_model_image_path), ov::Exception); -} - -TEST(OVClassBasicPropsTest, smoke_SetConfigAfterCreatedFwModelPathPositive) { - ov::Core core; - std::string path = ""; - - OV_ASSERT_NO_THROW( - core.set_property("GNA", ov::intel_gna::execution_target(ov::intel_gna::HWGeneration::GNA_3_5_E))); - OV_ASSERT_NO_THROW(core.set_property("GNA", ov::intel_gna::firmware_model_image_path("model.bin"))); - OV_ASSERT_NO_THROW(path = core.get_property("GNA", ov::intel_gna::firmware_model_image_path)); - ASSERT_EQ("model.bin", path); -} - -// IE Class Query network - -INSTANTIATE_TEST_SUITE_P(smoke_OVClassQueryModelTest, OVClassQueryModelTest, ::testing::Values("GNA")); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/life_time.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/life_time.cpp deleted file mode 100644 index 4b5bae71b8c..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/ov_plugin/life_time.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/ov_plugin/life_time.hpp" - -using namespace ov::test::behavior; -namespace { - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVHoldersTest, - ::testing::Values(ov::test::utils::DEVICE_GNA), - OVHoldersTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - OVHoldersTestOnImportedNetwork, - ::testing::Values(ov::test::utils::DEVICE_GNA), - OVHoldersTestOnImportedNetwork::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/caching_tests.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/caching_tests.cpp deleted file mode 100644 index 977e058755e..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/caching_tests.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/plugin/caching_tests.hpp" - -using namespace LayerTestsDefinitions; - -namespace { -static const std::vector precisionsGNA = { - ngraph::element::f32, - // integer weights are not supported by GNA so far - // ngraph::element::u8, - // ngraph::element::i16, -}; - -static const std::vector batchSizesGNA = {1, 2}; - -INSTANTIATE_TEST_SUITE_P(smoke_CachingSupportCase_GNA, - LoadNetworkCacheTestBase, - ::testing::Combine(::testing::ValuesIn(LoadNetworkCacheTestBase::getStandardFunctions()), - ::testing::ValuesIn(precisionsGNA), - ::testing::ValuesIn(batchSizesGNA), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - LoadNetworkCacheTestBase::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/configuration_tests.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/configuration_tests.cpp deleted file mode 100644 index 9eb77a00ee2..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/configuration_tests.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/plugin/configuration_tests.hpp" - -#include "gna/gna_config.hpp" - -using namespace BehaviorTestsDefinitions; -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> inconfigs = { - {{InferenceEngine::GNAConfigParams::KEY_GNA_DEVICE_MODE, InferenceEngine::GNAConfigParams::GNA_SW_FP32}, - {InferenceEngine::GNAConfigParams::KEY_GNA_LIB_N_THREADS, "2"}}, - {{InferenceEngine::GNAConfigParams::KEY_GNA_SCALE_FACTOR, "NAN"}}, - {{InferenceEngine::GNAConfigParams::KEY_GNA_PRECISION, "FP8"}}, - {{InferenceEngine::GNAConfigParams::KEY_GNA_DEVICE_MODE, "AUTO"}}, - {{InferenceEngine::GNAConfigParams::KEY_GNA_COMPACT_MODE, "ON"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - IncorrectConfigTests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(inconfigs)), - IncorrectConfigTests::getTestCaseName); - -const std::vector> Inconfigs = { - {{"KEY_KEY_GNA_DEVICE_MODE", InferenceEngine::GNAConfigParams::GNA_SW_EXACT}}, - {{"GNA_DEVICE_MODE_XYZ", InferenceEngine::GNAConfigParams::GNA_SW_EXACT}}, - {{"KEY_GNA_DEVICE_MODE_XYZ", InferenceEngine::GNAConfigParams::GNA_SW_EXACT}}, - {{"KEY_GNA_SCALE_FACTOR_1", InferenceEngine::GNAConfigParams::GNA_SW_EXACT}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - IncorrectConfigAPITests, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(Inconfigs)), - IncorrectConfigAPITests::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/core_integration.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/core_integration.cpp deleted file mode 100644 index 680012b2550..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/core_integration.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/plugin/core_integration.hpp" - -#include - -using namespace BehaviorTestsDefinitions; - -namespace { - -// -// IE Class Common tests with -// - -INSTANTIATE_TEST_SUITE_P(nightly_IEClassBasicTestP, - IEClassBasicTestP, - ::testing::Values(std::make_pair("openvino_intel_gna_plugin", "GNA"))); - -// TODO -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassNetworkTestP, IEClassNetworkTestP, ::testing::Values("GNA")); - -// -// IE Class GetMetric -// - -INSTANTIATE_TEST_SUITE_P(nightly_IEClassGetMetricTest, - IEClassGetMetricTest_SUPPORTED_CONFIG_KEYS, - ::testing::Values("GNA", "MULTI", "HETERO")); - -INSTANTIATE_TEST_SUITE_P(nightly_IEClassGetMetricTest, - IEClassGetMetricTest_SUPPORTED_METRICS, - ::testing::Values("GNA", "MULTI", "HETERO")); - -INSTANTIATE_TEST_SUITE_P(nightly_IEClassGetMetricTest, - IEClassGetMetricTest_AVAILABLE_DEVICES, - ::testing::Values("GNA")); - -INSTANTIATE_TEST_SUITE_P(nightly_IEClassGetMetricTest, - IEClassGetMetricTest_FULL_DEVICE_NAME, - ::testing::Values("GNA", "MULTI", "HETERO")); - -// TODO: Issue: 30198 -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassGetMetricTest, - IEClassGetMetricTest_OPTIMIZATION_CAPABILITIES, - ::testing::Values("GNA")); - -// TODO: Issue: 30199 -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_IEClassGetMetricTest, - IEClassGetMetricTest_RANGE_FOR_ASYNC_INFER_REQUESTS, - ::testing::Values("GNA")); - -INSTANTIATE_TEST_SUITE_P(nightly_IEClassGetMetricTest, - IEClassGetMetricTest_ThrowUnsupported, - ::testing::Values("GNA", "MULTI", "HETERO")); - -INSTANTIATE_TEST_SUITE_P(nightly_IEClassGetConfigTest, - IEClassGetConfigTest_ThrowUnsupported, - ::testing::Values("GNA", "MULTI", "HETERO")); - -INSTANTIATE_TEST_SUITE_P(nightly_IEClassGetAvailableDevices, IEClassGetAvailableDevices, ::testing::Values("GNA")); - -// -// IE Class GetConfig -// - -INSTANTIATE_TEST_SUITE_P(nightly_IEClassGetConfigTest, IEClassGetConfigTest, ::testing::Values("GNA")); - -// IE Class Query network - -INSTANTIATE_TEST_SUITE_P(smoke_IEClassQueryNetworkTest, IEClassQueryNetworkTest, ::testing::Values("GNA")); - -// IE Class Load network - -INSTANTIATE_TEST_SUITE_P(smoke_IEClassLoadNetworkTest, IEClassLoadNetworkTest, ::testing::Values("GNA")); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/core_threading_tests.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/core_threading_tests.cpp deleted file mode 100644 index 79e14876328..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/core_threading_tests.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -namespace { -Params params[] = { - std::tuple{ov::test::utils::DEVICE_GNA, {{CONFIG_KEY(PERF_COUNT), CONFIG_VALUE(YES)}}}, - std::tuple{ov::test::utils::DEVICE_HETERO, {{"TARGET_FALLBACK", ov::test::utils::DEVICE_GNA}}}, -}; -// TODO: Consider to append params[1] after issue *-45658 resolved -std::vector> paramsWithIterations{params[0]}; -} // namespace - -INSTANTIATE_TEST_SUITE_P(GNA, CoreThreadingTests, testing::ValuesIn(params), CoreThreadingTests::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(GNA, - CoreThreadingTestsWithIterations, - testing::Combine(testing::ValuesIn(paramsWithIterations), - testing::Values(3), - testing::Values(4), - testing::Values(ModelClass::ConvPoolRelu)), - CoreThreadingTestsWithIterations::getTestCaseName); diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/life_time.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/life_time.cpp deleted file mode 100644 index f46aa9d2156..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/life_time.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/plugin/life_time.hpp" - -using namespace BehaviorTestsDefinitions; -namespace { -const std::vector> orders = { - // 0 - plugin - // 1 - executable_network - // 2 - infer_request - // 3 - variable state - {3, 0, 1, 2}, - {3, 0, 2, 1}, - {3, 1, 0, 2}, - {3, 1, 2, 0}, - {3, 2, 0, 1}, - {3, 2, 1, 0}, - {0, 3, 1, 2}, - {0, 1, 3, 2}}; - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - HoldersTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(orders)), - HoldersTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - HoldersTestImportNetwork, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(orders)), - HoldersTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - HoldersTestOnImportedNetwork, - ::testing::Values(ov::test::utils::DEVICE_GNA), - HoldersTestOnImportedNetwork::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/version.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/version.cpp deleted file mode 100644 index f8705ad5ef3..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/behavior/plugin/version.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "behavior/plugin/version.hpp" - -using namespace BehaviorTestsDefinitions; -namespace { -INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, - VersionTest, - ::testing::Values(ov::test::utils::DEVICE_GNA), - VersionTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Hetero_BehaviorTests, - VersionTest, - ::testing::Values(ov::test::utils::DEVICE_HETERO), - VersionTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/core_config.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/core_config.cpp deleted file mode 100644 index 1fc31a26b39..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/core_config.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "functional_test_utils/core_config.hpp" - -#include -#include - -#include "functional_test_utils/blob_utils.hpp" -#include "shared_test_classes/base/ov_subgraph.hpp" - -void CoreConfiguration(LayerTestsUtils::LayerTestsCommon* test) { - const float MAX_VAL_2B_FEAT = 16384.0f; - auto inputParameters = test->GetFunction()->get_parameters(); - auto& configuration = test->GetConfiguration(); - for (size_t i = 0; i < inputParameters.size(); ++i) { - std::string scaleFactorConfigKey = "GNA_SCALE_FACTOR" + std::string("_") + std::to_string(i); - if (configuration.find(scaleFactorConfigKey) != configuration.end()) { - continue; - } - - auto elementType = inputParameters[i]->get_element_type(); - auto shape = inputParameters[i]->get_shape(); - auto precision = InferenceEngine::details::convertPrecision(elementType); - precision = (precision.getPrecVal() == InferenceEngine::Precision::FP16) - ? InferenceEngine::Precision(InferenceEngine::Precision::FP32) - : precision; - - InferenceEngine::SizeVector size(shape); - InferenceEngine::TensorDesc tensor(precision, size, InferenceEngine::Layout::ANY); - InferenceEngine::DataPtr dataPtr = std::make_shared("tmp", tensor); - - InferenceEngine::InputInfo info; - info.setInputData(dataPtr); - info.setPrecision(precision); - - auto blob = test->GenerateInput(info); - float floatScaleFactor = 1.0f; - - auto memory = InferenceEngine::as(blob); - IE_ASSERT(memory); - - const auto lockedMemory = memory->wmap(); - if (precision == InferenceEngine::Precision::FP32) { - float* ptrFloatFeat = lockedMemory.as(); - float max = 0.0; - - for (size_t i = 0; i < blob->size(); i++) { - if (fabs(ptrFloatFeat[i]) > max) { - max = fabs(ptrFloatFeat[i]); - } - } - - floatScaleFactor = (max == 0) ? 1.0f : MAX_VAL_2B_FEAT / max; - } - - configuration[scaleFactorConfigKey] = std::to_string(floatScaleFactor); - } -} - -namespace ov { -namespace test { - -void core_configuration(ov::test::SubgraphBaseTest* test) {} - -} // namespace test -} // namespace ov diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/execution_graph_tests/add_output.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/execution_graph_tests/add_output.cpp deleted file mode 100644 index 6778afeceb2..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/execution_graph_tests/add_output.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "execution_graph_tests/add_output.hpp" - -#include - -#include "functional_test_utils/plugin_cache.hpp" -#include "ov_models/builders.hpp" - -std::shared_ptr getTargetNetwork() { - ngraph::Shape shape = {1, 200}; - ngraph::element::Type type = ngraph::element::f32; - - auto input = std::make_shared(type, shape); - auto mem_i = std::make_shared(type, shape, 0); - auto mem_r = std::make_shared(mem_i, "r_1-3"); - auto mul = std::make_shared(mem_r, input); - auto mem_w = std::make_shared(mul, "r_1-3"); - auto sigm = std::make_shared(mul); - mem_r->output(0).set_names({"Memory_1"}); - mem_w->add_control_dependency(mem_r); - sigm->add_control_dependency(mem_w); - sigm->output(0).set_names({"Sigmoid"}); - return std::make_shared(ngraph::NodeVector{sigm}, ngraph::ParameterVector{input}, "addOutput"); -} - -std::vector testCases = { - addOutputsParams(getTargetNetwork(), {"Memory_1"}, ov::test::utils::DEVICE_GNA)}; - -INSTANTIATE_TEST_SUITE_P(smoke_AddOutputBasic, - AddOutputsTest, - ::testing::ValuesIn(testCases), - AddOutputsTest::getTestCaseName); diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/set_device_name.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/set_device_name.cpp deleted file mode 100644 index 3f259555b31..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/set_device_name.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "set_device_name.hpp" - -#include -#include - -namespace ov { -namespace test { -void set_device_suffix(const std::string& suffix) { - if (!suffix.empty()) { - throw std::runtime_error("The suffix can't be used for GNA device!"); - } -} -} // namespace test -} // namespace ov diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/activation.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/activation.cpp deleted file mode 100644 index b3dd8026cb2..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/activation.cpp +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/activation.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -namespace LayerTestsDefinitions { - -class ActivationLayerGNATest : public ActivationLayerTest { -protected: - void SetUp() override { - InferenceEngine::Precision netPrecision; - std::pair, std::vector> shapes; - std::pair> activationDecl; - std::tie(activationDecl, netPrecision, inPrc, outPrc, inLayout, outLayout, shapes, targetDevice) = GetParam(); - - const auto& inputShape = shapes.first; - const std::size_t inputDim = - std::accumulate(inputShape.begin(), inputShape.end(), 1, std::multiplies()); - const std::vector inputDims{1, inputDim}; - activationType = activationDecl.first; - const auto& constantsValue = activationDecl.second; - const auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputDims))}; - params[0]->set_friendly_name("Input"); - - // TODO: remove after integer inference output support - if (ngPrc == ngraph::element::u8 || ngPrc == ngraph::element::i16) { - threshold = 1.0; - } - - const auto inputReshapePattern = - std::make_shared(ngraph::element::i64, ngraph::Shape{inputShape.size()}, inputShape); - const auto inputReshape = std::make_shared(params[0], inputReshapePattern, false); - const auto activation = - ngraph::builder::makeActivation(inputReshape, ngPrc, activationType, shapes.second, constantsValue); - const auto outputReshapePattern = - std::make_shared(ngraph::element::i64, ngraph::Shape{2}, inputDims); - const auto outputReshape = std::make_shared(activation, outputReshapePattern, false); - - function = std::make_shared(ngraph::NodeVector{outputReshape}, params); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - bool inPrcSigned = function->get_parameters()[0]->get_element_type().is_signed(); - bool inPrcFloat = info.getPrecision().is_float(); - int32_t data_start_from = -10; - uint32_t data_range = 20; - int32_t resolution = 32768; - - switch (activationType) { - case ngraph::helpers::ActivationTypes::Log: { - data_start_from = 1; - data_range = 20; - resolution = 32768; - break; - } - case ngraph::helpers::ActivationTypes::Sign: { - data_start_from = -10; - data_range = 20; - resolution = 3072; - break; - } - case ngraph::helpers::ActivationTypes::Exp: { - const double max_result_on_GNA = 15.9; - const double exp_inverse = std::round(std::log(max_result_on_GNA)); - if (inPrcSigned) { - data_range = exp_inverse * 2.0; - data_start_from = -exp_inverse; - } else { - data_range = exp_inverse; - data_start_from = 0; - } - break; - } - } - if (!inPrcSigned) { - data_range = 15; - data_start_from = 0; - } - if (!inPrcFloat) { - resolution = 1; - } - - return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), data_range, data_start_from, resolution); - } -}; - -TEST_P(ActivationLayerGNATest, CompareWithRefs) { - Run(); -} - -} // namespace LayerTestsDefinitions - -using namespace LayerTestsDefinitions; -using namespace ngraph::helpers; -namespace { -// Common params - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::I16, - InferenceEngine::Precision::U8, -}; - -const std::vector preluNetPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::map>> activationTypes = - {{Sigmoid, {}}, {Tanh, {}}, {Relu, {}}, {Exp, {}}, {Log, {}}, {Sign, {}}, {Abs, {}}, {Clamp, {{-5, 5}}}}; - -const std::map>> preluActivationTypes = {{PReLu, {{-0.01f}}}, - {LeakyRelu, {{0.01f}}}}; - -std::map, std::vector>> basic = {{{1, 50}, {{}}}, - {{1, 128}, {{}}}, - {{1, 10 * 1024}, {{}}}, - {{8, 128}, {{}}}, - {{1, 4, 2, 256}, {{}}}, - {{4, 4, 4, 4}, {{}}}, - {{1, 16, 1, 128}, {{}}}, - {{1, 8, 15, 128}, {{}}}, - {{1, 4, 4, 128}, {{}}}, - {{8}, {{}}}, - {{5}, {{}}}, - {{1, 936, 513}, {{}}}, - {{2, 32, 8}, {{}}}}; - -const auto basicCases = ::testing::Combine(::testing::ValuesIn(ov::test::utils::combineParams(activationTypes)), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(ov::test::utils::combineParams(basic)), - ::testing::Values(ov::test::utils::DEVICE_GNA)); - -const auto preluCases = ::testing::Combine(::testing::ValuesIn(ov::test::utils::combineParams(preluActivationTypes)), - ::testing::ValuesIn(preluNetPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(ov::test::utils::combineParams(basic)), - ::testing::Values(ov::test::utils::DEVICE_GNA)); - -INSTANTIATE_TEST_SUITE_P(smoke_Activation_Basic, - ActivationLayerGNATest, - basicCases, - ActivationLayerTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_Activation_Basic_Prelu, - ActivationLayerGNATest, - preluCases, - ActivationLayerTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/concat.cpp deleted file mode 100644 index b6b6d04ee76..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/concat.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/concat.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace LayerTestsDefinitions; - -namespace { - -std::vector axes = {1}; -std::vector>> inShapes = { - {{10, 10, 10, 10}, {10, 10, 10, 10}}, - {{10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}}, - {{10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}}, - {{10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}}}; - -std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; -// TODO: Issue: 26421 -INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, - ConcatLayerTest, - ::testing::Combine(::testing::ValuesIn(axes), - ::testing::ValuesIn(inShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ConcatLayerTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/conv_low_precision.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/conv_low_precision.cpp deleted file mode 100644 index 5048e80ccf1..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/conv_low_precision.cpp +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include - -#include "../../shared_tests_instances/skip_tests_check.hpp" -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "openvino/opsets/opset12.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/pass/convert_prc.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -namespace ConvLowPrecicionTestNs { - -using namespace ov; -using namespace ngraph::builder; -using namespace ov::element; -using namespace ov::op; -using namespace ov::opset12; -using namespace std; - -using ConvLowPrecisionTestParams = tuple, // Configuration - Shape, // Input Shape - pair, // FQ Min and Max (before conv) - std::size_t // Levels - >; - -class ConvLowPrecisionTest : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { - float fqMin = 0.0f; - float fqMax = 0.0f; - float inputDataResolution = 1.0f; - -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision netPrecision; - std::string targetDevice; - map configuration; - Shape inputShape; - pair fqMinMax; - std::size_t levels = 0; - - tie(netPrecision, targetDevice, configuration, inputShape, fqMinMax, levels) = obj.param; - - ostringstream result; - result << "_netPRC=" << netPrecision.name(); - result << "_targetDevice=" << targetDevice; - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << ":" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(inputShape); - result << "_fqMinMax=(" << fqMinMax.first << ".." << fqMinMax.second << ")"; - result << "_levels=" << levels; - - return result.str(); - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - return FuncTestUtils::createAndFillBlobFloatNormalDistribution(info.getTensorDesc(), 0.0f, 0.2f, 7235346); - } - - ParameterVector createInputVector(const Type& type, const vector& shapes) { - return ov::ParameterVector{std::make_shared(type, ov::Shape(shapes))}; - } - - shared_ptr createFQNode(const Type& type, - const shared_ptr& node, - float fqMin, - float fqMax, - std::size_t levels) { - auto fqInpMin = makeConstant(type, {1}, {fqMin}); - auto fqInpMax = makeConstant(type, {1}, {fqMax}); - auto fqOutMin = makeConstant(type, {1}, {fqMin}); - auto fqOutMax = makeConstant(type, {1}, {fqMax}); - return make_shared(node, fqInpMin, fqInpMax, fqOutMin, fqOutMax, levels); - } - -protected: - GnaLayerTestCheck gnaVersionCheck; - - void SetUp() override { - // Loosen threshold because of precision decrease during test - threshold = 0.1; - - // Receive test params - InferenceEngine::Precision netPrecision; - vector inputShape; - pair fqMinMax; - std::size_t levels = 0; - tie(netPrecision, targetDevice, configuration, inputShape, fqMinMax, levels) = this->GetParam(); - tie(fqMin, fqMax) = fqMinMax; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - size_t kernelHeight = inputShape[2] == 1 ? 1 : 2; - - // Create network - auto inputVector = createInputVector(ngPrc, {inputShape}); - auto inputFQ = createFQNode(ngPrc, inputVector[0], fqMin, fqMax, levels); - auto kernelWeights = makeConstant(ngPrc, {8, 8, kernelHeight, 2}, {}, true, 1.0f, -1.0f, 7235346); - auto weightsFQ = createFQNode(ngPrc, kernelWeights, fqMin, fqMax, levels); - auto convolution = make_shared(inputFQ, - weightsFQ, - vector{1, 1}, - vector{0, 0}, - vector{0, 0}, - vector{1, 1}, - PadType::VALID); - auto outputFQ = createFQNode(ngPrc, convolution, fqMin, fqMax, levels); - function = make_shared(outputFQ, inputVector, "ConvLowPrecision"); - gnaVersionCheck.SetUp(targetDevice); - } -}; - -TEST_P(ConvLowPrecisionTest, CompareWithRefs) { - Run(); -}; - -const vector netPrecisions = {InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32}; - -const vector> configs_1 = { - {{"GNA_DEVICE_MODE", "GNA_AUTO"}, {"GNA_PRECISION", "I8"}, {"GNA_EXEC_TARGET", "GNA_TARGET_1_0"}}, - {{"GNA_DEVICE_MODE", "GNA_AUTO"}, {"GNA_PRECISION", "I16"}, {"GNA_EXEC_TARGET", "GNA_TARGET_1_0"}}, -}; - -const vector> configs_2 = { - {{"GNA_DEVICE_MODE", "GNA_AUTO"}, {"GNA_PRECISION", "I8"}, {"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}, - {{"GNA_DEVICE_MODE", "GNA_AUTO"}, {"GNA_PRECISION", "I16"}, {"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}, -}; - -const vector> configs_3 = { - {{"GNA_DEVICE_MODE", "GNA_AUTO"}, {"GNA_PRECISION", "I8"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_DEVICE_MODE", "GNA_AUTO"}, {"GNA_PRECISION", "I16"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_DEVICE_MODE", "GNA_AUTO"}, {"GNA_PRECISION", "I8"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}, - {{"GNA_DEVICE_MODE", "GNA_AUTO"}, {"GNA_PRECISION", "I16"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}, -}; - -const Shape conv1D = {1, 8, 1, 16}; -const Shape conv2D = {1, 8, 16, 16}; - -const vector inputShapes = {conv1D, conv2D}; - -const vector> fqMinMax = {{-1.0f, 1.0f}}; - -const vector levels = {numeric_limits::max(), numeric_limits::max()}; - -INSTANTIATE_TEST_SUITE_P(smoke_LowPrecision10, - ConvLowPrecisionTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs_1), - ::testing::Values(conv1D), - ::testing::ValuesIn(fqMinMax), - ::testing::ValuesIn(levels)), - ConvLowPrecisionTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_LowPrecision20, - ConvLowPrecisionTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs_2), - ::testing::Values(conv1D), - ::testing::ValuesIn(fqMinMax), - ::testing::ValuesIn(levels)), - ConvLowPrecisionTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_LowPrecision3X, - ConvLowPrecisionTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs_3), - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(fqMinMax), - ::testing::ValuesIn(levels)), - ConvLowPrecisionTest::getTestCaseName); - -} // namespace ConvLowPrecicionTestNs diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convert_color_i420.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convert_color_i420.cpp deleted file mode 100644 index 0ff30892bd1..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convert_color_i420.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/convert_color_i420.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "negative_layer_support_test.hpp" - -using namespace LayerTestsDefinitions; - -namespace { - -const std::vector inShapes_nhwc = {{1, 10, 10, 1}}; - -const std::vector inTypes = {ov::element::u8, ov::element::f32}; - -const auto testCase_values = ::testing::Combine(::testing::ValuesIn(inShapes_nhwc), - ::testing::ValuesIn(inTypes), - ::testing::Bool(), - ::testing::Bool(), - ::testing::Values(ov::test::utils::DEVICE_GNA)); - -GNA_UNSUPPPORTED_LAYER_NEG_TEST(ConvertColorI420LayerTest, "The plugin does not support layer", testCase_values) - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convert_color_nv12.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convert_color_nv12.cpp deleted file mode 100644 index 3ba78e4e434..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convert_color_nv12.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/convert_color_nv12.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "negative_layer_support_test.hpp" - -using namespace LayerTestsDefinitions; - -namespace { - -const std::vector inShapes_nhwc = {{1, 10, 10, 1}}; - -const std::vector inTypes = {ov::element::u8, ov::element::f32}; - -const auto testCase_values = ::testing::Combine(::testing::ValuesIn(inShapes_nhwc), - ::testing::ValuesIn(inTypes), - ::testing::Bool(), - ::testing::Bool(), - ::testing::Values(ov::test::utils::DEVICE_GNA)); - -GNA_UNSUPPPORTED_LAYER_NEG_TEST(ConvertColorNV12LayerTest, "The plugin does not support layer", testCase_values) - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convolution.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convolution.cpp deleted file mode 100644 index e3c570c393a..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convolution.cpp +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include - -#include "../skip_tests_check.hpp" -#include "common_test_utils/test_constants.hpp" -#include "openvino/opsets/opset11.hpp" -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -using namespace ov; -using namespace ov::op; -using namespace ov::opset11; - -namespace { - -// ! [test_convolution:definition] -typedef std::tuple, // Pad begin - std::vector, // Pad end - InferenceEngine::SizeVector, // Dilation - size_t, // Num out channels - PadType // Padding type - > - convSpecificParams; - -typedef std::tuple // GNA Config params - > - ConvLayerTestFixtureParamsSet; - -class ConvolutionLayerTestFixture : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj); - -protected: - void SetUp() override; -}; - -std::string ConvolutionLayerTestFixture::getTestCaseName( - const testing::TestParamInfo& obj) { - convSpecificParams convParams; - InferenceEngine::Precision netPrecision; - InferenceEngine::Precision inPrc, outPrc; - InferenceEngine::Layout inLayout, outLayout; - InferenceEngine::SizeVector inputShapes; - std::string targetDevice; - std::map config; - std::tie(convParams, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShapes, targetDevice, config) = - obj.param; - PadType padType; - InferenceEngine::SizeVector kernel, stride, dilation; - std::vector padBegin, padEnd; - size_t convOutChannels; - std::tie(kernel, stride, padBegin, padEnd, dilation, convOutChannels, padType) = convParams; - - std::ostringstream result; - result << "IS=" << ov::test::utils::vec2str(inputShapes) << "_"; - result << "K" << ov::test::utils::vec2str(kernel) << "_"; - result << "S" << ov::test::utils::vec2str(stride) << "_"; - result << "PB" << ov::test::utils::vec2str(padBegin) << "_"; - result << "PE" << ov::test::utils::vec2str(padEnd) << "_"; - result << "D=" << ov::test::utils::vec2str(dilation) << "_"; - result << "O=" << convOutChannels << "_"; - result << "AP=" << padType << "_"; - result << "netPRC=" << netPrecision.name() << "_"; - result << "inPRC=" << inPrc.name() << "_"; - result << "outPRC=" << outPrc.name() << "_"; - result << "inL=" << inLayout << "_"; - result << "outL=" << outLayout << "_"; - result << "trgDev=" << targetDevice; - for (auto const& config_entry : config) { - result << "_config_entry=" << config_entry.first << "_" << config_entry.second; - } - return result.str(); -} - -void ConvolutionLayerTestFixture::SetUp() { - convSpecificParams convParams; - std::vector inputShape; - auto netPrecision = InferenceEngine::Precision::UNSPECIFIED; - std::tie(convParams, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShape, targetDevice, configuration) = - this->GetParam(); - PadType padType; - InferenceEngine::SizeVector kernel, stride, dilation; - std::vector padBegin, padEnd; - size_t convOutChannels; - std::tie(kernel, stride, padBegin, padEnd, dilation, convOutChannels, padType) = convParams; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - std::vector filter_weights; - - auto filter_size = std::accumulate(std::begin(kernel), std::end(kernel), 1, std::multiplies()); - filter_weights = - ov::test::utils::generate_float_numbers(convOutChannels * inputShape[1] * filter_size, -0.1f, 0.1f); - - auto conv = std::dynamic_pointer_cast(ngraph::builder::makeConvolution(params[0], - ngPrc, - kernel, - stride, - padBegin, - padEnd, - dilation, - padType, - convOutChannels, - false, - filter_weights)); - ResultVector results{std::make_shared(conv)}; - function = std::make_shared(results, params, "convolution"); -} - -TEST_P(ConvolutionLayerTestFixture, CompareWithRefs) { - Run(); -} -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -/* ============= 2D Convolution ============= */ -const std::vector> kernelsH1 = {{1, 3}, {1, 5}}; -const std::vector> stridesH1 = {{1, 1}, {1, 3}}; -const std::vector> stridesH1Big = {{1, 9}, {1, 16}}; -const std::vector> padBeginsH1 = {{1, 0}, {1, 3}}; -const std::vector> padEndsH1 = {{1, 0}, {1, 3}}; -const std::vector> dilationsH1 = {{1, 1}, {1, 3}}; -const std::vector> inputShapesH1 = {{1, 1, 1, 32}, {1, 32, 1, 160}, {1, 8, 1, 64}}; -const std::vector> kernelsW1 = {{3, 1}, {5, 1}}; -const std::vector> stridesW1 = {{1, 1}, {3, 1}}; -const std::vector> padBeginsW1 = {{0, 1}, {3, 1}}; -const std::vector> padEndsW1 = {{0, 1}, {3, 1}}; -const std::vector> dilationsW1 = {{1, 1}, {3, 1}}; -const std::vector> inputShapesW1 = {{1, 1, 32, 1}, {1, 32, 160, 1}, {1, 8, 64, 1}}; -const std::vector numOutCannels = {4, 8, 12}; - -const std::vector> kernels2D = { - {5, 1}, - {4, 1}, - {1, 3}, - {1, 2}, - {2, 2}, - {7, 1}, - {3, 3}, -}; - -const std::vector> kernels2D_big = { - {7, 2}, - {2, 7}, - {3, 7}, - {6, 6}, - {7, 7}, -}; - -const std::vector> kernels2D_3x3 = { - {3, 3}, -}; -const std::vector> kernels2D_5x6 = { - {5, 6}, -}; - -const std::vector> strides2D = { - {1, 1}, -}; -const std::vector> padBegins2D = { - {0, 0}, -}; -const std::vector> padEnds2D = { - {0, 0}, -}; -const std::vector> dilations2D = { - {1, 1}, -}; -const std::vector numOutCannels2D = {8, 16, 32}; - -const std::vector num_out_channels_for_mapped_2d = {4, 8, 12}; - -const std::vector input2DNCHW = {1, 8, 20, 16}; - -const std::vector input2DNCHW_3x3 = {1, 16, 3, 3}; -const std::vector input2DNCHW_5x6 = {1, 16, 5, 6}; - -const std::vector> inputShapesMapTo1d = {{1, 1, 56, 5}, {1, 32, 56, 5}, {1, 2, 64, 5}}; - -std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}}; - -const auto conv2DParams_Kernels2D = ::testing::Combine(::testing::ValuesIn(kernels2D), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutCannels2D), - ::testing::Values(PadType::EXPLICIT)); -const auto conv2DParams_Kernels2D_big = ::testing::Combine(::testing::ValuesIn(kernels2D_big), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutCannels2D), - ::testing::Values(PadType::EXPLICIT)); - -const auto conv2DParams_Kernels2D_3x3 = ::testing::Combine(::testing::ValuesIn(kernels2D_3x3), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(num_out_channels_for_mapped_2d), - ::testing::Values(PadType::EXPLICIT)); - -const auto conv2DParams_Kernels2D_5x6 = ::testing::Combine(::testing::ValuesIn(kernels2D_5x6), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(num_out_channels_for_mapped_2d), - ::testing::Values(PadType::EXPLICIT)); - -const auto conv2DParams_ExplicitPadding_Height1 = ::testing::Combine(::testing::ValuesIn(kernelsH1), - ::testing::ValuesIn(stridesH1), - ::testing::ValuesIn(padBeginsH1), - ::testing::ValuesIn(padEndsH1), - ::testing::ValuesIn(dilationsH1), - ::testing::ValuesIn(numOutCannels), - ::testing::Values(PadType::EXPLICIT)); -const auto conv2DParams_ExplicitPadding_Width1 = ::testing::Combine(::testing::ValuesIn(kernelsW1), - ::testing::ValuesIn(stridesW1), - ::testing::ValuesIn(padBeginsW1), - ::testing::ValuesIn(padEndsW1), - ::testing::ValuesIn(dilationsW1), - ::testing::ValuesIn(numOutCannels), - ::testing::Values(PadType::EXPLICIT)); -const auto conv2DParams_AutoPadValid_Height1 = ::testing::Combine(::testing::ValuesIn(kernelsH1), - ::testing::ValuesIn(stridesH1), - ::testing::Values(std::vector({0, 0})), - ::testing::Values(std::vector({0, 0})), - ::testing::ValuesIn(dilationsH1), - ::testing::ValuesIn(numOutCannels), - ::testing::Values(PadType::VALID)); -const auto conv2DParams_AutoPadValid_Height1_BigStride = - ::testing::Combine(::testing::ValuesIn(kernelsH1), - ::testing::ValuesIn(stridesH1Big), - ::testing::Values(std::vector({0, 0})), - ::testing::Values(std::vector({0, 0})), - ::testing::ValuesIn(dilationsH1), - ::testing::ValuesIn(numOutCannels), - ::testing::Values(PadType::VALID)); -const auto conv2DParams_AutoPadValid_Width1 = ::testing::Combine(::testing::ValuesIn(kernelsW1), - ::testing::ValuesIn(stridesW1), - ::testing::Values(std::vector({0, 0})), - ::testing::Values(std::vector({0, 0})), - ::testing::ValuesIn(dilationsW1), - ::testing::ValuesIn(numOutCannels), - ::testing::Values(PadType::VALID)); -const auto conv2DParams_AutoPadValid_MapTo1d = ::testing::Combine(::testing::Values(std::vector{3, 5}), - ::testing::ValuesIn(stridesW1), - ::testing::Values(std::vector({0, 0})), - ::testing::Values(std::vector({0, 0})), - ::testing::Values(std::vector{1, 1}), - ::testing::ValuesIn(numOutCannels), - ::testing::Values(PadType::VALID)); - -// TODO: padding isn't currently supported in GNA -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_Convolution2D_ExplicitPadding_Height1, - ConvolutionLayerTestFixture, - ::testing::Combine(conv2DParams_ExplicitPadding_Height1, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapesH1), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvolutionLayerTestFixture::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_Convolution2D_ExplicitPadding_Width1, - ConvolutionLayerTestFixture, - ::testing::Combine(conv2DParams_ExplicitPadding_Width1, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapesW1), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvolutionLayerTestFixture::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Convolution2D_AutoPadValid_Height1, - ConvolutionLayerTestFixture, - ::testing::Combine(conv2DParams_AutoPadValid_Height1, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapesH1), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvolutionLayerTestFixture::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Convolution2D_AutoPadValid_Height1_BigStride, - ConvolutionLayerTestFixture, - ::testing::Combine(conv2DParams_AutoPadValid_Height1_BigStride, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapesH1), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvolutionLayerTestFixture::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Convolution2D_AutoPadValid_Width1, - ConvolutionLayerTestFixture, - ::testing::Combine(conv2DParams_AutoPadValid_Width1, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapesW1), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvolutionLayerTestFixture::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Convolution2D_AutoPadValid_MapTo1d, - ConvolutionLayerTestFixture, - ::testing::Combine(conv2DParams_AutoPadValid_MapTo1d, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapesMapTo1d), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvolutionLayerTestFixture::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Convolution2D_Kernels2D, - ConvolutionLayerTestFixture, - ::testing::Combine(conv2DParams_Kernels2D, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(input2DNCHW), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvolutionLayerTestFixture::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Convolution2D_Kernels2D_big, - ConvolutionLayerTestFixture, - ::testing::Combine(conv2DParams_Kernels2D_big, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(input2DNCHW), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvolutionLayerTestFixture::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Convolution2D_Map2D_Not_Transpose_h_w_3_3, - ConvolutionLayerTestFixture, - ::testing::Combine(conv2DParams_Kernels2D_3x3, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(input2DNCHW_3x3), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvolutionLayerTestFixture::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_Convolution2D_Map2D_Not_Transpose_h_w_5_6, - ConvolutionLayerTestFixture, - ::testing::Combine(conv2DParams_Kernels2D_5x6, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(input2DNCHW_5x6), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvolutionLayerTestFixture::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convolution_negative.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convolution_negative.cpp deleted file mode 100644 index f335b4d3d6f..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/convolution_negative.cpp +++ /dev/null @@ -1,216 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "../skip_tests_check.hpp" -#include "common_test_utils/test_assertions.hpp" -#include "common_test_utils/test_constants.hpp" -#include "openvino/runtime/intel_gna/properties.hpp" -#include "shared_test_classes/single_layer/convolution.hpp" - -using namespace LayerTestsDefinitions; - -namespace { - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -/* ============= 2D Convolution ============= */ -const std::vector> kernels2D = {{1, 3}, {7, 1}, {3, 3}, {7, 2}, {2, 7}}; - -const std::vector> kernels2DInvalid = { - {9, 3}, - {1, 9}, - {1, 8}, - {8, 1}, - {8, 8}, -}; - -const std::vector> kernels2DInvalidFor56InC = { - {1, 6}, - {2, 6}, - {7, 7}, - {1, 7}, - {4, 7}, -}; - -const std::vector> kernels2DInvalidFor120InC = { - {1, 4}, - {8, 3}, - {7, 5}, - {1, 6}, - {4, 7}, -}; - -const std::vector> strides2D = { - {1, 1}, -}; -const std::vector> strides2DInvalid = {{8, 8}, {1, 8}}; -const std::vector> padBegins2D = { - {0, 0}, -}; -// Padding must be less than kernel size -const std::vector> padTooBigForKernels2D = { - {3, 3}, -}; -const std::vector> padEnds2D = { - {0, 0}, -}; -const std::vector> padBegins2DInvalid = {{1, 0}, {1, 1}, {0, 1}}; -const std::vector> padEnds2DInvalid = {{1, 0}, {1, 1}, {0, 1}}; -const std::vector> dilations2D = { - {1, 1}, -}; -const std::vector> dilations2DInvalid = { - {2, 2}, -}; -const std::vector numOutChannels2D = {32}; -const std::vector numOutChannels2DInvalid = {1, 7, 9, 1032}; - -const std::vector> input2DNCHWFine = {{1, 8, 20, 16}}; - -const std::vector> input2DNCHWWithInC56 = {{1, 56, 20, 16}}; -const std::vector> input2DNCHWWithInC120 = {{1, 120, 20, 16}}; - -const std::vector> input2DNCHWInvalidInputC = {{1, 7, 20, 16}, {1, 9, 20, 16}, {1, 400, 20, 16}}; -const std::vector> input2DNCHWInvalidInputH = {{1, 8, 15, 16}, {1, 8, 400, 16}}; -const std::vector> input2DNCHWInvalidInputW = {{1, 8, 20, 14}, {1, 8, 20, 400}}; - -const auto conv2DParametersFine = ::testing::Combine(::testing::ValuesIn(kernels2D), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutChannels2D), - ::testing::Values(ngraph::op::PadType::EXPLICIT)); -const auto conv2DParametersInvalidKernel = ::testing::Combine(::testing::ValuesIn(kernels2DInvalid), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutChannels2D), - ::testing::Values(ngraph::op::PadType::EXPLICIT)); - -const auto conv2DParametersInvalidKernelFor56InC = ::testing::Combine(::testing::ValuesIn(kernels2DInvalidFor56InC), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutChannels2D), - ::testing::Values(ngraph::op::PadType::EXPLICIT)); - -const auto conv2DParametersInvalidKernelFor120InC = - ::testing::Combine(::testing::ValuesIn(kernels2DInvalidFor120InC), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutChannels2D), - ::testing::Values(ngraph::op::PadType::EXPLICIT)); - -const auto conv2DParametersInvalidFilterNumber = ::testing::Combine(::testing::ValuesIn(kernels2D), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutChannels2DInvalid), - ::testing::Values(ngraph::op::PadType::EXPLICIT)); -const auto conv2DParametersInvalidPadding = ::testing::Combine(::testing::ValuesIn(kernels2D), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2DInvalid), - ::testing::ValuesIn(padEnds2DInvalid), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutChannels2D), - ::testing::Values(ngraph::op::PadType::EXPLICIT)); -const auto conv2DParametersInvalidStride = ::testing::Combine(::testing::ValuesIn(kernels2D), - ::testing::ValuesIn(strides2DInvalid), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutChannels2D), - ::testing::Values(ngraph::op::PadType::EXPLICIT)); -const auto conv2DParametersInvalidDilation = ::testing::Combine(::testing::ValuesIn(kernels2D), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padBegins2D), - ::testing::ValuesIn(padEnds2D), - ::testing::ValuesIn(dilations2DInvalid), - ::testing::ValuesIn(numOutChannels2D), - ::testing::Values(ngraph::op::PadType::EXPLICIT)); -const auto conv2DParametersInvalidPaddingSize = ::testing::Combine(::testing::ValuesIn(kernels2D), - ::testing::ValuesIn(strides2D), - ::testing::ValuesIn(padTooBigForKernels2D), - ::testing::ValuesIn(padTooBigForKernels2D), - ::testing::ValuesIn(dilations2D), - ::testing::ValuesIn(numOutChannels2D), - ::testing::Values(ngraph::op::PadType::EXPLICIT)); - -class GnaConv2DNegativeTest : public ConvolutionLayerTest { -protected: - virtual std::string expectedSubstring() = 0; - virtual std::string getTarget() = 0; - void Run() override { - try { - ConvolutionLayerTest::LoadNetwork(); - FAIL() << "GNA's unsupported configuration of Convolution2D was not detected in " - "ConvolutionLayerTest::LoadNetwork()"; - } catch (std::runtime_error& e) { - const std::string errorMsg = e.what(); - const auto expected = expectedSubstring(); - ASSERT_STR_CONTAINS(errorMsg, expected); - EXPECT_TRUE(errorMsg.find(expected) != std::string::npos) - << "Wrong error message, actula error message: " << errorMsg << ", expected: " << expected; - } - } - void SetUp() override { - ConvolutionLayerTest::SetUp(); - const auto target = getTarget(); - configuration[ov::intel_gna::execution_target.name()] = target; - configuration[ov::intel_gna::compile_target.name()] = target; - } -}; - -#define GNA_NEG_INSTANTIATE(whats_wrong, suffix_params, suffix_input, error_message, gna_hw_gen) \ - struct GnaConv2DNegativeTest##whats_wrong : GnaConv2DNegativeTest { \ - std::string expectedSubstring() override { \ - return error_message; \ - } \ - std::string getTarget() override { \ - std::stringstream s; \ - s << gna_hw_gen; \ - return s.str(); \ - } \ - }; \ - TEST_P(GnaConv2DNegativeTest##whats_wrong, ThrowAsNotSupported) { \ - Run(); \ - } \ - INSTANTIATE_TEST_SUITE_P(smoke_GnaConv2DNegativeTestInvalid##whats_wrong, \ - GnaConv2DNegativeTest##whats_wrong, \ - ::testing::Combine(conv2DParameters##suffix_params, \ - ::testing::ValuesIn(netPrecisions), \ - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), \ - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), \ - ::testing::Values(InferenceEngine::Layout::ANY), \ - ::testing::Values(InferenceEngine::Layout::ANY), \ - ::testing::ValuesIn(input2DNCHW##suffix_input), \ - ::testing::Values(ov::test::utils::DEVICE_GNA)), \ - GnaConv2DNegativeTest##whats_wrong::getTestCaseName); - -constexpr auto GNA_3_0 = ov::intel_gna::HWGeneration::GNA_3_0; -constexpr auto GNA_3_5 = ov::intel_gna::HWGeneration::GNA_3_5; - -GNA_NEG_INSTANTIATE(FilterNumber, InvalidFilterNumber, Fine, "Unsupported number of kernels", GNA_3_0) -GNA_NEG_INSTANTIATE(Kernel, InvalidKernel, Fine, "Unsupported kernel shape", GNA_3_0) -GNA_NEG_INSTANTIATE(BigKernelFor56InC, InvalidKernelFor56InC, WithInC56, "Unsupported kernel shape", GNA_3_0) -GNA_NEG_INSTANTIATE(BigKernelFor120InC, InvalidKernelFor120InC, WithInC120, "Unsupported kernel shape", GNA_3_0) -GNA_NEG_INSTANTIATE(InputH, Fine, InvalidInputH, "Unsupported input height", GNA_3_0) -GNA_NEG_INSTANTIATE(InputW, Fine, InvalidInputW, "Unsupported input width", GNA_3_0) -GNA_NEG_INSTANTIATE(InputC, Fine, InvalidInputC, "Unsupported number of input channels", GNA_3_0) -GNA_NEG_INSTANTIATE(Padding, InvalidPadding, Fine, "Unsupported convolution input padding", GNA_3_0) -GNA_NEG_INSTANTIATE(Stride, InvalidStride, Fine, "Unsupported convolution stride shape", GNA_3_0) -GNA_NEG_INSTANTIATE(Dilation, InvalidDilation, Fine, "Unsupported dilation", GNA_3_0) -GNA_NEG_INSTANTIATE(Dilation35, InvalidDilation, Fine, "Unsupported dilation", GNA_3_5) -GNA_NEG_INSTANTIATE(PaddingSize, InvalidPaddingSize, Fine, "Unsupported convolution input padding", GNA_3_0) -GNA_NEG_INSTANTIATE(PaddingSize35, InvalidPaddingSize, Fine, "Unsupported convolution input padding", GNA_3_5) -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/eltwise.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/eltwise.cpp deleted file mode 100644 index 41ae1d34288..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/eltwise.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/eltwise.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace ov::test::subgraph; - -namespace { -std::vector> inShapes = { - {{2}}, - {{8}}, - {{1, 200}}, - {{1, 1, 1, 3}}, - {{1, 2, 4}}, - {{1, 4, 4}}, - {{1, 4, 4, 1}}, -}; - -std::vector netPrecisions = { - ov::element::f32, - ov::element::f16, -}; - -std::vector opTypes = { - ov::test::utils::OpType::SCALAR, - ov::test::utils::OpType::VECTOR, -}; - -std::vector eltwiseOpTypes = {ngraph::helpers::EltwiseTypes::MULTIPLY, - ngraph::helpers::EltwiseTypes::SUBTRACT, - ngraph::helpers::EltwiseTypes::ADD}; - -std::vector additional_config_inputs_1 = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1638.4"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}, {"GNA_SCALE_FACTOR_0", "1638.4"}}}; - -std::vector additional_config_inputs_2 = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1638.4"}, {"GNA_SCALE_FACTOR_1", "1638.4"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}, {"GNA_SCALE_FACTOR_0", "1638.4"}, {"GNA_SCALE_FACTOR_1", "1638.4"}}}; - -const auto multiply_params_1 = - ::testing::Combine(::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inShapes)), - ::testing::ValuesIn(eltwiseOpTypes), - ::testing::Values(ngraph::helpers::InputLayerType::CONSTANT), - ::testing::ValuesIn(opTypes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::element::undefined), - ::testing::Values(ov::element::undefined), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additional_config_inputs_1)); - -const auto multiply_params_2 = - ::testing::Combine(::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inShapes)), - ::testing::ValuesIn(eltwiseOpTypes), - ::testing::Values(ngraph::helpers::InputLayerType::PARAMETER), - ::testing::ValuesIn(opTypes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::element::undefined), - ::testing::Values(ov::element::undefined), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additional_config_inputs_2)); - -INSTANTIATE_TEST_SUITE_P(smoke_EltwiseLayerConstTest, - EltwiseLayerTest, - multiply_params_1, - EltwiseLayerTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_EltwiseLayerParamTest, - EltwiseLayerTest, - multiply_params_2, - EltwiseLayerTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/fake_quantize.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/fake_quantize.cpp deleted file mode 100644 index 502114a2963..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/fake_quantize.cpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/fake_quantize.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace LayerTestsDefinitions; - -namespace { - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -using ConfigType = std::map; -const ConfigType configFP32 = { - {"GNA_DEVICE_MODE", "GNA_SW_FP32"}, -}; -const ConfigType configInt16 = {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {InferenceEngine::GNAConfigParams::KEY_GNA_PRECISION, "I16"}, - {"GNA_SCALE_FACTOR_0", "327.67"}}; -const ConfigType configInt8 = {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {InferenceEngine::GNAConfigParams::KEY_GNA_PRECISION, "I8"}, - {"GNA_SCALE_FACTOR_0", "327.67"}}; - -/** - * @brief specific quantisation mode to be used internally - */ -const std::vector> gnaQuantModes = { - {"sw_fp32", configFP32}, - // TODO: support FakeQuantize in integer mode - // {"sw_exact_i16", configInt16}, - // {"sw_exact_i8", configInt8}, -}; - -const std::vector> inputShapes = - {{3, 10, 5, 6}, {1, 1, 1, 1}, {1, 8, 8, 256}, {1, 2, 2, 2}, {1, 3, 4, 5}, {8}}; -const std::vector> constShapes = {{1}}; -const std::vector levels = {16, 255, 256, UINT32_MAX}; - -const std::vector> fqArgs = {{}}; -const std::vector> inputParams = {{-10, 10, 0.1}, {}}; - -const std::vector fqInputMin = {0, 3}; -const std::vector fqInputMax = {10, 7}; -const std::vector fqOutputMin = {1, 3}; -const std::vector fqOutputMax = {7, 6}; - -std::vector> getInputOutputShapes(const std::vector inputsMin, - const std::vector inputsMax, - const std::vector OutputsMin, - const std::vector OutputsMax, - std::vector> fqArg) { - for (const auto& inputMin : inputsMin) { - for (const auto& inputMax : inputsMax) { - for (const auto& outputMin : OutputsMin) { - for (const auto& outputMax : OutputsMax) { - fqArg.push_back({inputMin, inputMax, outputMin, outputMax}); - } - } - } - } - return fqArg; -} - -const auto fqParams = ::testing::Combine(::testing::ValuesIn(levels), - ::testing::ValuesIn(constShapes), - ::testing::ValuesIn(fqArgs), - ::testing::ValuesIn(inputParams), - ::testing::Values(ngraph::op::AutoBroadcastType::NUMPY)); - -INSTANTIATE_TEST_SUITE_P(smoke_FakeQuantize, - FakeQuantizeLayerTest, - ::testing::Combine(fqParams, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(gnaQuantModes)), - FakeQuantizeLayerTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/gru_cell.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/gru_cell.cpp deleted file mode 100644 index 81114099f46..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/gru_cell.cpp +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/gru_cell.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" - -namespace LayerTestsDefinitions { - -using ngraph::helpers::InputLayerType; - -class GRUCellGNATest : public GRUCellTest { -protected: - void SetUp() override { - bool should_decompose; - size_t batch; - size_t hidden_size; - size_t input_size; - std::vector activations; - std::vector activations_alpha; - std::vector activations_beta; - float clip; - bool linear_before_reset; - InputLayerType WType; - InputLayerType RType; - InputLayerType BType; - InferenceEngine::Precision netPrecision; - std::tie(should_decompose, - batch, - hidden_size, - input_size, - activations, - clip, - linear_before_reset, - WType, - RType, - BType, - netPrecision, - targetDevice) = this->GetParam(); - - std::vector> inputShapes = { - {{batch, input_size}, - {batch, hidden_size}, - {3 * hidden_size, input_size}, - {3 * hidden_size, hidden_size}, - {(linear_before_reset ? 4 : 3) * hidden_size}}, - }; - - ASSERT_EQ(InputLayerType::CONSTANT, WType); - ASSERT_EQ(InputLayerType::CONSTANT, RType); - ASSERT_EQ(InputLayerType::CONSTANT, BType); - - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShapes[0])), - std::make_shared(ngPrc, ov::Shape(inputShapes[1]))}; - std::vector WRB = {inputShapes[2], inputShapes[3], inputShapes[4]}; - std::vector weights_vals = - ov::test::utils::generate_float_numbers(ngraph::shape_size(WRB[0]), -0.0001f, 0.0001f); - std::vector reccurrenceWeights_vals = - ov::test::utils::generate_float_numbers(ngraph::shape_size(WRB[1]), -0.0001f, 0.0001f); - std::vector bias_vals = - ov::test::utils::generate_float_numbers(ngraph::shape_size(WRB[2]), -0.0001f, 0.0001f); - - auto weightsNode = ngraph::builder::makeConstant(ngPrc, WRB[0], weights_vals); - auto reccurrenceWeightsNode = ngraph::builder::makeConstant(ngPrc, WRB[1], reccurrenceWeights_vals); - auto biasNode = ngraph::builder::makeConstant(ngPrc, WRB[2], bias_vals); - - auto gru_cell = std::make_shared(params[0], - params[1], - weightsNode, - reccurrenceWeightsNode, - biasNode, - hidden_size, - activations, - activations_alpha, - activations_beta, - clip, - linear_before_reset); - - ngraph::ResultVector results{std::make_shared(gru_cell->output(0))}; - function = std::make_shared(results, params, "gru_cell"); - if (should_decompose) { - ngraph::pass::Manager m; - m.register_pass(); - m.run_passes(function); - } - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.002f, 0.002f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } -}; - -TEST_P(GRUCellGNATest, CompareWithRefs) { - Run(); -} - -} // namespace LayerTestsDefinitions - -using namespace LayerTestsDefinitions; - -namespace { -std::vector should_decompose{false, true}; -std::vector batch{1}; -std::vector hidden_size{1, 5}; -std::vector input_size{1, 10}; -std::vector> activations = {{"relu", "tanh"}, - {"tanh", "sigmoid"}, - {"sigmoid", "tanh"}, - {"tanh", "relu"}}; -std::vector clip = {0.0f, 0.7f}; -std::vector linear_before_reset = {true, false}; -std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -INSTANTIATE_TEST_SUITE_P(smoke_GRUCellCommon, - GRUCellGNATest, - ::testing::Combine(::testing::ValuesIn(should_decompose), - ::testing::ValuesIn(batch), - ::testing::ValuesIn(hidden_size), - ::testing::ValuesIn(input_size), - ::testing::ValuesIn(activations), - ::testing::ValuesIn(clip), - ::testing::ValuesIn(linear_before_reset), - ::testing::Values(InputLayerType::CONSTANT), - ::testing::Values(InputLayerType::CONSTANT), - ::testing::Values(InputLayerType::CONSTANT), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - GRUCellTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/gru_sequence.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/gru_sequence.cpp deleted file mode 100644 index 97cd54070f1..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/gru_sequence.cpp +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/gru_sequence.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" -#include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" -#include "transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp" - -namespace LayerTestsDefinitions { - -using ngraph::helpers::InputLayerType; - -class GRUSequenceGNATest : public GRUSequenceTest { -protected: - void SetUp() override { - using namespace ngraph::helpers; - threshold = 0.015; - size_t seq_lengths; - size_t batch; - size_t hidden_size; - size_t input_size = 10; - std::vector activations; - std::vector activations_alpha; - std::vector activations_beta; - float clip; - bool linear_before_reset; - InputLayerType WRBType; - ngraph::op::RecurrentSequenceDirection direction; - InferenceEngine::Precision netPrecision; - std::tie(m_mode, - seq_lengths, - batch, - hidden_size, - activations, - clip, - linear_before_reset, - direction, - WRBType, - netPrecision, - targetDevice) = this->GetParam(); - - ASSERT_EQ(InputLayerType::CONSTANT, WRBType); - - size_t num_directions = direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL ? 2 : 1; - std::vector> inputShapes = { - {{batch, seq_lengths, input_size}, - {batch, num_directions, hidden_size}, - {batch}, - {num_directions, 3 * hidden_size, input_size}, - {num_directions, 3 * hidden_size, hidden_size}, - {num_directions, (linear_before_reset ? 4 : 3) * hidden_size}}, - }; - m_max_seq_len = seq_lengths; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShapes[0])), - std::make_shared(ngPrc, ov::Shape(inputShapes[1]))}; - - std::vector WRB = {inputShapes[3], inputShapes[4], inputShapes[5], inputShapes[2]}; - - std::vector weights_vals = - ov::test::utils::generate_float_numbers(ngraph::shape_size(WRB[0]), -0.0001f, 0.0001f); - std::vector reccurrenceWeights_vals = - ov::test::utils::generate_float_numbers(ngraph::shape_size(WRB[1]), -0.0001f, 0.0001f); - std::vector bias_vals = - ov::test::utils::generate_float_numbers(ngraph::shape_size(WRB[2]), -0.0001f, 0.0001f); - - auto weightsNode = ngraph::builder::makeConstant(ngPrc, WRB[0], weights_vals); - auto reccurrenceWeightsNode = ngraph::builder::makeConstant(ngPrc, WRB[1], reccurrenceWeights_vals); - auto biasNode = ngraph::builder::makeConstant(ngPrc, WRB[2], bias_vals); - - std::vector lengths(params[0]->get_partial_shape()[0].get_min_length(), - params[0]->get_partial_shape()[1].get_min_length()); - std::shared_ptr seq_length = - ngraph::builder::makeConstant(ngraph::element::i64, WRB[3], lengths, false); - - auto gru_sequence = std::make_shared(params[0], - params[1], - seq_length, - weightsNode, - reccurrenceWeightsNode, - biasNode, - hidden_size, - direction, - activations, - activations_alpha, - activations_beta, - clip, - linear_before_reset); - - ngraph::ResultVector results{std::make_shared(gru_sequence->output(0)), - std::make_shared(gru_sequence->output(1))}; - function = std::make_shared(results, params, "gru_sequence"); - - bool is_pure_sequence = m_mode == SequenceTestsMode::PURE_SEQ; - if (!is_pure_sequence) { - ngraph::pass::Manager manager; - if (direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - bool ti_found = is_tensor_iterator_exist(function); - EXPECT_EQ(ti_found, true); - } else { - bool ti_found = is_tensor_iterator_exist(function); - EXPECT_EQ(ti_found, false); - } - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.002f, 0.002f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } -}; - -TEST_P(GRUSequenceGNATest, CompareWithRefs) { - Run(); -} - -} // namespace LayerTestsDefinitions - -using namespace LayerTestsDefinitions; - -namespace { -std::vector mode{ - ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_CONST, - ngraph::helpers::SequenceTestsMode::PURE_SEQ}; -// output values increase rapidly without clip, so use only seq_lengths = 1 -std::vector seq_lengths_zero_clip{1}; -std::vector seq_lengths_clip_non_zero{1}; -std::vector batch{1}; -std::vector hidden_size{1, 10}; -// std::vector input_size{10}; -std::vector> activations = {{"relu", "tanh"}, - {"tanh", "sigmoid"}, - {"sigmoid", "tanh"}, - {"tanh", "relu"}}; -std::vector linear_before_reset = {true, false}; -std::vector clip{0.f}; -std::vector clip_non_zeros{0.7f}; -std::vector direction = {ngraph::op::RecurrentSequenceDirection::FORWARD, - ngraph::op::RecurrentSequenceDirection::REVERSE, - ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL}; -std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -INSTANTIATE_TEST_SUITE_P( - smoke_GRUSequenceCommonZeroClip, - GRUSequenceGNATest, - ::testing::Combine(::testing::ValuesIn(mode), - ::testing::ValuesIn(seq_lengths_zero_clip), - ::testing::ValuesIn(batch), - ::testing::ValuesIn(hidden_size), - // ::testing::ValuesIn(input_size), // hardcoded to 10 due to Combine supports up to 10 args - ::testing::ValuesIn(activations), - ::testing::ValuesIn(clip), - ::testing::ValuesIn(linear_before_reset), - ::testing::ValuesIn(direction), - ::testing::Values(InputLayerType::CONSTANT), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - GRUSequenceTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P( - smoke_GRUSequenceCommonClip, - GRUSequenceGNATest, - ::testing::Combine(::testing::ValuesIn(mode), - ::testing::ValuesIn(seq_lengths_clip_non_zero), - ::testing::ValuesIn(batch), - ::testing::ValuesIn(hidden_size), - // ::testing::ValuesIn(input_size), // hardcoded to 10 due to Combine supports up to 10 args - ::testing::ValuesIn(activations), - ::testing::ValuesIn(clip_non_zeros), - ::testing::ValuesIn(linear_before_reset), - ::testing::ValuesIn(direction), - ::testing::Values(InputLayerType::CONSTANT), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - GRUSequenceTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/low_precision.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/low_precision.cpp deleted file mode 100644 index b8e52a0fbb6..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/low_precision.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/low_precision.hpp" - -#include - -#include "../skip_tests_check.hpp" -#include "common_test_utils/test_constants.hpp" - -using namespace LowPrecisionTestDefinitions; - -namespace { - -class GnaLowPrecisionTest : public LowPrecisionTest { -protected: - void Run() override { - LowPrecisionTest::Run(); - } - - void SetUp() override { - LowPrecisionTest::SetUp(); - } -}; - -TEST_P(GnaLowPrecisionTest, CompareWithRefs) { - Run(); -} - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::map config_fp32 = { - {"GNA_DEVICE_MODE", "GNA_SW_FP32"}, -}; - -const std::map config_i16 = { - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_SCALE_FACTOR_0", "1"}, - {"GNA_PRECISION", "I16"}, -}; - -const std::map config_i8 = { - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_SCALE_FACTOR_0", "1"}, - {"GNA_PRECISION", "I8"}, -}; - -const std::vector>> configs = { - {"sw_fp32", config_fp32}, - {"sw_exact_i16", config_i16}, - {"sw_exact_i8", config_i8}, -}; - -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_LowPrecision, - GnaLowPrecisionTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - GnaLowPrecisionTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/lstm_cell_basic.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/lstm_cell_basic.cpp deleted file mode 100644 index b0b4a7b3f3c..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/lstm_cell_basic.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/lstm_cell_basic.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace LayerTestsDefinitions; - -namespace { -std::vector should_decompose{false, true}; -std::vector batch{1}; -std::vector hidden_size{1, 5, 16}; -std::vector input_size{1, 10, 16}; -std::vector> activations = {{"sigmoid", "tanh", "tanh"}, - {"sigmoid", "sigmoid", "sigmoid"}, - {"tanh", "tanh", "tanh"}, - {"tanh", "sigmoid", "relu"}}; -float clip = 0.f; -std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -std::vector> create_configs() { - const std::map scale_factors = {{"GNA_SCALE_FACTOR_0", "1024"}, - {"GNA_SCALE_FACTOR_1", "1024"}, - {"GNA_SCALE_FACTOR_2", "1024"}}; - - const std::pair precision_i8 = {"GNA_PRECISION", "I8"}; - const std::pair precision_i16 = {"GNA_PRECISION", "I16"}; - - const std::map config_sw_fp32 = {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}; - - const std::map config_target_3_0 = { - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}, - }; - - auto config_target_3_0_i8 = config_target_3_0; - config_target_3_0_i8.insert(precision_i8); - config_target_3_0_i8.insert(scale_factors.begin(), scale_factors.end()); - - auto config_target_3_0_i16 = config_target_3_0; - config_target_3_0_i16.insert(precision_i16); - config_target_3_0_i16.insert(scale_factors.begin(), scale_factors.end()); - - // In case of GNA Plugin LSTMCell is decomposed to a graph including Convolution layers. - // - // For GNA targets < 3.5 Convolution weights are always set to int16 precision, no matter what GNA_PRECISION is set - // to. For GNA targets >= 3.5 weights can have int8 or int16 precision based on GNA_PRECISION setting, but it's - // recommended to use POT, and not the GNA_PRECISION setting, so this test needs to be disabled for int8 precision - // until POT can be used inside functional tests. - // - // This is related to the issue 70675. - std::map config_target_3_5 = { - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}, - }; - - config_target_3_5.insert(precision_i16); - config_target_3_5.insert(scale_factors.begin(), scale_factors.end()); - - return {config_sw_fp32, config_target_3_0_i8, config_target_3_0_i16, config_target_3_5}; -} - -INSTANTIATE_TEST_SUITE_P(smoke_LSTMCellBasicCommon, - LSTMCellBasicTest, - ::testing::Combine(::testing::ValuesIn(should_decompose), - ::testing::ValuesIn(batch), - ::testing::ValuesIn(hidden_size), - ::testing::ValuesIn(input_size), - ::testing::ValuesIn(activations), - ::testing::Values(clip), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(create_configs())), - LSTMCellBasicTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/lstm_sequence.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/lstm_sequence.cpp deleted file mode 100644 index aa846c0a961..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/lstm_sequence.cpp +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/lstm_sequence.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" -#include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" -#include "transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp" - -namespace LayerTestsDefinitions { - -using ngraph::helpers::InputLayerType; - -class LSTMSequenceGNATest : public LSTMSequenceTest { -protected: - void SetUp() override { - using namespace ngraph::helpers; - threshold = 0.015; - size_t seq_lengths; - size_t batch; - size_t hidden_size; - size_t input_size; - std::vector activations; - std::vector activations_alpha; - std::vector activations_beta; - float clip; - ngraph::op::RecurrentSequenceDirection direction; - InputLayerType WRBType; - InferenceEngine::Precision netPrecision; - std::tie(m_mode, - seq_lengths, - batch, - hidden_size, - input_size, - activations, - clip, - direction, - WRBType, - netPrecision, - targetDevice) = this->GetParam(); - - ASSERT_EQ(InputLayerType::CONSTANT, WRBType); - - size_t num_directions = direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL ? 2 : 1; - std::vector> inputShapes = { - {{batch, seq_lengths, input_size}, - {batch, num_directions, hidden_size}, - {batch, num_directions, hidden_size}, - {batch}, - {num_directions, 4 * hidden_size, input_size}, - {num_directions, 4 * hidden_size, hidden_size}, - {num_directions, 4 * hidden_size}}, - }; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShapes[0])), - std::make_shared(ngPrc, ov::Shape(inputShapes[1])), - std::make_shared(ngPrc, ov::Shape(inputShapes[2]))}; - - std::vector WRB = {inputShapes[4], inputShapes[5], inputShapes[6], inputShapes[3]}; - - std::vector weights_vals = - ov::test::utils::generate_float_numbers(ngraph::shape_size(WRB[0]), -0.0001f, 0.0001f); - std::vector reccurrenceWeights_vals = - ov::test::utils::generate_float_numbers(ngraph::shape_size(WRB[1]), -0.0001f, 0.0001f); - std::vector bias_vals = - ov::test::utils::generate_float_numbers(ngraph::shape_size(WRB[2]), -0.0001f, 0.0001f); - - auto weightsNode = ngraph::builder::makeConstant(ngPrc, WRB[0], weights_vals); - auto reccurrenceWeightsNode = ngraph::builder::makeConstant(ngPrc, WRB[1], reccurrenceWeights_vals); - auto biasNode = ngraph::builder::makeConstant(ngPrc, WRB[2], bias_vals); - - std::vector lengths(params[0]->get_partial_shape()[0].get_min_length(), - params[0]->get_partial_shape()[1].get_min_length()); - std::shared_ptr seq_length = - ngraph::builder::makeConstant(ngraph::element::i64, WRB[3], lengths, false); - auto lstm_sequence = std::make_shared(params[0], - params[1], - params[2], - seq_length, - weightsNode, - reccurrenceWeightsNode, - biasNode, - hidden_size, - direction, - activations_alpha, - activations_beta, - activations, - clip); - - ngraph::ResultVector results{std::make_shared(lstm_sequence->output(0)), - std::make_shared(lstm_sequence->output(1)), - std::make_shared(lstm_sequence->output(2))}; - function = std::make_shared(results, params, "lstm_sequence"); - - bool is_pure_sequence = m_mode == SequenceTestsMode::PURE_SEQ; - if (!is_pure_sequence) { - ngraph::pass::Manager manager; - if (direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - bool ti_found = is_tensor_iterator_exist(function); - EXPECT_EQ(ti_found, true); - } else { - bool ti_found = is_tensor_iterator_exist(function); - EXPECT_EQ(ti_found, false); - } - } - - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - InferenceEngine::Blob::Ptr blob = make_blob_with_precision(info.getTensorDesc()); - blob->allocate(); - auto* rawBlobDataPtr = blob->buffer().as(); - std::vector values = ov::test::utils::generate_float_numbers(blob->size(), -0.002f, 0.002f); - for (size_t i = 0; i < blob->size(); i++) { - rawBlobDataPtr[i] = values[i]; - } - return blob; - } -}; - -TEST_P(LSTMSequenceGNATest, CompareWithRefs) { - Run(); -} - -} // namespace LayerTestsDefinitions - -using namespace LayerTestsDefinitions; - -namespace { -std::vector mode{ - ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_CONST, - ngraph::helpers::SequenceTestsMode::PURE_SEQ}; - -std::vector seq_lengths_zero_clip{1}; -std::vector seq_lengths_clip_non_zero{1}; -std::vector batch{1}; -std::vector hidden_size{1, 10}; -std::vector input_size{10}; -std::vector> activations = {{"relu", "sigmoid", "tanh"}, - {"sigmoid", "tanh", "tanh"}, - {"tanh", "relu", "sigmoid"}, - {"tanh", "tanh", "tanh"}, - {"relu", "relu", "relu"}}; -std::vector clip{0.f}; -std::vector clip_non_zeros{0.7f}; -std::vector direction = {ngraph::op::RecurrentSequenceDirection::FORWARD, - ngraph::op::RecurrentSequenceDirection::REVERSE, - ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL}; -std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonZeroClip, - LSTMSequenceGNATest, - ::testing::Combine(::testing::ValuesIn(mode), - ::testing::ValuesIn(seq_lengths_zero_clip), - ::testing::ValuesIn(batch), - ::testing::ValuesIn(hidden_size), - ::testing::ValuesIn(input_size), - ::testing::ValuesIn(activations), - ::testing::ValuesIn(clip), - ::testing::ValuesIn(direction), - ::testing::Values(InputLayerType::CONSTANT), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - LSTMSequenceTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonClip, - LSTMSequenceGNATest, - ::testing::Combine(::testing::ValuesIn(mode), - ::testing::ValuesIn(seq_lengths_clip_non_zero), - ::testing::ValuesIn(batch), - ::testing::ValuesIn(hidden_size), - ::testing::ValuesIn(input_size), - ::testing::ValuesIn(activations), - ::testing::ValuesIn(clip_non_zeros), - ::testing::ValuesIn(direction), - ::testing::Values(InputLayerType::CONSTANT), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - LSTMSequenceTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/mat_mul.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/mat_mul.cpp deleted file mode 100644 index a40afce64cd..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/mat_mul.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/mat_mul.hpp" - -#include - -using namespace LayerTestsDefinitions; - -namespace { - -const std::vector inputPrecisions = {InferenceEngine::Precision::FP32}; - -const std::vector shapeRelatedParams = {{{{5, 1}, true}, {{5, 1}, false}}, - {{{1, 5}, false}, {{1, 5}, true}}, - {{{5}, false}, {{5}, false}}, - {{{5}, true}, {{5}, true}}}; - -std::vector secondaryInputTypes = {ngraph::helpers::InputLayerType::CONSTANT}; - -std::vector> additional_config = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_MatMul, - MatMulTest, - ::testing::Combine(::testing::ValuesIn(shapeRelatedParams), - ::testing::ValuesIn(inputPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(secondaryInputTypes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additional_config)), - MatMulTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/memory.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/memory.cpp deleted file mode 100644 index 8797d3d8d37..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/memory.cpp +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/memory.h" - -#include - -#include "openvino/op/util/variable.hpp" -#include "openvino/opsets/opset11.hpp" -#include "ov_models/builders.hpp" - -using namespace LayerTestsDefinitions; -using namespace ngraph; -using namespace ov::opset11; - -namespace { - -class MemoryTestGna : public MemoryTest { -public: - InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { - // data comparison against relative threshold works correct when input data is shifted away from 0. - // This happens also when POT generated FQ layers are added (see below) to original model. - return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), 5, 5); - } - -protected: - void CreateCommonFunc() override; -}; - -void MemoryTestGna::CreateCommonFunc() { - ov::ParameterVector param{std::make_shared(ngPrc, ov::Shape(inputShape))}; - const auto variable_info = VariableInfo{inputShape, ngPrc, "v0"}; - auto variable = std::make_shared(variable_info); - - auto min55 = ngraph::builder::makeConstant(ngPrc, {}, {-55.001678466796875f}); - auto max55 = ngraph::builder::makeConstant(ngPrc, {}, {55.0f}); - - auto min270 = ngraph::builder::makeConstant(ngPrc, {}, {-270.00823974609375f}); - auto max270 = ngraph::builder::makeConstant(ngPrc, {}, {270.0f}); - - auto min325 = ngraph::builder::makeConstant(ngPrc, {}, {-325.0099182128906f}); - auto max325 = ngraph::builder::makeConstant(ngPrc, {}, {325.0f}); - - auto fq_from_Par225 = std::make_shared(param.at(0), min55, max55, min55, max55, 65536); - - auto read_value = CreateReadValueOp(fq_from_Par225, variable); - - auto fq_from_ReadVal = std::make_shared(read_value, min270, max270, min270, max270, 65536); - - auto add = std::make_shared(fq_from_ReadVal, fq_from_Par225); - - auto fq_from_add = std::make_shared(add, min325, max325, min325, max325, 65536); - - auto assign = CreateAssignOp(fq_from_add, variable); - auto res = std::make_shared(fq_from_add); - - function = std::make_shared(ResultVector{res}, SinkVector{assign}, param, "TestMemory"); -} - -TEST_P(MemoryTestGna, CompareWithRefs) { - Run(); -} - -std::vector transformation{ - ngraph::helpers::MemoryTransformation::NONE, - ngraph::helpers::MemoryTransformation::LOW_LATENCY_V2, - ngraph::helpers::MemoryTransformation::LOW_LATENCY_V2_ORIGINAL_INIT}; - -const std::vector inShapes = {{1, 1}, {1, 2}, {1, 10}}; - -const std::vector inputPrecisions = {InferenceEngine::Precision::FP32}; - -const std::vector iterationCount{1, 3, 4, 10}; - -INSTANTIATE_TEST_SUITE_P(smoke_MemoryTest, - MemoryTestGna, - ::testing::Combine(::testing::ValuesIn(transformation), - ::testing::ValuesIn(iterationCount), - ::testing::ValuesIn(inShapes), - ::testing::ValuesIn(inputPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - MemoryTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/negative_layer_support_test.hpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/negative_layer_support_test.hpp deleted file mode 100644 index c42f588ceb3..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/negative_layer_support_test.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -namespace LayerTestsDefinitions { - -#define GNA_UNSUPPPORTED_LAYER_NEG_TEST(test_class, expected_error_substring, test_configuration) \ - class Negative##test_class : public test_class { \ - public: \ - void Run() override { \ - try { \ - test_class::LoadNetwork(); \ - FAIL() << "GNA's unsupported layers were not detected during LoadNetwork()"; \ - } catch (std::runtime_error & e) { \ - const std::string errorMsg = e.what(); \ - const auto expectedMsg = expected_error_substring; \ - ASSERT_STR_CONTAINS(errorMsg, expectedMsg); \ - EXPECT_TRUE(errorMsg.find(expectedMsg) != std::string::npos) \ - << "Wrong error message, actual error message: " << errorMsg << ", expected: " << expectedMsg; \ - } \ - } \ - }; \ - \ - TEST_P(Negative##test_class, ThrowAsNotSupported) { \ - Run(); \ - } \ - \ - INSTANTIATE_TEST_SUITE_P(smoke_NegativeTestsUnsupportedLayer, \ - Negative##test_class, \ - test_configuration, \ - Negative##test_class::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/pooling.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/pooling.cpp deleted file mode 100644 index 4a1473d8b86..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/pooling.cpp +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/pooling.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace NGraphFunctions; -using namespace LayerTestsDefinitions; - -namespace { - -const std::vector netPrecisions = {InferenceEngine::Precision::FP16}; - -const std::vector> kernels = {{3, 3}, {3, 5}}; -const std::vector> strides = {{1, 1}, {1, 2}}; -const std::vector> padBegins = {{0, 0}, {0, 2}}; -const std::vector> padEnds = {{0, 0}, {0, 2}}; -const std::vector roundingTypes = {ngraph::op::RoundingType::CEIL, - ngraph::op::RoundingType::FLOOR}; -////* ========== Max Polling ========== */ -/* +========== Explicit Pad Floor Rounding ========== */ -const auto maxPool_ExplicitPad_FloorRounding_Params = - ::testing::Combine(::testing::Values(ngraph::helpers::PoolingTypes::MAX), - ::testing::ValuesIn(kernels), - ::testing::ValuesIn(strides), - ::testing::ValuesIn(padBegins), - ::testing::ValuesIn(padEnds), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::EXPLICIT), - ::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling - ); - -// TODO: Issue: 26503 -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_MaxPool_ExplicitPad_FloorRpunding, - PoolingLayerTest, - ::testing::Combine(maxPool_ExplicitPad_FloorRounding_Params, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({1, 3, 30, 30})), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - PoolingLayerTest::getTestCaseName); - -/* ========== Explicit Pad Ceil Rounding ========== */ -const auto maxPool_ExplicitPad_CeilRounding_Params = - ::testing::Combine(::testing::Values(ngraph::helpers::PoolingTypes::MAX), - ::testing::ValuesIn(kernels), - // TODO: Non 1 strides fails in ngraph reference implementation with error "The end corner is out - // of bounds at axis 3" thrown in the test body. - ::testing::Values(std::vector({1, 1})), - ::testing::ValuesIn(padBegins), - ::testing::ValuesIn(padEnds), - ::testing::Values(ngraph::op::RoundingType::CEIL), - ::testing::Values(ngraph::op::PadType::EXPLICIT), - ::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling - ); -// TODO: Issue: 26503 -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_MaxPool_ExplicitPad_CeilRpunding, - PoolingLayerTest, - ::testing::Combine(maxPool_ExplicitPad_CeilRounding_Params, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({1, 3, 30, 30})), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - PoolingLayerTest::getTestCaseName); - -////* ========== Avg Pooling ========== */ -/* +========== Explicit Pad Ceil Rounding ========== */ -const auto avgPoolExplicitPadCeilRoundingParams = - ::testing::Combine(::testing::Values(ngraph::helpers::PoolingTypes::AVG), - ::testing::ValuesIn(kernels), - // TODO: Non 1 strides fails in ngraph reference implementation with error "The end corner is out - // of bounds at axis 3" thrown in the test body. - ::testing::Values(std::vector({1, 1})), - // TODO: Non zero pads excluded because of accuracy mismatch - ::testing::Values(std::vector({0, 0})), - ::testing::Values(std::vector({0, 0})), - ::testing::Values(ngraph::op::RoundingType::CEIL), - ::testing::Values(ngraph::op::PadType::EXPLICIT), - ::testing::Values(true, false)); -// TODO: Issue: 26503 -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_AvgPool_ExplicitPad_CeilRounding, - PoolingLayerTest, - ::testing::Combine(avgPoolExplicitPadCeilRoundingParams, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({1, 3, 30, 30})), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - PoolingLayerTest::getTestCaseName); -/* +========== Explicit Pad Floor Rounding ========== */ -const auto avgPoolExplicitPadFloorRoundingParams = - ::testing::Combine(::testing::Values(ngraph::helpers::PoolingTypes::AVG), - ::testing::ValuesIn(kernels), - ::testing::ValuesIn(strides), - // TODO: Non zero pads excluded because of accuracy mismatch - ::testing::Values(std::vector({0, 0})), - ::testing::Values(std::vector({0, 0})), - ::testing::Values(ngraph::op::RoundingType::FLOOR), - ::testing::Values(ngraph::op::PadType::EXPLICIT), - ::testing::Values(true, false)); - -// TODO: Issue: 26503 -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_AvgPool_ExplicitPad_FloorRounding, - PoolingLayerTest, - ::testing::Combine(avgPoolExplicitPadFloorRoundingParams, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({1, 3, 30, 30})), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - PoolingLayerTest::getTestCaseName); - -////* ========== Avg and Max Polling Cases ========== */ -/* ========== Valid Pad Rounding Not Applicable ========== */ -const auto allPools_ValidPad_Params = ::testing::Combine( - ::testing::Values(ngraph::helpers::PoolingTypes::MAX, ngraph::helpers::PoolingTypes::AVG), - ::testing::ValuesIn(kernels), - ::testing::ValuesIn(strides), - ::testing::Values(std::vector({0, 0})), - ::testing::Values(std::vector({0, 0})), - ::testing::Values( - ngraph::op::RoundingType::FLOOR), // placeholder value - Rounding Type not applicable for Valid pad type - ::testing::Values(ngraph::op::PadType::VALID), - ::testing::Values(false) // placeholder value - exclude pad not applicable for max pooling -); -// TODO: Issue: 26503 -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_MAX_and_AVGPool_ValidPad, - PoolingLayerTest, - ::testing::Combine(allPools_ValidPad_Params, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({1, 3, 30, 30})), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - PoolingLayerTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/power.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/power.cpp deleted file mode 100644 index ca8ec6bf185..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/power.cpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/power.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace LayerTestsDefinitions; - -namespace { - -class PwlUniformDesignPowerLayerTest : public PowerLayerTest { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - std::ostringstream results; - results << PowerLayerTest::getTestCaseName(obj); - results << "_configItem=" << config.first << "_" << config.second; - return results.str(); - } - -protected: - void SetUp() override { - PowerLayerTest::SetUp(); - configuration.emplace(config); - } - -private: - static const std::pair config; -}; - -const std::pair PwlUniformDesignPowerLayerTest::config = {"GNA_PWL_UNIFORM_DESIGN", "YES"}; - -std::vector>> inShapes = - {{{1, 8}}, {{2, 16}}, {{3, 32}}, {{4, 64}}, {{5, 128}}, {{6, 256}}, {{7, 512}}, {{8, 1024}}, {{5}}, {{8}}}; - -std::vector> Power = { - {0.0f}, - {0.5f}, - {1.0f}, - {1.1f}, - {1.5f}, - {2.0f}, -}; - -std::vector> PowerPwlUniformDesign = { - {0.0f}, - {0.5f}, - {1.0f}, - {1.1f}, - {1.5f}, -}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_power, - PowerLayerTest, - ::testing::Combine(::testing::ValuesIn(inShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(Power)), - PowerLayerTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_power, - PwlUniformDesignPowerLayerTest, - ::testing::Combine(::testing::ValuesIn(inShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(PowerPwlUniformDesign)), - PwlUniformDesignPowerLayerTest::getTestCaseName); - -TEST_P(PwlUniformDesignPowerLayerTest, CompareWithRefs) { - Run(); -}; - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/split.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/split.cpp deleted file mode 100644 index 346fc819a71..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/split.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/split.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace LayerTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -// TODO: Issue: 26411 -INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_NumSplitsCheck, - SplitLayerTest, - ::testing::Combine(::testing::Values(1), - ::testing::Values(0, 1), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(std::vector({30, 30})), - ::testing::Values(std::vector({})), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - SplitLayerTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/tensor_iterator.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/tensor_iterator.cpp deleted file mode 100644 index a97374a19ae..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/single_layer_tests/tensor_iterator.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "single_layer_tests/tensor_iterator.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace LayerTestsDefinitions; - -namespace { -const std::vector should_decompose = {false}; -const std::vector seqLengths = {1}; -const std::vector batches = {1}; -const std::vector hiddenSizes = {128, 200, 300}; -const std::vector seqAxes = {0, 1}; -const std::vector clip = {0.f}; -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -INSTANTIATE_TEST_SUITE_P(smoke_TensorIterator, - TensorIteratorTest, - ::testing::Combine(::testing::ValuesIn(should_decompose), - ::testing::ValuesIn(seqLengths), - ::testing::ValuesIn(batches), - ::testing::ValuesIn(hiddenSizes), - ::testing::ValuesIn(seqAxes), - ::testing::ValuesIn(clip), - ::testing::Values(ngraph::helpers::TensorIteratorBody::LSTM), - ::testing::Values(ngraph::op::RecurrentSequenceDirection::FORWARD), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - TensorIteratorTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/skip_tests_check.hpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/skip_tests_check.hpp deleted file mode 100644 index 50e7fe41460..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/skip_tests_check.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common_test_utils/test_constants.hpp" -#include "ie_core.hpp" - -class GnaLayerTestCheck { - bool verRead = false; - int verMajor; - int verMinor; - std::string lastMsg; - -public: - void SetUp(const std::string deviceName) { - InferenceEngine::Core ieCore; - auto metrics = ieCore.GetMetric(deviceName, METRIC_KEY(SUPPORTED_METRICS)).as>(); - - if (deviceName == ov::test::utils::DEVICE_GNA) { - if (std::find(metrics.begin(), metrics.end(), METRIC_KEY(GNA_LIBRARY_FULL_VERSION)) != metrics.end()) { - auto gnaLibVerStr = - ieCore.GetMetric(deviceName, METRIC_KEY(GNA_LIBRARY_FULL_VERSION)).as(); - verRead = sscanf(gnaLibVerStr.c_str(), "%d.%d", &verMajor, &verMinor) == 2; - } - } - } - - std::string& getLastCmpResultMsg() { - return lastMsg; - } - - bool gnaLibVersionLessThan(std::string verToCmp) { - int verToCmpMajor; - int verToCmpMinor; - - if (!verRead) { - IE_THROW() << "GnaLayerTestCheck requires initialization with SetUp()"; - } - - if (sscanf(verToCmp.c_str(), "%d.%d", &verToCmpMajor, &verToCmpMinor) != 2) { - return false; - } - - if (verMajor < verToCmpMajor || (verMajor == verToCmpMajor && verMinor < verToCmpMinor)) { - lastMsg = "GNA library version is less than " + verToCmp; - return true; - } - return false; - } -}; diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/skip_tests_config.cpp deleted file mode 100644 index 23248f19473..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/skip_tests_config.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "functional_test_utils/skip_tests_config.hpp" - -#include -#include - -std::vector disabledTestPatterns() { - return { - // TODO: FIX BUG 31661 - // TODO: support InferRequest in GNAPlugin - ".*InferRequestMultithreadingTests\\.canRun3AsyncRequestsConsistentlyFromThreadsWithoutWait.*", - // TODO: FIX BUG 23741 - ".*InferRequestMultithreadingTests\\.canRun3SyncRequestsConsistentlyFromThreads.*", - // TODO: FIX BUG 59041 - ".*Behavior.*CallbackThrowException.*", - // TODO: FIX BUG 32210 - R"(.*ActivationFQSubgraph.*activation=(Exp|Log).*)", - // TODO: Issue 32542 - R"(.*(EltwiseLayerTest).*eltwiseOpType=(Sum|Sub).*opType=SCALAR.*)", - // TODO: Issue 32541 - R"(.*(EltwiseLayerTest).*eltwiseOpType=Prod.*secondaryInputType=PARAMETER.*opType=SCALAR.*)", - // TODO: Issue: 34348 - R"(.*IEClassGetAvailableDevices.*)", - // TODO: Issue 39358 - R"(.*unaligned.*MultipleConcatTest.*)", - R"(.*ActivationConcatsEltwise.*CS=35.*)", - // TODO: Issue 38974 - R"(.*ConcatMultiInput.CompareWithRefConstOnly.*IS=\(1.8\).*)", - R"(.*ConcatMultiInput.CompareWithRefConstOnly.*IS=\(1.16\).*)", - R"(.*ConcatMultiInput.CompareWithRefConstOnly.*IS=\(1.32\).*)", - // TODO: Issue: 46416 - R"(.*InferRequestVariableStateTest.inferreq_smoke_VariableState_2infers*.*)", - // TODO: Issue 24839 - R"(.*ConvolutionLayerTestFixture.CompareWithRefs.*D=\(1.3\).*)", - R"(.*ConvolutionLayerTestFixture.CompareWithRefs.*D=\(3.1\).*)", - R"(.*ConstantResultSubgraphTest.*IS=\(2\.3\.4\.5\).*)", - R"(.*ConstantResultSubgraphTest.*inPrc=(U8|I8|I32|U64|I64|BOOL).*)", - R"(.*importExportedFunctionParameterResultOnly.*)", - R"(.*importExportedFunctionConstantResultOnly.*)", - R"(.*importExportedIENetworkConstantResultOnly.*)", - R"(.*importExportedIENetworkParameterResultOnly.*)", - - // Issue 57368 (accuracy) - R"(.*smoke_MemoryTest.*transformation=LOW_LATENCY.*)", - - // Not implemented yet - R"(.*Behavior.*ExecutableNetworkBaseTest.*(canSetConfigToExecNet|canSetConfigToExecNetWithIncorrectConfig).*)", - R"(.*Behavior.*OVCompiledModelBaseTest.*(canSetConfigToCompiledModel|canSetConfigToCompiledModelWithIncorrectConfig).*)", - R"(.*Behavior.*ExecutableNetworkBaseTest.*(CheckExecGraphInfoBeforeExecution|CheckExecGraphInfoAfterExecution|CheckExecGraphInfoSerialization).*)", - R"(.*Behavior.*OVCompiledModelBaseTestOptional.*(CheckExecGraphInfoBeforeExecution|CheckExecGraphInfoAfterExecution).*)", - R"(.*Behavior.*ExecutableNetworkBaseTest.*canExport.*)", - R"(.*Behavior.*OVCompiledModelBaseTest.*canExportModel.*)", - R"(.*Behavior.*ExecutableNetworkBaseTest.*(CanCreateTwoExeNetworksAndCheckFunction).*)", - R"(.*Behavior.*OVCompiledModelBaseTest.*(canCreateTwoCompiledModelAndCheckTheir).*)", - R"(.*Behavior.*ExecutableNetworkBaseTest.*(checkGetExecGraphInfoIsNotNullptr).*)", - R"(.*Behavior.*OVCompiledModelBaseTest.*(checkGetExecGraphInfoIsNotNullptr).*)", - // Not implemented yet (dynamic cases) - R"(.*Behavior.*OVInferenceChaining.*(StaticOutputToDynamicInput).*)", - R"(.*Behavior.*OVInferenceChaining.*(DynamicOutputToDynamicInput).*)", - R"(.*Behavior.*OVInferenceChaining.*(DynamicInputToDynamicOutput).*)", - R"(.*Behavior.*OVInferRequestDynamicTests.*)", - // Not expected behavior - R"(.*Behavior.*ExecNetSetPrecision.*canSetInputPrecisionForNetwork.*FP16.*)", - R"(.*OVCompiledModelBaseTest.*canSetConfigToCompiledModel.*)", - R"(.*OVCompiledModelBaseTest.*canGetInputsInfoAndCheck.*)", - R"(.*OVCompiledModelBaseTest.*getOutputsFromSplitFunctionWithSeveralOutputs.*)", - R"(.*OVCompiledModelBaseTest.*canCompileModelFromMemory.*)", - R"(.*(OVClass|IEClass)HeteroExecutableNetworkGetMetricTest_TARGET_FALLBACK.*GetMetricNoThrow.*)", - R"(.*LoadNetwork*.*LoadNetwork(HETEROWithDeviceIDNoThrow|WithBigDeviceID|WithInvalidDeviceID)*.*)", - R"(.*QueryNetwork*.*QueryNetwork(HETEROWithDeviceIDNoThrow|WithBigDeviceID|WithInvalidDeviceID)*.*)", - R"(.*QueryModel*.*QueryModel(HETEROWithDeviceIDNoThrow|WithBigDeviceID|WithInvalidDeviceID)*.*)", - R"(.*LoadNetworkTest.*QueryNetwork(MULTIWithHETERO|HETEROWithMULTI)NoThrow_V10.*)", - R"(.*Behavior.*OVCompiledModelBaseTest.*get(Inputs|Outputs)FromFunctionWithSeveral(Inputs|Outputs).*)", - // TODO: temporary disabled. Need to be enabled when PR 9282 is merged - R"(.*OVCompiledGraphImportExportTest.*readFromV10IR.*)", - // Issue connected with OV2.0 - R"(.*EltwiseLayerTest.*NetType=f16.*)", - // TODO: Issue: 69639 - R"(.*EltwiseLayerTest.*OpType=Prod.*)", - R"(.*EltwiseLayerTest.*OpType=Sum.*PARAMETER.*VECTOR.*)", - // TODO: Issue:27391 - // TODO: Issue:28036 - R"(.*ActivationLayerGNATest.*(Log|Exp).*netPRC=(FP16|FP32).*)", - // TODO: Issue: 71068 - R"(.*OVInferRequestCancellationTests.*)", - // TODO: Issue: 95609 - R"(.*CompileModelCacheTestBase.*(ConvPoolRelu|TIwithLSTMcell1).*batch2.*)", - R"(.*CompileModelCacheTestBase.*(SplitConvConcat|KSOFunction).*)", - R"(.*CompileModelCacheTestBase.*(SingleConv|NestedSplitConvConcat).*)", - R"(.*CompileModelCacheTestBase.*(Bias|ReadConcatSplitAssign).*)", - // does not work due to GNA 3.0 convolution and other primitives limitations, partially can be resolved by - // switching GNA library to GNA3.5 - R"(.*CachingSupportCase.*LoadNet.*(Bias|Split|Concat|KSO|SingleConv).*)", - R"(.*CachingSupportCase.*LoadNet.*(ConvPoolRelu|TIwithLSTMcell1)_f32_batch2.*)", - R"(.*smoke_Multi_BehaviorTests.*)", - // unsupported metrics - R"(.*smoke_MultiHeteroOVGetMetricPropsTest.*OVGetMetricPropsTest.*(AVAILABLE_DEVICES|OPTIMIZATION_CAPABILITIES|RANGE_FOR_ASYNC_INFER_REQUESTS|RANGE_FOR_STREAMS).*)", - // TODO: Issue: 111556 - R"(.*SplitConvTest.CompareWithRefImpl.*IS=\(1.(128|256)\).*IC=4.*OC=4.*configItem=GNA_DEVICE_MODE_GNA_SW_FP32)", - // TODO: Issue: 114149 - R"(.*smoke_Decompose2DConv.*)", - // TODO: Issue: 123306 - R"(smoke_convert_matmul_to_fc/ConvertMatmulToFcWithTransposesPass.CompareWithRefImpl/netPRC=FP(32|16)_targetDevice=GNA__configItem=GNA_COMPACT_MODE_NO_configItem=GNA_DEVICE_MODE_GNA_SW_(FP32|EXACT)_IS=\(8.*)", - // TODO: CVS-125686 - R"(.*OVCompiledModelBaseTest.*CanSetOutputPrecisionForNetwork.*)", - R"(.*OVCompiledModelBaseTest.*CanSetInputPrecisionForNetwork.*)", - R"(.*OVCompiledModelBaseTest.*CanCreateTwoCompiledModelsAndCheckRuntimeModel.*)", - R"(.*OVInferRequestWaitTests.*FailedAsyncInferWithNegativeTimeForWait.*)", - // TODO: Issue 127801 - R"(.*smoke_MemoryTest.*transformation=NONE.*)", - R"(.*smoke_concat_memory.*)", - }; -} diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/activation_concats_eltwise.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/activation_concats_eltwise.cpp deleted file mode 100644 index 2cf78feeac4..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/activation_concats_eltwise.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/activation_concats_eltwise.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; -namespace { -std::vector input_sizes = {7, 16, 35, 64}; - -std::vector concat_const_sizes = {7, 16, 35, 64}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_CompareRefs, - ActivationConcatsEltwise, - ::testing::Combine(::testing::ValuesIn(input_sizes), - ::testing::ValuesIn(concat_const_sizes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ActivationConcatsEltwise::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/activation_fq.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/activation_fq.cpp deleted file mode 100644 index e891e91ce33..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/activation_fq.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/activation_fq.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -const std::vector netPrecisions = {InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32}; - -using ConfigType = std::map; -const ConfigType configFP32 = { - {"GNA_DEVICE_MODE", "GNA_SW_FP32"}, -}; - -const ConfigType configSWExact = {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_COMPACT_MODE", "NO"}}; - -const std::vector> gnaQuantModes = {{"sw_fp32", configFP32}, - {"sw_exact", configSWExact}}; - -const std::vector> inputShapes = {{1, 250}, {1, 640}, {1, 1024}}; - -const std::vector level = {65535}; -const std::vector> inputParams = {{-1, 1, 0.01}, {-5, 5, 1}, {-100, 100, 1}, {-16, 16, 1}}; - -const std::vector>> constShapes = {{{1}}}; - -const auto fqParams = - ::testing::Combine(::testing::Values(level), ::testing::ValuesIn(constShapes), ::testing::ValuesIn(inputParams)); - -const std::vector activations = {ngraph::helpers::ActivationTypes::Sigmoid, - ngraph::helpers::ActivationTypes::Tanh, - ngraph::helpers::ActivationTypes::Relu, - ngraph::helpers::ActivationTypes::Log, - ngraph::helpers::ActivationTypes::Abs, - ngraph::helpers::ActivationTypes::Sign, - ngraph::helpers::ActivationTypes::Exp}; - -INSTANTIATE_TEST_SUITE_P(smoke_ActivationFQSubgraph, - ActivationFakeQuantizeSubgraphTest, - ::testing::Combine(fqParams, - ::testing::ValuesIn(activations), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(gnaQuantModes)), - ActivationFakeQuantizeSubgraphTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/basic_lstm.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/basic_lstm.cpp deleted file mode 100644 index 07cbfe2ea97..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/basic_lstm.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/basic_lstm.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "1638.4"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}, {"GNA_SCALE_FACTOR_0", "1638.4"}}}; - -const std::vector> size_params = { - {49, 118}, - {300, 38}, -}; - -size_t small_num_cells = 10; - -size_t big_num_cells = 49; - -std::pair weights_range = {0.f, 0.02f}; - -const std::vector decompose = {false, true}; - -INSTANTIATE_TEST_SUITE_P(smoke_BasicLSTM, - Basic_LSTM_S, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(size_params), - ::testing::Values(small_num_cells), - ::testing::ValuesIn(decompose), - ::testing::Values(weights_range)), - Basic_LSTM_S::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_BasicLSTM_big_cells_num, - Basic_LSTM_S, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::Values(size_params[0]), - ::testing::Values(big_num_cells), - ::testing::ValuesIn(decompose), - ::testing::Values(weights_range)), - Basic_LSTM_S::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/broadcast_power.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/broadcast_power.cpp deleted file mode 100644 index ff1bce53931..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/broadcast_power.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_COMPACT_MODE", "NO"}, {"GNA_SCALE_FACTOR_0", "2048"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -const std::vector>> input_shapes{ - {{1, 8224}, {1, 257, 32}}, - {{2, 8224}, {1, 257, 64}}, - {{4, 8224}, {1, 257, 128}}, - {{8, 128}, {8, 128}}, - {{16, 128}, {16, 128}}, - {{18, 128}, {18, 128}}, - {{1, 16, 1, 128}, {1, 16, 1, 128}}, - {{1, 8, 15, 128}, {1, 8, 15, 128}}, - {{4, 4, 4, 4}, {4, 4, 4, 4}}, - {{1, 4, 4, 128}, {1, 4, 4, 128}} - // TODO: needed add split over channels - // {{8, 8224}}, -}; - -INSTANTIATE_TEST_SUITE_P(PowerBroadcast, - BroadcastPowerTest, - ::testing::Combine(::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - BroadcastPowerTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/cascade_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/cascade_concat.cpp deleted file mode 100644 index 668d0219022..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/cascade_concat.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector>> shape1{{{1, 64}}, {{1, 128}}, {{1, 32}}, {{1, 16}}, {{1, 8}}}; - -std::vector>> shape2{{{1, 72}}, {{1, 128}}, {{1, 32}}, {{1, 16}}, {{1, 8}}}; - -std::vector>> shape3{{{1, 80}}, {{1, 128}}, {{1, 32}}, {{1, 16}}, {{1, 8}}}; - -std::vector> shape_one_input{{1, 64}, {1, 128}, {1, 32}}; - -std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -std::map additional_config = {{"GNA_SCALE_FACTOR_0", "1"}, - {"GNA_SCALE_FACTOR_1", "1"}, - {"GNA_SCALE_FACTOR_2", "1"}}; - -std::vector> additional_config_one_input = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_cascade_concat, - CascadeConcat, - ::testing::Combine(::testing::ValuesIn(shape1), - ::testing::ValuesIn(shape2), - ::testing::ValuesIn(shape3), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(false), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(additional_config)), - CascadeConcat::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_cascade_concat_multioutput, - CascadeConcat, - ::testing::Combine(::testing::ValuesIn(shape1), - ::testing::ValuesIn(shape2), - ::testing::ValuesIn(shape3), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(true), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(additional_config)), - CascadeConcat::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_cascade_concat_reshape, - CascadeConcatWithMultiConnReshape, - ::testing::Combine(::testing::ValuesIn(shape_one_input), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additional_config_one_input)), - CascadeConcatWithMultiConnReshape::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/clamp_fq.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/clamp_fq.cpp deleted file mode 100644 index 59000337a6f..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/clamp_fq.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/clamp_fq.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -const std::vector netPrecisions = {InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32}; - -using ConfigType = std::map; -const ConfigType configFP32 = { - {"GNA_DEVICE_MODE", "GNA_SW_FP32"}, -}; - -const ConfigType configSWExact = {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_COMPACT_MODE", "NO"}}; - -const std::vector> gnaQuantModes = {{"sw_fp32", configFP32}, - {"sw_exact", configSWExact}}; - -const std::vector> inputShapes = {{1, 250}, {1, 640}, {1, 1024}}; - -const std::vector level = {65535}; -const std::vector> inputParams = {{-16, 16, 1}, - {-40, 40, 1}, - {0, 10, 1}, - {-50, 0, 1}, - {0, 50, 1}, - {-100, 100, 1}, - {-5, 5, 1}, - {-10, 10, 1}, - {-14, 14, 1}}; -const std::vector> clampMaxMin = - {{-5, 5}, {-20, 20}, {-25, 0}, {-30, 25}, {0, 40}, {-10, 10}, {-14, 14}}; - -const std::vector>> constShapes = {{{1}}}; - -const auto fqParams = ::testing::Combine(::testing::Values(level), - ::testing::ValuesIn(constShapes), - ::testing::ValuesIn(clampMaxMin), - ::testing::ValuesIn(inputParams)); - -INSTANTIATE_TEST_SUITE_P(smoke_Clamp_FQ_subgraph, - ClampFakeQuantizeSubgraphTest, - ::testing::Combine(fqParams, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(gnaQuantModes)), - ClampFakeQuantizeSubgraphTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_conv.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_conv.cpp deleted file mode 100644 index 92b0a3b6522..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_conv.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/concat_conv.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -std::vector params = {std::make_tuple(std::vector{1, 32}, // InputShape - std::vector{1, 3}, // KernelShape - 1), // Stride - std::make_tuple(std::vector{1, 64}, std::vector{1, 5}, 1), - std::make_tuple(std::vector{1, 256}, std::vector{1, 9}, 2)}; - -std::vector inputChannels = {1}; - -std::vector outputChannels = {4, 8}; - -INSTANTIATE_TEST_SUITE_P(smoke_ConcatConvTest, - ConcatConvTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)), - ConcatConvTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_multi_input.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_multi_input.cpp deleted file mode 100644 index a0b9df55826..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_multi_input.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/concat_multi_input.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -std::vector>> inShapes = { - {{1, 8}, {1, 8}}, - {{1, 3}, {1, 3}, {1, 3}}, - {{1, 16}, {1, 16}, {1, 16}}, - {{1, 16}, {1, 16}, {1, 16}, {1, 16}}, - {{1, 32}, {1, 32}, {1, 32}, {1, 32}}, - {{1, 16}, {1, 32}, {1, 16}, {1, 32}, {1, 16}, {1, 32}}, -}; - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -std::vector> configs = {{ - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_COMPACT_MODE", "NO"}, - {"GNA_SCALE_FACTOR_0", "2048"}, - {"GNA_PRECISION", "I16"}, - }, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_multi_input, - ConcatMultiInput, - ::testing::Combine(::testing::ValuesIn(inShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConcatMultiInput::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_quantization.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_quantization.cpp deleted file mode 100644 index 1c21697ac99..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_quantization.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/concat_quantization.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::I16, - InferenceEngine::Precision::U8}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_ConcatQuantization, - ConcatQuantization, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConcatQuantization::getTestCaseName); diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_quantization_during_memory_requantization.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_quantization_during_memory_requantization.cpp deleted file mode 100644 index e366aeb92ac..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/concat_quantization_during_memory_requantization.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/concat_quantization_during_memory_requantization.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "gna/gna_config.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector netPrecisions = {InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32}; - -std::vector> additionalConfig = { - {{"GNA_COMPACT_MODE", "NO"}}, - {{"GNA_COMPACT_MODE", "NO"}, {"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -std::vector inputSizes = {128, 64, 32}; - -std::vector hiddenSizes = {128, 64, 32}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_quant_memory_requant, - ConcatQuantDuringMemoryRequantTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(inputSizes), - ::testing::ValuesIn(hiddenSizes), - ::testing::ValuesIn(additionalConfig)), - ConcatQuantDuringMemoryRequantTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/connect_split_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/connect_split_concat.cpp deleted file mode 100644 index e6488e95487..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/connect_split_concat.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/connect_split_concat_concat.hpp" -#include "subgraph_tests/multiple_connect_split_concat.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -std::map additional_config = {{"GNA_COMPACT_MODE", "NO"}}; - -INSTANTIATE_TEST_SUITE_P(multiple_connect_split_concat, - MultipleConnectSplitConcatTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(additional_config)), - MultipleConnectSplitConcatTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(connect_split_concat_concat, - SplitConcatConcatTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(additional_config)), - MultipleConnectSplitConcatTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/const_conv_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/const_conv_concat.cpp deleted file mode 100644 index 65543b21da3..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/const_conv_concat.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/const_conv_concat.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -std::vector params = {std::make_tuple(std::vector{1, 64}, // InputShape - std::vector{1, 3}, // KernelShape - 1), // Stride - std::make_tuple(std::vector{1, 128}, std::vector{1, 5}, 1), - std::make_tuple(std::vector{1, 168}, std::vector{1, 3}, 2), - std::make_tuple(std::vector{1, 320}, std::vector{1, 8}, 4)}; - -std::vector inputChannels = {1, 4, 8}; - -std::vector outputChannels = {64}; - -INSTANTIATE_TEST_SUITE_P(smoke_ConstConvConcatTest, - ConstConvConcatTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)), - ConstConvConcatTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/const_strided_slice_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/const_strided_slice_concat.cpp deleted file mode 100644 index 14db4155c60..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/const_strided_slice_concat.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/const_strided_slice_concat.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -std::vector inputChunksSizes = {32, 64}; -std::vector inputChunksNumber = {4, 7}; - -std::vector constChunksSizes = {96, 128}; -std::vector constChunksNumber = {1, 3}; - -INSTANTIATE_TEST_SUITE_P(smoke_ConstStridedSliceConcatTest, - ConstStridedSliceConcatTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputChunksSizes), - ::testing::ValuesIn(inputChunksNumber), - ::testing::ValuesIn(constChunksSizes), - ::testing::ValuesIn(constChunksNumber)), - ConstStridedSliceConcatTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/constant_result.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/constant_result.cpp deleted file mode 100644 index 312466a2f76..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/constant_result.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common_test_utils/test_constants.hpp" -#include "subgraph_tests/constant_result_legacy.hpp" - -using namespace SubgraphTestsDefinitions; -using namespace InferenceEngine; - -namespace { - -const std::vector types = {ConstantSubgraphType::SINGLE_COMPONENT, - ConstantSubgraphType::SEVERAL_COMPONENT}; - -const std::vector shapes = {{1, 3, 10, 10}, {2, 3, 4, 5}}; - -const std::vector precisions = {Precision::U8, - Precision::I8, - Precision::U16, - Precision::I16, - Precision::I32, - Precision::U64, - Precision::I64, - Precision::FP32, - Precision::BOOL}; - -INSTANTIATE_TEST_SUITE_P(smoke_Check, - ConstantResultSubgraphTest, - ::testing::Combine(::testing::ValuesIn(types), - ::testing::ValuesIn(shapes), - ::testing::ValuesIn(precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ConstantResultSubgraphTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/conv_fq_eltwise.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/conv_fq_eltwise.cpp deleted file mode 100644 index 520673d9107..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/conv_fq_eltwise.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/conv_fq_eltwise.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -const std::vector> inputShapes = {{1, 1024}}; - -const size_t levels = 65535; - -const std::vector> inputParams = {{-10, 10, 1}}; - -const float convFQValue = 2.0f; - -const auto fqParams = - ::testing::Combine(::testing::Values(levels), ::testing::ValuesIn(inputParams), ::testing::Values(convFQValue)); - -const std::vector> kernels = {{1, 3}}; -const std::vector> strides = {{1, 1}}; -const std::vector inputChannels = {8}; -const std::vector outputChannels{4}; - -const auto convParams = ::testing::Combine(::testing::ValuesIn(kernels), - ::testing::ValuesIn(strides), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)); - -INSTANTIATE_TEST_SUITE_P(smoke_ConvFqEltwiseTest, - ConvFqEltwiseTest, - ::testing::Combine(fqParams, - convParams, - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(inputShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvFqEltwiseTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/conv_fq_relu.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/conv_fq_relu.cpp deleted file mode 100644 index 187bdd0b795..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/conv_fq_relu.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/conv_fq_relu.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -const std::vector> inputShapes = {{1, 1024}}; - -const size_t levels = 65535; - -const std::vector> inputParams = {{-100, 100, 1}}; - -const float convFQValue = 2.0f; - -const auto fqParams = - ::testing::Combine(::testing::Values(levels), ::testing::ValuesIn(inputParams), ::testing::Values(convFQValue)); - -const std::vector> kernels = {{1, 3}}; -const std::vector> strides = {{1, 1}}; -const std::vector inputChannels = {8}; -const std::vector outputChannels{4}; - -const auto convParams = ::testing::Combine(::testing::ValuesIn(kernels), - ::testing::ValuesIn(strides), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)); - -INSTANTIATE_TEST_SUITE_P(smoke_ConvFqReluTest, - ConvFqReluTest, - ::testing::Combine(fqParams, - convParams, - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(inputShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvFqReluTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/convolution_relu_sequence.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/convolution_relu_sequence.cpp deleted file mode 100644 index 5c26365a836..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/convolution_relu_sequence.cpp +++ /dev/null @@ -1,282 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/convolution_relu_sequence.hpp" - -#include - -#include "../skip_tests_check.hpp" -#include "common_test_utils/test_constants.hpp" -#include "gna/gna_config.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -class GnaConvolutionReluSequenceTest : public ConvolutionReluSequenceTest { -protected: - void Run() override { - ConvolutionReluSequenceTest::Run(); - } - - void SetUp() override { - ConvolutionReluSequenceTest::SetUp(); - } -}; - -TEST_P(GnaConvolutionReluSequenceTest, CompareWithRefs) { - Run(); -} - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector inputShapeSimple = { - {1, 32, 64, 32}, -}; - -const std::vector convReluSpecificParamsSimpleSeq{ - { - {2, 2}, // Kernel size - {2, 2}, // Stride - {0, 0}, // Pad begin - {0, 0}, // Pad end - 16, // Num out channels - {1, 1}, // Pooling window - {1, 1} // Pooling stride - }, - { - {2, 1}, // Kernel size - {2, 1}, // Stride - {0, 0}, // Pad begin - {0, 0}, // Pad end - 8, // Num out channels - {1, 1}, // Pooling window - {1, 1} // Pooling stride - }, -}; - -const std::vector inputShapeSimpleWithPooling = { - {1, 32, 53, 110}, -}; - -const std::vector convReluSpecificParamsSimpleSeqWithPooling{ - { - {3, 3}, // Kernel size - {1, 1}, // Stride - {0, 0}, // Pad begin - {0, 0}, // Pad end - 16, // Num out channels - {3, 3}, // Pooling window - {3, 3} // Pooling stride - }, - { - {2, 2}, // Kernel size - {1, 2}, // Stride - {0, 0}, // Pad begin - {0, 0}, // Pad end - 8, // Num out channels - {2, 2}, // Pooling window - {2, 2} // Pooling stride - }, -}; - -const InferenceEngine::SizeVector inputShapeFB = { - {1, 1, 5, 236}, -}; - -const std::vector convReluSpecificParamsFBSeq = { - { - {5, 7}, // Kernel size - {1, 1}, // Stride - {2, 3}, // Pad begin - {2, 3}, // Pad end - 32, // Num out channels - {1, 1}, // Pooling window - {1, 1} // Pooling stride - }, - { - {9, 5}, // Kernel size - {1, 1}, // Stride - {4, 2}, // Pad begin - {4, 2}, // Pad end - 32, // Num out channels - {1, 1}, // Pooling window - {1, 1} // Pooling stride - }, - { - {1, 1}, // Kernel size - {1, 1}, // Stride - {0, 0}, // Pad begin - {0, 0}, // Pad end - 8, // Num out channels - {1, 1}, // Pooling window - {1, 1} // Pooling stride - }, -}; - -const InferenceEngine::SizeVector inputShape3 = { - {1, 8, 18, 54}, -}; - -const std::vector convReluSpecificParams3Seq = { - { - {1, 3}, // Kernel size - {1, 1}, // Stride - {0, 0}, // Pad begin - {0, 0}, // Pad end - 32, // Num out channels - {1, 1}, // Pooling window - {1, 1} // Pooling stride - }, - { - {2, 1}, // Kernel size - {1, 1}, // Stride - {0, 0}, // Pad begin - {0, 0}, // Pad end - 8, // Num out channels - {1, 1}, // Pooling window - {1, 1} // Pooling stride - }, - { - {3, 3}, // Kernel size - {3, 3}, // Stride - {0, 0}, // Pad begin - {0, 0}, // Pad end - 8, // Num out channels - {3, 3}, // Pooling window - {3, 3} // Pooling stride - }, -}; - -const std::vector convReluSpecificParamsAllAll = { - {inputShapeSimple, convReluSpecificParamsSimpleSeq}, - {inputShape3, convReluSpecificParams3Seq}, - // Enable when bigger kernels (e.g., 5x7, 9x5) and input padding supported - // { - // inputShapeFB, - // convReluSpecificParamsFBSeq - // }, - {inputShapeSimpleWithPooling, convReluSpecificParamsSimpleSeqWithPooling}}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}}; - -const std::vector> configs_allowing_pooling_stride_above_window = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_2_0"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_ConvolutionReluSequenceTest, - GnaConvolutionReluSequenceTest, - ::testing::Combine(::testing::ValuesIn(convReluSpecificParamsAllAll), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - GnaConvolutionReluSequenceTest::getTestCaseName); - -const InferenceEngine::SizeVector inputShape1Even = { - {1, 1, 48, 1}, -}; - -const InferenceEngine::SizeVector inputShape1DOneAbove = { - {1, 1, 41, 1}, -}; - -const InferenceEngine::SizeVector inputShape1DOneBelow = { - {1, 1, 47, 1}, -}; - -const InferenceEngine::SizeVector inputShape1DMultichannel4 = { - {1, 4, 49, 1}, -}; - -const InferenceEngine::SizeVector inputShape1DMultichannel5 = { - {1, 5, 49, 1}, -}; - -const InferenceEngine::SizeVector inputShape1DMultichannel6 = { - {1, 6, 49, 1}, -}; - -const InferenceEngine::SizeVector inputShape1DMultichannel7 = { - {1, 7, 49, 1}, -}; - -const InferenceEngine::SizeVector inputShape1DMultichannel8 = { - {1, 8, 49, 1}, -}; - -const InferenceEngine::SizeVector inputShape1DMultichannel9 = { - {1, 9, 49, 1}, -}; - -const std::vector poolingStrideBelowWindow = { - { - {3, 1}, // Kernel size - {2, 1}, // Stride - {0, 0}, // Pad begin - {0, 0}, // Pad end - 4, // Num out channels - {4, 1}, // Pooling window - {2, 1} // Pooling stride - }, -}; - -const std::vector poolingStrideAboveWindow = { - { - {3, 1}, // Kernel size - {2, 1}, // Stride - {0, 0}, // Pad begin - {0, 0}, // Pad end - 4, // Num out channels - {2, 1}, // Pooling window - {4, 1} // Pooling stride - }, -}; - -const std::vector poolingStrideNotEqualWindow_Above = { - {inputShape1Even, poolingStrideAboveWindow}, - {inputShape1DOneAbove, poolingStrideAboveWindow}, - {inputShape1DOneBelow, poolingStrideAboveWindow}, - {inputShape1DMultichannel4, poolingStrideAboveWindow}, - {inputShape1DMultichannel5, poolingStrideAboveWindow}, - {inputShape1DMultichannel6, poolingStrideAboveWindow}, - {inputShape1DMultichannel7, poolingStrideAboveWindow}, - {inputShape1DMultichannel8, poolingStrideAboveWindow}, - {inputShape1DMultichannel9, poolingStrideAboveWindow}}; - -INSTANTIATE_TEST_SUITE_P(smoke_ConvolutionPoolingStrideNotEqualWindowTest_Above, - ConvolutionReluSequenceTest, - ::testing::Combine(::testing::ValuesIn(poolingStrideNotEqualWindow_Above), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs_allowing_pooling_stride_above_window)), - ConvolutionReluSequenceTest::getTestCaseName); - -const std::vector poolingStrideNotEqualWindow_Below = { - {inputShape1Even, poolingStrideBelowWindow}, - {inputShape1DOneAbove, poolingStrideBelowWindow}, - {inputShape1DOneBelow, poolingStrideBelowWindow}, - {inputShape1DMultichannel4, poolingStrideBelowWindow}, - {inputShape1DMultichannel5, poolingStrideBelowWindow}, - {inputShape1DMultichannel6, poolingStrideBelowWindow}, - {inputShape1DMultichannel7, poolingStrideBelowWindow}, - {inputShape1DMultichannel8, poolingStrideBelowWindow}, - {inputShape1DMultichannel9, poolingStrideBelowWindow}}; - -INSTANTIATE_TEST_SUITE_P(smoke_ConvolutionPoolingStrideNotEqualWindowTest_Below, - ConvolutionReluSequenceTest, - ::testing::Combine(::testing::ValuesIn(poolingStrideNotEqualWindow_Below), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - ConvolutionReluSequenceTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/copy_before_squeeze.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/copy_before_squeeze.cpp deleted file mode 100644 index 10dd726fa70..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/copy_before_squeeze.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/copy_before_squeeze.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "gna/gna_config.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector netPrecisions = {InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32}; - -std::map config = {{"GNA_COMPACT_MODE", "NO"}}; - -std::vector> inputShapes = {{1, 512}, {1, 1024}, {1, 192}, {1, 640}}; - -INSTANTIATE_TEST_SUITE_P(smoke_copy_before_squeeze, - CopyBeforeSqueezeTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(inputShapes), - ::testing::Values(config)), - CopyBeforeSqueezeTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/delayed_copy_layer.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/delayed_copy_layer.cpp deleted file mode 100644 index 272c149045e..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/delayed_copy_layer.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/delayed_copy_layer.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "gna/gna_config.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, -}; - -std::vector> additional_config = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -std::vector memory_sizes = {128, 256, 32}; - -INSTANTIATE_TEST_SUITE_P(smoke_delayed_copy_layer, - DelayedCopyTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additional_config), - ::testing::ValuesIn(memory_sizes)), - DelayedCopyTestBase::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_delayed_copy_layer, - DelayedCopyAfterReshapeWithMultipleConnTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additional_config), - ::testing::ValuesIn(memory_sizes)), - DelayedCopyTestBase::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/eltwise_conv_eltwise.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/eltwise_conv_eltwise.cpp deleted file mode 100644 index f0382d9e854..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/eltwise_conv_eltwise.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/eltwise_conv_eltwise.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -std::vector params = {std::make_tuple(std::vector{1, 64}, // InputShape - std::vector{1, 3}, // KernelShape - 1), // Stride - std::make_tuple(std::vector{1, 128}, std::vector{1, 5}, 1), - std::make_tuple(std::vector{1, 168}, std::vector{1, 9}, 2), - std::make_tuple(std::vector{1, 320}, std::vector{1, 8}, 4)}; - -std::vector inputChannels = {1, 4, 8}; - -std::vector outputChannels = {4, 8}; - -INSTANTIATE_TEST_SUITE_P(smoke_EltwiseAfterConvTest, - EltwiseAfterConvTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)), - EltwiseAfterConvTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_EltwiseBeforeConvTest, - EltwiseBeforeConvTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)), - EltwiseBeforeConvTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_EltwiseWithTwoConvsAsInputsTest, - EltwiseWithTwoConvsAsInputsTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)), - EltwiseWithTwoConvsAsInputsTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/eltwise_reshape_activation.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/eltwise_reshape_activation.cpp deleted file mode 100644 index 1377786a277..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/eltwise_reshape_activation.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/eltwise_reshape_activation.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; -namespace { -const std::vector>> shapes = {{{1, 64}, {64, 1}}, - {{8, 256}, {16, 128}}, - {{6, 384}, {18, 128}}, - {{8, 2048}, {32, 512}}, - {{2, 4, 64, 64}, {1, 8, 64, 64}}}; - -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -std::vector> additional_config = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_EltwiseReshapeActivationTest, - EltwiseReshapeActivation, - ::testing::Combine(::testing::ValuesIn(shapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additional_config)), - EltwiseReshapeActivation::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/fc_conv_fc.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/fc_conv_fc.cpp deleted file mode 100644 index 1680ffeee74..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/fc_conv_fc.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/fc_conv_fc.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -std::vector params = {std::make_tuple(std::vector{1, 64}, // InputShape - std::vector{1, 3}, // KernelShape - 1), // Stride - std::make_tuple(std::vector{1, 128}, std::vector{1, 5}, 1), - std::make_tuple(std::vector{1, 168}, std::vector{1, 3}, 2), - std::make_tuple(std::vector{1, 320}, std::vector{1, 8}, 4)}; - -std::vector inputChannels = {1, 4, 8}; - -std::vector outputChannels = {4, 8}; - -INSTANTIATE_TEST_SUITE_P(smoke_FcAfterConvTest, - FcAfterConvTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)), - FcAfterConvTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_FcBeforeConvTest, - FcBeforeConvTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)), - FcBeforeConvTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_FcBetweenConvsTest, - FcBetweenConvsTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)), - FcBetweenConvsTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/first_connect_input_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/first_connect_input_concat.cpp deleted file mode 100644 index 3aef5c29e8c..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/first_connect_input_concat.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/first_connect_input_concat.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -std::vector>> inShapes = {{{1, 1288}}, {{1, 56}}, {{1, 6456}}}; - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -std::vector> additional_config = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_COMPACT_MODE", "NO"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}, {"GNA_COMPACT_MODE", "NO"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_concat_first_input, - ConcatFirstInputTest, - ::testing::Combine(::testing::ValuesIn(inShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additional_config)), - ConcatFirstInputTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/fq_conv_fq_affine.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/fq_conv_fq_affine.cpp deleted file mode 100644 index 291770298da..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/fq_conv_fq_affine.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/fq_conv_fq_affine.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -const std::vector> inputShapes = {{1, 1024}}; - -const std::vector levels = {65535, 65535}; - -const std::vector> inputParams = {{-0.2, 0.2, 0.01}}; - -const auto fqParams = ::testing::Combine(::testing::Values(levels), ::testing::ValuesIn(inputParams)); - -const std::vector> kernels = {{1, 3}}; -const std::vector> strides = {{1, 1}}; -const std::vector inputChannels = {8}; -const std::vector outputChannels{4}; - -const auto convParams = ::testing::Combine(::testing::ValuesIn(kernels), - ::testing::ValuesIn(strides), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)); - -const std::vector permute = {false, true}; - -INSTANTIATE_TEST_SUITE_P(smoke_FqConvFqAffineTest, - FqConvFqAffineTest, - ::testing::Combine(fqParams, - convParams, - ::testing::ValuesIn(permute), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(inputShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - FqConvFqAffineTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/fq_with_mixed_levels.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/fq_with_mixed_levels.cpp deleted file mode 100644 index 89c9255b6a3..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/fq_with_mixed_levels.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/fq_with_mixed_levels.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -namespace SubgraphTestsDefinitions { -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_FqWithMixedLevelsTest, - FqWithMixedLevelsTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - FqWithMixedLevelsTest::getTestCaseName); -} // namespace -} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/get_output_before_activation.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/get_output_before_activation.cpp deleted file mode 100644 index 07cbd0dd905..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/get_output_before_activation.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/get_output_before_activation.hpp" - -namespace ov { -namespace test { -namespace { -std::vector input_sizes = {80, 32, 64, 100}; - -std::vector midLayerTypes{midOutputType::Mul, midOutputType::Sub, midOutputType::Sum}; - -std::vector configs = {{ - {"GNA_COMPACT_MODE", "NO"}, - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_SCALE_FACTOR_0", "1638.4"}, - {"GNA_SCALE_FACTOR_1", "1638.4"}, - }, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; -} // namespace - -INSTANTIATE_TEST_SUITE_P(OutputBeforeActivation, - OutputBeforeActivation, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(ov::element::f32), - ::testing::ValuesIn(input_sizes), - ::testing::ValuesIn(midLayerTypes), - ::testing::ValuesIn(configs)), - OutputBeforeActivation::getTestCaseName); -} // namespace test -} // namespace ov diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/handling_orientation_conv.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/handling_orientation_conv.cpp deleted file mode 100644 index 3d7114b0232..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/handling_orientation_conv.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/handling_orientation_conv.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -const std::vector> configs = {{ - {"GNA_SCALE_FACTOR_0", "1"}, - {"GNA_SCALE_FACTOR_1", "1"}, - {"GNA_COMPACT_MODE", "NO"}, -}}; - -INSTANTIATE_TEST_SUITE_P(smoke_handling_orientation, - HandlingOrientationClass, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - HandlingOrientationClass::getTestCaseName); diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/input_conv.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/input_conv.cpp deleted file mode 100644 index a1ac977c6e4..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/input_conv.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/input_conv.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "163.835"}}}; - -std::vector params = {std::make_tuple(std::vector{1, 1, 1, 16}, // InputShape - std::vector{1, 8}, // KernelShape - 1), // Stride - std::make_tuple(std::vector{1, 1, 1, 16}, std::vector{1, 9}, 1), - std::make_tuple(std::vector{1, 1, 1, 168}, std::vector{1, 9}, 1), - std::make_tuple(std::vector{1, 1, 1, 168}, std::vector{1, 8}, 1), - std::make_tuple(std::vector{1, 1, 1, 640}, std::vector{1, 512}, 128)}; - -std::vector outputChannels = {4, 8}; - -std::vector addReshape = {true, false}; - -INSTANTIATE_TEST_SUITE_P(smoke_InputConv, - InputConvTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(outputChannels), - ::testing::ValuesIn(addReshape)), - InputConvTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/input_split_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/input_split_concat.cpp deleted file mode 100644 index 75792b0a47e..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/input_split_concat.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/input_split_concat.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -const std::vector> inputShapes = {{1, 128}, {1, 512}, {1, 320}}; - -INSTANTIATE_TEST_SUITE_P(smoke_InputSplitConcat, - InputSplitConcatTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(inputShapes)), - InputSplitConcatTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/matmul_act_add.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/matmul_act_add.cpp deleted file mode 100644 index 8c82a5b0bf7..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/matmul_act_add.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/matmul_act_add.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -namespace SubgraphTestsDefinitions { -namespace { -const std::vector input_sizes = {25, 30, 50}; - -const std::vector net_precisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -std::vector> additional_config = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; -} // namespace - -INSTANTIATE_TEST_SUITE_P(smoke_MatMulActAdd, - MatMulActAddTest, - ::testing::Combine(::testing::ValuesIn(input_sizes), - ::testing::ValuesIn(net_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additional_config)), - MatMulActAddTest::getTestCaseName); - -} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/matmul_squeeze_add.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/matmul_squeeze_add.cpp deleted file mode 100644 index aafc875bc58..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/matmul_squeeze_add.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/matmul_squeeze_add.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace ov::test; - -namespace { -const std::vector netPrecisions = {ov::element::f32}; - -const std::vector configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "81.9175"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -std::vector input_shapes = {{1, 8}, {1, 42}, {1, 100}, {1, 128}, {1, 512}}; - -std::vector output_sizes = {1000, 512, 128, 42, 16, 8}; - -INSTANTIATE_TEST_SUITE_P(smoke_MatmulSqueezeAdd, - MatmulSqueezeAddTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(output_sizes)), - MatmulSqueezeAddTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/memory_LSTMCell.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/memory_LSTMCell.cpp deleted file mode 100644 index b7b398d67fc..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/memory_LSTMCell.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/memory_LSTMCell.hpp" - -namespace ov { -namespace test { - -std::vector transformation{ - ov::test::utils::MemoryTransformation::NONE, - ov::test::utils::MemoryTransformation::LOW_LATENCY_V2}; - -std::vector input_sizes = {80, 32, 64, 100, 25}; - -std::vector hidden_sizes = { - 128, - 200, - 300, - 24, - 32, -}; - -ov::AnyMap additional_config = { - {"GNA_COMPACT_MODE", "NO"}, - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_SCALE_FACTOR_0", "1638.4"}, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_MemoryLSTMCellTest, - MemoryLSTMCellTest, - ::testing::Combine(::testing::ValuesIn(transformation), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(ov::element::f32), - ::testing::ValuesIn(input_sizes), - ::testing::ValuesIn(hidden_sizes), - ::testing::Values(additional_config)), - MemoryLSTMCellTest::getTestCaseName); -} // namespace test -} // namespace ov diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/memory_eltwise_reshape_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/memory_eltwise_reshape_concat.cpp deleted file mode 100644 index 3f1cd76d521..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/memory_eltwise_reshape_concat.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common_test_utils/test_constants.hpp" - -namespace SubgraphTestsDefinitions { -namespace { -std::vector input_multiples = {1, 7, 5, 8}; - -std::vector concat_sizes = {32, 64}; - -std::map additional_config = { - {"GNA_COMPACT_MODE", "NO"}, - {"GNA_DEVICE_MODE", "GNA_SW_FP32"}, - {"GNA_SCALE_FACTOR_0", "1638.4"}, -}; -} // namespace - -INSTANTIATE_TEST_SUITE_P(smoke_MemoryEltwiseReshapeConcatTest, - MemoryEltwiseReshapeConcatTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::ValuesIn(input_multiples), - ::testing::ValuesIn(concat_sizes), - ::testing::Values(additional_config)), - MemoryEltwiseReshapeConcatTest::getTestCaseName); -} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/memory_fq_concat_prelu.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/memory_fq_concat_prelu.cpp deleted file mode 100644 index 96c74f6baa9..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/memory_fq_concat_prelu.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/memory_fq_concat_prelu.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "gna/gna_config.hpp" - -namespace SubgraphTestsDefinitions { -namespace { - -std::vector>> inputs{{{1, 64}}}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -std::vector, - std::vector, - std::vector, - std::vector, - std::vector>> - strided_slice_params = {std::make_tuple(std::vector{0, 0}, - std::vector{1, 64}, - std::vector{1, 1}, - std::vector{1, 0}, - std::vector{1, 0})}; - -std::vector, - std::vector, - std::vector, - std::vector, - std::vector>> - fake_quantize_params = {std::make_tuple(65535, - std::vector{1}, - std::vector{-1}, - std::vector{1}, - std::vector{-1}, - std::vector{1})}; - -} // namespace - -INSTANTIATE_TEST_SUITE_P(smoke_memory_fq_concat_prelu, - MemoryFqConcatPrelu, - ::testing::Combine(::testing::ValuesIn(inputs), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(strided_slice_params), - ::testing::ValuesIn(fake_quantize_params)), - MemoryFqConcatPrelu::getTestCaseName); -} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multi_crops_to_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multi_crops_to_concat.cpp deleted file mode 100644 index 88a1ef0dfc6..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multi_crops_to_concat.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common_test_utils/test_constants.hpp" - -namespace SubgraphTestsDefinitions { -namespace { -const std::vector> input_shapes = {{1, 48}, {1, 64}}; - -const std::vector>> offsets = {{{0, 16}, {33, 48}}, - {{17, 32}, {33, 48}}, - {{5, 14}, {17, 26}}, - {{1, 8}, {9, 16}, {17, 24}}}; - -const std::vector> additional_config = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; -} // namespace - -INSTANTIATE_TEST_SUITE_P(smoke_multi_crop_to_concat, - MultiCropsToConcatTest, - ::testing::Combine(::testing::Values(InferenceEngine::Precision::FP32), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(offsets), - ::testing::ValuesIn(additional_config)), - MultiCropsToConcatTest::getTestCaseName); -} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multi_input_scale.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multi_input_scale.cpp deleted file mode 100644 index 4298e41e93c..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multi_input_scale.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common_test_utils/test_constants.hpp" - -namespace SubgraphTestsDefinitions { -namespace { -std::vector input = {32, 15, 17, 10}; - -std::vector> additional_config = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "2"}, {"GNA_SCALE_FACTOR_1", "2"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "2"}, {"GNA_SCALE_FACTOR_1", "1638.4"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; -} // namespace - -INSTANTIATE_TEST_SUITE_P(smoke_multiple_input_scale, - MultipleInputScaleTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::ValuesIn(input), - ::testing::ValuesIn(additional_config)), - MultipleInputScaleTest::getTestCaseName); -} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multioutput_eltwise_squeeze_eltwise.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multioutput_eltwise_squeeze_eltwise.cpp deleted file mode 100644 index f61cdd79ded..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multioutput_eltwise_squeeze_eltwise.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/multioutput_eltwise_squeeze_eltwise.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector>> inputs{{{1, 16}}, - {{2, 16}}, - {{1, 160}}, - {{8, 40}}, - {{3, 8}}, - {{4, 32}}, - {{5, 64}}, - {{6, 128}}, - {{7, 256}}, - {{8, 512}}, - {{8, 1024}}}; - -std::vector> configs = {{{"GNA_COMPACT_MODE", "NO"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_multioutput_eltwise_identity, - MultioutputEltwiseReshapeEltwise, - ::testing::Combine(::testing::ValuesIn(inputs), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - MultioutputEltwiseReshapeEltwise::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multiple_LSTMCell.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multiple_LSTMCell.cpp deleted file mode 100644 index 03de35f9424..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multiple_LSTMCell.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/multiple_LSTMCell.hpp" - -#include "common_test_utils/test_constants.hpp" - -namespace ov { -namespace test { -namespace { - -std::vector transformation{ - ov::test::utils::MemoryTransformation::NONE, - ov::test::utils::MemoryTransformation::LOW_LATENCY_V2}; - -std::vector input_sizes = {80, 32, 64, 25}; - -std::vector hidden_sizes = { - 64, - 100, - 24, - 32, -}; - -ov::AnyMap additional_config = { - {"GNA_COMPACT_MODE", "NO"}, - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_SCALE_FACTOR_0", "1638.4"}, -}; -} // namespace - -INSTANTIATE_TEST_SUITE_P(MultipleLSTMCellTest, - MultipleLSTMCellTest, - ::testing::Combine(::testing::ValuesIn(transformation), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(ov::element::f32), - ::testing::ValuesIn(input_sizes), - ::testing::ValuesIn(hidden_sizes), - ::testing::Values(additional_config)), - MultipleLSTMCellTest::getTestCaseName); -} // namespace test -} // namespace ov diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multiple_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multiple_concat.cpp deleted file mode 100644 index 644bac3d31a..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multiple_concat.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common_test_utils/test_constants.hpp" - -namespace SubgraphTestsDefinitions { -namespace { -std::vector input_sizes_aligned = { - 64, - 576, -}; - -std::vector constant_sizes_aligned = { - 64, - 32, -}; - -std::vector input_sizes_unaligned = {26, 99}; - -std::vector constant_sizes_unaligned = {26, 99}; - -std::vector> additional_config = { - {{"GNA_COMPACT_MODE", "NO"}, {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "3276.8"}}, - {{"GNA_COMPACT_MODE", "NO"}, {"GNA_DEVICE_MODE", "GNA_SW_FP32"}, {"GNA_SCALE_FACTOR_0", "3276.8"}}, -}; -} // namespace - -INSTANTIATE_TEST_SUITE_P(I_aligned_C_aligned, - MultipleConcatTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::ValuesIn(input_sizes_aligned), - ::testing::ValuesIn(constant_sizes_aligned), - ::testing::ValuesIn(additional_config)), - MultipleConcatTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(I_aligned_C_unaligned, - MultipleConcatTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::ValuesIn(input_sizes_aligned), - ::testing::ValuesIn(constant_sizes_unaligned), - ::testing::ValuesIn(additional_config)), - MultipleConcatTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(I_unaligned_C_aligned, - MultipleConcatTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::ValuesIn(input_sizes_unaligned), - ::testing::ValuesIn(constant_sizes_aligned), - ::testing::ValuesIn(additional_config)), - MultipleConcatTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(I_unaligned_C_unaligned, - MultipleConcatTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::ValuesIn(input_sizes_unaligned), - ::testing::ValuesIn(constant_sizes_unaligned), - ::testing::ValuesIn(additional_config)), - MultipleConcatTest::getTestCaseName); -} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multiple_input_fq.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multiple_input_fq.cpp deleted file mode 100644 index 5832e3c1da4..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/multiple_input_fq.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common_test_utils/test_constants.hpp" - -namespace SubgraphTestsDefinitions { -namespace { -std::vector input = { - 64, -}; - -std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; -} // namespace - -INSTANTIATE_TEST_SUITE_P(smoke_multiple_input, - MultipleInputTest, - ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::ValuesIn(input), - ::testing::ValuesIn(configs)), - MultipleInputTest::getTestCaseName); -} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/negative_memory_layer_offset.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/negative_memory_layer_offset.cpp deleted file mode 100644 index e2ec92f9a13..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/negative_memory_layer_offset.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/negative_memory_layer_offset.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "gna/gna_config.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, -}; - -std::map config = {{"GNA_COMPACT_MODE", "NO"}}; - -std::vector inputSizes = {384, 128, 64, 32}; - -std::vector hiddenSizes = {384, 128, 64, 32, 100}; - -INSTANTIATE_TEST_SUITE_P(smoke_negative_memory_layer_offset, - NegativeMemoryOffsetTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(inputSizes), - ::testing::ValuesIn(hiddenSizes), - ::testing::Values(config)), - NegativeMemoryOffsetTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/parameter_reshape_result.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/parameter_reshape_result.cpp deleted file mode 100644 index fb72b17aee7..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/parameter_reshape_result.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/parameter_reshape_result.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "gna/gna_config.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector> inputShape = {{1, 1, 64}, {1, 1, 128}}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -std::vector> additional_config = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_param_reshape_result, - ParamReshapeResult, - ::testing::Combine(::testing::ValuesIn(inputShape), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additional_config)), - ParamReshapeResult::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/permute_concat_concat_permute.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/permute_concat_concat_permute.cpp deleted file mode 100644 index d0bce9eabad..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/permute_concat_concat_permute.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/permute_concat_concat_permute.hpp" - -#include - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector> inputs1{{{1, 8}}, {{8, 1}}, {{16, 2}}, {{8, 2}}}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_permute_concat_concat_permute, - PermuteConcatConcatPermute, - ::testing::Combine(::testing::ValuesIn(inputs1), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - PermuteConcatConcatPermute::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/permute_concat_permute.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/permute_concat_permute.cpp deleted file mode 100644 index 06831a5fc74..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/permute_concat_permute.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/permute_concat_permute.hpp" - -#include - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector>> inputs{{{1, 8}, {1, 0}, {1, 0}}, - {{32, 2}, {1, 0}, {1, 0}}, - {{8, 2}, {1, 0}, {1, 0}}}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_permute_concat_permute, - PermuteConcatPermute, - ::testing::Combine(::testing::ValuesIn(inputs), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - PermuteConcatPermute::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/relu_split_reshape.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/relu_split_reshape.cpp deleted file mode 100644 index 6e61fbe20a1..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/relu_split_reshape.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/relu_split_reshape.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "gna/gna_config.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector> inputShape = {{1, 1, 64}, {1, 1, 128}}; - -std::vector splitAxis = {2}; - -std::vector splitNum = {2}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -std::vector> additional_config = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_relu_split_reshape, - ReluSplitReshape, - ::testing::Combine(::testing::ValuesIn(inputShape), - ::testing::ValuesIn(splitAxis), - ::testing::ValuesIn(splitNum), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additional_config)), - ReluSplitReshape::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/reshape_permute_conv_permute_reshape_act.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/reshape_permute_conv_permute_reshape_act.cpp deleted file mode 100644 index 22225f69cab..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/reshape_permute_conv_permute_reshape_act.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/reshape_permute_conv_permute_reshape_act.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -namespace { -using ov::test::ConvReshapeAct; - -std::vector> input_shapes{ - {1, 1, 166, 2}, - {1, 1, 144, 2}, - {1, 1, 288, 2}, - {1, 1, 144, 4}, -}; - -std::vector> kernel_shapes{ - {1, 7}, - {1, 15}, -}; - -std::vector output_channels{ - 16, - 8, - 4, -}; - -std::vector model_types = { - ov::element::f32, -}; - -std::vector configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "2340"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_basic, - ConvReshapeAct, - ::testing::Combine(::testing::ValuesIn(model_types), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(kernel_shapes), - ::testing::ValuesIn(output_channels), - ::testing::ValuesIn(configs)), - ConvReshapeAct::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/reshapre_permute_reshape.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/reshapre_permute_reshape.cpp deleted file mode 100644 index e799f1b6228..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/reshapre_permute_reshape.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common_test_utils/test_constants.hpp" -#include "subgraph_tests/reshape_permute_reshape.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector>> inputs{ - {{1, 4, 160}, {0, 2, 1}}, - {{1, 160, 4}, {0, 2, 1}}, - {{8, 16}, {1, 0}}, - {{1, 1, 4, 16}, {3, 1, 2, 0}}, - {{1, 8, 200}, {0, 2, 1}}, - {{1, 8, 16}, {2, 1, 0}}, -}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_reshape_permute_reshape, - ReshapePermuteReshape, - ::testing::Combine(::testing::ValuesIn(inputs), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA)), - ReshapePermuteReshape::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/scale_shift.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/scale_shift.cpp deleted file mode 100644 index 4d93c2b1864..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/scale_shift.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common_test_utils/test_constants.hpp" -#include "subgraph_tests/scaleshift.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -std::vector>> inShapes = - {{{1, 8}}, {{2, 16}}, {{3, 32}}, {{4, 64}}, {{5, 128}}, {{6, 256}}, {{7, 512}}, {{8, 1024}}}; - -std::vector> Scales = {{2.0f}, {3.0f}, {-1.0f}, {-2.0f}, {-3.0f}}; - -std::vector> Shifts = {{1.0f}, {2.0f}, {3.0f}, {-1.0f}, {-2.0f}, {-3.0f}}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_scale_shift, - ScaleShiftLayerTest, - ::testing::Combine(::testing::ValuesIn(inShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(Scales), - ::testing::ValuesIn(Shifts)), - ScaleShiftLayerTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/scaleshift_conv_scaleshift.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/scaleshift_conv_scaleshift.cpp deleted file mode 100644 index 4970535e45e..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/scaleshift_conv_scaleshift.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/scaleshift_conv_scaleshift.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -std::vector params = {std::make_tuple(std::vector{1, 64}, // InputShape - std::vector{1, 3}, // KernelShape - 1), // Stride - std::make_tuple(std::vector{1, 128}, std::vector{1, 5}, 1), - std::make_tuple(std::vector{1, 168}, std::vector{1, 9}, 2), - std::make_tuple(std::vector{1, 320}, std::vector{1, 8}, 4)}; - -std::vector inputChannels = {1, 4, 8}; - -std::vector outputChannels = {4, 8}; - -INSTANTIATE_TEST_SUITE_P(smoke_ScaleShiftAfterConvTest, - ScaleShiftAfterConvTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)), - ScaleShiftAfterConvTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_ScaleShiftBeforeConvTest, - ScaleShiftBeforeConvTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)), - ScaleShiftBeforeConvTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/softsign.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/softsign.cpp deleted file mode 100644 index 73ac3f08c62..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/softsign.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/softsign.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_SCALE_FACTOR_0", "3276.7"}, {"GNA_COMPACT_MODE", "NO"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -std::vector> input_shapes = - {{1, 8}, {1, 42}, {1, 100}, {1, 128}, {1, 1, 64}, {1, 1, 1, 64}, {1, 1, 1, 100}}; - -INSTANTIATE_TEST_SUITE_P(smoke_Softsign, - SoftsignTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(input_shapes)), - SoftsignTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_concat_multi_inputs.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_concat_multi_inputs.cpp deleted file mode 100644 index 81f03092a98..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_concat_multi_inputs.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/split_concat_multi_inputs.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "gna/gna_config.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector precisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -std::vector> additionalConfig = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -std::vector> inputShapes = {{1, 10}, {1, 50}, {1, 32}, {1, 512}}; - -std::vector splitsNum = {2, 3, 4, 10}; - -std::vector isFc = {false, true}; - -INSTANTIATE_TEST_SUITE_P(smoke_splitConcatMultiInputs, - SplitConcatMultiInputsTest, - ::testing::Combine(::testing::ValuesIn(precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(additionalConfig), - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(splitsNum), - ::testing::ValuesIn(isFc)), - SplitConcatMultiInputsTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_conv.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_conv.cpp deleted file mode 100644 index 58a2a50b09e..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_conv.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/split_conv.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -std::vector params = {std::make_tuple(std::vector{1, 128}, // InputShape - std::vector{1, 3}, // KernelShape - 1), // Stride - std::make_tuple(std::vector{1, 256}, std::vector{1, 5}, 1), - std::make_tuple(std::vector{1, 336}, std::vector{1, 9}, 2), - std::make_tuple(std::vector{1, 640}, std::vector{1, 8}, 4)}; - -std::vector inputChannels = {1, 4, 8}; - -std::vector outputChannels = {4, 8}; - -INSTANTIATE_TEST_SUITE_P(smoke_SplitConvTest, - SplitConvTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)), - SplitConvTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_relu.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_relu.cpp deleted file mode 100644 index f5425f928ab..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_relu.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/split_relu.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "gna/gna_config.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector>> inputs{{{1, 64}}, {{1, 128}}, {{1, 96}}, {{1, 16}}, {{1, 132, 8}}}; - -std::vector> connect_index{ - {0, 1, 2, 3}, - {0, 1, 2}, - {0, 1, 3}, - {0, 2, 3}, - {1, 2, 3}, - {0, 1}, - {0, 2}, - {0, 3}, - {1, 2}, - {1, 3}, - {2, 3}, - {0}, - {1}, - {2}, - {3}, -}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -std::map additional_config = {{std::string(GNA_CONFIG_KEY(COMPACT_MODE)), "NO"}}; - -INSTANTIATE_TEST_SUITE_P(smoke_split_connected, - SplitRelu, - ::testing::Combine(::testing::ValuesIn(inputs), - ::testing::ValuesIn(connect_index), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(additional_config)), - SplitRelu::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_trivial_permute_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_trivial_permute_concat.cpp deleted file mode 100644 index 8c09200f358..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/split_trivial_permute_concat.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/split_trivial_permute_concat.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -#include "gna/gna_config.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, -}; - -std::map config = {{"GNA_COMPACT_MODE", "NO"}}; - -std::vector> inputSizes = { - {1, 128, 1, 8}, - {1, 4, 1, 128}, - {1, 16, 1, 128}, - {1, 128, 1, 2}, -}; - -std::vector split_axes = {1}; // only channels split is currently supported by gna for 4d inputs -std::vector concat_axes = {1}; // only channels concat is currently supported by gna for 4d inputs - -INSTANTIATE_TEST_SUITE_P(smoke_split_trivial_permute_concat, - SplitTrivialPermuteConcatTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(inputSizes), - ::testing::ValuesIn(split_axes), // split axis - ::testing::ValuesIn(concat_axes), // concat axis - ::testing::Values(config)), - SplitTrivialPermuteConcatTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/strided_slice.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/strided_slice.cpp deleted file mode 100644 index fafdba09003..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/strided_slice.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/strided_slice.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -std::vector ss_only_test_cases = { - StridedSliceSpecificParams{{1, 2, 100, 100}, - {0, 0, 0, 0}, - {1, 1, 1, 1}, - {1, 1, 1, 1}, - {1, 1, 1, 1}, - {1, 0, 1, 1}, - {0, 0, 0, 0}, - {1, 0, 0, 0}, - {0, 0, 0, 0}}, - StridedSliceSpecificParams{{1, 2, 100}, - {0, 0, 0}, - {1, 1, 1}, - {1, 1, 1}, - {1, 1, 1}, - {1, 0, 1}, - {0, 0, 0}, - {1, 0, 0}, - {0, 0, 0}}, -}; - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_COMPACT_MODE", "NO"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_stridedslice_gna, - StridedSliceTest, - ::testing::Combine(::testing::ValuesIn(ss_only_test_cases), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - StridedSliceTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/stridedslice_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/stridedslice_concat.cpp deleted file mode 100644 index 51ebd3ac0aa..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/stridedslice_concat.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/stridedslice_concat.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -const std::vector sliceParams = { - {{8, 16}, {1, 16}, {2, 16}, {1, 1}, {0, 1}, {0, 1}}, - {{1, 16}, {1, 1}, {1, 2}, {1, 1}, {1, 0}, {1, 0}}, - {{1, 8, 16}, {1, 1, 16}, {1, 2, 16}, {1, 1, 1}, {1, 0, 1}, {1, 0, 1}}, - {{8, 25}, {3, 25}, {4, 25}, {1, 1}, {0, 1}, {0, 1}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_SliceConcatTest, - SliceConcatTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(sliceParams)), - SliceConcatTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/stridedslice_conv.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/stridedslice_conv.cpp deleted file mode 100644 index 4c809d3a1cd..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/stridedslice_conv.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/stridedslice_conv.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -const std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -std::vector params = {std::make_tuple(std::vector{1, 1, 1, 256}, // InputShape - std::vector{1, 3}, // KernelShape - 1), // Stride - std::make_tuple(std::vector{1, 1, 1, 1024}, std::vector{1, 5}, 1), - std::make_tuple(std::vector{1, 1, 1, 336}, std::vector{1, 9}, 2), - std::make_tuple(std::vector{1, 1, 1, 640}, std::vector{1, 8}, 4)}; - -std::vector outputChannels = {4, 8}; - -INSTANTIATE_TEST_SUITE_P(smoke_SliceConvTest, - SliceConvTest, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(params), - ::testing::ValuesIn(outputChannels)), - SliceConvTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/tensor_names.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/tensor_names.cpp deleted file mode 100644 index 789d838762f..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/tensor_names.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/tensor_names.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -INSTANTIATE_TEST_SUITE_P(smoke_Check, - TensorNamesTest, - ::testing::Values(ov::test::utils::DEVICE_GNA), - TensorNamesTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/transpose_conv_transpose_squeeze.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/transpose_conv_transpose_squeeze.cpp deleted file mode 100644 index e0f6b3f178b..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/transpose_conv_transpose_squeeze.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/transpose_conv_transpose_squeeze.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -const std::vector> configs = {{{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}}}; - -const std::vector> inputShapes = {{1, 8192}}; - -const std::vector> kernels = {{1, 3}, {1, 4}, {1, 8}, {1, 9}}; -const std::vector> strides = {{1, 1}}; -const std::vector inputChannels = {64}; -const std::vector outputChannels{4, 8, 16}; - -const auto convParams = ::testing::Combine(::testing::ValuesIn(kernels), - ::testing::ValuesIn(strides), - ::testing::ValuesIn(inputChannels), - ::testing::ValuesIn(outputChannels)); - -INSTANTIATE_TEST_SUITE_P(smoke_TransposeConvTest, - TransposeConvTest, - ::testing::Combine(convParams, - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(inputShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs)), - TransposeConvTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/trivial_concat.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/trivial_concat.cpp deleted file mode 100644 index 715af28042b..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/trivial_concat.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/trivial_concat.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { -std::vector> inShapes = { - {1, 1, 33, 16}, - {1, 1, 65, 16}, - {10, 16}, - {10, 64}, - {15, 15}, -}; - -std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; - -std::map additional_config = { - {"GNA_COMPACT_MODE", "NO"}, - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_SCALE_FACTOR_0", "2000.0"}, -}; - -INSTANTIATE_TEST_SUITE_P(smoke_trivial_concat_Basic, - TrivialConcatLayerTest, - ::testing::Combine(::testing::ValuesIn(inShapes), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::Values(additional_config)), - TrivialConcatLayerTest::getTestCaseName); -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/two_fake_quantize_to_fullyconnected.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/two_fake_quantize_to_fullyconnected.cpp deleted file mode 100644 index 794c9709cef..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/subgraph_tests/two_fake_quantize_to_fullyconnected.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/two_fake_quantize_to_fullyconnected.hpp" - -#include -#include - -#include "common_test_utils/test_constants.hpp" - -using namespace SubgraphTestsDefinitions; - -namespace { - -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -using ConfigType = std::map; -const ConfigType configFP32 = { - {"GNA_DEVICE_MODE", "GNA_SW_FP32"}, -}; - -const ConfigType configSWExact = {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_COMPACT_MODE", "NO"}}; - -/** - * @brief specific quantisation mode to be used internally - */ -const std::vector> gnaQuantModes = { - {"sw_fp32", configFP32}, -}; - -const std::vector> gnaQuantModes_I8 = { - {"gna_sw_exact", configSWExact}, -}; - -const std::vector> inputShapes = {{1, 440}}; -const std::vector>> constShapes = {{{1}, {1024, 1}}}; - -const std::vector>> constShapes_int16 = {{{1}, {1}}}; - -const std::vector levels_fp = {255, 65535}; -const std::vector> levels_i16 = {{65535, 65535}, {32767, 32767}, {16383, 16383}}; -const std::vector> levels_i8 = {{255, 255}}; - -const std::vector> fqArgs = {{-2.0f, 2.0f, -2.0f, 2.0f}}; -const std::vector> inputParams = {{-64, 64, 1}, {-10, 10, 0.1}}; -const std::vector> inputParams_I8 = {{-2.0f, 2.0f, 0.1f}}; - -const std::vector biases = {false, true}; - -const auto fqParams = ::testing::Combine(::testing::Values(levels_fp), - ::testing::ValuesIn(constShapes), - ::testing::ValuesIn(fqArgs), - ::testing::ValuesIn(inputParams)); - -const auto fqParams_I8 = ::testing::Combine(::testing::ValuesIn(levels_i8), - ::testing::ValuesIn(constShapes), - ::testing::ValuesIn(fqArgs), - ::testing::ValuesIn(inputParams_I8)); - -const auto fqParams_I16 = ::testing::Combine(::testing::ValuesIn(levels_i16), - ::testing::ValuesIn(constShapes_int16), - ::testing::ValuesIn(fqArgs), - ::testing::ValuesIn(inputParams_I8)); - -INSTANTIATE_TEST_SUITE_P(smoke_FakeQuantize_subgraph, - FakeQuantizeSubgraphTest, - ::testing::Combine(fqParams, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(gnaQuantModes), - ::testing::ValuesIn(biases)), - FakeQuantizeSubgraphTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_FakeQuantize_subgraph_U8, - FakeQuantizeSubgraphTest, - ::testing::Combine(fqParams_I8, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(gnaQuantModes_I8), - ::testing::ValuesIn(biases)), - FakeQuantizeSubgraphTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_FakeQuantize_subgraph_I16, - FakeQuantizeSubgraphTest, - ::testing::Combine(fqParams_I16, - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::ValuesIn(inputShapes), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(gnaQuantModes_I8), - ::testing::ValuesIn(biases)), - FakeQuantizeSubgraphTest::getTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/functional/shared_tests_instances/transpose_add.cpp b/src/plugins/intel_gna/tests/functional/shared_tests_instances/transpose_add.cpp deleted file mode 100644 index 583e99391d4..00000000000 --- a/src/plugins/intel_gna/tests/functional/shared_tests_instances/transpose_add.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "subgraph_tests/transpose_add.hpp" - -#include - -#include "common_test_utils/test_constants.hpp" -namespace { -std::vector> input_shapes{{1, 4, 32}, {1, 8, 8}, {1, 7, 8}, {1, 40, 3}, {32, 8}, {8, 2}}; - -std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, -}; - -std::map additional_config = { - {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, -}; -} // namespace - -namespace SubgraphTestsDefinitions { -INSTANTIATE_TEST_SUITE_P(smoke_basic, - TransposeAdd, - ::testing::Combine(::testing::ValuesIn(netPrecisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(input_shapes), - ::testing::Values(additional_config)), - TransposeAdd::getTestCaseName); -} // namespace SubgraphTestsDefinitions diff --git a/src/plugins/intel_gna/tests/functional/subgraph_tests/add_transpose_detection.cpp b/src/plugins/intel_gna/tests/functional/subgraph_tests/add_transpose_detection.cpp deleted file mode 100644 index cffa490d0af..00000000000 --- a/src/plugins/intel_gna/tests/functional/subgraph_tests/add_transpose_detection.cpp +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "openvino/opsets/opset9.hpp" -#include "ov_models/builders.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" - -using namespace ov::opset9; - -typedef std::tuple, // Configuration - std::vector, // Input Shape - ngraph::helpers::InputLayerType, // Type of Eltwise input - size_t> // Order of Eltwise input - - InputConvAddParams; - -namespace LayerTestsDefinitions { - -class InputConvAddTransposing : public testing::WithParamInterface, - public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(testing::TestParamInfo obj) { - InferenceEngine::Precision precision; - std::string targetDevice; - std::map configuration; - std::vector input_shape; - ngraph::helpers::InputLayerType input_eltwise_type; - size_t input_eltwise_order; - - std::tie(precision, targetDevice, configuration, input_shape, input_eltwise_type, input_eltwise_order) = - obj.param; - - std::ostringstream result; - result << "netPRC=" << precision.name() << "_"; - result << "targetDevice=" << targetDevice << "_"; - - for (auto const& configItem : configuration) { - result << "_configItem=" << configItem.first << "_" << configItem.second; - } - result << "_inputShape=" << ov::test::utils::vec2str(input_shape); - result << "_input_eltwise_type=" << input_eltwise_type; - result << "_input_eltwise_order=" << input_eltwise_order; - - return result.str(); - } - -protected: - const std::vector filter_size{1, 1}; - const std::vector strides{1, 1}; - const std::vector pads_begin{0, 0}; - const std::vector pads_end{0, 0}; - const std::vector dilations{1, 1}; - const ov::op::PadType pad_type = ov::op::PadType::EXPLICIT; - const size_t out_channels_num = 8; - const size_t c_index_in_nchw = 1; - - void SetUp() override { - InferenceEngine::Precision precision; - std::vector input_shape; - ngraph::helpers::InputLayerType input_eltwise_type; - size_t input_eltwise_order; - std::tie(precision, targetDevice, configuration, input_shape, input_eltwise_type, input_eltwise_order) = - this->GetParam(); - - auto ng_precision = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(precision); - - auto input = std::make_shared(ng_precision, ov::Shape{input_shape}); - - const auto weights_size = ov::shape_size(filter_size) * out_channels_num * input_shape[c_index_in_nchw]; - auto weights_values = ov::test::utils::generate_float_numbers(weights_size, -0.2f, 0.2f); - - auto convolution = ngraph::builder::makeConvolution(input, - ng_precision, - filter_size, - strides, - pads_begin, - pads_end, - dilations, - pad_type, - out_channels_num, - false, - weights_values); - std::shared_ptr add; - if (input_eltwise_type == ngraph::helpers::InputLayerType::CONSTANT) { - auto const_node = std::make_shared(ng_precision, ov::Shape{input_shape}); - add = (input_eltwise_order == 0) ? std::make_shared(const_node, convolution) - : std::make_shared(convolution, const_node); - } else if (input_eltwise_type == ngraph::helpers::InputLayerType::PARAMETER) { - add = (input_eltwise_order == 0) ? std::make_shared(input, convolution) - : std::make_shared(convolution, input); - } - auto res = std::make_shared(add); - function = std::make_shared(ov::ResultVector{res}, ov::ParameterVector{input}); - } -}; - -TEST_P(InputConvAddTransposing, CompareWithRefImpl) { - Run(); -}; - -const std::vector eltwise_input_types = {ngraph::helpers::InputLayerType::CONSTANT, - ngraph::helpers::InputLayerType::PARAMETER}; - -const std::vector eltwise_input_order = {0, 1}; - -const InferenceEngine::Precision net_precisions{InferenceEngine::Precision::FP32}; - -const std::vector> configs = { - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}, - {{"GNA_DEVICE_MODE", "GNA_SW_FP32"}}}; - -const std::vector> input_shapes{{1, 8, 32, 16}}; - -INSTANTIATE_TEST_SUITE_P(smoke_add_transpose_detection, - InputConvAddTransposing, - ::testing::Combine(::testing::Values(net_precisions), - ::testing::Values(ov::test::utils::DEVICE_GNA), - ::testing::ValuesIn(configs), - ::testing::ValuesIn(input_shapes), - ::testing::ValuesIn(eltwise_input_types), - ::testing::ValuesIn(eltwise_input_order)), - InputConvAddTransposing::getTestCaseName); - -} // namespace LayerTestsDefinitions diff --git a/src/plugins/intel_gna/tests/unit/CMakeLists.txt b/src/plugins/intel_gna/tests/unit/CMakeLists.txt deleted file mode 100644 index cb77a5e190c..00000000000 --- a/src/plugins/intel_gna/tests/unit/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2018-2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -set(TARGET_NAME ov_gna_unit_tests) - -# because unit tests use plugins object files compiled with LTO -if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0) - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) -endif() - -# TODO: fix CVS-71010 and remove BUILD_SHARED_LIBS -if(NOT BUILD_SHARED_LIBS) - set(exclude_path EXCLUDED_SOURCE_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/(gna_api_stub|gna_wait_test|gna_export_import_test|gna_infer_request_test|gna_plugin_load_network_test|gna_mock_api_initializer|gna_extra_pwl_segments_tests).cpp") -endif() - -ov_add_test_target( - NAME ${TARGET_NAME} - ROOT ${CMAKE_CURRENT_SOURCE_DIR} - ${exclude_path} - LINK_LIBRARIES - PRIVATE - ov_models - gmock - common_test_utils_s - openvino_intel_gna_plugin_test_static - inference_engine_legacy_s - ADD_CLANG_FORMAT - LABELS - OV GNA -) - -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS -IGNORE:4286) -endif() - -if(SUGGEST_OVERRIDE_SUPPORTED) - set_source_files_properties(gna_model_serial_test.cpp - PROPERTIES COMPILE_OPTIONS -Wno-suggest-override) -endif() diff --git a/src/plugins/intel_gna/tests/unit/backend/gna_limitations_test.cpp b/src/plugins/intel_gna/tests/unit/backend/gna_limitations_test.cpp deleted file mode 100644 index fd1014e716c..00000000000 --- a/src/plugins/intel_gna/tests/unit/backend/gna_limitations_test.cpp +++ /dev/null @@ -1,366 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "backend/gna_limitations.hpp" - -#include - -#include - -#include "common/gna_target.hpp" - -using namespace ov::intel_gna::limitations; -using namespace ov::intel_gna::target; - -struct GNACnn2DValidatorTestParam { - DeviceVersion target; - std::string whatInvalid; - std::vector invalid; -}; - -const std::vector kInvalidH_30 = {0, 400}; -const std::vector kInvalidH_35 = {0, 65536}; - -const std::vector kInvalidW_30 = {0, 400}; -const std::vector kInvalidW_35 = {0, 65536}; - -const std::vector kInvalidC_30 = {0, 1, 400}; -const std::vector kInvalidC_35 = {0, 2049}; - -const std::vector kInvalidkH_30 = {0, 8, 400}; -const std::vector kInvalidkH_35 = {0, 257, 2049}; - -const std::vector kInvalidkW_30 = {0, 8, 400}; -const std::vector kInvalidkW_35 = {0, 257, 2049}; - -const std::vector kInvalidkN_30 = {0, 1, 400}; -const std::vector kInvalidkN_35 = {0, 2049}; - -const std::vector kInvalidsH_30 = {0, 400}; -const std::vector kInvalidsH_35 = {0, 2049}; - -const std::vector kInvalidsW_30 = {0, 400}; -const std::vector kInvalidsW_35 = {0, 2049}; - -const std::vector kInvaliddH_30 = {0, 2, 400}; -const std::vector kInvaliddH_35 = {0, 2, 2049}; - -const std::vector kInvaliddW_30 = {0, 2, 400}; -const std::vector kInvaliddW_35 = {0, 2, 2049}; - -const GNACnn2DValidatorTestParam target_30{ - DeviceVersion::GNA3_0, - "inH", - kInvalidH_30, -}; - -const GNACnn2DValidatorTestParam target_35{ - DeviceVersion::GNA3_5, - "inH", - kInvalidH_35, -}; - -const GNACnn2DValidatorTestParam target_30_inW{ - DeviceVersion::GNA3_0, - "inW", - kInvalidW_30, -}; - -const GNACnn2DValidatorTestParam target_35_inW{ - DeviceVersion::GNA3_5, - "inW", - kInvalidW_35, -}; - -const GNACnn2DValidatorTestParam target_30_inC{ - DeviceVersion::GNA3_0, - "inC", - kInvalidC_30, -}; - -const GNACnn2DValidatorTestParam target_35_inC{ - DeviceVersion::GNA3_5, - "inC", - kInvalidC_35, -}; - -const GNACnn2DValidatorTestParam target_30_kH{ - DeviceVersion::GNA3_0, - "kH", - kInvalidkH_30, -}; - -const GNACnn2DValidatorTestParam target_35_kH{ - DeviceVersion::GNA3_5, - "kH", - kInvalidkH_35, -}; - -const GNACnn2DValidatorTestParam target_30_kW{ - DeviceVersion::GNA3_0, - "kW", - kInvalidkW_30, -}; - -const GNACnn2DValidatorTestParam target_35_kW{ - DeviceVersion::GNA3_5, - "kW", - kInvalidkW_35, -}; - -const GNACnn2DValidatorTestParam target_30_kN{ - DeviceVersion::GNA3_0, - "inC", - kInvalidkN_30, -}; - -const GNACnn2DValidatorTestParam target_35_kN{ - DeviceVersion::GNA3_5, - "inC", - kInvalidkN_35, -}; - -const GNACnn2DValidatorTestParam target_30_sH{ - DeviceVersion::GNA3_0, - "sH", - kInvalidsH_30, -}; - -const GNACnn2DValidatorTestParam target_35_sH{ - DeviceVersion::GNA3_5, - "sH", - kInvalidsH_35, -}; - -const GNACnn2DValidatorTestParam target_30_sW{ - DeviceVersion::GNA3_0, - "sW", - kInvalidsW_30, -}; - -const GNACnn2DValidatorTestParam target_35_sW{ - DeviceVersion::GNA3_5, - "sW", - kInvalidsW_35, -}; - -const GNACnn2DValidatorTestParam target_30_dH{ - DeviceVersion::GNA3_0, - "dH", - kInvaliddH_30, -}; - -const GNACnn2DValidatorTestParam target_35_dH{ - DeviceVersion::GNA3_5, - "dH", - kInvaliddH_35, -}; - -const GNACnn2DValidatorTestParam target_30_dW{ - DeviceVersion::GNA3_0, - "dW", - kInvaliddW_30, -}; - -const GNACnn2DValidatorTestParam target_35_dW{ - DeviceVersion::GNA3_5, - "dW", - kInvaliddW_35, -}; - -const std::vector kInvalidpw_30 = {0, 2, 10}; -const GNACnn2DValidatorTestParam target_30_pwH{ - DeviceVersion::GNA3_0, - "windowH", - kInvalidpw_30, -}; -const GNACnn2DValidatorTestParam target_30_pwW{ - DeviceVersion::GNA3_0, - "windowW", - kInvalidpw_30, -}; - -const std::vector kInvalidps_30 = {0, 4, 10}; -const GNACnn2DValidatorTestParam target_30_psH{ - DeviceVersion::GNA3_0, - "strideH", - kInvalidps_30, -}; -const GNACnn2DValidatorTestParam target_30_psW{ - DeviceVersion::GNA3_0, - "strideW", - kInvalidps_30, -}; - -const std::vector kInvalidPoolingRange35 = {0, 256}; -const GNACnn2DValidatorTestParam target_35_pwH{ - DeviceVersion::GNA3_5, - "windowH", - kInvalidPoolingRange35, -}; -const GNACnn2DValidatorTestParam target_35_pwW{ - DeviceVersion::GNA3_5, - "windowW", - kInvalidPoolingRange35, -}; -const GNACnn2DValidatorTestParam target_35_psH{ - DeviceVersion::GNA3_5, - "strideH", - kInvalidPoolingRange35, -}; -const GNACnn2DValidatorTestParam target_35_psW{ - DeviceVersion::GNA3_5, - "strideW", - kInvalidPoolingRange35, -}; - -struct Validatecnn2dParams { - std::map parameters; - OvGnaType precission; - static const bool exceptionMode = false; - - static Validatecnn2dParams GetValid() { - Validatecnn2dParams v; - v.parameters["inH"] = 16; - v.parameters["inW"] = 16; - v.parameters["inC"] = 16; - v.parameters["kH"] = 2; - v.parameters["kW"] = 2; - v.parameters["kN"] = 8; - v.parameters["sH"] = 1; - v.parameters["sW"] = 1; - v.parameters["dH"] = 1; - v.parameters["dW"] = 1; - v.precission = OvGnaTypeInt16; - return v; - } - - static Validatecnn2dParams GetValidPooling() { - Validatecnn2dParams v; - v.parameters["windowH"] = 3; - v.parameters["windowW"] = 3; - v.parameters["strideH"] = 3; - v.parameters["strideW"] = 3; - return v; - } - - bool Validatecnn2d(const cnn2d::AbstractValidator& validator) { - return validator.ValidateCnn2D({}, - parameters["inH"], - parameters["inW"], - parameters["inC"], - parameters["kH"], - parameters["kW"], - parameters["kN"], - parameters["sH"], - parameters["sW"], - parameters["dH"], - parameters["dW"], - precission, - exceptionMode); - } - - bool ValidatePooling2D(const cnn2d::AbstractValidator& validator) { - return validator.ValidatePooling2D({}, - parameters["windowH"], - parameters["windowW"], - parameters["strideH"], - parameters["strideW"], - exceptionMode); - } - - void set(const std::string& what, const uint32_t value) { - if (what == "precission") { - precission = static_cast(value); - } else { - parameters[what] = value; - } - } -}; - -class GNAcnn2dValidatorTest : public ::testing::TestWithParam { -protected: - void SetUp() override { - Limitations::init(GetParam().target); - validator = Limitations::get_instance()->get_cnn_validator(); - ASSERT_TRUE(validator); - } - - void TearDown() override { - Limitations::deinit(); - } - - std::shared_ptr validator; -}; - -class GNAcnn2dValidatorTestPadding : public GNAcnn2dValidatorTest { -protected: - bool isPaddingSupported() { - static const std::set supported{DeviceVersion::GNA3_5}; - return supported.count(GetParam().target); - } -}; - -class GNAcnn2dValidatorTestPooling2D : public GNAcnn2dValidatorTest {}; - -namespace { -TEST_P(GNAcnn2dValidatorTestPadding, testPaddingSupported) { - ASSERT_TRUE(validator->ValidateInputPadding("", 1, 1, 1, 1, 2, 2, false) == isPaddingSupported()); -} - -TEST_P(GNAcnn2dValidatorTest, testValidatecnn2dInvalid) { - auto valid = Validatecnn2dParams::GetValid(); - for (const auto invalid : GetParam().invalid) { - valid.set(GetParam().whatInvalid, invalid); - ASSERT_FALSE(valid.Validatecnn2d(*validator)); - } -} - -TEST_P(GNAcnn2dValidatorTestPooling2D, testValidatecnn2dInvalid) { - auto valid = Validatecnn2dParams::GetValidPooling(); - for (const auto invalid : GetParam().invalid) { - valid.set(GetParam().whatInvalid, invalid); - ASSERT_FALSE(valid.ValidatePooling2D(*validator)); - } -} - -INSTANTIATE_TEST_SUITE_P(smoke_GNAcnn2dValidatorTestPadding, - GNAcnn2dValidatorTestPadding, - testing::Values(target_30, target_35)); - -INSTANTIATE_TEST_SUITE_P(smoke_GNAcnn2dValidatorTest, - GNAcnn2dValidatorTest, - testing::Values(target_30, - target_35, - target_30_inW, - target_35_inW, - target_30_inC, - target_35_inC, - target_30_kH, - target_35_kH, - target_30_kW, - target_35_kW, - target_30_kN, - target_35_kN, - target_30_sH, - target_30_sW, - target_30_dH, - target_30_dW, - target_35_sH, - target_35_sW, - target_35_dH, - target_35_dW)); - -INSTANTIATE_TEST_SUITE_P(smoke_GNAcnn2dValidatorTestPooling2D, - GNAcnn2dValidatorTestPooling2D, - testing::Values(target_30_pwH, - target_30_pwW, - target_30_psH, - target_30_psW, - target_35_pwH, - target_35_pwW, - target_35_psH, - target_35_psW)); - -} // namespace diff --git a/src/plugins/intel_gna/tests/unit/backend/gna_make_pwl_identity.cpp b/src/plugins/intel_gna/tests/unit/backend/gna_make_pwl_identity.cpp deleted file mode 100644 index 58538b69808..00000000000 --- a/src/plugins/intel_gna/tests/unit/backend/gna_make_pwl_identity.cpp +++ /dev/null @@ -1,292 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -//#include "backend/gna_limitations.hpp" -//#include "common/gna_target.hpp" - -#include - -#include - -#include "backend/dnn_types.hpp" -#include "backend/make_pwl.hpp" -#include "backend/pwl_input_params.hpp" -#include "backend/pwl_segments_creator_factory.hpp" -#include "backend/pwl_tools.hpp" -#include "common/numerical_utils.hpp" -#include "runtime/pwl.h" - -using namespace ov::intel_gna::backend; -using namespace ov::intel_gna::common; -using namespace ov::intel_gna::backend::pwl_tools; - -namespace { - -struct MakePWLIdentityTestParam { - double in_scale_; - double out_scale_; - bool should_throw_; - bool operator<(const MakePWLIdentityTestParam& rhs) const { - if (in_scale_ < rhs.in_scale_) { - return true; - } else if (in_scale_ > rhs.in_scale_) { - return false; - } else if (out_scale_ < rhs.out_scale_) { - return true; - } - return false; - } -}; - -std::string SegmentToString(const gna_pwl_segment_t& segment) { - std::stringstream stream; - stream << "Segment("; - stream << "xBase=" << static_cast(segment.xBase & XBASEMASK); - stream << ", yBase=" << segment.yBase; - stream << ", slope=" << segment.slope; - stream << ", slope_scale=" << ComputeSlopeScale(segment.xBase); - stream << ")"; - return stream.str(); -} - -size_t get_segment_index(const std::vector pwl_segments, const int64_t x) { - int j = 0; - for (int i = 0; i < pwl_segments.size(); ++i) { - if (static_cast(pwl_segments[i].xBase & XBASEMASK) <= x) { - j = i; - } else { - break; - } - } - return j; -} - -class MakePWLIdentityTestFixture : public ::testing::TestWithParam { -public: - static std::string GetTestCaseName(const testing::TestParamInfo& obj); - - DnnActivation identity_fun_{DnnActivation::fromType(kActIdentity)}; - std::vector pwl_; - double l_bound_{-1.0}; - double u_bound_{1.0}; - bool low_precision_ = false; - -protected: - std::set GenTestXValues(const std::vector& segments); - - void ValidateSegments(const std::vector& segments) { - std::set test_values = GenTestXValues(segments); - int64_t prev = std::numeric_limits::min(); - for (const auto& value : test_values) { - const auto& segment = segments[get_segment_index(segments, value)]; - auto result = ComputePWL(segment, value); - - // check saturation - if (result > std::numeric_limits::max() || result < std::numeric_limits::min()) { - FAIL() << "PWL with saturation F(" << value << ")=" << result << ", for " << SegmentToString(segment); - } - // check check monotocity - if (prev > result) { - FAIL() << "PWL is not monotonic for F(" << value << ")=" << std::to_string(result) - << " for segment: " << SegmentToString(segment) << ", where F(" << value - 1 - << ") = " << std::to_string(prev) << "!"; - } - // check 0,0 - if (value == 0 && result != 0) { - FAIL() << "PWL does not pass (0,0), but it is F(" << value << ")=" << result << ", for " - << SegmentToString(segment); - } - prev = result; - } - } -}; - -std::string MakePWLIdentityTestFixture::GetTestCaseName(const testing::TestParamInfo& obj) { - auto param = obj.param; - std::ostringstream result; - - result << "_scale_in=" << std::to_string(param.in_scale_) << "_"; - result << "_scale_out=" << std::to_string(param.out_scale_); - return result.str(); -} - -inline std::set MakePWLIdentityTestFixture::GenTestXValues(const std::vector& segments) { - std::set test_x_values; - test_x_values.insert(std::numeric_limits::min()); - test_x_values.insert(std::numeric_limits::max()); - - test_x_values.insert(-1); - test_x_values.insert(0); - test_x_values.insert(1); - for (const auto& segment : segments) { - auto x_base = static_cast(segment.xBase & XBASEMASK); - if (x_base > std::numeric_limits::min()) { - test_x_values.insert(x_base - 1); - } - test_x_values.insert(x_base); - if (x_base < std::numeric_limits::max()) { - test_x_values.insert(x_base + 1); - } - } - return test_x_values; -} - -// This test check if method available in the system returns proper segments. -TEST_P(MakePWLIdentityTestFixture, check_make_pwl) { - auto input_params = GetParam(); - std::vector output_pwl; - - try { - make_gna_pwl(identity_fun_, - pwl_, - l_bound_, - u_bound_, - input_params.in_scale_, - input_params.out_scale_, - low_precision_, - false, - output_pwl); - if (input_params.should_throw_) { - FAIL() << "Should throw, but didn't"; - return; - } - } catch (const std::exception& e) { - if (!input_params.should_throw_) { - FAIL() << "Thrown but shouldn't due to: " << e.what(); - } - return; - } - - ASSERT_FALSE(output_pwl.empty()); - - ValidateSegments(output_pwl); -} - -// This test check segment creation for PWL Identity -TEST_P(MakePWLIdentityTestFixture, check_pwl_identity_create_segments) { - auto input_params = GetParam(); - - auto pwl_creator = PWLSegmentsCreatorFactory::CreateCreator(identity_fun_.type); - ASSERT_NE(pwl_creator, nullptr); - - std::vector output_pwl; - - try { - PWLInputParams pwl_input(low_precision_, - identity_fun_.fqParams, - input_params.in_scale_, - input_params.out_scale_); - output_pwl = pwl_creator->CreateSegments(pwl_input); - if (input_params.should_throw_) { - FAIL() << "Should throw, but didn't"; - return; - } - } catch (const std::exception& e) { - if (!input_params.should_throw_) { - FAIL() << "Thrown but shouldn't due to: " << e.what(); - } - return; - } - - ASSERT_FALSE(output_pwl.empty()); - - ValidateSegments(output_pwl); -} - -// This test check segment creation with borders for PWL Identity -TEST_P(MakePWLIdentityTestFixture, check_pwl_identity_create_segments_with_borders) { - auto input_params = GetParam(); - - auto pwl_creator = PWLSegmentsCreatorFactory::CreateCreator(identity_fun_.type); - ASSERT_NE(pwl_creator, nullptr); - - PWLSegmentsWithBorderValues output_values; - - try { - PWLInputParams pwl_input(low_precision_, - identity_fun_.fqParams, - input_params.in_scale_, - input_params.out_scale_); - output_values = pwl_creator->CreateSegmentsWithBorders(pwl_input); - if (input_params.should_throw_) { - FAIL() << "Should throw, but didn't"; - return; - } - } catch (const std::exception& e) { - if (!input_params.should_throw_) { - FAIL() << "Thrown but shouldn't due to: " << e.what(); - } - return; - } - - auto& segments = output_values.segments; - - ASSERT_FALSE(segments.empty()); - - ValidateSegments(segments); -} -/** - * Create Input parameters. Sets should throw to true in case scale factors relation is inproper - */ -MakePWLIdentityTestParam createIdentityParamsForScales(double in, double out) { - auto slope = ComputeSlopeForSegment(1.0, in, out); - - // in case there is risk of division of 0 for given in/out parameters exception should be thrown - bool should_throw = false; - - // check if exception is thrown if division by zero is possible - // check if exception is thrown if scale factor with too big difference are used - const auto x_lower = DoubleToInt32(static_cast(std::numeric_limits::min()) * in / out); - - if (slope.value == 0 || x_lower == 0) { - should_throw = true; - } - return {in, out, should_throw}; -} - -std::set GenerateParams() { - // use set to avoid duplicates - std::set params; - - params.insert(createIdentityParamsForScales(1.0, 1.0)); - params.insert(createIdentityParamsForScales(1.0, 2049.0)); - params.insert(createIdentityParamsForScales(16777216.0, 2049.0)); - params.insert(createIdentityParamsForScales(17895698.0, 2049.0)); - params.insert(createIdentityParamsForScales(16384.0, 2049.0)); - params.insert(createIdentityParamsForScales(38347924.0, 2049.0)); - params.insert(createIdentityParamsForScales(33570816.0, 2049.0)); - params.insert(createIdentityParamsForScales(30720.0, 69905.0)); - params.insert(createIdentityParamsForScales(542115584.0, 2049.0)); - params.insert(createIdentityParamsForScales(273.0, 7866240.0)); - params.insert(createIdentityParamsForScales(2049.0, 273.0)); - params.insert(createIdentityParamsForScales(286331153.0, 7.0)); - params.insert(createIdentityParamsForScales(286331153.0, 2049.0)); - params.insert(createIdentityParamsForScales(6712372736.0, 2049.0)); - - for (int64_t i = 1; i < std::numeric_limits::max(); i = i * 16 + 1) { - params.insert(createIdentityParamsForScales(static_cast(i), 2049.0)); - } - - for (int64_t i = 1; i < std::numeric_limits::max(); i = i * 16 + 1) { - params.insert(createIdentityParamsForScales(2049.0, static_cast(i))); - } - - for (int64_t i = 1; i < std::numeric_limits::max(); i = i * 16 + 1) { - params.insert(createIdentityParamsForScales(static_cast(i), - static_cast(std::numeric_limits::max() / i))); - } - - for (int64_t i = 1; i < std::numeric_limits::max(); i = i * 16 + 1) { - params.insert(createIdentityParamsForScales(static_cast(std::numeric_limits::max() / i), - static_cast(i))); - } - return params; -} - -INSTANTIATE_TEST_SUITE_P(MakePWLIdentityTests, - MakePWLIdentityTestFixture, - ::testing::ValuesIn(GenerateParams()), - MakePWLIdentityTestFixture::GetTestCaseName); - -} // namespace diff --git a/src/plugins/intel_gna/tests/unit/gna_allocator_test.cpp b/src/plugins/intel_gna/tests/unit/gna_allocator_test.cpp deleted file mode 100644 index 26890bb99f1..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_allocator_test.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include - -#include "gna_device.hpp" -#include "memory/gna_memory.hpp" - -// dummy definitions to work around issue with Linux userspace library -typedef unsigned long long time_tsc; -typedef struct { - time_tsc start; // time value on profiler start - time_tsc stop; // time value on profiler stop - time_tsc passed; // time passed between start and stop -} intel_gna_profiler_tsc; - -void profilerTscStop(intel_gna_profiler_tsc* p) { - if (NULL == p) - return; - p->passed = 0; - p->stop = 0; - p->start = 0; -} - -void profilerTscStartAccumulate(intel_gna_profiler_tsc* p) { - if (NULL == p) - return; - p->stop = 0; - p->start = 0; -} - -void profilerTscStopAccumulate(intel_gna_profiler_tsc* p) { - if (NULL == p) - return; - p->stop = 0; - p->passed += p->stop - p->start; -} - -class GNAAllocatorTest : public ::testing::Test { -protected: - std::shared_ptr gnadevice; - void SetUp() override { - // gnadevice.reset(new GNADeviceHelper()); - } -}; - -TEST_F(GNAAllocatorTest, canAllocateStdMemory) { - auto sp = memory::GNAFloatAllocator{}; - uint8_t* x = nullptr; - ASSERT_NO_THROW(x = sp.allocate(100)); - ASSERT_NE(x, nullptr); - ASSERT_NO_THROW(sp.deallocate(x, 100)); -} - -TEST_F(GNAAllocatorTest, canAllocateGNAMemory) { - // GNA device can be opened one per process for now - gnadevice.reset(new GNADeviceHelper()); - memory::GNAAllocator sp{gnadevice}; - uint8_t* x = nullptr; - ASSERT_NO_THROW(x = sp.allocate(100)); - ASSERT_NE(x, nullptr); - ASSERT_NO_THROW(sp.deallocate(x, 100)); -} - -TEST_F(GNAAllocatorTest, canOpenDevice) { - std::thread th([]() { - GNADeviceHelper h1; - }); - - th.join(); - - std::thread th2([]() { - GNADeviceHelper h1; - }); - - th2.join(); -} diff --git a/src/plugins/intel_gna/tests/unit/gna_am_intel_dnn.cpp b/src/plugins/intel_gna/tests/unit/gna_am_intel_dnn.cpp deleted file mode 100644 index 6e5a0ab4669..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_am_intel_dnn.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include - -using namespace testing; - -class GNA_AmIntelDnn_test : public ::testing::Test { -protected: - backend::AMIntelDNN amIntelDnn; - Gna2Model desc = {}; -}; - -TEST_F(GNA_AmIntelDnn_test, intel_nnet_type_tSecondInitNotAllowed) { - desc.Operations = nullptr; - amIntelDnn.component.resize(1); - amIntelDnn.component[0].operation = kDnnAffineOp; - // First init is ok - ASSERT_NO_THROW(amIntelDnn.InitGNAStruct(&desc)); - // Second init would cause memory leak, so it's prohibited - ASSERT_THROW(amIntelDnn.InitGNAStruct(&desc), InferenceEngine::Exception); - amIntelDnn.DestroyGNAStruct(&desc); -} - -TEST_F(GNA_AmIntelDnn_test, intel_nnet_type_t_ptrIsNullptr) { - ASSERT_THROW(amIntelDnn.InitGNAStruct(nullptr), InferenceEngine::Exception); -} - -TEST_F(GNA_AmIntelDnn_test, intel_nnet_type_t_pLayersIsNotNullptr) { - ASSERT_THROW(amIntelDnn.InitGNAStruct(&desc), InferenceEngine::Exception); -} - -TEST_F(GNA_AmIntelDnn_test, ComponentIsEmpty) { - desc.Operations = nullptr; - ASSERT_THROW(amIntelDnn.InitGNAStruct(&desc), InferenceEngine::Exception); -} diff --git a/src/plugins/intel_gna/tests/unit/gna_api_stub.cpp b/src/plugins/intel_gna/tests/unit/gna_api_stub.cpp deleted file mode 100644 index fdb995b9378..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_api_stub.cpp +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#define INTEL_GNA_DLLEXPORT 1 - -#include -#include -#include - -#include "gna_mock_api.hpp" - -static GNACppApi* current = nullptr; - -GNACppApi::GNACppApi() { - current = this; -} - -GNACppApi::~GNACppApi() { - current = nullptr; -} - -#ifdef __cplusplus -extern "C" { // API uses C linkage so that it can be used by C and C++ applications -#endif - -GNA2_API enum Gna2Status Gna2MemoryAlloc(uint32_t sizeRequested, uint32_t* sizeGranted, void** memoryAddress) { - if (sizeGranted != nullptr) { - *sizeGranted = sizeRequested; - } - if (current != nullptr) { - return current->Gna2MemoryAlloc(sizeRequested, sizeGranted, memoryAddress); - } - *memoryAddress = reinterpret_cast(1); - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2MemorySetTag(void* memory, uint32_t tag) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2DeviceCreateForExport(Gna2DeviceVersion targetDeviceVersion, uint32_t* deviceIndex) { - *deviceIndex = 1; - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2DeviceOpen(uint32_t deviceIndex) { - if (current != nullptr) { - return current->Gna2DeviceOpen(deviceIndex); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2DeviceSetNumberOfThreads(uint32_t deviceIndex, uint32_t numberOfThreads) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2DeviceClose(uint32_t deviceIndex) { - if (current != nullptr) { - return current->Gna2DeviceClose(deviceIndex); - } - return Gna2StatusSuccess; -} - -GNA2_API Gna2Status Gna2DeviceGetCount(uint32_t* numberOfDevices) { - if (numberOfDevices != nullptr) { - *numberOfDevices = 1; - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2MemoryFree(void* memory) { - if (current != nullptr) { - return current->Gna2MemoryFree(memory); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2StatusGetMessage(enum Gna2Status status, char* messageBuffer, uint32_t messageBufferSize) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelCreate(uint32_t deviceIndex, struct Gna2Model const* model, uint32_t* modelId) { - if (current != nullptr) { - return current->Gna2ModelCreate(deviceIndex, model, modelId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelRelease(uint32_t modelId) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelGetLastError(struct Gna2ModelError* error) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2RequestConfigCreate(uint32_t modelId, uint32_t* requestConfigId) { - if (current != nullptr) { - return current->Gna2RequestConfigCreate(modelId, requestConfigId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2RequestConfigEnableActiveList(uint32_t requestConfigId, - uint32_t operationIndex, - uint32_t numberOfIndices, - uint32_t const* indices) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2RequestConfigSetAccelerationMode(uint32_t requestConfigId, - enum Gna2AccelerationMode accelerationMode) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2RequestEnqueue(uint32_t requestConfigId, uint32_t* requestId) { - if (current != nullptr) { - return current->Gna2RequestEnqueue(requestConfigId, requestId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2RequestWait(uint32_t requestId, uint32_t timeoutMilliseconds) { - if (current != nullptr) { - return current->Gna2RequestWait(requestId, timeoutMilliseconds); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelExportConfigCreate(Gna2UserAllocator userAllocator, uint32_t* exportConfigId) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelExportConfigRelease(uint32_t exportConfigId) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelExportConfigSetSource(uint32_t exportConfigId, - uint32_t sourceDeviceIndex, - uint32_t sourceModelId) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelExportConfigSetTarget(uint32_t exportConfigId, - enum Gna2DeviceVersion targetDeviceVersion) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2ModelExport(uint32_t exportConfigId, - enum Gna2ModelExportComponent componentType, - void** exportBuffer, - uint32_t* exportBufferSize) { - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2DeviceGetVersion(uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion) { - if (current != nullptr) { - return current->Gna2DeviceGetVersion(deviceIndex, deviceVersion); - } - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2InstrumentationConfigCreate(uint32_t numberOfInstrumentationPoints, - enum Gna2InstrumentationPoint* selectedInstrumentationPoints, - uint64_t* results, - uint32_t* instrumentationConfigId) { - if (current != nullptr) { - return current->Gna2InstrumentationConfigCreate(numberOfInstrumentationPoints, - selectedInstrumentationPoints, - results, - instrumentationConfigId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2InstrumentationConfigAssignToRequestConfig(uint32_t instrumentationConfigId, - uint32_t requestConfigId) { - if (current != nullptr) { - return current->Gna2InstrumentationConfigAssignToRequestConfig(instrumentationConfigId, requestConfigId); - } - return Gna2StatusSuccess; -} - -GNA2_API enum Gna2Status Gna2GetLibraryVersion(char* versionBuffer, uint32_t versionBufferSize) { - if (current != nullptr) { - return current->Gna2GetLibraryVersion(versionBuffer, versionBufferSize); - } - if (versionBuffer != nullptr && versionBufferSize > 0) { - versionBuffer[0] = '\0'; - return Gna2StatusSuccess; - } - return Gna2StatusNullArgumentNotAllowed; -} - -#ifdef __cplusplus -} -#endif diff --git a/src/plugins/intel_gna/tests/unit/gna_executable_network_metrics_test.cpp b/src/plugins/intel_gna/tests/unit/gna_executable_network_metrics_test.cpp deleted file mode 100644 index bdcac55afb0..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_executable_network_metrics_test.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include - -#include "any_copy.hpp" -#include "gna_executable_network.hpp" -#include "gna_plugin.hpp" -#include "memory/gna_memory.hpp" -#include "ov_models/builders.hpp" - -using namespace ov::intel_gna; -using namespace InferenceEngine; - -class GNAPluginForNetworkMetricsTest : public GNAPlugin { -public: - GNAPluginForNetworkMetricsTest(const std::map& configMap) : GNAPlugin(configMap) { - gnamem.reset(new gna_memory_float(memory::GNAFloatAllocator{})); - m_graph_compiler->setGNAMemoryPtr(gnamem); - gnadevice.reset(); - } -}; - -class GnaExecutableNetworkMetricsTest : public ::testing::Test { -public: - void Run(const std::string& metricName, const std::string& expectedResult) { - ov::AnyMap gnaConfig = { - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_EXACT), - }; - auto plugin = std::make_shared(ov::any_copy(gnaConfig)); - auto function = getFunction(); - CNNNetwork cnnNetwork(function); - GNAExecutableNetwork gnaNetwork = GNAExecutableNetwork(cnnNetwork, plugin); - auto result = gnaNetwork.GetMetric(metricName).as(); - ASSERT_EQ(result, expectedResult); - } - -protected: - std::shared_ptr getFunction() { - auto firstInput = std::make_shared(net_precision, shape); - auto secondInput = std::make_shared(net_precision, shape); - auto matmul = std::make_shared(firstInput, secondInput, false, true); - auto result = std::make_shared(matmul); - auto function = - std::make_shared(ov::ResultVector({result}), ov::ParameterVector({firstInput}), "MatMul"); - return function; - } - const ngraph::element::Type net_precision = ngraph::element::f32; - const ngraph::Shape shape = {1, 10}; -}; - -TEST_F(GnaExecutableNetworkMetricsTest, TestNetworkName) { - Run(ov::model_name.name(), "MatMul"); -} - -TEST_F(GnaExecutableNetworkMetricsTest, TestSupportedProperties) { - std::string supportedProperties = - "SUPPORTED_PROPERTIES AVAILABLE_DEVICES OPTIMAL_NUMBER_OF_INFER_REQUESTS RANGE_FOR_ASYNC_INFER_REQUESTS " - "OPTIMIZATION_CAPABILITIES FULL_DEVICE_NAME GNA_LIBRARY_FULL_VERSION " - "GNA_DEVICE_MODE PERFORMANCE_HINT LOG_LEVEL EXECUTION_DEVICES " - "GNA_SCALE_FACTOR_PER_INPUT GNA_FIRMWARE_MODEL_IMAGE GNA_HW_EXECUTION_TARGET GNA_HW_COMPILE_TARGET " - "GNA_PWL_DESIGN_ALGORITHM GNA_PWL_MAX_ERROR_PERCENT INFERENCE_PRECISION_HINT EXECUTION_MODE_HINT " - "PERFORMANCE_HINT_NUM_REQUESTS"; - Run(ov::supported_properties.name(), supportedProperties); -} diff --git a/src/plugins/intel_gna/tests/unit/gna_export_import_test.cpp b/src/plugins/intel_gna/tests/unit/gna_export_import_test.cpp deleted file mode 100644 index bc3fffde1ed..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_export_import_test.cpp +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include - -#include "any_copy.hpp" -#include "common/versioning.hpp" -#include "common_test_utils/data_utils.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "gna_mock_api.hpp" -#include "gna_plugin.hpp" -#include "ov_models/builders.hpp" - -using namespace ::testing; -using ov::intel_gna::GNAPlugin; -using ::testing::InSequence; -using namespace InferenceEngine; - -class GNAExportImportTest : public ::testing::Test { -public: - void ExportModel(std::string exportedModelFileName, const ov::AnyMap gnaConfig) { - auto function = getFunction(); - auto weights = make_shared_blob({Precision::U8, {1, 10}, Layout::NC}); - weights->allocate(); - fillWeights(weights); - - CNNNetwork cnnNetwork = CNNNetwork{function}; - - GNACppApi mockApi; - std::vector> data; - ExpectEnqueueCalls(&mockApi, data); - GNAPlugin plugin(any_copy(gnaConfig)); - - plugin.LoadNetwork(cnnNetwork); - plugin.Export(exportedModelFileName); - } - - void ImportModel(std::string modelPath, const ov::AnyMap gnaConfig) { - GNACppApi mockApi; - std::vector> data; - ExpectEnqueueCalls(&mockApi, data); - EXPECT_CALL(mockApi, Gna2RequestWait(_, _)).WillOnce(Return(Gna2StatusSuccess)); - GNAPlugin plugin(any_copy(gnaConfig)); - std::fstream inputStream(modelPath, std::ios_base::in | std::ios_base::binary); - if (inputStream.fail()) { - THROW_GNA_EXCEPTION << "Cannot open file to import model: " << modelPath; - } - - auto sp = plugin.ImportNetwork(inputStream); - auto inputsInfo = plugin.GetNetworkInputs(); - auto outputsInfo = plugin.GetNetworkOutputs(); - - BlobMap input, output; - AllocateInput(input, &plugin); - AllocateOutput(output, &plugin); - plugin.Infer(input, output); - } - - std::string ExportImportModelWithLogLevel(const ov::AnyMap gnaConfig) { - exported_file_name = "export_test.bin"; - ExportModel(exported_file_name, gnaConfig); - testing::internal::CaptureStdout(); - ImportModel(exported_file_name, gnaConfig); - return testing::internal::GetCapturedStdout(); - } - -protected: - void AllocateInput(BlobMap& input, GNAPlugin* plugin) { - auto inputsInfo = plugin->GetNetworkInputs(); - for (auto&& info : inputsInfo) { - auto& inputBlob = input[info.first]; - inputBlob = make_blob_with_precision( - {Precision::FP32, info.second->getTensorDesc().getDims(), info.second->getLayout()}); - inputBlob->allocate(); - } - } - - void AllocateOutput(BlobMap& output, GNAPlugin* plugin) { - auto outputsInfo = plugin->GetNetworkOutputs(); - for (auto&& out : outputsInfo) { - auto& outputBlob = output[out.first]; - auto dims = out.second->getDims(); - auto outsize = details::product(std::begin(dims), std::end(dims)); - outputBlob.reset(new TBlob({Precision::FP32, {1, outsize}, Layout::NC})); - outputBlob->allocate(); - } - } - - void fillWeights(InferenceEngine::Blob::Ptr weights, std::vector pattern = {(1.0F)}) { - float* p = weights->buffer().as(); - float* pEnd = p + weights->byteSize() / sizeof(float); - - for (; p != pEnd;) { - for (int i = 0; i != (weights->byteSize() / sizeof(float) / 3) + 1; i++) { - for (int j = 0; j != pattern.size() && p != pEnd; j++, p++) { - *p = pattern[j]; - } - } - } - } - - std::shared_ptr getFunction() { - auto ngPrc = ngraph::element::f32; - size_t shape = 10; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape{1, shape})}; - auto mul_const = - ngraph::builder::makeConstant(ngPrc, - {shape, shape}, - ov::test::utils::generate_float_numbers(shape * shape, -0.5f, 0.5f), - false); - - auto matmul = std::make_shared(params[0], mul_const, false, true); - auto res = std::make_shared(matmul); - auto function = std::make_shared(res, params, "MatMul"); - return function; - } - - void ExpectEnqueueCalls(GNACppApi* mockApi, std::vector>& data) { - EXPECT_CALL(*mockApi, Gna2MemoryAlloc(_, _, _)) - .Times(AtLeast(1)) - .WillRepeatedly(Invoke([&data](uint32_t sizeRequested, uint32_t* sizeGranted, void** memoryAddress) { - data.push_back(std::vector(sizeRequested)); - *sizeGranted = sizeRequested; - *memoryAddress = data.back().data(); - return Gna2StatusSuccess; - })); - - EXPECT_CALL(*mockApi, Gna2DeviceGetVersion(_, _)) - .WillOnce(Invoke([](uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion) { - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(*mockApi, Gna2DeviceOpen(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(*mockApi, Gna2GetLibraryVersion(_, _)).Times(AtLeast(0)).WillRepeatedly(Return(Gna2StatusSuccess)); - - EXPECT_CALL(*mockApi, Gna2InstrumentationConfigCreate(_, _, _, _)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(*mockApi, Gna2ModelCreate(_, _, _)) - .WillOnce(Invoke([](uint32_t deviceIndex, struct Gna2Model const* model, uint32_t* modelId) { - *modelId = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(*mockApi, Gna2RequestConfigCreate(_, _)) - .WillOnce(Invoke([](uint32_t modelId, uint32_t* requestConfigId) { - *requestConfigId = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(*mockApi, Gna2InstrumentationConfigAssignToRequestConfig(_, _)) - .Times(AtLeast(1)) - .WillRepeatedly(Return(Gna2StatusSuccess)); - - InSequence seq; - EXPECT_CALL(*mockApi, Gna2DeviceClose(_)).WillOnce(Return(Gna2StatusSuccess)); - EXPECT_CALL(*mockApi, Gna2MemoryFree(_)).Times(AtLeast(1)).WillRepeatedly(Return(Gna2StatusSuccess)); - } - void TearDown() override { - std::remove(exported_file_name.c_str()); - } - std::string exported_file_name; -}; - -TEST_F(GNAExportImportTest, ExportImportI16) { - const ov::AnyMap gna_config = {ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_EXACT), - ov::hint::inference_precision(ngraph::element::i16)}; - exported_file_name = "export_test.bin"; - ExportModel(exported_file_name, gna_config); - ImportModel(exported_file_name, gna_config); -} - -TEST_F(GNAExportImportTest, ExportImportI8) { - const ov::AnyMap gna_config = {ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_EXACT), - ov::hint::inference_precision(ngraph::element::i8)}; - exported_file_name = "export_test.bin"; - ExportModel(exported_file_name, gna_config); - ImportModel(exported_file_name, gna_config); -} - -TEST_F(GNAExportImportTest, HideLibVersionFromModelInLogNoMode) { - const ov::AnyMap gna_config = {ov::log::level(ov::log::Level::NO)}; - EXPECT_THAT(ExportImportModelWithLogLevel(gna_config), - Not(HasSubstr(ov::intel_gna::common::get_openvino_version_string()))); -} - -TEST_F(GNAExportImportTest, HideLibVersionFromModelInLogWarnMode) { - const ov::AnyMap gna_config = {ov::log::level(ov::log::Level::WARNING)}; - EXPECT_THAT(ExportImportModelWithLogLevel(gna_config), - Not(HasSubstr(ov::intel_gna::common::get_openvino_version_string()))); -} - -TEST_F(GNAExportImportTest, ShowLibVersionFromModelInLogDebugMode) { - const ov::AnyMap gna_config = {ov::log::level(ov::log::Level::DEBUG)}; - EXPECT_THAT(ExportImportModelWithLogLevel(gna_config), - HasSubstr(ov::intel_gna::common::get_openvino_version_string())); -} diff --git a/src/plugins/intel_gna/tests/unit/gna_extra_pwl_segments_tests.cpp b/src/plugins/intel_gna/tests/unit/gna_extra_pwl_segments_tests.cpp deleted file mode 100644 index 50c6ab0d609..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_extra_pwl_segments_tests.cpp +++ /dev/null @@ -1,276 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "any_copy.hpp" -#include "common/gna_target.hpp" -#include "gna_infer_request.hpp" -#include "gna_mock_api.hpp" -#include "gna_plugin.hpp" -#include "openvino/opsets/opset11.hpp" -#include "ov_models/builders.hpp" - -using ov::intel_gna::GNAPlugin; -using namespace ov::op; -using namespace ov::opset11; - -namespace { - -struct ConvolutionParameters { - intel_dnn_operation_t convolution_type; - ov::Shape input_shape; - ov::Shape kernel; - ov::Shape stride; - ov::Shape dilation; - size_t numOutChannels; - std::vector pad_begin_pool; - std::vector pad_end_pool; -}; - -struct PWLExtraSegmentsParamsWithConv { - ConvolutionParameters conv_params; - ov::element::Type precision; - ngraph::helpers::ActivationTypes activation_type; - size_t expected_segments_num; - bool use_pooling; - std::map config; -}; - -const std::unordered_map kNGraphActivationMapForTests{ - {ngraph::helpers::ActivationTypes::Relu, "Relu"}, - {ngraph::helpers::ActivationTypes::Sigmoid, "Sigmoid"}}; - -const std::unordered_map kDnnOperationMapForTests{ - {kDnnConvolutional1dOp, "kDnnConvolutional1dOp"}, - {kDnnConvolutional2dOp, "kDnnConvolutional2dOp"}, -}; - -template -std::string GetEnumName(const T& enum_value, - const std::unordered_map& enum_map, - const std::string default_value = "") { - auto iter = enum_map.find(enum_value); - if (iter == enum_map.end()) { - return default_value; - } - return iter->second; -} - -std::string GetDnnOperationName(const intel_dnn_operation_t& enum_value, const std::string default_value = "") { - return GetEnumName(enum_value, kDnnOperationMapForTests, default_value); -} - -std::string GetNGraphActivationTypeName(const ngraph::helpers::ActivationTypes& enum_value, - const std::string default_value = "") { - return GetEnumName(enum_value, kNGraphActivationMapForTests, default_value); -} - -std::ostream& operator<<(std::ostream& os, const ngraph::helpers::ActivationTypes& value) { - os << GetNGraphActivationTypeName(value); - return os; -} - -std::ostream& operator<<(std::ostream& os, const intel_dnn_operation_t& value) { - os << GetDnnOperationName(value); - return os; -} - -class GNAPluginForPWLExtraSegmentsTest : public GNAPlugin { -public: - GNAPluginForPWLExtraSegmentsTest(const std::map& config) : GNAPlugin(config) { - gnamem.reset(new gna_memory_float(memory::GNAFloatAllocator{})); - m_graph_compiler->setGNAMemoryPtr(gnamem); - gnadevice.reset(); - } - void Test(const size_t expected_segments) { - for (const auto& component : m_graph_compiler->dnnComponents.components) { - if (component.dnnComponent.operation == kDnnPiecewiselinearOp) { - EXPECT_EQ(expected_segments, component.dnnComponent.op.pwl.num_segments); - } - } - } -}; - -class GNAPWLExtraSegmentsTestFixture : public ::testing::TestWithParam { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj); - void SetUp() override; - -protected: - InferenceEngine::CNNNetwork m_cnn_network; -}; - -std::string GNAPWLExtraSegmentsTestFixture::getTestCaseName( - const testing::TestParamInfo& obj) { - auto params = obj.param; - std::ostringstream result; - result << "ConvolutionType=" << params.conv_params.convolution_type << "_"; - result << "ActivationType=" << params.activation_type << "_"; - result << "PoolingOn=" << (params.use_pooling ? "yes" : "no"); - for (auto const& config_entry : params.config) { - result << "_config_entry=" << config_entry.first << "_" << config_entry.second; - } - return result.str(); -} - -void GNAPWLExtraSegmentsTestFixture::SetUp() { - PWLExtraSegmentsParamsWithConv tests_params; - auto params = GetParam(); - const auto& conv_params = params.conv_params; - const auto& precision = params.precision; - const auto& input_shape = conv_params.input_shape; - const auto& kernel = conv_params.kernel; - const auto& stride = conv_params.stride; - const auto& pad_begin_pool = conv_params.pad_begin_pool; - const auto& pad_end_pool = conv_params.pad_end_pool; - ov::CoordinateDiff pad_begin(pad_begin_pool.begin(), pad_begin_pool.end()); - ov::CoordinateDiff pad_end(pad_end_pool.begin(), pad_end_pool.end()); - const auto& dilation = conv_params.dilation; - const auto& activation_type = params.activation_type; - const auto& use_pooling = params.use_pooling; - std::vector filter_shape; - filter_shape.push_back(conv_params.numOutChannels); - filter_shape.push_back(input_shape[1]); - filter_shape.insert(filter_shape.end(), kernel.begin(), kernel.end()); - - auto input = std::make_shared(precision, input_shape); - auto filter = ngraph::builder::makeConstant(precision, filter_shape, {1.f}, true); - - auto conv = std::make_shared(input, filter, stride, pad_begin, pad_end, dilation); - - auto activation = ngraph::builder::makeActivation(conv, precision, activation_type); - std::shared_ptr result = nullptr; - - if (use_pooling) { - OPENVINO_SUPPRESS_DEPRECATED_START - auto maxpool = ngraph::builder::makePooling(activation, - stride, - pad_begin_pool, - pad_end_pool, - kernel, - RoundingType::FLOOR, - PadType::VALID, - false, - ngraph::helpers::PoolingTypes::MAX); - OPENVINO_SUPPRESS_DEPRECATED_END - result = std::make_shared(maxpool); - } else { - result = std::make_shared(activation); - } - - auto function = std::make_shared(ov::ResultVector({result}), - ov::ParameterVector({input}), - "convolution_with_activation_exrta_segments"); - m_cnn_network = InferenceEngine::CNNNetwork(function); -} - -const std::map configs_30 = {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_EXEC_TARGET", "GNA_TARGET_3_0"}}; - -const std::map configs_35 = {{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, - {"GNA_EXEC_TARGET", "GNA_TARGET_3_5"}}; - -auto kPrecision32 = ov::element::f32; - -const ov::Shape kInput1D = {1, 1, 1, 8}; -const ov::Shape kKernel1D = {1, 2}; -const ov::Shape kStride1D = {1, 1}; -const ov::Shape kDilation1D = kStride1D; -const size_t kOutChanneldsNum1D = 4; -const std::vector kPadBegin1D = {0, 0}; -const std::vector kPadEnd1D = {0, 0}; -const ConvolutionParameters kConvolutionParams1D = - {kDnnConvolutional1dOp, kInput1D, kKernel1D, kStride1D, kDilation1D, kOutChanneldsNum1D, kPadBegin1D, kPadEnd1D}; - -const PWLExtraSegmentsParamsWithConv kConvolution1DReluWithoutPoolParams_30 = - {kConvolutionParams1D, kPrecision32, ngraph::helpers::ActivationTypes::Relu, 2, false, configs_30}; -const PWLExtraSegmentsParamsWithConv kConvolution1DReluWithPoolParams_30 = - {kConvolutionParams1D, kPrecision32, ngraph::helpers::ActivationTypes::Relu, 2, true, configs_30}; -const PWLExtraSegmentsParamsWithConv kConvolution1DSigmoidWithoutPoolParams_30 = - {kConvolutionParams1D, kPrecision32, ngraph::helpers::ActivationTypes::Sigmoid, 12, false, configs_30}; -const PWLExtraSegmentsParamsWithConv kConvolution1DSigmoidWithPoolParams_30 = - {kConvolutionParams1D, kPrecision32, ngraph::helpers::ActivationTypes::Sigmoid, 12, true, configs_30}; - -const PWLExtraSegmentsParamsWithConv kConvolution1DReluWithoutPoolParams_35 = - {kConvolutionParams1D, kPrecision32, ngraph::helpers::ActivationTypes::Relu, 4, false, configs_35}; -const PWLExtraSegmentsParamsWithConv kConvolution1DReluWithPoolParams_35 = - {kConvolutionParams1D, kPrecision32, ngraph::helpers::ActivationTypes::Relu, 4, true, configs_35}; -const PWLExtraSegmentsParamsWithConv kConvolution1DSigmoidWithoutPoolParams_35 = - {kConvolutionParams1D, kPrecision32, ngraph::helpers::ActivationTypes::Sigmoid, 12, false, configs_35}; -const PWLExtraSegmentsParamsWithConv kConvolution1DSigmoidWithPoolParams_35 = - {kConvolutionParams1D, kPrecision32, ngraph::helpers::ActivationTypes::Sigmoid, 12, true, configs_35}; - -const ov::Shape kInput2D = {1, 8, 20, 16}; -const ov::Shape kKernel2D = {1, 1}; -const ov::Shape kStride2D = {1, 1}; -const ov::Shape kDilation2D = kStride2D; -const size_t kOutChanneldsNum2D = 8; -const std::vector kPadBegin2D = {0, 0}; -const std::vector kPadEnd2D = {0, 0}; -const ConvolutionParameters kConvolutionParams2D = - {kDnnConvolutional2dOp, kInput2D, kKernel2D, kStride2D, kDilation2D, kOutChanneldsNum2D, kPadBegin2D, kPadEnd2D}; - -const PWLExtraSegmentsParamsWithConv kConvolution2DReluWithoutPoolParams_30 = - {kConvolutionParams2D, kPrecision32, ngraph::helpers::ActivationTypes::Relu, 4, false, configs_30}; -const PWLExtraSegmentsParamsWithConv kConvolution2DReluWithPoolParams_30 = - {kConvolutionParams2D, kPrecision32, ngraph::helpers::ActivationTypes::Relu, 4, true, configs_30}; -const PWLExtraSegmentsParamsWithConv kConvolution2DSigmoidWithoutPoolParams_30 = - {kConvolutionParams2D, kPrecision32, ngraph::helpers::ActivationTypes::Sigmoid, 12, false, configs_30}; -const PWLExtraSegmentsParamsWithConv kConvolution2DSigmoidWithPoolParams_30 = - {kConvolutionParams2D, kPrecision32, ngraph::helpers::ActivationTypes::Sigmoid, 12, true, configs_30}; - -const PWLExtraSegmentsParamsWithConv kConvolution2DReluWithoutPoolParams_35 = - {kConvolutionParams2D, kPrecision32, ngraph::helpers::ActivationTypes::Relu, 4, false, configs_35}; -const PWLExtraSegmentsParamsWithConv kConvolution2DReluWithPoolParams_35 = - {kConvolutionParams2D, kPrecision32, ngraph::helpers::ActivationTypes::Relu, 4, true, configs_35}; -const PWLExtraSegmentsParamsWithConv kConvolution2DSigmoidWithoutPoolParams_35 = - {kConvolutionParams2D, kPrecision32, ngraph::helpers::ActivationTypes::Sigmoid, 12, false, configs_35}; -const PWLExtraSegmentsParamsWithConv kConvolution2DSigmoidWithPoolParams_35 = - {kConvolutionParams2D, kPrecision32, ngraph::helpers::ActivationTypes::Sigmoid, 12, true, configs_35}; - -INSTANTIATE_TEST_CASE_P(GNAPWLExtraSegmentsConv1DTests, - GNAPWLExtraSegmentsTestFixture, - ::testing::Values(kConvolution1DReluWithoutPoolParams_30, - kConvolution1DReluWithPoolParams_30, - kConvolution1DSigmoidWithoutPoolParams_30, - kConvolution1DSigmoidWithPoolParams_30, - kConvolution1DReluWithoutPoolParams_35, - kConvolution1DReluWithPoolParams_35, - kConvolution1DSigmoidWithoutPoolParams_35, - kConvolution1DSigmoidWithPoolParams_35), - GNAPWLExtraSegmentsTestFixture::getTestCaseName); - -INSTANTIATE_TEST_CASE_P(GNAPWLExtraSegmentsConv2DTests, - GNAPWLExtraSegmentsTestFixture, - ::testing::Values(kConvolution2DReluWithoutPoolParams_30, - kConvolution2DReluWithPoolParams_30, - kConvolution2DSigmoidWithoutPoolParams_30, - kConvolution2DSigmoidWithPoolParams_30, - kConvolution2DReluWithoutPoolParams_35, - kConvolution2DReluWithPoolParams_35, - kConvolution2DSigmoidWithoutPoolParams_35, - kConvolution2DSigmoidWithPoolParams_35), - GNAPWLExtraSegmentsTestFixture::getTestCaseName); - -TEST_P(GNAPWLExtraSegmentsTestFixture, check_number_of_segments) { - auto params = GetParam(); - auto target_name = params.config["GNA_EXEC_TARGET"]; - auto target_device = ov::intel_gna::target::StringToDevice(target_name); - auto target_gna = ov::intel_gna::target::DeviceToGna(target_device); - - GNACppApi enableMocks; - EXPECT_CALL(enableMocks, Gna2DeviceGetVersion(testing::_, testing::_)) - .WillOnce(testing::Invoke([=](uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion) { - *deviceVersion = target_gna; - return Gna2StatusSuccess; - })); - - GNAPluginForPWLExtraSegmentsTest plugin(params.config); - - EXPECT_NO_THROW(plugin.LoadNetwork(m_cnn_network)); - EXPECT_NO_THROW(plugin.Test(params.expected_segments_num)); -} - -} // namespace \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/unit/gna_get_2d_reshaped_data.cpp b/src/plugins/intel_gna/tests/unit/gna_get_2d_reshaped_data.cpp deleted file mode 100644 index 3d39fe1ea5e..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_get_2d_reshaped_data.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -// to suppress deprecated definition errors -#define IMPLEMENT_INFERENCE_ENGINE_PLUGIN -#include "gna_groups.hpp" - -namespace { -std::vector, std::vector>> input_shapes_2d{ - {{1, 128}, {8, 16}}, {{1, 64}, {8, 8}}, {{1, 56}, {7, 8}}, {{1, 48}, {6, 8}}, {{1, 40}, {5, 8}}, - {{1, 32}, {4, 8}}, {{1, 24}, {3, 8}}, {{1, 16}, {2, 8}}, {{1, 8}, {1, 8}}, {{1, 19}, {1, 19}}, - {{128, 1}, {8, 16}}, {{64, 1}, {8, 8}}, {{56, 1}, {7, 8}}, {{48, 1}, {6, 8}}, {{40, 1}, {5, 8}}, - {{32, 1}, {4, 8}}, {{24, 1}, {3, 8}}, {{16, 1}, {2, 8}}, {{8, 1}, {1, 8}}, {{19, 1}, {1, 19}}}; - -std::vector, std::vector>> input_shapes_4d{ - {{1, 2, 2, 32}, {8, 16, 1, 1}}, {{1, 2, 4, 8}, {8, 8, 1, 1}}, {{1, 2, 2, 14}, {7, 8, 1, 1}}, - {{1, 2, 4, 6}, {6, 8, 1, 1}}, {{1, 2, 2, 10}, {5, 8, 1, 1}}, {{1, 2, 2, 8}, {4, 8, 1, 1}}, - {{1, 2, 2, 6}, {3, 8, 1, 1}}, {{1, 2, 2, 4}, {2, 8, 1, 1}}, {{1, 2, 2, 2}, {1, 8, 1, 1}}, - {{1, 1, 1, 19}, {1, 19, 1, 1}}, {{32, 2, 2, 1}, {8, 16, 1, 1}}, {{8, 4, 2, 1}, {8, 8, 1, 1}}, - {{14, 2, 2, 1}, {7, 8, 1, 1}}, {{6, 4, 2, 1}, {6, 8, 1, 1}}, {{10, 2, 2, 1}, {5, 8, 1, 1}}, - {{8, 2, 2, 1}, {4, 8, 1, 1}}, {{6, 2, 2, 1}, {3, 8, 1, 1}}, {{4, 2, 2, 1}, {2, 8, 1, 1}}, - {{2, 2, 2, 1}, {1, 8, 1, 1}}, {{19, 1, 1, 1}, {1, 19, 1, 1}}}; - -class Get2DReshapedDataTest : public ::testing::Test { -protected: - const char* input_name = "input"; - const InferenceEngine::Precision precision = InferenceEngine::Precision::FP32; - const size_t max_batch_size = 8; - void Reshape2dAndCheck(const std::pair, std::vector>& input_shape, - InferenceEngine::Layout layout) const { - auto data = - std::make_shared(input_name, - InferenceEngine::TensorDesc(precision, input_shape.first, layout)); - auto new_data = Get2DReshapedData(data, 1, max_batch_size); - ASSERT_EQ(new_data->getDims(), input_shape.second); - ASSERT_EQ(new_data->getPrecision(), precision); - ASSERT_EQ(new_data->getLayout(), layout); - } -}; - -TEST_F(Get2DReshapedDataTest, testReshape2D) { - auto layout = InferenceEngine::NC; - for (const auto& input_shape : input_shapes_2d) { - Reshape2dAndCheck(input_shape, layout); - } -} - -TEST_F(Get2DReshapedDataTest, testReshape4D) { - auto layout = InferenceEngine::NCHW; - for (const auto& input_shape : input_shapes_4d) { - Reshape2dAndCheck(input_shape, layout); - } -} -} // namespace diff --git a/src/plugins/intel_gna/tests/unit/gna_get_aligned_split_sizes.cpp b/src/plugins/intel_gna/tests/unit/gna_get_aligned_split_sizes.cpp deleted file mode 100644 index 0ec3d2063b2..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_get_aligned_split_sizes.cpp +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -// to suppress deprecated definition errors -#define IMPLEMENT_INFERENCE_ENGINE_PLUGIN -#include "common/gna_target.hpp" -#include "layers/gna_split_layer.hpp" -#include "ngraph/opsets/opset9.hpp" - -using namespace ov::intel_gna::limitations; -using namespace ov::intel_gna::target; - -namespace { - -using GetAlignedSplitSizesData = std::tuple // expected sizes - >; - -const std::vector data = { - GetAlignedSplitSizesData{10, 100, 64, std::vector{10}}, - GetAlignedSplitSizesData{1024, 100, 64, std::vector(16, 64)}, - GetAlignedSplitSizesData{151, 100, 64, std::vector{64, 64, 23}}, - GetAlignedSplitSizesData{151, 65, 32, std::vector{64, 64, 23}}, - GetAlignedSplitSizesData{151, 33, 32, std::vector{32, 32, 32, 32, 23}}, - GetAlignedSplitSizesData{151, 17, 16, std::vector{16, 16, 16, 16, 16, 16, 16, 16, 16, 7}}, - GetAlignedSplitSizesData{151, 65, 1, std::vector{65, 65, 21}}, - GetAlignedSplitSizesData{67000, 65528, 64, std::vector{65472, 1528}}, - GetAlignedSplitSizesData{67000, 65528, 16, std::vector{65520, 1480}}}; - -TEST(GetAlignedSplitSizesTest, testAlignedSplitSizes) { - for (const auto& dataItem : data) { - auto sizes = - ov::intel_gna::GetAlignedSplitSizes(std::get<0>(dataItem), std::get<1>(dataItem), std::get<2>(dataItem)); - ASSERT_EQ(sizes, std::get<3>(dataItem)); - } -} - -using VariadicSplitParameters = std::tuple, // split lengths - bool // supported - >; - -void RunVariadicSplitSupportedTest(DeviceVersion device_version, std::vector test_vectors) { - ov::Shape input_shape; - uint32_t axis; - std::vector split_lengths; - bool result; - - Limitations::init(device_version); - for (const auto& item : test_vectors) { - std::tie(input_shape, axis, split_lengths, result) = item; - - auto split = std::make_shared( - std::make_shared(ngraph::element::f32, input_shape), - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape({1}), {axis}), - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape({split_lengths.size()}), split_lengths)); - ASSERT_TRUE(Limitations::is_split_supported(split, false) == result); - } - Limitations::deinit(); -} - -TEST(CheckSplitSupported, CheckVariadicSplitSupported_GNA3_5) { - RunVariadicSplitSupportedTest( - DeviceVersion::GNA3_5, - {VariadicSplitParameters{ov::Shape{1024}, 0, std::vector{192, 192, 320, 320}, true}, - VariadicSplitParameters{ov::Shape{1, 1024}, 1, std::vector{640, 192, 192}, true}, - VariadicSplitParameters{ov::Shape{1024}, 0, std::vector{16, 1008}, false}, - VariadicSplitParameters{ov::Shape{1024}, 0, std::vector{500, 24, 500}, false}, - VariadicSplitParameters{ov::Shape{1, 1024}, 1, std::vector{700, 300, 24}, false}}); -} - -TEST(CheckSplitSupported, CheckVariadicSplitSupported_GNA3_6) { - RunVariadicSplitSupportedTest( - DeviceVersion::GNA3_6, - {VariadicSplitParameters{ov::Shape{1024}, 0, std::vector{192, 192, 320, 320}, true}, - VariadicSplitParameters{ov::Shape{1, 1024}, 1, std::vector{640, 192, 192}, true}, - VariadicSplitParameters{ov::Shape{1024}, 0, std::vector{16, 1008}, true}, - VariadicSplitParameters{ov::Shape{1024}, 0, std::vector{500, 24, 500}, false}, - VariadicSplitParameters{ov::Shape{1, 1024}, 1, std::vector{700, 300, 24}, false}}); -} - -using SplitParameters = std::tuple; - -void RunSplitSupportedTest(DeviceVersion device_version, std::vector test_vectors) { - ov::Shape input_shape; - uint32_t axis; - uint32_t num_splits; - bool result; - - Limitations::init(device_version); - for (const auto& item : test_vectors) { - std::tie(input_shape, axis, num_splits, result) = item; - auto split = std::make_shared( - std::make_shared(ngraph::element::f32, input_shape), - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape({}), {axis}), - num_splits); - ASSERT_TRUE(Limitations::is_split_supported(split, false) == result); - } - Limitations::deinit(); -} - -TEST(CheckSplitSupported, CheckSplitSupported_GNA3_5) { - RunSplitSupportedTest(DeviceVersion::GNA3_5, - { - SplitParameters{ov::Shape{1024}, 0, 4, true}, - SplitParameters{ov::Shape{1, 1024}, 1, 16, true}, - SplitParameters{ov::Shape{1024}, 0, 64, false}, - SplitParameters{ov::Shape{1, 1024}, 1, 256, false}, - }); -} - -TEST(CheckSplitSupported, CheckSplitSupported_GNA3_6) { - RunSplitSupportedTest(DeviceVersion::GNA3_6, - { - SplitParameters{ov::Shape{1024}, 0, 4, true}, - SplitParameters{ov::Shape{1, 1024}, 1, 16, true}, - SplitParameters{ov::Shape{1024}, 0, 64, true}, - SplitParameters{ov::Shape{1, 1024}, 1, 256, false}, - }); -} -} // namespace diff --git a/src/plugins/intel_gna/tests/unit/gna_get_crop_params.cpp b/src/plugins/intel_gna/tests/unit/gna_get_crop_params.cpp deleted file mode 100644 index 5e88d442044..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_get_crop_params.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -// to suppress deprecated definition errors -#define IMPLEMENT_INFERENCE_ENGINE_PLUGIN -#include - -#include - -namespace { - -using namespace ov::intel_gna; - -typedef std::tuple, // Input shape - std::vector, // Output shape - std::vector, // Axes - std::vector, // Offset - size_t, // Offset in flatten data - size_t // Output size in flatten data - > - CropParams; - -const std::vector crop_params_vector = {{{8, 16}, {1, 16}, {0, 1}, {1, 0}, 16, 16}, - {{5, 24}, {1, 24}, {0, 1}, {2, 0}, 48, 24}, - {{8, 16}, {2, 16}, {0, 1}, {1, 0}, 16, 32}, - {{1, 16}, {1, 8}, {0, 1}, {0, 5}, 5, 8}, - {{1, 8, 16}, {1, 1, 16}, {0, 1, 2}, {0, 1, 0}, 16, 16}, - {{1, 1, 8, 16}, {1, 1, 1, 16}, {0, 1, 2, 3}, {0, 0, 1, 0}, 16, 16}}; - -TEST(GetCropParamsTest, testGetCropParams) { - InferenceEngine::LayerParams attrs = {"Crop", "Crop", InferenceEngine::Precision::FP32}; - for (const auto& crop_params : crop_params_vector) { - std::vector in_shape; - std::vector orig_out_shape, orig_axes, orig_offset; - size_t result_offset, result_out_size; - std::tie(in_shape, orig_out_shape, orig_axes, orig_offset, result_offset, result_out_size) = crop_params; - - auto crop_layer = std::make_shared(attrs); - auto layout = in_shape.size() == 2 ? InferenceEngine::NC - : (in_shape.size() == 3 ? InferenceEngine::CHW : InferenceEngine::NCHW); - auto data = std::make_shared( - "Crop_input", - InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, in_shape, layout)); - crop_layer->insData.push_back(data); - crop_layer->dim = orig_out_shape; - crop_layer->axis = orig_axes; - crop_layer->offset = orig_offset; - const auto results = GetCropParams(crop_layer.get()); - ASSERT_EQ(results.start_offset, result_offset); - ASSERT_EQ(results.crop_size, result_out_size); - } -} - -} // namespace \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/unit/gna_get_scale_factor.cpp b/src/plugins/intel_gna/tests/unit/gna_get_scale_factor.cpp deleted file mode 100644 index 505f0784f46..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_get_scale_factor.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -// to suppress deprecated definition errors -#define IMPLEMENT_INFERENCE_ENGINE_PLUGIN -#include "frontend/scale_factor_calc.hpp" -#include "gna_graph_tools.hpp" - -namespace { - -class GnaGetScaleFactorTest : public ::testing::Test { -protected: - void GetScaleFactorAndCheck(float src_scale, float dst_scale, float weights_scale, float bias_scale) const { - InferenceEngine::LayerParams params("fc", "FullyConnected", InferenceEngine::Precision::FP32); - InferenceEngine::CNNLayerPtr layer = std::make_shared(params); - layer = InferenceEngine::injectData(*layer); - auto quant = InferenceEngine::getInjectedData(*layer); - quant->_src_quant.SetScale(src_scale); - quant->_dst_quant.SetScale(dst_scale); - quant->_weights_quant.SetScale(weights_scale); - quant->_bias_quant.SetScale(bias_scale); - ASSERT_EQ(ov::intel_gna::frontend::GetScaleFactor(layer, ov::intel_gna::frontend::QuantizedDataType::input), - src_scale); - ASSERT_EQ(ov::intel_gna::frontend::GetScaleFactor(layer, ov::intel_gna::frontend::QuantizedDataType::output), - dst_scale); - ASSERT_EQ(ov::intel_gna::frontend::GetScaleFactor(layer, ov::intel_gna::frontend::QuantizedDataType::weights), - weights_scale); - ASSERT_EQ(ov::intel_gna::frontend::GetScaleFactor(layer, ov::intel_gna::frontend::QuantizedDataType::bias), - bias_scale); - } -}; - -TEST_F(GnaGetScaleFactorTest, validSF) { - EXPECT_NO_THROW(GetScaleFactorAndCheck(100, 200, 300, 400)); -} - -TEST_F(GnaGetScaleFactorTest, invalidSF) { - EXPECT_ANY_THROW(GetScaleFactorAndCheck(0, 200, 300, 400)); - EXPECT_ANY_THROW(GetScaleFactorAndCheck(100, 0, 300, 400)); - EXPECT_ANY_THROW(GetScaleFactorAndCheck(100, 200, 0, 400)); - EXPECT_ANY_THROW(GetScaleFactorAndCheck(100, 200, 300, 0)); - EXPECT_ANY_THROW(GetScaleFactorAndCheck(-100, 200, 300, 400)); - EXPECT_ANY_THROW(GetScaleFactorAndCheck(100, -200, 300, 400)); - EXPECT_ANY_THROW(GetScaleFactorAndCheck(100, 200, -300, 400)); - EXPECT_ANY_THROW(GetScaleFactorAndCheck(100, 200, 300, -400)); - double inf = std::numeric_limits::infinity(); - EXPECT_ANY_THROW(GetScaleFactorAndCheck(inf, 200, 300, 400)); - EXPECT_ANY_THROW(GetScaleFactorAndCheck(100, inf, 300, 400)); - EXPECT_ANY_THROW(GetScaleFactorAndCheck(100, 200, inf, 400)); - EXPECT_ANY_THROW(GetScaleFactorAndCheck(100, 200, 300, inf)); -} - -} // namespace diff --git a/src/plugins/intel_gna/tests/unit/gna_hw_precision_test.cpp b/src/plugins/intel_gna/tests/unit/gna_hw_precision_test.cpp deleted file mode 100644 index 36c97f3c030..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_hw_precision_test.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "any_copy.hpp" -#include "gna_data_types.hpp" -#include "gna_plugin.hpp" -#include "memory/gna_memory.hpp" -#include "ov_models/builders.hpp" - -using namespace InferenceEngine; -namespace testing { - -class GNAPluginForPrecisionTest : public GNAPlugin { -public: - GNAPluginForPrecisionTest(const std::map& configMap) : GNAPlugin(configMap) { - gnamem.reset(new gna_memory_float(memory::GNAFloatAllocator{})); - m_graph_compiler->setGNAMemoryPtr(gnamem); - gnadevice.reset(); - } - std::vector get_components() { - return this->dnn->component; - } - void set_low_precision_input() { - this->gnaFlags->input_low_precision = true; - this->config.gnaFlags.input_low_precision = true; - } -}; - -class GNAHwPrecisionTest : public ::testing::Test { -public: - void Run(const ov::AnyMap gna_config, bool low_precision = false) { - auto plugin = GNAPluginForPrecisionTest(any_copy(gna_config)); - auto function = getFunction(); - CNNNetwork cnnNetwork(function); - if (low_precision) { - plugin.set_low_precision_input(); - } - plugin.LoadNetwork(cnnNetwork); - auto components = plugin.get_components(); - for (int k = 0; k < components.size(); ++k) { - if (components[k].operation == kDnnAffineOp || components[k].operation == kDnnDiagonalOp) { - i_precision_size = components[k].num_bytes_per_input; - o_precision_size = components[k].num_bytes_per_output; - weights_sizes.push_back(components[k].op.affine.num_bytes_per_weight); - bias_sizes.push_back(components[k].op.affine.num_bytes_per_bias); - } - } - } - -protected: - std::shared_ptr getFunction() { - auto firstInput = std::make_shared(net_precision, shape); - auto secondInput = std::make_shared(net_precision, shape); - auto matmul = std::make_shared(firstInput, secondInput, false, true); - auto result = std::make_shared(matmul); - auto function = - std::make_shared(ov::ResultVector({result}), ov::ParameterVector({firstInput}), "MatMul"); - return function; - } - void compare(ngraph::element::Type i_precision, ngraph::element::Type o_precision, size_t w_size, size_t b_size) { - EXPECT_EQ(i_precision_size, i_precision.size()); - EXPECT_EQ(o_precision_size, o_precision.size()); - for (size_t i = 0; i < weights_sizes.size(); ++i) { - EXPECT_EQ(w_size, weights_sizes[i]); - EXPECT_EQ(b_size, bias_sizes[i]); - } - } - const ngraph::element::Type net_precision = ngraph::element::f32; - const ngraph::Shape shape = {1, 10}; - uint32_t i_precision_size; - uint32_t o_precision_size; - std::vector weights_sizes; - std::vector bias_sizes; -}; - -TEST_F(GNAHwPrecisionTest, GNAHwPrecisionTestDefault) { - Run({ - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_EXACT), - }); - compare(ngraph::element::i16, ngraph::element::i32, sizeof(int16_t), sizeof(uint32_t)); -} - -TEST_F(GNAHwPrecisionTest, GNAHwPrecisionTestI16) { - Run({ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_EXACT), - ov::hint::inference_precision(ngraph::element::i16)}); - compare(ngraph::element::i16, ngraph::element::i32, sizeof(int16_t), sizeof(uint32_t)); -} - -TEST_F(GNAHwPrecisionTest, GNAHwPrecisionTestI8) { - Run({ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_EXACT), - ov::hint::inference_precision(ngraph::element::i8)}); - compare(ngraph::element::i16, - ngraph::element::i32, - sizeof(int8_t), - Precision::fromType().size()); -} - -TEST_F(GNAHwPrecisionTest, GNAHwPrecisionTestI8LP) { - Run({ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_EXACT), - ov::hint::inference_precision(ngraph::element::i8)}, - true); - compare(ngraph::element::i8, ngraph::element::i32, sizeof(int8_t), sizeof(int8_t)); -} - -TEST_F(GNAHwPrecisionTest, GNAHwPrecisionTestFP32) { - Run({ - ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_FP32), - }); - compare(ngraph::element::f32, ngraph::element::f32, sizeof(float), sizeof(float)); -} -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/gna_infer_request_test.cpp b/src/plugins/intel_gna/tests/unit/gna_infer_request_test.cpp deleted file mode 100644 index 4077a86159c..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_infer_request_test.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_infer_request.hpp" - -#include -#include - -#include - -#include "any_copy.hpp" -#include "common_test_utils/data_utils.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "gna_mock_api.hpp" -#include "gna_plugin.hpp" -#include "ov_models/builders.hpp" - -using namespace ::testing; -using namespace InferenceEngine; - -using ov::intel_gna::GNAInferRequest; -using ov::intel_gna::GNAPlugin; -using ::testing::InSequence; - -class GNAInferRequestTest : public ::testing::Test { -public: - IInferRequestInternal::Ptr CreateRequest() { - auto function = GetFunction(); - CNNNetwork cnn_network = CNNNetwork{function}; - - SetExpectsForLoadNetworkAndShutDown(_data); - const ov::AnyMap gna_config = {ov::intel_gna::execution_mode(ov::intel_gna::ExecutionMode::SW_EXACT)}; - auto plugin = std::make_shared(any_copy(gna_config)); - plugin->LoadNetwork(cnn_network); - - return std::make_shared(plugin, cnn_network.getInputsInfo(), cnn_network.getOutputsInfo()); - } - -protected: - std::shared_ptr GetFunction() { - auto ngPrc = ngraph::element::f32; - std::vector shape = {1, 10}; - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(shape))}; - auto shape_size = ov::shape_size(shape); - auto add_const = - ngraph::builder::makeConstant(ngPrc, - shape, - ov::test::utils::generate_float_numbers(shape_size, -0.5f, 0.5f), - false); - - auto add = std::make_shared(params[0], add_const); - auto res = std::make_shared(add); - auto function = std::make_shared(res, params, "Add"); - return function; - } - - void SetExpectsForLoadNetworkAndShutDown(std::vector>& data) { - EXPECT_CALL(*_mock_api, Gna2MemoryAlloc(_, _, _)) - .Times(AtLeast(1)) - .WillRepeatedly(Invoke([&data](uint32_t size_requested, uint32_t* size_granted, void** memory_address) { - data.push_back(std::vector(size_requested)); - *size_granted = size_requested; - *memory_address = data.back().data(); - return Gna2StatusSuccess; - })); - - EXPECT_CALL(*_mock_api, Gna2DeviceGetVersion(_, _)) - .WillOnce(Invoke([](uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion) { - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(*_mock_api, Gna2DeviceOpen(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(*_mock_api, Gna2GetLibraryVersion(_, _)) - .Times(AtLeast(0)) - .WillRepeatedly(Return(Gna2StatusSuccess)); - - EXPECT_CALL(*_mock_api, Gna2InstrumentationConfigCreate(_, _, _, _)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(*_mock_api, Gna2ModelCreate(_, _, _)) - .WillOnce(Invoke([](uint32_t deviceIndex, struct Gna2Model const* model, uint32_t* model_id) { - *model_id = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(*_mock_api, Gna2RequestConfigCreate(_, _)) - .WillOnce(Invoke([](uint32_t model_Id, uint32_t* request_config_id) { - *request_config_id = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(*_mock_api, Gna2InstrumentationConfigAssignToRequestConfig(_, _)) - .Times(AtLeast(1)) - .WillRepeatedly(Return(Gna2StatusSuccess)); - - InSequence seq; - EXPECT_CALL(*_mock_api, Gna2DeviceClose(_)).WillOnce(Return(Gna2StatusSuccess)); - EXPECT_CALL(*_mock_api, Gna2MemoryFree(_)).Times(AtLeast(1)).WillRepeatedly(Return(Gna2StatusSuccess)); - } - - void SetExpectOnEnqueue(const Gna2Status& return_status = Gna2StatusSuccess) { - EXPECT_CALL(*_mock_api, Gna2RequestEnqueue(_, _)).WillOnce(Return(return_status)); - } - - void SetExpectOnWait(const Gna2Status& return_status = Gna2StatusSuccess) { - EXPECT_CALL(*_mock_api, Gna2RequestWait(_, _)).WillOnce(Return(return_status)); - } - - void SetUp() override { - _mock_api = std::make_shared>(); - } - - void TearDown() override { - ASSERT_TRUE(Mock::VerifyAndClearExpectations(_mock_api.get())); - } - - std::shared_ptr> _mock_api; - std::vector> _data; -}; - -TEST_F(GNAInferRequestTest, start_async) { - auto request = CreateRequest(); - SetExpectOnEnqueue(); - // wait on shutdown neede if request was enqueued by not waited - SetExpectOnWait(); - EXPECT_NO_THROW(request->StartAsync()); -} - -TEST_F(GNAInferRequestTest, start_async_with_enqueue_error) { - auto request = CreateRequest(); - // trigger Gna2RequestEnqueue to fail - SetExpectOnEnqueue(Gna2StatusUnknownError); - // no wait needed due the fact there are no enqueud requests - EXPECT_THROW(request->StartAsync(), std::exception); -} - -TEST_F(GNAInferRequestTest, start_async_with_wait) { - auto request = CreateRequest(); - SetExpectOnEnqueue(); - // wait on shutdown needed if request was enqueued by not waited - SetExpectOnWait(); - EXPECT_NO_THROW(request->StartAsync()); - EXPECT_EQ(OK, request->Wait(0)); -} - -TEST_F(GNAInferRequestTest, start_async_error_with_wait) { - auto request = CreateRequest(); - SetExpectOnEnqueue(Gna2StatusUnknownError); - // wait on shutdown needed if request was enqueued by not waited - // SetExpectOnWait(); - EXPECT_THROW(request->StartAsync(), std::exception); - EXPECT_EQ(INFER_NOT_STARTED, request->Wait(0)); -} - -TEST_F(GNAInferRequestTest, start_async_with_wait_error) { - auto request = CreateRequest(); - SetExpectOnEnqueue(); - // wait on shutdown needed if request was enqueued by not waited - SetExpectOnWait(Gna2StatusUnknownError); - EXPECT_NO_THROW(request->StartAsync()); - EXPECT_THROW(request->Wait(0), std::exception); -} - -TEST_F(GNAInferRequestTest, start_async_wait_check_recovery_after_wait_error) { - auto request = CreateRequest(); - SetExpectOnEnqueue(); - SetExpectOnWait(Gna2StatusUnknownError); - EXPECT_NO_THROW(request->StartAsync()); - EXPECT_THROW(request->Wait(0), std::exception); - // check that no there is exception on second wiat after first failing - EXPECT_EQ(INFER_NOT_STARTED, request->Wait(0)); - - // start new request - SetExpectOnEnqueue(); - SetExpectOnWait(); - EXPECT_NO_THROW(request->StartAsync()); - EXPECT_EQ(OK, request->Wait(0)); -} - -TEST_F(GNAInferRequestTest, infer) { - auto request = CreateRequest(); - SetExpectOnEnqueue(); - SetExpectOnWait(); - EXPECT_NO_THROW(request->Infer()); -} - -TEST_F(GNAInferRequestTest, infer_enque_error) { - auto request = CreateRequest(); - SetExpectOnEnqueue(Gna2StatusUnknownError); - EXPECT_THROW(request->Infer(), std::exception); -} - -TEST_F(GNAInferRequestTest, infer_wait_error_check_recovery) { - auto request = CreateRequest(); - SetExpectOnEnqueue(); - SetExpectOnWait(Gna2StatusUnknownError); - EXPECT_THROW(request->Infer(), std::exception); - // check if next infer will execute properly after wait throwing - SetExpectOnEnqueue(); - SetExpectOnWait(); - EXPECT_NO_THROW(request->Infer()); -} diff --git a/src/plugins/intel_gna/tests/unit/gna_memory_alignment.cpp b/src/plugins/intel_gna/tests/unit/gna_memory_alignment.cpp deleted file mode 100644 index 02c3b7ce0c6..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_memory_alignment.cpp +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "any_copy.hpp" -#include "backend/gna_limitations.hpp" -#include "common/gna_target.hpp" -#include "gna_data_types.hpp" -#include "gna_plugin.hpp" -#include "memory/gna_memory.hpp" -#include "ov_models/builders.hpp" - -using namespace InferenceEngine; -using namespace ov::intel_gna::target; -using namespace ov::intel_gna::limitations; -namespace testing { - -using MemAlignmentTestParams = - std::tuple // input shape vs expected memory size of the input region in bytes. - // For this specific model and when the value of input_shape_H = 1, - // the memory input region size can be calculated using below formula: - // mem_input_region_size = ALIGN8(input_shape_W)*inputPrecInBytes. - // Refer to GNAGraphCompiler::AffinePrimitive for more details. - >; - -const std::vector> param_16B_alignment_prec_fp32{{{1, 2}, 32}, - {{1, 8}, 32}, - {{1, 9}, 64}}; - -const std::vector> param_64B_alignment_prec_int16{{{1, 2}, 64}, - {{1, 32}, 64}, - {{1, 33}, 128}}; - -const std::vector> param_16B_alignment_prec_int16{{{1, 2}, 16}, - {{1, 8}, 16}, - {{1, 9}, 32}, - {{1, 33}, 80}}; - -class GNAPluginForMemoryAlignmentTest : public GNAPlugin { -public: - GNAPluginForMemoryAlignmentTest(const std::map& configMap) : GNAPlugin(configMap) { - if (gnadevice) { - gnamem.reset(new gna_memory_float(memory::GNAFloatAllocator{}, - Limitations::get_instance()->get_memory_alignment(), - Limitations::kMemoryPageSize)); - m_graph_compiler->setGNAMemoryPtr(gnamem); - gnadevice.reset(); - } - } - - const size_t get_memory_REGION_INPUTS_size() const { - return this->gnamem->getQueue(ov::intel_gna::memory::REGION_INPUTS)->calcSize(); - } -}; - -class GNAPluginLoadNetworkTests : public ::testing::TestWithParam { -public: - static std::string GetTestCaseName(const testing::TestParamInfo& obj) { - ExecutionMode exe_mode; - HWGeneration hw_gen; - std::pair inp_shape_vs_mem; - tie(exe_mode, hw_gen, inp_shape_vs_mem) = obj.param; - - std::ostringstream result; - result << "inp=" << inp_shape_vs_mem.first.to_string() << "_"; - result << "mem_region_size=" << inp_shape_vs_mem.second; - return result.str(); - } - -protected: - void Run() { - ExecutionMode exe_mode; - HWGeneration hw_gen; - std::pair inp_shape_vs_mem; - tie(exe_mode, hw_gen, inp_shape_vs_mem) = this->GetParam(); - ngraph::Shape inp_shape = inp_shape_vs_mem.first; - size_t mem_region_size = inp_shape_vs_mem.second; - - const ov::AnyMap gna_config = {ov::intel_gna::execution_mode(exe_mode), ov::intel_gna::compile_target(hw_gen)}; - - auto plugin = GNAPluginForMemoryAlignmentTest(any_copy(gna_config)); - auto function = getMulFunction(inp_shape); - CNNNetwork cnnNetwork(function); - plugin.LoadNetwork(cnnNetwork); - EXPECT_EQ(plugin.get_memory_REGION_INPUTS_size(), mem_region_size); - } - - void SetUp() override { - test_params = GetParam(); - } - -private: - std::shared_ptr getMulFunction(const ngraph::Shape input_shape) { - const ngraph::element::Type net_precision = ngraph::element::f32; - - auto input = std::make_shared(net_precision, input_shape); - auto multiplier = std::make_shared(net_precision, input_shape); - auto matmul = std::make_shared(input, multiplier, false, true); - auto result = std::make_shared(matmul); - auto function = std::make_shared(ov::ResultVector({result}), ov::ParameterVector({input}), "MatMul"); - return function; - } - - MemAlignmentTestParams test_params; -}; - -TEST_P(GNAPluginLoadNetworkTests, CompareInpShapeVsReservedMemRegion) { - Run(); -} - -INSTANTIATE_TEST_SUITE_P(MemoryAlignment_FP32, - GNAPluginLoadNetworkTests, - ::testing::Combine(::testing::Values(ExecutionMode::SW_FP32), - ::testing::Values(HWGeneration::UNDEFINED), - ::testing::ValuesIn(param_16B_alignment_prec_fp32)), - GNAPluginLoadNetworkTests::GetTestCaseName); - -INSTANTIATE_TEST_SUITE_P(MemoryAlignment_GNA_3_0, - GNAPluginLoadNetworkTests, - ::testing::Combine(::testing::Values(ExecutionMode::SW_EXACT), - ::testing::Values(HWGeneration::GNA_3_0), - ::testing::ValuesIn(param_64B_alignment_prec_int16)), - GNAPluginLoadNetworkTests::GetTestCaseName); - -INSTANTIATE_TEST_SUITE_P(MemoryAlignment_GNA_3_5, - GNAPluginLoadNetworkTests, - ::testing::Combine(::testing::Values(ExecutionMode::SW_EXACT), - ::testing::Values(HWGeneration::GNA_3_5), - ::testing::ValuesIn(param_64B_alignment_prec_int16)), - GNAPluginLoadNetworkTests::GetTestCaseName); - -INSTANTIATE_TEST_SUITE_P(MemoryAlignment_GNA_3_6, - GNAPluginLoadNetworkTests, - ::testing::Combine(::testing::Values(ExecutionMode::SW_EXACT), - ::testing::Values(HWGeneration::GNA_3_6), - ::testing::ValuesIn(param_16B_alignment_prec_int16)), - GNAPluginLoadNetworkTests::GetTestCaseName); - -INSTANTIATE_TEST_SUITE_P(MemoryAlignment_GNA_4_0, - GNAPluginLoadNetworkTests, - ::testing::Combine(::testing::Values(ExecutionMode::SW_EXACT), - ::testing::Values(HWGeneration::GNA_4_0), - ::testing::ValuesIn(param_16B_alignment_prec_int16)), - GNAPluginLoadNetworkTests::GetTestCaseName); - -class MemoryAlignmentTest : public ::testing::Test {}; - -TEST(MemoryAlignmentTest, getMemoryAlignmentBytes_Expect64ByteAlignmentWhenTargetIsGNA3_5) { - Limitations::init(DeviceVersion::GNA3_5); - EXPECT_EQ(Limitations::get_instance()->get_memory_alignment(), 64); - Limitations::deinit(); -} - -TEST(MemoryAlignmentTest, getMemoryAlignmentBytes_Expect16ByteAlignmentWhenTargetIsGNA3_6) { - Limitations::init(DeviceVersion::GNA3_6); - EXPECT_EQ(Limitations::get_instance()->get_memory_alignment(), 16); - Limitations::deinit(); -} - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/gna_memory_compact_test.cpp b/src/plugins/intel_gna/tests/unit/gna_memory_compact_test.cpp deleted file mode 100644 index 9918008f799..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_memory_compact_test.cpp +++ /dev/null @@ -1,395 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include - -#include -#include -#include - -#include "gna_data_types.hpp" -#include "gna_fused_iterator.hpp" -#include "gna_plugin.hpp" -#include "memory/gna_memory.hpp" -#include "openvino/opsets/opset8.hpp" -#include "ov_models/builders.hpp" - -using namespace InferenceEngine; -using namespace memory; - -class GNAMemoryCompactTest : public ::testing::Test { -protected: - GNAMemory mem; - bool isCompact = true; - - void SetUp() override {} -}; - -TEST_F(GNAMemoryCompactTest, canOptimizeReservePtr) { - IE_SUPPRESS_DEPRECATED_START - CNNLayerPtr layer1 = std::make_shared(LayerParams("layer1", "test", Precision::FP32)); - CNNLayerPtr layer2 = std::make_shared(LayerParams("layer2", "test", Precision::FP32)); - layer1->userValue.v_int = 1; - layer2->userValue.v_int = 2; - IE_SUPPRESS_DEPRECATED_END - - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - - auto scratch = mem.getQueue(rRegion::REGION_SCRATCH); - scratch->reserve_ptr(layer1, pFuture1, 3 * sizeof(float)); - scratch->reserve_ptr(layer2, pFuture2, 2 * sizeof(float)); - - mem.commit(isCompact); - ASSERT_EQ(scratch->getSize(), 3 * sizeof(float)); -} - -TEST_F(GNAMemoryCompactTest, canOptimizePushValue) { - IE_SUPPRESS_DEPRECATED_START - CNNLayerPtr layer1 = std::make_shared(LayerParams("layer1", "test", Precision::FP32)); - CNNLayerPtr layer2 = std::make_shared(LayerParams("layer2", "test", Precision::FP32)); - layer1->userValue.v_int = 1; - layer2->userValue.v_int = 2; - IE_SUPPRESS_DEPRECATED_END - - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - - auto scratch = mem.getQueue(rRegion::REGION_SCRATCH); - scratch->push_value(layer1, pFuture1, 1.f, 2); - scratch->push_value(layer2, pFuture2, 2.f, 3); - - mem.commit(isCompact); - ASSERT_EQ(mem.getRegionBytes(rRegion::REGION_SCRATCH), 5 * sizeof(float)); -} - -TEST_F(GNAMemoryCompactTest, canOptimizePushValueAndReservePtr) { - IE_SUPPRESS_DEPRECATED_START - CNNLayerPtr layer1 = std::make_shared(LayerParams("layer1", "test", Precision::FP32)); - CNNLayerPtr layer2 = std::make_shared(LayerParams("layer2", "test", Precision::FP32)); - CNNLayerPtr layer3 = std::make_shared(LayerParams("layer3", "test", Precision::FP32)); - layer1->userValue.v_int = 1; - layer2->userValue.v_int = 2; - layer3->userValue.v_int = 3; - IE_SUPPRESS_DEPRECATED_END - - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - float* pFuture3 = reinterpret_cast(&pFuture3); - - auto scratchQueue = mem.getQueue(rRegion::REGION_SCRATCH); - scratchQueue->push_value(layer1, pFuture1, 3.f, 2); - scratchQueue->bind_ptr(layer2, pFuture2, pFuture1, 0, 2); - scratchQueue->reserve_ptr(layer3, pFuture3, 2 * sizeof(float)); - - mem.commit(isCompact); - ASSERT_EQ(scratchQueue->getSize(), 2 * sizeof(float)); -} - -TEST_F(GNAMemoryCompactTest, canOptimizeTwoPushValueAndReservePtr) { - IE_SUPPRESS_DEPRECATED_START - CNNLayerPtr layer1 = std::make_shared(LayerParams("layer1", "test", Precision::FP32)); - CNNLayerPtr layer2 = std::make_shared(LayerParams("layer2", "test", Precision::FP32)); - CNNLayerPtr layer3 = std::make_shared(LayerParams("layer3", "test", Precision::FP32)); - CNNLayerPtr layer4 = std::make_shared(LayerParams("layer4", "test", Precision::FP32)); - layer1->userValue.v_int = 1; - layer2->userValue.v_int = 2; - layer3->userValue.v_int = 3; - layer4->userValue.v_int = 4; - IE_SUPPRESS_DEPRECATED_END - - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - float* pFuture3 = reinterpret_cast(&pFuture3); - - auto scratchQueue = mem.getQueue(rRegion::REGION_SCRATCH); - scratchQueue->push_value(layer1, pFuture1, 1.f, 2); - scratchQueue->push_value(layer2, pFuture2, 2.f, 3); - scratchQueue->reserve_ptr(layer3, pFuture3, 5 * sizeof(float)); - scratchQueue->bind_ptr(layer2, pFuture2, pFuture1, 0, 2); - - mem.commit(isCompact); - ASSERT_EQ(scratchQueue->getSize(), 5 * sizeof(float)); -} - -TEST_F(GNAMemoryCompactTest, canOptimizePushPtrAndReservePtr) { - IE_SUPPRESS_DEPRECATED_START - CNNLayerPtr layer1 = std::make_shared(LayerParams("layer1", "test", Precision::FP32)); - CNNLayerPtr layer2 = std::make_shared(LayerParams("layer2", "test", Precision::FP32)); - CNNLayerPtr layer3 = std::make_shared(LayerParams("layer3", "test", Precision::FP32)); - layer1->userValue.v_int = 1; - layer2->userValue.v_int = 2; - layer3->userValue.v_int = 3; - IE_SUPPRESS_DEPRECATED_END - - float input[] = {1, 2, 3}; - size_t input_size = sizeof(input); - - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - float* pFuture3 = reinterpret_cast(&pFuture3); - - auto scratchQueue = mem.getQueue(rRegion::REGION_SCRATCH); - scratchQueue->push_ptr(layer1, pFuture1, input, input_size); - scratchQueue->reserve_ptr(layer2, pFuture2, input_size); - scratchQueue->bind_ptr(layer3, pFuture3, pFuture2, 0, input_size); - - mem.commit(isCompact); - ASSERT_EQ(scratchQueue->getSize(), input_size); -} - -TEST_F(GNAMemoryCompactTest, canOptimizePushLocalPtrAndReservePtr) { - IE_SUPPRESS_DEPRECATED_START - CNNLayerPtr layer1 = std::make_shared(LayerParams("layer1", "test", Precision::FP32)); - CNNLayerPtr layer2 = std::make_shared(LayerParams("layer2", "test", Precision::FP32)); - CNNLayerPtr layer3 = std::make_shared(LayerParams("layer3", "test", Precision::FP32)); - layer1->userValue.v_int = 1; - layer2->userValue.v_int = 2; - layer3->userValue.v_int = 3; - IE_SUPPRESS_DEPRECATED_END - - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - float* pFuture3 = reinterpret_cast(&pFuture3); - - auto scratchQueue = mem.getQueue(rRegion::REGION_SCRATCH); - size_t input_size; - { - std::vector input = {1.0f, 2.0f, 3.0f, 4.0f}; - input_size = input.size() * sizeof(float); - scratchQueue->push_local_ptr(layer1, pFuture1, &*input.begin(), input_size); - } - - scratchQueue->reserve_ptr(layer2, pFuture2, input_size); - scratchQueue->bind_ptr(layer3, pFuture3, pFuture2, 0, input_size); - - mem.commit(isCompact); - ASSERT_EQ(scratchQueue->getSize(), input_size); -} - -TEST_F(GNAMemoryCompactTest, canOptimizePushInitilizerPtrAndReservePtr) { - IE_SUPPRESS_DEPRECATED_START - CNNLayerPtr layer1 = std::make_shared(LayerParams("layer1", "test", Precision::FP32)); - CNNLayerPtr layer2 = std::make_shared(LayerParams("layer2", "test", Precision::FP32)); - CNNLayerPtr layer3 = std::make_shared(LayerParams("layer3", "test", Precision::FP32)); - layer1->userValue.v_int = 1; - layer2->userValue.v_int = 2; - layer3->userValue.v_int = 3; - IE_SUPPRESS_DEPRECATED_END - - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - float* pFuture3 = reinterpret_cast(&pFuture3); - - auto scratchQueue = mem.getQueue(rRegion::REGION_SCRATCH); - size_t input_size; - { - std::vector input = {1.0f, 2.0f, 3.0f}; - input_size = input.size() * sizeof(float); - scratchQueue->push_initializer(layer1, pFuture1, input_size, [=](void* data, size_t size) { - ie_memcpy(data, size, &input[0], input.size()); - }); - } - - scratchQueue->reserve_ptr(layer2, pFuture2, 2 * input_size); - scratchQueue->bind_ptr(layer3, pFuture3, pFuture2, 0, input_size); - - mem.commit(isCompact); - ASSERT_EQ(scratchQueue->getSize(), 2 * input_size); -} - -TEST_F(GNAMemoryCompactTest, canOptimizeBindInitilizerPtrAndReservePtr) { - IE_SUPPRESS_DEPRECATED_START - CNNLayerPtr layer1 = std::make_shared(LayerParams("layer1", "test", Precision::FP32)); - CNNLayerPtr layer2 = std::make_shared(LayerParams("layer2", "test", Precision::FP32)); - CNNLayerPtr layer3 = std::make_shared(LayerParams("layer3", "test", Precision::FP32)); - CNNLayerPtr layer4 = std::make_shared(LayerParams("layer4", "test", Precision::FP32)); - layer1->userValue.v_int = 1; - layer2->userValue.v_int = 2; - layer3->userValue.v_int = 3; - layer4->userValue.v_int = 4; - IE_SUPPRESS_DEPRECATED_END - - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - float* pFuture3 = reinterpret_cast(&pFuture3); - float* pFuture4 = reinterpret_cast(&pFuture4); - - auto scratchQueue = mem.getQueue(rRegion::REGION_SCRATCH); - { - std::vector input = {1.0f, 2.0f, 3.0f}; - scratchQueue->bind_initializer(layer2, pFuture1, [=](void* data, size_t size) { - ie_memcpy(data, size, &input[0], input.size()); - }); - } - - scratchQueue->reserve_ptr(layer1, pFuture1, 4 * sizeof(float)); - scratchQueue->reserve_ptr(layer3, pFuture3, 2 * sizeof(float)); - scratchQueue->bind_ptr(layer4, pFuture4, pFuture3, 0, 2 * sizeof(float)); - - mem.commit(isCompact); - ASSERT_EQ(scratchQueue->getSize(), 4 * sizeof(float)); -} - -TEST_F(GNAMemoryCompactTest, canOptimizeReservePtrWithOffset) { - IE_SUPPRESS_DEPRECATED_START - CNNLayerPtr layer1 = std::make_shared(LayerParams("layer1", "test", Precision::FP32)); - CNNLayerPtr layer2 = std::make_shared(LayerParams("layer2", "test", Precision::FP32)); - CNNLayerPtr layer3 = std::make_shared(LayerParams("layer3", "test", Precision::FP32)); - layer1->userValue.v_int = 1; - layer2->userValue.v_int = 2; - layer3->userValue.v_int = 3; - IE_SUPPRESS_DEPRECATED_END - - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - float* pFuture3 = reinterpret_cast(&pFuture3); - - auto scratchQueue = mem.getQueue(rRegion::REGION_SCRATCH); - scratchQueue->reserve_ptr(layer1, pFuture1, 2 * sizeof(float)); - scratchQueue->reserve_ptr(layer2, pFuture2, 2 * sizeof(float)); - scratchQueue->bind_ptr(layer3, pFuture3, pFuture2, 2 * sizeof(float), 2 * sizeof(float)); - - mem.commit(isCompact); - ASSERT_EQ(mem.getRegionBytes(rRegion::REGION_SCRATCH), 4 * sizeof(float)); -} - -class GNAMemoryTested : public memory::GNAMemory { - using GNAMemory::GNAMemory; - -public: - void Test() { - // filtering RW allocation requests only - auto filter_req = [](const MemRequest& re) { - return re._region == REGION_SCRATCH && re._type != REQUEST_BIND; - }; - std::vector test_reqs; - const auto& requests = getQueue(REGION_SCRATCH)->_mem_requests; - - auto it = std::copy_if(requests.begin(), requests.end(), std::back_inserter(test_reqs), filter_req); - - // intercrossing condition - auto is_crossed = [](const MemRequest& re1, const MemRequest& re2) { - const std::pair limits_default{0, UINT16_MAX}; - if (re1._life_limits == limits_default || re2._life_limits == limits_default) { - return true; - } - return (re1._life_limits.first > re2._life_limits.first && - re1._life_limits.first < re2._life_limits.second) || - (re1._life_limits.second > re2._life_limits.first && - re1._life_limits.second < re2._life_limits.second); - }; - - // verify that requests are intercrossed - for (auto re_it_1 = test_reqs.begin(); re_it_1 != test_reqs.end(); ++re_it_1) { - for (auto re_it_2 = re_it_1 + 1; re_it_2 != test_reqs.end(); ++re_it_2) { - ASSERT_TRUE(is_crossed(*re_it_1, *re_it_2)); - } - } - } -}; - -class GNAPluginTested : public GNAPlugin { -public: - std::shared_ptr gnamem_t; - GNAPluginTested() : GNAPlugin() { - gnamem_t = std::make_shared(); - gnamem = gnamem_t; - m_graph_compiler->setGNAMemoryPtr(gnamem); - gnadevice.reset(); - } - void Test() { - gnamem_t->Test(); - } -}; - -class GNAMemoryOrderTest : public ::testing::Test {}; - -TEST_F(GNAMemoryOrderTest, orderingFusedLayersActivation) { - auto plugin = GNAPluginTested(); - - ov::Shape input_shape = {1, 16, 20, 16}; - ov::Strides strides = {1, 1}; - ov::Strides dilations = {1, 1}; - ov::CoordinateDiff pad_begin(0, 0), pad_end(0, 0); - auto weights = ngraph::builder::makeConstant(ov::element::f32, {8, 16, 1, 1}, {1.f}); - - auto input = std::make_shared(ov::element::f32, input_shape); - auto conv = std::make_shared(input, weights, strides, pad_begin, pad_end, dilations); - auto activation = - ngraph::builder::makeActivation(conv, ov::element::f32, ngraph::helpers::ActivationTypes::Sigmoid); - auto result = std::make_shared(activation); - auto function = - std::make_shared(ov::ResultVector({result}), ov::ParameterVector({input}), "convolution"); - - InferenceEngine::CNNNetwork cnn_network(function); - plugin.LoadNetwork(cnn_network); - plugin.Test(); -} - -TEST_F(GNAMemoryOrderTest, orderingFusedLayersMaxPool) { - auto plugin = GNAPluginTested(); - - ov::Shape input_shape = {1, 16, 20, 16}; - ov::Strides strides = {1, 1}; - ov::Strides dilations = {1, 1}; - ov::CoordinateDiff pad_begin(0, 0), pad_end(0, 0); - auto weights = ngraph::builder::makeConstant(ov::element::f32, {8, 16, 1, 1}, {1.f}); - - auto input = std::make_shared(ov::element::f32, input_shape); - auto conv = std::make_shared(input, weights, strides, pad_begin, pad_end, dilations); - OPENVINO_SUPPRESS_DEPRECATED_START - auto maxpool = ngraph::builder::makePooling(conv, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ngraph::op::RoundingType::FLOOR, - ngraph::op::PadType::VALID, - false, - ngraph::helpers::PoolingTypes::MAX); - OPENVINO_SUPPRESS_DEPRECATED_END - auto result = std::make_shared(maxpool); - auto function = - std::make_shared(ov::ResultVector({result}), ov::ParameterVector({input}), "convolution"); - - InferenceEngine::CNNNetwork cnn_network(function); - plugin.LoadNetwork(cnn_network); - plugin.Test(); -} - -TEST_F(GNAMemoryOrderTest, orderingFusedLayersActivationMaxPool) { - auto plugin = GNAPluginTested(); - - ov::Shape input_shape = {1, 16, 20, 16}; - ov::Strides strides = {1, 1}; - ov::Strides dilations = {1, 1}; - ov::CoordinateDiff pad_begin(0, 0), pad_end(0, 0); - auto weights = ngraph::builder::makeConstant(ov::element::f32, {8, 16, 1, 1}, {1.f}); - - auto input = std::make_shared(ov::element::f32, input_shape); - auto conv = std::make_shared(input, weights, strides, pad_begin, pad_end, dilations); - auto activation = - ngraph::builder::makeActivation(conv, ov::element::f32, ngraph::helpers::ActivationTypes::Sigmoid); - OPENVINO_SUPPRESS_DEPRECATED_START - auto maxpool = ngraph::builder::makePooling(activation, - {1, 1}, - {0, 0}, - {0, 0}, - {1, 1}, - ngraph::op::RoundingType::FLOOR, - ngraph::op::PadType::VALID, - false, - ngraph::helpers::PoolingTypes::MAX); - OPENVINO_SUPPRESS_DEPRECATED_END - auto result = std::make_shared(maxpool); - auto function = - std::make_shared(ov::ResultVector({result}), ov::ParameterVector({input}), "convolution"); - - InferenceEngine::CNNNetwork cnn_network(function); - plugin.LoadNetwork(cnn_network); - plugin.Test(); -} diff --git a/src/plugins/intel_gna/tests/unit/gna_memory_test.cpp b/src/plugins/intel_gna/tests/unit/gna_memory_test.cpp deleted file mode 100644 index eae6f336c44..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_memory_test.cpp +++ /dev/null @@ -1,451 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "memory/gna_memory.hpp" - -#include - -#include - -using namespace memory; - -class GNAMemoryTest : public ::testing::Test { -protected: - GNAMemory mem{GNAFloatAllocator{}}; - - void SetUp() override {} -}; - -TEST_F(GNAMemoryTest, canStoreActualBlob) { - float input[] = {1, 2, 3}; - float* pFuture = nullptr; - size_t len = sizeof(input); - - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFuture, input, len); - mem.commit(); - - ASSERT_NE(pFuture, nullptr); - ASSERT_NE(pFuture, input); - ASSERT_EQ(pFuture[0], 1); - ASSERT_EQ(pFuture[1], 2); - ASSERT_EQ(pFuture[2], 3); -} - -TEST_F(GNAMemoryTest, canStore2Blobs) { - float input[] = {1, 2, 3, 4}; - float* pFuture = nullptr; - float* pFuture2 = nullptr; - - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFuture, input, 3 * 4); - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFuture2, input + 1, 3 * 4); - mem.commit(); - - ASSERT_NE(pFuture, input); - ASSERT_NE(pFuture2, input); - ASSERT_EQ(pFuture + 3, pFuture2); - - ASSERT_EQ(pFuture[0], 1); - ASSERT_EQ(pFuture[1], 2); - ASSERT_EQ(pFuture[2], 3); - ASSERT_EQ(pFuture[3], 2); - ASSERT_EQ(pFuture[4], 3); - ASSERT_EQ(pFuture[5], 4); -} - -TEST_F(GNAMemoryTest, canStoreBlobsALIGNED) { - GNAMemory dataAlignedMem(16); - float input[] = {1, 2, 3, 4, 5, 6, 7, 8}; - float* pFuture = nullptr; - auto queue = dataAlignedMem.getQueue(REGION_SCRATCH); - queue->push_ptr(nullptr, &pFuture, input, 3 * 4); - dataAlignedMem.commit(); - - ASSERT_EQ(16, queue->getSize()); - - ASSERT_NE(pFuture, input); - ASSERT_NE(pFuture, nullptr); - - ASSERT_EQ(pFuture[0], 1); - ASSERT_EQ(pFuture[1], 2); - ASSERT_EQ(pFuture[2], 3); - // least probability for next element to be equal if not copied - ASSERT_NE(pFuture[3], 4); -} - -TEST_F(GNAMemoryTest, canStore2BlobsALIGNED) { - GNAMemory dataAlignedMem(8); - float input[] = {1, 2, 3, 4, 5, 6, 7, 8}; - float* pFuture = nullptr; - float* pFuture2 = nullptr; - auto queue = dataAlignedMem.getQueue(REGION_SCRATCH); - queue->push_ptr(nullptr, &pFuture, input, 3 * 4); - queue->push_ptr(nullptr, &pFuture2, input, 1 * 4); - dataAlignedMem.commit(); - - ASSERT_EQ(24, queue->getSize()); - - ASSERT_NE(pFuture, nullptr); - - ASSERT_EQ(pFuture[0], 1); - ASSERT_EQ(pFuture[1], 2); - ASSERT_EQ(pFuture[2], 3); - // least probability for next element to be equal if not copied - ASSERT_EQ(pFuture[4], 1); -} - -TEST_F(GNAMemoryTest, canReserveData) { - float* pFuture = nullptr; - mem.getQueue(REGION_SCRATCH)->reserve_ptr(nullptr, &pFuture, 3 * 4); - mem.commit(); - - ASSERT_NE(pFuture, nullptr); -} - -TEST_F(GNAMemoryTest, canReserveDataByVoid) { - mem.getQueue(REGION_SCRATCH)->reserve_ptr(nullptr, nullptr, 3 * 4); - ASSERT_NO_THROW(mem.commit()); -} - -TEST_F(GNAMemoryTest, canReserveAndPushData) { - float input[] = {1, 2, 3}; - float* pFuture = nullptr; - float* pFuture2 = nullptr; - size_t len = sizeof(input); - - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFuture, input, len); - mem.getQueue(REGION_SCRATCH)->reserve_ptr(nullptr, &pFuture2, 3 * 4); - mem.commit(); - - ASSERT_NE(pFuture, nullptr); - ASSERT_NE(pFuture2, nullptr); - ASSERT_NE(pFuture, input); - ASSERT_NE(pFuture2, pFuture); - - pFuture2[0] = -1; - pFuture2[1] = -1; - pFuture2[2] = -1; - - ASSERT_EQ(pFuture[0], 1); - ASSERT_EQ(pFuture[1], 2); - ASSERT_EQ(pFuture[2], 3); -} - -TEST_F(GNAMemoryTest, canBindAndResolve) { - float input[] = {1, 2, 3}; - float* pFuture = nullptr; - float* pFuture2 = nullptr; - float* pFuture3 = nullptr; - size_t len = sizeof(input); - - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture3, &pFuture); - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFuture, input, len); - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture2, &pFuture); - - mem.commit(); - - ASSERT_NE(pFuture, input); - ASSERT_NE(pFuture2, nullptr); - ASSERT_EQ(pFuture2, pFuture); - ASSERT_EQ(pFuture3, pFuture); - - ASSERT_EQ(pFuture2[0], 1); - ASSERT_EQ(pFuture2[1], 2); - ASSERT_EQ(pFuture2[2], 3); -} - -TEST_F(GNAMemoryTest, canBindTransitevlyAndResolve) { - float input[] = {1, 2, 3}; - float* pFuture = nullptr; - float* pFuture3 = nullptr; - float* pFuture4 = nullptr; - size_t len = sizeof(input); - - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture4, &pFuture3); - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture3, &pFuture); - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFuture, input, len); - - mem.commit(); - - ASSERT_NE(pFuture, input); - ASSERT_EQ(pFuture3, pFuture); - ASSERT_EQ(pFuture4, pFuture); - - ASSERT_NE(pFuture4, nullptr); - - ASSERT_EQ(pFuture4[0], 1); - ASSERT_EQ(pFuture4[1], 2); - ASSERT_EQ(pFuture4[2], 3); -} - -TEST_F(GNAMemoryTest, canBindTransitevlyWithOffsetsAndResolve) { - float input[] = {1, 2, 3}; - float* pFuture = nullptr; - float* pFuture3 = nullptr; - float* pFuture4 = nullptr; - size_t len = sizeof(input); - - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture4, &pFuture3, 4); - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture3, &pFuture, 4); - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFuture, input, len); - - mem.commit(); - - ASSERT_NE(pFuture, input); - ASSERT_EQ(pFuture3, pFuture + 1); - ASSERT_EQ(pFuture4, pFuture + 2); - - ASSERT_NE(pFuture, nullptr); - - ASSERT_EQ(pFuture[0], 1); - ASSERT_EQ(pFuture[1], 2); - ASSERT_EQ(pFuture[2], 3); -} - -TEST_F(GNAMemoryTest, canBindWithOffsetAndResolve) { - float input[] = {1, 2, 3}; - float* pFuture = nullptr; - float* pFuture2 = nullptr; - float* pFuture3 = nullptr; - size_t len = sizeof(input); - - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture3, &pFuture, 4); - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFuture, input, len); - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture2, &pFuture); - - mem.commit(); - - ASSERT_NE(pFuture, input); - ASSERT_NE(pFuture2, nullptr); - ASSERT_EQ(pFuture2, pFuture); - ASSERT_NE(pFuture3, nullptr); - ASSERT_EQ(pFuture3, pFuture + 1); - - ASSERT_EQ(pFuture2[0], 1); - ASSERT_EQ(pFuture2[1], 2); - ASSERT_EQ(pFuture2[2], 3); - ASSERT_EQ(pFuture3[0], 2); -} - -TEST_F(GNAMemoryTest, canPushLocal) { - float* pFuture = reinterpret_cast(&pFuture); - - { - std::vector input = {1.0f, 2.0f, 3.0f, 4.0f}; - mem.getQueue(REGION_SCRATCH)->push_local_ptr(nullptr, pFuture, &*input.begin(), 4 * 4); - } - - // poison stack - mem.commit(); - - ASSERT_FLOAT_EQ(pFuture[0], 1); - ASSERT_FLOAT_EQ(pFuture[1], 2); - ASSERT_FLOAT_EQ(pFuture[2], 3); - ASSERT_FLOAT_EQ(pFuture[3], 4); -} - -TEST_F(GNAMemoryTest, canPushValue) { - float* pFuture = reinterpret_cast(&pFuture); - float* pFuture2 = reinterpret_cast(&pFuture2); - - { - mem.getQueue(REGION_SCRATCH)->push_value(nullptr, pFuture, 3.f, 2); - mem.getQueue(REGION_SCRATCH)->push_value(nullptr, pFuture2, 13.f, 2); - } - - mem.commit(); - - ASSERT_FLOAT_EQ(pFuture[0], 3); - ASSERT_FLOAT_EQ(pFuture[1], 3); - ASSERT_FLOAT_EQ(pFuture[2], 13); - ASSERT_FLOAT_EQ(pFuture[3], 13); -} - -TEST_F(GNAMemoryTest, canPushReadOnlyValue) { - float* pFuture = reinterpret_cast(&pFuture); - float* pFuture2 = reinterpret_cast(&pFuture2); - - { - mem.getQueue(REGION_SCRATCH)->push_value(nullptr, pFuture, 3.f, 2); - mem.getQueue(REGION_RO)->push_value(nullptr, pFuture2, 13.f, 2); - } - - mem.commit(); - - ASSERT_FLOAT_EQ(pFuture[0], 3); - ASSERT_FLOAT_EQ(pFuture[1], 3); - ASSERT_FLOAT_EQ(pFuture2[0], 13); - ASSERT_FLOAT_EQ(pFuture2[1], 13); -} - -TEST_F(GNAMemoryTest, canCalculateReadWriteSectionSizeEmptyReqs) { - mem.getQueue(REGION_SCRATCH)->push_value(nullptr, nullptr, 3.f, 2); - mem.getQueue(REGION_RO)->push_value(nullptr, nullptr, 13.f, 2); - mem.commit(); - - ASSERT_EQ(mem.getRegionBytes(rRegion::REGION_SCRATCH), 0); - ASSERT_EQ(mem.getRegionBytes(rRegion::REGION_RO), 0); -} - -TEST_F(GNAMemoryTest, canCalculateReadWriteSectionSizeWithEmptyReqs) { - // empty request before - mem.getQueue(REGION_SCRATCH)->push_value(nullptr, nullptr, 3.f, 2); - // not empty requests - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - mem.getQueue(REGION_SCRATCH)->push_value(nullptr, pFuture1, 3.f, 2); - mem.getQueue(REGION_RO)->push_value(nullptr, pFuture2, 13.f, 2); - // empty request after - mem.getQueue(REGION_SCRATCH)->push_value(nullptr, nullptr, 3.f, 2); - mem.getQueue(REGION_RO)->push_value(nullptr, nullptr, 13.f, 2); - mem.commit(); - - ASSERT_EQ(mem.getRegionBytes(rRegion::REGION_RO), 2 * sizeof(float)); - ASSERT_EQ(mem.getRegionBytes(rRegion::REGION_SCRATCH), 2 * sizeof(float)); -} - -TEST_F(GNAMemoryTest, canCalculateReadWriteSectionSize) { - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - mem.getQueue(REGION_SCRATCH)->push_value(nullptr, pFuture1, 3.f, 2); - mem.getQueue(REGION_RO)->push_value(nullptr, pFuture2, 13.f, 2); - mem.commit(); - - ASSERT_EQ(mem.getRegionBytes(rRegion::REGION_RO), 2 * sizeof(float)); - ASSERT_EQ(mem.getRegionBytes(rRegion::REGION_SCRATCH), 2 * sizeof(float)); -} - -TEST_F(GNAMemoryTest, canCalculateReadWriteSectionSizeWithAlignment) { - GNAMemory memAligned(1, 64); - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - - memAligned.getQueue(REGION_SCRATCH)->push_value(nullptr, pFuture1, 3.f, 2); - memAligned.getQueue(REGION_RO)->push_value(nullptr, pFuture2, 13.f, 2); - memAligned.commit(); - - ASSERT_EQ(memAligned.getRegionBytes(rRegion::REGION_RO), 64); - ASSERT_EQ(memAligned.getRegionBytes(rRegion::REGION_SCRATCH), 64); -} - -TEST_F(GNAMemoryTest, canSetUpReadWriteSectionPtr) { - float* pFuture1 = reinterpret_cast(&pFuture1); - float* pFuture2 = reinterpret_cast(&pFuture2); - float* pFuture3 = reinterpret_cast(&pFuture3); - - mem.getQueue(REGION_RO)->push_value(nullptr, pFuture1, 3.f, 2); - mem.getQueue(REGION_SCRATCH)->push_value(nullptr, pFuture2, 13.f, 3); - mem.getQueue(REGION_RO)->push_value(nullptr, pFuture3, 32.f, 4); - mem.commit(); - - ASSERT_EQ(mem.getRegionBytes(rRegion::REGION_RO), (2 + 4) * sizeof(float)); - ASSERT_EQ(mem.getRegionBytes(rRegion::REGION_SCRATCH), 3 * sizeof(float)); - - ASSERT_NE(&pFuture2[0], &pFuture1[0]); - ASSERT_LT(&pFuture1[0], &pFuture3[0]); - - ASSERT_FLOAT_EQ(pFuture1[0], 3.f); - ASSERT_FLOAT_EQ(pFuture1[1], 3.f); - - ASSERT_FLOAT_EQ(pFuture2[0], 13.f); - ASSERT_FLOAT_EQ(pFuture2[1], 13.f); - ASSERT_FLOAT_EQ(pFuture2[2], 13.f); - - ASSERT_FLOAT_EQ(pFuture3[0], 32.f); - ASSERT_FLOAT_EQ(pFuture3[1], 32.f); - ASSERT_FLOAT_EQ(pFuture3[2], 32.f); - ASSERT_FLOAT_EQ(pFuture3[3], 32.f); -} - -TEST_F(GNAMemoryTest, canUpdateSizeOfPushRequestWithBindRequest) { - float input[] = {1, 2, 3}; - float* pFuture = nullptr; - float* pFuture2 = nullptr; - float* pFuture3 = nullptr; - - size_t len = sizeof(input); - - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFuture, input, len); - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture2, &pFuture, len, len); - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture3, &pFuture2, 2 * len, len); - - mem.commit(); - - ASSERT_EQ(mem.getRegionBytes(REGION_SCRATCH), 4 * len); - ASSERT_NE(pFuture, nullptr); - ASSERT_EQ(pFuture2, pFuture + 3); - ASSERT_EQ(pFuture3, pFuture + 9); - - ASSERT_FLOAT_EQ(pFuture[0], 1); - ASSERT_FLOAT_EQ(pFuture[1], 2); - ASSERT_FLOAT_EQ(pFuture[2], 3); - ASSERT_FLOAT_EQ(pFuture[3], 0); - ASSERT_FLOAT_EQ(pFuture[4], 0); - ASSERT_FLOAT_EQ(pFuture[5], 0); - ASSERT_FLOAT_EQ(pFuture[6], 0); - ASSERT_FLOAT_EQ(pFuture[7], 0); - ASSERT_FLOAT_EQ(pFuture[8], 0); -} - -TEST_F(GNAMemoryTest, canUpdateSizeOfPushRequestWithBindRequestWhenPush) { - float input[] = {1, 2, 3}; - float input2[] = {6, 7, 8}; - - float* pFutureInput2 = nullptr; - float* pFuture = nullptr; - float* pFuture2 = nullptr; - - size_t len = sizeof(input); - - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFuture, input, len); - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture2, &pFuture, len, len); - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFutureInput2, input2, len); - - mem.commit(); - - ASSERT_EQ(mem.getRegionBytes(REGION_SCRATCH), 3 * len); - ASSERT_NE(pFuture, nullptr); - ASSERT_NE(pFutureInput2, nullptr); - ASSERT_EQ(pFuture2, pFuture + 3); - - ASSERT_FLOAT_EQ(pFuture[0], 1); - ASSERT_FLOAT_EQ(pFuture[1], 2); - ASSERT_FLOAT_EQ(pFuture[2], 3); - ASSERT_FLOAT_EQ(pFuture[3], 0); - ASSERT_FLOAT_EQ(pFuture[4], 0); - - ASSERT_FLOAT_EQ(pFutureInput2[0], 6); - ASSERT_FLOAT_EQ(pFutureInput2[1], 7); - ASSERT_FLOAT_EQ(pFutureInput2[2], 8); -} - -TEST_F(GNAMemoryTest, canUpdateSizeOfPushRequestWithBindRequestWhenAlloc) { - float input[] = {1, 2, 3}; - - float* pFutureInput = nullptr; - float* pFuture = nullptr; - float* pFuture2 = nullptr; - - size_t len = sizeof(input); - - mem.getQueue(REGION_SCRATCH)->reserve_ptr(nullptr, &pFuture, len); - mem.getQueue(REGION_AUTO)->bind_ptr(nullptr, &pFuture2, &pFuture, len, len); - mem.getQueue(REGION_SCRATCH)->push_ptr(nullptr, &pFutureInput, input, len); - - mem.commit(); - - ASSERT_EQ(mem.getRegionBytes(REGION_SCRATCH), 3 * len); - ASSERT_NE(pFuture, nullptr); - ASSERT_NE(pFutureInput, nullptr); - ASSERT_EQ(pFuture2, pFuture + 3); - - ASSERT_FLOAT_EQ(pFuture[0], 0); - ASSERT_FLOAT_EQ(pFuture[1], 0); - ASSERT_FLOAT_EQ(pFuture[2], 0); - ASSERT_FLOAT_EQ(pFuture[3], 0); - ASSERT_FLOAT_EQ(pFuture[4], 0); - - ASSERT_FLOAT_EQ(pFutureInput[0], 1); - ASSERT_FLOAT_EQ(pFutureInput[1], 2); - ASSERT_FLOAT_EQ(pFutureInput[2], 3); -} diff --git a/src/plugins/intel_gna/tests/unit/gna_mock_api.hpp b/src/plugins/intel_gna/tests/unit/gna_mock_api.hpp deleted file mode 100644 index da99a1d95c3..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_mock_api.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include -#include - -#include - -class GNACppApi { -public: - GNACppApi(); - ~GNACppApi(); - - MOCK_METHOD3(Gna2MemoryAlloc, Gna2Status(uint32_t sizeRequested, uint32_t* sizeGranted, void** memoryAddress)); - - MOCK_METHOD1(Gna2MemoryFree, Gna2Status(void* memory)); - - MOCK_METHOD1(Gna2DeviceOpen, Gna2Status(uint32_t deviceIndex)); - - MOCK_METHOD1(Gna2DeviceClose, Gna2Status(uint32_t deviceIndex)); - - MOCK_METHOD3(Gna2ModelCreate, Gna2Status(uint32_t deviceIndex, struct Gna2Model const* model, uint32_t* modelId)); - - MOCK_METHOD2(Gna2RequestConfigCreate, Gna2Status(uint32_t modelId, uint32_t* requestConfigId)); - - MOCK_METHOD2(Gna2RequestWait, Gna2Status(uint32_t requestId, uint32_t timeoutMilliseconds)); - - MOCK_METHOD2(Gna2RequestEnqueue, Gna2Status(uint32_t requestConfigId, uint32_t* requestId)); - - MOCK_METHOD2(Gna2DeviceGetVersion, Gna2Status(uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion)); - - MOCK_METHOD4(Gna2InstrumentationConfigCreate, - Gna2Status(uint32_t numberOfInstrumentationPoints, - enum Gna2InstrumentationPoint* selectedInstrumentationPoints, - uint64_t* results, - uint32_t* instrumentationConfigId)); - - MOCK_METHOD2(Gna2InstrumentationConfigAssignToRequestConfig, - Gna2Status(uint32_t instrumentationConfigId, uint32_t requestConfigId)); - - MOCK_METHOD2(Gna2GetLibraryVersion, Gna2Status(char* versionBuffer, uint32_t versionBufferSize)); -}; diff --git a/src/plugins/intel_gna/tests/unit/gna_mock_api_initializer.cpp b/src/plugins/intel_gna/tests/unit/gna_mock_api_initializer.cpp deleted file mode 100644 index 6d9d58b1243..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_mock_api_initializer.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_mock_api_initializer.hpp" - -#include - -#include -#include - -#include "gna_mock_api.hpp" - -void GnaMockApiInitializer::init() { - using ::testing::_; - using ::testing::AtLeast; - using ::testing::InSequence; - using ::testing::Invoke; - using ::testing::Return; - - EXPECT_CALL(_mock_api, Gna2DeviceGetVersion(_, _)) - .WillOnce(Invoke([this](uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion) { - *deviceVersion = this->_gna_device_version; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(_mock_api, Gna2DeviceOpen(_)).WillOnce(Return(Gna2StatusSuccess)); - - EXPECT_CALL(_mock_api, Gna2GetLibraryVersion(_, _)).Times(AtLeast(0)).WillRepeatedly(Return(Gna2StatusSuccess)); - - EXPECT_CALL(_mock_api, Gna2InstrumentationConfigCreate(_, _, _, _)).WillOnce(Return(Gna2StatusSuccess)); - - if (_create_model) { - EXPECT_CALL(_mock_api, Gna2MemoryAlloc(_, _, _)) - .Times(AtLeast(1)) - .WillRepeatedly(Invoke([this](uint32_t sizeRequested, uint32_t* sizeGranted, void** memoryAddress) { - this->_mocked_gna_memory.push_back(std::vector(sizeRequested)); - *sizeGranted = sizeRequested; - *memoryAddress = this->_mocked_gna_memory.back().data(); - return Gna2StatusSuccess; - })); - - EXPECT_CALL(_mock_api, Gna2ModelCreate(_, _, _)) - .WillOnce(Invoke([](uint32_t deviceIndex, struct Gna2Model const* model, uint32_t* modelId) { - *modelId = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(_mock_api, Gna2RequestConfigCreate(_, _)) - .WillOnce(Invoke([](uint32_t modelId, uint32_t* requestConfigId) { - *requestConfigId = 0; - return Gna2StatusSuccess; - })); - - EXPECT_CALL(_mock_api, Gna2InstrumentationConfigAssignToRequestConfig(_, _)) - .Times(AtLeast(1)) - .WillRepeatedly(Return(Gna2StatusSuccess)); - } - InSequence seq; - EXPECT_CALL(_mock_api, Gna2DeviceClose(_)).WillOnce(Return(Gna2StatusSuccess)); - if (_create_model) { - EXPECT_CALL(_mock_api, Gna2MemoryFree(_)).Times(AtLeast(1)).WillRepeatedly(Return(Gna2StatusSuccess)); - } -} -void GnaMockApiInitializer::set_gna_device_version(const Gna2DeviceVersion val) { - _gna_device_version = val; -} -void GnaMockApiInitializer::set_create_model(const bool val) { - _create_model = val; -} diff --git a/src/plugins/intel_gna/tests/unit/gna_mock_api_initializer.hpp b/src/plugins/intel_gna/tests/unit/gna_mock_api_initializer.hpp deleted file mode 100644 index b94c8a3db4c..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_mock_api_initializer.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once -#include - -#include "cstdint" -#include "gna_mock_api.hpp" -#include "vector" - -class GnaMockApiInitializer { - GNACppApi _mock_api; - std::vector> _mocked_gna_memory; - Gna2DeviceVersion _gna_device_version = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - bool _create_model = true; - -public: - void init(); - void set_gna_device_version(const Gna2DeviceVersion val); - void set_create_model(const bool val); -}; diff --git a/src/plugins/intel_gna/tests/unit/gna_model_serial_test.cpp b/src/plugins/intel_gna/tests/unit/gna_model_serial_test.cpp deleted file mode 100644 index e8acac9eb5c..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_model_serial_test.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include - -// to suppress deprecated definition errors -#define IMPLEMENT_INFERENCE_ENGINE_PLUGIN -#include "common/versioning.hpp" -#include "serial/gna_model_serial.hpp" - -using namespace testing; - -class IstreamMock final : public std::streambuf { -public: - MOCK_METHOD3(seekoff, std::streampos(std::streamoff, std::ios_base::seekdir, std::ios_base::openmode)); -}; - -TEST(GNAModelSerialTest, TestErrorOnTellg) { - IstreamMock mock; - EXPECT_CALL(mock, seekoff(_, _, _)).WillRepeatedly(Return(-1)); - std::istream is(&mock); - ASSERT_THROW(GNAModelSerial::ReadHeader(is), InferenceEngine::Exception); -} - -TEST(GNAVersionSerializerTest, Export) { - std::stringstream sBuf; - GNAVersionSerializer verSerializer; - verSerializer.Export(sBuf); - - EXPECT_THAT(sBuf.str(), HasSubstr(ov::intel_gna::common::get_openvino_version_string())); -} - -TEST(GNAVersionSerializerTest, ImportWhenVersionIsPresent) { - std::stringstream sBuf; - GNAVersionSerializer verSerializer; - verSerializer.Export(sBuf); - - EXPECT_THAT(verSerializer.Import(sBuf), HasSubstr(ov::intel_gna::common::get_openvino_version_string())); -} - -TEST(GNAVersionSerializerTest, ImportWhenVersionIsNotPresent) { - std::stringstream sBuf; - GNAVersionSerializer verSerializer; - - EXPECT_EQ(verSerializer.Import(sBuf).length(), 0); -} diff --git a/src/plugins/intel_gna/tests/unit/gna_permute_sequence_test.cpp b/src/plugins/intel_gna/tests/unit/gna_permute_sequence_test.cpp deleted file mode 100644 index 7250200491e..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_permute_sequence_test.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include - -using namespace ov::intel_gna::permute; - -class PermuteSequenceTest : public ::testing::Test {}; - -TEST_F(PermuteSequenceTest, testImpossiblePermute_neg_value) { - ASSERT_ANY_THROW(genPermutations({-1})); -} - -TEST_F(PermuteSequenceTest, testImpossiblePermute_big_value) { - ASSERT_ANY_THROW(genPermutations({1})); -} - -TEST_F(PermuteSequenceTest, testImpossiblePermute_big_value_2) { - ASSERT_ANY_THROW(genPermutations({0, 2})); -} - -TEST_F(PermuteSequenceTest, testImpossiblePermute_same_value) { - ASSERT_ANY_THROW(genPermutations({0, 1, 0})); -} - -TEST_F(PermuteSequenceTest, testIdentity1d) { - ASSERT_EQ(0, genPermutations({0}).size()); -} - -TEST_F(PermuteSequenceTest, testIdentity2d) { - ASSERT_EQ(0, genPermutations({0, 1}).size()); -} - -TEST_F(PermuteSequenceTest, testIdentity3d) { - ASSERT_EQ(0, genPermutations({0, 1, 2}).size()); -} - -TEST_F(PermuteSequenceTest, testIdentity4d) { - ASSERT_EQ(0, genPermutations({0, 1, 2, 3}).size()); -} - -TEST_F(PermuteSequenceTest, test2d) { - ASSERT_EQ(1, genPermutations({1, 0}).size()); - ASSERT_EQ(std::make_pair(0, 1), genPermutations({1, 0}).front()); -} - -TEST_F(PermuteSequenceTest, test3d_1_Permutation) { - ASSERT_EQ(1, genPermutations({1, 0, 2}).size()); - ASSERT_EQ(std::make_pair(0, 1), genPermutations({1, 0, 2})[0]); -} - -TEST_F(PermuteSequenceTest, test3d_1_Permutation_2) { - ASSERT_EQ(1, genPermutations({2, 1, 0}).size()); - ASSERT_EQ(std::make_pair(0, 2), genPermutations({2, 1, 0})[0]); -} - -TEST_F(PermuteSequenceTest, test3d_2_Permutations) { - ASSERT_EQ(2, genPermutations({2, 0, 1}).size()); - ASSERT_EQ(std::make_pair(0, 2), genPermutations({2, 0, 1})[0]); - ASSERT_EQ(std::make_pair(2, 1), genPermutations({2, 0, 1})[1]); -} - -TEST_F(PermuteSequenceTest, test3d_4_Permutation) { - auto permutation = {2, 1, 4, 5, 6, 3, 0, 7}; - ASSERT_EQ(4, genPermutations(permutation).size()); - ASSERT_EQ(std::make_pair(0, 2), genPermutations(permutation)[0]); - ASSERT_EQ(std::make_pair(2, 4), genPermutations(permutation)[1]); - ASSERT_EQ(std::make_pair(4, 6), genPermutations(permutation)[2]); - ASSERT_EQ(std::make_pair(3, 5), genPermutations(permutation)[3]); -} diff --git a/src/plugins/intel_gna/tests/unit/gna_plugin_config_test.cpp b/src/plugins/intel_gna/tests/unit/gna_plugin_config_test.cpp deleted file mode 100644 index 9747beeb38a..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_plugin_config_test.cpp +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gna_plugin_config.hpp" - -#include -#include - -#include -#include - -using namespace InferenceEngine; -using namespace ov::intel_gna; -using namespace ov::intel_gna::target; - -IE_SUPPRESS_DEPRECATED_START -const std::map supportedConfigKeysWithDefaults = { - {GNA_CONFIG_KEY(SCALE_FACTOR), "1.000000"}, - {GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_0"), "1.000000"}, - {GNA_CONFIG_KEY(FIRMWARE_MODEL_IMAGE), ""}, - {GNA_CONFIG_KEY(EXEC_TARGET), ""}, - {GNA_CONFIG_KEY(COMPILE_TARGET), ""}, - {GNA_CONFIG_KEY(DEVICE_MODE), GNAConfigParams::GNA_SW_EXACT}, - {GNA_CONFIG_KEY(COMPACT_MODE), CONFIG_VALUE(YES)}, - {CONFIG_KEY(EXCLUSIVE_ASYNC_REQUESTS), CONFIG_VALUE(NO)}, - {GNA_CONFIG_KEY(PRECISION), Precision(Precision::I16).name()}, - {GNA_CONFIG_KEY(PWL_UNIFORM_DESIGN), CONFIG_VALUE(NO)}, - {GNA_CONFIG_KEY(PWL_MAX_ERROR_PERCENT), "1.000000"}, - {CONFIG_KEY(PERF_COUNT), CONFIG_VALUE(NO)}, - {GNA_CONFIG_KEY(LIB_N_THREADS), "1"}, - {CONFIG_KEY(SINGLE_THREAD), CONFIG_VALUE(YES)}, - {CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_NONE}, - {CONFIG_KEY(PERFORMANCE_HINT), "LATENCY"}, - {CONFIG_KEY(PERFORMANCE_HINT_NUM_REQUESTS), "1"}, - {ov::hint::execution_mode.name(), ov::util::to_string(ov::hint::ExecutionMode::ACCURACY)}}; -IE_SUPPRESS_DEPRECATED_END - -class GNAPluginConfigTest : public ::testing::Test { -protected: - Config config; - void SetAndCompare(const std::string& key, const std::string& val) { - config.UpdateFromMap({{key, val}}); - EXPECT_EQ(config.GetParameter(key).as(), val); - } - void ExpectThrow(const std::string& key, const std::string& val) { - EXPECT_THROW(config.UpdateFromMap({{key, val}}), Exception); - } - void SetAndCheckFlag(const std::string& key, bool& val, bool reverse = false) { - const bool yes = reverse ? false : true; - const bool no = !yes; - SetAndCompare(key, CONFIG_VALUE(YES)); - EXPECT_EQ(val, yes); - SetAndCompare(key, CONFIG_VALUE(NO)); - EXPECT_EQ(val, no); - SetAndCompare(key, CONFIG_VALUE(YES)); - EXPECT_EQ(val, yes); - ExpectThrow(key, "abc"); - ExpectThrow(key, ""); - } -}; - -TEST_F(GNAPluginConfigTest, GnaConfigDefaultConfigIsExpected) { - ASSERT_EQ(config.keyConfigMap, supportedConfigKeysWithDefaults); -} - -TEST_F(GNAPluginConfigTest, GnaConfigScaleFactorTest) { - config.UpdateFromMap({{GNA_CONFIG_KEY(SCALE_FACTOR), std::string("34")}}); - EXPECT_EQ(config.GetParameter(GNA_CONFIG_KEY(SCALE_FACTOR)), std::string("34.000000")); - EXPECT_EQ(config.GetParameter(GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_0")), std::string("34.000000")); - EXPECT_EQ(config.inputScaleFactors.size(), 1); - EXPECT_FLOAT_EQ(config.inputScaleFactors[0], 34.0); - - config.UpdateFromMap({{GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_3"), std::string("15.2")}}); - EXPECT_EQ(config.GetParameter(GNA_CONFIG_KEY(SCALE_FACTOR)), std::string("34.000000")); - EXPECT_EQ(config.GetParameter(GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_0")), std::string("34.000000")); - EXPECT_EQ(config.GetParameter(GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_1")), std::string("1.000000")); - EXPECT_EQ(config.GetParameter(GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_2")), std::string("1.000000")); - EXPECT_EQ(config.GetParameter(GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_3")), std::string("15.200000")); - EXPECT_EQ(config.inputScaleFactors.size(), 4); - EXPECT_FLOAT_EQ(config.inputScaleFactors[0], 34.0); - EXPECT_FLOAT_EQ(config.inputScaleFactors[1], 1.0); - EXPECT_FLOAT_EQ(config.inputScaleFactors[2], 1.0); - EXPECT_FLOAT_EQ(config.inputScaleFactors[3], 15.2); - - config.UpdateFromMap({{GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_99"), std::string("8.43")}}); - EXPECT_EQ(config.GetParameter(GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_99")), std::string("8.430000")); - EXPECT_EQ(config.inputScaleFactors.size(), 100); - EXPECT_FLOAT_EQ(config.inputScaleFactors[99], 8.43); - - ExpectThrow(GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_100"), std::string("8.43")); - ExpectThrow(GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("&1"), std::string("8.43")); - ExpectThrow(GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_"), std::string("8.43")); - ExpectThrow(GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("abs"), std::string("8.43")); - ExpectThrow(GNA_CONFIG_KEY(SCALE_FACTOR), std::string("abc")); - ExpectThrow(GNA_CONFIG_KEY(SCALE_FACTOR), std::string("0")); -} - -TEST_F(GNAPluginConfigTest, GnaConfigDeviceModeTest) { - SetAndCompare(GNA_CONFIG_KEY(DEVICE_MODE), GNAConfigParams::GNA_HW); - EXPECT_EQ(config.pluginGna2AccMode, Gna2AccelerationModeHardware); - EXPECT_EQ(config.swExactMode, false); - SetAndCompare(GNA_CONFIG_KEY(DEVICE_MODE), GNAConfigParams::GNA_HW_WITH_SW_FBACK); - EXPECT_EQ(config.pluginGna2AccMode, Gna2AccelerationModeHardwareWithSoftwareFallback); - EXPECT_EQ(config.swExactMode, false); - IE_SUPPRESS_DEPRECATED_START - SetAndCompare(GNA_CONFIG_KEY(DEVICE_MODE), GNAConfigParams::GNA_SW); - IE_SUPPRESS_DEPRECATED_END - - EXPECT_EQ(config.pluginGna2AccMode, Gna2AccelerationModeSoftware); - EXPECT_EQ(config.swExactMode, false); - SetAndCompare(GNA_CONFIG_KEY(DEVICE_MODE), GNAConfigParams::GNA_SW_EXACT); - - EXPECT_EQ(config.pluginGna2AccMode, Gna2AccelerationModeSoftware); - EXPECT_EQ(config.swExactMode, true); - SetAndCompare(GNA_CONFIG_KEY(DEVICE_MODE), GNAConfigParams::GNA_AUTO); - - EXPECT_EQ(config.pluginGna2AccMode, Gna2AccelerationModeAuto); - EXPECT_EQ(config.swExactMode, false); - - ExpectThrow(GNA_CONFIG_KEY(DEVICE_MODE), ""); - ExpectThrow(GNA_CONFIG_KEY(DEVICE_MODE), "abc"); -} - -TEST_F(GNAPluginConfigTest, GnaConfigCompactMode) { - SetAndCheckFlag(GNA_CONFIG_KEY(COMPACT_MODE), config.gnaFlags.compact_mode); -} - -TEST_F(GNAPluginConfigTest, GnaConfigExclusiveAsyncRequestTest) { - SetAndCheckFlag(CONFIG_KEY(EXCLUSIVE_ASYNC_REQUESTS), config.gnaFlags.exclusive_async_requests); -} - -TEST_F(GNAPluginConfigTest, GnaConfigPrecisionTest) { - SetAndCompare(GNA_CONFIG_KEY(PRECISION), Precision(Precision::I8).name()); - EXPECT_EQ(config.gnaPrecision, Precision::I8); - SetAndCompare(GNA_CONFIG_KEY(PRECISION), Precision(Precision::I16).name()); - EXPECT_EQ(config.gnaPrecision, Precision::I16); - ExpectThrow(GNA_CONFIG_KEY(PRECISION), Precision(Precision::FP32).name()); - ExpectThrow(GNA_CONFIG_KEY(PRECISION), ""); -} - -TEST_F(GNAPluginConfigTest, GnaConfigPwlUniformDesignTest) { - IE_SUPPRESS_DEPRECATED_START - SetAndCheckFlag(GNA_CONFIG_KEY(PWL_UNIFORM_DESIGN), config.gnaFlags.uniformPwlDesign); - IE_SUPPRESS_DEPRECATED_END -} - -TEST_F(GNAPluginConfigTest, GnaConfigPwlMaxErrorPercentTest) { - IE_SUPPRESS_DEPRECATED_START - SetAndCompare(GNA_CONFIG_KEY(PWL_MAX_ERROR_PERCENT), std::string("0.100000")); - EXPECT_FLOAT_EQ(config.gnaFlags.pwlMaxErrorPercent, 0.1f); - SetAndCompare(GNA_CONFIG_KEY(PWL_MAX_ERROR_PERCENT), std::string("1.000000")); - EXPECT_FLOAT_EQ(config.gnaFlags.pwlMaxErrorPercent, 1); - SetAndCompare(GNA_CONFIG_KEY(PWL_MAX_ERROR_PERCENT), std::string("5.000000")); - EXPECT_FLOAT_EQ(config.gnaFlags.pwlMaxErrorPercent, 5); - ExpectThrow(GNA_CONFIG_KEY(PWL_MAX_ERROR_PERCENT), "-1"); - ExpectThrow(GNA_CONFIG_KEY(PWL_MAX_ERROR_PERCENT), "100.1"); - IE_SUPPRESS_DEPRECATED_END -} - -TEST_F(GNAPluginConfigTest, GnaConfigPerfCountTest) { - SetAndCheckFlag(CONFIG_KEY(PERF_COUNT), config.gnaFlags.performance_counting); -} - -IE_SUPPRESS_DEPRECATED_START - -TEST_F(GNAPluginConfigTest, GnaConfigLibNThreadsTest) { - SetAndCompare(GNA_CONFIG_KEY(LIB_N_THREADS), "2"); - EXPECT_EQ(config.gnaFlags.num_requests, 2); - SetAndCompare(GNA_CONFIG_KEY(LIB_N_THREADS), "25"); - EXPECT_EQ(config.gnaFlags.num_requests, 25); - ExpectThrow(GNA_CONFIG_KEY(LIB_N_THREADS), ""); - ExpectThrow(GNA_CONFIG_KEY(LIB_N_THREADS), "0"); - ExpectThrow(GNA_CONFIG_KEY(LIB_N_THREADS), "128"); - ExpectThrow(GNA_CONFIG_KEY(LIB_N_THREADS), "abc"); -} - -TEST_F(GNAPluginConfigTest, GnaConfigSingleThreadTest) { - SetAndCheckFlag(CONFIG_KEY(SINGLE_THREAD), config.gnaFlags.gna_openmp_multithreading, true); -} - -IE_SUPPRESS_DEPRECATED_END - -TEST_F(GNAPluginConfigTest, GnaConfigGnaExecTargetTest) { - SetAndCompare(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_1_0"); - EXPECT_EQ(config.target->get_user_set_execution_target(), DeviceVersion::GNA1_0); - SetAndCompare(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_1_0_E"); - EXPECT_EQ(config.target->get_user_set_execution_target(), DeviceVersion::GNAEmbedded1_0); - - SetAndCompare(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_2_0"); - EXPECT_EQ(config.target->get_user_set_execution_target(), DeviceVersion::GNA2_0); - SetAndCompare(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_3_0"); - EXPECT_EQ(config.target->get_user_set_execution_target(), DeviceVersion::GNA3_0); - SetAndCompare(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_3_1"); - EXPECT_EQ(config.target->get_user_set_execution_target(), DeviceVersion::GNA3_1); - - ExpectThrow(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_3_7"); - - SetAndCompare(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_3_5"); - EXPECT_EQ(config.target->get_user_set_execution_target(), DeviceVersion::GNA3_5); - SetAndCompare(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_3_5_E"); - EXPECT_EQ(config.target->get_user_set_execution_target(), DeviceVersion::GNAEmbedded3_5); - SetAndCompare(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_3_6"); - EXPECT_EQ(config.target->get_user_set_execution_target(), DeviceVersion::GNA3_6); - SetAndCompare(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_4_0"); - EXPECT_EQ(config.target->get_user_set_execution_target(), DeviceVersion::GNA4_0); - - ExpectThrow(GNA_CONFIG_KEY(EXEC_TARGET), "0"); - ExpectThrow(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET_1_5"); - ExpectThrow(GNA_CONFIG_KEY(EXEC_TARGET), "GNA_TARGET"); -} - -TEST_F(GNAPluginConfigTest, GnaConfigGnaCompileTargetTest) { - SetAndCompare(GNA_CONFIG_KEY(COMPILE_TARGET), "GNA_TARGET_2_0"); - EXPECT_EQ(config.target->get_user_set_compile_target(), DeviceVersion::GNA2_0); - SetAndCompare(GNA_CONFIG_KEY(COMPILE_TARGET), "GNA_TARGET_3_0"); - EXPECT_EQ(config.target->get_user_set_compile_target(), DeviceVersion::GNA3_0); - - ExpectThrow(GNA_CONFIG_KEY(COMPILE_TARGET), "GNA_TARGET_3_7"); - - SetAndCompare(GNA_CONFIG_KEY(COMPILE_TARGET), "GNA_TARGET_3_5"); - EXPECT_EQ(config.target->get_user_set_compile_target(), DeviceVersion::GNA3_5); - - ExpectThrow(GNA_CONFIG_KEY(COMPILE_TARGET), "0"); - ExpectThrow(GNA_CONFIG_KEY(COMPILE_TARGET), "GNA_TARGET_1_5"); - ExpectThrow(GNA_CONFIG_KEY(COMPILE_TARGET), "GNA_TARGET"); -} - -TEST_F(GNAPluginConfigTest, GnaConfigLogLevel) { - SetAndCompare(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_WARNING); - EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::WARNING); - SetAndCompare(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_NONE); - EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::NO); - SetAndCompare(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_DEBUG); - EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::DEBUG); - SetAndCompare(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_ERROR); - EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::ERR); - SetAndCompare(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_INFO); - EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::INFO); - SetAndCompare(CONFIG_KEY(LOG_LEVEL), PluginConfigParams::LOG_TRACE); - EXPECT_EQ(config.gnaFlags.log_level, ov::log::Level::TRACE); - EXPECT_THROW(config.UpdateFromMap({{CONFIG_KEY(LOG_LEVEL), "LOG_UNSUPPORTED"}}), ov::Exception); -} - -TEST_F(GNAPluginConfigTest, GnaConfigExecutionModeUpdatesGnaPrecision) { - SetAndCompare(ov::hint::execution_mode.name(), "PERFORMANCE"); - EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I8); - SetAndCompare(ov::hint::execution_mode.name(), "ACCURACY"); - EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I16); -} - -TEST_F(GNAPluginConfigTest, GnaConfigInferencePrecisionUpdatesGnaPrecision) { - SetAndCompare(ov::hint::inference_precision.name(), ov::util::to_string(ov::element::i8)); - EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I8); - SetAndCompare(ov::hint::inference_precision.name(), ov::util::to_string(ov::element::i16)); - EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I16); -} - -TEST_F(GNAPluginConfigTest, GnaConfigInferencePrecisionHasHigherPriorityI16) { - SetAndCompare(GNA_CONFIG_KEY(PRECISION), Precision(Precision::I8).name()); - SetAndCompare(ov::hint::execution_mode.name(), - ov::util::to_string(ov::hint::ExecutionMode::PERFORMANCE)); - SetAndCompare(ov::hint::inference_precision.name(), ov::util::to_string(ov::element::i16)); - EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I16); -} - -TEST_F(GNAPluginConfigTest, GnaConfigInferencePrecisionHasHigherPriorityI8) { - SetAndCompare(GNA_CONFIG_KEY(PRECISION), Precision(Precision::I16).name()); - SetAndCompare(ov::hint::execution_mode.name(), - ov::util::to_string(ov::hint::ExecutionMode::ACCURACY)); - SetAndCompare(ov::hint::inference_precision.name(), ov::util::to_string(ov::element::i8)); - EXPECT_EQ(config.gnaPrecision, InferenceEngine::Precision::I8); -} diff --git a/src/plugins/intel_gna/tests/unit/gna_plugin_load_network_test.cpp b/src/plugins/intel_gna/tests/unit/gna_plugin_load_network_test.cpp deleted file mode 100644 index 435f0bbab3d..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_plugin_load_network_test.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common/gna_target.hpp" -#include "gna_mock_api_initializer.hpp" -#include "gna_plugin.hpp" -#include "ov_models/builders.hpp" - -namespace { -typedef struct { - const std::vector input_size; - const std::vector filter_size; - const std::vector pads_begin; - const std::vector pads_end; -} ConvModel; - -const std::vector models{{{1, 8, 32, 1}, {2, 1}, {1, 0}, {1, 0}}, {{1, 8, 1, 32}, {1, 2}, {0, 1}, {0, 1}}}; - -typedef struct { - ConvModel model; - Gna2DeviceVersion mock_target; - bool load_succesfull; -} ConvModelTestParams; - -std::vector all_tests{{models[0], Gna2DeviceVersion::Gna2DeviceVersion3_0, false}, - {models[1], Gna2DeviceVersion::Gna2DeviceVersion3_0, false}, - {models[0], Gna2DeviceVersion::Gna2DeviceVersion3_5, true}, - {models[1], Gna2DeviceVersion::Gna2DeviceVersion3_5, true}}; - -class GNAPluginLoadNetworkTest : public ::testing::Test, public ::testing::WithParamInterface { - std::shared_ptr function; - -protected: - void Run() { - SetUp(); - const auto test_parameter = GetParam(); - GnaMockApiInitializer mock; - mock.set_gna_device_version(test_parameter.mock_target); - mock.set_create_model(test_parameter.load_succesfull); - mock.init(); - - GNAPlugin gna_plugin{}; - InferenceEngine::CNNNetwork cnn_network{function}; - bool load_succesfull = true; - try { - gna_plugin.LoadNetwork(cnn_network); - } catch (std::exception&) { - load_succesfull = false; - } - EXPECT_EQ(test_parameter.load_succesfull, load_succesfull); - } - - void SetUp() override { - const std::vector c_strides{1, 1}; - const std::vector c_dilations{1, 1}; - constexpr size_t c_num_out_channels = 8; - const auto& model = GetParam().model; - - using ngraph::element::f32; - auto parameter = std::make_shared(f32, ngraph::Shape{model.input_size}); - - auto conv = std::dynamic_pointer_cast( - ngraph::builder::makeConvolution(parameter, - f32, - model.filter_size, - c_strides, - model.pads_begin, - model.pads_end, - c_dilations, - ngraph::op::PadType::EXPLICIT, - c_num_out_channels)); - auto result = std::make_shared(conv); - function = std::make_shared(result, ov::ParameterVector{parameter}, "convolution"); - } -}; - -// This test covers GNAGraphCompiler::ShouldUseOnlyConv2DGnaIface() -// behavior when specific Gna2DeviceVersion is detected by Gna2DeviceGetVersion() -TEST_P(GNAPluginLoadNetworkTest, ReturnsSpecificGna2DeviceVersion) { - Run(); -} - -INSTANTIATE_TEST_SUITE_P(smoke_LoadConvolution1D, GNAPluginLoadNetworkTest, ::testing::ValuesIn(all_tests)); -} // namespace diff --git a/src/plugins/intel_gna/tests/unit/gna_wait_test.cpp b/src/plugins/intel_gna/tests/unit/gna_wait_test.cpp deleted file mode 100644 index 219d5013caa..00000000000 --- a/src/plugins/intel_gna/tests/unit/gna_wait_test.cpp +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include - -// to suppress deprecated definition errors -#define IMPLEMENT_INFERENCE_ENGINE_PLUGIN -#include "gna_infer_request.hpp" -#include "gna_mock_api.hpp" -#include "gna_plugin.hpp" -#include "request/model_wrapper_factory.hpp" -#include "request/subrequest_impl.hpp" -#include "request/worker_factory.hpp" -#include "request/worker_impl.hpp" -#include "request/worker_pool.hpp" - -using namespace ov::intel_gna::request; -using ::testing::_; -using ::testing::Return; - -class GNAWaitTest : public ::testing::Test {}; - -class GNAPluginForGNAWaitTest : public GNAPlugin { -public: - // Prepare underlining object to enable GNAInferRequest::Wait() working - GNAPluginForGNAWaitTest() { - InferenceEngine::TensorDesc td{InferenceEngine::Precision::FP32, {1, 1}, InferenceEngine::Layout::HW}; - auto fakeInfo = std::make_shared(); - auto fakePtr = std::make_shared("fakeName", td); - fakeInfo->setInputData(fakePtr); - outputs_data_map_["fakeOut"] = fakePtr; - inputs_data_map_["fakeIn"] = fakeInfo; - - std::vector> subrequests; - - // In the future code below could replaced with LoadNetwork with at least one layer and QueueInference - std::weak_ptr weakDevice = gnadevice; - - auto enqueue = []() -> uint32_t { - return 1; - }; - - auto wait = [weakDevice](uint32_t requestID, int64_t timeoutMilliseconds) { - if (auto device = weakDevice.lock()) { - return device->waitForRequest(requestID, timeoutMilliseconds); - } - THROW_GNA_EXCEPTION << "device is nullptr"; - }; - - auto model = ModelWrapperFactory::createWithNumberOfEmptyOperations(1); - subrequests.push_back(std::make_shared(std::move(enqueue), std::move(wait))); - _worker = std::make_shared(model, std::move(subrequests)); - - requestWorkerPool_->addModelWorker(_worker); - } - - void EnqueTestRequest() { - _worker->enqueueRequest(); - } - -private: - std::shared_ptr _worker; -}; - -class GNAInferRequestForGNAWaitTest : public GNAInferRequest { -public: - // Prepare underlining object to enable Wait() working - GNAInferRequestForGNAWaitTest(std::shared_ptr plugin) - : GNAInferRequest{plugin, plugin->GetNetworkInputs(), plugin->GetNetworkOutputs()}, - _plugin(plugin) {} - - void EnqueTestRequest() { - _plugin->EnqueTestRequest(); - SetRequestIndex(0); - } - - std::shared_ptr _plugin; -}; - -TEST_F(GNAWaitTest, ReturnsGna2StatusDriverQoSTimeoutExceeded) { - GNACppApi enableMocks; - EXPECT_CALL(enableMocks, Gna2DeviceGetVersion(_, _)) - .WillOnce(testing::Invoke([](uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion) { - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; - })); - EXPECT_CALL(enableMocks, Gna2RequestWait(_, _)).Times(1).WillOnce(Return(Gna2StatusDriverQoSTimeoutExceeded)); - auto plugin = std::make_shared(); - GNAInferRequestForGNAWaitTest inferRequest{plugin}; - inferRequest.EnqueTestRequest(); - ASSERT_EQ(InferenceEngine::INFER_NOT_STARTED, inferRequest.Wait(0)); -} - -TEST_F(GNAWaitTest, ReturnsGna2StatusWarningDeviceBusy) { - GNACppApi enableMocks; - EXPECT_CALL(enableMocks, Gna2DeviceGetVersion(_, _)) - .WillOnce(testing::Invoke([](uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion) { - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; - })); - EXPECT_CALL(enableMocks, Gna2RequestWait(_, _)).Times(1).WillOnce(Return(Gna2StatusWarningDeviceBusy)); - auto plugin = std::make_shared(); - GNAInferRequestForGNAWaitTest inferRequest{plugin}; - inferRequest.EnqueTestRequest(); - ASSERT_EQ(InferenceEngine::RESULT_NOT_READY, inferRequest.Wait(0)); -} - -TEST_F(GNAWaitTest, ReturnsGna2StatusDeviceParameterOutOfRange) { - GNACppApi enableMocks; - EXPECT_CALL(enableMocks, Gna2DeviceGetVersion(_, _)) - .WillOnce(testing::Invoke([](uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion) { - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; - })); - EXPECT_CALL(enableMocks, Gna2RequestWait(_, _)).Times(1).WillOnce(Return(Gna2StatusDeviceParameterOutOfRange)); - auto plugin = std::make_shared(); - GNAInferRequestForGNAWaitTest inferRequest{plugin}; - inferRequest.EnqueTestRequest(); - ASSERT_THROW(inferRequest.Wait(0), std::exception); -} - -TEST_F(GNAWaitTest, ReturnsGna2StatusDeviceParameterOutOfRange_Extra_Sync) { - GNACppApi enableMocks; - EXPECT_CALL(enableMocks, Gna2DeviceGetVersion(_, _)) - .WillOnce(testing::Invoke([](uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion) { - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; - })); - EXPECT_CALL(enableMocks, Gna2RequestWait(_, _)).Times(1).WillOnce(Return(Gna2StatusDeviceParameterOutOfRange)); - auto plugin = std::make_shared(); - GNAInferRequestForGNAWaitTest inferRequest{plugin}; - inferRequest.EnqueTestRequest(); - ASSERT_THROW(inferRequest.Wait(0), std::exception); - EXPECT_CALL(enableMocks, Gna2RequestWait(_, _)).Times(0); - ASSERT_EQ(InferenceEngine::INFER_NOT_STARTED, inferRequest.Wait(0)); -} - -TEST_F(GNAWaitTest, ReturnsGna2StatusDeviceParameterOutOfRange_Another_Use) { - GNACppApi enableMocks; - EXPECT_CALL(enableMocks, Gna2DeviceGetVersion(_, _)) - .WillOnce(testing::Invoke([](uint32_t deviceIndex, enum Gna2DeviceVersion* deviceVersion) { - *deviceVersion = Gna2DeviceVersion::Gna2DeviceVersionSoftwareEmulation; - return Gna2StatusSuccess; - })); - EXPECT_CALL(enableMocks, Gna2RequestWait(_, _)).Times(1).WillOnce(Return(Gna2StatusDeviceParameterOutOfRange)); - auto plugin = std::make_shared(); - GNAInferRequestForGNAWaitTest inferRequest{plugin}; - inferRequest.EnqueTestRequest(); - ASSERT_THROW(inferRequest.Wait(0), std::exception); - inferRequest.EnqueTestRequest(); - EXPECT_CALL(enableMocks, Gna2RequestWait(_, _)).Times(1).WillOnce(Return(Gna2StatusSuccess)); - ASSERT_EQ(InferenceEngine::OK, inferRequest.Wait(0)); -} diff --git a/src/plugins/intel_gna/tests/unit/log/logger.cpp b/src/plugins/intel_gna/tests/unit/log/logger.cpp deleted file mode 100644 index c45a160eb3c..00000000000 --- a/src/plugins/intel_gna/tests/unit/log/logger.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "log/log.hpp" -#include "openvino/runtime/properties.hpp" - -using namespace ov::intel_gna; - -namespace test { - -using GnaLogTestParams = std::tuple; - -class GnaLogTest : public ::testing::TestWithParam { -protected: - void SetUp() override {} - -public: - static std::string GetTestCaseName(const testing::TestParamInfo& obj) { - ov::log::Level log_level, message_level; - std::tie(log_level, message_level) = obj.param; - std::ostringstream result; - result << "LogLevel=" << log_level; - result << "_MsgLevel=" << message_level; - return result.str(); - } -}; - -TEST_P(GnaLogTest, LogLevel) { - std::string test_message = "Test message"; - std::stringstream expected_message; - std::stringstream buffer; - std::streambuf* sbuf = std::cout.rdbuf(); - std::streambuf* ebuf = std::cerr.rdbuf(); - std::cout.rdbuf(buffer.rdbuf()); - std::cerr.rdbuf(buffer.rdbuf()); - - ov::log::Level log_level, message_level; - std::tie(log_level, message_level) = GetParam(); - - const auto prev_log_level = GnaLog::get_log_level(); - GnaLog::set_log_level(log_level); - - switch (message_level) { - case ov::log::Level::ERR: - log::error() << test_message << std::endl; - break; - - case ov::log::Level::WARNING: - log::warning() << test_message << std::endl; - break; - - case ov::log::Level::INFO: - log::info() << test_message << std::endl; - break; - - case ov::log::Level::DEBUG: - log::debug() << test_message << std::endl; - break; - - case ov::log::Level::TRACE: - log::trace() << test_message << std::endl; - break; - - default: - break; - } - - expected_message << "[" << message_level << "] " << test_message << std::endl; - if (message_level <= log_level) { - EXPECT_TRUE(buffer.str() == expected_message.str()); - } else { - EXPECT_TRUE(buffer.str().empty()); - } - - std::cout.rdbuf(sbuf); - std::cerr.rdbuf(ebuf); - GnaLog::set_log_level(prev_log_level); -} - -INSTANTIATE_TEST_SUITE_P(smoke_GnaLogTest, - GnaLogTest, - ::testing::Combine(::testing::ValuesIn({ov::log::Level::NO, - ov::log::Level::ERR, - ov::log::Level::WARNING, - ov::log::Level::INFO, - ov::log::Level::DEBUG, - ov::log::Level::TRACE}), - ::testing::ValuesIn({ov::log::Level::ERR, - ov::log::Level::WARNING, - ov::log::Level::INFO, - ov::log::Level::DEBUG, - ov::log::Level::TRACE})), - GnaLogTest::GetTestCaseName); -} // namespace test \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/unit/ops/util_test.cpp b/src/plugins/intel_gna/tests/unit/ops/util_test.cpp deleted file mode 100644 index 30a34995bd4..00000000000 --- a/src/plugins/intel_gna/tests/unit/ops/util_test.cpp +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include - -#include "common/graph_utils.hpp" -#include "openvino/opsets/opset9.hpp" - -using namespace ov::intel_gna::graph_utils; -using namespace ov::opset9; - -namespace test { - -using GnaOpsUtilTestParams = std::tuple, bool>; - -class GnaOpsUtilTest : public ::testing::TestWithParam { -public: - static std::string get_test_name(const testing::TestParamInfo& obj) { - std::shared_ptr node; // node to be converted - bool result; // expected result - std::tie(node, result) = obj.param; - - std::ostringstream test_name; - test_name << "Node=" << node->get_type_info().name << "_"; - test_name << "Op=" << node->get_type_info().get_version() << "_"; - test_name << "ExpectedResult=" << result; - - return test_name.str(); - } -}; - -class GnaOpsUtilIsPoolingTest : public GnaOpsUtilTest { -public: - void validate() { - std::shared_ptr node; // node to be converted - bool result; // expected result - std::tie(node, result) = GetParam(); - ASSERT_TRUE(result == is_pooling(node)); - } -}; - -class GnaOpsUtilIsEltwiseMulTest : public GnaOpsUtilTest { -public: - void validate() { - std::shared_ptr node; // node to be converted - bool result; // expected result - std::tie(node, result) = GetParam(); - ASSERT_TRUE(result == is_eltwise_mul(node)); - } -}; - -class GnaOpsUtilIsEltwiseAddTest : public GnaOpsUtilTest { -public: - void validate() { - std::shared_ptr node; // node to be converted - bool result; // expected result - std::tie(node, result) = GetParam(); - ASSERT_TRUE(result == is_eltwise_add(node)); - } -}; - -TEST_P(GnaOpsUtilIsPoolingTest, isPoolingTest) { - validate(); -} - -TEST_P(GnaOpsUtilIsEltwiseMulTest, isEltwiseMulTest) { - validate(); -} - -TEST_P(GnaOpsUtilIsEltwiseAddTest, isEltwiseAddTest) { - validate(); -} - -ov::NodeVector pooling_nodes_false = {std::make_shared(), - std::make_shared(), - std::make_shared(), - std::make_shared()}; - -ov::NodeVector pooling_nodes_true = {std::make_shared()}; - -ov::NodeVector eltwise_mul_nodes_false = { - std::make_shared(), - std::make_shared(std::make_shared(), - std::make_shared(), - ELTWISE_TYPE::Sum), -}; - -ov::NodeVector eltwise_mul_nodes_true = {std::make_shared(std::make_shared(), - std::make_shared(), - ELTWISE_TYPE::Prod)}; - -ov::NodeVector eltwise_add_nodes_false = {std::make_shared(), - std::make_shared(std::make_shared(), - std::make_shared(), - ELTWISE_TYPE::Prod)}; - -ov::NodeVector eltwise_add_nodes_true = {std::make_shared(std::make_shared(), - std::make_shared(), - ELTWISE_TYPE::Sum)}; - -INSTANTIATE_TEST_SUITE_P(smoke_ops_util_is_pooling, - GnaOpsUtilIsPoolingTest, - ::testing::Combine(::testing::ValuesIn(pooling_nodes_true), ::testing::Values(true)), - GnaOpsUtilIsPoolingTest::get_test_name); - -INSTANTIATE_TEST_SUITE_P(smoke_ops_util_not_pooling, - GnaOpsUtilIsPoolingTest, - ::testing::Combine(::testing::ValuesIn(pooling_nodes_false), ::testing::Values(false)), - GnaOpsUtilIsPoolingTest::get_test_name); - -INSTANTIATE_TEST_SUITE_P(smoke_ops_util_is_eltwise_mul, - GnaOpsUtilIsEltwiseMulTest, - ::testing::Combine(::testing::ValuesIn(eltwise_mul_nodes_true), ::testing::Values(true)), - GnaOpsUtilIsEltwiseMulTest::get_test_name); - -INSTANTIATE_TEST_SUITE_P(smoke_ops_util_not_elwise_mul, - GnaOpsUtilIsEltwiseMulTest, - ::testing::Combine(::testing::ValuesIn(eltwise_mul_nodes_false), ::testing::Values(false)), - GnaOpsUtilIsEltwiseMulTest::get_test_name); - -INSTANTIATE_TEST_SUITE_P(smoke_ops_util_is_eltwise_add, - GnaOpsUtilIsEltwiseAddTest, - ::testing::Combine(::testing::ValuesIn(eltwise_add_nodes_true), ::testing::Values(true)), - GnaOpsUtilIsEltwiseAddTest::get_test_name); - -INSTANTIATE_TEST_SUITE_P(smoke_ops_util_not_eltwise_add, - GnaOpsUtilIsEltwiseAddTest, - ::testing::Combine(::testing::ValuesIn(eltwise_add_nodes_false), ::testing::Values(false)), - GnaOpsUtilIsEltwiseAddTest::get_test_name); - -} // namespace test \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/unit/pre_post_processing/converter_factory_test.cpp b/src/plugins/intel_gna/tests/unit/pre_post_processing/converter_factory_test.cpp deleted file mode 100644 index 5d89391e109..00000000000 --- a/src/plugins/intel_gna/tests/unit/pre_post_processing/converter_factory_test.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "pre_post_process/converter_factory.hpp" - -#include -#include - -using namespace ov::intel_gna::pre_post_processing; - -#ifdef HAVE_AVX2 -TEST(ConverterFactoryTests, TestAvx2Supported) { - // if compiled with AVX2 support, must return valid converter when AVX2 available at runtime - if (InferenceEngine::with_cpu_x86_avx2()) { - EXPECT_NE(ConverterFactory::create_converter(), nullptr); - } else { - EXPECT_EQ(ConverterFactory::create_converter(), nullptr); - } -} -#else -TEST(ConverterFactoryTests, TestConverterFactoryReturnsNullptr) { - // if compiled without AVX2 support, ConverterFactory must return nullptr - EXPECT_EQ(ConverterFactory::create_converter(), nullptr); -} -#endif // HAVE_AVX2 \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/unit/pre_post_processing/gna_input_preproc_test.cpp b/src/plugins/intel_gna/tests/unit/pre_post_processing/gna_input_preproc_test.cpp deleted file mode 100644 index 7da896f0ac0..00000000000 --- a/src/plugins/intel_gna/tests/unit/pre_post_processing/gna_input_preproc_test.cpp +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include - -#include "common_test_utils/data_utils.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "pre_post_process/converter_factory.hpp" -#include "pre_post_process/input_output_data_handler.hpp" - -using namespace InferenceEngine; -using namespace pre_post_processing; - -namespace testing { - -typedef std::tuple - GNAInputPrecisionParams; - -template -class GNAInputPrecisionTest : public ::testing::TestWithParam { -public: - void SetUp() override { - uint32_t input_range; - std::tie(prc, shape, orientation, sf, is_gna_device, is_low_precision, test_avx2, input_range) = GetParam(); - input_vals.resize(ov::shape_size(shape)); - ov::test::utils::fill_data_random(&input_vals[0], ov::shape_size(shape), input_range); - - std::transform(begin(input_vals), end(input_vals), std::back_inserter(refer_vals), [this](U i) { - return round(i * sf); - }); - - if (test_avx2) { - auto converter = ConverterFactory::create_converter(); - if (converter == nullptr) { - GTEST_SKIP() << "Tests compiled with with AVX2 support, but AVX2 unavailable at runtime"; - } - m_input_output_handler = std::make_shared(converter); - } else { - m_input_output_handler = std::make_shared(nullptr); - } - } - - T round(float src) { - float rounding_value = is_gna_device ? ((src > 0) ? 0.5f : -0.5f) : 0.0f; - float value = src + rounding_value; - if (value > std::numeric_limits::max()) { - return std::numeric_limits::max(); - } else if (value < std::numeric_limits::min()) { - return std::numeric_limits::min(); - } - return static_cast(value); - } - - void compare() { - auto total_size = ov::shape_size(shape); - std::vector plugin_inputs(total_size); - m_input_output_handler->import_frames(&(plugin_inputs.front()), - &(input_vals.front()), - prc, - sf, - orientation, - shape[0], - shape[0], - shape[1], - shape[1], - is_low_precision, - is_gna_device); - if (orientation == kDnnInterleavedOrientation) { - for (int i = 0; i < shape[0]; ++i) { - for (int j = 0; j < shape[1]; j++) { - float difference = std::abs(plugin_inputs[j * shape[0] + i] - refer_vals[i * shape[1] + j]); - EXPECT_LT(difference, std::numeric_limits::epsilon()); - } - } - } else { - for (int i = 0; i < total_size; ++i) { - float difference = std::abs(plugin_inputs[i] - refer_vals[i]); - EXPECT_LT(difference, std::numeric_limits::epsilon()); - } - } - } - -protected: - std::shared_ptr m_input_output_handler; - Precision prc; - SizeVector shape; - intel_dnn_orientation_t orientation; - std::vector refer_vals; - std::vector input_vals; - bool is_gna_device = false; - bool is_low_precision = false; - bool test_avx2 = false; - float sf = 1.0f; -}; - -const std::vector input_shapes{ - {1, 20}, - {4, 8}, - {31, 1}, - {9, 3}, -}; - -const std::vector orientations{kDnnInterleavedOrientation, kDnnNonInterleavedOrientation}; - -using GNAInputPrecisionTestFp32toI16 = GNAInputPrecisionTest; - -TEST_P(GNAInputPrecisionTestFp32toI16, GNAInputPrecisionTestI16) { - compare(); -} - -INSTANTIATE_TEST_SUITE_P( - GNAInputPrecisionTestSuite, - GNAInputPrecisionTestFp32toI16, - ::testing::Combine(::testing::Values(Precision::FP32), // input precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(std::vector{1.0f, 8.0f, 0.125f}), // scale factors - ::testing::Values(true), // gna device - ::testing::Values(false), // use low precision - ::testing::Values(false), // use AVX2 version - ::testing::Values(16))); // input range -using GNAInputPrecisionTestFp32toI8 = GNAInputPrecisionTest; - -TEST_P(GNAInputPrecisionTestFp32toI8, GNAInputPrecisionTestI8) { - compare(); -} - -INSTANTIATE_TEST_SUITE_P( - GNAInputPrecisionTestSuite, - GNAInputPrecisionTestFp32toI8, - ::testing::Combine(::testing::Values(Precision::FP32), // input precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(std::vector{1.0f, 4.0f, 0.25f}), // scale factors - ::testing::Values(true), // gna device - ::testing::Values(true), // use low precision - ::testing::Values(false), // use AVX2 version - ::testing::Values(12))); // input range - -using GNAInputPrecisionTestFp32toFp32 = GNAInputPrecisionTest; - -TEST_P(GNAInputPrecisionTestFp32toFp32, GNAInputPrecisionTestFp32) { - compare(); -} - -INSTANTIATE_TEST_SUITE_P(GNAInputPrecisionTestSuite, - GNAInputPrecisionTestFp32toFp32, - ::testing::Combine(::testing::Values(Precision::FP32), // input precision - ::testing::ValuesIn(input_shapes), // input shape - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(std::vector{1.0f}), // scale factors - ::testing::Values(false), // gna device - ::testing::Values(false), // use low precision - ::testing::Values(false), // use AVX2 version - ::testing::Values(1200))); // input range - -using GNAInputPrecisionTestI16toI16 = GNAInputPrecisionTest; - -TEST_P(GNAInputPrecisionTestI16toI16, GNAInputPrecisionTestI16) { - compare(); -} - -INSTANTIATE_TEST_SUITE_P(GNAInputPrecisionTestSuite, - GNAInputPrecisionTestI16toI16, - ::testing::Combine(::testing::Values(Precision::I16), // input precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(std::vector{1.0f}), // scale factors - ::testing::Values(true), // gna device - ::testing::Values(false), // use low precision - ::testing::Values(false), // use AVX2 version - ::testing::Values(16))); // input range - -using GNAInputPrecisionTestI16toI8 = GNAInputPrecisionTest; - -TEST_P(GNAInputPrecisionTestI16toI8, GNAInputPrecisionTestI8) { - compare(); -} - -INSTANTIATE_TEST_SUITE_P( - GNAInputPrecisionTestSuite, - GNAInputPrecisionTestI16toI8, - ::testing::Combine(::testing::Values(Precision::I16), // input precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(std::vector{1.0f, 10.0f, 20.0f}), // scale factors - ::testing::Values(true), // gna device - ::testing::Values(true), // use low precision - ::testing::Values(false), // use AVX2 version - ::testing::Values(12))); // input range - -using GNAInputPrecisionTestU8toI16 = GNAInputPrecisionTest; - -TEST_P(GNAInputPrecisionTestU8toI16, GNAInputPrecisionTestI16) { - compare(); -} - -INSTANTIATE_TEST_SUITE_P(GNAInputPrecisionTestSuite, - GNAInputPrecisionTestU8toI16, - ::testing::Combine(::testing::Values(Precision::U8), // input precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(std::vector{1.0f, 8.0f}), // scale factors - ::testing::Values(true), // gna device - ::testing::Values(false), // use low precision - ::testing::Values(false), // use AVX2 version - ::testing::Values(16))); // input range - -using GNAInputPrecisionTestU8toI8 = GNAInputPrecisionTest; - -TEST_P(GNAInputPrecisionTestU8toI8, GNAInputPrecisionTestI8) { - compare(); -} - -INSTANTIATE_TEST_SUITE_P(GNAInputPrecisionTestSuite, - GNAInputPrecisionTestU8toI8, - ::testing::Combine(::testing::Values(Precision::U8), // input precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(std::vector{1.0f}), // scale factors - ::testing::Values(true), // gna device - ::testing::Values(true), // use low precision - ::testing::Values(false), // use AVX2 version - ::testing::Values(12))); // input range - -#ifdef HAVE_AVX2 -// Below tests execute optimized functions, if AVX2 is available - -using GNAInputPrecisionTestFp32toI16Avx = GNAInputPrecisionTest; - -TEST_P(GNAInputPrecisionTestFp32toI16Avx, GNAInputPrecisionTestI16Avx) { - compare(); -} - -INSTANTIATE_TEST_SUITE_P( - GNAInputPrecisionTestSuite, - GNAInputPrecisionTestFp32toI16Avx, - ::testing::Combine(::testing::Values(Precision::FP32), // input precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(std::vector{1.0f, 8.0f, 0.125f}), // scale factors - ::testing::Values(true), // gna device - ::testing::Values(false), // use low precision - ::testing::Values(true), // use AVX2 version - ::testing::Values(16))); // input range - -using GNAInputPrecisionTestFp32toI8Avx = GNAInputPrecisionTest; - -TEST_P(GNAInputPrecisionTestFp32toI8Avx, GNAInputPrecisionTestI8Avx) { - compare(); -} - -INSTANTIATE_TEST_SUITE_P( - GNAInputPrecisionTestSuite, - GNAInputPrecisionTestFp32toI8Avx, - ::testing::Combine(::testing::Values(Precision::FP32), // input precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(std::vector{1.0f, 4.0f, 0.25f}), // scale factors - ::testing::Values(true), // gna device - ::testing::Values(true), // use low precision - ::testing::Values(true), // use AVX2 version - ::testing::Values(12))); // input range -#endif // HAVE_AVX2 -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/pre_post_processing/gna_output_postproc_test.cpp b/src/plugins/intel_gna/tests/unit/pre_post_processing/gna_output_postproc_test.cpp deleted file mode 100644 index e3169c2a342..00000000000 --- a/src/plugins/intel_gna/tests/unit/pre_post_processing/gna_output_postproc_test.cpp +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include - -#include "common_test_utils/data_utils.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "pre_post_process/converter_factory.hpp" -#include "pre_post_process/input_output_data_handler.hpp" - -using namespace InferenceEngine; -using namespace pre_post_processing; - -namespace testing { - -typedef std::tuple - GNAOutputPrecisionParams; - -template -class GNAOutputPrecisionTest : public ::testing::TestWithParam { -public: - void SetUp() override { - uint32_t input_range; - std::tie(precisionIn, precisionOut, shape, orientation, sf, test_avx2, input_range) = GetParam(); - inputValues.resize(ov::shape_size(shape)); - ov::test::utils::fill_data_random(&inputValues[0], ov::shape_size(shape), input_range); - - std::transform(begin(inputValues), end(inputValues), std::back_inserter(referenceValues), [this](U i) { - return static_cast(i / sf); - }); - - if (test_avx2) { - auto converter = ConverterFactory::create_converter(); - if (converter == nullptr) { - GTEST_SKIP() << "Tests compiled with with AVX2 support, but AVX2 unavailable at runtime"; - } - m_input_output_handler = std::make_shared(converter); - } else { - m_input_output_handler = std::make_shared(nullptr); - } - } - - void compare() { - auto total_size = ov::shape_size(shape); - std::vector pluginOutputs(total_size); - m_input_output_handler->export_scores(&(pluginOutputs.front()), - &(inputValues.front()), - orientation, - shape[0], - shape[0], - shape[1], - shape[1], - shape[1], - precisionIn, - precisionOut, - sf); - if (orientation == kDnnInterleavedOrientation) { - for (int i = 0; i < shape[0]; ++i) { - for (int j = 0; j < shape[1]; j++) { - float difference = std::abs(pluginOutputs[i * shape[1] + j] - referenceValues[j * shape[0] + i]); - EXPECT_LT(difference, std::numeric_limits::epsilon()); - } - } - } else { - for (int i = 0; i < total_size; ++i) { - float difference = std::abs(pluginOutputs[i] - referenceValues[i]); - EXPECT_LT(difference, std::numeric_limits::epsilon()); - } - } - } - -protected: - std::shared_ptr m_input_output_handler; - Precision precisionIn; - Precision precisionOut; - SizeVector shape; - intel_dnn_orientation_t orientation; - std::vector referenceValues; - std::vector inputValues; - bool test_avx2 = false; - float sf = 1.0f; -}; - -const std::vector input_shapes{ - {1, 20}, - {4, 8}, - {31, 1}, - {9, 3}, -}; - -const std::vector orientations{kDnnInterleavedOrientation, kDnnNonInterleavedOrientation}; - -const std::vector scale_factors{1.0f, 0.125f, 8.0f}; - -using GNAOutputPrecisionTestI8ToFp32 = GNAOutputPrecisionTest; -TEST_P(GNAOutputPrecisionTestI8ToFp32, GNAOutputPrecisionTestFp32) { - compare(); -} -INSTANTIATE_TEST_SUITE_P(GNAOutputPrecisionTestSuite, - GNAOutputPrecisionTestI8ToFp32, - ::testing::Combine(::testing::Values(Precision::I8), // input precision - ::testing::Values(Precision::FP32), // output precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(scale_factors), // scale factors - ::testing::Values(false), // use AVX2 version - ::testing::Values(16))); // input range - -using GNAOutputPrecisionTestI16ToFp32 = GNAOutputPrecisionTest; -TEST_P(GNAOutputPrecisionTestI16ToFp32, GNAOutputPrecisionTestFp32) { - compare(); -} -INSTANTIATE_TEST_SUITE_P(GNAOutputPrecisionTestSuite, - GNAOutputPrecisionTestI16ToFp32, - ::testing::Combine(::testing::Values(Precision::I16), // input precision - ::testing::Values(Precision::FP32), // output precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(scale_factors), // scale factors - ::testing::Values(false), // use AVX2 version - ::testing::Values(4000))); // input range - -using GNAOutputPrecisionTestI32ToFp32 = GNAOutputPrecisionTest; -TEST_P(GNAOutputPrecisionTestI32ToFp32, GNAOutputPrecisionTestFp32) { - compare(); -} -INSTANTIATE_TEST_SUITE_P(GNAOutputPrecisionTestSuite, - GNAOutputPrecisionTestI32ToFp32, - ::testing::Combine(::testing::Values(Precision::I32), // input precision - ::testing::Values(Precision::FP32), // output precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(scale_factors), // scale factors - ::testing::Values(false), // use AVX2 version - ::testing::Values(4000))); // input range - -using GNAOutputPrecisionTestI8ToI32 = GNAOutputPrecisionTest; -TEST_P(GNAOutputPrecisionTestI8ToI32, GNAOutputPrecisionTestI32) { - compare(); -} -INSTANTIATE_TEST_SUITE_P(GNAOutputPrecisionTestSuite, - GNAOutputPrecisionTestI8ToI32, - ::testing::Combine(::testing::Values(Precision::I8), // input precision - ::testing::Values(Precision::I32), // output precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(scale_factors), // scale factors - ::testing::Values(false), // use AVX2 version - ::testing::Values(16))); // input range - -using GNAOutputPrecisionTestI16ToI32 = GNAOutputPrecisionTest; -TEST_P(GNAOutputPrecisionTestI16ToI32, GNAOutputPrecisionTestI32) { - compare(); -} -INSTANTIATE_TEST_SUITE_P(GNAOutputPrecisionTestSuite, - GNAOutputPrecisionTestI16ToI32, - ::testing::Combine(::testing::Values(Precision::I16), // input precision - ::testing::Values(Precision::I32), // output precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(scale_factors), // scale factors - ::testing::Values(false), // use AVX2 version - ::testing::Values(4000))); // input range - -using GNAOutputPrecisionTestI32ToI32 = GNAOutputPrecisionTest; -TEST_P(GNAOutputPrecisionTestI32ToI32, GNAOutputPrecisionTestI32) { - compare(); -} -INSTANTIATE_TEST_SUITE_P(GNAOutputPrecisionTestSuite, - GNAOutputPrecisionTestI32ToI32, - ::testing::Combine(::testing::Values(Precision::I32), // input precision - ::testing::Values(Precision::I32), // output precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(std::vector{1.0f}), // scale factors - ::testing::Values(false), // use AVX2 version - ::testing::Values(4000))); // input range - -#ifdef HAVE_AVX2 -// Below tests execute optimized functions, if AVX2 is available - -using GNAOutputPrecisionTestI8ToFp32Avx = GNAOutputPrecisionTest; -TEST_P(GNAOutputPrecisionTestI8ToFp32Avx, GNAOutputPrecisionTestFp32Avx) { - compare(); -} -INSTANTIATE_TEST_SUITE_P(GNAOutputPrecisionTestSuite, - GNAOutputPrecisionTestI8ToFp32Avx, - ::testing::Combine(::testing::Values(Precision::I8), // input precision - ::testing::Values(Precision::FP32), // output precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(scale_factors), // scale factors - ::testing::Values(true), // use AVX2 version - ::testing::Values(16))); // input range - -using GNAOutputPrecisionTestI16ToFp32Avx = GNAOutputPrecisionTest; -TEST_P(GNAOutputPrecisionTestI16ToFp32Avx, GNAOutputPrecisionTestFp32Avx) { - compare(); -} -INSTANTIATE_TEST_SUITE_P(GNAOutputPrecisionTestSuite, - GNAOutputPrecisionTestI16ToFp32Avx, - ::testing::Combine(::testing::Values(Precision::I16), // input precision - ::testing::Values(Precision::FP32), // output precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(scale_factors), // scale factors - ::testing::Values(true), // use AVX2 version - ::testing::Values(4000))); // input range - -using GNAOutputPrecisionTestI32ToFp32Avx = GNAOutputPrecisionTest; -TEST_P(GNAOutputPrecisionTestI32ToFp32Avx, GNAOutputPrecisionTestFp32Avx) { - compare(); -} -INSTANTIATE_TEST_SUITE_P(GNAOutputPrecisionTestSuite, - GNAOutputPrecisionTestI32ToFp32Avx, - ::testing::Combine(::testing::Values(Precision::I32), // input precision - ::testing::Values(Precision::FP32), // output precision - ::testing::ValuesIn(input_shapes), // input shapes - ::testing::ValuesIn(orientations), // orientations - ::testing::ValuesIn(scale_factors), // scale factors - ::testing::Values(true), // use AVX2 version - ::testing::Values(4000))); // input range - -#endif // HAVE_AVX2 -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/request/gna_request_worker_factory_test.cpp b/src/plugins/intel_gna/tests/unit/request/gna_request_worker_factory_test.cpp deleted file mode 100644 index 53f2e08a3c3..00000000000 --- a/src/plugins/intel_gna/tests/unit/request/gna_request_worker_factory_test.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "mock_gna_device.hpp" -#include "mock_subrequest.hpp" -#include "request/model_wrapper_factory.hpp" -#include "request/worker_factory.hpp" - -using namespace ov::intel_gna; -using namespace request; -using namespace testing; - -class GNA_Request_WorkerFactoryTest : public ::testing::Test {}; - -TEST_F(GNA_Request_WorkerFactoryTest, createWorker_without_splitting) { - const Gna2AccelerationMode accMode = Gna2AccelerationModeAuto; - auto deviceMock = std::make_shared(); - - std::vector> subrequests; - // expect throw when model nullptr - EXPECT_THROW(subrequests = WorkerFactory::createModelSubrequests(nullptr, deviceMock, accMode), std::exception); - - // kMaxLayersBigger value bigger than model layers number - const constexpr uint32_t kObjectLayers = 2; - const constexpr uint32_t kMaxLayersBigger = kObjectLayers + 1; - const constexpr uint32_t numberOfPieces = 1; - auto modelWrapper = ModelWrapperFactory::createWithNumberOfEmptyOperations(kObjectLayers); - - // expect throw when model nullptr - EXPECT_THROW(subrequests = WorkerFactory::createModelSubrequests(modelWrapper, nullptr, accMode), std::exception); - - EXPECT_CALL(*deviceMock.get(), maxLayersCount()).Times(1).WillOnce(Return(kMaxLayersBigger)); - EXPECT_CALL(*deviceMock.get(), createModel(_)).Times(numberOfPieces).WillOnce(Return(0)); - EXPECT_CALL(*deviceMock.get(), createRequestConfig(_)).Times(numberOfPieces).WillOnce(Return(0)); - - EXPECT_NO_THROW((subrequests = WorkerFactory::createModelSubrequests(modelWrapper, deviceMock, accMode))); - EXPECT_EQ(subrequests.size(), numberOfPieces); - subrequests.clear(); - - // max layers count value equal to layers number - EXPECT_CALL(*deviceMock.get(), maxLayersCount()).Times(1).WillOnce(Return(kObjectLayers)); - EXPECT_CALL(*deviceMock.get(), createModel(_)).Times(numberOfPieces).WillOnce(Return(0)); - EXPECT_CALL(*deviceMock.get(), createRequestConfig(_)).Times(numberOfPieces).WillOnce(Return(0)); - - EXPECT_NO_THROW(subrequests = WorkerFactory::createModelSubrequests(modelWrapper, deviceMock, accMode)); - EXPECT_EQ(subrequests.size(), numberOfPieces); -} - -TEST_F(GNA_Request_WorkerFactoryTest, createWorker_with_splitting) { - auto deviceMock = std::make_shared(); - - const constexpr uint32_t kObjectLayers = 5; - const Gna2AccelerationMode accMode = Gna2AccelerationModeAuto; - - auto modelWrapper = ModelWrapperFactory::createWithNumberOfEmptyOperations(kObjectLayers); - - // ensure that kObjectLayers == 0 value is handled - const constexpr uint32_t kMaxLayersZero = 0; - EXPECT_CALL(*deviceMock.get(), maxLayersCount()).Times(1).WillOnce(Return(kMaxLayersZero)); - std::vector> subrequests; - EXPECT_THROW(subrequests = WorkerFactory::createModelSubrequests(modelWrapper, deviceMock, accMode), - std::exception); - subrequests.clear(); - - // check layers bigger than kMaxLayersSmaller - split into two pieces - const constexpr uint32_t kMaxLayersSmaller = kObjectLayers - 1; - size_t numberOfPieces = 2; - EXPECT_CALL(*deviceMock.get(), maxLayersCount()).Times(1).WillOnce(Return(kMaxLayersSmaller)); - subrequests.clear(); - - Gna2Model tempModel1; - Gna2Model tempModel2; - EXPECT_CALL(*deviceMock.get(), createModel(_)) - .Times(numberOfPieces) - .WillOnce(DoAll(SaveArg<0>(&tempModel1), Return(0))) - .WillOnce(DoAll(SaveArg<0>(&tempModel2), Return(0))); - EXPECT_CALL(*deviceMock.get(), createRequestConfig(_)).Times(numberOfPieces).WillRepeatedly(Return(0)); - - EXPECT_NO_THROW(subrequests = WorkerFactory::createModelSubrequests(modelWrapper, deviceMock, accMode)); - - EXPECT_EQ(tempModel1.NumberOfOperations, kMaxLayersSmaller); // 4 - EXPECT_EQ(tempModel1.Operations, modelWrapper->object().Operations); // Operations[0] - - EXPECT_EQ(tempModel2.NumberOfOperations, kObjectLayers % kMaxLayersSmaller); // 1 - EXPECT_EQ(tempModel2.Operations, &modelWrapper->object().Operations[kMaxLayersSmaller]); // Operations[4] - - EXPECT_EQ(subrequests.size(), numberOfPieces); -} diff --git a/src/plugins/intel_gna/tests/unit/request/gna_request_worker_impl_test.cpp b/src/plugins/intel_gna/tests/unit/request/gna_request_worker_impl_test.cpp deleted file mode 100644 index d690a10c950..00000000000 --- a/src/plugins/intel_gna/tests/unit/request/gna_request_worker_impl_test.cpp +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "mock_subrequest.hpp" -#include "request/model_wrapper_factory.hpp" -#include "request/worker_impl.hpp" - -using namespace ov::intel_gna; -using namespace request; -using namespace testing; - -class GNA_Request_WorkerImplTest : public ::testing::Test {}; - -TEST_F(GNA_Request_WorkerImplTest, initDeinit) { - ASSERT_THROW(WorkerImpl(nullptr, {}), std::exception); - - std::vector> subrequests; - ASSERT_THROW(WorkerImpl(nullptr, subrequests), std::exception); - auto wrapper = ModelWrapperFactory::createTrivial(); - ASSERT_THROW(WorkerImpl(wrapper, {}), std::exception); - - subrequests.push_back(nullptr); - ASSERT_THROW(WorkerImpl(wrapper, subrequests), std::exception); - subrequests.clear(); - - subrequests.push_back(std::make_shared()); - ASSERT_NO_THROW(WorkerImpl(wrapper, subrequests)); -} - -TEST_F(GNA_Request_WorkerImplTest, model) { - auto wrapper = ModelWrapperFactory::createTrivial(); - auto expectedModelPtr = &wrapper->object(); - std::vector> subrequests; - subrequests.push_back(std::make_shared()); - - WorkerImpl worker(wrapper, subrequests); - EXPECT_EQ(expectedModelPtr, worker.model()); -} - -TEST_F(GNA_Request_WorkerImplTest, model_const) { - auto wrapper = ModelWrapperFactory::createTrivial(); - auto expectedModelPtr = &wrapper->object(); - std::vector> subrequests; - subrequests.push_back(std::make_shared()); - - const WorkerImpl worker(wrapper, subrequests); - EXPECT_EQ(expectedModelPtr, worker.model()); -} - -TEST_F(GNA_Request_WorkerImplTest, enqueueRequest) { - auto wrapper = ModelWrapperFactory::createTrivial(); - std::vector> subrequests; - - auto subrequestMock1 = std::make_shared(); - subrequests.push_back(subrequestMock1); - auto subrequestMock2 = std::make_shared(); - subrequests.push_back(subrequestMock2); - WorkerImpl worker(wrapper, subrequests); - - // check if false will be returned if worker will be busy - at least one subrequest is pending. - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(1).WillOnce(Return(false)); - EXPECT_CALL(*subrequestMock2.get(), isPending()).Times(1).WillOnce(Return(true)); - EXPECT_FALSE(worker.enqueueRequest()); - - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(1).WillOnce(Return(false)); - EXPECT_CALL(*subrequestMock2.get(), isPending()).Times(1).WillOnce(Return(false)); - EXPECT_CALL(*subrequestMock1.get(), enqueue()).Times(1).WillOnce(Return(true)); - EXPECT_CALL(*subrequestMock2.get(), enqueue()).Times(1).WillOnce(Return(true)); - EXPECT_TRUE(worker.enqueueRequest()); -} - -TEST_F(GNA_Request_WorkerImplTest, enqueueRequest_second_enque_failed) { - auto wrapper = ModelWrapperFactory::createTrivial(); - std::vector> subrequests; - - auto subrequestMock1 = std::make_shared(); - subrequests.push_back(subrequestMock1); - auto subrequestMock2 = std::make_shared(); - subrequests.push_back(subrequestMock2); - WorkerImpl worker(wrapper, subrequests); - - // check if exception will be thrown if worker will be busy - at least one subrequest is pending. - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(1).WillOnce(Return(false)); - EXPECT_CALL(*subrequestMock2.get(), isPending()).Times(1).WillOnce(Return(true)); - EXPECT_FALSE(worker.enqueueRequest()); - - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(2).WillOnce(Return(false)).WillOnce(Return(true)); - EXPECT_CALL(*subrequestMock2.get(), isPending()).Times(2).WillOnce(Return(false)).WillOnce(Return(false)); - EXPECT_CALL(*subrequestMock1.get(), enqueue()).Times(1).WillOnce(Return(true)); - EXPECT_CALL(*subrequestMock2.get(), enqueue()).Times(1).WillOnce(Return(false)); - EXPECT_CALL(*subrequestMock1.get(), cleanup()).Times(1); - EXPECT_CALL(*subrequestMock2.get(), cleanup()).Times(0); - EXPECT_FALSE(worker.enqueueRequest()); -} - -TEST_F(GNA_Request_WorkerImplTest, wait) { - auto wrapper = ModelWrapperFactory::createTrivial(); - std::vector> subrequests; - int64_t referenceTimeout = 1; - - auto subrequestMock1 = std::make_shared(); - subrequests.push_back(subrequestMock1); - WorkerImpl worker(wrapper, subrequests); - - // subrequest enuqued and completed on wait - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(1).WillOnce(Return(true)); - EXPECT_CALL(*subrequestMock1.get(), isAborted()).Times(1).WillOnce(Return(false)); - EXPECT_CALL(*subrequestMock1.get(), wait(referenceTimeout)).Times(1).WillOnce(Return(RequestStatus::kCompleted)); - EXPECT_EQ(RequestStatus::kCompleted, worker.wait(referenceTimeout)); - - // subrequest enuqued and aborted on wait - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(1).WillOnce(Return(true)); - EXPECT_CALL(*subrequestMock1.get(), isAborted()).Times(1).WillOnce(Return(true)); - EXPECT_CALL(*subrequestMock1.get(), wait(referenceTimeout)).Times(1).WillOnce(Return(RequestStatus::kAborted)); - EXPECT_EQ(RequestStatus::kAborted, worker.wait(referenceTimeout)); - - // subrequest enuqued and panding on wait - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(1).WillOnce(Return(true)); - EXPECT_CALL(*subrequestMock1.get(), wait(referenceTimeout)).Times(1).WillOnce(Return(RequestStatus::kPending)); - EXPECT_EQ(RequestStatus::kPending, worker.wait(referenceTimeout)); - - // subrequest not enuqued and not aborted - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(1).WillOnce(Return(false)); - EXPECT_CALL(*subrequestMock1.get(), isAborted()).Times(1).WillOnce(Return(false)); - EXPECT_EQ(RequestStatus::kCompleted, worker.wait(referenceTimeout)); - - // subrequest not enuqued and aborted - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(1).WillOnce(Return(false)); - EXPECT_CALL(*subrequestMock1.get(), isAborted()).Times(1).WillOnce(Return(true)); - EXPECT_EQ(RequestStatus::kAborted, worker.wait(referenceTimeout)); - - // subrequest enuqued and completed with error - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(2).WillOnce(Return(true)).WillOnce(Return(false)); - EXPECT_CALL(*subrequestMock1.get(), wait(referenceTimeout)) - .Times(1) - .WillOnce(Return(RequestStatus::kCompletedWithError)); - EXPECT_EQ(RequestStatus::kCompletedWithError, worker.wait(referenceTimeout)); -} - -TEST_F(GNA_Request_WorkerImplTest, isFree) { - auto wrapper = ModelWrapperFactory::createTrivial(); - std::vector> subrequests; - - auto subrequestMock1 = std::make_shared(); - subrequests.push_back(subrequestMock1); - - WorkerImpl worker(wrapper, subrequests); - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(1).WillOnce(Return(true)); - EXPECT_EQ(false, worker.isFree()); - - EXPECT_CALL(*subrequestMock1.get(), isPending()).Times(1).WillOnce(Return(false)); - EXPECT_EQ(true, worker.isFree()); -} - -TEST_F(GNA_Request_WorkerImplTest, result) { - auto wrapper = ModelWrapperFactory::createTrivial(); - std::vector> subrequests; - - subrequests.push_back(std::make_shared()); - - InferenceEngine::BlobMap referenceBlobMap; - const std::string referenceBlobKey("test1"); - referenceBlobMap[referenceBlobKey] = nullptr; - WorkerImpl worker(wrapper, subrequests); - worker.setResult(referenceBlobMap); - EXPECT_EQ(referenceBlobMap, worker.result()); - - // for rvalue reference - auto referenceBlobMapCopy = referenceBlobMap; - worker.setResult(std::move(referenceBlobMapCopy)); - EXPECT_EQ(referenceBlobMap, worker.result()); -} diff --git a/src/plugins/intel_gna/tests/unit/request/gna_request_worker_pool_impl_test.cpp b/src/plugins/intel_gna/tests/unit/request/gna_request_worker_pool_impl_test.cpp deleted file mode 100644 index e304e06abae..00000000000 --- a/src/plugins/intel_gna/tests/unit/request/gna_request_worker_pool_impl_test.cpp +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "mock_worker.hpp" -#include "request/worker_pool_impl.hpp" - -using namespace ov::intel_gna::request; -using namespace testing; - -class GNA_Request_WorkerPoolImplTest : public ::testing::Test { -public: - static const constexpr uint32_t kExpectedIndex = 0; -}; -const constexpr uint32_t GNA_Request_WorkerPoolImplTest::kExpectedIndex; - -TEST_F(GNA_Request_WorkerPoolImplTest, initDeinit) { - ASSERT_NO_THROW(WorkerPoolImpl()); -} - -TEST_F(GNA_Request_WorkerPoolImplTest, addModelWorker_nullptr) { - std::shared_ptr workerPool; - ASSERT_NO_THROW(workerPool = std::make_shared()); - ASSERT_THROW(workerPool->addModelWorker(nullptr), std::exception); -} - -TEST_F(GNA_Request_WorkerPoolImplTest, addModelWorker_proper) { - WorkerPoolImpl workerPool; - auto workerMock = std::make_shared(); - - EXPECT_CALL(*workerMock.get(), setRepresentingIndex(kExpectedIndex)).Times(1); - ASSERT_NO_THROW(workerPool.addModelWorker(workerMock)); -} - -TEST_F(GNA_Request_WorkerPoolImplTest, size) { - WorkerPoolImpl workerPool; - ASSERT_EQ(workerPool.size(), 0); - auto workerMock = std::make_shared(); - EXPECT_CALL(*workerMock.get(), setRepresentingIndex(kExpectedIndex)).Times(1); - ASSERT_NO_THROW(workerPool.addModelWorker(workerMock)); - ASSERT_EQ(workerPool.size(), 1); -} - -TEST_F(GNA_Request_WorkerPoolImplTest, worker) { - WorkerPoolImpl workerPool; - ASSERT_THROW(workerPool.worker(0), std::exception); - auto workerMock = std::make_shared(); - EXPECT_CALL(*workerMock.get(), setRepresentingIndex(kExpectedIndex)).Times(1); - ASSERT_NO_THROW(workerPool.addModelWorker(workerMock)); - ASSERT_NO_THROW(workerPool.worker(0)); -} - -TEST_F(GNA_Request_WorkerPoolImplTest, worker_const) { - WorkerPoolImpl workerPool; - const WorkerPoolImpl& constWorkerPool = workerPool; - ASSERT_THROW(constWorkerPool.worker(0), std::exception); - auto workerMock = std::make_shared(); - EXPECT_CALL(*workerMock.get(), setRepresentingIndex(kExpectedIndex)).Times(1); - ASSERT_NO_THROW(workerPool.addModelWorker(workerMock)); - ASSERT_NO_THROW(constWorkerPool.worker(0)); -} - -TEST_F(GNA_Request_WorkerPoolImplTest, firstWorker) { - WorkerPoolImpl workerPool; - ASSERT_THROW(workerPool.firstWorker(), std::exception); - auto workerMock = std::make_shared(); - EXPECT_CALL(*workerMock.get(), setRepresentingIndex(kExpectedIndex)).Times(1); - ASSERT_NO_THROW(workerPool.addModelWorker(workerMock)); - ASSERT_NO_THROW(workerPool.firstWorker()); -} - -TEST_F(GNA_Request_WorkerPoolImplTest, firstWorker_const) { - WorkerPoolImpl workerPool; - const WorkerPoolImpl& constWorkerPool = workerPool; - ASSERT_THROW(constWorkerPool.firstWorker(), std::exception); - auto workerMock = std::make_shared(); - EXPECT_CALL(*workerMock.get(), setRepresentingIndex(kExpectedIndex)).Times(1); - ASSERT_NO_THROW(workerPool.addModelWorker(workerMock)); - ASSERT_NO_THROW(constWorkerPool.firstWorker()); -} - -TEST_F(GNA_Request_WorkerPoolImplTest, lastWorker) { - WorkerPoolImpl workerPool; - ASSERT_THROW(workerPool.lastWorker(), std::exception); - auto workerMock = std::make_shared(); - EXPECT_CALL(*workerMock.get(), setRepresentingIndex(kExpectedIndex)).Times(1); - ASSERT_NO_THROW(workerPool.addModelWorker(workerMock)); - ASSERT_NO_THROW(workerPool.lastWorker()); -} - -TEST_F(GNA_Request_WorkerPoolImplTest, lastWorker_const) { - WorkerPoolImpl workerPool; - const WorkerPoolImpl& constWorkerPool = workerPool; - ASSERT_THROW(constWorkerPool.lastWorker(), std::exception); - auto workerMock = std::make_shared(); - EXPECT_CALL(*workerMock.get(), setRepresentingIndex(kExpectedIndex)).Times(1); - ASSERT_NO_THROW(workerPool.addModelWorker(workerMock)); - ASSERT_NO_THROW(constWorkerPool.lastWorker()); -} - -TEST_F(GNA_Request_WorkerPoolImplTest, findFreeModelWorker) { - WorkerPoolImpl workerPool; - auto workerMock = std::make_shared(); - - std::shared_ptr foundWorker; - // return nullptr if no worker added - ASSERT_NO_THROW(foundWorker = workerPool.findFreeModelWorker()); - ASSERT_EQ(foundWorker.get(), nullptr); - EXPECT_CALL(*workerMock.get(), setRepresentingIndex(kExpectedIndex)).Times(1); - ASSERT_NO_THROW(workerPool.addModelWorker(workerMock)); - - // return nullptr if all workers busy - EXPECT_CALL(*workerMock.get(), isFree()).Times(1).WillOnce(Return(false)); - ASSERT_NO_THROW(foundWorker = workerPool.findFreeModelWorker()); - ASSERT_EQ(foundWorker.get(), nullptr); - - // return valid pointer if at least one worker free - EXPECT_CALL(*workerMock.get(), isFree()).Times(1).WillOnce(Return(true)); - ASSERT_NO_THROW(foundWorker = workerPool.findFreeModelWorker()); - ASSERT_NE(foundWorker.get(), nullptr); - auto worker = std::static_pointer_cast(workerMock); - ASSERT_EQ(foundWorker.get(), worker.get()); -} diff --git a/src/plugins/intel_gna/tests/unit/request/mock_gna_device.hpp b/src/plugins/intel_gna/tests/unit/request/mock_gna_device.hpp deleted file mode 100644 index c199ec7b9e1..00000000000 --- a/src/plugins/intel_gna/tests/unit/request/mock_gna_device.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "gmock/gmock.h" -#include "gna_device_interface.hpp" - -namespace ov { -namespace intel_gna { - -class MockGNADevice : public GNADevice { -public: - MOCK_METHOD(uint32_t, createModel, (Gna2Model&), (const, override)); - MOCK_METHOD(uint32_t, createRequestConfig, (const uint32_t), (const, override)); - MOCK_METHOD(uint32_t, enqueueRequest, (const uint32_t, Gna2AccelerationMode), (override)); - MOCK_METHOD(RequestStatus, waitForRequest, (uint32_t, int64_t), (override)); - MOCK_METHOD(uint32_t, maxLayersCount, (), (const, override)); -}; - -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/tests/unit/request/mock_subrequest.hpp b/src/plugins/intel_gna/tests/unit/request/mock_subrequest.hpp deleted file mode 100644 index 235bb06a655..00000000000 --- a/src/plugins/intel_gna/tests/unit/request/mock_subrequest.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "gmock/gmock.h" -#include "request/subrequest.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -class MockSubrequest : public Subrequest { -public: - MOCK_METHOD(RequestStatus, wait, (int64_t), (override)); - MOCK_METHOD(bool, enqueue, (), (override)); - MOCK_METHOD(void, cleanup, (), (override)); - MOCK_METHOD(bool, isPending, (), (const, override)); - MOCK_METHOD(bool, isAborted, (), (const, override)); - MOCK_METHOD(bool, isCompleted, (), (const, override)); -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/tests/unit/request/mock_worker.hpp b/src/plugins/intel_gna/tests/unit/request/mock_worker.hpp deleted file mode 100644 index 765963e150b..00000000000 --- a/src/plugins/intel_gna/tests/unit/request/mock_worker.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "gmock/gmock.h" -#include "request/worker.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -class MockWorker : public Worker { -public: - MOCK_METHOD(Gna2Model*, model, (), (override)); - MOCK_METHOD(const Gna2Model*, model, (), (const, override)); - MOCK_METHOD(bool, enqueueRequest, (), (override)); - MOCK_METHOD(RequestStatus, wait, (int64_t), (override)); - MOCK_METHOD(bool, isFree, (), (const, override)); - MOCK_METHOD(uint32_t, representingIndex, (), (const, override)); - MOCK_METHOD(void, setRepresentingIndex, (uint32_t), (override)); - MOCK_METHOD(InferenceEngine::BlobMap&, result, (), (override)); - MOCK_METHOD(void, setResult, (const InferenceEngine::BlobMap&), (override)); - MOCK_METHOD(void, setResult, (InferenceEngine::BlobMap &&), (override)); -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/tests/unit/request/mock_worker_pool.hpp b/src/plugins/intel_gna/tests/unit/request/mock_worker_pool.hpp deleted file mode 100644 index 935ee239a00..00000000000 --- a/src/plugins/intel_gna/tests/unit/request/mock_worker_pool.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "gmock/gmock.h" -#include "request/worker_pool.hpp" - -namespace ov { -namespace intel_gna { -namespace request { - -class MockWorkerPool : public WorkerPool { -public: - MOCK_METHOD(void, addModelWorker, (std::shared_ptr), (override)); - MOCK_METHOD(size_t, size, (), (const, override)); - MOCK_METHOD(size_t, empty, (), (const, override)); - MOCK_METHOD(Worker&, worker, (uint32_t), (override)); - MOCK_METHOD(const Worker&, worker, (uint32_t), (const, override)); - MOCK_METHOD(Worker&, firstWorker, (uint32_t), (override)); - MOCK_METHOD(const Worker&, firstWorker, (uint32_t), (const, override)); - MOCK_METHOD(Worker&, lastWorker, (uint32_t), (override)); - MOCK_METHOD(const Worker&, lastWorker, (uint32_t), (const, override)); - MOCK_METHOD(std::shared_ptr, findFreeModelWorker, (), (override)); -}; - -} // namespace request -} // namespace intel_gna -} // namespace ov diff --git a/src/plugins/intel_gna/tests/unit/scale_factor_helper_test.cpp b/src/plugins/intel_gna/tests/unit/scale_factor_helper_test.cpp deleted file mode 100644 index 98c084cd8a5..00000000000 --- a/src/plugins/intel_gna/tests/unit/scale_factor_helper_test.cpp +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "scale_factor_helper.hpp" - -#include - -using ScaleFactorHelperTestData = - std::tuple>, // inputs name and scale_factor - std::tuple, // header version majro,min and info if custom scale - // factor should be applied - bool>; // is test for legacy - -class GNAApplyInputScaleFactorsTest : public ::testing::TestWithParam { -public: - static std::string get_test_case_name(const testing::TestParamInfo& obj) { - std::vector> test_inputs; - std::tuple header_version_with_aplicability; - bool legacy; - - std::tie(test_inputs, header_version_with_aplicability, legacy) = obj.param; - std::string name("Inputs:["); - for (const auto& input : test_inputs) { - name += "[" + input.first + ", " + std::to_string(input.second) + "],"; - } - if (name.back() == ',') { - name.pop_back(); - } - auto major = std::to_string(std::get<0>(header_version_with_aplicability)); - auto minor = std::to_string(std::get<1>(header_version_with_aplicability)); - auto applicable = std::string(std::get<2>(header_version_with_aplicability) ? "scale_factor_applicable" - : "scale_factor_not_applicable"); - name += "],Header[" + major + "." + minor + "]," + applicable; - auto legacy_str = std::string(legacy ? "legacy" : ""); - if (!legacy_str.empty()) { - name += "," + legacy_str; - } - return name; - } - void SetUp() override { - std::tuple header_version_with_aplicability; - std::tie(_test_inputs, header_version_with_aplicability, _legacy_scale_factor) = GetParam(); - - _header.version.major = std::get<0>(header_version_with_aplicability); - _header.version.minor = std::get<1>(header_version_with_aplicability); - _applicable = std::get<2>(header_version_with_aplicability); - - _gna_inputs.Get().clear(); - for (const auto& input : _test_inputs) { - _gna_inputs.Get().push_back({input.first}); - } - - if (_legacy_scale_factor) { - auto& confg_input_factors = _config.inputScaleFactors; - confg_input_factors.clear(); - - std::transform(_test_inputs.begin(), - _test_inputs.end(), - std::back_inserter(confg_input_factors), - [](const std::pair& input) { - return input.second; - }); - - } else { - auto& confg_input_factors = _config.inputScaleFactorsPerInput; - confg_input_factors.clear(); - - // cofingure config with proper scale factors for legacy - std::transform(_test_inputs.begin(), - _test_inputs.end(), - std::inserter(confg_input_factors, confg_input_factors.end()), - [](const std::pair& input) { - return std::make_pair(input.first, input.second); - }); - } - } - - Config _config; - header_latest::ModelHeader _header; - GnaInputs _gna_inputs; - std::vector> _test_inputs; - bool _applicable; - bool _legacy_scale_factor; -}; - -TEST_P(GNAApplyInputScaleFactorsTest, test_import_scale_factor_set_properly) { - EXPECT_NO_THROW(ov::intel_gna::helpers::ApplyInputScaleFactors(_gna_inputs, _config, _header)); - for (const auto& input : _test_inputs) { - auto& input_ref = _gna_inputs[input.first]; - if (_applicable) { - EXPECT_FLOAT_EQ(input_ref.scale_factor, input.second); - } else { - EXPECT_FLOAT_EQ(input_ref.scale_factor, kScaleFactorDefault); - } - } -} - -TEST_P(GNAApplyInputScaleFactorsTest, test_load_scale_factor_set_properly) { - EXPECT_NO_THROW(ov::intel_gna::helpers::ApplyInputScaleFactors(_gna_inputs, _config)); - for (const auto& input : _test_inputs) { - auto& input_ref = _gna_inputs[input.first]; - EXPECT_FLOAT_EQ(input_ref.scale_factor, input.second); - } -} - -TEST_P(GNAApplyInputScaleFactorsTest, inputs_count_not_match_to_scale_factors) { - if (_legacy_scale_factor) { - _config.inputScaleFactors.push_back(10.0); - } else { - _config.inputScaleFactorsPerInput["unknown"] = 10.0; - } - - if (_applicable) { - EXPECT_THROW(ov::intel_gna::helpers::ApplyInputScaleFactors(_gna_inputs, _config, _header), std::exception); - } else { - // check if no exception and data are not changed - EXPECT_NO_THROW(ov::intel_gna::helpers::ApplyInputScaleFactors(_gna_inputs, _config, _header)); - for (const auto& input : _test_inputs) { - auto& input_ref = _gna_inputs[input.first]; - EXPECT_FLOAT_EQ(input_ref.scale_factor, kScaleFactorDefault); - } - } -} - -std::vector>> inputs = {{{"input", 2.0}}, - {{"input_1", 3.0}, {"input_2", 4.0}}}; - -// custom scale factors should not be applied for Model with version > 2.7 -std::vector> model_versions = {{2, 6, true}, {2, 7, true}, {2, 8, false}}; - -INSTANTIATE_TEST_CASE_P(smoke_, - GNAApplyInputScaleFactorsTest, - ::testing::Combine(::testing::ValuesIn(inputs), - ::testing::ValuesIn(model_versions), - ::testing::ValuesIn({true, false})), - GNAApplyInputScaleFactorsTest::get_test_case_name); - -// Tests if nothing was changed if there is no custom scale factor in configuration -TEST(smoke_GNAApplyInputScaleFactorsTest, test_default_scale_factor) { - Config config; - header_latest::ModelHeader header; - GnaInputs inputs; - - std::string input_name = "input"; - auto& input_ref = inputs[input_name]; - config.inputScaleFactors.clear(); - config.inputScaleFactorsPerInput.clear(); - - EXPECT_NO_THROW(ov::intel_gna::helpers::ApplyInputScaleFactors(inputs, config, header)); - - EXPECT_FLOAT_EQ(input_ref.scale_factor, kScaleFactorDefault); -} - -// Tests if exception is thron if input scale factor name does not match to input name -TEST(smoke_GNAApplyInputScaleFactorsTest, test_wrong_scale_factor_config_input_name) { - Config config; - header_latest::ModelHeader header; - header.version.major = 2; - header.version.minor = 7; - GnaInputs gna_inputs; - - const std::string name_1{"input_1"}; - const std::string name_2{"input_2"}; - gna_inputs.Get().clear(); - gna_inputs.Get().push_back(name_1); - gna_inputs.Get().push_back(name_2); - config.inputScaleFactorsPerInput.clear(); - config.inputScaleFactorsPerInput[name_1] = 2.0; - config.inputScaleFactorsPerInput[name_2 + "__"] = 2.0; - - EXPECT_THROW(ov::intel_gna::helpers::ApplyInputScaleFactors(gna_inputs, config, header), std::exception); -} - -// Tests if input scale factor name matches to the tensor name -TEST_P(GNAApplyInputScaleFactorsTest, test_scale_factor_config_input_tensor_name) { - Config config; - GnaInputs gna_inputs; - - const std::string name_1{"input_1"}; - const std::string tensor_name_1{"input_1:0"}; - - const std::string name_2{"input_2"}; - const std::string tensor_name_2{"input_2:0"}; - - gna_inputs[name_1].tensor_names = {tensor_name_1}; - gna_inputs[name_2].tensor_names = {tensor_name_2}; - - config.inputScaleFactorsPerInput.clear(); - config.inputScaleFactorsPerInput[tensor_name_1] = 2.0; - config.inputScaleFactorsPerInput[name_2] = 2.0; - - EXPECT_NO_THROW(ov::intel_gna::helpers::ApplyInputScaleFactors(gna_inputs, config)); - - for (const auto& input : gna_inputs.Get()) { - EXPECT_FLOAT_EQ(input.scale_factor, 2.0); - } -} \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_binary_test.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_binary_test.cpp deleted file mode 100644 index c357993bf19..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_binary_test.cpp +++ /dev/null @@ -1,1276 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_binary.hpp" - -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "gather_sinking_test_utils.hpp" -#include "gtest/gtest.h" -#include "openvino/frontend/manager.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/manager.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ov; -using namespace ov::opset12; - -namespace gather_sinking_binary_eltwise { - -namespace { - -using NodePtr = std::shared_ptr; -using ModelPtr = std::shared_ptr; -using Output = ov::Output; - -std::string to_string(const Shape& shape) { - std::ostringstream result; - result << "{"; - for (size_t idx = 0; idx < shape.size(); ++idx) { - if (idx) - result << ","; - result << shape[idx]; - } - result << "}"; - return result.str(); -} - -// ---------------------------------------------------------------------------- - -class IBinaryFactory { -public: - IBinaryFactory(const std::string& type_name) : type_name_(type_name) {} - virtual ~IBinaryFactory() = default; - virtual NodePtr create(NodePtr parent_left_node, NodePtr parent_right_node) const = 0; - const std::string& getTypeName() const { - return type_name_; - } - -private: - const std::string type_name_; -}; - -using BinaryFactoryPtr = std::shared_ptr; - -template -class BinaryFactory : public IBinaryFactory { -public: - BinaryFactory(const std::string& type_name) : IBinaryFactory(type_name) {} - NodePtr create(NodePtr parent_left_node, NodePtr parent_right_node) const override { - return std::make_shared(parent_left_node, parent_right_node); - } -}; - -template -BinaryFactoryPtr create_binary_factory(const std::string& type_name) { - return std::make_shared>(type_name); -} - -// ---------------------------------------------------------------------------- - -class IPassFactory { -public: - IPassFactory(const std::string& type_name) : type_name_(type_name) {} - virtual ~IPassFactory() = default; - virtual void registerPass(ov::pass::Manager& pass_manager) const = 0; - const std::string& getTypeName() const { - return type_name_; - } - -private: - const std::string type_name_; -}; - -using PassFactoryPtr = std::shared_ptr; - -template -class PassFactory : public IPassFactory { -public: - PassFactory(const std::string& type_name) : IPassFactory(type_name) {} - void registerPass(ov::pass::Manager& pass_manager) const override { - pass_manager.register_pass(); - } -}; - -#define CREATE_PASS_FACTORY(pass_name) std::make_shared>(#pass_name) - -#undef CREATE_BINARY_FACTORY -#define CREATE_BINARY_FACTORY(type_name) create_binary_factory(#type_name) - -std::vector binary_elementwise_factories = {CREATE_BINARY_FACTORY(Add), - CREATE_BINARY_FACTORY(Divide), - CREATE_BINARY_FACTORY(Maximum), - CREATE_BINARY_FACTORY(Minimum), - CREATE_BINARY_FACTORY(Mod), - CREATE_BINARY_FACTORY(Multiply), - CREATE_BINARY_FACTORY(Power), - CREATE_BINARY_FACTORY(SquaredDifference), - CREATE_BINARY_FACTORY(Subtract)}; - -std::vector binary_operations_numbers = {1, 10}; - -std::vector binary_transpose_input_indexes = {0, 1}; - -} // namespace - -namespace single_consumer { -namespace forward { -namespace one_input_transpose { - -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - size_t num_binary_ops, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - const Shape const_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - auto gather = make_gather(X, gather_forward, /* axis */ 1); - - NodePtr in_op = gather; - for (size_t i = 0; i < num_binary_ops; ++i) { - auto in_constant = std::make_shared(input_type, const_shape, Shape{1}); - if (!binary_gather_input_idx) - in_op = binary_factory->create(in_op, in_constant); - else - in_op = binary_factory->create(in_constant, in_op); - } - - return std::make_shared(ov::OutputVector{in_op}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - size_t num_binary_ops, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - NodePtr in_op = X; - for (size_t i = 0; i < num_binary_ops; ++i) { - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - auto gather_reversed = make_gather(in_constant, gather_backward, /* axis */ 1); - - if (!binary_gather_input_idx) - in_op = binary_factory->create(in_op, gather_reversed); - else - in_op = binary_factory->create(gather_reversed, in_op); - } - - auto gather = make_gather(in_op, gather_forward, /* axis */ 1); - - return std::make_shared(ov::OutputVector{gather}, ov::ParameterVector{X}); -} - -} // namespace one_input_transpose - -namespace double_transpose { -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - size_t num_binary_ops, - element::Type input_type) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - auto gather = make_gather(X, gather_forward, /* axis */ 1); - - NodePtr in_op = gather; - for (size_t i = 0; i < num_binary_ops; ++i) { - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - auto gather = make_gather(in_constant, gather_forward, /* axis */ 1); - - in_op = binary_factory->create(in_op, gather); - } - - return std::make_shared(ov::OutputVector{in_op}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - size_t num_binary_ops, - element::Type input_type) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - NodePtr in_op = X; - for (size_t i = 0; i < num_binary_ops; ++i) { - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - auto gather = make_gather(in_constant, gather_forward, /* axis */ 1); - auto gather_reversed = make_gather(gather, gather_backward, /* axis */ 1); - - in_op = binary_factory->create(in_op, gather_reversed); - } - - auto gather = make_gather(in_op, gather_forward, /* axis */ 1); - - return std::make_shared(ov::OutputVector{gather}, ov::ParameterVector{X}); -} - -using CreateGraphBinaryTwoTransposeInputsF = std::function< - std::shared_ptr(BinaryFactoryPtr binary_factory, size_t num_binary_ops, element::Type input_type)>; - -using TestBinaryTwoTransposeInputsParams = - std::tuple; /* input type */ - -class GatherSinkingBinaryTwoTransposeInputsTestFixture - : public ::testing::WithParamInterface, - public TransformationTestsF { -public: - static std::string get_test_name(const testing::TestParamInfo& obj) { - BinaryFactoryPtr binary_factory; - PassFactoryPtr pass_factory; - size_t num_binary_ops; - CreateGraphBinaryTwoTransposeInputsF model_factory; - CreateGraphBinaryTwoTransposeInputsF reference_model_factory; - element::Type input_type; - - std::tie(binary_factory, pass_factory, num_binary_ops, model_factory, reference_model_factory, input_type) = - obj.param; - - std::ostringstream test_name; - test_name << "binaryFactory=" << binary_factory->getTypeName() << "/"; - test_name << "passFactory=" << pass_factory->getTypeName() << "/"; - test_name << "numBinaryOps=" << num_binary_ops << "/"; - test_name << "inputType=" << input_type; - - return test_name.str(); - } -}; - -TEST_P(GatherSinkingBinaryTwoTransposeInputsTestFixture, CompareFunctions) { - BinaryFactoryPtr binary_factory; - PassFactoryPtr pass_factory; - size_t num_binary_ops; - CreateGraphBinaryTwoTransposeInputsF model_factory; - CreateGraphBinaryTwoTransposeInputsF reference_model_factory; - element::Type input_type; - - std::tie(binary_factory, pass_factory, num_binary_ops, model_factory, reference_model_factory, input_type) = - this->GetParam(); - - model = model_factory(binary_factory, num_binary_ops, input_type); - model_ref = reference_model_factory(binary_factory, num_binary_ops, input_type); - pass_factory->registerPass(manager); -} - -INSTANTIATE_TEST_SUITE_P(GatherSinkingBinaryTwoTransposeInputsForwardTestSuite, - GatherSinkingBinaryTwoTransposeInputsTestFixture, - ::testing::Combine(::testing::ValuesIn(binary_elementwise_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingBinaryForward)), - ::testing::ValuesIn(binary_operations_numbers), - ::testing::Values(CreateFunction), - ::testing::Values(CreateReferenceFunction), - ::testing::Values(element::f32)), - GatherSinkingBinaryTwoTransposeInputsTestFixture::get_test_name); - -} // namespace double_transpose -} // namespace forward - -namespace backward { -namespace one_input_transpose { -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - size_t num_binary_ops, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - NodePtr in_op = X; - for (size_t i = 0; i < num_binary_ops; ++i) { - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - if (!binary_gather_input_idx) - in_op = binary_factory->create(in_op, in_constant); - else - in_op = binary_factory->create(in_constant, in_op); - } - auto gather = make_gather(in_op, gather_forward, /* axis */ 1); - - return std::make_shared(ov::OutputVector{gather}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - size_t num_binary_ops, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - auto tanh = std::make_shared(X); - auto gather = make_gather(X, gather_forward, /* axis */ 1); - - NodePtr in_op = gather; - for (size_t i = 0; i < num_binary_ops; ++i) { - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - auto gather = make_gather(in_constant, gather_forward, /* axis */ 1); - if (!binary_gather_input_idx) - in_op = binary_factory->create(in_op, gather); - else - in_op = binary_factory->create(gather, in_op); - } - - return std::make_shared(ov::OutputVector{in_op}, ov::ParameterVector{X}); -} - -using CreateGraphBinaryF = std::function(BinaryFactoryPtr binary_factory, - size_t num_binary_ops, - element::Type input_type, - size_t binary_gather_input_idx)>; - -using TestBinaryParams = std::tuple; /* binary_gather_input_idx */ - -class GatherSinkingBinaryTestFixture : public ::testing::WithParamInterface, - public TransformationTestsF { -public: - static std::string get_test_name(const testing::TestParamInfo& obj) { - BinaryFactoryPtr binary_factory; - PassFactoryPtr pass_factory; - size_t num_binary_ops; - CreateGraphBinaryF model_factory; - CreateGraphBinaryF reference_model_factory; - element::Type input_type; - size_t binary_gather_input_idx; - - std::tie(binary_factory, - pass_factory, - num_binary_ops, - model_factory, - reference_model_factory, - input_type, - binary_gather_input_idx) = obj.param; - - std::ostringstream test_name; - test_name << "binaryFactory=" << binary_factory->getTypeName() << "/"; - test_name << "passFactory=" << pass_factory->getTypeName() << "/"; - test_name << "numBinaryOps=" << num_binary_ops << "/"; - test_name << "inputType=" << input_type << "/"; - test_name << "binaryTransposeInputIdx=" << binary_gather_input_idx; - - return test_name.str(); - } -}; - -TEST_P(GatherSinkingBinaryTestFixture, CompareFunctions) { - BinaryFactoryPtr binary_factory; - PassFactoryPtr pass_factory; - size_t num_binary_ops; - CreateGraphBinaryF model_factory; - CreateGraphBinaryF reference_model_factory; - element::Type input_type; - size_t binary_gather_input_idx; - std::tie(binary_factory, - pass_factory, - num_binary_ops, - model_factory, - reference_model_factory, - input_type, - binary_gather_input_idx) = this->GetParam(); - - model = model_factory(binary_factory, num_binary_ops, input_type, binary_gather_input_idx); - model_ref = reference_model_factory(binary_factory, num_binary_ops, input_type, binary_gather_input_idx); - pass_factory->registerPass(manager); -} - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingBinaryForwardTestSuite, - GatherSinkingBinaryTestFixture, - ::testing::Combine(::testing::ValuesIn(binary_elementwise_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingBinaryForward)), - ::testing::ValuesIn(binary_operations_numbers), - ::testing::Values(single_consumer::forward::one_input_transpose::CreateFunction), - ::testing::Values(single_consumer::forward::one_input_transpose::CreateReferenceFunction), - ::testing::Values(element::f32), - ::testing::ValuesIn(binary_transpose_input_indexes)), - GatherSinkingBinaryTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingBinaryBackwardTestSuite, - GatherSinkingBinaryTestFixture, - ::testing::Combine(::testing::ValuesIn(binary_elementwise_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingBinaryBackward)), - ::testing::ValuesIn(binary_operations_numbers), - ::testing::Values(single_consumer::backward::one_input_transpose::CreateFunction), - ::testing::Values(single_consumer::backward::one_input_transpose::CreateReferenceFunction), - ::testing::Values(element::f32), - ::testing::ValuesIn(binary_transpose_input_indexes)), - GatherSinkingBinaryTestFixture::get_test_name); - -// -------------------------------------------------------------------------------------- - -using CreateGraphBinaryIncompatShapesF = std::function< - std::shared_ptr(BinaryFactoryPtr unary_factory, element::Type input_type, size_t binary_gather_input_idx)>; - -using TestBinaryIncompatShapesParams = std::tuple; /* binary_gather_input_idx */ - -class GatherSinkingBinaryIncompatShapesTestFixture - : public ::testing::WithParamInterface, - public TransformationTestsF { -public: - static std::string get_test_name(const testing::TestParamInfo& obj) { - BinaryFactoryPtr binary_factory; - PassFactoryPtr pass_factory; - CreateGraphBinaryIncompatShapesF model_factory; - CreateGraphBinaryIncompatShapesF reference_model_factory; - element::Type input_type; - size_t binary_gather_input_idx; - std::tie(binary_factory, - pass_factory, - model_factory, - reference_model_factory, - input_type, - binary_gather_input_idx) = obj.param; - - std::ostringstream test_name; - test_name << "binaryFactory=" << binary_factory->getTypeName() << "/"; - test_name << "passFactory=" << pass_factory->getTypeName() << "/"; - test_name << "inputType=" << input_type << "/"; - test_name << "binaryTransposeInputIdx=" << binary_gather_input_idx; - - return test_name.str(); - } -}; - -namespace binary { -namespace single_consumer { -namespace backward { -namespace incompat_shapes { -namespace insert_gather { -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - auto X = std::make_shared(input_type, Shape{1, 20, 1}); - - auto in_constant = std::make_shared(input_type, Shape{5, 3, 20, 7}, Shape{1}); - - NodePtr binary_op; - if (!binary_gather_input_idx) - binary_op = binary_factory->create(X, in_constant); - else - binary_op = binary_factory->create(in_constant, X); - - auto gather = make_gather(binary_op, gather_forward, /* axis */ 2); - return std::make_shared(ov::OutputVector{gather}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - auto X = std::make_shared(input_type, Shape{1, 20, 1}); - auto gather0 = make_gather(X, gather_forward, /* axis */ 1); - - auto in_constant = std::make_shared(input_type, Shape{5, 3, 20, 7}, Shape{1}); - auto gather1 = make_gather(in_constant, gather_forward, /* axis */ 2); - - NodePtr binary_op; - if (!binary_gather_input_idx) - binary_op = binary_factory->create(gather0, gather1); - else - binary_op = binary_factory->create(gather1, gather0); - - return std::make_shared(ov::OutputVector{binary_op}, ov::ParameterVector{X}); -} -} // namespace insert_gather - -namespace no_insert_gather { -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - auto X = std::make_shared(input_type, Shape{1, 20, 1}); - - auto in_constant = std::make_shared(input_type, Shape{5, 3, 20, 7}, Shape{1}); - - NodePtr binary_op; - if (!binary_gather_input_idx) - binary_op = binary_factory->create(X, in_constant); - else - binary_op = binary_factory->create(in_constant, X); - - auto gather = make_gather(binary_op, gather_forward, /* axis */ 0); - return std::make_shared(ov::OutputVector{gather}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - auto X = std::make_shared(input_type, Shape{1, 20, 1}); - - auto in_constant = std::make_shared(input_type, Shape{5, 3, 20, 7}, Shape{1}); - auto gather1 = make_gather(in_constant, gather_forward, /* axis */ 0); - - NodePtr binary_op; - if (!binary_gather_input_idx) - binary_op = binary_factory->create(X, gather1); - else - binary_op = binary_factory->create(gather1, X); - - return std::make_shared(ov::OutputVector{binary_op}, ov::ParameterVector{X}); -} -} // namespace no_insert_gather - -} // namespace incompat_shapes -} // namespace backward - -namespace forward { -namespace incompat_shapes { -namespace gather_small_input { -namespace insert_gather { -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - auto X = std::make_shared(input_type, Shape{1, 20, 1}); - - auto in_constant = std::make_shared(input_type, Shape{5, 3, 20, 7}, Shape{1}); - auto gather0 = make_gather(in_constant, gather_forward, /* axis */ 2); - - NodePtr binary_op; - if (!binary_gather_input_idx) - binary_op = binary_factory->create(gather0, X); - else - binary_op = binary_factory->create(X, gather0); - - return std::make_shared(ov::OutputVector{binary_op}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - auto X = std::make_shared(input_type, Shape{1, 20, 1}); - auto gather0 = make_gather(X, gather_backward, /* axis */ 1); - - auto in_constant = std::make_shared(input_type, Shape{5, 3, 20, 7}, Shape{1}); - - NodePtr binary_op; - if (!binary_gather_input_idx) - binary_op = binary_factory->create(in_constant, gather0); - else - binary_op = binary_factory->create(gather0, in_constant); - - auto gather1 = make_gather(binary_op, gather_forward, /* axis */ 2); - - return std::make_shared(ov::OutputVector{gather1}, ov::ParameterVector{X}); -} -} // namespace insert_gather - -namespace no_insert_gather { -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - auto X = std::make_shared(input_type, Shape{1, 20, 1}); - - auto in_constant = std::make_shared(input_type, Shape{5, 3, 20, 7}, Shape{1}); - auto gather0 = make_gather(in_constant, gather_forward, /* axis */ 0); - - NodePtr binary_op; - if (!binary_gather_input_idx) - binary_op = binary_factory->create(gather0, X); - else - binary_op = binary_factory->create(X, gather0); - - return std::make_shared(ov::OutputVector{binary_op}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - auto X = std::make_shared(input_type, Shape{1, 20, 1}); - - auto in_constant = std::make_shared(input_type, Shape{5, 3, 20, 7}, Shape{1}); - - NodePtr binary_op; - if (!binary_gather_input_idx) - binary_op = binary_factory->create(in_constant, X); - else - binary_op = binary_factory->create(X, in_constant); - - auto gather1 = make_gather(binary_op, gather_forward, /* axis */ 0); - - return std::make_shared(ov::OutputVector{gather1}, ov::ParameterVector{X}); -} -} // namespace no_insert_gather - -} // namespace gather_small_input - -namespace gather_large_input { -namespace insert_gather { -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - auto X = std::make_shared(input_type, Shape{5, 3, 20, 7}); - - auto in_constant = std::make_shared(input_type, Shape{1, 20, 1}, Shape{1}); - auto gather0 = make_gather(in_constant, gather_forward, /* axis */ 1); - - NodePtr binary_op; - if (!binary_gather_input_idx) - binary_op = binary_factory->create(gather0, X); - else - binary_op = binary_factory->create(X, gather0); - - return std::make_shared(ov::OutputVector{binary_op}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - auto X = std::make_shared(input_type, Shape{5, 3, 20, 7}); - auto gather0 = make_gather(X, gather_backward, /* axis */ 2); - - auto in_constant = std::make_shared(input_type, Shape{1, 20, 1}, Shape{1}); - - NodePtr binary_op; - if (!binary_gather_input_idx) - binary_op = binary_factory->create(in_constant, gather0); - else - binary_op = binary_factory->create(gather0, in_constant); - - auto gather1 = make_gather(binary_op, gather_forward, /* axis */ 2); - - return std::make_shared(ov::OutputVector{gather1}, ov::ParameterVector{X}); -} -} // namespace insert_gather - -} // namespace gather_large_input - -} // namespace incompat_shapes -} // namespace forward - -} // namespace single_consumer -} // namespace binary - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingBinaryIncompatShapesBackwardInsertGatherTestSuite, - GatherSinkingBinaryIncompatShapesTestFixture, - ::testing::Combine( - ::testing::ValuesIn(binary_elementwise_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingBinaryBackward)), - ::testing::Values(binary::single_consumer::backward::incompat_shapes::insert_gather::CreateFunction), - ::testing::Values(binary::single_consumer::backward::incompat_shapes::insert_gather::CreateReferenceFunction), - ::testing::Values(element::f32), - ::testing::ValuesIn(binary_transpose_input_indexes)), - GatherSinkingBinaryIncompatShapesTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingBinaryIncompatShapesBackwardNoGatherInsertTestSuite, - GatherSinkingBinaryIncompatShapesTestFixture, - ::testing::Combine( - ::testing::ValuesIn(binary_elementwise_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingBinaryBackward)), - ::testing::Values(binary::single_consumer::backward::incompat_shapes::no_insert_gather::CreateFunction), - ::testing::Values( - binary::single_consumer::backward::incompat_shapes::no_insert_gather::CreateReferenceFunction), - ::testing::Values(element::f32), - ::testing::ValuesIn(binary_transpose_input_indexes)), - GatherSinkingBinaryIncompatShapesTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingBinaryIncompatShapesGatherSmallInputForwardInsertGatherTestSuite, - GatherSinkingBinaryIncompatShapesTestFixture, - ::testing::Combine( - ::testing::ValuesIn(binary_elementwise_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingBinaryForward)), - ::testing::Values( - binary::single_consumer::forward::incompat_shapes::gather_small_input::insert_gather::CreateFunction), - ::testing::Values(binary::single_consumer::forward::incompat_shapes::gather_small_input::insert_gather:: - CreateReferenceFunction), - ::testing::Values(element::f32), - ::testing::ValuesIn(binary_transpose_input_indexes)), - GatherSinkingBinaryIncompatShapesTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingBinaryIncompatShapesGatherSmallInputForwardNoGatherInsertTestSuite, - GatherSinkingBinaryIncompatShapesTestFixture, - ::testing::Combine( - ::testing::ValuesIn(binary_elementwise_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingBinaryForward)), - ::testing::Values( - binary::single_consumer::forward::incompat_shapes::gather_small_input::no_insert_gather::CreateFunction), - ::testing::Values(binary::single_consumer::forward::incompat_shapes::gather_small_input::no_insert_gather:: - CreateReferenceFunction), - ::testing::Values(element::f32), - ::testing::ValuesIn(binary_transpose_input_indexes)), - GatherSinkingBinaryIncompatShapesTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingBinaryIncompatShapesGatherLargeInputInsertgather_forwardTestSuite, - GatherSinkingBinaryIncompatShapesTestFixture, - ::testing::Combine( - ::testing::ValuesIn(binary_elementwise_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingBinaryForward)), - ::testing::Values( - binary::single_consumer::forward::incompat_shapes::gather_large_input::insert_gather::CreateFunction), - ::testing::Values(binary::single_consumer::forward::incompat_shapes::gather_large_input::insert_gather:: - CreateReferenceFunction), - ::testing::Values(element::f32), - ::testing::ValuesIn(binary_transpose_input_indexes)), - GatherSinkingBinaryIncompatShapesTestFixture::get_test_name); - -} // namespace one_input_transpose -} // namespace backward -} // namespace single_consumer - -namespace mult_consumers { -namespace forward { -namespace input_transpose_consumers { - -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - auto gather0 = make_gather(X, gather_forward, /* axis */ 1); - - auto tanh = std::make_shared(gather0); - - NodePtr binary; - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - if (!binary_gather_input_idx) - binary = binary_factory->create(gather0, in_constant); - else - binary = binary_factory->create(in_constant, gather0); - - return std::make_shared(ov::OutputVector{binary, tanh}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - auto gather0 = make_gather(X, gather_forward, /* axis */ 1); - - auto tanh = std::make_shared(gather0); - - NodePtr binary; - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - auto gather_reversed = make_gather(in_constant, gather_backward, /* axis */ 1); - - if (!binary_gather_input_idx) - binary = binary_factory->create(X, gather_reversed); - else - binary = binary_factory->create(gather_reversed, X); - - auto gather1 = make_gather(binary, gather_forward, /* axis */ 1); - - return std::make_shared(ov::OutputVector{gather1, tanh}, ov::ParameterVector{X}); -} - -} // namespace input_transpose_consumers - -namespace output_consumers { - -namespace one_binary { - -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - auto gather0 = make_gather(X, gather_forward, /* axis */ 1); - - NodePtr binary; - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - if (!binary_gather_input_idx) - binary = binary_factory->create(gather0, in_constant); - else - binary = binary_factory->create(in_constant, gather0); - - auto tanh1 = std::make_shared(binary); - auto tanh2 = std::make_shared(binary); - - return std::make_shared(ov::OutputVector{tanh1, tanh2}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - NodePtr binary; - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - - auto gather_reversed = make_gather(in_constant, gather_backward, /* axis */ 1); - - if (!binary_gather_input_idx) - binary = binary_factory->create(X, gather_reversed); - else - binary = binary_factory->create(gather_reversed, X); - - auto gather0 = make_gather(binary, gather_forward, /* axis */ 1); - - auto tanh1 = std::make_shared(gather0); - auto tanh2 = std::make_shared(gather0); - - return std::make_shared(ov::OutputVector{tanh1, tanh2}, ov::ParameterVector{X}); -} - -} // namespace one_binary - -} // namespace output_consumers - -namespace input_node_consumers { - -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - auto gather0 = make_gather(X, gather_forward, /* axis */ 1); - - NodePtr binary; - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - if (!binary_gather_input_idx) - binary = binary_factory->create(gather0, in_constant); - else - binary = binary_factory->create(in_constant, gather0); - - auto tanh = std::make_shared(X); - - return std::make_shared(ov::OutputVector{binary, tanh}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - auto tanh = std::make_shared(X); - - NodePtr binary; - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - - auto gather_reversed = make_gather(in_constant, gather_backward, /* axis */ 1); - - if (!binary_gather_input_idx) - binary = binary_factory->create(X, gather_reversed); - else - binary = binary_factory->create(gather_reversed, X); - - auto gather1 = make_gather(binary, gather_forward, /* axis */ 1); - - return std::make_shared(ov::OutputVector{gather1, tanh}, ov::ParameterVector{X}); -} - -} // namespace input_node_consumers - -} // namespace forward - -namespace backward { - -namespace output_consumers { - -namespace one_binary { - -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - auto tanh0 = std::make_shared(X); - - NodePtr binary; - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - if (!binary_gather_input_idx) - binary = binary_factory->create(tanh0, in_constant); - else - binary = binary_factory->create(in_constant, tanh0); - - auto tanh = std::make_shared(binary); - - auto gather0 = make_gather(binary, gather_forward, /* axis */ 1); - - return std::make_shared(ov::OutputVector{gather0, tanh}, ov::ParameterVector{X}); -} - -} // namespace one_binary - -namespace multiple_binaries { - -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - const size_t n_binaries = 10; - - auto X = std::make_shared(input_type, input_shape); - - auto tanh0 = std::make_shared(X); - - NodePtr in_op = tanh0; - for (size_t i = 0; i < n_binaries; ++i) { - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - if (!binary_gather_input_idx) - in_op = binary_factory->create(in_op, in_constant); - else - in_op = binary_factory->create(in_constant, in_op); - } - - auto tanh = std::make_shared(in_op); - - auto gather0 = make_gather(in_op, gather_forward, /* axis */ 1); - - return std::make_shared(ov::OutputVector{gather0, tanh}, ov::ParameterVector{X}); -} - -} // namespace multiple_binaries - -} // namespace output_consumers - -namespace input_node_consumers { - -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - auto tanh0 = std::make_shared(X); - - NodePtr binary; - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - if (!binary_gather_input_idx) - binary = binary_factory->create(tanh0, in_constant); - else - binary = binary_factory->create(in_constant, tanh0); - - auto gather0 = make_gather(binary, gather_forward, /* axis */ 1); - - auto tanh1 = std::make_shared(tanh0); - - return std::make_shared(ov::OutputVector{gather0, tanh1}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - auto tanh0 = std::make_shared(X); - - auto gather0 = make_gather(tanh0, gather_forward, /* axis */ 1); - - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - - auto gather = make_gather(in_constant, gather_forward, /* axis */ 1); - - NodePtr binary; - if (!binary_gather_input_idx) - binary = binary_factory->create(gather0, gather); - else - binary = binary_factory->create(gather, gather0); - - auto tanh1 = std::make_shared(tanh0); - - return std::make_shared(ov::OutputVector{binary, tanh1}, ov::ParameterVector{X}); -} - -} // namespace input_node_consumers - -namespace output_transpose_mult_consumers { - -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - NodePtr binary; - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - if (!binary_gather_input_idx) - binary = binary_factory->create(X, in_constant); - else - binary = binary_factory->create(in_constant, X); - - auto gather0 = make_gather(binary, gather_forward, /* axis */ 1); - - auto tanh0 = std::make_shared(gather0); - auto tanh1 = std::make_shared(gather0); - - return std::make_shared(ov::OutputVector{tanh0, tanh1}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - auto gather0 = make_gather(X, gather_forward, /* axis */ 1); - - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - - auto gather = make_gather(in_constant, gather_forward, /* axis */ 1); - - NodePtr binary; - if (!binary_gather_input_idx) - binary = binary_factory->create(gather0, gather); - else - binary = binary_factory->create(gather, gather0); - - auto tanh0 = std::make_shared(binary); - auto tanh1 = std::make_shared(binary); - - return std::make_shared(ov::OutputVector{tanh0, tanh1}, ov::ParameterVector{X}); -} - -} // namespace output_transpose_mult_consumers - -namespace output_transpose_mult_transposes { - -std::shared_ptr CreateFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - NodePtr binary; - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - if (!binary_gather_input_idx) - binary = binary_factory->create(X, in_constant); - else - binary = binary_factory->create(in_constant, X); - - auto gather0 = make_gather(binary, gather_forward, /* axis */ 1); - - auto tanh0 = std::make_shared(gather0); - - auto gather1 = make_gather(binary, gather_forward, /* axis */ 1); - - auto tanh1 = std::make_shared(gather1); - - return std::make_shared(ov::OutputVector{tanh0, tanh1}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(BinaryFactoryPtr binary_factory, - element::Type input_type, - size_t binary_gather_input_idx) { - const Shape input_shape{1, 20}; - - auto X = std::make_shared(input_type, input_shape); - - auto gather0 = make_gather(X, gather_forward, /* axis */ 1); - - auto in_constant = std::make_shared(input_type, input_shape, Shape{1}); - - auto gather = make_gather(in_constant, gather_forward, /* axis */ 1); - - NodePtr binary; - if (!binary_gather_input_idx) - binary = binary_factory->create(gather0, gather); - else - binary = binary_factory->create(gather, gather0); - - auto tanh0 = std::make_shared(binary); - auto tanh1 = std::make_shared(binary); - - return std::make_shared(ov::OutputVector{tanh0, tanh1}, ov::ParameterVector{X}); -} - -} // namespace output_transpose_mult_transposes - -} // namespace backward - -using CreateGraphF = std::function< - std::shared_ptr(BinaryFactoryPtr binary_factory, element::Type input_type, size_t binary_gather_input_idx)>; - -struct CreateGraphFunctionDesc { - CreateGraphFunctionDesc() = default; - CreateGraphFunctionDesc(CreateGraphF a_model_factory, - CreateGraphF a_reference_model_factory, - std::string a_subtest_name) - : model_factory(a_model_factory), - reference_model_factory(a_reference_model_factory), - subtest_name(a_subtest_name) {} - CreateGraphF model_factory; - CreateGraphF reference_model_factory; - std::string subtest_name; -}; - -using TestBinaryParams = std::tuple; /*binary_gather_input_idx*/ - -class TransposeBinaryMultiSinkingFixture : public ::testing::WithParamInterface, - public TransformationTestsF { -public: - static std::string get_test_name(const testing::TestParamInfo& obj) { - BinaryFactoryPtr binary_factory; - PassFactoryPtr pass_factory; - CreateGraphFunctionDesc function_desc; - element::Type input_type; - size_t binary_gather_input_idx; - - std::tie(binary_factory, pass_factory, function_desc, input_type, binary_gather_input_idx) = obj.param; - - std::ostringstream test_name; - test_name << "binaryFactory=" << binary_factory->getTypeName() << "/"; - test_name << "passFactory=" << pass_factory->getTypeName() << "/"; - test_name << function_desc.subtest_name << "/"; - test_name << "inputType=" << input_type << "/"; - test_name << "binaryTransposeInputIdx=" << binary_gather_input_idx; - - return test_name.str(); - } -}; - -TEST_P(TransposeBinaryMultiSinkingFixture, CompareFunctions) { - BinaryFactoryPtr binary_factory; - PassFactoryPtr pass_factory; - CreateGraphFunctionDesc function_desc; - element::Type input_type; - size_t binary_gather_input_idx; - - std::tie(binary_factory, pass_factory, function_desc, input_type, binary_gather_input_idx) = this->GetParam(); - - model = function_desc.model_factory(binary_factory, input_type, binary_gather_input_idx); - model_ref = function_desc.reference_model_factory(binary_factory, input_type, binary_gather_input_idx); - pass_factory->registerPass(manager); -} - -#define SUBTEST(nmspace, subtest_name) \ - CreateGraphFunctionDesc(nmspace::CreateFunction, nmspace::CreateReferenceFunction, subtest_name) - -std::vector forward_subtests = { - SUBTEST(forward::input_transpose_consumers, "forwardInputTransposeConsumers"), - SUBTEST(forward::output_consumers::one_binary, "forwardOutputConsumers"), - SUBTEST(forward::input_node_consumers, "forwardInputNodeConsumers")}; - -std::vector backward_subtests = { - SUBTEST(backward::input_node_consumers, "backwardInputNodeConsumers"), - SUBTEST(backward::output_transpose_mult_consumers, "backwardOutputTransposeMultConsumers"), - SUBTEST(backward::output_transpose_mult_transposes, "outputTransposeMultTransposes")}; - -#undef SUBTEST - -INSTANTIATE_TEST_SUITE_P(GatherSinkingBinaryForwardMultiConsumersTestSuite, - TransposeBinaryMultiSinkingFixture, - ::testing::Combine(::testing::ValuesIn(binary_elementwise_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingBinaryForward)), - ::testing::ValuesIn(forward_subtests), - ::testing::Values(element::f32), - ::testing::ValuesIn(binary_transpose_input_indexes)), - TransposeBinaryMultiSinkingFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P(GatherSinkingBinaryBackwardMultiConsumersTestSuite, - TransposeBinaryMultiSinkingFixture, - ::testing::Combine(::testing::ValuesIn(binary_elementwise_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingBinaryBackward)), - ::testing::ValuesIn(backward_subtests), - ::testing::Values(element::f32), - ::testing::ValuesIn(binary_transpose_input_indexes)), - TransposeBinaryMultiSinkingFixture::get_test_name); - -namespace no_sinking { - -struct CreateGraphFunctionDesc { - CreateGraphFunctionDesc() = default; - CreateGraphFunctionDesc(CreateGraphF a_model_factory, std::string a_subtest_name) - : model_factory(a_model_factory), - subtest_name(a_subtest_name) {} - CreateGraphF model_factory; - std::string subtest_name; -}; - -using TestBinaryParams = std::tuple; /*binary_gather_input_idx*/ - -class TransposeBinaryMultiSinkingBinaryMultiConsumersFixture : public ::testing::WithParamInterface, - public TransformationTestsF { -public: - static std::string get_test_name(const testing::TestParamInfo& obj) { - BinaryFactoryPtr binary_factory; - PassFactoryPtr pass_factory; - CreateGraphFunctionDesc function_desc; - element::Type input_type; - size_t binary_gather_input_idx; - - std::tie(binary_factory, pass_factory, function_desc, input_type, binary_gather_input_idx) = obj.param; - - std::ostringstream test_name; - test_name << "binaryFactory=" << binary_factory->getTypeName() << "/"; - test_name << "passFactory=" << pass_factory->getTypeName() << "/"; - test_name << function_desc.subtest_name << "/"; - test_name << "inputType=" << input_type << "/"; - test_name << "binaryTransposeInputIdx=" << binary_gather_input_idx; - - return test_name.str(); - } -}; - -TEST_P(TransposeBinaryMultiSinkingBinaryMultiConsumersFixture, CompareFunctions) { - BinaryFactoryPtr binary_factory; - PassFactoryPtr pass_factory; - CreateGraphFunctionDesc function_desc; - element::Type input_type; - size_t binary_gather_input_idx; - - std::tie(binary_factory, pass_factory, function_desc, input_type, binary_gather_input_idx) = this->GetParam(); - - model = function_desc.model_factory(binary_factory, input_type, binary_gather_input_idx); - model_ref = model->clone(); - pass_factory->registerPass(manager); -} - -#define SUBTEST(nmspace, subtest_name) CreateGraphFunctionDesc(nmspace::CreateFunction, subtest_name) - -std::vector backward_subtests_binary_consumers = { - SUBTEST(backward::output_consumers::one_binary, "backwardOutputConsumersOneBinary"), - SUBTEST(backward::output_consumers::multiple_binaries, "backwardOutputConsumersMultipleBinaries"), -}; -#undef SUBTEST - -INSTANTIATE_TEST_SUITE_P(GatherSinkingBinaryBackwardBinaryMultiConsumersTestSuite, - TransposeBinaryMultiSinkingBinaryMultiConsumersFixture, - ::testing::Combine(::testing::ValuesIn(binary_elementwise_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingBinaryBackward)), - ::testing::ValuesIn(backward_subtests_binary_consumers), - ::testing::Values(element::f32), - ::testing::ValuesIn(binary_transpose_input_indexes)), - TransposeBinaryMultiSinkingBinaryMultiConsumersFixture::get_test_name); - -} // namespace no_sinking - -} // namespace mult_consumers - -} // namespace gather_sinking_binary_eltwise diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_fuse_test.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_fuse_test.cpp deleted file mode 100644 index a1c7bb75d34..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_fuse_test.cpp +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_fuse.hpp" - -#include "common_test_utils/ov_test_utils.hpp" -#include "gtest/gtest.h" -#include "openvino/frontend/manager.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/manager.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ov; -using namespace ov::opset12; - -using NodePtr = std::shared_ptr; - -namespace { - -std::shared_ptr make_gather(NodePtr input_node, const std::vector& indices, size_t axis) { - const ov::Shape& input_shape = input_node->get_output_shape(0); - auto gather_indexes_node = Constant::create(element::i64, ov::Shape{indices.size()}, indices); - - auto gather_axis_node = Constant::create(element::i64, Shape{}, {axis}); - - return std::make_shared(input_node, gather_indexes_node, gather_axis_node); -} - -} // namespace - -TEST(GatherSinkingFuse, Remove) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 3, 80}); - auto tanh0 = std::make_shared(input_params); - - auto input_gather = make_gather(tanh0, std::vector{2, 0, 1}, /* axis */ 1); - auto output_gather = make_gather(input_gather, std::vector{1, 2, 0}, /* axis */ 1); - - auto tanh1 = std::make_shared(output_gather); - const auto result = std::make_shared(tanh1); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 3, 80}); - auto tanh0 = std::make_shared(input_params); - - auto tanh1 = std::make_shared(tanh0); - const auto result = std::make_shared(tanh1); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} - -TEST(GatherSinkingFuse, DifferentAxis) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 3, 80}); - auto tanh0 = std::make_shared(input_params); - - auto input_gather = make_gather(tanh0, std::vector{2, 0, 1}, /* axis */ 1); - auto output_gather = make_gather(input_gather, std::vector{1, 2, 0}, /* axis */ 2); - - auto tanh1 = std::make_shared(output_gather); - const auto result = std::make_shared(tanh1); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function = function->clone(); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} - -TEST(GatherSinkingFuse, Combine) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 3, 80}); - auto tanh0 = std::make_shared(input_params); - - auto input_gather = make_gather(tanh0, std::vector{2, 0, 1}, /* axis */ 1); - auto output_gather = make_gather(input_gather, std::vector{1, 0, 2}, /* axis */ 1); - - auto tanh1 = std::make_shared(output_gather); - const auto result = std::make_shared(tanh1); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 3, 80}); - auto tanh0 = std::make_shared(input_params); - - auto gather = make_gather(tanh0, std::vector{0, 2, 1}, /* axis */ 1); - - auto tanh1 = std::make_shared(gather); - const auto result = std::make_shared(tanh1); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} \ No newline at end of file diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_general_test.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_general_test.cpp deleted file mode 100644 index 8879695d0b2..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_general_test.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "common_test_utils/ov_test_utils.hpp" -#include "gather_sinking_test_utils.hpp" -#include "gtest/gtest.h" -#include "openvino/core/model.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/manager.hpp" -#include "transformations/gather_sinking.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ov; -using namespace ov::opset12; - -TEST(GatherSinkingGeneral, General) { - std::shared_ptr function; - { - auto input_params1 = std::make_shared(element::Type_t::f32, Shape{20, 20}); - auto input_params2 = std::make_shared(element::Type_t::f32, Shape{20, 20}); - - auto gather = make_gather(input_params1, gather_forward, /* axis */ 1); - - auto tanh = std::make_shared(input_params2); - auto mult = std::make_shared(gather, tanh); - auto sinh = std::make_shared(mult); - - const auto result = std::make_shared(sinh); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params1, input_params2}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params1 = std::make_shared(element::Type_t::f32, Shape{20, 20}); - auto input_params2 = std::make_shared(element::Type_t::f32, Shape{20, 20}); - - auto gather1 = make_gather(input_params2, gather_backward, /* axis */ 1); - - auto tanh = std::make_shared(gather1); - auto mult = std::make_shared(input_params1, tanh); - auto sinh = std::make_shared(mult); - - auto gather2 = make_gather(sinh, gather_forward, /* axis */ 1); - - const auto result = std::make_shared(gather2); - reference_function = - std::make_shared(OutputVector{result}, ParameterVector{input_params1, input_params2}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_matmul_test.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_matmul_test.cpp deleted file mode 100644 index f81e1420bf1..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_matmul_test.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_matmul.hpp" - -#include "common_test_utils/ov_test_utils.hpp" -#include "gather_sinking_test_utils.hpp" -#include "gtest/gtest.h" -#include "openvino/core/model.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/manager.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ov; -using namespace ov::opset12; - -TEST(GatherSinkingMatMul, Forward) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{20, 20}); - - auto gather = make_gather(input_params, gather_forward, /* axis */ 1); - - auto input_const1 = Constant::create(ov::element::f32, {20, 20}, {1}); - auto matmul1 = std::make_shared(gather, input_const1); - - auto input_const2 = Constant::create(ov::element::f32, {20, 20}, {1}); - auto matmul2 = std::make_shared(input_const2, matmul1); - - const auto result = std::make_shared(matmul2); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{20, 20}); - auto input_const = Constant::create(ov::element::f32, {20, 20}, {1}); - - auto gather = make_gather(input_const, gather_backward, /* axis */ 0); - - auto input_const1 = Constant::create(ov::element::f32, {20, 20}, {1}); - auto matmul1 = std::make_shared(input_params, gather); - - auto input_const2 = Constant::create(ov::element::f32, {20, 20}, {1}); - auto matmul2 = std::make_shared(input_const2, matmul1); - - const auto result = std::make_shared(matmul2); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} - -TEST(GatherSinkingMatMul, Backward) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{20, 20}); - - auto input_const1 = Constant::create(ov::element::f32, {20, 20}, {1}); - auto matmul1 = std::make_shared(input_params, input_const1); - - auto input_const2 = Constant::create(ov::element::f32, {20, 20}, {1}); - auto matmul2 = std::make_shared(input_const2, matmul1); - - auto gather = make_gather(matmul2, gather_forward, /* axis */ 1); - - const auto result = std::make_shared(gather); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{20, 20}); - auto input_const = Constant::create(ov::element::f32, {20, 20}, {1}); - - auto gather = make_gather(input_const, gather_forward, /* axis */ 1); - - auto input_const1 = Constant::create(ov::element::f32, {20, 20}, {1}); - auto matmul1 = std::make_shared(input_params, gather); - - auto input_const2 = Constant::create(ov::element::f32, {20, 20}, {1}); - auto matmul2 = std::make_shared(input_const2, matmul1); - - const auto result = std::make_shared(matmul2); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_reshape_test.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_reshape_test.cpp deleted file mode 100644 index c9d546da8c0..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_reshape_test.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_reshape.hpp" - -#include "common_test_utils/ov_test_utils.hpp" -#include "gather_sinking_test_utils.hpp" -#include "gtest/gtest.h" -#include "openvino/core/model.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/manager.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ov; -using namespace ov::opset12; - -using NodePtr = std::shared_ptr; -using ModelPtr = std::shared_ptr; -using Output = ov::Output; - -TEST(GatherSinkingReshape, Backward) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 168}); - - auto reshape_const1 = Constant::create(element::i64, ov::Shape{4}, ov::Shape{1, 168, 1, 1}); - auto reshape1 = std::make_shared(input_params, reshape_const1, false); - - auto reshape_const2 = Constant::create(element::i64, ov::Shape{5}, ov::Shape{1, 168, 1, 1, 1}); - auto reshape2 = std::make_shared(reshape1, reshape_const2, false); - - auto gather = make_gather(reshape2, gather_forward, /* axis */ 1); - - const auto result = std::make_shared(gather); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 168}); - - auto gather = make_gather(input_params, gather_forward, /* axis */ 1); - - auto reshape_const1 = Constant::create(element::i64, ov::Shape{4}, ov::Shape{1, 168, 1, 1}); - auto reshape1 = std::make_shared(gather, reshape_const1, false); - - auto reshape_const2 = Constant::create(element::i64, ov::Shape{5}, ov::Shape{1, 168, 1, 1, 1}); - auto reshape2 = std::make_shared(reshape1, reshape_const2, false); - - const auto result = std::make_shared(reshape2); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_split_test.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_split_test.cpp deleted file mode 100644 index e394f3d4b7e..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_split_test.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_split.hpp" - -#include "common_test_utils/ov_test_utils.hpp" -#include "gather_sinking_test_utils.hpp" -#include "gtest/gtest.h" -#include "openvino/core/model.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/manager.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ov; -using namespace ov::opset12; - -TEST(GatherSinkingSplit, Backward) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{20, 20}); - - auto split_axis1 = Constant::create(element::i64, ov::Shape{}, ov::Shape{0}); - auto split1 = std::make_shared(input_params, split_axis1, 2); - - auto split_axis2 = Constant::create(element::i64, ov::Shape{}, ov::Shape{0}); - auto split2 = std::make_shared(split1, split_axis2, 2); - - auto gather = make_gather(split2, gather_forward, /* axis */ 1); - - const auto result = std::make_shared(gather); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{20, 20}); - - auto gather = make_gather(input_params, gather_forward, /* axis */ 1); - - auto split_axis1 = Constant::create(element::i64, ov::Shape{}, ov::Shape{0}); - auto split1 = std::make_shared(gather, split_axis1, 2); - - auto split_axis2 = Constant::create(element::i64, ov::Shape{}, ov::Shape{0}); - auto split2 = std::make_shared(split1, split_axis2, 2); - - const auto result = std::make_shared(split2); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_test.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_test.cpp deleted file mode 100644 index 3fde2aec9d7..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_test.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking.hpp" - -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "gtest/gtest.h" -#include "transformations/gather_sinking_matmul.hpp" -#include "transformations/gather_sinking_reshape.hpp" -#include "transformations/gather_sinking_split.hpp" -#include "transformations/replace_gna_nhwc_layers.hpp" - -using namespace ov; -using namespace ov::opset10; - -TEST(TransposeNCHW, Convolution) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 1, 41, 1}); - auto kernel = Constant::create(ov::element::f32, {4, 1, 3, 1}, {1}); - - auto convolution = std::make_shared(input_params, - kernel, - Strides{2, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - - const auto result = std::make_shared(convolution); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 1, 41, 1}); - - auto transpose_before_const = Constant::create(element::i32, Shape{4}, {0, 2, 3, 1}); - - auto transpose_before = std::make_shared(input_params, transpose_before_const); - - auto kernel = Constant::create(ov::element::f32, {4, 1, 3, 1}, {1}); - - auto transpose_conv_const = Constant::create(element::i32, Shape{4}, {0, 2, 3, 1}); - - auto transpose_conv_before = std::make_shared(input_params, transpose_conv_const); - - auto transpose_conv_constant = std::make_shared(kernel, transpose_conv_const); - - auto convolution = std::make_shared(transpose_before, - transpose_conv_constant, - Strides{2, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 0}, - Strides{1, 1}); - - auto transpose_after_const = Constant::create(element::i32, Shape{4}, {0, 3, 1, 2}); - - auto transpose_after = std::make_shared(convolution, transpose_after_const); - - const auto result = std::make_shared(transpose_after); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} - -TEST(TransposeNCHW, MaxPool) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 1, 41, 1}); - - auto max_pool = - std::make_shared(input_params, Strides{2, 1}, Shape{0, 0}, Shape{0, 0}, Shape{4, 1}); - - const auto result = std::make_shared(max_pool); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 1, 41, 1}); - - auto transpose_before_const = Constant::create(element::i32, Shape{4}, {0, 2, 3, 1}); - - auto transpose_before = std::make_shared(input_params, transpose_before_const); - - auto max_pool = std::make_shared(transpose_before, - Strides{2, 1}, - Shape{0, 0}, - Shape{0, 0}, - Shape{4, 1}); - - auto transpose_after_const = Constant::create(element::i32, Shape{4}, {0, 3, 1, 2}); - - auto transpose_after = std::make_shared(max_pool, transpose_after_const); - - const auto result = std::make_shared(transpose_after); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_test_utils.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_test_utils.cpp deleted file mode 100644 index de775ed10c8..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_test_utils.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "gather_sinking_test_utils.hpp" - -#include "openvino/opsets/opset12.hpp" - -using namespace ov; -using namespace ov::opset12; - -void shift_left(std::vector& vec, size_t k) { - if (k > vec.size()) - return; - std::vector buffer(k); - std::copy(vec.begin(), vec.begin() + k, buffer.begin()); - - for (int i = k; i < vec.size(); ++i) { - vec[i - k] = vec[i]; - } - - std::copy(buffer.begin(), buffer.end(), vec.end() - k); -} - -void shift_right(std::vector& vec, size_t k) { - if (k > vec.size()) - return; - std::vector buffer(k); - std::copy(vec.end() - k, vec.end(), buffer.begin()); - - for (int i = vec.size() - 1 - k; i >= 0; --i) { - vec[i + k] = vec[i]; - } - - std::copy(buffer.begin(), buffer.end(), vec.begin()); -} - -std::vector gather_forward(size_t size, size_t initial_value) { - std::vector vec(size); - std::iota(vec.begin(), vec.end(), initial_value); - shift_left(vec, 2); - return vec; -} - -std::vector gather_backward(size_t size, size_t initial_value) { - std::vector vec(size); - std::iota(vec.begin(), vec.end(), initial_value); // Not the same as in binary tests - shift_right(vec, 2); - return vec; -} diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_test_utils.hpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_test_utils.hpp deleted file mode 100644 index d89eb0ee91f..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_test_utils.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include "openvino/opsets/opset12.hpp" - -void shift_left(std::vector& vec, size_t k); - -void shift_right(std::vector& vec, size_t k); - -std::vector gather_forward(size_t size, size_t initial_value); - -std::vector gather_backward(size_t size, size_t initial_value); - -template -std::shared_ptr make_gather(std::shared_ptr input_node, - CreateIndicesF create_indices_func, - size_t axis) { - const ov::Shape& input_shape = input_node->get_output_shape(0); - const std::vector indexes = create_indices_func(input_shape[axis], 0); - - auto gather_indexes_node = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{indexes.size()}, indexes); - - auto gather_axis_node = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {axis}); - - return std::make_shared(input_node->output(0), gather_indexes_node, gather_axis_node); -} diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_transpose_reshape.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_transpose_reshape.cpp deleted file mode 100644 index 732e85a4b79..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_transpose_reshape.cpp +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_transpose_reshape.hpp" - -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "gtest/gtest.h" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/manager.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ov; -using namespace ov::opset12; - -namespace testing { - -TEST(GatherSinkingTransposeReshape, ForwardSinking) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 3, 4}); - auto tanh0 = std::make_shared(input_params); - - auto transpose_order = std::make_shared(element::u64, Shape{3}, Shape{0, 2, 1}); - auto transpose = std::make_shared(tanh0, transpose_order); - - auto reshape_const = std::make_shared(element::i64, Shape{2}, std::vector{1, -1}); - auto reshape = std::make_shared(transpose, reshape_const, false); - - auto tanh1 = std::make_shared(reshape); - const auto result = std::make_shared(tanh1); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 3, 4}); - auto tanh0 = std::make_shared(input_params); - - auto reshape_const = std::make_shared(element::i64, Shape{2}, std::vector{1, -1}); - auto reshape = std::make_shared(tanh0, reshape_const, false); - - std::vector gather_indices = {0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11}; - auto gather_indices_const = - std::make_shared(element::i64, Shape{gather_indices.size()}, gather_indices); - auto gather_axis_const = std::make_shared(element::i64, Shape{}, 1); - auto gather = std::make_shared(reshape, gather_indices_const, gather_axis_const); - - auto tanh1 = std::make_shared(gather); - const auto result = std::make_shared(tanh1); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -TEST(GatherSinkingTransposeReshape, ForwardSinking3D) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 1, 14, 4}); - auto tanh0 = std::make_shared(input_params); - - auto transpose_order = std::make_shared(element::u64, Shape{4}, Shape{0, 3, 1, 2}); - auto transpose = std::make_shared(tanh0, transpose_order); - - auto reshape_const = std::make_shared(element::i64, Shape{2}, std::vector{1, 56}); - auto reshape = std::make_shared(transpose, reshape_const, false); - - auto tanh1 = std::make_shared(reshape); - const auto result = std::make_shared(tanh1); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 1, 14, 4}); - auto tanh0 = std::make_shared(input_params); - - auto reshape_const = std::make_shared(element::i64, Shape{2}, std::vector{1, -1}); - auto reshape = std::make_shared(tanh0, reshape_const, false); - - auto generate_indices = []() -> std::vector { - std::vector indices; - for (int j = 0; j < 4; ++j) { - for (int i = 0; i < 14; ++i) { - indices.push_back(j + 4 * i); - } - } - return indices; - }; - auto gather_indices = generate_indices(); - auto gather_indices_const = - std::make_shared(element::i64, Shape{gather_indices.size()}, gather_indices); - auto gather_axis_const = std::make_shared(element::i64, Shape{}, 1); - auto gather = std::make_shared(reshape, gather_indices_const, gather_axis_const); - - auto tanh1 = std::make_shared(gather); - const auto result = std::make_shared(tanh1); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} - -TEST(GatherSinkingTransposeReshape, BackwardSinking) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 1, 2, 2}); - auto tanh0 = std::make_shared(input_params); - - auto reshape_const = std::make_shared(element::i64, Shape{4}, std::vector{1, 2, 1, 2}); - auto reshape = std::make_shared(tanh0, reshape_const, false); - - auto transpose_order = std::make_shared(element::u64, Shape{4}, Shape{0, 2, 3, 1}); - auto transpose = std::make_shared(reshape, transpose_order); - - auto tanh1 = std::make_shared(transpose); - const auto result = std::make_shared(tanh1); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 1, 2, 2}); - auto tanh0 = std::make_shared(input_params); - - auto reshape_const1 = std::make_shared(element::i64, Shape{4}, std::vector{1, 2, 1, 2}); - auto reshape1 = std::make_shared(tanh0, reshape_const1, false); - - auto reshape_const2 = std::make_shared(element::i64, Shape{4}, std::vector{1, 1, 2, 2}); - auto reshape2 = std::make_shared(reshape1, reshape_const2, false); - - auto tanh1 = std::make_shared(reshape2); - const auto result = std::make_shared(tanh1); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_ts_split_test.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_ts_split_test.cpp deleted file mode 100644 index 48c12f124c9..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_ts_split_test.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// -#include "common_test_utils/ov_test_utils.hpp" -#include "gather_sinking_test_utils.hpp" -#include "gtest/gtest.h" -#include "openvino/core/model.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/manager.hpp" -#include "transformations/init_node_info.hpp" -#include "transformations/ts_split_backward.hpp" - -using namespace ov; -using namespace ov::opset12; - -namespace { -std::vector TSSplit_Backward_indexes(size_t size, size_t initial_value) { - return std::vector{0, 2, 4, 6, 1, 3, 5, 7}; -} -} // namespace - -TEST(TSSplit, Backward) { - std::shared_ptr function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 4, 1, 2}); - auto split_axis = Constant::create(element::i64, ov::Shape{}, ov::Shape{1}); - auto split = std::make_shared(input_params, split_axis, 1); - auto transpose_const = Constant::create(element::i64, Shape{4}, {0, 2, 3, 1}); - auto transpose = std::make_shared(split->output(0), transpose_const); - const auto result = std::make_shared(transpose); - function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - std::shared_ptr orig_function = function->clone(); - ov::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - std::shared_ptr reference_function; - { - auto input_params = std::make_shared(element::Type_t::f32, Shape{1, 4, 1, 2}); - auto reshape_const1 = Constant::create(element::i64, ov::Shape{2}, ov::Shape{1, 8}); - auto reshape1 = std::make_shared(input_params, reshape_const1, false); - auto gather = make_gather(reshape1, TSSplit_Backward_indexes, /* axis */ 1); - auto split_axis = Constant::create(element::i64, ov::Shape{}, ov::Shape{1}); - auto split_lengths = Constant::create(element::i64, ov::Shape{1}, ov::Shape{8}); - auto split = std::make_shared(gather, split_axis, split_lengths); - auto reshape_const2 = Constant::create(element::i64, ov::Shape{4}, ov::Shape{1, 1, 2, 4}); - auto reshape2 = std::make_shared(split->output(0), reshape_const2, false); - const auto result = std::make_shared(reshape2); - reference_function = std::make_shared(OutputVector{result}, ParameterVector{input_params}); - } - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_unary_test.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_unary_test.cpp deleted file mode 100644 index fddcf806aa0..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_sinking_unary_test.cpp +++ /dev/null @@ -1,562 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/gather_sinking_unary.hpp" - -#include "common_test_utils/ov_test_utils.hpp" -#include "gtest/gtest.h" -#include "openvino/frontend/manager.hpp" -#include "openvino/opsets/opset12.hpp" -#include "openvino/pass/manager.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ov; -using namespace ov::opset12; - -using NodePtr = std::shared_ptr; - -namespace { -std::string to_string(const Shape& shape) { - std::ostringstream result; - result << "{"; - for (size_t idx = 0; idx < shape.size(); ++idx) { - if (idx) - result << ","; - result << shape[idx]; - } - result << "}"; - return result.str(); -} - -std::vector GenerateVector(size_t size, size_t initial_value) { - std::vector vec(size); - std::iota(vec.begin(), vec.end(), initial_value); - return vec; -} - -std::vector MakeGatherIndexes(size_t size) { - std::vector indexes = GenerateVector(size, 0); - std::next_permutation(indexes.begin(), indexes.end()); - return indexes; -} - -std::shared_ptr MakeGather(NodePtr input_node) { - const ov::Shape& input_shape = input_node->get_output_shape(0); - const size_t input_shape_product = - std::accumulate(input_shape.begin(), input_shape.end(), 1, std::multiplies()); - const std::vector indexes = MakeGatherIndexes(input_shape_product); - auto gather_indexes_node = Constant::create(element::i64, ov::Shape{indexes.size()}, indexes); - - const size_t axis = 1; - auto gather_axis_node = Constant::create(element::i64, Shape{}, {axis}); - - return std::make_shared(input_node, gather_indexes_node, gather_axis_node); -} - -} // namespace - -class IUnaryFactory { -public: - IUnaryFactory(const std::string& type_name) : type_name_(type_name) {} - virtual ~IUnaryFactory() = default; - virtual NodePtr create(NodePtr parent_node) const = 0; - - const std::string& getTypeName() const { - return type_name_; - } - -private: - const std::string type_name_; -}; - -using UnaryFactoryPtr = std::shared_ptr; - -template -class UnaryFactory : public IUnaryFactory { -public: - UnaryFactory(const std::string& type_name) : IUnaryFactory(type_name) {} - NodePtr create(NodePtr parent_node) const override { - return std::make_shared(parent_node); - } -}; - -template <> -NodePtr UnaryFactory::create(NodePtr parent_node) const { - return std::make_shared(parent_node, 0.1); -} - -template <> -NodePtr UnaryFactory::create(NodePtr parent_node) const { - return std::make_shared(parent_node, 0.1, 0.2); -} - -template <> -NodePtr UnaryFactory::create(NodePtr parent_node) const { - return std::make_shared(parent_node, element::f64); -} - -template -UnaryFactoryPtr CreateUnaryFactory(const std::string& type_name) { - return std::make_shared>(type_name); -} - -// ---------------------------------------------------------------------------- - -class IPassFactory { -public: - IPassFactory(const std::string& type_name) : type_name_(type_name) {} - virtual ~IPassFactory() = default; - virtual void registerPass(ov::pass::Manager& pass_manager) const = 0; - const std::string& getTypeName() const { - return type_name_; - } - -private: - const std::string type_name_; -}; - -using PassFactoryPtr = std::shared_ptr; - -template -class PassFactory : public IPassFactory { -public: - PassFactory(const std::string& type_name) : IPassFactory(type_name) {} - void registerPass(ov::pass::Manager& pass_manager) const override { - pass_manager.register_pass(); - } -}; - -#define CREATE_PASS_FACTORY(pass_name) std::make_shared>(#pass_name) - -#undef CREATE_UNARY_FACTORY -#define CREATE_UNARY_FACTORY(type_name) CreateUnaryFactory(#type_name) - -// ---------------------------------------------------------------------------- - -using FloatPtr = std::unique_ptr; - -using CreateGraphF = std::function(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type)>; - -using TestParams = std::tuple; /* input type */ - -class GatherSinkingUnaryTestFixture : public ::testing::WithParamInterface, public TransformationTestsF { -public: - static std::string get_test_name(const testing::TestParamInfo& obj) { - UnaryFactoryPtr unary_factory; - PassFactoryPtr pass_factory; - size_t num_unary_ops; - CreateGraphF model_factory; - CreateGraphF reference_model_factory; - Shape input_shape; - element::Type input_type; - std::tie(unary_factory, - pass_factory, - num_unary_ops, - model_factory, - reference_model_factory, - input_shape, - input_type) = obj.param; - - std::ostringstream test_name; - test_name << "unaryFactory=" << unary_factory->getTypeName() << "/"; - test_name << "numUnaryOps=" << num_unary_ops << "/"; - test_name << "inputShape=" << to_string(input_shape) << "/"; - test_name << "unaryFactory=" << unary_factory->getTypeName() << "/"; - test_name << "passFactory=" << pass_factory->getTypeName() << "/"; - test_name << "inputType=" << input_type; - - return test_name.str(); - } -}; - -namespace { - -std::string GetFinalNodeName(std::shared_ptr model, int index = 0) { - NodePtr result_node = model->get_results()[index]; - return result_node->get_input_node_ptr(0)->get_friendly_name(); -} - -std::shared_ptr CreateFunctionTransposeBefore(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type) { - auto X = std::make_shared(input_type, input_shape); - - auto gather = MakeGather(X); - - NodePtr in_op = gather; - for (size_t i = 0; i < num_unary_ops; ++i) { - in_op = unary_factory->create(in_op); - } - - return std::make_shared(in_op, ov::ParameterVector{X}); -} - -std::shared_ptr CreateFunctionTransposeAfter(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type) { - auto X = std::make_shared(input_type, input_shape); - - NodePtr in_op = X; - for (size_t i = 0; i < num_unary_ops; ++i) { - in_op = unary_factory->create(in_op); - } - - auto gather = MakeGather(in_op); - - return std::make_shared(gather, ov::ParameterVector{X}); -} - -static NodePtr CreateReshape(NodePtr parent_node) { - const Shape& input_shape = parent_node->get_output_shape(0); - const size_t mul = std::accumulate(input_shape.begin(), input_shape.end(), (size_t)1, std::multiplies()); - auto reshape_const = std::make_shared(element::u64, Shape{1}, Shape{mul}); - return std::make_shared(parent_node, reshape_const, false); -} - -namespace mult_consumers_last_node { -namespace with_reshape { - -std::shared_ptr CreateFunctionTransposeAfter(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type) { - auto X = std::make_shared(input_type, input_shape); - - NodePtr in_op = X; - for (size_t i = 0; i < num_unary_ops; ++i) { - in_op = unary_factory->create(in_op); - } - - auto gather = MakeGather(in_op); - - auto reshape1 = CreateReshape(gather); - auto reshape2 = CreateReshape(gather); - - return std::make_shared(ov::OutputVector{reshape1, reshape2}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateFunctionTransposeBefore(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type) { - auto X = std::make_shared(input_type, input_shape); - - auto gather = MakeGather(X); - - NodePtr in_op = gather; - for (size_t i = 0; i < num_unary_ops; ++i) { - in_op = unary_factory->create(in_op); - } - - auto reshape1 = CreateReshape(in_op); - auto reshape2 = CreateReshape(in_op); - - return std::make_shared(ov::OutputVector{reshape1, reshape2}, ov::ParameterVector{X}); -} -} // namespace with_reshape - -namespace with_eltwise { - -std::shared_ptr CreateFunctionTransposeAfter(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type) { - auto X = std::make_shared(input_type, input_shape); - - NodePtr in_op = X; - for (size_t i = 0; i < num_unary_ops; ++i) { - in_op = unary_factory->create(in_op); - } - - auto sinh = std::make_shared(in_op); - - auto gather0 = MakeGather(sinh); - - auto cosh = std::make_shared(in_op); - - auto gather1 = MakeGather(cosh); - - return std::make_shared(ov::OutputVector{gather0, gather1}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateFunctionTransposeBefore(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type) { - auto X = std::make_shared(input_type, input_shape); - - auto gather0 = MakeGather(X); - - NodePtr in_op = gather0; - for (size_t i = 0; i < num_unary_ops; ++i) { - in_op = unary_factory->create(in_op); - } - - auto sinh = std::make_shared(in_op); - auto cosh = std::make_shared(in_op); - - return std::make_shared(ov::OutputVector{sinh, cosh}, ov::ParameterVector{X}); -} - -} // namespace with_eltwise -} // namespace mult_consumers_last_node - -namespace mult_consumers_first_node { -namespace backward { - -std::shared_ptr CreateFunction(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type) { - auto X = std::make_shared(input_type, input_shape); - ov::OutputVector outputs; - - NodePtr in_op = X; - for (size_t i = 0; i < num_unary_ops; ++i) { - in_op = unary_factory->create(in_op); - auto cosh = std::make_shared(in_op); - outputs.push_back(cosh); - } - - auto gather0 = MakeGather(in_op); - - outputs.push_back(gather0); - - return std::make_shared(outputs, ov::ParameterVector{X}); -} - -} // namespace backward - -namespace backward_mult_transposes { - -std::shared_ptr CreateFunction(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type) { - auto X = std::make_shared(input_type, input_shape); - - NodePtr in_op = X; - for (size_t i = 0; i < num_unary_ops; ++i) { - in_op = unary_factory->create(in_op); - } - - auto gather0 = MakeGather(in_op); - - auto tanh0 = std::make_shared(gather0); - - auto gather1 = MakeGather(in_op); - - auto tanh1 = std::make_shared(gather1); - - return std::make_shared(ov::OutputVector{tanh0, tanh1}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type) { - auto X = std::make_shared(input_type, input_shape); - - auto gather0 = MakeGather(X); - - NodePtr in_op = gather0; - for (size_t i = 0; i < num_unary_ops; ++i) { - in_op = unary_factory->create(in_op); - } - - auto tanh0 = std::make_shared(in_op); - auto tanh1 = std::make_shared(in_op); - - return std::make_shared(ov::OutputVector{tanh0, tanh1}, ov::ParameterVector{X}); -} - -} // namespace backward_mult_transposes - -namespace forward { - -std::shared_ptr CreateFunction(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type) { - auto X = std::make_shared(input_type, input_shape); - - auto sinh = std::make_shared(X); - - auto gather0 = MakeGather(sinh); - - auto reshape = CreateReshape(gather0); - - NodePtr in_op = gather0; - for (size_t i = 0; i < num_unary_ops; ++i) { - in_op = unary_factory->create(in_op); - } - - return std::make_shared(ov::OutputVector{in_op, reshape}, ov::ParameterVector{X}); -} - -std::shared_ptr CreateReferenceFunction(UnaryFactoryPtr unary_factory, - size_t num_unary_ops, - const Shape& input_shape, - element::Type input_type) { - auto X = std::make_shared(input_type, input_shape); - - auto sinh = std::make_shared(X); - - auto gather0 = MakeGather(sinh); - - auto reshape = CreateReshape(gather0); - - NodePtr in_op = sinh; - for (size_t i = 0; i < num_unary_ops; ++i) { - in_op = unary_factory->create(in_op); - } - - auto gather1 = MakeGather(in_op); - - return std::make_shared(ov::OutputVector{gather1, reshape}, ov::ParameterVector{X}); -} - -} // namespace forward -} // namespace mult_consumers_first_node - -std::vector unary_factories = { - CREATE_UNARY_FACTORY(Clamp), CREATE_UNARY_FACTORY(Elu), CREATE_UNARY_FACTORY(SoftPlus), - CREATE_UNARY_FACTORY(LogicalNot), CREATE_UNARY_FACTORY(Convert), CREATE_UNARY_FACTORY(Abs), - CREATE_UNARY_FACTORY(Acos), CREATE_UNARY_FACTORY(Asin), CREATE_UNARY_FACTORY(Asinh), - CREATE_UNARY_FACTORY(Atan), CREATE_UNARY_FACTORY(Ceiling), CREATE_UNARY_FACTORY(Cos), - CREATE_UNARY_FACTORY(Cosh), CREATE_UNARY_FACTORY(Erf), CREATE_UNARY_FACTORY(Exp), - CREATE_UNARY_FACTORY(Gelu), CREATE_UNARY_FACTORY(HSigmoid), CREATE_UNARY_FACTORY(HSwish), - CREATE_UNARY_FACTORY(Log), CREATE_UNARY_FACTORY(Negative), CREATE_UNARY_FACTORY(Relu), - CREATE_UNARY_FACTORY(Sigmoid), CREATE_UNARY_FACTORY(Sign), CREATE_UNARY_FACTORY(Sin), - CREATE_UNARY_FACTORY(Sinh), CREATE_UNARY_FACTORY(SoftSign), CREATE_UNARY_FACTORY(Sqrt), - CREATE_UNARY_FACTORY(Tan), CREATE_UNARY_FACTORY(Tanh)}; - -std::vector unary_operations_numbers = {1, 10}; - -} // namespace - -TEST_P(GatherSinkingUnaryTestFixture, CompareFunctions) { - UnaryFactoryPtr unary_factory; - PassFactoryPtr pass_factory; - size_t num_unary_ops; - CreateGraphF model_factory; - CreateGraphF reference_model_factory; - Shape input_shape; - element::Type input_type; - std::tie(unary_factory, - pass_factory, - num_unary_ops, - model_factory, - reference_model_factory, - input_shape, - input_type) = this->GetParam(); - - model = model_factory(unary_factory, num_unary_ops, input_shape, input_type); - model_ref = reference_model_factory(unary_factory, num_unary_ops, input_shape, input_type); - pass_factory->registerPass(manager); -} - -INSTANTIATE_TEST_SUITE_P(GatherSinkingUnaryForwardTestSuite, - GatherSinkingUnaryTestFixture, - ::testing::Combine(::testing::ValuesIn(unary_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingUnaryForward)), - ::testing::ValuesIn(unary_operations_numbers), - ::testing::Values(CreateFunctionTransposeBefore), - ::testing::Values(CreateFunctionTransposeAfter), - ::testing::Values(Shape{1, 96, 55, 55}), - ::testing::Values(element::f32)), - GatherSinkingUnaryTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P(GatherSinkingUnaryBackwardTestSuite, - GatherSinkingUnaryTestFixture, - ::testing::Combine(::testing::ValuesIn(unary_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingUnaryBackward)), - ::testing::ValuesIn(unary_operations_numbers), - ::testing::Values(CreateFunctionTransposeAfter), - ::testing::Values(CreateFunctionTransposeBefore), - ::testing::Values(Shape{1, 96, 55, 55}), - ::testing::Values(element::f32)), - GatherSinkingUnaryTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingUnaryForwardMultConsumersTestSuiteLastNodeReshape, - GatherSinkingUnaryTestFixture, - ::testing::Combine(::testing::ValuesIn(unary_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingUnaryForward)), - ::testing::ValuesIn(unary_operations_numbers), - ::testing::Values(mult_consumers_last_node::with_reshape::CreateFunctionTransposeBefore), - ::testing::Values(mult_consumers_last_node::with_reshape::CreateFunctionTransposeAfter), - ::testing::Values(Shape{1, 96, 55, 55}), - ::testing::Values(element::f32)), - GatherSinkingUnaryTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingUnaryBackwardMultConsumersTestSuiteLastNodeReshape, - GatherSinkingUnaryTestFixture, - ::testing::Combine(::testing::ValuesIn(unary_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingUnaryBackward)), - ::testing::ValuesIn(unary_operations_numbers), - ::testing::Values(mult_consumers_last_node::with_reshape::CreateFunctionTransposeAfter), - ::testing::Values(mult_consumers_last_node::with_reshape::CreateFunctionTransposeBefore), - ::testing::Values(Shape{1, 96, 55, 55}), - ::testing::Values(element::f32)), - GatherSinkingUnaryTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingUnaryForwardMultConsumersTestSuiteLastNodeEltwise, - GatherSinkingUnaryTestFixture, - ::testing::Combine(::testing::ValuesIn(unary_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingUnaryForward)), - ::testing::ValuesIn(unary_operations_numbers), - ::testing::Values(mult_consumers_last_node::with_eltwise::CreateFunctionTransposeBefore), - ::testing::Values(mult_consumers_last_node::with_eltwise::CreateFunctionTransposeAfter), - ::testing::Values(Shape{1, 96, 55, 55}), - ::testing::Values(element::f32)), - GatherSinkingUnaryTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingUnaryForwardMultConsumersTestSuiteFirstNode, - GatherSinkingUnaryTestFixture, - ::testing::Combine(::testing::ValuesIn(unary_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingUnaryForward)), - ::testing::ValuesIn(unary_operations_numbers), - ::testing::Values(mult_consumers_first_node::forward::CreateFunction), - ::testing::Values(mult_consumers_first_node::forward::CreateReferenceFunction), - ::testing::Values(Shape{1, 96, 55, 55}), - ::testing::Values(element::f32)), - GatherSinkingUnaryTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P(GatherSinkingUnaryBackwardMultConsumersTestSuiteFirstNode, - GatherSinkingUnaryTestFixture, - ::testing::Combine(::testing::ValuesIn(unary_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingUnaryBackward)), - ::testing::ValuesIn(unary_operations_numbers), - ::testing::Values(mult_consumers_first_node::backward::CreateFunction), - ::testing::Values(mult_consumers_first_node::backward::CreateFunction), - ::testing::Values(Shape{1, 96, 55, 55}), - ::testing::Values(element::f32)), - GatherSinkingUnaryTestFixture::get_test_name); - -INSTANTIATE_TEST_SUITE_P( - GatherSinkingUnaryBackwardMultTransposeConsumersTestSuiteFirstNode, - GatherSinkingUnaryTestFixture, - ::testing::Combine(::testing::ValuesIn(unary_factories), - ::testing::Values(CREATE_PASS_FACTORY(GatherSinkingUnaryBackward)), - ::testing::ValuesIn(unary_operations_numbers), - ::testing::Values(mult_consumers_first_node::backward_mult_transposes::CreateFunction), - ::testing::Values(mult_consumers_first_node::backward_mult_transposes::CreateReferenceFunction), - ::testing::Values(Shape{1, 96, 55, 55}), - ::testing::Values(element::f32)), - GatherSinkingUnaryTestFixture::get_test_name); diff --git a/src/plugins/intel_gna/tests/unit/transformations/gather_transpose_merge.cpp b/src/plugins/intel_gna/tests/unit/transformations/gather_transpose_merge.cpp deleted file mode 100644 index c73e99eb1a5..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gather_transpose_merge.cpp +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "common/graph_utils.hpp" -#include "common_test_utils/common_utils.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset10.hpp" -#include "openvino/pass/manager.hpp" -#include "ov_models/builders.hpp" -#include "transformations/gather_sinking_transpose.hpp" -#include "transformations/init_node_info.hpp" - -using namespace ov::opset10; -using namespace ov::intel_gna; - -namespace gather_transpose_merge_test { - -namespace { - -inline std::vector make_indexes(size_t size) { - std::vector indexes(size); - std::iota(indexes.begin(), indexes.end(), 0); - std::reverse(indexes.begin(), indexes.end()); - return indexes; -} - -inline std::vector make_transpose_order(const std::vector& input_shape) { - std::vector transpose_order; - switch (input_shape.size()) { - case 2: - transpose_order = {1, 0}; - break; - case 3: - transpose_order = {0, 2, 1}; - break; - case 4: - transpose_order = {0, 2, 3, 1}; - break; - default: - break; - } - - return transpose_order; -} - -} // namespace - -typedef std::tuple - GatherTransposeMergeTestParams; - -class GatherTransposeMergeBase : public ov::test::TestsCommon, - public ::testing::WithParamInterface { -public: - static std::string get_test_name(const testing::TestParamInfo& obj) { - std::vector input_shape; - ov::element::Type net_type; - std::tie(net_type, input_shape) = obj.param; - - std::ostringstream result; - result << "netPRC=" << net_type << "_"; - result << "Shape=" << ov::test::utils::vec2str(input_shape); - - return result.str(); - } - void SetUp() override { - std::tie(m_net_type, m_input_shape) = this->GetParam(); - } - - virtual void init_test_model(){}; - virtual void init_ref_model(){}; - - virtual void Validate() { - ov::pass::Manager m; - m.register_pass(); - m.register_pass("test_before.xml", "test_before.bin"); - m.register_pass(); - m.register_pass("test_after.xml", "test_after.bin"); - m.run_passes(m_model); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - FunctionsComparator::Result result = func_comparator(m_model, m_model_ref); - - EXPECT_TRUE(result.valid) << result.message; - } - virtual void Run() { - SetUp(); - init_test_model(); - init_ref_model(); - Validate(); - } - -protected: - std::shared_ptr m_model, m_model_ref; - ov::element::Type m_net_type; - ov::Shape m_input_shape, m_output_shape; - ov::AxisVector m_gather_ids_ref; -}; - -class TransposeGatherTest : public GatherTransposeMergeBase { -public: - void init_test_model() override { - ov::ParameterVector params{std::make_shared(m_net_type, ov::Shape(m_input_shape))}; - const size_t input_shape_size = ov::shape_size(params[0]->get_shape()); - - std::vector transpose_order = make_transpose_order(m_input_shape); - auto transpose_const = - std::make_shared(ov::element::i8, ov::Shape{transpose_order.size()}, transpose_order); - auto transpose_node = std::make_shared(params[0], transpose_const); - - ov::Shape shape_in = {1, input_shape_size}; - auto reshape_in_const = std::make_shared(ov::element::i64, ov::Shape{shape_in.size()}, shape_in); - auto reshape_in_node = std::make_shared(transpose_node, reshape_in_const, false); - - const std::vector gather_ids = make_indexes(ov::shape_size(m_input_shape)); - auto gather_const_ids = Constant::create(ov::element::i64, ov::Shape{gather_ids.size()}, gather_ids); - const size_t gather_axis = 1; - auto gather_const_axis = Constant::create(ov::element::i64, ov::Shape{}, {gather_axis}); - auto gather_node = std::make_shared(reshape_in_node, gather_const_ids, gather_const_axis); - - ov::Shape shape_out = transpose_node->get_output_shape(0); - auto reshape_out_const = std::make_shared(ov::element::i64, ov::Shape{shape_out.size()}, shape_out); - auto reshape_out_node = std::make_shared(gather_node, reshape_out_const, false); - - ov::ResultVector results{std::make_shared(reshape_out_node)}; - m_model = std::make_shared(results, params, "concat"); - // save for the ref model - const ov::AxisVector transpose_ids = - graph_utils::make_gather_indexes_from_transpose_axes(m_input_shape, transpose_order); - m_gather_ids_ref = graph_utils::combine_gather_indexes(gather_ids, transpose_ids); - m_output_shape = shape_out; - } - - void init_ref_model() override { - ov::ParameterVector params{std::make_shared(m_net_type, ov::Shape(m_input_shape))}; - const size_t input_shape_size = ov::shape_size(params[0]->get_shape()); - - ov::Shape shape_in = {1, input_shape_size}; - auto reshape_in_const = std::make_shared(ov::element::i64, ov::Shape{shape_in.size()}, shape_in); - auto reshape_in_node = std::make_shared(params[0], reshape_in_const, false); - - const std::vector gather_ids = m_gather_ids_ref; - auto gather_const_ids = Constant::create(ov::element::i64, ov::Shape{gather_ids.size()}, gather_ids); - const size_t gather_axis = 1; - auto gather_const_axis = Constant::create(ov::element::i64, ov::Shape{}, {gather_axis}); - auto gather_node = std::make_shared(reshape_in_node, gather_const_ids, gather_const_axis); - - ov::Shape shape_out = m_output_shape; - auto reshape_out_const = std::make_shared(ov::element::i64, ov::Shape{shape_out.size()}, shape_out); - auto reshape_out_node = std::make_shared(gather_node, reshape_out_const, false); - - ov::ResultVector results{std::make_shared(reshape_out_node)}; - m_model_ref = std::make_shared(results, params, "concat"); - } -}; - -class GatherTransposeTest : public GatherTransposeMergeBase { -public: - void init_test_model() override { - ov::ParameterVector params{std::make_shared(m_net_type, ov::Shape(m_input_shape))}; - const size_t input_shape_size = ov::shape_size(params[0]->get_shape()); - - ov::Shape shape_in = {1, input_shape_size}; - auto reshape_in_const = std::make_shared(ov::element::i64, ov::Shape{shape_in.size()}, shape_in); - auto reshape_in_node = std::make_shared(params[0], reshape_in_const, false); - - const std::vector gather_ids = make_indexes(ov::shape_size(m_input_shape)); - auto gather_const_ids = Constant::create(ov::element::i64, ov::Shape{gather_ids.size()}, gather_ids); - const size_t gather_axis = 1; - auto gather_const_axis = Constant::create(ov::element::i64, ov::Shape{}, {gather_axis}); - auto gather_node = std::make_shared(reshape_in_node, gather_const_ids, gather_const_axis); - - ov::Shape shape_middle = m_input_shape; - auto reshape_middle_const = - std::make_shared(ov::element::i64, ov::Shape{shape_middle.size()}, shape_middle); - auto reshape_middle_node = std::make_shared(gather_node, reshape_middle_const, false); - - std::vector transpose_order = make_transpose_order(m_input_shape); - auto transpose_const = - std::make_shared(ov::element::i8, ov::Shape{transpose_order.size()}, transpose_order); - auto transpose_node = std::make_shared(reshape_middle_node, transpose_const); - - ov::ResultVector results{std::make_shared(transpose_node)}; - m_model = std::make_shared(results, params, "transpose_gather_test_model"); - - // save values for the ref model - const ov::AxisVector transpose_ids = - graph_utils::make_gather_indexes_from_transpose_axes(m_input_shape, transpose_order); - m_gather_ids_ref = graph_utils::combine_gather_indexes(gather_ids, transpose_ids); - m_output_shape = transpose_node->get_output_shape(0); - } - - void init_ref_model() override { - ov::ParameterVector params{std::make_shared(m_net_type, ov::Shape(m_input_shape))}; - const size_t input_shape_size = ov::shape_size(params[0]->get_shape()); - - ov::Shape shape_in = {1, input_shape_size}; - auto reshape_in_const = std::make_shared(ov::element::i64, ov::Shape{shape_in.size()}, shape_in); - auto reshape_in_node = std::make_shared(params[0], reshape_in_const, false); - - const std::vector gather_ids = m_gather_ids_ref; - auto gather_const_ids = Constant::create(ov::element::i64, ov::Shape{gather_ids.size()}, gather_ids); - const size_t gather_axis = 1; - auto gather_const_axis = Constant::create(ov::element::i64, ov::Shape{}, {gather_axis}); - auto gather_node = std::make_shared(reshape_in_node, gather_const_ids, gather_const_axis); - - ov::Shape shape_out = m_output_shape; - auto reshape_out_const = std::make_shared(ov::element::i64, ov::Shape{shape_out.size()}, shape_out); - auto reshape_out_node = std::make_shared(gather_node, reshape_out_const, false); - - ov::ResultVector results{std::make_shared(reshape_out_node)}; - m_model_ref = std::make_shared(results, params, "transpose_gather_test_model"); - } -}; - -TEST_P(TransposeGatherTest, CompareWithRefs) { - Run(); -} - -TEST_P(GatherTransposeTest, CompareWithRefs) { - Run(); -} - -ov::element::TypeVector input_precisions = {ov::element::f16, ov::element::f32}; - -const std::vector input_shapes = {{16, 64}, {1, 16, 64}, {1, 8, 16, 64}}; - -INSTANTIATE_TEST_SUITE_P(smoke_merge_transpose_gather, - TransposeGatherTest, - ::testing::Combine(::testing::ValuesIn(input_precisions), ::testing::ValuesIn(input_shapes)), - TransposeGatherTest::get_test_name); - -INSTANTIATE_TEST_SUITE_P(smoke_merge_transpose_gather, - GatherTransposeTest, - ::testing::Combine(::testing::ValuesIn(input_precisions), ::testing::ValuesIn(input_shapes)), - GatherTransposeTest::get_test_name); - -} // namespace gather_transpose_merge_test diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_broadcast_const.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_broadcast_const.cpp deleted file mode 100644 index 7b3b59f55f2..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_broadcast_const.cpp +++ /dev/null @@ -1,360 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "legacy/ngraph_ops/eltwise.hpp" -#include "legacy/ngraph_ops/scaleshift.hpp" -#include "openvino/opsets/opset8.hpp" -#include "transformations/broadcast_const.hpp" - -namespace testing { - -// ------------------------------------------------------------------------------------------------ - -namespace { - -// TODO: use std::make_unique when C++14 will be available -template -std::unique_ptr createUnique(Args&&... args) { - return std::unique_ptr(new T(std::forward(args)...)); -} - -std::shared_ptr createFakeQuantizeNode(std::shared_ptr parent_node) { - auto input_low = ov::op::v0::Constant::create(ngraph::element::f32, {}, {-0.5}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::f32, {}, {0.5}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::f32, {}, {-0.5}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::f32, {}, {0.5}); - return std::make_shared(parent_node, input_low, input_high, output_low, output_high, 0); -} - -using Node = std::shared_ptr; - -// ------------------------------------------------------------------------------------------------ - -struct ShapeInfo { - ShapeInfo(const ngraph::Shape& a_data_shape, - const ngraph::Shape& a_const_shape_dims_in, - const ngraph::Shape& a_const_shape_values_in, - const ngraph::Shape& a_const_shape_values_out) - : data_shape(a_data_shape), - const_shape_dims_in(a_const_shape_dims_in), - const_shape_values_in(a_const_shape_values_in), - const_shape_values_out(a_const_shape_values_out) {} - - ngraph::Shape data_shape; - ngraph::Shape const_shape_dims_in; - ngraph::Shape const_shape_values_in; - ngraph::Shape const_shape_values_out; -}; - -std::unordered_map ShapesRightConst = { - {ov::op::AutoBroadcastType::NONE, - ShapeInfo(/* data_shape */ {3, 2}, - /* const_shape_dims_in */ {3, 2}, - /* const_shape_values_in */ {1, 2, 1, 2, 1, 2}, - /* const_shape_values_out */ {1, 2, 1, 2, 1, 2})}, - {ov::op::AutoBroadcastType::EXPLICIT, - ShapeInfo(/* data_shape */ {3, 2}, - /* const_shape_dims_in */ {3, 2}, - /* const_shape_values_in */ {1, 2, 1, 2, 1, 2}, - /* const_shape_values_out */ {1, 2, 1, 2, 1, 2})}, - {ov::op::AutoBroadcastType::NUMPY, - ShapeInfo(/* data_shape */ {3, 2}, - /* const_shape_dims_in */ {2}, - /* const_shape_values_in */ {1, 2}, - /* const_shape_values_out */ {1, 2, 1, 2, 1, 2})}, - {ov::op::AutoBroadcastType::PDPD, - ShapeInfo(/* data_shape */ {3, 2}, - /* const_shape_dims_in */ {3, 1}, - /* const_shape_values_in */ {1, 2, 3}, - /* const_shape_values_out */ {1, 1, 2, 2, 3, 3})}}; - -// ------------------------------------------------------------------------------------------------ - -class IEltwiseFactory { -public: - IEltwiseFactory() = default; - virtual ~IEltwiseFactory() = default; - virtual Node CreateNode(Node left_input, Node right_input) const = 0; - - void SetBroadcastType(ov::op::AutoBroadcastType type) { - m_broadcast_type = type; - } - ov::op::AutoBroadcastType GetBroadcastType() const { - return m_broadcast_type; - } - -private: - ov::op::AutoBroadcastType m_broadcast_type = ov::op::AutoBroadcastType::NUMPY; -}; - -using EltwiseFactoryPtr = std::shared_ptr; - -template -class EltwiseFactory : public IEltwiseFactory { -public: - Node CreateNode(Node left_input, Node right_input) const override { - return std::make_shared(left_input, right_input, GetBroadcastType()); - } -}; - -template <> -class EltwiseFactory : public IEltwiseFactory { -public: - Node CreateNode(Node left_input, Node right_input) const override { - return std::make_shared(left_input, right_input, ELTWISE_TYPE::Sum); - } -}; - -template -EltwiseFactoryPtr CreateEltwiseFactory() { - return std::make_shared>(); -} - -// ------------------------------------------------------------------------------------------------ - -std::shared_ptr CreateFunction(const ngraph::Shape& data_shape, - const ngraph::Shape& const_shape_dims, - const ngraph::Shape& const_shape_values, - bool add_input_fake_quantize, - bool add_const_fake_quantize, - bool swap_outputs, - bool add_scaleshift, - EltwiseFactoryPtr eltwise_factory) { - const auto input_params_1 = std::make_shared(ngraph::element::Type_t::f32, data_shape); - ngraph::ParameterVector params{input_params_1}; - - const auto constant_1 = - ov::op::v0::Constant::create(ngraph::element::Type_t::f32, ngraph::Shape{const_shape_dims}, const_shape_values); - - Node const_last_node = constant_1; - - if (add_scaleshift) { - const auto input_params_2 = std::make_shared(ngraph::element::Type_t::f32, data_shape); - params.push_back(input_params_2); - - const auto constant_2 = ov::op::v0::Constant::create(ngraph::element::Type_t::f32, - ngraph::Shape{const_shape_dims}, - const_shape_values); - - const_last_node = std::make_shared(input_params_2, - constant_1, - constant_2, - ngraph::element::Type_t::f32); - } - - if (add_const_fake_quantize) { - const auto fake_quantize = createFakeQuantizeNode(const_last_node); - const_last_node = fake_quantize; - } - - Node input_last_node = input_params_1; - - if (add_input_fake_quantize) { - const auto fake_quantize = createFakeQuantizeNode(input_last_node); - input_last_node = fake_quantize; - } - - Node left_node = input_last_node; - Node right_node = const_last_node; - - if (swap_outputs) - left_node.swap(right_node); - - const auto add = eltwise_factory->CreateNode(left_node, right_node); - - const auto result = std::make_shared(add); - return std::make_shared(ngraph::ResultVector{result}, params); -} - -} // namespace - -// ------------------------------------------------------------------------------------------------ - -class BroadcastConstTestFixture : public ov::test::TestsCommon, - public ::testing::WithParamInterface> { -public: - void SetUp() override; - -public: - std::shared_ptr function, reference_function; -}; - -void BroadcastConstTestFixture::SetUp() { - // TODO: use auto & [ ... ] = this->GetParam() when C++17 - EltwiseFactoryPtr eltwise_factory; - bool add_input_fake_quantize; - bool add_const_fake_quantize; - bool swap_outputs; - bool add_scaleshift; - ov::op::AutoBroadcastType broadcast_type; - std::tie(eltwise_factory, - add_input_fake_quantize, - add_const_fake_quantize, - swap_outputs, - add_scaleshift, - broadcast_type) = this->GetParam(); - - eltwise_factory->SetBroadcastType(broadcast_type); - - ShapeInfo shape_info = ShapesRightConst.at(broadcast_type); - - function = CreateFunction(shape_info.data_shape, - shape_info.const_shape_dims_in, - shape_info.const_shape_values_in, - add_input_fake_quantize, - add_const_fake_quantize, - swap_outputs, - add_scaleshift, - eltwise_factory); - reference_function = CreateFunction(shape_info.data_shape, - shape_info.data_shape, - shape_info.const_shape_values_out, - add_input_fake_quantize, - add_const_fake_quantize, - swap_outputs, - add_scaleshift, - eltwise_factory); -} - -void execute_test(std::shared_ptr function, std::shared_ptr reference_function) { - ngraph::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - FunctionsComparator func_comparator = FunctionsComparator::with_default(); - func_comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -void execute_cloned_test(std::shared_ptr function) { - auto reference_function = ngraph::clone_function(*function); - - ngraph::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - FunctionsComparator func_comparator = FunctionsComparator::with_default(); - func_comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -// ------------------------------------------------------------------------------------------------ - -namespace { - -std::vector opset8_eltwise_factories = {CreateEltwiseFactory(), - CreateEltwiseFactory(), - CreateEltwiseFactory()}; - -std::vector all_eltwise_factories = {CreateEltwiseFactory(), - CreateEltwiseFactory(), - CreateEltwiseFactory(), - CreateEltwiseFactory()}; - -std::vector broadcast_passed_types = {ov::op::AutoBroadcastType::NONE, - ov::op::AutoBroadcastType::EXPLICIT}; - -} // namespace - -TEST_P(BroadcastConstTestFixture, CompareFunctions) { - execute_test(function, reference_function); -} - -INSTANTIATE_TEST_SUITE_P(BroadcastConstTestNumpySuite, - BroadcastConstTestFixture, - ::testing::Combine(::testing::ValuesIn(all_eltwise_factories), - ::testing::Bool(), - ::testing::Bool(), - ::testing::Bool(), - ::testing::Bool(), - ::testing::Values(ov::op::AutoBroadcastType::NUMPY))); - -INSTANTIATE_TEST_SUITE_P(BroadcastConstTestPDPDSuite, - BroadcastConstTestFixture, - ::testing::Combine(::testing::ValuesIn(opset8_eltwise_factories), - ::testing::Bool(), - ::testing::Bool(), - ::testing::Values(false), - ::testing::Bool(), - ::testing::Values(ov::op::AutoBroadcastType::PDPD))); - -// ------------------------------------------------------------------------------------------------ - -class BroadcastConstTestPassedFixture - : public ov::test::TestsCommon, - public ::testing::WithParamInterface> { -public: - void SetUp() override; - -public: - std::shared_ptr function; -}; - -void BroadcastConstTestPassedFixture::SetUp() { - // TODO: use auto & [ ... ] = this->GetParam() when C++17 - EltwiseFactoryPtr eltwise_factory; - bool add_input_fake_quantize; - bool add_const_fake_quantize; - bool swap_outputs; - bool add_scaleshift; - ov::op::AutoBroadcastType broadcast_type; - std::tie(eltwise_factory, - add_input_fake_quantize, - add_const_fake_quantize, - swap_outputs, - add_scaleshift, - broadcast_type) = this->GetParam(); - - eltwise_factory->SetBroadcastType(broadcast_type); - - ShapeInfo shape_info = ShapesRightConst.at(broadcast_type); - - function = CreateFunction(shape_info.data_shape, - shape_info.const_shape_dims_in, - shape_info.const_shape_values_in, - add_input_fake_quantize, - add_const_fake_quantize, - swap_outputs, - add_scaleshift, - eltwise_factory); -} - -TEST_P(BroadcastConstTestPassedFixture, CompareFunctionsPassedTypes) { - execute_cloned_test(function); -} - -INSTANTIATE_TEST_SUITE_P(BroadcastConstTestPassedSuite, - BroadcastConstTestPassedFixture, - ::testing::Combine(::testing::ValuesIn(opset8_eltwise_factories), - ::testing::Bool(), - ::testing::Bool(), - ::testing::Bool(), - ::testing::Bool(), - ::testing::ValuesIn(broadcast_passed_types))); - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_convert_dwsc_to_scaleshifts.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_convert_dwsc_to_scaleshifts.cpp deleted file mode 100644 index e453dfbad66..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_convert_dwsc_to_scaleshifts.cpp +++ /dev/null @@ -1,541 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset7.hpp" -#include "transformations/convert_dwsc_to_scaleshifts.hpp" - -namespace testing { - -namespace { - -enum class modelType { - TranspDWSCTransp = 0, /* Transpose(NHWC->NCHW) => DWSC (Group Convolution) => Transpose(NCHW->NHWC) */ - TranspDWSCBiasTransp, /* Transpose(NHWC->NCHW) => DWSC => Broadcasted Add (Bias) => Transpose(NCHW->NHWC) */ -}; - -typedef std::tuple - DWSCToScaleShiftsParams; - -typedef std::tuple - fqDWSCToScaleShiftsParams; - -std::shared_ptr createFQ(std::shared_ptr& in_node) { - auto input_low = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {5}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {10}); - return std::make_shared(in_node, input_low, input_high, output_low, output_high, 11); -} - -std::shared_ptr createBiasFQ(const std::shared_ptr& in_node, - std::shared_ptr& bias_const, - const bool& fq) { - std::shared_ptr node; - node = std::make_shared(in_node, bias_const); - - if (fq) { - node = createFQ(node); - } - - return node; -} - -std::shared_ptr createFunction(const bool& fq, - const modelType& model, - const ngraph::Output& input_node, - const ngraph::Shape& filters_shape, - const ngraph::Strides& conv_stride, - const ngraph::CoordinateDiff& pads_begin, - const ngraph::CoordinateDiff& pads_end, - const ngraph::Strides& conv_dilation, - const ngraph::Shape& bias_shape, - const ngraph::op::PadType& pad_type, - std::shared_ptr& dwsc, - std::shared_ptr& bias_const, - std::shared_ptr& fq_bias) { - std::shared_ptr fq_filters; - - auto transpose_in_order = std::make_shared(ngraph::element::i64, - ngraph::Shape{4}, - std::vector{0, 3, 1, 2}); - auto transpose_in = std::make_shared(input_node, transpose_in_order); - - if (fq) { - fq_filters = std::make_shared( - ngraph::element::i64, - ngraph::Shape{input_node.get_shape()[3], 1, filters_shape[0], filters_shape[1]}); - fq_filters = createFQ(fq_filters); - fq_filters = std::make_shared( - fq_filters, - ov::op::v0::Constant::create( - ngraph::element::i64, - ngraph::Shape{5}, - ngraph::Shape{input_node.get_shape()[3], 1, 1, filters_shape[0], filters_shape[1]}), - false); - } else { - fq_filters = std::make_shared( - ngraph::element::i64, - ngraph::Shape{input_node.get_shape()[3], 1, 1, filters_shape[0], filters_shape[1]}); - } - - dwsc = std::make_shared(transpose_in, - fq_filters, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - pad_type); - auto transpose_out_order = std::make_shared(ngraph::element::i64, - ngraph::Shape{4}, - std::vector{0, 2, 3, 1}); - auto last_op = std::make_shared(dwsc, transpose_out_order); - - if (model == modelType::TranspDWSCBiasTransp || fq) { - bias_const = std::make_shared(ngraph::element::i64, bias_shape); - auto bias = createBiasFQ(dwsc, bias_const, fq); - fq_bias = std::dynamic_pointer_cast(bias); - last_op = std::make_shared(bias, transpose_out_order); - } - - return std::make_shared(last_op); -} - -std::shared_ptr get_initial_function(const bool& fq, - const modelType& model, - const ngraph::Shape& input_shape, - const ngraph::Shape& filters_shape, - const ngraph::Strides& conv_stride, - const ngraph::CoordinateDiff& pads_begin, - const ngraph::CoordinateDiff& pads_end, - const ngraph::Strides& conv_dilation, - const ngraph::Shape& bias_shape, - const ngraph::op::PadType& pad_type, - std::shared_ptr& dwsc, - std::shared_ptr& bias_const, - std::shared_ptr& fq_bias) { - auto input_params = std::make_shared(ngraph::element::i64, input_shape); - auto result = createFunction(fq, - model, - input_params, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - pad_type, - dwsc, - bias_const, - fq_bias); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -// --------------------------------------------------------------------------------------------------------------------- - -class ConvertDWSCToScaleShiftsTestInvalidFixture : public ov::test::TestsCommon, - public ::testing::WithParamInterface { -public: - void SetUp() override; - -public: - std::shared_ptr function, reference_function; - modelType model; -}; - -void ConvertDWSCToScaleShiftsTestInvalidFixture::SetUp() { - bool fq; - DWSCToScaleShiftsParams params; - ngraph::Shape input_shape; - ngraph::Shape filters_shape, bias_shape; - ngraph::Strides conv_stride, conv_dilation; - ngraph::CoordinateDiff pads_begin, pads_end; - ngraph::op::PadType pad_type; - std::shared_ptr dwsc; - std::shared_ptr bias_const; - std::shared_ptr fq_bias; - std::tie(fq, params) = this->GetParam(); - std::tie(model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - pad_type) = params; - - function = get_initial_function(fq, - model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - pad_type, - dwsc, - bias_const, - fq_bias); - reference_function = get_initial_function(fq, - model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - pad_type, - dwsc, - bias_const, - fq_bias); -} - -// --------------------------------------------------------------------------------------------------------------------- - -class ConvertDWSCToScaleShiftsTestFixture : public ov::test::TestsCommon, - public ::testing::WithParamInterface { -public: - void SetUp() override; - std::shared_ptr get_reference(const bool& fq, - const modelType& model, - const ngraph::Shape& input_shape, - const ngraph::Shape& filters_shape, - const ngraph::Strides& conv_stride, - const ngraph::CoordinateDiff& pads_begin, - const ngraph::CoordinateDiff& pads_end, - const ngraph::Strides& conv_dilation, - const ngraph::Shape& bias_shape, - const ngraph::op::PadType& pad_type, - const std::shared_ptr& dwsc, - const std::shared_ptr& bias_const, - const std::shared_ptr& fq_bias); - -public: - std::shared_ptr function, reference_function; - modelType model; -}; - -void ConvertDWSCToScaleShiftsTestFixture::SetUp() { - bool fq; - DWSCToScaleShiftsParams params; - ngraph::Shape input_shape; - ngraph::Shape filters_shape, bias_shape; - ngraph::Strides conv_stride, conv_dilation; - ngraph::CoordinateDiff pads_begin, pads_end; - ngraph::op::PadType pad_type; - std::shared_ptr dwsc; - std::shared_ptr bias_const; - std::shared_ptr fq_bias; - std::tie(fq, params) = this->GetParam(); - std::tie(model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - pad_type) = params; - - function = get_initial_function(fq, - model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - pad_type, - dwsc, - bias_const, - fq_bias); - reference_function = get_reference(fq, - model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - pad_type, - dwsc, - bias_const, - fq_bias); -} - -std::shared_ptr FlatCrop(ngraph::Output input, size_t offset, size_t size) { - return std::make_shared( - input, // data - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {(size_t)0, offset}), // begin sice index - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - {(size_t)0, offset + size}), // end slice index - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {(size_t)1, (size_t)1}), // strides - std::vector{1, 0}, // begin mask - std::vector{1, 0}); // end mask -} - -std::shared_ptr InsertFQLayer(const std::shared_ptr fq_layer, - std::shared_ptr last_node) { - if (fq_layer != nullptr) { - return fq_layer->clone_with_new_inputs( - {last_node, - ov::op::v0::Constant::create( - ngraph::element::f32, - ngraph::Shape{1}, - std::dynamic_pointer_cast(fq_layer->input_value(1).get_node_shared_ptr()) - ->cast_vector()), - ov::op::v0::Constant::create( - ngraph::element::f32, - ngraph::Shape{1}, - std::dynamic_pointer_cast(fq_layer->input_value(2).get_node_shared_ptr()) - ->cast_vector()), - ov::op::v0::Constant::create( - ngraph::element::f32, - ngraph::Shape{1}, - std::dynamic_pointer_cast(fq_layer->input_value(3).get_node_shared_ptr()) - ->cast_vector()), - ov::op::v0::Constant::create( - ngraph::element::f32, - ngraph::Shape{1}, - std::dynamic_pointer_cast(fq_layer->input_value(4).get_node_shared_ptr()) - ->cast_vector())}); - } - return last_node; -} - -std::shared_ptr DecomposeDWSC(std::shared_ptr dwsc, - std::shared_ptr bias_const, - std::shared_ptr fq_bias, - std::shared_ptr flat_input_plane, - std::shared_ptr flat_filters_plane) { - std::shared_ptr const_zero_padding; - std::shared_ptr reshaped_bias; - ngraph::OutputVector output_chunks; - auto input_channel_count = dwsc->get_input_shape(0)[1]; - auto input_width = dwsc->get_input_shape(0)[3]; - auto output_width = dwsc->get_output_shape(0)[3]; - auto filter_width = dwsc->get_input_shape(1)[4]; - auto pads_begin = dwsc->get_pads_begin()[1]; - auto stride_width = dwsc->get_strides()[1]; - auto dilation_width = dwsc->get_dilations()[1]; - - // Constant with zero padding - if (pads_begin) { - const_zero_padding = - std::make_shared(dwsc->get_element_type(), ngraph::Shape{1, input_channel_count}, 0); - } - - // Reshape bias const - if (bias_const) { - auto bias_size = shape_size(bias_const->get_shape()); - reshaped_bias = ov::op::util::make_try_fold( - bias_const, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, ngraph::Shape{1, bias_size}), - false); - } - - // Move filter over input performing multiplication and addition (scaleshift), take padding, stride, dilation and - // bias into account - for (int32_t input_position = -pads_begin, o = 0; o < output_width; input_position += stride_width, o++) { - std::shared_ptr previous_layer_output, last_layer_output; - int32_t filter_end = input_position + filter_width * dilation_width; - bool first = true; - - filter_end = filter_end < input_width ? filter_end : input_width; - - for (int32_t filter_pos = input_position, filter_idx = 0; filter_pos < filter_end; - filter_pos += dilation_width, filter_idx++) { - if (filter_pos >= 0) { - auto conv_input_slice = - FlatCrop(flat_input_plane, filter_pos * input_channel_count, input_channel_count); - auto conv_filter_slice = - FlatCrop(flat_filters_plane, filter_idx * input_channel_count, input_channel_count); - - if (first) { - first = false; - previous_layer_output = std::make_shared(conv_input_slice, conv_filter_slice); - if (bias_const) { - previous_layer_output = std::make_shared(previous_layer_output, reshaped_bias); - previous_layer_output = InsertFQLayer(fq_bias, previous_layer_output); - } - last_layer_output = previous_layer_output; - } else { - last_layer_output = std::make_shared(conv_input_slice, conv_filter_slice); - last_layer_output = std::make_shared(last_layer_output, previous_layer_output); - previous_layer_output = last_layer_output; - } - } - } - - if (!last_layer_output) { - IE_ASSERT(const_zero_padding); - last_layer_output = const_zero_padding; - } - - output_chunks.push_back(last_layer_output); - } - - // Concat and transpose is only needed when output width > 1 - if (output_chunks.size() > 1) { - return std::make_shared(output_chunks, 0); - } - - return output_chunks[0].get_node_shared_ptr(); -} - -std::shared_ptr ConvertDWSCToScaleShiftsTestFixture::get_reference( - const bool& fq, - const modelType& model, - const ngraph::Shape& input_shape, - const ngraph::Shape& filters_shape, - const ngraph::Strides& conv_stride, - const ngraph::CoordinateDiff& pads_begin, - const ngraph::CoordinateDiff& pads_end, - const ngraph::Strides& conv_dilation, - const ngraph::Shape& bias_shape, - const ngraph::op::PadType& pad_type, - const std::shared_ptr& dwsc, - const std::shared_ptr& bias_const, - const std::shared_ptr& fq_bias) { - auto input_params = std::make_shared(ngraph::element::i64, input_shape); - auto output_channel_count = dwsc->get_output_shape(0)[1]; - auto output_width = dwsc->get_output_shape(0)[3]; - - // Prepare flat input data - auto flat_input_plane = std::make_shared( - input_params, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - ngraph::Shape{1, ngraph::shape_size(input_shape)}), - false); - - // Prepare flat filter data - auto filters_const = std::dynamic_pointer_cast(dwsc->get_input_node_shared_ptr(1)); - auto filters_size = ngraph::shape_size(filters_const->get_shape()); - - auto transposed_filters_const = ov::op::util::make_try_fold( - filters_const, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{5}, ngraph::Shape{4, 1, 2, 3, 0})); - - auto flat_filters_plane = ov::op::util::make_try_fold( - transposed_filters_const, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, ngraph::Shape{1, filters_size}), - false); - - // Convert DWSC to a set of diagonal layers - auto output_plane = DecomposeDWSC(dwsc, bias_const, fq_bias, flat_input_plane, flat_filters_plane); - - // Restore the original output shape - auto result = std::make_shared( - output_plane, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{1, output_channel_count, 1, output_width}), - false); - - return std::make_shared(ngraph::ResultVector{std::make_shared(result)}, - ngraph::ParameterVector{input_params}); -} - -// --------------------------------------------------------------------------------------------------------------------- - -void execute_test(modelType model, - std::shared_ptr function, - std::shared_ptr reference_function) { - ngraph::pass::Manager manager; - manager.register_pass(); - - manager.register_pass(); - manager.run_passes(function); - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -TEST_P(ConvertDWSCToScaleShiftsTestFixture, CompareFunctions) { - execute_test(model, function, reference_function); -} - -INSTANTIATE_TEST_SUITE_P(ConvertDWSCToScaleShiftsTestSuite, - ConvertDWSCToScaleShiftsTestFixture, - ::testing::Combine( - // With / without Fake Quantize layers - ::testing::Values(true, false), - ::testing::Values(std::make_tuple(modelType::TranspDWSCTransp, - ngraph::Shape{1, 1, 5, 32}, - ngraph::Shape{1, 3}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 1}, - ngraph::CoordinateDiff{0, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 32, 1, 1}, - ngraph::op::PadType::VALID), - std::make_tuple(modelType::TranspDWSCBiasTransp, - ngraph::Shape{1, 1, 5, 32}, - ngraph::Shape{1, 3}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 2}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 32, 1, 1}, - ngraph::op::PadType::VALID)))); - -TEST_P(ConvertDWSCToScaleShiftsTestInvalidFixture, CompareFunctions) { - execute_test(model, function, reference_function); -} - -INSTANTIATE_TEST_SUITE_P(ConvertDWSCToScaleShiftsInvalidTestSuite, - ConvertDWSCToScaleShiftsTestInvalidFixture, - ::testing::Combine( - // With / without Fake Quantize layers - ::testing::Values(true, false), - ::testing::Values(std::make_tuple(modelType::TranspDWSCTransp, - ngraph::Shape{2, 16, 8, 1}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::op::PadType::SAME_UPPER), - std::make_tuple(modelType::TranspDWSCBiasTransp, - ngraph::Shape{2, 16, 8, 1}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::op::PadType::EXPLICIT)))); - -} // namespace - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_convert_matmul_to_pointwise_convolution.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_convert_matmul_to_pointwise_convolution.cpp deleted file mode 100644 index 3ec27e0b5e1..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_convert_matmul_to_pointwise_convolution.cpp +++ /dev/null @@ -1,483 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset7.hpp" -#include "ov_models/builders.hpp" -#include "transformations/convert_matmul_to_pointwise_convolution.hpp" - -namespace testing { - -namespace { - -struct Graph { - std::shared_ptr createFunction(); - - std::shared_ptr input_params; - std::shared_ptr output; -}; - -std::shared_ptr Graph::createFunction() { - auto result = std::make_shared(output); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -// ------------------------------------------------------------------------------------------------------------ - -// TODO: use std::make_unique when C++14 will be available -template -std::unique_ptr createUnique(Args&&... args) { - return std::unique_ptr(new T(std::forward(args)...)); -} - -class CreateGraphDecorator { -public: - CreateGraphDecorator(std::unique_ptr prev_builder = nullptr) - : prev_builder_(std::move(prev_builder)) {} - virtual ~CreateGraphDecorator() = default; - virtual Graph build() { - Graph graph; - if (prev_builder_) - graph = prev_builder_->build(); - updateGraph(graph); - return graph; - } - -protected: - virtual void updateGraph(Graph&) = 0; - -private: - CreateGraphDecorator(const CreateGraphDecorator&) = delete; - CreateGraphDecorator& operator=(const CreateGraphDecorator&) = delete; - -private: - std::unique_ptr prev_builder_; -}; - -using CreateGraphDecoratorPtr = std::unique_ptr; - -class CreateBaseDecorator : public CreateGraphDecorator { -public: - // always the first decorator => no prev_builder - CreateBaseDecorator(const ngraph::Shape& input_data_shape, const ngraph::Shape& input_const_shape) - : CreateGraphDecorator(nullptr), - input_data_shape_(input_data_shape), - input_const_shape_(input_const_shape) {} - -protected: - Graph build() override; - void updateGraph(Graph&) override {} - -private: - const ngraph::Shape input_data_shape_; - const ngraph::Shape input_const_shape_; -}; - -Graph CreateBaseDecorator::build() { - Graph graph; - graph.input_params = std::make_shared(ngraph::element::i64, input_data_shape_); - graph.output = ov::op::v0::Constant::create(ngraph::element::i64, input_const_shape_, {1}); - return graph; -} - -class CreateFakeQuantize : public CreateGraphDecorator { -public: - CreateFakeQuantize(CreateGraphDecoratorPtr prev_builder = nullptr) - : CreateGraphDecorator(std::move(prev_builder)) {} - -protected: - void updateGraph(Graph&) override; -}; - -std::shared_ptr createFakeQuantizeNode(std::shared_ptr parent_node) { - auto input_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {20}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {10}); - return std::make_shared(parent_node, input_low, input_high, output_low, output_high, 11); -} - -void CreateFakeQuantize::updateGraph(Graph& graph) { - graph.output = createFakeQuantizeNode(graph.output); -} - -class CreateMatMul : public CreateGraphDecorator { -public: - CreateMatMul(CreateGraphDecoratorPtr prev_builder = nullptr) : CreateGraphDecorator(std::move(prev_builder)) {} - -protected: - void updateGraph(Graph&) override; -}; - -void CreateMatMul::updateGraph(Graph& graph) { - auto matmul_node = std::make_shared(graph.input_params, graph.output); - graph.output = matmul_node; -} - -template -class CreateAdd : public CreateGraphDecorator { -public: - CreateAdd(CreateGraphDecoratorPtr prev_builder = nullptr) : CreateGraphDecorator(std::move(prev_builder)) {} - -protected: - void updateGraph(Graph&) override; -}; - -template -void CreateAdd::updateGraph(Graph& graph) { - std::vector axes(1, 1); - if (std::is_same, std::integral_constant>::value) { - auto shape = graph.output->get_output_shape(0); - if (std::is_same, std::integral_constant>::value) { - axes.resize(shape.size(), 1); - } - axes.back() = shape.back(); - } - - auto bias = ngraph::builder::makeConstant(ngraph::element::i64, axes, {}, true); - auto add_node = std::make_shared(graph.output, bias); - graph.output = add_node; -} - -template ::type = true> -CreateGraphDecoratorPtr createBuildDecorator(const ngraph::Shape& input_data_shape = ngraph::Shape{16, 8}, - const ngraph::Shape& input_const_shape = ngraph::Shape{8, 8}) { - CreateGraphDecoratorPtr build_decorator = createUnique(input_data_shape, input_const_shape); - return createUnique(std::move(build_decorator)); -} - -template 0), bool>::type = true> -CreateGraphDecoratorPtr createBuildDecorator(const ngraph::Shape& input_data_shape = ngraph::Shape{16, 8}, - const ngraph::Shape& input_const_shape = ngraph::Shape{8, 8}) { - CreateGraphDecoratorPtr build_decorator = createBuildDecorator(input_data_shape, input_const_shape); - return createUnique(std::move(build_decorator)); -} - -template -Graph createTransformedGraph(const ngraph::Shape& input_data_shape = ngraph::Shape{16, 8}, - const ngraph::Shape& input_const_shape = ngraph::Shape{8, 8}) { - CreateGraphDecoratorPtr build_decorator = - createBuildDecorator(input_data_shape, input_const_shape); - return build_decorator->build(); -} - -// ------------------------------------------------------------------------------------------------------------ - -template -Graph createReferenceGraph() { - Graph graph; - - graph.input_params = std::make_shared(ngraph::element::i64, ngraph::Shape{16, 8}); - auto constant_node = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{8, 8}, {1}); - - auto const_reshape_before = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{4}, - ngraph::Shape{1, 1, 16, 8}); - auto reshape_before = std::make_shared(graph.input_params, const_reshape_before, false); - - auto const_transpose_before = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, ngraph::Shape{0, 3, 1, 2}); - auto transpose_before = std::make_shared(reshape_before, const_transpose_before); - - std::shared_ptr parent_node = constant_node; - if (std::is_same, - std::integral_constant>::value) { - parent_node = createFakeQuantizeNode(constant_node); - } - - auto weights_reshape_const = std::make_shared(ngraph::element::Type_t::i64, - ngraph::Shape{4}, - ngraph::Shape{8, 8, 1, 1}); - auto weights_reshaped = std::make_shared(parent_node, weights_reshape_const, false); - - auto conv_node = std::make_shared(transpose_before, - weights_reshaped, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}, - ngraph::op::PadType::VALID); - - parent_node = conv_node; - if (std::is_same, std::integral_constant>::value) { - std::vector axes(1, 1); - if (std::is_same, std::integral_constant>::value) { - axes.resize(4, 1); - axes[1] = 8; - } - - auto bias = ngraph::builder::makeConstant(ngraph::element::i64, axes, {}, true); - auto add_node = std::make_shared(parent_node, bias); - parent_node = add_node; - } - - if (std::is_same, - std::integral_constant>::value) { - parent_node = createFakeQuantizeNode(parent_node); - } - - auto const_transpose_after = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, ngraph::Shape{0, 2, 3, 1}); - auto transpose_after = std::make_shared(parent_node, const_transpose_after); - - auto const_reshape_after = - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{2}, ngraph::Shape{16, 8}); - graph.output = std::make_shared(transpose_after, const_reshape_after, false); - - return graph; -} - -// ------------------------------------------------------------------------------------------------------- - -class ConvertMatmulToPointWiseConvolutionFixture - : public ov::test::TestsCommon, - public ::testing::WithParamInterface< - std::tuple> { -public: - void SetUp() override; - -public: - std::shared_ptr function, reference_function; - ngraph::pass::Manager pass_manager; -}; - -void ConvertMatmulToPointWiseConvolutionFixture::SetUp() { - // TODO: use auto & [transformed_graph, reference_graph] = this->GetParam() when C++17 - Graph transformed_graph; - Graph reference_graph; - std::tie(transformed_graph, reference_graph, pass_manager) = this->GetParam(); - - function = transformed_graph.createFunction(); - reference_function = reference_graph.createFunction(); -} - -void execute_test(std::shared_ptr function, - std::shared_ptr reference_function, - ngraph::pass::Manager& pass_manager) { - pass_manager.run_passes(function); - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -template -ngraph::pass::Manager createPassManager() { - ngraph::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - return manager; -} - -TEST_P(ConvertMatmulToPointWiseConvolutionFixture, CompareFunctions) { - execute_test(function, reference_function, pass_manager); -} - -namespace { -constexpr bool AddConstFakeQuantizeNode = true; -constexpr bool InsertAddNode = true; -constexpr bool OneDimensional = true; -constexpr bool OneChannel = true; -constexpr bool AddOutFakeQuantizeNode = true; -} // namespace - -INSTANTIATE_TEST_SUITE_P( - ConvertMatmulToPointWiseConvolutionTestSuite, - ConvertMatmulToPointWiseConvolutionFixture, - ::testing::Values( - std::make_tuple( - createTransformedGraph(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, CreateMatMul>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, CreateMatMul>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, CreateMatMul>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, CreateMatMul, CreateFakeQuantize>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, CreateMatMul, CreateFakeQuantize>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, CreateMatMul, CreateFakeQuantize>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, CreateMatMul>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, CreateMatMul>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, CreateMatMul>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, - CreateMatMul, - CreateFakeQuantize>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, - CreateMatMul, - CreateFakeQuantize>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph, - CreateMatMul, - CreateFakeQuantize>(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph(), - createReferenceGraph(), - createPassManager()), - std::make_tuple( - createTransformedGraph(), - createReferenceGraph(), - createPassManager()))); - -// ------------------------------------------------------------------------------------------------------- - -class ITransformedGraphFactory { -public: - virtual ~ITransformedGraphFactory() = default; - virtual Graph createGraph(const ngraph::Shape& input_data_shape, const ngraph::Shape& input_const_shape) = 0; -}; - -template -class TransformedGraphFactory : public ITransformedGraphFactory { -public: - TransformedGraphFactory() = default; - - Graph createGraph(const ngraph::Shape& input_data_shape, const ngraph::Shape& input_const_shape) override { - return createTransformedGraph(input_data_shape, input_const_shape); - } - -private: - TransformedGraphFactory(const TransformedGraphFactory&) = delete; - TransformedGraphFactory& operator=(const TransformedGraphFactory&) = delete; -}; - -struct FixtureData { - std::shared_ptr graph_factory; - ngraph::pass::Manager pass_manager; - - template - static FixtureData create() { - FixtureData fixture_data; - fixture_data.graph_factory = std::make_shared>(); - fixture_data.pass_manager = createPassManager(); - return fixture_data; - } -}; - -using FixtureInputShapes = std::tuple; - -class ConvertMatmulToPointWiseConvolutionInvalidInputFixture - : public ov::test::TestsCommon, - public ::testing::WithParamInterface> { -public: - void SetUp() override; - -public: - std::shared_ptr function; - ngraph::pass::Manager pass_manager; -}; - -void ConvertMatmulToPointWiseConvolutionInvalidInputFixture::SetUp() { - // TODO: use auto & [fixture_data, input_shapes] = this->GetParam() when C++17 - FixtureData fixture_data; - FixtureInputShapes input_shapes; - std::tie(fixture_data, input_shapes) = this->GetParam(); - - ngraph::Shape input_data, input_const; - std::tie(input_data, input_const) = input_shapes; - - function = fixture_data.graph_factory->createGraph(input_data, input_const).createFunction(); - pass_manager = fixture_data.pass_manager; -} - -void execute_test_cloned_function(std::shared_ptr function, ngraph::pass::Manager& pass_manager) { - std::shared_ptr reference_function = ngraph::clone_function(*function); - pass_manager.run_passes(function); - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -std::vector transform_types = { - FixtureData::create(), - FixtureData::create(), - FixtureData::create, - CreateMatMul>(), - FixtureData::create, - CreateMatMul, - CreateFakeQuantize>(), - FixtureData::create, - CreateMatMul>(), - FixtureData::create, - CreateMatMul, - CreateFakeQuantize>(), - FixtureData:: - create(), - FixtureData::create()}; - -std::vector input_shapes = {std::make_tuple(ngraph::Shape{16, 16, 16}, ngraph::Shape{16, 16, 16}), - std::make_tuple(ngraph::Shape{16, 9}, ngraph::Shape{9, 9}), - std::make_tuple(ngraph::Shape{16, 65533}, ngraph::Shape{65533, 2}), - std::make_tuple(ngraph::Shape{16, 769}, ngraph::Shape{769, 2})}; - -TEST_P(ConvertMatmulToPointWiseConvolutionInvalidInputFixture, CompareFunctions) { - execute_test_cloned_function(function, pass_manager); -} - -INSTANTIATE_TEST_SUITE_P(ConvertMatmulToPointWiseConvolutionInvalidInputTestSuite, - ConvertMatmulToPointWiseConvolutionInvalidInputFixture, - ::testing::Combine(::testing::ValuesIn(transform_types), ::testing::ValuesIn(input_shapes))); - -} // namespace - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_convert_padded_to_valid_convolution.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_convert_padded_to_valid_convolution.cpp deleted file mode 100644 index e0c1485e569..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_convert_padded_to_valid_convolution.cpp +++ /dev/null @@ -1,752 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset7.hpp" -#include "transformations/convert_padded_to_valid_convolution.hpp" - -namespace testing { - -namespace { - -enum class modelType { - TranspConvTransp = 0, /* Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) */ - TranspConvBcastAddTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => Transpose(NCHW->NHWC) */ - TranspConvActTransp, /* Transpose(NHWC->NCHW) => Conv => Activation Function => Transpose(NCHW->NHWC) */ - TranspConvBcastAddMaxPoolTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => MaxPooling => - Transpose(NCHW->NHWC) (2D Max Pool case) */ - TranspConvBcastAddActTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => Activation Function => - Transpose(NCHW->NHWC) */ - TranspConvBcastAddMaxPoolActTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => MaxPool => - Activation Function => Transpose(NCHW->NHWC) */ - TranspConvTranspBcastAdd, /* Transpose(NHWC->NCHW) => conv => Transpose(NCHW->NHWC) => Bias */ - TranspConvTranspBcastAddAct /* Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) => Bias => Activation Function - */ -}; - -typedef std::tuple - paddedToValidConvParams; - -typedef std::tuple - fqPaddedToValidConvParams; - -struct ConvData { - size_t input_height; - size_t input_width; - size_t input_channel_count; - size_t pads_begin_width; - size_t pads_begin_height; - size_t pads_end_width; - size_t pads_end_height; -}; - -void GetConvParams(std::shared_ptr conv, ConvData& conv_data) { - conv_data.input_channel_count = conv->input_value(0).get_shape()[1]; - conv_data.input_height = conv->input_value(0).get_shape()[2]; - conv_data.input_width = conv->input_value(0).get_shape()[3]; - conv_data.pads_begin_height = conv->get_pads_begin()[0]; - conv_data.pads_begin_width = conv->get_pads_begin()[1]; - conv_data.pads_end_height = conv->get_pads_end()[0]; - conv_data.pads_end_width = conv->get_pads_end()[1]; -} - -std::shared_ptr createFQ(std::shared_ptr& in_node) { - auto input_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {5}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {10}); - return std::make_shared(in_node, input_low, input_high, output_low, output_high, 11); -} - -ngraph::Output createBiasFQ(const ngraph::Output& in_node, - std::shared_ptr& bias_const, - const bool& fq) { - std::shared_ptr bcast_add = std::make_shared(in_node, bias_const); - - if (fq) { - bcast_add = createFQ(bcast_add); - } - - return bcast_add; -} - -std::shared_ptr createFunction(const bool& fq, - const modelType& model, - const ngraph::Output& input_node, - const ngraph::Shape& filters_shape, - const ngraph::Strides& conv_stride, - const ngraph::CoordinateDiff& pads_begin, - const ngraph::CoordinateDiff& pads_end, - const ngraph::Strides& conv_dilation, - const ngraph::Shape& bias_shape, - const ngraph::Strides& maxpool_stride, - const ngraph::Shape& maxpool_shape, - const ngraph::op::PadType& pad_type, - ConvData* conv_data) { - auto transpose_in_order = std::make_shared(ngraph::element::i64, - ngraph::Shape{4}, - std::vector{0, 3, 1, 2}); - auto transpose_in = std::make_shared(input_node, transpose_in_order); - std::shared_ptr filters = std::make_shared( - ngraph::element::i64, - ngraph::Shape{4, input_node.get_shape()[3], filters_shape[0], filters_shape[1]}); - - if (fq) { - filters = createFQ(filters); - } - - auto conv = std::make_shared(transpose_in, - filters, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - pad_type); - if (conv_data) - GetConvParams(conv, *conv_data); - auto transpose_out_order = std::make_shared(ngraph::element::i64, - ngraph::Shape{4}, - std::vector{0, 2, 3, 1}); - auto bias_const = std::make_shared(ngraph::element::i64, bias_shape); - - ngraph::Output last_op = std::make_shared(conv, transpose_out_order); - - switch (model) { - case modelType::TranspConvBcastAddTransp: { - auto bcast_add = createBiasFQ(conv, bias_const, fq); - last_op = std::make_shared(bcast_add, transpose_out_order); - } break; - - case modelType::TranspConvActTransp: { - auto bcast_add = createBiasFQ(conv, bias_const, fq); - std::shared_ptr activation = std::make_shared(bcast_add); - - if (fq) { - activation = createFQ(activation); - } - - last_op = std::make_shared(activation, transpose_out_order); - } break; - - case modelType::TranspConvBcastAddMaxPoolTransp: { - auto bcast_add = createBiasFQ(conv, bias_const, fq); - auto maxpool = std::make_shared(bcast_add, - maxpool_stride, - ngraph::Shape{0, 0}, - ngraph::Shape{0, 0}, - maxpool_shape, - ngraph::op::RoundingType::FLOOR, - ngraph::op::PadType::VALID); - auto transpose = std::make_shared(maxpool, transpose_out_order); - last_op = std::make_shared(transpose); - } break; - - case modelType::TranspConvBcastAddActTransp: { - auto bcast_add = createBiasFQ(conv, bias_const, fq); - auto activation = std::make_shared(bcast_add); - last_op = std::make_shared(activation, transpose_out_order); - } break; - - case modelType::TranspConvBcastAddMaxPoolActTransp: { - auto bcast_add = createBiasFQ(conv, bias_const, fq); - auto maxpool = std::make_shared(bcast_add, - maxpool_stride, - ngraph::Shape{0, 0}, - ngraph::Shape{0, 0}, - maxpool_shape, - ngraph::op::RoundingType::FLOOR, - ngraph::op::PadType::VALID); - auto activation = std::make_shared(maxpool); - last_op = std::make_shared(activation, transpose_out_order); - } break; - - case modelType::TranspConvTranspBcastAdd: { - last_op = createBiasFQ(last_op, bias_const, fq); - } break; - - case modelType::TranspConvTranspBcastAddAct: { - auto bcast_add = createBiasFQ(last_op, bias_const, fq); - last_op = std::make_shared(bcast_add); - } break; - - case modelType::TranspConvTransp: - default: - break; - } - - return std::make_shared(last_op); -} - -std::shared_ptr get_initial_function(const bool& fq, - const modelType& model, - const ngraph::PartialShape& input_shape, - const ngraph::Shape& filters_shape, - const ngraph::Strides& conv_stride, - const ngraph::CoordinateDiff& pads_begin, - const ngraph::CoordinateDiff& pads_end, - const ngraph::Strides& conv_dilation, - const ngraph::Shape& bias_shape, - const ngraph::Strides& maxpool_stride, - const ngraph::Shape& maxpool_shape, - const ngraph::op::PadType& pad_type, - ConvData& conv_data) { - auto input_params = std::make_shared(ngraph::element::i64, input_shape); - auto result = createFunction(fq, - model, - input_params, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - pad_type, - &conv_data); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -// --------------------------------------------------------------------------------------------------------------------- - -class ConvertPaddedToValidConvTestInvalidFixture : public ov::test::TestsCommon, - public ::testing::WithParamInterface { -public: - void SetUp() override; - -public: - std::shared_ptr function, reference_function; -}; - -void ConvertPaddedToValidConvTestInvalidFixture::SetUp() { - bool fq; - paddedToValidConvParams params; - modelType model; - ngraph::PartialShape input_shape; - ngraph::Shape filters_shape, bias_shape, maxpool_shape; - ngraph::Strides conv_stride, conv_dilation, maxpool_stride; - ngraph::CoordinateDiff pads_begin, pads_end; - ngraph::op::PadType pad_type; - ConvData conv_data; - std::tie(fq, params) = this->GetParam(); - std::tie(model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - pad_type) = params; - - function = get_initial_function(fq, - model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - pad_type, - conv_data); - reference_function = get_initial_function(fq, - model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - pad_type, - conv_data); -} - -// --------------------------------------------------------------------------------------------------------------------- - -class ConvertPaddedToValidConvTestFixture : public ov::test::TestsCommon, - public ::testing::WithParamInterface { -public: - void SetUp() override; - std::shared_ptr get_reference(const bool& fq, - const modelType& model, - const ngraph::PartialShape& input_shape, - const ngraph::Shape& filters_shape, - const ngraph::Strides& conv_stride, - const ngraph::CoordinateDiff& pads_begin, - const ngraph::CoordinateDiff& pads_end, - const ngraph::Strides& conv_dilation, - const ngraph::Shape& bias_shape, - const ngraph::Strides& maxpool_stride, - const ngraph::Shape& maxpool_shape, - const ngraph::op::PadType& pad_type, - const ConvData& conv_data); - -public: - std::shared_ptr function, reference_function; -}; - -void ConvertPaddedToValidConvTestFixture::SetUp() { - bool fq; - paddedToValidConvParams params; - modelType model; - ngraph::PartialShape input_shape; - ngraph::Shape filters_shape, bias_shape, maxpool_shape; - ngraph::Strides conv_stride, conv_dilation, maxpool_stride; - ngraph::CoordinateDiff pads_begin, pads_end; - ngraph::op::PadType pad_type; - ConvData conv_data; - std::tie(fq, params) = this->GetParam(); - std::tie(model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - pad_type) = params; - - function = get_initial_function(fq, - model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - pad_type, - conv_data); - reference_function = get_reference(fq, - model, - input_shape, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - pad_type, - conv_data); -} - -std::shared_ptr FlatCrop(ngraph::Output input, size_t offset, size_t size) { - return std::make_shared( - input, // data - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {(size_t)0, offset}), // begin sice index - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - {(size_t)0, offset + size}), // end slice index - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {(size_t)1, (size_t)1}), // strides - std::vector{1, 0}, // begin mask - std::vector{1, 0}); // end mask -} - -void InsertPadding(ngraph::OutputVector& input_rows_to_concat, - size_t size, - const std::shared_ptr padding_const, - size_t biggest_padding) { - if (size == biggest_padding) { - input_rows_to_concat.push_back(padding_const); - } else { - auto slice = FlatCrop(padding_const, 0, size); - input_rows_to_concat.push_back(slice); - } -} - -std::shared_ptr CreatePaddedNet(const ngraph::Output& input_node, - const ConvData& conv_data) { - size_t flat_left_padding = conv_data.input_channel_count * conv_data.pads_begin_width; - size_t flat_right_padding = conv_data.input_channel_count * conv_data.pads_end_width; - size_t padded_row_size = - flat_left_padding + conv_data.input_channel_count * conv_data.input_width + flat_right_padding; - size_t flat_top_padding = padded_row_size * conv_data.pads_begin_height; - size_t flat_bottom_padding = padded_row_size * conv_data.pads_end_height; - size_t biggest_padding = - std::max(std::max(flat_left_padding, flat_right_padding), std::max(flat_top_padding, flat_bottom_padding)); - - if (conv_data.input_height > 1 && (flat_top_padding > 1 || flat_bottom_padding > 1)) { - biggest_padding = biggest_padding > padded_row_size ? biggest_padding : padded_row_size; - } - - if (!biggest_padding) - return nullptr; - - auto flat_input = std::make_shared( - input_node, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - ngraph::Shape{1ull, shape_size(input_node.get_shape())}), - false); - - // Constant with zero padding - auto const_holding_padding = - std::make_shared(ngraph::element::i64, ngraph::Shape{1, biggest_padding}, 0); - - std::shared_ptr original_row = flat_input; - ngraph::OutputVector input_rows_to_concat; - - // Add top padding - for (size_t p = 0; p < conv_data.pads_begin_height; p++) { - InsertPadding(input_rows_to_concat, padded_row_size, const_holding_padding, biggest_padding); - } - - if (flat_left_padding || flat_right_padding) { - // Pad every row of input plain if neccessary - for (size_t h = 0; h < conv_data.input_height; h++) { - // left padding input right padding - // | | | - // +--------------+-----------+ - // | - // concat - - if (conv_data.input_height > 1) - original_row = FlatCrop(flat_input, - h * conv_data.input_width * conv_data.input_channel_count, - conv_data.input_width * conv_data.input_channel_count); - - ngraph::OutputVector single_row_concat_inputs; - if (flat_left_padding) { - InsertPadding(single_row_concat_inputs, flat_left_padding, const_holding_padding, biggest_padding); - } - single_row_concat_inputs.push_back(original_row); - if (flat_right_padding) { - InsertPadding(single_row_concat_inputs, flat_right_padding, const_holding_padding, biggest_padding); - } - auto padded_row_concat = std::make_shared(single_row_concat_inputs, 1); - - input_rows_to_concat.push_back(padded_row_concat); - } - } else { - input_rows_to_concat.push_back(original_row); - } - - // Bottom padding - for (size_t p = 0; p < conv_data.pads_end_height; p++) { - InsertPadding(input_rows_to_concat, padded_row_size, const_holding_padding, biggest_padding); - } - - auto padded_input_plane = std::make_shared(input_rows_to_concat, 1); - return padded_input_plane; -} - -std::shared_ptr ConvertPaddedToValidConvTestFixture::get_reference( - const bool& fq, - const modelType& model, - const ngraph::PartialShape& input_shape, - const ngraph::Shape& filters_shape, - const ngraph::Strides& conv_stride, - const ngraph::CoordinateDiff& pads_begin, - const ngraph::CoordinateDiff& pads_end, - const ngraph::Strides& conv_dilation, - const ngraph::Shape& bias_shape, - const ngraph::Strides& maxpool_stride, - const ngraph::Shape& maxpool_shape, - const ngraph::op::PadType& pad_type, - const ConvData& conv_data) { - auto input_params = std::make_shared(ngraph::element::i64, input_shape); - - // Add padding where neccessary - - // padding - // padding - // ... row ... - // ... row ... - // ........... - // ... row ... - // padding - // padding - auto padded_input_plane = CreatePaddedNet(input_params, conv_data); - std::shared_ptr result; - - if (padded_input_plane) { - auto shape_const = std::make_shared( - ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{static_cast(1), - conv_data.pads_begin_height + conv_data.input_height + conv_data.pads_end_height, - conv_data.pads_begin_width + conv_data.input_width + conv_data.pads_end_width, - conv_data.input_channel_count}); - auto padded_input_plane_reshaped = - std::make_shared(padded_input_plane, shape_const, false); - result = createFunction(fq, - model, - padded_input_plane_reshaped, - filters_shape, - conv_stride, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - ngraph::op::PadType::EXPLICIT, - nullptr); - } else { - // Valid padding - result = createFunction(fq, - model, - input_params, - filters_shape, - conv_stride, - pads_begin, - pads_end, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - pad_type, - nullptr); - } - - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -// --------------------------------------------------------------------------------------------------------------------- - -void execute_test(std::shared_ptr function, std::shared_ptr reference_function) { - ngraph::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -TEST_P(ConvertPaddedToValidConvTestFixture, CompareFunctions) { - execute_test(function, reference_function); -} - -INSTANTIATE_TEST_SUITE_P(ConvertPaddedToValidConvTestSuite, - ConvertPaddedToValidConvTestFixture, - ::testing::Combine( - // With / without Fake Quantize layers - ::testing::Values(true, false), - ::testing::Values(std::make_tuple(modelType::TranspConvTransp, - ngraph::PartialShape{1, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::EXPLICIT), - std::make_tuple(modelType::TranspConvBcastAddTransp, - ngraph::PartialShape{1, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::EXPLICIT), - std::make_tuple(modelType::TranspConvActTransp, - ngraph::PartialShape{1, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::EXPLICIT), - std::make_tuple(modelType::TranspConvBcastAddMaxPoolTransp, - ngraph::PartialShape{1, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::EXPLICIT), - std::make_tuple(modelType::TranspConvBcastAddActTransp, - ngraph::PartialShape{1, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::SAME_LOWER), - std::make_tuple(modelType::TranspConvBcastAddMaxPoolActTransp, - ngraph::PartialShape{1, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::SAME_UPPER), - std::make_tuple(modelType::TranspConvTranspBcastAdd, - ngraph::PartialShape{1, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1, 1, 4}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::EXPLICIT), - std::make_tuple(modelType::TranspConvTranspBcastAddAct, - ngraph::PartialShape{1, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1, 1, 4}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::EXPLICIT)))); - -TEST_P(ConvertPaddedToValidConvTestInvalidFixture, CompareFunctions) { - execute_test(function, reference_function); -} - -INSTANTIATE_TEST_SUITE_P(ConvertPaddedToValidConvInvalidTestSuite, - ConvertPaddedToValidConvTestInvalidFixture, - ::testing::Combine( - // With / without Fake Quantize layers - ::testing::Values(true, false), - ::testing::Values(std::make_tuple(modelType::TranspConvTransp, - ngraph::PartialShape{2, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::SAME_UPPER), - std::make_tuple(modelType::TranspConvBcastAddTransp, - ngraph::PartialShape{2, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::EXPLICIT), - std::make_tuple(modelType::TranspConvActTransp, - ngraph::PartialShape{2, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::EXPLICIT), - std::make_tuple(modelType::TranspConvBcastAddMaxPoolTransp, - ngraph::PartialShape{2, 16, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{5, 1}, - ngraph::op::PadType::EXPLICIT), - std::make_tuple(modelType::TranspConvBcastAddActTransp, - ngraph::PartialShape{2, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::SAME_LOWER), - std::make_tuple(modelType::TranspConvBcastAddMaxPoolActTransp, - ngraph::PartialShape{2, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 5}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4}, - ngraph::op::PadType::SAME_UPPER), - std::make_tuple(modelType::TranspConvTranspBcastAdd, - ngraph::PartialShape{2, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1, 1, 4}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::EXPLICIT), - std::make_tuple(modelType::TranspConvTranspBcastAddAct, - ngraph::PartialShape{2, 1, 16, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 2}, - ngraph::CoordinateDiff{0, 3}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1, 1, 4}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}, - ngraph::op::PadType::EXPLICIT)))); - -} // namespace - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_decompose_2d_convolution.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_decompose_2d_convolution.cpp deleted file mode 100644 index 0f7c5a99b46..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_decompose_2d_convolution.cpp +++ /dev/null @@ -1,1065 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset7.hpp" -#include "transformations/decompose_2d_convolution.hpp" - -using namespace ov::intel_gna::limitations; -namespace testing { - -namespace { - -enum class modelType { - TranspConvTransp = 0, /* Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) */ - TranspConvBcastAddTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => Transpose(NCHW->NHWC) */ - TranspConvActTransp, /* Transpose(NHWC->NCHW) => Conv => Activation Function => Transpose(NCHW->NHWC) */ - TranspConvBcastAddMaxPoolTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => MaxPooling => - Transpose(NCHW->NHWC) (2D Max Pool case) */ - TranspConvBcastAddActTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => Activation Function => - Transpose(NCHW->NHWC) */ - TranspConvBcastAddMaxPoolActTransp, /* Transpose(NHWC->NCHW) => Conv => Broadcasted Add (Bias) => MaxPool => - Activation Function => Transpose(NCHW->NHWC) */ - TranspConvTranspBcastAdd, /* Transpose(NHWC->NCHW) => conv => Transpose(NCHW->NHWC) => Bias */ - TranspConvTranspBcastAddAct /* Transpose(NHWC->NCHW) => Conv => Transpose(NCHW->NHWC) => Bias => Activation Function - */ -}; - -typedef std::tuple - decompose2DConvParams; - -typedef std::tuple - fqDecompose2DConvParams; - -struct GraphData { - std::shared_ptr input_node; - std::shared_ptr fq_filters; - std::shared_ptr conv; - std::shared_ptr bias; - std::shared_ptr fq_conv; - std::shared_ptr fq_bias; - std::shared_ptr max_pool; - std::shared_ptr af; - std::shared_ptr fq_af; - std::shared_ptr bias_const; - std::shared_ptr last_op_in_sequence_for_replacement; - size_t conv_count; - size_t pool_size_width; - size_t pool_stride_width; -}; - -struct ConvParams { - size_t input_height; - size_t input_width; - size_t input_channel_count; - size_t output_channel_count; - size_t filter_height; - size_t filter_width; - size_t filter_count; - size_t filter_channel_count; - size_t filter_dilation_height; - size_t filter_dilation_width; - size_t filter_stride_height; - size_t filter_stride_width; - size_t output_height; - size_t output_width; -}; - -void GetConvParams(std::shared_ptr conv, ConvParams& conv_params) { - conv_params.output_height = conv->get_output_shape(0)[2]; - conv_params.output_width = conv->get_output_shape(0)[3]; - conv_params.input_channel_count = conv->input_value(0).get_shape()[1]; - conv_params.input_height = conv->input_value(0).get_shape()[2]; - conv_params.input_width = conv->input_value(0).get_shape()[3]; - conv_params.filter_count = conv->input_value(1).get_shape()[0]; - conv_params.filter_channel_count = conv->input_value(1).get_shape()[1]; - conv_params.filter_height = conv->input_value(1).get_shape()[2]; - conv_params.filter_width = conv->input_value(1).get_shape()[3]; - conv_params.filter_dilation_height = conv->get_dilations()[0]; - conv_params.filter_dilation_width = conv->get_dilations()[1]; - conv_params.filter_stride_height = conv->get_strides()[0]; - conv_params.filter_stride_width = conv->get_strides()[1]; - conv_params.output_channel_count = conv_params.filter_count; -} - -std::shared_ptr createFQ(std::shared_ptr& in_node) { - auto input_low = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {5}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {10}); - return std::make_shared(in_node, input_low, input_high, output_low, output_high, 11); -} - -std::shared_ptr createBiasFQ(const ngraph::Output& in_node, - std::shared_ptr& bias_const, - std::shared_ptr& bias, - const bool& fq) { - std::shared_ptr node; - bias = std::make_shared(in_node, bias_const); - node = bias; - - if (fq) { - node = createFQ(node); - } - - return node; -} - -std::shared_ptr createFunction(const bool& fq, - const modelType& model, - const ngraph::Output& input_node, - const ngraph::Shape& filters_shape, - const ngraph::Strides& conv_stride, - const ngraph::Strides& conv_dilation, - const ngraph::Shape& bias_shape, - const ngraph::Strides& maxpool_stride, - const ngraph::Shape& maxpool_shape, - GraphData* graph_data, - ConvParams* conv_params) { - auto transpose_in_order = std::make_shared(ngraph::element::i64, - ngraph::Shape{4}, - std::vector{0, 3, 1, 2}); - auto transpose_in = std::make_shared(input_node, transpose_in_order); - std::shared_ptr fq_filters = std::make_shared( - ngraph::element::i64, - ngraph::Shape{4, input_node.get_shape()[3], filters_shape[0], filters_shape[1]}); - - if (fq) { - fq_filters = createFQ(fq_filters); - } - - auto conv = std::make_shared(transpose_in, - fq_filters, - conv_stride, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - conv_dilation, - ngraph::op::PadType::VALID); - if (conv_params) - GetConvParams(conv, *conv_params); - - auto transpose_out_order = std::make_shared(ngraph::element::i64, - ngraph::Shape{4}, - std::vector{0, 2, 3, 1}); - auto bias_const = std::make_shared(ngraph::element::i64, bias_shape); - std::shared_ptr bias = nullptr; - std::shared_ptr fq_bias = nullptr, fq_af = nullptr; - std::shared_ptr max_pool = nullptr; - std::shared_ptr activation = nullptr; - std::shared_ptr fq_conv = nullptr; - std::shared_ptr last_op = std::make_shared(conv, transpose_out_order); - - switch (model) { - case modelType::TranspConvBcastAddTransp: { - fq_bias = createBiasFQ(conv, bias_const, bias, fq); - last_op = std::make_shared(fq_bias, transpose_out_order); - } break; - - case modelType::TranspConvActTransp: { - fq_bias = createBiasFQ(conv, bias_const, bias, fq); - std::shared_ptr activation = std::make_shared(fq_bias); - - if (fq) { - activation = createFQ(activation); - } - - last_op = std::make_shared(activation, transpose_out_order); - } break; - - case modelType::TranspConvBcastAddMaxPoolTransp: { - fq_bias = createBiasFQ(conv, bias_const, bias, fq); - max_pool = std::make_shared(fq_bias, - maxpool_stride, - ngraph::Shape{0, 0}, - ngraph::Shape{0, 0}, - maxpool_shape, - ngraph::op::RoundingType::FLOOR, - ngraph::op::PadType::VALID); - auto transpose = std::make_shared(max_pool, transpose_out_order); - last_op = std::make_shared(transpose); - } break; - - case modelType::TranspConvBcastAddActTransp: { - fq_bias = createBiasFQ(conv, bias_const, bias, fq); - activation = std::make_shared(fq_bias); - last_op = std::make_shared(activation, transpose_out_order); - } break; - - case modelType::TranspConvBcastAddMaxPoolActTransp: { - fq_bias = createBiasFQ(conv, bias_const, bias, fq); - max_pool = std::make_shared(fq_bias, - maxpool_stride, - ngraph::Shape{0, 0}, - ngraph::Shape{0, 0}, - maxpool_shape, - ngraph::op::RoundingType::FLOOR, - ngraph::op::PadType::VALID); - activation = std::make_shared(max_pool); - if (fq) { - fq_af = createFQ(activation); - } - last_op = std::make_shared(fq_af ? fq_af : activation, transpose_out_order); - } break; - - case modelType::TranspConvTranspBcastAdd: { - last_op = createBiasFQ(last_op, bias_const, bias, fq); - } break; - - case modelType::TranspConvTranspBcastAddAct: { - fq_bias = createBiasFQ(last_op, bias_const, bias, fq); - last_op = std::make_shared(fq_bias); - } break; - - case modelType::TranspConvTransp: { - if (fq) { - auto conv_ptr = conv->shared_from_this(); - fq_conv = createFQ(conv_ptr); - last_op = std::make_shared(fq_conv, transpose_out_order); - } - } - default: - break; - } - - if (graph_data) { - graph_data->fq_filters = fq ? std::dynamic_pointer_cast(fq_filters) : nullptr; - graph_data->conv = conv; - graph_data->bias = bias; - graph_data->fq_conv = fq ? std::dynamic_pointer_cast(fq_conv) : nullptr; - graph_data->fq_bias = fq ? std::dynamic_pointer_cast(fq_bias) : nullptr; - graph_data->af = std::dynamic_pointer_cast(activation); - graph_data->fq_af = fq ? std::dynamic_pointer_cast(fq_af) : nullptr; - graph_data->max_pool = max_pool; - graph_data->last_op_in_sequence_for_replacement = last_op; - graph_data->bias_const = nullptr; - graph_data->conv_count = 0; - - if (max_pool) { - graph_data->pool_size_width = max_pool->get_kernel()[1]; - graph_data->pool_stride_width = max_pool->get_strides()[1]; - } - } - - return std::make_shared(last_op); -} - -std::shared_ptr get_initial_function(const bool& fq, - const modelType& model, - const ngraph::PartialShape& input_shape, - const ngraph::Shape& filters_shape, - const ngraph::Strides& conv_stride, - const ngraph::Strides& conv_dilation, - const ngraph::Shape& bias_shape, - const ngraph::Strides& maxpool_stride, - const ngraph::Shape& maxpool_shape, - GraphData& graph_data, - ConvParams& conv_params) { - auto input_params = std::make_shared(ngraph::element::i64, input_shape); - auto result = createFunction(fq, - model, - input_params, - filters_shape, - conv_stride, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - &graph_data, - &conv_params); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -// --------------------------------------------------------------------------------------------------------------------- - -class Decompose2DConvTestInvalidFixture : public ov::test::TestsCommon, - public ::testing::WithParamInterface { -public: - void SetUp() override; - void TearDown() override; - -public: - std::shared_ptr function, reference_function; - modelType model; -}; - -void Decompose2DConvTestInvalidFixture::SetUp() { - bool fq; - decompose2DConvParams params; - ngraph::PartialShape input_shape; - ngraph::Shape filters_shape, bias_shape, maxpool_shape; - ngraph::Strides conv_stride, conv_dilation, maxpool_stride; - GraphData graph_data{}; - ConvParams conv_params{}; - std::tie(fq, params) = this->GetParam(); - std::tie(model, input_shape, filters_shape, conv_stride, conv_dilation, bias_shape, maxpool_stride, maxpool_shape) = - params; - - Limitations::init(ov::intel_gna::target::DeviceVersion::Default); - - function = get_initial_function(fq, - model, - input_shape, - filters_shape, - conv_stride, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - graph_data, - conv_params); - reference_function = get_initial_function(fq, - model, - input_shape, - filters_shape, - conv_stride, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - graph_data, - conv_params); -} - -void Decompose2DConvTestInvalidFixture::TearDown() { - Limitations::deinit(); -} - -// --------------------------------------------------------------------------------------------------------------------- - -class Decompose2DConvTestFixture : public ov::test::TestsCommon, - public ::testing::WithParamInterface { -public: - void SetUp() override; - void TearDown() override; - - std::shared_ptr get_reference(const bool& fq, - const modelType& model, - const ngraph::PartialShape& input_shape, - GraphData& graph_data, - ConvParams& conv_params); - -public: - std::shared_ptr function, reference_function; - modelType model; -}; - -void Decompose2DConvTestFixture::SetUp() { - bool fq; - decompose2DConvParams params; - ngraph::PartialShape input_shape; - ngraph::Shape filters_shape, bias_shape, maxpool_shape; - ngraph::Strides conv_stride, conv_dilation, maxpool_stride; - GraphData graph_data{}; - ConvParams conv_params{}; - std::tie(fq, params) = this->GetParam(); - std::tie(model, input_shape, filters_shape, conv_stride, conv_dilation, bias_shape, maxpool_stride, maxpool_shape) = - params; - - Limitations::init(ov::intel_gna::target::DeviceVersion::Default); - - function = get_initial_function(fq, - model, - input_shape, - filters_shape, - conv_stride, - conv_dilation, - bias_shape, - maxpool_stride, - maxpool_shape, - graph_data, - conv_params); - reference_function = get_reference(fq, model, input_shape, graph_data, conv_params); -} - -void Decompose2DConvTestFixture::TearDown() { - Limitations::deinit(); -} - -std::shared_ptr ReshapeBiasConst(std::shared_ptr conv_bias, - const ConvParams& conv_params) { - auto add_const = std::dynamic_pointer_cast(conv_bias->input_value(1).get_node_shared_ptr()); - - IE_ASSERT(add_const); - - auto bias_size = shape_size(add_const->get_shape()); - return ov::op::util::make_try_fold( - add_const, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, ngraph::Shape{1, bias_size, 1, 1}), - false); -} - -std::shared_ptr FlatCrop(ngraph::Output input, size_t offset, size_t size) { - auto shape = input.get_shape(); - return std::make_shared( - input, // data - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {(size_t)0, offset}), // begin slice index - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - {(size_t)0, offset + size}), // end slice index - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {(size_t)1, (size_t)1}), // strides - std::vector{1, 0}, // begin mask - std::vector{1, 0}); // end mask -} - -static std::vector> Split2DConvFilters(std::shared_ptr& filters, - const bool& vertical_permute, - const bool& horizontal_permute, - const size_t& split_channels) { - if (!horizontal_permute && !vertical_permute && split_channels == 1) - return {filters}; - - std::vector> result; - ngraph::Shape reshape_shape; - auto flat_filters = filters->outputs(); - const auto filter_shape = filters->get_output_shape(0); - IE_ASSERT(filter_shape.size() == 4); - - if (split_channels > 1) { - const auto axis_node = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{}, {1}); - const auto split = std::make_shared(filters, axis_node, split_channels); - flat_filters = split->outputs(); - } - - if (horizontal_permute) { - for (size_t split_index = 0; split_index < split_channels; split_index++) { - ngraph::Output& flat_filter = flat_filters[split_index]; - result.push_back(std::make_shared( - flat_filter, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, ngraph::Shape{0, 1, 3, 2}))); - } - } - - if (vertical_permute && horizontal_permute) { - reshape_shape = - ngraph::Shape{filter_shape[0], filter_shape[1] * filter_shape[2] * filter_shape[3] / split_channels, 1, 1}; - } else if (vertical_permute && !horizontal_permute) { - reshape_shape = - ngraph::Shape{filter_shape[0], filter_shape[1] * filter_shape[2] / split_channels, 1, filter_shape[3]}; - } else if (!vertical_permute && horizontal_permute) { - reshape_shape = - ngraph::Shape{filter_shape[0], filter_shape[1] * filter_shape[3] / split_channels, filter_shape[2], 1}; - } else { - reshape_shape = - ngraph::Shape{filter_shape[0], filter_shape[1] / split_channels, filter_shape[2], filter_shape[3]}; - } - - for (auto& new_filter : result) - new_filter = ov::op::util::make_try_fold( - new_filter, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, reshape_shape), - false); - - return result; -} - -ngraph::OutputVector SplitInput(const GraphData& graph_data, ConvParams& conv_params) { - // We need to have proper input shape first - ngraph::OutputVector split_planes; - auto padded_input_plane = std::make_shared( - graph_data.input_node, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - ngraph::Shape{1, shape_size(graph_data.input_node->get_shape())}), - false); - - if (graph_data.conv_count > 1) { - // If we split input plane and filters due to GNA limitations - we must sum their results at the end - conv_params.input_channel_count /= graph_data.conv_count; - - auto reshape_before_transpose = std::make_shared( - padded_input_plane, - ov::op::v0::Constant::create( - ngraph::element::i64, - ngraph::Shape{2}, - {shape_size(padded_input_plane->get_shape()) / graph_data.conv_count, graph_data.conv_count}), - false); - - auto transpose_before_channel_wise_split = std::make_shared( - reshape_before_transpose, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 0})->output(0)); - - const auto axis_node = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}); - const auto split = - std::make_shared(transpose_before_channel_wise_split, axis_node, graph_data.conv_count); - split_planes = split->outputs(); - } else { - split_planes.push_back(padded_input_plane); - } - - return split_planes; -} - -std::vector> SplitFilters(const GraphData& graph_data, ConvParams& conv_params) { - // If the input plane exceeds GNA limits and we have split into several convolutions, then we need to split filter - // data as well; we also need to take filter height and potential dilation into account when modifying the filters - - // Take account of fake quantize when getting filter values - auto filter_values = std::dynamic_pointer_cast( - graph_data.fq_filters == nullptr ? graph_data.conv->input_value(1).get_node_shared_ptr() - : graph_data.fq_filters->input_value(0).get_node_shared_ptr()); - bool vertical_permute = (conv_params.filter_height > 1); - bool horizontal_permute = (conv_params.filter_dilation_width > 1); - std::vector> h_1_filters{}; - - h_1_filters = Split2DConvFilters(filter_values, vertical_permute, horizontal_permute, graph_data.conv_count); - - return h_1_filters; -} - -void TransformInput(const GraphData& graph_data, - const ConvParams& conv_params, - ngraph::Output& split_input_plane) { - /* - * Padded row - NHWC order - * | - * Split in vertical dim (filter height) - * / | \ - * Concat - * | - * Transpose - */ - - // First we need to prepare flat (height = 1) slices of input data proper for flattened (height = 1) filters created - // later on; the input data is overlapping (duplicated) - ngraph::OutputVector dilated_input_planes; - for (size_t filter_height = 0; filter_height < conv_params.filter_height; filter_height++) { - size_t offset; - - if (conv_params.filter_stride_height > 1) { - // Prepare strided slices of input data - for (size_t output_height = 0; output_height < conv_params.output_height; output_height++) { - offset = (filter_height * conv_params.filter_dilation_height + - output_height * conv_params.filter_stride_height) * - conv_params.input_width * conv_params.input_channel_count; - auto slice = - FlatCrop(split_input_plane, offset, conv_params.input_width * conv_params.input_channel_count); - dilated_input_planes.push_back(slice); - } - } else { - offset = filter_height * conv_params.filter_dilation_height * conv_params.input_width * - conv_params.input_channel_count; - auto slice = - FlatCrop(split_input_plane, - offset, - conv_params.input_width * conv_params.input_channel_count * conv_params.output_height); - dilated_input_planes.push_back(slice); - } - } - - // Interleaving dilated input planes - std::shared_ptr dilated_chunks_concat = std::make_shared(dilated_input_planes, 0); - - // Additional reshape is required for strided slices of input intended for each filter row - if (conv_params.filter_stride_height > 1) { - dilated_chunks_concat = std::make_shared( - dilated_chunks_concat, - ov::op::v0::Constant::create( - ngraph::element::i64, - ngraph::Shape{2}, - {conv_params.filter_height, - conv_params.input_width * conv_params.input_channel_count * conv_params.output_height}), - false); - } - - auto transposed_dilated_chunks = std::make_shared( - dilated_chunks_concat, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 0})->output(0)); - - // Flattening of interleaved input planes - auto flattened_dilated_transposed_input = std::make_shared( - transposed_dilated_chunks, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - {(size_t)1, - conv_params.input_width * conv_params.input_channel_count * - conv_params.output_height * conv_params.filter_height}), - false); - - split_input_plane = flattened_dilated_transposed_input; -} - -static void InsertFQLayer(const std::shared_ptr fqLayer, - std::shared_ptr lastNode) { - if (fqLayer != nullptr) { - lastNode = fqLayer->clone_with_new_inputs( - {lastNode, - ov::op::v0::Constant::create( - ngraph::element::f32, - ngraph::Shape{1}, - std::dynamic_pointer_cast(fqLayer->input_value(1).get_node_shared_ptr()) - ->cast_vector()), - ov::op::v0::Constant::create( - ngraph::element::f32, - ngraph::Shape{1}, - std::dynamic_pointer_cast(fqLayer->input_value(2).get_node_shared_ptr()) - ->cast_vector()), - ov::op::v0::Constant::create( - ngraph::element::f32, - ngraph::Shape{1}, - std::dynamic_pointer_cast(fqLayer->input_value(3).get_node_shared_ptr()) - ->cast_vector()), - ov::op::v0::Constant::create( - ngraph::element::f32, - ngraph::Shape{1}, - std::dynamic_pointer_cast(fqLayer->input_value(4).get_node_shared_ptr()) - ->cast_vector())}); - } -} - -std::shared_ptr Create1DConv(const GraphData& graph_data, - const ConvParams& conv_params, - const ngraph::Output& input, - std::shared_ptr filters, - const size_t conv_index, - const size_t h_index) { - // Transpose NHWC => NCHW - std::shared_ptr nchw_input = std::make_shared( - input, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 3, 1, 2})->output(0)); - - // Fake quantize - InsertFQLayer(graph_data.fq_filters, filters); - - // 1D Convolution & fake quantize - auto conv = std::make_shared(nchw_input, - filters, - ngraph::Strides{1, conv_params.filter_stride_width}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}, - ngraph::op::PadType::VALID); - std::string conv_name = - graph_data.conv->get_friendly_name() + "_H_" + std::to_string(h_index) + "_CH_" + std::to_string(0); - conv->set_friendly_name(conv_name); - std::shared_ptr last_conv_block_op = conv; - InsertFQLayer(graph_data.fq_conv, last_conv_block_op); - - // Bias & fake quantize - if (graph_data.bias_const && conv_index == 0) { - last_conv_block_op = std::make_shared(conv, graph_data.bias_const); - InsertFQLayer(graph_data.fq_bias, last_conv_block_op); - } - - // Max pooling - if (graph_data.pool_size_width > 1 || graph_data.pool_stride_width > 1) { - last_conv_block_op = std::make_shared(last_conv_block_op, - ngraph::Strides{1, graph_data.pool_stride_width}, - ngraph::Shape{0, 0}, - ngraph::Shape{0, 0}, - ngraph::Shape{1, graph_data.pool_size_width}, - graph_data.max_pool->get_rounding_type(), - ngraph::op::PadType::VALID); - } - // Activation function - if (graph_data.af && graph_data.conv_count == 1) { - last_conv_block_op = graph_data.af->clone_with_new_inputs({last_conv_block_op}); - InsertFQLayer(graph_data.fq_af, last_conv_block_op); - } - - // Transpose NCHW => NHWC - auto nhwc_output = std::make_shared( - last_conv_block_op, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 2, 3, 1})->output(0)); - return nhwc_output; -} - -std::shared_ptr CreateDeomposedConv(const GraphData& graph_data, - ConvParams& conv_params, - ngraph::Output& reduced_input_plane, - const std::vector>& h_1_filters, - const size_t conv_index) { - ngraph::OutputVector result_chunks; - std::shared_ptr last_op; - bool horizontal_permute = (conv_params.filter_dilation_width > 1); - size_t h_1_filter_channel_count = (conv_params.input_channel_count * conv_params.filter_height); - - for (size_t output_height = 0; output_height < conv_params.output_height; output_height++) { - size_t offset = output_height * conv_params.input_width * h_1_filter_channel_count; - auto row = (conv_params.output_height == 1) - ? reduced_input_plane - : FlatCrop(reduced_input_plane, offset, conv_params.input_width * h_1_filter_channel_count); - /* - * Padded row - * | - * ??? ??? - * | - * Split in vertical dim - * / | \ - * Concat - * | - * Permute - * | - * Transpose (NHWC => NCHW) - * | - * 1D Conv (Bias | MaxPooling) - * | - * Transpose (NCHW => NHWC) - */ - auto nhwc_conv_y_input = row; - - if (horizontal_permute) { - // Horizontal split - transform input accordingly - ngraph::OutputVector dilated_chunks; - std::shared_ptr dilated_chunks_concat = nhwc_conv_y_input.get_node_shared_ptr(); - - // We need to calculate some parameters in case horizontal stride > 1 is used, because if we use the ones - // available from the original convolution we won't take into account the fact horizontal strides will be - // supported by the newly created 1D convolution, and not by decomposition - size_t filter_dilation_width = conv_params.filter_width > 1 ? conv_params.filter_dilation_width : 1; - size_t output_width = (conv_params.input_width - (filter_dilation_width * (conv_params.filter_width - 1))); - - if (conv_params.filter_width > 1) { - for (size_t filter_width = 0; filter_width < conv_params.filter_width; filter_width++) { - size_t offset = filter_width * conv_params.filter_dilation_width * h_1_filter_channel_count; - auto slice = FlatCrop(row, offset, h_1_filter_channel_count * output_width); - dilated_chunks.push_back(slice); - } - - dilated_chunks_concat = std::make_shared(dilated_chunks, 0); - } - - auto transposed_dilated_chunks = std::make_shared( - dilated_chunks_concat, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 0})->output(0)); - - auto flattened_dilated_conv_input = std::make_shared( - transposed_dilated_chunks, - ov::op::v0::Constant::create( - ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{1, 1, output_width, h_1_filter_channel_count * conv_params.filter_width}), - false); - - nhwc_conv_y_input = flattened_dilated_conv_input; - } else { - // If no horizontal split is done, only reshape is required before decomposed convolution - nhwc_conv_y_input = std::make_shared( - nhwc_conv_y_input, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{1, 1, conv_params.input_width, h_1_filter_channel_count}), - false); - } - - // Pointwise convolutions - // Valid 1D convolution wrapped with transposes NHWC => NCHW => Conv => NCHW => NHWC - // Activation function can be fused with convolution only if it isn't split - auto nhwc_y_output = Create1DConv(graph_data, - conv_params, - nhwc_conv_y_input, - h_1_filters[conv_index], - conv_index, - output_height); - result_chunks.push_back(nhwc_y_output); - last_op = nhwc_y_output; - } - - // Horizontal dimemsion greater than 1 - if (result_chunks.size() > 1) { - // Concat in horizontal dimension - // In NHWC index of H is 1 - auto concatenated_sub_results = std::make_shared(result_chunks, 1); - last_op = concatenated_sub_results; - } - return last_op; -} - -static size_t CalculateConvCount(const ConvParams& conv_params) { - // Check if split of plane due to GNA HW limitations of 768 filter elements is possible - size_t conv_count = 1; - size_t total_factorized_conv_channel_count = - (conv_params.input_channel_count * conv_params.filter_height * conv_params.filter_width); - while (total_factorized_conv_channel_count / conv_count > Limitations::kConvFilterMaxSize || - total_factorized_conv_channel_count % conv_count != 0 || conv_params.filter_channel_count % conv_count != 0) - conv_count++; - - return conv_count++; -} - -static bool ShouldDecompose(GraphData& graph_data, const ConvParams& conv_params) { - // Calculate the number of splits required - graph_data.conv_count = CalculateConvCount(conv_params); - - // Concat (copy) layer limitation allows to split up to a certain limit - // Currently we are able to split only convolutions without pooling in horizontal dimension - if (graph_data.conv_count > Limitations::kCopyMaxGrouping || - ((graph_data.pool_size_width > 1 || graph_data.pool_stride_width > 1) && graph_data.conv_count > 1)) - return false; - - // GNA supported features or handled otherwise - there is no need to decompose such convolution - if (graph_data.conv_count == 1 && - (((conv_params.input_height == 1 || conv_params.input_width == 1) && conv_params.filter_dilation_width == 1 && - conv_params.filter_dilation_height == 1) || - (conv_params.input_height > 1 && conv_params.input_width > 1 && - conv_params.input_width == conv_params.filter_width && conv_params.filter_stride_width == 1))) - return false; - - return true; -} - -std::shared_ptr Decompose(const GraphData& graph_data, ConvParams& conv_params) { - std::vector> partial_conv_results; - - // Split input and filters due to GNA filter element count limit - auto split_planes = SplitInput(graph_data, conv_params); - auto h_1_filters = SplitFilters(graph_data, conv_params); - - // Do transformations in each of the splits created above - for (size_t conv_index = 0; conv_index < graph_data.conv_count; conv_index++) { - ngraph::Output& split_input_plane = split_planes[conv_index]; - - // Input data needs to be prepared before 2D convolution decomposition - if (conv_params.filter_height > 1 || conv_params.filter_stride_height > 1) { - TransformInput(graph_data, conv_params, split_input_plane); - } - - auto flat_conv = CreateDeomposedConv(graph_data, conv_params, split_input_plane, h_1_filters, conv_index); - partial_conv_results.push_back(flat_conv); - } - - std::shared_ptr conv_result = partial_conv_results.front(); - for (size_t i = 1; i < partial_conv_results.size(); i++) { - auto add_result = std::make_shared(partial_conv_results[i], conv_result); - conv_result = add_result; - } - - // Activation function after trailing Transpose NCHW->NHWC - if (graph_data.af && graph_data.conv_count > 1) { - auto af_result = graph_data.af->clone_with_new_inputs({conv_result}); - conv_result = af_result; - } - // We need to put the same name as before for the Convolution layer, so its output can be used as network result - std::string conv_result_name = graph_data.last_op_in_sequence_for_replacement->get_friendly_name(); - ngraph::replace_node(graph_data.last_op_in_sequence_for_replacement, conv_result); - conv_result->set_friendly_name(conv_result_name); - - return std::make_shared(conv_result); -} - -std::shared_ptr Decompose2DConvTestFixture::get_reference(const bool& fq, - const modelType& model, - const ngraph::PartialShape& input_shape, - GraphData& graph_data, - ConvParams& conv_params) { - auto input_params = std::make_shared(ngraph::element::i64, input_shape); - graph_data.input_node = input_params; - - ShouldDecompose(graph_data, conv_params); - - if (model != modelType::TranspConvTransp) { - graph_data.bias_const = - ReshapeBiasConst(std::dynamic_pointer_cast(graph_data.bias), conv_params); - } - - // Create decomposed reference function - std::shared_ptr result; - result = Decompose(graph_data, conv_params); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -// --------------------------------------------------------------------------------------------------------------------- - -void execute_test(modelType model, - std::shared_ptr function, - std::shared_ptr reference_function) { - ngraph::pass::Manager manager; - manager.register_pass(); - InferenceEngine::Precision gnaPrecision = InferenceEngine::Precision::I16; - - switch (model) { - default: - case modelType::TranspConvTransp: - case modelType::TranspConvBcastAddTransp: - case modelType::TranspConvActTransp: - case modelType::TranspConvBcastAddMaxPoolTransp: - case modelType::TranspConvBcastAddActTransp: - case modelType::TranspConvBcastAddMaxPoolActTransp: - manager.register_pass(gnaPrecision); - break; - case modelType::TranspConvTranspBcastAdd: - manager.register_pass(gnaPrecision); - break; - case modelType::TranspConvTranspBcastAddAct: - manager.register_pass(gnaPrecision); - break; - } - - manager.run_passes(function); - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -TEST_P(Decompose2DConvTestFixture, CompareFunctions) { - execute_test(model, function, reference_function); -} - -INSTANTIATE_TEST_SUITE_P(Decompose2DConvTestSuite, - Decompose2DConvTestFixture, - ::testing::Combine( - // With / without Fake Quantize layers - ::testing::Values(true, false), - ::testing::Values(std::make_tuple(modelType::TranspConvTransp, - ngraph::PartialShape{1, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}), - std::make_tuple(modelType::TranspConvBcastAddTransp, - ngraph::PartialShape{1, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}), - std::make_tuple(modelType::TranspConvActTransp, - ngraph::PartialShape{1, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}), - std::make_tuple(modelType::TranspConvBcastAddMaxPoolTransp, - ngraph::PartialShape{1, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}), - std::make_tuple(modelType::TranspConvBcastAddActTransp, - ngraph::PartialShape{1, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}), - std::make_tuple(modelType::TranspConvBcastAddMaxPoolActTransp, - ngraph::PartialShape{1, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}), - std::make_tuple(modelType::TranspConvTranspBcastAdd, - ngraph::PartialShape{1, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1, 1, 4}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}), - std::make_tuple(modelType::TranspConvTranspBcastAddAct, - ngraph::PartialShape{1, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1, 1, 4}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1})))); - -TEST_P(Decompose2DConvTestInvalidFixture, CompareFunctions) { - execute_test(model, function, reference_function); -} - -INSTANTIATE_TEST_SUITE_P(Decompose2DConvInvalidTestSuite, - Decompose2DConvTestInvalidFixture, - ::testing::Combine( - // With / without Fake Quantize layers - ::testing::Values(true, false), - ::testing::Values(std::make_tuple(modelType::TranspConvTransp, - ngraph::PartialShape{1, 1, 4, 8}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}), - std::make_tuple(modelType::TranspConvBcastAddTransp, - ngraph::PartialShape{2, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}), - std::make_tuple(modelType::TranspConvActTransp, - ngraph::PartialShape{2, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}), - std::make_tuple(modelType::TranspConvBcastAddMaxPoolTransp, - ngraph::PartialShape{1, 16, 16, 128}, - ngraph::Shape{5, 5}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{2, 2}), - std::make_tuple(modelType::TranspConvBcastAddActTransp, - ngraph::PartialShape{2, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}), - std::make_tuple(modelType::TranspConvBcastAddMaxPoolActTransp, - ngraph::PartialShape{1, 16, 16, 128}, - ngraph::Shape{4, 4}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 4, 1, 1}, - ngraph::Strides{2, 2}, - ngraph::Shape{1, 2}), - std::make_tuple(modelType::TranspConvTranspBcastAdd, - ngraph::PartialShape{2, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1, 1, 4}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2}), - std::make_tuple(modelType::TranspConvTranspBcastAddAct, - ngraph::PartialShape{2, 4, 4, 32}, - ngraph::Shape{1, 2}, - ngraph::Strides{1, 1}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1, 1, 4}, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 2})))); - -} // namespace - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_decompose_mvn.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_decompose_mvn.cpp deleted file mode 100644 index a568ab5d5fd..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_decompose_mvn.cpp +++ /dev/null @@ -1,351 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset2.hpp" -#include "openvino/opsets/opset8.hpp" -#include "transformations/decompose_mvn.hpp" -#include "transformations/op_conversions/convert_mvn1_to_mvn6.hpp" - -using namespace ov::intel_gna::limitations; - -namespace decomposeMVN { - -typedef std::tuple - decomposeMVNParams; - -struct MVNParams { - size_t N; - size_t C; - size_t H; - size_t W = 0; - size_t num_parts; - float eps; - ngraph::op::MVNEpsMode eps_mode; - bool normalize_variance; -}; - -static std::shared_ptr NormalizeVariance( - const MVNParams& mvn_data, - const std::shared_ptr& subtract_mean, - const std::shared_ptr& avg_broadcast_const) { - // Prepare consts - auto combined_C_H = mvn_data.C * mvn_data.H; - - std::vector avg_weights(8 * mvn_data.W / mvn_data.num_parts, 1.0f / mvn_data.W); - auto avg_weights_const = ov::op::v0::Constant::create(ngraph::element::f32, - ngraph::Shape{8, mvn_data.W / mvn_data.num_parts, 1, 1}, - avg_weights); - std::vector eps_tensor(combined_C_H * mvn_data.W, mvn_data.eps); - auto eps_tensor_const = - ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1, combined_C_H * mvn_data.W}, eps_tensor); - std::vector minus_half(combined_C_H * mvn_data.W, -0.5f); - auto minus_half_const = - ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1, combined_C_H * mvn_data.W}, minus_half); - - // Calculate square of the difference between input and its mean - auto squared_diff = std::make_shared(subtract_mean, subtract_mean); - squared_diff->set_friendly_name("MvnSqrDiff"); - - // Calculate sum of the squares - auto squared_diff_reshape = std::make_shared( - squared_diff, - ov::op::v0::Constant::create( - ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{mvn_data.N, combined_C_H * mvn_data.num_parts, 1ull, mvn_data.W / mvn_data.num_parts}), - false); - auto transposed_input_3 = std::make_shared( - squared_diff_reshape, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 3, 1, 2})); - auto transposed_avg_conv_3 = std::make_shared(transposed_input_3, - avg_weights_const, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}, - ngraph::op::PadType::VALID); - transposed_avg_conv_3->set_friendly_name("MvnAvg3"); - auto avg_conv_3 = std::make_shared( - transposed_avg_conv_3, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 2, 3, 1})); - auto reshape_avg_conv_3 = std::make_shared( - avg_conv_3, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{mvn_data.N, 1ull, combined_C_H, 8 * mvn_data.num_parts}), - false); - auto transposed_input_4 = std::make_shared( - reshape_avg_conv_3, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 3, 1, 2})); - auto transposed_avg_conv_4 = std::make_shared(transposed_input_4, - avg_broadcast_const, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}, - ngraph::op::PadType::VALID); - transposed_avg_conv_4->set_friendly_name("MvnAvg4"); - auto avg_conv_4 = std::make_shared( - transposed_avg_conv_4, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 2, 3, 1})); - auto reshape_avg_conv_4 = std::make_shared( - avg_conv_4, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - ngraph::Shape{1ull, combined_C_H * mvn_data.W}), - false); - std::shared_ptr inv_stdev; - - // Create normalization part of the graph - // We ignore inside/outside epsilon position here and always use inside, to get better accuracy - // even though the built-in MVN1 to MVN6 transformation enforces outside setting - - // Add epsilon inside the square root - auto add_epsilon = std::make_shared(eps_tensor_const, reshape_avg_conv_4); - - // Calculate square root and inversion - auto log_var_eps = std::make_shared(add_epsilon); - log_var_eps->set_friendly_name("MvnLogVarEps"); - auto log_inv_stdev = std::make_shared(log_var_eps, minus_half_const); - log_inv_stdev->set_friendly_name("MvnLogInvStdev"); - inv_stdev = std::make_shared(log_inv_stdev); - inv_stdev->set_friendly_name("MvnInvStdev"); - - auto normalized_output = std::make_shared(subtract_mean, inv_stdev); - normalized_output->set_friendly_name("MvnOutput"); - - return normalized_output; -} - -static std::shared_ptr Decompose(const std::shared_ptr input_node, - const MVNParams& mvn_data) { - // Prepare data - auto combined_C_H = mvn_data.C * mvn_data.H; - - std::vector neg_avg_weights(8 * mvn_data.W / mvn_data.num_parts, -1.0f / mvn_data.W); - auto neg_avg_weights_const = ov::op::v0::Constant::create(ngraph::element::f32, - ngraph::Shape{8, mvn_data.W / mvn_data.num_parts, 1, 1}, - neg_avg_weights); - - std::vector avg_broadcast(8 * mvn_data.W * mvn_data.num_parts, 0.0f); - for (size_t i = 0; i < mvn_data.W * mvn_data.num_parts; i++) { - avg_broadcast[i * 8] = 1.0f; - } - auto avg_broadcast_const = ov::op::v0::Constant::create(ngraph::element::f32, - ngraph::Shape{mvn_data.W, 8 * mvn_data.num_parts, 1, 1}, - avg_broadcast); - - // Create average calculation part of the graph - // We assume C = 1 case (combined channels) - auto reshape = std::make_shared( - input_node, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{mvn_data.N, 1ull, combined_C_H, mvn_data.W}), - false); - auto input_4d = std::make_shared( - reshape, - ov::op::v0::Constant::create( - ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{mvn_data.N, combined_C_H * mvn_data.num_parts, 1ull, mvn_data.W / mvn_data.num_parts}), - false); - auto input_2d = std::make_shared( - reshape, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - ngraph::Shape{1ull, combined_C_H * mvn_data.W}), - false); - auto transposed_input_1 = std::make_shared( - input_4d, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 3, 1, 2})); - auto transposed_avg_conv_1 = std::make_shared(transposed_input_1, - neg_avg_weights_const, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}, - ngraph::op::PadType::VALID); - transposed_avg_conv_1->set_friendly_name("MvnAvg1"); - auto avg_conv_1 = std::make_shared( - transposed_avg_conv_1, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 2, 3, 1})); - auto reshape_avg_conv_1 = std::make_shared( - avg_conv_1, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{mvn_data.N, 1ull, combined_C_H, 8 * mvn_data.num_parts}), - false); - auto transposed_input_2 = std::make_shared( - reshape_avg_conv_1, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 3, 1, 2})); - auto transposed_avg_conv_2 = std::make_shared(transposed_input_2, - avg_broadcast_const, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}, - ngraph::op::PadType::VALID); - transposed_avg_conv_2->set_friendly_name("MvnAvg2"); - auto avg_conv_2 = std::make_shared( - transposed_avg_conv_2, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 2, 3, 1})); - auto avg_conv_2_2d = std::make_shared( - avg_conv_2, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{2}, - ngraph::Shape{1ull, combined_C_H * mvn_data.W}), - false); - auto subtract_mean = std::make_shared(input_2d, avg_conv_2_2d); - subtract_mean->set_friendly_name("MvnSubMean"); - - std::shared_ptr mvn_output, pre_output = subtract_mean; - - // Normalize variance if required - if (mvn_data.normalize_variance) { - pre_output = NormalizeVariance(mvn_data, subtract_mean, avg_broadcast_const); - } - - // Reshape (combined channels) back to get the final output - if (input_node->get_output_shape(0).size() == 3) { - mvn_output = std::make_shared( - pre_output, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {mvn_data.C, mvn_data.H, mvn_data.W}), - false); - } else { - mvn_output = std::make_shared( - pre_output, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{4}, - {mvn_data.N, mvn_data.C, mvn_data.H, mvn_data.W}), - false); - } - - return std::make_shared(mvn_output); -} - -std::shared_ptr getReferenceFunction(const ngraph::Shape& input_shape, - const bool& normalize_variance, - const float& eps, - const ngraph::op::MVNEpsMode& eps_mode, - const InferenceEngine::SizeVector& axes) { - MVNParams mvn_data; - auto mvn_shape_size = input_shape.size(); - - if (mvn_shape_size == 4) { - mvn_data.N = input_shape[0]; - mvn_data.C = input_shape[1]; - mvn_data.H = input_shape[2]; - mvn_data.W = input_shape[3]; - } else if (mvn_shape_size == 3) { - mvn_data.N = 1; - mvn_data.C = input_shape[0]; - mvn_data.H = input_shape[1]; - mvn_data.W = input_shape[2]; - } - - mvn_data.eps = eps; - mvn_data.eps_mode = eps_mode; - mvn_data.normalize_variance = normalize_variance; - mvn_data.num_parts = 1; - - while (mvn_data.W / mvn_data.num_parts > Limitations::kConvFilterMaxSize) { - mvn_data.num_parts *= 2; - } - - // Create decomposed reference function - auto input_params = std::make_shared(ngraph::element::f32, input_shape); - std::shared_ptr result = Decompose(input_params, mvn_data); - - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -std::shared_ptr getInitialFunction(const ngraph::Shape& input_shape, - const bool& normalize_variance, - const float& eps, - const ngraph::op::MVNEpsMode& eps_mode, - const InferenceEngine::SizeVector& axes, - const bool& across_channels, - const bool& mvn_version_6) { - auto input_params = std::make_shared(ngraph::element::f32, input_shape); - std::shared_ptr mvn; - - if (mvn_version_6) { - const auto axesConst = - std::make_shared(ngraph::element::i64, ngraph::Shape{axes.size()}, axes); - mvn = std::make_shared(input_params, axesConst, normalize_variance, eps, eps_mode); - } else { - mvn = std::make_shared(input_params, across_channels, normalize_variance, eps); - } - - auto result = std::make_shared(mvn); - - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -} // namespace decomposeMVN - -// --------------------------------------------------------------------------------------------------------------------- - -namespace { - -void execute_test(std::shared_ptr function, std::shared_ptr reference_function) { - ngraph::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -} // namespace - -TEST(TransformationTests, DecomposeMVNTest) { - for (auto mvn_version_6 : {true, false}) { - for (auto normalize_variance : {true, false}) { - execute_test(decomposeMVN::getInitialFunction(ngraph::Shape{1, 1, 5, 300}, - normalize_variance, - 1.0e-09f, - ngraph::op::MVNEpsMode::INSIDE_SQRT, - InferenceEngine::SizeVector{2, 1}, - false, - mvn_version_6), - decomposeMVN::getReferenceFunction(ngraph::Shape{1, 1, 5, 300}, - normalize_variance, - 1.0e-09f, - ngraph::op::MVNEpsMode::INSIDE_SQRT, - InferenceEngine::SizeVector{2, 1})); - execute_test(decomposeMVN::getInitialFunction(ngraph::Shape{1, 6, 256}, - normalize_variance, - 1.0e-09f, - ngraph::op::MVNEpsMode::INSIDE_SQRT, - InferenceEngine::SizeVector{2}, - false, - mvn_version_6), - decomposeMVN::getReferenceFunction(ngraph::Shape{1, 6, 256}, - normalize_variance, - 1.0e-09f, - ngraph::op::MVNEpsMode::INSIDE_SQRT, - InferenceEngine::SizeVector{2})); - } - } -} diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_handle_transposes_around_matmul.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_handle_transposes_around_matmul.cpp deleted file mode 100644 index 7fbdfd7cf40..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_handle_transposes_around_matmul.cpp +++ /dev/null @@ -1,494 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset7.hpp" -#include "transformations/handle_transposes_around_matmul.hpp" - -namespace handle_transpose_before_matmul { - -std::shared_ptr CreateTransposeMatmulFunction(const ngraph::Shape& input_shape, - const ngraph::Shape& reshape_shape, - const ngraph::Shape& matmul_shape, - bool create_reshape_after_transpose) { - auto input_params = std::make_shared(ngraph::element::i64, input_shape); - - auto new_shape_const = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{reshape_shape.size()}, reshape_shape); - auto reshape = std::make_shared(input_params, new_shape_const, false); - - auto transpose_order = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 0}); - auto transpose = std::make_shared(reshape, transpose_order); - - std::vector data(ngraph::shape_size(matmul_shape)); - std::iota(std::begin(data), std::end(data), 1); - auto constant = ov::op::v0::Constant::create(ngraph::element::i64, matmul_shape, data); - std::shared_ptr matmul; - if (create_reshape_after_transpose) { - auto reshape_after_transpose_const = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{reshape_shape.size()}, reshape_shape); - auto reshape_after_transpose = - std::make_shared(transpose, reshape_after_transpose_const, false); - matmul = std::make_shared(reshape_after_transpose, constant); - } else { - matmul = std::make_shared(transpose, constant); - } - - auto result = std::make_shared(matmul); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -std::shared_ptr CreateMatmulFunction(const ngraph::Shape& input_shape, - const ngraph::Shape& reshape_shape, - const ngraph::Shape& matmul_shape, - bool create_reshape_instead_of_transpose) { - auto input_params = std::make_shared(ngraph::element::i64, input_shape); - - std::shared_ptr reshape; - auto const_shape = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{reshape_shape.size()}, reshape_shape); - if (create_reshape_instead_of_transpose) { - auto new_reshape = std::make_shared(input_params, const_shape, false); - auto new_shape_after_transpose = ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{reshape_shape.size()}, - {reshape_shape[1], reshape_shape[0]}); - reshape = std::make_shared(new_reshape, new_shape_after_transpose, false); - } else { - reshape = std::make_shared(input_params, const_shape, false); - } - - std::vector data(ngraph::shape_size(matmul_shape)); - std::iota(std::begin(data), std::end(data), 1); - auto constant = ov::op::v0::Constant::create(ngraph::element::i64, matmul_shape, data); - auto matmul = std::make_shared(reshape, constant); - - auto result = std::make_shared(matmul); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -std::shared_ptr CreateConcatTransposeMatmulFunction(const ngraph::Shape& input1_shape, - const ngraph::Shape& input2_shape, - const ngraph::Shape& reshape1_shape, - const ngraph::Shape& reshape2_shape, - bool create_reshape_after_transpose) { - auto transpose_order = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 0}); - - auto input1_params = std::make_shared(ngraph::element::i64, input1_shape); - std::vector data1(ngraph::shape_size(input1_shape)); - std::iota(std::begin(data1), std::end(data1), 1); - auto concat1_const = ov::op::v0::Constant::create(ngraph::element::i64, input1_shape, data1); - ngraph::OutputVector concat1_chunks{input1_params, concat1_const}; - auto concat1 = std::make_shared(concat1_chunks, 0); - auto transpose1 = std::make_shared(concat1, transpose_order); - - auto input2_params = std::make_shared(ngraph::element::i64, input2_shape); - std::vector data2(ngraph::shape_size(input2_shape)); - std::iota(std::begin(data2), std::end(data2), 1); - auto concat2_const = ov::op::v0::Constant::create(ngraph::element::i64, input2_shape, data2); - ngraph::OutputVector concat2_chunks{input2_params, concat2_const}; - auto concat2 = std::make_shared(concat2_chunks, 0); - auto transpose2 = std::make_shared(concat2, transpose_order); - - std::shared_ptr matmul; - - if (create_reshape_after_transpose) { - auto reshape_after_transpose1_const = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{reshape1_shape.size()}, reshape1_shape); - auto reshape_after_transpose1 = - std::make_shared(transpose1, reshape_after_transpose1_const, false); - auto reshape_after_transpose2_const = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{reshape2_shape.size()}, reshape2_shape); - auto reshape_after_transpose2 = - std::make_shared(transpose2, reshape_after_transpose2_const, false); - matmul = std::make_shared(reshape_after_transpose1, reshape_after_transpose2); - } else { - matmul = std::make_shared(transpose1, transpose2); - } - - auto result = std::make_shared(matmul); - return std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input1_params, input2_params}); -} - -std::shared_ptr CreateConcatMatmulFunction(const ngraph::Shape& input1_shape, - const ngraph::Shape& input2_shape, - const ngraph::Shape& reshape1_shape, - const ngraph::Shape& reshape2_shape, - bool create_reshape_instead_of_transpose) { - auto input1_params = std::make_shared(ngraph::element::i64, input1_shape); - std::vector data1(ngraph::shape_size(input1_shape)); - std::iota(std::begin(data1), std::end(data1), 1); - auto concat1_const = ov::op::v0::Constant::create(ngraph::element::i64, input1_shape, data1); - ngraph::OutputVector concat1_chunks{input1_params, concat1_const}; - auto concat1 = std::make_shared(concat1_chunks, 0); - - auto input2_params = std::make_shared(ngraph::element::i64, input2_shape); - std::vector data2(ngraph::shape_size(input2_shape)); - std::iota(std::begin(data2), std::end(data2), 1); - auto concat2_const = ov::op::v0::Constant::create(ngraph::element::i64, input2_shape, data2); - ngraph::OutputVector concat2_chunks{input2_params, concat2_const}; - auto concat2 = std::make_shared(concat2_chunks, 0); - - std::shared_ptr matmul; - - if (create_reshape_instead_of_transpose) { - auto new_shape_after_transpose1 = ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{reshape1_shape.size()}, - {reshape1_shape[1], reshape1_shape[0]}); - auto reshape1 = std::make_shared(concat1, new_shape_after_transpose1, false); - auto new_shape_after_transpose2 = ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{reshape2_shape.size()}, - {reshape2_shape[1], reshape2_shape[0]}); - auto reshape2 = std::make_shared(concat2, new_shape_after_transpose2, false); - matmul = std::make_shared(reshape1, reshape2); - } else { - matmul = std::make_shared(concat1, concat2); - } - - auto result = std::make_shared(matmul); - return std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input1_params, input2_params}); -} - -} // namespace handle_transpose_before_matmul - -namespace handle_transpose_after_matmul { - -std::shared_ptr CreateMatmulTransposeFunction(const ngraph::Shape& input_shape, - const ngraph::Shape& matmul_shape, - const ngraph::Shape& reshape_shape, - bool create_reshape_before_transpose, - bool enable_last_reshape, - bool enable_add, - bool matmul_on_left_side, - bool enable_fq1, - bool enable_fq2) { - auto input_params = std::make_shared(ngraph::element::i64, input_shape); - - std::vector data(ngraph::shape_size(matmul_shape)); - std::iota(std::begin(data), std::end(data), 1); - auto matmul_constant = ov::op::v0::Constant::create(ngraph::element::i64, matmul_shape, data); - std::shared_ptr node = std::make_shared(input_params, matmul_constant); - const auto matmul_output_shape = node->get_output_shape(0); - - if (enable_fq1) { - node = - std::make_shared(node, - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {0.1}), - 255); - } - - if (enable_add) { - auto add_const = ov::op::v0::Constant::create(ngraph::element::i64, matmul_output_shape, {1}); - if (matmul_on_left_side) { - node = std::make_shared(add_const, node); - } else { - node = std::make_shared(node, add_const); - } - - if (enable_fq2) { - node = std::make_shared( - node, - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {0.1}), - 255); - } - } - - if (create_reshape_before_transpose) { - auto matmul_output_shape = node->get_output_shape(0); - std::swap(matmul_output_shape[0], matmul_output_shape[1]); - auto reshape_before_transpose_const = ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{matmul_output_shape.size()}, - matmul_output_shape); - node = std::make_shared(node, reshape_before_transpose_const, false); - } - - auto transpose_order = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 0}); - node = std::make_shared(node, transpose_order); - - if (enable_last_reshape) { - auto shape_const = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{reshape_shape.size()}, reshape_shape); - node = std::make_shared(node, shape_const, false); - } - - auto result = std::make_shared(node); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -std::shared_ptr CreateMatmulFunction(const ngraph::Shape& input_shape, - const ngraph::Shape& matmul_shape, - const ngraph::Shape& reshape_shape, - bool create_reshape_instead_of_transpose, - bool enable_last_reshape, - bool enable_add, - bool matmul_on_left_side, - bool enable_fq1, - bool enable_fq2) { - auto input_params = std::make_shared(ngraph::element::i64, input_shape); - - std::vector data(ngraph::shape_size(matmul_shape)); - std::iota(std::begin(data), std::end(data), 1); - auto matmul_constant = ov::op::v0::Constant::create(ngraph::element::i64, matmul_shape, data); - std::shared_ptr node = std::make_shared(input_params, matmul_constant); - const auto matmul_output_shape = node->get_output_shape(0); - - if (enable_fq1) { - node = - std::make_shared(node, - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {0.1}), - 255); - } - - if (enable_add) { - auto add_const = ov::op::v0::Constant::create(ngraph::element::i64, matmul_output_shape, {1}); - if (matmul_on_left_side) { - node = std::make_shared(add_const, node); - } else { - node = std::make_shared(node, add_const); - } - - if (enable_fq2) { - node = std::make_shared( - node, - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {0.1}), - 255); - } - } - - std::shared_ptr reshape; - auto shape_const = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{reshape_shape.size()}, reshape_shape); - if (create_reshape_instead_of_transpose) { - auto reshape_instead_of_transpose_const = - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{matmul_output_shape.size()}, - {matmul_output_shape[1], matmul_output_shape[0]}); - auto reshape_instead_of_transpose = - std::make_shared(node, reshape_instead_of_transpose_const, false); - reshape = reshape_instead_of_transpose; - if (enable_last_reshape) { - reshape = std::make_shared(reshape_instead_of_transpose, shape_const, false); - } - } else { - reshape = node; - if (enable_last_reshape) { - reshape = std::make_shared(node, shape_const, false); - } - } - - auto result = std::make_shared(reshape); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -} // namespace handle_transpose_after_matmul - -namespace { - -void RunTest(const std::shared_ptr& func, const std::shared_ptr& reference_func) { - { - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -} // namespace - -TEST(TransformationTests, InsertTransposeBeforeMatmulTest) { - RunTest(handle_transpose_before_matmul::CreateMatmulFunction({2, 8}, {8, 2}, {2, 1}, false), - handle_transpose_before_matmul::CreateTransposeMatmulFunction({2, 8}, {8, 2}, {2, 1}, true)); - RunTest(handle_transpose_before_matmul::CreateMatmulFunction({1, 16}, {8, 2}, {2, 1}, false), - handle_transpose_before_matmul::CreateTransposeMatmulFunction({1, 16}, {8, 2}, {2, 1}, true)); - RunTest(handle_transpose_before_matmul::CreateMatmulFunction({1, 2, 8}, {8, 2}, {2, 1}, false), - handle_transpose_before_matmul::CreateTransposeMatmulFunction({1, 2, 8}, {8, 2}, {2, 1}, true)); - RunTest( - handle_transpose_before_matmul::CreateConcatMatmulFunction({4, 16}, {8, 8}, {8, 16}, {16, 8}, false), - handle_transpose_before_matmul::CreateConcatTransposeMatmulFunction({4, 16}, {8, 8}, {8, 16}, {16, 8}, true)); -} - -TEST(TransformationTests, InsertTransposeBeforeMatmulTestReshapeInOutEq) { - RunTest(handle_transpose_before_matmul::CreateMatmulFunction({2, 9}, {9, 2}, {2, 1}, false), - handle_transpose_before_matmul::CreateMatmulFunction({2, 9}, {9, 2}, {2, 1}, false)); - RunTest(handle_transpose_before_matmul::CreateMatmulFunction({9, 2}, {9, 2}, {2, 1}, false), - handle_transpose_before_matmul::CreateMatmulFunction({9, 2}, {9, 2}, {2, 1}, false)); - RunTest(handle_transpose_before_matmul::CreateConcatMatmulFunction({8, 16}, {8, 16}, {16, 16}, {16, 16}, false), - handle_transpose_before_matmul::CreateConcatMatmulFunction({8, 16}, {8, 16}, {16, 16}, {16, 16}, false)); -} - -TEST(TransformationTests, RemoveTransposeBeforeMatmulTest) { - RunTest(handle_transpose_before_matmul::CreateTransposeMatmulFunction({1, 8}, {2, 4}, {2, 1}, false), - handle_transpose_before_matmul::CreateMatmulFunction({1, 8}, {2, 4}, {2, 1}, true)); - RunTest( - handle_transpose_before_matmul::CreateConcatTransposeMatmulFunction({4, 16}, {8, 8}, {8, 16}, {16, 8}, false), - handle_transpose_before_matmul::CreateConcatMatmulFunction({4, 16}, {8, 8}, {8, 16}, {16, 8}, true)); -} - -TEST(TransformationTests, RemoveTransposeBeforeMatmulTestReshapeInOutEq) { - RunTest(handle_transpose_before_matmul::CreateTransposeMatmulFunction({2, 8}, {2, 8}, {2, 5}, false), - handle_transpose_before_matmul::CreateTransposeMatmulFunction({2, 8}, {2, 8}, {2, 5}, false)); -} - -TEST(TransformationTests, InsertTransposeAfterMatmulTest) { - for (auto enable_add : {true, false}) { - for (auto matmul_on_left_side : {true, false}) { - for (auto enable_fq1 : {true, false}) { - for (auto enable_fq2 : {true, false}) { - RunTest(handle_transpose_after_matmul::CreateMatmulFunction({4, 1}, - {1, 8}, - {2, 16}, - false, - true, - enable_add, - matmul_on_left_side, - enable_fq1, - enable_fq2), - handle_transpose_after_matmul::CreateMatmulTransposeFunction({4, 1}, - {1, 8}, - {2, 16}, - true, - true, - enable_add, - matmul_on_left_side, - enable_fq1, - enable_fq2)); - RunTest(handle_transpose_after_matmul::CreateMatmulFunction({1, 256}, - {256, 256}, - {8, 32}, - false, - true, - enable_add, - matmul_on_left_side, - enable_fq1, - enable_fq2), - handle_transpose_after_matmul::CreateMatmulFunction({1, 256}, - {256, 256}, - {8, 32}, - false, - true, - enable_add, - matmul_on_left_side, - enable_fq1, - enable_fq2)); - } - } - } - } -} - -TEST(TransformationTests, RemoveTransposeAfterMatmulTest) { - for (auto enable_add : {true, false}) { - for (auto matmul_on_left_side : {true, false}) { - for (auto enable_fq1 : {true, false}) { - for (auto enable_fq2 : {true, false}) { - RunTest(handle_transpose_after_matmul::CreateMatmulTransposeFunction({4, 1}, - {1, 8}, - {2, 16}, - false, - true, - enable_add, - matmul_on_left_side, - enable_fq1, - enable_fq2), - handle_transpose_after_matmul::CreateMatmulFunction({4, 1}, - {1, 8}, - {2, 16}, - true, - true, - enable_add, - matmul_on_left_side, - enable_fq1, - enable_fq2)); - } - } - } - } -} - -TEST(TransformationTests, RemoveTransposeAfterMatmulTestReshapeInOutEq) { - for (auto enable_add : {true, false}) { - for (auto matmul_on_left_side : {true, false}) { - for (auto enable_fq1 : {true, false}) { - for (auto enable_fq2 : {true, false}) { - RunTest(handle_transpose_after_matmul::CreateMatmulTransposeFunction({4, 1}, - {1, 8}, - {8, 4}, - false, - true, - enable_add, - matmul_on_left_side, - enable_fq1, - enable_fq2), - handle_transpose_after_matmul::CreateMatmulTransposeFunction({4, 1}, - {1, 8}, - {8, 4}, - false, - true, - enable_add, - matmul_on_left_side, - enable_fq1, - enable_fq2)); - } - } - } - } -} - -TEST(TransformationTests, InsertTransposeAfterMatmulTestReshapeInOutEq) { - for (auto enable_last_reshape : {true, false}) { - for (auto enable_add : {true, false}) { - for (auto matmul_on_left_side : {true, false}) { - for (auto enable_fq1 : {true, false}) { - for (auto enable_fq2 : {true, false}) { - RunTest(handle_transpose_after_matmul::CreateMatmulFunction({4, 1}, - {1, 8}, - {4, 8}, - false, - enable_last_reshape, - enable_add, - matmul_on_left_side, - enable_fq1, - enable_fq2), - handle_transpose_after_matmul::CreateMatmulFunction({4, 1}, - {1, 8}, - {4, 8}, - false, - enable_last_reshape, - enable_add, - matmul_on_left_side, - enable_fq1, - enable_fq2)); - } - } - } - } - } -} diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_insert_copy_layer.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_insert_copy_layer.cpp deleted file mode 100644 index 8ef907c90e6..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_insert_copy_layer.cpp +++ /dev/null @@ -1,1735 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "common/gna_target.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "ops/copy.hpp" -#include "ov_models/builders.hpp" -#include "transformations/insert_copy_layer.hpp" - -using namespace ov::intel_gna::limitations; -using namespace ov::intel_gna::target; - -namespace testing { - -typedef std::tuple - InsertCopyTestParams; - -class InsertCopyLayerTest : public ov::test::TestsCommon, public ::testing::WithParamInterface { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - DeviceVersion device_ver; - size_t axis, inputs_num; - std::tie(device_ver, axis, inputs_num) = obj.param; - - std::ostringstream result; - result << DeviceToString(device_ver) << "_"; - result << "inputsNum=" << inputs_num << "_"; - result << "axis=" << axis; - - return result.str(); - } - void SetUp() override; - void TearDown() override; - virtual void Validate(); - virtual void Run(); - -public: - std::shared_ptr m_func, m_ref_func; - DeviceVersion m_device_ver; - size_t m_axis, m_inputs_num; -}; - -void InsertCopyLayerTest::Validate() { - ASSERT_NO_THROW(check_rt_info(m_func)); - - auto result = compare_functions(m_func, m_ref_func); - ASSERT_TRUE(result.first); -} - -void InsertCopyLayerTest::SetUp() { - std::tie(m_device_ver, m_axis, m_inputs_num) = this->GetParam(); - Limitations::init(m_device_ver); -} -void InsertCopyLayerTest::TearDown() { - Limitations::deinit(); -} - -void InsertCopyLayerTest::Run() { - Validate(); -} - -// [Parameter] [Parameter] -// \ / \ / -// [Add] [Add] -// / | ..\ / | ..\ -// \ | ../ | [Copy] [Copy] -// [Concat] \ | ../ -// | [Concat] -// [Result] | -// [Result] -class InsertCopyLayerConcatTest : public InsertCopyLayerTest { -public: - void SetUp() override { - ngraph::Shape input_shape{10}; - InsertCopyLayerTest::SetUp(); - - { - auto params = std::make_shared(ngraph::element::i64, input_shape); - auto add = std::make_shared(params, params); - ngraph::OutputVector concat_inputs; - for (int i = 0; i < m_inputs_num; ++i) { - concat_inputs.push_back(add); - } - auto concat = std::make_shared(concat_inputs, m_axis); - auto result = std::make_shared(concat); - m_func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{params}, - "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, input_shape); - auto add = std::make_shared(params, params); - auto copy = std::make_shared(add); - ngraph::OutputVector concat_inputs = {}; - for (int i = 0; i < m_inputs_num - 1; ++i) { - concat_inputs.push_back(copy); - } - concat_inputs.push_back(add); - auto concat = std::make_shared(concat_inputs, m_axis); - auto result = std::make_shared(concat); - m_ref_func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{params}, - "Concat"); - } - } - - void Validate() override { - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(m_func); - - InsertCopyLayerTest::Validate(); - } -}; - -// [Parameter] [Parameter] -// | | -// [Split] [Split] -// / | ..\ / | ..\ -// \ | ../ | [Copy] [Copy] -// [Concat] \ | ../ -// | [Concat] -// [Result] | -// [Result] -class InsertCopyLayerSplitConcatTest : public InsertCopyLayerTest { -public: - void SetUp() override { - ngraph::Shape input_shape{256}; - InsertCopyLayerTest::SetUp(); - - { - auto params = std::make_shared(ngraph::element::i64, input_shape); - OPENVINO_SUPPRESS_DEPRECATED_START - auto split = ngraph::builder::makeSplit(params, ngraph::element::i64, m_inputs_num, m_axis); - OPENVINO_SUPPRESS_DEPRECATED_END - - ngraph::OutputVector concat_inputs; - for (int i = 0; i < m_inputs_num; ++i) { - concat_inputs.push_back(split->output(i)); - } - auto concat = std::make_shared(concat_inputs, m_axis); - auto result = std::make_shared(concat); - m_func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{params}, - "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, input_shape); - OPENVINO_SUPPRESS_DEPRECATED_START - auto split = ngraph::builder::makeSplit(params, ngraph::element::i64, m_inputs_num, m_axis); - OPENVINO_SUPPRESS_DEPRECATED_END - - ngraph::OutputVector concat_inputs; - int copy_layer_interval = - (Limitations::get_instance()->get_memory_alignment() / Limitations::kBytesPerSplitElement) * - m_inputs_num / input_shape[0]; - - for (int i = 0; i < m_inputs_num; ++i) { - if (m_inputs_num == 1 || (i % copy_layer_interval == 0)) - concat_inputs.push_back(std::make_shared(split->output(i))); - else - concat_inputs.push_back(split->output(i)); - } - auto concat = std::make_shared(concat_inputs, m_axis); - - auto result = std::make_shared(concat); - m_ref_func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{params}, - "Concat"); - } - } - void Validate() override { - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(m_func); - - InsertCopyLayerTest::Validate(); - } -}; - -class TransformationTestsBase : public ov::test::TestsCommon, - public ::testing::WithParamInterface> { -public: - static std::string getTestCaseName(const testing::TestParamInfo>& obj) { - DeviceVersion device_ver; - std::tie(device_ver) = obj.param; - - std::ostringstream result; - result << DeviceToString(device_ver); - - return result.str(); - } - - void SetUp() override { - std::tie(m_device_ver) = this->GetParam(); - Limitations::init(m_device_ver); - } - - void TearDown() override { - m_func.reset(); - Limitations::deinit(); - } - - void RunPasses(ngraph::pass::Manager& m) { - m.run_passes(m_func); - } - - void Validate(const std::shared_ptr& f_ref) { - ASSERT_NO_THROW(check_rt_info(m_func)); - auto result1 = compare_functions(m_func, f_ref); - ASSERT_TRUE(result1.first); - } - - void Validate(const std::shared_ptr& f_ref1, const std::shared_ptr& f_ref2) { - ASSERT_NO_THROW(check_rt_info(m_func)); - - auto result1 = compare_functions(m_func, f_ref1); - auto result2 = compare_functions(m_func, f_ref2); - ASSERT_TRUE(result1.first || result2.first); - } - -public: - DeviceVersion m_device_ver; - std::shared_ptr m_func; -}; - -// [Parameter] [Parameter] -// \ / => | -// [Concat] [Copy] -// | \ / -// [Result] [Concat] -// | -// [Result] -using InsertCopyLayerMultiParamConcatTest = TransformationTestsBase; -TEST_P(InsertCopyLayerMultiParamConcatTest, CompareWithRefs) { - std::shared_ptr ref_func; - size_t axis = 0; - ngraph::Shape in_shape{10}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - ngraph::OutputVector concat_inputs{params, params}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - m_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto copy = std::make_shared(params); - - ngraph::OutputVector concat_inputs{copy, copy}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - ref_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerMultiParamConcatTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Parameter] -// / \ / \ -// [Reshape][Reshape] [Reshape][Reshape] -// \ / => | | -// [Concat] [Copy] [Copy] -// | \ / -// [Result] [Concat] -// | -// [Result] -using InsertCopyLayerMultiParamNFLConcatTest = TransformationTestsBase; -TEST_P(InsertCopyLayerMultiParamNFLConcatTest, CompareWithRefs) { - std::shared_ptr ref_func; - size_t axis = 0; - ngraph::Shape shape = {1, 1, 2, 4}; - ngraph::Shape in_shape = {1, 2, 4}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape1 = ov::op::util::reshapeTo(params, shape); - auto reshape2 = ov::op::util::reshapeTo(params, shape); - ngraph::OutputVector concat_inputs{reshape1, reshape2}; - - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - m_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape1 = ov::op::util::reshapeTo(params, shape); - auto reshape2 = ov::op::util::reshapeTo(params, shape); - auto copy1 = std::make_shared(reshape1); - auto copy2 = std::make_shared(reshape2); - - ngraph::OutputVector concat_inputs{copy1, copy2}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - ref_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerMultiParamNFLConcatTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Parameter] -// / \ / \ -// [Reshape][Reshape] [Reshape][Reshape] -// / | \/ | / \ | -// [Result] | /\ | => [Result] [Copy [Copy] -// [Concat] [Concat] | \/ | -// | | | /\ | -// [Result] [Result] [Concat] [Concat] -// | | -// [Result] [Result] -using InsertCopyLayerMultiParamMultiNFLConcatTest = TransformationTestsBase; -TEST_P(InsertCopyLayerMultiParamMultiNFLConcatTest, CompareWithRefs) { - std::shared_ptr ref_func; - size_t axis = 0; - ngraph::Shape shape = {1, 1, 2, 4}; - ngraph::Shape in_shape = {1, 2, 4}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape1 = ov::op::util::reshapeTo(params, shape); - auto reshape2 = ov::op::util::reshapeTo(params, shape); - ngraph::OutputVector concat_inputs{reshape1, reshape2}; - - auto concat1 = std::make_shared(concat_inputs, axis); - auto concat2 = std::make_shared(concat_inputs, axis); - auto result1 = std::make_shared(concat1); - auto result2 = std::make_shared(concat2); - auto result3 = std::make_shared(reshape1); - m_func = std::make_shared(ngraph::ResultVector{result1, result2, result3}, - ngraph::ParameterVector{params}, - "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape1 = ov::op::util::reshapeTo(params, shape); - auto reshape2 = ov::op::util::reshapeTo(params, shape); - auto copy1 = std::make_shared(reshape1); - auto copy2 = std::make_shared(reshape2); - - ngraph::OutputVector concat_inputs{copy1, copy2}; - auto concat1 = std::make_shared(concat_inputs, axis); - auto concat2 = std::make_shared(concat_inputs, axis); - auto result1 = std::make_shared(concat1); - auto result2 = std::make_shared(concat2); - auto result3 = std::make_shared(reshape1); - ref_func = std::make_shared(ngraph::ResultVector{result1, result2, result3}, - ngraph::ParameterVector{params}, - "Concat"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerMultiParamMultiNFLConcatTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter][Constant] [Parameter][Constant] -// \ | / \ | / -// [Concat] \ [Copy] / -// | => \ | / -// [Result] [Concat] -// | -// [Result] -using InsertCopyLayerMultiConstConcatTest = TransformationTestsBase; -TEST_P(InsertCopyLayerMultiConstConcatTest, CompareWithRefs) { - std::shared_ptr ref_func1, ref_func2; - size_t axis = 0; - ngraph::Shape in_shape{10}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto constant = std::make_shared(ngraph::element::i64, in_shape); - - ngraph::OutputVector concat_inputs{params, constant, constant}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - m_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto constant = std::make_shared(ngraph::element::i64, in_shape); - auto copy = std::make_shared(constant); - - ngraph::OutputVector concat_inputs{params, copy, constant}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - ref_func1 = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto constant = std::make_shared(ngraph::element::i64, in_shape); - auto copy = std::make_shared(constant); - - ngraph::OutputVector concat_inputs{params, constant, copy}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - ref_func2 = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func1, ref_func2); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerMultiConstConcatTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Parameter] -// \ / \ / -// [Add] [Add] -// \ / | \ -// [Concat] => [Copy] | -// | \ / -// [Result] [Concat] -// | -// [Result] -using InsertCopyLayerMultiLayerConcatTest = TransformationTestsBase; -TEST_P(InsertCopyLayerMultiLayerConcatTest, CompareWithRefs) { - std::shared_ptr ref_func1, ref_func2; - size_t axis = 0; - ngraph::Shape in_shape{10}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto add = std::make_shared(params, params); - ngraph::OutputVector concat_inputs{add, add}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - m_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto add = std::make_shared(params, params); - auto copy = std::make_shared(add); - - ngraph::OutputVector concat_inputs{copy, add}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - ref_func1 = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto add = std::make_shared(params, params); - auto copy = std::make_shared(add); - - ngraph::OutputVector concat_inputs{add, copy}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - ref_func2 = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - // Transformation is based on outputs order and insert copy layer in one of the branches, - // so this is right, that we have two different result graph based on output order. - Validate(ref_func1, ref_func1); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerMultiLayerConcatTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Constant] [Parameter] [Constant] -// | \ | | \ | -// [Assign] \ [ReadValue] [Copy] [Copy] [ReadValue] -// \ / | \ / -// [Add] => [Assign] [Add] -// | | -// [Result] [Result] -using InsertCopyLayerMultiLayerNFLConcatTest = TransformationTestsBase; -TEST_P(InsertCopyLayerMultiLayerNFLConcatTest, CompareWithRefs) { - std::shared_ptr ref_func1, ref_func2; - size_t axis = 0; - ngraph::Shape shape = {1, 1, 2, 4}; - ngraph::Shape in_shape = {1, 2, 4}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto add = std::make_shared(params, params); - auto reshape1 = ov::op::util::reshapeTo(add, shape); - auto reshape2 = ov::op::util::reshapeTo(add, shape); - ngraph::OutputVector concat_inputs{reshape1, reshape2}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - m_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto add = std::make_shared(params, params); - auto reshape1 = ov::op::util::reshapeTo(add, shape); - auto reshape_copy = std::make_shared(reshape1); - auto reshape2 = ov::op::util::reshapeTo(add, shape); - - ngraph::OutputVector concat_inputs{reshape_copy, reshape2}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - ref_func1 = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto add = std::make_shared(params, params); - auto reshape1 = ov::op::util::reshapeTo(add, shape); - auto reshape2 = ov::op::util::reshapeTo(add, shape); - auto reshape_copy = std::make_shared(reshape2); - - ngraph::OutputVector concat_inputs{reshape1, reshape_copy}; - auto concat = std::make_shared(concat_inputs, axis); - auto result = std::make_shared(concat); - ref_func2 = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - // Transformation is based on outputs order and insert copy layer in one of the branches, - // so this is right, that we have two different result graph based on output order. - Validate(ref_func1, ref_func2); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerMultiLayerNFLConcatTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Constant] [Parameter] [Constant] -// | \ | | \ | -// [Assign] \ [ReadValue] [Copy] [Copy] [ReadValue] -// \ / | \ / -// [Add] => [Assign] [Add] -// | | -// [Result] [Result] -using InsertCopyLayerMultiParamMemoryTest = TransformationTestsBase; -TEST_P(InsertCopyLayerMultiParamMemoryTest, CompareWithRefs) { - std::shared_ptr ref_func; - ngraph::Shape in_shape{10}; - const std::string variable_name("variable_id"); - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{in_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, in_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto add = std::make_shared(input, read_value); - auto result = std::make_shared(add); - auto assign = std::make_shared(input, variable); - assign->add_control_dependency(read_value); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - m_func = std::make_shared(results, sinks, params); - } - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{in_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, in_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto copy1 = std::make_shared(input); - auto add = std::make_shared(copy1, read_value); - auto result = std::make_shared(add); - auto copy2 = std::make_shared(input); - auto assign = std::make_shared(copy2, variable); - assign->add_control_dependency(read_value); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - ref_func = std::make_shared(results, sinks, params); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerMultiParamMemoryTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Constant] [Parameter] [Constant] -// | \ | | \ | -// [Assign] \ [ReadValue] [Copy] [Copy] [ReadValue] -// \ / | \ / -// [Concat] => [Assign] [Concat] -// | | -// [Result] [Result] -using InsertCopyLayerMultiParamConcatMemoryTest = TransformationTestsBase; -TEST_P(InsertCopyLayerMultiParamConcatMemoryTest, CompareWithRefs) { - std::shared_ptr ref_func; - ngraph::Shape in_shape{10}; - size_t axis = 0; - const std::string variable_name("variable_id"); - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{in_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, in_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(input, variable); - assign->add_control_dependency(read_value); - auto concat = std::make_shared(ngraph::OutputVector{input, read_value}, axis); - auto result = std::make_shared(concat); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - m_func = std::make_shared(results, sinks, params); - } - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{in_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto copy1 = std::make_shared(input); - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, in_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(copy1, variable); - assign->add_control_dependency(read_value); - auto copy2 = std::make_shared(input); - auto concat = std::make_shared(ngraph::OutputVector{copy2, read_value}, axis); - auto result = std::make_shared(concat); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - ref_func = std::make_shared(results, sinks, params); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerMultiParamConcatMemoryTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Constant] [Parameter] [Constant] -// / \ | / \ | -// [Reshape][Reshape][ReadValue] [Reshape][Reshape][ReadValue] -// | \ / | | / -// [Assign] [Concat] => [Copy] [Copy] / -// | | \ / -// [Result] [Assign] [Concat] -// | -// [Result] -using InsertCopyLayerMultiParamNFLConcatMemoryTest = TransformationTestsBase; -TEST_P(InsertCopyLayerMultiParamNFLConcatMemoryTest, CompareWithRefs) { - std::shared_ptr ref_func; - ngraph::Shape in_shape = {1, 2, 4}; - ngraph::Shape shape1 = {1, 1, 2, 4}; - ngraph::Shape shape2 = {2, 4}; - ngraph::PartialShape allowed_shape = ngraph::PartialShape::dynamic(); - size_t axis = 0; - const std::string variable_name("variable_id"); - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{allowed_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto reshape1 = ov::op::util::reshapeTo(input, shape1); - auto reshape2 = ov::op::util::reshapeTo(input, shape2); - - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, shape2, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(reshape1, variable); - assign->add_control_dependency(read_value); - - auto concat = std::make_shared(ngraph::OutputVector{reshape2, read_value}, axis); - auto result = std::make_shared(concat); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - m_func = std::make_shared(results, sinks, params); - } - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{allowed_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto reshape1 = ov::op::util::reshapeTo(input, shape1); - auto reshape2 = ov::op::util::reshapeTo(input, shape2); - auto copy1 = std::make_shared(reshape1); - auto copy2 = std::make_shared(reshape2); - - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, shape2, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(copy1, variable); - assign->add_control_dependency(read_value); - - auto concat = std::make_shared(ngraph::OutputVector{copy2, read_value}, axis); - auto result = std::make_shared(concat); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - ref_func = std::make_shared(results, sinks, params); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerMultiParamNFLConcatMemoryTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Constant] [Parameter] [Constant] -// | | | | -// [Reshape] [ReadValue] [Reshape] [ReadValue] -// | / | / -// [CropIE] / => [CropIE] / -// | \ / | \ / -// [Assign] [Mul] [Copy] [Mul] -// | | | -// [Result] [Assign] [Result] -using InsertCopyLayerMultiLayerConcatMemoryTest = TransformationTestsBase; -TEST_P(InsertCopyLayerMultiLayerConcatMemoryTest, CompareWithRefs) { - std::shared_ptr ref_func; - std::vector axes = {0, 1, 2, 3}; - std::vector dim = {1, 1, 2, 2}; - std::vector offset = {0, 0, 0, 0}; - ngraph::Shape shape = {1, 1, 2, 4}; - ngraph::Shape in_shape = {1, 2, 4}; - ngraph::Shape out_shape = {1, 1, 2, 2}; - const std::string variable_name("variable_id"); - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{out_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto reshape = ov::op::util::reshapeTo(input, shape); - auto crop = std::make_shared(reshape, axes, dim, offset); - - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, out_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto mul = std::make_shared(crop, read_value); - auto assign = std::make_shared(crop, variable); - assign->add_control_dependency(read_value); - auto result = std::make_shared(mul); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - m_func = std::make_shared(results, sinks, params); - } - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{out_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto reshape = ov::op::util::reshapeTo(input, shape); - auto crop = std::make_shared(reshape, axes, dim, offset); - auto copy = std::make_shared(crop); - - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, out_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto mul = std::make_shared(crop, read_value); - auto assign = std::make_shared(copy, variable); - assign->add_control_dependency(read_value); - auto result = std::make_shared(mul); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - ref_func = std::make_shared(results, sinks, params); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerMultiLayerConcatMemoryTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Constant] [Parameter] [Constant] -// | | | | -// [Reshape] [ReadValue] [Reshape] [ReadValue] -// | / | / -// [CropIE] / [CropIE] / -// | / => | / -// [Reshape] / [Reshape] / -// | \ / | \ / -// [Assign] [Add] [Copy] [Add] -// | | | -// [Result] [Assign] [Result] -using InsertCopyLayerCropMemoryTest = TransformationTestsBase; -TEST_P(InsertCopyLayerCropMemoryTest, CompareWithRefs) { - std::shared_ptr ref_func; - std::vector axes = {0, 1, 2, 3}; - std::vector dim = {1, 1, 2, 2}; - std::vector offset = {0, 0, 0, 0}; - ngraph::Shape shape1 = {1, 1, 2, 4}; - ngraph::Shape shape2 = {1, 1, 2, 2}; - ngraph::Shape in_shape = {1, 2, 4}; - const std::string variable_name("variable_id"); - - { - auto variable = - std::make_shared(ov::op::util::VariableInfo{shape2, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto reshape1 = ov::op::util::reshapeTo(input, shape1); - auto crop = std::make_shared(reshape1, axes, dim, offset); - auto reshape2 = ov::op::util::reshapeTo(crop, shape2); - - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, shape2, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto add = std::make_shared(reshape2, read_value); - auto assign = std::make_shared(reshape2, variable); - assign->add_control_dependency(read_value); - auto result = std::make_shared(add); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - m_func = std::make_shared(results, sinks, params); - } - - { - auto variable = - std::make_shared(ov::op::util::VariableInfo{shape2, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto reshape1 = ov::op::util::reshapeTo(input, shape1); - auto crop = std::make_shared(reshape1, axes, dim, offset); - auto reshape2 = ov::op::util::reshapeTo(crop, shape2); - - auto copy = std::make_shared(reshape2); - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, shape2, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto add = std::make_shared(reshape2, read_value); - auto assign = std::make_shared(copy, variable); - assign->add_control_dependency(read_value); - auto result = std::make_shared(add); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - ref_func = std::make_shared(results, sinks, params); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerCropMemoryTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Constant] [Parameter] [Constant] -// | | | | -// [Reshape] [ReadValue] [Reshape] [ReadValue] -// \ / \ / -// [Concat] => [Concat] -// | | -// [Split] [Split] -// / \ / \ -// [Assign] [Result] [Сopy] [Result] -// | -// [Assign] -using InsertCopyLayerCropNFLMemoryTest = TransformationTestsBase; -TEST_P(InsertCopyLayerCropNFLMemoryTest, CompareWithRefs) { - std::shared_ptr ref_func; - ngraph::Shape in_shape{10}; - size_t axis = 0; - const std::string variable_name("variable_id"); - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{in_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, in_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto concat = std::make_shared(ngraph::OutputVector{input, read_value}, axis); - auto axis_const = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}); - auto split = std::make_shared(concat, axis_const, 2); - auto result = std::make_shared(split); - auto assign = std::make_shared(split, variable); - assign->add_control_dependency(read_value); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - m_func = std::make_shared(results, sinks, params); - } - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{in_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, in_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto concat = std::make_shared(ngraph::OutputVector{input, read_value}, axis); - auto axis_const = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}); - auto split = std::make_shared(concat, axis_const, 2); - auto result = std::make_shared(split); - auto copy = std::make_shared(split); - auto assign = std::make_shared(copy, variable); - assign->add_control_dependency(read_value); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - ref_func = std::make_shared(results, sinks, params); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerCropNFLMemoryTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter1][Parameter2][Constant] [Parameter1][Parameter2][Constant] -// | / | | / | -// [Reshape] / [ReadValue] [Reshape] / [ReadValue] -// \ / / \ / / -// [Concat] / => [Concat] / -// / \ / / \ / -// [Assign] \ / [Сopy] \ / -// [Add] | [Add] -// | [Assign] | -// [Result] [Result] -using InsertCopyLayerConcatMemoryTest = TransformationTestsBase; -TEST_P(InsertCopyLayerConcatMemoryTest, CompareWithRefs) { - std::shared_ptr ref_func; - ngraph::Shape in_shape = {1, 2, 4}; - ngraph::Shape out_shape = {2, 2, 4}; - size_t axis = 0; - const std::string variable_name("variable_id"); - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{out_shape, ngraph::element::i64, variable_name}); - auto input1 = std::make_shared(ngraph::element::i64, in_shape); - auto input2 = std::make_shared(ngraph::element::i64, in_shape); - auto concat = std::make_shared(ngraph::OutputVector{input1, input2}, axis); - - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, out_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(concat, variable); - assign->add_control_dependency(read_value); - auto add = std::make_shared(concat, read_value); - auto result = std::make_shared(add); - - ngraph::ParameterVector params = {input1, input2}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - m_func = std::make_shared(results, sinks, params); - } - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{out_shape, ngraph::element::i64, variable_name}); - auto input1 = std::make_shared(ngraph::element::i64, in_shape); - auto input2 = std::make_shared(ngraph::element::i64, in_shape); - auto concat = std::make_shared(ngraph::OutputVector{input1, input2}, axis); - auto copy = std::make_shared(concat); - - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, out_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(copy, variable); - assign->add_control_dependency(read_value); - auto add = std::make_shared(concat, read_value); - auto result = std::make_shared(add); - - ngraph::ParameterVector params = {input1, input2}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - ref_func = std::make_shared(results, sinks, params); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerConcatMemoryTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter1][Parameter2][Constant] [Parameter1][Parameter2][Constant] -// | / | | / | -// [Reshape] / [ReadValue] [Reshape] / [ReadValue] -// \ / / \ / / -// [Concat] / => [Concat] / -// | / | / -// [Reshape] / [Reshape] / -// / \ / / \ / -// [Assign] \ / [Сopy] \ / -// [Add] | [Add] -// | [Assign] | -// [Result] [Result] -using InsertCopyLayerConcatNFLMemoryTest = TransformationTestsBase; -TEST_P(InsertCopyLayerConcatNFLMemoryTest, CompareWithRefs) { - std::shared_ptr ref_func; - ngraph::Shape shape = {1, 2, 2, 4}; - ngraph::Shape in_shape = {1, 2, 4}; - ngraph::PartialShape allowed_shape = {}; - size_t axis = 0; - const std::string variable_name("variable_id"); - - { - auto variable = - std::make_shared(ov::op::util::VariableInfo{shape, ngraph::element::i64, variable_name}); - auto input1 = std::make_shared(ngraph::element::i64, in_shape); - auto input2 = std::make_shared(ngraph::element::i64, in_shape); - auto concat = std::make_shared(ngraph::OutputVector{input1, input2}, axis); - auto reshape = ov::op::util::reshapeTo(concat, shape); - - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(reshape, variable); - assign->add_control_dependency(read_value); - auto add = std::make_shared(reshape, read_value); - auto result = std::make_shared(add); - - ngraph::ParameterVector params = {input1, input2}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - m_func = std::make_shared(results, sinks, params); - } - - { - auto variable = - std::make_shared(ov::op::util::VariableInfo{shape, ngraph::element::i64, variable_name}); - auto input1 = std::make_shared(ngraph::element::i64, in_shape); - auto input2 = std::make_shared(ngraph::element::i64, in_shape); - auto concat = std::make_shared(ngraph::OutputVector{input1, input2}, axis); - auto reshape = ov::op::util::reshapeTo(concat, shape); - auto copy = std::make_shared(reshape); - - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(copy, variable); - assign->add_control_dependency(read_value); - auto add = std::make_shared(reshape, read_value); - auto result = std::make_shared(add); - - ngraph::ParameterVector params = {input1, input2}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - ref_func = std::make_shared(results, sinks, params); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerConcatNFLMemoryTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Constant] [Parameter] [Constant] -// | | | | -// [Split] [ReadValue] [Split] [ReadValue] -// / \ / / \ / -// [Assign][Concat] [Сopy] [Concat] -// | | | -// [Result] [Assign [Result] -using InsertCopyLayerSplitMemoryTest = TransformationTestsBase; -TEST_P(InsertCopyLayerSplitMemoryTest, CompareWithRefs) { - std::shared_ptr ref_func; - ngraph::Shape in_shape{10}; - ngraph::Shape out_shape{5}; - ngraph::PartialShape allowed_shape = {{5, 10}}; - size_t axis = 0; - const std::string variable_name("variable_id"); - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{allowed_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - OPENVINO_SUPPRESS_DEPRECATED_START - auto split = ngraph::builder::makeSplit(input, ngraph::element::i64, 1, axis); - OPENVINO_SUPPRESS_DEPRECATED_END - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, out_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(split, variable); - assign->add_control_dependency(read_value); - auto concat = std::make_shared(ngraph::OutputVector{split, read_value}, axis); - auto result = std::make_shared(concat); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - m_func = std::make_shared(results, sinks, params); - } - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{allowed_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - OPENVINO_SUPPRESS_DEPRECATED_START - auto split = ngraph::builder::makeSplit(input, ngraph::element::i64, 1, axis); - OPENVINO_SUPPRESS_DEPRECATED_END - auto copy = std::make_shared(split); - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, out_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(copy, variable); - assign->add_control_dependency(read_value); - auto concat = std::make_shared(ngraph::OutputVector{split, read_value}, axis); - auto result = std::make_shared(concat); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - ref_func = std::make_shared(results, sinks, params); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerSplitMemoryTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Constant] [Parameter] [Constant] -// | | | | -// [Split] [ReadValue] [Split] [ReadValue] -// | \ / | \ / -// [Reshape]\ / [Reshape]\ / -// | \ / | \ / -// [Assign] [Concat] [Сopy] [Concat] -// | | | -// [Result] [Assign [Result] -using InsertCopyLayerSplitNFLMemoryTest = TransformationTestsBase; -TEST_P(InsertCopyLayerSplitNFLMemoryTest, CompareWithRefs) { - std::shared_ptr ref_func; - ngraph::Shape in_shape{10}; - ngraph::Shape shape{1, 5}; - ngraph::Shape out_shape{5}; - ngraph::PartialShape allowed_shape = ngraph::PartialShape::dynamic(); - size_t axis = 0; - const std::string variable_name("variable_id"); - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{allowed_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - OPENVINO_SUPPRESS_DEPRECATED_START - auto split = ngraph::builder::makeSplit(input, ngraph::element::i64, 2, axis); - OPENVINO_SUPPRESS_DEPRECATED_END - auto reshape = ov::op::util::reshapeTo(split, shape); - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, out_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(reshape, variable); - assign->add_control_dependency(read_value); - auto concat = std::make_shared(ngraph::OutputVector{split, read_value}, axis); - auto result = std::make_shared(concat); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - m_func = std::make_shared(results, sinks, params); - } - - { - auto variable = std::make_shared( - ov::op::util::VariableInfo{allowed_shape, ngraph::element::i64, variable_name}); - auto input = std::make_shared(ngraph::element::i64, in_shape); - OPENVINO_SUPPRESS_DEPRECATED_START - auto split = ngraph::builder::makeSplit(input, ngraph::element::i64, 2, axis); - OPENVINO_SUPPRESS_DEPRECATED_END - auto reshape = ov::op::util::reshapeTo(split, shape); - auto copy = std::make_shared(reshape); - auto init_value = ngraph::builder::makeConstant(ngraph::element::i64, out_shape, std::vector{0}); - auto read_value = std::make_shared(init_value, variable); - auto assign = std::make_shared(copy, variable); - assign->add_control_dependency(read_value); - auto concat = std::make_shared(ngraph::OutputVector{split, read_value}, axis); - auto result = std::make_shared(concat); - - ngraph::ParameterVector params = {input}; - ngraph::ResultVector results = {result}; - ngraph::SinkVector sinks = {assign}; - ref_func = std::make_shared(results, sinks, params); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerSplitNFLMemoryTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Parameter] -// | | -// [Reshape] [Reshape] -// | | -// [CropIE] [Constant] => [CropIE] [Constant] -// \ / | / -// [Concat] [Copy] / -// | \ / -// [Result] [Concat] -// | -// [Result] -using InsertCopyLayerCropConcatTest = TransformationTestsBase; -TEST_P(InsertCopyLayerCropConcatTest, CompareWithRefs) { - std::shared_ptr ref_func; - size_t axis = 0; - std::vector axes = {0, 1, 2, 3}; - std::vector dim = {1, 1, 2, 2}; - std::vector offset = {0, 0, 0, 0}; - ngraph::Shape shape = {1, 1, 2, 4}; - ngraph::Shape in_shape = {1, 2, 4}; - ngraph::Shape out_shape = {1, 1, 2, 2}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape = ov::op::util::reshapeTo(params, shape); - auto crop = std::make_shared(reshape, axes, dim, offset); - auto const_value = ngraph::builder::makeConstant(ngraph::element::i64, out_shape, std::vector{1}); - auto concat = std::make_shared(ngraph::OutputVector{crop, const_value}, axis); - auto result = std::make_shared(concat); - m_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape = ov::op::util::reshapeTo(params, shape); - auto crop = std::make_shared(reshape, axes, dim, offset); - auto copy = std::make_shared(crop); - auto const_value = ngraph::builder::makeConstant(ngraph::element::i64, out_shape, std::vector{1}); - auto concat = std::make_shared(ngraph::OutputVector{copy, const_value}, axis); - auto result = std::make_shared(concat); - ref_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerCropConcatTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Parameter] -// | | -// [Reshape] => [Copy] -// | | -// [Result] [Reshape] -// | -// [Result] -using InsertCopyLayerNonfuncTest = TransformationTestsBase; -TEST_P(InsertCopyLayerNonfuncTest, CompareWithRefs) { - std::shared_ptr ref_func; - std::vector axes = {0, 1, 2, 3}; - std::vector dim = {1, 1, 2, 2}; - std::vector offset = {0, 0, 0, 0}; - ngraph::Shape shape = {1, 1, 2, 4}; - ngraph::Shape in_shape = {1, 2, 4}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape = ov::op::util::reshapeTo(params, shape); - auto result = std::make_shared(reshape); - m_func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{params}, - "nonfunc"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto copy = std::make_shared(params); - auto reshape = ov::op::util::reshapeTo(copy, shape); - auto result = std::make_shared(reshape); - ref_func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{params}, - "nonfunc"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerNonfuncTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Parameter] -// / \ | -// [Reshape][Reshape] => [Copy] -// | | / \ -// [Result] [Result] [Reshape][Reshape] -// | | -// [Result] [Result] -using InsertCopyLayerNonfuncTwoSubgraphsTest = TransformationTestsBase; -TEST_P(InsertCopyLayerNonfuncTwoSubgraphsTest, CompareWithRefs) { - std::shared_ptr ref_func; - std::vector axes = {0, 1, 2, 3}; - std::vector dim = {1, 1, 2, 2}; - std::vector offset = {0, 0, 0, 0}; - ngraph::Shape shape = {1, 1, 2, 4}; - ngraph::Shape in_shape = {1, 2, 4}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape1 = ov::op::util::reshapeTo(params, shape); - auto reshape2 = ov::op::util::reshapeTo(params, shape); - auto result1 = std::make_shared(reshape1); - auto result2 = std::make_shared(reshape2); - m_func = std::make_shared(ngraph::ResultVector{result1, result2}, - ngraph::ParameterVector{params}, - "nonfunc"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto copy = std::make_shared(params); - auto reshape1 = ov::op::util::reshapeTo(copy, shape); - auto reshape2 = ov::op::util::reshapeTo(copy, shape); - auto result1 = std::make_shared(reshape1); - auto result2 = std::make_shared(reshape2); - ref_func = std::make_shared(ngraph::ResultVector{result1, result2}, - ngraph::ParameterVector{params}, - "nonfunc"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerNonfuncTwoSubgraphsTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Parameter] -// | | -// [Reshape] [Copy] -// / \ | -// [Result] [Result] [Reshape] -// / \ -// [Result] [Result] -using InsertCopyLayerNonfuncTwoResultsTest = TransformationTestsBase; -TEST_P(InsertCopyLayerNonfuncTwoResultsTest, CompareWithRefs) { - std::shared_ptr ref_func; - std::vector axes = {0, 1, 2, 3}; - std::vector dim = {1, 1, 2, 2}; - std::vector offset = {0, 0, 0, 0}; - ngraph::Shape shape = {1, 1, 2, 4}; - ngraph::Shape in_shape = {1, 2, 4}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape = ov::op::util::reshapeTo(params, shape); - auto result1 = std::make_shared(reshape); - auto result2 = std::make_shared(reshape); - m_func = std::make_shared(ngraph::ResultVector{result1, result2}, - ngraph::ParameterVector{params}, - "nonfunc"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto copy = std::make_shared(params); - auto reshape = ov::op::util::reshapeTo(copy, shape); - auto result1 = std::make_shared(reshape); - auto result2 = std::make_shared(reshape); - ref_func = std::make_shared(ngraph::ResultVector{result1, result2}, - ngraph::ParameterVector{params}, - "nonfunc"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerNonfuncTwoResultsTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Parameter] -// | | -// [Reshape] [Reshape] -// | \ => | \ -// [Relu] [Reshape] [Relu] [Copy] -// | | | | -// [Result] [Result] [Result] [Reshape] -// | -// [Result] -using InsertCopyLayerNFLBranchTest = TransformationTestsBase; -TEST_P(InsertCopyLayerNFLBranchTest, CompareWithRefs) { - std::shared_ptr ref_func; - std::vector axes = {0, 1, 2, 3}; - std::vector dim = {1, 1, 2, 2}; - std::vector offset = {0, 0, 0, 0}; - ngraph::Shape shape = {1, 1, 2, 4}; - ngraph::Shape in_shape = {1, 2, 4}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape = ov::op::util::reshapeTo(params, shape); - auto reshape2 = ov::op::util::reshapeTo(reshape, shape); - auto result = std::make_shared(reshape2); - - auto relu = std::make_shared(reshape); - auto result_relu = std::make_shared(relu); - - m_func = std::make_shared(ngraph::ResultVector{result, result_relu}, - ngraph::ParameterVector{params}, - "nonfunc"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape = ov::op::util::reshapeTo(params, shape); - auto copy = std::make_shared(reshape); - auto reshape2 = ov::op::util::reshapeTo(copy, shape); - auto result = std::make_shared(reshape2); - - auto relu = std::make_shared(reshape); - auto result_relu = std::make_shared(relu); - - ref_func = std::make_shared(ngraph::ResultVector{result, result_relu}, - ngraph::ParameterVector{params}, - "nonfunc"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerNFLBranchTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Parameter] -// | | -// [Reshape] [Reshape] -// | \ => | \ -// [Relu] [Reshape] [Relu] [Copy] -// | | | | -// [Reshape] [Result] [Reshape] [Reshape] -// | | | -// [Result] [Result] [Result] -using InsertCopyLayerNFLvsFLSubgraphTest = TransformationTestsBase; -TEST_P(InsertCopyLayerNFLvsFLSubgraphTest, CompareWithRefs) { - std::shared_ptr ref_func; - std::vector axes = {0, 1, 2, 3}; - std::vector dim = {1, 1, 2, 2}; - std::vector offset = {0, 0, 0, 0}; - ngraph::Shape shape = {1, 1, 2, 4}; - ngraph::Shape in_shape = {1, 2, 4}; - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto reshape = ov::op::util::reshapeTo(params, shape); - auto result = std::make_shared(reshape); - - auto relu = std::make_shared(params); - auto reshape2 = ov::op::util::reshapeTo(relu, shape); - auto result_relu = std::make_shared(reshape2); - - m_func = std::make_shared(ngraph::ResultVector{result, result_relu}, - ngraph::ParameterVector{params}, - "nonfunc"); - } - - { - auto params = std::make_shared(ngraph::element::i64, in_shape); - auto copy = std::make_shared(params); - auto reshape = ov::op::util::reshapeTo(copy, shape); - auto result = std::make_shared(reshape); - - auto relu = std::make_shared(params); - auto reshape2 = ov::op::util::reshapeTo(relu, shape); - auto result_relu = std::make_shared(reshape2); - - ref_func = std::make_shared(ngraph::ResultVector{result, result_relu}, - ngraph::ParameterVector{params}, - "nonfunc"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerNFLvsFLSubgraphTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -// [Parameter] [Parameter] -// | | -// [Split] [Split] -// | => | -// [Reshape] [Constant] [Reshape] -// \ / | -// [Concat] [Copy] [Constant] -// | \ / -// [Result] [Concat] -// | -// [Result] -using InsertCopyLayerSplitNFLConcatTest = TransformationTestsBase; -TEST_P(InsertCopyLayerSplitNFLConcatTest, CompareWithRefs) { - std::shared_ptr ref_func; - ngraph::Shape input_shape{1, 2, 4}; - ngraph::Shape shape{1, 1, 2, 4}; - size_t axis = 0; - - { - auto params = std::make_shared(ngraph::element::i64, input_shape); - OPENVINO_SUPPRESS_DEPRECATED_START - auto split = ngraph::builder::makeSplit(params, ngraph::element::i64, 1, axis); - OPENVINO_SUPPRESS_DEPRECATED_END - auto reshape = ov::op::util::reshapeTo(split->output(0), shape); - auto const_value = ngraph::builder::makeConstant(ngraph::element::i64, shape, std::vector{1}); - auto concat = std::make_shared(ngraph::OutputVector{reshape, const_value}, axis); - auto result = std::make_shared(concat); - m_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - { - auto params = std::make_shared(ngraph::element::i64, input_shape); - OPENVINO_SUPPRESS_DEPRECATED_START - auto split = ngraph::builder::makeSplit(params, ngraph::element::i64, 1, axis); - OPENVINO_SUPPRESS_DEPRECATED_END - auto reshape = ov::op::util::reshapeTo(split->output(0), shape); - auto copy = std::make_shared(reshape); - auto const_value = ngraph::builder::makeConstant(ngraph::element::i64, shape, std::vector{1}); - auto concat = std::make_shared(ngraph::OutputVector{copy, const_value}, axis); - - auto result = std::make_shared(concat); - ref_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{params}, "Concat"); - } - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - - RunPasses(m); - Validate(ref_func); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerSplitNFLConcatTest, - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - TransformationTestsBase::getTestCaseName); - -TEST_P(InsertCopyLayerConcatTest, CompareWithRefs) { - Run(); -} - -TEST_P(InsertCopyLayerSplitConcatTest, CompareWithRefs) { - Run(); -} - -const size_t axis = 0; -const std::vector inputCounts = {1, 64, 128, 256}; - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerConcatTest, - ::testing::Combine(::testing::ValuesIn(std::vector{DeviceVersion::GNA3_0, - DeviceVersion::GNA3_5, - DeviceVersion::GNA3_6}), - ::testing::Values(axis), - ::testing::ValuesIn(inputCounts)), - InsertCopyLayerTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertCopyLayerSplitConcatTest, - ::testing::Combine(::testing::ValuesIn(std::vector{DeviceVersion::GNA3_0, - DeviceVersion::GNA3_5, - DeviceVersion::GNA3_6}), - ::testing::Values(axis), - ::testing::ValuesIn(inputCounts)), - InsertCopyLayerTest::getTestCaseName); - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_insert_identity_layer.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_insert_identity_layer.cpp deleted file mode 100644 index 3ba212c6dc7..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_insert_identity_layer.cpp +++ /dev/null @@ -1,678 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "openvino/opsets/opset12.hpp" -#include "openvino/opsets/opset7.hpp" -#include "ops/identity.hpp" -#include "transformations/insert_identity_layer.hpp" -#include "transformations/rt_info/gna_precision_change_flag.hpp" - -namespace testing { - -using namespace ngraph::builder; -using namespace ngraph::op; -using namespace ov; -using namespace ov::opset12; -using namespace ov::pass; -using namespace ov::intel_gna; -using namespace ov::intel_gna::pass; -using namespace ov::intel_gna::op; -using namespace ov::element; -using namespace std; - -class InsertIdentityLayerTest : public ov::test::TestsCommon { -public: - virtual void Validate(); - virtual void Run(); - -public: - shared_ptr m_func, m_ref_func; - Shape m_input_shape{10}; - bool m_low_precision = false; -}; - -void InsertIdentityLayerTest::Validate() { - Manager m; - m.register_pass(); - m.register_pass(m_low_precision); - m.register_pass(); - m.register_pass(); - m.run_passes(m_func); - ASSERT_NO_THROW(check_rt_info(m_func)); - - auto result = compare_functions(m_func, m_ref_func); - ASSERT_TRUE(result.first); - - // Cleanup rt info and check - m.register_pass(); - m.run_passes(m_func); - for (auto& node : m_func->get_ordered_ops()) { - for (auto& input : node->inputs()) { - const RTMap& rt_info = input.get_rt_info(); - ASSERT_EQ(rt_info.count(rt_info::GNAPrecisionChangeFlag::get_type_info_static()), 0); - } - } -} - -void InsertIdentityLayerTest::Run() { - SetUp(); - Validate(); -} - -/******************************************************* Concat layer tests - * *******************************************************/ - -typedef tuple - InsertIdentityConcatTestParams; - -class InsertIdentityLayerConcatTest : public InsertIdentityLayerTest, - public ::testing::WithParamInterface { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - size_t axis, inputs_num; - tie(axis, inputs_num) = obj.param; - - ostringstream result; - result << "inputsNum=" << inputs_num << "_"; - result << "axis=" << axis; - - return result.str(); - } - void SetUp() override { - size_t axis, inputs_num; - tie(axis, inputs_num) = this->GetParam(); - - InsertIdentityLayerTest::SetUp(); - { - auto params = make_shared(f32, m_input_shape); - auto const_add = Constant::create(f32, m_input_shape, {1}); - auto add = make_shared(params, const_add); - OutputVector concat_inputs = {add}; - for (size_t i = 1; i < inputs_num; ++i) { - auto const_mul = Constant::create(f32, m_input_shape, {i}); - auto mul = make_shared(add, const_mul); - concat_inputs.push_back(mul); - } - auto concat = make_shared(concat_inputs, axis); - auto result = make_shared(concat); - m_func = make_shared(ResultVector{result}, ParameterVector{params}); - } - - { - auto params = make_shared(f32, m_input_shape); - auto const_add = Constant::create(f32, m_input_shape, {1}); - auto add = make_shared(params, const_add); - auto identity = make_shared(add); - OutputVector concat_inputs = {identity}; - for (size_t i = 1; i < inputs_num; ++i) { - auto const_mul = Constant::create(f32, m_input_shape, {i}); - auto mul = make_shared(identity, const_mul); - auto identity_mul = make_shared(mul); - concat_inputs.push_back(identity_mul); - } - auto concat = make_shared(concat_inputs, axis); - auto result = make_shared(concat); - m_ref_func = make_shared(ResultVector{result}, ParameterVector{params}); - } - } -}; - -const size_t axis = 0; -const vector inputCounts = {1, 8}; - -TEST_P(InsertIdentityLayerConcatTest, CompareWithRefs) { - Run(); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertIdentityLayerConcatTest, - ::testing::Combine(::testing::Values(axis), ::testing::ValuesIn(inputCounts)), - InsertIdentityLayerConcatTest::getTestCaseName); - -/******************************************************* Split layer tests - * *******************************************************/ - -class InsertIdentityLayerSplitTest : public InsertIdentityLayerTest { -public: - void SetUp() override { - InsertIdentityLayerTest::SetUp(); - { - auto params = make_shared(f32, m_input_shape); - auto const_add = Constant::create(f32, m_input_shape, {1}); - auto add = make_shared(params, const_add); - auto axis_const = Constant::create(i64, Shape{}, {0}); - auto split = make_shared(add, axis_const, 2); - auto result1 = make_shared(split->output(0)); - auto const_reshape = Constant::create(i64, {2}, {1, 5}); - auto reshape = make_shared(split->output(1), const_reshape, false); - auto const_mul = Constant::create(f32, {1, 5}, {1}); - auto mul = make_shared(reshape, const_mul); - auto result2 = make_shared(mul); - m_func = make_shared(ResultVector{result1, result2}, ParameterVector{params}); - } - - { - auto params = make_shared(f32, m_input_shape); - auto const_add = Constant::create(f32, m_input_shape, {1}); - auto add = make_shared(params, const_add); - auto identity = make_shared(add); - auto axis_const = Constant::create(i64, Shape{}, {0}); - auto split = make_shared(identity, axis_const, 2); - auto result1 = make_shared(split->output(0)); - auto const_reshape = Constant::create(i64, {2}, {1, 5}); - auto reshape = make_shared(split->output(1), const_reshape, false); - auto const_mul = Constant::create(f32, {1, 5}, {1}); - auto mul = make_shared(reshape, const_mul); - auto result2 = make_shared(mul); - m_ref_func = make_shared(ResultVector{result1, result2}, ParameterVector{params}); - } - } -}; - -TEST_F(InsertIdentityLayerSplitTest, CompareWithRefs) { - Run(); -} - -/******************************************************* Eltwise layer tests - * *******************************************************/ - -typedef tuple - InsertIdentityEltwiseTestParams; - -class InsertIdentityLayerEltwiseTest : public InsertIdentityLayerTest, - public ::testing::WithParamInterface { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - ELTWISE_TYPE type; - bool low_precision, both_inputs_32bits; - tie(type, low_precision, both_inputs_32bits) = obj.param; - - ostringstream result; - result << "type="; - switch (type) { - case ELTWISE_TYPE::Sum: - result << "sum"; - break; - case ELTWISE_TYPE::Prod: - result << "prod"; - break; - default: - break; - } - result << "_low_precision=" << low_precision; - result << "_both_inputs_32bits=" << both_inputs_32bits; - - return result.str(); - } - void SetUp() override { - ELTWISE_TYPE type; - bool both_inputs_32bits; - tie(type, m_low_precision, both_inputs_32bits) = this->GetParam(); - - InsertIdentityLayerTest::SetUp(); - { - ParameterVector params; - auto input1 = make_shared(f32, m_input_shape); - params.push_back(input1); - auto const_input1 = Constant::create(f32, m_input_shape, {1}); - auto eltwise1 = make_shared(input1, const_input1, type); - shared_ptr second_input; - - if (both_inputs_32bits) { - auto input2 = make_shared(f32, m_input_shape); - params.push_back(input2); - auto const_input2 = Constant::create(f32, m_input_shape, {1}); - auto eltwise2 = make_shared(input2, const_input2, type); - second_input = eltwise2; - } else { - auto const_input2 = Constant::create(f32, m_input_shape, {1}); - second_input = const_input2; - } - - auto eltwise3 = make_shared(eltwise1, second_input, type); - - auto result = make_shared(eltwise3); - m_func = make_shared(ResultVector{result}, ParameterVector{params}); - } - - { - ParameterVector params; - auto input1 = make_shared(f32, m_input_shape); - params.push_back(input1); - auto const_input1 = Constant::create(f32, m_input_shape, {1}); - auto eltwise1 = make_shared(input1, const_input1, type); - shared_ptr first_input, second_input; - first_input = eltwise1; - - if (both_inputs_32bits) { - auto input2 = make_shared(f32, m_input_shape); - params.push_back(input2); - auto const_input2 = Constant::create(f32, m_input_shape, {1}); - auto eltwise2 = make_shared(input2, const_input2, type); - second_input = eltwise2; - } else { - auto const_input2 = Constant::create(f32, m_input_shape, {1}); - second_input = const_input2; - } - - if (type == ELTWISE_TYPE::Sum && !m_low_precision && both_inputs_32bits) { - auto identity = make_shared(eltwise1); - first_input = identity; - } else if (type == ELTWISE_TYPE::Prod || m_low_precision) { - auto identity = make_shared(eltwise1); - first_input = identity; - if (both_inputs_32bits) { - auto identity = make_shared(eltwise1); - second_input = identity; - } - } - - auto eltwise3 = make_shared(first_input, second_input, type); - - auto result = make_shared(eltwise3); - m_ref_func = make_shared(ResultVector{result}, ParameterVector{params}); - } - } -}; - -TEST_P(InsertIdentityLayerEltwiseTest, CompareWithRefs) { - Run(); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertIdentityLayerEltwiseTest, - ::testing::Combine(::testing::ValuesIn({ELTWISE_TYPE::Sum, ELTWISE_TYPE::Prod}), - ::testing::ValuesIn({true, false}), - ::testing::ValuesIn({true, false})), - InsertIdentityLayerEltwiseTest::getTestCaseName); - -/******************************************* Eltwise layer tests (Multiple outputs) - * *************************************************/ - -class InsertIdentityLayerEltwiseMultipleOutputTest : public InsertIdentityLayerEltwiseTest { -public: - void SetUp() override { - ELTWISE_TYPE type; - bool both_inputs_32bits; - tie(type, m_low_precision, both_inputs_32bits) = this->GetParam(); - - InsertIdentityLayerTest::SetUp(); - { - ParameterVector params; - auto input1 = make_shared(f32, m_input_shape); - params.push_back(input1); - auto const_input1 = Constant::create(f32, m_input_shape, {1}); - auto eltwise1 = make_shared(input1, const_input1, type); - shared_ptr second_input; - - if (both_inputs_32bits) { - auto input2 = make_shared(f32, m_input_shape); - params.push_back(input2); - auto const_input2 = Constant::create(f32, m_input_shape, {1}); - auto eltwise2 = make_shared(input2, const_input2, type); - second_input = eltwise2; - } else { - auto const_input2 = Constant::create(f32, m_input_shape, {1}); - second_input = const_input2; - } - auto relu = make_shared(eltwise1); - auto eltwise3 = make_shared(eltwise1, second_input, type); - - auto result1 = make_shared(relu); - auto result2 = make_shared(eltwise3); - m_func = make_shared(ResultVector{result1, result2}, ParameterVector{params}); - } - - { - ParameterVector params; - auto input1 = make_shared(f32, m_input_shape); - params.push_back(input1); - auto const_input1 = Constant::create(f32, m_input_shape, {1}); - auto eltwise1 = make_shared(input1, const_input1, type); - shared_ptr first_input, second_input; - first_input = eltwise1; - - if (both_inputs_32bits) { - auto input2 = make_shared(f32, m_input_shape); - params.push_back(input2); - auto const_input2 = Constant::create(f32, m_input_shape, {1}); - auto eltwise2 = make_shared(input2, const_input2, type); - second_input = eltwise2; - } else { - auto const_input2 = Constant::create(f32, m_input_shape, {1}); - second_input = const_input2; - } - - if (type == ELTWISE_TYPE::Sum && !m_low_precision && both_inputs_32bits) { - auto identity = make_shared(eltwise1); - first_input = identity; - } else if (type == ELTWISE_TYPE::Prod || m_low_precision) { - auto identity = make_shared(eltwise1); - first_input = identity; - if (both_inputs_32bits) { - auto identity = make_shared(eltwise1); - second_input = identity; - } - } - auto relu = make_shared(first_input); - auto eltwise3 = make_shared(first_input, second_input, type); - - auto result1 = make_shared(relu); - auto result2 = make_shared(eltwise3); - m_ref_func = make_shared(ResultVector{result1, result2}, ParameterVector{params}); - } - } -}; - -TEST_P(InsertIdentityLayerEltwiseMultipleOutputTest, CompareWithRefs) { - Run(); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertIdentityLayerEltwiseMultipleOutputTest, - ::testing::Combine(::testing::ValuesIn({ELTWISE_TYPE::Sum, ELTWISE_TYPE::Prod}), - ::testing::ValuesIn({true, false}), - ::testing::ValuesIn({true, false})), - InsertIdentityLayerEltwiseMultipleOutputTest::getTestCaseName); - -/*************************************************** Eltwise with FQ layer tests - * ****************************************************/ - -class InsertIdentityLayerEltwiseFQTest : public InsertIdentityLayerEltwiseTest { -public: - void SetUp() override { - ELTWISE_TYPE type; - bool both_inputs_32bits; - tie(type, m_low_precision, both_inputs_32bits) = this->GetParam(); - - InsertIdentityLayerTest::SetUp(); - - auto add_fake_quantize = [&](const shared_ptr& node) { - auto levels = (m_low_precision) ? numeric_limits::max() : numeric_limits::max(); - auto input_low = Constant::create(i64, Shape{1}, {1}); - auto input_high = Constant::create(i64, Shape{1}, {5}); - auto output_low = Constant::create(i64, Shape{1}, {0}); - auto output_high = Constant::create(i64, Shape{1}, {10}); - return make_shared(node, input_low, input_high, output_low, output_high, levels); - }; - - { - ParameterVector params; - auto input1 = make_shared(f32, m_input_shape); - params.push_back(input1); - auto input1_fq = add_fake_quantize(input1); - auto const_input1 = Constant::create(f32, m_input_shape, {1}); - auto const_input1_fq = add_fake_quantize(const_input1); - auto eltwise1 = make_shared(input1_fq, const_input1_fq, type); - auto eltwise1_fq = add_fake_quantize(eltwise1); - shared_ptr second_input; - - if (both_inputs_32bits) { - auto input2 = make_shared(f32, m_input_shape); - params.push_back(input2); - auto input2_fq = add_fake_quantize(input2); - auto const_input2 = Constant::create(f32, m_input_shape, {1}); - auto const_input2_fq = add_fake_quantize(const_input2); - auto eltwise2 = make_shared(input2_fq, const_input2_fq, type); - auto eltwise2_fq = add_fake_quantize(eltwise2); - second_input = eltwise2_fq; - } else { - auto const_input2 = Constant::create(f32, m_input_shape, {1}); - auto const_input2_fq = add_fake_quantize(const_input2); - second_input = const_input2_fq; - } - - auto eltwise3 = make_shared(eltwise1_fq, second_input, type); - auto eltwise3_fq = add_fake_quantize(eltwise3); - - auto result = make_shared(eltwise3_fq); - m_func = make_shared(ResultVector{result}, ParameterVector{params}); - } - - { m_ref_func = m_func->clone(); } - } -}; - -TEST_P(InsertIdentityLayerEltwiseFQTest, CompareWithRefs) { - Run(); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertIdentityLayerEltwiseFQTest, - ::testing::Combine(::testing::ValuesIn({ELTWISE_TYPE::Sum, ELTWISE_TYPE::Prod}), - ::testing::ValuesIn({true, false}), - ::testing::ValuesIn({true, false})), - InsertIdentityLayerEltwiseFQTest::getTestCaseName); - -/***************************************************** Convolution layer tests - * *****************************************************/ - -typedef tuple - InsertIdentityConvTestParams; - -class InsertIdentityLayerConvMatMulTest : public InsertIdentityLayerTest, - public ::testing::WithParamInterface { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - bool with_pool, with_act, swap_matmul; - tie(with_pool, with_act, swap_matmul) = obj.param; - - ostringstream result; - result << "with_pool=" << with_pool; - result << "_with_act=" << with_act; - result << "_swap_matmul=" << swap_matmul; - - return result.str(); - } - void SetUp() override { - bool with_pool, with_act, swap_matmul; - tie(with_pool, with_act, swap_matmul) = this->GetParam(); - - InsertIdentityLayerTest::SetUp(); - - m_input_shape = {1, 3, 1, 64}; - auto reshape_shape = Shape{3, 64}; - - { - shared_ptr last_node; - auto input = make_shared(f32, m_input_shape); - auto weights = Constant::create(f32, Shape{3, 3, 1, 2}, {1}); - auto conv = make_shared(input, - weights, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 1}, - Strides{1, 1}); - last_node = conv; - if (with_pool) { - auto max_pool = - make_shared(last_node, Strides{1, 1}, Shape{0, 0}, Shape{0, 1}, Shape{1, 2}); - last_node = max_pool; - } - if (with_act) { - auto relu = make_shared(last_node); - last_node = relu; - } - auto reshape_const = Constant::create(i64, Shape{reshape_shape.size()}, reshape_shape); - auto reshape = make_shared(last_node, reshape_const, false); - auto matmul_const = Constant::create(f32, {64, 3}, {1.2}); - auto matmul = - swap_matmul ? make_shared(matmul_const, reshape) : make_shared(reshape, matmul_const); - - auto result = make_shared(matmul); - m_func = make_shared(ResultVector{result}, ParameterVector{input}); - } - - { - shared_ptr last_node; - auto input = make_shared(f32, m_input_shape); - auto weights = Constant::create(f32, Shape{3, 3, 1, 2}, {1}); - auto conv = make_shared(input, - weights, - Strides{1, 1}, - CoordinateDiff{0, 0}, - CoordinateDiff{0, 1}, - Strides{1, 1}); - last_node = conv; - if (with_pool) { - auto max_pool = - make_shared(last_node, Strides{1, 1}, Shape{0, 0}, Shape{0, 1}, Shape{1, 2}); - last_node = max_pool; - } - if (with_act) { - auto relu = make_shared(last_node); - last_node = relu; - } else { - auto identity = make_shared(last_node); - last_node = identity; - } - auto reshape_const = Constant::create(i64, Shape{reshape_shape.size()}, reshape_shape); - auto reshape = make_shared(last_node, reshape_const, false); - auto matmul_const = Constant::create(f32, {64, 3}, {1.2}); - auto matmul = - swap_matmul ? make_shared(matmul_const, reshape) : make_shared(reshape, matmul_const); - - auto result = make_shared(matmul); - m_ref_func = make_shared(ResultVector{result}, ParameterVector{input}); - } - } -}; - -TEST_P(InsertIdentityLayerConvMatMulTest, CompareWithRefs) { - Run(); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - InsertIdentityLayerConvMatMulTest, - ::testing::Combine(::testing::ValuesIn({true, false}), - ::testing::ValuesIn({true, false}), - ::testing::ValuesIn({true, false})), - InsertIdentityLayerConvMatMulTest::getTestCaseName); - -/***************************************************** Result layer tests - * *****************************************************/ - -class InsertIdentityLayerResultTest : public InsertIdentityLayerTest { -public: - void SetUp() override { - InsertIdentityLayerTest::SetUp(); - { - auto params = make_shared(f32, m_input_shape); - auto const_add = Constant::create(f32, m_input_shape, {1}); - auto add = make_shared(params, const_add); - auto relu = make_shared(add); - auto result1 = make_shared(add); - auto result2 = make_shared(relu); - m_func = make_shared(ResultVector{result1, result2}, ParameterVector{params}); - } - - { - auto params = make_shared(f32, m_input_shape); - auto const_add = Constant::create(f32, m_input_shape, {1}); - auto add = make_shared(params, const_add); - auto identity = make_shared(add); - auto relu = make_shared(add); - auto result1 = make_shared(identity); - auto result2 = make_shared(relu); - m_ref_func = make_shared(ResultVector{result1, result2}, ParameterVector{params}); - } - } - void Validate() override { - Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(m_func); - ASSERT_NO_THROW(check_rt_info(m_func)); - - auto result = compare_functions(m_func, m_ref_func); - ASSERT_TRUE(result.first); - } -}; - -TEST_F(InsertIdentityLayerResultTest, CompareWithRefs) { - Run(); -} - -class InsertIdentityForNonQuantizableConcatInputTest : public InsertIdentityLayerTest { - std::string getName() { - return "InsertIdentityForPrecAgnosticConcatInput"; - } - - shared_ptr create_fq(const Type& type, - const shared_ptr& node, - float fq_min, - float fq_max, - std::size_t levels) { - // - auto fq_inp_min = makeConstant(type, {1}, {fq_min}); - auto fq_inp_max = makeConstant(type, {1}, {fq_max}); - auto fq_out_min = makeConstant(type, {1}, {fq_min}); - auto fq_out_max = makeConstant(type, {1}, {fq_max}); - return make_shared(node, fq_inp_min, fq_inp_max, fq_out_min, fq_out_max, levels); - } - -public: - void SetUp() override { - InsertIdentityLayerTest::SetUp(); - { - ov::ParameterVector inputs{std::make_shared(ov::element::f32, m_input_shape), - std::make_shared(ov::element::f32, m_input_shape)}; - auto fq = create_fq(f32, inputs[0], -1, 1, 256); - auto relu = make_shared(fq); - auto reshape_const = make_shared(i64, Shape{1}, m_input_shape); - auto reshape = make_shared(inputs[1], reshape_const, false); - auto concat = std::make_shared(ov::NodeVector{relu, reshape}, 0); - auto result = make_shared(concat); - m_func = make_shared(result, inputs, getName()); - } - - { - ov::ParameterVector inputs{std::make_shared(ov::element::f32, m_input_shape), - std::make_shared(ov::element::f32, m_input_shape)}; - auto fq = create_fq(f32, inputs[0], -1, 1, 256); - auto relu = make_shared(fq); - auto reshape_const = make_shared(i64, Shape{1}, m_input_shape); - auto reshape = make_shared(inputs[1], reshape_const, false); - // We expect the following Identity layer to be inserted - auto identity = make_shared(reshape); - auto concat = std::make_shared(ov::NodeVector{relu, identity}, 0); - auto result = make_shared(concat); - m_ref_func = make_shared(result, inputs, getName()); - } - } - - void Validate() override { - Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(m_func); - ASSERT_NO_THROW(check_rt_info(m_func)); - - auto result = compare_functions(m_func, m_ref_func); - ASSERT_TRUE(result.first); - } -}; - -TEST_F(InsertIdentityForNonQuantizableConcatInputTest, CompareWithRefs) { - Run(); -} -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_insert_reshape_around_matmul.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_insert_reshape_around_matmul.cpp deleted file mode 100644 index 8b4f021e8cb..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_insert_reshape_around_matmul.cpp +++ /dev/null @@ -1,308 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "transformations/insert_reshape_around_matmul.hpp" - -template -struct InsertReshapeAroundMatmulTest { - static std::shared_ptr CreateAdd(std::shared_ptr input, - const ngraph::Shape& constant_shape) { - std::vector data(ngraph::shape_size(constant_shape)); - std::iota(std::begin(data), std::end(data), 1); - auto constant = ov::op::v0::Constant::create(ngraph::element::i64, constant_shape, data); - return std::make_shared(input, constant); - } - - static std::shared_ptr CreateMatmul(std::shared_ptr input, - const ngraph::Shape& matmul_constant_shape, - const ngraph::Shape& permutation_shape) { - std::vector data(ngraph::shape_size(matmul_constant_shape)); - std::iota(std::begin(data), std::end(data), 1); - auto constant = ov::op::v0::Constant::create(ngraph::element::i64, matmul_constant_shape, data); - std::shared_ptr node; - node = std::make_shared(input, constant); - - if (ADD) { - std::vector add_constant_shape(2, 1); - auto matmul_shape = node->get_output_shape(0); - data.resize(ngraph::shape_size(matmul_shape)); - std::iota(std::begin(data), std::end(data), 1); - - if (ADD_FULL_DIM) { - add_constant_shape.resize(matmul_shape.size(), 1); - std::copy(matmul_shape.begin(), matmul_shape.end(), add_constant_shape.begin()); - } else { - std::copy_if(matmul_shape.begin(), matmul_shape.end(), add_constant_shape.begin(), [](size_t e) { - return e > 1; - }); - } - - auto constant_add = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{add_constant_shape}, data); - if (ADD_FIRST_INPUT_NOT_CONSTANT) { - node = std::make_shared(node, constant_add); - } else { - node = std::make_shared(constant_add, node); - } - } - - if (FQ) { - node = std::make_shared( - node, - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {-0.1}), - ov::op::v0::Constant::create(ngraph::element::f32, {1}, {0.1}), - 255); - } - - if (TRANSPOSE) { - node = std::make_shared( - node, - ov::op::v0::Constant::create(ngraph::element::i64, {permutation_shape.size()}, permutation_shape)); - } - - return node; - } - - static std::shared_ptr CreateFunction(const ngraph::Shape& input_shape, - const ngraph::Shape& matmul_constant_shape, - const ngraph::Shape& permutation_shape = ngraph::Shape()) { - auto input = std::make_shared(ngraph::element::i64, input_shape); - auto before = std::make_shared(input); - auto matmul = CreateMatmul(before, matmul_constant_shape, permutation_shape); - auto after = std::make_shared(matmul); - return std::make_shared(ngraph::ResultVector{std::make_shared(after)}, - ngraph::ParameterVector{input}); - } - - static std::shared_ptr CreateReferenceFunction( - const ngraph::Shape& input_shape, - const std::vector& reshape_before_shape, - const ngraph::Shape& matmul_constant_shape, - const ngraph::Shape& reshape_after_shape, - const ngraph::Shape& permutation_shape = ngraph::Shape()) { - auto input = std::make_shared(ngraph::element::i64, input_shape); - auto before = std::make_shared(input); - auto reshape_before_constant = ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{reshape_before_shape.size()}, - reshape_before_shape); - auto reshape_before = std::make_shared(before, reshape_before_constant, false); - auto matmul = CreateMatmul(reshape_before, matmul_constant_shape, permutation_shape); - auto reshape_after_constant = ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape{reshape_after_shape.size()}, - reshape_after_shape); - auto reshape_after = std::make_shared(matmul, reshape_after_constant, false); - auto after = std::make_shared(reshape_after); - return std::make_shared(ngraph::ResultVector{std::make_shared(after)}, - ngraph::ParameterVector{input}); - } -}; // struct InsertReshapeAroundMatmulTest - -namespace { - -void RunTest(const std::shared_ptr& func, const std::shared_ptr& reference_func) { - { - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.register_pass(); - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -} // namespace - -TEST(TransformationTests, InsertReshapeAroundMatmul) { - RunTest(InsertReshapeAroundMatmulTest<>::CreateFunction({1, 6, 8}, {8, 10}), - InsertReshapeAroundMatmulTest<>::CreateReferenceFunction({1, 6, 8}, {-1, 8}, {8, 10}, {1, 6, 10})); - RunTest(InsertReshapeAroundMatmulTest<>::CreateReferenceFunction({1, 6, 8}, {-1, 8}, {8, 10}, {1, 6, 10}), - InsertReshapeAroundMatmulTest<>::CreateReferenceFunction({1, 6, 8}, {-1, 8}, {8, 10}, {1, 6, 10})); - RunTest(InsertReshapeAroundMatmulTest<>::CreateFunction({1, 6, 1, 8}, {8, 10}), - InsertReshapeAroundMatmulTest<>::CreateReferenceFunction({1, 6, 1, 8}, {-1, 8}, {8, 10}, {1, 6, 1, 10})); - RunTest(InsertReshapeAroundMatmulTest<>::CreateReferenceFunction({1, 6, 1, 8}, {-1, 8}, {8, 10}, {1, 6, 1, 10}), - InsertReshapeAroundMatmulTest<>::CreateReferenceFunction({1, 6, 1, 8}, {-1, 8}, {8, 10}, {1, 6, 1, 10})); - RunTest(InsertReshapeAroundMatmulTest<>::CreateFunction({1, 1, 8}, {8, 10}), - InsertReshapeAroundMatmulTest<>::CreateReferenceFunction({1, 1, 8}, {-1, 8}, {8, 10}, {1, 1, 10})); - RunTest(InsertReshapeAroundMatmulTest<>::CreateReferenceFunction({1, 1, 8}, {-1, 8}, {8, 10}, {1, 1, 10}), - InsertReshapeAroundMatmulTest<>::CreateReferenceFunction({1, 1, 8}, {-1, 8}, {8, 10}, {1, 1, 10})); -} - -TEST(TransformationTests, InsertReshapeAroundMatmulWithAdd) { - RunTest( - InsertReshapeAroundMatmulTest::CreateFunction({1, 6, 8}, {8, 10}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, {-1, 8}, {8, 10}, {1, 6, 10})); - RunTest( - InsertReshapeAroundMatmulTest::CreateFunction({1, 6, 8}, {8, 10}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, {-1, 8}, {8, 10}, {1, 6, 10})); - RunTest( - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, {-1, 8}, {8, 10}, {1, 6, 10}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, {-1, 8}, {8, 10}, {1, 6, 10})); -} - -TEST(TransformationTests, InsertReshapeAroundMatmulWithAdd_AddFirstInputConstant) { - RunTest(InsertReshapeAroundMatmulTest::CreateFunction({1, 6, 8}, {8, 10}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, {-1, 8}, {8, 10}, {1, 6, 10})); - RunTest(InsertReshapeAroundMatmulTest::CreateFunction({1, 6, 8}, {8, 10}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, {-1, 8}, {8, 10}, {1, 6, 10})); - RunTest(InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, {-1, 8}, {8, 10}, {1, 6, 10}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, {-1, 8}, {8, 10}, {1, 6, 10})); -} - -TEST(TransformationTests, InsertReshapeAroundMatmulWithFq) { - RunTest(InsertReshapeAroundMatmulTest::CreateFunction({1, 6, 8}, {8, 10}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 6, 10})); - RunTest(InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 6, 10}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 6, 10})); -} - -TEST(TransformationTests, InsertReshapeAroundMatmulWithAddAndFq) { - RunTest(InsertReshapeAroundMatmulTest::CreateFunction({1, 6, 8}, {8, 10}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 6, 10})); - RunTest(InsertReshapeAroundMatmulTest::CreateFunction({1, 6, 8}, {8, 10}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 6, 10})); - RunTest(InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 6, 10}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 6, 10})); -} - -TEST(TransformationTests, InsertReshapeAroundMatmulWithTranspose) { - RunTest( - InsertReshapeAroundMatmulTest::CreateFunction({1, 6, 8}, {8, 10}, {0, 2, 1}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 6}, - {1, 0})); - RunTest(InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 6}, - {1, 0}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 6}, - {1, 0})); - RunTest( - InsertReshapeAroundMatmulTest::CreateFunction({1, 1, 8}, {8, 10}, {0, 2, 1}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 1, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 1}, - {1, 0})); - RunTest(InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 1, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 1}, - {1, 0}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 1, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 1}, - {1, 0})); -} - -TEST(TransformationTests, InsertReshapeAroundMatmulWithFqAndTranspose) { - RunTest( - InsertReshapeAroundMatmulTest::CreateFunction({1, 6, 8}, {8, 10}, {0, 2, 1}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 6}, - {1, 0})); - RunTest(InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 6}, - {1, 0}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 6}, - {1, 0})); - RunTest( - InsertReshapeAroundMatmulTest::CreateFunction({1, 1, 8}, {8, 10}, {0, 2, 1}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 1, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 1}, - {1, 0})); - RunTest(InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 1, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 1}, - {1, 0}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 1, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 1}, - {1, 0})); -} - -TEST(TransformationTests, InsertReshapeAroundMatmulWithAddAndFqAndTranspose) { - RunTest(InsertReshapeAroundMatmulTest::CreateFunction({1, 6, 8}, {8, 10}, {0, 2, 1}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 6}, - {1, 0})); - RunTest(InsertReshapeAroundMatmulTest::CreateFunction({1, 6, 8}, {8, 10}, {0, 2, 1}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 6}, - {1, 0})); - RunTest(InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 6}, - {1, 0}), - InsertReshapeAroundMatmulTest::CreateReferenceFunction({1, 6, 8}, - {-1, 8}, - {8, 10}, - {1, 10, 6}, - {1, 0})); -} diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_insert_transpose_after_convolution_or_pooling.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_insert_transpose_after_convolution_or_pooling.cpp deleted file mode 100644 index a1ffcc75fe7..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_insert_transpose_after_convolution_or_pooling.cpp +++ /dev/null @@ -1,299 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset7.hpp" -#include "transformations/insert_transpose_after_convolution_or_pooling.hpp" - -namespace testing { - -TEST(TransformationTests, InsertTransposeAfterConvOrPoolTestStartConvolution) { - std::shared_ptr func(nullptr), reference_func(nullptr); - - { - auto input_params_convolution = - std::make_shared(ngraph::element::i64, ngraph::Shape{1, 3, 1, 64}); - - auto weights = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{3, 3, 1, 2}, {1}); - auto convolution_operation = std::make_shared(input_params_convolution, - weights, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 1}, - ngraph::Strides{1, 1}); - - auto new_shape = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {1, 1, 1, 3 * 64}); - auto reshape_operation = std::make_shared(convolution_operation, new_shape, true); - - auto weights_next_convolution = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1, 1, 1, 3 * 63}, {1}); - auto next_convolution_operation = std::make_shared(reshape_operation, - weights_next_convolution, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 1}, - ngraph::Strides{1, 1}); - - auto result = std::make_shared(next_convolution_operation); - func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input_params_convolution}); - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - { - auto input_params_convolution = - std::make_shared(ngraph::element::i64, ngraph::Shape{1, 3, 1, 64}); - - auto weights = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{3, 3, 1, 2}, {1}); - auto convolution_operation = std::make_shared(input_params_convolution, - weights, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 1}, - ngraph::Strides{1, 1}); - - auto new_shape_out = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {1, 64, 1, 3}); - auto reshape_out_operation = std::make_shared(convolution_operation, new_shape_out, false); - - auto transpose = std::make_shared( - reshape_out_operation, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 3, 1, 2})); - - auto new_shape = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {1, 1, 1, 3 * 64}); - auto reshape_operation = std::make_shared(transpose, new_shape, true); - - auto weights_next_convolution = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1, 1, 1, 3 * 63}, {1}); - auto next_convolution_operation = std::make_shared(reshape_operation, - weights_next_convolution, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 1}, - ngraph::Strides{1, 1}); - - auto result = std::make_shared(next_convolution_operation); - reference_func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input_params_convolution}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -TEST(TransformationTests, InsertTransposeAfterConvOrPoolTestStartMaxPool) { - std::shared_ptr func(nullptr), reference_func(nullptr); - - { - auto input_params = std::make_shared(ngraph::element::i64, ngraph::Shape{1, 3, 1, 64}); - - auto max_pool_operation = std::make_shared(input_params, - ngraph::Strides{1, 1}, - ngraph::Shape{0, 0}, - ngraph::Shape{0, 1}, - ngraph::Shape{1, 2}); - - auto new_shape = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {1, 1, 1, 3 * 64}); - auto reshape_operation = std::make_shared(max_pool_operation, new_shape, true); - - auto weights_next_convolution = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1, 1, 1, 3 * 63}, {1}); - auto next_convolution_operation = std::make_shared(reshape_operation, - weights_next_convolution, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 1}, - ngraph::Strides{1, 1}); - - auto result = std::make_shared(next_convolution_operation); - func = std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - { - auto input_params = std::make_shared(ngraph::element::i64, ngraph::Shape{1, 3, 1, 64}); - - auto max_pool_operation = std::make_shared(input_params, - ngraph::Strides{1, 1}, - ngraph::Shape{0, 0}, - ngraph::Shape{0, 1}, - ngraph::Shape{1, 2}); - - auto new_shape_out = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {1, 64, 1, 3}); - auto reshape_out_operation = std::make_shared(max_pool_operation, new_shape_out, false); - - auto transpose = std::make_shared( - reshape_out_operation, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 3, 1, 2})); - - auto new_shape = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {1, 1, 1, 3 * 64}); - auto reshape_operation = std::make_shared(transpose, new_shape, true); - - auto weights_next_convolution = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1, 1, 1, 3 * 63}, {1}); - auto next_convolution_operation = std::make_shared(reshape_operation, - weights_next_convolution, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 1}, - ngraph::Strides{1, 1}); - - auto result = std::make_shared(next_convolution_operation); - reference_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -TEST(TransformationTests, InsertTransposeAfterConvOrPoolTestInputRank3) { - std::shared_ptr func(nullptr), reference_func(nullptr); - - { - auto input_params_convolution = - std::make_shared(ngraph::element::i64, ngraph::Shape{1, 3, 64}); - - auto weights = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2, 3, 2}, {1}); - auto convolution_operation = std::make_shared(input_params_convolution, - weights, - ngraph::Strides{1}, - ngraph::CoordinateDiff{0}, - ngraph::CoordinateDiff{1}, - ngraph::Strides{1}); - - auto new_shape = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 1, 128}); - auto reshape_operation = std::make_shared(convolution_operation, new_shape, true); - - auto weights_next_convolution = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1, 1, 63}, {1}); - auto next_convolution_operation = std::make_shared(reshape_operation, - weights_next_convolution, - ngraph::Strides{1}, - ngraph::CoordinateDiff{0}, - ngraph::CoordinateDiff{1}, - ngraph::Strides{1}); - - auto result = std::make_shared(next_convolution_operation); - - func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input_params_convolution}); - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - { - auto input_params_convolution = - std::make_shared(ngraph::element::i64, ngraph::Shape{1, 3, 64}); - - auto weights = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2, 3, 2}, {1}); - auto convolution_operation = std::make_shared(input_params_convolution, - weights, - ngraph::Strides{1}, - ngraph::CoordinateDiff{0}, - ngraph::CoordinateDiff{1}, - ngraph::Strides{1}); - - auto new_shape_out = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 64, 2}); - auto reshape_out_operation = std::make_shared(convolution_operation, new_shape_out, false); - - auto transpose = std::make_shared( - reshape_out_operation, - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {0, 2, 1})); - - auto new_shape = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 1, 128}); - auto reshape_operation = std::make_shared(transpose, new_shape, true); - - auto weights_next_convolution = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1, 1, 63}, {1}); - auto next_convolution_operation = std::make_shared(reshape_operation, - weights_next_convolution, - ngraph::Strides{1}, - ngraph::CoordinateDiff{0}, - ngraph::CoordinateDiff{1}, - ngraph::Strides{1}); - - auto result = std::make_shared(next_convolution_operation); - reference_func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input_params_convolution}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -std::shared_ptr CreatePoolConvFunction(const ngraph::Shape& input_shape, - const ngraph::Shape& pool_kernel_shape) { - auto input_params = std::make_shared(ngraph::element::i64, input_shape); - - auto max_pool_operation = std::make_shared(input_params, - pool_kernel_shape, - ngraph::Shape{0, 0}, - ngraph::Shape{0, 1}, - pool_kernel_shape); - - auto pool_out_shape = max_pool_operation->get_output_shape(0); - ngraph::Shape new_shape = { - 1, - 1, - 1, - std::accumulate(std::begin(pool_out_shape), std::end(pool_out_shape), size_t{1}, std::multiplies())}; - auto new_shape_const = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, new_shape); - auto reshape_operation = std::make_shared(max_pool_operation, new_shape_const, true); - - auto weights_next_convolution = ov::op::v0::Constant::create(ngraph::element::i64, new_shape, {1}); - auto next_convolution_operation = std::make_shared(reshape_operation, - weights_next_convolution, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 1}, - ngraph::Strides{1, 1}); - - auto result = std::make_shared(next_convolution_operation); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -TEST(TransformationTests, InsertTransposeAfterConvOrPoolTest1dOutput) { - std::shared_ptr func(nullptr), reference_func(nullptr); - - func = CreatePoolConvFunction(ngraph::Shape{1, 3, 1, 8}, ngraph::Strides{1, 8}); - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - - reference_func = ngraph::clone_function(*func); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_pwl.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_pwl.cpp deleted file mode 100644 index 24b846f2ef6..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_pwl.cpp +++ /dev/null @@ -1,279 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include - -#include "common_test_utils/data_utils.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset9.hpp" -#include "transformations/pwl_approximation.hpp" - -using namespace ov::intel_gna::common; - -namespace { - -template -struct Function {}; - -template <> -struct Function { - static std::function get_function() { - return [](const double x) { - return 0.5 * (1.0 + std::tanh(x / 2.0)); - }; - } -}; - -template <> -struct Function { - static std::function get_function() { - return [](const double x) { - return std::tanh(x); - }; - } -}; - -template <> -struct Function { - static std::function get_function() { - return [](const double x) { - return x / (1.0 + std::abs(x)); - }; - } -}; - -template <> -struct Function { - static std::function get_function() { - return [](const double x) { - return std::log(x); - }; - } -}; - -template <> -struct Function { - static std::function get_function() { - return [](const double x) { - return std::exp(x); - }; - } -}; - -template <> -struct Function { - static std::function get_function(double exp) { - return [exp](const double x) { - return std::pow(x, exp); - }; - } -}; - -template -using Enable = std::enable_if::value || std::is_same::value || - std::is_same::value || - std::is_same::value || std::is_same::value, - int>; -template -using EnableWithExtraArg = std::enable_if::value, int>; - -template -class GnaPWlTestsFixture { -public: - template ::type = 0> - GnaPWlTestsFixture(const ngraph::Shape& input_shape, - double lower_bound, - double upper_bound, - double max_error_percent); - - template ::type = 0> - GnaPWlTestsFixture(const ngraph::Shape& input_shape, - double lower_bound, - double upper_bound, - double exp, - double max_error_percent); - - void run(); - -private: - void validate_results(const std::vector& input_data, - const std::vector& results, - double max_error_percent); - - double count_abs_peak_to_peak(int samples = 1000); - - template - static std::shared_ptr create_activation_function(const ngraph::Shape& input_shape); - - template - static std::shared_ptr create_activation_function(const ngraph::Shape& input_shape, double exp); - - double _lower_bound; - double _upper_bound; - double _max_error_percent; - std::shared_ptr _function_under_test; - std::function _reference_function; -}; - -template -template ::type> -inline GnaPWlTestsFixture::GnaPWlTestsFixture(const ngraph::Shape& input_shape, - double lower_bound, - double upper_bound, - double max_error_percent) - : _lower_bound(lower_bound), - _upper_bound(upper_bound), - _max_error_percent(max_error_percent) { - _function_under_test = create_activation_function(input_shape); - _reference_function = Function::get_function(); -} - -template -template ::type> -inline GnaPWlTestsFixture::GnaPWlTestsFixture(const ngraph::Shape& input_shape, - double lower_bound, - double upper_bound, - double exp, - double max_error_percent) - : _lower_bound(lower_bound), - _upper_bound(upper_bound), - _max_error_percent(max_error_percent) { - _function_under_test = create_activation_function(input_shape, exp); - _reference_function = Function::get_function(exp); -} - -template -template -inline std::shared_ptr GnaPWlTestsFixture::create_activation_function( - const ngraph::Shape& input_shape) { - auto input_params = std::make_shared(ngraph::element::f32, input_shape); - auto f = std::make_shared(input_params); - auto result = std::make_shared(f); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -template -template -inline std::shared_ptr GnaPWlTestsFixture::create_activation_function( - const ngraph::Shape& input_shape, - double exp) { - auto input_params = std::make_shared(ngraph::element::f32, input_shape); - auto exponents = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {exp}); - auto f = std::make_shared(input_params, exponents); - auto result = std::make_shared(f); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -template -inline double GnaPWlTestsFixture::count_abs_peak_to_peak(int samples) { - double delta = (_upper_bound - _lower_bound) / (samples + 1); - - if (delta <= 0) { - std::stringstream str_stream; - str_stream << "Cannot count test parameters for given data!! Lower bound=" << _lower_bound - << ", upper bound=" << _upper_bound << std::endl; - throw std::runtime_error(str_stream.str()); - } - - double min_val = _reference_function(_lower_bound); - double max_val = min_val; - - for (int i = 0; i < samples; i++) { - double arg = _lower_bound + i * delta; - double val = _reference_function(arg); - if (val > max_val) - max_val = val; - if (val < min_val) - min_val = val; - } - - return std::abs(max_val - min_val); -} - -template -inline void GnaPWlTestsFixture::run() { - { - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(_max_error_percent); - m.run_passes(_function_under_test); - ASSERT_NO_THROW(check_rt_info(_function_under_test)); - } - - auto shape = _function_under_test->input().get_node_shared_ptr()->get_output_shape(0); - ov::runtime::TensorVector result(1); - std::vector data = - ov::test::utils::generate_float_numbers(ov::shape_size(shape), _lower_bound, _upper_bound); - ov::runtime::Tensor input{ov::element::f32, shape, data.data()}; - ASSERT_TRUE(_function_under_test->evaluate(result, ov::runtime::TensorVector{input})); - - const float* result_data = result[0].data(); - std::vector results(result_data, result_data + result[0].get_size()); - - validate_results(data, results, _max_error_percent); -} - -template -inline void GnaPWlTestsFixture::validate_results(const std::vector& input_data, - const std::vector& results, - double max_error_percent) { - ASSERT_FALSE(results.empty()); - - std::vector reference_values; - std::for_each(input_data.begin(), input_data.end(), [&reference_values, this](const double& x) { - reference_values.push_back(_reference_function(x)); - }); - - ASSERT_EQ(results.size(), reference_values.size()); - - auto abs_peak_to_peak = count_abs_peak_to_peak(); - - for (int i = 0; i < results.size(); ++i) { - double delta = std::abs(static_cast(results[i]) - static_cast(reference_values[i])); - double error_percentage = delta / abs_peak_to_peak * 100.0; - EXPECT_TRUE(error_percentage < max_error_percent); - } -} - -TEST(GnaPwlTest, Sigmoid) { - GnaPWlTestsFixture test_instance({1, 100}, -10.0, 10.0, 1.0); - test_instance.run(); -} - -TEST(GnaPwlTest, Tanh) { - GnaPWlTestsFixture test_instance({1, 32}, -5.0, 5.0, 1.0); - test_instance.run(); -} - -TEST(GnaPwlTest, Exp) { - GnaPWlTestsFixture test_instance({1, 32}, -std::log2(INT16_MAX), std::log10(INT16_MAX), 1.0); - test_instance.run(); -} - -TEST(GnaPwlTest, SoftSign) { - GnaPWlTestsFixture test_instance({1, 32}, -10, 10, 1.0); - test_instance.run(); -} - -TEST(GnaPwlTest, Log) { - GnaPWlTestsFixture test_instance({1, 32}, 0.001, 2981, 1.0); - test_instance.run(); -} - -TEST(GnaPwlTest, Power) { - for (float exp = 1; exp <= 2.2; exp += 0.1) { - GnaPWlTestsFixture test_instance({1, 32}, - AreFpEq(std::fmod(exp, 1.0), 0.0) ? -16 : 0, - 16, - exp, - 1.0); - test_instance.run(); - } -} -} // namespace diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_remove_convert.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_remove_convert.cpp deleted file mode 100644 index e57bc0349d9..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_remove_convert.cpp +++ /dev/null @@ -1,397 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include - -#include "common_test_utils/node_builders/eltwise.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset8.hpp" -#include "ov_models/builders.hpp" -#include "transformations/remove_converts.hpp" - -namespace testing { - -typedef std::tuple - removeConvertTestParams; - -class RemoveInputConvertTest : public ov::test::TestsCommon, - public ::testing::WithParamInterface { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - ov::element::Type net_precision, target_precision; - std::tie(net_precision, target_precision) = obj.param; - - std::ostringstream result; - result << "netPRC=" << net_precision << "_"; - result << "trgPRC=" << target_precision << "_"; - - return result.str(); - } - void SetUp() override; - virtual void Validate(); - virtual void Run(); - -public: - std::shared_ptr func_, ref_func_no_convert_, ref_func_convert_; - ov::element::Type net_precision_, target_precision_; -}; - -void RemoveInputConvertTest::Run() { - SetUp(); - Validate(); -} - -void RemoveInputConvertTest::SetUp() { - const ngraph::Shape input_shape{10}; - - std::tie(net_precision_, target_precision_) = this->GetParam(); - - // test function - { - auto params = std::make_shared(target_precision_, input_shape); - auto conversion = std::make_shared(params, net_precision_); - auto add_const = ov::op::v0::Constant::create(net_precision_, input_shape, {10}); - auto add = std::make_shared(conversion, add_const); - - auto result = std::make_shared(add); - func_ = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{params}, - "Conversion"); - } - - // ref function convert should be removed - { - auto params = std::make_shared(net_precision_, input_shape); - auto add_const = ov::op::v0::Constant::create(net_precision_, input_shape, {10}); - auto add = std::make_shared(params, add_const); - - auto result = std::make_shared(add); - ref_func_no_convert_ = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{params}, - "Conversion"); - } - - // ref function convert should not be removed - ref_func_convert_ = ngraph::clone_function(*func_); -} - -void RemoveInputConvertTest::Validate() { - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func_); - ASSERT_NO_THROW(check_rt_info(func_)); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - FunctionsComparator::Result result; - if (std::count(ov::intel_gna::pass::kSupportedInputConverts.begin(), - ov::intel_gna::pass::kSupportedInputConverts.end(), - std::make_pair(target_precision_, net_precision_)) == 0) { - result = func_comparator(func_, ref_func_convert_); - } else { - result = func_comparator(func_, ref_func_no_convert_); - } - - ASSERT_TRUE(result.valid); -} - -class RemoveOutputConvertTest : public RemoveInputConvertTest { -public: - void SetUp() override { - const ngraph::Shape input_shape{10}; - - std::tie(net_precision_, target_precision_) = this->GetParam(); - - // test function - { - auto params = std::make_shared(net_precision_, input_shape); - auto add_const = ov::op::v0::Constant::create(net_precision_, input_shape, {10}); - auto add = std::make_shared(params, add_const); - auto conversion = std::make_shared(add, target_precision_); - auto result = std::make_shared(conversion); - func_ = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{params}, - "Conversion"); - } - - // ref function - { - auto params = std::make_shared(net_precision_, input_shape); - auto add_const = ov::op::v0::Constant::create(net_precision_, input_shape, {10}); - auto add = std::make_shared(params, add_const); - - auto result = std::make_shared(add); - ref_func_no_convert_ = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{params}, - "Conversion"); - } - - // ref function convert should not be removed - ref_func_convert_ = ngraph::clone_function(*func_); - } - void Validate() override { - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func_); - ASSERT_NO_THROW(check_rt_info(func_)); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - FunctionsComparator::Result result; - if (std::count(ov::intel_gna::pass::kSupportedOutputConverts.begin(), - ov::intel_gna::pass::kSupportedOutputConverts.end(), - std::make_pair(net_precision_, target_precision_)) == 0) { - result = func_comparator(func_, ref_func_convert_); - } else { - result = func_comparator(func_, ref_func_no_convert_); - } - - ASSERT_TRUE(result.valid); - } -}; - -class LeaveConvertTest : public RemoveInputConvertTest { -public: - void SetUp() override { - const ngraph::Shape input_shape{10}; - - std::tie(net_precision_, target_precision_) = this->GetParam(); - - // test function - { - auto params = std::make_shared(net_precision_, input_shape); - auto add_const = ov::op::v0::Constant::create(net_precision_, input_shape, {10}); - auto add1 = std::make_shared(params, add_const); - auto conversion = std::make_shared(add1, net_precision_); - auto add2 = std::make_shared(conversion, add_const); - auto result = std::make_shared(add2); - func_ = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{params}, - "Conversion"); - } - - // ref function - ref_func_convert_ = ngraph::clone_function(*func_); - } - void Validate() override { - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.register_pass(); - m.run_passes(func_); - ASSERT_NO_THROW(check_rt_info(func_)); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func_, ref_func_convert_); - ASSERT_TRUE(result.valid); - } -}; - -class RemoveMultiInputsConvertTest : public RemoveInputConvertTest { -public: - void SetUp() override { - std::tie(net_precision_, target_precision_) = this->GetParam(); - const ngraph::Shape input_shape{1, 10}; - - // test function - { - ov::ParameterVector input{std::make_shared(target_precision_, input_shape), - std::make_shared(target_precision_, input_shape), - std::make_shared(target_precision_, input_shape)}; - auto convert1 = std::make_shared(input[0], net_precision_); - auto convert2 = std::make_shared(input[1], net_precision_); - auto convert3 = std::make_shared(input[2], net_precision_); - auto mul1 = ov::test::utils::make_eltwise(convert1, convert2, ngraph::helpers::EltwiseTypes::ADD); - auto mul2 = ov::test::utils::make_eltwise(convert3, mul1, ngraph::helpers::EltwiseTypes::ADD); - auto result = std::make_shared(mul2); - func_ = std::make_shared(ngraph::ResultVector{result}, input, "multiple_input"); - } - - // ref function - { - ov::ParameterVector input{std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape)}; - auto mul1 = ov::test::utils::make_eltwise(input[0], input[1], ngraph::helpers::EltwiseTypes::ADD); - auto mul2 = ov::test::utils::make_eltwise(input[2], mul1, ngraph::helpers::EltwiseTypes::ADD); - auto result = std::make_shared(mul2); - ref_func_no_convert_ = - std::make_shared(ngraph::ResultVector{result}, input, "multiple_input"); - } - - // ref function convert should not be removed - ref_func_convert_ = ngraph::clone_function(*func_); - } -}; - -class RemoveMultiOutputsConvertTest : public RemoveOutputConvertTest { -public: - void SetUp() override { - std::tie(net_precision_, target_precision_) = this->GetParam(); - const ngraph::Shape input_shape{1, 10}; - // test function - { - ov::ParameterVector input{std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape)}; - auto mul1 = ov::test::utils::make_eltwise(input[0], input[1], ngraph::helpers::EltwiseTypes::ADD); - auto mul2 = ov::test::utils::make_eltwise(input[2], input[3], ngraph::helpers::EltwiseTypes::ADD); - auto convert1 = std::make_shared(mul1, target_precision_); - auto convert2 = std::make_shared(mul2, target_precision_); - auto result1 = std::make_shared(convert1); - auto result2 = std::make_shared(convert2); - - func_ = - std::make_shared(ngraph::ResultVector{result1, result2}, input, "multiple_output"); - } - - // ref function - { - ov::ParameterVector input{std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape)}; - auto mul1 = ov::test::utils::make_eltwise(input[0], input[1], ngraph::helpers::EltwiseTypes::ADD); - auto mul2 = ov::test::utils::make_eltwise(input[2], input[3], ngraph::helpers::EltwiseTypes::ADD); - auto result1 = std::make_shared(mul1); - auto result2 = std::make_shared(mul2); - - ref_func_no_convert_ = - std::make_shared(ngraph::ResultVector{result1, result2}, input, "multiple_output"); - } - - // ref function convert should not be removed - ref_func_convert_ = ngraph::clone_function(*func_); - } -}; - -class RemoveOutputConvertConnectedToLayerTest : public RemoveOutputConvertTest { -public: - void SetUp() override { - std::tie(net_precision_, target_precision_) = this->GetParam(); - const ngraph::Shape input_shape{1, 10}; - // test function - { - ov::ParameterVector input{std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape)}; - auto mul1 = ov::test::utils::make_eltwise(input[0], input[1], ngraph::helpers::EltwiseTypes::ADD); - auto mul2 = ov::test::utils::make_eltwise(input[2], input[3], ngraph::helpers::EltwiseTypes::ADD); - auto mul3 = ov::test::utils::make_eltwise(mul1, mul2, ngraph::helpers::EltwiseTypes::ADD); - auto convert1 = std::make_shared(mul1, target_precision_); - auto convert2 = std::make_shared(mul2, target_precision_); - auto convert3 = std::make_shared(mul3, target_precision_); - auto result1 = std::make_shared(convert1); - auto result2 = std::make_shared(convert2); - auto result3 = std::make_shared(convert3); - - func_ = std::make_shared(ngraph::ResultVector{result1, result2, result3}, - input, - "multiple_output"); - } - - // ref function - { - ov::ParameterVector input{std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape), - std::make_shared(net_precision_, input_shape)}; - auto mul1 = ov::test::utils::make_eltwise(input[0], input[1], ngraph::helpers::EltwiseTypes::ADD); - auto mul2 = ov::test::utils::make_eltwise(input[2], input[3], ngraph::helpers::EltwiseTypes::ADD); - auto mul3 = ov::test::utils::make_eltwise(mul1, mul2, ngraph::helpers::EltwiseTypes::ADD); - auto result1 = std::make_shared(mul1); - auto result2 = std::make_shared(mul2); - auto result3 = std::make_shared(mul3); - - ref_func_no_convert_ = std::make_shared(ngraph::ResultVector{result1, result2, result3}, - input, - "multiple_output"); - } - - // ref function convert should not be removed - ref_func_convert_ = ngraph::clone_function(*func_); - } -}; - -ov::element::TypeVector netTypes = {ov::element::f16, - ov::element::f32, - ov::element::i8, - ov::element::u8, - ov::element::i16, - ov::element::i32, - ov::element::i64}; - -ov::element::TypeVector targetTypes = {ov::element::f16, - ov::element::f32, - ov::element::i8, - ov::element::u8, - ov::element::i16, - ov::element::i32, - ov::element::i64}; - -TEST_P(RemoveInputConvertTest, CompareWithRefs) { - Run(); -} - -TEST_P(RemoveOutputConvertTest, CompareWithRefs) { - Run(); -} - -TEST_P(LeaveConvertTest, CompareWithRefs) { - Run(); -} - -TEST_P(RemoveMultiInputsConvertTest, CompareWithRefs) { - Run(); -} - -TEST_P(RemoveMultiOutputsConvertTest, CompareWithRefs) { - Run(); -} - -TEST_P(RemoveOutputConvertConnectedToLayerTest, CompareWithRefs) { - Run(); -} - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - RemoveInputConvertTest, - ::testing::Combine(::testing::ValuesIn(netTypes), ::testing::ValuesIn(targetTypes)), - RemoveInputConvertTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - RemoveOutputConvertTest, - ::testing::Combine(::testing::ValuesIn(netTypes), ::testing::ValuesIn(targetTypes)), - RemoveOutputConvertTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - LeaveConvertTest, - ::testing::Combine(::testing::ValuesIn(netTypes), ::testing::ValuesIn(targetTypes)), - LeaveConvertTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - RemoveMultiInputsConvertTest, - ::testing::Combine(::testing::ValuesIn(netTypes), ::testing::ValuesIn(targetTypes)), - RemoveMultiInputsConvertTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - RemoveMultiOutputsConvertTest, - ::testing::Combine(::testing::ValuesIn(netTypes), ::testing::ValuesIn(targetTypes)), - RemoveMultiOutputsConvertTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(TransformationTests, - RemoveOutputConvertConnectedToLayerTest, - ::testing::Combine(::testing::ValuesIn(netTypes), ::testing::ValuesIn(targetTypes)), - RemoveOutputConvertConnectedToLayerTest::getTestCaseName); -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_remove_extra_reshapes.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_remove_extra_reshapes.cpp deleted file mode 100644 index 3ffecba3f60..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_remove_extra_reshapes.cpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset7.hpp" -#include "transformations/remove_extra_reshapes.hpp" - -namespace testing { - -TEST(TransformationTests, RemoveExtraReshapesTestReshapeNotEqualInputOutput) { - std::shared_ptr func(nullptr), reference_func(nullptr); - const ngraph::Shape data_shape{1, 3, 64, 64}; - - { - auto input_params = std::make_shared(ngraph::element::f32, data_shape); - auto new_shape = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 3, 64 * 64}); - auto reshape_operation = std::make_shared(input_params, new_shape, true); - auto max_pool_operation = std::make_shared(reshape_operation, - ngraph::Strides{1}, - ngraph::Shape{0}, - ngraph::Shape{0}, - ngraph::Shape{3}); - auto result = std::make_shared(max_pool_operation); - func = std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - - reference_func = ngraph::clone_function(*func); - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -TEST(TransformationTests, RemoveExtraReshapesTestReshapeEqualInputOutput) { - std::shared_ptr func(nullptr), reference_func(nullptr); - const ngraph::Shape data_shape{1, 3, 64, 64}; - - { - auto input_params = std::make_shared(ngraph::element::f32, data_shape); - auto new_shape = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {1, 3, 64, 64}); - auto reshape_operation = std::make_shared(input_params, new_shape, true); - auto max_pool_operation = std::make_shared(reshape_operation, - ngraph::Strides{1, 1}, - ngraph::Shape{0, 0}, - ngraph::Shape{0, 0}, - ngraph::Shape{3, 3}); - auto result = std::make_shared(max_pool_operation); - func = std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - { - auto input_params = std::make_shared(ngraph::element::f32, data_shape); - auto max_pool_operation = std::make_shared(input_params, - ngraph::Strides{1, 1}, - ngraph::Shape{0, 0}, - ngraph::Shape{1, 1}, - ngraph::Shape{4, 4}); - auto result = std::make_shared(max_pool_operation); - reference_func = - std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); - } - - const FunctionsComparator func_comparator = FunctionsComparator::with_default(); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_remove_single_input_concat.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_remove_single_input_concat.cpp deleted file mode 100644 index 28f97615dbf..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_remove_single_input_concat.cpp +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset8.hpp" -#include "transformations/remove_single_input_concat.hpp" - -namespace testing { -namespace { - -using GraphInputs = std::vector>; -using GraphOutputs = ngraph::OutputVector; - -struct Graph { - std::shared_ptr createFunction(); - - GraphInputs inputs; - GraphOutputs outputs; -}; - -std::shared_ptr Graph::createFunction() { - ngraph::ResultVector results; - std::transform(outputs.begin(), - outputs.end(), - std::back_inserter(results), - [](ngraph::Output output) { - return std::make_shared(output); - }); - - ngraph::ParameterVector params(inputs.begin(), inputs.end()); - - return std::make_shared(results, params); -} - -// ------------------------------------------------------------------------------------------------------- - -using Operations = std::vector>; - -Graph createGraph(int n_inputs, bool has_concat, int n_outputs) { - GraphInputs inputs; - Operations outputs; - - for (int i = 0; i < n_inputs; ++i) { - auto input = std::make_shared(ngraph::element::i64, ngraph::Shape{1, 3, 64}); - inputs.push_back(input); - outputs.push_back(input); - } - - { - Operations new_outputs; - for (auto output : outputs) { - auto add_bias = ov::op::v0::Constant::create(ngraph::element::i64, {1, 1, 1}, {2}); - auto add_operation = std::make_shared(output, add_bias); - new_outputs.push_back(add_operation); - } - outputs.swap(new_outputs); - } - - if (has_concat) { - auto concat_operation = - std::make_shared(ngraph::OutputVector(outputs.begin(), outputs.end()), 0); - outputs = {concat_operation}; - } - - { - Operations new_outputs; - for (auto output : outputs) { - for (int i = 0; i < n_outputs; ++i) { - auto add_bias = ov::op::v0::Constant::create(ngraph::element::i64, {1, 1, 1}, {3}); - auto add_operation = std::make_shared(output, add_bias); - new_outputs.push_back(add_operation); - } - } - outputs.swap(new_outputs); - } - - Graph graph; - graph.inputs.swap(inputs); - graph.outputs.insert(graph.outputs.end(), - std::make_move_iterator(outputs.begin()), - std::make_move_iterator(outputs.end())); - - return graph; -} - -// ------------------------------------------------------------------------------------------------------- - -class RemoveSingleInputConcatFixture - : public ov::test::TestsCommon, - public ::testing::WithParamInterface> { -public: - void SetUp() override; - -public: - std::shared_ptr function, reference_function; -}; - -void RemoveSingleInputConcatFixture::SetUp() { - // TODO: use auto & [transformed_graph, reference_graph] = this->GetParam() when C++17 - Graph transformed_graph; - Graph reference_graph; - std::tie(transformed_graph, reference_graph) = this->GetParam(); - - function = transformed_graph.createFunction(); - reference_function = reference_graph.createFunction(); -} - -ngraph::pass::Manager createPassManager() { - ngraph::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - return manager; -} - -void execute_test(std::shared_ptr function, std::shared_ptr reference_function) { - ngraph::pass::Manager pass_manager = createPassManager(); - pass_manager.run_passes(function); - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -TEST_P(RemoveSingleInputConcatFixture, CompareFunctions) { - execute_test(function, reference_function); -} - -INSTANTIATE_TEST_SUITE_P( - RemoveSingleInputConcatTestSuite, - RemoveSingleInputConcatFixture, - ::testing::Values(std::make_tuple(createGraph(1 /* n_inputs */, true /* has_concat */, 1 /* n_outputs */), - createGraph(1 /* n_inputs */, false /* has_concat */, 1 /* n_outputs */)), - std::make_tuple(createGraph(1 /* n_inputs */, true /* has_concat */, 2 /* n_outputs */), - createGraph(1 /* n_inputs */, false /* has_concat */, 2 /* n_outputs */)), - std::make_tuple(createGraph(2 /* n_inputs */, true /* has_concat */, 1 /* n_outputs */), - createGraph(2 /* n_inputs */, true /* has_concat */, 1 /* n_outputs */)))); - -} // namespace -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_reorder_activation_and_pooling.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_reorder_activation_and_pooling.cpp deleted file mode 100644 index fb989ab2369..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_reorder_activation_and_pooling.cpp +++ /dev/null @@ -1,385 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset7.hpp" -#include "transformations/reorder_activation_and_pooling.hpp" - -namespace testing { - -namespace { - -class IActivationNodeFactory { -public: - virtual ~IActivationNodeFactory() = default; - virtual std::shared_ptr createNode(const ngraph::Output& in) = 0; -}; - -template -class ActivationNodeFactory : public IActivationNodeFactory { -public: - ActivationNodeFactory() = default; - std::shared_ptr createNode(const ngraph::Output& operation_before) override { - return std::make_shared(operation_before); - } - -private: - ActivationNodeFactory(const ActivationNodeFactory&) = delete; - ActivationNodeFactory& operator=(const ActivationNodeFactory&) = delete; -}; - -template <> -class ActivationNodeFactory : public IActivationNodeFactory { -public: - ActivationNodeFactory(const double min, const double max) : min_(min), max_(max) {} - std::shared_ptr createNode(const ngraph::Output& operation_before) override { - return std::make_shared(operation_before, min_, max_); - } - -private: - ActivationNodeFactory(const ActivationNodeFactory&) = delete; - ActivationNodeFactory& operator=(const ActivationNodeFactory&) = delete; - -private: - const double min_; - const double max_; -}; - -using ActivationFactoryPtr = std::shared_ptr; - -template -ActivationFactoryPtr createActivationFactory(Args&&... args) { - return std::make_shared>(std::forward(args)...); -} - -// ---------------------------------------------------------------------------------------------------------------------- - -/* Variants: - Convolution -> Add -> Activation -> MaxPool - Convolution -> Activation -> MaxPool - */ - -typedef std::tuple - ConvolutionActivationPoolTestOptions; - -class ConvolutionActivationPoolTestFixture : public ov::test::TestsCommon, - public testing::WithParamInterface { -public: - void SetUp() override; - std::shared_ptr get_initial_function(ActivationFactoryPtr activation_factory, - bool isAddNodeNeeded); - std::shared_ptr get_reference(ActivationFactoryPtr activation_factory, bool isAddNodeNeeded); - -public: - std::shared_ptr function, reference_function; -}; - -void ConvolutionActivationPoolTestFixture::SetUp() { - ActivationFactoryPtr activation_factory; - bool isAddNodeNeeded = false; - std::tie(activation_factory, isAddNodeNeeded) = GetParam(); - - function = get_initial_function(activation_factory, isAddNodeNeeded); - reference_function = get_reference(activation_factory, isAddNodeNeeded); -} - -std::shared_ptr ConvolutionActivationPoolTestFixture::get_initial_function( - ActivationFactoryPtr activation_factory, - bool isAddNodeNeeded) { - auto input_params_convolution = - std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 64, 64}); - auto input_params_add = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 64, 64}); - - auto weights = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 3, 1, 1}, {1}); - auto bias = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 1, 1}, {1}); - auto convolution_operation = std::make_shared(input_params_convolution, - weights, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}); - - std::shared_ptr last_operation = convolution_operation; - if (isAddNodeNeeded) { - auto add_operation = std::make_shared(convolution_operation, input_params_add); - last_operation = add_operation; - } - auto activation = activation_factory->createNode(last_operation); - - auto max_pool_operation = std::make_shared(activation, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}); - - auto result = std::make_shared(max_pool_operation); - return std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input_params_convolution, input_params_add}); -} - -std::shared_ptr ConvolutionActivationPoolTestFixture::get_reference( - ActivationFactoryPtr activation_factory, - bool isAddNodeNeeded) { - auto input_params_convolution = - std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 64, 64}); - - auto input_params_add = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 64, 64}); - - auto weights = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 3, 1, 1}, {1}); - auto bias = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 1, 1}, {1}); - auto convolution_operation = std::make_shared(input_params_convolution, - weights, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}); - - std::shared_ptr last_operation = convolution_operation; - if (isAddNodeNeeded) { - auto add_operation = std::make_shared(convolution_operation, input_params_convolution); - last_operation = add_operation; - } - - auto max_pool_operation = std::make_shared(last_operation, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}); - - auto activation = activation_factory->createNode(max_pool_operation); - - auto result = std::make_shared(activation); - return std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input_params_convolution, input_params_add}); -} - -void execute_test(std::shared_ptr function, std::shared_ptr reference_function) { - ngraph::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -TEST_P(ConvolutionActivationPoolTestFixture, CompareFunctions) { - execute_test(function, reference_function); -} - -const std::vector activationFactories = {createActivationFactory(), - createActivationFactory(), - createActivationFactory(), - createActivationFactory(), - createActivationFactory(), - createActivationFactory(), - createActivationFactory(), - createActivationFactory(0.1, 0.2)}; - -INSTANTIATE_TEST_SUITE_P(ConvolutionActivationPoolTestSuite, - ConvolutionActivationPoolTestFixture, - ::testing::Combine(::testing::ValuesIn(activationFactories), - ::testing::ValuesIn(std::vector{true, false}))); - -//----------------------------------------------------------------------------------------------------------- - -// Variant Convolution -> FakeQuantize -> MaxPool : ConvFqMp - -TEST(TransformationTests, ReorderActivationAndPoolingTestConvFqMp) { - std::shared_ptr func(nullptr), reference_func(nullptr); - - { - auto input_params_convolution = - std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 64, 64}); - - auto weights = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 3, 1, 1}, {1}); - auto bias = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 1, 1}, {1}); - auto convolution_operation = std::make_shared(input_params_convolution, - weights, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}); - - auto input_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {20}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {10}); - auto fake_quantize_op = std::make_shared(convolution_operation, - input_low, - input_high, - output_low, - output_high, - 11); - - auto max_pool_operation = std::make_shared(fake_quantize_op, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}); - - auto result = std::make_shared(max_pool_operation); - func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input_params_convolution}); - - ngraph::pass::Manager m; - m.register_pass(); - - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - { - auto input_params_convolution = - std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 64, 64}); - - auto weights = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 3, 1, 1}, {1}); - auto bias = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 1, 1}, {1}); - auto convolution_operation = std::make_shared(input_params_convolution, - weights, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}); - - auto max_pool_operation = std::make_shared(convolution_operation, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}); - - auto input_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {20}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {10}); - auto fake_quantize_op = std::make_shared(max_pool_operation, - input_low, - input_high, - output_low, - output_high, - 11); - - auto result = std::make_shared(fake_quantize_op); - reference_func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input_params_convolution}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -// Variant Convolution -> Add -> FakeQuantize -> MaxPool : ConvAddFqMp - -TEST(TransformationTests, ReorderActivationAndPoolingTestConvAddFqMp) { - std::shared_ptr func(nullptr), reference_func(nullptr); - - { - auto input_params_convolution = - std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 64, 64}); - - auto input_params_add = - std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 64, 64}); - - auto weights = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 3, 1, 1}, {1}); - auto bias = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 1, 1}, {1}); - auto convolution_operation = std::make_shared(input_params_convolution, - weights, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}); - - auto add_operation = std::make_shared(convolution_operation, input_params_add); - - auto input_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {20}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {10}); - auto fake_quantize_op = std::make_shared(add_operation, - input_low, - input_high, - output_low, - output_high, - 11); - - auto max_pool_operation = std::make_shared(fake_quantize_op, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}); - - auto result = std::make_shared(max_pool_operation); - func = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input_params_convolution, input_params_add}); - - ngraph::pass::Manager m; - m.register_pass(); - - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - { - auto input_params_convolution = - std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 64, 64}); - - auto input_params_add = - std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 64, 64}); - - auto weights = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 3, 1, 1}, {1}); - auto bias = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{3, 1, 1}, {1}); - auto convolution_operation = std::make_shared(input_params_convolution, - weights, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}); - - auto add_operation = std::make_shared(convolution_operation, input_params_add); - - auto max_pool_operation = std::make_shared(add_operation, - ngraph::Strides{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}, - ngraph::Shape{1, 1}); - - auto input_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {20}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {10}); - auto fake_quantize_op = std::make_shared(max_pool_operation, - input_low, - input_high, - output_low, - output_high, - 11); - - auto result = std::make_shared(fake_quantize_op); - reference_func = - std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{input_params_convolution, input_params_add}); - } - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -} // namespace - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_split_convolution_with_large_buffer_size.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_split_convolution_with_large_buffer_size.cpp deleted file mode 100644 index fe8aeedb43f..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_split_convolution_with_large_buffer_size.cpp +++ /dev/null @@ -1,382 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "common/gna_target.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset7.hpp" -#include "transformations/split_convolution_with_large_buffer_size.hpp" - -using namespace ov::intel_gna::limitations; -using namespace ov::intel_gna::target; - -namespace testing { -namespace { - -struct Graph { - std::shared_ptr createFunction(); - - std::shared_ptr input_params; - ngraph::OutputVector output_nodes; -}; - -std::shared_ptr Graph::createFunction() { - auto result = std::make_shared(output_nodes.front()); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -// TODO: use std::make_unique when C++14 will be available -template -std::unique_ptr createUnique(Args&&... args) { - return std::unique_ptr(new T(std::forward(args)...)); -} - -class CreateGraphDecorator { -public: - CreateGraphDecorator(std::unique_ptr prev = nullptr) : prev_(std::move(prev)) {} - virtual ~CreateGraphDecorator() = default; - virtual Graph build() { - Graph graph; - if (prev_) - graph = prev_->build(); - updateGraph(graph); - return graph; - } - -protected: - virtual void updateGraph(Graph& graph) = 0; - -private: - CreateGraphDecorator(const CreateGraphDecorator&) = delete; - CreateGraphDecorator& operator=(const CreateGraphDecorator&) = delete; - -private: - std::unique_ptr prev_; -}; - -using CreateGraphDecoratorPtr = std::unique_ptr; - -class CreateAppendableGraphDecorator : public CreateGraphDecorator { -public: - CreateAppendableGraphDecorator(std::unique_ptr prev = nullptr) - : CreateGraphDecorator(std::move(prev)) {} - -protected: - void updateGraph(Graph& graph) override { - ngraph::OutputVector new_graph_output; - for (auto&& node : graph.output_nodes) { - new_graph_output.emplace_back(createOutputNode(node)); - } - - if (graph.output_nodes.empty()) - new_graph_output.emplace_back(createOutputNode(graph.input_params)); - - graph.output_nodes.swap(new_graph_output); - } - virtual ngraph::Output createOutputNode(const ngraph::Output& parent_node) = 0; -}; - -class CreateBaseDecorator : public CreateGraphDecorator { -public: - // always the first decorator => no prev_builder - CreateBaseDecorator(const ngraph::Shape& input_data_shape = ngraph::Shape{1, 64, 1, 4096}) - : CreateGraphDecorator(nullptr), - input_data_shape_(input_data_shape) {} - -protected: - Graph build() override; - void updateGraph(Graph& graph) override {} - -private: - const ngraph::Shape input_data_shape_; -}; - -using CreateBaseDecoratorPtr = std::unique_ptr; - -Graph CreateBaseDecorator::build() { - Graph graph; - graph.input_params = std::make_shared(ngraph::element::f32, input_data_shape_); - return graph; -} - -class CreateConvolution : public CreateAppendableGraphDecorator { -public: - CreateConvolution(CreateGraphDecoratorPtr prev, const ngraph::Shape& kernel_shape = ngraph::Shape{1, 64, 1, 1}) - : CreateAppendableGraphDecorator(std::move(prev)), - kernel_shape_(kernel_shape) {} - -protected: - ngraph::Output createOutputNode(const ngraph::Output& parent_node) override; - -private: - const ngraph::Shape kernel_shape_; -}; - -ngraph::Output CreateConvolution::createOutputNode(const ngraph::Output& parent_node) { - auto kernel = ov::op::v0::Constant::create(ngraph::element::f32, kernel_shape_, {1}); - - return std::make_shared(parent_node, - kernel, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}); -} - -// should be used only after CreateBaseDecorator -template -class CreateSplittedConvolution : public CreateGraphDecorator { -public: - CreateSplittedConvolution(CreateGraphDecoratorPtr prev) - : CreateGraphDecorator(std::move(prev)), - kernel_shape_(kernel_shape), - split_shape_(split_shape) {} - -protected: - void updateGraph(Graph& graph) override { - auto split_node_c1 = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape({1}), std::vector{3}); - auto split_node_c2 = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape({split_shape_.size()}), split_shape_); - auto split_node = std::make_shared(graph.input_params, split_node_c1, split_node_c2); - - auto kernel = ov::op::v0::Constant::create(ngraph::element::f32, kernel_shape_, {1}); - - for (int i = 0; i < split_shape_.size(); ++i) { - auto convolution_operation = std::make_shared(split_node->output(i), - kernel, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}); - graph.output_nodes.push_back(convolution_operation); - } - } - -private: - const ngraph::Shape kernel_shape_; - const ngraph::Shape split_shape_; -}; - -class CreateAdd : public CreateAppendableGraphDecorator { -public: - CreateAdd(CreateGraphDecoratorPtr prev) : CreateAppendableGraphDecorator(std::move(prev)) {} - -protected: - ngraph::Output createOutputNode(const ngraph::Output& parent_node) override; -}; - -ngraph::Output CreateAdd::createOutputNode(const ngraph::Output& parent_node) { - auto bias = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {1}); - return std::make_shared(parent_node, bias); -} - -class CreateFakeQuantize : public CreateAppendableGraphDecorator { -public: - CreateFakeQuantize(CreateGraphDecoratorPtr prev) : CreateAppendableGraphDecorator(std::move(prev)) {} - -protected: - ngraph::Output createOutputNode(const ngraph::Output& parent_node) override; -}; - -ngraph::Output CreateFakeQuantize::createOutputNode(const ngraph::Output& parent_node) { - auto input_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {20}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {10}); - return std::make_shared(parent_node, input_low, input_high, output_low, output_high, 11); -} - -class CreateConcat : public CreateGraphDecorator { -public: - CreateConcat(CreateGraphDecoratorPtr prev) : CreateGraphDecorator(std::move(prev)) {} - -protected: - void updateGraph(Graph& graph) override; -}; - -void CreateConcat::updateGraph(Graph& graph) { - ngraph::OutputVector new_graph_output; - new_graph_output.emplace_back(std::make_shared(graph.output_nodes, 3)); - graph.output_nodes.swap(new_graph_output); -} - -// ------------------------------------------------------------------------------------------------------- - -template ::type = true> -CreateGraphDecoratorPtr createBuildDecorator() { - CreateGraphDecoratorPtr build_decorator = createUnique(); - return createUnique(std::move(build_decorator)); -} - -template 0), bool>::type = true> -CreateGraphDecoratorPtr createBuildDecorator() { - CreateGraphDecoratorPtr build_decorator = createBuildDecorator(); - return createUnique(std::move(build_decorator)); -} - -template -Graph createGraph() { - CreateGraphDecoratorPtr build_decorator = createBuildDecorator(); - return build_decorator->build(); -} - -CreateGraphDecoratorPtr createBuildDecorator(const ngraph::Shape& input_shape, const ngraph::Shape& kernel_shape) { - CreateGraphDecoratorPtr base_decorator = createUnique(input_shape); - return createUnique(std::move(base_decorator), kernel_shape); -} - -template ::type = true> -CreateGraphDecoratorPtr createBuildDecorator(const ngraph::Shape& input_shape, const ngraph::Shape& kernel_shape) { - CreateGraphDecoratorPtr build_decorator = createBuildDecorator(input_shape, kernel_shape); - return createUnique(std::move(build_decorator)); -} - -template 0), bool>::type = true> -CreateGraphDecoratorPtr createBuildDecorator(const ngraph::Shape& input_shape, const ngraph::Shape& kernel_shape) { - CreateGraphDecoratorPtr build_decorator = createBuildDecorator(input_shape, kernel_shape); - return createUnique(std::move(build_decorator)); -} - -Graph createSolidGraph(const ngraph::Shape& input_shape, const ngraph::Shape& kernel_shape) { - CreateGraphDecoratorPtr build_decorator = createBuildDecorator(input_shape, kernel_shape); - return build_decorator->build(); -} - -template -Graph createSolidGraph(const ngraph::Shape& input_shape, const ngraph::Shape& kernel_shape) { - CreateGraphDecoratorPtr build_decorator = createBuildDecorator(input_shape, kernel_shape); - return build_decorator->build(); -} - -// ------------------------------------------------------------------------------------------------------- - -using TestParams = std::tuple; - -class SplitConvolutionFixture : public ov::test::TestsCommon, - public ::testing::WithParamInterface> { -public: - void SetUp() override; - void TearDown() override; - -public: - std::shared_ptr function, reference_function; - ngraph::pass::Manager pass_manager; -}; - -void SplitConvolutionFixture::SetUp() { - // TODO: use auto & [transformed_graph, reference_graph] = this->GetParam() when C++17 - DeviceVersion device_version; - TestParams params; - Graph transformed_graph; - Graph reference_graph; - std::tie(device_version, params) = this->GetParam(); - std::tie(transformed_graph, reference_graph, pass_manager) = params; - - Limitations::init(device_version); - function = transformed_graph.createFunction(); - reference_function = reference_graph.createFunction(); -} - -void SplitConvolutionFixture::TearDown() { - Limitations::deinit(); -} - -void execute_test(std::shared_ptr function, - std::shared_ptr reference_function, - ngraph::pass::Manager& pass_manager) { - pass_manager.run_passes(function); - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -template -ngraph::pass::Manager createPassManager() { - ngraph::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - return manager; -} - -TEST_P(SplitConvolutionFixture, CompareFunctions) { - execute_test(function, reference_function, pass_manager); -} - -INSTANTIATE_TEST_SUITE_P( - SplitConvolution_GNA3_0_3_5_3_6_TestSuite, - SplitConvolutionFixture, - ::testing::Combine( - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5, DeviceVersion::GNA3_6), - ::testing::Values( - std::make_tuple(createSolidGraph(ngraph::Shape{1, 1, 1, 1}, ngraph::Shape{1, 1, 1, 1}), - createSolidGraph(ngraph::Shape{1, 1, 1, 1}, ngraph::Shape{1, 1, 1, 1}), - createPassManager()), - std::make_tuple(createSolidGraph(ngraph::Shape{1, 1, 1, 1}, ngraph::Shape{1, 1, 1, 1}), - createSolidGraph(ngraph::Shape{1, 1, 1, 1}, ngraph::Shape{1, 1, 1, 1}), - createPassManager()), - std::make_tuple(createSolidGraph(ngraph::Shape{1, 1, 1, 1}, ngraph::Shape{1, 1, 1, 1}), - createSolidGraph(ngraph::Shape{1, 1, 1, 1}, ngraph::Shape{1, 1, 1, 1}), - createPassManager()), - std::make_tuple( - createSolidGraph(ngraph::Shape{1, 1, 1, 1}, ngraph::Shape{1, 1, 1, 1}), - createSolidGraph(ngraph::Shape{1, 1, 1, 1}, ngraph::Shape{1, 1, 1, 1}), - createPassManager())))); - -ngraph::Shape kernel_shape_3_5 = {1, 64, 1, 1}; -ngraph::Shape split_shape_3_5 = {960, 960, 960, 960, 256}; -using CreateSplitedConvolution3_5 = CreateSplittedConvolution; - -INSTANTIATE_TEST_SUITE_P( - SplitConvolution_GNA3_0_3_5_TestSuite, - SplitConvolutionFixture, - ::testing::Combine( - ::testing::Values(DeviceVersion::GNA3_0, DeviceVersion::GNA3_5), - ::testing::Values( - std::make_tuple(createGraph(), - createGraph(), - createPassManager()), - std::make_tuple(createGraph(), - createGraph(), - createPassManager()), - std::make_tuple(createGraph(), - createGraph(), - createPassManager()), - std::make_tuple(createGraph(), - createGraph(), - createPassManager())))); - -ngraph::Shape kernel_shape_3_6 = {1, 64, 1, 1}; -ngraph::Shape split_shape_3_6 = {1008, 1008, 1008, 1008, 64}; -using CreateSplitedConvolution3_6 = CreateSplittedConvolution; - -INSTANTIATE_TEST_SUITE_P( - SplitConvolution_GNA3_6_TestSuite, - SplitConvolutionFixture, - ::testing::Combine( - ::testing::Values(DeviceVersion::GNA3_6), - ::testing::Values( - std::make_tuple(createGraph(), - createGraph(), - createPassManager()), - std::make_tuple(createGraph(), - createGraph(), - createPassManager()), - std::make_tuple(createGraph(), - createGraph(), - createPassManager()), - std::make_tuple(createGraph(), - createGraph(), - createPassManager())))); - -} // namespace -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_split_eltwise.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_split_eltwise.cpp deleted file mode 100644 index b8415d6fc9f..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_split_eltwise.cpp +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include - -#include "backend/gna_limitations.hpp" -#include "common/gna_target.hpp" -#include "common_test_utils/common_utils.hpp" -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset9.hpp" -#include "transformations/split_eltwise.hpp" - -using namespace ov::intel_gna::limitations; -using namespace ov::intel_gna::target; - -namespace testing { -namespace { - -static std::shared_ptr createFunction(const ngraph::Shape& input_shape, - bool with_const, - bool with_fq, - ELTWISE_TYPE type, - bool split) { - std::shared_ptr last_node, last_node0, last_node1; - - ngraph::ParameterVector parameters; - auto input0 = std::make_shared(ngraph::element::f32, input_shape); - parameters.push_back(input0); - last_node0 = input0; - std::shared_ptr input1; - if (with_const) { - auto const_input = ov::op::v0::Constant::create(ngraph::element::f32, input_shape, {1}); - last_node1 = const_input; - } else { - auto input1 = std::make_shared(ngraph::element::f32, input_shape); - last_node1 = input1; - parameters.push_back(input1); - } - - auto add_fake_quantize = [&](const std::shared_ptr& node) { - auto input_low = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {5}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {10}); - return std::make_shared(node, input_low, input_high, output_low, output_high, 11); - }; - - if (with_fq) { - auto fq_eltwise_input0 = add_fake_quantize(last_node0); - last_node0 = fq_eltwise_input0; - auto fq_eltwise_input1 = add_fake_quantize(last_node1); - last_node1 = fq_eltwise_input1; - } - - if (split) { - auto split_sizes_per_axis = ov::intel_gna::AlignedSplitSizesPerAxis(input_shape); - auto split0 = std::make_shared( - last_node0, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape({1}), - std::vector{split_sizes_per_axis.first}), - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape({split_sizes_per_axis.second.size()}), - split_sizes_per_axis.second)); - auto split1 = std::make_shared( - last_node1, - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape({1}), - std::vector{split_sizes_per_axis.first}), - ov::op::v0::Constant::create(ngraph::element::i64, - ngraph::Shape({split_sizes_per_axis.second.size()}), - split_sizes_per_axis.second)); - ov::NodeVector concat_inputs; - for (size_t i = 0; i < split_sizes_per_axis.second.size(); i++) { - auto eltwise_node_part = std::make_shared(split0->output(i), split1->output(i), type); - concat_inputs.push_back(eltwise_node_part); - } - auto concat = std::make_shared(concat_inputs, split_sizes_per_axis.first); - auto result = std::make_shared(concat); - return std::make_shared(ngraph::ResultVector{result}, parameters); - } else { - auto eltwise = std::make_shared(last_node0, last_node1, type); - auto result = std::make_shared(eltwise); - return std::make_shared(ngraph::ResultVector{result}, parameters); - } -} - -typedef std::tuple - EltwiseSplitParams; - -static std::string getTestCaseName(testing::TestParamInfo obj) { - DeviceVersion device_ver; - ngraph::Shape shape; - bool with_const; - bool with_fq; - ELTWISE_TYPE type; - std::tie(device_ver, shape, with_const, with_fq, type) = obj.param; - - std::ostringstream result; - result << DeviceToString(device_ver) << "_"; - result << "IS=" << ov::test::utils::vec2str(shape) << "_"; - result << "wConst=" << with_const << "_"; - result << "wFQ=" << with_fq << "_"; - result << "type="; - switch (type) { - case ELTWISE_TYPE::Sum: - result << "sum"; - break; - case ELTWISE_TYPE::Sub: - result << "sub"; - break; - case ELTWISE_TYPE::Prod: - result << "prod"; - break; - default: - break; - } - return result.str(); -} - -class SplitEltwiseTestSuiteFixture : public ov::test::TestsCommon, - public ::testing::WithParamInterface { -public: - void SetUp() override; - void TearDown() override; - -public: - std::shared_ptr function, reference_function; -}; - -void SplitEltwiseTestSuiteFixture::SetUp() { - DeviceVersion device_ver; - ngraph::Shape shape; - bool with_const; - bool with_fq; - ELTWISE_TYPE type; - std::tie(device_ver, shape, with_const, with_fq, type) = this->GetParam(); - Limitations::init(device_ver); - function = createFunction(shape, with_const, with_fq, type, false); - reference_function = createFunction(shape, with_const, with_fq, type, true); -} - -void SplitEltwiseTestSuiteFixture::TearDown() { - Limitations::deinit(); -} - -void execute_test(std::shared_ptr function, std::shared_ptr reference_function) { - ngraph::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} - -TEST_P(SplitEltwiseTestSuiteFixture, CompareFunctions) { - execute_test(function, reference_function); -} - -const std::vector inputShape = {{1, 67000}, {1, 500000}, {1, 936, 513}, {1, 64, 64, 64}, {1, 256, 64, 64}}; - -INSTANTIATE_TEST_SUITE_P( - SplitEltwiseTestSuite, - SplitEltwiseTestSuiteFixture, - ::testing::Combine(::testing::ValuesIn(std::vector{DeviceVersion::GNA3_0, // device version - DeviceVersion::GNA3_5, - DeviceVersion::GNA3_6}), - ::testing::ValuesIn(inputShape), - ::testing::ValuesIn(std::vector{true, false}), // with const - ::testing::ValuesIn(std::vector{true, false}), // with fq - ::testing::ValuesIn(std::vector{ELTWISE_TYPE::Sum, - ELTWISE_TYPE::Sub, - ELTWISE_TYPE::Prod})), // eltwise type - getTestCaseName); - -} // namespace -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_substitute_softsign.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_substitute_softsign.cpp deleted file mode 100644 index 91c610d1478..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_substitute_softsign.cpp +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "transformations/substitute_softsign.hpp" -namespace testing { - -namespace { - -std::shared_ptr createSoftSignFunction() { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1, 64}); - - auto softsign = std::make_shared(input_params); - - ngraph::ResultVector results{std::make_shared(softsign)}; - - return std::make_shared(ngraph::ResultVector{results}, ngraph::ParameterVector{input_params}); -} - -} // namespace - -TEST(TransformationTests, SubstituteSoftSignMulPower) { - std::shared_ptr func(nullptr), reference_func(nullptr); - - { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1, 64}); - - auto abs = std::make_shared(input_params); - - auto const_1 = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {1}); - auto const_neg_1 = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {-1}); - - auto add = std::make_shared(abs, const_1); - auto power = std::make_shared(add, const_neg_1); - - auto mul = std::make_shared(power, input_params); - ngraph::ResultVector results{std::make_shared(mul)}; - - func = std::make_shared(ngraph::ResultVector{results}, ngraph::ParameterVector{input_params}); - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - reference_func = createSoftSignFunction(); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -TEST(TransformationTests, SubstituteSoftSignDivide) { - std::shared_ptr func(nullptr), reference_func(nullptr); - - { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1, 64}); - - auto abs = std::make_shared(input_params); - - auto const_1 = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {1}); - auto add = std::make_shared(abs, const_1); - - auto divide = std::make_shared(input_params, add); - ngraph::ResultVector results{std::make_shared(divide)}; - - func = std::make_shared(ngraph::ResultVector{results}, ngraph::ParameterVector{input_params}); - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - reference_func = createSoftSignFunction(); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -TEST(TransformationTests, SubstituteSoftSignMulPowerInvalidAddConst) { - std::shared_ptr func(nullptr), reference_func(nullptr); - - { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1, 64}); - - auto abs = std::make_shared(input_params); - - auto const_1 = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {1.1}); - auto const_neg_1 = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {-1}); - - auto add = std::make_shared(abs, const_1); - auto power = std::make_shared(add, const_neg_1); - - auto mul = std::make_shared(power, input_params); - ngraph::ResultVector results{std::make_shared(mul)}; - - func = std::make_shared(ngraph::ResultVector{results}, ngraph::ParameterVector{input_params}); - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - reference_func = ngraph::clone_function(*func); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -TEST(TransformationTests, SubstituteSoftSignMulPowerInvalidPowerConst) { - std::shared_ptr func(nullptr), reference_func(nullptr); - - { - auto input_params = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1, 64}); - - auto abs = std::make_shared(input_params); - - auto const_1 = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {1}); - auto const_neg_1 = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{}, {-1.1}); - - auto add = std::make_shared(abs, const_1); - auto power = std::make_shared(add, const_neg_1); - - auto mul = std::make_shared(power, input_params); - ngraph::ResultVector results{std::make_shared(mul)}; - - func = std::make_shared(ngraph::ResultVector{results}, ngraph::ParameterVector{input_params}); - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(func); - ASSERT_NO_THROW(check_rt_info(func)); - } - - reference_func = ngraph::clone_function(*func); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(func, reference_func); - ASSERT_TRUE(result.valid); -} - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_swap_input_matmul.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_swap_input_matmul.cpp deleted file mode 100644 index 6f361e5f4c7..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_swap_input_matmul.cpp +++ /dev/null @@ -1,311 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset8.hpp" -#include "transformations/swap_input_matmul_gna.hpp" - -namespace testing { - -static std::shared_ptr CreateMatMulFunction(const ngraph::Shape& input1_shape, - const ngraph::Shape& input2_shape, - const ngraph::Shape& bias_shape, - bool withBias, - bool withWeightsFq, - bool withOutFq, - bool withAct, - bool swappedInputs, - bool needTranspose, - bool expected = false) { - auto input_params = std::make_shared(ngraph::element::i64, input2_shape); - std::shared_ptr input = input_params; - if (input->get_output_shape(0).size() == 2 && needTranspose) { - auto transpose_order = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, std::vector{1, 0}); - input = std::make_shared(input, transpose_order); - } - - auto constant = ov::op::v0::Constant::create(ngraph::element::i64, input1_shape, {1}); - std::shared_ptr const_input = constant; - if (withWeightsFq) { - auto input_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {20}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {10}); - const_input = - std::make_shared(const_input, input_low, input_high, output_low, output_high, 11); - } - auto matmul = swappedInputs ? std::make_shared(input, const_input, false, needTranspose) - : std::make_shared(const_input, input, needTranspose, false); - - std::shared_ptr final_node = matmul; - if (withBias) { - auto shape = bias_shape; - if ((needTranspose && !expected || !needTranspose && expected) && bias_shape.size() > 1) { - std::swap(shape[0], shape[1]); - } - auto bias = ov::op::v0::Constant::create(ngraph::element::i64, shape, {1}); - std::shared_ptr bias_node = bias; - if (expected && bias_shape.size() > 1) { - auto transpose_order = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, std::vector{1, 0}); - bias_node = std::make_shared(bias_node, transpose_order); - } - final_node = std::make_shared(matmul, bias_node); - } - - if (withOutFq) { - auto input_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {20}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1}, {10}); - final_node = - std::make_shared(final_node, input_low, input_high, output_low, output_high, 11); - } - - if (withAct) { - final_node = std::make_shared(final_node); - } - - if (final_node->get_output_shape(0).size() == 2 && needTranspose) { - auto transpose_order = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, std::vector{1, 0}); - final_node = std::make_shared(final_node, transpose_order); - } - - auto result = std::make_shared(final_node); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); -} - -static void Execute(std::shared_ptr function, std::shared_ptr reference_function) { - ngraph::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.register_pass(); - m.register_pass(); - m.register_pass(); - m.register_pass(); - m.run_passes(function); - ASSERT_NO_THROW(check_rt_info(function)); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid); -} - -typedef std::tuple, // constant input shape, non-const input shape, bias shape - bool, // with bias - bool, // with weights FakeQuantize - bool, // with output FakeQuantize - bool, // with activation after MatMul - bool // with transposes - > - SwapInputMatmulParams; - -static std::string getTestCaseName(testing::TestParamInfo obj) { - std::vector shapes; - bool withBias, withWeightsFq, withOutFq, withAct, withTransposes; - std::tie(shapes, withBias, withWeightsFq, withOutFq, withAct, withTransposes) = obj.param; - - std::ostringstream result; - result << "IS1=" << shapes[0] << "_"; - result << "IS2=" << shapes[1] << "_"; - result << "BS=" << shapes[2] << "_"; - result << "bias=" << withBias << "_"; - result << "wFQ=" << withWeightsFq << "_"; - result << "oFQ=" << withOutFq << "_"; - result << "act=" << withAct << "_"; - result << "transposes=" << withTransposes; - return result.str(); -} - -enum class MatmulInputType { FirstInputConstant, SecondInputConstant }; // enum class MatmulInputType - -static void transposeInputShapes(std::vector& shapes) { - if (shapes[0].size() > 1) { - std::swap(shapes[0][0], shapes[0][1]); - } - if (shapes[1].size() > 1) { - std::swap(shapes[1][0], shapes[1][1]); - } - if (shapes[2].size() > 1) { - std::swap(shapes[2][0], shapes[2][1]); - } -} - -template -class SwapInputMatmul : public ov::test::TestsCommon, public ::testing::WithParamInterface { -public: - void SetUp() override { - std::vector shapes; - bool withBias, withWeightsFq, withOutFq, withAct, withTransposes; - std::tie(shapes, withBias, withWeightsFq, withOutFq, withAct, withTransposes) = this->GetParam(); - - bool swap_inputs = false; - switch (E) { - case MatmulInputType::FirstInputConstant: - break; - case MatmulInputType::SecondInputConstant: - swap_inputs = true; - break; - } - - if (withTransposes) { - transposeInputShapes(shapes); - } - function = CreateMatMulFunction(shapes[0], - shapes[1], - shapes[2], - withBias, - withWeightsFq, - withOutFq, - withAct, - swap_inputs, - withTransposes); - reference_function = CreateMatMulFunction(shapes[0], - shapes[1], - shapes[2], - withBias, - withWeightsFq, - withOutFq, - withAct, - !swap_inputs, - !withTransposes, - true); - } - -public: - std::shared_ptr function, reference_function; -}; - -template -class SwapInputMatmulNotApplied : public ov::test::TestsCommon, - public ::testing::WithParamInterface { -public: - void SetUp() override { - std::vector shapes; - bool withBias, withWeightsFq, withOutFq, withAct, withTransposes; - std::tie(shapes, withBias, withWeightsFq, withOutFq, withAct, withTransposes) = this->GetParam(); - - bool swap_inputs = false; - switch (E) { - case MatmulInputType::FirstInputConstant: - break; - case MatmulInputType::SecondInputConstant: - swap_inputs = true; - break; - } - - if (withTransposes) { - transposeInputShapes(shapes); - } - function = CreateMatMulFunction(shapes[0], - shapes[1], - shapes[2], - withBias, - withWeightsFq, - withOutFq, - withAct, - swap_inputs, - withTransposes); - reference_function = ngraph::clone_function(*function); - } - -public: - std::shared_ptr function, reference_function; -}; - -using SwapInputMatmulWithFirstInputConstant = SwapInputMatmul; -using SwapInputMatmulWithSecondInputConstant = SwapInputMatmul; -using SwapInputMatmulWithFirstInputConstantNotApplied = SwapInputMatmulNotApplied; -using SwapInputMatmulWithSecondInputConstantNotApplied = - SwapInputMatmulNotApplied; - -TEST_P(SwapInputMatmulWithFirstInputConstant, CompareFunctions) { - Execute(function, reference_function); -} - -TEST_P(SwapInputMatmulWithFirstInputConstantNotApplied, CompareFunctions) { - Execute(function, reference_function); -} - -TEST_P(SwapInputMatmulWithSecondInputConstant, CompareFunctions) { - Execute(function, reference_function); -} - -TEST_P(SwapInputMatmulWithSecondInputConstantNotApplied, CompareFunctions) { - Execute(function, reference_function); -} - -const std::vector> input_shapes_for_matmul_with_first_constant_applied = { - {{16, 8}, {8, 8}, {16, 8}}, - {{16, 8}, {8, 8}, {1}}, -}; - -const std::vector> input_shapes_for_matmul_with_first_constant_not_applied = { - {{1, 8}, {8, 8}, {1, 8}}, - {{8}, {8, 8}, {8}}}; - -const std::vector> input_shapes_for_matmul_with_second_constant_applied = { - {{64, 6}, {100, 64}, {100, 6}}, - {{64, 6}, {100, 64}, {1}}, -}; - -const std::vector> input_shapes_for_matmul_with_second_constant_not_applied = { - {{64, 16}, {100, 64}, {100, 16}}, - {{64, 6}, {8, 64}, {8, 6}}, - {{8, 1}, {8, 8}, {8, 1}}, - {{8}, {8, 8}, {8}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_swap_input_matmul, - SwapInputMatmulWithFirstInputConstant, - ::testing::Combine(::testing::ValuesIn(input_shapes_for_matmul_with_first_constant_applied), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true})), - getTestCaseName); - -INSTANTIATE_TEST_SUITE_P( - smoke_swap_input_matmul, - SwapInputMatmulWithFirstInputConstantNotApplied, - ::testing::Combine(::testing::ValuesIn(input_shapes_for_matmul_with_first_constant_not_applied), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true})), - getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_swap_input_matmul, - SwapInputMatmulWithSecondInputConstant, - ::testing::Combine(::testing::ValuesIn(input_shapes_for_matmul_with_second_constant_applied), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true})), - getTestCaseName); - -INSTANTIATE_TEST_SUITE_P( - smoke_swap_input_matmul, - SwapInputMatmulWithSecondInputConstantNotApplied, - ::testing::Combine(::testing::ValuesIn(input_shapes_for_matmul_with_second_constant_not_applied), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true}), - ::testing::ValuesIn(std::vector{false, true})), - getTestCaseName); - -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/gna_unfuse_reshape_and_transpose.cpp b/src/plugins/intel_gna/tests/unit/transformations/gna_unfuse_reshape_and_transpose.cpp deleted file mode 100644 index 8be223526e3..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/gna_unfuse_reshape_and_transpose.cpp +++ /dev/null @@ -1,260 +0,0 @@ -// Copyright (C) 2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include -#include -#include -#include -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/opsets/opset8.hpp" -#include "transformations/unfuse_reshape_and_transpose.hpp" - -namespace testing { -namespace { - -class IActivationFactory { -public: - virtual ~IActivationFactory() = default; - virtual std::shared_ptr createNode(const ngraph::Output& in) = 0; -}; - -template -class ActivationFactory : public IActivationFactory { -public: - ActivationFactory() = default; - std::shared_ptr createNode(const ngraph::Output& operation_before) override { - return std::make_shared(operation_before); - } - -private: - ActivationFactory(const ActivationFactory&) = delete; - ActivationFactory& operator=(const ActivationFactory&) = delete; -}; - -template <> -class ActivationFactory : public IActivationFactory { -public: - ActivationFactory(const double min, const double max) : min_(min), max_(max) {} - std::shared_ptr createNode(const ngraph::Output& operation_before) override { - return std::make_shared(operation_before, min_, max_); - } - -private: - ActivationFactory(const ActivationFactory&) = delete; - ActivationFactory& operator=(const ActivationFactory&) = delete; - -private: - const double min_; - const double max_; -}; - -using ActivationFactoryPtr = std::shared_ptr; - -template -ActivationFactoryPtr createActivationFactory(Args&&... args) { - return std::make_shared>(std::forward(args)...); -} - -static std::shared_ptr createFunction(const ngraph::Shape& conv_input_shape, - const ngraph::Shape& conv_filter_shape, - bool with_bias, - bool with_pool, - ActivationFactoryPtr activation_factory, - bool with_fq, - bool single_reshape_before, - bool single_reshape_after, - bool single_batch) { - size_t total_in = - std::accumulate(std::begin(conv_input_shape), std::end(conv_input_shape), 1, std::multiplies()); - auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{1, total_in}); - std::shared_ptr last_node, last_const; - auto add_fake_quantize = [&](const std::shared_ptr& node) { - auto input_low = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto input_high = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {5}); - auto output_low = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto output_high = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {10}); - return std::make_shared(node, input_low, input_high, output_low, output_high, 11); - }; - if (single_reshape_before) { - auto reshape_in_const = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, conv_input_shape); - auto reshape_in = std::make_shared(input, reshape_in_const, false); - last_node = reshape_in; - } else { - auto reshape_in_const = ov::op::v0::Constant::create( - ngraph::element::i64, - ngraph::Shape{4}, - ngraph::Shape{conv_input_shape[0], conv_input_shape[2], conv_input_shape[3], conv_input_shape[1]}); - auto reshape_in = std::make_shared(input, reshape_in_const, false); - auto transpose_in_const = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, ngraph::Shape{0, 3, 1, 2}); - auto transpose_in = std::make_shared(reshape_in, transpose_in_const); - last_node = transpose_in; - } - auto conv_weights = ov::op::v0::Constant::create(ngraph::element::f32, conv_filter_shape, {1}); - last_const = conv_weights; - if (with_fq) { - auto conv_input_fq = add_fake_quantize(last_node); - last_node = conv_input_fq; - auto conv_weights_fq = add_fake_quantize(conv_weights); - last_const = conv_weights_fq; - } - auto conv = std::make_shared(last_node, - last_const, - ngraph::Strides{1, 1}, - ngraph::CoordinateDiff{0, 0}, - ngraph::CoordinateDiff{0, 0}, - ngraph::Strides{1, 1}); - last_node = conv; - auto conv_output_shape = conv->get_output_shape(0); - size_t total_out = - std::accumulate(std::begin(conv_output_shape), std::end(conv_output_shape), 1, std::multiplies()); - if (with_bias) { - auto add_const = - ov::op::v0::Constant::create(ngraph::element::f32, ngraph::Shape{1, conv_output_shape.at(1), 1, 1}, {1}); - auto add = std::make_shared(conv, add_const); - last_node = add; - } - if (with_fq) { - auto conv_bias_fq = add_fake_quantize(last_node); - last_node = conv_bias_fq; - } - if (with_pool) { - auto pool = std::make_shared(last_node, - ngraph::Strides{1, 1}, - ngraph::Shape{0, 0}, - ngraph::Shape{0, 0}, - ngraph::Shape{1, 1}); - last_node = pool; - } - if (activation_factory) { - if (with_fq) { - auto act_fq_in = add_fake_quantize(last_node); - last_node = act_fq_in; - } - auto act = activation_factory->createNode(last_node); - last_node = act; - if (with_fq) { - auto act_fq_out = add_fake_quantize(last_node); - last_node = act_fq_out; - } - } - auto out_shape = single_batch ? ngraph::Shape{1, total_out} : ngraph::Shape{total_out, 1}; - auto reshape_out_const = ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{2}, out_shape); - if (!single_reshape_after) { - auto transpose_out_const = - ov::op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{4}, ngraph::Shape{0, 2, 3, 1}); - auto transpose_out = std::make_shared(last_node, transpose_out_const); - last_node = transpose_out; - } - auto reshape_out = std::make_shared(last_node, reshape_out_const, false); - - auto result = std::make_shared(reshape_out); - auto func = std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input}); - - return func; -} - -typedef std::tuple, - bool, // with bias - bool, // with pooling - ActivationFactoryPtr, // with activation - bool, // with fq - bool // out batch is 1 or not - > - UnfuseReshapeAndTransposeParams; - -class UnfuseReshapeAndTransposeTestSuiteFixture - : public ov::test::TestsCommon, - public ::testing::WithParamInterface { -public: - void SetUp() override; - -public: - std::shared_ptr function, reference_function; -}; - -void UnfuseReshapeAndTransposeTestSuiteFixture::SetUp() { - std::tuple conv_data; - bool with_bias; - bool with_pool; - bool with_fq; - bool single_batch; - ActivationFactoryPtr af; - std::tie(conv_data, with_bias, with_pool, af, with_fq, single_batch) = this->GetParam(); - ngraph::Shape conv_input_shape; - ngraph::Shape conv_filter_shape; - bool replace_before; - bool replace_after; - std::tie(conv_input_shape, conv_filter_shape, replace_before, replace_after) = conv_data; - function = createFunction(conv_input_shape, - conv_filter_shape, - with_bias, - with_pool, - af, - with_fq, - true, - true, - single_batch); - reference_function = createFunction(conv_input_shape, - conv_filter_shape, - with_bias, - with_pool, - af, - with_fq, - !replace_before, - !replace_after, - single_batch); -} - -void execute_test(std::shared_ptr function, std::shared_ptr reference_function) { - ngraph::pass::Manager manager; - manager.register_pass(); - manager.register_pass(); - manager.register_pass(); - manager.run_passes(function); - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(function, reference_function); - ASSERT_TRUE(result.valid) << result.message; -} - -TEST_P(UnfuseReshapeAndTransposeTestSuiteFixture, CompareFunctions) { - execute_test(function, reference_function); -} - -const std::vector activationFactories = {nullptr, - createActivationFactory(), - createActivationFactory(), - createActivationFactory(), - createActivationFactory(), - createActivationFactory(), - createActivationFactory(), - createActivationFactory(), - createActivationFactory(0.1, 0.2)}; - -INSTANTIATE_TEST_SUITE_P( - UnfuseReshapeAndTransposeTestSuite, - UnfuseReshapeAndTransposeTestSuiteFixture, - ::testing::Combine(::testing::ValuesIn(std::vector>{ - {ngraph::Shape{1, 1, 1, 168}, ngraph::Shape{12, 1, 1, 8}, true, false}, - {ngraph::Shape{1, 1, 1, 640}, ngraph::Shape{256, 1, 1, 512}, true, false}, - {ngraph::Shape{1, 1, 1, 1024}, ngraph::Shape{256, 1, 1, 512}, true, false}, - {ngraph::Shape{1, 1, 33, 32}, ngraph::Shape{128, 1, 33, 9}, true, false}, - {ngraph::Shape{1, 1, 11, 13}, ngraph::Shape{128, 1, 11, 9}, true, false}, - {ngraph::Shape{1, 1, 33, 23}, ngraph::Shape{128, 1, 11, 5}, true, false}, - {ngraph::Shape{1, 1, 33, 32}, ngraph::Shape{1, 1, 33, 9}, true, true}, - {ngraph::Shape{1, 1, 1, 1024}, ngraph::Shape{256, 1, 1, 1024}, true, true}, - {ngraph::Shape{1, 1, 33, 32}, ngraph::Shape{1, 1, 33, 9}, true, true}}), - ::testing::ValuesIn(std::vector{true, false}), // with bias - ::testing::ValuesIn(std::vector{true, false}), // with max pool - ::testing::ValuesIn(activationFactories), // with activation - ::testing::ValuesIn(std::vector{true, false}), // with fq - ::testing::ValuesIn(std::vector{true, false}))); // out batch is 1 - -} // namespace -} // namespace testing diff --git a/src/plugins/intel_gna/tests/unit/transformations/transpose_compress.cpp b/src/plugins/intel_gna/tests/unit/transformations/transpose_compress.cpp deleted file mode 100644 index 86577b16693..00000000000 --- a/src/plugins/intel_gna/tests/unit/transformations/transpose_compress.cpp +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "transformations/transpose_compress.hpp" - -#include - -#include "common_test_utils/ov_test_utils.hpp" -#include "openvino/core/model.hpp" -#include "openvino/opsets/opset12.hpp" - -using namespace ov::opset12; - -namespace transpose_compress_test { - -struct TestData { - ov::Shape shape_src; - ov::AxisVector tr_order_src; - ov::Shape shape_ref; - ov::AxisVector tr_order_ref; -}; - -typedef std::tuple // Transpose order - test_params; - -class TransposeCompressTest : public ov::test::TestsCommon, public ::testing::WithParamInterface { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj) { - TestData test_shapes; - std::tie(test_shapes) = obj.param; - - std::ostringstream result; - result << "InputShape=" << test_shapes.shape_src << "_"; - result << "TransposeOrder=" << test_shapes.tr_order_src << "_"; - - return result.str(); - } - - virtual void set_test_model() { - auto param = std::make_shared(m_type, m_test_shapes.shape_src); - - auto transpose_const = std::make_shared(ov::element::i32, - ov::Shape{m_test_shapes.tr_order_src.size()}, - m_test_shapes.tr_order_src); - auto transpose = std::make_shared(param, transpose_const); - - m_shape_out = transpose->get_output_shape(0); - - auto result = std::make_shared(transpose); - m_model_test = - std::make_shared(ov::ResultVector{result}, ov::ParameterVector{param}, "transpose_compress"); - } - - virtual void set_ref_model() { - auto param = std::make_shared(m_type, m_test_shapes.shape_src); - - auto shape_in_const = std::make_shared(ov::element::i32, - ov::Shape{m_test_shapes.shape_ref.size()}, - m_test_shapes.shape_ref); - auto shape_in = std::make_shared(param, shape_in_const, false); - - auto transpose_const = std::make_shared(ov::element::i8, - ov::Shape{m_test_shapes.tr_order_ref.size()}, - m_test_shapes.tr_order_ref); - auto transpose = std::make_shared(shape_in, transpose_const); - - auto shape_out_const = std::make_shared(ov::element::i32, ov::Shape{m_shape_out.size()}, m_shape_out); - auto shape_out = std::make_shared(transpose, shape_out_const, false); - - auto result = std::make_shared(shape_out); - m_model_ref = - std::make_shared(ov::ResultVector{result}, ov::ParameterVector{param}, "transpose_compress"); - } - - void SetUp() override { - std::tie(m_test_shapes) = this->GetParam(); - set_test_model(); - set_ref_model(); - }; - - void Validate() { - ov::pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(m_model_test); - - check_rt_info(m_model_test); - - const FunctionsComparator func_comparator = - FunctionsComparator::with_default().enable(FunctionsComparator::ATTRIBUTES); - const FunctionsComparator::Result result = func_comparator(m_model_test, m_model_ref); - - ASSERT_TRUE(result.valid) << result.message; - } - - void Run() { - SetUp(); - Validate(); - } - -public: - TestData m_test_shapes; - ov::Shape m_shape_out; - ov::element::Type m_type = ov::element::f32; - std::shared_ptr m_model_test; - std::shared_ptr m_model_ref; -}; - -class TransposeCompressNegTest : public TransposeCompressTest { - void set_ref_model() override { - m_model_ref = m_model_test->clone(); - } -}; - -TEST_P(TransposeCompressTest, CompareWithRefs) { - Run(); -} - -TEST_P(TransposeCompressNegTest, CompareWithRefs) { - Run(); -} - -const std::vector test_shapes = {{{1, 2, 3}, {1, 2, 0}, {1, 6}, {1, 0}}, - {{1, 2, 4}, {1, 2, 0}, {1, 8}, {1, 0}}, - {{2, 2, 4}, {1, 2, 0}, {2, 8}, {1, 0}}, - {{2, 2, 4, 4}, {2, 3, 0, 1}, {4, 16}, {1, 0}}}; - -const std::vector test_neg_shapes = {{{1, 2, 3, 4}, {1, 0, 2, 3}, {}, {}}, - {{1, 2, 3, 4}, {0, 2, 1, 3}, {}, {}}, - {{1, 2, 3, 4}, {2, 3, 0, 1}, {}, {}}, - {{10, 20}, {1, 0}, {}, {}}}; - -INSTANTIATE_TEST_SUITE_P(smoke_transpose_compress_test, - TransposeCompressTest, - ::testing::Combine(::testing::ValuesIn(test_shapes)), - TransposeCompressTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_transpose_compress_test, - TransposeCompressNegTest, - ::testing::Combine(::testing::ValuesIn(test_neg_shapes)), - TransposeCompressNegTest::getTestCaseName); - -} // namespace transpose_compress_test diff --git a/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/include/ov_api_conformance_helpers.hpp b/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/include/ov_api_conformance_helpers.hpp index 6dd7a82928c..1c6f8fd0e17 100644 --- a/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/include/ov_api_conformance_helpers.hpp +++ b/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/include/ov_api_conformance_helpers.hpp @@ -28,7 +28,6 @@ inline const std::string get_plugin_lib_name_by_device(const std::string& device { "MULTI", "openvino_auto_plugin" }, { "NPU", "openvino_intel_npu_plugin" }, { "CPU", "openvino_intel_cpu_plugin" }, - { "GNA", "openvino_intel_gna_plugin" }, { "GPU", "openvino_intel_gpu_plugin" }, { "TEMPLATE", "openvino_template_plugin" }, { "NVIDIA", "openvino_nvidia_gpu_plugin" }, diff --git a/src/tests/ie_tsan.supp b/src/tests/ie_tsan.supp index d99d602cbec..3d73d1223dc 100644 --- a/src/tests/ie_tsan.supp +++ b/src/tests/ie_tsan.supp @@ -9,9 +9,6 @@ race:^ov::intel_cpu::Node::GetNodesHolder()::localHolder$ # global const variable from pugixml race:^pugi::impl::(anonymous namespace)::dummy_node_set$ -# global const variable from GNA plugin -race:^GNAPluginNS::supported_values[abi:cxx11]$ - # Issue 91368 race:libopenvino_gapi_preproc.so diff --git a/tests/model_hub_tests/models_hub_common/constants.py b/tests/model_hub_tests/models_hub_common/constants.py index 8830543ed8b..cf2b92637d5 100644 --- a/tests/model_hub_tests/models_hub_common/constants.py +++ b/tests/model_hub_tests/models_hub_common/constants.py @@ -27,5 +27,5 @@ if os.environ.get('USE_SYSTEM_CACHE', 'True') == 'False': no_clean_cache_dir = True os.environ['HUGGINGFACE_HUB_CACHE'] = hf_hub_cache_dir -# supported_devices : CPU, GPU, GNA +# supported_devices : CPU, GPU test_device = os.environ.get('TEST_DEVICE', 'CPU;GPU').split(';')